Index: dialin/common/msg_defs.py =================================================================== diff -u -r120e6925083c799b20143834e431bdc9f34c3687 -rf8e83b59e5f3b903abb1cb78969d858439420f59 --- dialin/common/msg_defs.py (.../msg_defs.py) (revision 120e6925083c799b20143834e431bdc9f34c3687) +++ dialin/common/msg_defs.py (.../msg_defs.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) @@ -1,18 +1,3 @@ -########################################################################### -# -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. -# -# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN -# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. -# -# @file msg_defs.py -# -# @author (last) Peter Lucia -# @date (last) 07-Aug-2020 -# @author (original) Peter Lucia -# @date (original) 07-Aug-2020 -# -############################################################################ import enum @@ -75,6 +60,8 @@ MSG_ID_DG_HEAT_DISINFECT_DATA = 0x37 # DG heat disinfection publish data MSG_ID_UI_START_TREATMENT = 0x38 # UI user request to initiate a treatment MSG_ID_HD_START_TREATMENT_RESPONSE = 0x39 # HD response to user request to initiate a treatment + MSG_ID_UI_CONFIRM_TREATMENT = 0x3A # UI Confirms treatment parameters + MSG_ID_UI_END_TREATMENT = 0x3B # UI Ends a treatment MSG_ID_CAN_ERROR_COUNT = 0x999 # test code in support of EMC testing @@ -161,7 +148,7 @@ MSG_ID_HEAT_DISINFECT_RSRVR2_TO_RSRVR1_DURATION_MINS = 0xA01F # Heat disinfection reservoir 2 to reservoir 1 duration in minutes MSG_ID_HEAT_DISINFECT_NO_OF_CYCLES_TO_RUN = 0xA020 # Heat disinfection number of cycles to run MSG_ID_HEAT_DISINFECT_PUBLISH_INTERVAL_OVERRIDE = 0xA021 # Heat disinfection data publish interval override request - MSG_ID_PRIMING_STATUS = 0xA022 # The priming status + MSG_ID_PRIMING_STATUS = 0x0037 # The priming status MSG_ID_HD_DEBUG_EVENT = 0xFFF1 # HD debug event text to be logged in event log MSG_ID_DG_DEBUG_EVENT = 0xFFF2 # DG debug event text to be logged in event log Index: dialin/protocols/CAN.py =================================================================== diff -u -r39cffcc77c7c0ce645325cf50cad65874b2bb096 -rf8e83b59e5f3b903abb1cb78969d858439420f59 --- dialin/protocols/CAN.py (.../CAN.py) (revision 39cffcc77c7c0ce645325cf50cad65874b2bb096) +++ dialin/protocols/CAN.py (.../CAN.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) @@ -380,15 +380,15 @@ """ if self.bus is None: - self.logger.debug("Cannot start can listener.") + self.logger.error("Cannot start can listener.") return else: self.run = True if self.serial_listener_thread is not None: self.serial_listener_thread.start() - self.logger.debug("Can listener has started.") + self.logger.info("Can listener has started.") else: - self.logger.debug("Cannot start listener...") + self.logger.error("Cannot start listener...") def stop(self): """ @@ -476,9 +476,7 @@ elif dialin_ch_id in self.sync_response_dictionary.keys() and \ dialin_msg_id in self.sync_response_dictionary[channel_id].keys(): - # send the message to all the callback functions - for func in self.sync_response_dictionary[dialin_ch_id][dialin_msg_id]: - func(complete_dialin_message) + self.sync_response_dictionary[dialin_ch_id][dialin_msg_id](complete_dialin_message) # Done with this message, let's get the next one self.messages = None @@ -499,16 +497,11 @@ # if the channel_id exist, we just update the dictionary for the channel_id if channel_id in self.sync_response_dictionary.keys(): - if message_id in self.sync_response_dictionary[channel_id]: - self.sync_response_dictionary[channel_id][message_id] += [function] - else: - self.sync_response_dictionary[channel_id][message_id] = {} - self.sync_response_dictionary[channel_id][message_id] = [function] + self.sync_response_dictionary[channel_id].update({message_id: function}) # otherwise, we need to create the dictionary for the channel_id else: - self.sync_response_dictionary[channel_id] = {} - self.sync_response_dictionary[channel_id][message_id] = [function] + self.sync_response_dictionary[channel_id] = {message_id: function} def send(self, built_message, time_out=DIALIN_MSG_RESP_TO): """ @@ -604,4 +597,3 @@ with open(filename, 'a') as f: f.write("{0}\n".format(packet)) - Index: dialin/ui/hd_proxy.py =================================================================== diff -u -r120e6925083c799b20143834e431bdc9f34c3687 -rf8e83b59e5f3b903abb1cb78969d858439420f59 --- dialin/ui/hd_proxy.py (.../hd_proxy.py) (revision 120e6925083c799b20143834e431bdc9f34c3687) +++ dialin/ui/hd_proxy.py (.../hd_proxy.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) @@ -1,28 +1,29 @@ ########################################################################### # -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # -# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN -# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # -# @file hd_proxy.py +# @file hd_proxy.py # -# @author (last) Peter Lucia -# @date (last) 12-Aug-2020 -# @author (original) Peter Lucia -# @date (original) 07-Aug-2020 +# @date 29-July-2020 +# @author P. Lucia # +# @brief This class simulates the hd when interfacing with the UI +# ############################################################################ from ..protocols.CAN import (DenaliMessage, DenaliCanMessenger, DenaliChannels) -from ..utils.base import _AbstractSubSystem, _LogManager +from ..utils.base import _AbstractSubSystem, _LogManager, _publish from ..utils.conversions import integer_to_bytearray from ..hd.buttons import HDButtons from .hd_proxy_alarms import HDProxyAlarms import enum from typing import List from ..common.msg_defs import RequestRejectReasons, MsgIds +import struct class HDSimulator(_AbstractSubSystem): @@ -38,6 +39,19 @@ self.can_interface = DenaliCanMessenger(can_interface=can_interface, logger=self.logger, log_can=self._log_manager.log_level == "CAN_ONLY") + self.can_interface.start() + + if self.can_interface is not None: + channel_id = DenaliChannels.ui_to_hd_ch_id + self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_UI_START_TREATMENT.value, + self._handler_ui_start_treatment) + self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_UI_CONFIRM_TREATMENT.value, + self._handler_ui_confirm_treatment) + self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_UI_END_TREATMENT.value, + self._handler_ui_end_treatment) self.alarms = HDProxyAlarms(self.can_interface, self.logger) def cmd_send_treatment_parameter_validation_response(self, rejections: List[RequestRejectReasons]): @@ -132,3 +146,37 @@ payload=payload) self.can_interface.send(message, 0) + + def _handler_ui_confirm_treatment(self, message): + """ + + @param message: + @return: + """ + self.logger.debug("Confirmed Treatment Parameters") + + def _handler_ui_start_treatment(self, message): + """ + + @param message: + @return: + """ + START_POS = DenaliMessage.PAYLOAD_START_INDEX + END_POS = START_POS + 4 + + request = struct.unpack('i', bytearray( + message['message'][START_POS:END_POS]))[0] + if request == 0: + self.logger.debug("Selecting treatment parameters") + elif request == 1: + self.logger.debug("Canceling treatment") + elif request == 2: + self.logger.debug("Starting treatment") + + def _handler_ui_end_treatment(self, message): + """ + + @param message: + @return: + """ + self.logger.debug("Ending Treatment") Index: tests/test_hd_simulator.py =================================================================== diff -u -r120e6925083c799b20143834e431bdc9f34c3687 -rf8e83b59e5f3b903abb1cb78969d858439420f59 --- tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision 120e6925083c799b20143834e431bdc9f34c3687) +++ tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision f8e83b59e5f3b903abb1cb78969d858439420f59) @@ -1,17 +1,18 @@ ########################################################################### # -# Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +# Copyright (c) 2020 Diality Inc. - All Rights Reserved. # -# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN -# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # -# @file test_hd_simulator.py +# @file test_hd_simulator.py # -# @author (last) Peter Lucia -# @date (last) 28-Aug-2020 -# @author (original) Peter Lucia -# @date (original) 06-Aug-2020 +# @date 06-Aug-2020 +# @author P. Lucia # +# @brief +# +# ############################################################################ import sys sys.path.append("..") @@ -117,16 +118,30 @@ hd_simulator.cmd_send_priming_time_remaining(state, seconds_remaining, total_seconds) sleep(0.05) +class StartTreatmentObserver(AbstractObserver): + def __init__(self): + self.received_response = False + def update(self, result): + print(result) + self.received_response = True +def test_start_confirm_end_treatment(): + hd_simulator = HDSimulator(log_level="PRINT_ONLY") + observer = StartTreatmentObserver() + hd_simulator.attach(observer) + + while not observer.received_response: + sleep(0.50) + if __name__ == '__main__': # test_clear_alarms() # sleep(1) # test_poweroff() # test_valid_parameters() - test_priming() + # test_priming() + test_start_confirm_end_treatment() -