solarrd/mockup.py

32 lines
558 B
Python
Raw Normal View History

2018-03-11 21:30:10 +01:00
#!/usr/bin/env python3
import crcmod
from random import randint
from config import *
from update import parse_line
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
def gen_line():
values = [str(randint(0,1000)) for _ in range(0,len(FORMAT))]
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():
line = gen_line()
result = parse_line(line)
print(result)
if __name__ == '__main__':
main()