Index: HemodialysisDevice.py =================================================================== diff -u -r7da3ea9575c7a0ae9a03ea934ce907f4eccbc2aa -r227fad421dde9339458aa8e5826be4807599038a --- HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 7da3ea9575c7a0ae9a03ea934ce907f4eccbc2aa) +++ HemodialysisDevice.py (.../HemodialysisDevice.py) (revision 227fad421dde9339458aa8e5826be4807599038a) @@ -18,6 +18,7 @@ from DialityCoreCanProtocol import DialityPacket from time import sleep from binascii import unhexlify +import struct class HD: """ @@ -73,7 +74,7 @@ - def login(self): + def CmdLogInToHD(self): """ Constructs and sends a login command via CAN bus. Login required before \n other commands can be sent to the HD. @@ -102,7 +103,7 @@ - def HDMessageInsert(self, msg): + def CmdHDMessageInsert(self, msg): """ Constructs and sends the insert HD message command. Given message will \n be inserted into the HD's received message queue for processing. @@ -155,7 +156,7 @@ - def OffButtonOverride(self, reset, state): + def CmdOffButtonOverride(self, reset, state): """ Constructs and sends the Off button override command @@ -194,7 +195,7 @@ - def StopButtonOverride(self, reset, state): + def CmdStopButtonOverride(self, reset, state): """ Constructs and sends the Stop button override command @@ -251,7 +252,7 @@ """ - def WatchdogTaskCheckinOverride(self, reset, state, task): + def CmdWatchdogTaskCheckinOverride(self, reset, state, task): """ Constructs and sends the watchdog task check-in override command @@ -308,7 +309,7 @@ """ - def AlarmStateOverride(self, reset, state, alarm): + def CmdAlarmStateOverride(self, reset, state, alarm): """ Constructs and sends the alarm state override command @@ -349,7 +350,7 @@ - def AlarmTimeOverride(self, reset, time_ms, alarm): + def CmdAlarmTimeOverride(self, reset, time_ms, alarm): """ Constructs and sends the alarm time override command @@ -390,7 +391,7 @@ - def AlarmLampPatternOverride(self, reset, pattern): + def CmdAlarmLampPatternOverride(self, reset, pattern): """ Constructs and sends the alarm lamp pattern override command. @@ -463,8 +464,8 @@ if can_interface is not None: channel_id = 0x40 - msg_id = 0x5 - can_interface.registerSyncFunction( channel_id, msg_id, self.BloodFlowSyncFunction) + msg_id = 0x0005 + can_interface.registerSyncFunction( channel_id, msg_id, self.handlerBloodFlowSyncFunction) self.TargetBloodFlowRate = 0 self.MeasuredBloodFlowRate = 0.0 @@ -480,12 +481,15 @@ \returns HD_BloodFlow object. """ - def BloodFlowSyncFunction(self, message): + def handlerBloodFlowSyncFunction(self, message): self.TargetBloodFlowRate = int.from_bytes(bytearray(message[4:8]),byteorder='little') + self.MeasuredBloodFlowRate = struct.unpack('f', bytearray(message[8:12])) + self.MeasuredBloodPumpMCSpeed = struct.unpack('f', bytearray(message[12:16])) + self.MeasuredBloodPumpCurrent = struct.unpack('f', bytearray(message[16:20])) + print("Tgt Flow: " + str(self.TargetBloodFlowRate) + " Meas Flow: " + str(self.MeasuredBloodFlowRate) + " Meas Spd: " + str(self.MeasuredBloodPumpMCSpeed) + " Meas Curr: " + str(self.MeasuredBloodPumpCurrent)) - - def BloodFlowSetPointOverride(self, reset, flow): + def CmdBloodFlowSetPointOverride(self, reset, flow): """ Constructs and sends the blood flow set point override command @@ -524,7 +528,7 @@ - def BloodFlowMeasuredOverride(self, reset, flow): + def CmdBloodFlowMeasuredOverride(self, reset, flow): """ Constructs and sends the measured blood flow override command @@ -566,7 +570,7 @@ # TODO - add override command for blood pump speed (pump hall sensor via NHET?) - def BloodPumpMCMeasuredSpeedOverride(self, reset, speed): + def CmdBloodPumpMCMeasuredSpeedOverride(self, reset, speed): """ Constructs and sends the measured blood pump motor controller speed \n override command. @@ -606,7 +610,7 @@ - def BloodPumpMeasuredCurrentOverride(self, reset, curr): + def CmdBloodPumpMeasuredCurrentOverride(self, reset, curr): """ Constructs and sends the measured blood pump motor current override command @@ -645,7 +649,7 @@ - def BloodFlowBroadcastIntervalOverride(self, reset, ms): + def CmdBloodFlowBroadcastIntervalOverride(self, reset, ms): """ Constructs and sends the measured flow broadcast interval override command @@ -707,4 +711,4 @@ # wait 2 seconds and then login to HD as a tester sleep(2) - hd._Basics.login() + hd._Basics.CmdLogInToHD()