int32_t fw_version_read( char * ver, int32_t max_sz );
int32_t hw_version_read( char * ver, int32_t max_sz );
int32_t tuya_productid_read( char * ver, int32_t max_sz );
+
+uint32_t device_uptime_sec( void );
#endif //__MG_DEVICE_H__
int32_t mg_device_active( mg_dev_t *dev )
{
FILE *fp;
- uint32_t now = time(NULL);
char key_id[200];
char uuid[100];
char *s;
MG_LOGI( "enter clean mode ..." );
dev->clean_device = 1;
- dev->clean_start_time = time(NULL);
+ dev->clean_start_time = device_uptime_sec();
}else if( dev->clean_device && to_clean_mode_exit ){
dev->clean_start_time = 0;
}else if( !dev->clean_device && !dev->netconfig && to_net_config ){
MG_LOGI( "enter net config mode ..." );
- //dev->netconfig = 1;
- //dev->netconfig_start_time = time(NULL);
- printf( "pressed key -- start net config, t:%ld\n", dev->netconfig_start_time );
+ printf( "pressed key -- start net config\n" );
netconfig_start( dev );
}
if( dev->clean_device ){
//检查清洁模式是否超时
- if( dev->clean_start_time && time(NULL) - dev->clean_start_time > CLEANMODE_TIMEOUT_SEC ){
+ if( dev->clean_start_time && device_uptime_sec() - dev->clean_start_time > CLEANMODE_TIMEOUT_SEC ){
mg_dev_lock( dev );
dev->clean_device = 0;
dev->clean_start_time = 0;
}
}else if( dev->netconfig){
//检查配网超时
- if( dev->netconfig_start_time && time(NULL) - dev->netconfig_start_time > NETCONFIG_TIMEOUT_SEC ){
- printf( "net config, timeout, now:%ld, s:%ld\n", time(NULL), dev->netconfig_start_time );
- //mg_dev_lock( dev );
- //dev->netconfig= 0;
- //dev->netconfig_start_time = 0;
- //mg_dev_unlock( dev );
+ if( dev->netconfig_start_time && device_uptime_sec() - dev->netconfig_start_time > NETCONFIG_TIMEOUT_SEC ){
+ printf( "net config, timeout, now:%ld, s:%ld\n", device_uptime_sec(), dev->netconfig_start_time );
netconfig_stop( dev );
}
}
light_mode_set( dev, LIGHT_MODE_TOF_ACTIVE );
}
- if( dev->tof && time(NULL ) - tof_check_time > cfg_mg_tof_interval_read( dev ) ){
+ if( dev->tof && device_uptime_sec() - tof_check_time > cfg_mg_tof_interval_read( dev ) ){
- tof_check_time = time(NULL);
+ tof_check_time = device_uptime_sec();
memset( &info, 0, sizeof( info ) );
//检查周期到达,读取tof状态
#include <string.h>
#include <unistd.h>
#include <pthread.h>
+#include <sys/sysinfo.h>
//#include "button.h"
//#include "iot.h"
//#include "mg_log.h"
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", time(NULL), dev->netconfig, dev->netconfig_start_time );
+ printf( "netconfig_start,now:%ld, , cfg:%d, s:%ld\n", device_uptime_sec(), dev->netconfig, dev->netconfig_start_time );
mg_dev_lock( dev );
dev->netconfig = 1;
- dev->netconfig_start_time = time(NULL);
+ dev->netconfig_start_time = device_uptime_sec();
mg_dev_unlock( dev );
return 0;
}
int32_t netconfig_stop( mg_dev_t *dev )
{
- printf( "netconfig_stop,now:%ld, , cfg:%d, s:%ld\n", time(NULL), dev->netconfig, dev->netconfig_start_time );
+ printf( "netconfig_stop,now:%ld, , cfg:%d, s:%ld\n", device_uptime_sec(), dev->netconfig, dev->netconfig_start_time );
mg_dev_lock( dev );
dev->netconfig = 0;
dev->netconfig_start_time = 0;
}
}
-#if 0
-int32_t tuya_config_start( mg_dev_t *dev );
-int32_t tuya_config_stop( mg_dev_t *dev );
-
-
-int32_t wificonfig_start( mg_dev_t *dev )
-{
- mg_dev_lock( dev );
- dev->wifi_config = 1;
- dev->wifi_config_timeout = time(NULL)+2*60;//2minutes timeout
- mg_dev_unlock( dev );
- //TODO: start ble adver ...
- g_ble_adv = 1;
- return 0;
-}
-
-int32_t wificonfig_stop( mg_dev_t *dev )
-{
- mg_dev_lock( dev );
- dev->wifi_config = 0;
- dev->wifi_config_timeout = 0;
- mg_dev_unlock( dev );
- //TODO: stop ble adver ...
- g_ble_adv = 0;
- return 0;
-}
-
-int32_t wificonfig_success( mg_dev_t *dev )
-{
- return 0;
-}
-
-int32_t wificonfig_fail( mg_dev_t *dev )
-{
- return 0;
-}
-#endif