Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
301d533
initial wifi autoconfig
silverchris Nov 6, 2020
7a7d33b
detect wireless settings
silverchris Nov 7, 2020
a511dac
hack startup script
silverchris Nov 7, 2020
7bebd50
shutdown from dbus signal
silverchris Nov 8, 2020
58374c7
simplify day/night mode checking
silverchris Nov 8, 2020
f124085
Fix thread exiting
silverchris Nov 8, 2020
c39b2f3
handle HUD not being initialized
silverchris Nov 8, 2020
2838661
Stop the main loop when we get the signal to exit
silverchris Nov 8, 2020
bfb7d0d
Allow command server to be stopped
silverchris Nov 8, 2020
550b112
Do we need to close dbus connections? dbus-c++ is not so great on the…
silverchris Nov 8, 2020
af8e818
give everything a couple seconds to settle out.
silverchris Nov 8, 2020
28bc6a1
Trying to fix the crashing instead of exiting
silverchris Nov 8, 2020
392ae8b
Try and connect to our Bluetooth service once we start, to try and st…
silverchris Nov 9, 2020
be8d49c
Code quality improvements
silverchris Nov 10, 2020
bd320ba
shutdown without crashing
silverchris Nov 10, 2020
ead834d
Don't actually need this
silverchris Nov 10, 2020
1a07cd1
Set GPS update rate back
silverchris Nov 10, 2020
57f5875
Some code quality improvements
silverchris Nov 10, 2020
479d6cf
Don't use DBus to get IP and MAC. It's not reliable.
silverchris Nov 12, 2020
7a9d89f
Trying new and interesting ways to solve our exiting issues
silverchris Nov 12, 2020
b738b69
Include BdsConfiguration.xml, as that will be needed to be deployed t…
silverchris Nov 12, 2020
509b9fd
detect usb or wifi in the program, instead of relying on the shell sc…
silverchris Nov 12, 2020
72a568f
Move GPS thread function into gps/mzd_gps.cpp, instead of main.cpp
silverchris Nov 12, 2020
1a45a6f
cleanup
silverchris Nov 12, 2020
75e2b99
nightmode changes
silverchris Nov 12, 2020
79c09d6
cleanup
silverchris Nov 13, 2020
2a205c4
update tweaks.sh and Makefile
silverchris Nov 13, 2020
c3b7910
Remove local copies of libraries. Not needed with new build tools
silverchris Nov 19, 2020
ff75c93
update include paths for new build tools
silverchris Nov 19, 2020
00a3f66
cmake stuff
silverchris Nov 19, 2020
d4b5ca3
optimize protobufs for lite
silverchris Nov 19, 2020
2cc10ee
remove unused build stuff
silverchris Nov 19, 2020
6d8a88c
cleanup static analyse issues
silverchris Nov 19, 2020
0e44848
use only one dbus dispatcher, and share our dbus connections around
silverchris Nov 19, 2020
b1b2250
cleanup/refactor/make less bad in general
silverchris Nov 19, 2020
895679c
Remove logunknownfields, so we can use protobuf-lite
silverchris Nov 19, 2020
7f5ae64
remove unused include
silverchris Nov 19, 2020
7a253ae
fixed surface switching... not sure how this worked? or if any of the…
silverchris Nov 20, 2020
34547a8
If we are using glib, we might as well use it instead of threads for …
silverchris Nov 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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" ON)
option(BUILD_UBUNTU "Builds Ubuntu version of Android Auto" OFF)
if(BUILD_MAZDA)
set(BUILD_UBUNTU OFF)
set(OPENSSL_USE_STATIC_LIBS TRUE) #Statically link openssl for Mazda target
set(Protobuf_USE_STATIC_LIBS ON) #Statically link protobuf for Mazda target
elseif(BUILD_UBUNTU)
set(BUILD_MAZDA OFF)
endif()

set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")

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/wireless/wireless.cpp
mazda/usb/usb.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
${GLIB_INCLUDE_DIRS}
${GTK3_INCLUDE_DIRS}
${USB_INCLUDE_DIRS}
${GST_INCLUDE_DIRS}
${DBUS_INCLUDE_DIRS}
${DBUS_C++_INCLUDE_DIRS}
${DBUS_C++-GLIB_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SYSROOT}/usr/include/SDL2
${CMAKE_SYSROOT}/mazda/dbus/
)

target_compile_options(headunit PUBLIC
-Wno-narrowing
-D__STDC_FORMAT_MACROS
-DDBUS_API_SUBJECT_TO_CHANGE
)

target_link_libraries(headunit PUBLIC
${GST_LIBRARIES}
${GLIB_LIBRARIES}
${ALSA_LIBRARIES}
${UDEV_LIBRARIES}
${Protobuf_LITE_LIBRARIES}
OpenSSL::Crypto
OpenSSL::SSL
Threads::Threads
-v
)

if(BUILD_UBUNTU)
target_link_libraries(headunit PUBLIC
${GTK3_LIBRARIES}
${X11_LIBRARIES}
${GLFW_STATIC_LIBRARY}
${SDL2_LIBRARIES}
${USB_LIBRARIES}
${UNWIND_LIBRARIES}
${DBUS_LIBRARIES}
${DBUS_C++_LIBRARIES}
)
endif()

if(BUILD_MAZDA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -s")

target_compile_options(headunit PUBLIC -static-libstdc++ -DCMU=1)

#Statically link in some libraries that are either different, or not availible on Mazda CMU
target_link_libraries(headunit PUBLIC
libdbus-1.a
libdbus-c++-1.a
libunwind.a
# libudev.a
libusb-1.0.a)
target_link_libraries(headunit PUBLIC -static-libstdc++)

endif()

install(TARGETS headunit RUNTIME DESTINATION bin)
59 changes: 59 additions & 0 deletions cmake/FindDBus.cmake
Original file line number Diff line number Diff line change
@@ -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 <rakuco@webkit.org>
#
# 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)
18 changes: 18 additions & 0 deletions cmake/arm-cortexa9_neon-linux-gnueabi.toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /home/silverchris/headunit/mazda/m3-toolchain/arm-cortexa9_neon-linux-gnueabi/sysroot/)

set(tools /home/silverchris/headunit/mazda/m3-toolchain/)
set(CMAKE_C_COMPILER ${tools}/bin/arm-cortexa9_neon-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${tools}bin/arm-cortexa9_neon-linux-gnueabi-g++)

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_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_MAKE_PROGRAM /usr/bin/make)

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
18 changes: 18 additions & 0 deletions cmake/arm-unknown-linux-glibabi.toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /home/silverchris/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot/)

set(tools /home/silverchris/x-tools/arm-unknown-linux-gnueabi/)
set(CMAKE_C_COMPILER ${tools}/bin/arm-unknown-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-unknown-linux-gnueabi-g++)

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_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
#set(CMAKE_MAKE_PROGRAM /usr/bin/make)

set(ENV{PKG_CONFIG_DIR} "")
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
71 changes: 71 additions & 0 deletions cmake/deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Protobuf REQUIRED)
find_package(ALSA REQUIRED)


find_package(PkgConfig REQUIRED)
if(PKG_CONFIG_EXECUTABLE)

pkg_check_modules(GST REQUIRED gstreamer-0.10
gstreamer-video-0.10
gstreamer-app-0.10
gstreamer-audio-0.10
)

pkg_check_modules(USB REQUIRED libusb-1.0)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(UNWIND REQUIRED libunwind)
pkg_check_modules(UDEV REQUIRED libudev)
pkg_check_modules(DBUS REQUIRED dbus-1)
pkg_check_modules(DBUS_C++ REQUIRED dbus-c++-1)
if(BUILD_UBUNTU)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
find_package(X11 REQUIRED)
find_package(SDL2 REQUIRED)
endif()

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 /home/silverchris/headunit/mazda/dbus/dbusxx-xml2cpp)

execute_process(COMMAND ${GEN_DBUS_HEADER_COMMAND} cmu_interfaces.xml --proxy=generated_cmu.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mazda/dbus)

# add_custom_target(generated_cmu ALL DEPENDS generated_cmu.h)

endif()
1 change: 1 addition & 0 deletions cmake/version.in.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define HEADUNIT_VERSION "@BUILD_HASH@"
2 changes: 1 addition & 1 deletion common/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <glib.h>
#include <stdio.h>
#include <asoundlib.h>
#include <alsa/asoundlib.h>
#include <thread>

#include "hu_uti.h"
Expand Down
4 changes: 4 additions & 0 deletions common/command_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ bool CommandServer::Start()
{
return server.start(9999);
}

void CommandServer::Stop(){
server.stop();
}
1 change: 1 addition & 0 deletions common/command_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ class CommandServer
CommandServer(ICommandServerCallbacks& callbacks);

bool Start();
void Stop();
};
16 changes: 16 additions & 0 deletions common/web++/web++.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "web++.hpp"
#include <condition_variable>
#include <mutex>
#include <chrono>


namespace {
using namespace std;
Expand Down Expand Up @@ -391,6 +395,9 @@ bool Server::match_route(Request* req, Response* res) {
return false;
}

std::condition_variable quitcv;
std::mutex quitmutex;

void Server::main_loop() {

struct sockaddr_in cli_addr;
Expand Down Expand Up @@ -467,6 +474,11 @@ void Server::main_loop() {
t = write(newsc, body_string.c_str(), body_string.size());

close(newsc);

std::unique_lock <std::mutex> lk(quitmutex);
if (quitcv.wait_for(lk, std::chrono::milliseconds{0}) == std::cv_status::no_timeout) {
break;
}
}
}

Expand Down Expand Up @@ -504,6 +516,10 @@ bool Server::start(int port) {
return true;
}

void Server::stop(){
quitcv.notify_all();
}

Server::Server() {

}
Expand Down
1 change: 1 addition & 0 deletions common/web++/web++.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace WPP {
void post(string, string);
void all(string, string);
bool start(int port = 80);
void stop();

Server();
~Server();
Expand Down
Loading