| | |
| | | static HIDO_UINT32 l_u32HeartBeatTick = 0; |
| | | static HIDO_UINT8 l_au8CmdBuff[1024]; |
| | | |
| | | uint8_t TCPfail_flag = 0,flag_first_TCPconnect=1; |
| | | uint32_t TCPfailetimer; |
| | | uint16_t ip0,ip1,ip2,ip3,port; |
| | | |
| | | /******************************************************************************* |
| | | * Local Function Declaration * |
| | | *******************************************************************************/ |
| | | HIDO_INT32 TCPClient_Heartbeat(HIDO_VOID); |
| | | void TCPHeartBeatUpload(void); |
| | | void UDPClient_UploadGPS(void); |
| | | void TCPReceiveMessageReply(void); |
| | | /******************************************************************************* |
| | | * Local Function * |
| | |
| | | * Author : www.hido-studio.com |
| | | * Modified Date: : 2021年1月9日 |
| | | *******************************************************************************/ |
| | | extern uint8_t gps_4g_flag,search_open_flag; |
| | | extern uint8_t gps_4g_flag,search_open_flag,gps_open_flag,gps_wait_count,gps_need_data_flag,gps_wait_count2; |
| | | extern Operation_step UWB_work_state; |
| | | Commend_Datestruct TCP_command; |
| | | uint8_t result; |
| | | char applyid[10]; |
| | | uint16_t receive_id; |
| | | uint16_t g_com_position; |
| | | uint16_t g_com_num; |
| | | |
| | | HIDO_UINT8 *_u8Data_temp1=NULL; |
| | | HIDO_UINT32 _u32Len_temp; |
| | | extern int32_t distance; |
| | | extern uint8_t GPS_GGAmessage[150],userkey_state,gps_timeout_flag; |
| | | extern uint16_t g_spsum,g_snum,ave_sp; |
| | | extern uint32_t u32GGaLenth; |
| | | extern char GGA_Final_message[1024]; |
| | | extern uint32_t gga_num; |
| | | static HIDO_INT32 TCPClient_DataProc(HIDO_UINT8 *_u8Data, HIDO_UINT32 _u32Len) |
| | | { |
| | | HIDO_CHAR *apcSplitStr[12]; |
| | | HIDO_UINT32 u32SplitCnt = 0; |
| | | |
| | | HIDO_CHAR acResponse[200]; |
| | | HIDO_CHAR temp_acResponse[200]; |
| | | _u8Data_temp1=_u8Data; |
| | | _u32Len_temp=_u32Len; |
| | | HIDO_CHAR acReadponse[200]; |
| | | HIDO_UINT32 datalenth; |
| | | HIDO_UINT32 u32ResponseLen; |
| | | HIDO_UINT32 u32ReadResponseLen; |
| | | LOG_INFO(TRACE_MODULE_APP, "收到数据\r\n"); |
| | | |
| | | |
| | | |
| | | if(STRCMP(_u8Data, "$instruct,") == 0) |
| | | if(STRCMP(_u8Data, "$setpara,") == 0) |
| | | { |
| | | u32ResponseLen = snprintf(acResponse, 12+_u32Len, "$setparaok,%s\r\n", \ |
| | | _u8Data); |
| | | memcpy(temp_acResponse,acResponse,sizeof(acResponse)); |
| | | |
| | | u32SplitCnt = HIDO_UtilStrSplit((HIDO_CHAR *)_u8Data, ',', apcSplitStr, HIDO_ARRARY_COUNT(apcSplitStr)); |
| | | TCP_command.tagId = HIDO_UtilHexStrToInt(apcSplitStr[3]); |
| | | |
| | | if(g_com_map[DEV_ID]==TCP_command.tagId) |
| | | receive_id = HIDO_UtilHexStrToInt(apcSplitStr[1]); |
| | | |
| | | if(g_com_map[DEV_ID]==receive_id) |
| | | { |
| | | g_com_position=HIDO_UtilStrToInt(apcSplitStr[2]); |
| | | if(g_com_position!=CNT_RESTART&&g_com_position!=0&&g_com_position!=CNT_UPDATE) |
| | | { |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)temp_acResponse, u32ResponseLen); |
| | | g_com_map[g_com_position]=HIDO_UtilStrToInt(apcSplitStr[3]); |
| | | } |
| | | if(g_com_map[SEND_4G_SECOND]<30) |
| | | { |
| | | gps_open_flag=0; |
| | | gps_wait_count=0; |
| | | gps_wait_count2=0; |
| | | gps_need_data_flag=1;//切换状态 |
| | | memset(GGA_Final_message, 0, sizeof(GGA_Final_message));//清空接收到的用完的数组 |
| | | u32GGaLenth=0; |
| | | gga_num=0;//清0有效次数 |
| | | }else{ |
| | | gps_open_flag=1; |
| | | gps_wait_count=0; |
| | | gps_wait_count2=0; |
| | | gps_need_data_flag=1;//切换状态 |
| | | } |
| | | |
| | | // switch(TCP_command.type) |
| | | // { |
| | | // case BIND_SUCCESS: |
| | | // { |
| | | |
| | | TCP_command.type = HIDO_UtilStrToInt(apcSplitStr[1]); |
| | | memcpy(&applyid,apcSplitStr[2],8); |
| | | // TCP_command.applyID = HIDO_UtilStrToInt(apcSplitStr[2]); |
| | | TCP_command.gunLableId = HIDO_UtilHexStrToInt(apcSplitStr[4]); |
| | | TCP_command.warnDistance = HIDO_UtilStrToInt(apcSplitStr[5]); |
| | | TCP_command.alarmDistance = HIDO_UtilStrToInt(apcSplitStr[6]); |
| | | TCP_command.frequency = HIDO_UtilStrToInt(apcSplitStr[7]); |
| | | if(TCP_command.type>0&&TCP_command.type<8) |
| | | result = 1; |
| | | |
| | | switch(TCP_command.type) |
| | | { |
| | | case BIND_SUCCESS: |
| | | { |
| | | |
| | | g_com_map[ALARM_DISTANCE1]= TCP_command.warnDistance; |
| | | g_com_map[ALARM_DISTANCE2]=TCP_command.alarmDistance; |
| | | // g_com_map[SEND_4G_FREQUENCY]=1000/TCP_command.frequency; |
| | | if(g_com_map[BIND_DEV_ID]!=TCP_command.gunLableId) |
| | | { |
| | | g_com_map[BIND_DEV_ID]=TCP_command.gunLableId; |
| | | UWB_work_state = SEARCH_DEV; |
| | | search_open_flag = 1; |
| | | } |
| | | // g_com_map[ALARM_DISTANCE1]= TCP_command.warnDistance; |
| | | // g_com_map[ALARM_DISTANCE2]=TCP_command.alarmDistance; |
| | | // // g_com_map[SEND_4G_FREQUENCY]=1000/TCP_command.frequency; |
| | | // if(g_com_map[BIND_DEV_ID]!=TCP_command.gunLableId) |
| | | // { |
| | | // g_com_map[BIND_DEV_ID]=TCP_command.gunLableId; |
| | | // UWB_work_state = SEARCH_DEV; |
| | | // search_open_flag = 1; |
| | | // } |
| | | |
| | | |
| | | } |
| | | break; |
| | | case UNBIND: |
| | | g_com_map[BIND_DEV_ID] = 0; |
| | | UWB_work_state = UN_BIND; |
| | | // } |
| | | // break; |
| | | // case UNBIND: |
| | | // g_com_map[BIND_DEV_ID] = 0; |
| | | // UWB_work_state = UN_BIND; |
| | | |
| | | |
| | | break; |
| | | // bind_resetbreak(); |
| | | case OPEN_GNSS: |
| | | gps_4g_flag = 1; |
| | | // break; |
| | | // // bind_resetbreak(); |
| | | // case OPEN_GNSS: |
| | | // gps_4g_flag = 1; |
| | | |
| | | break; |
| | | // break; |
| | | |
| | | case CLOSE_VIBRATION: |
| | | g_com_map[MOTOR_ENABLE]=0; |
| | | // case CLOSE_VIBRATION: |
| | | // g_com_map[MOTOR_ENABLE]=0; |
| | | |
| | | |
| | | break; |
| | | case OPEN_VIBRATION: |
| | | g_com_map[MOTOR_ENABLE]=1; |
| | | // break; |
| | | // case OPEN_VIBRATION: |
| | | // g_com_map[MOTOR_ENABLE]=1; |
| | | |
| | | |
| | | break; |
| | | case QUARY_INFORMATION: |
| | | //?? |
| | | // break; |
| | | // case QUARY_INFORMATION: |
| | | // //?? |
| | | |
| | | break; |
| | | case CHANGE_POLL_FREQUENCY: |
| | | // break; |
| | | // case CHANGE_POLL_FREQUENCY: |
| | | |
| | | g_com_map[SEND_4G_SECOND]=TCP_command.frequency*60; |
| | | break; |
| | | } |
| | | result = 1; |
| | | TCPHeartBeatUpload(); |
| | | if(TCP_command.type!=QUARY_INFORMATION||TCP_command.type!=OPEN_GNSS) |
| | | // g_com_map[SEND_4G_SECOND]=TCP_command.frequency*60; |
| | | // break; |
| | | // } |
| | | // result = 1; |
| | | // TCPHeartBeatUpload(); |
| | | // if(TCP_command.type!=QUARY_INFORMATION||TCP_command.type!=OPEN_GNSS) |
| | | save_com_map_to_flash(); |
| | | result = 0; |
| | | memset(&applyid,0,8); |
| | | // result = 0; |
| | | // memset(&applyid,0,8); |
| | | } |
| | | } else if(STRCMP(_u8Data, "$message_reply,") == 0) |
| | | } else if(STRCMP(_u8Data, "$readpara,") == 0) |
| | | { |
| | | u32SplitCnt = HIDO_UtilStrSplit((HIDO_CHAR *)_u8Data, ',', apcSplitStr, HIDO_ARRARY_COUNT(apcSplitStr)); |
| | | TCP_command.tagId = HIDO_UtilHexStrToInt(apcSplitStr[1]); |
| | | if(g_com_map[DEV_ID]==TCP_command.tagId) |
| | | receive_id = HIDO_UtilHexStrToInt(apcSplitStr[1]); |
| | | if(g_com_map[DEV_ID]==receive_id) |
| | | { |
| | | g_com_position=HIDO_UtilStrToInt(apcSplitStr[2]); |
| | | g_com_num= HIDO_UtilStrToInt(apcSplitStr[3]); |
| | | u32ReadResponseLen = snprintf(acReadponse, sizeof(acReadponse), "$replypara,%04x,%d", \ |
| | | receive_id,g_com_position); |
| | | for(uint16_t i=0;i<g_com_num;i++) |
| | | { |
| | | datalenth = sprintf((HIDO_CHAR *)&acReadponse[u32ReadResponseLen],",%d",g_com_map[g_com_position+i]); |
| | | u32ReadResponseLen += datalenth; |
| | | } |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)acReadponse, u32ReadResponseLen); |
| | | } |
| | | } |
| | | return HIDO_OK; |
| | |
| | | { |
| | | if(l_eTCPClientState == TCP_CLIENT_STATE_CONNECTING) |
| | | { |
| | | TCPfail_flag = 0; |
| | | l_eTCPClientState = TCP_CLIENT_STATE_IDLE; |
| | | } |
| | | |
| | |
| | | } |
| | | case SOCKET_EVENT_CLOSED: |
| | | { |
| | | TCPfail_flag = 0; |
| | | l_eTCPClientState = TCP_CLIENT_STATE_IDLE; |
| | | break; |
| | | } |
| | |
| | | HIDO_UINT32 u32RecvLen = 0; |
| | | |
| | | i32Ret = Socket_Recv(l_i32TCPClientID, l_au8CmdBuff, sizeof(l_au8CmdBuff) - 1, &u32RecvLen); |
| | | |
| | | if(HIDO_OK == i32Ret) |
| | | { |
| | | TCPClient_DataProc(l_au8CmdBuff, u32RecvLen); |
| | | } |
| | | memset(l_au8CmdBuff,0,sizeof(l_au8CmdBuff)); |
| | | break; |
| | | } |
| | | default: |
| | |
| | | extern uint8_t bat_percent,taglist_num; |
| | | uint8_t alarm_type; |
| | | extern double jd,wd; |
| | | extern int32_t distance; |
| | | void TCPHeartBeatUpload(void) |
| | | { |
| | | |
| | | void UDPClient_UploadGPS(void) |
| | | { if(gps_open_flag||userkey_state) |
| | | air780_led_on(); |
| | | HIDO_CHAR acHeart[200]; |
| | | HIDO_UINT32 u32HeartLen; |
| | | if(alarm_type) |
| | | { |
| | | u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,alarm,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | } else { |
| | | u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,heart,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | } |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)acHeart, u32HeartLen); |
| | | ave_sp = g_spsum/g_snum; |
| | | g_spsum = 0; |
| | | g_snum = 0; |
| | | // if(alarm_type==1) |
| | | // { |
| | | // u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,alarm,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | // g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | // } else { |
| | | // u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,heart,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | // g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | // } |
| | | |
| | | u32HeartLen = snprintf(acHeart, sizeof(acHeart), "%s,%04x,%02u%%,%d,%d,0,0\r\n", \ |
| | | GPS_GGAmessage,g_com_map[DEV_ID],bat_percent,userkey_state,gps_timeout_flag); |
| | | |
| | | |
| | | if(gps_open_flag||userkey_state){ |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)acHeart, u32HeartLen); |
| | | }else{ |
| | | // Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)GGA_Final_message, u32GGaLenth); |
| | | // memset(GGA_Final_message, 0, sizeof(GGA_Final_message));//清空接收到的用完的数组 |
| | | // u32GGaLenth=0; |
| | | // gga_num=0;//清0有效次数 |
| | | } |
| | | userkey_state = 0; |
| | | air780_led_off(); |
| | | } |
| | | void UDPClient_UploadGPS_10pack(void)//10包发送功能 |
| | | { air780_led_on(); |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)GGA_Final_message, u32GGaLenth); |
| | | memset(GGA_Final_message, 0, sizeof(GGA_Final_message));//清空接收到的用完的数组 |
| | | u32GGaLenth=0; |
| | | gga_num=0;//清0有效次数 |
| | | air780_led_off(); |
| | | } |
| | | void TCPHeartBeatUpload(void) |
| | | { |
| | | HIDO_CHAR acHeart1[200]; |
| | | HIDO_UINT32 u32HeartLen; |
| | | ave_sp = g_spsum/g_snum; |
| | | g_spsum = 0; |
| | | g_snum = 0; |
| | | // if(alarm_type==1) |
| | | // { |
| | | // u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,alarm,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | // g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | // } else { |
| | | // u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message,heart,%04x,%d,%04x,%d,%02u%%,%d,%d,%lf,%lf,%s,%d,%d,0\r\n", \ |
| | | // g_com_map[DEV_ID],GetUWBBindState(),g_com_map[BIND_DEV_ID],alarm_type,bat_percent,g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],jd,wd,applyid,result,distance); |
| | | // } |
| | | // u32Len = HIDO_UtilSnprintf((HIDO_CHAR *)l_au8CmdBuff, sizeof(l_au8CmdBuff), "$XTB,%X,%02u%%,%d.%d,%s,%d,1.", |
| | | // g_com_map[DEV_ID], bat_percent2, g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff, Module_GetCCID(),userkey_state4g,g_com_map[TCP_IP_0],g_com_map[TCP_IP_1],g_com_map[TCP_IP_2],g_com_map[TCP_IP_3],g_com_map[TCP_PORT]); |
| | | |
| | | u32HeartLen = snprintf(acHeart1, sizeof(acHeart1), "$XTB,%04x,%02u%%,%d.%d,%s,%d,0\r\n", \ |
| | | g_com_map[DEV_ID],bat_percent,g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff,Module_GetCCID(),userkey_state); |
| | | Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)acHeart1, u32HeartLen); |
| | | } |
| | | void TCPReceiveMessageReply(void) |
| | | { |
| | | HIDO_CHAR acHeart[200]; |
| | |
| | | if(alarm_type == 2) |
| | | alarm_type = 0; |
| | | } |
| | | uint8_t TCPfail_flag = 0,flag_first_TCPconnect=1; |
| | | uint32_t TCPfailetimer; |
| | | uint16_t ip0,ip1,ip2,ip3,port; |
| | | |
| | | HIDO_INT32 TCPClient_Poll(void) |
| | | { |
| | | if (Internet_IsIPReady() == HIDO_TRUE) |
| | |
| | | l_eTCPClientState = TCP_CLIENT_STATE_CONNECTING; |
| | | |
| | | |
| | | HIDO_UtilSnprintf((HIDO_CHAR *) l_au8CmdBuff, sizeof(l_au8CmdBuff), "%u.%u.%u.%u", ip0,ip1, ip2, ip3); |
| | | HIDO_UtilSnprintf((HIDO_CHAR *) l_au8CmdBuff, sizeof(l_au8CmdBuff), "%u.%u.%u.%u", ip0,ip1, ip2, ip3); |
| | | |
| | | Socket_Connect(l_i32TCPClientID, (HIDO_CHAR *) l_au8CmdBuff, port); |
| | | |
| | | // HIDO_UtilSnprintf((HIDO_CHAR *) l_au8CmdBuff, sizeof(l_au8CmdBuff), "123.57.87.125"); |
| | | // Socket_Connect(l_i32TCPClientID, (HIDO_CHAR *) l_au8CmdBuff, 8888); |
| | | TCPfail_flag = 1; |
| | | |
| | | // HIDO_UtilSnprintf((HIDO_CHAR *) l_au8CmdBuff, sizeof(l_au8CmdBuff), "111.198.60.6"); |
| | | // Socket_Connect(l_i32TCPClientID, (HIDO_CHAR *) l_au8CmdBuff, 1234); |
| | | TCPfail_flag = 1; |
| | | } |
| | | else |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | if ((u32CurTick - l_u32HeartBeatTick) >= HIDO_TIMER_TICK_S(g_com_map[SEND_4G_SECOND])||flag_first_TCPconnect) |
| | | // if ((u32CurTick - l_u32HeartBeatTick) >= HIDO_TIMER_TICK_S(15)||flag_first_TCPconnect) |
| | | |
| | | if ((u32CurTick - l_u32HeartBeatTick) >= HIDO_TIMER_TICK_S(60)||flag_first_TCPconnect) |
| | | //if ((u32CurTick - l_u32HeartBeatTick) >= HIDO_TIMER_TICK_S(g_com_map[SEND_4G_SECOND])||flag_first_TCPconnect) |
| | | { |
| | | flag_first_TCPconnect = 0; |
| | | l_u32HeartBeatTick = u32CurTick; |
| | | // 这里是自定义心跳 |
| | | if(g_com_map[HEARTBEAT]) |
| | | TCPHeartBeatUpload(); |
| | | //UDPClient_UploadGPS();//先不弄心跳 |
| | | // HIDO_CHAR acHeart[128]; |
| | | // HIDO_UINT32 u32HeartLen = snprintf(acHeart, sizeof(acHeart), "$message heart,%04x,00001,1,50,50,50,,,,\r\n", g_com_map[DEV_ID]); |
| | | // Socket_Send(l_i32TCPClientID, (HIDO_UINT8 *)acHeart, u32HeartLen); |
| | |
| | | return HIDO_OK; |
| | | } |
| | | |
| | | HIDO_BOOL TCPClient_IsSendOver(HIDO_VOID) |
| | | { |
| | | return Socket_IsSendQueueEmpty(l_i32TCPClientID); |
| | | } |
| | | |
| | | /******************************************************************************* |
| | | * Function Name : TCPClient_Init |
| | | * Description : TCP客户端初始化 |