Initial commit
This commit is contained in:
commit
1c4e50d790
|
@ -0,0 +1,3 @@
|
||||||
|
*.pyc
|
||||||
|
__pycache__
|
||||||
|
virtenv
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import serial # for parity constants
|
||||||
|
|
||||||
|
SERIAL = '/dev/ttyUSB0'
|
||||||
|
BAUD_RATE = 4800
|
||||||
|
STOP_BITS = 1
|
||||||
|
PARITY = None
|
||||||
|
|
||||||
|
DATA_INTERVAL = 60
|
||||||
|
ARCHIVE_INTERVAL = 60 * 60 # 1h
|
||||||
|
KEEP_INTERVAL = 365 * 24 * 60 * 60 # 1 year
|
||||||
|
|
||||||
|
# Manual claims poly should be 0x8404, internet says xmodem
|
||||||
|
CRC_TYPE = 'xmodem'
|
||||||
|
|
||||||
|
STORED_VALUES = [
|
||||||
|
'U_bat',
|
||||||
|
'U_mod1',
|
||||||
|
'U_mod2',
|
||||||
|
'I_pv_in',
|
||||||
|
'I_load_total',
|
||||||
|
'load_switch',
|
||||||
|
'max_charge_bat_day',
|
||||||
|
'max_charge_load_day'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
FORMAT = ['Version',
|
||||||
|
'Date',
|
||||||
|
'Time',
|
||||||
|
'U_bat',
|
||||||
|
'U_mod1',
|
||||||
|
'U_mod2',
|
||||||
|
'SOC',
|
||||||
|
'SOH',
|
||||||
|
'I_bat_total',
|
||||||
|
'I_pv_max1',
|
||||||
|
'I_pv_max2',
|
||||||
|
'I_pv_in',
|
||||||
|
'I_charge_total',
|
||||||
|
'I_load_device',
|
||||||
|
'I_load_total',
|
||||||
|
'T_bat',
|
||||||
|
'error',
|
||||||
|
'charge_mode',
|
||||||
|
'load_switch',
|
||||||
|
'relais_aux1',
|
||||||
|
'relais_aux2',
|
||||||
|
'max_charge_bat_day',
|
||||||
|
'max_charge_bat_ever',
|
||||||
|
'max_charge_load_day',
|
||||||
|
'max_charge_load_ever',
|
||||||
|
'derating']
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/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()
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import serial
|
||||||
|
import crcmod
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
|
||||||
|
calc_crc = crcmod.predefined.mkCrcFun(CRC_TYPE)
|
||||||
|
|
||||||
|
def parse_line(line):
|
||||||
|
if line[-2:] != "\r\n":
|
||||||
|
return {key : None for key in FORMAT}
|
||||||
|
line = line[:-2]
|
||||||
|
|
||||||
|
crc_str = line[-2:]
|
||||||
|
payload = line[0:-2]
|
||||||
|
crc = (ord(crc_str[0]) << 8) | ord(crc_str[1])
|
||||||
|
if crc != calc_crc(payload.encode('ascii')):
|
||||||
|
return {key : None for key in FORMAT}
|
||||||
|
|
||||||
|
parts = payload.split(';')
|
||||||
|
parts = [p.strip() for p in parts]
|
||||||
|
parts = [x if x != '#' else None for x in parts]
|
||||||
|
data = zip(FORMAT, parts)
|
||||||
|
|
||||||
|
return dict(data)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue