/******************************************************************************* * File Name : NTRIPApp.c * Description : * Created on : 2022Äê3ÔÂ30ÈÕ * Author : www.hido-studio.com *******************************************************************************/ /******************************************************************************* * Include Files * *******************************************************************************/ #include "NTRIPApp.h" #include "NTRIPClient.h" #include "HIDO_Timer.h" #include "HIDO_Debug.h" #include "Uart.h" #include "string.h" #include "global_param.h" #include "Module.h" #include "DBG.h" #define CONNECT_RETRY_CNT 3 #define CONNECT_RETRY_INTERVAL 30 #define NTRIP_HOST "rtk.ntrip.qxwz.com" #define NTRIP_PORT 8002 #define NTRIP_USERNANME "qxmfdg007" #define NTRIP_PASSWORD "4595a89" #define NTRIP_SOURCE_NAME "xxxxxxxxx" /******************************************************************************* * Macro * *******************************************************************************/ /******************************************************************************* * Type Definition * *******************************************************************************/ /******************************************************************************* * Local Variable * *******************************************************************************/ static HIDO_UINT32 l_u32TimerID = 0; static HIDO_UINT32 l_u32RetryCnt = 0; static HIDO_UINT32 l_u32CSQTimerID = 0; /******************************************************************************* * Local Function Declaration * *******************************************************************************/ static HIDO_INT32 ConnectSetup(void); /******************************************************************************* * Local Function * *******************************************************************************/ /******************************************************************************* * Function Name : TimeOutCallback * Description : * Input : * Output : * Return : * Author : ¶Å¼ü * Modified Date: : 2022-03-29 *******************************************************************************/ static HIDO_VOID TimeOutCallback(HIDO_VOID *_pArg) { HIDO_Debug("NTRIP App Reconnect\r\n"); l_u32RetryCnt = 0; ConnectSetup(); } /******************************************************************************* * Function Name : SignalIntensityCallback * Description : * Input : * Output : * Return : * Author : ¶Å¼ü * Modified Date: : 2022-03-29 *******************************************************************************/ static HIDO_VOID SignalIntensityCallback(HIDO_UINT32 _u32SignalIntensity, HIDO_VOID *_pArg) { uint8_t u32Len,l_au8CmdBuff[200]; HIDO_Debug("4G signal intensity is %u\r\n", _u32SignalIntensity); u32Len = HIDO_UtilSnprintf((HIDO_CHAR *)l_au8CmdBuff, sizeof(l_au8CmdBuff),"4G signal intensity is %u\r\n", _u32SignalIntensity); TCPClient_Uploadhex(l_au8CmdBuff,u32Len); } /******************************************************************************* * Function Name : CSQCallback * Description : * Input : * Output : * Return : * Author : ¶Å¼ü * Modified Date: : 2022-03-29 *******************************************************************************/ static HIDO_VOID CSQCallback(HIDO_VOID *_pArg) { Module_GetSignalIntensityAsync(SignalIntensityCallback, HIDO_NULL); } /******************************************************************************* * Function Name : NTRIPClientCallback * Description : * Input : * Output : * Return : * Author : www.hido-studio.com * Modified Date: : 2022Äê3ÔÂ30ÈÕ *******************************************************************************/ static HIDO_INT32 NTRIPClientCallback(HIDO_UINT32 _u32Code, HIDO_UINT8 *_pu8Data, HIDO_UINT32 _u32Len, HIDO_VOID *_pArg) { switch(_u32Code) { case NTRIP_CODE_CONNECT_FAILED: case NTRIP_CODE_DISCONNECT: { l_u32RetryCnt++; if(l_u32RetryCnt > CONNECT_RETRY_CNT) { HIDO_TimerStart(l_u32TimerID, HIDO_TIMER_TYPE_ONCE, HIDO_TIMER_TICK_S(CONNECT_RETRY_INTERVAL), TimeOutCallback, HIDO_NULL); } else { ConnectSetup(); } break; } case NTRIP_CODE_RTCM_DATA: { l_u32RetryCnt = 0; if(DBG_GetMode() == DBG_MODE_GPS) { if(Uart_Send(UART_ID_DBG_GPS, _pu8Data, _u32Len) != HIDO_OK) { HIDO_Debug("RTK Data Send Error\r\n"); } } HIDO_Debug("%uB RTK Data Sent\r\n", _u32Len); break; } default: { break; } } return HIDO_OK; } /******************************************************************************* * Function Name : ConnectSetup * Description : * Input : * Output : * Return : * Author : www.hido-studio.com * Modified Date: : 2022Äê3ÔÂ30ÈÕ *******************************************************************************/ static HIDO_INT32 ConnectSetup(void) { return NTRIPClient_Connect((char *)&g_com_map[NTRIP_HOST_INDEX], g_com_map[NTRIP_PORT_INDEX], (char *)&g_com_map[NTRIP_USERNANME_INDEX], (char *)&g_com_map[NTRIP_PASSWORD_INDEX], (char *)&g_com_map[NTRIP_SOURCENAME_INDEX], NTRIPClientCallback, HIDO_NULL); } /******************************************************************************* * Global Function * *******************************************************************************/ /******************************************************************************* * Function Name : NTRIPApp_ReportGGA * Description : * Input : * Output : * Return : * Author : www.hido-studio.com * Modified Date: : 2022Äê3ÔÂ30ÈÕ *******************************************************************************/ HIDO_INT32 NTRIPApp_ReportGGA(HIDO_UINT8 *_pu8Data, HIDO_UINT32 _u32Len) { // HIDO_UINT8 *pcTestData = "$GPGGA,000001,3112.518576,N,12127.901251,E,1,8,1,0,M,-32,M,3,0*4B\r\n"; return NTRIPClient_ReportGGA(_pu8Data, strlen((HIDO_CHAR*)_pu8Data)); } /******************************************************************************* * Function Name : NTRIPApp_Init * Description : * Input : * Output : * Return : * Author : www.hido-studio.com * Modified Date: : 2022Äê3ÔÂ30ÈÕ *******************************************************************************/ HIDO_INT32 NTRIPApp_Init(void) { if(HIDO_TimerCreate(&l_u32TimerID) != HIDO_OK) { return HIDO_ERR; } if(HIDO_TimerCreate(&l_u32CSQTimerID) != HIDO_OK) { return HIDO_ERR; } HIDO_TimerStart(l_u32CSQTimerID, HIDO_TIMER_TYPE_LOOP, HIDO_TIMER_TICK_S(10), CSQCallback, HIDO_NULL); l_u32RetryCnt = 0; ConnectSetup(); return HIDO_OK; }