Ejemplo n.º 1
0
 def makeMBAPHeader(self, segMac, pdu):
     session = struct.pack("!H", self.session_id)
     proto = struct.pack("!H", 0)
     length = struct.pack("<H", len(pdu) + 4)
     segmac = struct.pack("!I", convertmac(segMac))
     mbap_header = session + proto + length + segmac
     return mbap_header
Ejemplo n.º 2
0
 def makeMBAPHeader(self, segMac, pdu):
     session = struct.pack("!H", self.session_id)
     proto = struct.pack("!H", 0)
     length = struct.pack("<H", len(pdu) + 4)
     segmac = struct.pack("!I", convertmac(segMac))
     mbap_header = session + proto + length + segmac
     return mbap_header
Ejemplo n.º 3
0
    def makePDU(self, segMac, scMac, registerAddr, TH, TL):
        header = struct.pack("!B", 0xCC)#帧头
        scmac = struct.pack("!Q", convertmac(scMac))#采控器地址
        cmd = struct.pack("!B", 0x06)#下发控制命令
        register = struct.pack("<H", registerAddr)#寄存器地址
        
        try:
            data = TH << 8 | TL
            print data
            data = struct.pack("<H", data)#数据
        except:
            data = struct.pack("<H", 0x00)

        tail = struct.pack("!B", 0xDD)#帧尾
        pdu = scmac + cmd + register +  data# 要送去做CRC的字段
        format = "!" + "B" * len(pdu)
        crc = struct.pack("!H", getCRC(list(struct.unpack(format, pdu))))#unpack之后是元组,转成列表

        pdu = header + pdu + crc + tail
        pdu = self.makeMBAPHeader(segMac, pdu) + pdu
        return pdu
Ejemplo n.º 4
0
    def makePDU(self, segMac, scMac, registerAddr, TH, TL):
        header = struct.pack("!B", 0xCC)  #帧头
        scmac = struct.pack("!Q", convertmac(scMac))  #采控器地址
        cmd = struct.pack("!B", 0x06)  #下发控制命令
        register = struct.pack("<H", registerAddr)  #寄存器地址

        try:
            data = TH << 8 | TL
            print data
            data = struct.pack("<H", data)  #数据
        except:
            data = struct.pack("<H", 0x00)

        tail = struct.pack("!B", 0xDD)  #帧尾
        pdu = scmac + cmd + register + data  # 要送去做CRC的字段
        format = "!" + "B" * len(pdu)
        crc = struct.pack("!H",
                          getCRC(list(struct.unpack(format,
                                                    pdu))))  #unpack之后是元组,转成列表

        pdu = header + pdu + crc + tail
        pdu = self.makeMBAPHeader(segMac, pdu) + pdu
        return pdu