text chan types, comp options, counter fixed

This commit is contained in:
Климов Андрей Николаевич
2023-10-21 21:06:00 +03:00
parent e93e52702e
commit f6a57348eb
12 changed files with 104 additions and 35 deletions

View File

@@ -15,4 +15,5 @@
-DTIMER_INT
-DRESTART_LAN_ON_MQTT_ERRORS
-DOTA_PORT=80
-DOTA_PORT=80
-DMERCURY_ENABLE

View File

@@ -56,4 +56,5 @@
-DMQTT_KEEPALIVE=10
-DMQTT_SOCKET_TIMEOUT=20
-D CORS=\"*\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
-DMERCURY_ENABLE

View File

@@ -38,5 +38,5 @@
-DOTA_PORT=80
-D CORS=\"*\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
#-D MERCURY_ENABLE
-D MERCURY_ENABLE
#-D IPMODBUS

View File

@@ -6,6 +6,12 @@
-DARDUINO_OTA_MDNS_DISABLE
-DMDNS_ENABLE
-DNO_HOMIE
-DCSSHDC_DISABLE
-DSPILED_DISABLE
-DAC_DISABLE
-DRESTART_LAN_ON_MQTT_ERRORS
-D CORS=\"*\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"

View File

@@ -27,3 +27,4 @@
# Example of UARTBRIDGE configuration
#-DUARTBRIDGE_ENABLE
-DOTA_PORT=80
-DMERCURY_ENABLE

View File

@@ -15,4 +15,5 @@
#-DMCP23017
-D CORS=\"*\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
-D REDIRECTION_URL=\"http://lazyhome.ru/pwa\"
-DMERCURY_ENABLE

View File

@@ -36,4 +36,5 @@
-D HAL_CAN_MODULE_ENABLED
#HAL_ETH_MODULE_DISABLED
#HAL_SD_MODULE_DISABLED
#HAL_DAC_MODULE_DISABLED
#HAL_DAC_MODULE_DISABLED
-DMERCURY_ENABLE

View File

@@ -140,7 +140,8 @@ void Item::Parse() {
for (int i = aJson.getArraySize(itemArr); i < 4; i++)
aJson.addItemToArray(itemArr, aJson.createNull());//( (long int) 0));
// int(defval[i]) )); //Enlarge item to 4 elements. VAL=int if no other definition in conf
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
//itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
itemType = replaceTypeToInt (aJson.getArrayItem(itemArr, I_TYPE));
itemArg = aJson.getArrayItem(itemArr, I_ARG);
itemVal = aJson.getArrayItem(itemArr, I_VAL);
itemExt = aJson.getArrayItem(itemArr, I_EXT);
@@ -794,6 +795,8 @@ int Item::scheduleOppositeCommand(itemCmd cmd,bool authorized)
break;
case CMD_RESTORE: nextCmd.Cmd(CMD_HALT);
break;
case CMD_TOGGLE: nextCmd.Cmd(CMD_TOGGLE);
break;
default: return 0;
}
@@ -1341,12 +1344,12 @@ if (invalidArgument) return -4;
if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
{
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
//debugSerial<<F("sts:")<<status2Send<<endl;
if (driver) //New style modular code
{
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
res = driver->Ctrl(cmd, subItem, toExecute,authorized);
if (driver->getChanType() == CH_THERMO) status2Send |= FLAG_SEND_IMMEDIATE;
//if (res==-1) status2Send=0; ///////not working
@@ -1365,6 +1368,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
short icmd =cmd.getCmd();
if (!authorized && isProtectedPin(iaddr)) {errorSerial<<F("Unauthorized")<<endl; return -5;}
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
if (iaddr)
{
int k;
@@ -1409,6 +1415,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
}
case CH_THERMO:
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
switch (suffixCode)
{
case S_VAL:
@@ -1438,6 +1447,9 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
#ifndef MODBUS_DISABLE
case CH_MODBUS:
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue()))
{
int vol;
@@ -1451,9 +1463,13 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED)))
}
break;
case CH_VC:
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetFan(cmd);
break;
case CH_VCTEMP:
// UPDATE internal variables
if (status2Send) cmd.saveItem(this,status2Send);
if (toExecute && !(chActive && cmd.getCmd()==CMD_ON && !cmd.isValue())) res=VacomSetHeat(cmd);
break;
#endif

View File

@@ -39,6 +39,20 @@ int txt2cmd(char *payload) {
return cmd;
}
int type2num(char *payload) {
if (!payload || !payload[0]) return -1;
for(uint8_t i=0; i<ch_typeNum ;i++)
if (strncmp_P(payload, ch_type_P[i], strlen_P(ch_type_P[i])) == 0)
{
return i;
}
return -1;
}
/*!
\brief Constructor with definition of type and command
\param type - type of value (ST_???, ST_VOID by default)
@@ -1180,6 +1194,22 @@ return false;
return 0;
}
int replaceTypeToInt(aJsonObject* verb)
{
if (verb && verb->type == aJson_String)
{
int type = type2num(verb->valuestring);
if (type>=0)
{
freeString(verb->valuestring);
verb->valueint=type;
verb->type=aJson_Int;
return verb->valueint;
}
} else if (verb && verb->type == aJson_Int) return verb->valueint;
return -1;
}
// Mapping from unified itemCmd object to some specific device-depended value
itemCmd itemCmd::doMapping(aJsonObject *mappingData)
{

View File

@@ -31,8 +31,39 @@ const cmdstr commands_P[] PROGMEM =
"HIGH","MEDIUM","LOW",
"HEAT","COOL","DRY","STOP","RGB","HSV"
};
#define commandsNum sizeof(commands_P)/sizeof(cmdstr)
typedef char ch_type[9];
const ch_type ch_type_P[] PROGMEM =
{
"DMX", // 0 //DMX 1-4 ch
"DMXRGBW",// 1 //DMX 4 ch
"DMXRGB", // 2 //DMX 3 ch
"PWM", // 3 //PWM output directly to PIN 1-4 CH
"MBUSDIM",// 4 //Modbus AC Dimmer
"THERMO", // 5 //Simple ON/OFF thermostat
"RELAY", // 6 //ON_OFF relay output
"GROUP", // 7 //Group pseudochannel
"VCTEMP", // 8 //Vacom PID regulator
"MBUSVC", // 9 //Vacom modbus motor regulator
"ACHAIER",// 10 //AC Haier
"SPILED", // 11 //SPI led strip
"MOTOR", // 12 //Motorized gate with feedback resistor
"PID", // 13 //PID regulator
"MBUS", // 14 //Universal Modbus Master channel
"UARTBRDG", // 15 //Bridge between 2 UARTS with reporting PDUs to Wireshark via UDP
"RELAYPWM", // 16 //Slow PWM relay to control objects with inertia
"DMXRGBWW", // 17 //DMX RGBWW channel (warm&cold white)
"VENTS", // 18 //Multichannel ventilation
"ELEVATOR", // 19 //
"COUNTER", // 20 //Generic counter
"HUM", // 21 //Humidifier
"MERCURY" // 22 //Mercury energy meter/RS485 interface
};
#define ch_typeNum sizeof(ch_type_P)/sizeof(ch_type)
/// Definition of Commands
#define CMD_ON 1 /// Turn channel ON
#define CMD_OFF 2 /// Turn channel OFF
@@ -241,4 +272,5 @@ public:
};
int replaceTypeToInt(aJsonObject* verb);
#pragma pack(pop)

View File

@@ -6,19 +6,10 @@
#include "item.h"
#include "main.h"
//#include "dmx.h"
static int driverStatus = CST_UNKNOWN;
void out_counter::getConfig()
{
if (!item) return;
impulse = item->getFloatArg(0)*TENS_BASE;
period = item->getFloatArg(1)*1000.0;
//debugSerial<<"CTR: imp:"<<impulse<<" period:"<<period<<endl;
}
int out_counter::Setup()
{
abstractOut::Setup();
@@ -43,22 +34,18 @@ int out_counter::Poll(short cause)
if (cause==POLLING_SLOW || cause==POLLING_INT) return 0;
if (!item) return 0;
uint32_t timer = item->getExt();
uint32_t timer = item->getExt();
uint32_t period = item->getFloatArg(1)*1000.0;
if (timer && period && isTimeOver(timer,millis(),period))
{
uint32_t impulse = item->getFloatArg(0)*TENS_BASE;
item->setExt(millisNZ());
itemCmd st;
st.loadItem(item,FLAG_PARAMETERS|FLAG_COMMAND);
//float val = st.getFloat();
uint32_t val = st.getTens_raw();
//short cmd = st.getCmd();
debugSerial<<"CTR: tick val:"<<val<< " + "<< impulse << endl;
val+=impulse;
//st.Float(val);
st.Tens_raw(val);
st.saveItem(item);
debugSerial<<"CTR: tick saved val:"<<val<<endl;

View File

@@ -9,19 +9,12 @@
class out_counter : public abstractOut {
public:
out_counter(Item * _item):abstractOut(_item){ getConfig();};
void getConfig();
out_counter(Item * _item):abstractOut(_item){};
int Setup() override;
int Poll(short cause) override;
int Stop() override;
int Status() override;
int Status() override;
int getChanType() override;
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
protected:
//float impulse;
uint32_t impulse;
uint32_t period;
};
#endif