17
17
## along with this program; if not, see <http://www.gnu.org/licenses/>.
18
18
##
19
19
20
+ ##
21
+ ## 2024/7/30 DreamSourceLab : Allow adjustment of data structure and pulse width timing for high and low levels
22
+ ##
23
+
20
24
import sigrokdecode as srd
21
25
22
26
class SamplerateError (Exception ):
@@ -60,11 +64,14 @@ class SamplerateError(Exception):
60
64
True : 24.0 ,
61
65
},
62
66
},
67
+ #Frame
63
68
'SLOT' : {
69
+ #Frame End
64
70
'min' : {
65
71
False : 60.0 ,
66
72
True : 6.0 ,
67
73
},
74
+ #Frame Mid
68
75
'max' : {
69
76
False : 120.0 ,
70
77
True : 16.0 ,
@@ -77,10 +84,12 @@ class SamplerateError(Exception):
77
84
},
78
85
},
79
86
'LOWR' : {
87
+ # if time < min , is too short
80
88
'min' : {
81
89
False : 1.0 ,
82
90
True : 1.0 ,
83
91
},
92
+ # if time > max , bit = 1, else bit = 0
84
93
'max' : {
85
94
False : 15.0 ,
86
95
True : 2.0 ,
@@ -104,6 +113,12 @@ class Decoder(srd.Decoder):
104
113
options = (
105
114
{'id' : 'overdrive' , 'desc' : 'Start in overdrive speed' ,
106
115
'default' : 'no' , 'values' : ('yes' , 'no' ), 'idn' :'dec_onewire_link_opt_overdrive' },
116
+ {'id' : 'min height level pulse time' , 'desc' : 'min height level pulse time(us)' ,
117
+ 'default' : 2.0 , 'idn' :'dec_onewire_link_opt_min_height_level_pulse_time' },
118
+ {'id' : 'min overdrive height level pulse time' , 'desc' : 'min overdrive height level pulse time(us)' ,
119
+ 'default' : 15.0 , 'idn' :'dec_onewire_link_opt_min_overdrive_height_level_pulse_time' },
120
+ {'id' : 'data order' , 'desc' : 'data order' ,
121
+ 'default' : 'bit first' , 'values' : ('bit first' , 'space first' ),'idn' :'dec_can_opt_data_order' },
107
122
)
108
123
annotations = (
109
124
('bit' , 'Bit' ),
@@ -129,13 +144,18 @@ def reset(self):
129
144
self .bit_count = - 1
130
145
self .command = 0
131
146
self .overdrive = False
147
+ self .bit_first = True
132
148
self .fall = 0
133
149
self .rise = 0
134
150
135
151
def start (self ):
136
152
self .out_python = self .register (srd .OUTPUT_PYTHON )
137
153
self .out_ann = self .register (srd .OUTPUT_ANN )
138
154
self .overdrive = (self .options ['overdrive' ] == 'yes' )
155
+ self .bit_first = (self .options ['data order' ] == 'bit first' )
156
+ timing ['LOWR' ]['max' ][False ] = float (self .options ['min height level pulse time' ])
157
+ timing ['LOWR' ]['max' ][True ] = float (self .options ['min overdrive height level pulse time' ])
158
+
139
159
self .fall = 0
140
160
self .rise = 0
141
161
self .bit_count = - 1
@@ -188,6 +208,19 @@ def wait_falling_timeout(self, start, t):
188
208
samples_to_skip = samples_to_skip if (samples_to_skip > 0 ) else 0
189
209
return self .wait ([{0 : 'f' }, {'skip' : samples_to_skip }])
190
210
211
+ def MinBitTimeOutput (self , time ):
212
+ if time < timing ['LOWR' ]['min' ][self .overdrive ]:
213
+ self .putfr ([1 , ['Low signal not long enough' ,
214
+ 'Low too short' ,
215
+ 'LOW < ' + str (timing ['LOWR' ]['min' ][self .overdrive ])]])
216
+
217
+ def GetBitValue (self , time ):
218
+ if time > timing ['LOWR' ]['max' ][self .overdrive ]:
219
+ self .bit = 1 #Long pulse is a 1 bit.
220
+ else :
221
+ self .bit = 0 #Short pulse is a 0 bit.
222
+
223
+
191
224
def decode (self ):
192
225
if not self .samplerate :
193
226
raise SamplerateError ('Cannot decode without samplerate.' )
@@ -237,16 +270,13 @@ def decode(self):
237
270
# Overdrive reset pulse.
238
271
self .putfr ([2 , ['Reset' , 'Rst' , 'R' ]])
239
272
self .state = 'PRESENCE DETECT HIGH'
273
+ #Frame
240
274
elif time < timing ['SLOT' ]['max' ][self .overdrive ]:
241
- # Read/write time slot.
242
- if time < timing ['LOWR' ]['min' ][self .overdrive ]:
243
- self .putfr ([1 , ['Low signal not long enough' ,
244
- 'Low too short' ,
245
- 'LOW < ' + str (timing ['LOWR' ]['min' ][self .overdrive ])]])
246
- if time < timing ['LOWR' ]['max' ][self .overdrive ]:
247
- self .bit = 1 # Short pulse is a 1 bit.
248
- else :
249
- self .bit = 0 # Long pulse is a 0 bit.
275
+ if self .bit_first == True :
276
+ # Read/write time slot.
277
+ self .MinBitTimeOutput (time )
278
+ self .GetBitValue (time )
279
+
250
280
# Wait for end of slot.
251
281
self .state = 'SLOT'
252
282
else :
@@ -305,6 +335,12 @@ def decode(self):
305
335
self .state = 'LOW'
306
336
else : # End of time slot.
307
337
# Output bit.
338
+ if self .bit_first == False :
339
+ time = ((self .samplenum - self .rise ) / self .samplerate ) * 1000000.0
340
+ # Read/write time slot.
341
+ self .MinBitTimeOutput (time )
342
+ self .GetBitValue (time )
343
+
308
344
self .putfs ([0 , ['Bit: %d' % self .bit , '%d' % self .bit ]])
309
345
self .putpfs (['BIT' , self .bit ])
310
346
# Save command bits.
0 commit comments