修正位置最高位值要取反
This commit is contained in:
+47
-15
@@ -99,6 +99,7 @@ class Decoder(srd.Decoder):
|
||||
self.yv_cnt = 0 #y坐标校验累积的数据位个数
|
||||
self.yv_first = 0 #y坐标校验起始位置
|
||||
self.state = 'HEADER' #当前处理的字段
|
||||
self.state2 = 'FIND START' #当前处理的字段
|
||||
self.data = 0 #存放坐标值数据
|
||||
self.highpin = 0 #当前采样宽度(78.125ns)内高电平数量
|
||||
self.lowpin = 0 #当前采样宽度(78.125ns)内低电平数量
|
||||
@@ -126,14 +127,17 @@ class Decoder(srd.Decoder):
|
||||
if self.state == 'HEADER':
|
||||
self.header_str += str(bit)
|
||||
self.head_cnt = self.head_cnt+1
|
||||
if self.head_cnt == 8:
|
||||
if self.head_cnt == 6:
|
||||
self.put(self.header_first, es, self.out_ann,[2, ['HEADER_x:' + self.header_str]])
|
||||
self.state = 'xpos'
|
||||
self.xpos_first = es
|
||||
self.xpos_cnt = 0 #当前坐标 位数归零,准备累积
|
||||
self.data = 0 #当前坐标值归零,准备开始累积
|
||||
elif self.state == 'xpos':
|
||||
self.data = (bit << self.xpos_cnt) | self.data
|
||||
if self.xpos_cnt == 19:
|
||||
self.data = ((not bit) << self.xpos_cnt) | self.data
|
||||
else:
|
||||
self.data = (bit << self.xpos_cnt) | self.data
|
||||
self.xpos_cnt = self.xpos_cnt+1
|
||||
if self.xpos_cnt == 20:
|
||||
self.put(self.xpos_first, es, self.out_ann,[3, ['X坐标:' + ': 0x%x' % self.data + ' = %d' % self.data]])
|
||||
@@ -162,7 +166,10 @@ class Decoder(srd.Decoder):
|
||||
self.ypos_cnt = 0 #当前坐标 位数归零,准备累积
|
||||
self.data = 0 #当前坐标值归零,准备开始累积
|
||||
elif self.state == 'ypos':
|
||||
self.data = (bit << self.ypos_cnt) | self.data
|
||||
if self.ypos_cnt == 19:
|
||||
self.data = ((not bit) << self.ypos_cnt) | self.data
|
||||
else:
|
||||
self.data = (bit << self.ypos_cnt) | self.data
|
||||
self.ypos_cnt = self.ypos_cnt+1
|
||||
if self.ypos_cnt == 20:
|
||||
self.put(self.ypos_first, es, self.out_ann,[7, ['y坐标:' + ': 0x%x' % self.data + ' = %d' % self.data]])
|
||||
@@ -178,6 +185,7 @@ class Decoder(srd.Decoder):
|
||||
if self.yv_cnt == 4:
|
||||
self.put(self.yv_first, es, self.out_ann,[9, ['y校验:' + self.yv_str]])
|
||||
self.state = 'HEADER'
|
||||
self.state2 = 'FIND START'
|
||||
self.header_first = es
|
||||
self.head_cnt = 0
|
||||
self.header_str = ""
|
||||
@@ -223,18 +231,42 @@ class Decoder(srd.Decoder):
|
||||
self.lowpin = 0 #当前采样宽度(78.125ns)内低电平数量
|
||||
|
||||
while True:
|
||||
(pin,) = self.wait({0:'n'})
|
||||
#当前已经累积的采样宽度
|
||||
total_width = self.samplenum - self.oldsamplenum
|
||||
if pin==1:
|
||||
self.highpin += 1 #当前采样宽度内高电平数量加1
|
||||
else:
|
||||
self.lowpin += 1 #当前采样宽度内低电平数量加1
|
||||
if total_width>=self.bit_width : #累积采样宽度接近设置的采样次数
|
||||
self.oldsamplenum = self.oldsamplenum+self.bit_width #当前采样结束作为下一采样的开始
|
||||
self.manchester_decode(1 if self.highpin > self.lowpin else 0)
|
||||
self.highpin = 0 #当前采样宽度(78.125ns)内高电平数量
|
||||
self.lowpin = 0 #当前采样宽度(78.125ns)内低电平数量
|
||||
if self.state2 == 'FIND START':
|
||||
#self.file.write('FIND START'+ '\n')
|
||||
self.wait({0: 'l'})
|
||||
self.oldsamplenum = self.samplenum
|
||||
self.state2 = 'FIND START2'
|
||||
if self.state2 == 'FIND START2':
|
||||
#self.file.write('FIND START2'+ '\n')
|
||||
self.wait({0: 'r'})
|
||||
start_width = self.samplenum - self.oldsamplenum
|
||||
self.oldsamplenum = self.samplenum
|
||||
if start_width >= self.bit_width*2.2:
|
||||
self.state2 = 'FIND START3'
|
||||
else:
|
||||
self.state2 = 'FIND START'
|
||||
if self.state2 == 'FIND START3':
|
||||
#self.file.write('FIND START3'+ '\n')
|
||||
(pin,) = self.wait({0:'n'})
|
||||
#当前已经累积的采样宽度
|
||||
total_width = self.samplenum - self.oldsamplenum
|
||||
if total_width>=self.bit_width : #累积采样宽度接近设置的采样次数
|
||||
self.state2 = 'FIND DATA'
|
||||
self.oldsamplenum = self.samplenum
|
||||
if self.state2 == 'FIND DATA':
|
||||
#self.file.write('FIND DATA'+ '\n')
|
||||
(pin,) = self.wait({0:'n'})
|
||||
#当前已经累积的采样宽度
|
||||
total_width = self.samplenum - self.oldsamplenum
|
||||
if pin==1:
|
||||
self.highpin += 1 #当前采样宽度内高电平数量加1
|
||||
else:
|
||||
self.lowpin += 1 #当前采样宽度内低电平数量加1
|
||||
if total_width>=self.bit_width : #累积采样宽度接近设置的采样次数
|
||||
self.oldsamplenum = self.oldsamplenum+self.bit_width #当前采样结束作为下一采样的开始
|
||||
self.manchester_decode(1 if self.highpin > self.lowpin else 0)
|
||||
self.highpin = 0 #当前采样宽度(78.125ns)内高电平数量
|
||||
self.lowpin = 0 #当前采样宽度(78.125ns)内低电平数量
|
||||
# self.wait()可带参数,也可以不带参数,不带参数时将返回每个采样数据
|
||||
# 参数{0:'r'}, 0表示匹配channels第1项绑定的通道,'r'表示查找向上边沿
|
||||
# wait函数可传多个条件,与条件:{0:'f',1:'r'}, 或条件:[{0:'f'},{1:'r'}]
|
||||
|
||||
Reference in New Issue
Block a user