XNova CRYPT,SHAREDSECRET,PROTECTED_PINS,PULSEPIN12

This commit is contained in:
Климов Андрей Николаевич
2023-10-08 17:43:30 +03:00
parent 6cd4f1d82a
commit e93e52702e
34 changed files with 173 additions and 68 deletions

View File

@@ -15,6 +15,7 @@
-DPID_DISABLE
-DOTA
-DMOTOR_DISABLE
-DMULTIVENT_DISABLE
#-DWiz5100
-DARDUINO_OTA_MDNS_DISABLE
-DMDNS_ENABLE

View File

@@ -0,0 +1,16 @@
REM fetch DeviceID of Arduino Port from WMI Service
FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%Arduino Uno%%'" get DeviceID') DO (
SET COMX=%%a
GOTO exit1
)
REM Arduino Due Programming Port not exist
GOTO error_comport
:exit1
REM remove blank
SET COMPORT=%COMX: =%
..\tools\win\tool-avrdude\avrdude -C ..\tools\win\tool-avrdude\avrdude.conf -c arduino -P %COMPORT% -b 19200 -p m16u2 -vvv -U flash:w:16u2.hex:i

View File

@@ -0,0 +1 @@
wmic PATH Win32_SerialPort get DeviceID

View File

@@ -28,7 +28,7 @@ REM bin file exist?
IF NOT EXIST "%BINFILE%" GOTO error_binfile
REM fetch DeviceID of Arduino Due Programming Port from WMI Service
FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%USB%%'" get DeviceID') DO (
FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%Due%%'" get DeviceID') DO (
SET COMX=%%a
GOTO exit1
)

View File

@@ -8,7 +8,7 @@ class chPersistent {};
class abstractOut : public abstractCh{
public:
abstractOut(Item * _item):abstractCh(){item=_item;};
virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) =0;
virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) =0;
virtual int isActive();
virtual bool isAllowed(itemCmd cmd){return true;};
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};

View File

@@ -44,7 +44,7 @@ return val;
}
*/
int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute, bool authorized)
{
debugSerial<<F("clrCtr: ");
cmd.debugOut();
@@ -67,7 +67,8 @@ case S_CMD:
switch (cmd.getCmd())
{
case CMD_ON:
if (vol=cmd.getPercents()<MIN_VOLUME && vol>=0)
vol=cmd.getPercents();
if (vol<MIN_VOLUME && vol>=0)
{
cmd.setPercents(INIT_VOLUME);
cmd.saveItem(item);

View File

@@ -14,7 +14,7 @@ public:
if (iaddr<0) iaddr=-iaddr;
numArgs = item->getArgCount(); // and how many addresses is configured
};
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override;
int getDefaultStorageType()override;
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0;
short getChannelAddr(short n =0);

View File

@@ -696,7 +696,7 @@ st.setSuffix(suffixCode);
default:;
}
return Ctrl(st,subItem);
return Ctrl(st,subItem,true,authorized);
}
case CMD_UP:
case CMD_DN:
@@ -704,13 +704,13 @@ st.setSuffix(suffixCode);
itemCmd Par0 = getNumber((char **) &payload);
Par0.Cmd(cmd);
Par0.setSuffix(suffixCode);
return Ctrl(Par0, subItem);
return Ctrl(Par0, subItem,true,authorized);
}
default: //some known command
{
int32_t intParam = getInt((char **) &payload);
if (intParam) st.Int(intParam);
return Ctrl(st, subItem);
return Ctrl(st,NULL, true, authorized);
}
} //ctrl
return 0;
@@ -719,7 +719,7 @@ return 0;
// Recursive function with small stack consumption
// if cmd defined - execute Ctrl for any group members recursively
// else performs Activity check for group members and return true if any member is active
bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem)
bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem, bool authorized)
{ if (!itemArr || itemArr->type!=aJson_Array) return false;
// Iterate across array of names
aJsonObject *i = itemArr->child;
@@ -731,13 +731,13 @@ bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem)
if (nextItem && nextItem->type == aJson_Array) //nextItem is correct item
{
Item it(nextItem);
if (cmd && it.isValid()) it.Ctrl(*cmd,subItem,false); //Execute (non recursive)
if (cmd && it.isValid()) it.Ctrl(*cmd,subItem,false,authorized); //Execute (non recursive)
//Retrieve itemType
aJsonObject * itemtype = aJson.getArrayItem(nextItem,0);
if (itemtype && itemtype->type == aJson_Int && itemtype->valueint == CH_GROUP)
{ //is Group
aJsonObject * itemSubArray = aJson.getArrayItem(nextItem,1);
short res = digGroup(itemSubArray,cmd,subItem);
short res = digGroup(itemSubArray,cmd,subItem,authorized);
if (!cmd && res)
{
configLocked--;
@@ -769,7 +769,7 @@ aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
return 0;
}
int Item::scheduleOppositeCommand(itemCmd cmd)
int Item::scheduleOppositeCommand(itemCmd cmd,bool authorized)
{
itemCmd nextCmd=cmd;
@@ -798,11 +798,11 @@ int Item::scheduleOppositeCommand(itemCmd cmd)
default: return 0;
}
debugSerial<<F("CTRL: Schedule cmd ")<<nextCmd.getCmd()<<F(" for (ms):")<<nextCmd.getInt()<<endl;
scheduleCommand(nextCmd);
scheduleCommand(nextCmd,authorized);
return 1;
}
int Item::scheduleCommand(itemCmd cmd)
int Item::scheduleCommand(itemCmd cmd,bool authorized)
{
if (!itemArr) return 0;
@@ -816,7 +816,8 @@ int Item::scheduleCommand(itemCmd cmd)
{
timestampObj->valueint = millis()+cmd.getInt();
timestampObj->type = aJson_Int;
timestampObj->subtype=cmd.getCmd();
timestampObj->subtype=(cmd.getCmd() & 0xF) | ((authorized?1:0)<<4);
debugSerial<<F( "Armed for ")<< cmd.getInt() << F(" ms :")<<timestampObj->valueint<<endl;
}
else
@@ -836,6 +837,7 @@ int Item::scheduleCommand(itemCmd cmd)
// -3 ignored
// -1 system error
// -4 invalid argument
// -5 unauthorized
int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized)
{
int fr = freeRam();
@@ -876,7 +878,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
/// DELAYED COMMANDS processing
if (suffixCode == S_DELAYED)
{
return scheduleCommand(cmd);
return scheduleCommand(cmd,authorized);
}
///
int8_t chActive = -1;
@@ -1012,14 +1014,14 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
{
status2Send |= FLAG_PARAMETERS | FLAG_SEND_DEFFERED;
cmd.setSuffix(S_SET);
} else {cmd=fallbackCmd;invalidArgument=true;}
} else {cmd=fallbackCmd;invalidArgument=true; errorSerial << F("Invalid arg")<<endl;}
break;
case S_SAT:
if (cmd.incrementS(step))
{
status2Send |= FLAG_PARAMETERS | FLAG_SEND_DEFFERED;
cmd.setSuffix(S_SET);
} else {cmd=fallbackCmd;invalidArgument=true;}
} else {cmd=fallbackCmd;invalidArgument=true; errorSerial << F("Invalid arg")<<endl;}
} //switch suffix
} //Case UP/DOWN
@@ -1036,7 +1038,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
if (allowRecursion && itemArg->type == aJson_Array && operation)
{
chActive=(isActive()>0);
digGroup(itemArg,&cmd,subItem);
digGroup(itemArg,&cmd,subItem,authorized);
}
res=1;
@@ -1046,7 +1048,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
case CMD_RESTORE: // individual for group members
switch (t = getCmd()) {
case CMD_HALT: //previous command was HALT ?
if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd);
if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized);
debugSerial << F("CTRL: Restored from:") << t << endl;
cmd.loadItemDef(this);
cmd.Cmd(CMD_ON); //turning on
@@ -1060,7 +1062,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
case CMD_XOFF: // individual for group members
switch (t = getCmd()) {
case CMD_XON: //previous command was CMD_XON ?
if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd);
if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized);
debugSerial << F("CTRL: Turned off from:") << t << endl;
cmd.Cmd(CMD_OFF); //turning Off
status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE;
@@ -1077,7 +1079,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
{
if (chActive == -1) chActive=(isActive()>0);
if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd);
if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized);
if (!chActive) //if channel was'nt active before CMD_XON
@@ -1104,7 +1106,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
break;
case CMD_HALT:
if (chActive == -1) chActive=(isActive()>0);
if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd);
if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized);
if (chActive) //if channel was active before CMD_HALT /// HERE bug - if cmd == On but 0 = active
{
cmd.Cmd(CMD_OFF);
@@ -1147,7 +1149,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
}
else // Fast track for commands to subitems
{
if (driver) return driver->Ctrl(cmd,subItem,toExecute);
if (driver) return driver->Ctrl(cmd,subItem,toExecute,authorized);
///// return 0;
}
}
@@ -1160,7 +1162,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
switch (t = getCmd()) {
case CMD_HALT: //previous command was HALT ?
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
debugSerial << F("CTRL: Restored from:") << t << endl;
cmd.loadItemDef(this);
@@ -1178,7 +1180,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
switch (t = getCmd()) {
case CMD_XON: //previous command was CMD_XON ?
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
debugSerial << F("CTRL: Turned off from:") << t << endl;
toExecute=true;
cmd.Cmd(CMD_OFF); //turning Off
@@ -1195,7 +1197,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
if (!getFlag(FLAG_DISABLED))
{
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
if (!chActive) //if channel was'nt active before CMD_XON
{
@@ -1222,7 +1224,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
case CMD_HALT:
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
if (chActive) //if channel was active before CMD_HALT
{
cmd.Cmd(CMD_OFF);
@@ -1247,7 +1249,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
if (getCmd() == CMD_HALT) return 3; //Halted, ignore OFF
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE;
toExecute=true;
break;
@@ -1255,7 +1257,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
case CMD_ON:
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
if (!cmd.isChannelCommand()) //Command for driver, not for whole channel
{
@@ -1298,7 +1300,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
toExecute=true;
//debugSerial<<F("Disable Flag is:")<<getFlag(FLAG_DISABLED)<<endl;
if (allowRecursion && cmd.isValue() && (getFlag(FLAG_DISABLED) || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
break;
case CMD_DISABLE:
@@ -1307,7 +1309,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
toExecute=true;
//debugSerial<<F("Disable Flag is:")<<getFlag(FLAG_DISABLED)<<endl;
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!getFlag(FLAG_DISABLED) || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
break;
case CMD_UNFREEZE:
@@ -1316,7 +1318,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
toExecute=true;
//debugSerial<<F("Disable Flag is:")<<getFlag(FLAG_DISABLED)<<endl;
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (getFlag(FLAG_FREEZED) || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
break;
case CMD_FREEZE:
@@ -1326,7 +1328,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized
toExecute=true;
//debugSerial<<F("Disable Flag is:")<<getFlag(FLAG_DISABLED)<<endl;
if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!getFlag(FLAG_FREEZED) || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule
scheduleOppositeCommand(cmd);
scheduleOppositeCommand(cmd,authorized);
break;
default:
@@ -1345,7 +1347,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
if (driver) //New style modular code
{
res = driver->Ctrl(cmd, subItem, toExecute);
res = driver->Ctrl(cmd, subItem, toExecute,authorized);
if (driver->getChanType() == CH_THERMO) status2Send |= FLAG_SEND_IMMEDIATE;
//if (res==-1) status2Send=0; ///////not working
if (status2Send & FLAG_FLAGS) res =1; //ENABLE & DISABLE processed by core
@@ -1361,6 +1363,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
short iaddr=getArg();
short icmd =cmd.getCmd();
if (!authorized && isProtectedPin(iaddr)) {errorSerial<<F("Unauthorized")<<endl; return -5;}
if (iaddr)
{
@@ -1397,6 +1400,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
*/
debugSerial<<F("Pin:")<<iaddr<<F("=")<<k<<endl;
if (isProtectedPin(iaddr) && !isScheduled()) attachMaturaTimer();
status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE;
res=1;
}
@@ -1564,7 +1568,8 @@ if (isPendedModbusWrites) resumeModbus();
aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP);
if (timestampObj)
{
uint8_t cmd = timestampObj->subtype;
uint8_t cmd = timestampObj->subtype & 0xF;
bool authorized = timestampObj->subtype & 0x10;
int32_t remain = (uint32_t) timestampObj->valueint - (uint32_t)millis();
if (cmd) {
@@ -1588,9 +1593,9 @@ if (timestampObj)
errorSerial<<F("CTRL/poll: OutOfMemory: ")<<fr<<endl;
return -1;
}
Ctrl(itemCmd(ST_VOID,cmd));
timestampObj->subtype=0;
Ctrl(itemCmd(ST_VOID,cmd),NULL,true,authorized);
//timestampObj->subtype=0; ////
}
}
}

View File

@@ -103,7 +103,7 @@ extern aJsonObject *items;
extern short thermoSetCurTemp(char *name, float t);
int txt2cmd (char * payload);
bool digGroup (aJsonObject *itemArr, itemCmd *cmd = NULL, char* subItem = NULL);
bool digGroup (aJsonObject *itemArr, itemCmd *cmd = NULL, char* subItem = NULL, bool authorized = false);
class Item
{
public:
@@ -148,8 +148,8 @@ class Item
inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));};
inline int Off(){return Ctrl(itemCmd(ST_VOID,CMD_OFF));};
inline int Toggle(){return Ctrl(itemCmd(ST_VOID,CMD_TOGGLE));};
int scheduleCommand(itemCmd cmd);
int scheduleOppositeCommand(itemCmd cmd);
int scheduleCommand(itemCmd cmd, bool authorized);
int scheduleOppositeCommand(itemCmd cmd,bool authorized);
int isScheduled();
protected:

View File

@@ -98,6 +98,10 @@ lan_status lanStatus = INITIAL_STATE;
const char configserver[] PROGMEM = CONFIG_SERVER;
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
#ifdef CRYPT
char cryptoKey[] = QUOTE(SHAREDSECRET);
#endif
#if defined(__SAM3X8E__)
UID UniqueID;
#endif
@@ -2046,6 +2050,56 @@ int16_t attachTimer(double microseconds, timerCallback callback, const char* Tim
}
#endif
#if defined(__SAM3X8E__) && defined (PULSEPIN12)
#define MATURA_PULSE 100
#define MATURA_PERIOD 2500
void maturaTimerHandler(void){ }
volatile int maturaTimerNumber = -1;
int16_t attachMaturaTimer()
{
if (maturaTimerNumber==-1)
{
DueTimerInterrupt dueTimerInterrupt = DueTimerInterrupt(8);
dueTimerInterrupt.attachInterruptInterval(MATURA_PERIOD*1000, maturaTimerHandler);
maturaTimerNumber = dueTimerInterrupt.getTimerNumber();
TC_SetRB(TC2,2,REG_TC2_RC2 - (REG_TC2_RC2 / MATURA_PERIOD * MATURA_PULSE));
REG_TC2_CMR2 |= TC_CMR_BCPB_SET | TC_CMR_BCPC_CLEAR | TC_CMR_EEVT_XC0; // on CTR==A -> SET; on CTR == C - CLEAR pin, enable TIOB as out
}
debugSerial<<F("Matura attached to Timer(")<<maturaTimerNumber<<F(")")<<endl;
//pinMode(11,OUTPUT); //PIO_PD7B_TIOA8 PERIPH_B //T7
pinMode(12,OUTPUT); //PIO_PD8B_TIOB8 PERIPH_B //T8
// Memo for some future use timers:
//pinMode(2,OUTPUT); //PIO_PB25B_TIOA0 PERIPH_B
//pinMode(13,OUTPUT);//PIO_PB27B_TIOB0 PERIPH_B
//pinMode(3,OUTPUT); //PIO_PC28B_TIOA7 PERIPH_B
//pinMode(10,OUTPUT);//PIO_PC29B_TIOB7 PERIPH_B
//pinMode(5,OUTPUT); //PIO_PC25B_TIOA6 PERIPH_B
//pinMode(4,OUTPUT); //PIO_PC26B_TIOB6 PERIPH_B
// 11 & 12 pins example (TC2 ch2 (#8) A & B channels for some future use)
//REG_PIOD_PDR = PIO_PD7 | PIO_PD8;
//REG_PIOD_ABSR |= PIO_PD7 | PIO_PD8;
//REG_TC2_CMR2 |= TC_CMR_ACPA_SET | TC_CMR_ACPC_CLEAR | TC_CMR_BCPB_SET | TC_CMR_BCPC_CLEAR | TC_CMR_EEVT_XC0;
//TC_SetRA(TC2,2,1000000);TC_SetRB(TC2,2,1500000);
REG_PIOD_PDR = PIO_PD8; //Disabling PD8 IO - move to pereferia
REG_PIOD_ABSR |= PIO_PD8; //Select Pereferia B
//REG_TC2_CMR2 |= TC_CMR_BCPB_SET | TC_CMR_BCPC_CLEAR | TC_CMR_EEVT_XC0; // on CTR==A -> SET; on CTR == C - CLEAR pin, enable TIOB as out
//REG_PIOD_WPMR = PIO_WPMR_WPKEY(0x50494f) | 1; //Write protect whole IOD
return maturaTimerNumber;
}
#else
int16_t attachMaturaTimer(){};
#endif
#if defined(WIFI_ENABLE)
#if defined (ESP32)
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info)
@@ -2804,6 +2858,8 @@ configLocked++;
#if defined(__SAM3X8E__) && defined (TIMER_INT)
// Interval in microsecs
attachTimer(TIMER_CHECK_INPUT * 1000, TimerHandler, "ITimer");
attachMaturaTimer();
#endif
configLocked--;
}

View File

@@ -319,4 +319,6 @@ void printCurentLanConfig();
void onMQTTConnect();
int16_t attachMaturaTimer();
//void printFreeRam();

View File

@@ -433,7 +433,7 @@ debugSerial<<F("AC: ")<<portNum<<F(" >> ");
return true;
};
int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized)
{
//char s_mode[10];
char s_speed[10];

View File

@@ -44,7 +44,7 @@ public:
int isActive() override;
int getChanType() override;
int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
void SubmitParameters(const char * name, itemCmd value);
protected:

View File

@@ -69,7 +69,7 @@ uint32_t timer = item->getExt();
};
int out_counter::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_counter::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized)
{
debugSerial<<F("Counter: ");
cmd.debugOut();

View File

@@ -17,7 +17,7 @@ public:
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
protected:
//float impulse;

View File

@@ -18,7 +18,7 @@ public:
int getChanType() override;
// int Ctrl(itemCmd cmd, char* subItem=NULL) override;
// int PixelCtrl(itemCmd cmd) override;
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) override;
virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true) override;
protected:
};

View File

@@ -337,6 +337,7 @@ int out_Mercury::Poll(short cause)
//bool lineInitialized = false;
if (cause==POLLING_SLOW) return 0;
if (modbusBusy || ( mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100))) return 0;
if (store->driverStatus == CST_FAILED) return 0;
if (!getConfig()) return 0;
switch (Status())
@@ -474,7 +475,7 @@ int out_Mercury::getChanType()
//!Control unified item
int out_Mercury::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_Mercury::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized)
{
if (!store) return -1;

View File

@@ -49,7 +49,7 @@ public:
int Stop() override;
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
int getDefaultStorageType(){return ST_INT32;};

View File

@@ -856,7 +856,7 @@ else return 0;
// 2. custom textual subItem
// 3. non-standard numeric suffix Code equal param id
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized)
{
if (!store) return -1;

View File

@@ -39,7 +39,7 @@ public:
int Stop() override;
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
int getDefaultStorageType(){return ST_INT32;};
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;

View File

@@ -151,7 +151,7 @@ else if (curPos>=0)
else
dif=targetPos-255/2; // Have No feedback
debugSerial<<F("Motor: in:")<<pinFeedback<<F(" Val:")<<fb<<F("/")<<curPos<<F("->")<<targetPos<<F(" delta:")<<dif<<endl;
//debugSerial<<F("Motor: in:")<<pinFeedback<<F(" Val:")<<fb<<F("/")<<curPos<<F("->")<<targetPos<<F(" delta:")<<dif<<endl;
if (dif<-POS_ERR)
{
@@ -261,7 +261,7 @@ int out_Motor::getChanType()
int out_Motor::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
int out_Motor::Ctrl(itemCmd cmd, char* subItem , bool toExecute,bool authorized)
{
int suffixCode = cmd.getSuffix();
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it

View File

@@ -29,7 +29,7 @@ public:
int getChanType() override;
int getDefaultStorageType(){return ST_PERCENTS255;};
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
int8_t pinUp;
int8_t pinDown;

View File

@@ -94,7 +94,7 @@ int out_Multivent::getChanType()
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized)
{
if (cmd.getCmd()==CMD_DISABLE || cmd.getCmd()==CMD_ENABLE) return 0;

View File

@@ -19,7 +19,7 @@ public:
//int isActive() override;
int getChanType() override;
int getDefaultStorageType(){return ST_PERCENTS255;};
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
protected:
void getConfig();
aJsonObject * gatesObj;

View File

@@ -286,7 +286,7 @@ int out_pid::getChanType()
// /val suffix - to put value into controller
// accept ON and OFF commands
int out_pid::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_pid::Ctrl(itemCmd cmd, char* subItem, bool toExecute, bool authorized)
{
if (!store || !store->pid || (Status() != CST_INITIALIZED)) return 0;
int suffixCode = cmd.getSuffix();

View File

@@ -34,7 +34,7 @@ public:
int isActive() override;
int getChanType() override;
int getDefaultStorageType(){return ST_FLOAT;};
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
void alarm(bool);

View File

@@ -143,7 +143,7 @@ bool needToOff = isTimeOver(timer,millis(),period*val/255);
};
int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized)
{
debugSerial<<F("relayCtr: ");
cmd.debugOut();

View File

@@ -18,7 +18,7 @@ public:
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
protected:
short pin;

View File

@@ -389,7 +389,7 @@ int out_UARTbridge::getChanType()
// 2. custom textual subItem
// 3. non-standard numeric suffix Code equal param id
int out_UARTbridge::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
int out_UARTbridge::Ctrl(itemCmd cmd, char* subItem, bool toExecute, bool authorized)
{
//int chActive = item->isActive();
//bool toExecute = (chActive>0);

View File

@@ -65,7 +65,7 @@ public:
int Stop() override;
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
int getDefaultStorageType(){return ST_INT32;};
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;

View File

@@ -362,3 +362,17 @@
#else
#define minimalMemory 1200
#endif
#if not defined PROTECTED_PINS
#define PROTECTED_PINS
#endif
const short protectedPins[]={PROTECTED_PINS};
#define protectedPinsNum (sizeof(protectedPins)/sizeof(short))
#ifdef CRYPT
#if not defined SHAREDSECRET
#define SHAREDSECRET "12345678"
#endif
#endif

View File

@@ -99,12 +99,12 @@ void SetAddr(char *out, uint8_t *addr) {
// chan is pointer to pointer to string
// Function return first retrived integer and move pointer to position next after ','
int getInt(char **chan) {
long getInt(char **chan) {
if (chan && *chan && **chan)
{
//Skip non-numeric values
while (**chan && !(**chan == '-' || (**chan >= '0' && **chan<='9'))) *chan += 1;
int ch = atoi(*chan);
long ch = atol(*chan);
//Move pointer to next element (after ,)
*chan = strchr(*chan, ',');
@@ -362,7 +362,8 @@ uint32_t ReadUniqueID( uint32_t * pdwUniqueID )
return *(uint32_t *)(IFLASH1_ADDR + 128); // dont remove: SAM defect workaround - MPU dont leave Unique Identifier mode until read flash out UID of range
#else
return 0;
#endif
}
//#pragma optimize("", on)
@@ -814,13 +815,12 @@ bool getPinVal(uint8_t pin)
{
return (0!=(*portOutputRegister( digitalPinToPort(pin) ) & digitalPinToBitMask(pin)));
}
#ifdef CRYPT
#ifdef CRYPT
#define HASH_SIZE 32
SHA256 sha256;
extern uint32_t cryptoSalt;
//extern
const char cryptoKey[] ="12345678";
extern char cryptoKey[];
bool checkToken(char * token, char * data)
{
@@ -864,5 +864,12 @@ bool checkToken(char * token, char * data)
{return true;}
#endif
bool isProtectedPin(short pin)
{
for (short i=0; i<protectedPinsNum; i++)
if (pin==protectedPins[i]) return true;
return false;
}
#pragma message(VAR_NAME_VALUE(debugSerial))
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))

View File

@@ -53,7 +53,7 @@ void PrintBytes(uint8_t* addr, uint8_t count, bool newline);
void SetBytes(uint8_t* addr, uint8_t count, char * out);
void SetAddr(char * out, uint8_t* addr);
uint8_t HEX2DEC(char i);
int getInt(char ** chan);
long getInt(char ** chan);
itemCmd getNumber(char ** chan);
unsigned long freeRam ();
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
@@ -78,3 +78,4 @@ String toString(const IPAddress& address);
bool getPinVal(uint8_t pin);
int str2regSize(char * str);
bool checkToken(char * token, char * data);
bool isProtectedPin(short pin);