Init basesystem source codes.
[staging/basesystem.git] / positioning_hal / inc / GpsCommon / MDev_Gps_Main.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17 * @file MDev_Gps_Main.h
18 */
19
20 #ifndef  INC_GPSCOMMON_MDEV_GPS_MAIN_H_
21 #define  INC_GPSCOMMON_MDEV_GPS_MAIN_H_
22
23 /*---------------------------------------------------------------------------*/
24 // Include files
25
26 #include "gps_hal.h"
27 #include "positioning_def.h"
28
29 // #include "gps_hal.h"
30 // #include "MDev_Gps_Nmea.h"
31 // #include "LineSensDrv_Api.h"
32
33 /*---------------------------------------------------------------------------*/
34 // Value define
35
36 #define OFF           0       /* OFF */
37 #define ON            1       /* ON */
38 #define OK            0       /* Normal */
39 #define NG            (-1L)   /* Abnormality */
40 #define DAT_END       0xff    /* Exit code */
41
42 // State
43 typedef enum GpsMatrixSts {
44   GPS_STS_STARTUP = 0,        /* Startup confirmation */
45   GPS_STS_NORMAL,             /* In operation */
46   GPS_STS_SENT,               /* Command sent status */
47   GPS_STS_NUM
48 }TG_GPS_MATRIX_STS;
49
50 // Event
51 typedef enum GpsMatrixEvt {
52   GPS_EVT_SENDREQ = 0,              /* Transmission request              */
53   GPS_EVT_RESETREQ,                 /* GPS reset request        */
54   GPS_EVT_RECVCYCLDAT,              /* Cyclic reception command reception        */
55   GPS_EVT_RECVRSPDAT,               /* Receive response command          */
56   GPS_EVT_TIMEOUT_RSPDAT,           /* Response monitoring timeout        */
57   GPS_EVT_TIMEOUT_CYCLDAT,          /* Periodic reception data monitoring timeout  */
58   GPS_EVT_TIMEOUT_NAVI,             /* Navigation providing data monitoring timeout  */
59   GPS_EVT_TIMEOUT_DIAGCLKGUARD,     /* Diagnosis provision time guard monitoring timeout*/
60   GPS_EVT_ACC_OFF,                  /* In-function ACC-OFF instructions        */
61   GPS_EVT_NAVI_LOCATIONINFO,        /* Providing navigation information            */
62   GPS_EVT_NAVI_SPEEDINFO,           /* Navigation speed information service          */
63   GPS_EVT_TIMESETTING,              /* GPS time setting instruction          */
64   GPS_EVT_TIMEOUT_NMEADATAGUARD,    /* NMEA data-providing guard monitoring timeout*/
65   GPS_EVT_BACKUPDATA_LOAD,          /* Backup data read request       */
66   GPS_EVT_STOPREQ,                  /* Thread stop request                 */
67   GPS_EVT_WEEKCOR_CNT_NOTIFICATIO,  /* GPS Week Adjustment Counter Notification            */
68   GPS_EVT_TIMEOUT_RECOVERY,         /* GPS error monitoring reset timer      */
69   GPS_EVT_TIMEOUT_RECEIVERERR,      /* GPS receiver anomaly detection timeout  */
70   GPS_EVT_NUM
71 } TG_GPS_MATRIX_EVT;
72
73 typedef enum GpsOutputFormat {
74   GPS_FORMAT_MIN = -1,        /* Minimum Receive Format(Initialization)  */
75   GPS_FORMAT_BINARY,          /* Standard binary            */
76   GPS_FORMAT_FULLBIN,         /* Full binary            */
77   GPS_FORMAT_GGA,             /* GGA                */
78   GPS_FORMAT_DGGA,            /* DGGA                */
79   GPS_FORMAT_VTG,             /* VTG                */
80   GPS_FORMAT_RMC,             /* RMC                */
81   GPS_FORMAT_DRMC,            /* DRMC                */
82   GPS_FORMAT_GLL,             /* GLL                */
83   GPS_FORMAT_DGLL,            /* DGLL                */
84   GPS_FORMAT_GSA,             /* GSA                */
85   GPS_FORMAT_GSV1,            /* GSV(1)              */
86   GPS_FORMAT_GSV2,            /* GSV(2)              */
87   GPS_FORMAT_GSV3,            /* GSV(3)              */
88   GPS_FORMAT_GSV4,            /* GSV(4)              */
89   GPS_FORMAT_GSV5,            /* GSV(5)              */
90   GPS_FORMAT_GST,             /* GST                */
91   GPS_FORMAT__CWORD44__GP3,       /* _CWORD44_,GP,3            */
92   GPS_FORMAT__CWORD44__GP4,       /* _CWORD44_,GP,4            */
93   GPS_FORMAT_P_CWORD82_F_GP0,       /* P_CWORD82_F,GP,0            */
94   GPS_FORMAT_P_CWORD82_J_GP1,       /* P_CWORD82_J,GP,1            */
95   GPS_FORMAT_P_CWORD82_I_GP,        /* P_CWORD82_I,GP              */
96   GPS_FORMAT_P_CWORD82_E_GP0,       /* P_CWORD82_E,GP,0            */
97   GPS_FORMAT_P_CWORD82_J_GP0,       /* P_CWORD82_J,GP,0            */
98   GPS_FORMAT_P_CWORD82_E_GP2,       /* P_CWORD82_E,GP,2            */
99   GPS_FORMAT_P_CWORD82_G_GP0,       /* P_CWORD82_G,GP,0            */
100   GPS_FORMAT_P_CWORD82_J_GP7,       /* P_CWORD82_J,GP,7            */
101   GPS_FORMAT_P_CWORD82_J_GP8,       /* P_CWORD82_J,GP,8            */
102   GPS_FORMAT_MON_VER,         /* MON-VER              */
103   GPS_FORMAT_AID_INI,         /* AID-INI              */
104   GPS_FORMAT_ACK_ACKNACK,     /* ACK-ACKNACK            */
105   GPS_FORMAT_NAV_TIMEUTC,     /* NAV-TIMEUTC            */
106   GPS_FORMAT_NAV_CLOCK,       /* NAV-CLOCK                        */
107   GPS_FORMAT_RXM_RTC5,        /* RXM-RTC5                         */
108   GPS_FORMAT_NAV_SVINFO,      /* NAV-SVINFO                       */
109   GPS_FORMAT_CFG_NAVX5,       /* CFG-NAVX5            */
110   GPS_FORMAT_NMEA,            /* NMEA (Sentence unspecified)      */
111   GPS_FORMAT_UBX,             /* UBX Protocol (binary)      */
112   GPS_FORMAT_MAX              /* Maximum Receive Format        */
113 } TG_GPS_OUTPUT_FORMAT;
114
115 // Return value
116 #define RETRY_OFF       0     /* No retry            */
117 #define RETRY_ON        1     /* Retry exists            */
118 #define RETRY_OUT       2     /* Retry out          */
119 #define NG_RETRYOUT     4     /* Transmission failure retry out      */
120
121 #define GPSRET_NOPCMD   (0)   /* Non notification target command  #GPF_60_024 */
122 #define GPSRET_SNDCMD   (1)   /* Notification target command    #GPF_60_024 */
123 #define GPSRET_CMDERR   (-1)  /* No applicable command    #GPF_60_024 */
124
125 // Number of Retries
126 #define SRSET_MAX       4     /* Maximum serial reset retry value  */
127 #define HRSET_MAX       3     /* Maximum value of hard reset retry    */
128 #define SNDNG_MAX       4     /* Maximum retry value of transmission failure      */
129
130 /* The actual number of retries is SNDNG_MAX-1. */
131 #define GPS_RECV_ERR_MAX 5    /* Maximum number of reception errors  #GPF_60_024  */
132
133 // Others
134 #define SAV_MAX                   11
135 #define GPS_ALTITUDE_INVALID_VAL  (-1000000)  /* Value when fix altitude is invalid */
136 #define GPS_HEADING_INVALID_VAL   36100       /* Value when measurement orientation is invalid */
137
138 #define GPS_RECVOK                0           /* Normal reception            #13 */
139 #define GPS_RECVNG                1           /* Reception error            #13 */
140 #define GPS_OVERRUN               2           /* Overrun detection        #13 */
141 #define GPS_PARITY                3           /* Parity detection          #13 */
142 #define GPS_FRAMING               4           /* Framing detection        #13 */
143
144 // For the communication management thread
145 #define  GPS_NON_RECV             0           /* Not received              */
146 #define  GPS_RECV_ACK             1           /* ACK received            */
147 #define  GPS_RECV_DATA            2           /* Receive response command          */
148
149 #define GPS_SEND_ERR_MAX          5           /* Maximum number of transmission errors        */
150 #define GPS_CNCT_ERR_MAX          5           /* Maximum number of connection errors        */
151
152 #define GPS_START_EVT             "GPS_EVT"   /* Interthread synchronization events      */
153 #define GPS_EVT_VAL               99          /* Event settings          */
154 #define GPS_MSGDAT_BUF_SZ         500         /* Receive message buffer size    */
155
156 // Definition for receive command analysis table  #GPF_60_024
157 #define SENTENCE_STR_MAX          12      /* Maximum string for judging sentence  */
158
159 #define SENSOR_MSG_VSINFO_DSIZE  1904  //!< \~english message body max size
160
161 /*---------------------------------------------------------------------------*/
162 // Structure
163
164 /********************************************************************************
165  * TAG      :TG_GPS_MNG
166  * ABSTRACT :GPS process management information
167  * NOTE     :
168  ********************************************************************************/
169 typedef struct GpsMng {
170   u_int32               sts;            /* Matrix state          */
171   u_int32               event;          /* Matrix event code      */
172   u_int32               rcvsts;         /* Response reception status            */
173   u_int32               sndcnt;         /* Number of transmission attempts          */
174   u_int32               hrsetcnt;       /* Number of tries before hard reset  */
175   u_int32               sndngcnt;       /* Number of failed-to-send attempts        */
176   TG_GPS_OUTPUT_FORMAT  rcv_cmd;        /* Types of received GPS commands      */
177   TG_GPS_OUTPUT_FORMAT  resp_cmd;       /* Types of GPS commands during response monitoring  */
178   PNO                   resp_pno;       /* Destination PNO            */
179   RID                   resp_rid;       /* RID to be notified when responding        */
180   u_int8                resp_rst_flag;  /* Response command reset flag    */
181   BOOL                  rcv_err_flag;   /* GPS receiver error detection flag        */
182 } TG_GPS_MNG;
183
184 /********************************************************************************
185  * TAG      :TG_GPS_SAVECMD
186  * ABSTRACT :GPS process pending command
187  * NOTE     :
188  ********************************************************************************/
189 typedef struct GpsSaveCmd {
190   TG_GPS_SND_DATA       sndcmd;       /* Sending commands(_CWORD82_ command)    */
191   PNO                   us_pno;       /* Result notification destination process number(Unused)  */
192   RID                   uc_rid;       /* Result Notification Resource ID(Unused)    */
193   u_int8                uc_rst;       /* Reset flag          */
194   TG_GPS_OUTPUT_FORMAT  e_cmd_info;   /* Command information          */
195 } TG_GPS_SAVECMD;
196
197 /********************************************************************************
198  * TAG      :TG_GPS_SAVEBUF
199  * ABSTRACT :GPS process pending buffer management information
200  * NOTE     :
201  ********************************************************************************/
202 typedef struct GpsSaveBuf {
203   u_int32         saveno;             /* Current pending index number    */
204   u_int32         sendno;             /* Current send index number    */
205   u_int32         bufsav;             /* Number of pending buffers used        */
206   TG_GPS_SAVECMD  savebuf[SAV_MAX];   /* Pending buffer            */
207 } TG_GPS_SAVEBUF;
208
209 /********************************************************************************
210  * TAG      :TG_GPS_MSGRCV
211  * ABSTRACT :Receive message
212  * NOTE     :
213  ********************************************************************************/
214 typedef struct GpsMsgRcv {
215   T_APIMSG_MSGBUF_HEADER  header;     /* Message header          */
216   u_int8                  msgdat[SENSOR_MSG_VSINFO_DSIZE + 12];
217 } TG_GPS_MSGRCV;
218
219 /********************************************************************************
220  * TAG      :TG_GPS_MSGEVTCHNG
221  * ABSTRACT :GPS message event translation table
222  * NOTE     :
223  ********************************************************************************/
224 typedef struct GpsMsgEvtChng {
225   u_int32     cid;            /* Matrix state          */
226   u_int32     event;          /* Matrix event code      */
227 } TG_GPS_MSGEVTCHNG;
228
229 /********************************************************************************
230  * TAG      :TG_GPS_TIMEVTCHNG
231  * ABSTRACT :GPS timer ID and event translation table
232  * NOTE     :
233  ********************************************************************************/
234 typedef struct GpsTimEvtChng {
235   u_int16     tim_id;         /* Timer ID information          */
236   u_int16     reserve;        /* Reserved              */
237   u_int32     event;          /* Matrix event code      */
238 } TG_GPS_TIMEVTCHNG;
239
240 /********************************************************************************
241  * TAG      :Gps_Jmp_Tbl
242  * ABSTRACT :GPS jump table
243  * NOTE     :
244  ********************************************************************************/
245 typedef struct GpsJmpTbl {
246   void        (*func)( void );    /* Jump-to module          */
247 } TG_GPS_JMP_TBL;
248
249 /********************************************************************************
250  * TAG      :TG_GPS_CMD_ANA_TBL
251  * ABSTRACT :Receive command analysis table structure
252  * NOTE     :
253  ********************************************************************************/
254 typedef struct TgGpsCmdAnaTbl {
255   u_char                c_sentence[SENTENCE_STR_MAX];   /* Sentence identifier    */
256   u_int32               ul_length;                      /* Length of the command      */
257   u_int32               ul_rcv_kind;                    /* Receiving type        */
258   BOOL                  b_snd_cmd_flg;                  /* Command notification flag  */
259   TG_GPS_OUTPUT_FORMAT  e_rcv_format;                   /* Receive Format    */
260 } TG_GPS_CMD_ANA_TBL;
261
262 /********************************************************************************
263  * TAG      :TG_GPS_TIME_BCD
264  * ABSTRACT :Time information (BCD) structure
265  * NOTE     :
266  ********************************************************************************/
267 typedef struct GpsTimeBCD {
268   u_int8          uc_year;      /* Year information    */
269   u_int8          uc_month;     /* Month information    */
270   u_int8          uc_day;       /* Day information    */
271   u_int8          uc_hour;      /* Time information    */
272   u_int8          uc_min;       /* Minute information    */
273   u_int8          uc_sec;       /* Second information    */
274 } TG_GPS_TIME_BCD;
275
276 /*---------------------------------------------------------------------------*/
277 // Global values
278
279 #define MDEV_GPSMSGCHKC_MAX 10
280 #define MDEV_PSTIMCHKC_MAX  11
281 extern const TG_GPS_MSGEVTCHNG    kGpsMsgchkC[MDEV_GPSMSGCHKC_MAX];     /* Ignore -> MISRA-C:2004 Rule 8.12 */
282 extern const TG_GPS_TIMEVTCHNG    kGpsTimchkC[MDEV_PSTIMCHKC_MAX];      /* Ignore -> MISRA-C:2004 Rule 8.12 */
283 extern const TG_GPS_JMP_TBL       kGpsMatxC[GPS_STS_NUM][GPS_EVT_NUM];
284
285 #define MDEV_GPSCMDANATBLNMEA_MAX 20
286 extern const TG_GPS_CMD_ANA_TBL*  kGpsCmdAnaTbl;
287 extern const TG_GPS_CMD_ANA_TBL   kGpsCmdAnaTblUblox[MDEV_GPSCMDANATBLNMEA_MAX];
288
289 extern TG_GPS_SAVEBUF             g_gps_save_cmdr;
290 extern TG_GPS_MSGRCV              g_gps_msg_rcvr;
291 extern TG_GPS_MNG                 g_gps_mngr;
292
293 extern u_int16                    g_wsend_err;        /* Number of transmission errors          */
294 extern u_int16                    g_wcnct_err;        /* Number of connection errors          */
295 extern TG_GPS_OUTPUT_FORMAT       g_rcv_format;       /* Receive Format          */
296
297 /*---------------------------------------------------------------------------*/
298 // Prototype
299
300 EFrameworkunifiedStatus  DevGpsMainThread(HANDLE h_app);
301 BOOL        DevGpsInit(void);
302 void        DevGpsRcvMsg(void);
303 void        DevGpsMsgEventCheck(void);
304 void        DevGpsTimEventCheck(void);
305 void        DevGpsGpsVersionCheck(void);
306
307 /*---------------------------------------------------------------------------*/
308 #endif  // INC_GPSCOMMON_MDEV_GPS_MAIN_H_
309
310 /*---------------------------------------------------------------------------*/
311 /*EOF*/