Repository navigation
Let the framer decide the next transaction id. - #3101
janiversen merged 3 commits into
Conversation
TransactionManager.getNextTID() asked isinstance(self.framer, (FramerAscii, FramerRTU)) to decide whether frames carry a transaction id. Each framer now answers this itself through next_transaction_id(): FramerBase (socket/tls) counts 1..65000 and wraps, FramerRTU/FramerAscii return 0. The transaction manager no longer imports concrete framer classes.
| continue | ||
| return used_len, dev_id, 0, msg[1:] | ||
|
|
||
| def next_transaction_id(self, transaction_id: int) -> int: |
There was a problem hiding this comment.
It would be more logical to have this in the base, and the exception (where TID is actually used) in socket.py (remark tls should really depend on socket, as there are no special implementation).
The default implementation is not to use transaction_id. Mid term, the idea is to move the whole transaction handling into socket.py, and simplify transaction.py
| return data_len, dev_id, 0, data[used_len + 1 : crc_start] | ||
| return 0, 0, 0, self.EMPTY | ||
|
|
||
| def next_transaction_id(self, transaction_id: int) -> int: |
There was a problem hiding this comment.
Please remove, it covered in base.py
|
TLS have been cleaned up in #3102 |
As requested in review: FramerBase.next_transaction_id() now returns 0, the default for frames without a transaction id, and the 1..65000 sequence lives in FramerSocket, where the transaction id is used. FramerTLS inherits it from FramerSocket (pymodbus-dev#3102). The RTU and ASCII overrides are no longer needed and are removed.
|
If you want to have a challenge for a future PR: We want to move the transaction_id handling from transaction.py to socket.py. Transaction.py probably still needs access to the received/sent transaction_id. When client.py calls transaction.py it should send a 0 as transaction_id to socket and socket should assign the next id. |
TransactionManager.getNextTID()checksisinstance(self.framer, (FramerAscii, FramerRTU)). As a result, the transaction manager imports concrete framer classes, and a new framer type would need an edit there. This PR moves the decision to the framers:FramerBase.next_transaction_id()returns 0, the default for frames without a transaction id (RTU, ASCII).FramerSocket.next_transaction_id()returns 1..65000 and wraps;FramerTLSinherits it (Cleanup TLS framer. #3102).getNextTID()becomes a single call, andtransaction.pyonly importsFramerBase.Behaviour is identical for all four framers.
test_next_transaction_idcovers every framer, including the wrap-around.check_ci.shpasses with coverage at 100%.