Exemple #1
0
 def _api_frame(self, cmd, *args):
     schema = TX_COMMANDS[cmd]
     d = t.serialize(args, schema)
     data = t.uint8_t(cmd).serialize()
     self._seq = (self._seq % 255) + 1
     data += t.uint8_t(self._seq).serialize()
     data += t.uint8_t(0).serialize()
     data += t.uint16_t(len(d) + 5).serialize()
     data += d
     return data, self._seq
Exemple #2
0
    def write_parameter(self, id_, *args):
        try:
            if isinstance(id_, str):
                param = NetworkParameter[id_]
            else:
                param = NetworkParameter(id_)
        except (KeyError, ValueError):
            raise KeyError("Unknown parameter id: %s write request" % (id_, ))

        v = t.serialize(args, NETWORK_PARAMETER_SCHEMA[param])
        length = len(v) + 1
        return self._command(Command.write_parameter, length, param, v)
Exemple #3
0
    async def read_parameter(self, id_, *args):
        try:
            if isinstance(id_, str):
                param = NetworkParameter[id_]
            else:
                param = NetworkParameter(id_)
        except (KeyError, ValueError):
            raise KeyError("Unknown parameter id: %s" % (id_,))

        data = t.serialize(args, NETWORK_PARAMETER_SCHEMA[param])
        r = await self._command(Command.read_parameter, 1 + len(data), param, data)
        data = t.deserialize(r[2], NETWORK_PARAMETER_SCHEMA[param])[0]
        LOGGER.debug("Read parameter %s response: %s", param.name, data)
        return data