| 17 | |
| 18 | |
| 19 | {{{ |
| 20 | def parseLine(line): |
| 21 | msgLength = line[0] & 0b1111 |
| 22 | isExtended = (line[0] >> 4) & 1 |
| 23 | isRTR = (line[0] >> 5) & 1 |
| 24 | payload = line[1:msgLength+1] |
| 25 | id = line[-4:] |
| 26 | id = id[0] + (id[1] << 8) + (id[2] << 16) + (id[3] << 24) |
| 27 | #print msgLength, isExtended, isRTR, [hex(x) for x in payload], hex(id) |
| 28 | return id, payload |
| 29 | |
| 30 | |
| 31 | |
| 32 | while True: |
| 33 | s = ser.read() |
| 34 | if s == ";": |
| 35 | buffer = buffer[1:] |
| 36 | print [x for x in buffer] |
| 37 | print buffer |
| 38 | id,strData = parseLine(buffer) |
| 39 | buffer = bytearray() |
| 40 | # strID, strData = parseLine(buffer) |
| 41 | # id = int(strID, base=16) |
| 42 | priority, source_id, pgn, destination_id = parseCanID(id) |
| 43 | # |
| 44 | print strformat.format(i, buffer, id, (priority, source_id, pgn, destination_id)), strData, msgdict.get(pgn) |
| 45 | # i+=1 |
| 46 | # buffer = '' |
| 47 | else: |
| 48 | buffer.append(ord(s)) |
| 49 | }}} |
| 50 | |