This repository was archived by the owner on Jan 4, 2024. It is now read-only.
forked from aanjhan/ubx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw-with-key-sync.py
More file actions
executable file
·71 lines (62 loc) · 2.8 KB
/
raw-with-key-sync.py
File metadata and controls
executable file
·71 lines (62 loc) · 2.8 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
#!/usr/bin/python
# Copyright (C) 2010 Timo Juhani Lindfors <timo.lindfors@iki.fi>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import ubx
import struct
import os
import gobject
import fcntl
import sys
input_event_struct = "@LLHHi"
input_event_size = struct.calcsize(input_event_struct)
ubxfile = open(sys.argv[1], "w")
keyfile = open(sys.argv[2], "w")
itow = False
week = False
def cbUbxPacket(ty, packet):
#print("cbUbxPacket %s %s" % (ty, repr(packet)))
if ty == "RXM-RAW":
global week
global itow
week = packet[0]["Week"]
itow = packet[0]["ITOW"]
def cbUbxRaw(payload):
#print("cbUbxRaw %s" % " ".join("%02x" % ord(x) for x in payload))
ubxfile.write(payload)
def cbButtonPress(source, condition):
print("cbButtonPress %s %s" % (source, condition))
data = os.read(source, 512)
events = [ data[i:i+input_event_size] for i in range(0, len(data), input_event_size) ]
for e in events:
timestamp, microseconds, typ, code, value = struct.unpack( input_event_struct, e )
# We need more then just second accuracy
timestamp = timestamp + microseconds/1000000.0
if typ != 0x00: # ignore EV_SYN (synchronization event)
print("event %s %s %s %s %s %s" % (week, itow, timestamp, typ, code, value))
keyfile.write("event %s %s %s %s %s %s\n" % (week, itow, timestamp, typ, code, value))
keyfile.flush()
if code == 169 and value == 1:
pass
if code == 116 and value == 1:
pass
return True
if __name__ == "__main__":
fd = os.open("/dev/input/event4", os.O_NONBLOCK | os.O_RDONLY)
fcntl.ioctl(fd, 0x40044590, 1) # EVIOCGRAB
gobject.io_add_watch(fd, gobject.IO_IN, cbButtonPress)
ubx.Parser(cbUbxPacket, rawCallback = cbUbxRaw)
gobject.MainLoop().run()