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 * This file has been generated automatically.
19 * User hand written code entry is allowed only inside protected zones.
23 * This file has been generated automatically.
24 * User hand written code entry is allowed only inside protected zones.
27 #include <native_service/frameworkunified_application.h>
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/frameworkunified_service_protocol.h>
30 #include <native_service/frameworkunified_multithreading.h>
31 #include <peripheral_service/communication_notifications.h>
32 #include <peripheral_service/Canif_API.h>
38 #include "communication_cid.h"
39 #include "communication_communicationlog.h"
40 #include "Thread_Common.h"
42 extern EFrameworkunifiedStatus CANThreadStart(HANDLE h_app);
43 extern EFrameworkunifiedStatus CANThreadStop(HANDLE h_app);
45 HANDLE g_can_thread = NULL;
47 EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE h_app) {
48 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
52 // API to Register Notification for Service Availability.
53 e_status = FrameworkunifiedRegisterServiceAvailabilityNotification(h_app,
54 NTFY_Communication_Availability);
55 if (eFrameworkunifiedStatusOK != e_status) {
56 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
57 "Failed to Register Service Availability Notification.");
59 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
60 "Service Availability Notification registered successfully.");
63 // API to Publish Service Availability Notification.
64 e_status = FrameworkunifiedPublishServiceAvailability(h_app, FALSE);
65 if (eFrameworkunifiedStatusOK != e_status) {
66 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
67 "Failed to Publish Service Availability Notification.");
69 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
70 "Service Availability Notification published successfully.");
73 g_can_thread = FrameworkunifiedCreateChildThread(h_app, LAN_SERVICE_CAN,
74 CANThreadStart, CANThreadStop);
75 if (g_can_thread == NULL) {
76 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to create CAN");
79 // API to Publish Service Availability Notification.
80 e_status = FrameworkunifiedPublishServiceAvailability(h_app, TRUE);
81 if (eFrameworkunifiedStatusOK != e_status) {
82 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
83 "Failed to Publish Service Availability Notification.");
85 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
86 "Service Availability Notification published successfully.");
92 EFrameworkunifiedStatus FrameworkunifiedOnWakeup(HANDLE h_app) {
93 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
97 EFrameworkunifiedStatus FrameworkunifiedOnShutdown(HANDLE h_app) {
98 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
102 EFrameworkunifiedStatus FrameworkunifiedOnEShutdown(HANDLE h_app) {
103 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
107 EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE h_app) {
108 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
112 EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE h_app) {
113 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
117 EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE h_app) {
118 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
122 static EFrameworkunifiedStatus CommThreadCheckAndStart(HANDLE p, HANDLE c,
123 UI_32 len, PCVOID data, BOOL current) {
124 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
125 if (TRUE != current) {
126 e_status = FrameworkunifiedStartChildThread(p, c, len, data);
131 static EFrameworkunifiedStatus CommThreadCheckAndStop(HANDLE p, HANDLE c,
132 UI_32 len, PCVOID data, BOOL current) {
133 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
134 if (TRUE == current) {
135 e_status = FrameworkunifiedStopChildThread(p, c, len, data);
140 EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE h_app) {
141 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
142 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
144 e_status = CommThreadCheckAndStart(h_app, g_can_thread,
145 0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
146 if (eFrameworkunifiedStatusOK != e_status) {
147 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
148 "Fail to Start CAN Thread. Status:%#x", e_status);
151 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
155 EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE h_app) {
156 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
158 e_status = CommThreadCheckAndStop(h_app, g_can_thread,
159 0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
160 if (eFrameworkunifiedStatusOK != e_status) {
161 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
162 "Fail to Stop CAN Thread. Status:%#x", e_status);
170 EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE h_app) {
171 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
172 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
174 e_status = CommThreadCheckAndStart(h_app, g_can_thread,
175 0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
176 if (eFrameworkunifiedStatusOK != e_status) {
177 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
178 "Fail to Start CAN Thread. Status:%#x", e_status);
181 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
185 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE h_app) {
186 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
187 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
189 e_status = CommThreadCheckAndStart(h_app, g_can_thread,
190 0, NULL, CommGetAvailabilityCurrent(CAN_AVAILABILITY));
191 if (eFrameworkunifiedStatusOK != e_status) {
192 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
193 "Fail to Start CAN Thread. Status:%#x", e_status);
196 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
200 EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE h_app) {
201 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
202 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
204 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
208 EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE h_app) {
209 EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK;
210 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[START]");
212 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "[END]");
216 std::string MessageDataOutputLog(uint8_t *msg_data, uint32_t len){
217 std::string data_log;
219 for(uint32_t i = 0; i < len; i++){
220 std::ostringstream ss;
221 data_buf = (int)msg_data[i];
222 ss << std::hex << data_buf;
223 data_log = ss.str() + " " + data_log;