Esempio n. 1
0
 def decode_MsgBody(self, payload, UIDisp):
     sPayload = str(payload, encoding = "utf-8")
     if 0xc1 == int(sPayload[6:8], 16):
         UIDisp.connect_log("=========RC AC Resp Msg Body begin===========")
         strlen = len(sPayload[72:])
         # 4 indicate no msgbody only have CRC
         if 4 == len(sPayload[72:]):
             UIDisp.connect_log("msgBody is NULLLLLLLL")
         else:
             UIDisp.connect_log("msgBody ="+sPayload[72:72+strlen-4])
         UIDisp.connect_log("=========RC AC Resp Msg Body end  ===========")
     else:
         UIDisp.connect_log("=========RC AC Resp Msg Body begin===========")
         strlen = len(sPayload[62:])
         #remove CRC part
         UIDisp.connect_log("msgBody ="+sPayload[62:62+strlen-4])
         length =  0
         DecodeMsg = CommonMsg.DecodeMsg()
         for i in range(3):
             UIDisp.connect_log("key=0x"+ '{:03x}'.format(DecodeMsg.decode_key(int(sPayload[62+length : 62+length +4], 16))))
             type = DecodeMsg.decode_type(int(sPayload[62+length : 62+length +4], 16))
             UIDisp.connect_log("type=0x"+'{:02x}'.format(type))
             #based on type to set len
             lenvalue =  DecodeMsg.decode_len(type)*2
             if 0 == lenvalue:
                 lenvalue = int(sPayload[62 + length + 4: 62 + length + 8], 16)
                 UIDisp.connect_log("len=0x" + '{:04x}'.format(lenvalue))
                 UIDisp.connect_log("data=" + sPayload[62 + length + 8: 62 + length + lenvalue])
                 length += (8 + lenvalue)
             else:
                 UIDisp.connect_log("len=0x" + '{:02x}'.format(lenvalue))
                 UIDisp.connect_log("data=" + sPayload[62 + length + 4: 62 + length + lenvalue])
                 length += (4 + lenvalue)
         UIDisp.connect_log("=========RC AC Resp Msg Body end  ===========")
Esempio n. 2
0
 def decode_MsgBody(self, payload, UIDisp):
     sPayload = str(payload, encoding = "utf-8")
     if 0xc1 == int(sPayload[6:8], 16):
         UIDisp.connect_log("=========SVT CMD Req Msg Body begin===========")
         UIDisp.connect_log("msgBody ="+sPayload[72:])
         UIDisp.connect_log("=========SVT CMD Req Msg Body end  ===========")
     else:
         UIDisp.connect_log("=========SVT CMD Req Msg Body begin===========")
         UIDisp.connect_log("msgBody ="+sPayload[62:])
         length =  0
         DecodeMsg = CommonMsg.DecodeMsg()
         for i in range(4):
             UIDisp.connect_log("key=0x"+ '{:03x}'.format(DecodeMsg.decode_key(int(sPayload[62+length : 62+length +4], 16))))
             type = DecodeMsg.decode_type(int(sPayload[62+length : 62+length +4], 16))
             UIDisp.connect_log("type=0x"+'{:02x}'.format(type))
             #based on type to set len
             lenvalue =  DecodeMsg.decode_len(type)*2
             if 0 == lenvalue:
                 lenvalue = int(sPayload[62 + length + 4: 62 + length + 8], 16)
                 UIDisp.connect_log("len=0x" + '{:04x}'.format(lenvalue))
                 UIDisp.connect_log("data=" + sPayload[62 + length + 8: 62 + length + lenvalue])
                 length += (8 + lenvalue)
             else:
                 UIDisp.connect_log("len=0x" + '{:02x}'.format(lenvalue))
                 UIDisp.connect_log("data=" + sPayload[62 + length + 4: 62 + length + lenvalue])
                 length += (4 + lenvalue)
         UIDisp.connect_log("=========SVT CMD Req Msg Body end  ===========")
Esempio n. 3
0
def on_message(client, userdata, msg):
    if True == operator.eq(msg.topic, MQTT_TOPIC_IOT_RESP_LOGIN) \
        or True == operator.eq(msg.topic, MQTT_TOPIC_IOT_RESP_LOGOUT) \
        or True == operator.eq(msg.topic, MQTT_TOPIC_IOT_RESP_OFFLINE) \
        or True == operator.eq(msg.topic, MQTT_TOPIC_IOT_REQ_CONTROL) \
        or True == operator.eq(msg.topic, MQTT_TOPIC_IOT_REQ_PARAMETER):
        return

    myUI = userdata
    #myUI.connect_log(msg.topic+" "+str(msg.payload))
    myUI.connect_log("<<<<<<<<<<<<<Rec Msg<<<<<<<<<<<<<<<<<<<<<<<<")
    myUI.connect_log("Rec topic is" + msg.topic)
    msgPayload = binascii.hexlify(msg.payload)
    myUI.connect_log("payload:" + str(msgPayload))
    DecodeMsg = CommonMsg.DecodeMsg()
    if (True == DecodeMsg.check_crc(msgPayload)):
        myUI.connect_log("CRC Check is OK")
    else:
        myUI.connect_log("CRC Check is not OK")
        #return
    busnisstype = DecodeMsg.decode_Header(msgPayload, myUI)
    if True == operator.eq(msg.topic, MQTT_TOPIC_IOT_REQ_LOGIN):
        recMsg = LoginMsg()
        recMsg.decode_MsgBody(msgPayload, myUI)
    elif True == operator.eq(msg.topic, MQTT_TOPIC_IOT_RESP_CONTROL):
        if 0x1501 == busnisstype:
            recMsg = SVTCmdMsg.SVTRepMsg()
            recMsg.decode_MsgBody(msgPayload, myUI)
        elif 0x1102 == busnisstype:
            recMsg = RCHornFlash.RCHornFlashRespMsg()
            recMsg.decode_MsgBody(msgPayload, myUI)
        elif 0x1107 == busnisstype:
            recMsg = RCAC.RCACRespMsg()
            recMsg.decode_MsgBody(msgPayload, myUI)
Esempio n. 4
0
    def pack(self):
        curTime = int(time.time())
        timeTmp = [0x00,0x00,0x00,0x00,0x00,0x00]
        timeTmp[0] = (curTime&0xFF0000000000)>>40
        timeTmp[1] = (curTime&0x00FF00000000)>>32
        timeTmp[2] = (curTime&0x0000FF000000)>>24
        timeTmp[3] = (curTime&0x000000FF0000)>>16
        timeTmp[4] = (curTime&0x00000000FF00)>>8
        timeTmp[5] = curTime&0x0000000000FF
        timeStr = ''
        for i in range(6):
            timeStr += '{:02x}'.format(timeTmp[i])
        #print("timeStr=",timeStr)

        vinStr=''
        for i in range(17):
            vinStr += '{:02x}'.format(self.vin[i])
        #print("vinStr=",vinStr)

        #encode Token
        payloadStr = '00B4'
        payloadStr += '{:04x}'.format(self.tokenLen)
        for i in range(16):
            payloadStr += '{:02x}'.format(self.token[i])
        #print("payloadStr=",payloadStr)

        #encode validationTime
        payloadStr += '2050'
        payloadStr += '{:02x}'.format(self.u8RCvalitionTime)
        #print("payloadStr=",payloadStr)

        #encode AC Switch
        payloadStr += '9490'
        payloadStr += '{:02x}'.format(self.u8ACSwitch)
        #print("payloadStr=",payloadStr)

        #encode AC SetValue
        payloadStr += '9420'
        payloadStr += '{:02x}'.format(self.u8ACSetValue)
        #print("payloadStr=",payloadStr)

        #encode AC SetValue
        payloadStr += '9451'
        payloadStr += '{:04x}'.format(self.u16DurationOfAC)
        #print("payloadStr=",payloadStr)

        #encode Booking AC Switch
        payloadStr += '9460'
        payloadStr += '{:02x}'.format(self.u8BookingAC)
        #print("payloadStr=",payloadStr)

        #encode Booking AC StartTime
        payloadStr += '94A1'
        payloadStr += '{:04x}'.format(self.u16BookingACStartTime)
        #print("payloadStr=",payloadStr)

        #encode requestID
        payloadStr += '00D4'
        payloadStr += '{:04x}'.format(self.requestIdLen)
        for i in range(10):
            payloadStr += '{:02x}'.format(self.requestId[i])
        #print("payloadStr=",payloadStr)

        bufferTmp = '{:04x}{:02x}{:02x}{:04x}{:04x}'.format(self.businessType, self.protocolVerNum, self.flag, self.serialNum, self.vinLen)
        buffer  = bufferTmp + vinStr + timeStr + payloadStr
        bufferBytes = bytes(buffer, encoding="utf-8")

        EncodeMsg = CommonMsg.EncodeMsg()
        crcRet = EncodeMsg.get_crc(bufferBytes)
        crc0Str = '{:02x}'.format(crcRet[0])
        btmp = bytes(crc0Str, "utf-8")
        bufferTmp = bufferBytes + btmp
        crc1Str = '{:02x}'.format(crcRet[1])
        btmp = bytes(crc1Str, "utf-8")
        bufferTmp += btmp
        print("buffer+crc=",bufferTmp)

        return binascii.unhexlify(bufferTmp)
Esempio n. 5
0
            UIDisp.connect_log("=========RC AC Resp Msg Body begin===========")
            strlen = len(sPayload[62:])
            #remove CRC part
            UIDisp.connect_log("msgBody ="+sPayload[62:62+strlen-4])
            length =  0
            DecodeMsg = CommonMsg.DecodeMsg()
            for i in range(3):
                UIDisp.connect_log("key=0x"+ '{:03x}'.format(DecodeMsg.decode_key(int(sPayload[62+length : 62+length +4], 16))))
                type = DecodeMsg.decode_type(int(sPayload[62+length : 62+length +4], 16))
                UIDisp.connect_log("type=0x"+'{:02x}'.format(type))
                #based on type to set len
                lenvalue =  DecodeMsg.decode_len(type)*2
                if 0 == lenvalue:
                    lenvalue = int(sPayload[62 + length + 4: 62 + length + 8], 16)
                    UIDisp.connect_log("len=0x" + '{:04x}'.format(lenvalue))
                    UIDisp.connect_log("data=" + sPayload[62 + length + 8: 62 + length + lenvalue])
                    length += (8 + lenvalue)
                else:
                    UIDisp.connect_log("len=0x" + '{:02x}'.format(lenvalue))
                    UIDisp.connect_log("data=" + sPayload[62 + length + 4: 62 + length + lenvalue])
                    length += (4 + lenvalue)
            UIDisp.connect_log("=========RC AC Resp Msg Body end  ===========")

if __name__ == '__main__':
    #VIN="UCIT123456789ABCD"
    #SVTCmdReqMsg = SVTCmdReqMsg(VIN)
    #SVTCmdReqMsg.pack()
    RCACReqMsg = RCACReqMsg()
    DecodeMsg = CommonMsg.DecodeMsg()
    print("is big endian = ", DecodeMsg.is_big_endian())