Browse Source

[megatec]add check qflag "l" & enable this flag

balbekova 2 năm trước cách đây
mục cha
commit
fe629e1e50
2 tập tin đã thay đổi với 65 bổ sung11 xóa
  1. 63 10
      modules/MegaTec/megatec.c
  2. 2 1
      modules/MegaTec/megatec.h

+ 63 - 10
modules/MegaTec/megatec.c

@@ -51,6 +51,8 @@ uint32_t Period_testing = 0;
 
 static bool sync_data = false;
 
+static bool QFLAG_L = false;
+
 enum {
     NORMAL = 0x00,
     VER_ERROR = 0x01,
@@ -95,6 +97,8 @@ const char *MegaTecCMD[] = {
     "QWS\r",
     "QBYV\r",
     "PHV264\r",//264
+    "QFLAG\r",
+    "PEL\r",
 };
 
 extern bool flUpdateLog;
@@ -874,7 +878,7 @@ void ups_warn_status_response(char *data)
                         + BIT_OFFSET(data[7], 4) + BIT_OFFSET(data[8], 5) + BIT_OFFSET(data[12], 6) + BIT_OFFSET(data[13], 7); 
 }
 
-void ups_bypass_hvolt_set(char *data)
+void ups_get_ack(char *data)
 {
     UPS.Present = UPS_CONNECTED;
     UPS.Flag_Present = true;
@@ -889,6 +893,24 @@ void ups_bypass_hvolt_set(char *data)
     DBG printf("UPS ups_buzzer_cntrl_parser_start: %s\r\n", data);    
 }
 
+void ups_qflag_status_get(char *data)
+{
+    char *ptr1, *ptr2;
+    UPS.Present = UPS_CONNECTED;
+    UPS.Flag_Present = true;
+    UPS.cnt_err_ups = 0;
+
+    if (strlen(data) != 0) {
+        ptr1 = strchr(data, 'l');
+        ptr2 = strchr(data, 'D');
+        if (ptr1 != NULL && ptr2 != NULL) {
+            if (ptr2 < ptr1) {
+                QFLAG_L = true;
+            }
+        }
+    }   
+}
+
 void ups_megatec_process_pdu(cmdMegaTecEnums_t command)
 {
     switch (command) {
@@ -935,7 +957,11 @@ void ups_megatec_process_pdu(cmdMegaTecEnums_t command)
             ups_warn_status_response(ups_pdu.data);
             break;
         case ups_bypass_hvolt_264_set:
-            ups_bypass_hvolt_set(ups_pdu.data);
+        case ups_cmd_enable_flag_l:
+            ups_get_ack(ups_pdu.data);
+            break;
+        case ups_qflag_status:
+            ups_qflag_status_get(ups_pdu.data);
             break;
         default:
             break;
@@ -1057,6 +1083,7 @@ void request_task(void *params)
     uint8_t voltronic_req[8] = {ups_status_req, ups_akb_info, ups_model_req, ups_mode_req, ups_version_req, ups_version2_req, ups_serial_req, ups_warning_status};//
     uint8_t num_req = 0;
     uint8_t *req;
+    bool flag_init_ups = false;
 
     ups_megatec_rx_pdu();
     for (;;) {
@@ -1082,6 +1109,7 @@ void request_task(void *params)
                     //memset(UPS.model, 0, 11);
                     memset(UPS.vertion, 0, sizeof(UPS.vertion));
                     init_ups_rbuf();
+                    flag_init_ups = false;
                 }
             }
         }
@@ -1120,15 +1148,40 @@ void request_task(void *params)
                     }
                 }
 #endif
-                if (megatec_send) {
-                    memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
-                    megatec_send = false;
-                    UPS.Flag_Present = false;
-                    send_MegaTec_cmd(ups_bypass_hvolt_264_set);
-                    if (ups_megatec_rx_pdu()) {
-                        ups_megatec_process_pdu(ups_bypass_hvolt_264_set);
+                if(!flag_init_ups) {
+                    flag_init_ups = true;
+                    if (megatec_send) {
+                        memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
+                        megatec_send = false;
+                        UPS.Flag_Present = false;
+                        send_MegaTec_cmd(ups_bypass_hvolt_264_set);
+                        if (ups_megatec_rx_pdu()) {
+                            ups_megatec_process_pdu(ups_bypass_hvolt_264_set);
+                        }
+                        megatec_send = true;
+                    }
+                    if (megatec_send) {
+                        memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
+                        megatec_send = false;
+                        UPS.Flag_Present = false;
+                        send_MegaTec_cmd(ups_qflag_status);
+                        if (ups_megatec_rx_pdu()) {
+                            ups_megatec_process_pdu(ups_qflag_status);
+                        }
+                        megatec_send = true;
+                    }
+                    if (QFLAG_L) {
+                        if (megatec_send) {
+                            memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
+                            megatec_send = false;
+                            UPS.Flag_Present = false;
+                            send_MegaTec_cmd(ups_cmd_enable_flag_l);
+                            if (ups_megatec_rx_pdu()) {
+                                ups_megatec_process_pdu(ups_cmd_enable_flag_l);
+                            }
+                            megatec_send = true;
+                        }
                     }
-                    megatec_send = true;
                 }
                 break;
             default:

+ 2 - 1
modules/MegaTec/megatec.h

@@ -51,7 +51,8 @@ typedef enum{
 	ups_warning_status,
 	ups_bypass_volt_range,
 	ups_bypass_hvolt_264_set,
-
+	ups_qflag_status,
+	ups_cmd_enable_flag_l,
 
 	MegaTec_cmd_max
 } cmdMegaTecEnums_t;