From 3df29476aad72ac1d8a0e721ec3f4e5ab76e0dfe Mon Sep 17 00:00:00 2001 From: kyz Date: Wed, 29 Oct 2025 11:44:37 +0800 Subject: [PATCH] modify pcs parameter set --- src/user_pcs.h | 30 ++++++- src/user_web_data.c | 193 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 1 deletion(-) diff --git a/src/user_pcs.h b/src/user_pcs.h index 5cd87b0..5d062c0 100644 --- a/src/user_pcs.h +++ b/src/user_pcs.h @@ -34,7 +34,35 @@ typedef enum { USER_PCS_PARAM_DC_UNDERVOLTAGE_THRESHOLD, // 直流欠压保护值 USER_PCS_PARAM_DC_UNDERVOLTAGE_RECOVER, // 直流欠压恢复值 USER_PCS_PARAM_HEARTBEAT_EN, // 心跳检测及使能 - USER_PCS_PARAM_CLEAR_FAULT // 清除故障 + USER_PCS_PARAM_CLEAR_FAULT, // 清除故障 + // 新增寄存器100-136相关参数类型 + USER_PCS_PARAM_PROTECTION_ENABLE, // 保护使能位设置 (地址100) + USER_PCS_PARAM_GRID_OVERVOLTAGE1_PROT_TIME, // 电网过压1保护时间 (地址101) + USER_PCS_PARAM_GRID_OVERVOLTAGE2_VALUE, // 电网过压2保护值 (地址102) + USER_PCS_PARAM_GRID_OVERVOLTAGE2_PROT_TIME, // 电网过压2保护时间 (地址103) + USER_PCS_PARAM_GRID_OVERVOLTAGE3_VALUE, // 电网过压3保护值 (地址104) + USER_PCS_PARAM_GRID_OVERVOLTAGE3_PROT_TIME, // 电网过压3保护时间 (地址105) + USER_PCS_PARAM_GRID_UNDERVOLTAGE1_PROT_TIME, // 电网欠压1保护时间 (地址108) + USER_PCS_PARAM_GRID_UNDERVOLTAGE2_VALUE, // 电网欠压2保护值 (地址109) + USER_PCS_PARAM_GRID_UNDERVOLTAGE2_PROT_TIME, // 电网欠压2保护时间 (地址110) + USER_PCS_PARAM_GRID_UNDERVOLTAGE3_VALUE, // 电网欠压3保护值 (地址111) + USER_PCS_PARAM_GRID_UNDERVOLTAGE3_PROT_TIME, // 电网欠压3保护时间 (地址112) + USER_PCS_PARAM_GRID_OVERFREQUENCY1_PROT_TIME, // 电网过频1保护时间 (地址115) + USER_PCS_PARAM_GRID_OVERFREQUENCY2_VALUE, // 电网过频2保护值 (地址116) + USER_PCS_PARAM_GRID_OVERFREQUENCY2_PROT_TIME, // 电网过频2保护时间 (地址117) + USER_PCS_PARAM_GRID_OVERFREQUENCY3_VALUE, // 电网过频3保护值 (地址118) + USER_PCS_PARAM_GRID_OVERFREQUENCY3_PROT_TIME, // 电网过频3保护时间 (地址119) + USER_PCS_PARAM_GRID_UNDERFREQUENCY1_PROT_TIME, // 电网欠频1保护时间 (地址122) + USER_PCS_PARAM_GRID_UNDERFREQUENCY2_VALUE, // 电网欠频2保护值 (地址123) + USER_PCS_PARAM_GRID_UNDERFREQUENCY2_PROT_TIME, // 电网欠频2保护时间 (地址124) + USER_PCS_PARAM_GRID_UNDERFREQUENCY3_VALUE, // 电网欠频3保护值 (地址125) + USER_PCS_PARAM_GRID_UNDERFREQUENCY3_PROT_TIME, // 电网欠频3保护时间 (地址126) + USER_PCS_PARAM_UNDERVOLTAGE_REACTIVE_SLOPE, // 欠电压无功曲线斜率 (地址129) + USER_PCS_PARAM_REACTIVE_UNDERVOLTAGE_ENTRY, // 无功欠电压进入点 (地址130) + USER_PCS_PARAM_REACTIVE_UNDERVOLTAGE_EXIT, // 无功欠电压退出点 (地址131) + USER_PCS_PARAM_OVERVOLTAGE_REACTIVE_SLOPE, // 过电压无功曲线斜率 (地址134) + USER_PCS_PARAM_REACTIVE_OVERVOLTAGE_ENTRY, // 无功过电压进入点 (地址135) + USER_PCS_PARAM_REACTIVE_OVERVOLTAGE_EXIT // 无功过电压退出点 (地址136) } user_pcs_param_type_t; /* PCS设备信息结构体 - 根据pcs-modbus.txt协议更新 */ diff --git a/src/user_web_data.c b/src/user_web_data.c index 3b11a27..8d55e8a 100644 --- a/src/user_web_data.c +++ b/src/user_web_data.c @@ -175,6 +175,35 @@ int process_http_post_message( char * url, char *message, size_t len, char **p_r cJSON_AddNumberToObject(data_json, "heartbeat_enable", pcs_data.heartbeat_enable); cJSON_AddNumberToObject(data_json, "clear_fault", pcs_data.clear_fault); + // 添加新增寄存器100-136相关字段 + cJSON_AddNumberToObject(data_json, "protection_enable", pcs_data.protection_enable); + cJSON_AddNumberToObject(data_json, "grid_overvoltage1_prot_time", pcs_data.grid_overvoltage1_prot_time); + cJSON_AddNumberToObject(data_json, "grid_overvoltage2_value_p1v", pcs_data.grid_overvoltage2_value_p1v); + cJSON_AddNumberToObject(data_json, "grid_overvoltage2_prot_time", pcs_data.grid_overvoltage2_prot_time); + cJSON_AddNumberToObject(data_json, "grid_overvoltage3_value_p1v", pcs_data.grid_overvoltage3_value_p1v); + cJSON_AddNumberToObject(data_json, "grid_overvoltage3_prot_time", pcs_data.grid_overvoltage3_prot_time); + cJSON_AddNumberToObject(data_json, "grid_undervoltage1_prot_time", pcs_data.grid_undervoltage1_prot_time); + cJSON_AddNumberToObject(data_json, "grid_undervoltage2_value_p1v", pcs_data.grid_undervoltage2_value_p1v); + cJSON_AddNumberToObject(data_json, "grid_undervoltage2_prot_time", pcs_data.grid_undervoltage2_prot_time); + cJSON_AddNumberToObject(data_json, "grid_undervoltage3_value_p1v", pcs_data.grid_undervoltage3_value_p1v); + cJSON_AddNumberToObject(data_json, "grid_undervoltage3_prot_time", pcs_data.grid_undervoltage3_prot_time); + cJSON_AddNumberToObject(data_json, "grid_overfrequency1_prot_time", pcs_data.grid_overfrequency1_prot_time); + cJSON_AddNumberToObject(data_json, "grid_overfrequency2_value_p2hz", pcs_data.grid_overfrequency2_value_p2hz); + cJSON_AddNumberToObject(data_json, "grid_overfrequency2_prot_time", pcs_data.grid_overfrequency2_prot_time); + cJSON_AddNumberToObject(data_json, "grid_overfrequency3_value_p2hz", pcs_data.grid_overfrequency3_value_p2hz); + cJSON_AddNumberToObject(data_json, "grid_overfrequency3_prot_time", pcs_data.grid_overfrequency3_prot_time); + cJSON_AddNumberToObject(data_json, "grid_underfrequency1_prot_time", pcs_data.grid_underfrequency1_prot_time); + cJSON_AddNumberToObject(data_json, "grid_underfrequency2_value_p2hz", pcs_data.grid_underfrequency2_value_p2hz); + cJSON_AddNumberToObject(data_json, "grid_underfrequency2_prot_time", pcs_data.grid_underfrequency2_prot_time); + cJSON_AddNumberToObject(data_json, "grid_underfrequency3_value_p2hz", pcs_data.grid_underfrequency3_value_p2hz); + cJSON_AddNumberToObject(data_json, "grid_underfrequency3_prot_time", pcs_data.grid_underfrequency3_prot_time); + cJSON_AddNumberToObject(data_json, "undervoltage_reactive_slope_p1", pcs_data.undervoltage_reactive_slope_p1); + cJSON_AddNumberToObject(data_json, "reactive_undervoltage_entry_p1v", pcs_data.reactive_undervoltage_entry_p1v); + cJSON_AddNumberToObject(data_json, "reactive_undervoltage_exit_p1v", pcs_data.reactive_undervoltage_exit_p1v); + cJSON_AddNumberToObject(data_json, "overvoltage_reactive_slope_p1", pcs_data.overvoltage_reactive_slope_p1); + cJSON_AddNumberToObject(data_json, "reactive_overvoltage_entry_p1v", pcs_data.reactive_overvoltage_entry_p1v); + cJSON_AddNumberToObject(data_json, "reactive_overvoltage_exit_p1v", pcs_data.reactive_overvoltage_exit_p1v); + // 处理获取BMS信息的请求 } else if (strcmp(msg, "get_bms_info") == 0) { cJSON_AddNumberToObject(response_json, "code", 0); @@ -276,6 +305,169 @@ int process_http_post_message( char * url, char *message, size_t len, char **p_r parameter_set = true; } + // 处理新增寄存器100-136相关参数 + if (cJSON_HasObjectItem(data_item, "protection_enable")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "protection_enable")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_PROTECTION_ENABLE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overvoltage1_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overvoltage1_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERVOLTAGE1_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overvoltage2_value_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overvoltage2_value_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERVOLTAGE2_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overvoltage2_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overvoltage2_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERVOLTAGE2_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overvoltage3_value_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overvoltage3_value_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERVOLTAGE3_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overvoltage3_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overvoltage3_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERVOLTAGE3_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_undervoltage1_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_undervoltage1_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERVOLTAGE1_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_undervoltage2_value_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_undervoltage2_value_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERVOLTAGE2_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_undervoltage2_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_undervoltage2_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERVOLTAGE2_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_undervoltage3_value_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_undervoltage3_value_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERVOLTAGE3_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_undervoltage3_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_undervoltage3_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERVOLTAGE3_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overfrequency1_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overfrequency1_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERFREQUENCY1_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overfrequency2_value_p2hz")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overfrequency2_value_p2hz")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERFREQUENCY2_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overfrequency2_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overfrequency2_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERFREQUENCY2_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overfrequency3_value_p2hz")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overfrequency3_value_p2hz")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERFREQUENCY3_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_overfrequency3_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_overfrequency3_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_OVERFREQUENCY3_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_underfrequency1_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_underfrequency1_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERFREQUENCY1_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_underfrequency2_value_p2hz")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_underfrequency2_value_p2hz")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERFREQUENCY2_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_underfrequency2_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_underfrequency2_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERFREQUENCY2_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_underfrequency3_value_p2hz")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_underfrequency3_value_p2hz")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERFREQUENCY3_VALUE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "grid_underfrequency3_prot_time")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "grid_underfrequency3_prot_time")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_GRID_UNDERFREQUENCY3_PROT_TIME, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "undervoltage_reactive_slope_p1")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "undervoltage_reactive_slope_p1")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_UNDERVOLTAGE_REACTIVE_SLOPE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "reactive_undervoltage_entry_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "reactive_undervoltage_entry_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_REACTIVE_UNDERVOLTAGE_ENTRY, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "reactive_undervoltage_exit_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "reactive_undervoltage_exit_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_REACTIVE_UNDERVOLTAGE_EXIT, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "overvoltage_reactive_slope_p1")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "overvoltage_reactive_slope_p1")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_OVERVOLTAGE_REACTIVE_SLOPE, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "reactive_overvoltage_entry_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "reactive_overvoltage_entry_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_REACTIVE_OVERVOLTAGE_ENTRY, &value); + parameter_set = true; + } + + if (cJSON_HasObjectItem(data_item, "reactive_overvoltage_exit_p1v")) { + uint16_t value = (uint16_t)cJSON_GetObjectItem(data_item, "reactive_overvoltage_exit_p1v")->valueint; + user_pcs_write_single_param(g_pcs.handler, USER_PCS_PARAM_REACTIVE_OVERVOLTAGE_EXIT, &value); + parameter_set = true; + } + // 设置响应 cJSON_AddNumberToObject(response_json, "code", 0); cJSON_AddStringToObject(response_json, "msg", "set_pcs_parameter"); @@ -306,3 +498,4 @@ int process_http_post_message( char * url, char *message, size_t len, char **p_r return 0; } + -- 2.34.1