Merge branch 'main' of https://github.com/s-allius/tsun-gen3-proxy into dev-0.9
This commit is contained in:
@@ -22,6 +22,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [0.8.0] - 2024-06-07
|
## [0.8.0] - 2024-06-07
|
||||||
|
|
||||||
|
## [0.8.1] - 2024-06-21
|
||||||
|
|
||||||
|
- Fix MODBUS responses are dropped and not forwarded to the TSUN cloud [#104](https://github.com/s-allius/tsun-gen3-proxy/issues/104)
|
||||||
|
- GEN3: Fix connections losts due MODBUS requests [#102](https://github.com/s-allius/tsun-gen3-proxy/issues/102)
|
||||||
|
|
||||||
|
## [0.8.0] - 2024-06-07
|
||||||
|
|
||||||
- improve logging: add protocol or node_id to connection logs
|
- improve logging: add protocol or node_id to connection logs
|
||||||
- improve logging: log ignored AT+ or MODBUS commands
|
- improve logging: log ignored AT+ or MODBUS commands
|
||||||
- improve tracelog: log level depends on message type and source
|
- improve tracelog: log level depends on message type and source
|
||||||
|
|||||||
@@ -444,7 +444,8 @@ class Talent(Message):
|
|||||||
|
|
||||||
if self.ctrl.is_req():
|
if self.ctrl.is_req():
|
||||||
if self.remoteStream.mb.recv_req(data[hdr_len:],
|
if self.remoteStream.mb.recv_req(data[hdr_len:],
|
||||||
self.msg_forward):
|
self.remoteStream.
|
||||||
|
msg_forward):
|
||||||
self.inc_counter('Modbus_Command')
|
self.inc_counter('Modbus_Command')
|
||||||
else:
|
else:
|
||||||
self.inc_counter('Invalid_Msg_Format')
|
self.inc_counter('Invalid_Msg_Format')
|
||||||
|
|||||||
@@ -504,7 +504,8 @@ class SolarmanV5(Message):
|
|||||||
|
|
||||||
elif ftype == self.MB_RTU_CMD:
|
elif ftype == self.MB_RTU_CMD:
|
||||||
if self.remoteStream.mb.recv_req(data[15:],
|
if self.remoteStream.mb.recv_req(data[15:],
|
||||||
self.__forward_msg()):
|
self.remoteStream.
|
||||||
|
__forward_msg):
|
||||||
self.inc_counter('Modbus_Command')
|
self.inc_counter('Modbus_Command')
|
||||||
else:
|
else:
|
||||||
logger.error('Invalid Modbus Msg')
|
logger.error('Invalid Modbus Msg')
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Schedule:
|
|||||||
fnc = getattr(m, "send_modbus_cmd", None)
|
fnc = getattr(m, "send_modbus_cmd", None)
|
||||||
if callable(fnc):
|
if callable(fnc):
|
||||||
await fnc(Modbus.READ_REGS, 0x3008, 21, logging.DEBUG)
|
await fnc(Modbus.READ_REGS, 0x3008, 21, logging.DEBUG)
|
||||||
if 0 == (cls.count % 30):
|
# if 0 == (cls.count % 30):
|
||||||
# logging.info("Regular Modbus Status request")
|
# # logging.info("Regular Modbus Status request")
|
||||||
await fnc(Modbus.READ_REGS, 0x2007, 2, logging.DEBUG)
|
# await fnc(Modbus.READ_REGS, 0x2007, 2, logging.DEBUG)
|
||||||
cls.count += 1
|
cls.count += 1
|
||||||
|
|||||||
@@ -109,6 +109,9 @@ class MemoryStream(SolarmanV5):
|
|||||||
def get_sn() -> bytes:
|
def get_sn() -> bytes:
|
||||||
return b'\x21\x43\x65\x7b'
|
return b'\x21\x43\x65\x7b'
|
||||||
|
|
||||||
|
def get_sn_int() -> int:
|
||||||
|
return 2070233889
|
||||||
|
|
||||||
def get_inv_no() -> bytes:
|
def get_inv_no() -> bytes:
|
||||||
return b'T170000000000001'
|
return b'T170000000000001'
|
||||||
|
|
||||||
@@ -550,6 +553,15 @@ def MsgModbusCmd():
|
|||||||
msg += b'\x15'
|
msg += b'\x15'
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def MsgModbusCmdFwd():
|
||||||
|
msg = b'\xa5\x17\x00\x10\x45\x01\x00' +get_sn() +b'\x02\xb0\x02'
|
||||||
|
msg += b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x06\x20\x08'
|
||||||
|
msg += b'\x00\x00\x03\xc8'
|
||||||
|
msg += correct_checksum(msg)
|
||||||
|
msg += b'\x15'
|
||||||
|
return msg
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def MsgModbusCmdCrcErr():
|
def MsgModbusCmdCrcErr():
|
||||||
msg = b'\xa5\x17\x00\x10\x45\x03\x02' +get_sn() +b'\x02\xb0\x02'
|
msg = b'\xa5\x17\x00\x10\x45\x03\x02' +get_sn() +b'\x02\xb0\x02'
|
||||||
@@ -1451,9 +1463,11 @@ def test_msg_at_command_rsp2(ConfigTsunInv1, AtCommandRspMsg):
|
|||||||
assert m.db.stat['proxy']['Modbus_Command'] == 0
|
assert m.db.stat['proxy']['Modbus_Command'] == 0
|
||||||
m.close()
|
m.close()
|
||||||
|
|
||||||
def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
|
def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd, MsgModbusCmdFwd):
|
||||||
ConfigTsunInv1
|
ConfigTsunInv1
|
||||||
m = MemoryStream(b'')
|
m = MemoryStream(b'')
|
||||||
|
m.snr = get_sn_int()
|
||||||
|
m.state = m.STATE_UP
|
||||||
c = m.createClientStream(MsgModbusCmd)
|
c = m.createClientStream(MsgModbusCmd)
|
||||||
|
|
||||||
m.db.stat['proxy']['Unknown_Ctrl'] = 0
|
m.db.stat['proxy']['Unknown_Ctrl'] = 0
|
||||||
@@ -1467,8 +1481,9 @@ def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
|
|||||||
assert str(c.seq) == '03:02'
|
assert str(c.seq) == '03:02'
|
||||||
assert c.header_len==11
|
assert c.header_len==11
|
||||||
assert c.data_len==23
|
assert c.data_len==23
|
||||||
assert c._forward_buffer==MsgModbusCmd
|
assert c._forward_buffer==b''
|
||||||
assert c._send_buffer==b''
|
assert c._send_buffer==b''
|
||||||
|
assert m.writer.sent_pdu == MsgModbusCmdFwd
|
||||||
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
|
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
|
||||||
assert m.db.stat['proxy']['AT_Command'] == 0
|
assert m.db.stat['proxy']['AT_Command'] == 0
|
||||||
assert m.db.stat['proxy']['Modbus_Command'] == 1
|
assert m.db.stat['proxy']['Modbus_Command'] == 1
|
||||||
@@ -1478,6 +1493,8 @@ def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
|
|||||||
def test_msg_modbus_req2(ConfigTsunInv1, MsgModbusCmdCrcErr):
|
def test_msg_modbus_req2(ConfigTsunInv1, MsgModbusCmdCrcErr):
|
||||||
ConfigTsunInv1
|
ConfigTsunInv1
|
||||||
m = MemoryStream(b'')
|
m = MemoryStream(b'')
|
||||||
|
m.snr = get_sn_int()
|
||||||
|
m.state = m.STATE_UP
|
||||||
c = m.createClientStream(MsgModbusCmdCrcErr)
|
c = m.createClientStream(MsgModbusCmdCrcErr)
|
||||||
|
|
||||||
m.db.stat['proxy']['Unknown_Ctrl'] = 0
|
m.db.stat['proxy']['Unknown_Ctrl'] = 0
|
||||||
@@ -1491,8 +1508,9 @@ def test_msg_modbus_req2(ConfigTsunInv1, MsgModbusCmdCrcErr):
|
|||||||
assert str(c.seq) == '03:02'
|
assert str(c.seq) == '03:02'
|
||||||
assert c.header_len==11
|
assert c.header_len==11
|
||||||
assert c.data_len==23
|
assert c.data_len==23
|
||||||
assert c._forward_buffer==MsgModbusCmdCrcErr
|
assert c._forward_buffer==b''
|
||||||
assert c._send_buffer==b''
|
assert c._send_buffer==b''
|
||||||
|
assert m.writer.sent_pdu==b''
|
||||||
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
|
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
|
||||||
assert m.db.stat['proxy']['AT_Command'] == 0
|
assert m.db.stat['proxy']['AT_Command'] == 0
|
||||||
assert m.db.stat['proxy']['Modbus_Command'] == 0
|
assert m.db.stat['proxy']['Modbus_Command'] == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user