def __init__(self, byteCodeId=None, data=None): if data != None: Packet.__init__(self, b"\x5A", b"\xA5", byteCodeId) self.__data = data else: length = len(byteCodeId) if length >= 8: if byteCodeId[0]== b"\x5A" and byteCodeId[1]== b"\xA5": Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4]) self.__data = byteCodeId[4:length-2] #print("com1:", self.__commandCode0) #print("com2:", self.__commandCode1) #print("Id:", self.__deviceId) #print("rawData:", self.__data) #checkRec = bytearray(byteCode)[length-2] + bytearray(byteCode)[length-1] #print("checkRec:", checkRec) #print("checkRec:", receivedByteArray[length-2:length]) #checkCalc = bytearray(super.getCheckSum())[0]+ bytearray(super.getCheckSum())[1] #print("checkCalc:", checkCalc) #print("checkCalc:", self.getCheckSum()) #if self.getCheckSum() != receivedByteArray[length-1:length]: #if checkRec != checkCalc: if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]: raise SensorException(CHECKSUM_ERROR, DATA_PACK_ERROR) else: raise SensorException(PACKET_HEADER_ERROR,DATA_PACK_ERROR) else: raise SensorException(LENGTH_ERROR, DATA_PACK_ERROR)
def __init__(self, byteCodeId=None, comResp=None, parameter=None): if comResp != None: #super().__init__(b"\x55", b"\xAA", byteCodeId) Packet.__init__(self, b"\x55", b"\xAA", byteCodeId) self.__parameter = parameter self.__comResp = comResp else: length = len(byteCodeId) if length == 12: if byteCodeId[0]== b"\x55" and byteCodeId[1]== b"\xAA": Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4]) self.__parameter = byteCodeId[4:8] self.__comResp = byteCodeId[8:10] #print("com1:", self.__commandCode0) #print("com2:", self.__commandCode1) #print("deviceId:", self.__deviceId) #print("parameter:", self.__parameter) #print("comResp:", self.__comResp) #print("check:", receivedByteArray[10:12]) #print("checkCalc:",self.getCheckSum()) if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]: raise SensorException(CHECKSUM_ERROR, COMMAND_PACK_ERROR) else: raise SensorException(PACKET_HEADER_ERROR, COMMAND_PACK_ERROR) else: raise SensorException(LENGTH_ERROR, COMMAND_PACK_ERROR)
def __init__(self,main, data): Packet.__init__(self, 06,data) self.main = main
def __init__(self, *arguments, **kw): if len(arguments) == 0: Packet.__init__(self) else: Packet.__init__(self, self.VERSION, arguments[0], self.__class__._id, 0, *arguments[1:], **kw)
def __init__(self, main, data): Packet.__init__(self, 00, data) self.main = main
def __init__(self, main, data): Packet.__init__(self, 11, data) self.main = main self.data = data
def __init__(self,main, data): Packet.__init__(self, 12,data) self.main = main self.data = data