Index: dialin/dg/calibration_record.py =================================================================== diff -u -r20659ffd56482b0596253aa0f1f1a7eda1221945 -r46ebf93d3666db40f25ad1e9170426853aa845d4 --- dialin/dg/calibration_record.py (.../calibration_record.py) (revision 20659ffd56482b0596253aa0f1f1a7eda1221945) +++ dialin/dg/calibration_record.py (.../calibration_record.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) @@ -72,6 +72,7 @@ if not self._is_getting_cal_in_progress: self._is_getting_cal_in_progress = True + self._raw_cal_record.clear() message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_DG_GET_CALIBRATION_RECORD.value) @@ -85,7 +86,7 @@ self.logger.debug("Timeout!!!!") - self.logger.debug("Request cancelled: an existing request is in progress.") + self.logger.warning("Request cancelled: an existing request is in progress.") return False def _handler_dg_calibration_sync(self, message): Index: dialin/hd/ui_proxy.py =================================================================== diff -u -r2e392c92d55178f457a67423ba8c503a86dcf3c8 -r46ebf93d3666db40f25ad1e9170426853aa845d4 --- dialin/hd/ui_proxy.py (.../ui_proxy.py) (revision 2e392c92d55178f457a67423ba8c503a86dcf3c8) +++ dialin/hd/ui_proxy.py (.../ui_proxy.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) @@ -1219,7 +1219,7 @@ self.can_interface.send(message, 0) - def set_a_treatment_parameter(self, param_idx, value): + def set_a_treatment_parameter(self, param_idx: int, value: int) -> None: """ Constructs and sends a set treatment parameter message Constraints: Index: dialin/protocols/CAN.py =================================================================== diff -u -rbfb0c47181dc8a73d09825ab697a7799dd520417 -r46ebf93d3666db40f25ad1e9170426853aa845d4 --- dialin/protocols/CAN.py (.../CAN.py) (revision bfb0c47181dc8a73d09825ab697a7799dd520417) +++ dialin/protocols/CAN.py (.../CAN.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) @@ -16,6 +16,7 @@ import threading from collections import deque +import asyncio import can import math @@ -452,6 +453,7 @@ # try to setup can bus and exit if the can bus has not ben setup to use. try: self.bus = can.interfaces.socketcan.SocketcanBus(channel=can_interface) + self.loop = asyncio.get_event_loop() if self.bus is not None: self.canbus_thread = threading.Thread(target=self.listener, daemon=True) self.message_queue_thread = threading.Thread(target=self.handle_messages, daemon=True) @@ -460,8 +462,8 @@ s = "Can connection is not valid" self.logger.debug(s) sys.exit(s) - self.listener_buffer = can.BufferedReader() - self.notifier = can.Notifier(self.bus, [self.listener_buffer]) + self.listener_buffer = can.AsyncBufferedReader() + self.notifier = can.Notifier(bus=self.bus, listeners=[self.listener_buffer], loop=self.loop) except Exception as e: s = str(e) self.logger.error(s) @@ -491,7 +493,7 @@ return else: self.run = True - if self.canbus_thread is not None: + if self.message_queue_thread is not None and self.canbus_thread is not None: self.canbus_thread.start() self.message_queue_thread.start() self.logger.info("Can listener has started.") @@ -510,17 +512,22 @@ """ Listens for diality message on the can interface passed during construction. """ + async def _listener(): + while True: + message = await self.listener_buffer.get_message() - while self.run: + if message is not None: + self.message_queue.append(message) - message = self.listener_buffer.get_message(0.0) + else: # no new packets in receive buffer + # Careful here, making this any shorter will start limiting CPU time for other threads + sleep(0.01) - if message is not None: - self.message_queue.append(message) + if not self.loop.is_running(): + self.loop.run_until_complete(_listener()) + else: + self.loop.create_task(_listener()) - else: # no new packets in receive buffer - # Careful here, making this any shorter will start limiting CPU time for other threads - sleep(0.01) def handle_messages(self): """ @@ -591,7 +598,7 @@ message_valid = False dialin_ch_id = None dialin_msg_id = None - sys.stderr.write( + self.logger.critical( "Incorrect CRC, received message: {}, crc: {}, calculated crc: {}\n".format( self.messages, DenaliMessage.get_crc(complete_dialin_message), DenaliMessage.crc8(self.messages))) Index: tests/peter/test_blood_flow.py =================================================================== diff -u -rbfb0c47181dc8a73d09825ab697a7799dd520417 -r46ebf93d3666db40f25ad1e9170426853aa845d4 --- tests/peter/test_blood_flow.py (.../test_blood_flow.py) (revision bfb0c47181dc8a73d09825ab697a7799dd520417) +++ tests/peter/test_blood_flow.py (.../test_blood_flow.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) @@ -48,6 +48,7 @@ payload=payload) hd_sim.can_interface.send(message, 0) + print("Sent", message) sleep(1) Index: tests/peter/test_calibration.py =================================================================== diff -u -rbfb0c47181dc8a73d09825ab697a7799dd520417 -r46ebf93d3666db40f25ad1e9170426853aa845d4 --- tests/peter/test_calibration.py (.../test_calibration.py) (revision bfb0c47181dc8a73d09825ab697a7799dd520417) +++ tests/peter/test_calibration.py (.../test_calibration.py) (revision 46ebf93d3666db40f25ad1e9170426853aa845d4) @@ -1,3 +1,6 @@ +import copy +import pprint +import subprocess import sys import struct @@ -10,6 +13,7 @@ def process_calibration_record(read=False): + dg = DG() cal = dg.calibration_record print(cal.tmp_record) @@ -74,6 +78,7 @@ except KeyboardInterrupt: pass + def test_crc(): val = NVOpsUtils.crc_16(b''.join([ struct.pack("