def legacy_erase_calibration_cell(self, unit_index): ''' MIXBoard erase calibration unit Args: unit_index: int, calibration unit index. Returns: string, "done", api execution successful. Examples: board.erase_calibration_cell(0) ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( 'calibration unit memory unit_index data type is not int type or unit_index < 0' ) data = [0xff for i in range(ArmorCoeffDef.CAL_DATA_LEN)] address = self.calibration_info['unit_start_addr'] + \ ArmorCoeffDef.CAL_DATA_LEN * unit_index self.write_eeprom(address, data) return 'done'
def legacy_erase_calibration_cell(self, unit_index): ''' MIXBoard erase calibration unit Note: This function will not be used if ICI is support by module. Args: unit_index: int, calibration unit index. Returns: string, "done", api execution successful. Examples: board.erase_calibration_cell(1) ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( 'calibration unit memory unit_index data type is not int type or unit_index < 0' ) data = [0xff for i in range(WolverineiiCoeffDef.CAL_DATA_LEN)] address = self.calibration_info['unit_start_addr'] + \ WolverineiiCoeffDef.CAL_DATA_LEN * unit_index self.write_eeprom(address, data) return 'done'
def legacy_erase_calibration_cell(self, unit_index): ''' Erase calibration value in eeprom Args: unit_index: int, calibration unit index. Returns: string, "done", api execution successful, raise Exception at failure. Raise: BoardArgCheckError: unit_index < 0 or type is not int. :Examples: # erase the unit_index 0 calibration value in eeprom ret = dmm010001.erase_calibration_cell(0) # ret == "done" ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0") data = [0xff for i in range(DMM010Def.CAL_DATA_LEN)] address = self.calibration_info["unit_start_addr"] + DMM010Def.CAL_DATA_LEN * unit_index self.write_eeprom(address, data) return "done"
def legacy_read_calibration_cell(self, unit_index): ''' MIXBoard read calibration data Args: unit_index: int, calibration unit index. Returns: dict, {'gain': value, 'offset': value, 'threshold': value, 'is_use': value}. Examples: data = omega.legacy_read_calibration_cell(0) print(data) Raise: BoardArgCheckError: unit_index data type is not int type or unit_index < 0. calibration unit format: Meaning: Gain, Offset, threshold value, Use flag Mem size: 4Bytes, 4Bytes, 4Bytes, Byte Data type: float, float, float, uint8_t Formula: Y = Gain * X + Offset ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0" ) address = self.calibration_info[ "unit_start_addr"] + OmegaDef.CAL_DATA_LEN * unit_index data = self.read_eeprom(address, OmegaDef.READ_CAL_BYTE) s = struct.Struct(OmegaDef.READ_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(OmegaDef.READ_CAL_DATA_UNPACK_FORMAT) result = s.unpack(pack_data) threshold = 0.0 for cal_item in self.omega_calibration_info: for level in self.omega_calibration_info[cal_item]: if unit_index == self.omega_calibration_info[cal_item][level][ "unit_index"]: threshold = self.omega_calibration_info[cal_item][level][ "limit"][0] if self.calibration_info["use_flag"] != result[2]: return {"gain": 1.0, "offset": 0.0, "threshold": 0, "is_use": True} else: return { "gain": result[0], "offset": result[1], "threshold": threshold, "is_use": True }
def legacy_read_calibration_cell(self, cal_name, unit_index): ''' DarkBeastF read calibration data Args: cal_name: string, ['set_eload_current', 'set_orion_voltage', 'read_eload_current', 'read_orion_current', 'read_orion_voltage'], calibration name. unit_index: int, calibration unit index. Returns: dict, {"gain": value, "offset": value, "threshold": value, "is_use": value}. Examples: data = board.read_calibration_cell('set_eload_current', 0) print(data) Raises: BoardArgCheckError: unit_index < 0 or type is not int. calibration unit format: Meaning: Gain, Offset, threshold value, Use flag Mem size: 4Bytes, 4Bytes, 4Bytes, Byte Data type: float, float, float, uint8_t Formula: Y = Gain * X + Offset ''' assert cal_name in ["set_eload_current", "set_orion_voltage", "read_eload_current", "read_orion_current", "read_orion_voltage"] if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0") address = darkbeastf_calibration_base_addr[cal_name] + DarkBeastFDef.CAL_DATA_LEN * unit_index data = self.read_eeprom(address, DarkBeastFDef.READ_CAL_BYTE) s = struct.Struct(DarkBeastFDef.READ_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(DarkBeastFDef.READ_CAL_DATA_UNPACK_FORMAT) result = s.unpack(pack_data) use_flag = result[3] if self.calibration_info["use_flag"] != use_flag: return {"gain": 1.0, "offset": 0.0, "threshold": 0.0, "is_use": False} else: return {"gain": result[0], "offset": result[1], "threshold": result[2], "is_use": True}
def legacy_read_calibration_cell(self, unit_index): ''' Read calibration data function Args: unit_index: int, calibration unit index. Returns: dict, {"gain": value, "offset": value, "threshold": value, "is_use": value}. Raise: BoardArgCheckError: unit_index < 0 or type is not int. :Examples: # read unit_index 0 calibration value data = dmm010001.legacy_read_calibration_cell(0) # data = {"gain": 1.1, "offset": 0.1, "threshold": -1000, "is_use": true} print(data) ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0") address = self.calibration_info["unit_start_addr"] + \ DMM010Def.CAL_DATA_LEN * unit_index data = self.read_eeprom(address, DMM010Def.READ_CAL_BYTE) s = struct.Struct(DMM010Def.READ_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(DMM010Def.READ_CAL_DATA_UNPACK_FORMAT) result = s.unpack(pack_data) threshold = 0.0 for cal_item in dmm010_calibration_info.keys(): for level in dmm010_calibration_info[cal_item].keys(): if unit_index == dmm010_calibration_info[cal_item][level]["unit_index"]: threshold = dmm010_calibration_info[cal_item][level]["limit"][0] break if self.calibration_info["use_flag"] != result[2]: return {"gain": 1.0, "offset": 0.0, "threshold": 0, "is_use": False} else: return {"gain": result[0], "offset": result[1], "threshold": threshold, "is_use": True}
def legacy_write_calibration_cell(self, cal_name, unit_index, gain, offset, threshold): ''' DarkBeastF calibration data write Args: cal_name: string, ['set_eload_current', 'set_orion_voltage', 'read_eload_current', 'read_orion_current', 'read_orion_voltage'], calibration name. unit_index: int, calibration unit index. gain: float, calibration gain. offset: float, calibration offset. threshold: float, if value < threshold, use this calibration unit data. Returns: string, "done", api execution successful. Examples: board.write_calibration_cell(0, 1.1, 0.1, 1000, 'set_eload_current') Raises: BoardArgCheckError: unit_index < 0 or type is not int. calibration unit format: Meaning: Gain, Offset, threshold value, Use flag Mem size: 4Bytes, 4Bytes, 4Bytes, Byte Data type: float, float, float, uint8_t Formula: Y = Gain * X + Offset ''' assert cal_name in ["set_eload_current", "set_orion_voltage", "read_eload_current", "read_orion_current", "read_orion_voltage"] if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0") use_flag = self.calibration_info["use_flag"] data = (gain, offset, threshold, use_flag, 0xff, 0xff, 0xff) s = struct.Struct(DarkBeastFDef.WRITE_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(DarkBeastFDef.WRITE_CAL_DATA_UNPACK_FORMAT) data = s.unpack(pack_data) address = darkbeastf_calibration_base_addr[cal_name] + DarkBeastFDef.CAL_DATA_LEN * unit_index self.write_eeprom(address, data)
def legacy_write_calibration_cell(self, unit_index, gain, offset, threshold): ''' MIXBoard calibration data write Args: unit_index: int, calibration unit index. gain: float, calibration gain. offset: float, calibration offset. threshold: float, if value < threshold, use this calibration unit data. Returns: string, "done", api execution successful. Examples: board.write_calibration_cel(0, 1.1, 0.1, 100) Raise: BoardArgCheckError: unit_index data type is not int type or unit_index < 0. calibration unit format: Meaning: Gain, Offset, threshold value, Use flag Mem size: 4Bytes, 4Bytes, 4Bytes, Byte Data type: float, float, float, uint8_t Formula: Y = Gain * X + Offset ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( 'calibration unit memory unit_index data type is not int type or unit_index < 0' ) use_flag = self.calibration_info['use_flag'] data = (gain, offset, use_flag, 0xff, 0xff, 0xff, 0xff) s = struct.Struct(ArmorCoeffDef.WRITE_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(ArmorCoeffDef.WRITE_CAL_DATA_UNPACK_FORMAT) data = s.unpack(pack_data) address = self.calibration_info['unit_start_addr'] + \ ArmorCoeffDef.CAL_DATA_LEN * unit_index self.write_eeprom(address, data) return 'done'
def legacy_erase_calibration_cell(self, unit_index): ''' MIXBoard erase calibration unit Returns: string, "done", api execution successful. Examples: board.erase_calibration_cell(0) ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0" ) data = [0xff for i in range(9)] address = self.calibration_info["unit_start_addr"] + 9 * unit_index self.write_eeprom(address, data) return "done"
def legacy_write_calibration_cell(self, unit_index, gain, offset): ''' Calibration data write function Args: unit_index: int, calibration unit index. gain: float, calibration gain. offset: float, calibration offset. Returns: string, "done", api execution successful, raise Exception at failure. Raise: BoardArgCheckError: unit_index < 0 or type is not int. :Examples: # write calibration gain 1.1, offset 0.1 to unit index 0 ret = dmm010001.legacy_write_calibration_cell(0, 1.1, 0.1) # ret == "done" ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( "calibration unit memory unit_index data type is not int type or unit_index < 0") use_flag = self.calibration_info["use_flag"] data = (gain, offset, use_flag, 0xff, 0xff, 0xff) s = struct.Struct(DMM010Def.WRITE_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(DMM010Def.WRITE_CAL_DATA_UNPACK_FORMAT) data = s.unpack(pack_data) address = self.calibration_info["unit_start_addr"] + \ DMM010Def.CAL_DATA_LEN * unit_index self.write_eeprom(address, data) return "done"
def legacy_read_calibration_cell(self, unit_index): ''' MIXBoard read calibration data Args: unit_index: int, calibration unit index. Returns: dict, {"gain": value, "offset":value, "threshold": value, "is_use": value}. Examples: data = board.read_calibration_cel(0) print(data) Raise: BoardArgCheckError: unit_index data type is not int type or unit_index < 0. calibration unit format: Meaning: Gain, Offset, threshold value, Use flag Mem size: 4Bytes, 4Bytes, 4Bytes, Byte Data type: float, float, float, uint8_t Formula: Y = Gain * X + Offset ''' if not isinstance(unit_index, int) or unit_index < 0: raise BoardArgCheckError( 'calibration unit memory unit_index data type is not int type or unit_index < 0' ) address = self.calibration_info['unit_start_addr'] + \ ArmorCoeffDef.CAL_DATA_LEN * unit_index data = self.read_eeprom(address, ArmorCoeffDef.READ_CAL_BYTE) s = struct.Struct(ArmorCoeffDef.READ_CAL_DATA_PACK_FORMAT) pack_data = s.pack(*data) s = struct.Struct(ArmorCoeffDef.READ_CAL_DATA_UNPACK_FORMAT) result = s.unpack(pack_data) threshold = 0.0 for cal_type in armor_calibration_info.keys(): for level in armor_calibration_info[cal_type].keys(): if unit_index == armor_calibration_info[cal_type][level][ 'unit_index']: threshold = armor_calibration_info[cal_type][level][ 'limit'][0] break if self.calibration_info['use_flag'] != result[2]: return { 'gain': 1.0, 'offset': 0.0, 'threshold': 0, 'is_use': False } else: return { 'gain': result[0], 'offset': result[1], 'threshold': threshold, 'is_use': True }