Files
IoTManager/src/BufferExecute.cpp

160 lines
5.0 KiB
C++
Raw Normal View History

2020-09-04 18:58:03 +03:00
#include "BufferExecute.h"
2020-11-15 22:39:38 +03:00
#include "Global.h"
2020-12-17 22:48:20 +01:00
#include "SoftUART.h"
//
2020-11-15 01:44:25 +03:00
#include "items/vButtonOut.h"
#include "items/vCountDown.h"
#include "items/vImpulsOut.h"
2020-11-17 01:01:42 +03:00
#include "items/vInOutput.h"
#include "items/vLogging.h"
#include "items/vPwmOut.h"
2020-12-21 01:46:11 +01:00
#include "items/vSensorAnalog.h"
#include "items/vSensorBme280.h"
#include "items/vSensorBmp280.h"
#include "items/vSensorDallas.h"
#include "items/vSensorDht.h"
#include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h"
#include "items/vSensorCcs811.h"
2020-09-04 18:58:03 +03:00
2020-11-02 01:21:51 +03:00
void loopCmdAdd(const String& cmdStr) {
2020-12-17 22:48:20 +01:00
if (cmdStr.endsWith(",")) {
orderBuf += cmdStr;
#ifdef uartEnable
2020-12-17 22:48:20 +01:00
if (jsonReadBool(configSetupJson, "uart")) {
if (jsonReadBool(configSetupJson, "uartEvents")) {
if (myUART) {
myUART->print(cmdStr);
SerialPrint("I", "<=UART", cmdStr);
}
}
}
#endif
2020-09-04 18:58:03 +03:00
}
}
2020-11-02 01:21:51 +03:00
void fileCmdExecute(const String& filename) {
2020-10-10 12:04:40 +03:00
String cmdStr = readFile(filename, 4096);
2020-09-04 18:58:03 +03:00
csvCmdExecute(cmdStr);
}
2020-11-02 01:21:51 +03:00
void csvCmdExecute(String& cmdStr) {
2020-09-04 18:58:03 +03:00
cmdStr.replace(";", " ");
cmdStr += "\r\n";
cmdStr.replace("\r\n", "\n");
cmdStr.replace("\r", "\n");
int count = 0;
while (cmdStr.length()) {
String buf = selectToMarker(cmdStr, "\n");
2020-11-04 23:48:21 +03:00
2020-10-20 22:55:45 +03:00
buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса
2020-11-04 23:48:21 +03:00
2020-09-04 18:58:03 +03:00
count++;
2020-11-04 23:48:21 +03:00
if (count > 1) {
SerialPrint("I", "Items", buf);
String order = selectToMarker(buf, " "); //отсечка самой команды
2020-11-04 23:48:21 +03:00
if (order == F("button-out")) {
sCmd.addCommand(order.c_str(), buttonOut);
}
2020-12-16 13:59:01 +01:00
#ifdef PwmOutEnable
2020-11-04 23:48:21 +03:00
else if (order == F("pwm-out")) {
sCmd.addCommand(order.c_str(), pwmOut);
}
2020-12-16 13:59:01 +01:00
#endif
2020-11-04 23:48:21 +03:00
else if (order == F("button-in")) {
sCmd.addCommand(order.c_str(), buttonIn);
} else if (order == F("inoutput")) {
2020-11-17 01:01:42 +03:00
sCmd.addCommand(order.c_str(), inOutput);
} else if (order == F("analog-adc")) {
2020-11-04 23:48:21 +03:00
sCmd.addCommand(order.c_str(), analogAdc);
} else if (order == F("ultrasonic-cm")) {
2020-12-06 00:34:30 +03:00
sCmd.addCommand(order.c_str(), ultrasonic);
} else if (order == F("dallas-temp")) {
2020-11-04 23:48:21 +03:00
sCmd.addCommand(order.c_str(), dallas);
}
2020-12-16 13:59:01 +01:00
#ifdef SensorDhtEnabled
2020-12-24 01:41:15 +01:00
else if (order == F("dht")) {
sCmd.addCommand(order.c_str(), dhtSensor);
2020-11-04 23:48:21 +03:00
}
2020-12-16 13:59:01 +01:00
#endif
#ifdef SensorBme280Enabled
else if (order == F("bme280")) {
sCmd.addCommand(order.c_str(), bme280Sensor);
2020-11-04 23:48:21 +03:00
}
2020-12-16 13:59:01 +01:00
#endif
else if (order == F("ccs811")) {
sCmd.addCommand(order.c_str(), ccs811Sensor);
}
else if (order == F("bmp280")) {
sCmd.addCommand(order.c_str(), bmp280Sensor);
} else if (order == F("uptime")) {
2021-01-04 16:56:20 +01:00
sCmd.addCommand(order.c_str(), uptimeSensor);
} else if (order == F("logging")) {
2020-11-04 23:48:21 +03:00
sCmd.addCommand(order.c_str(), logging);
} else if (order == F("impuls-out")) {
2020-11-04 23:48:21 +03:00
sCmd.addCommand(order.c_str(), impuls);
} else if (order == F("count-down")) {
2020-11-18 03:25:05 +03:00
sCmd.addCommand(order.c_str(), countDown);
}
2020-11-19 04:14:52 +03:00
2020-11-04 23:48:21 +03:00
sCmd.readStr(buf);
}
2020-09-04 18:58:03 +03:00
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
}
}
2020-11-02 01:21:51 +03:00
void spaceCmdExecute(String& cmdStr) {
2020-09-04 18:58:03 +03:00
cmdStr += "\r\n";
cmdStr.replace("\r\n", "\n");
cmdStr.replace("\r", "\n");
while (cmdStr.length()) {
String buf = selectToMarker(cmdStr, "\n");
sCmd.readStr(buf);
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
}
}
void loopCmdExecute() {
if (orderBuf.length()) {
String tmp = selectToMarker(orderBuf, ","); //выделяем первую команду rel 5 1,
2020-10-20 22:55:45 +03:00
SerialPrint("I", "CMD", "do: " + tmp);
sCmd.readStr(tmp); //выполняем
2020-09-04 18:58:03 +03:00
orderBuf = deleteBeforeDelimiter(orderBuf, ","); //осекаем
}
}
2020-11-02 15:20:04 +03:00
void addKey(String& key, String& keyNumberTable, int number) {
keyNumberTable += key + " " + String(number) + ",";
2020-11-02 01:21:51 +03:00
}
2020-11-02 15:20:04 +03:00
int getKeyNum(String& key, String& keyNumberTable) {
String keyNumberTableBuf = keyNumberTable;
2020-11-04 23:48:21 +03:00
2020-11-02 01:21:51 +03:00
int number = -1;
while (keyNumberTableBuf.length()) {
String tmp = selectToMarker(keyNumberTableBuf, ",");
String keyIncomming = selectToMarker(tmp, " ");
if (keyIncomming == key) {
number = selectToMarkerLast(tmp, " ").toInt();
}
keyNumberTableBuf = deleteBeforeDelimiter(keyNumberTableBuf, ",");
}
return number;
}
2020-11-19 04:14:52 +03:00
String getValue(String& key) {
String live = jsonReadStr(configLiveJson, key);
String store = jsonReadStr(configStoreJson, key);
if (live != nullptr) {
return live;
} else if (store != nullptr) {
2020-11-19 04:14:52 +03:00
return store;
} else if (store == nullptr && live == nullptr) {
2020-11-19 04:14:52 +03:00
return "no value";
} else {
2020-11-19 04:14:52 +03:00
return "data error";
}
}