Skip to content

Commit

Permalink
step.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Oct 6, 2024
1 parent 558ac74 commit 7958de3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
9 changes: 1 addition & 8 deletions pymodbus/framer/old_framer_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ def __init__(self, decoder, client=None):
self._end = b"\r\n"
self.message_handler = FramerAscii(decoder, [0])

def frameProcessIncomingPacket(self, single, callback, slave, _tid):
def frameProcessIncomingPacket(self, used_len, data, single, callback, slave, _tid):
"""Process new packet pattern."""
used_len, data = self.message_handler.decode(self._buffer)
if not data:
if not used_len:
return False
self._buffer = self._buffer[used_len :]
return True
self.dev_id = self.message_handler.incoming_dev_id
if not self._validate_slave_id(slave, single):
Log.error("Not a valid slave id - {}, ignoring!!", self.message_handler.incoming_dev_id)
self.resetFrame()
Expand Down
12 changes: 10 additions & 2 deletions pymodbus/framer/old_framer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,19 @@ def processIncomingPacket(self, data: bytes, callback, slave, single=False, tid=
while True:
if self._buffer == b'':
return
if not self.frameProcessIncomingPacket(single, callback, slave, tid):
used_len, data = self.message_handler.decode(self._buffer)
self.dev_id = self.message_handler.incoming_dev_id
if used_len:
self._buffer = self._buffer[used_len:]
if not data:
return
self.dev_id = self.message_handler.incoming_dev_id
self.tid = self.message_handler.incoming_tid
if not self.frameProcessIncomingPacket(used_len, data, single, callback, slave, tid):
return

def frameProcessIncomingPacket(
self, _single, _callback, _slave, _tid) -> bool:
self, _used_len, _data, _single, _callback, _slave, _tid) -> bool:
"""Process new packet pattern."""
return True

Expand Down
8 changes: 1 addition & 7 deletions pymodbus/framer/old_framer_rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ def __init__(self, decoder, client=None):
super().__init__(decoder, client)
self.message_handler: FramerRTU = FramerRTU(self.decoder, [0])

def frameProcessIncomingPacket(self, _single, callback, _slave, _tid):
def frameProcessIncomingPacket(self, _used_len, data, _single, callback, _slave, _tid):
"""Process new packet pattern."""
used_len, data = self.message_handler.decode(self._buffer)
self.dev_id = self.message_handler.incoming_dev_id
if used_len:
self._buffer = self._buffer[used_len:]
if not data:
return False
if (result := self.decoder.decode(data)) is None:
raise ModbusIOException("Unable to decode request")
result.slave_id = self.dev_id
Expand Down
7 changes: 1 addition & 6 deletions pymodbus/framer/old_framer_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, decoder, client=None):
self._hsize = 0x07
self.message_handler = FramerSocket(decoder, [0])

def frameProcessIncomingPacket(self, single, callback, slave, tid):
def frameProcessIncomingPacket(self, used_len, data, single, callback, slave, tid):
"""Process new packet pattern.
This takes in a new request packet, adds it to the current
Expand All @@ -53,11 +53,6 @@ def frameProcessIncomingPacket(self, single, callback, slave, tid):
The processed and decoded messages are pushed to the callback
function to process and send.
"""
used_len, data = self.message_handler.decode(self._buffer)
if not data:
return False
self.dev_id = self.message_handler.incoming_dev_id
self.tid = self.message_handler.incoming_tid
if not self._validate_slave_id(slave, single):
Log.debug("Not a valid slave id - {}, ignoring!!", self.message_handler.incoming_dev_id)
self.resetFrame()
Expand Down
8 changes: 1 addition & 7 deletions pymodbus/framer/old_framer_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@ def __init__(self, decoder, client=None):
self._hsize = 0x0
self.message_handler = FramerTLS(decoder, [0])

def frameProcessIncomingPacket(self, _single, callback, _slave, _tid):
def frameProcessIncomingPacket(self, used_len, data, _single, callback, _slave, _tid):
"""Process new packet pattern."""
# no slave id for Modbus Security Application Protocol

used_len, data = self.message_handler.decode(self._buffer)
if not data:
return False
self.dev_id = self.message_handler.incoming_dev_id
self.tid = self.message_handler.incoming_tid

if (result := self.decoder.decode(data)) is None:
self.resetFrame()
raise ModbusIOException("Unable to decode request")
Expand Down

0 comments on commit 7958de3

Please sign in to comment.