mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
interim modbus commit (untested)
This commit is contained in:
@@ -10,8 +10,9 @@ public:
|
||||
abstractOut(Item * _item):abstractCh(){item=_item;};
|
||||
virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) =0;
|
||||
virtual int isActive(){return 0;};
|
||||
virtual int getDefaultOnVal(){return 100;};
|
||||
virtual itemCmd getDefaultOnVal(){return itemCmd(ST_PERCENTS,CMD_VOID).Percents(100);};
|
||||
virtual int getChanType(){return 0;}
|
||||
virtual int getDefaultStorageType(){return ST_PERCENTS;}
|
||||
protected:
|
||||
Item * item;
|
||||
};
|
||||
|
||||
@@ -115,11 +115,11 @@ void Input::Parse(aJsonObject * configObj)
|
||||
}
|
||||
|
||||
// Persistant storage
|
||||
itemBuffer = aJson.getObjectItem(inputObj, "S");
|
||||
itemBuffer = aJson.getObjectItem(inputObj, "@S");
|
||||
if (!itemBuffer) {
|
||||
debugSerial<<F("In: ")<<pin<<F("/")<<inType<<endl;
|
||||
aJson.addNumberToObject(inputObj, "S", 0);
|
||||
itemBuffer = aJson.getObjectItem(inputObj, "S");
|
||||
aJson.addNumberToObject(inputObj, "@S", (long int) 0);
|
||||
itemBuffer = aJson.getObjectItem(inputObj, "@S");
|
||||
}
|
||||
if (itemBuffer) store = (inStore *) &itemBuffer->valueint;
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void Item::Parse() {
|
||||
if (isValid()) {
|
||||
// Todo - avoid static enlarge for every types
|
||||
for (int i = aJson.getArraySize(itemArr); i < 4; i++)
|
||||
aJson.addItemToArray(itemArr, aJson.createItem(
|
||||
aJson.addItemToArray(itemArr, aJson.createItem( (long int)
|
||||
int(defval[i]))); //Enlarge item to 4 elements. VAL=int if no other definition in conf
|
||||
itemType = aJson.getArrayItem(itemArr, I_TYPE)->valueint;
|
||||
itemArg = aJson.getArrayItem(itemArr, I_ARG);
|
||||
@@ -374,7 +374,7 @@ void Item::setExt(long int par) // Only store if VAL is int (autogenerated or c
|
||||
if (!itemExt)
|
||||
{
|
||||
for (int i = aJson.getArraySize(itemArr); i <= 4; i++)
|
||||
aJson.addItemToArray(itemArr, itemExt=aJson.createItem(0));
|
||||
aJson.addItemToArray(itemArr, itemExt=aJson.createItem((long int)0));
|
||||
//itemExt = aJson.getArrayItem(itemArr, I_EXT);
|
||||
};
|
||||
|
||||
@@ -396,7 +396,7 @@ chPersistent * Item::setPersistent(chPersistent * par)
|
||||
if (!itemExt)
|
||||
{
|
||||
for (int i = aJson.getArraySize(itemArr); i <= 4; i++)
|
||||
aJson.addItemToArray(itemArr, itemExt = aJson.createItem(0));
|
||||
aJson.addItemToArray(itemArr, itemExt = aJson.createItem((long int)0));
|
||||
//itemExt = aJson.getArrayItem(itemArr, I_EXT);
|
||||
};
|
||||
|
||||
@@ -858,7 +858,7 @@ switch (itemType) {
|
||||
iaddr = -iaddr;
|
||||
inverse = 1;
|
||||
}
|
||||
if (iaddr <=PINS_COUNT && iaddr>0)
|
||||
if (iaddr <= (short) PINS_COUNT && iaddr>0)
|
||||
{
|
||||
pinMode(iaddr, OUTPUT);
|
||||
|
||||
@@ -1263,17 +1263,17 @@ int Item::checkFM() {
|
||||
debugSerial<<_HEX(data)<<F("-");
|
||||
}
|
||||
debugSerial<<endl;
|
||||
int RPM;
|
||||
long int RPM;
|
||||
// aJson.addNumberToObject(out,"gsw", (int) node.getResponseBuffer(1));
|
||||
aJson.addNumberToObject(out, "V", (int) node.getResponseBuffer(2) / 100.);
|
||||
aJson.addNumberToObject(out, "V", (long int) node.getResponseBuffer(2) / 100.);
|
||||
// aJson.addNumberToObject(out,"f", (int) node.getResponseBuffer(3)/100.);
|
||||
aJson.addNumberToObject(out, "RPM", RPM=(int) node.getResponseBuffer(4));
|
||||
aJson.addNumberToObject(out, "I", (int) node.getResponseBuffer(5) / 100.);
|
||||
aJson.addNumberToObject(out, "M", (int) node.getResponseBuffer(6) / 10.);
|
||||
aJson.addNumberToObject(out, "RPM", RPM=(long int) node.getResponseBuffer(4));
|
||||
aJson.addNumberToObject(out, "I", (long int) node.getResponseBuffer(5) / 100.);
|
||||
aJson.addNumberToObject(out, "M", (long int) node.getResponseBuffer(6) / 10.);
|
||||
// aJson.addNumberToObject(out,"P", (int) node.getResponseBuffer(7)/10.);
|
||||
// aJson.addNumberToObject(out,"U", (int) node.getResponseBuffer(8)/10.);
|
||||
// aJson.addNumberToObject(out,"Ui", (int) node.getResponseBuffer(9));
|
||||
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
||||
aJson.addNumberToObject(out, "sw", (long int) node.getResponseBuffer(0));
|
||||
if (RPM && itemArg->type == aJson_Array) {
|
||||
aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1);
|
||||
if (airGateObj && airGateObj->type == aJson_String) {
|
||||
@@ -1290,11 +1290,11 @@ int Item::checkFM() {
|
||||
if (node.getResponseBuffer(0) & 8) //Active fault
|
||||
{
|
||||
result = node.readHoldingRegisters(2111 - 1, 1);
|
||||
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (int) node.getResponseBuffer(0));
|
||||
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (long int) node.getResponseBuffer(0));
|
||||
modbusBusy=0;
|
||||
if (isActive()>0) Off(); //Shut down ///
|
||||
modbusBusy=1;
|
||||
} else aJson.addNumberToObject(out, "flt", 0);
|
||||
} else aJson.addNumberToObject(out, "flt", (long int)0);
|
||||
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(20 - 1, 4);
|
||||
@@ -1316,7 +1316,7 @@ int Item::checkFM() {
|
||||
int16_t pwr = node.getResponseBuffer(3);
|
||||
if (pwr > 0)
|
||||
aJson.addNumberToObject(out, "pwr", pwr / 10.);
|
||||
else aJson.addNumberToObject(out, "pwr", 0);
|
||||
else aJson.addNumberToObject(out, "pwr", (long int) 0);
|
||||
|
||||
if (ftemp > FM_OVERHEAT_CELSIUS && set) {
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
|
||||
@@ -552,6 +552,7 @@ long int itemCmd::getInt()
|
||||
case ST_UINT32:
|
||||
case ST_RGB:
|
||||
case ST_RGBW:
|
||||
case ST_TENS:
|
||||
return param.aslong;
|
||||
|
||||
case ST_PERCENTS:
|
||||
@@ -571,6 +572,11 @@ long int itemCmd::getInt()
|
||||
}
|
||||
}
|
||||
|
||||
long int itemCmd::getSingleInt()
|
||||
{
|
||||
if (cmd.cmdCode) return cmd.cmdCode;
|
||||
return getInt();
|
||||
}
|
||||
|
||||
short itemCmd::getPercents(bool inverse)
|
||||
{
|
||||
@@ -683,8 +689,21 @@ itemCmd itemCmd::Int(int32_t i)
|
||||
return *this;
|
||||
}
|
||||
|
||||
itemCmd itemCmd::Int(uint32_t i)
|
||||
{
|
||||
cmd.itemArgType=ST_UINT32;
|
||||
param.asUint32=i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
itemCmd itemCmd::Tens(int32_t i)
|
||||
{
|
||||
cmd.itemArgType=ST_TENS;
|
||||
param.asInt32=i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
itemCmd itemCmd::HSV(uint16_t h, uint8_t s, uint8_t v)
|
||||
{
|
||||
cmd.itemArgType=ST_HSV;
|
||||
@@ -737,12 +756,7 @@ itemCmd itemCmd::RGBW(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
|
||||
return *this;
|
||||
}
|
||||
|
||||
itemCmd itemCmd::Int(uint32_t i)
|
||||
{
|
||||
cmd.itemArgType=ST_UINT32;
|
||||
param.asUint32=i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
itemCmd itemCmd::Cmd(uint8_t i)
|
||||
@@ -797,6 +811,17 @@ return false;
|
||||
}
|
||||
|
||||
|
||||
int itemCmd::doMapping(aJsonObject *mappingData)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
int itemCmd::doReverseMapping (aJsonObject *mappingData)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
|
||||
{
|
||||
@@ -826,7 +851,9 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags )
|
||||
break;
|
||||
case ST_INT32:
|
||||
snprintf(argPtr, bufLen, "%ld", param.asInt32);
|
||||
|
||||
break;
|
||||
case ST_TENS:
|
||||
snprintf(argPtr, bufLen, "%ld.%d", param.asInt32/10, param.asInt32 % 10);
|
||||
break;
|
||||
case ST_HSV:
|
||||
case ST_HSV255:
|
||||
|
||||
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
#include "aJson.h"
|
||||
|
||||
typedef char cmdstr[9];
|
||||
|
||||
@@ -110,6 +111,8 @@ ST_FLOAT = 13//,
|
||||
#define ST_STRING 13 /// pointer to string (for further use)
|
||||
#define ST_FLOAT 14 /// generic Float value
|
||||
|
||||
#define MAP_SCALE 1
|
||||
#define MAP_VAL_CMD 2
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
@@ -184,6 +187,7 @@ public:
|
||||
|
||||
itemCmd Int(int32_t i);
|
||||
itemCmd Int(uint32_t i);
|
||||
itemCmd Tens(int32_t i);
|
||||
itemCmd Cmd(uint8_t i);
|
||||
itemCmd HSV(uint16_t h, uint8_t s, uint8_t v);
|
||||
itemCmd HSV255(uint16_t h, uint8_t s, uint8_t v);
|
||||
@@ -208,6 +212,7 @@ public:
|
||||
bool incrementS(int16_t);
|
||||
|
||||
long int getInt();
|
||||
long int getSingleInt();
|
||||
short getPercents(bool inverse=false);
|
||||
short getPercents255(bool inverse=false);
|
||||
uint8_t getCmd();
|
||||
@@ -222,6 +227,11 @@ public:
|
||||
itemCmd setDefault();
|
||||
itemCmd setChanType(short chanType);
|
||||
void debugOut();
|
||||
|
||||
int doMapping(aJsonObject *mappingData);
|
||||
int doReverseMapping (aJsonObject *mappingData);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -2161,7 +2161,7 @@ short thermoSetCurTemp(char *name, float t) {
|
||||
extArray = aJson.createArray(); //Create Ext Array
|
||||
|
||||
aJsonObject *ocurt = aJson.createItem(t); //Create float
|
||||
aJsonObject *oattempts = aJson.createItem(T_ATTEMPTS); //Create int
|
||||
aJsonObject *oattempts = aJson.createItem((long int) T_ATTEMPTS); //Create int
|
||||
aJson.addItemToArray(extArray, ocurt);
|
||||
aJson.addItemToArray(extArray, oattempts);
|
||||
aJson.addItemToArray(thermoItem, extArray); //Adding to thermoItem
|
||||
|
||||
@@ -36,6 +36,7 @@ struct serial_t
|
||||
#define PAR_I8L 6
|
||||
#define PAR_U8H 7
|
||||
#define PAR_U8L 8
|
||||
#define PAR_TENS 9
|
||||
|
||||
|
||||
const reg_t regSize_P[] PROGMEM =
|
||||
@@ -47,7 +48,8 @@ const reg_t regSize_P[] PROGMEM =
|
||||
{ "i8h", (uint8_t) PAR_I8H },
|
||||
{ "i8l", (uint8_t) PAR_I8L },
|
||||
{ "u8h", (uint8_t) PAR_U8H },
|
||||
{ "u8l", (uint8_t) PAR_U8L }
|
||||
{ "u8l", (uint8_t) PAR_U8L },
|
||||
{ "x10", (uint8_t) PAR_TENS }
|
||||
} ;
|
||||
#define regSizeNum sizeof(regSize_P)/sizeof(reg_t)
|
||||
|
||||
@@ -223,40 +225,75 @@ int out_Modbus::findRegister(int registerNum, int posInBuffer)
|
||||
int8_t regType = PAR_I16;
|
||||
uint32_t param =0;
|
||||
itemCmd mappedParam;
|
||||
bool isSigned=false;
|
||||
char buf[16];
|
||||
|
||||
//bool isSigned=false;
|
||||
if (typeObj && typeObj->type == aJson_String) regType=str2regSize(typeObj->valuestring);
|
||||
switch(regType) {
|
||||
|
||||
case PAR_I16:
|
||||
isSigned=true;
|
||||
//isSigned=true;
|
||||
mappedParam.Int((int32_t)data);
|
||||
break;
|
||||
|
||||
case PAR_U16:
|
||||
param=data;
|
||||
mappedParam.Int((uint32_t)data);
|
||||
//param=data;
|
||||
break;
|
||||
case PAR_I32:
|
||||
isSigned=true;
|
||||
//isSigned=true;
|
||||
param = data | (node.getResponseBuffer(posInBuffer+1)<<16);
|
||||
mappedParam.Int((int32_t)param);
|
||||
break;
|
||||
|
||||
case PAR_U32:
|
||||
param = data | (node.getResponseBuffer(posInBuffer+1)<<16);
|
||||
mappedParam.Int((uint32_t)param);
|
||||
break;
|
||||
|
||||
case PAR_U8L:
|
||||
is8bit=true;
|
||||
//is8bit=true;
|
||||
param = data & 0xFF;
|
||||
mappedParam.Int((uint32_t)param);
|
||||
break;
|
||||
|
||||
case PAR_U8H:
|
||||
is8bit=true;
|
||||
//is8bit=true;
|
||||
param = data << 8;
|
||||
mappedParam.Int((uint32_t)param);
|
||||
break;
|
||||
|
||||
case PAR_TENS:
|
||||
mappedParam.Tens((int32_t) data);
|
||||
}
|
||||
|
||||
if (mapObj && (mapObj->type==aJson_Array || mapObj->type==aJson_Object))
|
||||
mappedParam = mapInt(param,mapObj);
|
||||
else mappedParam.Int(param);
|
||||
mappedParam.doMapping(mapObj);
|
||||
|
||||
debugSerial << F("MB got ")<<mappedParam.toString(buf,sizeof(buf))<< F(" from ")<<regType<<F(":")<<paramObj->name<<endl;
|
||||
|
||||
if (itemParametersObj && itemParametersObj->type ==aJson_Object)
|
||||
{
|
||||
aJsonObject *execObj = aJson.getObjectItem(itemParametersObj,paramObj->name);
|
||||
if (execObj) executeCommand(execObj, -1, mappedParam);
|
||||
if (execObj)
|
||||
{
|
||||
bool submitParam=true;
|
||||
//Retrive previous data
|
||||
aJsonObject *lastMeasured = aJson.getObjectItem(execObj,"@S");
|
||||
if (lastMeasured)
|
||||
{
|
||||
if (lastMeasured->valueint == mappedParam.getSingleInt())
|
||||
submitParam=false; //supress repeating execution for same val
|
||||
else lastMeasured->valueint=mappedParam.getSingleInt();
|
||||
}
|
||||
else //No container to store value yet
|
||||
{
|
||||
debugSerial<<F("Add @S: ")<<paramObj->name<<endl;
|
||||
aJson.addNumberToObject(execObj, "@S", mappedParam.getSingleInt());
|
||||
}
|
||||
if (submitParam) executeCommand(execObj, -1, mappedParam);
|
||||
}
|
||||
}
|
||||
debugSerial << F("MB got ")<<param<< F(" from ")<<regType<<F(":")<<paramObj->name<<endl;
|
||||
|
||||
if (!is8bit) return 1;
|
||||
}
|
||||
paramObj=paramObj->next;
|
||||
|
||||
@@ -16,7 +16,6 @@ public:
|
||||
uint32_t timestamp;
|
||||
aJsonObject * pollingRegisters;
|
||||
aJsonObject * parameters;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user