60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
import csv
|
|
|
|
print("Exporter")
|
|
|
|
file = open("../PM8000_Modbus_Map.csv", "r")
|
|
data = list(csv.reader(file, delimiter=","))
|
|
file.close()
|
|
|
|
header = """
|
|
#include <stdint.h>
|
|
struct RegisterMap
|
|
{
|
|
uint16_t regaddr;
|
|
uint8_t regtype;
|
|
};
|
|
|
|
const PROGMEM RegisterMap registers[] = {
|
|
[replace]
|
|
}
|
|
;
|
|
"""
|
|
|
|
|
|
|
|
lines = ""
|
|
for d in range(1, len(data)):
|
|
typeint = 0
|
|
if not data[d][1].isnumeric():
|
|
continue
|
|
# if data[d][9] == "NONE":
|
|
# continue
|
|
if data[d][4] == "seconds" or data[d][4] == "degrees":
|
|
continue
|
|
if data[d][3] == "DATETIME" or data[d][3] == "BITMAP" or data[d][3] == "N/A":
|
|
continue
|
|
if data[d][0].find("Magnitude") >= 0:
|
|
continue
|
|
|
|
if data[d][3] == "INT16U":
|
|
typeint = 1
|
|
elif data[d][3] == "FLOAT32":
|
|
typeint = 2
|
|
elif data[d][3] == "INT64":
|
|
typeint = 3
|
|
elif data[d][3] == "INT32U":
|
|
typeint = 4
|
|
elif data[d][3] == "UTF8":
|
|
typeint = 5
|
|
|
|
|
|
#print("{} @ {}:{} ({}) Tag: {}".format(data[d][0], data[d][1] ,data[d][2] ,data[d][3],data[d][7]))
|
|
lines += " { " + data[d][1] + ", " + str(typeint) + "} , // Name: " + data[d][0] + " (" + data[d][8] + ") - [" + data[d][1] + "," + data[d][2] + "]" + " as " + data[d][3] + "\n"
|
|
#
|
|
|
|
|
|
print(header.replace("[replace]", lines))
|
|
|
|
file = open("PM8000_Modbus_Map_ad.h", "w")
|
|
file.write(header.replace("[replace]", lines))
|
|
file.close() |