Sat, 07 Nov 2020 19:20:39 +0100
Adjust font rendering
- fix +, -, and ' ' so they habe the same width
- add a method to move the current location for a given char (without drawing it)
43
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
1 | import sys |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
2 | import re |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
3 | import click |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
4 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
5 | F = 1e6 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
6 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
7 | reg = re.compile(r'^(?P<fr1>\d+)-(?P<fr2>\d+) uart-1: (?P<value>.+)$') # noqa |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
8 | # to use with |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
9 | # sigrok-cli -i startup-no-key -P uart:baudrate=187500:parity=even:rx=RX:tx=TX \ |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
10 | # --channels RX,TX -A uart=rx-data:tx-data:tx-start --protocol-decoder-samplenum |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
11 | # |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
12 | # in this configuration: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
13 | # RX: FP --> CPU |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
14 | # TX: CPU --> FP |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
15 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
16 | class ProtocolError(Exception): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
17 | pass |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
18 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
19 | class ProtocolReset(Exception): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
20 | pass |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
21 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
22 | pkts = [] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
23 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
24 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
25 | class Packet: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
26 | def __init__(self, frame, rxtx, value): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
27 | self.frame = frame |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
28 | self.rxtx = rxtx |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
29 | self.value = value |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
30 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
31 | @property |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
32 | def timestamp(self): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
33 | return self.frame / F * 1000 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
34 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
35 | @property |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
36 | def relts(self): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
37 | return self.timestamp - pkts[0].timestamp |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
38 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
39 | def __str__(self): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
40 | return '[%06.2f] %s: %02X' % (self.timestamp, self.rxtx, self.value) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
41 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
42 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
43 | def read_line(seq): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
44 | rxtx = "rx" |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
45 | for line in seq: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
46 | m = reg.match(line) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
47 | if m: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
48 | frame = int(m.group('fr1')) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
49 | v = m.group('value') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
50 | if v == "Start bit": |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
51 | rxtx = "tx" |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
52 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
53 | v = int(v, base=16) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
54 | pkt = Packet(frame, rxtx, v) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
55 | pkts.append(pkt) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
56 | yield pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
57 | rxtx = "rx" |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
58 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
59 | print("nope", line) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
60 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
61 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
62 | def read_input(stream=None): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
63 | if stream is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
64 | stream = sys.stdin |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
65 | for line in stream: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
66 | yield line |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
67 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
68 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
69 | def print_input(): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
70 | t0 = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
71 | for pkt in read_line(read_input()): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
72 | c = chr(pkt.value) if 32 <= pkt.value <= 127 else '' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
73 | if t0 is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
74 | t0 = pkt.timestamp |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
75 | cnxdir = 'CPU-->DP' if pkt.rxtx == 'rx' else 'CPU<--DP' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
76 | print('[%s] %06.1f: %02X # %s' % ( |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
77 | cnxdir, (pkt.timestamp-t0), pkt.value, c)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
78 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
79 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
80 | def flipdir(rxtx): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
81 | return 'rx' if rxtx == 'tx' else 'tx' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
82 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
83 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
84 | def check_rxtx(cur, pkt): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
85 | if cur.rxtx == pkt.rxtx: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
86 | raise ProtocolError('Expected %s transmission %02X %02X' % |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
87 | (flipdir(cur.rxtx), cur.value, pkt.value)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
88 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
89 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
90 | def check_sot_ack(ack, sot): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
91 | check_rxtx(ack, sot) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
92 | if ack.value != (0xFF - sot.value): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
93 | if ack.value == 0x66: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
94 | raise ProtocolReset() |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
95 | raise ProtocolError('Expected ACK value %02X, got %02X' % |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
96 | (0xFF - sot.value, ack.value)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
97 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
98 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
99 | def wait_for_sot(seq, sot_pkt=None): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
100 | if sot_pkt is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
101 | for sot_pkt in seq: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
102 | #print("PKT", sot_pkt) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
103 | if sot_pkt.value not in SOT_VALUES: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
104 | print('Unexpected value %s: %02X' % |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
105 | (sot_pkt.rxtx, sot_pkt.value)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
106 | if sot_pkt.value == 0x76: # off by one due to sampling freq |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
107 | print(" off by one on 0x66, fixing value") |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
108 | sot_pkt.value = 0x66 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
109 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
110 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
111 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
112 | for ack_pkt in seq: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
113 | try: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
114 | check_sot_ack(sot_pkt, ack_pkt) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
115 | #print('New packet %s %s' % (sot_pkt, ack_pkt)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
116 | return sot_pkt, ack_pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
117 | except ProtocolReset: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
118 | # print('reset') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
119 | sot_pkt = ack_pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
120 | #raise StopIteration() |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
121 | return None, None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
122 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
123 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
124 | SOT_VALUES = [0x33, 0x66] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
125 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
126 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
127 | def recv_packet(seq): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
128 | sot_pkt = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
129 | while True: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
130 | sot_pkt, ack_pkt = wait_for_sot(seq, sot_pkt) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
131 | if sot_pkt is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
132 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
133 | payload = [] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
134 | recv_char = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
135 | may_stop = False |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
136 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
137 | cur_pkt = ack_pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
138 | for pkt in seq: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
139 | if pkt.value == 0x66: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
140 | sot_pkt = pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
141 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
142 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
143 | check_rxtx(pkt, cur_pkt) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
144 | if recv_char is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
145 | if pkt.rxtx != sot_pkt.rxtx: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
146 | raise ProtocolError() |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
147 | recv_char = pkt.value |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
148 | cur_pkt = pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
149 | if may_stop: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
150 | if recv_char == 0x55: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
151 | cur_pkt = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
152 | sot_pkt = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
153 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
154 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
155 | if pkt.rxtx == sot_pkt.rxtx: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
156 | raise ProtocolError() |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
157 | if pkt.value == 0x00: # ack, previous recv-char is valid |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
158 | payload.append(recv_char) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
159 | if check_payload(sot_pkt, payload): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
160 | may_stop = True |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
161 | yield (sot_pkt, payload) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
162 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
163 | may_stop = False |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
164 | elif pkt.value != 0xFF: # really? |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
165 | # if FF, ignore the char (ie. its a NACK, so resend) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
166 | raise ProtocolError('Not really but hey %02X [%02X] %s' % |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
167 | (pkt.value, recv_char, payload)) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
168 | recv_char = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
169 | cur_pkt = pkt |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
170 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
171 | break |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
172 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
173 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
174 | def check_payload(sot, payload): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
175 | if sot.rxtx == 'rx': |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
176 | if sot.value == 0x33: # init sequence, payload can be 2 or 3 chars: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
177 | if len(payload) > 1: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
178 | if payload[1] == 0xFF: # should be [0x02, 0xFF, <KEY>] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
179 | return len(payload) == 3 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
180 | else: # should be [0x02, 0x00] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
181 | return len(payload) == 2 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
182 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
183 | return len(payload) == 1 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
184 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
185 | if len(payload) > 1: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
186 | return len(payload) == (payload[1]+2) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
187 | return False |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
188 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
189 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
190 | KEYCODES = { |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
191 | 0x00: 'View', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
192 | 0x01: 'Mon', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
193 | 0x02: 'Sto/Rcl', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
194 | 0x03: 'Scan', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
195 | 0x04: 'Alarm', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
196 | 0x05: 'Mx+B', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
197 | 0x06: 'Measure', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
198 | 0x07: 'Interval', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
199 | 0x08: 'Card Reset', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
200 | 0x09: 'Close', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
201 | 0x0A: 'Open', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
202 | 0x0B: 'Read', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
203 | 0x0C: 'Shift', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
204 | 0x0D: 'Write', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
205 | 0x0E: 'Left', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
206 | 0x0F: 'Right', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
207 | 0x10: 'Advanced', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
208 | 0x11: 'Step', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
209 | 0x80: 'Knob right', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
210 | 0x81: 'Knob left', |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
211 | } |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
212 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
213 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
214 | FLAGS = [ |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
215 | ['<Bell>', 'Mx+B', 'Ch. frame', 'Channel', 'LO', 'Alarm', 'HI', 'Al. frame'], |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
216 | ['2', '4', '3', '1', '4W', 'OC', 'SHIFT?', 'AVG'], |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
217 | ['MAX', 'MIN', 'LAST', 'MEM', '', 'ONCE', 'EXT', 'ERROR'], |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
218 | ['REMOTE', 'ADRS', '*', 'VIEW', 'MON', 'SCAN', 'CONFIG', ''] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
219 | ] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
220 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
221 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
222 | def flag(payload): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
223 | flags = [] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
224 | for flg, byte in zip(FLAGS, payload[2:]): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
225 | for i in range(8): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
226 | if byte & 2**i: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
227 | flags.append(flg[i]) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
228 | return ','.join(flags) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
229 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
230 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
231 | def flag_by_num(num): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
232 | for b in FLAGS: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
233 | for f in b: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
234 | if num == 0: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
235 | return f |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
236 | num -= 1 |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
237 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
238 | CMDS = { |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
239 | 0x00: ('DISPLAY ', lambda pl: ''.join(chr(x) for x in pl[2:])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
240 | 0x0C: ('CHANNEL ', lambda pl: ''.join(chr(x) for x in pl[2:])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
241 | 0x0A: ('FLAGS ', flag), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
242 | 0x01: ('CLR FLAG', lambda pl: flag_by_num(pl[2])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
243 | 0x86: ('SHUTDOWN', None), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
244 | 0x0D: ('CHAR LO ', lambda pl: str(pl[2])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
245 | 0x08: ('FLAG LO ', lambda pl: flag_by_num(pl[2])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
246 | 0x09: ('FLAG HI ', lambda pl: flag_by_num(pl[2])), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
247 | 0x02: ('RST? ', lambda pl: "[%s]" % (",".join("%02X"%c for c in pl))), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
248 | } |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
249 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
250 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
251 | def parse_packet(sot, payload): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
252 | if sot.value == 0x33: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
253 | if len(payload) == 2: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
254 | return 'INIT NO KEY' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
255 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
256 | return 'INIT WITH KEY\t\t%s' % click.style(KEYCODES.get(payload[-1], 'None'), fg='cyan') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
257 | if sot.rxtx == 'rx': |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
258 | kc = payload[0] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
259 | if kc in (0x80, 0x81): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
260 | return 'KNOB\t\t%s' % click.style(KEYCODES.get(kc), fg='magenta') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
261 | if kc & 0x40: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
262 | kc = kc & 0xBF |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
263 | event = 'RELEASED' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
264 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
265 | event = 'PRESSED ' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
266 | return 'KEY\t%s\t%s' % (click.style(event, fg='green'), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
267 | click.style(KEYCODES.get(kc, "[%02X]"%kc), fg='cyan')) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
268 | lbl, dspfunc = CMDS[payload[0]] |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
269 | if dspfunc: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
270 | lbl += '\t%s' % click.style(dspfunc(payload), fg='green') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
271 | return lbl |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
272 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
273 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
274 | @click.command() |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
275 | @click.option('-p', '--packets/--no-packets', default=False) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
276 | @click.option('-f', '--filename', default=None) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
277 | def main(packets, filename): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
278 | if filename: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
279 | input_stream = open(filename) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
280 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
281 | input_stream = None # == stdin |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
282 | if packets: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
283 | try: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
284 | for sot, payload in recv_packet(read_line(read_input(input_stream))): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
285 | cnxdir = 'CPU=>DP' if sot.rxtx == 'tx' else 'CPU<-DP' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
286 | print('[%s]: %02X=[%s]' % |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
287 | (cnxdir, sot.value, |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
288 | ','.join('%02x' % x for x in payload))) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
289 | except: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
290 | print('\n'.join(str(x) for x in pkts[-10:])) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
291 | raise |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
292 | else: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
293 | click.secho("Transmission CPU <--> DP", fg="red") |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
294 | try: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
295 | t0 = None |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
296 | for sot, payload in recv_packet(read_line(read_input(input_stream))): |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
297 | cnxdir = '>>>' if sot.rxtx == 'tx' else '<<<' |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
298 | if t0 is None: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
299 | t0 = sot.timestamp |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
300 | click.secho('%08.0f ' % sot.relts, |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
301 | fg='yellow', nl=False) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
302 | click.secho('[+%04.2f] ' % ((sot.timestamp - t0)/1000.), |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
303 | fg='blue', nl=False) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
304 | click.secho(cnxdir + ' ', fg='red' if cnxdir == ">>>" else 'green', nl=False) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
305 | click.secho(parse_packet(sot, payload), fg='white') |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
306 | t0 = sot.timestamp |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
307 | except: |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
308 | print('\n'.join(str(x) for x in pkts[-10:])) |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
309 | raise |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
310 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
311 | |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
312 | if __name__ == '__main__': |
c850674a3101
Add a series of reference serial data sessions from a working 34970A unit.
David Douard <david.douard@sdf3.org>
parents:
diff
changeset
|
313 | main() |