diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..3c73f32a --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium +# This defaults to 'Auto'. Explicitly set it for a while, so that +# 'vector >' in existing files gets formatted to +# 'vector>'. ('Auto' means that clang-format will only use +# 'int>>' if the file already contains at least one such instance.) +Standard: Cpp11 +SortIncludes: true +--- +Language: ObjC +ColumnLimit: 100 diff --git a/.gitignore b/.gitignore index 9ae90c01..9045cc99 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,11 @@ *.project *.workspace .idea/ -CMakeLists.txt cmake-build-debug/ mazda/installer/config/androidauto/data_persist/dev/bin/headunit *.creator.user bin/ */version\.h -.vscode \ No newline at end of file +.vscode +build +third_party \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7e3f3034..211b3067 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,70 @@ -dist: trusty +dist: focal + addons: apt: packages: - - libdbus-c++-bin + - libssl-dev + - libusb-1.0-0-dev + - libgstreamer1.0-dev + - gstreamer1.0-gl + - libgstreamer-plugins-base1.0-dev + - libgstreamer-plugins-bad1.0-dev + - protobuf-compiler + - libprotobuf-dev + - libsdl1.2-dev + - libsdl2-dev + - libgtk-3-dev + - libudev-dev + - libunwind-dev + - libtool-bin + - libefl-all-dev + language: cpp -before_script: cd mazda -script: make clean release -deploy: - - provider: releases - api_key: $GITHUB_TOKEN - file: AndroidAuto_*.zip - file_glob: true - overwrite: true - skip_cleanup: true - on: - tags: true + +compiler: + - gcc + - clang + +arch: + - amd64 + - arm64 + +env: + jobs: + - BUILD_TYPE=Debug CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local" + - BUILD_TYPE=Release CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local" + - BUILD_TYPE=MinSizeRel CMAKE_ARGS="-DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local" + - BUILD_TYPE=Debug + CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake + -DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local + -DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a + -DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include + -DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a + -DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include" + export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig + export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH + - BUILD_TYPE=Release + CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake + -DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local + -DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a + -DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include + -DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a + -DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include" + export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig + export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH + - BUILD_TYPE=MinSizeRel + CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=${TRAVIS_BUILD_DIR}/cmake/gcc-toolchain.cmake + -DBUILD_MAZDA=ON -DCMAKE_STAGING_PREFIX=`pwd`/staging/usr/local + -DOPENSSL_CRYPTO_LIBRARY=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a + -DOPENSSL_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include + -DProtobuf_LIBRARIES=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a + -DProtobuf_INCLUDE_DIR=${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include" + export PKG_CONFIG_PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/pkgconfig:${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/pkgconfig + export PATH=${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/bin:$PATH + +script: + - env + - cd ${TRAVIS_BUILD_DIR} + - mkdir build && cd build + - cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${CMAKE_ARGS} + - make install -j diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..11c360c2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,116 @@ +cmake_minimum_required(VERSION 3.10.2) + +if(NOT CMAKE_MODULE_PATH) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +elseif() + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +endif() + +project(AAHU LANGUAGES CXX) + +option(BUILD_MAZDA "Builds Mazda version of Android Auto" OFF) +option(BUILD_UBUNTU "Builds Ubuntu version of Android Auto" ON) +if(BUILD_MAZDA) + set(BUILD_UBUNTU OFF) +elseif(BUILD_UBUNTU) + set(BUILD_MAZDA OFF) +endif() + +include(deps) + +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) + +protobuf_generate_cpp(PROTO_SRC PROTO_HEADER hu/hu.proto) + +set(SRC_FILES + hu/hu_aap.cpp + hu/hu_aad.cpp + hu/hu_ssl.cpp + hu/hu_usb.cpp + hu/hu_uti.cpp + hu/hu_tcp.cpp + ${PROTO_HEADER} ${PROTO_SRC} + + common/audio.cpp + common/command_server.cpp + common/config.cpp + common/glib_utils.cpp + common/web++/web++.cpp +) + +set(MAZDA_SRC + mazda/bt/mzd_bluetooth.cpp + mazda/gps/mzd_gps.cpp + mazda/hud/hud.cpp + mazda/nm/mzd_nightmode.cpp + mazda/callbacks.cpp + mazda/outputs.cpp + mazda/main.cpp +) + +set(UBUNTU_SRC + ubuntu/bt/ub_bluetooth.cpp + ubuntu/main.cpp + ubuntu/outputs.cpp + ubuntu/callbacks.cpp +) + +if(BUILD_MAZDA) + list(APPEND SRC_FILES ${MAZDA_SRC}) +endif() + +if(BUILD_UBUNTU) + list(APPEND SRC_FILES ${UBUNTU_SRC}) +endif() + +add_executable(headunit ${SRC_FILES}) + +target_include_directories(headunit PUBLIC + hu common + ${GTK3_INCLUDE_DIRS} + ${USB_INCLUDE_DIRS} + ${GST_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SYSROOT}/usr/include/SDL2 +) + +target_compile_options(headunit PUBLIC + -Wno-narrowing + -D__STDC_FORMAT_MACROS + -DDBUS_API_SUBJECT_TO_CHANGE +) + +target_link_libraries(headunit PUBLIC + ${GST_LIBRARIES} + ${GTK3_LIBRARIES} + ${X11_LIBRARIES} + ${ALSA_LIBRARIES} + ${Protobuf_LIBRARY} + ${GLFW_STATIC_LIBRARY} + ${SDL2_LIBRARIES} + ${UDEV_LIBRARIES} + ${USB_LIBRARIES} + ${UNWIND_LIBRARIES} + OpenSSL::Crypto + OpenSSL::SSL + Threads::Threads + -v +) + +if(BUILD_MAZDA) + target_compile_options(headunit PUBLIC -static-libstdc++ -DCMU=1) + + target_include_directories(headunit PUBLIC + ${CMAKE_STAGING_PREFIX}/include + ${THIRD_PARTY_DIR}/dbus-cplusplus + ${CMAKE_STAGING_PREFIX}/include/dbus-c++-1) + + target_link_libraries(headunit PUBLIC + ${CMAKE_STAGING_PREFIX}/lib/libdbus-c++-1.a + ${CMAKE_STAGING_PREFIX}/lib/libdbus-c++-glib-1.a + ${DBUS_LIBRARIES}) +endif() + +install(TARGETS headunit RUNTIME DESTINATION bin) diff --git a/cmake/FindDBus.cmake b/cmake/FindDBus.cmake new file mode 100644 index 00000000..1d0f29dd --- /dev/null +++ b/cmake/FindDBus.cmake @@ -0,0 +1,59 @@ +# - Try to find DBus +# Once done, this will define +# +# DBUS_FOUND - system has DBus +# DBUS_INCLUDE_DIRS - the DBus include directories +# DBUS_LIBRARIES - link these to use DBus +# +# Copyright (C) 2012 Raphael Kubo da Costa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS +# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PC_DBUS QUIET dbus-1) + +FIND_LIBRARY(DBUS_LIBRARIES + NAMES dbus-1 + HINTS ${PC_DBUS_LIBDIR} + ${PC_DBUS_LIBRARY_DIRS} +) + +FIND_PATH(DBUS_INCLUDE_DIR + NAMES dbus/dbus.h + HINTS ${PC_DBUS_INCLUDEDIR} + ${PC_DBUS_INCLUDE_DIRS} +) + +GET_FILENAME_COMPONENT(_DBUS_LIBRARY_DIR ${DBUS_LIBRARIES} PATH) +FIND_PATH(DBUS_ARCH_INCLUDE_DIR + NAMES dbus/dbus-arch-deps.h + HINTS ${PC_DBUS_INCLUDEDIR} + ${PC_DBUS_INCLUDE_DIRS} + ${_DBUS_LIBRARY_DIR} + ${DBUS_INCLUDE_DIR} + PATH_SUFFIXES include +) + +SET(DBUS_INCLUDE_DIRS ${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(DBUS REQUIRED_VARS DBUS_INCLUDE_DIRS DBUS_LIBRARIES) \ No newline at end of file diff --git a/cmake/dbus.patch b/cmake/dbus.patch new file mode 100644 index 00000000..52f79263 --- /dev/null +++ b/cmake/dbus.patch @@ -0,0 +1,54 @@ +diff --git a/include/dbus-c++/dispatcher.h b/include/dbus-c++/dispatcher.h +index b5b5536..b7a4534 100644 +--- a/include/dbus-c++/dispatcher.h ++++ b/include/dbus-c++/dispatcher.h +@@ -267,6 +267,18 @@ struct Threading + return new Mx; + } + ++#ifndef DBUS_HAS_RECURSIVE_MUTEX ++ static bool mutex_free(Mutex *mx) ++ { ++ delete mx; ++ return false; ++ } ++ static bool mutex_lock(Mutex *mx) ++ { ++ mx->lock(); ++ return false; ++ } ++#else + static void mutex_free(Mutex *mx) + { + delete mx; +@@ -276,6 +288,7 @@ struct Threading + { + mx->lock(); + } ++#endif//DBUS_HAS_RECURSIVE_MUTEX + + static void mutex_unlock(Mutex *mx) + { +diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp +index 0cc65c3..5776971 100644 +--- a/src/eventloop-integration.cpp ++++ b/src/eventloop-integration.cpp +@@ -38,6 +38,7 @@ + #include + #include + #include ++#include + + using namespace DBus; + using namespace std; +diff --git a/src/pipe.cpp b/src/pipe.cpp +index 01211b3..d0572c7 100644 +--- a/src/pipe.cpp ++++ b/src/pipe.cpp +@@ -83,5 +83,5 @@ ssize_t Pipe::read(void *buffer, unsigned int &nbytes) + void Pipe::signal() + { + // TODO: ignoring return of read/write generates warning; maybe relevant for eventloop work... +- ::write(_fd_write, '\0', 1); ++ ::write(_fd_write, "\0", 1); + } diff --git a/cmake/deps.cmake b/cmake/deps.cmake new file mode 100644 index 00000000..3fa56aed --- /dev/null +++ b/cmake/deps.cmake @@ -0,0 +1,70 @@ + +find_package(Threads REQUIRED) +find_package(OpenSSL REQUIRED) +find_package(Protobuf REQUIRED) +find_package(SDL2 REQUIRED) +find_package(ALSA REQUIRED) +find_package(X11 REQUIRED) + +find_package(PkgConfig REQUIRED) +if(PKG_CONFIG_EXECUTABLE) + + pkg_check_modules(GST REQUIRED gstreamer-1.0 + gstreamer-video-1.0 + gstreamer-app-1.0 + gstreamer-audio-1.0 + gstreamer-codecparsers-1.0) + + pkg_check_modules(USB REQUIRED libusb-1.0) + pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + pkg_check_modules(UNWIND REQUIRED libunwind) + pkg_check_modules(UDEV REQUIRED libudev) +endif() + +find_package(Git) +if(GIT_EXECUTABLE) + execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND "${GIT_EXECUTABLE}" describe --tags --always + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(BUILD_HASH ${GIT_HASH}) + + if (NOT REPRODUCIBLE) + execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND "whoami" + OUTPUT_VARIABLE GIT_USER + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND "hostname" + OUTPUT_VARIABLE GIT_HOST + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER}) + set(BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH}) + endif() + + message("Git commit hash: ${BUILD_HASH}") + + configure_file(cmake/version.in.h ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY) +endif() + +if(BUILD_MAZDA) + set(GEN_DBUS_HEADER_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mazda/dbus/dbusxx-xml2cpp) + add_custom_command(TARGET dbus-cplusplus POST_BUILD + COMMAND ${GEN_DBUS_HEADER_COMMAND} cmu_interfaces.xml --proxy=generated_cmu.h + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mazda/dbus + COMMENT "Generating generated_cmu.h") + + set(DBUS1_LIBRARY="${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libdbus-1.so.3.7.12") + + set(OPENSSL_CRYPTO_LIBRARY="${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/lib/libcrypto.a") + set(OPENSSL_INCLUDE_DIR="${TRAVIS_BUILD_DIR}/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/usr/include") + + set(Protobuf_LIBRARIES="${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/lib/libprotobuf-lite.a") + set(Protobuf_INCLUDE_DIR="${TRAVIS_BUILD_DIR}/mazda/protobuf-2.6.1-arm/include") +endif() \ No newline at end of file diff --git a/cmake/gcc-toolchain.cmake b/cmake/gcc-toolchain.cmake new file mode 100644 index 00000000..e20bd4ba --- /dev/null +++ b/cmake/gcc-toolchain.cmake @@ -0,0 +1,139 @@ +# +# MIT License +# +# Copyright (c) 2019 Joel Winarske +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +include_guard() + +IF(NOT TRIPLE) + set(TRIPLE arm-cortexa9_neon-linux-gnueabi) +endif() + +message(STATUS "Triple ................. ${TRIPLE}") + +STRING(REGEX REPLACE "^([a-zA-Z0-9]+).*" "\\1" target_arch "${TRIPLE}") +message(STATUS "Triple Arch ............ ${target_arch}") + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ${target_arch}) + + +if(MINGW OR CYGWIN OR WIN32) + set(UTIL_SEARCH_CMD where) +elseif(UNIX OR APPLE) + set(UTIL_SEARCH_CMD which) +endif() + +execute_process( + COMMAND ${UTIL_SEARCH_CMD} ${TRIPLE}-g++ + OUTPUT_VARIABLE BINUTILS_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +get_filename_component(TOOLCHAIN_PATH ${BINUTILS_PATH} DIRECTORY) + +message(STATUS "Toolchain Path ......... ${TOOLCHAIN_PATH}") + +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_AR ${TRIPLE}-ar) +set(CMAKE_ASM_COMPILER ${TRIPLE}-gcc) +set(CMAKE_CC_COMPILER ${TRIPLE}-gcc) + +if("${TRIPLE}" STREQUAL "x86_64-w64-mingw32" AND "${TARGET}" STREQUAL "host") + set(CMAKE_CXX_COMPILER ${TRIPLE}-g++-posix) +else() + set(CMAKE_CXX_COMPILER ${TRIPLE}-g++) +endif() + + +set(CPPFILT ${TRIPLE}-c++filt) +set(NM ${TRIPLE}-nm) +set(OBJDUMP ${TRIPLE}-objdump) +set(OBJCOPY ${TRIPLE}-objcopy) +set(READELF ${TRIPLE}-readelf) +set(SIZE ${TRIPLE}-size) + + +set(GCCFLAGS + -g + -Wall + -Wextra + -pedantic + -Wmain + -Wundef + -Wsign-conversion + -Wunused-parameter + -Wuninitialized + -Wmissing-declarations + -Wshadow + -Wunreachable-code + -Wswitch-default + -Wswitch-enum + -Wcast-align + -Wmissing-include-dirs + -Winit-self + -Wfloat-equal + -Wdouble-promotion + -gdwarf-2 + -fno-exceptions + -ffunction-sections + -fdata-sections +) + +set(_CFLAGS ${GCCFLAGS} + -Wunsuffixed-float-constants + -x c + -std=c99 +) + +set(_CPPFLAGS ${GCCFLAGS} + -x c++ + -fno-rtti + -fstrict-enums + -fno-use-cxa-atexit + -fno-use-cxa-get-exception-ptr + -fno-nonansi-builtins + -fno-threadsafe-statics + -fno-enforce-eh-specs + -ftemplate-depth=32 + -Wzero-as-null-pointer-constant +) + +set(_AFLAGS ${GCCFLAGS} + -x assembler +) + +set(_LDFLAGS ${GCCFLAGS} + -x none + -Wl,--gc-sections +) + +# remove list item delimeter +string(REPLACE ";" " " CFLAGS "${_CFLAGS}") +string(REPLACE ";" " " CPPFLAGS "${_CPPFLAGS}") +string(REPLACE ";" " " AFLAGS "${_AFLAGS}") +string(REPLACE ";" " " LDFLAGS "${_LDFLAGS}") \ No newline at end of file diff --git a/cmake/version.in.h b/cmake/version.in.h new file mode 100644 index 00000000..3b6b7033 --- /dev/null +++ b/cmake/version.in.h @@ -0,0 +1,2 @@ + +#define HEADUNIT_VERSION "@BUILD_HASH@" diff --git a/common/audio.h b/common/audio.h index f16a3765..0ed5ec4c 100644 --- a/common/audio.h +++ b/common/audio.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include "hu_uti.h" diff --git a/hu/hu_aad.cpp b/hu/hu_aad.cpp index 6b6744c3..47ef9567 100644 --- a/hu/hu_aad.cpp +++ b/hu/hu_aad.cpp @@ -234,13 +234,13 @@ Channel specified for each service: if (log_dmp) { //logd ("iaad_dmp_arry n: %d num: %d alen: %ld", n, num, alen); // Dump raw array - char str_buf [256] = {0}; + char str_buf [255] = {0}; int ctr = 0; for (ctr = 0; ctr < n - 1; ctr ++) strncat (str_buf, " ", sizeof(str_buf) - strlen(str_buf) - 1); char str_buf2 [256] = {0}; - snprintf (str_buf2, sizeof (str_buf), "%s%1.1u", str_buf, num); // Dump raw array + snprintf (str_buf2, sizeof (str_buf2), "%s%1.1u", str_buf, num); // Dump raw array hex_dump (str_buf2, 16, buf, alen); } diff --git a/hu/hu_aap.cpp b/hu/hu_aap.cpp index 68c64246..43dbab38 100644 --- a/hu/hu_aap.cpp +++ b/hu/hu_aap.cpp @@ -1166,6 +1166,7 @@ delete ptr; loge("hu_queue_command error %d", ret); } + return ret; } int HUServer::hu_aap_shutdown() @@ -1285,7 +1286,8 @@ { logd("Got command_read_fd"); IHUAnyThreadInterface::HUThreadCommand* ptr = nullptr; - if(ptr = hu_pop_command()) + ptr = hu_pop_command(); + if(ptr) { logd("Running %p", ptr); (*ptr)(*this); diff --git a/hu/hu_ssl.cpp b/hu/hu_ssl.cpp index d3f6e5b7..50629c44 100644 --- a/hu/hu_ssl.cpp +++ b/hu/hu_ssl.cpp @@ -138,7 +138,7 @@ else logd ("BIO_free(pkey_bio) ret: %d", ret); - hu_ssl_method = (SSL_METHOD *) TLSv1_2_client_method (); + hu_ssl_method = (SSL_METHOD *)SSLv23_client_method(); if (hu_ssl_method == NULL) { loge ("TLSv1_2_client_method() error"); return (-1); diff --git a/hu/hu_usb.cpp b/hu/hu_usb.cpp index 67ebfeb1..6074148c 100644 --- a/hu/hu_usb.cpp +++ b/hu/hu_usb.cpp @@ -5,7 +5,7 @@ #include -#include +#include #ifndef LIBUSB_LOG_LEVEL_NONE #define LIBUSB_LOG_LEVEL_NONE 0 @@ -355,7 +355,7 @@ int HUTransportStreamUSB::Start(bool waitForDevice) { return (-1); } - libusb_set_debug(iusb_ctx, LIBUSB_LOG_LEVEL_INFO); + libusb_set_option(iusb_ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO); //See if there is a OAP device already while ((iusb_dev_hndl = find_oap_device()) == nullptr) diff --git a/hu/hu_usb.h b/hu/hu_usb.h index f168d5fc..9636cef1 100644 --- a/hu/hu_usb.h +++ b/hu/hu_usb.h @@ -1,6 +1,6 @@ #include "hu_aap.h" #include -#include +#include #include #include #include diff --git a/hu/hu_uti.cpp b/hu/hu_uti.cpp index 95d9607e..06d4a22f 100644 --- a/hu/hu_uti.cpp +++ b/hu/hu_uti.cpp @@ -31,7 +31,7 @@ #include // For opendir (), readdir (), closedir (), DIR, struct dirent. #include -#include +#include #include #include // for dladdr #include // for __cxa_demangle @@ -102,7 +102,7 @@ int hu_log (int prio, const char * tag, const char * func, const char * fmt, ... //Time doesn't work on CMU anyway, always says 1970 time_t timestamp; time(×tamp); - printf ("%d %s: %s: %s : %s\n", timestamp, prio_get (prio), tag, func, log_line); + printf ("%ld %s: %s: %s : %s\n", timestamp, prio_get (prio), tag, func, log_line); va_end(aq); #endif @@ -145,15 +145,15 @@ void hex_dump (const char * prefix, int width, unsigned char * buf, int len) { if (prefix) //strlcpy (line, prefix, sizeof (line)); - strlcat (line, prefix, sizeof(line)); + strlcat (line, prefix, sizeof(line) - strlen(line) - 1); snprintf (tmp, sizeof (tmp), " %8.8x ", 0); - strlcat (line, tmp, sizeof(line) - strlen(line)); + strlcat (line, tmp, sizeof(line) - strlen(line) - 1); for (i = 0, n = 1; i < len; i ++, n ++) { // i keeps incrementing, n gets reset to 0 each line snprintf (tmp, sizeof (tmp), "%2.2x ", buf [i]); - strlcat (line, tmp, sizeof(line) - strlen(line)); // Append 2 bytes hex and space to line + strlcat (line, tmp, sizeof(line) - strlen(line) - 1); // Append 2 bytes hex and space to line if (n == width) { // If at specified line width n = 0; // Reset position in line counter @@ -162,11 +162,11 @@ void hex_dump (const char * prefix, int width, unsigned char * buf, int len) { line [0] = 0; if (prefix) //strlcpy (line, prefix, sizeof (line)); - strlcat (line, prefix, sizeof(line) - strlen(line)); + strlcat (line, prefix, sizeof(line) - strlen(line) - 1); //snprintf (tmp, sizeof (tmp), " %8.8x ", i + 1); snprintf (tmp, sizeof (tmp), " %4.4x ", i + 1); - strlcat (line, tmp, sizeof(line) - strlen(line)); + strlcat (line, tmp, sizeof(line) - strlen(line) - 1); } else if (i == len - 1) // Else if at last byte logd (line); // Log line @@ -322,6 +322,7 @@ void hu_install_crash_handler() sigaction(SIGXFSZ, &sigact, nullptr); std::set_terminate (crash_handler_terminate); } + int wait_for_device_connection(){ int ret; diff --git a/mazda/callbacks.h b/mazda/callbacks.h index 2481806c..d1db1d27 100644 --- a/mazda/callbacks.h +++ b/mazda/callbacks.h @@ -7,7 +7,7 @@ #include "command_server.h" #include "audio.h" #include -#include +#include #include "dbus/generated_cmu.h" #include "version.h" diff --git a/mazda/dbus/dbusxx-xml2cpp b/mazda/dbus/dbusxx-xml2cpp index d7c9dab4..09731e9d 100755 Binary files a/mazda/dbus/dbusxx-xml2cpp and b/mazda/dbus/dbusxx-xml2cpp differ diff --git a/mazda/outputs.cpp b/mazda/outputs.cpp index 08c970ad..46520b88 100644 --- a/mazda/outputs.cpp +++ b/mazda/outputs.cpp @@ -435,19 +435,19 @@ VideoOutput::VideoOutput(MazdaEventCallbacks* callbacks) if (ioctl(ui_fd, UI_SET_EVBIT, EV_KEY) < 0) { - fprintf(stderr, "UI_SET_EVBIT failed on %s\n", EV_KEY); + fprintf(stderr, "UI_SET_EVBIT failed on %c\n", EV_KEY); } if (ioctl(ui_fd, UI_SET_KEYBIT, KEY_LEFTBRACE) < 0) { - fprintf(stderr, "UI_SET_KEYBIT failed on %s\n", KEY_LEFTBRACE); + fprintf(stderr, "UI_SET_KEYBIT failed on %c\n", KEY_LEFTBRACE); } if (ioctl(ui_fd, UI_SET_KEYBIT, KEY_RIGHTBRACE) < 0) { - fprintf(stderr, "UI_SET_KEYBIT failed on %s\n", KEY_RIGHTBRACE); + fprintf(stderr, "UI_SET_KEYBIT failed on %c\n", KEY_RIGHTBRACE); } if (ioctl(ui_fd, UI_SET_KEYBIT, KEY_E) < 0) { - fprintf(stderr, "UI_SET_KEYBIT failed on %s\n", KEY_E); + fprintf(stderr, "UI_SET_KEYBIT failed on %c\n", KEY_E); } struct uinput_user_dev uidev; memset(&uidev, 0, sizeof(uidev)); @@ -534,9 +534,9 @@ VideoOutput::~VideoOutput() void VideoOutput::MediaPacket(uint64_t timestamp, const byte *buf, int len) { GstBuffer * buffer = gst_buffer_new_and_alloc(len); - memcpy(GST_BUFFER_DATA(buffer), buf, len); - int ret = gst_app_src_push_buffer(vid_src, buffer); - if(ret != GST_FLOW_OK){ + gst_buffer_fill(buffer, 0, buf, len); + int ret = gst_app_src_push_buffer((GstAppSrc *) vid_src, buffer); + if (ret != GST_FLOW_OK) { printf("push buffer returned %d for %d bytes \n", ret, len); } } diff --git a/ubuntu/callbacks.cpp b/ubuntu/callbacks.cpp index 7de703c0..220c9ac5 100644 --- a/ubuntu/callbacks.cpp +++ b/ubuntu/callbacks.cpp @@ -204,7 +204,7 @@ void DesktopEventCallbacks::HandleNaviStatus(IHUConnectionThreadInterface& strea void DesktopEventCallbacks::HandleNaviTurn(IHUConnectionThreadInterface& stream, const HU::NAVTurnMessage &request){ const char *event_name = &request.event_name()[0]; std::string image = request.image(); - printf(event_name); + printf("%s", event_name); logv ("AA_CH_NAVI: %s, TurnSide: %d, TurnEvent:%d, TurnNumber: %d, TurnAngle: %d", event_name, request.turn_side(), request.turn_event(), request.turn_number(), request.turn_angle()); hex_dump("AA_CH_NAVI", 256, (unsigned char*)image.c_str(), image.length()); } diff --git a/ubuntu/callbacks.h b/ubuntu/callbacks.h index 04af3793..856bf284 100644 --- a/ubuntu/callbacks.h +++ b/ubuntu/callbacks.h @@ -6,7 +6,7 @@ #include "audio.h" #include "command_server.h" -#include +#include #include "version.h" class VideoOutput;