mirror of
https://codeberg.org/ET-Kiel/tk102gpx.git
synced 2026-06-28 07:29:51 +02:00
Compare commits
5 commits
02e96d82a1
...
fa469cda30
| Author | SHA1 | Date | |
|---|---|---|---|
| fa469cda30 | |||
| 20453c8570 | |||
| 434cec1aa7 | |||
|
|
ada56a8ad5 | ||
|
|
be10b8b551 |
3 changed files with 49 additions and 33 deletions
2
crontab
2
crontab
|
|
@ -1,2 +1,2 @@
|
|||
# m h dom mon dow command
|
||||
*/5 * * * * make -C /home/ncrs1/stephan/tk102gpx > /home/ncrs1/stephan/tk102gpx/cron.log 2>&1
|
||||
* * * * * /home/ncrs1/stephan/tk102gpx/cron.sh > /home/ncrs1/stephan/tk102gpx/cron.log 2>&1
|
||||
|
|
|
|||
52
tk102cat.py
52
tk102cat.py
|
|
@ -8,7 +8,7 @@ files = []
|
|||
timeout = None
|
||||
|
||||
def logger(s):
|
||||
print(s, file=sys.stderr)
|
||||
print("\n"+s, file=sys.stderr)
|
||||
|
||||
oo,files = getopt.getopt(sys.argv[1:], "p:", ("port=",))
|
||||
|
||||
|
|
@ -18,37 +18,53 @@ for o,v in oo:
|
|||
|
||||
poll = select.poll()
|
||||
|
||||
sockets = {}
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(("", port))
|
||||
sock.listen(2)
|
||||
poll.register(sock, select.POLLIN)
|
||||
logger("listening on port %d, socket fd %d" % (port,sock.fileno()))
|
||||
logger(f"listening on port {port}, socket fd {sock.fileno()}")
|
||||
|
||||
class tksocks:
|
||||
def __init__(self):
|
||||
self.sockets = {}
|
||||
self.fdescs = []
|
||||
def add(self, s):
|
||||
if len(self.fdescs) > 9:
|
||||
self.close(self.fdescs[0])
|
||||
fd = s[0].fileno()
|
||||
self.sockets[fd] = s
|
||||
self.fdescs.append(fd)
|
||||
poll.register(fd, select.POLLIN | select.POLLHUP | select.POLLRDHUP)
|
||||
def get(self, fd):
|
||||
return self.sockets[fd]
|
||||
def close(self, fd):
|
||||
s = self.get(fd)
|
||||
logger(f"closing connection from {repr(s[1])}")
|
||||
del self.sockets[fd]
|
||||
self.fdescs.remove(fd)
|
||||
poll.unregister(fd)
|
||||
s[0].close()
|
||||
|
||||
sockets = tksocks()
|
||||
|
||||
while True:
|
||||
try:
|
||||
c = poll.poll(timeout)
|
||||
for fd, ev in c:
|
||||
if fd==sock.fileno():
|
||||
s = sock.accept()
|
||||
logger("connection from %s" % repr(s[1]))
|
||||
if len(sockets) > 99:
|
||||
logger("too many connections %s" % repr(sockets))
|
||||
s[0].send("too many connections, good bye")
|
||||
s[0].close()
|
||||
logger(f"connection from {repr(s[1])}")
|
||||
sockets.add(s)
|
||||
else:
|
||||
sockets[s[0].fileno()] = s
|
||||
poll.register(s[0], select.POLLIN | select.POLLHUP | select.POLLRDHUP)
|
||||
elif fd in sockets:
|
||||
so = sockets[fd][0]
|
||||
if ev & select.POLLIN:
|
||||
d = so.recv(4096, socket.MSG_DONTWAIT)
|
||||
d = sockets.get(fd)[0].recv(4096, socket.MSG_DONTWAIT)
|
||||
if d:
|
||||
out.write(d)
|
||||
out.flush()
|
||||
if ev & (select.POLLHUP | select.POLLRDHUP):
|
||||
logger("closing connection from %s" % repr(sockets[fd][1]))
|
||||
del sockets[fd]
|
||||
poll.unregister(fd)
|
||||
so.close()
|
||||
sockets.close(fd)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception as e:
|
||||
logger(f"Error: {repr(e)}")
|
||||
|
|
|
|||
10
tk102gpx.py
10
tk102gpx.py
|
|
@ -72,7 +72,7 @@ tk_re = re.compile(b"".join((
|
|||
b"(?P<VAR>[^,]+)?,",
|
||||
b"(?P<WHAT>[^,]*,)?",
|
||||
b"A\*(?P<GPCKS>[0-9A-F][0-9A-F]),",
|
||||
b"(?P<BAT>[FL])?,",
|
||||
b"(?P<SIGNAL>[FL])?,",
|
||||
b"imei:(?P<IMEI>[0-9]+),",
|
||||
b"(?P<LEN>[0-9]{3})",
|
||||
b"(?P<BCKS>..)"
|
||||
|
|
@ -130,7 +130,7 @@ class TKGPX(gpxpy.gpx.GPX):
|
|||
slept = True
|
||||
sys.stderr.write(".")
|
||||
sys.stderr.flush()
|
||||
time.sleep(60)
|
||||
time.sleep(10)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
continue
|
||||
|
|
@ -151,8 +151,8 @@ class TKGPX(gpxpy.gpx.GPX):
|
|||
if verbose >= 3:
|
||||
print(repr(rd), file=sys.stderr)
|
||||
|
||||
if verbose>0 and rd["BAT"] != b"F":
|
||||
print(f"Battery is {repr(rd['BAT'])} at {rd['SERIAL']}", file=sys.stderr)
|
||||
if verbose>0 and rd["SIGNAL"] != b"F":
|
||||
print(f"Signal is {repr(rd['SIGNAL'])} at {rd['SERIAL']}", file=sys.stderr)
|
||||
|
||||
pd = {
|
||||
"latitude": gprmc2deg(rd["LAT"], rd["NS"]),
|
||||
|
|
@ -183,7 +183,7 @@ class TKGPX(gpxpy.gpx.GPX):
|
|||
|
||||
if raw==2:
|
||||
cd = {}
|
||||
cd.update(strorbytes(rd, 'BAT'))
|
||||
cd.update(strorbytes(rd, 'SIGNAL'))
|
||||
cd.update(strorbytes(rd, 'SERIAL'))
|
||||
cd.update(strorbytes(rd, 'PHONE'))
|
||||
cd['time'] = pd['time'].isoformat()[:19]+'Z'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue