mirror of
https://github.com/commaai/agnos-builder.git
synced 2026-07-09 00:32:04 +08:00
anomalous touch logger (#147)
* anomalous touch logger * service * add evdev * rename * Update userspace/files/phantom_touch_logger.service
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
User=comma
|
||||
Restart=no
|
||||
ExecStart=/usr/local/pyenv/shims/python -u /usr/comma/phantom_touch_logger.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -25,6 +25,7 @@ systemctl enable ssh-param-watcher.service
|
||||
systemctl enable home.mount
|
||||
systemctl enable logrotate-hourly.timer
|
||||
systemctl enable set_time.service
|
||||
systemctl enable phantom_touch_logger.service
|
||||
|
||||
# Disable some of our services
|
||||
systemctl disable serial-hostname.service
|
||||
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
from collections import deque
|
||||
from evdev import InputDevice, ecodes
|
||||
|
||||
def log(msg):
|
||||
# TODO: keep buffer of touch events + coords and dump after log
|
||||
print(msg, file=sys.stderr)
|
||||
|
||||
if __name__ == "__main__":
|
||||
touch_starts = deque([0.]*20, maxlen=20)
|
||||
|
||||
dev = InputDevice('/dev/input/by-path/platform-894000.i2c-event')
|
||||
for event in dev.read_loop():
|
||||
#print(event.type, event.code, event.value)
|
||||
|
||||
# TODO: consider multitouch events
|
||||
if event.type == ecodes.EV_KEY and event.code == ecodes.BTN_TOUCH:
|
||||
if event.value == 1:
|
||||
touch_starts.append(event.timestamp())
|
||||
|
||||
avg_touch_dt = (max(touch_starts) - min(touch_starts)) / len(touch_starts)
|
||||
avg_touch_freq = 1 / (avg_touch_dt + 0.0001)
|
||||
if avg_touch_freq > 15:
|
||||
log(f"Quick touch frequency {avg_touch_freq:.2f}s / {event}")
|
||||
|
||||
if len(touch_starts) > 2:
|
||||
dt = (touch_starts[-1] - touch_starts[-2])
|
||||
if dt < 0.02:
|
||||
log(f"Quick consecutive touches {dt:.2f}s / {event}")
|
||||
elif event.value == 0:
|
||||
if len(touch_starts):
|
||||
dt = event.timestamp() - touch_starts[-1]
|
||||
if dt > 10.:
|
||||
log(f"Touch point persisted for {dt:.2f}s / {event}")
|
||||
Reference in New Issue
Block a user