beautify some traces
This commit is contained in:
@@ -141,8 +141,8 @@ class Talent(Message):
|
|||||||
|
|
||||||
def send_modbus_cb(self, modbus_pdu: bytearray, log_lvl: int, state: str):
|
def send_modbus_cb(self, modbus_pdu: bytearray, log_lvl: int, state: str):
|
||||||
if self.state != self.STATE_UP:
|
if self.state != self.STATE_UP:
|
||||||
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
|
logger.warn(f'[{self.node_id}] ignore MODBUS cmd,'
|
||||||
' as the state is not UP')
|
' cause the state is not UP anymore')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.__build_header(0x70, 0x77)
|
self.__build_header(0x70, 0x77)
|
||||||
@@ -158,8 +158,8 @@ class Talent(Message):
|
|||||||
|
|
||||||
async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None:
|
async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None:
|
||||||
if self.state != self.STATE_UP:
|
if self.state != self.STATE_UP:
|
||||||
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
|
logger.log(log_lvl, f'[{self.node_id}] ignore MODBUS cmd,'
|
||||||
' as the state is not UP')
|
' as the state is not UP')
|
||||||
return
|
return
|
||||||
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)
|
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)
|
||||||
|
|
||||||
|
|||||||
@@ -339,8 +339,8 @@ class SolarmanV5(Message):
|
|||||||
|
|
||||||
def send_modbus_cb(self, pdu: bytearray, log_lvl: int, state: str):
|
def send_modbus_cb(self, pdu: bytearray, log_lvl: int, state: str):
|
||||||
if self.state != self.STATE_UP:
|
if self.state != self.STATE_UP:
|
||||||
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
|
logger.warn(f'[{self.node_id}] ignore MODBUS cmd,'
|
||||||
' as the state is not UP')
|
' cause the state is not UP anymore')
|
||||||
return
|
return
|
||||||
self.__build_header(0x4510)
|
self.__build_header(0x4510)
|
||||||
self._send_buffer += struct.pack('<BHLLL', self.MB_RTU_CMD,
|
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:
|
async def send_modbus_cmd(self, func, addr, val, log_lvl) -> None:
|
||||||
if self.state != self.STATE_UP:
|
if self.state != self.STATE_UP:
|
||||||
logger.debug(f'[{self.node_id}] ignore MODBUS cmd,'
|
logger.log(log_lvl, f'[{self.node_id}] ignore MODBUS cmd,'
|
||||||
' as the state is not UP')
|
' as the state is not UP')
|
||||||
return
|
return
|
||||||
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)
|
self.mb.build_msg(Modbus.INV_ADDR, func, addr, val, log_lvl)
|
||||||
|
|
||||||
|
|||||||
@@ -172,23 +172,25 @@ class Modbus():
|
|||||||
self.err = 5
|
self.err = 5
|
||||||
return
|
return
|
||||||
if not self.__check_crc(buf):
|
if not self.__check_crc(buf):
|
||||||
logger.error('Modbus resp: CRC error')
|
logger.error(f'[{node_id}] Modbus resp: CRC error')
|
||||||
self.err = 1
|
self.err = 1
|
||||||
return
|
return
|
||||||
if buf[0] != self.last_addr:
|
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
|
self.err = 2
|
||||||
return
|
return
|
||||||
fcode = buf[1]
|
fcode = buf[1]
|
||||||
if fcode != self.last_fcode:
|
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
|
self.err = 3
|
||||||
return
|
return
|
||||||
if self.last_addr == self.INV_ADDR and \
|
if self.last_addr == self.INV_ADDR and \
|
||||||
(fcode == 3 or fcode == 4):
|
(fcode == 3 or fcode == 4):
|
||||||
elmlen = buf[2] >> 1
|
elmlen = buf[2] >> 1
|
||||||
if elmlen != self.last_len:
|
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
|
self.err = 4
|
||||||
return
|
return
|
||||||
first_reg = self.last_reg # save last_reg before sending next pdu
|
first_reg = self.last_reg # save last_reg before sending next pdu
|
||||||
|
|||||||
@@ -148,10 +148,10 @@ class Mqtt(metaclass=Singleton):
|
|||||||
node_id = topic.split('/')[1] + '/'
|
node_id = topic.split('/')[1] + '/'
|
||||||
# refactor into a loop over a table
|
# refactor into a loop over a table
|
||||||
payload = message.payload.decode("UTF-8")
|
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:
|
for m in Message:
|
||||||
if m.server_side and (m.node_id == node_id):
|
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)
|
fnc = getattr(m, "send_modbus_cmd", None)
|
||||||
res = payload.split(',')
|
res = payload.split(',')
|
||||||
if params != len(res):
|
if params != len(res):
|
||||||
|
|||||||
Reference in New Issue
Block a user