diff --git a/.gitignore b/.gitignore index 9580fac..482b082 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ bin/ build/ .vscode/ openauto.ini -CMakeLists.txt.user \ No newline at end of file +CMakeLists.txt.user +/cmake-build-*/ +.idea/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 85a64be..d204d66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,10 @@ cmake_minimum_required(VERSION 3.5.1) +if(CROSS_COMPILE_ARMHF) + message("Cross compiling for armhf") + set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc-8) + set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++-8) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf") +endif(CROSS_COMPILE) project(openauto CXX) set(CMAKE_AUTOMOC ON) @@ -27,7 +33,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-g -O3") add_definitions(-DBOOST_ALL_DYN_LINK) -find_package(Boost REQUIRED COMPONENTS system log OPTIONAL_COMPONENTS unit_test_framework) +find_package(Boost REQUIRED COMPONENTS system log_setup log OPTIONAL_COMPONENTS unit_test_framework) find_package(libusb-1.0 REQUIRED) find_package(Qt5 COMPONENTS Multimedia MultimediaWidgets Bluetooth Network) find_package(Protobuf REQUIRED) diff --git a/Readme.md b/Readme.md index 2deb2eb..d59e159 100644 --- a/Readme.md +++ b/Readme.md @@ -48,5 +48,24 @@ Copyrights (c) 2018 f1x.studio (Michal Szwaj) - Broadcom ilclient from RaspberryPI 3 firmware - OpenMAX IL API +### Building +#### Amd64 +Install the packages specified in the [prebuilts](https://github.com/opencardev/prebuilts) repository. Qt5 is required, versions packaged in modern Ubuntu and Debian +seem to work fine. + +You will also likely need to install the udev rules from `prebuilts` + +You need to point some CMAKE variables at your `aasdk` files. +```text +-DAASDK_INCLUDE_DIRS=/include +-DAASDK_LIBRARIES=/lib/libaasdk.so + DAASDK_PROTO_INCLUDE_DIRS= +-DAASDK_PROTO_LIBRARIES=/lib/libaasdk_proto.so +``` + +#### Raspberry Pi +Just run the scripts in the `prebuilts` repository for `aasdk` and `openauto`. It is possible to cross compile if your raspberry pi is too slow to compile the code itself. +However, its easiest to just develop on a more capable `amd64` device. + ### Remarks **This software is not certified by Google Inc. It is created for R&D purposes and may not work as expected by the original authors. Do not use while driving. You use this software at your own risk.** diff --git a/buildenv/Dockerfile b/buildenv/Dockerfile new file mode 100644 index 0000000..c5eebb1 --- /dev/null +++ b/buildenv/Dockerfile @@ -0,0 +1,49 @@ +FROM debian:buster AS prebuilts + +COPY ./buildenv/pi_binaries/buster.tar.gz buster.tar.gz +COPY ./buildenv/pi_binaries/aasdk_armhf.deb aasdk_armhf.deb +RUN apt-get update &&\ + apt-get -y install cmake build-essential git zip &&\ + git clone https://github.com/SonOfGib/prebuilts.git &&\ + mkdir qt5 &&\ + cat prebuilts/qt5/Qt_5151_armv7l_OpenGLES2.tar.xz* > Qt5_OpenGLES2.tar.xz + + +FROM debian:buster AS openauto + +COPY --from=prebuilts Qt5_OpenGLES2.tar.xz Qt5_OpenGLES2.tar.xz +COPY --from=prebuilts buster.tar.gz buster.tar.gz +COPY --from=prebuilts aasdk_armhf.deb aasdk_armhf.deb + +RUN dpkg --add-architecture armhf &&\ + apt-get update &&\ + apt-get -y install cmake build-essential git &&\ + apt-get -y install gcc-arm-linux-gnueabihf cpp-arm-linux-gnueabihf g++-arm-linux-gnueabihf protobuf-compiler &&\ + apt-get -y install gcc-8-base:armhf libc6:armhf libgcc1:armhf libicu63:armhf libidn2-0:armhf libstdc++6:armhf libunistring2:armhf pulseaudio:armhf librtaudio-dev:armhf libgps-dev:armhf libblkid-dev:armhf libtag1-dev:armhf libgles2-mesa-dev:armhf libdouble-conversion-dev:armhf &&\ + tar -xf Qt5_OpenGLES2.tar.xz -C / &&\ + tar -xf buster.tar.gz -C / + +# These are all the libboost requirements. It would be shorter if libboost-log-dev wasn't a disaster that's being dealt with manually. +RUN apt-get install -y libprotobuf-dev libusb-1.0.0-dev libssl-dev libboost-dev libboost-system-dev libboost-atomic1.67.0 libboost-chrono1.67.0 libboost-date-time1.67.0 libboost-filesystem1.67.0 libboost-regex1.67.0 libboost-thread1.67.0 libboost-filesystem1.67-dev libboost-thread1.67-dev libboost-date-time1.67-dev &&\ + apt-get install -y libprotobuf-dev:armhf libusb-1.0.0-dev:armhf libssl-dev:armhf libboost-dev:armhf libboost-system-dev:armhf libboost-atomic1.67.0:armhf libboost-chrono1.67.0:armhf libboost-date-time1.67.0:armhf libboost-filesystem1.67.0:armhf libboost-regex1.67.0:armhf libboost-system1.67.0:armhf libboost-thread1.67.0:armhf libboost-filesystem1.67-dev:armhf libboost-thread1.67-dev:armhf libboost-date-time1.67-dev:armhf + +COPY / /src + +WORKDIR /src + +# Import resources +COPY ./buildenv/patch-libboost-log-deb.sh /src/resources/patch-libboost-log-deb.sh +COPY ./buildenv/entrypoint.sh /entrypoint.sh + +# Patch libboost-log-dev and install +RUN chmod +x ./resources/patch-libboost-log-deb.sh +RUN ./resources/patch-libboost-log-deb.sh + +# Make Executable +RUN chmod +x /entrypoint.sh + +WORKDIR / +RUN dpkg-deb -xv aasdk_armhf.deb / + +WORKDIR /src +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] \ No newline at end of file diff --git a/buildenv/cross-compile.md b/buildenv/cross-compile.md new file mode 100644 index 0000000..520b929 --- /dev/null +++ b/buildenv/cross-compile.md @@ -0,0 +1,16 @@ +### RPI Cross Compile +The docker image in this folder is intended to be used to cross compile `openauto` without having to configure your +host pc with multiarch or installing a toolchain. + +#### Setup +The `openauto` build for RPI3 requires some files from the PI, as well as aasdk libraries compiled for amrhf. + + - RPI files should be compressed to `buildenv/pi_binaries/buster.tar.gz`. The files required in the archive should +match the path/files in the `if(RPI3_BUILD)` section of `CMakeLists.txt` + - Copy the `.deb` file from `aasdk` docker cross compile build and place it in `buildenv/pi_binaries/aasdk_armhf.dev` +#### Build +```bash +cd buildenv +sudo docker compose up --build +``` +Binary files will then be available in `buildenv/release`. \ No newline at end of file diff --git a/buildenv/docker-compose.yml b/buildenv/docker-compose.yml new file mode 100644 index 0000000..5cc1f5d --- /dev/null +++ b/buildenv/docker-compose.yml @@ -0,0 +1,7 @@ +services: + openauto-build: + build: + context: ../ + dockerfile: buildenv/Dockerfile + volumes: + - ./release/:/release/ \ No newline at end of file diff --git a/buildenv/entrypoint.sh b/buildenv/entrypoint.sh new file mode 100644 index 0000000..08160f4 --- /dev/null +++ b/buildenv/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Clear out the /build directory +mkdir build; +cd build; +cmake -DCMAKE_BUILD_TYPE=Release -DRPI3_BUILD=true -DCROSS_COMPILE_ARMHF=true -DAASDK_INCLUDE_DIRS=/usr/include/aasdk -DAASDK_LIBRARIES=/usr/lib/libaasdk.so -DAASDK_PROTO_INCLUDE_DIRS=/usr/include/aasdk_proto -DAASDK_PROTO_LIBRARIES=/usr/lib/libaasdk_proto.so ../ +make -j4 +cd ../bin + +# Move it to release +rm -f /release/autoapp +rm -f /release/btservice +mv autoapp /release +mv btservice /release \ No newline at end of file diff --git a/buildenv/patch-libboost-log-deb.sh b/buildenv/patch-libboost-log-deb.sh new file mode 100644 index 0000000..7454a91 --- /dev/null +++ b/buildenv/patch-libboost-log-deb.sh @@ -0,0 +1,46 @@ +# All this because of a packaging bug in libboost-log-dev +# 'Multi-Arch: same' is not present in the control file of Debian packages, all the way up to Sid +# Rather than recompiling the parent libbost suite, download the 6 packages, extract, edit, and repackage. + +# https://bugs.debian.org/cgi-bin/pkgreport.cgi?package=libboost-log-dev + +apt-get -y install --download-only libboost-log-dev:amd64 libboost-log1.67.0:amd64 libboost-log1.67-dev:amd64 +apt-get -y install --download-only libboost-log-dev:armhf libboost-log1.67.0:armhf libboost-log1.67-dev:armhf + +mkdir -p /tmp/armhf/libboost-log-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log-dev_1.67.0.1_armhf.deb /tmp/armhf/libboost-log-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log-dev_1.67.0.1_armhf.deb /tmp/armhf/libboost-log-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log-dev/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log-dev/ /tmp/libboost-log-dev_1.67.0.1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log-dev_1.67.0.1_amd64.deb /tmp/amd64/libboost-log-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log-dev_1.67.0.1_amd64.deb /tmp/amd64/libboost-log-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log-dev/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log-dev/ /tmp/libboost-log-dev_1.67.0.1_amd64.deb + +mkdir -p /tmp/armhf/libboost-log1.67-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log1.67-dev/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log1.67-dev/ /tmp/libboost-log1.67-dev_1.67.0-13+deb10u1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log1.67-dev/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67-dev/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67-dev/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log1.67-dev/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log1.67-dev/ /tmp/libboost-log1.67-dev_1.67.0-13+deb10u1_amd64.deb + +mkdir -p /tmp/armhf/libboost-log1.67.0/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67.0/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb /tmp/armhf/libboost-log1.67.0/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/armhf/libboost-log1.67.0/DEBIAN/control +dpkg-deb -b /tmp/armhf/libboost-log1.67.0/ /tmp/libboost-log1.67.0_1.67.0-13+deb10u1_armhf.deb + +mkdir -p /tmp/amd64/libboost-log1.67.0/ +dpkg-deb -x /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67.0/ +dpkg-deb -e /var/cache/apt/archives/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb /tmp/amd64/libboost-log1.67.0/DEBIAN/ +sed -i '/^Priority: optional/a Multi-Arch: same' /tmp/amd64/libboost-log1.67.0/DEBIAN/control +dpkg-deb -b /tmp/amd64/libboost-log1.67.0/ /tmp/libboost-log1.67.0_1.67.0-13+deb10u1_amd64.deb + +dpkg -i /tmp/libboost*.deb \ No newline at end of file diff --git a/buildenv/pi_binaries/.gitignore b/buildenv/pi_binaries/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/buildenv/pi_binaries/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/buildenv/release/.gitignore b/buildenv/release/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/buildenv/release/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/include/f1x/openauto/autoapp/App.hpp b/include/f1x/openauto/autoapp/App.hpp index 4ecd245..0af1e18 100644 --- a/include/f1x/openauto/autoapp/App.hpp +++ b/include/f1x/openauto/autoapp/App.hpp @@ -18,11 +18,11 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include diff --git a/include/f1x/openauto/autoapp/Projection/IAudioInput.hpp b/include/f1x/openauto/autoapp/Projection/IAudioInput.hpp index 67c3373..a85d588 100644 --- a/include/f1x/openauto/autoapp/Projection/IAudioInput.hpp +++ b/include/f1x/openauto/autoapp/Projection/IAudioInput.hpp @@ -19,8 +19,8 @@ #pragma once #include -#include -#include +#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp b/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp index c41de31..aaec03a 100644 --- a/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/IAudioOutput.hpp @@ -19,8 +19,8 @@ #pragma once #include -#include -#include +#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp b/include/f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp index 2d151fd..e5794cb 100644 --- a/include/f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp +++ b/include/f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #pragma once diff --git a/include/f1x/openauto/autoapp/Projection/IInputDevice.hpp b/include/f1x/openauto/autoapp/Projection/IInputDevice.hpp index 663fbbd..3c9256a 100644 --- a/include/f1x/openauto/autoapp/Projection/IInputDevice.hpp +++ b/include/f1x/openauto/autoapp/Projection/IInputDevice.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp b/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp index ef0f91c..0fdbe5b 100644 --- a/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/IVideoOutput.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Projection/InputEvent.hpp b/include/f1x/openauto/autoapp/Projection/InputEvent.hpp index fe22064..db47442 100644 --- a/include/f1x/openauto/autoapp/Projection/InputEvent.hpp +++ b/include/f1x/openauto/autoapp/Projection/InputEvent.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Projection/SequentialBuffer.hpp b/include/f1x/openauto/autoapp/Projection/SequentialBuffer.hpp index 153b687..179aabe 100644 --- a/include/f1x/openauto/autoapp/Projection/SequentialBuffer.hpp +++ b/include/f1x/openauto/autoapp/Projection/SequentialBuffer.hpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp index 0ae914c..8fc9b15 100644 --- a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp @@ -19,10 +19,10 @@ #pragma once #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -60,8 +60,10 @@ public: void onShutdownRequest(const aasdk::proto::messages::ShutdownRequest& request) override; void onShutdownResponse(const aasdk::proto::messages::ShutdownResponse& response) override; void onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request) override; - void onPingResponse(const aasdk::proto::messages::PingResponse& response) override; void onChannelError(const aasdk::error::Error& e) override; + void onPingRequest(const aasdk::proto::messages::PingRequest& request) override; + void onPingResponse(const aasdk::proto::messages::PingResponse& response) override; + void onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request) override; private: using std::enable_shared_from_this::shared_from_this; diff --git a/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp index b9fed4f..9c45e27 100644 --- a/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/include/f1x/openauto/autoapp/Service/AudioInputService.hpp b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp index c8e56c2..6b1dfba 100644 --- a/include/f1x/openauto/autoapp/Service/AudioInputService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include #include diff --git a/include/f1x/openauto/autoapp/Service/AudioService.hpp b/include/f1x/openauto/autoapp/Service/AudioService.hpp index 034ddec..51e5427 100644 --- a/include/f1x/openauto/autoapp/Service/AudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioService.hpp @@ -18,8 +18,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/include/f1x/openauto/autoapp/Service/BluetoothService.hpp b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp index 27b46d8..b5d8619 100644 --- a/include/f1x/openauto/autoapp/Service/BluetoothService.hpp +++ b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include #include diff --git a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp index 648d125..2ae816d 100644 --- a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp index 97b958b..5a174fd 100644 --- a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp @@ -18,8 +18,8 @@ #pragma once -#include -#include +#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/IPinger.hpp b/include/f1x/openauto/autoapp/Service/IPinger.hpp index d345ed3..c283c88 100644 --- a/include/f1x/openauto/autoapp/Service/IPinger.hpp +++ b/include/f1x/openauto/autoapp/Service/IPinger.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include namespace f1x { diff --git a/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp b/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp index 6049d9d..e7d724a 100644 --- a/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/InputService.hpp b/include/f1x/openauto/autoapp/Service/InputService.hpp index 03ed01b..0a1ee00 100644 --- a/include/f1x/openauto/autoapp/Service/InputService.hpp +++ b/include/f1x/openauto/autoapp/Service/InputService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp b/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp index bbd1414..0d25046 100644 --- a/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/SensorService.hpp b/include/f1x/openauto/autoapp/Service/SensorService.hpp index 93d96d6..66494fb 100644 --- a/include/f1x/openauto/autoapp/Service/SensorService.hpp +++ b/include/f1x/openauto/autoapp/Service/SensorService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp b/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp index d71f1a9..62d3199 100644 --- a/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp b/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp index af775b2..c0090ed 100644 --- a/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include namespace f1x diff --git a/include/f1x/openauto/autoapp/Service/VideoService.hpp b/include/f1x/openauto/autoapp/Service/VideoService.hpp index 391e1bc..24a8bfb 100644 --- a/include/f1x/openauto/autoapp/Service/VideoService.hpp +++ b/include/f1x/openauto/autoapp/Service/VideoService.hpp @@ -19,8 +19,8 @@ #pragma once #include -#include -#include +#include +#include #include #include diff --git a/include/f1x/openauto/autoapp/Service/WifiService.hpp b/include/f1x/openauto/autoapp/Service/WifiService.hpp index f9aefcf..d02b57b 100644 --- a/include/f1x/openauto/autoapp/Service/WifiService.hpp +++ b/include/f1x/openauto/autoapp/Service/WifiService.hpp @@ -21,7 +21,9 @@ #include #include #include -#include +#include +#include +#include namespace f1x { @@ -32,22 +34,27 @@ namespace autoapp namespace service { -class WifiService: public IService, public std::enable_shared_from_this +class WifiService: public aasdk::channel::wifi::IWIFIServiceChannelEventHandler, public IService, public std::enable_shared_from_this { public: typedef std::shared_ptr Pointer; - WifiService(configuration::IConfiguration::Pointer configuration); + WifiService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration); void start() override; void stop() override; void pause() override; void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; + void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; + void onChannelError(const aasdk::error::Error& e) override; + void onWifiSecurityRequest() override; private: using std::enable_shared_from_this::shared_from_this; configuration::IConfiguration::Pointer configuration_; + boost::asio::io_service::strand strand_; + aasdk::channel::wifi::WIFIServiceChannel::Pointer channel_; }; } diff --git a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp index f97d5fa..5d39d7a 100644 --- a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp +++ b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp @@ -3,8 +3,8 @@ #include #include #include -#include -#include +#include +#include #include namespace Ui { diff --git a/include/f1x/openauto/btservice/AndroidBluetoothServer.hpp b/include/f1x/openauto/btservice/AndroidBluetoothServer.hpp index bfa40d6..4eb540b 100644 --- a/include/f1x/openauto/btservice/AndroidBluetoothServer.hpp +++ b/include/f1x/openauto/btservice/AndroidBluetoothServer.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace f1x { diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp index 3967385..b016ea2 100644 --- a/src/autoapp/App.cpp +++ b/src/autoapp/App.cpp @@ -17,8 +17,8 @@ */ #include -#include -#include +#include +#include #include #include diff --git a/src/autoapp/Projection/OMXVideoOutput.cpp b/src/autoapp/Projection/OMXVideoOutput.cpp index f8f3808..6a46380 100644 --- a/src/autoapp/Projection/OMXVideoOutput.cpp +++ b/src/autoapp/Projection/OMXVideoOutput.cpp @@ -23,7 +23,7 @@ extern "C" #include } -#include +#include #include #include diff --git a/src/autoapp/Service/AndroidAutoEntity.cpp b/src/autoapp/Service/AndroidAutoEntity.cpp index 02986dd..cea74e5 100644 --- a/src/autoapp/Service/AndroidAutoEntity.cpp +++ b/src/autoapp/Service/AndroidAutoEntity.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #include #include @@ -238,6 +238,20 @@ void AndroidAutoEntity::onShutdownRequest(const aasdk::proto::messages::Shutdown controlServiceChannel_->sendShutdownResponse(response, std::move(promise)); } +void AndroidAutoEntity::onPingRequest(const aasdk::proto::messages::PingRequest& request) +{ + OPENAUTO_LOG(info) << "[AndroidAutoEntity] ping request "; + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + controlServiceChannel_->sendPingRequest(request, std::move(promise)); +} + +void AndroidAutoEntity::onVoiceSessionRequest(const aasdk::proto::messages::VoiceSessionRequest& request) +{ + OPENAUTO_LOG(error) << "[AndroidAutoEntity] voice session request not implemented"; +} + void AndroidAutoEntity::onShutdownResponse(const aasdk::proto::messages::ShutdownResponse&) { OPENAUTO_LOG(info) << "[AndroidAutoEntity] Shutdown response "; diff --git a/src/autoapp/Service/AndroidAutoEntityFactory.cpp b/src/autoapp/Service/AndroidAutoEntityFactory.cpp index d833250..9f0ace8 100644 --- a/src/autoapp/Service/AndroidAutoEntityFactory.cpp +++ b/src/autoapp/Service/AndroidAutoEntityFactory.cpp @@ -16,14 +16,14 @@ * along with openauto. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/src/autoapp/Service/MediaAudioService.cpp b/src/autoapp/Service/MediaAudioService.cpp index b754d21..b4bf247 100644 --- a/src/autoapp/Service/MediaAudioService.cpp +++ b/src/autoapp/Service/MediaAudioService.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #include namespace f1x diff --git a/src/autoapp/Service/SensorService.cpp b/src/autoapp/Service/SensorService.cpp index 851744e..7a47d6c 100644 --- a/src/autoapp/Service/SensorService.cpp +++ b/src/autoapp/Service/SensorService.cpp @@ -188,7 +188,7 @@ void SensorService::sendGPSLocationData() auto * locInd = indication.add_gps_location(); // epoch seconds - locInd->set_timestamp(this->gpsData_.fix.time * 1e3); + locInd->set_timestamp(this->gpsData_.fix.time.tv_sec); // degrees locInd->set_latitude(this->gpsData_.fix.latitude * 1e7); locInd->set_longitude(this->gpsData_.fix.longitude * 1e7); @@ -229,8 +229,7 @@ void SensorService::sensorPolling() if ((this->gpsEnabled_) && (gps_waiting(&this->gpsData_, 0)) && - (gps_read(&this->gpsData_) > 0) && - (this->gpsData_.status != STATUS_NO_FIX) && + (gps_read(&this->gpsData_, nullptr, 0) > 0) && (this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) && (this->gpsData_.set & TIME_SET) && (this->gpsData_.set & LATLON_SET)) diff --git a/src/autoapp/Service/ServiceFactory.cpp b/src/autoapp/Service/ServiceFactory.cpp index 9ef2e70..5d8d561 100644 --- a/src/autoapp/Service/ServiceFactory.cpp +++ b/src/autoapp/Service/ServiceFactory.cpp @@ -18,9 +18,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -68,7 +68,7 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng serviceList.emplace_back(this->createVideoService(messenger)); serviceList.emplace_back(this->createBluetoothService(messenger)); serviceList.emplace_back(this->createInputService(messenger)); - serviceList.emplace_back(std::make_shared(configuration_)); + serviceList.emplace_back(std::make_shared(ioService_, messenger, configuration_)); return serviceList; } diff --git a/src/autoapp/Service/SpeechAudioService.cpp b/src/autoapp/Service/SpeechAudioService.cpp index 5930095..47e9006 100644 --- a/src/autoapp/Service/SpeechAudioService.cpp +++ b/src/autoapp/Service/SpeechAudioService.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #include namespace f1x diff --git a/src/autoapp/Service/SystemAudioService.cpp b/src/autoapp/Service/SystemAudioService.cpp index 0998615..33f5f94 100644 --- a/src/autoapp/Service/SystemAudioService.cpp +++ b/src/autoapp/Service/SystemAudioService.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #include namespace f1x diff --git a/src/autoapp/Service/WifiService.cpp b/src/autoapp/Service/WifiService.cpp index f8d0d55..13b7220 100644 --- a/src/autoapp/Service/WifiService.cpp +++ b/src/autoapp/Service/WifiService.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace f1x @@ -30,26 +31,41 @@ namespace autoapp namespace service { -WifiService::WifiService(configuration::IConfiguration::Pointer configuration) +WifiService::WifiService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration) : configuration_(std::move(configuration)) + , strand_(ioService) + , channel_(std::make_shared(strand_, std::move(messenger))) { } void WifiService::start() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[WifiService] start."; + channel_->receive(this->shared_from_this()); + }); } void WifiService::stop() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[WifiService] stop."; + }); } void WifiService::pause() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[WifiService] pause."; + }); } void WifiService::resume() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[WifiService] resume."; + }); } void WifiService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) @@ -57,12 +73,47 @@ void WifiService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& OPENAUTO_LOG(info) << "[WifiService] fill features."; auto* channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(14); + channelDescriptor->set_channel_id(static_cast(channel_->getId())); auto* channel = channelDescriptor->mutable_wifi_channel(); channel->set_ssid(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","ssid").toStdString()); } +void WifiService::onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[WifiService] open request, priority: " << request.priority(); + const aasdk::proto::enums::Status::Enum status = aasdk::proto::enums::Status::OK; + OPENAUTO_LOG(info) << "[WifiService] open status: " << status; + + aasdk::proto::messages::ChannelOpenResponse response; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&WifiService::onChannelError, this->shared_from_this(), std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); +} + +void WifiService::onChannelError(const aasdk::error::Error &e) { + OPENAUTO_LOG(error) << "[WifiService] channel error: " << e.what(); +} + +void WifiService::onWifiSecurityRequest() { + OPENAUTO_LOG(info) << "[WifiService] handle Wifi Security Request "; + aasdk::proto::messages::WifiSecurityResponse response; + + response.set_access_point_type(aasdk::proto::messages::WifiSecurityResponse_AccessPointType_STATIC); + response.set_ssid(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","ssid").toStdString()); + response.set_key(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","wpa_passphrase").toStdString()); + // response.set_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString()); + response.set_security_mode(aasdk::proto::messages::WifiSecurityResponse_SecurityMode_WPA2_PERSONAL); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&WifiService::onChannelError, this->shared_from_this(), std::placeholders::_1)); + channel_->sendWifiSecurityResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); +} } } } diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index a2f1ea1..b8fcfd0 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -19,12 +19,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -38,7 +39,6 @@ #include #include -namespace aasdk = f1x::aasdk; namespace autoapp = f1x::openauto::autoapp; using ThreadPool = std::vector; @@ -71,8 +71,25 @@ void startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threa threadPool.emplace_back(ioServiceWorker); } +void configureLogging() { + const std::string logIni = "openauto-logs.ini"; + std::ifstream logSettings(logIni); + if (logSettings.good()) { + try { + // For boost < 1.71 the severity types are not automatically parsed so lets register them. + boost::log::register_simple_filter_factory("Severity"); + boost::log::register_simple_formatter_factory("Severity"); + boost::log::init_from_stream(logSettings); + } catch (std::exception const & e) { + OPENAUTO_LOG(warning) << "[OpenAuto] " << logIni << " was provided but was not valid."; + } + } +} + int main(int argc, char* argv[]) { + configureLogging(); + libusb_context* usbContext; if(libusb_init(&usbContext) != 0) { diff --git a/src/btservice/AndroidBluetoothServer.cpp b/src/btservice/AndroidBluetoothServer.cpp index ee3bfd6..08ec2ac 100644 --- a/src/btservice/AndroidBluetoothServer.cpp +++ b/src/btservice/AndroidBluetoothServer.cpp @@ -23,6 +23,7 @@ #include #include #include + #include #include #include @@ -61,7 +62,7 @@ namespace f1x { // connect(socket, &QBluetoothSocket::disconnected, this, // QOverload<>::of(&ChatServer::clientDisconnected)); - f1x::aasdk::proto::messages::WifiInfoRequest request; + ::aasdk::proto::messages::WifiInfoRequest request; request.set_ip_address(getIP4_("wlan0")); request.set_port(5000); @@ -121,26 +122,26 @@ namespace f1x { } void AndroidBluetoothServer::handleWifiInfoRequest(QByteArray &buffer, uint16_t length) { - f1x::aasdk::proto::messages::WifiInfoRequest msg; + ::aasdk::proto::messages::WifiInfoRequest msg; msg.ParseFromArray(buffer.data() + 4, length); OPENAUTO_LOG(info) << "WifiInfoRequest: " << msg.DebugString(); - f1x::aasdk::proto::messages::WifiInfoResponse response; + ::aasdk::proto::messages::WifiInfoResponse response; response.set_ip_address(getIP4_("wlan0")); response.set_port(5000); - response.set_status(aasdk::proto::messages::WifiInfoResponse_Status_STATUS_SUCCESS); + response.set_status(::aasdk::proto::messages::WifiInfoResponse_Status_STATUS_SUCCESS); sendMessage(response, 7); } void AndroidBluetoothServer::handleWifiSecurityRequest(QByteArray &buffer, uint16_t length) { - f1x::aasdk::proto::messages::WifiSecurityReponse response; + ::aasdk::proto::messages::WifiSecurityResponse response; response.set_ssid(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","ssid").toStdString()); - response.set_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString()); + // response.set_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString()); response.set_key(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","wpa_passphrase").toStdString()); - response.set_security_mode(aasdk::proto::messages::WifiSecurityReponse_SecurityMode_WPA2_PERSONAL); - response.set_access_point_type(aasdk::proto::messages::WifiSecurityReponse_AccessPointType_STATIC); + response.set_security_mode(::aasdk::proto::messages::WifiSecurityResponse_SecurityMode_WPA2_PERSONAL); + response.set_access_point_type(::aasdk::proto::messages::WifiSecurityResponse_AccessPointType_STATIC); sendMessage(response, 3); } @@ -170,7 +171,7 @@ namespace f1x { } void AndroidBluetoothServer::handleWifiInfoRequestResponse(QByteArray &buffer, uint16_t length) { - f1x::aasdk::proto::messages::WifiInfoResponse msg; + ::aasdk::proto::messages::WifiInfoResponse msg; msg.ParseFromArray(buffer.data() + 4, length); OPENAUTO_LOG(info) << "WifiInfoResponse: " << msg.DebugString(); } @@ -184,4 +185,4 @@ namespace f1x { } } } -} \ No newline at end of file +}