From: kyz Date: Fri, 7 Jun 2024 07:51:53 +0000 (+0800) Subject: 增加心跳包上报平台30秒一次 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=243b1caf63f3d91b9638ec7a6588e66b56dd2deb;p=yn%2Fweldingcontroller.git 增加心跳包上报平台30秒一次 --- diff --git a/user/user_report.c b/user/user_report.c index 6ce62bd..bef75e8 100644 --- a/user/user_report.c +++ b/user/user_report.c @@ -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; }