Skip to content

Commit ade21e6

Browse files
authoredAug 2, 2024··
Fixed broken single frame transmission in blocking_send mode (#130)
1 parent 9bfe34c commit ade21e6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎isotp/protocol.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,8 @@ def _process_rx(self, msg: CanMessage) -> ProcessRxReport:
982982
immediate_tx_msg_required = True
983983

984984
return self.ProcessRxReport(immediate_tx_required=immediate_tx_msg_required, frame_received=frame_complete)
985-
985+
986+
986987
def _process_tx(self) -> ProcessTxReport:
987988
"""Process the transmit state machine"""
988989
output_msg = None # Value outputted. If None, no subsequent call to _process_tx will be done.
@@ -1076,7 +1077,7 @@ def _process_tx(self) -> ProcessTxReport:
10761077
if total_size <= self.params.tx_data_length - size_offset - len(self.address.get_tx_payload_prefix()):
10771078
# Will raise if size is not what was requested
10781079
payload = self.active_send_request.generator.consume(total_size, enforce_exact=True)
1079-
1080+
10801081
if size_on_first_byte:
10811082
msg_data = self.address.get_tx_payload_prefix() + bytearray([0x0 | len(payload)]) + payload
10821083
else:
@@ -1090,7 +1091,8 @@ def _process_tx(self) -> ProcessTxReport:
10901091
self.tx_state = self.TxState.TRANSMIT_SF_STANDBY
10911092
else:
10921093
output_msg = msg_temp
1093-
1094+
self._stop_sending(success=True)
1095+
10941096
# Multi frame - First Frame
10951097
else:
10961098
self.tx_frame_length = total_size
@@ -1125,7 +1127,6 @@ def _process_tx(self) -> ProcessTxReport:
11251127
# This states serves if the rate limiter prevent from starting a new transmission.
11261128
# We need to pop the isotp frame to know if the rate limiter must kick, but since the data is already popped,
11271129
# we can't stay in IDLE state. So we come here until the rate limiter gives us permission to proceed.
1128-
11291130
if self.tx_standby_msg is not None:
11301131
if len(self.tx_standby_msg.data) <= allowed_bytes:
11311132
output_msg = self.tx_standby_msg
@@ -1151,7 +1152,7 @@ def _process_tx(self) -> ProcessTxReport:
11511152
payload = self.active_send_request.generator.consume(payload_length, enforce_exact=False)
11521153
if len(payload) > 0: # Corner case. If generator size is a multiple of ll_data_length, we will get an empty payload on last frame.
11531154
msg_data = self.address.get_tx_payload_prefix() + bytearray([0x20 | self.tx_seqnum]) + payload
1154-
arbitration_id = self.address.get_tx_arbitration_id()
1155+
arbitration_id = self.address.get_tx_arbitration_id()
11551156
output_msg = self._make_tx_msg(arbitration_id, msg_data)
11561157
self.tx_seqnum = (self.tx_seqnum + 1) & 0xF
11571158
self.timer_tx_stmin.start()

‎test/test_transport_layer.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,20 @@ def test_blocking_send_error(self):
164164
# Transmission will fail because no flow control
165165
self.layer1.send(bytes([1] * 10), send_timeout=10)
166166

167-
def test_blocking_send(self):
167+
def test_blocking_send_multiframe(self):
168168
self.layer1.params.blocking_send = True
169169
self.layer1.load_params()
170170
# layer2 has a thread to handle reception
171171
self.layer1.send(bytes([1] * 100), send_timeout=5)
172172
self.assert_no_error_reported()
173173

174+
def test_blocking_send_single_frame(self):
175+
self.layer1.params.blocking_send = True
176+
self.layer1.load_params()
177+
# layer2 has a thread to handle reception
178+
self.layer1.send(bytes([1] * 4), send_timeout=5)
179+
self.assert_no_error_reported()
180+
174181
def test_listen_mode_receiver(self):
175182
# listen mode enabled. Address is the receiver address
176183
self.layer2.params.blocksize=5

0 commit comments

Comments
 (0)
Please sign in to comment.