示例#1
0
    def read_temp_sensor(sensorId):
        #insertDebugLog(NOTICE, "Read temp sensor: {}".format(sensorId), CDH, int(time.time()))

        if not SensorManager.isCorrectSensor(sensorId, TEMP):
            raise Exception('Incorrect sensor specified')
            insertDebugLog(NOTICE, "Incorrect sensor specified: {}".format(sensorId),
            CDH, int(time.time()))
            return None

        addr = SensorEntropy.addr(sensorId)
        if sensorId == TEMP_PAYLOAD_A or sensorId == TEMP_PAYLOAD_B:
            bus = SensorManager.payloadbus
        else:
            SensorManager.mux_select(sensorId)
            bus = SensorManager.bus

        try:
            bus.write_byte(addr, SensorEntropy.reg(TEMP)[VAL])
        except(IOError, OSError):
            print("[READ] Error writing to temperature sensor: {}".format(sensorId))
            insertDebugLog(NOTICE, "[READ] Error writing to temperature sensor: {}".format(sensorId),
            CDH, int(time.time()))
            return None
        try:
            decValue = bus.read_byte(addr)
            fractValue = bus.read_byte(addr)
            sleep(0.02)
        except(IOError, OSError):
            print('[READ] Error reading from temperature sensor at address ' + \
                str(addr))
            insertDebugLog(NOTICE, "[READ] Error reading from temperature sensor: {}".format(sensorId),
            CDH, int(time.time()))
            return None

        # Log data
        value = utility.conv_bin_to_float(decValue, fractValue)
        sub = SensorEntropy.subsystem(sensorId)
        insertTelemetryLog(sensorId, value, sub, int(time.time()))
        return value
示例#2
0
    def read_payload(experiment, sensorId):

        addr = SensorEntropy.addr(ADC)
        adc_reg = SensorEntropy.reg(ADC)
        bus = SensorManager.payloadbus

        try:
            bus.write_byte(addr, adc_reg['READ_REG_BASE'] + experiment)
            strain = ((bus.read_byte(addr) << 8) | (bus.read_byte(addr))) & 0xFFF0
            strain = strain >> 4

            bus.write_byte(addr, adc_reg['READ_REG_BASE'] + experiment + 1)
            force = ((bus.read_byte(addr) << 8) | (bus.read_byte(addr))) & 0xFFF0
            force = force >> 4

            bus.write_byte(addr, adc_reg['READ_REG_BASE'] + 7)
            temp = ((bus.read_byte(addr) << 8) | (bus.read_byte(addr))) & 0xFF80
            temp = temp >> 7

        except(IOError, OSError):
            print('[READ] Error reading payload')
            insertDebugLog(NOTICE, "[READ] Error reading payload",
            PAYLOAD, int(time.time()))
            return None, None, None

        if temp & 0x100 == 0:
            temp /= 2.
        else:
            temp = -((512 - temp) / 2.)

        sleep(0.01)

        addr = SensorEntropy.addr(sensorId)
        if sensorId == TEMP_PAYLOAD_A or sensorId == TEMP_PAYLOAD_B:
            bus = SensorManager.payloadbus
        else:
            SensorManager.mux_select(sensorId)
            bus = SensorManager.bus

        try:
            bus.write_byte(addr, SensorEntropy.reg(TEMP)[VAL])
        except(IOError, OSError):
            print("[READ] Error writing to temperature sensor: {}".format(sensorId))
            insertDebugLog(NOTICE, "[READ] Error writing to temperature sensor: {}".format(sensorId),
            PAYLOAD, int(time.time()))
            return None
        try:
            decValue = bus.read_byte(addr)
            fractValue = bus.read_byte(addr)
            sleep(0.02)
        except(IOError, OSError):
            print('[READ] Error reading from temperature sensor at address ' + \
                str(addr))
            insertDebugLog(NOTICE, "[READ] Error reading from temperature sensor: {}".format(sensorId),
            PAYLOAD, int(time.time()))
            return None

        # Log data
        heater_temp = utility.conv_bin_to_float(decValue, fractValue)

        # Log data
        value = (strain, force, heater_temp, temp)
        insertTelemetryLog(PAYLOAD_ID, value, PAYLOAD, int(time.time()))
        return value