Skip to content

Commit

Permalink
Bola pridana moznost rozdelit paketovanie na dva riadky (RX/TX,MOSI/M…
Browse files Browse the repository at this point in the history
…ISO)
  • Loading branch information
matomarss committed Jan 26, 2022
1 parent d248400 commit 7898362
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 67 deletions.
12 changes: 6 additions & 6 deletions extractor_i2c/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def putp(self, data):
self.put(self.ss, self.es, self.out_python, data)

def send_address_byte(self, b):
# send address byte of type ADDRESS
self.putp(['ADDRESS', b])
# send the address byte of type ADDRESS onto row no. 0
self.putp(['ADDRESS', b, 0])

def send_data_byte(self, b):
# send data byte of type DATA
self.putp(['DATA', b])
# send the data byte of type DATA onto row no. 0
self.putp(['DATA', b, 0])

def decode(self, ss, es, data):
cmd, data_byte = data
Expand All @@ -88,12 +88,12 @@ def decode(self, ss, es, data):
self.state = 'ACTIVE'
# START REPEAT means an end of a packet
if cmd == 'START REPEAT':
self.putp(['PACKET END', 0])
self.putp(['PACKET END', 0, 0])
return
elif cmd == 'STOP':
self.state = 'INACTIVE'
# STOP means an end of a packet
self.putp(['PACKET END', 0])
self.putp(['PACKET END', 0, 0])
return

if self.state == 'ACTIVE':
Expand Down
22 changes: 9 additions & 13 deletions extractor_spi/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class Decoder(srd.Decoder):
license = 'gplv2+'
inputs = ['spi']
outputs = ['dataBytes']
options = (
{'id': 'miso-mosi', 'desc': 'Display MISO or MOSI communication',
'default': 'MISO', 'values': ('MISO', 'MOSI')},
)
tags = ['Embedded/industrial']
annotations = ()
annotation_rows = ()
Expand All @@ -64,19 +60,19 @@ def start(self):
def putp(self, data):
self.put(self.ss, self.es, self.out_python, data)

def send_data(self, b):
# Send received data packet of type DATA
self.putp(['DATA', b])
def send_data(self, b, r):
# Send the received data packet of type DATA onto row no. r
self.putp(['DATA', b, r])

def decode(self, ss, es, data):
cmd, mosi, miso = data

self.ss, self.es = ss, es

if cmd == 'DATA':
# If MOSI is sending a packet and the right option is selected, pass it on as a single packet
if mosi is not None and self.options['miso-mosi'] == 'MOSI':
self.send_data(mosi)
# If MISO is sending a packet and the right option is selected, pass it on as a single packet
if miso is not None and self.options['miso-mosi'] == 'MISO':
self.send_data(miso)
# If MOSI is sending a packet, pass it on as a single packet onto row no. 1
if mosi is not None:
self.send_data(mosi, 1)
# If MISO is sending a packet, pass it on as a single packet onto row no. 0
if miso is not None:
self.send_data(miso, 0)
10 changes: 5 additions & 5 deletions extractor_uart/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def start(self):
def putp(self, data):
self.put(self.ss, self.es, self.out_python, data)

def send_data_value(self, b):
# Send value of received data of type DATA
self.putp(['DATA', b])
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
Expand All @@ -77,7 +77,7 @@ def decode(self, ss, es, data):
elif cmd == 'STOPBIT':
self.state = 'INACTIVE'
# STOPBIT means end of a packet
self.putp(['PACKET END', 0])
self.putp(['PACKET END', 0, rxtx])
elif cmd == 'DATA':
# Send just value of received data packet without individual bits
self.send_data_value(data_value_and_bits[0])
self.send_data_value(data_value_and_bits[0], rxtx)
105 changes: 62 additions & 43 deletions packeter/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
from common.srdhelper import bcd2int, SrdIntEnum
import math

a = ['ADDRESS', 'DATA', ]
a = ['ADDRESS', 'DATA', 'ADDRESS2', 'DATA2', ]

Ann = SrdIntEnum.from_list('Ann', a)


class Decoder(srd.Decoder):
api_version = 3
id = 'packeter'
Expand All @@ -54,23 +53,31 @@ class Decoder(srd.Decoder):
outputs = []
tags = ['Embedded/industrial']
annotations = (
('adr', 'Adrs'),
('dt', 'Dat'),
('address', 'Address'),
('data', 'Data'),
('address2', 'Address2'),
('data2', 'Data2'),
)
annotation_rows = (
('main', 'MAIN', (Ann.ADDRESS, Ann.DATA,)),
('first', 'First row', (Ann.ADDRESS, Ann.DATA,)),
('second', 'Second row', (Ann.ADDRESS2, Ann.DATA2,)),
)

def __init__(self):
self.reset()

def reset(self):
self.state = 'NEUTRAL'
self.stored_values = []
self.separation_sequence_pointer = 0
# Almost all global variables are remembered for each row separately
self.ss = [0, 0]
self.es = [0, 0]
self.state = ['NEUTRAL', 'NEUTRAL']
self.current_row = 0
self.stored_values = [[], []]
self.separation_sequence_pointer = [0, 0]

def start(self):
self.out_ann = self.register(srd.OUTPUT_ANN)
# Split the separation sequence string at commas to create a list
if self.options['use-separator-sequence'] == 'yes':
self.separation_sequence = str(self.options['packet-separator-sequence']).split(',')
else:
Expand All @@ -81,25 +88,33 @@ def manage_stored_values(self, t):
self.output_stored_values(t)

def output_stored_values(self, t):
# Outputs all values stored until now with the correct annotation type
if len(self.stored_values) == 0:
# Outputs all values stored until now at the current row with the correct annotation type and at the correct row
if len(self.stored_values[self.current_row]) == 0:
return
if t == 'DATA':
self.put(self.ss, self.es, self.out_ann, [Ann.DATA, ['Data: ' + self.get_output(), 'Da', 'D']])
if self.current_row == 0:
self.put(self.ss[0], self.es[0], self.out_ann, [Ann.DATA, ['Data: ' + self.get_output(), 'Da', 'D']])
elif self.current_row == 1:
self.put(self.ss[1], self.es[1], self.out_ann, [Ann.DATA2, ['Data: ' + self.get_output(), 'Da', 'D']])
elif t == 'ADDR':
self.put(self.ss, self.es, self.out_ann, [Ann.ADDRESS, ['Address: ' + self.get_output(), 'Add', 'A']])
if self.current_row == 0:
self.put(self.ss[0], self.es[0], self.out_ann, [Ann.ADDRESS, ['Address: ' + self.get_output(), 'Add', 'A']])
elif self.current_row == 1:
self.put(self.ss[1], self.es[1], self.out_ann, [Ann.ADDRESS2, ['Address: ' + self.get_output(), 'Add', 'A']])

# Resets the current state, stored values and separation sequence pointer
self.reset()
# Resets the current state, stored values and separation sequence pointer for the current row
self.state[self.current_row] = 'NEUTRAL'
self.stored_values[self.current_row] = []
self.separation_sequence_pointer[self.current_row] = 0

def have_to_output(self):
# Returns True if the options indicate that a new packet should be started and the previous one finished
return self.options['max-packet-length'] == len(self.stored_values) or self.is_separated_by_sequence()
return self.options['max-packet-length'] == len(self.stored_values[self.current_row]) or self.is_separated_by_sequence()

def is_separated_by_sequence(self):
# Returns True if the sequence separation is active and the pointer indicates the need of separation
return (self.options['use-separator-sequence'] == 'yes' and
0 < len(self.separation_sequence) <= self.separation_sequence_pointer)
0 < len(self.separation_sequence) <= self.separation_sequence_pointer[self.current_row])

def move_separation_sequence_pointer(self, value):
# If the sequence separation is active
Expand All @@ -110,32 +125,32 @@ def move_separation_sequence_pointer(self, value):

# ...and this value is starting a separation sequence or following an already
# started separation sequence, move the separation sequence pointer potentially causing separation
if str(hex(value).replace("0x", "")) == self.separation_sequence[self.separation_sequence_pointer]:
self.separation_sequence_pointer += 1
if str(hex(value).replace("0x", "")) == self.separation_sequence[self.separation_sequence_pointer[self.current_row]]:
self.separation_sequence_pointer[self.current_row] += 1
# ...otherwise reset separation sequence pointer
else:
self.separation_sequence_pointer = 0
self.separation_sequence_pointer[self.current_row] = 0

def get_output(self):
# If the options say so, the separation sequence characters should be excluded from the output
if self.is_separated_by_sequence() and self.options['display-separator-sequence'] == 'no':
for _ in self.separation_sequence:
self.stored_values.pop()
self.stored_values[self.current_row].pop()

# Get the output from the stored values according to output and input binary format options
# Get the output from the values stored in the current row according to output and input binary format options
output = ''
if self.options['output-format'] == 'dec':
for b in self.stored_values:
for b in self.stored_values[self.current_row]:
if self.options['input-binary-format'] == 'BCD':
b = bcd2int(b)
output = output + ' ' + str(b)
elif self.options['output-format'] == 'bin':
for b in self.stored_values:
for b in self.stored_values[self.current_row]:
if self.options['input-binary-format'] == 'BCD':
b = bcd2int(b)
output = output + ' ' + str(bin(b).replace("0b", ""))
elif self.options['output-format'] == 'ASCII':
for b in self.stored_values:
for b in self.stored_values[self.current_row]:
if self.options['input-binary-format'] == 'BCD':
b = bcd2int(b)

Expand All @@ -155,51 +170,55 @@ def get_output(self):
b = "\ufffd"
output = output + b
elif self.options['output-format'] == 'hex':
for b in self.stored_values:
for b in self.stored_values[self.current_row]:
if self.options['input-binary-format'] == 'BCD':
b = bcd2int(b)
output = output + ' ' + hex(b)
return output

# Any addition to stored values should be done via this method
def add_to_stored_values(self, value):
self.stored_values.append(value)
self.stored_values[self.current_row].append(value)
self.move_separation_sequence_pointer(value)

def decode(self, ss, es, data):
cmd, data_value = data
cmd, data_value, row = data

# Data values are stored for each row separately and separation conditions are checked for each row separately
# Therefore, current_row has to be set before the processing of the next data value can start
self.current_row = row

# State machine.
if self.state == 'NEUTRAL':
self.ss = ss
if self.state[self.current_row] == 'NEUTRAL':
self.ss[self.current_row] = ss

if cmd == 'DATA':
# If has not finished collecting an ADDRESS packet yet, finish it now
if self.state == 'RECEIVING ADDRESS':
if self.state[self.current_row] == 'RECEIVING ADDRESS':
self.output_stored_values('ADDR')
self.ss = ss
self.ss[self.current_row] = ss

# We are receiving DATA packets now
self.state = 'RECEIVING DATA'
# Set the end of the current packet for now
self.es = es
# On this row we are receiving DATA packets now
self.state[self.current_row] = 'RECEIVING DATA'
# Set the end of the current packet on this row for now
self.es[self.current_row] = es

self.add_to_stored_values(data_value)

# Send all data values stored until now if it is suitable and clear the buffer
# Send all data values stored in this row until now if it is necessary and clear the buffer
self.manage_stored_values('DATA')
elif cmd == 'ADDRESS':
# If has not finished collecting a DATA packet yet, finish it now
if self.state == 'RECEIVING DATA':
if self.state[self.current_row] == 'RECEIVING DATA':
self.output_stored_values('DATA')
self.ss = ss
self.ss[self.current_row] = ss

# We are receiving ADDRESS packets now
self.state = 'RECEIVING ADDRESS'
# Set the end of the current packet for now
self.es = es
# On this row we are receiving ADDRESS packets now
self.state[self.current_row] = 'RECEIVING ADDRESS'
# Set the end of the current packet on this row for now
self.es[self.current_row] = es

self.add_to_stored_values(data_value)

# Send all address values stored until now if it is suitable and clear the buffer
# Send all address values stored in this row until now if it is necessary and clear the buffer
self.manage_stored_values('ADDR')

0 comments on commit 7898362

Please sign in to comment.