WXK
2025-03-12 3ec132c58bc4130f79390cebca35c176173cb67c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
 * 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"
 
#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(Uart_Send(UART_ID_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;
}