增加心跳包上报平台30秒一次
authorkyz <kongyuzhong@google.com>
Fri, 7 Jun 2024 07:51:53 +0000 (15:51 +0800)
committerkyz <kongyuzhong@google.com>
Fri, 7 Jun 2024 07:51:53 +0000 (15:51 +0800)
user/user_report.c

index 6ce62bde80291f9228f9aa2d811990221361715d..bef75e8929611d35215c6bb6852b8d054467f499 100644 (file)
@@ -53,6 +53,9 @@ static const char *fmt = "{\n\
 }";
 
 #endif
+
+static const char* keepalive_fmt ="{ \"action\":\"heartbeat\", \"mac\":\"%s\" }";
+
 typedef struct{
        uint32_t cid;
        char* mac;
@@ -163,13 +166,28 @@ static void mac_str_init( void )
 
 static const char * weld_method_str[3] = {"TIG", "MIG", "MAG" };
 
+
+
 char * devinfo_report_str( void )
 {
     static char tx_buf[500];
-         static rpt_info_t to_rpt;
+       static rpt_info_t to_rpt;
+       static uint32_t last_rpt_tick = 0;
+       uint32_t now = xTaskGetTickCount();
+
+       if( last_rpt_tick == 0 )
+               last_rpt_tick = now;
 
          if( get_new_rpt_info( &to_rpt ) < 0 ){
-                       return NULL;
+                       if( now - last_rpt_tick < 30*1000 ){
+                               //数据没有变化,不上报
+                               return NULL;
+                       }else{
+                               //30秒上报一个心跳包
+                               sprintf( (char*)tx_buf, keepalive_fmt, g_mac_str );
+                               last_rpt_tick = now;
+                               return tx_buf;
+                       }
                }
                memcpy( &g_rpt_sent, &to_rpt, sizeof( g_rpt_sent ) );
 
@@ -192,7 +210,7 @@ char * devinfo_report_str( void )
                          g_rpt_sent.freq,
                          g_rpt_sent.gas
                                );
-
+       last_rpt_tick = now;
     return tx_buf;
 }