11import re
22from datetime import datetime
3- from saleae .analyzers import HighLevelAnalyzer , AnalyzerFrame , StringSetting
3+ from saleae .analyzers import HighLevelAnalyzer , AnalyzerFrame
4+ from saleae .analyzers import NumberSetting , StringSetting
45from saleae .data import GraphTimeDelta as GTD
56
67kTimeZero = datetime (1 , 1 , 1 )
@@ -73,11 +74,37 @@ def Drop(self, lastIndex):
7374 # the string. Trim the string and update the block start time
7475 startEpoch = block .start
7576 endEpoch = block .end
76- charTime = (endEpoch - startEpoch ) / strLen
7777 delChars = lastIndex - blockStartIndex
78- block .start = startEpoch + GTD (charTime * delChars )
78+ block .start = startEpoch + GTD (block . charTime * delChars )
7979 block .str = block .str [lastIndex - blockStartIndex : ]
80- block .charTime = charTime
80+ return
81+
82+ def DropBefore (self , timeDelta ):
83+ # Remove all blocks before the end time of the last block - timeDelta
84+ if not len (self .blocks ):
85+ return
86+
87+ # Calculate the cut off time
88+ cutOffTime = self .blocks [- 1 ].end - GTD (timeDelta )
89+
90+ while len (self .blocks ):
91+ block = self .blocks [0 ]
92+ strLen = len (block .str )
93+
94+ if block .start > cutOffTime :
95+ # Whole block is within allowed time span. Done
96+ return
97+
98+ if block .end < cutOffTime :
99+ # None of the block is within the allowed time span. Drop it.
100+ del self .blocks [0 ]
101+ continue
102+
103+ # The block spans the start of the allowed time span. Trim the
104+ # block.
105+ delCount = int ((float (cutOffTime - block .start ) + block .charTime ) / block .charTime )
106+ block .start += GTD (delCount * block .charTime )
107+ block .str = block .str [delCount : ]
81108 return
82109
83110 def Match (self , drop = False ):
@@ -142,6 +169,7 @@ def Match(self, drop = False):
142169class ReSearch (HighLevelAnalyzer ):
143170
144171 kMatch = StringSetting (label = "Match" )
172+ kMatchTime = StringSetting (label = "Max span (s)" )
145173
146174 result_types = {
147175 "Matched" : {"format" : "{{{data.Matched}}}" },
@@ -188,9 +216,7 @@ def AddData(self, params):
188216 if 'address' in params .data and params .data ["address" ]:
189217 asStr = '@' + hex (params .data ["data" ][0 ]) + ' '
190218
191- elif self .haveAddress \
192- or params .data ["data" ][0 ] > 127 \
193- or params .data ["data" ][0 ] < 32 :
219+ elif self .haveAddress or params .data ["data" ][0 ] > 127 :
194220 # I2C or other bus protocol with addressed devices or the character
195221 # from an async serial analyzer is outside the ASCII range
196222 asStr = hex (params .data ["data" ][0 ]) + ' '
@@ -218,6 +244,11 @@ def __init__(self):
218244 self .isSource = False
219245 self .Reset ()
220246
247+ if not len (self .kMatchTime ):
248+ self .kMatchTime = "0"
249+
250+ self .kMatchTime = float (str (self .kMatchTime ))
251+
221252 # handlers return True if a match should be attempted
222253 self .handlerDispatch = {
223254 "address" : self .AddAddress ,
@@ -238,6 +269,9 @@ def decode(self, newFrame: AnalyzerFrame):
238269 if not self .handlerDispatch [newFrame .type ](newFrame ):
239270 return
240271
272+ if self .kMatchTime :
273+ self .blocks .DropBefore (self .kMatchTime )
274+
241275 match = self .blocks .Match (drop = True )
242276
243277 if not match :
0 commit comments