54 lines
1.3 KiB
Python
Executable File
54 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import database
|
|
import argparse
|
|
import sys
|
|
import ctypes
|
|
import json
|
|
|
|
ACCEL = ctypes.cdll.LoadLibrary('./libaccel.so')
|
|
ACCEL_NAME_BUF = ctypes.create_string_buffer(b'Z'*255, 255)
|
|
ACCEL_VALUE_BUF = ctypes.create_string_buffer(b'Z'*255, 255)
|
|
|
|
FUNCTION_MAP = {
|
|
b'a': database.feed_a,
|
|
b'cname': database.feed_cname,
|
|
}
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Parsing arguments
|
|
parser = argparse.ArgumentParser(
|
|
description="TODO")
|
|
parser.add_argument(
|
|
'-i', '--input', type=argparse.FileType('rb'), default=sys.stdin.buffer,
|
|
help="TODO")
|
|
args = parser.parse_args()
|
|
|
|
database.open_db()
|
|
|
|
line = b'(none)'
|
|
|
|
def err(name: bytes, value: bytes) -> None:
|
|
print(f"Error with line: {line!r}")
|
|
|
|
FUNCTIONS = [err, database.feed_cname, database.feed_a]
|
|
|
|
try:
|
|
database.time_step('iowait')
|
|
for line in args.input:
|
|
database.time_step('feed_json_parse')
|
|
dtype = ACCEL.feed_dns_parse_json(
|
|
ctypes.c_char_p(line),
|
|
ACCEL_NAME_BUF,
|
|
ACCEL_VALUE_BUF
|
|
)
|
|
database.time_step('feed_switch')
|
|
FUNCTIONS[dtype](ACCEL_NAME_BUF.value, ACCEL_VALUE_BUF.value)
|
|
database.time_step('iowait')
|
|
except KeyboardInterrupt:
|
|
print("Interupted.")
|
|
pass
|
|
|
|
database.close_db()
|