コード例 #1
0
ファイル: brewpi.py プロジェクト: RonnyRoos/brewpi-script
 elif messageType == "refreshDeviceList":
     deviceList['listState'] = ""  # invalidate local copy
     if value.find("readValues") != -1:
         bg_ser.write("d{r:1}")  # request installed devices
         bg_ser.write("h{u:-1,v:1}"
                      )  # request available, but not installed devices
     else:
         bg_ser.write("d{}")  # request installed devices
         bg_ser.write(
             "h{u:-1}")  # request available, but not installed devices
 elif messageType == "getDeviceList":
     if deviceList['listState'] in ["dh", "hd"]:
         response = dict(board=hwVersion.board,
                         shield=hwVersion.shield,
                         deviceList=deviceList,
                         pinList=pinList.getPinList(
                             hwVersion.board, hwVersion.shield))
         conn.send(json.dumps(response))
     else:
         conn.send("device-list-not-up-to-date")
 elif messageType == "applyDevice":
     try:
         configStringJson = json.loads(
             value)  # load as JSON to check syntax
     except json.JSONDecodeError:
         logMessage("Error: invalid JSON parameter string received: " +
                    value)
         continue
     bg_ser.write("U" + json.dumps(configStringJson))
     deviceList['listState'] = ""  # invalidate local copy
 elif messageType == "writeDevice":
     try:
コード例 #2
0
ファイル: brewpi.py プロジェクト: jlvnyc/brewpi-brewometer
     python = sys.executable
     os.execl(python, python, *sys.argv)
 elif messageType == "refreshDeviceList":
     deviceList['listState'] = ""  # invalidate local copy
     if value.find("readValues") != -1:
         bg_ser.write("d{r:1}")  # request installed devices
         bg_ser.write("h{u:-1,v:1}")  # request available, but not installed devices
     else:
         bg_ser.write("d{}")  # request installed devices
         bg_ser.write("h{u:-1}")  # request available, but not installed devices
 elif messageType == "getDeviceList":
     if deviceList['listState'] in ["dh", "hd"]:
         response = dict(board=hwVersion.board,
                         shield=hwVersion.shield,
                         deviceList=deviceList,
                         pinList=pinList.getPinList(hwVersion.board, hwVersion.shield))
         conn.send(json.dumps(response))
     else:
         conn.send("device-list-not-up-to-date")
 elif messageType == "applyDevice":
     try:
         configStringJson = json.loads(value)  # load as JSON to check syntax
     except json.JSONDecodeError:
         logMessage("Error: invalid JSON parameter string received: " + value)
         continue
     bg_ser.write("U" + json.dumps(configStringJson))
     deviceList['listState'] = ""  # invalidate local copy
 elif messageType == "getVersion":
     if hwVersion:
         response = hwVersion.__dict__
         # replace LooseVersion with string, because it is not JSON serializable
コード例 #3
0
ファイル: brewpi.py プロジェクト: gkowalski/brewpi-script
        elif messageType == "refreshDeviceList":
            deviceList['listState'] = ""  # invalidate local copy
            if value.find("readValues") != -1:
                ser.write("d{r:1}")  # request installed devices
                serialRestoreTimeOut = ser.getTimeout()
                ser.setTimeout(2)  # set timeOut to 2 seconds because retreiving values takes a while
                ser.write("h{u:-1,v:1}")  # request available, but not installed devices
            else:
                ser.write("d{}")  # request installed devices
                ser.write("h{u:-1}")  # request available, but not installed devices
        elif messageType == "getDeviceList":
            if deviceList['listState'] in ["dh", "hd"]:
                response = dict(board=avrVersion.board,
                                shield=avrVersion.shield,
                                deviceList=deviceList,
                                pinList=pinList.getPinList(avrVersion.board, avrVersion.shield))
                conn.send(json.dumps(response))
            else:
                conn.send("device-list-not-up-to-date")
        elif messageType == "applyDevice":
            try:
                configStringJson = json.loads(value)  # load as JSON to check syntax
            except json.JSONDecodeError:
                logMessage("Error: invalid JSON parameter string received: " + value)
                continue
            ser.write("U" + value)
            deviceList['listState'] = ""  # invalidate local copy
        else:
            logMessage("Error: Received invalid message on socket: " + message)

        if (time.time() - prevTimeOut) < serialCheckInterval: