mirror of https://github.com/arendst/Tasmota.git
Add (S)SerialSend features
* Fix mDNS addService (#4938, #4951) * Add (S)SerialSend3 escape sequence \x to allow hexadecimal byte value (#3560, #4947) * Add SerialBridge command SSerialSend5 <hexdata>
This commit is contained in:
parent
be23f905ae
commit
e7e378f463
|
@ -1,7 +1,9 @@
|
|||
/* 6.4.1.9 20190115
|
||||
* Add support for Mi LED Desk Lamp with rotary switch (#4887)
|
||||
* Fix mDNS addService (#4938)
|
||||
* Fix mDNS addService (#4938, #4951)
|
||||
* Fix allowable MAX_RULE_VARS to 16 (#4933)
|
||||
* Add (S)SerialSend3 escape sequence \x to allow hexadecimal byte value (#3560, #4947)
|
||||
* Add SerialBridge command SSerialSend5 <hexdata>
|
||||
*
|
||||
* 6.4.1.8 20190107
|
||||
* Change sonoff_template.h layout regarding optional module flags like ADC0
|
||||
|
|
|
@ -1051,7 +1051,7 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
|||
Serial.printf("%s", Unescape(dataBuf, &dat_len)); // "Hello\f"
|
||||
}
|
||||
else if (5 == index) {
|
||||
SerialSendRaw(RemoveSpace(dataBuf)); // "AA004566"
|
||||
SerialSendRaw(RemoveSpace(dataBuf)); // "AA004566" as hex values
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
|
||||
}
|
||||
|
|
|
@ -210,10 +210,12 @@ char* Unescape(char* buffer, uint16_t* size)
|
|||
{
|
||||
uint8_t* read = (uint8_t*)buffer;
|
||||
uint8_t* write = (uint8_t*)buffer;
|
||||
uint16_t start_size = *size;
|
||||
uint16_t end_size = *size;
|
||||
int16_t start_size = *size;
|
||||
int16_t end_size = *size;
|
||||
uint8_t che = 0;
|
||||
|
||||
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size);
|
||||
|
||||
while (start_size > 0) {
|
||||
uint8_t ch = *read++;
|
||||
start_size--;
|
||||
|
@ -235,6 +237,14 @@ char* Unescape(char* buffer, uint16_t* size)
|
|||
case 's': che = ' '; break; // 20 Space
|
||||
case 't': che = '\t'; break; // 09 Horizontal tab
|
||||
case 'v': che = '\v'; break; // 0B Vertical tab
|
||||
case 'x': {
|
||||
uint8_t* start = read;
|
||||
che = (uint8_t)strtol((const char*)read, (char**)&read, 16);
|
||||
start_size -= (uint16_t)(read - start);
|
||||
end_size -= (uint16_t)(read - start);
|
||||
break;
|
||||
}
|
||||
case '"': che = '\"'; break; // 22 Quotation mark
|
||||
// case '?': che = '\?'; break; // 3F Question mark
|
||||
default : {
|
||||
che = chi;
|
||||
|
@ -247,6 +257,9 @@ char* Unescape(char* buffer, uint16_t* size)
|
|||
}
|
||||
}
|
||||
*size = end_size;
|
||||
|
||||
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -511,7 +524,7 @@ void ModuleGpios(myio *gp)
|
|||
memcpy_P(&src, &kModules[Settings.module].gp, sizeof(mycfgio));
|
||||
// 11 85 00 85 85 00 00 00 15 38 85 00 00 81
|
||||
|
||||
// AddLogSerial(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
|
||||
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)&src, sizeof(mycfgio));
|
||||
|
||||
for (uint8_t i = 0; i < sizeof(mycfgio); i++) {
|
||||
if (i < 6) {
|
||||
|
@ -526,7 +539,7 @@ void ModuleGpios(myio *gp)
|
|||
}
|
||||
// 11 85 00 85 85 00 00 00 00 00 00 00 15 38 85 00 00 81
|
||||
|
||||
// AddLogSerial(LOG_LEVEL_DEBUG, (uint8_t *)gp, sizeof(myio));
|
||||
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t *)gp, sizeof(myio));
|
||||
}
|
||||
|
||||
gpio_flag ModuleFlag()
|
||||
|
@ -1197,9 +1210,9 @@ void AddLog_P(byte loglevel, const char *formatP, const char *formatP2)
|
|||
AddLog(loglevel);
|
||||
}
|
||||
|
||||
void AddLogSerial(byte loglevel, uint8_t *buffer, int count)
|
||||
void AddLogBuffer(byte loglevel, uint8_t *buffer, int count)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_RECEIVED));
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("DMP:"));
|
||||
for (int i = 0; i < count; i++) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, *(buffer++));
|
||||
}
|
||||
|
@ -1208,7 +1221,7 @@ void AddLogSerial(byte loglevel, uint8_t *buffer, int count)
|
|||
|
||||
void AddLogSerial(byte loglevel)
|
||||
{
|
||||
AddLogSerial(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
|
||||
AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter);
|
||||
}
|
||||
|
||||
void AddLogMissed(char *sensor, uint8_t misses)
|
||||
|
|
|
@ -99,18 +99,34 @@ boolean SerialBridgeCommand(void)
|
|||
if (-1 == command_code) {
|
||||
serviced = false; // Unknown command
|
||||
}
|
||||
else if ((CMND_SSERIALSEND == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 3)) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
else if ((CMND_SSERIALSEND == command_code) && (XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
|
||||
if (XdrvMailbox.data_len > 0) { // "Hello Tiger\n"
|
||||
if (1 == XdrvMailbox.index) {
|
||||
SerialBridgeSerial->write(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||
SerialBridgeSerial->write("\n");
|
||||
}
|
||||
else if (2 == XdrvMailbox.index) {
|
||||
else if ((2 == XdrvMailbox.index) || (4 == XdrvMailbox.index)) { // "Hello Tiger" or "A0"
|
||||
SerialBridgeSerial->write(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||
}
|
||||
else if (3 == XdrvMailbox.index) {
|
||||
else if (3 == XdrvMailbox.index) { // "Hello\f"
|
||||
SerialBridgeSerial->write(Unescape(XdrvMailbox.data, &XdrvMailbox.data_len), XdrvMailbox.data_len);
|
||||
}
|
||||
else if (5 == XdrvMailbox.index) { // "AA004566" as hex values
|
||||
char *p;
|
||||
char stemp[3];
|
||||
uint8_t code;
|
||||
|
||||
char *codes = RemoveSpace(XdrvMailbox.data);
|
||||
int size = strlen(XdrvMailbox.data);
|
||||
|
||||
while (size > 0) {
|
||||
snprintf(stemp, sizeof(stemp), codes);
|
||||
code = strtol(stemp, &p, 16);
|
||||
SerialBridgeSerial->write(code);
|
||||
size -= 2;
|
||||
codes += 2;
|
||||
}
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_SVALUE, command, D_JSON_DONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ bool PzemRecieve(uint8_t resp, float *data)
|
|||
}
|
||||
}
|
||||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, len);
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, len);
|
||||
|
||||
if (len != sizeof(PZEMCommand)) {
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "Pzem comms timeout"));
|
||||
|
|
|
@ -143,7 +143,7 @@ void McpSend(uint8_t *data)
|
|||
data[0] = MCP_START_FRAME;
|
||||
data[data[1] -1] = McpChecksum(data);
|
||||
|
||||
// AddLogSerial(LOG_LEVEL_DEBUG_MORE, data, data[1]);
|
||||
// AddLogBuffer(LOG_LEVEL_DEBUG_MORE, data, data[1]);
|
||||
|
||||
for (byte i = 0; i < data[1]; i++) {
|
||||
Serial.write(data[i]);
|
||||
|
|
|
@ -46,7 +46,7 @@ void PzemAcEverySecond(void)
|
|||
uint8_t buffer[26];
|
||||
|
||||
uint8_t error = PzemAcModbus->ReceiveBuffer(buffer, 10);
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
|
||||
|
||||
if (error) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "PzemAc response error %d"), error);
|
||||
|
|
|
@ -46,7 +46,7 @@ void PzemDcEverySecond(void)
|
|||
uint8_t buffer[22];
|
||||
|
||||
uint8_t error = PzemDcModbus->ReceiveBuffer(buffer, 8);
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
|
||||
|
||||
if (error) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "PzemDc response error %d"), error);
|
||||
|
|
|
@ -198,7 +198,7 @@ void MhzEverySecond(void)
|
|||
}
|
||||
}
|
||||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, mhz_response, counter);
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, mhz_response, counter);
|
||||
|
||||
if (counter < 9) {
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "MH-Z19 comms timeout"));
|
||||
|
|
|
@ -62,7 +62,7 @@ boolean PmsReadData(void)
|
|||
PmsSerial->readBytes(buffer, 32);
|
||||
PmsSerial->flush(); // Make room for another burst
|
||||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, buffer, 32);
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 32);
|
||||
|
||||
// get checksum ready
|
||||
for (uint8_t i = 0; i < 30; i++) {
|
||||
|
|
|
@ -108,7 +108,7 @@ bool NovaSdsCommand(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint16_t sensor
|
|||
|
||||
// read rest (9 of 10 bytes) of message
|
||||
NovaSdsSerial->readBytes(&recbuf[1], 9);
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, recbuf, sizeof(recbuf));
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, recbuf, sizeof(recbuf));
|
||||
|
||||
if ( NULL != buffer ) {
|
||||
// return data to buffer
|
||||
|
|
|
@ -158,7 +158,7 @@ void AzEverySecond(void)
|
|||
}
|
||||
} while(((millis() - start) < AZ_READ_TIMEOUT) && (counter < sizeof(az_response)) && !az_received);
|
||||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, az_response, counter);
|
||||
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, az_response, counter);
|
||||
|
||||
if (!az_received) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "AZ7798 comms timeout"));
|
||||
|
|
Loading…
Reference in New Issue