Re-organized sub-directory by category
[staging/basesystem.git] / hal / positioning_hal / inc / GpsCommon / MDev_Gps_Common.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_Common.h
18 */
19
20 #ifndef  INC_GPSCOMMON_MDEV_GPS_COMMON_H_
21 #define  INC_GPSCOMMON_MDEV_GPS_COMMON_H_
22
23 /*---------------------------------------------------------------------------*/
24 // Include files
25
26 #include "positioning_def.h"
27 #include "MDev_Gps_Main.h"
28
29 /*---------------------------------------------------------------------------*/
30 // Define
31
32 #define NMEA_CHECKSUM_CHAR            '*'    /* *## (HEX) */
33 #define NMEA_DATA_SEPARATOR           ','
34
35 #define GPS_NMEA_FIELD_LEN_MAX        (GPS_NMEA_MAX_SZ)
36
37 // NMEA GGA Sentence
38 /* Fix Status */
39 #define GPS_NMEA_GGA_FIX_STATUS_NON   0 /* invalid */
40 #define GPS_NMEA_GGA_FIX_STATUS_GPS   1 /* GPS SPS Mode, Fix valid */
41 #define GPS_NMEA_GGA_FIX_STATUS_DGPS  2 /* DGPS SPS Mode, Fix valid */
42 #define GPS_NMEA_GGA_FIX_STATUS_DR    6 /* Estimated/Dead Reckoning */
43 /* Field No */
44 #define GPS_NMEA_FNO_GGA_FS           6
45 #define GPS_NMEA_FNO_GGA_MSL          9
46
47 /* number of SV Fields */
48 #define GPS_NMEA_NUM_GSA_SV           12
49 /* Fix Status */
50 #define GPS_NMEA_GSA_FIX_STS_NON      1
51 #define GPS_NMEA_GSA_FIX_STS_2D       2
52 #define GPS_NMEA_GSA_FIX_STS_3D       3
53 /* Field No */
54 #define GPS_NMEA_FNO_GSA_FS           2
55 #define GPS_NMEA_FNO_GSA_SV           3
56
57 /* number of Satellite Infomation Fields (sv+elv+az+cno) */
58 #define GPS_NMEA_NUM_GSV_SINFO        4
59     /* Field No */
60 #define GPS_NMEA_FNO_GSV_NOSV         3
61 #define GPS_NMEA_FNO_GSV_SV           4
62 #define GPS_NMEA_FNO_GSV_ELV          5
63 #define GPS_NMEA_FNO_GSV_AZ           6
64 #define GPS_NMEA_FNO_GSV_CNO          7
65
66 #define GPS_NMEA_RMC_STS_INVALID      'V'
67 #define GPS_NMEA_RMC_STS_VALID        'A'
68 #define GPS_NMEA_RMC_IND_NORTH        'N'
69 #define GPS_NMEA_RMC_IND_EAST         'E'
70
71 /* Field No */
72 #define GPS_NMEA_FNO_RMC_UTC          1
73 #define GPS_NMEA_FNO_RMC_STATUS       2
74 #define GPS_NMEA_FNO_RMC_LATITUDE     3
75 #define GPS_NMEA_FNO_RMC_NS           4
76 #define GPS_NMEA_FNO_RMC_LONGITUDE    5
77 #define GPS_NMEA_FNO_RMC_EW           6
78 #define GPS_NMEA_FNO_RMC_SPEED        7
79 #define GPS_NMEA_FNO_RMC_COG          8
80 #define GPS_NMEA_FNO_RMC_DATE         9
81
82 // Diag Fix Count
83 #define GPS_DIAG_FIX_COUNT_3D         (0x01)
84 #define GPS_DIAG_FIX_COUNT_2D         (0x02)
85 #define GPS_DIAG_FIX_COUNT_ELSE       (0x04)
86
87 /* GPS time setting related */
88 #define GPS_SETTIME_RANGE             5   /* 5 seconds : Valid range of GPS time setting */
89 #define GPS_TIME_RANGE                10  /* 10 seconds : GPS time change range */
90
91 /* NAV-SVINFO logging status */
92 #define GPS_NAVSVINFO_STS_INIT        0
93 #define GPS_NAVSVINFO_STS_READY       1
94 #define GPS_NAVSVINFO_STS_DONE        2
95 #define GPS_NAVSVINFO_STS_SETTING     3
96
97 /* Time setting information  */
98 #define GPS_TIME_RX                   0   /* Time not set */
99 #define GPS_TIME_ROLOVR               1   /* First GPS reception(for rollover) */
100 #define GPS_TIME_SET                  2   /* Time setting in progress */
101
102 /*!
103     @brief Satellite position information
104 */
105 typedef struct GpsSatelliteInfoStr {
106   uint8_t  sv;                    /* Satellite number       */
107   uint8_t  elv;                   /* Height 0-99      */
108   uint16_t az;                    /* Orientation 0-359     */
109   uint8_t  cno;                   /* Signal strength       */
110   uint8_t  sts;                   /* Reception status */
111 } GpsSatelliteInfo;
112
113 /*---------------------------------------------------------------------------*/
114 // Global values
115
116 extern BOOL g_gps_rcv_thread_stop;
117 extern uint8_t g_is_gpstime_sts;
118
119 /*---------------------------------------------------------------------------*/
120 // Prototype
121
122 void                ChangeStatusGpsCommon(u_int32 sts);
123 void                RtyResetGpsCommon(void);
124 void                SendRtyResetGpsCommon(void);
125 void                SendReqGpsCommon(void);
126 void                GPSResetReqGpsCommon(void);
127 void                CyclDataTimeOutGpsCommon(void);
128 RET_API             CheckFrontStringPartGpsCommon(const u_char *p_tartget, const u_char *p_start);
129 int32               JudgeFormatGpsCommon(u_char *p_send_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format);
130 RET_API             CheckSumGpsCommon(const u_int8 p_uc_data[], u_int32 ul_length, TG_GPS_OUTPUT_FORMAT e_cmd_info);
131 u_int8              AtoHGpsCommon(u_int8 ascii);
132 RET_API             DevGpsSaveCmd(TG_GPS_SAVECMD *p_send_data);
133 void                SendSaveCmdGpsCommon(void);
134 void                DeleteSaveCmdGpsCommon(void);
135 void                DeleteAllSaveCmdGpsCommon(void);
136 void                RcvCyclCmdNmeaGpsCommon(u_int8 *p_uc_data, u_int32 ul_len, TG_GPS_OUTPUT_FORMAT s_output_format);
137 int32               CheckSendCmdGpsCommon(const u_char *p_rcv_data, u_int32 ul_length, TG_GPS_OUTPUT_FORMAT *p_format);
138 int32_t             GetStringFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, char* p_dst, size_t size);
139 double              GetNumericFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
140 int32               GetIntegerFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src);
141 int32               GetLonLatFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
142 u_int16             GetHeadingFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
143 int32               GetAltitudeFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
144 u_int16             GetSpeedFromNmeaGpsCommon(u_int8 field_number, u_int8 *p_src, BOOL *p_valid);
145 void                StopThreadGpsCommon(void);
146 uint8_t             JudgeFormatOrderGpsCommon(TG_GPS_OUTPUT_FORMAT s_format_1, TG_GPS_OUTPUT_FORMAT s_format_2);
147 ENUM_GPS_NMEA_INDEX GetNmeaIdxGpsCommon(TG_GPS_OUTPUT_FORMAT s_output_format);
148 void                SendResetReqGpsCommon(void);
149
150
151 void                WriteGpsTimeToBackup(uint8_t flag, POS_DATETIME* pst_datetime);
152 void                DevGpsCommSettingTime(void);
153 RET_API             GpsSetPosBaseEvent(uint16_t snd_pno, int32_t event_val);
154 uint8_t             HardResetChkGpsCommon(void);
155 void                RcvCyclCmdExtGpsCommon(u_int8 *p_data, u_int32 len, TG_GPS_OUTPUT_FORMAT format);
156
157 BOOL                DevGpsRcvProcGpsResetResp(TG_GPS_RCV_DATA*);
158 void                DevGpsRcvProcTimeSetResp(TG_GPS_RCV_DATA*);
159 void                DevGpsRcvProcWknRolloverGetResp(TG_GPS_RCV_DATA* p_data);
160 void                DevGpsRcvProcNavSvinfoAddResp(TG_GPS_RCV_DATA* p_data);
161 void                DevGpsReadGpsTime(POS_DATETIME* p_st_datetime);
162 RET_API             DevGpsRcvProcCmnResp(TG_GPS_RCV_DATA* p_data, uint8_t cmd);
163 RET_API             DevGpsResetReq(PNO us_pno, RID uc_rid);
164 void                DevGpsSettingTime(POS_DATETIME* p_st_datetime);
165 int                 DevGpsYMD2JD(int y, int m, int d);
166 BOOL                DevGpsYMD2GPSTIME(const int32 y, const int32 m, const int32 d,
167                                         const int32 hh, const int32 mm, const int32 ss,
168                                         u_int16* gpsw, u_int32* gpsws);
169 void                DevGpsSetChkSum(u_int8* uc_buffer, u_int32 ul_length);
170 RET_API             DevGpsCatPollReq(uint8_t *p_ublox_data, uint16_t kind);
171 void                DevGpsSetGpsweekcorcnt(void);
172 RET_API             DevGpsNavTimeUTCAddReq(void);
173 RET_API             DevGpsWknRolloverGetReq(void);
174 BOOL                DevGpsCheckGpsTime(uint16_t set_gpsw, uint32_t set_gpsws,
175                               uint16_t rcv_gpsw, uint32_t rcv_gpsws, int32_t offset_range);
176
177 void                DevGpsCnvLonLatNavi(SENSORLOCATION_LONLATINFO_DAT* p_lonlat,
178                                                   u_int8 fix_sts, int32 lon, int32 lat);
179 void                DevGpsCnvAltitudeNavi(SENSORLOCATION_ALTITUDEINFO_DAT* p_altitude,
180                                                   u_int8 fix_sts, int32 alt);
181 void                DevGpsCnvHeadingNavi(SENSORMOTION_HEADINGINFO_DAT* p_heading,
182                                                   u_int8 fix_sts, u_int16 heading);
183 /*---------------------------------------------------------------------------*/
184 #endif  // INC_GPSCOMMON_MDEV_GPS_COMMON_H_
185
186 /*---------------------------------------------------------------------------*/
187 /*EOF*/