From 3b027abe705de8048975b0024c1d299297229466 Mon Sep 17 00:00:00 2001 From: yunyaobaihong <896458252@qq.com> Date: Fri, 16 Aug 2024 17:08:55 +0800 Subject: [PATCH] Decoder Update : cjtag , onewire_link and sbus --- libsigrokdecode4DSL/decoders/cjtag/pd.py | 8 +++ .../decoders/onewire_link/pd.py | 54 +++++++++++++++---- .../decoders/sbus_futaba/pd.py | 6 +++ 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/libsigrokdecode4DSL/decoders/cjtag/pd.py b/libsigrokdecode4DSL/decoders/cjtag/pd.py index cd4dc4e5..218739aa 100644 --- a/libsigrokdecode4DSL/decoders/cjtag/pd.py +++ b/libsigrokdecode4DSL/decoders/cjtag/pd.py @@ -4,6 +4,7 @@ ## Copyright (C) 2012-2020 Uwe Hermann ## Copyright (C) 2019 Zhiyuan Wan ## Copyright (C) 2019 Kongou Hikari +## Copyright (C) 2024 DreamSourceLab ## ## 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 @@ -19,6 +20,11 @@ ## along with this program; if not, see . ## +## +## 2024/8/7 DreamSourceLab : Display data when zooming out +## 2024/8/16 DreamSourceLab : Added a filter to remove non-binary data +## + import sigrokdecode as srd from common.srdhelper import SrdStrEnum @@ -257,6 +263,7 @@ class Decoder(srd.Decoder): t = self.state.value[-2:] + ' TDI' b = ''.join(map(str, self.bits_tdi[1:])) + b = ''.join(filter(lambda x: x in '01', b)) h = ' (0x%x' % int('0b0' + b, 2) + ')' s = t + ': ' + b + h + ', ' + str(len(self.bits_tdi[1:])) + ' bits' self.putx_bs([30, [s]]) @@ -266,6 +273,7 @@ class Decoder(srd.Decoder): t = self.state.value[-2:] + ' TDO' b = ''.join(map(str, self.bits_tdo[1:])) + b = ''.join(filter(lambda x: x in '01', b)) h = ' (0x%x' % int('0b0' + b, 2) + ')' s = t + ': ' + b + h + ', ' + str(len(self.bits_tdo[1:])) + ' bits' self.putx_bs([31, [s]]) diff --git a/libsigrokdecode4DSL/decoders/onewire_link/pd.py b/libsigrokdecode4DSL/decoders/onewire_link/pd.py index b56e168c..42906f37 100644 --- a/libsigrokdecode4DSL/decoders/onewire_link/pd.py +++ b/libsigrokdecode4DSL/decoders/onewire_link/pd.py @@ -17,6 +17,10 @@ ## along with this program; if not, see . ## +## +## 2024/7/30 DreamSourceLab : Allow adjustment of data structure and pulse width timing for high and low levels +## + import sigrokdecode as srd class SamplerateError(Exception): @@ -60,11 +64,14 @@ timing = { True: 24.0, }, }, + #Frame 'SLOT': { + #Frame End 'min': { False: 60.0, True: 6.0, }, + #Frame Mid 'max': { False: 120.0, True: 16.0, @@ -77,10 +84,12 @@ timing = { }, }, 'LOWR': { + # if time < min , is too short 'min': { False: 1.0, True: 1.0, }, + # if time > max , bit = 1, else bit = 0 'max': { False: 15.0, True: 2.0, @@ -104,6 +113,12 @@ class Decoder(srd.Decoder): options = ( {'id': 'overdrive', 'desc': 'Start in overdrive speed', 'default': 'no', 'values': ('yes', 'no'), 'idn':'dec_onewire_link_opt_overdrive'}, + {'id': 'min height level pulse time', 'desc': 'min height level pulse time(us)', + 'default': 2.0, 'idn':'dec_onewire_link_opt_min_height_level_pulse_time'}, + {'id': 'min overdrive height level pulse time', 'desc': 'min overdrive height level pulse time(us)', + 'default': 15.0, 'idn':'dec_onewire_link_opt_min_overdrive_height_level_pulse_time'}, + {'id': 'data order', 'desc': 'data order', + 'default': 'bit first', 'values': ('bit first', 'space first'),'idn':'dec_can_opt_data_order'}, ) annotations = ( ('bit', 'Bit'), @@ -129,6 +144,7 @@ class Decoder(srd.Decoder): self.bit_count = -1 self.command = 0 self.overdrive = False + self.bit_first = True self.fall = 0 self.rise = 0 @@ -136,6 +152,10 @@ class Decoder(srd.Decoder): self.out_python = self.register(srd.OUTPUT_PYTHON) self.out_ann = self.register(srd.OUTPUT_ANN) self.overdrive = (self.options['overdrive'] == 'yes') + self.bit_first = (self.options['data order'] == 'bit first') + timing['LOWR']['max'][False] = float(self.options['min height level pulse time']) + timing['LOWR']['max'][True] = float(self.options['min overdrive height level pulse time']) + self.fall = 0 self.rise = 0 self.bit_count = -1 @@ -188,6 +208,19 @@ class Decoder(srd.Decoder): samples_to_skip = samples_to_skip if (samples_to_skip > 0) else 0 return self.wait([{0: 'f'}, {'skip': samples_to_skip}]) + def MinBitTimeOutput(self, time): + if time < timing['LOWR']['min'][self.overdrive]: + self.putfr([1, ['Low signal not long enough', + 'Low too short', + 'LOW < ' + str(timing['LOWR']['min'][self.overdrive])]]) + + def GetBitValue(self, time): + if time > timing['LOWR']['max'][self.overdrive]: + self.bit = 1 #Long pulse is a 1 bit. + else: + self.bit = 0 #Short pulse is a 0 bit. + + def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') @@ -237,16 +270,13 @@ class Decoder(srd.Decoder): # Overdrive reset pulse. self.putfr([2, ['Reset', 'Rst', 'R']]) self.state = 'PRESENCE DETECT HIGH' + #Frame elif time < timing['SLOT']['max'][self.overdrive]: - # Read/write time slot. - if time < timing['LOWR']['min'][self.overdrive]: - self.putfr([1, ['Low signal not long enough', - 'Low too short', - 'LOW < ' + str(timing['LOWR']['min'][self.overdrive])]]) - if time < timing['LOWR']['max'][self.overdrive]: - self.bit = 1 # Short pulse is a 1 bit. - else: - self.bit = 0 # Long pulse is a 0 bit. + if self.bit_first == True: + # Read/write time slot. + self.MinBitTimeOutput(time) + self.GetBitValue(time) + # Wait for end of slot. self.state = 'SLOT' else: @@ -305,6 +335,12 @@ class Decoder(srd.Decoder): self.state = 'LOW' else: # End of time slot. # Output bit. + if self.bit_first == False: + time = ((self.samplenum - self.rise) / self.samplerate) * 1000000.0 + # Read/write time slot. + self.MinBitTimeOutput(time) + self.GetBitValue(time) + self.putfs([0, ['Bit: %d' % self.bit, '%d' % self.bit]]) self.putpfs(['BIT', self.bit]) # Save command bits. diff --git a/libsigrokdecode4DSL/decoders/sbus_futaba/pd.py b/libsigrokdecode4DSL/decoders/sbus_futaba/pd.py index 75c2cfba..22963c6f 100644 --- a/libsigrokdecode4DSL/decoders/sbus_futaba/pd.py +++ b/libsigrokdecode4DSL/decoders/sbus_futaba/pd.py @@ -2,6 +2,7 @@ ## This file is part of the libsigrokdecode project. ## ## Copyright (C) 2022 Gerhard Sittig +## Copyright (C) 2024 DreamSourceLab ## ## 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 @@ -17,6 +18,10 @@ ## along with this program; if not, see . ## +## +## 2024/7/5 DreamSourceLab : Fixing the issue of decoding only the first frame +## + """ OUTPUT_PYTHON format: @@ -223,6 +228,7 @@ class Decoder(srd.Decoder): # spans all unprocessed data, and improves perception. if self.sent_fields >= upto: self.msg_complete = True + self.sent_fields = 0 if self.msg_complete and self.bits_accum: self.failed = ['Excess data bits', 'Excess']