Index: shared/scripts/denaliMessages.py =================================================================== diff -u -r40568c277aa2c01963d0f3f9da41748c2686d343 -r929c42f19c662c57ae264d200658fb1690353008 --- shared/scripts/denaliMessages.py (.../denaliMessages.py) (revision 40568c277aa2c01963d0f3f9da41748c2686d343) +++ shared/scripts/denaliMessages.py (.../denaliMessages.py) (revision 929c42f19c662c57ae264d200658fb1690353008) @@ -12,6 +12,7 @@ # author Behrouz NematiPour # +import time import subprocess import utils import messageBuilder @@ -61,93 +62,101 @@ def show_PowerOffRejectionDialog(): subprocess.call(['cansend', 'can0', '020#A5.01.00.01.00.01.02.5A']) +################################################################################################## +# After each multi-frame message put a 100ms sleep, time.sleep(0.1) # +# it seems it's needed otherwise the test will check a value which has not been received yet. # +################################################################################################## +def waitForMessageToBeSent(): + time.sleep(0.1) + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate): - msg = messageBuilder.buildMessage( GuiActionType.TreatmentRanges, 4 * 6, - utils.toU32(vMinTreatmentDuration), - utils.toU32(vMaxTreatmentDuration), - utils.toU32(vMinUFVolume ), - utils.toU32(vMaxUFVolume ), - utils.toU32(vMinDialysateFlowRate), - utils.toU32(vMaxDialysateFlowRate) + msg = messageBuilder.buildMessage( GuiActionType.TreatmentRanges, 4 * 6, True, + utils.toI32(vMinTreatmentDuration), + utils.toI32(vMaxTreatmentDuration), + utils.toI32(vMinUFVolume ), + utils.toI32(vMaxUFVolume ), + utils.toI32(vMinDialysateFlowRate), + utils.toI32(vMaxDialysateFlowRate) ) return messageBuilder.toFrames(msg) ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def setTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate): # This message needs to be acknowledged by seq# 01.00 : just call send_acknowledge_UI after this - # ------------------------------------------vvvvv----------------------------------------------- frames = buildSetTreatmentParamRanges(vMinTreatmentDuration, vMaxTreatmentDuration, vMinUFVolume, vMaxUFVolume, vMinDialysateFlowRate, vMaxDialysateFlowRate) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) + waitForMessageToBeSent() - ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildSetTreatmentBloodFlowRate(vFlowSetPt, vMeasFlow = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): - msg = messageBuilder.buildMessage( 5, 4 * 7, - utils.toU32(vFlowSetPt ), - utils.toU32(vMeasFlow ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vRotSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMotSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMCSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMCCurr ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vPWM ) # it has to be F32 and at this moment I haven't implemented and I don't currently need it + msg = messageBuilder.buildMessage( GuiActionType.BloodFlow, 4 * 7, False, + utils.toI32(vFlowSetPt ), + utils.toF32(vMeasFlow ), + utils.toF32(vRotSpd ), + utils.toF32(vMotSpd ), + utils.toF32(vMCSpd ), + utils.toF32(vMCCurr ), + utils.toF32(vPWM ) ) - return messageBuilder.toFrames(msg) - + return messageBuilder.toFrames(msg) ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setTreatmentBloodFlowRate(vFlowSetPt): +def setTreatmentBloodFlowRate(vFlowSetPt, vMeasFlow = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): frames = buildSetTreatmentBloodFlowRate(vFlowSetPt) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) - + waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildSetTreatmentDialysateFlowRate(vFlowSetPt, vMeasFlow = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): - msg = messageBuilder.buildMessage( 8, 4 * 7, - utils.toU32(vFlowSetPt ), - utils.toU32(vMeasFlow ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vRotSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMotSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMCSpd ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vMCCurr ), # it has to be F32 and at this moment I haven't implemented and I don't currently need it - utils.toU32(vPWM ) # it has to be F32 and at this moment I haven't implemented and I don't currently need it + msg = messageBuilder.buildMessage( GuiActionType.DialysateInletFlow, 4 * 7, False, + utils.toI32(vFlowSetPt ), + utils.toF32(vMeasFlow ), + utils.toF32(vRotSpd ), + utils.toF32(vMotSpd ), + utils.toF32(vMCSpd ), + utils.toF32(vMCCurr ), + utils.toF32(vPWM ) ) return messageBuilder.toFrames(msg) - ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def setTreatmentDialysateFlowRate(vFlowSetPt): +def setTreatmentDialysateFlowRate(vFlowSetPt, vMeasFlow = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): frames = buildSetTreatmentDialysateFlowRate(vFlowSetPt) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) - + waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildTreatmentAdjustBloodDialysateResponse(vAccepted, vReason, vBloodRate, vDialysate): - msg = messageBuilder.buildMessage( GuiActionType.AdjustBloodDialysateRsp, 4 * 4, - utils.toU32(vAccepted), - utils.toU32(vReason), - utils.toU32(vBloodRate), - utils.toU32(vDialysate) + msg = messageBuilder.buildMessage( GuiActionType.AdjustBloodDialysateRsp, 4 * 4, True, + utils.toI32(vAccepted), + utils.toI32(vReason), + utils.toI32(vBloodRate), + utils.toI32(vDialysate) ) return messageBuilder.toFrames(msg) - +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def sendTreatmentAdjustBloodDialysateResponse(vAccepted, vReason, vBloodRate, vDialysate): frames = buildTreatmentAdjustBloodDialysateResponse(vAccepted, vReason, vBloodRate, vDialysate) frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '020#{}'.format(frame)]) - + waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildTreatmentTime(vSecsTotal, vSecsElap, vSecsRem): - msg = messageBuilder.buildMessage( GuiActionType.TreatmentTime, 3 * 4, - utils.toU32(vSecsTotal ), - utils.toU32(vSecsElap ), - utils.toU32(vSecsRem ) + msg = messageBuilder.buildMessage( GuiActionType.TreatmentTime, 3 * 4, False, + utils.toI32(vSecsTotal ), + utils.toI32(vSecsElap ), + utils.toI32(vSecsRem ) ) return messageBuilder.toFrames(msg) ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -156,16 +165,57 @@ frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) - + waitForMessageToBeSent() + ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def buildSetTreatmentUltrafiltration(vRefUFVol, vMeasUFVol = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): + msg = messageBuilder.buildMessage( GuiActionType.DialysateOutletFlow, 4 * 7, False, + utils.toF32(vRefUFVol ), + utils.toF32(vMeasUFVol ), + utils.toF32(vRotSpd ), + utils.toF32(vMotSpd ), + utils.toF32(vMCSpd ), + utils.toF32(vMCCurr ), + utils.toF32(vPWM ) + ) + return messageBuilder.toFrames(msg) +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def setTreatmentUltrafiltration(vRefUFVol, vMeasUFVol = 0, vRotSpd = 0, vMotSpd = 0, vMCSpd = 0, vMCCurr = 0, vPWM = 0): + frames = buildSetTreatmentUltrafiltration(vRefUFVol, vMeasUFVol, vRotSpd, vMotSpd, vMCSpd, vMCCurr, vPWM) + frames = messageBuilder.toCandumpFormat(frames) + for frame in frames: + subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) + waitForMessageToBeSent() + +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def buildSetTreatmentPressureOcclusion(vArtPres, vVenPres, vBPOccl, vDIPOccl, vDOPOccl): + msg = messageBuilder.buildMessage( GuiActionType.PressureOcclusion, 4 * 5, False, + utils.toF32(vArtPres ), + utils.toF32(vVenPres ), + utils.toF32(vBPOccl ), + utils.toF32(vDIPOccl ), + utils.toF32(vDOPOccl ) + ) + return messageBuilder.toFrames(msg) +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +def setTreatmentPressureOcclusion(vArtPres = 0, vVenPres = 0, vBPOccl = 0, vDIPOccl = 0, vDOPOccl = 0): + frames = buildSetTreatmentPressureOcclusion(vArtPres, vVenPres, vBPOccl, vDIPOccl, vDOPOccl) + frames = messageBuilder.toCandumpFormat(frames) + for frame in frames: + subprocess.call(['cansend', 'can0', '040#{}'.format(frame)]) + waitForMessageToBeSent() + +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def buildAlarm(vState, vTop, vEsclatesIn, vSilentExpires, vFlags): - msg = messageBuilder.buildMessage( GuiActionType.AlarmStatus, 4 * 4 + 2, - utils.toU32(vState ), - utils.toU32(vTop ), - utils.toU32(vEsclatesIn ), - utils.toU32(vSilentExpires ), - utils.toU16(vFlags ) + msg = messageBuilder.buildMessage( GuiActionType.AlarmStatus, 4 * 4 + 2, False, + utils.toI32(vState ), + utils.toI32(vTop ), + utils.toI32(vEsclatesIn ), + utils.toI32(vSilentExpires ), + utils.toI16(vFlags ) ) return messageBuilder.toFrames(msg) ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -174,4 +224,4 @@ frames = messageBuilder.toCandumpFormat(frames) for frame in frames: subprocess.call(['cansend', 'can0', '001#{}'.format(frame)]) - + waitForMessageToBeSent()