mirror of https://github.com/arendst/Tasmota.git
Small refactor adding define USE_SERIAL_BRIDGE_TEE
This commit is contained in:
parent
44ce19f26f
commit
8a425c40c9
|
@ -25,6 +25,8 @@
|
||||||
#define XDRV_08 8
|
#define XDRV_08 8
|
||||||
#define HARDWARE_FALLBACK 2
|
#define HARDWARE_FALLBACK 2
|
||||||
|
|
||||||
|
#define USE_SERIAL_BRIDGE_TEE
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
const uint16_t SERIAL_BRIDGE_BUFFER_SIZE = 130;
|
const uint16_t SERIAL_BRIDGE_BUFFER_SIZE = 130;
|
||||||
#else
|
#else
|
||||||
|
@ -63,6 +65,7 @@ void SetSSerialConfig(uint32_t serial_config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialBridgeLog(const char *mxtime, const char *log_data, const char *log_data_payload, const char *log_data_retained) {
|
void SerialBridgeLog(const char *mxtime, const char *log_data, const char *log_data_payload, const char *log_data_retained) {
|
||||||
|
#ifdef USE_SERIAL_BRIDGE_TEE
|
||||||
if (Settings->sbflag1.serbridge_console && serial_bridge_buffer) {
|
if (Settings->sbflag1.serbridge_console && serial_bridge_buffer) {
|
||||||
char empty[2] = { 0 };
|
char empty[2] = { 0 };
|
||||||
if (!log_data) { log_data = empty; }
|
if (!log_data) { log_data = empty; }
|
||||||
|
@ -70,6 +73,7 @@ void SerialBridgeLog(const char *mxtime, const char *log_data, const char *log_d
|
||||||
if (!log_data_retained) { log_data_retained = empty; }
|
if (!log_data_retained) { log_data_retained = empty; }
|
||||||
SerialBridgeSerial->printf("%s%s%s%s\r\n", mxtime, log_data, log_data_payload, log_data_retained);
|
SerialBridgeSerial->printf("%s%s%s%s\r\n", mxtime, log_data, log_data_payload, log_data_retained);
|
||||||
}
|
}
|
||||||
|
#endif // USE_SERIAL_BRIDGE_TEE
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
@ -79,6 +83,7 @@ void SerialBridgeInput(void) {
|
||||||
yield();
|
yield();
|
||||||
uint8_t serial_in_byte = SerialBridgeSerial->read();
|
uint8_t serial_in_byte = SerialBridgeSerial->read();
|
||||||
|
|
||||||
|
#ifdef USE_SERIAL_BRIDGE_TEE
|
||||||
if (Settings->sbflag1.serbridge_console) {
|
if (Settings->sbflag1.serbridge_console) {
|
||||||
static bool serial_bridge_overrun = false;
|
static bool serial_bridge_overrun = false;
|
||||||
|
|
||||||
|
@ -104,6 +109,7 @@ void SerialBridgeInput(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#endif // USE_SERIAL_BRIDGE_TEE
|
||||||
serial_bridge_raw = (254 == Settings->serial_delimiter);
|
serial_bridge_raw = (254 == Settings->serial_delimiter);
|
||||||
if ((serial_in_byte > 127) && !serial_bridge_raw) { // Discard binary data above 127 if no raw reception allowed
|
if ((serial_in_byte > 127) && !serial_bridge_raw) { // Discard binary data above 127 if no raw reception allowed
|
||||||
serial_bridge_in_byte_counter = 0;
|
serial_bridge_in_byte_counter = 0;
|
||||||
|
@ -128,10 +134,17 @@ void SerialBridgeInput(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serial_bridge_polling_window = millis(); // Wait for more data
|
serial_bridge_polling_window = millis(); // Wait for more data
|
||||||
|
#ifdef USE_SERIAL_BRIDGE_TEE
|
||||||
}
|
}
|
||||||
|
#endif // USE_SERIAL_BRIDGE_TEE
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings->sbflag1.serbridge_console) {
|
#ifdef USE_SERIAL_BRIDGE_TEE
|
||||||
|
if (Settings->sbflag1.serbridge_console) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif // USE_SERIAL_BRIDGE_TEE
|
||||||
|
|
||||||
if (serial_bridge_in_byte_counter && (millis() > (serial_bridge_polling_window + SERIAL_POLLING))) {
|
if (serial_bridge_in_byte_counter && (millis() > (serial_bridge_polling_window + SERIAL_POLLING))) {
|
||||||
serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // Serial data completed
|
serial_bridge_buffer[serial_bridge_in_byte_counter] = 0; // Serial data completed
|
||||||
bool assume_json = (!serial_bridge_raw && (serial_bridge_buffer[0] == '{'));
|
bool assume_json = (!serial_bridge_raw && (serial_bridge_buffer[0] == '{'));
|
||||||
|
@ -154,7 +167,6 @@ void SerialBridgeInput(void) {
|
||||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_SSERIALRECEIVED));
|
||||||
serial_bridge_in_byte_counter = 0;
|
serial_bridge_in_byte_counter = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
@ -221,12 +233,14 @@ void CmndSSerialSend(void) {
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_SERIAL_BRIDGE_TEE
|
||||||
if (9 == XdrvMailbox.index) {
|
if (9 == XdrvMailbox.index) {
|
||||||
if (XdrvMailbox.payload >= 0) {
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
|
||||||
Settings->sbflag1.serbridge_console = XdrvMailbox.payload &1;
|
Settings->sbflag1.serbridge_console = XdrvMailbox.payload &1;
|
||||||
}
|
}
|
||||||
ResponseCmndStateText(Settings->sbflag1.serbridge_console);
|
ResponseCmndStateText(Settings->sbflag1.serbridge_console);
|
||||||
}
|
}
|
||||||
|
#endif // USE_SERIAL_BRIDGE_TEE
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndSBaudrate(void) {
|
void CmndSBaudrate(void) {
|
||||||
|
|
Loading…
Reference in New Issue