core fixes, modbus, ac, pre-mapping, bins

This commit is contained in:
2022-06-04 22:04:54 +03:00
parent 64eea07d78
commit a17ea0bad7
26 changed files with 45651 additions and 43999 deletions

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownExportedFiles">
<htmlFiles />
<imageFiles />
<otherFiles />
</component>
</project>

View File

@@ -1,67 +0,0 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -280,7 +280,7 @@ Item::Item(char *name) //Constructor
buf[i]=0;
itemArr = aJson.getObjectItem(items, buf);
sub++;
strncpy(defaultSubItem,sub,sizeof(defaultSubItem));
strncpy(defaultSubItem,sub,sizeof(defaultSubItem)-1);
defaultSuffixCode = retrieveCode (&pDefaultSubItem);
if (!pDefaultSubItem) defaultSubItem[0] =0; //Zero string
//debugSerial<<F("defaultSubItem: ")<<defaultSubItem<<F(" defaultSuffixCode:")<<defaultSuffixCode<<endl;
@@ -761,7 +761,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion)
int fr = freeRam();
debugSerial<<F("RAM=")<<fr<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd:");
debugSerial<<F("RAM=")<<fr<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" ");
if (fr < 200)
{
errorSerial<<F("OutOfMemory!\n")<<endl;
@@ -1281,6 +1281,15 @@ int Item::isActive() {
}
int cmd = getCmd();
if (driver) {
short active = driver->isActive();
if (active >= 0)
{
printActiveStatus(active);
return active;
}
}
// No driver - check command
if (itemType != CH_GROUP)
// Simple check last command first
@@ -1300,12 +1309,7 @@ int Item::isActive() {
}
// Last time was not a command but parameters set. Looking inside
if (driver) {
bool active = driver->isActive();
printActiveStatus(active);
return active;
}
// No driver - check value
st.loadItem(this);
switch (itemType) {
@@ -1431,7 +1435,7 @@ int Item::SendStatus(int sendFlags) {
{
char addrstr[48];
char valstr[20] = "";
char cmdstr[8] = "";
char cmdstr[9] = "";
st.debugOut();
if (sendFlags & SEND_COMMAND)
{
@@ -1571,11 +1575,11 @@ int Item::SendStatus(int sendFlags) {
strncat(addrstr, itemArr->name, sizeof(addrstr)-1);
if (subItem)
{
strncat(addrstr, "/", sizeof(addrstr));
strncat(addrstr, "/", sizeof(addrstr)-1);
strncat(addrstr, subItem, sizeof(addrstr)-1);
}
strncat(addrstr, "/", sizeof(addrstr));
strncat_P(addrstr, CMD_P, sizeof(addrstr));
strncat(addrstr, "/", sizeof(addrstr)-1);
strncat_P(addrstr, CMD_P, sizeof(addrstr)-1);
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<cmdstr<<endl;
if (mqttClient.connected() && !ethernetIdleCount)

View File

@@ -168,7 +168,7 @@ class Item
int checkFM();
char defaultSubItem[10];
char defaultSubItem[16];
int defaultSuffixCode;
};

View File

@@ -1129,15 +1129,39 @@ return false;
}
int itemCmd::doMapping(aJsonObject *mappingData)
itemCmd itemCmd::doMapping(aJsonObject *mappingData)
{
if (isCommand())
{
switch (getCmd())
{
case CMD_AUTO:
case CMD_ON:
return itemCmd().Int((uint32_t)3);
case CMD_OFF:
return itemCmd().Int((uint32_t)0);
case CMD_FAN:
return itemCmd().Int((uint32_t)1);
case CMD_HEAT:
return itemCmd().Int((uint32_t)2);
return 0;
case CMD_LOW:
return itemCmd().Int((uint32_t)10);
case CMD_MED:
return itemCmd().Int((uint32_t)128);
case CMD_HIGH:
return itemCmd().Int((uint32_t)255);
default:
return itemCmd().Int((uint32_t)0);
}
int itemCmd::doReverseMapping (aJsonObject *mappingData)
}
return *this;
}
itemCmd itemCmd::doReverseMapping (aJsonObject *mappingData)
{
return 0;
return *this;
}
int itemCmd::doMappingCmd(aJsonObject *mappingData)

View File

@@ -220,8 +220,8 @@ public:
itemCmd setChanType(short chanType);
void debugOut();
int doMapping(aJsonObject *mappingData);
int doReverseMapping (aJsonObject *mappingData);
itemCmd doMapping(aJsonObject *mappingData);
itemCmd doReverseMapping (aJsonObject *mappingData);
int doMappingCmd(aJsonObject *mappingData);
int doReverseMappingCmd (aJsonObject *mappingData);
bool scale100();

View File

@@ -186,11 +186,11 @@ byte getCRC(byte req[], size_t size){
return crc;
}
void SendData(byte req[], size_t size){
void out_AC::SendData(byte req[], size_t size){
AC_Serial.write(req, size - 1);
AC_Serial.write(getCRC(req, size-1));
//AC_Serial.flush();
item->setExt(millisNZ());
debugSerial.print("AirCon<<");
for (int i=0; i < size-1; i++)
{
@@ -485,9 +485,12 @@ int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute)
data[10] = 77;
data[11] = 95;
AC_Serial.flush();
uint32_t ts=item->getExt();
while (ts && !isTimeOver(ts,millis(),100)) yield();
SendData(data, sizeof(data)/sizeof(byte));
//InsertData(data, sizeof(data)/sizeof(byte));
//AC_Serial.flush();
//item->setExt(millisNZ());
return 1;
}

View File

@@ -36,5 +36,6 @@ public:
protected:
void InsertData(byte data[], size_t size);
void SendData(byte req[], size_t size);
};
#endif

View File

@@ -423,15 +423,12 @@ int out_Modbus::sendModbus(char * paramName, int32_t value, uint8_t regType)
switch(regType) {
case PAR_U16:
//res = node.writeSingleRegister(regObj->valueint,value);
//break;
case PAR_I16:
case PAR_TENS:
case PAR_100:
res = node.writeSingleRegister(regObj->valueint,value);
break;
break;
case PAR_I32:
case PAR_U32:
@@ -440,11 +437,12 @@ int out_Modbus::sendModbus(char * paramName, int32_t value, uint8_t regType)
break;
case PAR_U8L:
case PAR_I8L:
res = node.writeSingleRegister(regObj->valueint,value & 0xFF);
break;
case PAR_U8H:
case PAR_I8H:
res = node.writeSingleRegister(regObj->valueint,(value & 0xFFFF)>> 8);
break;
}
@@ -484,6 +482,7 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
case 0: //fault
execObj->subtype |= MB_SEND_ERROR;
errorSerial<<F("MBus ")<<execObj->name<<F(" send error")<<endl;
if ((execObj->subtype & 3) != MB_SEND_ATTEMPTS) execObj->subtype++;
break;
default: //param not found
errorSerial<<F("MBus param ")<<execObj->name<<F(" not found")<<endl;
@@ -507,6 +506,7 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
while (execObj && execObj->type == aJson_Object)
{
if (execObj->subtype & MB_SEND_ERROR) execObj->subtype&=~ MB_SEND_ERROR;
if ((execObj->subtype & 0x3) >= MB_SEND_ATTEMPTS) execObj->subtype&=~ MB_NEED_SEND;
execObj=execObj->next;
}
}
@@ -545,68 +545,39 @@ int out_Modbus::getChanType()
return CH_MBUS;
}
//!Control unified Modbus item
// Priority of selection sub-items control to:
// 1. if defined standard suffix Code inside cmd
// 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::sendItemCmd(aJsonObject *templateParamObj, itemCmd cmd)
{
int suffixCode = cmd.getSuffix();
aJsonObject *templateParamObj = NULL;
short mappedCmdVal = 0;
char * suffixStr = subItem;
// trying to find parameter in template with name == subItem (NB!! standard suffixes dint working here)
if (subItem && strlen (subItem) && store) templateParamObj = aJson.getObjectItem(store->parameters, subItem);
if (!templateParamObj && store)
{
// Fallback - Trying to find template parameter where id == suffixCode
templateParamObj = store->parameters->child;
while (templateParamObj)
{
//aJsonObject *regObj = aJson.getObjectItem(paramObj, "reg");
aJsonObject *idObj = aJson.getObjectItem(templateParamObj, "id");
if (idObj->type==aJson_Int && idObj->valueint == suffixCode)
{
suffixStr=templateParamObj->name;
break;
}
// aJsonObject *mapObj = aJson.getObjectItem(templateParamObj, "mapcmd");
// if (mapObj && (mappedCmdVal = cmd.doReverseMappingCmd(mapObj))) break;
templateParamObj=templateParamObj->next;
}
}
if (templateParamObj)
{
int suffixCode = cmd.getSuffix();
//bool isCommand = cmd.isCommand();
if (!suffixCode) return 0;
char *suffixStr =templateParamObj->name;
// We have find template for suffix or suffixCode
long Value = 0;
int8_t regType = PAR_I16;
aJsonObject * typeObj = aJson.getObjectItem(templateParamObj, "type");
aJsonObject * mapObj = aJson.getObjectItem(templateParamObj, "map");
if (typeObj && typeObj->type == aJson_String) regType=str2regSize(typeObj->valuestring);
switch(regType) {
case PAR_I16:
case PAR_U16:
case PAR_I32:
case PAR_U32:
case PAR_U8L:
case PAR_U8H:
Value=cmd.getInt();
case PAR_I8H:
case PAR_I8L:
Value=cmd.doMapping(mapObj).getInt();
break;
case PAR_TENS:
Value=cmd.getTens();
Value=cmd.doMapping(mapObj).getTens();
break;
case PAR_100:
Value=cmd.getTens_raw()*(100/TENS_BASE);
Value=cmd.doMapping(mapObj).getTens_raw()*(100/TENS_BASE);
}
debugSerial<<F("MB suffix:")<<suffixStr<< F(" Val: ")<<Value<<endl;
@@ -643,49 +614,52 @@ if (itemParametersObj && itemParametersObj->type ==aJson_Object)
}
}
}
return 1;
}
else errorSerial<<F("No template for ")<<subItem<<F("/")<<suffixCode<<endl;
if (cmd.isCommand() && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it
switch(suffixCode)
{
case S_NOTFOUND:
// turn on and set
toExecute = true;
debugSerial<<F("Forced execution");
case S_SET:
//case S_ESET:
if (!cmd.isValue()) return 0;
//TODO
return 1;
//break;
case S_CMD:
switch (cmd.getCmd())
{
case CMD_ON:
return 1;
case CMD_OFF:
return 1;
default:
debugSerial<<F("Unknown cmd ")<<cmd.getCmd()<<endl;
} //switch cmd
default:
debugSerial<<F("Unknown suffix ")<<suffixCode<<endl;
} //switch suffix
return 0;
else return 0;
}
//!Control unified Modbus item
// Priority of selection sub-items control to:
// 1. if defined standard suffix Code inside cmd
// 2. custom textual subItem
// 3. non-standard numeric suffix Code equal param id
int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute)
{
if (!store) return -1;
int suffixCode = cmd.getSuffix();
aJsonObject *templateParamObj = NULL;
int res = -1;
// trying to find parameter in template with name == subItem (NB!! standard suffixes dint working here)
if (subItem && strlen (subItem))
{
templateParamObj = aJson.getObjectItem(store->parameters, subItem);
res= sendItemCmd(templateParamObj,cmd);
}
else
// No subitem, trying to find suffix with root item - (Trying to find template parameter where id == suffixCode)
{
templateParamObj = store->parameters->child;
bool suffixFinded = false;
while (templateParamObj)
{
aJsonObject *idObj = aJson.getObjectItem(templateParamObj, "id");
if (idObj->type==aJson_Int && idObj->valueint == suffixCode)
{
res= sendItemCmd(templateParamObj,cmd);
suffixFinded = true;
}
templateParamObj=templateParamObj->next;
}
if (!suffixFinded) errorSerial<<F("No template for ")<<subItem<<F(" or suffix ")<<suffixCode<<endl;
}
return res;
}
#endif

View File

@@ -22,8 +22,9 @@ public:
aJsonObject * parameters;
};
#define MB_NEED_SEND 1
#define MB_SEND_ERROR 2
#define MB_NEED_SEND 8
#define MB_SEND_ERROR 4
#define MB_SEND_ATTEMPTS 3
class out_Modbus : public abstractOut {
@@ -46,5 +47,6 @@ protected:
void pollModbus(aJsonObject * reg, int regType);
void initLine();
int sendModbus(char * paramName, int32_t value, uint8_t regType);
int sendItemCmd(aJsonObject *templateParamObj, itemCmd cmd);
};
#endif

View File

@@ -10,7 +10,7 @@
class out_pwm : public colorChannel {
public:
out_pwm(Item * _item):colorChannel(_item){};
out_pwm(Item * _item):colorChannel(_item){numChannels=0;};
int Setup() override;
int Stop() override;
int Status() override;

View File

@@ -142,7 +142,7 @@ itemCmd getNumber(char **chan) {
}
}
if (!fractlen) val.Int(atol(*chan));
if (!fractlen) val.Int((int32_t) atol(*chan));
else if (fractlen<=TENS_FRACT_LEN && intlen+TENS_FRACT_LEN<=9)
{
long intpart = atol(*chan);
@@ -162,7 +162,10 @@ itemCmd getNumber(char **chan) {
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
unsigned long freeRam ()
{return system_get_free_heap_size();}
{
return esp_get_free_heap_size();//heap_caps_get_free_size();
//return system_get_free_heap_size();
}
#endif
#if defined(__AVR__)

View File

@@ -1,2 +1,2 @@
#!/usr/bin/env bash
sed -i -- 's/void USART0_Handler(void)/void USART0_Handler(void ) __attribute__((weak)); void USART0_Handler(void )/g' ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/variant.cpp
sed -i -- 's/void USART0_Handler(void)/void USART0_Handler(void ) __attribute__((weak)); void USART0_Handler(void )/g' ~/.platformio/packages/framework-arduino-sam/variants/arduino_due_x/variant.cpp