Advertisement
Guest User

Untitled

a guest
Dec 12th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.46 KB | None | 0 0
  1. --- /tmp/.diff1857401768    2014-12-12 05:25:29.360665674 -0400
  2. +++ /tmp/.diff740589034 2014-12-12 05:25:29.361665801 -0400
  3. @@ -1,4 +1,3 @@
  4. -#!/usr/bin/env
  5.  from __future__ import print_function
  6.  import argparse
  7.  import time
  8. @@ -18,13 +17,20 @@
  9.      def __repr__(self):
  10.          return "OverflowPacket"
  11. +class TimestampPacket(ITMDWTPacket):
  12. +    def __init__(self, delta):
  13. +        self.delta = delta
  14. +
  15. +    def __repr__(self):
  16. +        return "TimestampPacket"
  17. +
  18.  class SourcePacket(ITMDWTPacket):
  19.      def __init__(self, address, source, size, data):
  20.          self.address = address
  21.          self.source = source
  22.          self.size = size
  23.          if size == 1:
  24. -            self.data = data[0]
  25. +            self.sdata = self.data = data[0]
  26.          elif size == 2:
  27.              d = bytearray(data)
  28.              self.data = struct.unpack_from("<H", d)[0]
  29. @@ -67,7 +73,7 @@
  30.                  if b == 0x80 and (len(frame) == 5):
  31.                      frame.append(b)
  32.                  else:
  33. -                    print("Not in sync: invalid byte for sync frame: %d" % b)
  34. +                    #print("Not in sync: invalid byte for sync frame: %d" % b)
  35.                      frame = []
  36.              #print("Frame so far", frame)
  37. @@ -87,7 +93,7 @@
  38.                      if b == 0x80 and (len(frame) == 5):
  39.                          frame.append(b)
  40.                      else:
  41. -                        print("invalid sync frame byte? trying to resync: %d" % b)
  42. +                        print("invalid sync frame byte? trying to resync: %d, %d" % (b, len(frame)))
  43.                          frame = []
  44.                  if frame == synchro:
  45.                      target.send(SynchroPacket())
  46. @@ -101,6 +107,13 @@
  47.              if b == 0x70:
  48.                  print("Overflow!")
  49.                  target.send(OverflowPacket())
  50. +            elif (b & 0x80) == 0x80:
  51. +                ts = 0
  52. +                while (b & 0x80) == 0x80:
  53. +                    b = yield
  54. +                    ts <<= 7
  55. +                    ts |= b & 0x7F
  56. +                target.send(TimestampPacket(ts))
  57.              else:
  58.                  print("Protocol packet decoding not handled, breaking stream to next sync :( byte was: %d (%x)" % (b, b))
  59.                  in_sync = False
  60. @@ -131,16 +144,33 @@
  61.  @coroutine
  62.  def PacketReceiverConsolePrinter(valid_address=-1):
  63. +    ts = 0
  64. +    buf = ''
  65. +    bts = 0
  66. +    lbts = 0
  67. +    lts = {}
  68.      while True:
  69.          f = yield
  70. +        if hasattr(f, "delta"):
  71. +            ts += f.delta
  72. +            continue
  73.          if not hasattr(f, "address"):
  74.              # Skip things like synchro packets
  75.              continue
  76.          if f.address == valid_address or valid_address == -1:
  77.              if (f.size == 1):
  78. -                print(chr(f.data), end='')
  79. +                if buf == '': bts = ts
  80. +                buf = buf + chr(f.data)
  81. +                if chr(f.data) == '\n':
  82. +                    print("%.3f: %s" % ((bts-lbts)/120000000.0*1000, buf), end='')
  83. +                    lbts = bts
  84. +                    buf = ''
  85.              else:
  86. -                print("Channel %d: %d byte value: %d : %#x : %d" % (f.address, f.size, f.data, f.data, f.sdata))
  87. +                if not lts.has_key(f.address):
  88. +                    lts[f.address] = 0
  89. +                t = (ts-lts[f.address])/120000000.0*1000
  90. +                lts[f.address] = ts
  91. +                print("%.3f: Channel %d: %d byte value: %d : %#x : %d" % (t, f.address, f.size, f.data, f.data, f.sdata))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement