Init basesystem source codes.
[staging/basesystem.git] / positioning_hal / src / GpsCommon / MDev_GpsRecv.cpp
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.cpp
18 */
19
20 /*---------------------------------------------------------------------------*/
21 // Include files
22
23 #include "MDev_GpsRecv.h"
24 #include "MDev_Gps_Common.h"
25 #include "positioning_common.h"
26 #include "MDev_Gps_API.h"
27 //extern "C" {
28 //#include <stub/gps_mng_api.h>
29 //}
30
31 /*---------------------------------------------------------------------------*/
32 // Global values
33
34 #define FTEN_DRIVER   0
35 #define TEST_HAL2
36
37 #if FTEN_DRIVER
38 static GpsMngApiObj g_gps_mng_obj;
39 #endif
40
41 /*---------------------------------------------------------------------------*/
42 // Functions
43
44 /*******************************************************************************
45  * MODULE   : DEV_Gps_RecvThread
46  * ABSTRACT : GPS communication management reception thread
47  * FUNCTION : GPS communication management reception thread main
48  * ARGUMENT : PVOID     pv....Thread creation arguments
49  * NOTE     : -
50  * RETURN   : TRUE
51  ******************************************************************************/
52 EFrameworkunifiedStatus DevGpsRecvThread(HANDLE h_app) {
53   int32 ret               = GPS_RCV_RET_NML;
54   int32 gps_ret            = 0;
55   BOOL* p_thread_stop_req = &g_gps_rcv_thread_stop;
56
57   (void)PosSetupThread(h_app, ETID_POS_GPS_RECV);
58
59   /* Initializing process */
60   DevGpsRecvInit();
61
62 #if FTEN_DRIVER
63   gps_ret = GpsMngApiOpen(&g_gps_mng_obj);
64   if (gps_ret != GPS_CTL_RET_SUCCESS) {
65     printf("[For test] GpsMngApiOpen open failed\n");
66   }
67 #endif
68
69   while (1) {
70     /* Thread stop request is received */
71     if (TRUE == *p_thread_stop_req) {
72       /* Thread stop processing */
73       DevGpsRecvThreadStopProcess();
74     }
75
76     ret = DevGpsRecvReadRcvData(&g_gps_rcvdata);
77
78     if (GPS_RCV_RET_NML == ret) {
79       /* For reception (normal) */
80       DevGpsRecvRcvNormal();
81     }
82   }
83
84   return eFrameworkunifiedStatusOK;
85 }
86
87 /*******************************************************************************
88  * MODULE   : DEV_Gps_Recv_Init
89  * ABSTRACT : Receive thread initialization processing
90  * FUNCTION : Initialize the receive thread
91  * ARGUMENT : -
92  * NOTE     : -
93  * RETURN   : -
94  ******************************************************************************/
95 void DevGpsRecvInit(void) {
96   /* Clears the receive buffer */
97   DevGpsRecvClrRcvBuf();
98
99   /* Clear receive error count */
100   g_wrecv_err = 0;
101
102   return;
103 }
104
105 /*******************************************************************************
106  * MODULE   : DEV_Gps_Recv_ClrRcvBuf
107  * ABSTRACT : Buffer clear processing
108  * FUNCTION : Clears the receive buffer for serial reception.
109  * ARGUMENT : -
110  * NOTE     : -
111  * RETURN   : -
112  ******************************************************************************/
113 void  DevGpsRecvClrRcvBuf(void) {
114   /*-----------------------------------------------------------------------*/
115   /* Clear serial receive data storage buffer                                  */
116   /*-----------------------------------------------------------------------*/
117   memset(&g_gps_rcvdata, 0, sizeof(TG_GPS_RECV_RcvData));
118
119   /*-----------------------------------------------------------------------*/
120   /* Clear receive data storage buffer                                          */
121   /*-----------------------------------------------------------------------*/
122   memset(&g_gps_rcvbuf, 0, sizeof(TG_GPS_RECV_RcvBuf));
123
124   /*-----------------------------------------------------------------------*/
125   /* Clear analysis data buffer                                              */
126   /*-----------------------------------------------------------------------*/
127   memset(&g_gps_ana_databuf, 0, sizeof(TG_GPS_RECV_AnaDataBuf));
128
129   /*-----------------------------------------------------------------------*/
130   /* Clear receive frame buffer                                            */
131   /*-----------------------------------------------------------------------*/
132   memset(&g_gps_rcv_framebuf, 0, sizeof(TG_GPS_RECV_RcvFrameBuf));
133 }
134
135 /*******************************************************************************
136  * MODULE   : DevGpsRecvJudgeStartSeqence
137  * ABSTRACT : Start sequence determination process
138  * FUNCTION : Determine whether or not the beginning of the data is the start sequence of the _CWORD82_ command
139  * ARGUMENT : const u_char *buf_p   ... Pointer to analysis data
140  *            u_int16  ana_size ... Size of data to be analyzed
141  * NOTE     :
142  * RETURN   : GPS__CWORD82__RET_START_SEQ_NONE ... No start sequence
143  *            GPS__CWORD82__RET_START_SEQ_NMEA ... NMEA Start Sequences
144  *            GPS__CWORD82__RET_START_SEQ_FULL ... Full Customization Start Sequence
145  ******************************************************************************/
146 static int32 DevGpsRecvJudgeStartSeqence(const u_char *buf_p, u_int16 ana_size) {
147   int32 ret = GPS__CWORD82__RET_START_SEQ_NONE;
148
149   if ((ana_size >= 1) && (buf_p[0] == 0x24u)) {
150     /* Ignore -> No applicable rules for MISRA-C */ /* 0x24: '$' QAC 285 */
151     ret = GPS__CWORD82__RET_START_SEQ_NMEA;
152   } else if ((ana_size >= 1) && (buf_p[0] == 0xB0)) {
153     ret = GPS__CWORD82__RET_START_SEQ_FULL;
154   } else if ((ana_size >= 1) && (buf_p[0] == 0xC6)) {
155     /* #GPF_60_024 */
156     ret = GPS__CWORD82__RET_START_SEQ_BIN;
157   } else if ((ana_size >= 1) && (buf_p[0] == 0xB5)) {
158     /* #GPF_60_024 */
159     ret = GPS_UBLOX_RET_START_SEQ_UBX;
160   } else {
161     ret = GPS__CWORD82__RET_START_SEQ_NONE;
162   }
163
164   return ret;
165 }
166
167 /*******************************************************************************
168  * MODULE   : DEV_Gps_Recv_SearchFrameData
169  * ABSTRACT : Frame detection processing
170  * FUNCTION : Find if a frame exists in the data
171  * ARGUMENT : TG_GPS_RECV_AnaDataBuf *adbuf_p ... Pointer to the analysis data storage buffer
172  *            u_int16 *ana_size; ... Analysis completion data size
173  * NOTE     : Since it is assumed that the beginning of the frame is stored in the analysis start offset,
174  *            when the beginning of the frame is detected in the middle of the buffer,
175  *            the processing is terminated with the data up to that point as abnormal format data.
176  * RETURN   : GPS_RCV_FRMSRCH_ERR_FORMAT ... Frame format error
177  *            GPS_RCV_FRMSRCH_FIXED      ... Frame determination
178  *            GPS_RCV_FRMSRCH_NOT_FIXED  ... Frame undetermined
179  *            GPS_RCV_FRMSRCH_NO_DATA    ... No analysis data
180  ******************************************************************************/
181 int32 DevGpsRecvSearchFrameData(const TG_GPS_RECV_AnaDataBuf *adbuf_p, u_int16 *ana_size) {
182   int32   ret = GPS_RCV_FRMSRCH_ERR_FORMAT;          /* Return value(Frame format error) */
183   /* ++ GPS _CWORD82_ support */
184   int32   start_seq_type = GPS__CWORD82__RET_START_SEQ_NONE; /* Fully customized or NMEA */
185   /* -- GPS _CWORD82_ support */
186   u_int16 start_offset = 0;                           /* Analysis start offset */
187   u_int16 i = 0;
188   u_int16 d_size = 0;                                 /* Unanalyzed data size */
189
190   /* Offset Initialization */
191   start_offset = adbuf_p->offset;  /* Start of analysis */ /* Ignore -> No applicable rules for MISRA-C */
192
193   /* Setting of unanalyzed data size */
194   d_size = adbuf_p->datsize - start_offset;
195
196   /* For size 0 */
197   if (d_size == 0) {
198     /* No analysis data */
199     ret = GPS_RCV_FRMSRCH_NO_DATA;
200     /* Set the analysis completion size to 0. */
201     *ana_size = 0; /* Ignore -> No applicable rules for MISRA-C */
202   } else {
203     /* Since it is assumed that beginning of the frame is stored in the analysis start offset,         */
204     /* determine if the start sequence is the first one. */
205
206     /* ++ GPS _CWORD82_ support */
207     start_seq_type = DevGpsRecvJudgeStartSeqence(&(adbuf_p->datbuf[start_offset]), d_size);
208
209     if (start_seq_type != GPS__CWORD82__RET_START_SEQ_NONE) {
210       /* -- GPS _CWORD82_ support */
211       /* Set the frame as undetermined */
212       ret = GPS_RCV_FRMSRCH_NOT_FIXED;
213
214       /* ++ GPS _CWORD82_ support */
215       /* Find end sequence */
216       if (start_seq_type == GPS__CWORD82__RET_START_SEQ_NMEA) {
217         for (i = 0; i < d_size; i++) {
218           if (adbuf_p->datbuf[(start_offset + i)] == 0x0A) {
219             /* If the end sequence is found, */
220             /* end as frame fix. */
221             ret = GPS_RCV_FRMSRCH_FIXED;
222
223           /* Set the frame size for the analysis completion size. */
224           *ana_size = i + 1;
225
226           break;
227           }
228         }
229
230         if (i == d_size) {
231           if (i >= GPS__CWORD82__CMD_LEN_MAX) {
232             /* If no end sequence is found, */
233             /* frame format error. */
234             ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
235             /* After that, searching for start sequence. */
236           } else {
237             /* Because the end sequence cannot be analyzed, */
238             /* frame undetermined. */
239             ret = GPS_RCV_FRMSRCH_NOT_FIXED;
240
241             /* Set the size of unanalyzed data for the analysis completion size. */
242             *ana_size = d_size;
243           }
244         }
245       } else if (start_seq_type == GPS__CWORD82__RET_START_SEQ_FULL) {
246         /* #GPF_60_024 */
247         /* Is there one frame of data for full customization information? */
248         if (d_size >= GPS__CWORD82__FULLBINARY_LEN) {
249           /* Is there an end sequence? */
250           if (adbuf_p->datbuf[( (start_offset + GPS__CWORD82__FULLBINARY_LEN) - 1)] == 0xDA) {
251             /* Ignore -> MISRA-C:2004 Rule 12.1 */
252             /* If an end sequence is found, */
253             /* end as frame fix. */
254             ret = GPS_RCV_FRMSRCH_FIXED;
255
256             /* Set the frame size for the analysis completion size. */
257             *ana_size = GPS__CWORD82__FULLBINARY_LEN;
258           } else {
259             /* If it is not an end sequence, */
260             /* frame format error. */
261             ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
262             /* Searching for Start Sequence */
263           }
264         } else {
265           /* Because the end sequence cannot be analyzed, */
266           /* frame undetermined. */
267           ret = GPS_RCV_FRMSRCH_NOT_FIXED;
268
269           /* Set the size of unanalyzed data for the analysis completion size. */
270           *ana_size = d_size;
271         }
272       } else if (start_seq_type == GPS__CWORD82__RET_START_SEQ_BIN) {
273         /* Is there data for one standard binary frame? */
274         if (d_size >= GPS__CWORD82__NORMALBINARY_LEN) {
275           /* Is there an end sequence? */
276           if (adbuf_p->datbuf[((start_offset + GPS__CWORD82__NORMALBINARY_LEN) - 1)] == 0xDA) {
277             /* Ignore -> MISRA-C:2004 Rule 12.1 */
278             /* If an end sequence is found, */
279             /* end as frame fix. */
280             ret = GPS_RCV_FRMSRCH_FIXED;
281
282             /* Set the frame size for the analysis completion size. */
283             *ana_size = GPS__CWORD82__NORMALBINARY_LEN;
284           } else {
285             /* If it is not an end sequence, */
286             /* frame format error. */
287             ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
288             /* Searching for Start Sequence */
289           }
290         } else {
291           /* Because the end sequence cannot be analyzed, */
292           /* frame undetermined. */
293           ret = GPS_RCV_FRMSRCH_NOT_FIXED;
294
295           /* Set the size of unanalyzed data for the analysis completion size. */
296           *ana_size = d_size;
297         }
298       } else if (start_seq_type == GPS_UBLOX_RET_START_SEQ_UBX) {
299         /* TODO Checksum calculation using data from start_offset to d_size */
300         /* TODO Check that the checksum is correct. (See test code.) */
301         /* If the if checksums match, */
302         /* end as frame fix. */
303         ret = GPS_RCV_FRMSRCH_FIXED;
304
305         /* Set the frame size for the analysis completion size. */
306         *ana_size = d_size;
307         } else {
308       }
309     /* -- #GPF_60_024 */
310     } else {
311       /* It is not a start sequence, so it is regarded as a frame format error. */
312       ret = GPS_RCV_FRMSRCH_ERR_FORMAT;
313
314       /* After that, searching for Start Sequence. */
315     }
316
317     /* If the frame format is abnormal, search for the start sequence. */
318     if (ret == GPS_RCV_FRMSRCH_ERR_FORMAT) {
319       POSITIONING_LOG("FORMAT ERROR [start_seq_type:%d]\n", start_seq_type);
320
321       /* Assuming that the start sequence has not been found until the end, */
322       /* the size of the analysis completed is set as the size of the unanalyzed data.  */
323       *ana_size = d_size;
324
325       /* ++ GPS _CWORD82_ support (Search from the second byte for safety (at least the first byte is checked at the beginning of the function)))*/
326       for (i = start_offset + 1; i < (u_int32)(start_offset + d_size); i++) {
327         /* for( i = (start_offset + 2); i < (u_int32)(start_offset + d_size); i++ ) */
328         /* -- GPS _CWORD82_ support */
329         /* Start Sequence? */
330         /* ++ GPS _CWORD82_ support */
331         if (DevGpsRecvJudgeStartSeqence(&(adbuf_p->datbuf[i]), d_size) != GPS__CWORD82__RET_START_SEQ_NONE) {
332           /* if( (adbuf_p->datbuf[(i-1)] == GPS_CODE_START_SQ_HI) && */
333           /*  (adbuf_p->datbuf[i] == GPS_CODE_START_SQ_LOW) ) */
334           /* -- GPS _CWORD82_ support */
335           /* In the case of a start sequence, the analysis is completed before that. #01 */
336           *ana_size = (i - start_offset - 1);
337
338           break;
339         }
340       }
341     }
342   }
343
344   return ret;
345 }
346
347 /*******************************************************************************
348  * MODULE : DEV_Gps_Recv_ReadRcvData
349  * ABSTRACT : Data reception processing
350  * FUNCTION : Read serial data
351  * ARGUMENT : TG_GPS_RECV_RcvData* pst_rcv_data : Receive data read buffer
352  * NOTE  : -
353  * RETURN : T_ErrCodes Error code
354  *    MCSUB_NML   Normal
355  *    MCCOM_ERR_SYSTEM Abnormality
356  ******************************************************************************/
357 int32 DevGpsRecvReadRcvData(TG_GPS_RECV_RcvData* pst_rcv_data) {
358   int32 ret = GPS_RCV_RET_ERR;
359   INT32 gps_ret = 0;
360
361 #if FTEN_DRIVER
362   static int msg_kind = GPS_RCV_NMEA_GGA;
363
364   // Serial data capture
365   GpsMngApiDat gps_mng_data;
366
367   memset(&gps_mng_data, 0, sizeof(gps_mng_data));
368 #ifdef TEST_HAL2
369   if (msg_kind > GPS_RCV_NMEA_RMC) {
370     msg_kind = GPS_RCV_NMEA_GGA;
371   }
372 #else
373   if (msg_kind == GPS_RCV_NMEA_GGA) {
374     msg_kind = GPS_RCV_NMEA_RMC;
375   } else if (msg_kind == GPS_RCV_NMEA_RMC) {
376     msg_kind = GPS_RCV_NMEA_GGA;
377   } else {
378     msg_kind = GPS_RCV_NMEA_GGA;
379   }
380 #endif
381
382   gps_ret = GpsMngApiGetRcvMsg(&g_gps_mng_obj, msg_kind, &gps_mng_data);
383
384 #ifdef TEST_HAL2
385     msg_kind++;
386 #endif
387
388   pst_rcv_data->us_read_size = (u_int16)gps_mng_data.dataLength;
389
390   if (pst_rcv_data->us_read_size >= GPS_RCV_MAXREADSIZE) {
391     return GPS_RCV_RET_ERR_SYSTEM;
392   }
393
394   memcpy(pst_rcv_data->uc_read_data, gps_mng_data.data, pst_rcv_data->us_read_size);
395
396   // Add '\0'
397   pst_rcv_data->uc_read_data[pst_rcv_data->us_read_size] = '\0';
398
399   if (GPS_CTL_RET_SUCCESS != gps_ret) {
400     ret = GPS_RCV_RET_ERR_SYSTEM;
401   } else {
402     ret = GPS_RCV_RET_NML;
403   }
404 #endif
405
406   return ret;
407 }
408
409 /*******************************************************************************
410  * MODULE : DEV_Gps_Recv_RcvNormal
411  * ABSTRACT : Receive (normal) Receive processing
412  * FUNCTION : Receive (normal) Processing at event reception
413  * ARGUMENT : -
414  * NOTE  :
415  * RETURN : -
416  ******************************************************************************/
417 void DevGpsRecvRcvNormal(void) {
418   TG_GPS_RECV_RcvData*      pst_rcv_data = NULL;        /* Buffer for reading serial data */
419   TG_GPS_RECV_RcvBuf*       pst_rcv_buf = NULL;         /* Receive data storage buffer */
420   TG_GPS_RECV_AnaDataBuf*   pst_ana_data_buf = NULL;    /* Analysis data storage buffer */
421   TG_GPS_RECV_RcvFrameBuf*  pst_rcv_frame_buf = NULL;   /* Receive frame buffer */
422   int32                     i_ret = 0;                  /* Frame Detection Result */
423   u_int16                   ana_size = 0;               /* Data analysis size storage */
424
425   /* Initializing process */
426   pst_ana_data_buf = &g_gps_ana_databuf;
427
428   /* Fast _CWORD71_ processing(memset fix) */
429   /* Initializes the offset that needs initialization in the receive data storage buffer. */
430   pst_ana_data_buf->offset = 0;
431
432   /* Serial continuous reception data analysis processing */
433   pst_rcv_data = &g_gps_rcvdata;
434   pst_rcv_buf = &g_gps_rcvbuf;
435   memcpy(&(pst_ana_data_buf->datbuf[0]), &(pst_rcv_buf->r_buf[0]), pst_rcv_buf->r_size);
436   memcpy(&(pst_ana_data_buf->datbuf[pst_rcv_buf->r_size]),
437          &(pst_rcv_data->uc_read_data[0]),
438          pst_rcv_data->us_read_size);
439
440   pst_ana_data_buf->datsize = pst_rcv_buf->r_size + pst_rcv_data->us_read_size;
441
442   /* Serial receive data analysis process */
443   do {
444     /* Frame detection processing */
445     i_ret = DevGpsRecvSearchFrameData(pst_ana_data_buf, &ana_size);
446
447     /* For frame determination */
448     if (i_ret == GPS_RCV_FRMSRCH_FIXED) {
449       /* Frames are stored in the receive frame buffer. */
450       pst_rcv_frame_buf = &g_gps_rcv_framebuf;
451       memset(pst_rcv_frame_buf, 0, sizeof(TG_GPS_RECV_RcvFrameBuf)); /* Ignore -> No applicable rules for MISRA-C */
452       /* Ignore -> No applicable rules for MISRA-C */ /* QAC 3200 */
453       memcpy(& (pst_rcv_frame_buf->buf[0]),
454              &(pst_ana_data_buf->datbuf[pst_ana_data_buf->offset]),
455              ana_size);
456       pst_rcv_frame_buf->size = ana_size;
457
458       /* Reception of the command */
459       /* Send receipt notice (command) to main thread */
460       /* Send Received Data to Main Thread */
461       DevGpsRecvSndRcvData(pst_rcv_frame_buf);
462     } else if (i_ret == GPS_RCV_FRMSRCH_NOT_FIXED) {
463       /* Store unconfirmed data in the received data storage buffer, */
464       /* and leave no unanalyzed data.                       */
465       memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf)); /* Ignore -> No applicable rules for MISRA-C */
466       memcpy(& (pst_rcv_buf->r_buf[0]),
467              &(pst_ana_data_buf->datbuf[pst_ana_data_buf->offset]),
468              ana_size);
469       pst_rcv_buf->r_size = ana_size;
470       i_ret = GPS_RCV_FRMSRCH_NO_DATA;
471     } else if (i_ret == GPS_RCV_FRMSRCH_ERR_FORMAT) {
472       /* [Measures against resetting with 1S + _CWORD82_]From here */
473       /* Clears the unanalyzed data stored in the receive data storage buffer, */
474       /* and flag is set to "No Unparsed Data" so that data can be parsed from the beginning of the next. */
475       memset(&(pst_rcv_buf->r_buf[0]), 0, pst_rcv_buf->r_size);
476       pst_rcv_buf->r_size = 0;
477       i_ret = GPS_RCV_FRMSRCH_NO_DATA;
478       /* [Measures against resetting with 1S + _CWORD82_]Up to this point */
479       /* Since this section discards garbage data, */
480       /* not subject to diagnosis registration.     */
481       /* Diagnosis registration check */
482     } else if (i_ret == GPS_RCV_FRMSRCH_NO_DATA) {
483       /* Ignore -> No applicable rules for MISRA-C */
484       memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf));
485       /* Termination */
486     } else {
487       /* No unanalyzed data is assumed because it is impossible. */
488       i_ret = GPS_RCV_FRMSRCH_NO_DATA;
489
490       /* Ignore -> No applicable rules for MISRA-C */
491       memset(pst_rcv_buf, 0, sizeof(TG_GPS_RECV_RcvBuf));
492     }
493
494     /* Update analysis data offset */
495     pst_ana_data_buf->offset += ana_size;
496
497     /* Repeat until no unanalyzed data is found. */
498   } while (i_ret != GPS_RCV_FRMSRCH_NO_DATA);
499 }
500
501 /********************************************************************************
502  * MODULE     : DEV_RcvDATA
503  * ABSTRACT   : Acknowledgement
504  * FUNCTION   : Send message notifications to the communication management thread 
505  * ARGUMENT   : TG_GPS_RCV_DATA   *ptg_rcv_data....I/F information between the receiving thread 
506  *                                                and the communication management thread
507  * NOTE       :
508  * RETURN     : RET_API  :RET_NORMAL:Normal completion
509  *                       :RET_ERROR:ABENDs
510  ********************************************************************************/
511 RET_API DevRcvData(const TG_GPS_RCV_DATA* ptg_rcv_data) {
512   RET_API                 ret = RET_NORMAL; /* Return value */
513   u_int16                 w_size = 0;        /* Data length setting */
514   u_int16                 w_all_len = 0;      /* Sent message length */
515   u_int16                 w_mode = 0;        /* Mode information */
516   RID                     req_id = 0;       /* Resources ID */
517   T_APIMSG_MSGBUF_HEADER  tg_header;            /* Message header */
518
519   // Initialzie struct
520   memset(&tg_header, 0, sizeof(tg_header));
521
522   /* Transmitting buffer */
523   u_int8 by_snd_buf[(sizeof(T_APIMSG_MSGBUF_HEADER) + sizeof(TG_GPS_RCV_DATA))];
524
525   /* Calculation of transmission data length     */
526   w_size = ptg_rcv_data->bydata_len + sizeof(ptg_rcv_data->dwret_status) + sizeof(ptg_rcv_data->bydata_len);
527
528   /* <<Creation of message header section>>>>  */
529   tg_header.signo           = 0;                  /* Signal information setting */
530   tg_header.hdr.sndpno      = PNO_NAVI_GPS_RCV;   /* Source thread No. setting */
531   tg_header.hdr.respno      = 0;                  /* Destination process No. */
532   tg_header.hdr.cid         = CID_GPS_RECVDATA;   /* Command ID setting */
533   tg_header.hdr.msgbodysize = w_size;              /* Message data length setting */
534   tg_header.hdr.rid         = req_id;             /* Resource ID Setting */
535   tg_header.hdr.reserve     = 0;                  /* Reserved area clear */
536
537   memcpy(&by_snd_buf[ 0 ], &tg_header, sizeof(T_APIMSG_MSGBUF_HEADER));
538   /* <<Creation of data section>>     */
539   /* Copy data to send buffer  */
540   memcpy(&by_snd_buf[ sizeof(T_APIMSG_MSGBUF_HEADER)], ptg_rcv_data, w_size);
541
542   /* <<Messaging>>    */
543   /* Calculation of Sent Message Length    */
544   w_all_len = w_size + sizeof(T_APIMSG_MSGBUF_HEADER);
545
546   /* Mode information(Reserved) */
547   w_mode = 0;
548
549   /* Message transmission request */
550   ret = _pb_SndMsg(PNO_NAVI_GPS_MAIN, w_all_len, reinterpret_cast<void*>(by_snd_buf), w_mode);
551
552   /* End of the process */
553   return ret;
554 }
555
556 /********************************************************************************
557  * MODULE   : DEV_Gps_Recv_SndRcvData
558  * ABSTRACT : Receive data transmission processing
559  * FUNCTION : Transmit received data
560  * ARGUMENT : TG_GPS_RECV_RcvFrameBuf *frame_baf Receive frame buffer pointer
561  * NOTE     : Fetches a command from the receive frame buffer and
562  *            issue received data notifications to the main thread
563  * RETURN   : None
564  ********************************************************************************/
565 void DevGpsRecvSndRcvData(const TG_GPS_RECV_RcvFrameBuf* p_frame_buf) {
566   TG_GPS_RCV_DATA tg_rcv_data;
567   u_int16         w_cmd_len = 0;
568
569   // Initialzie struct
570   memset(&tg_rcv_data, 0, sizeof(tg_rcv_data));
571
572   if (p_frame_buf != NULL) {
573     w_cmd_len = p_frame_buf->size;
574
575     if (w_cmd_len <= GPS_READ_LEN) {
576       /* Ignore -> No applicable rules for MISRA-C */
577       memset(&tg_rcv_data, 0, sizeof(TG_GPS_RCV_DATA));
578
579       /* Status Settings */
580       tg_rcv_data.dwret_status = GPS_RECVOK;
581
582       /* Command length setting */
583       tg_rcv_data.bydata_len = w_cmd_len;
584
585       /* Receive data setting */
586       /* Sending from the Beginning of the Sirf Binary #03 */
587       memcpy(&tg_rcv_data.bygps_data[0], &p_frame_buf->buf[0], w_cmd_len);
588
589       /* Issuance of reception notice */
590       DevRcvData(&tg_rcv_data); /* Ignore -> No applicable rules for MISRA-C */
591     }
592   }
593 }
594
595 /**
596  * @brief
597  *   Pos_Gps_Recv Thread Stop Processing
598  */
599 void DevGpsRecvThreadStopProcess(void) {
600 #if FTEN_DRIVER
601   GpsMngApiClose(&g_gps_mng_obj);
602 #endif
603   PosTeardownThread(ETID_POS_GPS_RECV);
604   return;
605 }
606
607 /*---------------------------------------------------------------------------*/
608 /*EOF*/