Exemplo n.º 1
0
def calibration_float10_write(ee_profile, address, gain, offset):
    """ Calibration data write 
         Compatible with the old case.
         {float gain,float offset,uint8_t flag,uint8_t dummy,uint8_t dummy,uint8_t dummy}

         Args:
            ee_profile: dict type, the eeprom profile which calibration data stored
            address: the starting address
            gain:   float data
            offset: float data

         Returns:
            bool: True | False, True for success, False for adc read failed
    """
    data = (gain, offset)
    s = struct.Struct("2f")
    pack_data = s.pack(*data)

    s = struct.Struct("8B")
    data = s.unpack(pack_data)
    checksum = 0x00
    for i in range(len(data)):
        checksum += data[i]
    data_byte = list(data)
    data_byte.append(checksum & 0xff)
    data_byte.append((checksum >> 8) & 0xff)
    result = Eeprom.write(ee_profile, address, data_byte)

    return result
Exemplo n.º 2
0
def eeprom_write(module_name, addr, data):
    """ write  a list data  by the defined profile
        
        Args:
            module_name: the key of Dictionary which can get the hardware profile.for example: "dmm-module-1"
            addr: which  addr will be write data in. 
            data: data type is list.
            
        Returns:
            bool: The return value. True for success, False otherwise.
            
    """
    try:
        profile = Profile.get_eeprom_by_name(module_name)
        result = Eeprom.write(profile, addr, data)
    except Exception as e:
        logger.error("execute module  eeprom_write  False:" + repr(e))
        return False
    return result
Exemplo n.º 3
0
def calibration_double_write(ee_profile, address, gain, offset):
    """ Calibration data write  
         {double gain,double offset,uint8_t flag}

         Args:
            ee_profile: dict type, the eeprom profile which calibration data stored
            address: the starting address
            gain: doble data
            offset: double data

        Returns:
            bool: True | False, True for success, False for adc read failed
    """
    data = (gain, offset, 0x5a)
    s = struct.Struct("2dB")
    pack_data = s.pack(*data)

    s = struct.Struct("17B")
    data = s.unpack(pack_data)
    result = Eeprom.write(ee_profile, address, data)

    return result
Exemplo n.º 4
0
def calibration_float12_write(ee_profile, address, gain, offset):
    """ Calibration data write 
         Compatible with the old case.
         {float gain,float offset,uint8_t flag,uint8_t dummy,uint8_t dummy,uint8_t dummy}

         Args:
            ee_profile: dict type, the eeprom profile which calibration data stored
            address: the starting address
            gain:   float data
            offset: float data

         Returns:
            bool: True | False, True for success, False for adc read failed
    """
    data = (gain, offset, 0x5a, 0xff, 0xff, 0xff)
    s = struct.Struct("2f4B")
    pack_data = s.pack(*data)

    s = struct.Struct("12B")
    data = s.unpack(pack_data)
    result = Eeprom.write(ee_profile, address, data)

    return result