text stringlengths 1 93.6k |
|---|
self.ctlc = False
|
self.thread = None
|
self._gen_char_list()
|
def _gen_char_list(self):
|
c = ' '
|
while c <= '~':
|
self.valid_characters.append(c)
|
c = chr(ord(c) + 1)
|
for c in self.WHITESPACE:
|
if c not in self.valid_characters:
|
self.valid_characters.append(c)
|
def _print(self, data):
|
if self.verbose:
|
sys.stderr.write(data)
|
def Open(self):
|
self.serial = serial.Serial(self.port, timeout=self.timeout)
|
self.NextBaudrate(0)
|
def NextBaudrate(self, updn):
|
self.index += updn
|
if self.index >= len(self.BAUDRATES):
|
self.index = 0
|
elif self.index < 0:
|
self.index = len(self.BAUDRATES) - 1
|
sys.stderr.write('\n\n@@@@@@@@@@@@@@@@@@@@@ Baudrate: %s @@@@@@@@@@@@@@@@@@@@@\n\n' % self.BAUDRATES[self.index])
|
self.serial.flush()
|
self.serial.baudrate = self.BAUDRATES[self.index]
|
self.serial.flush()
|
def Detect(self):
|
count = 0
|
whitespace = 0
|
punctuation = 0
|
vowels = 0
|
start_time = 0
|
timed_out = False
|
clear_counters = False
|
if not self.auto_detect:
|
self.thread = Thread(None, self.HandleKeypress, None, (self, 1))
|
self.thread.start()
|
while True:
|
if start_time == 0:
|
start_time = time.time()
|
byte = self.serial.read(1)
|
if byte:
|
if self.auto_detect and byte in self.valid_characters:
|
if byte in self.WHITESPACE:
|
whitespace += 1
|
elif byte in self.PUNCTUATION:
|
punctuation += 1
|
elif byte in self.VOWELS:
|
vowels += 1
|
count += 1
|
else:
|
clear_counters = True
|
self._print(byte)
|
if count >= self.threshold and whitespace > 0 and punctuation > 0 and vowels > 0:
|
break
|
elif (time.time() - start_time) >= self.timeout:
|
timed_out = True
|
else:
|
timed_out = True
|
if timed_out and self.auto_detect:
|
start_time = 0
|
self.NextBaudrate(-1)
|
clear_counters = True
|
timed_out = False
|
if clear_counters:
|
whitespace = 0
|
punctuation = 0
|
vowels = 0
|
count = 0
|
clear_counters = False
|
if self.ctlc:
|
break
|
self._print("\n")
|
return self.BAUDRATES[self.index]
|
def HandleKeypress(self, *args):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.