2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19 File name : _pbOSCtrl.cpp
23 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28 #include <vehicle_service/positioning_base_library.h>
29 #include "WPF_STD_private.h"
30 #include "_pbInternalProc.h"
31 #include "_pbSerial.h"
32 /* For CreateFile--> */
33 #include <sys/select.h>
37 /* For CreateFile <-- */
39 #define GPS_FUNC_DEBUG_MSG__CWORD71__FILE 0
41 #if GPS_FUNC_DEBUG_MSG__CWORD71__FILE
42 #define FILE_OUT_LINE 50
43 static u_int8 file_buf[FILE_OUT_LINE][1024];
44 static u_int16 line_size_buf[FILE_OUT_LINE];
46 /* Log destination selection (Activate the one you want to output.) */
47 #define POS_GPS_R_LOGFILE_PATH "/var/local/lib/basesystem/nv/BS/vs/positioning_base_library/rwdata/Test_Pos_gps_read_data.txt"
48 #define POS_GPS_W_LOGFILE_PATH "/var/local/lib/basesystem/nv/BS/vs/positioning_base_library/rwdata/Test_Pos_gps_write_data.txt"
50 #endif /* GPS_FUNC_DEBUG_MSG__CWORD71__FILE */
52 /* For CreateFile--> */
53 #define BAUDRATE B9600
54 #define MODEMDEVICE "/dev/tty.gps"
55 /* For CreateFile <-- */
57 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
58 * MODULE : ClearCommError
59 * ABSTRACT : Get the communication error information and report the current status of the communication device.
62 * RETURN : BOOL defined
63 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
64 /* Wait for replacement */
65 BOOL ClearCommError(HANDLE h_file, LPDWORD lp_errors, LPCOMSTAT lp_stat) { // LCOV_EXCL_START 8:dead code
66 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
72 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
73 * MODULE : GetCommState
74 * ABSTRACT : Store the current control settings of the specified communication device in the device control block (DCB struct).
77 * RETURN : BOOL defined
78 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
79 /* Wait for replacement */ /* TODO IHFLOW OHFLOW declarations are missing */
80 BOOL GetCommState(HANDLE h_file, LPDCB lp_dcb) { // LCOV_EXCL_START 8:dead code
81 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
86 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
87 * MODULE : GetCommTimeouts
88 * ABSTRACT : Get the timeout parameters for all read and write operations performed on the specified communication device.
91 * RETURN : BOOL defined
92 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94 BOOL GetCommTimeouts(HANDLE h_file, LPCOMMTIMEOUTS lp_comm_timeouts) { // LCOV_EXCL_START 8:dead code
95 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
101 if ((INVALID_HANDLE_VALUE != h_file) && (NULL != lp_comm_timeouts)) {
103 memset(lp_comm_timeouts, 0, sizeof(COMMTIMEOUTS));
104 bret = SerialObjectTimeoutGet(h_file, &dw_read, &dw_write);
106 lp_comm_timeouts->write_total_timeout_constant = dw_write;
108 /* Return as 0? or return this setting? */
109 lp_comm_timeouts->read_interval_timeout = INFINITE;
110 lp_comm_timeouts->read_total_timeout_constant = 0;
111 lp_comm_timeouts->read_total_timeout_multiplier = 0;
113 lp_comm_timeouts->read_total_timeout_constant = dw_read;
116 /* not exist in the list */
117 lp_comm_timeouts->write_total_timeout_constant = INFINITE;
118 lp_comm_timeouts->read_total_timeout_constant = INFINITE;
131 * Clear Communication Buffer
133 * Discard all characters in the output buffer or input buffer of the specified resource
136 * @param[in] h_file Handle of the communication resource
137 * @param[in] dw_flags Operation to perform
139 * @return Processing result
140 * @retval TRUE processing succeeded
141 * @retval FALSE Processing failed
143 BOOL PurgeComm(HANDLE h_file, DWORD dw_flags) { // LCOV_EXCL_START 8:dead code
144 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
147 /* h_file is FD, and less than INT_MAX(0x7fffffff) */
148 /* Flush received but unreceived data */
149 res = tcflush(static_cast<int>((long)h_file), TCIFLUSH); // NOLINT(runtime/int)
157 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
158 * MODULE : SetCommMask
159 * ABSTRACT : Specify a set of events to monitor for a specific communication device.
162 * RETURN : BOOL defined
163 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
165 BOOL SetCommMask(HANDLE h_file, DWORD dw_evt_mask) { // LCOV_EXCL_START 8:dead code
166 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
170 bret = SerialObjectWaitmaskAdd(h_file, dw_evt_mask);
179 * Communication setting
181 * Set the serial communication according to the setting information.
183 * @param[in] h_file Communication handle
184 * @param[in] lp_dcb Serial port setting information
186 * @return Processing result
187 * @retval TRUE processing succeeded
188 * @retval FALSE Processing failed
190 BOOL SetCommState(HANDLE h_file, LPDCB lp_dcb) { // LCOV_EXCL_START 8:dead code
191 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
192 struct termios newtio;
194 bzero(&newtio, sizeof(newtio));
195 cfmakeraw(&newtio); /* RAW mode */
196 newtio.c_cflag |= (BAUDRATE | CS8 | CLOCAL | CREAD);/*Baud:9600*/
197 newtio.c_lflag &= ~ECHO;
199 /* h_file is FD, and less than INT_MAX(0x7fffffff) */
200 tcflush(static_cast<int>((long)h_file), TCIFLUSH); // NOLINT(runtime/int)
201 tcsetattr(static_cast<int>((long)h_file), TCSANOW, &newtio); // NOLINT(runtime/int)
208 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
209 * MODULE : SetCommTimeouts
210 * ABSTRACT : Set the timeout parameter for all read and write operations performed on the specified communication device.
213 * RETURN : BOOL defined
214 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
216 BOOL SetCommTimeouts(HANDLE h_file, LPCOMMTIMEOUTS lp_comm_timeouts) { // LCOV_EXCL_START 8:dead code
217 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
220 DWORD dw_read_timeout = INFINITE;
221 DWORD dw_write_timeout = INFINITE;
223 /* Calculate timeout time */
224 if ((INFINITE == lp_comm_timeouts->read_interval_timeout)
225 && (0 == lp_comm_timeouts->read_total_timeout_constant)
226 && (0 == lp_comm_timeouts->read_total_timeout_multiplier)) {
227 /* Set without waiting */
230 dw_read_timeout = lp_comm_timeouts->read_total_timeout_constant;
234 dw_write_timeout = lp_comm_timeouts->write_total_timeout_constant;
236 bret = SerialObjectTimeoutAdd(h_file, dw_read_timeout, dw_write_timeout);
246 * Waiting for communication event
248 * Wait for an event to be generated for a specified handle
249 * Note : Continue to wait indefinitely until data reception/error occurs
251 * @param[in] h_file Communication handle
252 * @param[out] lp_evt_mask Pointer to the variable to receive the event
253 * @param[in] lp_overlapped OVERLAPPED Pointer to a struct[Note:Not used]
255 * @return Processing result
256 * @retval TRUE Processing succeeded
257 * @retval FALSE Processing failed
259 BOOL WaitCommEvent(HANDLE h_file, LPDWORD lp_evt_mask, LPOVERLAPPED lp_overlapped) { // LCOV_EXCL_START 8:dead code
260 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
265 fd_set fds_set; // Set of file descriptor
269 /* Monitor for 0.5 seconds */
272 /* h_file is FD, and less than INT_MAX(0x7fffffff) */
273 fd = static_cast<int>((long)h_file); // NOLINT(runtime/int)
277 FD_ZERO(&fds_set_err);
279 FD_SET(fd, &fds_set);
280 FD_SET(fd, &fds_set_err);
282 res = select(fd + 1, &fds_set, NULL, &fds_set_err, &tv);
285 if (FD_ISSET(fd, &fds_set)) {
286 *lp_evt_mask = EV_RXCHAR;
290 *lp_evt_mask = EV_ERROR;
305 * Create or open an object and return a handle which can be used to access the object
307 * @param lp_file_name Not used
308 * @param dw_desired_access Not used
309 * @param dw_share_mode Not used
310 * @param lp_security_attributes Not used
311 * @param dw_creation_disposition Not used
312 * @param dw_flags_and_attributes Not used
313 * @param h_template_file Not used
317 HANDLE CreateFile(LPCTSTR lp_file_name, DWORD dw_desired_access, DWORD dw_share_mode, LPSECURITY_ATTRIBUTES lp_security_attributes, DWORD dw_creation_disposition, DWORD dw_flags_and_attributes, HANDLE h_template_file) { // LCOV_EXCL_START 8:dead code // NOLINT(whitespace/line_length)
318 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
323 fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
329 /* fd is FD, and less than INT_MAX(0x7fffffff) and the return data type is HANDLE. */
330 return (HANDLE)((long)(fd)); // NOLINT(runtime/int)
341 * @param[in] h_object Handle
343 * @return Processing result
344 * @retval TRUE Processing succeeded
345 * @retval FALSE Processing failed
347 BOOL CloseFile(HANDLE h_object) { // LCOV_EXCL_START 8:dead code
348 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
349 if (h_object != reinterpret_cast<void*>(-1)) {
350 /* h_object is FD, and less than INT_MAX(0x7fffffff) */
351 close(static_cast<int>((long)h_object)); // NOLINT(runtime/int)
364 * Writing Data to a File
366 * @param[in] h_file Handle
367 * @param[in] lp_buffer buffer to write
368 * @param[out] n_number_of_bytes_to_write Maximum writing size
369 * @param[out] lpNumberOfBytesWrite Writing size
370 * @param lp_overlapped Not used
372 * @return Processing result
373 * @retval TRUE Processing succeeded
374 * @retval FALSE Processing failed
376 BOOL WriteFile(HANDLE h_file, LPCVOID lp_buffer, DWORD n_number_of_bytes_to_write, LPDWORD lp_number_of_bytes_written, LPOVERLAPPED lp_overlapped) { // LCOV_EXCL_START 8:dead code // NOLINT(whitespace/line_length)
377 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
381 fd_set fds_set; /* Set of file descriptors */
386 #if GPS_FUNC_DEBUG_MSG__CWORD71__FILE
387 static FILE* fp = NULL; /* For debugging */
389 #endif /* GPS_FUNC_DEBUG_MSG__CWORD71__FILE */
391 /* monitor for 2 seconds.*/
394 /* h_file is FD, and less than INT_MAX(0x7fffffff) */
395 fd = static_cast<int>((long)h_file); // NOLINT(runtime/int)
399 FD_ZERO(&fds_set_err);
401 FD_SET(fd, &fds_set);
402 FD_SET(fd, &fds_set_err);
404 res = select(fd + 1, &fds_set, NULL, &fds_set_err, &tv);
406 if (FD_ISSET(fd, &fds_set)) {
407 /* h_file is FD, and less than INT_MAX(0x7fffffff) */
408 res = static_cast<int>(write(static_cast<int>((long)h_file), lp_buffer, // NOLINT(runtime/int)
409 n_number_of_bytes_to_write));
410 *lp_number_of_bytes_written = res;
412 #if GPS_FUNC_DEBUG_MSG__CWORD71__FILE
414 /* File initialization */
415 fp = fopen(POS_GPS_W_LOGFILE_PATH, "w+");
417 fp = fopen(POS_GPS_W_LOGFILE_PATH, "a+");
419 for (i = 0; i < n_number_of_bytes_to_write; i++) {
420 fprintf(fp, "%02x ", *(reinterpret_cast<char *>(lp_buffer) + i));
424 #endif /* GPS_FUNC_DEBUG_MSG__CWORD71__FILE */
437 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
439 * ABSTRACT : Format a string and store the value in a buffer. If any of the arguments are passed,
440 * Format according to the corresponding format specifier in the format control string and copies it to the output buffer.
443 * RETURN : int defined
444 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
445 int Wsprintf(LPTSTR lp_out, LPCTSTR lp_fmt, ...) { // LCOV_EXCL_START 8:dead code
446 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
451 va_start(args, lp_fmt);
452 /* Seems to be occured problems because the buffer size is not known. */
453 rtn = vswprintf(reinterpret_cast<wchar_t*>(lp_out), 256, reinterpret_cast<const wchar_t*>(lp_fmt), args);
461 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
462 * MODULE : PbSystemTimeToFileTime
463 * ABSTRACT : Convert the system date and time to 64-bit format file time.
466 * RETURN : BOOL defined
467 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
468 BOOL PbSystemTimeToFileTime(const SYSTEMTIME* lp_system_time, LPFILETIME lp_file_time) { // LCOV_EXCL_START 8:dead code
469 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
475 * Function name : MunmapDeviceIo<br>
476 * Register unmapping<br>
478 * Overview : Remove the mapping of a register to memory.<br>
480 * -# Release the mapping of the specified register to memory.
482 * @param h_dev [I]Handle to the device object
483 * @param map_size [I]Size of mapped device I/O memory
485 * @return RET_API Processing result
486 * @retval RET_NORMAL Processing succeeded
487 * @retval RET_ERROR Processing failed
489 /* Wait for replacement */
490 RET_API MunmapDeviceIo(HANDLE h_dev, u_int32 map_size) { // LCOV_EXCL_START 8:dead code
491 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
497 * Function name : MmapDeviceIo<br>
498 * Register mapping<br>
500 * Overview : Map registers to memory.<br>
502 * -# Map the specified register to memory.
504 * @param map_size [I]Size of mapped device I/O memory
505 * @param map_addr [I]Mapped physical address
507 * @return HANDLE Processing result
508 * @retval Except NULL Handle
509 * @retval NULL Processing failed
511 /* Wait for replacement */
512 HANDLE MmapDeviceIo(u_int32 map_size, u_int32 map_addr) { // LCOV_EXCL_START 8:dead code
513 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
525 * @param[in] p_func Calling function
526 * @param[in] line Number of caller rows
528 void _pb_Exit_d(const char* p_func, int line) { // LCOV_EXCL_START 8:dead code // NOLINT(whitespace/line_length) // NOLINT(readability/nolint) WPF_SYSAPI.h API
529 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
532 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FORBIDDEN ERROR [Called by:%s, Line:%d]", p_func, line);
540 /* GPF001_sample_ttaka add end */