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.
21 * Clock service-to-service interface
24 /*---------------------------------------------------------------------------------*
26 *---------------------------------------------------------------------------------*/
27 #include <vehicle_service/positioning_base_library.h>
29 #include <stub/clock_notifications.h>
31 /*---------------------------------------------------------------------------------*
33 *---------------------------------------------------------------------------------*/
35 /*---------------------------------------------------------------------------------*
37 *---------------------------------------------------------------------------------*/
39 /*---------------------------------------------------------------------------------*
40 * Local Function Prototype *
41 *---------------------------------------------------------------------------------*/
43 /*---------------------------------------------------------------------------------*
45 *---------------------------------------------------------------------------------*/
46 static BOOL g_clock_availability = FALSE;
48 /*---------------------------------------------------------------------------------*
50 *---------------------------------------------------------------------------------*/
53 * Clock Services IF Availability Change Notification Registration
55 * @param[in] fp_on_cmd Callback function
56 * @return eFrameworkunifiedStatusOK
57 * @return eFrameworkunifiedStatusFail
59 EFrameworkunifiedStatus ClockIfNotifyOnClockAvailability(CbFuncPtr fp_on_cmd) {
60 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
63 happ = _pb_GetAppHandle();
65 /* Clock/Availability Changing notification registration */
66 estatus = FrameworkunifiedSubscribeNotificationWithCallback(happ, NTFY_Clock_Availability, fp_on_cmd); // LCOV_EXCL_BR_LINE 6:unexpected branch //NOLINT (whitespace/line_length)
67 if (eFrameworkunifiedStatusOK != estatus) { // LCOV_EXCL_BR_LINE 4: nsfw error
68 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
69 "PositioningSubscriveNotificationswithCallback ERROR!! [estatus=%d]", estatus);
72 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
80 * Clock Services IF-Availability Settings
82 * @param[in] b_is_available Available state
85 void ClockIfSetAvailability(BOOL b_is_available) {
86 g_clock_availability = b_is_available;
88 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "g_clock_availability=%d", g_clock_availability);
95 * Clock Services IF GPS Time
97 * @param[in] *gps_time GPS time
98 * @param[out] *b_is_available Available state
99 * @return eFrameworkunifiedStatusOK
100 * @return eFrameworkunifiedStatusFail
102 EFrameworkunifiedStatus ClockIfDtimeSetGpsTime(const SENSOR_MSG_GPSTIME *pst_gps_time, BOOL* pb_is_available) {
103 EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusFail;
105 T_DTIME_MSG_GPSTIME st_dtime_gpstime;
107 if (g_clock_availability == TRUE) {
108 happ = _pb_GetAppHandle();
109 if (happ != NULL) { // LCOV_EXCL_BR_LINE 4: nsfw error
110 st_dtime_gpstime.utc.year = pst_gps_time->utc.year;
111 st_dtime_gpstime.utc.month = pst_gps_time->utc.month;
112 st_dtime_gpstime.utc.date = pst_gps_time->utc.date;
113 st_dtime_gpstime.utc.hour = pst_gps_time->utc.hour;
114 st_dtime_gpstime.utc.minute = pst_gps_time->utc.minute;
115 st_dtime_gpstime.utc.second = pst_gps_time->utc.second;
116 st_dtime_gpstime.tdsts = pst_gps_time->tdsts;
118 /* Set GPS time for Clock services */
119 estatus = DTime_setGpsTime(happ, &st_dtime_gpstime);
120 if (estatus != eFrameworkunifiedStatusOK) {
121 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
122 "DTime_setGpsTime ERROR!! [ret=%d, y=%d, m=%d, d=%d, h=%d, n=%d, s=%d, sts=%d]", \
123 estatus, st_dtime_gpstime.utc.year, st_dtime_gpstime.utc.month, st_dtime_gpstime.utc.date, \
124 st_dtime_gpstime.utc.hour, st_dtime_gpstime.utc.minute, st_dtime_gpstime.utc.second, \
125 st_dtime_gpstime.tdsts);
128 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_GetAppHandle ERROR!! [happ=%p]", happ);
134 *pb_is_available = g_clock_availability;