Init basesystem source codes.
[staging/basesystem.git] / positioning_hal / inc / GpsCommon / MDev_GpsRecv.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_GpsRecv.h
18 */
19
20 #ifndef INC_GPSCOMMON_MDEV_GPSRECV_H_
21 #define INC_GPSCOMMON_MDEV_GPSRECV_H_
22
23 /*---------------------------------------------------------------------------*/
24 // Include files
25
26 #include "gps_hal.h"
27 #include "positioning_def.h"
28
29 /*---------------------------------------------------------------------------*/
30 // Define
31
32 /* ++ GPS _CWORD82_ support */
33 #define GPS__CWORD82__CMD_LEN_MAX         200
34 /* -- GPS _CWORD82_ support */
35
36 /* ++ GPS _CWORD82_ support */
37 #define GPS__CWORD82__RET_START_SEQ_NONE  0       /* _CWORD82_ Start Sequence Determination Result = None   */
38 #define GPS__CWORD82__RET_START_SEQ_NMEA  1       /* _CWORD82_ Start Sequence Determination Result = NMEA  */
39 #define GPS__CWORD82__RET_START_SEQ_FULL  2       /* _CWORD82_ Start Sequence Determination Result = Full customization */
40 #define GPS__CWORD82__RET_START_SEQ_BIN   3       /* _CWORD82_ Start Sequence Determination Result = Standard binary  #GPF_60_024 */
41
42 #define GPS_UBLOX_RET_START_SEQ_UBX 4       /* Ublox Start Sequence Decision Result = UBX Protocol (binary) */
43 #define GPS__CWORD82__FULLBINARY_LEN      GPS_CMD_FULLBIN_SZ  /* _CWORD82_ Full Customization Instruction Length     */
44
45 #define GPS__CWORD82__NORMALBINARY_LEN    81      /* _CWORD82_ standard binary instruction length       #GPF_60_024 */
46 /* -- GPS _CWORD82_ support */
47
48 /* Maximum size of serial data read */
49 #define GPS_RCV_MAXREADSIZE         (2048)  /* Changed from 256 -> 2048   #01 */
50
51 /* Receive data storage buffer size */
52 #define GPS_RCV_RCVBUFSIZE          512     /* Maximum size of the command to be received must be larger than the maximum size */
53
54 /* Max-size receive commands ID4:(188+8)byte */
55 /* Analysis data buffer size */
56 #define GPS_RCV_ANADATABUFSIZE      (GPS_RCV_MAXREADSIZE + GPS_RCV_RCVBUFSIZE)
57
58 /* Receive frame buffer size */
59 #define GPS_RCV_RCVFRAMEBUFSIZE     GPS_RCV_RCVBUFSIZE  /* Maximum size of the command to be received must be larger than the maximum size */
60
61 /* Reception notification data buffer size */
62 #define GPS_RCV_SNDCMD_SIZE_MAX
63
64 /* Common return values */
65 #define GPS_RCV_RET_ERR_EXT         (-4)    /* External cause error */
66 #define GPS_RCV_RET_ERR_SYSTEM      (-3)    /* System error */
67 #define GPS_RCV_RET_ERR             (-1)    /* Abnormality */
68 #define GPS_RCV_RET_NML             0       /* Normal */
69
70 // Reception thread reception frame detection result
71 #define GPS_RCV_FRMSRCH_ERR_FORMAT  (-1)    /* Frame format error */
72 #define GPS_RCV_FRMSRCH_FIXED       0       /* Frame determination   */
73 #define GPS_RCV_FRMSRCH_NOT_FIXED   1       /* Frame undetermined */
74 #define GPS_RCV_FRMSRCH_NO_DATA     2       /* No analysis data */
75
76 // Result of receive thread receive frame analysis
77 #define GPS_RCV_FRMANA_ERR_PRM      (-3)    /* Parameter error   */
78 #define GPS_RCV_FRMANA_ERR_FORMAT   (-2)    /* Frame format error */
79 #define GPS_RCV_FRMANA_ERR_CS       (-1)    /* Sumcheck error  */
80 #define GPS_RCV_FRMANA_OK           0       /* Normal data    */
81
82 /* Serial reception event determination result */
83 enum GpsRcvRet {
84   GPS_RCV_REVT_NML = 0,   /* Receiving(Normal)       */
85   GPS_RCV_REVT_ERR,       /* Receiving(Error)       */
86   GPS_RCV_REVT_NUM        /* Number of events received      */
87 };
88
89 // Error logging
90 #define ERLG_SER_FRAMEERR     "Serial Framing Error"
91 #define ERLG_SER_OVERRUNERR   "Serial Overrun Error"
92 #define ERLG_SER_PARITYERR    "Serial Parity Error"
93 #define ERLG_RCVEV_JDGERR     "DEV_Gps_Recv_JdgSerEvt error"
94 #define ERLG_RCVDATA_SNDERR   "DEV_Gps_Recv_SndRcvData error"
95 #define ERLG_COMEVNT_WAITERR  "WaitCommEvent error"
96
97 /*---------------------------------------------------------------------------*/
98 // Struct
99
100 // Serial receive buffer structure
101 typedef struct GPSRecvData {
102   u_int16   us_read_size;                       /* Serial data read data size */
103   u_int8    uc_reserve[2];                      /* Preliminary */
104   u_int8    uc_read_data[GPS_RCV_MAXREADSIZE];  /* Serial read data */
105 } TG_GPS_RECV_RcvData;
106
107 // Receive data storage buffer structure
108 typedef struct GPSRecvBuf {
109   u_int16   r_size;                             /* Received size */
110   u_int8    rsv[2];                             /* Reserved */
111   u_int8    r_buf[GPS_RCV_RCVBUFSIZE];          /* Receive command data */
112 } TG_GPS_RECV_RcvBuf;
113
114 // Data analysis buffer
115 typedef struct GPSRecvAnaDataBuf {
116   u_int16   datsize;                            /* Size of the data */
117   u_int16   offset;                             /* Analysis start offset */
118   u_int8    datbuf[GPS_RCV_ANADATABUFSIZE];     /* Analysis data */
119 } TG_GPS_RECV_AnaDataBuf;
120
121 // Receive frame buffer
122 typedef struct GPSRecvFrameBuf {
123   u_int16   size;                               /* Frame-size */
124   u_int8    rsv[2];                             /* Reserved */
125   u_int8    buf[GPS_RCV_RCVFRAMEBUFSIZE];       /* Command data */
126 } TG_GPS_RECV_RcvFrameBuf;
127
128 /*---------------------------------------------------------------------------*/
129 // External variable
130
131 extern TG_GPS_RECV_RcvData      g_gps_rcvdata;      /* Serial receive buffer */
132 extern TG_GPS_RECV_RcvBuf       g_gps_rcvbuf;       /* Receive data storage buffer */
133 extern TG_GPS_RECV_AnaDataBuf   g_gps_ana_databuf;  /* Analysis data buffer */
134 extern TG_GPS_RECV_RcvFrameBuf  g_gps_rcv_framebuf; /* Receive frame buffer */
135 extern u_int16                  g_wrecv_err;        /* Number of reception errors */
136
137 /*---------------------------------------------------------------------------*/
138 // Prototype
139
140 /* Initializing process     */
141 void        DevGpsRecvInit(void);
142
143 /* Buffer clear processing   */
144 void        DevGpsRecvClrRcvBuf(void);
145
146 /* Receive (normal) receive processing   */
147 void        DevGpsRecvRcvNormal(void);
148
149 /* Data reception processing */
150 int32       DevGpsRecvReadRcvData(TG_GPS_RECV_RcvData* pst_rcv_data);
151
152 /* Frame detection processing   */
153 int32       DevGpsRecvSearchFrameData(const TG_GPS_RECV_AnaDataBuf *adbuf_p, u_int16 *ana_size);
154
155 /* Receive data transmission processing */
156 void        DevGpsRecvSndRcvData(const TG_GPS_RECV_RcvFrameBuf *p_frame_buf);
157
158 /* Acknowledgement      */
159 RET_API     DevRcvData(const TG_GPS_RCV_DATA* ptg_rcv_data);
160
161 /* Pos_Gps_Recv Thread Stop Processing */
162 void        DevGpsRecvThreadStopProcess(void);
163
164 EFrameworkunifiedStatus  DevGpsRecvThread(HANDLE h_app);
165
166 /*---------------------------------------------------------------------------*/
167 #endif  // INC_GPSCOMMON_MDEV_GPSRECV_H_
168
169 /*---------------------------------------------------------------------------*/
170 /*EOF*/