2025-09-12 18:44:34 +08:00
|
|
|
from openpyxl import load_workbook
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
def read_cell(sheet, row, col):
|
|
|
|
|
val = str(sheet.cell(row, col).value)
|
|
|
|
|
if val == "None":
|
|
|
|
|
val = ""
|
|
|
|
|
return val.strip()
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
def read_sheet(wb, topic, sht_name):
|
|
|
|
|
sheet = wb[sht_name]
|
|
|
|
|
|
|
|
|
|
text = ""
|
|
|
|
|
for i in range(1, sheet.max_row):
|
|
|
|
|
# print(str(sheet.cell(i, 1).value))
|
|
|
|
|
addr = read_cell(sheet, i, 8)
|
|
|
|
|
name = read_cell(sheet,i, 2)
|
|
|
|
|
datatype = read_cell(sheet,i, 4)
|
|
|
|
|
unit = read_cell(sheet, i, 5)
|
|
|
|
|
remark = read_cell(sheet, i, 6)
|
|
|
|
|
remark = name + remark
|
|
|
|
|
|
|
|
|
|
if (len(addr) == 6):
|
|
|
|
|
if (len(unit)>0):
|
|
|
|
|
remark += '(' + unit + ')'
|
|
|
|
|
if (len(text)>0):
|
|
|
|
|
text += ',\n'
|
|
|
|
|
text += '\t\t\t{"key": "%s", "datatype": "%s", "remark": "%s"}' % (addr, datatype, remark.replace("\n", ""))
|
|
|
|
|
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
if (len(text)>0):
|
|
|
|
|
text = "\n" + text + "\n\t\t"
|
|
|
|
|
text = '\t"%s":{\n\t\t"addr":[%s]\n\t}' % (topic, text)
|
|
|
|
|
return text
|
|
|
|
|
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
wb = load_workbook('EMU对外通信点表最终修改1版_v9.xlsx', data_only=True)
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
text = ""
|
|
|
|
|
text = read_sheet(wb, "EMS_YT", "EMS遥调")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "EMS_YX", "EMS遥信")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "PCU_YC", "PCU遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "PCU_YX", "PCU遥信")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "PCS_YC", "PCS遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "PCS_YX", "PCS遥信")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "BMS_YC", "BMS电池堆遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "BCU_YC", "BCU电池簇遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "BCU_YX", "BCU电池簇遥信")
|
|
|
|
|
# text += ',\n' + read_sheet(wb, "AirC_YC", "空调遥测")
|
|
|
|
|
# text += ',\n' + read_sheet(wb, "AirC_YX", "空调遥信")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "MEM_YC", "多功能电表遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "TH_YC", "温湿度状态遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "Fire40_YX", "消防4.0遥信")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "Cooling_YC", "冷机遥测")
|
|
|
|
|
text += ',\n' + read_sheet(wb, "Cooling_YX", "冷机遥信")
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
with open('registeraddr.json', 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write("{\n" + text + "\n}")
|
2025-09-05 19:44:26 +08:00
|
|
|
|
|
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
def read_sheet_alarm(wb, device_type, sht_name):
|
|
|
|
|
sheet = wb[sht_name]
|
|
|
|
|
text = ""
|
|
|
|
|
for i in range(1, sheet.max_row):
|
|
|
|
|
addr = read_cell(sheet, i, 8)
|
|
|
|
|
is_alarm = (read_cell(sheet, i, 7) == "告警")
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
if (len(addr) == 6 and is_alarm) :
|
|
|
|
|
name = read_cell(sheet,i, 2)
|
|
|
|
|
datatype = read_cell(sheet,i, 4)
|
|
|
|
|
unit = read_cell(sheet, i, 5)
|
|
|
|
|
remark = read_cell(sheet, i, 6)
|
|
|
|
|
remark = name + remark
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
if (len(unit)>0):
|
|
|
|
|
remark += '(' + unit + ')'
|
|
|
|
|
if (len(text)>0):
|
|
|
|
|
text += ',\n'
|
|
|
|
|
text += '\t\t\t{"key": "%s", "datatype": "%s", "remark": "%s"}' % (addr, datatype, remark.replace("\n", ""))
|
|
|
|
|
if (len(text)>0):
|
|
|
|
|
text = "\n" + text + "\n\t\t"
|
|
|
|
|
text = '\t"%s":{\n\t\t"addr":[%s]\n\t}' % (device_type, text)
|
|
|
|
|
return text;
|
2025-09-05 19:44:26 +08:00
|
|
|
|
2025-09-12 18:44:34 +08:00
|
|
|
text_err = ""
|
|
|
|
|
text_err = read_sheet_alarm(wb, 103, "PCU遥信")
|
|
|
|
|
text_err += ',\n' + read_sheet_alarm(wb, 104, "PCS遥信")
|
|
|
|
|
with open('registeraddrErr.json', 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write("{\n" + text_err + "\n}")
|