#!/usr/bin/env python def toint(s: str) -> int: return int.from_bytes(bytes.fromhex(s), byteorder='little') def readmodule(line: str): # -68 interface = toint(line[0:2]) vo1 = toint(line[2:6])/10 cu1 = toint(line[6:10])/10 acv1 = toint(line[10:14])/10 acfreq = toint(line[14:18])/100 acpow = toint(line[18:22])/10 ptoday = toint(line[22:26])/1000 ptotal = toint(line[26:32])/1000 temp1 = toint(line[34:36])/10 a02 = line[36:38] a03 = toint(line[36:38]) modulestatus = toint(line[38:40]) #??? 3=arbeitet, 2=arbeitet wenig (frühe Nacht), 5=???spätere Nacht, 0=aus/offline modulefails = toint(line[46:48]) connectionstatus = toint(line[50:52]) print("Panel:", interface) print("DC Volt: ", vo1, "V", "| DC Amp: ", cu1, "A", "| AC Volt: ", acv1, "| Temperatur: ", temp1 ," C", "| A02", a02, a03) print("AC Freq: ", acfreq, "Hz", "| AC Power: ", acpow, "W", "| P today: ", ptoday, "kWh", "| P total: ", ptotal, "MWh") print("Modulstatus: ", modulestatus, "| Anz. Modulfehler:", modulefails, "| Connectionstatus: ", connectionstatus) print("-") def main(): with open("raw.txt") as f: for line in f: line = line.strip() if line == "": continue print("-") print(line) dtuid = line[14:26] print("DTU id: ", dtuid) year = toint(line[36:38]) month = toint(line[38:40]) day = toint(line[40:42]) hour = toint(line[42:44]) minute = toint(line[44:46]) seconds = toint(line[46:48]) wrid = line[56:68] print("WR id: ", wrid) print("Datum: ",day,".",month,".",year," | Zeit: ",hour,":",minute,":",seconds) readmodule(line[68:120]) readmodule(line[144:196]) if __name__ == "__main__": main()