2 * @copyright Copyright (c) 2017-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 #include <linux/cdrom.h>
19 #include <sys/ioctl.h>
21 #include <native_service/frameworkunified_types.h>
22 #include <native_service/frameworkunified_framework_if.h>
25 #include "deck_hal_deckhallog.h"
27 #define DECKHAL_THREAD "DeckHal"
28 #define DISC_PATH "/dev/sr0"
30 static char g_notify_name[NOTIFY_NAME_MAX_SIZE + 1] = {0};
31 static bool g_register_status = false; // deck_hal register status
34 EFrameworkunifiedStatus DeckNotifyInfo(const DECK_MSG_DELIVERY &DeliveryData);
36 EFrameworkunifiedStatus StopDiscRotation() {
39 fd = open(DISC_PATH, O_RDONLY);
41 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "open failed.");
42 return eFrameworkunifiedStatusFail;
44 ret = ioctl(fd, CDROMSTOP);
47 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "ioctl failed.");
48 return eFrameworkunifiedStatusFail;
50 return eFrameworkunifiedStatusOK;
53 EFrameworkunifiedStatus EjectDisc(DeckKind kind, DeckEjectMode mode) {
56 fd = open(DISC_PATH, O_RDONLY);
58 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "open failed.");
59 return eFrameworkunifiedStatusFail;
61 ret = ioctl(fd, CDROM_LOCKDOOR);
63 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "unlock disc failed.");
65 return eFrameworkunifiedStatusFail;
67 ret = ioctl(fd, CDROMEJECT);
70 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "eject disc failed.");
71 return eFrameworkunifiedStatusFail;
73 return eFrameworkunifiedStatusOK;
76 EFrameworkunifiedStatus DeckHalSysSend(HANDLE h_app, PCSTR name, const DECK_CMD* cmd, uint8_t req_id) {
77 EFrameworkunifiedStatus ret = eFrameworkunifiedStatusOK;
79 if (NULL == h_app || NULL == name || NULL == cmd) {
80 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input param is NULL\n");
81 return eFrameworkunifiedStatusInvldParam;
84 if (NOTIFY_NAME_MAX_SIZE < strlen(name)) {
85 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input name length is overlapped\n");
86 return eFrameworkunifiedStatusInvldParam;
88 // DeckHalSysSend aims to send command to micon,
89 // since micon is stub now,so DeckHalSysSend is stub either.
91 // deck_hal should notify chande mode status after received mode change info
92 // from micon,since now micon is stub,notify change mode status to vehicle
94 // the data notify to vehile is just a example.
95 DECK_MSG_DELIVERY data;
96 data.cmd.cmdhdr.lgadr_from = 0x44; // vehile:LSDRV_ADR_DVD_P
97 data.cmd.cmdhdr.lgadr_to = 0xC8; // vehicle:LSDRV_OPC_DRV_M_CH_A_DVD
98 data.cmd.cmdhdr.opc = 0xC8; // vehicle:LSDRV_OPC_DRV_M_CH_A_DVD
104 EFrameworkunifiedStatus DeckHalRegister(HANDLE h_app, PCSTR notify_name) {
106 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input h_app is NULL\n");
107 return eFrameworkunifiedStatusInvldParam;
110 if (NULL == notify_name) {
111 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input notify_name is NULL\n");
112 return eFrameworkunifiedStatusInvldParam;
115 if (strlen(notify_name) > NOTIFY_NAME_MAX_SIZE) {
116 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Input notify_name length is overlapped\n");
117 return eFrameworkunifiedStatusInvldParam;
120 strncpy(g_notify_name, notify_name, NOTIFY_NAME_MAX_SIZE);
122 // now micon is stub,in the future,should register to micon
124 g_register_status = true;
126 return eFrameworkunifiedStatusOK;
129 // DeckNotifyInfo aims to send deck infos to vehicle
130 // if micon is not stub in the future,after received meesage from micon
131 // or any other ways triggered by micon,deck_hal should call this function
132 // with different input data to send these data to vehicle.
133 EFrameworkunifiedStatus DeckNotifyInfo(const DECK_MSG_DELIVERY &DeliveryData) {
134 EFrameworkunifiedStatus ret = eFrameworkunifiedStatusOK;
135 HANDLE send_handle = NULL;
137 if (g_register_status == true) {
138 send_handle = McOpenSender(g_notify_name);
139 if (send_handle == NULL) {
140 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "FrameworkunifiedMcOpenSender to _CWORD121_Shadow Failed.");
141 return eFrameworkunifiedStatusFail;
144 ret = McSend(send_handle, DECKHAL_THREAD, CID_DECK_SYS_DELIVERY,
145 sizeof(DECK_MSG_DELIVERY), &DeliveryData);
147 if (eFrameworkunifiedStatusOK != ret) {
148 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__, "Failed to send CID_DECK_SYS_DELIVERY.");
149 ret = eFrameworkunifiedStatusFail;
152 if (send_handle != NULL) {
153 McClose(send_handle);