MCPcopy Index your code
hub / github.com/DreamSourceLab/DSView / decode

Method decode

libsigrokdecode4DSL/decoders/example/pd.py:140–186  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

138 # 奇数次显示第二行,偶数次显示在第一行,我们只指定annotations里定义的序号
139 # 软件会自动根据annotation_rows的设置,决定显示在哪一行
140 def decode(self):
141 # 次数计数
142 times = 0
143
144 # 向上边沿样品位置
145 rising_sample = 0
146
147 # 条件参数列表
148 flag_arr = [{0:'r'}, {0:'f'}]
149
150 # wait参数的条件序号
151 flag_dex = 0
152
153 # 不断循环,处理完所有数据
154 while True:
155 # 边沿条件
156 edge = flag_arr[flag_dex]
157
158 # 取一个条件,调用wait函数,找到符合条件的数据
159 # (a,b)是一个元组,里边的变量数一定要跟channel数一致
160 (a,b) = self.wait(edge)
161
162 # 条件在向上边沿和向下边沿中切换
163 # 初始是向上边沿,取到样品位置后,切换成下向边沿
164 if flag_dex == 0:
165 flag_dex = 1
166
167 # 保存向上边沿采样位置
168 rising_sample = self.samplenum
169 else:
170 flag_dex = 0
171
172 # 打印次数计数加1
173 times += 1
174
175 # 向下边沿采样位置
176 falling_sample = self.samplenum
177
178 # 向下边沿和向上边沿采样位置差
179 v = falling_sample - rising_sample
180
181 # 转换成16进制的字符串
182 s = '%02X' % v
183
184 # 对times求余得值在0和1中变换,对应annotation的序号
185 ann = times % 2
186 self.put_ann(rising_sample, falling_sample, ann, [s])
187
188
189 # self.wait()可带参数,也可以不带参数,不带参数时将返回每个采样数据

Callers

nothing calls this directly

Calls 2

put_annMethod · 0.95
waitMethod · 0.80

Tested by

no test coverage detected