Exemplo n.º 1
0
    def __init__(self, dat, timestp=None, offset=0) :
        """ 
        reads a raw packet in the form of a string of "1' & "0"
        """
        self.raw_dat = dat
        self.offset = dat
        self.validcrc = 0
        self.calc_crc = None

        if timestp is not None:
            self.timestamp = datetime.fromtimestamp(timestp)
        else:
            self.timestamp = datetime.datetime.now()

        self.time_str = self.timestamp.time().isoformat()
        self.dat = extract_pkt_data(self.raw_dat)

        if len(self.dat) >= 10:
            self.calc_crc = pkt_crc(self.dat)
        self.hex_str = self.pkt_simple()
Exemplo n.º 2
0
    def __init__(self, dat, timestp=None, offset=0):
        """ 
        reads a raw packet in the form of a string of "1' & "0"
        """
        self.raw_dat = dat
        self.offset = dat
        self.validcrc = 0
        self.calc_crc = None

        if timestp is not None:
            self.timestamp = datetime.fromtimestamp(timestp)
        else:
            self.timestamp = datetime.datetime.now()

        self.time_str = self.timestamp.time().isoformat()
        self.dat = extract_pkt_data(self.raw_dat)

        if len(self.dat) >= 10:
            self.calc_crc = pkt_crc(self.dat)
        self.hex_str = self.pkt_simple()
Exemplo n.º 3
0
def uncode(Sout, mark=None) :

    if mark is None :
        print "mark missing"
        return  None, None

    slen = len(Sout)
    r = list()
    datl = list()
    cont = True
    completed = 0;

    j = 0
    while cont and mark < slen :
        markStr = Sout[mark: mark +2]

        if markStr != "11" :
            print "Mark Missed", markStr
            print "\t", Sout[mark -3: mark], Sout[mark: mark +2], Sout[mark +2: mark+44]
            break

#       if mark < 20 :
#           print "=\t11 01010101010110011010100110"
        pm = mark
        mark = mark + 2
        dat = Sout[mark : mark +26]
        mark = mark +26
        r.append(markStr)
        r.append(dat)
        dm = local_demanchester(dat)
        # print "dm", dm
        if dm is None :
            print "dm is None"
            break
        m = "".join(dm)

        #print "{:d}\t{:s} {:s} {:<3d} {:s} {:s} {:s}".format(
        #       pm, markStr, dat, cs, m, hexstr(dat, sep=''), hexstr(m, sep='') )

        if len(m) < 13 :
            print "len m < 13"
            break
        print "{:02d} {:d}\t{:s} {:s}".format(j, pm, markStr, dat),
        count_field = int(m[4::-1], 2)
        dat_field   = int(m[:4:-1], 2)
        datl.append(dat_field)
        print "{:5s} ({:2d}) : {:s} {:02X}".format(
                m[4::-1], count_field, 
                m[:4:-1], dat_field),
        if ( j == 0 ):
            d = extract_insteon_flags(flag=dat_field)
            print flag_str(d),
        elif ( j == 7 ) :
            print lookup_insteon_cmd(cmd=dat_field),
        elif ( count_field == 3 and d["extended"] == 0) :
            print "CRC",
            c = pkt_crc(datl)
            if dat_field == c :
                print "OK",
            else :
                # print "c", type(c), c
                # print "dat_field", type(dat_field), dat_field
                print "Fail {:02X} != {:02X}".format(dat_field, c),

        elif ( count_field == 9 and d["extended"] == 1) :
            print "extend CRC",
            c = calc_ext_crc(datl)
            if dat_field == c :
                print "OK",
            else :
                print "Fail {:X02} != {:X02}".format(dat_field, c),
        elif ( count_field == 8 and d["extended"] == 1) :
            print "packet CRC",
            c = pkt_crc(datl)
            if dat_field == c :
                print "eOK",
            else :
                print "e3_Fail {:02X} != {:02X}".format(dat_field, c),
        print
        j = j + 1
        if count_field == 0 :
            print "count_field = ", count_field
            completed=mark
            mark = pm
            break

    else :
        print "While done : cont =", cont, "mark=", mark, "<", slen



    # print "While done : cont =", cont, "mark=", mark, "<", slen

    print "Mark", mark
    print "Last Mark", Sout[mark -26:mark], Sout[mark: mark +2], Sout[mark +2: mark+28],
    print Sout[mark+28: mark+30], Sout[mark+30: mark+58]
    print "dat", ["{:02X}".format(x) for x in datl]
    return r, mark, completed
Exemplo n.º 4
0
        #   continue

        # print ":", " ".join( d["hex"][1:4]),
        # print ":", " ".join( d["hex"][4:7]),
        # print ":", " ".join( d["hex"][7:])

    except ValueError, err :
        print "ValueError",err, d["hex"]

    if fg["extended"] and d["ext_crc"] is not None :
        e_crc = calc_ext_crc( d["dat"] )
        if d["ext_crc"] != e_crc :
            print "Ext CRC mismatch : {:02X} != {:02X}".format( d["crc"], d["calc_crc"] )

    if d["crc"] is not None :
        crc = pkt_crc( d["dat"] ) 
        if  d["crc"] != crc :
            print "CRC mismatch : {:02X} != {:02X}".format( d["crc"], crc )

    print "\n"


# -- testing --
def render_insteon_rf_pkt(d):
    fg = d["flags"]
    # if fg["group"] :
    #     print d["dst"], "->", d["src"], ":", d["cmd"]
    # elif d["src"] is not None :
    #     print d["src"], "->", d["dst"], ":", d["cmd"]
    #     print "\t", flag_str(d["flags"])
    #     print ":  {:28s} Extended={:d} Bcast={:d} Max_Hops={:d} Hops_Left={:d}".format(
Exemplo n.º 5
0
def uncode(Sout, mark=None):

    if mark is None:
        print "mark missing"
        return None, None

    slen = len(Sout)
    r = list()
    datl = list()
    cont = True
    completed = 0

    j = 0
    while cont and mark < slen:
        markStr = Sout[mark:mark + 2]

        if markStr != "11":
            print "Mark Missed", markStr
            print "\t", Sout[mark - 3:mark], Sout[mark:mark +
                                                  2], Sout[mark + 2:mark + 44]
            break


#       if mark < 20 :
#           print "=\t11 01010101010110011010100110"
        pm = mark
        mark = mark + 2
        dat = Sout[mark:mark + 26]
        mark = mark + 26
        r.append(markStr)
        r.append(dat)
        dm = local_demanchester(dat)
        # print "dm", dm
        if dm is None:
            print "dm is None"
            break
        m = "".join(dm)

        #print "{:d}\t{:s} {:s} {:<3d} {:s} {:s} {:s}".format(
        #       pm, markStr, dat, cs, m, hexstr(dat, sep=''), hexstr(m, sep='') )

        if len(m) < 13:
            print "len m < 13"
            break
        print "{:02d} {:d}\t{:s} {:s}".format(j, pm, markStr, dat),
        count_field = int(m[4::-1], 2)
        dat_field = int(m[:4:-1], 2)
        datl.append(dat_field)
        print "{:5s} ({:2d}) : {:s} {:02X}".format(m[4::-1], count_field,
                                                   m[:4:-1], dat_field),
        if (j == 0):
            d = extract_insteon_flags(flag=dat_field)
            print flag_str(d),
        elif (j == 7):
            print lookup_insteon_cmd(cmd=dat_field),
        elif (count_field == 3 and d["extended"] == 0):
            print "CRC",
            c = pkt_crc(datl)
            if dat_field == c:
                print "OK",
            else:
                # print "c", type(c), c
                # print "dat_field", type(dat_field), dat_field
                print "Fail {:02X} != {:02X}".format(dat_field, c),

        elif (count_field == 9 and d["extended"] == 1):
            print "extend CRC",
            c = calc_ext_crc(datl)
            if dat_field == c:
                print "OK",
            else:
                print "Fail {:X02} != {:X02}".format(dat_field, c),
        elif (count_field == 8 and d["extended"] == 1):
            print "packet CRC",
            c = pkt_crc(datl)
            if dat_field == c:
                print "eOK",
            else:
                print "e3_Fail {:02X} != {:02X}".format(dat_field, c),
        print
        j = j + 1
        if count_field == 0:
            print "count_field = ", count_field
            completed = mark
            mark = pm
            break

    else:
        print "While done : cont =", cont, "mark=", mark, "<", slen

    # print "While done : cont =", cont, "mark=", mark, "<", slen

    print "Mark", mark
    print "Last Mark", Sout[mark - 26:mark], Sout[mark:mark +
                                                  2], Sout[mark + 2:mark + 28],
    print Sout[mark + 28:mark + 30], Sout[mark + 30:mark + 58]
    print "dat", ["{:02X}".format(x) for x in datl]
    return r, mark, completed
Exemplo n.º 6
0
        #   continue

        # print ":", " ".join( d["hex"][1:4]),
        # print ":", " ".join( d["hex"][4:7]),
        # print ":", " ".join( d["hex"][7:])

    except ValueError, err:
        print "ValueError", err, d["hex"]

    if fg["extended"] and d["ext_crc"] is not None:
        e_crc = calc_ext_crc(d["dat"])
        if d["ext_crc"] != e_crc:
            print "Ext CRC mismatch : {:02X} != {:02X}".format(d["crc"], d["calc_crc"])

    if d["crc"] is not None:
        crc = pkt_crc(d["dat"])
        if d["crc"] != crc:
            print "CRC mismatch : {:02X} != {:02X}".format(d["crc"], crc)

    print "\n"


# -- testing --
def render_insteon_rf_pkt(d):
    fg = d["flags"]
    # if fg["group"] :
    #     print d["dst"], "->", d["src"], ":", d["cmd"]
    # elif d["src"] is not None :
    #     print d["src"], "->", d["dst"], ":", d["cmd"]
    #     print "\t", flag_str(d["flags"])
    #     print ":  {:28s} Extended={:d} Bcast={:d} Max_Hops={:d} Hops_Left={:d}".format(