Просмотр исходного кода

1、添加看门狗
2、解决阈值导入bug

guohui 1 год назад
Родитель
Сommit
b12b2e7f92
3 измененных файлов с 95 добавлено и 13 удалено
  1. 6 0
      pro/config/cfg.h
  2. 8 13
      pro/src/paras.c
  3. 81 0
      pro/src/sys.c

+ 6 - 0
pro/config/cfg.h

@@ -26,6 +26,8 @@
 //#define PRJ_TEST_AC_I3_O1
 
 
+//#define USE_WDOG
+
 #define USE_MAIL
 #define MAIL_SEND_BUILTIN
 
@@ -168,6 +170,10 @@
     #define CHANNEL_DELAY                       8
 
     #define PROD_POWER_TYPE                     5
+
+    #define CONFIG_XPORT
+    #define LOG_SEND_MAIL
+
 #elif defined PRJ_TEST_AC_I1_O1
     #define LANGUAGE                            0           //chinese
     #define SMPLE_TIME                          30          //ms

+ 8 - 13
pro/src/paras.c

@@ -2218,21 +2218,16 @@ static int proc_sensor(char *path, int op, GlobalSensorManger *sensor)
 
 static int get_power(int ch_id, GlobalPowerManger *power)
 {
-    GlobalPowerManger *tmp=NULL;
     GlobalDeviceManager *dm=get_dm();
+    GlobalPowerManger *tmp=&dm->_globalPowerManger;
 
-    if(list_empty(&dm->_globalPowerManger.list)) {
-        return -1;
-    }
-
-    list_for_each_entry(tmp, &dm->_globalPowerManger.list, list) {
-        if(!tmp) {
-            return -1;
-        }
+    while(tmp) {
         if(tmp->product_ch_id==ch_id) {
             if(power) *power = *tmp;
             return 0;
         }
+        if(!tmp->list.next) break;
+        tmp = (GlobalPowerManger*)((uint32_t)tmp->list.next - offsetof(typeof(*tmp),list));
     }
     return -1;
 }
@@ -2378,11 +2373,11 @@ static int proc_power(char *path, int op, GlobalPowerManger *power)
                     }
                     else {
                         GlobalPowerManger pwr;
-                        r = get_power(tmp->product_ch_id, &pwr); if(r) break;
-
-                        //r = dev_update_power_manage_genera_info(dm->db, 0, i, tmp);  if(r) break;
-                        r = dev_update_power_manage_over_info(dm->db, 0, i, tmp);    if(r) break;
+                        
+                        r = dev_update_power_manage_genera_info(dm->db, 0, tmp->product_ch_id, tmp);  if(r) break;
+                        r = dev_update_power_manage_over_info(dm->db, 0, tmp->product_ch_id, tmp);    if(r) break;
 
+                        r = get_power(tmp->product_ch_id, &pwr); if(r) break;
                         tmp->_PowerInfo = pwr._PowerInfo;
                         r = g_switch_set_all_single_threshold(&dm->_globalRelaySampManger,
                                                     tmp->product_ch_type, tmp->product_saddr,

+ 81 - 0
pro/src/sys.c

@@ -1255,12 +1255,93 @@ static void send_check(void)
         }
     }
 }
+
+
+//https://blog.csdn.net/weixin_47604497/article/details/136913868
+#include <linux/watchdog.h>
+static int wdog_fd=-1;
+static int wdog_init(void)
+{
+    int r=0;
+
+#ifdef USE_WDOG
+    char *path="/dev/watchdog";
+    struct watchdog_info info;
+    int option = WDIOS_DISABLECARD;
+
+    if(wdog_fd<0) {
+        wdog_fd = open(path, O_RDWR);   //O_WRONLY
+        if(wdog_fd<0) {
+            printf("___ %s open failed\n", path);
+            return -1;
+        }
+    }
+
+#if 0
+    r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
+
+    r = ioctl(wdog_fd, WDIOC_GETSUPPORT, &info);
+    if(r<0) {
+        printf("___ %s getsupport failed\n", path);
+        return -1;
+    }
+    printf("___ watchdog options: 0x%x\n", info.options&WDIOC_SETTIMEOUT);
+
+    r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &timeout);
+
+    option = WDIOS_ENABLECARD;
+    r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
+#endif
+
+#endif
+
+    return r;
+}
+static int wdog_enable(int en)
+{
+    int r=0;
+
+#ifdef USE_WDOG
+    int option = en?WDIOS_ENABLECARD:WDIOS_DISABLECARD;
+    r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
+#endif
+    return r;
+}
+static int wdog_feed(void)
+{
+    int r=0,t1=100,t2=0;
+
+#ifdef USE_WDOG
+    r = ioctl(wdog_fd, WDIOC_KEEPALIVE, NULL);
+
+    //r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &t1);
+    //printf("______set__________ wdog timeout: %d\n", r);
+    //r = ioctl(wdog_fd, WDIOC_GETTIMEOUT, &t2);
+    //printf("________________ wdog timeout: %d\n", t2);
+#endif
+    return r;
+}
+
+
+static void sig_handler(int signo)
+{
+    printf("sigint_handler, signo: %d\n", signo);
+}
+static void sig_init(void)
+{
+    signal(SIGINT,  sig_handler);
+    signal(SIGTERM, sig_handler);
+    signal(SIGKILL, sig_handler);
+}
+
 static void* polling_thread(void *arg)
 {
     thread_handle_t *h=(thread_handle_t*)arg;
 
+    wdog_init();
     tmp_create();
     while(h->quit==0) {
+        wdog_feed();
         mem_check();
         send_check();
         sleep(1);