修改读取时间函数,避免ntp影响
authorkyz <kongyuzhong@gmail.com>
Fri, 21 Jul 2023 07:41:02 +0000 (15:41 +0800)
committerkyz <kongyuzhong@gmail.com>
Fri, 21 Jul 2023 07:41:02 +0000 (15:41 +0800)
app/inc/device.h
app/src/device_gesture.c
app/src/device_light.c
app/src/device_netconfig.c
app/src/main.c
button/src/button_scan.c
led/src/led.c

index eb7e15f9f0baf28d9f5b73551f3c788ced875c96..4e215c344fac798d834673e527fbeb247a214c7c 100644 (file)
@@ -329,6 +329,7 @@ void device_light_init( mg_dev_t *dev );
 void led_flash_for_btn_single_click( mg_dev_t *dev, button_code_t btn_code );
 void light_set_key_br( mg_dev_t *dev, uint32_t id, uint32_t br );
 void light_set_atmos_br( mg_dev_t *dev, uint32_t id, uint32_t br );
+int32_t load_light_cfg( light_cfg_t * cfg );
 
 //-------------------------------------------------------------------------------------
 //net config
@@ -358,6 +359,7 @@ int32_t tuya_productid_read( char * ver, int32_t max_sz );
 //ble广播配置文件
 char *load_ble_adv_local_name( void );
 
-uint32_t device_uptime_sec( void );
+extern time_t device_uptime_sec( void );
+extern time_t device_uptime_msec( void );
 #endif //__MG_DEVICE_H__
 
index ffecee177a1cabd441940926cdc42587e6d84101..d79face3c823c1e46423caa45703bfbfc5f8c26e 100644 (file)
@@ -467,7 +467,7 @@ static int32_t gr_detect_effective(gesture_ev_t ev)
         if ((repeating_gestures != ev) || (no_hands == 1))
         {
             dp_gesture_event_report(ev);
-            timeout = time(NULL);
+            timeout = device_uptime_sec();
             no_hands = 0;
             printf("上报dp ===================== %d\n", ev);
         }
@@ -521,7 +521,7 @@ void *gr_task(void *param)
     uint32_t privacy =0;
 
     gr_ctrl_t *p_gr = (gr_ctrl_t *)param;
-    gr_time = time(NULL);
+    gr_time = device_uptime_sec();
 
 
     my_privacy =  -1;
@@ -581,11 +581,11 @@ void *gr_task(void *param)
                     usleep(100 * 000);
                     if (time_flasg)
                     {
-                        gr_time = time(NULL);
+                        gr_time = device_uptime_sec();
                         time_flasg = 0;
                     }
                     dp_timeout = cfg_recognition_duration_read(p_gr->dev);
-                    if (time(NULL) - gr_time > dp_timeout)
+                    if (device_uptime_sec() - gr_time > dp_timeout)
                     {
                         printf("gesture Time out\n");
                         reportdp_and_close_ring_gr(p_gr->light_ctrl);
index 256aba26bc2a5723248dc0db8c18d2d0730508f3..89adfcc7a6e7e3425f25adb190002d1d5ea21e27 100644 (file)
@@ -37,7 +37,7 @@ void device_light_init( mg_dev_t *dev )
                MG_LOGE( "mg_led_open fail!" );
        }
 }
-
+/*
 char *light_mode_name[]={
        "led_off",
        "led_on",
@@ -50,6 +50,18 @@ char *light_mode_name[]={
        "led_breath",
        "led_nochange",
 };
+*/
+static const char* light_mode_name[] = {
+       "LIGHT_MODE_INIT", //开机初始状态,所有灯常灭
+       "LIGHT_MODE_NO_AUTH", //未授权:控制所有按键背光连续慢闪,装饰灯带常灭;不加载涂鸦 SDK应用程序轮询授权是否已写入,并校验写入长度符合要求;
+       "LIGHT_MODE_AUTH_NO_WIFICONFIG", //已授权未配网:所有灯光常灭;
+       "LIGHT_MODE_AUTH_WIFICONFIGING", //配网过程中 LED7 & LED8 连续慢闪, 2分钟超时后退出
+       "LIGHT_MODE_AUTH_WIFICONFIG_NO_ACTIVE", //已授权已配网未激活:所有灯光常灭;
+       "LIGHT_MODE_ACTIVE", //已授权已配网已激活:进入主流程,灯光根据 DP 设置处理。
+       "LIGHT_MODE_CLEAN",
+       "LIGHT_MODE_TOF_ACTIVE",
+       "LIGHT_MODE_TOF_DEACTIVE"
+};
 
 void light_mode_set( mg_dev_t *dev, light_mode_t mode )
 {
index d28b539b8bccff1dd90d7115d9dec20ac21ea284..ece079ac70ebf05cda9218eb21a2036437bfa9e7 100644 (file)
 
 extern int32_t mg_device_bind_flag_write( void );
 
-//使用sysinfo来获取系统运行时间,因使用time(NULL)获取时间会受到ntp的干扰。
-uint32_t device_uptime_sec( void )
-{
-       struct sysinfo info;    
-
-       if( sysinfo( &info ) ){
-               return 0;
-       }
-
-       return info.uptime;
-}
-
 int32_t        netconfig_start( mg_dev_t *dev )
 {
        printf( "netconfig_start,now:%ld, , cfg:%d, s:%ld\n", device_uptime_sec(), dev->netconfig, dev->netconfig_start_time );
index 1cc879f2adccd15544016511aa5569d499aa77e6..cc4b25b74988e50444c8c0dc5950fdcddb456bc2 100644 (file)
 
 #define PID_FILE "/var/run/mg_app/mg_app.pid"
 
+extern int32_t read_device_uuid( mg_dev_t *dev );
+
 static mg_dev_t g_mg_dev;
 
+time_t device_uptime_msec( void )
+{
+       struct timespec ts;
+
+       clock_gettime( CLOCK_BOOTTIME, &ts );
+       
+       return (time_t )(ts.tv_sec*1000+ts.tv_nsec/1000/1000);
+}
+
+time_t device_uptime_sec( void )
+{
+       //struct sysinfo info;  
+       //( sysinfo( &info ) ){
+       //return info.uptime;
+       struct timespec ts;
+
+       clock_gettime( CLOCK_BOOTTIME, &ts );
+       
+       return ts.tv_sec;
+}
+
 char * dev_uuid_str( void )
 {
        return g_mg_dev.uuid;
index dc19ac6243ca972f459a446b3aa7f5e1021ebda7..f8e274709760c4a2c7b689b999f910e2e8f531ae 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <time.h>
 #include <sys/time.h>
+#include <time.h>
 #include <unistd.h>
 
 #include "button.h"
@@ -48,9 +49,14 @@ int32_t is_comb_code( btn_ctrl_t btn_ctrl,  uint32_t code )
 
 static uint32_t get_systime_ms( void )
 {
-       struct timeval tm;
-       gettimeofday( &tm, NULL );
-       return (uint32_t)(tm.tv_sec*1000+tm.tv_usec/1000);
+       //struct timeval tm;
+       //gettimeofday( &tm, NULL );
+       //return (uint32_t)(tm.tv_sec*1000+tm.tv_usec/1000);
+       struct timespec ts;
+
+       clock_gettime( CLOCK_BOOTTIME, &ts );
+       
+       return (time_t )(ts.tv_sec*1000+ts.tv_nsec/1000/1000);
 }
 
 void single_btn_report( btn_ctrl_t btn_ctrl, uint32_t code, button_event_t event  )
index 6d7797901f2d9cad021cf35188877cf34cc9fc72..2142f8290cb3d25501167a0365adff9123672314 100644 (file)
@@ -7,6 +7,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/time.h>
+#include <time.h>
 
 #include "led.h"
 #include "mg_log.h"
@@ -87,11 +88,15 @@ static int32_t mg_led_br_update(  light_ctrl_t ctrl, uint32_t led_id, uint32_t b
 static int32_t mg_led_st(  light_ctrl_t ctrl, uint32_t led_id, light_st_t *st );
 //--------------------------------------------------------------------------------------------------------------------------------
 
-uint32_t now_msec( void )
+static uint32_t now_msec( void )
 {
-       struct timeval tm;
-       gettimeofday( &tm, NULL );
-       return (uint32_t)(tm.tv_sec*1000+tm.tv_usec/1000 );
+//     struct timeval tm;
+//     gettimeofday( &tm, NULL );
+//     return (uint32_t)(tm.tv_sec*1000+tm.tv_usec/1000 );
+       struct timespec ts;
+
+       clock_gettime( CLOCK_BOOTTIME, &ts );
+       return (time_t )(ts.tv_sec*1000+ts.tv_nsec/1000/1000);
 }
 
 static uint32_t  get_key_led_id( uint32_t key_led )