Index: HemodialysisDevice.py =================================================================== diff -u -r8e5f99291989ba68281aa5e763a7eb5df87e170e -r1550adb024fe0ea22b81ba8ef73387f6af7fc3e3 --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 8e5f99291989ba68281aa5e763a7eb5df87e170e) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 1550adb024fe0ea22b81ba8ef73387f6af7fc3e3) @@ -21,6 +21,7 @@ from time import sleep from binascii import unhexlify import struct +import ctypes class HD: @@ -49,6 +50,7 @@ self.Alarms = HD.HD_Alarms(self, self.can_interface) self.Buttons = HD.HD_Buttons(self) self.BloodFlow = HD.HD_BloodFlow(self, self.can_interface) + self.RTC = HD.HD_RTC(self, self.can_interface) self.DialysateInletFlow = HD.HD_DialysateInletFlow(self, self.can_interface) self.Watchdog = HD.HD_Watchdog(self) @@ -508,6 +510,81 @@ print("Timeout!!!!") return False + class HD_RTC: + + MSG_ID_SET_RTC_DATE_TIME = 0x801D + MSG_ID_RTC_EPOCH = 0x000A + + START_POS_SET_PT = DenaliMessage.PAYLOAD_START_INDEX + END_POS_SET_PT = START_POS_SET_PT + 4 + + def __init__(self, outer_instance, can_interface=None): + """ + HD_BloodFlow constructor + + \param outer_instance: reference to the HD (outer) class. + + \returns HD_BloodFlow object. + """ + self.outer_instance = outer_instance + + if can_interface is not None: + channel_id = DenaliChannels.hd_sync_broadcast_ch_id + msg_id = self.MSG_ID_RTC_EPOCH + can_interface.registerReceivingPublicationFunction(channel_id, msg_id, + self.handlerRTCEpoch) + self.RTCEpoch = 0 + + def handlerRTCEpoch(self, message): + """ + Publishes the RTC time in epoch + + \param message: published RTC epoch message + \returns none + """ + epoch = int.from_bytes(bytearray( + message['message'][self.START_POS_SET_PT:self.END_POS_SET_PT]), + byteorder=DenaliMessage.BYTE_ORDER) + self.RTCEpoch = ctypes.c_uint32(epoch) + + def CmdSetRTCTimeAndDate(self, secs, mins, hours, days, months, years): + """ + Constructs and sends the time and date to be written to RTC + + \returns 1 if successful, zero otherwise + """ + sec = bytes([secs]) + min = bytes([mins]) + hour = bytes([hours]) + day = bytes([days]) + month = bytes([months]) + year = self.outer_instance.integer2ByteArray(years) + payload = sec + min + hour + day + month + year + + message = DenaliMessage.buildMessage(channel_id=DenaliChannels.dialin_to_hd_ch_id, + message_id=self.MSG_ID_SET_RTC_DATE_TIME, + payload=payload) + + print("Setting time and date to RTC") + + # Send message + received_message = self.outer_instance.can_interface.send(message) + + # If there is content... + if received_message is not None: + print(received_message) + #str_res = str(flow) + print("Time and Date in RTC set to seconds: " + str(sec) + " minutes: " + str(min) + " hours: " + + str(hour) + " days: " + str(day) + " months: " + str(month) + " years: " + str(year) + + str(received_message['message'][DenaliMessage.PAYLOAD_START_INDEX])) + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + print("Timeout!!!!") + return False + + + class HD_BloodFlow: """ \class HD_BloodFlow @@ -1246,8 +1323,14 @@ sleep(2) hd._Basics.CmdLogInToHD() - hd.BloodFlow.CmdBloodPumpMeasuredCurrentOverride(hd.NO_RESET,149) + hd.RTC.CmdSetRTCTimeAndDate(0, 2, 1, 5, 1, 2020) + while True: + print(hd.RTC.RTCEpoch) + sleep(1) + +"""" + hd.BloodFlow.CmdBloodPumpMeasuredCurrentOverride(hd.NO_RESET,149) tgtRate = 0 hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.NO_RESET, 2000) @@ -1266,3 +1349,4 @@ print(hd.BloodFlow.MeasuredBloodFlowRate) # hd.BloodFlow.CmdBloodFlowBroadcastIntervalOverride(hd.RESET,0) +"""