修正bug
This commit is contained in:
+33
-22
@@ -20,7 +20,7 @@
|
||||
|
||||
import sigrokdecode as srd
|
||||
|
||||
ann_bit,ann_bit2, ann_stat_bit, ann_type, ann_command, ann_parameter, ann_parity, ann_type2, ann_command2, ann_parameter2, ann_parity2, ann_pos,ann_pos2, ann_status, ann_warning = range(15)
|
||||
ann_bit,ann_bit2, ann_stat_bit, ann_type, ann_command, ann_parameter, ann_parity, ann_type2, ann_command2, ann_parameter2, ann_parity2, ann_pos,ann_pos2, ann_status, ann_warning, ann_warning2 = range(16)
|
||||
frame_type_none, frame_type_command, frame_type_16bit_pos, frame_type_18bit_pos = range(4)
|
||||
|
||||
class Decoder(srd.Decoder):
|
||||
@@ -46,15 +46,22 @@ class Decoder(srd.Decoder):
|
||||
)
|
||||
|
||||
annotations = (
|
||||
('bit', 'Data Bit'),
|
||||
('bit', 'Data Bit'),
|
||||
('stat_bit', 'Status Bit'),
|
||||
('type', 'Frame Type'),
|
||||
('command', 'Command'),
|
||||
('parameter', 'Parameter'),
|
||||
('parity', 'Parity'),
|
||||
('type', 'Frame Type'),
|
||||
('command', 'Command'),
|
||||
('parameter', 'Parameter'),
|
||||
('parity', 'Parity'),
|
||||
('position', 'Position'),
|
||||
('position', 'Position'),
|
||||
('status', 'Status'),
|
||||
('warning', 'Human-readable warnings'),
|
||||
('warning', 'Human-readable warnings'),
|
||||
)
|
||||
annotation_rows = (
|
||||
('bits', 'Data Bits', (ann_bit,)),
|
||||
@@ -66,16 +73,20 @@ class Decoder(srd.Decoder):
|
||||
('positions2', 'Positions2', (ann_pos2,)),
|
||||
('statuses', 'Statuses', (ann_status,)),
|
||||
('warnings', 'Warnings', (ann_warning,)),
|
||||
('warnings', 'Warnings', (ann_warning2,)),
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
self.samplerate = None
|
||||
self.reset()
|
||||
self.reset2()
|
||||
|
||||
def reset(self):
|
||||
self.bits = []
|
||||
self.stat_bits = []
|
||||
self.stat_skip_bit = True
|
||||
def reset2(self):
|
||||
self.bits2 = []
|
||||
|
||||
def metadata(self, key, value):
|
||||
if key == srd.SRD_CONF_SAMPLERATE:
|
||||
@@ -199,12 +210,12 @@ class Decoder(srd.Decoder):
|
||||
|
||||
def process_bit2(self, sync, bit_ss, bit_es, bit2_value):
|
||||
self.put_ann(bit_ss, bit_es, ann_bit2, ['%d' % bit2_value])
|
||||
self.bits.append((bit_ss, bit_es, bit2_value))
|
||||
self.bits2.append((bit_ss, bit_es, bit2_value))
|
||||
|
||||
if sync == 0:
|
||||
if len(self.bits) < 20:
|
||||
self.put_ann(self.bits[0][0], bit_es, ann_warning, ['Not enough data bits'])
|
||||
self.reset()
|
||||
if len(self.bits2) < 20:
|
||||
self.put_ann(self.bits2[0][0], bit_es, ann_warning2, ['Not enough data bits 0x%X' % len(self.bits2)])
|
||||
self.reset2()
|
||||
return
|
||||
|
||||
# Bit structure:
|
||||
@@ -215,10 +226,10 @@ class Decoder(srd.Decoder):
|
||||
|
||||
# Calculate parity, excluding the parity bit itself
|
||||
parity = 0
|
||||
for ss, es, value in self.bits[:-1]:
|
||||
for ss, es, value in self.bits2[:-1]:
|
||||
parity ^= value
|
||||
|
||||
par_ss, par_es, par_value = self.bits[19]
|
||||
par_ss, par_es, par_value = self.bits2[19]
|
||||
parity_even = 0
|
||||
parity_odd = 0
|
||||
if (par_value == parity):
|
||||
@@ -226,20 +237,20 @@ class Decoder(srd.Decoder):
|
||||
else:
|
||||
parity_odd = 1
|
||||
|
||||
type_1_value = self.bits[0][2]
|
||||
type_3_value = (self.bits[0][2] << 2) | (self.bits[1][2] << 1) | self.bits[2][2]
|
||||
type_1_value = self.bits2[0][2]
|
||||
type_3_value = (self.bits2[0][2] << 2) | (self.bits2[1][2] << 1) | self.bits2[2][2]
|
||||
|
||||
# Determine frame type
|
||||
type = frame_type_none
|
||||
parity_status = ['X', 'Unknown']
|
||||
type_ss = self.bits[0][0]
|
||||
type_es = self.bits[2][1]
|
||||
type_ss = self.bits2[0][0]
|
||||
type_es = self.bits2[2][1]
|
||||
|
||||
### 18-bit position
|
||||
if (type_1_value == 1) and (parity_odd == 1):
|
||||
type = frame_type_18bit_pos
|
||||
type_es = self.bits[0][1]
|
||||
self.put_ann(self.bits[0][0], bit_es, ann_warning, ['Careful: 18-bit position frames with wrong parity and command frames with wrong parity cannot be identified'])
|
||||
type_es = self.bits2[0][1]
|
||||
self.put_ann(self.bits2[0][0], bit_es, ann_warning2, ['Careful: 18-bit position frames with wrong parity and command frames with wrong parity cannot be identified'])
|
||||
### 16-bit position
|
||||
elif (type_3_value == 1):
|
||||
type = frame_type_16bit_pos
|
||||
@@ -247,15 +258,15 @@ class Decoder(srd.Decoder):
|
||||
parity_status = ['OK']
|
||||
else:
|
||||
parity_status = ['NOK']
|
||||
self.put_ann(self.bits[0][0], bit_es, ann_warning, ['Parity error', 'PE'])
|
||||
self.put_ann(self.bits2[0][0], bit_es, ann_warning2, ['Parity error', 'PE'])
|
||||
### Command
|
||||
elif (type_3_value == 7) and (parity_even == 1):
|
||||
type = frame_type_command
|
||||
self.put_ann(self.bits[0][0], bit_es, ann_warning, ['Careful: 18-bit position frames with wrong parity and command frames with wrong parity cannot be identified'])
|
||||
self.put_ann(self.bits2[0][0], bit_es, ann_warning2, ['Careful: 18-bit position frames with wrong parity and command frames with wrong parity cannot be identified'])
|
||||
### Other
|
||||
else:
|
||||
self.put_ann(self.bits[0][0], bit_es, ann_warning, ['Error', 'Unknown command or parity error'])
|
||||
self.reset()
|
||||
self.put_ann(self.bits2[0][0], bit_es, ann_warning2, ['Error', 'Unknown command or parity error'])
|
||||
self.reset2()
|
||||
return
|
||||
|
||||
# Output command and parity annotations
|
||||
@@ -274,13 +285,13 @@ class Decoder(srd.Decoder):
|
||||
|
||||
if (type == frame_type_16bit_pos):
|
||||
count = 15
|
||||
for ss, es, value in self.bits[3:19]:
|
||||
for ss, es, value in self.bits2[3:19]:
|
||||
pos |= value << count
|
||||
count -= 1
|
||||
# pos = pos if pos < 32768 else pos - 65536
|
||||
else:
|
||||
count = 17
|
||||
for ss, es, value in self.bits[3:19]:
|
||||
for ss, es, value in self.bits2[3:19]:
|
||||
pos |= value << count
|
||||
count -= 1
|
||||
pos = pos if pos < 131072 else pos - 262144
|
||||
@@ -291,7 +302,7 @@ class Decoder(srd.Decoder):
|
||||
count = 7
|
||||
cmd = 0
|
||||
cmd_es = 0
|
||||
for ss, es, value in self.bits[3:11]:
|
||||
for ss, es, value in self.bits2[3:11]:
|
||||
cmd |= value << count
|
||||
count -= 1
|
||||
cmd_es = es
|
||||
@@ -299,12 +310,12 @@ class Decoder(srd.Decoder):
|
||||
|
||||
count = 7
|
||||
param = 0
|
||||
for ss, es, value in self.bits[11:19]:
|
||||
for ss, es, value in self.bits2[11:19]:
|
||||
param |= value << count
|
||||
count -= 1
|
||||
self.put_ann(cmd_es, par_ss, ann_parameter2, ['Parameter 0x%X / %d' % (param, param), '0x%X / %d' % (param, param),'0x%X' % param])
|
||||
|
||||
self.reset()
|
||||
self.reset2()
|
||||
|
||||
def process_stat_bit(self, sync, bit_ss, bit_es, bit_value):
|
||||
if self.stat_skip_bit:
|
||||
|
||||
Reference in New Issue
Block a user