aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE177
-rw-r--r--Makefile69
-rw-r--r--README.md3
-rw-r--r--hal_api/vehicle_hal.h210
-rw-r--r--inc/vehicle_hal_frameworkunifiedlog.h78
-rw-r--r--src/vehicle_hal.cpp398
6 files changed, 935 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..f433b1a5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..d009b134
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,69 @@
+#
+# @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+######### installed program/file ################
+TARGET := libvehicle_hal.so
+
+HEADER := hal_api/vehicle_hal.h
+
+######### include paths/files ###################
+CXXFLAGS := -I./inc/
+CXXFLAGS += -I./hal_api/
+CXXFLAGS += -I$(SDKTARGETSYSROOT)/usr/agl/include
+CXXFLAGS += -include $(SDKTARGETSYSROOT)/usr/agl/include/agl_types_obsoluted.h
+
+######### compile options #######################
+CXXFLAGS += -Wall -fPIC
+
+######### link options ##########################
+LDFLAGS += -shared
+LDFLAGS += -Wl,--no-as-needed
+LDFLAGS += -Wl,--no-undefined
+LDFLAGS += -L$(SDKTARGETSYSROOT)/usr/agl/lib
+
+RPATH := /usr/lib
+
+######### linked library ########################
+LIBS += -Wl,-Bdynamic -lstdc++
+LIBS += -Wl,-Bdynamic -lpthread
+LIBS += -Wl,-Bdynamic -lNS_FrameworkUnified
+#LIBS += -Wl,-Bdynamic -lcarsignal_mng
+
+######### source files ##########################
+VPATH := src
+OBJS := vehicle_hal.o
+
+######### make targets ##########################
+all: $(TARGET)
+ @echo $@ done.
+
+$(TARGET): $(OBJS)
+ $(CC) $(LDFLAGS) -Wl,-rpath=:$(RPATH) $(OBJS) $(LIBS) -o $(TARGET)
+ @echo $@ done.
+
+######### make cleans ###########################
+GCNO_FILES := $(filter %.gcno,$(OBJS:%.o=%.gcno))
+
+clean:
+ rm -f $(OBJS) $(TARGET) $(GCNO_FILES)
+ @echo $@ done.
+
+######### make installs #########################
+install:
+ install -d -m 0755 $(DESTDIR)/usr/lib
+ install -m 0755 $(TARGET) $(DESTDIR)/usr/lib
+ @echo $@ done.
+
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..6636a4f3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+vehicle_hal library
+==================
+Vehicle HAL implementation library for AGL Reference Board.
diff --git a/hal_api/vehicle_hal.h b/hal_api/vehicle_hal.h
new file mode 100644
index 00000000..4e6cc89e
--- /dev/null
+++ b/hal_api/vehicle_hal.h
@@ -0,0 +1,210 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HAL_API_VEHICLE_HAL_H_
+#define HAL_API_VEHICLE_HAL_H_
+/**
+ * @file vehicle_hal.h
+ */
+
+/** @addtogroup vehicle
+ * @{
+ */
+/** @addtogroup vehicle_hal
+ * @ingroup vehicle
+ * @{
+ */
+
+#include <native_service/frameworkunified_types.h>
+
+/**
+ * \~english Name of the send thread
+ */
+#define TN_LINE_SENS_READ "Vehicle Hal"
+
+/**
+ * @enum LineSensReadInternalServiceProtocol
+ * \~english Command ID used by Vehicle_hal to send the vehicle signal input from the jicage line to the user \n
+ To receive events with this command ID, use the interface defined in framework_unified as follows
+ * @code
+ * ret_status = FrameworkunifiedAttachCallbackToDispatcher(h_app, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS, CbCallbackFunc);
+ * @endcode
+ */
+enum LineSensReadInternalServiceProtocol {
+ CID_VEHICLEHAL_LINESENS = 0x00000101, //!< \~english LineSens Message Command ID
+ CID_VEHICLEHAL_SPDPULSE = 0x00000102, //!< \~english SpeedPulse Message Command ID
+ CID_VEHICLEHAL_SPD = 0x00000103, //!< \~english Speed Message Command ID
+ CID_VEHICLEHAL_LINESENS_POL = 0x00000104,
+ //!< \~english voltage and RHEOSTAT Message Command ID
+};
+
+/**
+ * @enum VehiclehalLinesenskindMicBit
+ * \~english MIC BIT
+ */
+enum VehiclehalLinesenskindMicBit {
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_MIC = 0x01, //!< \~english MIC
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_ANALOGMIC1 = 0x02, //!< \~english ANALOGMIC1
+ VEHICLEHAL_LINESENSKIND_MIC_BIT_ANALOGMIC2 = 0x04, //!< \~english ANALOGMIC2
+};
+
+/**
+ * @enum VehiclehalLinesenskindMic2Bit
+ * \~english MIC2 BIT
+ */
+enum VehiclehalLinesenskindMic2Bit {
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_A2BHUB = 0x01, //!< \~english A2BHUB
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC1 = 0x02, //!< \~english MULTIMIC1
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC2 = 0x04, //!< \~english MULTIMIC2
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC3 = 0x08, //!< \~english MULTIMIC3
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC4 = 0x10, //!< \~english MULTIMIC4
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC5 = 0x20, //!< \~english MULTIMIC5
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_MULTIMIC6 = 0x40, //!< \~english MULTIMIC6
+ VEHICLEHAL_LINESENSKIND_MIC2_BIT_ANC = 0x80, //!< \~english ANC
+};
+
+/**
+ * @enum VehicleHalLineSensKind
+ * \~english Line Sensor kind
+ */
+enum VehicleHalLineSensKind {
+ VEHICLEHAL_LINESENSKIND_IG = 0, //!< \~english IG
+ VEHICLEHAL_LINESENSKIND_PKB, //!< \~english PKB
+ VEHICLEHAL_LINESENSKIND_REV, //!< \~english REV
+ VEHICLEHAL_LINESENSKIND_ILL, //!< \~english ILL
+ VEHICLEHAL_LINESENSKIND_LOWVOLTAGE, //!< \~english LOWVOLTAGE
+ VEHICLEHAL_LINESENSKIND_ADIM, //!< \~english ADIM
+ VEHICLEHAL_LINESENSKIND_MIC, //!< \~english MIC,ANALOGMIC1,ANALOGMIC2
+ VEHICLEHAL_LINESENSKIND_USBPOWERSUPPLY, //!< \~english USB Power Supply[10mA]
+ VEHICLEHAL_LINESENSKIND_MIC2, //!< \~english A2BHUB,MULTIMIC1 to 6,ANC
+ VEHICLEHAL_LINESENSKIND_NUM, //!< \~english MAX Number
+};
+
+/**
+ * @enum VEHICLEHAL_RET_TYPE
+ * \~english The return value of vehicle_hal API
+ */
+typedef enum {
+ /**
+ * \~english Success
+ */
+ VEHICLEHAL_RET_SUCCESS = 0,
+ /**
+ * \~english Car Signal Ctrl Api Initialize failed
+ */
+ VEHICLEHAL_RET_ERR_HARDINIT,
+ /**
+ * \~english McSend Open failed
+ */
+ VEHICLEHAL_RET_ERR_MCOPEN,
+ /**
+ * \~english Create Thread failed
+ */
+ VEHICLEHAL_RET_ERR_THREADSTART,
+ /**
+ * \~english Invalid paramter
+ */
+ VEHICLEHAL_RET_ERR_PARAM,
+}VEHICLEHAL_RET_TYPE;
+
+/**
+ * @struct VehicleHalSpeedPulse
+ * \~english Struct of SpeedPulse
+ */
+struct VehicleHalSpeedPulse {
+ float pulse; //!< \~english speed pulse[Hz]
+ float period; //!< \~english pulse period[ms]
+};
+
+/**
+ * @struct VehicleHalLineSensMsg
+ * \~english Struct of Meassage
+ */
+struct VehicleHalLineSensMsg {
+ uint8_t stdata[VEHICLEHAL_LINESENSKIND_NUM]; //!< \~english line data
+};
+
+/**
+ * @struct VehicleHalPol
+ * \~english Struct of VehicleHalPolling
+ */
+struct VehicleHalPol {
+ uint8_t vb; //!< \~english voltage [10 * v]
+ uint8_t rheostat; //!< \~english RHEOSTAT [10 * v]
+};
+
+/**
+ * \ingroup VehicleHalStart
+ * \~english @par Brief
+ * API to start the vehicle_hal
+ * \~english @param [in] happ
+ * HANDLE - Handle for Application
+ * \~english @retval VEHICLEHAL_RET_SUCCESS : Success
+ * \~english @retval VEHICLEHAL_RET_ERR_HARDINIT : Car Signal Ctrl Api Initialize failed
+ * \~english @retval VEHICLEHAL_RET_ERR_MCOPEN : McSend Open failed
+ * \~english @retval VEHICLEHAL_RET_ERR_THREADSTART : Create Thread failed
+ * \~english @retval VEHICLEHAL_RET_ERR_PARAM : Invalid paramter
+ * \~english @par Prerequisite
+ * None
+ * \~english @par Change of internal state
+ * - If start successfully, vehicle_hal changes from stop to start.
+ * - If start failed, the state of the vehicle_hal remains no change.
+ * \~english @par Conditions of processing failure
+ * - Car Signal Ctrl Api Initialize failed.
+ * - McSend Open failed.
+ * - Create Thread failed.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Start the vehicle_hal service.
+ * - The API can only be used by 1 process.
+ * \~english @see
+ * None
+ */
+VEHICLEHAL_RET_TYPE VehicleHalStart(HANDLE happ);
+
+/**
+ * \ingroup VehicleHalStop
+ * \~english @par Brief
+ * API to stop the vehicle_hal
+ * \~english @param [in] happ
+ * HANDLE - Handle for Application
+ * \~english @retval VEHICLEHAL_RET_SUCCESS : Success
+ * \~english @retval VEHICLEHAL_RET_ERR_PARAM : Invalid paramter
+ * \~english @par Prerequisite
+ * vehicle_hal start successfully.
+ * \~english @par Change of internal state
+ * - If start successfully, vehicle_hal changes from start to stop.
+ * - If start failed, the state of the vehicle_hal remains no change.
+ * \~english @par Conditions of processing failure
+ * None.
+ * \~english @par Classification
+ * Public
+ * \~english @par Type
+ * Sync
+ * \~english @par Detail
+ * - Stop the vehicle_hal service.
+ * - The API can only be used by 1 process.
+ * \~english @see
+ * None
+ */
+VEHICLEHAL_RET_TYPE VehicleHalStop(HANDLE happ);
+
+/** @}*/ //!< end of vehicle_hal
+/** @}*/ //!< end of vehicle
+#endif // HAL_API_VEHICLE_HAL_H_
diff --git a/inc/vehicle_hal_frameworkunifiedlog.h b/inc/vehicle_hal_frameworkunifiedlog.h
new file mode 100644
index 00000000..2cee8ebc
--- /dev/null
+++ b/inc/vehicle_hal_frameworkunifiedlog.h
@@ -0,0 +1,78 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+#define INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+
+#include <native_service/ns_logger_if.h>
+
+#define ZONE_INIT ZONEMASK(10)
+#define ZONE_FUNC ZONEMASK(11)
+#define ZONE_MEM ZONEMASK(12)
+#define ZONE_13 ZONEMASK(13)
+#define ZONE_14 ZONEMASK(14)
+#define ZONE_15 ZONEMASK(15)
+#define ZONE_16 ZONEMASK(16)
+#define ZONE_17 ZONEMASK(17)
+#define ZONE_18 ZONEMASK(18)
+#define ZONE_19 ZONEMASK(19)
+#define ZONE_20 ZONEMASK(20)
+#define ZONE_21 ZONEMASK(21)
+#define ZONE_22 ZONEMASK(22)
+#define ZONE_23 ZONEMASK(23)
+#define ZONE_24 ZONEMASK(24)
+#define ZONE_25 ZONEMASK(25)
+#define ZONE_26 ZONEMASK(26)
+#define ZONE_27 ZONEMASK(27)
+#define ZONE_28 ZONEMASK(28)
+#define ZONE_INFO ZONEMASK(29)
+#define ZONE_WARN ZONEMASK(30)
+#define ZONE_ERR ZONEMASK(31)
+
+#define ZONE_TEXT_10 "Init"
+#define ZONE_TEXT_11 "Function"
+#define ZONE_TEXT_12 "Memory"
+#define ZONE_TEXT_13 ""
+#define ZONE_TEXT_14 ""
+#define ZONE_TEXT_15 ""
+#define ZONE_TEXT_16 ""
+#define ZONE_TEXT_17 ""
+#define ZONE_TEXT_18 ""
+#define ZONE_TEXT_19 ""
+#define ZONE_TEXT_20 ""
+#define ZONE_TEXT_21 ""
+#define ZONE_TEXT_22 ""
+#define ZONE_TEXT_23 ""
+#define ZONE_TEXT_24 ""
+#define ZONE_TEXT_25 ""
+#define ZONE_TEXT_26 ""
+#define ZONE_TEXT_27 ""
+#define ZONE_TEXT_28 ""
+#define ZONE_TEXT_29 "Info"
+#define ZONE_TEXT_30 "Warning"
+#define ZONE_TEXT_31 "Error"
+
+#ifndef FRAMEWORKUNIFIEDLOGOPTIONS
+#define FRAMEWORKUNIFIEDLOGOPTIONS (LSHAREDMEM) // LPRINT , LMSGQ, LSLOGGER
+#endif
+
+#ifndef FRAMEWORKUNIFIEDLOGAPPZONES
+#define FRAMEWORKUNIFIEDLOGAPPZONES ZONE_ERR, ZONE_WARN, ZONE_INFO
+#endif
+
+extern const CHAR AppName[]; // NOLINT (defind outside)
+#endif // INC_VEHICLE_HAL_FRAMEWORKUNIFIEDLOG_H_
+
diff --git a/src/vehicle_hal.cpp b/src/vehicle_hal.cpp
new file mode 100644
index 00000000..258c51a4
--- /dev/null
+++ b/src/vehicle_hal.cpp
@@ -0,0 +1,398 @@
+/*
+ * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <agl_thread.h>
+#include <native_service/frameworkunified_framework_if.h>
+#include <native_service/frameworkunified_dispatcher.h>
+#include <native_service/frameworkunified_multithreading.h>
+#include "vehicle_hal_frameworkunifiedlog.h"
+
+extern "C" {
+// #include "carsignal_mng_api.h"
+}
+
+#include "vehicle_hal.h"
+
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_ADIM_DATA "VEHICLEHAL_LINESENSKIND_ADIM"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_MIC_DATA "VEHICLEHAL_LINESENSKIND_MIC"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_VB_DATA "VEHICLEHAL_LINESENSKIND_VB"
+/**
+* \~english environment variable define
+*/
+#define VEHICLEHAL_LINESENSKIND_RHEOSTAT_DATA "VEHICLEHAL_LINESENSKIND_RHEOSTAT"
+
+#define VEHICLEHAL_LOWVB_VALUE 75
+
+// send message flag
+static HANDLE g_sendmsg_handle = NULL;
+
+// work thread exit flag
+static BOOL g_loopendflag = FALSE;
+
+// polling thread exit flag
+static BOOL g_polloopendflag = FALSE;
+
+// isOpen flag
+static BOOL g_isopenflag = FALSE;
+
+// thread id
+static pthread_t g_threadid = 0;
+
+// hard object struct
+//static VclCtlApiObj g_sclientobj;
+
+// app name
+static CHAR g_appname[MAX_NAME_SIZE_APP];
+
+// line sense list
+const UINT8 kLineSensList[VEHICLEHAL_LINESENSKIND_NUM] = {
+// CARSIGNAL_IG,
+// CARSIGNAL_PKB,
+// CARSIGNAL_REV,
+// CARSIGNAL_ILL,
+};
+
+static void *VehicleHalProcess(void *arg);
+
+HANDLE g_vehiclehalext_thread;
+HANDLE g_vehiclehalpol_thread;
+EFrameworkunifiedStatus VehicleHalProcessExtStart(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessExtStop(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessRecvSpeed(HANDLE happ);
+
+EFrameworkunifiedStatus VehicleHalProcessPolStart(HANDLE happ);
+EFrameworkunifiedStatus VehicleHalProcessPolStop(HANDLE happ);
+
+static const FrameworkunifiedProtocolCallbackHandler kVehicleHalSpd[] = { {
+ CID_VEHICLEHAL_SPD, VehicleHalProcessRecvSpeed } };
+
+#define VEHICLEHAL_SPEED "VehicleHalSpd"
+#define VEHICLEHAL_EXT "VehicleHalExt"
+#define VEHICLEHAL_POL "VehicleHalPol"
+
+VEHICLEHAL_RET_TYPE VehicleHalStart(HANDLE happ) {
+ if (NULL == happ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Handle is NULL");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ // check open flag
+ if (TRUE == g_isopenflag) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Already Opened");
+ return VEHICLEHAL_RET_SUCCESS;
+ }
+
+// memset(&g_sclientobj, 0, sizeof(g_sclientobj));
+
+ // enter loop
+ g_loopendflag = FALSE;
+
+ g_polloopendflag = FALSE;
+
+ // get app name
+ PCSTR app_name = FrameworkunifiedGetAppName(happ);
+ if (NULL == app_name) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Get App Name Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ memset(g_appname, 0, sizeof(g_appname));
+ memcpy(g_appname, app_name, sizeof(g_appname));
+ g_appname[MAX_NAME_SIZE_APP] = '\0';
+
+// // Start VLC data input control API
+// UINT32 ret = VclCtlApiOpen(&g_sclientobj);
+// if ( CARSIGNAL_CTL_RET_SUCCESS != ret ) {
+// FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Ten Api Open Failed");
+// return VEHICLEHAL_RET_ERR_HARDINIT;
+// }
+
+ // Open message queue for sending
+ g_sendmsg_handle = McOpenSender(g_appname);
+ if (NULL == g_sendmsg_handle) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Open Mc Sender Failed");
+// VclCtlApiClose(&g_sclientobj);
+ return VEHICLEHAL_RET_ERR_MCOPEN;
+ }
+
+ // create thread
+ int iret = pthread_create(&g_threadid,
+ NULL,
+ VehicleHalProcess,
+ NULL);
+ if ( 0 != iret ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Create Thread Failed");
+ McClose(g_sendmsg_handle);
+// VclCtlApiClose(&g_sclientobj);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+ g_vehiclehalext_thread = FrameworkunifiedCreateChildThread(happ, VEHICLEHAL_EXT,
+ VehicleHalProcessExtStart,
+ VehicleHalProcessExtStop);
+
+ EFrameworkunifiedStatus estatus = FrameworkunifiedStartChildThread(happ, g_vehiclehalext_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedStartChildThread Failed");
+ McClose(g_sendmsg_handle);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+ g_vehiclehalpol_thread = FrameworkunifiedCreateChildThread(happ, VEHICLEHAL_POL,
+ VehicleHalProcessPolStart,
+ VehicleHalProcessPolStop);
+
+ EFrameworkunifiedStatus estatus_pol = FrameworkunifiedStartChildThread(happ, g_vehiclehalpol_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus_pol) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedStartChildThread polling Failed");
+ McClose(g_sendmsg_handle);
+ return VEHICLEHAL_RET_ERR_THREADSTART;
+ }
+
+
+ // set open flag true
+ g_isopenflag = TRUE;
+
+ return VEHICLEHAL_RET_SUCCESS;
+}
+
+VEHICLEHAL_RET_TYPE VehicleHalStop(HANDLE happ) {
+ if (NULL == happ) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Handle is NULL");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+
+ if (NULL != g_vehiclehalext_thread) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedDestroyChildThread(happ, g_vehiclehalext_thread);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ g_vehiclehalext_thread = NULL;
+ }
+
+ // set open flag of polling to fasle
+ g_polloopendflag = TRUE;
+
+ if (NULL != g_vehiclehalpol_thread) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedStopChildThread(happ, g_vehiclehalpol_thread, 0, NULL);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread polling Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ estatus = FrameworkunifiedDestroyChildThread(happ, g_vehiclehalpol_thread);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "FrameworkunifiedDestroyChildThread polling Failed");
+ return VEHICLEHAL_RET_ERR_PARAM;
+ }
+ g_vehiclehalpol_thread = NULL;
+ }
+
+ // set open flag fasle
+ g_isopenflag = FALSE;
+
+ // exit loop
+ g_loopendflag = TRUE;
+
+ // destroy thead
+ pthread_join(g_threadid, NULL);
+
+ // Close message queue
+ McClose(g_sendmsg_handle);
+
+// // End VLC data input control API
+// VclCtlApiClose(&g_sclientobj);
+
+ return VEHICLEHAL_RET_SUCCESS;
+}
+
+void *VehicleHalProcess(void *arg) {
+ // Line Sense Message
+ VehicleHalLineSensMsg s_linesensmsg;
+ memset( &s_linesensmsg, 0xFF, sizeof(s_linesensmsg) );
+
+ // main loop
+ while (TRUE != g_loopendflag) {
+ char* p_env_vb = NULL;
+ p_env_vb = getenv(VEHICLEHAL_LINESENSKIND_VB_DATA);
+ if (NULL != p_env_vb) {
+ // low voltage
+ if (VEHICLEHAL_LOWVB_VALUE >= atoi(p_env_vb)) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_LOWVOLTAGE] = 1;
+ } else {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_LOWVOLTAGE] = 0;
+ }
+ }
+
+ // loop to get line sense status
+ for (UI_32 iloopnum = 0; iloopnum <= VEHICLEHAL_LINESENSKIND_ILL; ++iloopnum) {
+ // line sense status
+ UINT8 signalret = 0;
+
+// // get line sense status
+// UINT32 ret = VclCtlApiRcvVclData(&g_sclientobj, kLineSensList[iloopnum], &signalret);
+// if ( CARSIGNAL_CTL_RET_SUCCESS != ret ) {
+// FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Get LineSens [%d] status faild [%d]", kLineSensList[iloopnum], ret);
+// continue;
+// }
+
+ // convert 0 to 1 or 1 to 0 for IG,REV according car signal api reference
+ switch (kLineSensList[iloopnum]) {
+// case CARSIGNAL_IG:
+// case CARSIGNAL_REV:
+// signalret = 1 - signalret;
+// break;
+
+ default:
+ break;
+ }
+
+ // check status
+ if (signalret != s_linesensmsg.stdata[iloopnum]) {
+ s_linesensmsg.stdata[iloopnum] = signalret;
+ }
+ }
+
+ char* p_env_adim = NULL;
+ p_env_adim = getenv(VEHICLEHAL_LINESENSKIND_ADIM_DATA);
+ if (NULL != p_env_adim) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_ADIM] = atoi(p_env_adim);
+ }
+
+ char* p_env_mic = NULL;
+ p_env_mic = getenv(VEHICLEHAL_LINESENSKIND_MIC_DATA);
+ if (NULL != p_env_mic) {
+ s_linesensmsg.stdata[VEHICLEHAL_LINESENSKIND_MIC] = atoi(p_env_mic);
+ }
+
+ // send line sens
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS,
+ sizeof(s_linesensmsg), (PVOID)&s_linesensmsg);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend LineSens failed");
+ }
+
+ // wait 10ms
+ usleep(10000);
+ }
+ return NULL;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessExtStart(HANDLE happ) {
+ EFrameworkunifiedStatus estatus = FrameworkunifiedAttachCallbacksToDispatcher(happ, VEHICLEHAL_SPEED,
+ kVehicleHalSpd,
+ static_cast<UI_32>(_countof(kVehicleHalSpd)));
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __func__,
+ "Error FrameworkunifiedAttachCallbacksToDispatcher Vehicle_Hal_Speed:%d", estatus);
+ return estatus;
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessExtStop(HANDLE happ) {
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessRecvSpeed(HANDLE happ) {
+ // Speed Pusle Message
+ VehicleHalSpeedPulse speedpulsemsg;
+ memset( &speedpulsemsg, 0xFF, sizeof(speedpulsemsg) );
+
+ // get vehicle speed
+ UINT16 speed = 0;
+ EFrameworkunifiedStatus estatus = eFrameworkunifiedStatusOK;
+
+ estatus = FrameworkunifiedGetMsgDataOfSize(happ, &speed, sizeof(speed), eSMRRelease);
+ if (eFrameworkunifiedStatusOK != estatus) {
+ FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "failed FrameworkunifiedGetMsgDataOfSize() Status=[%d]", estatus);
+ return estatus;
+ }
+
+ // calculate speed to speed pulse
+ float speedpulse = static_cast<float>(speed * (4.0*637.0) / (60.0 * 60.0));
+ if ( speedpulse != speedpulsemsg.pulse ) {
+ speedpulsemsg.pulse = speedpulse;
+ if (0.0 != speedpulse) {
+ speedpulsemsg.period = static_cast<float>((1 / speedpulse) * 1000);
+ } else {
+ speedpulsemsg.period = 0;
+ }
+ }
+
+ // send line sens
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_SPDPULSE,
+ sizeof(speedpulsemsg), (PVOID)&speedpulsemsg);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Speed Pulse failed");
+ }
+
+ eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_SPD,
+ sizeof(UINT16), (PVOID)&speed);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Speed failed");
+ }
+
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessPolStart(HANDLE happ) {
+ VehicleHalPol s_pol;
+ memset( &s_pol, 0xFF, sizeof(s_pol) );
+
+ while (!g_polloopendflag) {
+ char* p_env_vb = NULL;
+ char* p_env_rheostat = NULL;
+ p_env_vb = getenv(VEHICLEHAL_LINESENSKIND_VB_DATA);
+ p_env_rheostat = getenv(VEHICLEHAL_LINESENSKIND_RHEOSTAT_DATA);
+ if (NULL != p_env_vb) {
+ // covert voltage value
+ s_pol.vb = atoi(p_env_vb);
+ }
+
+ if (NULL != p_env_rheostat) {
+ // covert RHEOSTAT value
+ s_pol.rheostat = atoi(p_env_rheostat);
+ }
+ // send vb and rheostat
+ EFrameworkunifiedStatus eretval = McSend(g_sendmsg_handle, TN_LINE_SENS_READ, CID_VEHICLEHAL_LINESENS_POL,
+ sizeof(s_pol), (PVOID)&s_pol);
+ if (eFrameworkunifiedStatusOK != eretval) {
+ FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "McSend Vb and RHEOSTAT failed");
+ }
+ // sleep 700ms
+ usleep(700000);
+ }
+ return eFrameworkunifiedStatusOK;
+}
+
+EFrameworkunifiedStatus VehicleHalProcessPolStop(HANDLE happ) {
+ return eFrameworkunifiedStatusOK;
+}