mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
add some protection on tcpbridge
This commit is contained in:
parent
a67898e8b3
commit
2edb39d556
@ -104,7 +104,7 @@ void TCPLoop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buf_len > 0) {
|
if (buf_len > 0) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "from MCU: %*_H"), buf_len, tcp_buf);
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_TCP "from MCU: %*_H"), buf_len, tcp_buf);
|
||||||
|
|
||||||
for (uint32_t i=0; i<nitems(client_tcp); i++) {
|
for (uint32_t i=0; i<nitems(client_tcp); i++) {
|
||||||
WiFiClient &client = client_tcp[i];
|
WiFiClient &client = client_tcp[i];
|
||||||
@ -124,7 +124,7 @@ void TCPLoop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buf_len > 0) {
|
if (buf_len > 0) {
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "to MCU/%d: %*_H"), i+1, buf_len, tcp_buf);
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_TCP "to MCU/%d: %*_H"), i+1, buf_len, tcp_buf);
|
||||||
TCPSerial->write(tcp_buf, buf_len);
|
TCPSerial->write(tcp_buf, buf_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,10 +144,16 @@ void TCPInit(void) {
|
|||||||
|
|
||||||
if (!Settings->tcp_baudrate) { Settings->tcp_baudrate = 115200 / 1200; }
|
if (!Settings->tcp_baudrate) { Settings->tcp_baudrate = 115200 / 1200; }
|
||||||
TCPSerial = new TasmotaSerial(Pin(GPIO_TCP_RX), Pin(GPIO_TCP_TX), TasmotaGlobal.seriallog_level ? 1 : 2, 0, TCP_BRIDGE_BUF_SIZE); // set a receive buffer of 256 bytes
|
TCPSerial = new TasmotaSerial(Pin(GPIO_TCP_RX), Pin(GPIO_TCP_TX), TasmotaGlobal.seriallog_level ? 1 : 2, 0, TCP_BRIDGE_BUF_SIZE); // set a receive buffer of 256 bytes
|
||||||
TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config));
|
if (TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config))) {
|
||||||
if (TCPSerial->hardwareSerial()) {
|
if (TCPSerial->hardwareSerial()) {
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
}
|
}
|
||||||
|
#ifdef ESP32
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "using hardserial %d"), TCPSerial->getUart());
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "failed init serial"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,20 +203,30 @@ void CmndTCPStart(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmndTCPBaudrate(void) {
|
void CmndTCPBaudrate(void) {
|
||||||
|
if (!TCPSerial) { return; }
|
||||||
|
|
||||||
if ((XdrvMailbox.payload >= 1200) && (XdrvMailbox.payload <= 115200)) {
|
if ((XdrvMailbox.payload >= 1200) && (XdrvMailbox.payload <= 115200)) {
|
||||||
XdrvMailbox.payload /= 1200; // Make it a valid baudrate
|
XdrvMailbox.payload /= 1200; // Make it a valid baudrate
|
||||||
|
if (Settings->tcp_baudrate != XdrvMailbox.payload) {
|
||||||
Settings->tcp_baudrate = XdrvMailbox.payload;
|
Settings->tcp_baudrate = XdrvMailbox.payload;
|
||||||
TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config)); // Reinitialize serial port with new baud rate
|
if (!TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config))) {
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "failed reinit serial"));
|
||||||
|
} // Reinitialize serial port with new baud rate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ResponseCmndNumber(Settings->tcp_baudrate * 1200);
|
ResponseCmndNumber(Settings->tcp_baudrate * 1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CmndTCPConfig(void) {
|
void CmndTCPConfig(void) {
|
||||||
|
if (!TCPSerial) { return; }
|
||||||
|
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
uint8_t serial_config = ParseSerialConfig(XdrvMailbox.data);
|
uint8_t serial_config = ParseSerialConfig(XdrvMailbox.data);
|
||||||
if (serial_config >= 0) {
|
if ((serial_config >= 0) && (Settings->tcp_config != (0x80 | serial_config))) {
|
||||||
Settings->tcp_config = 0x80 | serial_config; // default 0x00 should be 8N1
|
Settings->tcp_config = 0x80 | serial_config; // default 0x00 should be 8N1
|
||||||
TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config)); // Reinitialize serial port with new config
|
if (!TCPSerial->begin(Settings->tcp_baudrate * 1200, ConvertSerialConfig(0x7F & Settings->tcp_config))) {
|
||||||
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_TCP "failed reinit serial"));
|
||||||
|
} // Reinitialize serial port with new config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResponseCmndChar_P(GetSerialConfig(0x7F & Settings->tcp_config).c_str());
|
ResponseCmndChar_P(GetSerialConfig(0x7F & Settings->tcp_config).c_str());
|
||||||
@ -223,6 +239,8 @@ void CmndTCPConfig(void) {
|
|||||||
void CmndTCPConnect(void) {
|
void CmndTCPConnect(void) {
|
||||||
int32_t tcp_port = XdrvMailbox.payload;
|
int32_t tcp_port = XdrvMailbox.payload;
|
||||||
|
|
||||||
|
if (!TCPSerial) { return; }
|
||||||
|
|
||||||
if (ArgC() == 2) {
|
if (ArgC() == 2) {
|
||||||
char sub_string[XdrvMailbox.data_len];
|
char sub_string[XdrvMailbox.data_len];
|
||||||
WiFiClient new_client;
|
WiFiClient new_client;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user