Index: leahi_dialin/common/msg_ids.py =================================================================== diff -u -re324174eeb74c1630c6e913e7dfb65246924cd1f -r87ffed5716c48332d6dc3c5f5a80660614d813c0 --- leahi_dialin/common/msg_ids.py (.../msg_ids.py) (revision e324174eeb74c1630c6e913e7dfb65246924cd1f) +++ leahi_dialin/common/msg_ids.py (.../msg_ids.py) (revision 87ffed5716c48332d6dc3c5f5a80660614d813c0) @@ -194,12 +194,46 @@ MSG_ID_TD_WATER_SAMPLE_DATA = 0xAC MSG_ID_TD_DRY_SELF_TEST_PROGRESS_DATA = 0xAD MSG_ID_TD_TUBE_SET_AUTHENTICATION_REQUEST = 0xAE - MSG_ID_UI_TUBE_SET_AUTHENTICATION_ACK_RESPONSE = 0xAF + MSG_ID_TD_TUBE_SET_AUTHENTICATION_REQUEST = 0xAF + MSG_ID_UI_TUBE_SET_AUTHENTICATION_ACK_RESPONSE = 0xB0 MSG_ID_TD_SYRINGE_PUMP_DATA = 0xB1 MSG_ID_TD_HEPARIN_PAUSE_RESUME_RESPONSE= 0xB2 MSG_ID_FFU_SIGNAL_TD_UPDATE_AVAILABLE = 0xB3 MSG_ID_FFU_SIGNAL_DD_UPDATE_AVAILABLE = 0xB4 - MSG_ID_DD_SUBSTITUTION_PUMP_DATA = 0xB5 + MSG_ID_TD_UI_CONFIRMATION_REQUEST = 0xB5 + MSG_ID_UI_CONFIRMATION_RESULT_RESPONSE = 0xB6 + MSG_ID_TD_POWER_OFF_REQUEST = 0xB7 + MSG_ID_UI_VITALS_ADJUSTMENT_REQUEST = 0xB8 + MSG_ID_TD_VITALS_ADJUSTMENT_RESPONSE = 0xB9 + MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST = 0xBA + MSG_ID_DD_NVM_SYSTEM_RECORD_RESPONSE = 0xBB + MSG_ID_UI_DD_NVM_SET_SYSTEM_RECORD = 0xBC + MSG_ID_DD_NVM_SERVICE_RECORD_RESPONSE = 0xBD + MSG_ID_DD_NVM_SET_SERVICE_RECORD = 0xBE + MSG_ID_DD_NVM_INSTITUTIONAL_RECORD_RESPONSE = 0xBF + MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD = 0xC0 + MSG_ID_DD_NVM_USAGE_INFO_RECORD_RESPONSE = 0xC1 + MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD = 0xC2 + MSG_ID_DD_NVM_CAL_PRESSURE_SENSOR_RESPONSE = 0xC3 + MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR = 0xC4 + MSG_ID_DD_NVM_CAL_TEMP_SENSOR_RESPONSE = 0xC5 + MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR = 0xC6 + MSG_ID_DD_NVM_CAL_CONC_PUMP_RESPONSE = 0xC7 + MSG_ID_DD_NVM_SET_CAL_CONC_PUMP = 0xC8 + MSG_ID_DD_NVM_CAL_D12_PUMP_RESPONSE = 0xC9 + MSG_ID_DD_NVM_SET_CAL_D12_PUMP = 0xCA + MSG_ID_DD_NVM_CAL_D48_PUMP_RESPONSE = 0xCB + MSG_ID_DD_NVM_SET_CAL_D48_PUMP = 0xCC + MSG_ID_DD_NVM_CAL_ACID_CONCENTRATE_RESPONSE = 0xCD + MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE = 0xCE + MSG_ID_DD_NVM_CAL_BICARB_CONCENTRATE_RESPONSE = 0xCF + MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE = 0xD0 + MSG_ID_DD_NVM_CAL_ACCEL_SENSOR_RESPONSE = 0xD1 + MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR = 0xD2 + MSG_ID_DD_NVM_CAL_BLOOD_LEAK_SENSOR_RESPONSE = 0xD3 + MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR = 0xD4 + MSG_ID_DD_NVM_RECORD_CRC_OVERRIDE_REQUEST = 0xD5 + MSG_ID_DD_SUBSTITUTION_PUMP_DATA = 0xD5 MSG_ID_DD_PISTON_PUMP_CONTROL_DATA = 0xF0 @@ -380,18 +414,6 @@ MSG_ID_DD_BICARB_CHAMBER_FILL_REQUEST_OVERRIDE_REQUEST = 0xA059 MSG_ID_DD_BICART_DRAIN_REQUEST_OVERRIDE_REQUEST = 0xA05A MSG_ID_DD_BICART_CARTRIDGE_SELECT_OVERRIDE_REQUEST = 0xA05B - MSG_ID_DD_NVM_GET_RECORD = 0xA05C - MSG_ID_DD_NVM_SEND_SYSTEM_RECORD = 0xA05D - MSG_ID_DD_NVM_SET_SYSTEM_RECORD = 0xA05E - MSG_ID_DD_NVM_SEND_SERVICE_RECORD = 0xA05F - MSG_ID_DD_NVM_SET_SERVICE_RECORD = 0xA060 - MSG_ID_DD_NVM_SEND_CALIBRATION_RECORD = 0xA061 - MSG_ID_DD_NVM_SET_CALIBRATION_RECORD = 0xA062 - MSG_ID_DD_NVM_SEND_INSTITUTIONAL_RECORD = 0xA063 - MSG_ID_DD_NVM_SET_INSTITUTIONAL_RECORD = 0xA064 - MSG_ID_DD_NVM_SEND_USAGE_INFO_RECORD = 0xA065 - MSG_ID_DD_NVM_SET_USAGE_INFO_RECORD = 0xA066 - MSG_ID_DD_FLOATER_LEVEL_OVERRIDE_REQUEST = 0xA06C MSG_ID_DD_SUBSTITUTION_PUMP_START_STOP_OVERRIDE_REQUEST = 0xA06D MSG_ID_DD_SUBSTITUTION_PUMP_BROADCAST_OVERRIDE_REQUEST = 0xA06E MSG_ID_DD_SUBSTITUTION_PUMP_TARGET_SPEED_OVERRIDE_REQUEST = 0xA06F Index: leahi_dialin/dd/modules/records.py =================================================================== diff -u -r8e8f0771536848eee49720b72ec44b4bf4eebf80 -r87ffed5716c48332d6dc3c5f5a80660614d813c0 --- leahi_dialin/dd/modules/records.py (.../records.py) (revision 8e8f0771536848eee49720b72ec44b4bf4eebf80) +++ leahi_dialin/dd/modules/records.py (.../records.py) (revision 87ffed5716c48332d6dc3c5f5a80660614d813c0) @@ -35,6 +35,15 @@ DD interface containing pressure related commands. """ + CALIB_RECORDS_PRESSURE_SENSORS = 'pressure_sensors' + CALIB_RECORDS_TEMPERATURE_SENSORS = 'temperature_sensors' + CALIB_RECORDS_CONCENTRATE_PUMPS = 'concentrate_pump' + CALIB_RECORDS_DIALYSATE_PUMPS = 'dialysate_pumps' + CALIB_RECORDS_ACID_CONCENTRATE = 'acid_concentrate' + CALIB_RECORDS_BICARB_CONCENTRATE = 'bicarb_concentrate' + CALIB_RECORDS_ACCELEROMETER = 'accelerometer' + CALIB_RECORDS_BLOOD_LEAK = 'blood_leak' + def __init__(self, can_interface: CanMessenger, logger: Logger): """ @param can_interface: The CanMessenger object @@ -45,19 +54,43 @@ if self.can_interface is not None: self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, - message_id = MsgIds.MSG_ID_DD_NVM_SEND_SYSTEM_RECORD.value, + message_id = MsgIds.MSG_ID_DD_NVM_SYSTEM_RECORD_RESPONSE.value, function = self._handler_system_record_sync) self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, - message_id = MsgIds.MSG_ID_DD_NVM_SEND_SERVICE_RECORD.value, + message_id = MsgIds.MSG_ID_DD_NVM_SERVICE_RECORD_RESPONSE.value, function = self._handler_service_record_sync) self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, - message_id = MsgIds.MSG_ID_DD_NVM_SEND_CALIBRATION_RECORD.value, - function = self._handler_calibration_record_sync) + message_id = MsgIds.MSG_ID_DD_NVM_CAL_PRESSURE_SENSOR_RESPONSE.value, + function = self._handler_calibration_record_pres_sensor_sync) self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, - message_id = MsgIds.MSG_ID_DD_NVM_SEND_INSTITUTIONAL_RECORD.value, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_TEMP_SENSOR_RESPONSE.value, + function = self._handler_calibration_record_temp_sensor_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_CONC_PUMP_RESPONSE.value, + function = self._handler_calibration_record_conc_pump_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_D12_PUMP_RESPONSE.value, + function = self._handler_calibration_record_dial_pump_d12_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_D48_PUMP_RESPONSE.value, + function = self._handler_calibration_record_dial_pump_d48_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_ACID_CONCENTRATE_RESPONSE.value, + function = self._handler_calibration_record_acid_conc_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_BICARB_CONCENTRATE_RESPONSE.value, + function = self._handler_calibration_record_bicarb_conc_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_ACCEL_SENSOR_RESPONSE.value, + function = self._handler_calibration_record_accelerometer_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_CAL_BLOOD_LEAK_SENSOR_RESPONSE.value, + function = self._handler_calibration_record_blood_leak_sync) + self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, + message_id = MsgIds.MSG_ID_DD_NVM_INSTITUTIONAL_RECORD_RESPONSE.value, function = self._handler_institutional_record_sync) self.can_interface.register_receiving_publication_function(channel_id = CanChannels.dd_sync_broadcast_ch_id, - message_id = MsgIds.MSG_ID_DD_NVM_SEND_USAGE_INFO_RECORD.value, + message_id = MsgIds.MSG_ID_DD_NVM_USAGE_INFO_RECORD_RESPONSE.value, function = self._handler_usage_info_record_sync) self.system_records_timestamp = 0 #: The timestamp of the latest System Records message @@ -127,7 +160,7 @@ record_list.append((name, sys_record.datatype)) result_payload = self.process_into_vars(decoder_list = record_list, message = message, - start_from_byte = len(msg_list) * DataTypes.U32.size) + start_from_byte = len(msg_list) * DataTypes.U32.size()) # Saving data into System Records self.system_records[dd_enum_repository.SystemRecordFields.TOP_LEVEL_PN.name] = '' @@ -174,26 +207,208 @@ self.service_records_timestamp = timestamp - @publish(["msg_id_dd_nvm_send_calibration_record", "calibration_records", "calibration_records_timestamp"]) - def _handler_calibration_record_sync(self, message, timestamp = 0.0): + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_pres_sensor_sync(self, message, timestamp = 0.0): """ - Handles published DD Calibration Record data messages. DD Calibration Records are captured - for reference. + Handles published DD Calibration Record Pressure Sensor Details data messages. + DD Calibration Records Pressure Sensor Details are captured for reference. @param message: published data message @return: none """ + # Get the sensor_id to identify the location of the payload + msg_list = [('sensor_id', DataTypes.U08)] + result = self.process_into_vars(decoder_list = msg_list, + message = message) + sensor_name = dd_enum_repository.DDPressureSensorNames(result['sensor_id']).name + record_list = [] - for member in dd_enum_repository.CalibrationRecordFields: - record_list.append((member.name, member.datatype)) + for member in dd_enum_repository.CalibRecordSensorFields: + record_list.append((self.CALIB_RECORDS_PRESSURE_SENSORS, sensor_name, member.name, member.datatype)) - self.process_into_dict(dict_to_update = self.service_records, + self.process_into_dict(dict_to_update = self.calibration_records, decoder_list = record_list, + message = message, + start_from_byte = len(msg_list) * DataTypes.U08.size()) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_temp_sensor_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Temperature Sensor Details data messages. + DD Calibration Records Temperature Sensor Details are captured for reference. + + @param message: published data message + @return: none + """ + # Get the sensor_id to identify the location of the payload + msg_list = [('sensor_id', DataTypes.U08)] + result = self.process_into_vars(decoder_list = msg_list, + message = message) + sensor_name = dd_enum_repository.DDTemperatureSensorNames(result['sensor_id']).name + + record_list = [] + for member in dd_enum_repository.CalibRecordSensorFields: + record_list.append((self.CALIB_RECORDS_TEMPERATURE_SENSORS, sensor_name, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message, + start_from_byte = len(msg_list) * DataTypes.U08.size()) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_conc_pump_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Concentrate Pump Details data messages. + DD Calibration Records Concentrate Pump Details are captured for reference. + + @param message: published data message + @return: none + """ + # Get the sensor_id to identify the location of the payload + msg_list = [('sensor_id', DataTypes.U08)] + result = self.process_into_vars(decoder_list = msg_list, + message = message) + sensor_name = dd_enum_repository.DDConcentratePumpNames(result['sensor_id']).name + + record_list = [] + for member in dd_enum_repository.CalibRecordSensorFields: + record_list.append((self.CALIB_RECORDS_CONCENTRATE_PUMPS, sensor_name, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message, + start_from_byte = len(msg_list) * DataTypes.U08.size()) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_dial_pump_d12_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Dialysate Pump D12 Details data messages. + DD Calibration Records Dialysate Pump D12 Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + record_list.append((self.CALIB_RECORDS_DIALYSATE_PUMPS, dd_enum_repository.DDDialysatePumpNames.D12_PUMP.name, 'target_speed', DataTypes.F32)) + for member in dd_enum_repository.CalibRecordSensorFields: + record_list.append((self.CALIB_RECORDS_DIALYSATE_PUMPS, dd_enum_repository.DDDialysatePumpNames.D12_PUMP.name, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, message = message) self.calibration_records_timestamp = timestamp + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_dial_pump_d48_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Dialysate Pump D48 Details data messages. + DD Calibration Records Dialysate Pump D48 Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + for member in dd_enum_repository.CalibRecordSensorFields: + record_list.append((self.CALIB_RECORDS_DIALYSATE_PUMPS, dd_enum_repository.DDDialysatePumpNames.D48_PUMP.name, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_acid_conc_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Acid Concentrate Details data messages. + DD Calibration Records Acid Concentrate Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + for member in dd_enum_repository.CalibRecordConcentrateFields: + record_list.append((self.CALIB_RECORDS_ACID_CONCENTRATE, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_bicarb_conc_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Bicarb Concentrate Details data messages. + DD Calibration Records Bicarb Concentrate Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + for member in dd_enum_repository.CalibRecordConcentrateFields: + record_list.append((self.CALIB_RECORDS_BICARB_CONCENTRATE, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_accelerometer_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Accelerometer Details data messages. + DD Calibration Records Accelerometer Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + for member in dd_enum_repository.CalibRecordAccelerometerFields: + record_list.append((self.CALIB_RECORDS_ACCELEROMETER, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message) + + self.calibration_records_timestamp = timestamp + + + @publish(["msg_id_dd_nvm_send_cal_pressure_sensor", "calibration_records", "calibration_records_timestamp"]) + def _handler_calibration_record_blood_leak_sync(self, message, timestamp = 0.0): + """ + Handles published DD Calibration Record Blood Leak Details data messages. + DD Calibration Records Blood Leak Details are captured for reference. + + @param message: published data message + @return: none + """ + record_list = [] + for member in dd_enum_repository.CalibRecordBloodLeakFields: + record_list.append((self.CALIB_RECORDS_BLOOD_LEAK, member.name, member.datatype)) + + self.process_into_dict(dict_to_update = self.calibration_records, + decoder_list = record_list, + message = message) + + self.calibration_records_timestamp = timestamp + + @publish(["msg_id_dd_nvm_send_institutional_record", "institutional_records", "institutional_records_timestamp"]) def _handler_institutional_record_sync(self, message, timestamp = 0.0): """ @@ -212,12 +427,11 @@ record_list = [] record_list.append((member.name, member.datatype)) - record_list.append((dd_enum_repository.InstitutionalRecordFields.CALIBRATION_TIME.name, dd_enum_repository.InstitutionalRecordFields.datatype)) - self.process_into_dict(dict_to_update = self.service_records, + self.process_into_dict(dict_to_update = self.institutional_records, decoder_list = record_list, message = message, - start_from_byte = len(record_list) * DataTypes.U08.size) + start_from_byte = len(record_list) * DataTypes.U08.size()) self.institutional_records_timestamp = timestamp @@ -284,7 +498,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_GET_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, entity_name = f'DD System Record request', override_text = '', logger = self.logger, @@ -306,7 +520,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_GET_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, entity_name = f'DD Service Record request', override_text = '', logger = self.logger, @@ -328,7 +542,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_GET_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, entity_name = f'DD Calibration Record request', override_text = '', logger = self.logger, @@ -350,7 +564,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_GET_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, entity_name = f'DD Institutional Record request', override_text = '', logger = self.logger, @@ -372,7 +586,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_GET_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_GET_RECORD_REQUEST, entity_name = f'DD Usage Information Record request', override_text = '', logger = self.logger, @@ -412,7 +626,7 @@ payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, - msg_id = MsgIds.MSG_ID_DD_NVM_SET_SYSTEM_RECORD, + msg_id = MsgIds.MSG_ID_UI_DD_NVM_SET_SYSTEM_RECORD, entity_name = f'New DD System Record', override_text = 'being set', logger = self.logger, @@ -460,60 +674,61 @@ @return: 1 if successful, zero otherwise """ msg_id_pairing = { - 'pressure_sensors': MsgIds.TBD, - 'temperature_sensors': MsgIds.TBD, - 'concentrate_pumps': MsgIds.TBD, - 'dialysate_pumps': MsgIds.TBD, - 'acid': MsgIds.TBD, - 'bicarb': MsgIds.TBD, - 'accelerometer': MsgIds.TBD, - 'blood_leak': MsgIds.TBD, + self.CALIB_RECORDS_PRESSURE_SENSORS: MsgIds.MSG_ID_DD_NVM_SET_CAL_PRESSURE_SENSOR, + self.CALIB_RECORDS_TEMPERATURE_SENSORS: MsgIds.MSG_ID_DD_NVM_SET_CAL_TEMP_SENSOR, + self.CALIB_RECORDS_CONCENTRATE_PUMPS: MsgIds.MSG_ID_DD_NVM_SET_CAL_D48_PUMP, + self.CALIB_RECORDS_DIALYSATE_PUMPS: MsgIds.MSG_ID_DD_NVM_SET_CAL_CONC_PUMP, + self.CALIB_RECORDS_ACID_CONCENTRATE: MsgIds.MSG_ID_DD_NVM_SET_CAL_ACID_CONCENTRATE, + self.CALIB_RECORDS_BICARB_CONCENTRATE: MsgIds.MSG_ID_DD_NVM_SET_CAL_BICARB_CONCENTRATE, + self.CALIB_RECORDS_ACCELEROMETER: MsgIds.MSG_ID_DD_NVM_SET_CAL_ACCEL_SENSOR, + self.CALIB_RECORDS_BLOOD_LEAK: MsgIds.MSG_ID_DD_NVM_SET_CAL_BLOOD_LEAK_SENSOR, } # Make a dictionary to store all the send functions for later send send_data = [] for key in calibration_records: - if key.lower() in ['pressure_sensors', 'temperature_sensors', 'concentrate_pumps', 'dialysate_pumps']: + if key.lower() in [self.CALIB_RECORDS_PRESSURE_SENSORS, self.CALIB_RECORDS_TEMPERATURE_SENSORS, self.CALIB_RECORDS_CONCENTRATE_PUMPS, self.CALIB_RECORDS_DIALYSATE_PUMPS]: for sensor in calibration_records[key]: - # Store the function but do not execute it - send_data.append(partial(self.cmd_set_calibration_records_sensor(sensor_enum = sensor, - msg_id = msg_id_pairing[key], - forth_order_coeff = calibration_records[key][sensor]['forth_order_coeff'], - third_order_coeff = calibration_records[key][sensor]['third_order_coeff'], - second_order_coeff = calibration_records[key][sensor]['second_order_coeff'], - gain = calibration_records[key][sensor]['gain'], - offset = calibration_records[key][sensor]['offset'], - calibration_time = calibration_records[key][sensor]['calibration_time']))) - elif key.lower() in ['dialysate_pumps']: + # Exception handling as D12 has an extra field (target speed) + if sensor in [dd_enum_repository.DDDialysatePumpNames.D12_PUMP]: + # Store the function but do not execute it + send_data.append(partial(self.cmd_set_calibration_records_sensor(sensor_enum = sensor, + msg_id = MsgIds.MSG_ID_DD_NVM_SET_CAL_D12_PUMP, + dialysate_pump_target_speed = calibration_records[key][sensor]['target_speed'], + forth_order_coeff = calibration_records[key][sensor]['forth_order_coeff'], + third_order_coeff = calibration_records[key][sensor]['third_order_coeff'], + second_order_coeff = calibration_records[key][sensor]['second_order_coeff'], + gain = calibration_records[key][sensor]['gain'], + offset = calibration_records[key][sensor]['offset'], + calibration_time = calibration_records[key][sensor]['calibration_time']))) + else: + # Store the function but do not execute it + send_data.append(partial(self.cmd_set_calibration_records_sensor(sensor_enum = sensor, + msg_id = msg_id_pairing[key], + forth_order_coeff = calibration_records[key][sensor]['forth_order_coeff'], + third_order_coeff = calibration_records[key][sensor]['third_order_coeff'], + second_order_coeff = calibration_records[key][sensor]['second_order_coeff'], + gain = calibration_records[key][sensor]['gain'], + offset = calibration_records[key][sensor]['offset'], + calibration_time = calibration_records[key][sensor]['calibration_time']))) + elif key.lower() in [self.CALIB_RECORDS_ACID_CONCENTRATE, self.CALIB_RECORDS_BICARB_CONCENTRATE]: for sensor in calibration_records[key]: # Store the function but do not execute it - send_data.append(partial(self.cmd_set_calibration_records_sensor(sensor_enum = sensor, - msg_id = msg_id_pairing[key], - dialysate_pump_target_speed = calibration_records[key][sensor]['target_speed'], - forth_order_coeff = calibration_records[key][sensor]['forth_order_coeff'], - third_order_coeff = calibration_records[key][sensor]['third_order_coeff'], - second_order_coeff = calibration_records[key][sensor]['second_order_coeff'], - gain = calibration_records[key][sensor]['gain'], - offset = calibration_records[key][sensor]['offset'], - calibration_time = calibration_records[key][sensor]['calibration_time']))) - elif key.lower() in ['acid', 'bicarb']: - for sensor in calibration_records[key]: - # Store the function but do not execute it send_data.append(partial(self.cmd_set_calibration_records_concentrate(msg_id = msg_id_pairing[key], concentrate_mix_ratio = calibration_records[key][sensor]['concentrate_mix_ratio'], volume_ml = calibration_records[key][sensor]['volume_ml'], conductivity_uspcm = calibration_records[key][sensor]['conductivity_uspcm'], temperature_c = calibration_records[key][sensor]['temperature_c'], calibration_time = calibration_records[key][sensor]['calibration_time']))) - elif key.lower() in ['accelerometer']: + elif key.lower() in [self.CALIB_RECORDS_ACCELEROMETER]: for sensor in calibration_records[key]: # Store the function but do not execute it send_data.append(partial(self.cmd_set_calibration_records_accelerometer(msg_id = msg_id_pairing[key], accel_x_offset = calibration_records[key][sensor]['accel_x_offset'], accel_y_offset = calibration_records[key][sensor]['accel_y_offset'], accel_z_offset = calibration_records[key][sensor]['accel_z_offset'], calibration_time = calibration_records[key][sensor]['calibration_time']))) - elif key.lower() in ['blood_leak']: + elif key.lower() in [self.CALIB_RECORDS_BLOOD_LEAK]: for sensor in calibration_records[key]: # Store the function but do not execute it send_data.append(partial(self.cmd_set_calibration_records_blood_leak(msg_id = msg_id_pairing[key], @@ -546,16 +761,38 @@ """ # Make a dictionary to store all the send functions for later send send_data = [] - for key in institutional_records: - payload = integer_to_bytearray(key.value) - if key.datatype() in [DataTypes.U32, DataTypes.BOOL, DataTypes.S32]: - payload += integer_to_bytearray(institutional_records[key]) - elif key.datatype() in [DataTypes.F32]: - payload += float_to_bytearray(institutional_records[key]) - elif key.datatype() in [DataTypes.U08, DataTypes.BOOL_U08]: - payload += byte_to_bytearray(institutional_records[key]) - payload += short_to_bytearray(crc16_modbus(payload)) + total_payload = b'' + for record_enum in dd_enum_repository.InstitutionalRecordFields: + if record_enum in institutional_records: + value = institutional_records[record_enum] + else: + # Set default values if it's missing from the provided dictionary + if record_enum.datatype() in [DataTypes.U32, DataTypes.BOOL, DataTypes.S32, DataTypes.U16, DataTypes.U08, DataTypes.BOOL_U08]: + value = 0 + elif record_enum.datatype() in [DataTypes.F32]: + value = 0.0 + # Set the enum_id to identify which parameter is being sent U08 - 1 byte - 0->255 !! + payload = byte_to_bytearray(record_enum.value) + + # Calculate the CRC for the total institutional record (should be the last message) + if record_enum == dd_enum_repository.InstitutionalRecordFields.CRC: + payload += short_to_bytearray(crc16_modbus(total_payload)) + + # Else just send the data + elif record_enum.datatype() in [DataTypes.U32, DataTypes.BOOL, DataTypes.S32]: + payload += integer_to_bytearray(value) + total_payload += integer_to_bytearray(value) + elif record_enum.datatype() in [DataTypes.F32]: + payload += float_to_bytearray(value) + total_payload += float_to_bytearray(value) + elif record_enum.datatype() in [DataTypes.U16]: + payload += short_to_bytearray(value) + total_payload += short_to_bytearray(value) + elif record_enum.datatype() in [DataTypes.U08, DataTypes.BOOL_U08]: + payload += byte_to_bytearray(value) + total_payload += byte_to_bytearray(value) + send_data.append(partial(cmd_generic_override(payload = payload, reset = None, channel_id = CanChannels.dialin_to_dd_ch_id, Index: leahi_dialin/utils/abstract_classes.py =================================================================== diff -u -r78b7d4b47c77f390fdb0c796e4861cc9abb343fd -r87ffed5716c48332d6dc3c5f5a80660614d813c0 --- leahi_dialin/utils/abstract_classes.py (.../abstract_classes.py) (revision 78b7d4b47c77f390fdb0c796e4861cc9abb343fd) +++ leahi_dialin/utils/abstract_classes.py (.../abstract_classes.py) (revision 87ffed5716c48332d6dc3c5f5a80660614d813c0) @@ -135,6 +135,7 @@ # Content of the decode list key_1 = decode_details[0] key_2 = decode_details[1] if len(decode_details) >= 3 else None + key_3 = decode_details[2] if len(decode_details) >= 4 else None datatype: DataTypes = decode_details[-1] end_pos = start_pos + datatype.size() @@ -154,7 +155,15 @@ if len(decode_details) == 2: dict_to_update[key_1] = value elif len(decode_details) == 3: + if key_1 not in dict_to_update: + dict_to_update[key_1] = {} dict_to_update[key_1][key_2] = value + elif len(decode_details) == 4: + if key_1 not in dict_to_update: + dict_to_update[key_1] = {} + if key_2 not in dict_to_update[key_1]: + dict_to_update[key_1][key_2] = {} + dict_to_update[key_1][key_2][key_3] = value start_pos = end_pos if debug: print('Finished cycle\n')