-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpd.py
80 lines (66 loc) · 2.31 KB
/
pd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2022 Matej Martinček <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
'''
OUTPUT_PYTHON format:
Packet:
[<ptype>, <pdata>]
<ptype>:
- 'ADDRESS
- 'DATA'
<pdata> is the data value associated with the 'DATA'
command.
'''
import re
import sigrokdecode as srd
from common.srdhelper import bcd2int, SrdIntEnum
class Decoder(srd.Decoder):
api_version = 3
id = 'uart_extractor'
name = 'UART bytes extractor'
longname = 'The UART bytes extractor'
desc = 'Extracts data packets values from UART communication and potentially sends them to other stack-decoders'
license = 'gplv2+'
inputs = ['uart']
outputs = ['dataBytes']
tags = ['Embedded/industrial']
annotations = ()
annotation_rows = ()
def __init__(self):
self.reset()
def reset(self):
self.state = 'INACTIVE'
def start(self):
self.out_python = self.register(srd.OUTPUT_PYTHON)
def putp(self, data):
self.put(self.ss, self.es, self.out_python, data)
def send_data_value(self, b, rxtx):
# Send the value of the received data of type DATA onto row no. rxtx
self.putp(['DATA', b, rxtx])
def decode(self, ss, es, data):
cmd, rxtx, data_value_and_bits = data
# Store the start/end samples of this packet.
self.ss, self.es = ss, es
# State machine.
if cmd == 'STARTBIT':
self.state = 'ACTIVE'
elif cmd == 'STOPBIT':
self.state = 'INACTIVE'
elif cmd == 'DATA':
# Send just the value of the received data packet without the individual bits
self.send_data_value(data_value_and_bits[0], rxtx)