diff --git a/app/lib/a_process/pd_csg.c b/app/lib/a_process/pd_csg.c index e2e95d5..c18b2ad 100755 --- a/app/lib/a_process/pd_csg.c +++ b/app/lib/a_process/pd_csg.c @@ -1001,13 +1001,9 @@ int32_t _csg_config_set_recv(char *pkt) pd_config.config.trend_up_period = config->trend_up_period; pd_config.config.heartbeat_period = config->heartbeat_period; pd_config.config.ch_en_mask = config->ch_en_mask; - if (config->sync_mode == 0) + if(config->sync_mode < 4) { - BITMAP_RESET(pd_config.config.pt_B_sync_mode, PD_BIT_PT); - } - else - { - BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_PT); + pd_config.config.pt_B_sync_mode = config.sync_mode; } pd_config.config.pt_internal_period = 1000000000UL / config->pt_internal_period; vtysh_config_save(); @@ -1023,7 +1019,6 @@ int32_t _csg_config_set_recv(char *pkt) /* 查询用户参数查询报文处理. */ int32_t _csg_config_get_recv(char *pkt) { - printf("%s\n", __FUNCTION__); csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; csg_global_config_t *config = (csg_global_config_t *)(pkt + sizeof(csg_pkt_head_t)); config->sample_frequency = pd_config.config.sample_frequency; @@ -1033,14 +1028,7 @@ int32_t _csg_config_get_recv(char *pkt) config->trend_up_period = pd_config.config.trend_up_period; config->heartbeat_period = pd_config.config.heartbeat_period; config->ch_en_mask = pd_config.config.ch_en_mask; - if (IS_BITMAP_SET(pd_config.config.pt_B_sync_mode, PD_BIT_PT)) - { - config->sync_mode = 1; - } - else - { - config->sync_mode = 0; - } + config->sync_mode = pd_config.config.pt_B_sync_mode; config->pt_internal_period = 1000000000UL / pd_config.config.pt_internal_period; _csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(csg_global_config_t)); @@ -1543,7 +1531,7 @@ void *_csg_heartbeat_handle(void *arg) } /* 发送心跳包. */ - if (abs(now - t_heartbeat) / pd_config.config.heartbeat_period >= 1/*pd_config.config.heartbeat_period*/) + if (abs(now - t_heartbeat) > pd_config.config.heartbeat_period) { _csg_heartbeat_send(); t_heartbeat = now; diff --git a/device-tool/pages/global_params.py b/device-tool/pages/global_params.py index 32a789c..6603f00 100755 --- a/device-tool/pages/global_params.py +++ b/device-tool/pages/global_params.py @@ -9,6 +9,16 @@ from config import Cmd class GlobalParamsPage(BasePage): def __init__(self, parent, tcp_client): + # 先定义同步模式映射关系 + self.sync_mode_mapping = { + "PT外同步,B码外同步": 0, + "PT内同步,B码外同步": 1, + "PT外同步,B码内同步": 2, + "PT内同步,B码内同步": 3 + } + self.reverse_sync_mode_mapping = {v: k for k, v in self.sync_mode_mapping.items()} + + # 然后调用父类的__init__ super().__init__(parent, tcp_client, "全局参数") # 配置样式 @@ -61,7 +71,8 @@ class GlobalParamsPage(BasePage): {"label": "心跳包周期", "attr": "heartbeat_period", "type": "spin", "args": (1, 3600), "unit": "s", "readonly": False}, {"label": "通道使能掩码", "attr": "ch_en_mask", "type": "hex_entry", "unit": "", "readonly": False}, - {"label": "同步模式", "attr": "sync_mode", "type": "combo", "options": ["外同步", "内同步"], + {"label": "同步模式", "attr": "sync_mode", "type": "combo", + "options": list(self.sync_mode_mapping.keys()), # 使用映射的键作为选项 "readonly": False}, {"label": "内同步频率", "attr": "pt_internal_period", "type": "spin", "args": (40, 300), "unit": "", "readonly": False}, @@ -101,13 +112,9 @@ class GlobalParamsPage(BasePage): entry.configure(state='readonly', style='Readonly.TEntry') elif field["type"] == "combo": - var = tk.StringVar() # 改为StringVar来存储显示文本 - # 存储映射关系 - self.sync_mode_mapping = {"外同步": 0, "内同步": 1} - self.reverse_sync_mode_mapping = {0: "外同步", 1: "内同步"} - + var = tk.StringVar() # 使用StringVar存储显示文本 combobox = ttk.Combobox(parent, textvariable=var, - values=list(self.sync_mode_mapping.keys()), state="readonly", width=10) + values=field["options"], state="readonly", width=15) # 增加宽度以适应更长的文本 combobox.grid(row=i, column=1, sticky='w', padx=2, pady=2) else: # entry @@ -192,11 +199,12 @@ class GlobalParamsPage(BasePage): self.ch_en_mask_var.set(f"0x{config.ch_en_mask:02X}") # 同步模式:将数字值转换为对应的文本显示 - sync_mode_text = self.reverse_sync_mode_mapping.get(config.sync_mode, "外同步") + sync_mode_text = self.reverse_sync_mode_mapping.get(config.sync_mode, "PT外同步,B码外同步") self.sync_mode_var.set(sync_mode_text) self.pt_internal_period_var.set(config.pt_internal_period) + print(f"同步模式设置: {config.sync_mode} -> {sync_mode_text}") print("全局参数读取成功") except Exception as e: