Removed logging and changed maximum number of coils/inputs

This commit is contained in:
JeroenSt 2022-08-27 10:54:41 +02:00
parent f57acac48b
commit 728c108294
2 changed files with 11 additions and 4 deletions

View File

@ -25,6 +25,7 @@
extern void AddLog(uint32_t loglevel, PGM_P formatP, ...);
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE};
//#define TASMOTAMODBUSDEBUG
TasmotaModbus::TasmotaModbus(int receive_pin, int transmit_pin) : TasmotaSerial(receive_pin, transmit_pin, 1)
{
@ -135,6 +136,7 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1
frame[framepointer++] = (uint8_t)(crc);
frame[framepointer++] = (uint8_t)(crc >> 8);
#ifdef TASMOTAMODBUSDEBUG
uint8_t *buf;
uint16_t bufsize=(framepointer + 1) * 3;
buf = (uint8_t *)malloc(bufsize);
@ -144,6 +146,7 @@ uint8_t TasmotaModbus::Send(uint8_t device_address, uint8_t function_code, uint1
snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",frame[i]);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Send: %s"), buf);
free(buf);
#endif
flush();
write(frame, framepointer);
@ -181,6 +184,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count, ui
}
}
#ifdef TASMOTAMODBUSDEBUG
// RX Logging
uint8_t *buf;
uint16_t bufsize=(mb_len + 1) * 3;
@ -191,6 +195,7 @@ uint8_t TasmotaModbus::ReceiveBuffer(uint8_t *buffer, uint8_t register_count, ui
snprintf((char *)&buf[i*3], (bufsize-i*3), "%02X ",buffer[i]);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("MBS: Serial Received: %s"), buf);
free(buf);
#endif
if (buffer[1] & 0x80)
{ // 01 84 02 f2 f1

View File

@ -317,6 +317,7 @@ void ModbusBridgeHandle(void)
modbusBridge.byteCount = 0;
ModbusBridgeError errorcode = ModbusBridgeError::noerror;
if (modbusBridge.deviceAddress == 0)
{
#ifdef USE_MODBUS_BRIDGE_TCP
@ -682,12 +683,10 @@ void ModbusTCPHandle(void)
if (dataPointer % 2 == 0)
{
writeData[dataPointer / 2] = (uint16_t)(((uint16_t)modbusBridgeTCP.tcp_buf[dataStartByte + dataPointer]) << 8);
AddLog(LOG_LEVEL_DEBUG_MORE, "%d=%04X", dataPointer/2, writeData[dataPointer/2]);
}
else
{
writeData[dataPointer / 2] |= ((uint16_t)modbusBridgeTCP.tcp_buf[dataStartByte + dataPointer]);
AddLog(LOG_LEVEL_DEBUG_MORE, "%d=%04X", dataPointer/2, writeData[dataPointer/2]);
}
}
}
@ -806,7 +805,10 @@ void CmndModbusBridgeSend(void)
}
// Prevent buffer overflow due to usage of to many registers
if (modbusBridge.dataCount > MBR_MAX_REGISTERS)
if ((!bitMode) && (modbusBridge.dataCount > MBR_MAX_REGISTERS))
errorcode = ModbusBridgeError::wrongcount;
if ((bitMode) && (modbusBridge.dataCount > MBR_MAX_REGISTERS * 8))
errorcode = ModbusBridgeError::wrongcount;
// Get Json data for writing