Beispiel #1
0
def ProcessApplicationData(data):
    print("application data: ", Hexify(data))
    data = command.MaybePatchCommand(data)
    k = (data[0], data[1])
    table = z.SUBCMD_TO_PARSE_TABLE[k[0] * 256 + k[1]]
    print("parse table: ", table)

    value = command.ParseCommand(data)
    print(value)
    data2 = command.AssembleCommand(k, value)
    print("assembled data: ", Hexify(data2))
    assert data == data2
    def _HandleMessageApplicationCommand(self, ts, m):
        _ = m[4]  # status
        n = m[5]
        size = m[6]
        try:
            data = [int(x) for x in m[7:7 + size]]
            if len(data) < 2:
                logging.error("impossible short message: %s", repr(data))
                return
            data = command.MaybePatchCommand(data)
            value = command.ParseCommand(data)
            if value is None:
                logging.error("[%d] parsing failed for %s", n, Hexify(data))
                return
            # hack for multichannel devices
            if (data[0], data[1]) == z.MultiChannel_CapabilityReport:
                logging.warning("FOUND MULTICHANNEL ENDPOINT: %s", value)
                # fake node number
                n = MakeSplitMultiChannelNode(n, value["endpoint"])
                # fake NIF
                value["commands"] = value["classes"]
                value["controls"] = []
                self._PushToListeners(
                    n, ts, command.CUSTOM_COMMAND_APPLICATION_UPDATE,
                    value)
                return
            elif (data[0], data[1]) == z.MultiChannel_CmdEncap:
                n = MakeSplitMultiChannelNode(n, data[2])
                data = data[4:]
                value = command.ParseCommand(data)
        except Exception as e:
            logging.error("[%d] cannot parse: %s", n,
                          zmessage.PrettifyRawMessage(m))
            print("-" * 60)
            traceback.print_exc(file=sys.stdout)
            print("-" * 60)
            return

        self._PushToListeners(n, ts, (data[0], data[1]), value)
    def _HandleMessageApplicationCommand(self, ts, m):
        _ = m[4]  # status
        n = m[5]
        size = m[6]
        try:
            data = [int(x) for x in m[7:7 + size]]
            data = command.MaybePatchCommand(data)
            value = command.ParseCommand(data)
            if value is None:
                logging.error("[%d] parsing failed for %s", n, Hexify(data))
                return
        except Exception as _e:
            logging.error("[%d] cannot parse: %s", n,
                          zmessage.PrettifyRawMessage(m))
            print("-" * 60)
            traceback.print_exc(file=sys.stdout)
            print("-" * 60)
            return

        self._PushToListeners(n, ts, (data[0], data[1]), value)