From ed561b6b1c2eaed18bf319662c25db85697d96cb Mon Sep 17 00:00:00 2001 From: chenyue Date: Thu, 9 Jul 2026 17:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=A1=E5=8F=B7=E5=8F=96?= =?UTF-8?q?=E5=8F=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sl2-100/pd.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/sl2-100/pd.py b/sl2-100/pd.py index ce5b367..3b0f5a4 100644 --- a/sl2-100/pd.py +++ b/sl2-100/pd.py @@ -45,7 +45,8 @@ class Decoder(srd.Decoder): options = ( # 一个数据周期10us {'id': 'datatime', 'desc': '数据传输时间(ns)', 'default': 10000}, - {'id': 'filename', 'desc': '解码输出文件名','default':'d:/sl2-100.csv'}, + {'id': 'filename', 'desc': '解码输出文件名','default':'d:/sl2-100.csv'}, + {'id': 'invert', 'desc': 'Invert Signal?', 'default': 'no','values': ('yes', 'no'), 'idn':'opt_invert'}, ) # 解析结果项定义 # annotations里的每一项可以有2到3个属性,当有3个属性时,第一个表示类型 @@ -245,16 +246,24 @@ class Decoder(srd.Decoder): self.oldsamplenum = self.samplenum self.highpin = 0 #当前采样宽度(78.125ns)内高电平数量 self.lowpin = 0 #当前采样宽度(78.125ns)内低电平数量 + #当前电平值是否取反 + inv = self.options['invert'] == 'yes' while True: if self.state2 == 'FIND START': #self.file.write('FIND START'+ '\n') - self.wait({0: 'l'}) + if inv: + self.wait({0: 'h'}) + else: + 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'}) + if inv: + self.wait({0: 'e'}) + else: + self.wait({0: 'e'}) start_width = self.samplenum - self.oldsamplenum self.oldsamplenum = self.samplenum if start_width >= self.bit_width*2.2: @@ -264,6 +273,9 @@ class Decoder(srd.Decoder): if self.state2 == 'FIND START3': #self.file.write('FIND START3'+ '\n') (pin,) = self.wait({0:'n'}) + if inv: + pin =not pin + #当前已经累积的采样宽度 total_width = self.samplenum - self.oldsamplenum if total_width>=self.bit_width : #累积采样宽度接近设置的采样次数 @@ -272,6 +284,8 @@ class Decoder(srd.Decoder): if self.state2 == 'FIND DATA': #self.file.write('FIND DATA'+ '\n') (pin,) = self.wait({0:'n'}) + if inv: + pin = not pin #当前已经累积的采样宽度 total_width = self.samplenum - self.oldsamplenum if pin==1: @@ -294,4 +308,4 @@ class Decoder(srd.Decoder): # 底层模块提供的属性: # 1. self.samplenum 当前wait()调用匹配结束的采样点位置 # 2. self.matched 本次调用wait()后所有通道的匹配结果信息,是一个uint64类型数值, - # 表示0到63个通道的匹配信息,通过位运算来获取具体信息。 + # 表示0到63个通道的匹配信息,通过位运算来获取具体� \ No newline at end of file