You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
#!/usr/bin/env python3 |
|
import os |
|
import crcmod |
|
from random import randint |
|
from time import sleep |
|
|
|
from config import * |
|
|
|
from update import parse_line, create_database, update_database, update_graphs, upload_graphs |
|
|
|
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE) |
|
|
|
def gen_line(): |
|
values = [] |
|
|
|
stored = {name : (minval, maxval) for name, minval, maxval in STORED_VALUES} |
|
for name in FORMAT: |
|
minval = 0 |
|
maxval = 1000 |
|
if name in stored.keys(): |
|
minval, maxval = stored[name] |
|
|
|
values += [str(randint(minval, maxval))] |
|
|
|
payload = ";".join(values) + ";" |
|
crc = calc_crc(payload.encode('ascii')) |
|
crc_str = chr((crc & 0xFF00) >> 8) + chr(crc & 0xFF) |
|
|
|
return payload + crc_str + "\r\n" |
|
|
|
|
|
|
|
def main(): |
|
if not os.path.exists(DATA_FILE) or not os.path.exists(ARCHIVE_DATA_FILE): |
|
create_database() |
|
sleep(60) |
|
|
|
while True: |
|
print("Adding Line...") |
|
line = gen_line() |
|
parsed = parse_line(line) |
|
update_database(parsed) |
|
update_graphs() |
|
upload_graphs() |
|
sleep(60) |
|
|
|
if __name__ == '__main__': |
|
main()
|
|
|