wiki:BlueCANReader

Version 2 (modified by Boris Ioffe, 11 years ago) ( diff )

--

: 00000000b 00 00 00 00 00 00 00 00 ID0 ID1 ID2 ID3 ;

00000000b --- bit.0=Data Length Code bit.0 
	bit.1=Data Length Code bit.1
	bit.2=Data Length Code bit.2
	bit.3=Data Length Code bit.3
	bit.4=extended ID or Standard
	bit.5=RTR message or Normal


00 00 00 00 00 00 00 00 --- DATA bytes

ID0 ID1 ID2 ID3 --- CAN ID
def parseLine(line):
    msgLength = line[0] & 0b1111
    isExtended = (line[0] >> 4) & 1
    isRTR = (line[0] >> 5) & 1
    payload = line[1:msgLength+1]
    id = line[-4:]
    id =  id[0] + (id[1] << 8) + (id[2] << 16) + (id[3] << 24)
    #print msgLength, isExtended, isRTR, [hex(x) for x in payload], hex(id)
    return id, payload



while True:
    s = ser.read()
    if s == ";":
        buffer = buffer[1:]
        print [x for x in buffer]
        print buffer
        id,strData = parseLine(buffer)
        buffer = bytearray()
#        strID, strData = parseLine(buffer)
#        id = int(strID, base=16)
        priority, source_id, pgn, destination_id  = parseCanID(id)
#
        print strformat.format(i, buffer, id, (priority, source_id, pgn, destination_id)), strData, msgdict.get(pgn)
#        i+=1
#        buffer = ''
    else:
        buffer.append(ord(s))
Note: See TracWiki for help on using the wiki.