Skip to content

Commit 527ae35

Browse files
authored
S allius/issue104 (#105)
* Update README.md Exchange logger fw version with the real inverter fw version in the compatibility table * Update python-app.yml run also on pushes to issue branches fix name for issues branches * fix forwarding of MODBUS responses * fix unit tests
1 parent 6b39187 commit 527ae35

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

app/src/gen3/talent.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ def msg_modbus(self):
426426

427427
if self.ctrl.is_req():
428428
if self.remoteStream.mb.recv_req(data[hdr_len:],
429-
self.msg_forward):
429+
self.remoteStream.
430+
msg_forward):
430431
self.inc_counter('Modbus_Command')
431432
else:
432433
self.inc_counter('Invalid_Msg_Format')

app/src/gen3plus/solarman_v5.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ def msg_command_req(self):
495495

496496
elif ftype == self.MB_RTU_CMD:
497497
if self.remoteStream.mb.recv_req(data[15:],
498-
self.__forward_msg()):
498+
self.remoteStream.
499+
__forward_msg):
499500
self.inc_counter('Modbus_Command')
500501
else:
501502
self.inc_counter('Invalid_Msg_Format')

app/tests/test_solarman.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def _SolarmanV5__flush_recv_msg(self) -> None:
9191
def get_sn() -> bytes:
9292
return b'\x21\x43\x65\x7b'
9393

94+
def get_sn_int() -> int:
95+
return 2070233889
96+
9497
def get_inv_no() -> bytes:
9598
return b'T170000000000001'
9699

@@ -531,6 +534,15 @@ def MsgModbusCmd():
531534
msg += b'\x15'
532535
return msg
533536

537+
@pytest.fixture
538+
def MsgModbusCmdFwd():
539+
msg = b'\xa5\x17\x00\x10\x45\x01\x00' +get_sn() +b'\x02\xb0\x02'
540+
msg += b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x06\x20\x08'
541+
msg += b'\x00\x00\x03\xc8'
542+
msg += correct_checksum(msg)
543+
msg += b'\x15'
544+
return msg
545+
534546
@pytest.fixture
535547
def MsgModbusCmdCrcErr():
536548
msg = b'\xa5\x17\x00\x10\x45\x03\x02' +get_sn() +b'\x02\xb0\x02'
@@ -1412,9 +1424,11 @@ def test_msg_at_command_rsp2(ConfigTsunInv1, AtCommandRspMsg):
14121424
assert m.db.stat['proxy']['Modbus_Command'] == 0
14131425
m.close()
14141426

1415-
def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
1427+
def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd, MsgModbusCmdFwd):
14161428
ConfigTsunInv1
14171429
m = MemoryStream(b'')
1430+
m.snr = get_sn_int()
1431+
m.state = m.STATE_UP
14181432
c = m.createClientStream(MsgModbusCmd)
14191433

14201434
m.db.stat['proxy']['Unknown_Ctrl'] = 0
@@ -1428,8 +1442,9 @@ def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
14281442
assert str(c.seq) == '03:02'
14291443
assert c.header_len==11
14301444
assert c.data_len==23
1431-
assert c._forward_buffer==MsgModbusCmd
1445+
assert c._forward_buffer==b''
14321446
assert c._send_buffer==b''
1447+
assert m.writer.sent_pdu == MsgModbusCmdFwd
14331448
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
14341449
assert m.db.stat['proxy']['AT_Command'] == 0
14351450
assert m.db.stat['proxy']['Modbus_Command'] == 1
@@ -1439,6 +1454,8 @@ def test_msg_modbus_req(ConfigTsunInv1, MsgModbusCmd):
14391454
def test_msg_modbus_req2(ConfigTsunInv1, MsgModbusCmdCrcErr):
14401455
ConfigTsunInv1
14411456
m = MemoryStream(b'')
1457+
m.snr = get_sn_int()
1458+
m.state = m.STATE_UP
14421459
c = m.createClientStream(MsgModbusCmdCrcErr)
14431460

14441461
m.db.stat['proxy']['Unknown_Ctrl'] = 0
@@ -1452,8 +1469,9 @@ def test_msg_modbus_req2(ConfigTsunInv1, MsgModbusCmdCrcErr):
14521469
assert str(c.seq) == '03:02'
14531470
assert c.header_len==11
14541471
assert c.data_len==23
1455-
assert c._forward_buffer==MsgModbusCmdCrcErr
1472+
assert c._forward_buffer==b''
14561473
assert c._send_buffer==b''
1474+
assert m.writer.sent_pdu==b''
14571475
assert m.db.stat['proxy']['Unknown_Ctrl'] == 0
14581476
assert m.db.stat['proxy']['AT_Command'] == 0
14591477
assert m.db.stat['proxy']['Modbus_Command'] == 0

0 commit comments

Comments
 (0)