Browse Source

[megatec] change process of restore load

balbekova 4 years ago
parent
commit
8710652eb9
2 changed files with 31 additions and 2 deletions
  1. 30 2
      modules/MegaTec/megatec.c
  2. 1 0
      modules/MegaTec/megatec.h

+ 30 - 2
modules/MegaTec/megatec.c

@@ -6,6 +6,7 @@
  */
  */
 #include "FreeRTOS.h"
 #include "FreeRTOS.h"
 #include "task.h"
 #include "task.h"
+#include "fr_timers.h"
 #include "usart.h"
 #include "usart.h"
 #include "megatec.h"
 #include "megatec.h"
 #include "ups_monitor.h"
 #include "ups_monitor.h"
@@ -24,6 +25,8 @@
 
 
 #define DBG if (0)
 #define DBG if (0)
 
 
+TimerHandle_t UPSRestoreTimer;
+
 /**
 /**
   * @brief  Общая структура настроек
   * @brief  Общая структура настроек
   */
   */
@@ -79,6 +82,7 @@ const char *MegaTecCMD[] = {
     "M\r",
     "M\r",
     "PDA\r",
     "PDA\r",
     "QMOD\r",
     "QMOD\r",
+    "SON\r",
 };
 };
 
 
 extern bool flUpdateLog;
 extern bool flUpdateLog;
@@ -159,7 +163,7 @@ bool ups_megatec_rx_pdu(void)
     ups_pdu.len = 0;
     ups_pdu.len = 0;
 
 
     while (c >= 0) {
     while (c >= 0) {
-        c = ups_getchar(200);//portMAX_DELAY200
+        c = ups_getchar(300);//portMAX_DELAY200
         if (c >= 0) {
         if (c >= 0) {
             ups_pdu.len = 0;
             ups_pdu.len = 0;
             memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
             memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
@@ -782,7 +786,7 @@ int ups_metac_service_pdu(cmdMegaTecEnums_t command)
         UPS_Status_prev = UPS.Status;
         UPS_Status_prev = UPS.Status;
         memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
         memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
         megatec_send = false;
         megatec_send = false;
-        if (sSettings.UPS_Setting.type_ups == ups_offline && command == ups_shutdown) {
+        if (command == ups_shutdown) {//sSettings.UPS_Setting.type_ups == ups_offline && 
             TimeParam2 = 1;
             TimeParam2 = 1;
             send_MegaTec_cmd(ups_shutdown_restore);
             send_MegaTec_cmd(ups_shutdown_restore);
         } else {
         } else {
@@ -792,6 +796,12 @@ int ups_metac_service_pdu(cmdMegaTecEnums_t command)
         if (ups_megatec_rx_pdu()) {
         if (ups_megatec_rx_pdu()) {
             megatec_send = true;
             megatec_send = true;
             if (strncmp(ups_pdu.data, "ACK", 3) == 0 || strncmp(ups_pdu.data, "(ACK", 4) == 0) {
             if (strncmp(ups_pdu.data, "ACK", 3) == 0 || strncmp(ups_pdu.data, "(ACK", 4) == 0) {
+                if (command == ups_shutdown) {
+                    xTimerChangePeriod(UPSRestoreTimer, (TimeParamFloat + 0.3)*60*configTICK_RATE_HZ, 0);
+                    xTimerStart(UPSRestoreTimer, 0);
+                } else if(command == ups_cancel_shut_down) {
+                    xTimerStop(UPSRestoreTimer, 0);
+                }
                 return 1;
                 return 1;
             } else if (strncmp(ups_pdu.data, "NAK", 3) == 0 || strncmp(ups_pdu.data, "(NAK", 4) == 0) {
             } else if (strncmp(ups_pdu.data, "NAK", 3) == 0 || strncmp(ups_pdu.data, "(NAK", 4) == 0) {
                 return 0;
                 return 0;
@@ -971,6 +981,23 @@ void akb_time_work_task(void *params)
     }
     }
 }
 }
 
 
+void UPSRestoreCallback(TimerHandle_t pxTimer)
+{
+    if (UPS.Present) {
+        while (!megatec_send) {
+            vTaskDelay(50);
+        }
+        memset(ups_pdu.data, 0, UPS_PDU_MAX_LEN);
+        megatec_send = false;
+        //UPS.Flag_Present = false;
+        send_MegaTec_cmd(ups_remote_turn_on);
+        if (ups_megatec_rx_pdu()) {
+            ups_megatec_process_pdu(ups_remote_turn_on);
+        }
+        megatec_send = true;
+    }
+}
+
 void ups_megatec_init(void)
 void ups_megatec_init(void)
 {
 {
     init_UPS_value();
     init_UPS_value();
@@ -978,4 +1005,5 @@ void ups_megatec_init(void)
     xTaskCreate(request_task, ( char * ) "request_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
     xTaskCreate(request_task, ( char * ) "request_task", configMINIMAL_STACK_SIZE * 2, NULL, tskIDLE_PRIORITY, NULL);
     xTaskCreate(akb_time_work_task, ( char * ) "akb_time_work_task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY,
     xTaskCreate(akb_time_work_task, ( char * ) "akb_time_work_task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY,
         NULL);
         NULL);
+    UPSRestoreTimer = xTimerCreate("UPSRestoreTmr", configTICK_RATE_HZ*30, pdFALSE, ( void * ) 0, UPSRestoreCallback);
 }
 }

+ 1 - 0
modules/MegaTec/megatec.h

@@ -49,6 +49,7 @@ typedef enum{
 	ups_passw_req,
 	ups_passw_req,
 	ups_buzzer_cntrl,
 	ups_buzzer_cntrl,
 	ups_mode_req,
 	ups_mode_req,
+	ups_remote_turn_on,
 
 
 	MegaTec_cmd_max
 	MegaTec_cmd_max
 } cmdMegaTecEnums_t;
 } cmdMegaTecEnums_t;