36 lines
820 B
Python
36 lines
820 B
Python
import csv
|
|
|
|
print("Exporter")
|
|
|
|
file = open("PM8000_Modbus_Map.csv", "r")
|
|
data = list(csv.reader(file, delimiter=","))
|
|
file.close()
|
|
|
|
header = """
|
|
typedef struct
|
|
{
|
|
uint16_t address;
|
|
uint16_t size;
|
|
char* type[];
|
|
char* name[];
|
|
|
|
} pm8000_reg_map_t;
|
|
|
|
pm8000_reg_map_t pm8000_reg_map[] = {
|
|
[replace]
|
|
};
|
|
"""
|
|
|
|
lines = ""
|
|
for d in range(1, len(data)):
|
|
if not data[d][1].isnumeric():
|
|
continue
|
|
#print("{} @ {}:{} ({}) Tag: {}".format(data[d][0], data[d][1] ,data[d][2] ,data[d][3],data[d][7]))
|
|
lines += " { " + data[d][1] + ", " + data[d][2] + ", \"" + data[d][3] + "\", \"" + data[d][0].encode('ascii',"ignore").decode('ascii') + "\" },\n"
|
|
#
|
|
|
|
print(header.replace("[replace]", lines))
|
|
|
|
file = open("PM8000_Modbus_Map.h", "w")
|
|
file.write(header.replace("[replace]", lines))
|
|
file.close() |