-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatch.py
More file actions
executable file
·79 lines (61 loc) · 1.79 KB
/
watch.py
File metadata and controls
executable file
·79 lines (61 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
#
# Copyright 2014 Angus Ainslie <angus@akkea.ca>
# This software is licensed GPL V2
#
import serial
import array
import kiss
import AX25
import sys
done = False
debug = False
max_timeout = 10
def usage( name ) :
print "%s : [port[ baud]]" % name
print "\tport - serial port to listen to \"/dev/rfcomm0\", \"/dev/ttyUSB0\"\n"
print "\tbaud - port baud rate\n"
if len( sys.argv ) > 3 :
usage( sys.argv[0] )
sys.exit()
if len( sys.argv ) >= 2 :
port = sys.argv[1]
else :
port = '/dev/rfcomm0'
if len( sys.argv ) == 3 :
baud = int( sys.argv[2] )
else :
baud = 9600
print "Opening %s at %d baud" % ( port, baud )
ser = serial.Serial( port, baud, timeout=0.5)
remainder = ''
timeout = 0
while not done :
s = ser.read( 100 )
if len( s ) == 0 and len( remainder ) == 0 :
timeout = 0
else :
timeout += 1
if timeout > max_timeout and len( s ) == 0 and len( remainder ) > 0:
# timeout waiting for the reset of the packet
print "timeout wating for FEND"
timeout = 0
remainder =''
else :
print "Got chars %d %d %d" % ( timeout, len(s), len( remainder))
if len( remainder ) > 0 :
s = remainder + s
remainder = ''
if debug and len( s ) > 0 :
print "Hexdump: " + ":".join("{:02x}".format(ord(c)) for c in s)
if s is not None and len( s ) > 0 :
( frame, remainder ) = kiss.deKiss( s )
if debug :
print "Frame: " + ":".join("{:02x}".format(ord(c)) for c in frame)
print "Reaminder: " + ":".join("{:02x}".format(ord(c)) for c in remainder)
frame_str = AX25.deAX25( frame )
if len( frame_str ) > 0 :
print "Frame: ", frame_str
timeout = 0
else :
remainder = s