Пример #1
0
def getDeviceStatePayload():

    payload = drone.dronePayload(_log)

    for device in list_i2c_devices():
        payloadSub = drone.dronePayload(_log)
        sensor = sensors.Sensor(deviceName[device], device)
        sensor.connect()

        response = sensor.query(commands.INFO)
        deviceType = response.data.decode("utf-8").split(",")[1]
        payloadSub.add("Device", deviceType)
        payloadSub.add("Firmware", response.data.decode("utf-8").split(",")[2])

        response = sensor.query(Cal)
        payloadSub.add("Calibration Points",
                       response.data.decode("utf-8").split("?CAL,")[1])

        response = sensor.query(commands.STATUS)
        payloadSub.add(
            "Reason for restart",
            restartCodes[response.data.decode("utf-8").split(",")[1]])
        payloadSub.add("VoltageatVcc",
                       response.data.decode("utf-8").split(",")[2])

        response = sensor.query(commands.LED, arguments="?")
        payloadSub.add("LED",
                       ledStatus[response.data.decode("utf-8").split("L,")[1]])

        if (deviceType == "PMP"):
            response = sensor.query(PumpVoltage)
            payloadSub.add("Pump Voltage",
                           response.data.decode("utf-8").split("PV,")[1])
            response = sensor.query(TotalVolume)
            payloadSub.add("Total Volume",
                           response.data.decode("utf-8").split("TV,")[1])
            response = sensor.query(AbsoluteTotalVolume)
            payloadSub.add("Absolute Total Volume",
                           response.data.decode("utf-8").split("ATV,")[1])
            response = sensor.query(Parameters)
            payloadSub.add("Parameters",
                           response.data.decode("utf-8").split("O,")[1])
        else:
            response = sensor.query(commands.READ)
            payloadSub.add("Reading", response.data.decode("utf-8"))

        payload.add(sensor.name, payloadSub.getSub())

    stateJson = json.loads(payload.getWithSub())
    serializedState = json.dumps(stateJson, sort_keys=False, indent=3)
    return serializedState
Пример #2
0
 def test_query_with_args(self):
     device_file = io.BytesIO()
     i2c_client = atlas_i2c.AtlasI2C(device_file=device_file)
     i2c_client.query = Mock()
     response = atlas_i2c.CommandResponse()
     response.sensor_name = "test-sensor"
     response.sensor_address = 102
     response.original_command = "S,?"
     response.response_type = str
     response.response_data = "?S,c"
     i2c_client.query.return_value = response
     sensor = sensors.Sensor("test-sensor", i2c_client=i2c_client)
     result = sensor.query(commands.SCALE, arguments="?")
     assert isinstance(result, atlas_i2c.CommandResponse)
     assert result == response
Пример #3
0
def deviceCalibrationCommand(sDevice, sCommand):
    try:
        device_name = deviceName[int(sDevice)]
    except:
        return -1
    if (device_name is None):
        return -1
    try:
        sensor = sensors.Sensor(device_name, int(sDevice))
        sensor.connect()
    except:
        return -1
    try:
        response = sensor.query(CalAction, sCommand)
        if (response.status_code is None or str(response.status_code) != "1"):
            print("response.status_code =" +
                  responseCodes[response.status_code])
            return 0
        else:
            return 1
    except:
        return 0
Пример #4
0
from atlas_i2c import sensors
sensor = sensors.Sensor("Temperature", 102)
sensor.connect()
response = sensor.query(commands.READ)
print(response.data)
Пример #5
0
 def _setup(self, name, address):
     sensor = sensors.Sensor(name, address)
     sensor.connect()
     return sensor
Пример #6
0
 def test_query_with_nonexisting_command(self):
     device_file = io.BytesIO()
     i2c_client = atlas_i2c.AtlasI2C(device_file=device_file)
     sensor = sensors.Sensor("test-sensor", i2c_client=i2c_client)
     with pytest.raises(AttributeError) as ex:
         sensor.query("eat")
Пример #7
0
    dev = atlas_i2c.AtlasI2C()
    for device in deviceName.keys():
        try:
            dev = atlas_i2c.AtlasI2C()
            dev.set_i2c_address(device)
            dev.read("R")
            i2c_devices_attached.append(device)
            print("Found " + str(deviceName[device]))
        except IOError:
            pass
    return i2c_devices_attached


for device in list_i2c_devices():
    try:
        sensor = sensors.Sensor(deviceName[device], device)
    except:
        print("Error creating sensor " + str(deviceName[device]))
    try:
        sensor.connect()
    except:
        print("Error connecting sensor " + str(deviceName[device]))
    try:
        response = sensor.query(commands.INFO)
    except:
        print("Error query sensor " + str(deviceName[device]))
    try:
        print(response.data.decode("utf-8"))
    except:
        print("Error on decode data " + str(deviceName[device]))