|
|
@ -8,6 +8,7 @@ |
|
|
|
#include "def.h" |
|
|
|
#include "protocol.h" |
|
|
|
#include "encoder.h" |
|
|
|
#include "zport.h" |
|
|
|
|
|
|
|
static bool udp_client_active_flag; |
|
|
|
|
|
|
@ -31,7 +32,7 @@ static struct sockaddr_in sock; |
|
|
|
socklen_t sock_len = sizeof(sock); |
|
|
|
|
|
|
|
active_report_data_t active_report_data_structer; |
|
|
|
|
|
|
|
static int active_report_cycle; |
|
|
|
static void active_report_data_structer_init(void) |
|
|
|
{ |
|
|
|
active_report_data_structer.index = 0; /* */ |
|
|
@ -94,6 +95,7 @@ void udp_client_send_string(char *pData) |
|
|
|
void udp_client_init(void) |
|
|
|
{ |
|
|
|
active_report_data_structer_init(); |
|
|
|
active_report_cycle = 1000; /* 上报周期开始设置默认为1S */ |
|
|
|
|
|
|
|
// bool bOpt = true; |
|
|
|
struct timeval tv = {0, 20000}; |
|
|
@ -168,7 +170,11 @@ void udp_client_parse(int recv_datalen) |
|
|
|
switch (rxcmd->cmd_id) |
|
|
|
{ |
|
|
|
case CMD_SET_AUTOMATIC_REPORTING_FREQUENCY: /* 设置自动上报频率 */ |
|
|
|
/* code */ |
|
|
|
if (rxcmd->data >= 10) |
|
|
|
{ |
|
|
|
active_report_cycle = rxcmd->data; |
|
|
|
} |
|
|
|
udp_client_create_basic_response(rxcmd, recv_datalen); |
|
|
|
break; |
|
|
|
case CMD_GET_ENCODER_DATA: /* 获取编码器数据 */ |
|
|
|
/* code */ |
|
|
@ -192,7 +198,12 @@ void udp_cllient_active(void) |
|
|
|
{ |
|
|
|
if (udp_client_active_flag) |
|
|
|
{ |
|
|
|
active_report_data_structer_update(); |
|
|
|
printf("encoder1:%d,encoder2:%d\r\n", active_report_data_structer.encoder_1_count, active_report_data_structer.encoder_2_count); |
|
|
|
static uint32_t lastprocess = 0; |
|
|
|
if (sys_haspassedms(lastprocess) > active_report_cycle) |
|
|
|
{ |
|
|
|
lastprocess = HAL_GetTick(); |
|
|
|
active_report_data_structer_update(); |
|
|
|
printf("encoder1:%d,encoder2:%d\r\n", active_report_data_structer.encoder_1_count, active_report_data_structer.encoder_2_count); |
|
|
|
} |
|
|
|
} |
|
|
|
} |