beautify some traces

This commit is contained in:
Stefan Allius
2024-06-07 19:27:36 +02:00
parent c59bd16664
commit 0b2631c162
4 changed files with 16 additions and 14 deletions

View File

@@ -141,8 +141,8 @@ class Talent(Message):
def send_modbus_cb(self, modbus_pdu: bytearray, log_lvl: int, state: str):
if self.state != self.STATE_UP:
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
logger.warn(f'[{self.node_id}] ignore MODBUS cmd,'
' cause the state is not UP anymore')
return
self.__build_header(0x70, 0x77)
@@ -158,8 +158,8 @@ class Talent(Message):
async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None:
if self.state != self.STATE_UP:
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
logger.log(log_lvl, f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
return
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)

View File

@@ -339,8 +339,8 @@ class SolarmanV5(Message):
def send_modbus_cb(self, pdu: bytearray, log_lvl: int, state: str):
if self.state != self.STATE_UP:
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
logger.warn(f'[{self.node_id}] ignore MODBUS cmd,'
' cause the state is not UP anymore')
return
self.__build_header(0x4510)
self._send_buffer += struct.pack('<BHLLL', self.MB_RTU_CMD,
@@ -354,8 +354,8 @@ class SolarmanV5(Message):
async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None:
if self.state != self.STATE_UP:
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
logger.log(log_lvl, f'[{self.node_id}] ignore MODBUS cmd,'
' as the state is not UP')
return
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)

View File

@@ -172,23 +172,25 @@ class Modbus():
self.err = 5
return
if not self.__check_crc(buf):
logger.error('Modbus resp: CRC error')
logger.error(f'[{node_id}] Modbus resp: CRC error')
self.err = 1
return
if buf[0] != self.last_addr:
logger.info(f'Modbus resp: Wrong addr {buf[0]}')
logger.info(f'[{node_id}] Modbus resp: Wrong addr {buf[0]}')
self.err = 2
return
fcode = buf[1]
if fcode != self.last_fcode:
logger.info(f'Modbus: Wrong fcode {fcode} != {self.last_fcode}')
logger.info(f'[{node_id}] Modbus: Wrong fcode {fcode}'
f' != {self.last_fcode}')
self.err = 3
return
if self.last_addr == self.INV_ADDR and \
(fcode == 3 or fcode == 4):
elmlen = buf[2] >> 1
if elmlen != self.last_len:
logger.info(f'Modbus: len error {elmlen} != {self.last_len}')
logger.info(f'[{node_id}] Modbus: len error {elmlen}'
f' != {self.last_len}')
self.err = 4
return
first_reg = self.last_reg # save last_reg before sending next pdu

View File

@@ -148,10 +148,10 @@ class Mqtt(metaclass=Singleton):
node_id = topic.split('/')[1] + '/'
# refactor into a loop over a table
payload = message.payload.decode("UTF-8")
logger_mqtt.info(f'InvCnf: {node_id}:{payload}')
logger_mqtt.info(f'MODBUS via MQTT: {topic} = {payload}')
for m in Message:
if m.server_side and (m.node_id == node_id):
logger_mqtt.info(f'Found: {node_id}')
logger_mqtt.debug(f'Found: {node_id}')
fnc = getattr(m, "send_modbus_cmd", None)
res = payload.split(',')
if params != len(res):