diff --git a/CMakeLists.txt b/CMakeLists.txt index 4499c9a..79cf6c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ SET(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} -Wall -pedantic -fPIC") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_CXX_FLAGS_RELEASE "-g -O3") +set(CMAKE_BUILD_TYPE Debug) # Paths set(resources_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets) @@ -50,10 +51,12 @@ endif (RPI3_BUILD) # Building on a Mac requires Abseil if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # macOS + add_definitions(-DMAC_OS) find_package(protobuf REQUIRED CONFIG) find_package(absl REQUIRED) set(CMAKE_PREFIX_PATH "/usr/local/opt/qt@5" ${CMAKE_PREFIX_PATH}) list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/util-linux) + list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/taglib) include(FindProtobuf) else () find_package(Protobuf REQUIRED) @@ -77,15 +80,16 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${Qt5Bluetooth_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} - ${PROTOBUF_INCLUDE_DIR} - ${AAP_PROTOBUF_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${RTAUDIO_INCLUDE_DIRS} ${TAGLIB_INCLUDE_DIRS} ${BLKID_INCLUDE_DIRS} ${BCM_HOST_INCLUDE_DIRS} ${ILCLIENT_INCLUDE_DIRS} - ${include_directory}) + ${include_directory} + ${PROTOBUF_INCLUDE_DIR} + ${AAP_PROTOBUF_INCLUDE_DIR} + ${AASDK_INCLUDE_DIR}) link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) @@ -98,22 +102,25 @@ file(GLOB_RECURSE autoapp_source_files ${autoapp_sources_directory}/*.ui ${autoa add_executable(autoapp ${autoapp_source_files}) -target_link_libraries(autoapp libusb - aap_protobuf - aasdk +target_include_directories(autoapp PUBLIC ${AAP_PROTOBUF_INCLUDE_DIR} ${AASDK_INCLUDE_DIR}) + +target_link_libraries(autoapp PUBLIC + libusb ${Boost_LIBRARIES} ${Qt5Multimedia_LIBRARIES} ${Qt5MultimediaWidgets_LIBRARIES} ${Qt5Bluetooth_LIBRARIES} ${Qt5Network_LIBRARIES} - ${PROTOBUF_LIBRARIES} ${BCM_HOST_LIBRARIES} ${ILCLIENT_LIBRARIES} ${WINSOCK2_LIBRARIES} ${RTAUDIO_LIBRARIES} ${TAGLIB_LIBRARIES} ${BLKID_LIBRARIES} - ${GPS_LIBRARIES}) + ${GPS_LIBRARIES} + ${PROTOBUF_LIBRARIES} + ${AAP_PROTOBUF_LIB_DIR} + ${AASDK_LIB_DIR}) set(btservice_sources_directory ${sources_directory}/btservice) set(btservice_include_directory ${include_directory}/f1x/openauto/btservice) @@ -121,11 +128,10 @@ file(GLOB_RECURSE btservice_source_files ${btservice_sources_directory}/*.cpp ${ add_executable(btservice ${btservice_source_files}) -target_link_libraries( - btservice - aap_protobuf +target_link_libraries(btservice PUBLIC ${Boost_LIBRARIES} ${Qt5Bluetooth_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5MultimediaWidgets_LIBRARIES} - ${PROTOBUF_LIBRARIES}) + ${PROTOBUF_LIBRARIES} + ${AAP_PROTOBUF_LIB_DIR}) diff --git a/cmake_modules/Findaap_protobuf.cmake b/cmake_modules/Findaap_protobuf.cmake new file mode 100644 index 0000000..56a29b1 --- /dev/null +++ b/cmake_modules/Findaap_protobuf.cmake @@ -0,0 +1,55 @@ +if (AAP_PROTOBUF_LIB_DIRS AND AAP_PROTOBUF_INCLUDE_DIRS) + # in cache already + message(STATUS "aap_protobuf cached") + set(AAP_PROTOBUF_FOUND TRUE) +else (AAP_PROTOBUF_LIB_DIRS AND AAP_PROTOBUF_INCLUDE_DIRS) + find_path(AAP_PROTOBUF_INCLUDE_DIR + NAMES + channel/ChannelCloseNotification.pb.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES + aap_protobuf + ) + + find_library(AAP_PROTOBUF_LIB_DIR + NAMES + aap_protobuf libaap_protobuf + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(AAP_PROTOBUF_INCLUDE_DIRS + ${AAP_PROTOBUF_INCLUDE_DIR} + ) + set(AAP_PROTOBUF_LIB_DIRS + ${AAP_PROTOBUF_LIB_DIR} + ) + + if (AAP_PROTOBUF_INCLUDE_DIRS AND AAP_PROTOBUF_LIB_DIRS) + set(AAP_PROTOBUF_FOUND TRUE) + endif (AAP_PROTOBUF_INCLUDE_DIRS AND AAP_PROTOBUF_LIB_DIRS) + + if (AAP_PROTOBUF_FOUND) + message(STATUS "Found aap_protobuf:") + message(STATUS " - Includes: ${AAP_PROTOBUF_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${AAP_PROTOBUF_LIB_DIRS}") + add_library(aap_protobuf INTERFACE) + target_include_directories(aap_protobuf SYSTEM INTERFACE ${AAP_PROTOBUF_INCLUDE_DIR}) + target_link_libraries(aap_protobuf INTERFACE ${AAP_PROTOBUF_LIB_DIR}) + else (AAP_PROTOBUF_FOUND) + message(STATUS " - Includes: ${AAP_PROTOBUF_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${AAP_PROTOBUF_LIB_DIRS}") + message(FATAL_ERROR "Could not find aap_protobuf") + endif (AAP_PROTOBUF_FOUND) + + # show the AAP_PROTOBUF_INCLUDE_DIRS and AAP_PROTOBUF_LIB_DIRS variables only in the advanced view + mark_as_advanced(AAP_PROTOBUF_INCLUDE_DIRS AAP_PROTOBUF_LIB_DIRS) + +endif (AAP_PROTOBUF_LIB_DIRS AND AAP_PROTOBUF_INCLUDE_DIRS) diff --git a/cmake_modules/Findaasdk.cmake b/cmake_modules/Findaasdk.cmake new file mode 100644 index 0000000..3b56595 --- /dev/null +++ b/cmake_modules/Findaasdk.cmake @@ -0,0 +1,55 @@ +if (AASDK_LIB_DIRS AND AASDK_INCLUDE_DIRS) + # in cache already + message(STATUS "aasdk cached") + set(AASDK_FOUND TRUE) +else (AASDK_LIB_DIRS AND AASDK_INCLUDE_DIRS) + find_path(AASDK_INCLUDE_DIR + NAMES + Version.hpp + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES + aasdk + ) + + find_library(AASDK_LIB_DIR + NAMES + aasdk libaasdk + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(AASDK_INCLUDE_DIRS + ${AASDK_INCLUDE_DIR} + ) + set(AASDK_LIB_DIRS + ${AASDK_LIB_DIR} + ) + + if (AASDK_INCLUDE_DIRS AND AASDK_LIB_DIRS) + set(AASDK_FOUND TRUE) + endif (AASDK_INCLUDE_DIRS AND AASDK_LIB_DIRS) + + if (AASDK_FOUND) + message(STATUS "Found aasdk:") + message(STATUS " - Includes: ${AASDK_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${AASDK_LIB_DIRS}") + add_library(aasdk INTERFACE) + target_include_directories(aasdk SYSTEM INTERFACE ${AASDK_INCLUDE_DIR}) + target_link_libraries(aasdk INTERFACE ${AASDK_LIB_DIR}) + else (AASDK_FOUND) + message(STATUS " - Includes: ${AASDK_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${AASDK_LIB_DIRS}") + message(FATAL_ERROR "Could not find aasdk") + endif (AASDK_FOUND) + + # show the AASDK_INCLUDE_DIRS and AASDK_LIB_DIRS variables only in the advanced view + mark_as_advanced(AASDK_INCLUDE_DIRS AASDK_LIB_DIRS) + +endif (AASDK_LIB_DIRS AND AASDK_INCLUDE_DIRS) diff --git a/include/f1x/openauto/autoapp/Projection/InputEvent.hpp b/include/f1x/openauto/autoapp/Projection/InputEvent.hpp index 7e4f92a..a5c39d0 100644 --- a/include/f1x/openauto/autoapp/Projection/InputEvent.hpp +++ b/include/f1x/openauto/autoapp/Projection/InputEvent.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include namespace f1x @@ -54,7 +54,7 @@ struct ButtonEvent struct TouchEvent { - aap_protobuf::service::input::message::TouchAction type; + aap_protobuf::service::input::message::PointerAction type; uint32_t x; uint32_t y; uint32_t pointerId; diff --git a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp index a30381f..19acce9 100644 --- a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/f1x/openauto/autoapp/Service/InputSource/InputSourceService.hpp b/include/f1x/openauto/autoapp/Service/InputSource/InputSourceService.hpp index adc5816..a612c26 100644 --- a/include/f1x/openauto/autoapp/Service/InputSource/InputSourceService.hpp +++ b/include/f1x/openauto/autoapp/Service/InputSource/InputSourceService.hpp @@ -48,7 +48,7 @@ namespace f1x { void onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) override; - void onBindingRequest(const aap_protobuf::channel::input::event::BindingRequest &request) override; + void onKeyBindingRequest(const aap_protobuf::channel::input::event::KeyBindingRequest &request) override; void onChannelError(const aasdk::error::Error &e) override; diff --git a/include/f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp b/include/f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp index 214ecd8..9f2600f 100644 --- a/include/f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp +++ b/include/f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp @@ -44,7 +44,7 @@ namespace service // General Constructor MediaSourceService(boost::asio::io_service& ioService, - aasdk::channel::mediasource::IMediaSourceService::Pointer channel, projection::IAudioInput::Pointer audioOutput); + aasdk::channel::mediasource::IMediaSourceService::Pointer channel, projection::IAudioInput::Pointer audioInput); void start() override; @@ -70,7 +70,7 @@ namespace service void onChannelError(const aasdk::error::Error &e) override; - private: + protected: using std::enable_shared_from_this::shared_from_this; void onMediaSourceOpenSuccess(); diff --git a/include/f1x/openauto/autoapp/Service/Sensor/SensorService.hpp b/include/f1x/openauto/autoapp/Service/Sensor/SensorService.hpp index c57c557..de2b10a 100644 --- a/include/f1x/openauto/autoapp/Service/Sensor/SensorService.hpp +++ b/include/f1x/openauto/autoapp/Service/Sensor/SensorService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ namespace f1x { namespace service { namespace sensor { class SensorService : - public aasdk::channel::sensor::ISensorServiceEventHandler, + public aasdk::channel::sensorsource::ISensorSourceServiceEventHandler, public IService, public std::enable_shared_from_this { public: @@ -71,7 +71,7 @@ namespace f1x { boost::asio::deadline_timer timer_; boost::asio::io_service::strand strand_; - aasdk::channel::sensor::SensorService::Pointer channel_; + aasdk::channel::sensorsource::SensorSourceService::Pointer channel_; struct gps_data_t gpsData_; bool gpsEnabled_ = false; }; diff --git a/include/f1x/openauto/autoapp/Service/WifiProjection/WifiProjectionService.hpp b/include/f1x/openauto/autoapp/Service/WifiProjection/WifiProjectionService.hpp index f4450ee..242448a 100644 --- a/include/f1x/openauto/autoapp/Service/WifiProjection/WifiProjectionService.hpp +++ b/include/f1x/openauto/autoapp/Service/WifiProjection/WifiProjectionService.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include #include #include diff --git a/include/f1x/openauto/autoapp/UI/SettingsWindow.hpp b/include/f1x/openauto/autoapp/UI/SettingsWindow.hpp index 367dd32..b91be8f 100644 --- a/include/f1x/openauto/autoapp/UI/SettingsWindow.hpp +++ b/include/f1x/openauto/autoapp/UI/SettingsWindow.hpp @@ -18,11 +18,14 @@ #pragma once -#include #include #include #include #include +#ifdef MAC_OS +#else + #include +#endif class QCheckBox; class QTimer; @@ -50,7 +53,7 @@ public: void loadSystemValues(); protected: - void keyPressEvent(QKeyEvent *event); + void keyPressEvent(QKeyEvent *event) override; private slots: void unpairAll(); @@ -95,7 +98,7 @@ public slots: void show_tab9(); private: - void showEvent(QShowEvent* event); + void showEvent(QShowEvent* event) override; void load(); void loadButtonCheckBoxes(); void saveButtonCheckBoxes(); @@ -104,6 +107,8 @@ private: Ui::SettingsWindow* ui_; configuration::IConfiguration::Pointer configuration_; + + void getMacMemoryInfo(QString &freeMemory); }; } diff --git a/src/autoapp/Projection/InputDevice.cpp b/src/autoapp/Projection/InputDevice.cpp index 808d3c8..cb39975 100644 --- a/src/autoapp/Projection/InputDevice.cpp +++ b/src/autoapp/Projection/InputDevice.cpp @@ -193,18 +193,18 @@ bool InputDevice::handleTouchEvent(QEvent* event) return true; } - aap_protobuf::service::input::message::TouchAction type; + aap_protobuf::service::input::message::PointerAction type; switch(event->type()) { case QEvent::MouseButtonPress: - type = aap_protobuf::service::input::message::TouchAction::ACTION_DOWN; + type = aap_protobuf::service::input::message::PointerAction::ACTION_DOWN; break; case QEvent::MouseButtonRelease: - type = aap_protobuf::service::input::message::TouchAction::ACTION_UP; + type = aap_protobuf::service::input::message::PointerAction::ACTION_UP; break; case QEvent::MouseMove: - type = aap_protobuf::service::input::message::TouchAction::ACTION_MOVED; + type = aap_protobuf::service::input::message::PointerAction::ACTION_MOVED; break; default: return true; diff --git a/src/autoapp/Projection/RtAudioOutput.cpp b/src/autoapp/Projection/RtAudioOutput.cpp index a59ea4b..aa12a8a 100644 --- a/src/autoapp/Projection/RtAudioOutput.cpp +++ b/src/autoapp/Projection/RtAudioOutput.cpp @@ -33,15 +33,9 @@ RtAudioOutput::RtAudioOutput(uint32_t channelCount, uint32_t sampleSize, uint32_ , sampleSize_(sampleSize) , sampleRate_(sampleRate) { - - std::vector apis; - RtAudio::getCompiledApi(apis); - dac_ = std::find(apis.begin(), apis.end(), RtAudio::LINUX_PULSE) == apis.end() ? std::make_unique() : std::make_unique(RtAudio::LINUX_PULSE); - - // Set the error callback - dac_->setErrorCallback([](RtAudioErrorType type, const std::string& errorText) { - OPENAUTO_LOG(error) << "[RtAudioOutput] " << errorText; - }); + std::vector apis; + RtAudio::getCompiledApi(apis); + dac_ = std::find(apis.begin(), apis.end(), RtAudio::LINUX_PULSE) == apis.end() ? std::make_unique() : std::make_unique(RtAudio::LINUX_PULSE); } bool RtAudioOutput::open() @@ -60,19 +54,13 @@ bool RtAudioOutput::open() RtAudio::StreamOptions streamOptions; streamOptions.flags = RTAUDIO_MINIMIZE_LATENCY | RTAUDIO_SCHEDULE_REALTIME; uint32_t bufferFrames = sampleRate_ == 16000 ? 1024 : 2048; //according to the observation of audio packets - auto result = dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this), &streamOptions); dac_->openStream(¶meters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast(this), &streamOptions); - if (result == RtAudioErrorType::RTAUDIO_NO_ERROR) { - OPENAUTO_LOG(info) << "[RtAudioOutput] Sample Rate: " << sampleRate_; - return audioBuffer_.open(QIODevice::ReadWrite); - } else { - // Log the error using the callback or handle it here directly - OPENAUTO_LOG(error) << "[RtAudioOutput] Error opening stream: "; - } + OPENAUTO_LOG(info) << "[RtAudioOutput] Sample Rate: " << sampleRate_; + return audioBuffer_.open(QIODevice::ReadWrite); } - catch(const std::exception& e) + catch(const RtAudioError& e) { - OPENAUTO_LOG(error) << "[RtAudioOutput] Exception: " << e.what(); + OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to open audio output, what: " << e.what(); } } else @@ -98,10 +86,9 @@ void RtAudioOutput::start() { dac_->startStream(); } - catch(const RtAudioErrorType& e) + catch(const RtAudioError& e) { - // TODO: What's the new RtAudio Error? - //OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to start audio output, what: " << e.what(); + OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to start audio output, what: " << e.what(); } } } @@ -146,10 +133,9 @@ void RtAudioOutput::doSuspend() { dac_->stopStream(); } - catch(const RtAudioErrorType& e) + catch(const RtAudioError& e) { - // TODO: What's the new RtAudio Error? - //OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to suspend audio output, what: " << e.what(); + OPENAUTO_LOG(error) << "[RtAudioOutput] Failed to suspend audio output, what: " << e.what(); } } } diff --git a/src/autoapp/Service/AndroidAutoEntity.cpp b/src/autoapp/Service/AndroidAutoEntity.cpp index 3cea7f4..700813a 100644 --- a/src/autoapp/Service/AndroidAutoEntity.cpp +++ b/src/autoapp/Service/AndroidAutoEntity.cpp @@ -74,329 +74,307 @@ */ -namespace f1x -{ -namespace openauto -{ -namespace autoapp -{ -namespace service -{ +namespace f1x { + namespace openauto { + namespace autoapp { + namespace service { -AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, - aasdk::messenger::ICryptor::Pointer cryptor, - aasdk::transport::ITransport::Pointer transport, - aasdk::messenger::IMessenger::Pointer messenger, - configuration::IConfiguration::Pointer configuration, - ServiceList serviceList, - IPinger::Pointer pinger) - : strand_(ioService) - , cryptor_(std::move(cryptor)) - , transport_(std::move(transport)) - , messenger_(std::move(messenger)) - , controlServiceChannel_(std::make_shared(strand_, messenger_)) - , configuration_(std::move(configuration)) - , serviceList_(std::move(serviceList)) - , pinger_(std::move(pinger)) - , eventHandler_(nullptr) -{ -} - -AndroidAutoEntity::~AndroidAutoEntity() -{ - OPENAUTO_LOG(debug) << "[AndroidAutoEntity] destroy."; -} - -void AndroidAutoEntity::start(IAndroidAutoEntityEventHandler& eventHandler) -{ - strand_.dispatch([this, self = this->shared_from_this(), eventHandler = &eventHandler]() { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] start."; - - eventHandler_ = eventHandler; - std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::start, std::placeholders::_1)); - //this->schedulePing(); - - auto versionRequestPromise = aasdk::channel::SendPromise::defer(strand_); - versionRequestPromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendVersionRequest(std::move(versionRequestPromise)); - controlServiceChannel_->receive(this->shared_from_this()); - }); -} - -void AndroidAutoEntity::stop() -{ - strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop."; - - try { - eventHandler_ = nullptr; - std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1)); - //pinger_->cancel(); - messenger_->stop(); - transport_->stop(); - cryptor_->deinit(); - } catch (...) { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] exception in stop."; + AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service &ioService, + aasdk::messenger::ICryptor::Pointer cryptor, + aasdk::transport::ITransport::Pointer transport, + aasdk::messenger::IMessenger::Pointer messenger, + configuration::IConfiguration::Pointer configuration, + ServiceList serviceList, + IPinger::Pointer pinger) + : strand_(ioService), cryptor_(std::move(cryptor)), transport_(std::move(transport)), + messenger_(std::move(messenger)), controlServiceChannel_( + std::make_shared(strand_, messenger_)), + configuration_(std::move(configuration)), serviceList_(std::move(serviceList)), + pinger_(std::move(pinger)), eventHandler_(nullptr) { } - }); -} -void AndroidAutoEntity::pause() -{ - strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] pause."; - - try { - std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::pause, std::placeholders::_1)); - } catch (...) { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] exception in pause."; + AndroidAutoEntity::~AndroidAutoEntity() { + OPENAUTO_LOG(debug) << "[AndroidAutoEntity] destroy."; } - }); -} -void AndroidAutoEntity::resume() -{ - strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] resume."; + void AndroidAutoEntity::start(IAndroidAutoEntityEventHandler &eventHandler) { + strand_.dispatch([this, self = this->shared_from_this(), eventHandler = &eventHandler]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] start()"; - try { - std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::resume, std::placeholders::_1)); - } catch (...) { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] exception in resume."; - } - }); -} + eventHandler_ = eventHandler; + std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::start, std::placeholders::_1)); -void AndroidAutoEntity::onVersionResponse(uint16_t majorCode, uint16_t minorCode, aap_protobuf::shared::MessageStatus status) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] version response, version: " << majorCode - << "." << minorCode - << ", status: " << status; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Event handlers added."; + auto versionRequestPromise = aasdk::channel::SendPromise::defer(strand_); + versionRequestPromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), + std::placeholders::_1)); - if(status == aap_protobuf::shared::MessageStatus::STATUS_NO_COMPATIBLE_VERSION) - { - OPENAUTO_LOG(error) << "[AndroidAutoEntity] version mismatch."; - this->triggerQuit(); - } - else - { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Begin handshake."; - - try - { - cryptor_->doHandshake(); - - auto handshakePromise = aasdk::channel::SendPromise::defer(strand_); - handshakePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendHandshake(cryptor_->readHandshakeBuffer(), std::move(handshakePromise)); + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Sending version request."; + controlServiceChannel_->sendVersionRequest(std::move(versionRequestPromise)); controlServiceChannel_->receive(this->shared_from_this()); - } - catch(const aasdk::error::Error& e) - { - this->onChannelError(e); - } - } -} - -void AndroidAutoEntity::onHandshake(const aasdk::common::DataConstBuffer& payload) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Handshake, size: " << payload.size; - - try - { - cryptor_->writeHandshakeBuffer(payload); - - if(!cryptor_->doHandshake()) - { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] continue handshake."; - - auto handshakePromise = aasdk::channel::SendPromise::defer(strand_); - handshakePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendHandshake(cryptor_->readHandshakeBuffer(), std::move(handshakePromise)); - } - else - { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Auth completed."; - - aap_protobuf::channel::control::auth::AuthResponse authCompleteIndication; - authCompleteIndication.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); - - auto authCompletePromise = aasdk::channel::SendPromise::defer(strand_); - authCompletePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendAuthComplete(authCompleteIndication, std::move(authCompletePromise)); + }); } - controlServiceChannel_->receive(this->shared_from_this()); - } - catch(const aasdk::error::Error& e) - { - this->onChannelError(e); - } -} + void AndroidAutoEntity::stop() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop()"; -void AndroidAutoEntity::onServiceDiscoveryRequest(const aap_protobuf::channel::control::servicediscovery::event::ServiceDiscoveryRequest& request) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Discovery request, device name: " << request.device_name() - << ", brand: " << request.label_text(); + try { + eventHandler_ = nullptr; + std::for_each(serviceList_.begin(), serviceList_.end(), + std::bind(&IService::stop, std::placeholders::_1)); + //pinger_->cancel(); + messenger_->stop(); + transport_->stop(); + cryptor_->deinit(); + } catch (...) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop() - exception when stopping."; + } + }); + } - /* - aap_protobuf::connection::PingConfiguration pingConfiguration; - pingConfiguration.set_high_latency_threshold_ms(); - pingConfiguration.set_interval_ms(); - pingConfiguration.set_timeout_ms(); - pingConfiguration.set_tracked_ping_count(); + void AndroidAutoEntity::pause() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] pause()"; - aap_protobuf::connection::WirelessTcpConfiguration wirelessTcpConfiguration; - wirelessTcpConfiguration.set_socket_read_timeout_ms(); - wirelessTcpConfiguration.set_socket_receive_buffer_size_kb(); - wirelessTcpConfiguration.set_socket_send_buffer_size_kb(); + try { + std::for_each(serviceList_.begin(), serviceList_.end(), + std::bind(&IService::pause, std::placeholders::_1)); + } catch (...) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] pause() - exception when pausing."; + } + }); + } - aap_protobuf::connection::ConnectionConfiguration connectionConfiguration; - connectionConfiguration.set_allocated_ping_configuration(); - connectionConfiguration.set_allocated_wireless_tcp_configuration();*/ + void AndroidAutoEntity::resume() { + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] resume()"; - aap_protobuf::channel::control::servicediscovery::notification::HeadUnitInfo headUnitInfo; - headUnitInfo.set_make("CubeOne"); - headUnitInfo.set_model("Journey"); - headUnitInfo.set_year("2024"); - headUnitInfo.set_vehicle_id("2009"); - headUnitInfo.set_head_unit_make("CubeOne"); - headUnitInfo.set_head_unit_model("Journey"); - headUnitInfo.set_head_unit_software_build("2024.10.15"); - headUnitInfo.set_head_unit_software_version("1"); + try { + std::for_each(serviceList_.begin(), serviceList_.end(), + std::bind(&IService::resume, std::placeholders::_1)); + } catch (...) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] resume() exception when resuming."; + } + }); + } - aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse serviceDiscoveryResponse; - serviceDiscoveryResponse.mutable_channels()->Reserve(256); + void AndroidAutoEntity::onVersionResponse(uint16_t majorCode, uint16_t minorCode, + aap_protobuf::shared::MessageStatus status) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onVersionResponse()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Version Received: " << majorCode << "." << minorCode + << ", with status: " << status; - //serviceDiscoveryResponse.set_headunit_sw_build("2024.10.15"); - //serviceDiscoveryResponse.set_headunit_sw_version("1"); - serviceDiscoveryResponse.set_display_name("JourneyOS"); - - serviceDiscoveryResponse.set_allocated_headunit_info(&headUnitInfo); - - //serviceDiscoveryResponse.set_can_play_native_media_during_vr(false); - - std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::fillFeatures, std::placeholders::_1, std::ref(serviceDiscoveryResponse))); - - auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendServiceDiscoveryResponse(serviceDiscoveryResponse, std::move(promise)); - controlServiceChannel_->receive(this->shared_from_this()); -} - -void AndroidAutoEntity::onAudioFocusRequest(const aap_protobuf::channel::control::focus::audio::event::AudioFocusRequest& request) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] requested audio focus, type: " << request.audio_focus_type(); - - aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType audioFocusState = - request.audio_focus_type() == aap_protobuf::channel::control::focus::audio::event::AudioFocusRequestType::AUDIO_FOCUS_RELEASE - ? aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType::AUDIO_FOCUS_STATE_LOSS - : aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType::AUDIO_FOCUS_STATE_GAIN; - - OPENAUTO_LOG(info) << "[AndroidAutoEntity] audio focus state: " << audioFocusState; - - aap_protobuf::channel::control::focus::audio::notification::AudioFocusNotification response; - response.set_audio_focus_state(audioFocusState); - - auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendAudioFocusResponse(response, std::move(promise)); - controlServiceChannel_->receive(this->shared_from_this()); -} - -void AndroidAutoEntity::onByeByeRequest(const aap_protobuf::channel::control::byebye::event::ByeByeRequest& request) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Shutdown request, reason: " << request.reason(); - - aap_protobuf::channel::control::byebye::notification::ByeByeResponse response; - auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then(std::bind(&AndroidAutoEntity::triggerQuit, this->shared_from_this()), - std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - - controlServiceChannel_->sendShutdownResponse(response, std::move(promise)); -} - -void AndroidAutoEntity::onByeByeResponse(const aap_protobuf::channel::control::byebye::notification::ByeByeResponse& response) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Shutdown response "; - this->triggerQuit(); -} - -void AndroidAutoEntity::onNavigationFocusRequest(const aap_protobuf::channel::control::focus::navigation::event::NavFocusRequestNotification& request) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] navigation focus request, type: " << request.focus_type(); - - aap_protobuf::channel::control::focus::navigation::notification::NavFocusNotification response; - response.set_focus_type(aap_protobuf::channel::control::focus::navigation::shared::NavFocusType::NAV_FOCUS_PROJECTED); - - auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); - controlServiceChannel_->sendNavigationFocusResponse(response, std::move(promise)); - controlServiceChannel_->receive(this->shared_from_this()); -} - - void onVoiceSessionRequest(const aap_protobuf::channel::control::voice::VoiceSessionNotification &request) { - // TODO: FIXME - } - void AndroidAutoEntity::onPingRequest(const aap_protobuf::channel::control::ping::PingRequest& request) - { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Ping request, timestamp: " << request.timestamp(); - //pinger_->ping(); - //controlServiceChannel_->receive(this->shared_from_this()); - } - -void AndroidAutoEntity::onPingResponse(const aap_protobuf::channel::control::ping::PingResponse& response) -{ - OPENAUTO_LOG(info) << "[AndroidAutoEntity] Ping response, timestamp: " << response.timestamp(); - pinger_->pong(); - controlServiceChannel_->receive(this->shared_from_this()); -} - -void AndroidAutoEntity::onChannelError(const aasdk::error::Error& e) -{ - OPENAUTO_LOG(error) << "[AndroidAutoEntity] channel error: " << e.what(); - this->triggerQuit(); -} - -void AndroidAutoEntity::triggerQuit() -{ - if(eventHandler_ != nullptr) - { - eventHandler_->onAndroidAutoQuit(); - } -} - -void AndroidAutoEntity::schedulePing() -{ - auto promise = IPinger::Promise::defer(strand_); - promise->then([this, self = this->shared_from_this()]() { - this->sendPing(); - this->schedulePing(); - }, - [this, self = this->shared_from_this()](auto error) { - if(error != aasdk::error::ErrorCode::OPERATION_ABORTED && - error != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS) - { - OPENAUTO_LOG(error) << "[AndroidAutoEntity] ping timer exceeded."; + if (status == aap_protobuf::shared::MessageStatus::STATUS_NO_COMPATIBLE_VERSION) { + OPENAUTO_LOG(error) << "[AndroidAutoEntity] Version mismatch."; this->triggerQuit(); + } else { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Version matches."; + + try { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Beginning SSL handshake..."; + cryptor_->doHandshake(); + + auto handshakePromise = aasdk::channel::SendPromise::defer(strand_); + handshakePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + controlServiceChannel_->sendHandshake(cryptor_->readHandshakeBuffer(), std::move(handshakePromise)); + controlServiceChannel_->receive(this->shared_from_this()); + } + catch (const aasdk::error::Error &e) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Handshake Error."; + this->onChannelError(e); + } + } } - }); - pinger_->ping(std::move(promise)); -} + void AndroidAutoEntity::onHandshake(const aasdk::common::DataConstBuffer &payload) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onHandshake()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Payload size: " << payload.size; -void AndroidAutoEntity::sendPing() -{ - auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + try { + cryptor_->writeHandshakeBuffer(payload); - aap_protobuf::channel::control::ping::PingRequest request; - auto timestamp = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); - request.set_timestamp(timestamp.count()); - controlServiceChannel_->sendPingRequest(request, std::move(promise)); -} + if (!cryptor_->doHandshake()) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Re-attempting handshake."; -} -} -} + auto handshakePromise = aasdk::channel::SendPromise::defer(strand_); + handshakePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + controlServiceChannel_->sendHandshake(cryptor_->readHandshakeBuffer(), std::move(handshakePromise)); + } else { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Handshake completed."; + + aap_protobuf::channel::control::auth::AuthResponse authCompleteIndication; + authCompleteIndication.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); + + auto authCompletePromise = aasdk::channel::SendPromise::defer(strand_); + authCompletePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + controlServiceChannel_->sendAuthComplete(authCompleteIndication, std::move(authCompletePromise)); + } + + controlServiceChannel_->receive(this->shared_from_this()); + } + catch (const aasdk::error::Error &e) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Error during handshake"; + this->onChannelError(e); + } + } + + void AndroidAutoEntity::onServiceDiscoveryRequest( + const aap_protobuf::channel::control::servicediscovery::event::ServiceDiscoveryRequest &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onServiceDiscoveryRequest()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Type: " << request.label_text() << ", Model: " + << request.device_name(); + + aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse serviceDiscoveryResponse; + serviceDiscoveryResponse.mutable_channels()->Reserve(256); + auto *headUnitInfo = serviceDiscoveryResponse.mutable_headunit_info(); + + serviceDiscoveryResponse.set_display_name("JourneyOS"); + headUnitInfo->set_make("CubeOne"); + headUnitInfo->set_model("Journey"); + headUnitInfo->set_year("2024"); + headUnitInfo->set_vehicle_id("2009"); + headUnitInfo->set_head_unit_make("CubeOne"); + headUnitInfo->set_head_unit_model("Journey"); + headUnitInfo->set_head_unit_software_build("2024.10.15"); + headUnitInfo->set_head_unit_software_version("1"); + + std::for_each(serviceList_.begin(), serviceList_.end(), + std::bind(&IService::fillFeatures, std::placeholders::_1, std::ref(serviceDiscoveryResponse))); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + controlServiceChannel_->sendServiceDiscoveryResponse(serviceDiscoveryResponse, std::move(promise)); + controlServiceChannel_->receive(this->shared_from_this()); + } + + void AndroidAutoEntity::onAudioFocusRequest( + const aap_protobuf::channel::control::focus::audio::event::AudioFocusRequest &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onAudioFocusRequest()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] AudioFocusRequestType received: " + << AudioFocusRequestType_Name(request.audio_focus_type()); + + aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType audioFocusStateType = + request.audio_focus_type() == + aap_protobuf::channel::control::focus::audio::event::AudioFocusRequestType::AUDIO_FOCUS_RELEASE + ? aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType::AUDIO_FOCUS_STATE_LOSS + : aap_protobuf::channel::control::focus::audio::notification::AudioFocusStateType::AUDIO_FOCUS_STATE_GAIN; + + OPENAUTO_LOG(info) << "[AndroidAutoEntity] AudioFocusStateType determined: " + << AudioFocusStateType_Name(audioFocusStateType); + + aap_protobuf::channel::control::focus::audio::notification::AudioFocusNotification response; + response.set_audio_focus_state(audioFocusStateType); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + controlServiceChannel_->sendAudioFocusResponse(response, std::move(promise)); + controlServiceChannel_->receive(this->shared_from_this()); + } + + void AndroidAutoEntity::onByeByeRequest( + const aap_protobuf::channel::control::byebye::event::ByeByeRequest &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onByeByeRequest()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Reason received: " << request.reason(); + + aap_protobuf::channel::control::byebye::notification::ByeByeResponse response; + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then(std::bind(&AndroidAutoEntity::triggerQuit, this->shared_from_this()), + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + + controlServiceChannel_->sendShutdownResponse(response, std::move(promise)); + } + + void AndroidAutoEntity::onByeByeResponse( + const aap_protobuf::channel::control::byebye::notification::ByeByeResponse &response) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onByeByeResponse()"; + this->triggerQuit(); + } + + void AndroidAutoEntity::onNavigationFocusRequest( + const aap_protobuf::channel::control::focus::navigation::event::NavFocusRequestNotification &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onByeByeResponse()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] NavFocusRequestNotification type received: " << NavFocusType_Name(request.focus_type()); + + aap_protobuf::channel::control::focus::navigation::notification::NavFocusNotification response; + response.set_focus_type( + aap_protobuf::channel::control::focus::navigation::shared::NavFocusType::NAV_FOCUS_PROJECTED); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + controlServiceChannel_->sendNavigationFocusResponse(response, std::move(promise)); + controlServiceChannel_->receive(this->shared_from_this()); + } + + void AndroidAutoEntity::onVoiceSessionRequest( + const aap_protobuf::channel::control::voice::VoiceSessionNotification &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onVoiceSessionRequest()"; + } + + void AndroidAutoEntity::onPingRequest(const aap_protobuf::channel::control::ping::PingRequest &request) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onPingRequest()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Timestamp: " << request.timestamp(); + //pinger_->ping(); + //controlServiceChannel_->receive(this->shared_from_this()); + } + + void AndroidAutoEntity::onPingResponse(const aap_protobuf::channel::control::ping::PingResponse &response) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] onPingResponse()"; + OPENAUTO_LOG(info) << "[AndroidAutoEntity] Timestamp: " << response.timestamp(); + pinger_->pong(); + controlServiceChannel_->receive(this->shared_from_this()); + } + + void AndroidAutoEntity::onChannelError(const aasdk::error::Error &e) { + OPENAUTO_LOG(error) << "[AndroidAutoEntity] onChannelError(): " << e.what(); + this->triggerQuit(); + } + + void AndroidAutoEntity::triggerQuit() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] triggerQuit()"; + if (eventHandler_ != nullptr) { + eventHandler_->onAndroidAutoQuit(); + } + } + + void AndroidAutoEntity::schedulePing() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] schedulePing()"; + auto promise = IPinger::Promise::defer(strand_); + promise->then([this, self = this->shared_from_this()]() { + this->sendPing(); + this->schedulePing(); + }, + [this, self = this->shared_from_this()](auto error) { + if (error != aasdk::error::ErrorCode::OPERATION_ABORTED && + error != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS) { + OPENAUTO_LOG(error) << "[AndroidAutoEntity] Ping timer exceeded."; + this->triggerQuit(); + } + }); + + pinger_->ping(std::move(promise)); + } + + void AndroidAutoEntity::sendPing() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] sendPing()"; + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + + aap_protobuf::channel::control::ping::PingRequest request; + auto timestamp = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()); + request.set_timestamp(timestamp.count()); + controlServiceChannel_->sendPingRequest(request, std::move(promise)); + } + + } + } + } } diff --git a/src/autoapp/Service/Bluetooth/BluetoothService.cpp b/src/autoapp/Service/Bluetooth/BluetoothService.cpp index a9e7704..c4e07ec 100644 --- a/src/autoapp/Service/Bluetooth/BluetoothService.cpp +++ b/src/autoapp/Service/Bluetooth/BluetoothService.cpp @@ -36,53 +36,52 @@ namespace f1x { void BluetoothService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[BluetoothService] start."; + OPENAUTO_LOG(info) << "[BluetoothService] start()"; channel_->receive(this->shared_from_this()); }); } void BluetoothService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[BluetoothService] stop."; + OPENAUTO_LOG(info) << "[BluetoothService] stop()"; bluetoothDevice_->stop(); }); } void BluetoothService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[BluetoothService] pause."; + OPENAUTO_LOG(info) << "[BluetoothService] pause()"; }); } void BluetoothService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[BluetoothService] resume."; + OPENAUTO_LOG(info) << "[BluetoothService] resume()"; }); } void BluetoothService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[BluetoothService] fill features"; + OPENAUTO_LOG(info) << "[BluetoothService] fillFeatures()"; if (bluetoothDevice_->isAvailable()) { - OPENAUTO_LOG(info) << "[BluetoothService] sending local adapter adress: " - << bluetoothDevice_->getLocalAddress(); + OPENAUTO_LOG(info) << "[BluetoothService] Local Address: " << bluetoothDevice_->getLocalAddress(); - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); - auto bluetoothChannel = channelDescriptor->mutable_bluetooth_service(); - bluetoothChannel->set_adapter_address(bluetoothDevice_->getLocalAddress()); - bluetoothChannel->add_supported_pairing_methods(aap_protobuf::channel::bluetooth::event::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN); - bluetoothChannel->add_supported_pairing_methods(aap_protobuf::channel::bluetooth::event::BluetoothPairingMethod::BLUETOOTH_PAIRING_NUMERIC_COMPARISON); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); + auto bluetooth = service->mutable_bluetooth_service(); + bluetooth->set_car_address(bluetoothDevice_->getLocalAddress()); + bluetooth->add_supported_pairing_methods(aap_protobuf::channel::bluetooth::event::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN); + bluetooth->add_supported_pairing_methods(aap_protobuf::channel::bluetooth::event::BluetoothPairingMethod::BLUETOOTH_PAIRING_NUMERIC_COMPARISON); } } void BluetoothService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[BluetoothService] open request, priority: " << request.priority(); - const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; - OPENAUTO_LOG(info) << "[BluetoothService] open status: " << status; + OPENAUTO_LOG(info) << "[BluetoothService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[BluetoothService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; response.set_status(status); auto promise = aasdk::channel::SendPromise::defer(strand_); @@ -95,11 +94,18 @@ namespace f1x { void BluetoothService::onBluetoothPairingRequest( const aap_protobuf::channel::bluetooth::event::BluetoothPairingRequest &request) { - OPENAUTO_LOG(info) << "[BluetoothService] pairing request, address: " << request.phone_address(); + OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothPairingRequest()"; + OPENAUTO_LOG(info) << "[BluetoothService] Phone Address: " << request.phone_address(); aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response; const auto isPaired = bluetoothDevice_->isPaired(request.phone_address()); + if (isPaired) { + OPENAUTO_LOG(info) << "[BluetoothService] Phone is Already Paired"; + } else { + OPENAUTO_LOG(info) << "[BluetoothService] Phone is Not Paired"; + } + response.set_already_paired(isPaired); response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); @@ -112,9 +118,8 @@ namespace f1x { } void BluetoothService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[BluetoothService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[BluetoothService] onChannelError(): " << e.what(); } - } } } diff --git a/src/autoapp/Service/GenericNotification/GenericNotificationService.cpp b/src/autoapp/Service/GenericNotification/GenericNotificationService.cpp index 2d3116d..ec17cbd 100644 --- a/src/autoapp/Service/GenericNotification/GenericNotificationService.cpp +++ b/src/autoapp/Service/GenericNotification/GenericNotificationService.cpp @@ -37,40 +37,56 @@ namespace f1x { void GenericNotificationService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[GenericNotificationService] start."; + OPENAUTO_LOG(info) << "[GenericNotificationService] start()"; }); } void GenericNotificationService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[GenericNotificationService] stop."; + OPENAUTO_LOG(info) << "[GenericNotificationService] stop()"; }); } void GenericNotificationService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[GenericNotificationService] pause."; + OPENAUTO_LOG(info) << "[GenericNotificationService] pause()"; }); } void GenericNotificationService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[GenericNotificationService] resume."; + OPENAUTO_LOG(info) << "[GenericNotificationService] resume()"; }); } void GenericNotificationService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[GenericNotificationService] fill features."; + OPENAUTO_LOG(info) << "[GenericNotificationService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *genericNotification = service->mutable_wifi_projection_service(); + } + + void GenericNotificationService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[GenericNotificationService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[GenericNotificationService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&GenericNotificationService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); } void GenericNotificationService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[GenericNotificationService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[GenericNotificationService] onChannelError(): " << e.what(); } } } diff --git a/src/autoapp/Service/InputSource/InputSourceService.cpp b/src/autoapp/Service/InputSource/InputSourceService.cpp index 54aeb5b..2ca8f64 100644 --- a/src/autoapp/Service/InputSource/InputSourceService.cpp +++ b/src/autoapp/Service/InputSource/InputSourceService.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include #include #include @@ -36,38 +36,38 @@ namespace f1x { void InputSourceService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[InputService] start."; + OPENAUTO_LOG(info) << "[InputSourceService] start()"; channel_->receive(this->shared_from_this()); }); } void InputSourceService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[InputService] stop."; + OPENAUTO_LOG(info) << "[InputSourceService] stop()"; inputDevice_->stop(); }); } void InputSourceService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[InputService] pause."; + OPENAUTO_LOG(info) << "[InputSourceService] pause()"; }); } void InputSourceService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[InputService] resume."; + OPENAUTO_LOG(info) << "[InputSourceService] resume()"; }); } void InputSourceService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[InputService] fill features."; + OPENAUTO_LOG(info) << "[InputSourceService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *inputChannel = channelDescriptor->mutable_input_service(); + auto *inputChannel = service->mutable_input_source_service(); const auto &supportedButtonCodes = inputDevice_->getSupportedButtonCodes(); @@ -77,7 +77,7 @@ namespace f1x { if (inputDevice_->hasTouchscreen()) { const auto &touchscreenSurface = inputDevice_->getTouchscreenGeometry(); - auto touchscreenConfig = inputChannel->add_touch_screen_config(); + auto touchscreenConfig = inputChannel->add_touchscreen(); touchscreenConfig->set_width(touchscreenSurface.width()); touchscreenConfig->set_height(touchscreenSurface.height()); @@ -85,22 +85,24 @@ namespace f1x { } void InputSourceService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[InputService] open request, priority: " << request.priority(); - const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; - OPENAUTO_LOG(info) << "[InputService] open status: " << status; + OPENAUTO_LOG(info) << "[InputSourceService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[InputSourceService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; response.set_status(status); auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then([]() {}, std::bind(&InputSourceService::onChannelError, this->shared_from_this(), std::placeholders::_1)); channel_->sendChannelOpenResponse(response, std::move(promise)); - channel_->receive(this->shared_from_this()); } - void InputSourceService::onBindingRequest(const aap_protobuf::channel::input::event::BindingRequest &request) { - OPENAUTO_LOG(info) << "[InputService] binding request, scan codes count: " << request.keycodes_size(); + + void InputSourceService::onKeyBindingRequest(const aap_protobuf::channel::input::event::KeyBindingRequest &request) { + OPENAUTO_LOG(info) << "[InputSourceService] onKeyBindingRequest()"; + OPENAUTO_LOG(info) << "[InputSourceService] KeyCodes Count: " << request.keycodes_size(); aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; const auto &supportedButtonCodes = inputDevice_->getSupportedButtonCodes(); @@ -108,49 +110,48 @@ namespace f1x { for (int i = 0; i < request.keycodes_size(); ++i) { if (std::find(supportedButtonCodes.begin(), supportedButtonCodes.end(), request.keycodes(i)) == supportedButtonCodes.end()) { - OPENAUTO_LOG(error) << "[InputService] binding request, scan code: " << request.keycodes(i) - << " is not supported."; - - status = aap_protobuf::shared::MessageStatus::STATUS_UNSOLICITED_MESSAGE; + OPENAUTO_LOG(error) << "[InputSourceService] onKeyBindingRequest is not supported for KeyCode: " << request.keycodes(i); + status = aap_protobuf::shared::MessageStatus::STATUS_KEYCODE_NOT_BOUND; break; } } - aap_protobuf::service::media::sink::message::BindingResponse response; + aap_protobuf::service::media::sink::message::KeyBindingResponse response; response.set_status(status); if (status == aap_protobuf::shared::MessageStatus::STATUS_SUCCESS) { inputDevice_->start(*this); } - OPENAUTO_LOG(info) << "[InputService] binding request, status: " << status; + OPENAUTO_LOG(info) << "[InputSourceService] Sending KeyBindingResponse with Status: " << status; auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then([]() {}, std::bind(&InputSourceService::onChannelError, this->shared_from_this(), std::placeholders::_1)); - channel_->sendBindingResponse(response, std::move(promise)); + channel_->sendKeyBindingResponse(response, std::move(promise)); channel_->receive(this->shared_from_this()); } void InputSourceService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[InputSourceService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[InputSourceService] onChannelError(): " << e.what(); } void InputSourceService::onButtonEvent(const projection::ButtonEvent &event) { + OPENAUTO_LOG(error) << "[InputSourceService] onButtonEvent()"; auto timestamp = std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch()); strand_.dispatch( [this, self = this->shared_from_this(), event = std::move(event), timestamp = std::move(timestamp)]() { - aap_protobuf::service::input::message::InputEventIndication inputEventIndication; - inputEventIndication.set_timestamp(timestamp.count()); + aap_protobuf::service::input::message::InputReport inputReport; + inputReport.set_timestamp(timestamp.count()); if (event.code == aap_protobuf::service::media::sink::KeyCode::KEYCODE_ROTARY_CONTROLLER) { - auto relativeEvent = inputEventIndication.mutable_relative_input_event()->add_relative_input_events(); + auto relativeEvent = inputReport.mutable_relative_event()->add_data(); relativeEvent->set_delta(event.wheelDirection == projection::WheelDirection::LEFT ? -1 : 1); - relativeEvent->set_scan_code(event.code); + relativeEvent->set_keycode(event.code); } else { - auto buttonEvent = inputEventIndication.mutable_button_event()->add_keys(); + auto buttonEvent = inputReport.mutable_key_event()->add_keys(); buttonEvent->set_metastate(0); buttonEvent->set_down(event.type == projection::ButtonEventType::PRESS); buttonEvent->set_longpress(false); @@ -160,22 +161,23 @@ namespace f1x { auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then([]() {}, std::bind(&InputSourceService::onChannelError, this->shared_from_this(), std::placeholders::_1)); - channel_->sendInputEventIndication(inputEventIndication, std::move(promise)); + channel_->sendInputReport(inputReport, std::move(promise)); }); } void InputSourceService::onTouchEvent(const projection::TouchEvent &event) { + OPENAUTO_LOG(error) << "[InputSourceService] onTouchEvent()"; auto timestamp = std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch()); strand_.dispatch( [this, self = this->shared_from_this(), event = std::move(event), timestamp = std::move(timestamp)]() { - aap_protobuf::service::input::message::InputEventIndication inputEventIndication; - inputEventIndication.set_timestamp(timestamp.count()); + aap_protobuf::service::input::message::InputReport inputReport; + inputReport.set_timestamp(timestamp.count()); - auto touchEvent = inputEventIndication.mutable_touch_event(); - touchEvent->set_touch_action(event.type); - auto touchLocation = touchEvent->add_touch_location(); + auto touchEvent = inputReport.mutable_touch_event(); + touchEvent->set_action(event.type); + auto touchLocation = touchEvent->add_pointer_data(); touchLocation->set_x(event.x); touchLocation->set_y(event.y); touchLocation->set_pointer_id(0); @@ -183,12 +185,9 @@ namespace f1x { auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then([]() {}, std::bind(&InputSourceService::onChannelError, this->shared_from_this(), std::placeholders::_1)); - channel_->sendInputEventIndication(inputEventIndication, std::move(promise)); + channel_->sendInputReport(inputReport, std::move(promise)); }); } - - - } } } diff --git a/src/autoapp/Service/MediaBrowser/MediaBrowserService.cpp b/src/autoapp/Service/MediaBrowser/MediaBrowserService.cpp index 4d6d9bd..ff7f362 100644 --- a/src/autoapp/Service/MediaBrowser/MediaBrowserService.cpp +++ b/src/autoapp/Service/MediaBrowser/MediaBrowserService.cpp @@ -37,40 +37,56 @@ namespace f1x { void MediaBrowserService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaBrowserService] start."; + OPENAUTO_LOG(info) << "[MediaBrowserService] start()"; }); } void MediaBrowserService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaBrowserService] stop."; + OPENAUTO_LOG(info) << "[MediaBrowserService] stop()"; }); } void MediaBrowserService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaBrowserService] pause."; + OPENAUTO_LOG(info) << "[MediaBrowserService] pause()"; }); } void MediaBrowserService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaBrowserService] resume."; + OPENAUTO_LOG(info) << "[MediaBrowserService] resume()"; }); } void MediaBrowserService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[MediaBrowserService] fill features."; + OPENAUTO_LOG(info) << "[MediaBrowserService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *mediaBrowser = service->mutable_media_browser_service(); + } + + void MediaBrowserService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[MediaBrowserService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[MediaBrowserService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&MediaBrowserService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); } void MediaBrowserService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[MediaBrowserService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[MediaBrowserService] onChannelError(): " << e.what(); } } } diff --git a/src/autoapp/Service/MediaPlaybackStatus/MediaPlaybackStatusService.cpp b/src/autoapp/Service/MediaPlaybackStatus/MediaPlaybackStatusService.cpp index 4a2ad10..c736181 100644 --- a/src/autoapp/Service/MediaPlaybackStatus/MediaPlaybackStatusService.cpp +++ b/src/autoapp/Service/MediaPlaybackStatus/MediaPlaybackStatusService.cpp @@ -37,40 +37,57 @@ namespace f1x { void MediaPlaybackStatusService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] start."; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] start()"; }); } void MediaPlaybackStatusService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] stop."; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] stop()"; }); } void MediaPlaybackStatusService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] pause."; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] pause()"; }); } void MediaPlaybackStatusService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] resume."; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] resume()"; }); } void MediaPlaybackStatusService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] fill features."; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *mediaPlaybackStatus = service->mutable_media_playback_service(); } + void MediaPlaybackStatusService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[MediaPlaybackStatusService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&MediaPlaybackStatusService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); + } + + void MediaPlaybackStatusService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[MediaPlaybackStatusService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[MediaPlaybackStatusService] onChannelError(): " << e.what(); } } } diff --git a/src/autoapp/Service/MediaSink/AudioMediaSinkService.cpp b/src/autoapp/Service/MediaSink/AudioMediaSinkService.cpp index 802d765..ccc3d09 100644 --- a/src/autoapp/Service/MediaSink/AudioMediaSinkService.cpp +++ b/src/autoapp/Service/MediaSink/AudioMediaSinkService.cpp @@ -34,29 +34,33 @@ namespace f1x { void AudioMediaSinkService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] start, channel: " - << aasdk::messenger::channelIdToString(channel_->getId()); + OPENAUTO_LOG(info) << "[AudioMediaSinkService] start()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); channel_->receive(this->shared_from_this()); }); } void AudioMediaSinkService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] stop, channel: " - << aasdk::messenger::channelIdToString(channel_->getId()); + OPENAUTO_LOG(info) << "[AudioMediaSinkService] stop()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); audioOutput_->stop(); }); } void AudioMediaSinkService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] pause."; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] pause()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); + }); } void AudioMediaSinkService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] resume."; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] resume()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); + }); } @@ -66,37 +70,42 @@ namespace f1x { void AudioMediaSinkService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[MediaSinkService] fill features, channel: " - << aasdk::messenger::channelIdToString(channel_->getId()); + OPENAUTO_LOG(info) << "[AudioMediaSinkService] fillFeatures()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel: " << aasdk::messenger::channelIdToString(channel_->getId()); - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto audioChannel = channelDescriptor->mutable_media_sink_service(); + auto audioChannel = service->mutable_media_sink_service(); audioChannel->set_stream_type( aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM); switch (channel_->getId()) { case aasdk::messenger::ChannelId::MEDIA_SINK_SYSTEM_AUDIO: + OPENAUTO_LOG(info) << "[AudioMediaSinkService] System Audio."; audioChannel->set_audio_type( aap_protobuf::service::media::sink::AudioStreamType::AUDIO_STREAM_SYSTEM_AUDIO); break; case aasdk::messenger::ChannelId::MEDIA_SINK_MEDIA_AUDIO: + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Music Audio."; audioChannel->set_audio_type(aap_protobuf::service::media::sink::AudioStreamType::AUDIO_STREAM_MEDIA); break; case aasdk::messenger::ChannelId::MEDIA_SINK_GUIDANCE_AUDIO: + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Guidance Audio."; audioChannel->set_audio_type( aap_protobuf::service::media::sink::AudioStreamType::AUDIO_STREAM_GUIDANCE); break; case aasdk::messenger::ChannelId::MEDIA_SINK_TELEPHONY_AUDIO: + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Telephony Audio."; audioChannel->set_audio_type( aap_protobuf::service::media::sink::AudioStreamType::AUDIO_STREAM_TELEPHONY); break; default: + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Unknown Audio."; break; } @@ -113,18 +122,16 @@ namespace f1x { */ void AudioMediaSinkService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[MediaSinkService] Channel Open Request with priority " << request.priority() - << " on channel " << aasdk::messenger::channelIdToString(channel_->getId()); + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); - OPENAUTO_LOG(debug) << "[AudioMediaSinkService] Sample Rate: " << audioOutput_->getSampleRate() - << ", Sample Size: " << audioOutput_->getSampleSize() - << ", Channels: " << audioOutput_->getChannelCount(); + OPENAUTO_LOG(debug) << "[AudioMediaSinkService] Sample Rate: " << audioOutput_->getSampleRate() << ", Sample Size: " << audioOutput_->getSampleSize() << ", Audio Channels: " << audioOutput_->getChannelCount(); const aap_protobuf::shared::MessageStatus status = audioOutput_->open() ? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS : aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR; - OPENAUTO_LOG(info) << "[MediaSinkService] open status: " << status; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Status determined: " << aap_protobuf::shared::MessageStatus_Name(status); aap_protobuf::channel::ChannelOpenResponse response; response.set_status(status); @@ -137,7 +144,7 @@ namespace f1x { } void AudioMediaSinkService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[MediaSinkService] channel error: " << e.what() + OPENAUTO_LOG(error) << "[AudioMediaSinkService] onChannelError(): " << e.what() << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()); } @@ -146,16 +153,11 @@ namespace f1x { */ void AudioMediaSinkService::onMediaChannelSetupRequest(const aap_protobuf::channel::media::event::Setup &request) { - - OPENAUTO_LOG(info) << "[MediaSinkService] setup request" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", codec type: " << MediaCodecType_Name(request.type()); - - auto status = aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY; - - OPENAUTO_LOG(info) << "[MediaSinkService] setup status: " << status; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onMediaChannelSetupRequest()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", Codec: " << MediaCodecType_Name(request.type()); aap_protobuf::service::media::sink::message::MediaSinkChannelSetupResponse response; + auto status = aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY; response.set_media_status(status); response.set_max_unacked(1); response.add_configuration_indices(0); @@ -170,18 +172,16 @@ namespace f1x { void AudioMediaSinkService::onMediaChannelStartIndication(const aap_protobuf::channel::media::event::Start &indication) { - OPENAUTO_LOG(info) << "[MediaSinkService] start indication" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", session: " << indication.session_id(); + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onMediaChannelStartIndication()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " << indication.session_id(); session_ = indication.session_id(); audioOutput_->start(); channel_->receive(this->shared_from_this()); } void AudioMediaSinkService::onMediaChannelStopIndication(const aap_protobuf::channel::media::event::Stop &indication) { - OPENAUTO_LOG(info) << "[MediaSinkService] stop indication" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", session: " << session_; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onMediaChannelStopIndication()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " << session_; session_ = -1; audioOutput_->suspend(); @@ -191,6 +191,9 @@ namespace f1x { void AudioMediaSinkService::onMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType timestamp, const aasdk::common::DataConstBuffer &buffer) { + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onMediaWithTimestampIndication()"; + OPENAUTO_LOG(info) << "[AudioMediaSinkService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " << session_; + audioOutput_->write(timestamp, buffer); // TODO: Move MediaSourceMediaAckIndication to Ack and move to Shared. @@ -206,6 +209,8 @@ namespace f1x { } void AudioMediaSinkService::onMediaIndication(const aasdk::common::DataConstBuffer &buffer) { + OPENAUTO_LOG(info) << "[AudioMediaSinkService] onMediaIndication()"; + this->onMediaWithTimestampIndication(0, buffer); } diff --git a/src/autoapp/Service/MediaSink/SystemAudioService.cpp b/src/autoapp/Service/MediaSink/SystemAudioService.cpp index 373ae84..4b92cf9 100644 --- a/src/autoapp/Service/MediaSink/SystemAudioService.cpp +++ b/src/autoapp/Service/MediaSink/SystemAudioService.cpp @@ -16,7 +16,6 @@ * along with openauto. If not, see . */ -#include #include #include diff --git a/src/autoapp/Service/MediaSink/TelephonyAudioService.cpp b/src/autoapp/Service/MediaSink/TelephonyAudioService.cpp index 5c7fa2b..91f8c6b 100644 --- a/src/autoapp/Service/MediaSink/TelephonyAudioService.cpp +++ b/src/autoapp/Service/MediaSink/TelephonyAudioService.cpp @@ -16,7 +16,6 @@ * along with openauto. If not, see . */ -#include #include #include diff --git a/src/autoapp/Service/MediaSink/VideoMediaSinkService.cpp b/src/autoapp/Service/MediaSink/VideoMediaSinkService.cpp index f672281..3c985e1 100644 --- a/src/autoapp/Service/MediaSink/VideoMediaSinkService.cpp +++ b/src/autoapp/Service/MediaSink/VideoMediaSinkService.cpp @@ -33,7 +33,8 @@ namespace f1x { void VideoMediaSinkService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] start, channel: " + OPENAUTO_LOG(info) << "[VideoMediaSinkService] start()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); channel_->receive(this->shared_from_this()); }); @@ -41,32 +42,39 @@ namespace f1x { void VideoMediaSinkService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] stop, channel: " + OPENAUTO_LOG(info) << "[VideoMediaSinkService] stop()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); }); } void VideoMediaSinkService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] pause."; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] pause()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel " + << aasdk::messenger::channelIdToString(channel_->getId()); }); } void VideoMediaSinkService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[MediaSinkService] resume."; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] resume()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel " + << aasdk::messenger::channelIdToString(channel_->getId()); + }); } void VideoMediaSinkService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[MediaSinkService] fill features, channel: " + OPENAUTO_LOG(info) << "[VideoMediaSinkService] fillFeatures()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel " << aasdk::messenger::channelIdToString(channel_->getId()); - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *videoChannel = channelDescriptor->mutable_media_sink_service(); + auto *videoChannel = service->mutable_media_sink_service(); videoChannel->set_stream_type( aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_VIDEO_H264_BP); videoChannel->set_available_while_in_call(true); @@ -82,16 +90,19 @@ namespace f1x { } - void VideoMediaSinkService::onMediaChannelSetupRequest(const aap_protobuf::channel::media::event::Setup &request) { + void + VideoMediaSinkService::onMediaChannelSetupRequest(const aap_protobuf::channel::media::event::Setup &request) { + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onMediaChannelSetupRequest()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel Id: " + << aasdk::messenger::channelIdToString(channel_->getId()) << ", Codec: " + << MediaCodecType_Name(request.type()); - OPENAUTO_LOG(info) << "[MediaSinkService] setup request" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", codec type: " << MediaCodecType_Name(request.type()); - auto status = videoOutput_->init() ? aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY - : aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_WAIT; + auto status = videoOutput_->init() + ? aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY + : aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_WAIT; - OPENAUTO_LOG(info) << "[MediaSinkService] setup status: " << status; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] setup status: " << status; aap_protobuf::service::media::sink::message::MediaSinkChannelSetupResponse response; response.set_media_status(status); @@ -100,21 +111,24 @@ namespace f1x { auto promise = aasdk::channel::SendPromise::defer(strand_); promise->then(std::bind(&VideoMediaSinkService::sendVideoFocusIndication, this->shared_from_this()), - std::bind(&VideoMediaSinkService::onChannelError, this->shared_from_this(), std::placeholders::_1)); + std::bind(&VideoMediaSinkService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); channel_->sendChannelSetupResponse(response, std::move(promise)); channel_->receive(this->shared_from_this()); } void VideoMediaSinkService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[MediaSinkService] Channel Open Request with priority " << request.priority() - << " on channel " << aasdk::messenger::channelIdToString(channel_->getId()); + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel Id: " << request.service_id() << ", Priority: " + << request.priority(); const aap_protobuf::shared::MessageStatus status = videoOutput_->open() ? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS : aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR; - OPENAUTO_LOG(info) << "[MediaSinkService] open status: " << status; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Status determined: " + << aap_protobuf::shared::MessageStatus_Name(status); aap_protobuf::channel::ChannelOpenResponse response; response.set_status(status); @@ -126,24 +140,32 @@ namespace f1x { channel_->receive(this->shared_from_this()); } - void VideoMediaSinkService::onMediaChannelStartIndication(const aap_protobuf::channel::media::event::Start &indication) { - OPENAUTO_LOG(info) << "[MediaSinkService] start indication" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", session: " << indication.session_id(); + void VideoMediaSinkService::onMediaChannelStartIndication( + const aap_protobuf::channel::media::event::Start &indication) { + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onMediaChannelStartIndication()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel Id: " + << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " + << indication.session_id(); + session_ = indication.session_id(); channel_->receive(this->shared_from_this()); } - void VideoMediaSinkService::onMediaChannelStopIndication(const aap_protobuf::channel::media::event::Stop &indication) { - OPENAUTO_LOG(info) << "[MediaSinkService] stop indication" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", session: " << session_; + void VideoMediaSinkService::onMediaChannelStopIndication( + const aap_protobuf::channel::media::event::Stop &indication) { + OPENAUTO_LOG(info) << "[onMediaChannelStopIndication] onMediaChannelStopIndication()"; + OPENAUTO_LOG(info) << "[onMediaChannelStopIndication] Channel Id: " + << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " << session_; channel_->receive(this->shared_from_this()); } void VideoMediaSinkService::onMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType timestamp, - const aasdk::common::DataConstBuffer &buffer) { + const aasdk::common::DataConstBuffer &buffer) { + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onMediaWithTimestampIndication()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Channel Id: " + << aasdk::messenger::channelIdToString(channel_->getId()) << ", session: " << session_; + videoOutput_->write(timestamp, buffer); aap_protobuf::service::media::source::message::MediaSourceMediaAckIndication indication; @@ -158,31 +180,30 @@ namespace f1x { } void VideoMediaSinkService::onMediaIndication(const aasdk::common::DataConstBuffer &buffer) { + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onMediaIndication()"; this->onMediaWithTimestampIndication(0, buffer); } void VideoMediaSinkService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[MediaSinkService] channel error: " << e.what() + OPENAUTO_LOG(error) << "[VideoMediaSinkService] onChannelError(): " << e.what() << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()); } - - void VideoMediaSinkService::onVideoFocusRequest( const aap_protobuf::channel::control::focus::video::event::VideoFocusRequestNotification &request) { - OPENAUTO_LOG(info) << "[VideoMediaSinkService] video focus request, display index: " << request.disp_channel_id() - << ", focus mode: " << VideoFocusMode_Name(request.mode()) - << ", focus reason: " << VideoFocusReason_Name(request.reason()); - // package aap_protobuf.channel.control.focus.video.shared; - // stop video service on go back to openauto - if (request.mode() == aap_protobuf::channel::control::focus::video::shared::VideoFocusMode::VIDEO_FOCUS_NATIVE) { - OPENAUTO_LOG(info) << "[VideoMediaSinkService] Back to CSNG..."; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] onMediaIndication()"; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Display index: " << request.disp_channel_id() << ", focus mode: " << VideoFocusMode_Name(request.mode()) << ", focus reason: " << VideoFocusReason_Name(request.reason()); + + if (request.mode() == + aap_protobuf::channel::control::focus::video::shared::VideoFocusMode::VIDEO_FOCUS_NATIVE) { + // Return to OS + OPENAUTO_LOG(info) << "[VideoMediaSinkService] Returning to OS."; try { if (!std::ifstream("/tmp/entityexit")) { std::ofstream("/tmp/entityexit"); } } catch (...) { - OPENAUTO_LOG(error) << "[VideoMediaSinkService] Error in creating entityexit"; + OPENAUTO_LOG(error) << "[VideoMediaSinkService] Error in creating /tmp/entityexit"; } } @@ -191,14 +212,16 @@ namespace f1x { } void VideoMediaSinkService::sendVideoFocusIndication() { - OPENAUTO_LOG(info) << "[VideoMediaSinkService] video focus indication."; + OPENAUTO_LOG(info) << "[VideoMediaSinkService] sendVideoFocusIndication()"; aap_protobuf::channel::control::focus::video::notification::VideoFocusNotification videoFocusIndication; - videoFocusIndication.set_focus(aap_protobuf::channel::control::focus::video::shared::VideoFocusMode::VIDEO_FOCUS_PROJECTED); + videoFocusIndication.set_focus( + aap_protobuf::channel::control::focus::video::shared::VideoFocusMode::VIDEO_FOCUS_PROJECTED); videoFocusIndication.set_unsolicited(false); auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([]() {}, std::bind(&VideoMediaSinkService::onChannelError, this->shared_from_this(), std::placeholders::_1)); + promise->then([]() {}, std::bind(&VideoMediaSinkService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); channel_->sendVideoFocusIndication(videoFocusIndication, std::move(promise)); } } diff --git a/src/autoapp/Service/MediaSink/VideoService.cpp b/src/autoapp/Service/MediaSink/VideoService.cpp index 57917ff..eb8b421 100644 --- a/src/autoapp/Service/MediaSink/VideoService.cpp +++ b/src/autoapp/Service/MediaSink/VideoService.cpp @@ -16,7 +16,6 @@ * along with openauto. If not, see . */ -#include #include #include diff --git a/src/autoapp/Service/MediaSource/MediaSourceService.cpp b/src/autoapp/Service/MediaSource/MediaSourceService.cpp index dd98385..a4f3eab 100644 --- a/src/autoapp/Service/MediaSource/MediaSourceService.cpp +++ b/src/autoapp/Service/MediaSource/MediaSourceService.cpp @@ -36,27 +36,27 @@ namespace f1x { void MediaSourceService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AudioInputService] start."; + OPENAUTO_LOG(info) << "[MediaSourceService] start()"; channel_->receive(this->shared_from_this()); }); } void MediaSourceService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AudioInputService] stop."; + OPENAUTO_LOG(info) << "[MediaSourceService] stop()"; audioInput_->stop(); }); } void MediaSourceService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AudioInputService] pause."; + OPENAUTO_LOG(info) << "[MediaSourceService] pause()"; }); } void MediaSourceService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AudioInputService] resume."; + OPENAUTO_LOG(info) << "[MediaSourceService] resume()"; }); } @@ -70,12 +70,12 @@ namespace f1x { */ void MediaSourceService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[AudioInputService] fill features."; + OPENAUTO_LOG(info) << "[MediaSourceService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *avInputChannel = channelDescriptor->mutable_media_source_service(); + auto *avInputChannel = service->mutable_media_source_service(); avInputChannel->set_stream_type( aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM); @@ -94,11 +94,14 @@ namespace f1x { * @param request */ void MediaSourceService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[AudioInputService] open request, priority: " << request.priority(); + OPENAUTO_LOG(info) << "[MediaSourceService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + const aap_protobuf::shared::MessageStatus status = audioInput_->open() ? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS - : aap_protobuf::shared::MessageStatus::STATUS_UNSOLICITED_MESSAGE; - OPENAUTO_LOG(info) << "[AudioInputService] open status: " << status; + : aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR; + + OPENAUTO_LOG(info) << "[MediaSourceService] Status determined: " << aap_protobuf::shared::MessageStatus_Name(status); aap_protobuf::channel::ChannelOpenResponse response; response.set_status(status); @@ -107,8 +110,8 @@ namespace f1x { promise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(), std::placeholders::_1)); - channel_->sendChannelOpenResponse(response, std::move(promise)); + channel_->sendChannelOpenResponse(response, std::move(promise)); channel_->receive(this->shared_from_this()); } @@ -117,7 +120,7 @@ namespace f1x { * @param e */ void MediaSourceService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[AudioInputService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[MediaSourceService] onChannelError(): " << e.what(); } /* @@ -131,15 +134,11 @@ namespace f1x { void MediaSourceService::onMediaChannelSetupRequest(const aap_protobuf::channel::media::event::Setup &request) { - OPENAUTO_LOG(info) << "[MediaSinkService] setup request" - << ", channel: " << aasdk::messenger::channelIdToString(channel_->getId()) - << ", codec type: " << MediaCodecType_Name(request.type()); - - auto status = aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY; - - OPENAUTO_LOG(info) << "[MediaSinkService] setup status: " << status; + OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelSetupRequest()"; + OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", Codec: " << MediaCodecType_Name(request.type()); aap_protobuf::service::media::sink::message::MediaSinkChannelSetupResponse response; + auto status = aap_protobuf::service::media::sink::MediaSinkChannelSetupStatus::STATUS_READY; response.set_media_status(status); response.set_max_unacked(1); response.add_configuration_indices(0); @@ -157,6 +156,7 @@ namespace f1x { */ void MediaSourceService::onMediaChannelAckIndication( const aap_protobuf::service::media::source::message::MediaSourceMediaAckIndication &) { + OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelAckIndication()"; channel_->receive(this->shared_from_this()); } @@ -167,25 +167,24 @@ namespace f1x { // TODO: These are Source Channel Handlers - should be moved to their own handlers in case any more are implemented in the future. /** - * Handle request to open Microphone Channel + * Handle request to Open or Close Microphone Source Channel * @param request */ void MediaSourceService::onMediaSourceOpenRequest( const aap_protobuf::service::media::source::message::MicrophoneRequest &request) { - OPENAUTO_LOG(info) << "[AudioInputService] input open request, open: " << request.open() - << ", anc: " << request.anc_enabled() - << ", ec: " << request.ec_enabled() - << ", max unacked: " << request.max_unacked(); + OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelAckIndication()"; + OPENAUTO_LOG(info) << "[MediaSourceService] Request to Open?: " << request.open() << ", anc: " << request.anc_enabled() << ", ec: " << request.ec_enabled() << ", max unacked: " << request.max_unacked(); if (request.open()) { + // Request for Channel Open auto startPromise = projection::IAudioInput::StartPromise::defer(strand_); startPromise->then(std::bind(&MediaSourceService::onMediaSourceOpenSuccess, this->shared_from_this()), [this, self = this->shared_from_this()]() { - OPENAUTO_LOG(error) << "[AudioInputService] audio input open failed."; + OPENAUTO_LOG(error) << "[MediaSourceService] Media Source Open Failed"; aap_protobuf::service::media::source::message::MicrophoneResponse response; response.set_session_id(session_); - // TODO: Matches previous number, but doesn't seem like the right status. + response.set_status(aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR); auto sendPromise = aasdk::channel::SendPromise::defer(strand_); @@ -198,11 +197,12 @@ namespace f1x { audioInput_->start(std::move(startPromise)); } else { + // Request for Channel Close audioInput_->stop(); aap_protobuf::service::media::source::message::MicrophoneResponse response; response.set_session_id(session_); - // TODO: Matches previous number, but doesn't seem like the right status. + response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); auto sendPromise = aasdk::channel::SendPromise::defer(strand_); @@ -219,7 +219,7 @@ namespace f1x { * Sends response to advise Microphone is Open */ void MediaSourceService::onMediaSourceOpenSuccess() { - OPENAUTO_LOG(info) << "[AudioInputService] audio input open succeed."; + OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceOpenSuccess()"; aap_protobuf::service::media::source::message::MicrophoneResponse response; response.set_session_id(session_); @@ -239,6 +239,7 @@ namespace f1x { * @param data */ void MediaSourceService::onMediaSourceDataReady(aasdk::common::Data data) { + OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceDataReady()"; auto sendPromise = aasdk::channel::SendPromise::defer(strand_); sendPromise->then(std::bind(&MediaSourceService::readMediaSource, this->shared_from_this()), std::bind(&MediaSourceService::onChannelError, this->shared_from_this(), @@ -253,13 +254,14 @@ namespace f1x { * Reads audio from a MediaSource (eg Microphone). Promise resolves to onMediaSourceDataReady. */ void MediaSourceService::readMediaSource() { + OPENAUTO_LOG(error) << "[MediaSourceService] readMediaSource()"; if (audioInput_->isActive()) { auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_); readPromise->then( std::bind(&MediaSourceService::onMediaSourceDataReady, this->shared_from_this(), std::placeholders::_1), [this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[AudioInputService] audio input read rejected."; + OPENAUTO_LOG(info) << "[MediaSourceService] audio input read rejected."; }); audioInput_->read(std::move(readPromise)); diff --git a/src/autoapp/Service/MediaSource/MicrophoneMediaSourceService.cpp b/src/autoapp/Service/MediaSource/MicrophoneMediaSourceService.cpp new file mode 100644 index 0000000..7d14c4a --- /dev/null +++ b/src/autoapp/Service/MediaSource/MicrophoneMediaSourceService.cpp @@ -0,0 +1,40 @@ +/* +* This file is part of openauto project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* openauto is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* openauto is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with openauto. If not, see . +*/ + +#include +#include + +namespace f1x { + namespace openauto { + namespace autoapp { + namespace service { + namespace mediasource { + MicrophoneMediaSourceService::MicrophoneMediaSourceService(boost::asio::io_service &ioService, + aasdk::messenger::IMessenger::Pointer messenger, + projection::IAudioInput::Pointer audioOutput) + : MediaSourceService(ioService, std::make_shared(strand_, + std::move( + messenger)), + std::move(audioOutput)) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/autoapp/Service/NavigationStatus/NavigationStatusService.cpp b/src/autoapp/Service/NavigationStatus/NavigationStatusService.cpp index 26ca1e3..3f5dec8 100644 --- a/src/autoapp/Service/NavigationStatus/NavigationStatusService.cpp +++ b/src/autoapp/Service/NavigationStatus/NavigationStatusService.cpp @@ -37,40 +37,56 @@ namespace f1x { void NavigationStatusService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[NavigationStatusService] start."; + OPENAUTO_LOG(info) << "[NavigationStatusService] start()"; }); } void NavigationStatusService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[NavigationStatusService] stop."; + OPENAUTO_LOG(info) << "[NavigationStatusService] stop()"; }); } void NavigationStatusService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[NavigationStatusService] pause."; + OPENAUTO_LOG(info) << "[NavigationStatusService] pause()"; }); } void NavigationStatusService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[NavigationStatusService] resume."; + OPENAUTO_LOG(info) << "[NavigationStatusService] resume()"; }); } void NavigationStatusService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[NavigationStatusService] fill features."; + OPENAUTO_LOG(info) << "[NavigationStatusService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *navigationStatus = service->mutable_navigation_status_service(); + } + + void NavigationStatusService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[NavigationStatusService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[NavigationStatusService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&NavigationStatusService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); } void NavigationStatusService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[NavigationStatusService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[NavigationStatusService] onChannelError(): " << e.what(); } } } diff --git a/src/autoapp/Service/PhoneStatus/PhoneStatusService.cpp b/src/autoapp/Service/PhoneStatus/PhoneStatusService.cpp index 79a78a5..7a5510f 100644 --- a/src/autoapp/Service/PhoneStatus/PhoneStatusService.cpp +++ b/src/autoapp/Service/PhoneStatus/PhoneStatusService.cpp @@ -37,43 +37,58 @@ namespace f1x { void PhoneStatusService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[PhoneStatusService] start."; + OPENAUTO_LOG(info) << "[PhoneStatusService] start()"; }); } void PhoneStatusService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[PhoneStatusService] stop."; + OPENAUTO_LOG(info) << "[PhoneStatusService] stop()"; }); } void PhoneStatusService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[PhoneStatusService] pause."; + OPENAUTO_LOG(info) << "[PhoneStatusService] pause()"; }); } void PhoneStatusService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[PhoneStatusService] resume."; + OPENAUTO_LOG(info) << "[PhoneStatusService] resume()"; }); } void PhoneStatusService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[PhoneStatusService] fill features."; + OPENAUTO_LOG(info) << "[PhoneStatusService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *phoneStatus = service->mutable_phone_status_service(); } + void PhoneStatusService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[PhoneStatusService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[PhoneStatusService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&PhoneStatusService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); + } + + void PhoneStatusService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[PhoneStatusService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[PhoneStatusService] onChannelError(): " << e.what(); } - - } } } diff --git a/src/autoapp/Service/Radio/RadioService.cpp b/src/autoapp/Service/Radio/RadioService.cpp index d7d520a..cf6c77a 100644 --- a/src/autoapp/Service/Radio/RadioService.cpp +++ b/src/autoapp/Service/Radio/RadioService.cpp @@ -37,40 +37,57 @@ namespace f1x { void RadioService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[RadioService] start."; + OPENAUTO_LOG(info) << "[RadioService] start()"; }); } void RadioService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[RadioService] stop."; + OPENAUTO_LOG(info) << "[RadioService] stop()"; }); } void RadioService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[RadioService] pause."; + OPENAUTO_LOG(info) << "[RadioService] pause()"; }); } void RadioService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[RadioService] resume."; + OPENAUTO_LOG(info) << "[RadioService] resume()"; }); } void RadioService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[RadioService] fill features."; + OPENAUTO_LOG(info) << "[RadioService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *radio = service->mutable_radio_service(); + } + + void RadioService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[RadioService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[RadioService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + + + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&RadioService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + + channel_->receive(this->shared_from_this()); } void RadioService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[RadioService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[RadioService] onChannelError(): " << e.what(); } diff --git a/src/autoapp/Service/Sensor/SensorService.cpp b/src/autoapp/Service/Sensor/SensorService.cpp index 4db4bae..7335931 100644 --- a/src/autoapp/Service/Sensor/SensorService.cpp +++ b/src/autoapp/Service/Sensor/SensorService.cpp @@ -33,7 +33,7 @@ namespace f1x { aasdk::messenger::IMessenger::Pointer messenger) : strand_(ioService), timer_(ioService), - channel_(std::make_shared(strand_, std::move(messenger))) { + channel_(std::make_shared(strand_, std::move(messenger))) { } @@ -52,7 +52,7 @@ namespace f1x { } this->sensorPolling(); - OPENAUTO_LOG(info) << "[SensorService] start."; + OPENAUTO_LOG(info) << "[SensorService] start()"; channel_->receive(this->shared_from_this()); }); @@ -68,41 +68,42 @@ namespace f1x { this->gpsEnabled_ = false; } - OPENAUTO_LOG(info) << "[SensorService] stop."; + OPENAUTO_LOG(info) << "[SensorService] stop()"; }); } void SensorService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[SensorService] pause."; + OPENAUTO_LOG(info) << "[SensorService] pause()"; }); } void SensorService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[SensorService] resume."; + OPENAUTO_LOG(info) << "[SensorService] resume()"; }); } void SensorService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[SensorService] fill features."; + OPENAUTO_LOG(info) << "[SensorService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *sensorChannel = channelDescriptor->mutable_sensor_service(); + // TODO: Add and Link other Sensors Here + auto *sensorChannel = service->mutable_sensor_source_service(); sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensor::message::SensorType::SENSOR_DRIVING_STATUS_DATA); sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensor::message::SensorType::SENSOR_LOCATION); sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensor::message::SensorType::SENSOR_NIGHT_MODE); } void SensorService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[SensorService] open request, priority: " << request.priority(); - const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; - OPENAUTO_LOG(info) << "[SensorService] open status: " << status; + OPENAUTO_LOG(info) << "[SensorService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[SensorService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; response.set_status(status); auto promise = aasdk::channel::SendPromise::defer(strand_); @@ -115,19 +116,21 @@ namespace f1x { void SensorService::onSensorStartRequest( const aap_protobuf::channel::sensor::event::SensorRequest &request) { - OPENAUTO_LOG(info) << "[SensorService] sensor start request, type: " << request.sensor_type(); + OPENAUTO_LOG(info) << "[SensorService] onSensorStartRequest()"; + OPENAUTO_LOG(info) << "[SensorService] Request Type: "<< request.type(); aap_protobuf::service::sensor::message::SensorStartResponseMessage response; response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); auto promise = aasdk::channel::SendPromise::defer(strand_); - if (request.sensor_type() == aap_protobuf::service::sensor::message::SENSOR_DRIVING_STATUS_DATA) + // TODO: Convert to Switch? + if (request.type() == aap_protobuf::service::sensor::message::SENSOR_DRIVING_STATUS_DATA) { promise->then(std::bind(&SensorService::sendDrivingStatusUnrestricted, this->shared_from_this()), std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1)); } - else if (request.sensor_type() == aap_protobuf::service::sensor::message::SensorType::SENSOR_NIGHT_MODE) + else if (request.type() == aap_protobuf::service::sensor::message::SensorType::SENSOR_NIGHT_MODE) { promise->then(std::bind(&SensorService::sendNightData, this->shared_from_this()), std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1)); @@ -143,6 +146,7 @@ namespace f1x { } void SensorService::sendDrivingStatusUnrestricted() { + OPENAUTO_LOG(info) << "[SensorService] sendDrivingStatusUnrestricted()"; aap_protobuf::service::sensor::message::SensorBatch indication; indication.add_driving_status_data()->set_status(aap_protobuf::service::sensor::message::DrivingStatus::DRIVE_STATUS_UNRESTRICTED); @@ -153,13 +157,14 @@ namespace f1x { } void SensorService::sendNightData() { + OPENAUTO_LOG(info) << "[SensorService] sendNightData()"; aap_protobuf::service::sensor::message::SensorBatch indication; if (SensorService::isNight) { - OPENAUTO_LOG(info) << "[SensorService] Mode night triggered"; + OPENAUTO_LOG(info) << "[SensorService] Night Mode Triggered"; indication.add_night_mode_data()->set_night_mode(true); } else { - OPENAUTO_LOG(info) << "[SensorService] Mode day triggered"; + OPENAUTO_LOG(info) << "[SensorService] Day Mode Triggered"; indication.add_night_mode_data()->set_night_mode(false); } @@ -174,6 +179,7 @@ namespace f1x { } void SensorService::sendGPSLocationData() { + OPENAUTO_LOG(info) << "[SensorService] sendGPSLocationData()"; aap_protobuf::service::sensor::message::SensorBatch indication; auto *locInd = indication.add_location_data(); @@ -206,6 +212,7 @@ namespace f1x { } void SensorService::sensorPolling() { + OPENAUTO_LOG(info) << "[SensorService] sensorPolling()"; if (!this->stopPolling) { strand_.dispatch([this, self = this->shared_from_this()]() { this->isNight = is_file_exist("/tmp/night_mode_enabled"); @@ -216,12 +223,12 @@ namespace f1x { if ((this->gpsEnabled_) && (gps_waiting(&this->gpsData_, 0)) && - //extern int gps_read(struct gps_data_t *, char *message, int message_len); - //(gps_read(&this->gpsData_) > 0) && - (this->gpsData_.fix.status != MODE_NO_FIX) && + (gps_read(&this->gpsData_) > 0) && + (this->gpsData_.status != STATUS_NO_FIX) && (this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) && (this->gpsData_.set & TIME_SET) && - (this->gpsData_.set & LATLON_SET)) { + (this->gpsData_.set & LATLON_SET)) + { this->sendGPSLocationData(); } @@ -232,12 +239,13 @@ namespace f1x { } bool SensorService::is_file_exist(const char *fileName) { + OPENAUTO_LOG(info) << "[SensorService] is_file_exist()"; std::ifstream ifile(fileName, std::ios::in); return ifile.good(); } void SensorService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[SensorService] onChannelError(): " << e.what(); } } } diff --git a/src/autoapp/Service/ServiceFactory.cpp b/src/autoapp/Service/ServiceFactory.cpp index e2ad415..b7c2b3c 100644 --- a/src/autoapp/Service/ServiceFactory.cpp +++ b/src/autoapp/Service/ServiceFactory.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -49,7 +49,6 @@ #include #include - namespace f1x { namespace openauto { namespace autoapp { @@ -64,13 +63,8 @@ namespace f1x { // TODO: MEDIA SERVICE ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] create()"; ServiceList serviceList; -/* - projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000), - std::bind(&QObject::deleteLater, std::placeholders::_1)); - serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(audioInput))); - */ - this->createMediaSinkServices(serviceList, messenger); this->createMediaSourceServices(serviceList, messenger); @@ -83,20 +77,24 @@ namespace f1x { } IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] createBluetoothService()"; projection::IBluetoothDevice::Pointer bluetoothDevice; switch (configuration_->getBluetoothAdapterType()) { case configuration::BluetoothAdapterType::LOCAL: + OPENAUTO_LOG(info) << "[ServiceFactory] Local Bluetooth"; bluetoothDevice = projection::IBluetoothDevice::Pointer(new projection::LocalBluetoothDevice(), std::bind(&QObject::deleteLater, std::placeholders::_1)); break; case configuration::BluetoothAdapterType::REMOTE: + OPENAUTO_LOG(info) << "[ServiceFactory] Remote Bluetooth"; bluetoothDevice = std::make_shared( configuration_->getBluetoothRemoteAdapterAddress()); break; default: + OPENAUTO_LOG(info) << "[ServiceFactory] Dummy Bluetooth"; bluetoothDevice = std::make_shared(); break; } @@ -105,17 +103,19 @@ namespace f1x { } IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] createInputService()"; QRect videoGeometry; switch (configuration_->getVideoResolution()) { case aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1280x720: + OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1280x720"; videoGeometry = QRect(0, 0, 1280, 720); break; - case aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1920x1080: + OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1920x1080"; videoGeometry = QRect(0, 0, 1920, 1080); break; - default: + OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 800x480"; videoGeometry = QRect(0, 0, 800, 480); break; } @@ -131,7 +131,9 @@ namespace f1x { void ServiceFactory::createMediaSinkServices(ServiceList &serviceList, aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSinkServices()"; if (configuration_->musicAudioChannelEnabled()) { + OPENAUTO_LOG(info) << "[ServiceFactory] Media Audio Channel enabled"; auto mediaAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? std::make_shared(2, 16, 48000) : @@ -143,6 +145,7 @@ namespace f1x { } if (configuration_->guidanceAudioChannelEnabled()) { + OPENAUTO_LOG(info) << "[ServiceFactory] Guidance Audio Channel enabled"; auto guidanceAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? std::make_shared(1, 16, 16000) : @@ -154,6 +157,7 @@ namespace f1x { } if (configuration_->telephonyAudioChannelEnabled()) { + OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled"; auto telephonyAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? std::make_shared(1, 16, 16000) : @@ -167,6 +171,8 @@ namespace f1x { /* * No Need to Check for systemAudioChannelEnabled - MUST be enabled by default. */ + + OPENAUTO_LOG(info) << "[ServiceFactory] System Audio Channel enabled"; auto systemAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? std::make_shared(1, 16, 16000) : @@ -183,20 +189,26 @@ namespace f1x { std::bind(&QObject::deleteLater, std::placeholders::_1)); #endif + OPENAUTO_LOG(info) << "[ServiceFactory] Video Channel enabled"; serviceList.emplace_back( std::make_shared(ioService_, messenger, std::move(videoOutput))); } void ServiceFactory::createMediaSourceServices(f1x::openauto::autoapp::service::ServiceList &serviceList, aasdk::messenger::IMessenger::Pointer messenger) { - + OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSourceServices()"; + projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000), + std::bind(&QObject::deleteLater, std::placeholders::_1)); + serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(audioInput))); } IService::Pointer ServiceFactory::createSensorService(aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] createSensorService()"; return std::make_shared(ioService_, messenger); } IService::Pointer ServiceFactory::createWifiProjectionService(aasdk::messenger::IMessenger::Pointer messenger) { + OPENAUTO_LOG(info) << "[ServiceFactory] createWifiProjectionService()"; return std::make_shared(ioService_, messenger); } diff --git a/src/autoapp/Service/VendorExtension/VendorExtensionService.cpp b/src/autoapp/Service/VendorExtension/VendorExtensionService.cpp index cbbc9c1..27d748a 100644 --- a/src/autoapp/Service/VendorExtension/VendorExtensionService.cpp +++ b/src/autoapp/Service/VendorExtension/VendorExtensionService.cpp @@ -37,43 +37,56 @@ namespace f1x { void VendorExtensionService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[VendorExtensionService] start."; + OPENAUTO_LOG(info) << "[VendorExtensionService] start()"; }); } void VendorExtensionService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[VendorExtensionService] stop."; + OPENAUTO_LOG(info) << "[VendorExtensionService] stop()"; }); } void VendorExtensionService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[VendorExtensionService] pause."; + OPENAUTO_LOG(info) << "[VendorExtensionService] pause()"; }); } void VendorExtensionService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[VendorExtensionService] resume."; + OPENAUTO_LOG(info) << "[VendorExtensionService] resume()"; }); } void VendorExtensionService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[VendorExtensionService] fill features."; + OPENAUTO_LOG(info) << "[VendorExtensionService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *vendorExtension = channelDescriptor->mutable_wifi_projection_service(); + auto *vendorExtension = service->mutable_vendor_extension_service(); } void VendorExtensionService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[VendorExtensionService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[VendorExtensionService] onChannelError(): " << e.what(); } + void VendorExtensionService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { + OPENAUTO_LOG(info) << "[VendorExtensionService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[VendorExtensionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; + response.set_status(status); + + auto promise = aasdk::channel::SendPromise::defer(strand_); + promise->then([]() {}, std::bind(&VendorExtensionService::onChannelError, this->shared_from_this(), + std::placeholders::_1)); + channel_->sendChannelOpenResponse(response, std::move(promise)); + channel_->receive(this->shared_from_this()); + } } } } diff --git a/src/autoapp/Service/WifiProjection/WifiProjectionStatus.cpp b/src/autoapp/Service/WifiProjection/WifiProjectionStatus.cpp index 58bcfbd..56b91a9 100644 --- a/src/autoapp/Service/WifiProjection/WifiProjectionStatus.cpp +++ b/src/autoapp/Service/WifiProjection/WifiProjectionStatus.cpp @@ -36,51 +36,53 @@ namespace f1x { void WifiProjectionService::start() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[WifiProjectionService] start."; + OPENAUTO_LOG(info) << "[WifiProjectionService] start()"; }); } void WifiProjectionService::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[WifiProjectionService] stop."; + OPENAUTO_LOG(info) << "[WifiProjectionService] stop()"; }); } void WifiProjectionService::pause() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[WifiProjectionService] pause."; + OPENAUTO_LOG(info) << "[WifiProjectionService] pause()"; }); } void WifiProjectionService::resume() { strand_.dispatch([this, self = this->shared_from_this()]() { - OPENAUTO_LOG(info) << "[WifiProjectionService] resume."; + OPENAUTO_LOG(info) << "[WifiProjectionService] resume()"; }); } void WifiProjectionService::fillFeatures( aap_protobuf::channel::control::servicediscovery::notification::ServiceDiscoveryResponse &response) { - OPENAUTO_LOG(info) << "[WifiProjectionService] fill features."; + OPENAUTO_LOG(info) << "[WifiProjectionService] fillFeatures()"; - auto *channelDescriptor = response.add_channels(); - channelDescriptor->set_channel_id(static_cast(channel_->getId())); + auto *service = response.add_channels(); + service->set_id(static_cast(channel_->getId())); - auto *wifiChannel = channelDescriptor->mutable_wifi_projection_service(); + auto *wifiChannel = service->mutable_wifi_projection_service(); wifiChannel->set_car_wifi_bssid(""); // TODO: Temporarily disabled and populating with empty string. } void WifiProjectionService::onWifiCredentialsRequest( const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) { + OPENAUTO_LOG(info) << "[WifiProjectionService] onWifiCredentialsRequest()"; // channel_->sendWifiCredentialsResponse(response, std::move(promise)); } void WifiProjectionService::onChannelOpenRequest(const aap_protobuf::channel::ChannelOpenRequest &request) { - OPENAUTO_LOG(info) << "[WifiProjectionService] open request, priority: " << request.priority(); - const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; - OPENAUTO_LOG(info) << "[WifiProjectionService] open status: " << status; + OPENAUTO_LOG(info) << "[WifiProjectionService] onChannelOpenRequest()"; + OPENAUTO_LOG(info) << "[WifiProjectionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); + aap_protobuf::channel::ChannelOpenResponse response; + const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; response.set_status(status); auto promise = aasdk::channel::SendPromise::defer(strand_); @@ -92,7 +94,7 @@ namespace f1x { } void WifiProjectionService::onChannelError(const aasdk::error::Error &e) { - OPENAUTO_LOG(error) << "[WifiProjectionService] channel error: " << e.what(); + OPENAUTO_LOG(error) << "[WifiProjectionService] onChannelError(): " << e.what(); } diff --git a/src/autoapp/UI/SettingsWindow.cpp b/src/autoapp/UI/SettingsWindow.cpp index cceeec6..b1ca528 100644 --- a/src/autoapp/UI/SettingsWindow.cpp +++ b/src/autoapp/UI/SettingsWindow.cpp @@ -18,7 +18,7 @@ #include #include -#include "ui_settingswindow.h" +#include "ui_settingswindow.h" // AutoGenerated at Compile Time #include #include #include @@ -30,1407 +30,1478 @@ #include #include -namespace f1x -{ -namespace openauto -{ -namespace autoapp -{ -namespace ui -{ - -SettingsWindow::SettingsWindow(configuration::IConfiguration::Pointer configuration, QWidget *parent) - : QWidget(parent) - , ui_(new Ui::SettingsWindow) - , configuration_(std::move(configuration)) -{ - ui_->setupUi(this); - connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &SettingsWindow::close); - connect(ui_->pushButtonSave, &QPushButton::clicked, this, &SettingsWindow::onSave); - connect(ui_->pushButtonUnpair , &QPushButton::clicked, this, &SettingsWindow::unpairAll); - connect(ui_->pushButtonUnpair , &QPushButton::clicked, this, &SettingsWindow::close); - connect(ui_->horizontalSliderScreenDPI, &QSlider::valueChanged, this, &SettingsWindow::onUpdateScreenDPI); - connect(ui_->horizontalSliderAlphaTrans, &QSlider::valueChanged, this, &SettingsWindow::onUpdateAlphaTrans); - connect(ui_->horizontalSliderDay, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightnessDay); - connect(ui_->horizontalSliderNight, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightnessNight); - connect(ui_->horizontalSliderBrightness1, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness1); - connect(ui_->horizontalSliderBrightness2, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness2); - connect(ui_->horizontalSliderBrightness3, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness3); - connect(ui_->horizontalSliderBrightness4, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness4); - connect(ui_->horizontalSliderBrightness5, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness5); - connect(ui_->horizontalSliderLux1, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux1); - connect(ui_->horizontalSliderLux2, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux2); - connect(ui_->horizontalSliderLux3, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux3); - connect(ui_->horizontalSliderLux4, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux4); - connect(ui_->horizontalSliderLux5, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux5); - connect(ui_->radioButtonUseExternalBluetoothAdapter, &QRadioButton::clicked, [&](bool checked) { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(checked); }); - connect(ui_->radioButtonDisableBluetooth, &QRadioButton::clicked, [&]() { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(false); }); - connect(ui_->radioButtonUseLocalBluetoothAdapter, &QRadioButton::clicked, [&]() { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(false); }); - connect(ui_->pushButtonClearSelection, &QPushButton::clicked, std::bind(&SettingsWindow::setButtonCheckBoxes, this, false)); - connect(ui_->pushButtonSelectAll, &QPushButton::clicked, std::bind(&SettingsWindow::setButtonCheckBoxes, this, true)); - connect(ui_->pushButtonResetToDefaults, &QPushButton::clicked, this, &SettingsWindow::onResetToDefaults); - connect(ui_->horizontalSliderSystemVolume, &QSlider::valueChanged, this, &SettingsWindow::onUpdateSystemVolume); - connect(ui_->horizontalSliderSystemCapture, &QSlider::valueChanged, this, &SettingsWindow::onUpdateSystemCapture); - connect(ui_->radioButtonHotspot, &QPushButton::clicked, this, &SettingsWindow::onStartHotspot); - connect(ui_->radioButtonClient, &QPushButton::clicked, this, &SettingsWindow::onStopHotspot); - connect(ui_->pushButtonSetTime, &QPushButton::clicked, this, &SettingsWindow::setTime); - connect(ui_->pushButtonSetTime, &QPushButton::clicked, this, &SettingsWindow::close); - connect(ui_->pushButtonNTP, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft rtc sync &"); }); - connect(ui_->pushButtonNTP, &QPushButton::clicked, this, &SettingsWindow::close); - connect(ui_->pushButtonCheckNow, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft update check &"); }); - connect(ui_->pushButtonDebuglog, &QPushButton::clicked, this, &SettingsWindow::close); - connect(ui_->pushButtonDebuglog, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft debuglog &");}); - connect(ui_->pushButtonNetworkAuto, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft network auto &");}); - connect(ui_->pushButtonNetwork0, &QPushButton::clicked, this, &SettingsWindow::on_pushButtonNetwork0_clicked); - connect(ui_->pushButtonNetwork1, &QPushButton::clicked, this, &SettingsWindow::on_pushButtonNetwork1_clicked); - connect(ui_->pushButtonSambaStart, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft samba start &");}); - connect(ui_->pushButtonSambaStop, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft samba stop &");}); - - // menu - ui_->tab1->show(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - - ui_->horizontalGroupBox->hide(); - ui_->labelBluetoothAdapterAddress->hide(); - ui_->lineEditExternalBluetoothAdapterAddress->hide(); - ui_->labelTestInProgress->hide(); - - connect(ui_->pushButtonTab1, &QPushButton::clicked, this, &SettingsWindow::show_tab1); - connect(ui_->pushButtonTab2, &QPushButton::clicked, this, &SettingsWindow::show_tab2); - connect(ui_->pushButtonTab3, &QPushButton::clicked, this, &SettingsWindow::show_tab3); - connect(ui_->pushButtonTab4, &QPushButton::clicked, this, &SettingsWindow::show_tab4); - connect(ui_->pushButtonTab5, &QPushButton::clicked, this, &SettingsWindow::show_tab5); - connect(ui_->pushButtonTab5, &QPushButton::clicked, this, &SettingsWindow::updateNetworkInfo); - connect(ui_->pushButtonTab6, &QPushButton::clicked, this, &SettingsWindow::show_tab6); - connect(ui_->pushButtonTab6, &QPushButton::clicked, this, &SettingsWindow::updateSystemInfo); - connect(ui_->pushButtonTab7, &QPushButton::clicked, this, &SettingsWindow::show_tab7); - connect(ui_->pushButtonTab8, &QPushButton::clicked, this, &SettingsWindow::show_tab8); - connect(ui_->pushButtonTab9, &QPushButton::clicked, this, &SettingsWindow::show_tab9); - - QTime time=QTime::currentTime(); - QString time_text_hour=time.toString("hh"); - QString time_text_minute=time.toString("mm"); - ui_->spinBoxHour->setValue((time_text_hour).toInt()); - ui_->spinBoxMinute->setValue((time_text_minute).toInt()); - ui_->label_modeswitchprogress->setText("Ok"); - ui_->label_notavailable->hide(); - - QString wifi_ssid = configuration_->getCSValue("WIFI_SSID"); - QString wifi2_ssid = configuration_->getCSValue("WIFI2_SSID"); - - ui_->pushButtonNetwork0->setText(wifi_ssid); - ui_->pushButtonNetwork1->setText(wifi2_ssid); - - if (!std::ifstream("/boot/crankshaft/network1.conf")) { - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetwork0->show(); - } - if (!std::ifstream("/boot/crankshaft/network0.conf")) { - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetwork0->setText(configuration_->getCSValue("WIFI2_SSID")); - } - if (!std::ifstream("/boot/crankshaft/network0.conf") && !std::ifstream("/boot/crankshaft/network1.conf")) { - ui_->pushButtonNetwork0->hide(); - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetworkAuto->hide(); - ui_->label_notavailable->show(); - } - - if (std::ifstream("/tmp/hotspot_active")) { - ui_->radioButtonClient->setChecked(0); - ui_->radioButtonHotspot->setChecked(1); - ui_->lineEditWifiSSID->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","ssid")); - ui_->lineEditPassword->show(); - ui_->label_password->show(); - ui_->lineEditPassword->setText("1234567890"); - ui_->clientNetworkSelect->hide(); - ui_->label_notavailable->show(); - } else { - ui_->radioButtonClient->setChecked(1); - ui_->radioButtonHotspot->setChecked(0); - ui_->lineEditWifiSSID->setText(configuration_->readFileContent("/tmp/wifi_ssid")); - ui_->lineEditPassword->hide(); - ui_->label_password->hide(); - ui_->lineEditPassword->setText(""); - ui_->clientNetworkSelect->hide(); - ui_->label_notavailable->show(); - } - - if (std::ifstream("/tmp/samba_running")) { - ui_->labelSambaStatus->setText("running"); - ui_->pushButtonSambaStart->hide(); - ui_->pushButtonSambaStop->show(); - } else { - ui_->labelSambaStatus->setText("stopped"); - ui_->pushButtonSambaStop->hide(); - ui_->pushButtonSambaStart->show(); - } - - QTimer *refresh=new QTimer(this); - connect(refresh, SIGNAL(timeout()),this,SLOT(updateInfo())); - refresh->start(5000); -} - -SettingsWindow::~SettingsWindow() -{ - delete ui_; -} - -void SettingsWindow::updateInfo() -{ - if (ui_->tab6->isVisible() == true) { - updateSystemInfo(); - } - if (ui_->tab5->isVisible() == true) { - updateNetworkInfo(); - } -} - -void SettingsWindow::onSave() -{ - configuration_->setHandednessOfTrafficType(ui_->radioButtonLeftHandDrive->isChecked() ? configuration::HandednessOfTrafficType::LEFT_HAND_DRIVE : configuration::HandednessOfTrafficType::RIGHT_HAND_DRIVE); - - configuration_->showClock(ui_->checkBoxShowClock->isChecked()); - configuration_->showBigClock(ui_->checkBoxShowBigClock->isChecked()); - configuration_->oldGUI(ui_->checkBoxOldGUI->isChecked()); - configuration_->setAlphaTrans(static_cast(ui_->horizontalSliderAlphaTrans->value())); - configuration_->hideMenuToggle(ui_->checkBoxHideMenuToggle->isChecked()); - configuration_->showLux(ui_->checkBoxShowLux->isChecked()); - configuration_->showCursor(ui_->checkBoxShowCursor->isChecked()); - configuration_->hideBrightnessControl(ui_->checkBoxHideBrightnessControl->isChecked()); - configuration_->showNetworkinfo(ui_->checkBoxNetworkinfo->isChecked()); - configuration_->mp3AutoPlay(ui_->checkBoxAutoPlay->isChecked()); - configuration_->showAutoPlay(ui_->checkBoxShowPlayer->isChecked()); - configuration_->instantPlay(ui_->checkBoxInstantPlay->isChecked()); - configuration_->hideWarning(ui_->checkBoxDontShowAgain->isChecked()); - - configuration_->setVideoFPS(ui_->radioButton30FPS->isChecked() ? aap_protobuf::service::media::shared::message::VideoFrameRateType::_30 : aap_protobuf::service::media::shared::message::VideoFrameRateType::_60); - - if(ui_->radioButton480p->isChecked()) - { - configuration_->setVideoResolution(aap_protobuf::service::media::shared::message::VideoCodecResolutionType_480p); - } - else if(ui_->radioButton720p->isChecked()) - { - configuration_->setVideoResolution(aap_protobuf::service::media::shared::message::VideoCodecResolutionType_720p); - } - else if(ui_->radioButton1080p->isChecked()) - { - configuration_->setVideoResolution(aap_protobuf::service::media::shared::message::VideoCodecResolutionType_1080p); - } - - configuration_->setScreenDPI(static_cast(ui_->horizontalSliderScreenDPI->value())); - configuration_->setOMXLayerIndex(ui_->spinBoxOmxLayerIndex->value()); - - QRect videoMargins(0, 0, ui_->spinBoxVideoMarginWidth->value(), ui_->spinBoxVideoMarginHeight->value()); - configuration_->setVideoMargins(std::move(videoMargins)); - - configuration_->setTouchscreenEnabled(ui_->checkBoxEnableTouchscreen->isChecked()); - this->saveButtonCheckBoxes(); - - configuration_->playerButtonControl(ui_->checkBoxPlayerControl->isChecked()); - - if(ui_->radioButtonDisableBluetooth->isChecked()) - { - configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::NONE); - } - else if(ui_->radioButtonUseLocalBluetoothAdapter->isChecked()) - { - configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::LOCAL); - } - else if(ui_->radioButtonUseExternalBluetoothAdapter->isChecked()) - { - configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::REMOTE); - } - - configuration_->setBluetoothRemoteAdapterAddress(ui_->lineEditExternalBluetoothAdapterAddress->text().toStdString()); - - configuration_->setMusicAudioChannelEnabled(ui_->checkBoxMusicAudioChannel->isChecked()); - configuration_->setSpeechAudioChannelEnabled(ui_->checkBoxSpeechAudioChannel->isChecked()); - configuration_->setAudioOutputBackendType(ui_->radioButtonRtAudio->isChecked() ? configuration::AudioOutputBackendType::RTAUDIO : configuration::AudioOutputBackendType::QT); - - configuration_->save(); - - // generate param string for autoapp_helper - std::string params; - params.append( std::to_string(ui_->horizontalSliderSystemVolume->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderSystemCapture->value()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxDisconnect->value()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxShutdown->value()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxDay->value()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxNight->value()) ); - params.append("#"); - if (ui_->checkBoxGPIO->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxDevMode->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxInvert->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxX11->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxRearcam->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxAndroid->currentText().toStdString()) ); - params.append("#"); - if (ui_->radioButtonX11->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->radioButtonScreenRotated->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string("'") + std::string(ui_->comboBoxPulseOutput->currentText().toStdString()) + std::string("'") ); - params.append("#"); - params.append( std::string("'") + std::string(ui_->comboBoxPulseInput->currentText().toStdString()) + std::string("'") ); - params.append("#"); - params.append( std::string(ui_->comboBoxHardwareRTC->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxTZ->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxHardwareDAC->currentText().toStdString()) ); - params.append("#"); - if (ui_->checkBoxDisableShutdown->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->checkBoxDisableScreenOff->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->radioButtonDebugmodeEnabled->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxGPIOShutdown->currentText().toStdString()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxGPIOShutdownDelay->value()) ); - params.append("#"); - if (ui_->checkBoxHotspot->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxCam->currentText().toStdString()) ); - params.append("#"); - if (ui_->checkBoxBluetoothAutoPair->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxBluetooth->currentText().toStdString()) ); - params.append("#"); - if (ui_->checkBoxHardwareSave->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxUSBCam->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxLS->currentText().split(" ")[0].toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxDayNight->currentText().toStdString()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderDay->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderNight->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderLux1->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderBrightness1->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderLux2->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderBrightness2->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderLux3->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderBrightness3->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderLux4->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderBrightness4->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderLux5->value()) ); - params.append("#"); - params.append( std::to_string(ui_->horizontalSliderBrightness5->value()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxCheckInterval->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxNightmodeStep->currentText().toStdString()) ); - params.append("#"); - if (ui_->checkBoxDisableDayNightRTC->isChecked()) { - params.append("0"); - } else { - params.append("1"); - } - params.append("#"); - if(ui_->radioButtonAnimatedCSNG->isChecked()) - { - params.append("0"); - } - else if(ui_->radioButtonCSNG->isChecked()) - { - params.append("1"); - } - else if(ui_->radioButtonCustom->isChecked()) - { - params.append("2"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxCountryCode->currentText().split("|")[0].replace(" ","").toStdString()) ); - params.append("#"); - if (ui_->checkBoxBlankOnly ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->checkBoxFlipX ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->checkBoxFlipY ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxRotation->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxResolution->currentText().toStdString()) ); - params.append("#"); - params.append( std::string((ui_->comboBoxFPS->currentText()).replace(" (not @1080)","").toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxAWB->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxEXP->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxLoopTime->currentText().toStdString()) ); - params.append("#"); - params.append( std::string(ui_->comboBoxLoopCount->currentText().toStdString()) ); - params.append("#"); - if (ui_->checkBoxAutoRecording ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->checkBoxFlipXUSB ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - if (ui_->checkBoxFlipYUSB ->isChecked()) { - params.append("1"); - } else { - params.append("0"); - } - params.append("#"); - params.append( std::string(ui_->comboBoxUSBRotation->currentText().replace("180","1").toStdString()) ); - params.append("#"); - system((std::string("/usr/local/bin/autoapp_helper setparams#") + std::string(params) + std::string(" &") ).c_str()); - - this->close(); -} - -void SettingsWindow::onResetToDefaults() -{ - QMessageBox confirmationMessage(QMessageBox::Question, "Confirmation", "Are you sure you want to reset settings?", QMessageBox::Yes | QMessageBox::Cancel); - //confirmationMessage.setWindowFlags(Qt::WindowStaysOnTopHint); - if(confirmationMessage.exec() == QMessageBox::Yes) - { - configuration_->reset(); - this->load(); - } -} - -void SettingsWindow::showEvent(QShowEvent* event) -{ - QWidget::showEvent(event); - this->load(); -} - -void SettingsWindow::load() -{ - ui_->radioButtonLeftHandDrive->setChecked(configuration_->getHandednessOfTrafficType() == configuration::HandednessOfTrafficType::LEFT_HAND_DRIVE); - ui_->radioButtonRightHandDrive->setChecked(configuration_->getHandednessOfTrafficType() == configuration::HandednessOfTrafficType::RIGHT_HAND_DRIVE); - ui_->checkBoxShowClock->setChecked(configuration_->showClock()); - ui_->horizontalSliderAlphaTrans->setValue(static_cast(configuration_->getAlphaTrans())); - - ui_->checkBoxShowBigClock->setChecked(configuration_->showBigClock()); - ui_->checkBoxOldGUI->setChecked(configuration_->oldGUI()); - ui_->checkBoxHideMenuToggle->setChecked(configuration_->hideMenuToggle()); - ui_->checkBoxShowLux->setChecked(configuration_->showLux()); - ui_->checkBoxShowCursor->setChecked(configuration_->showCursor()); - ui_->checkBoxHideBrightnessControl->setChecked(configuration_->hideBrightnessControl()); - ui_->checkBoxNetworkinfo->setChecked(configuration_->showNetworkinfo()); - ui_->checkBoxAutoPlay->setChecked(configuration_->mp3AutoPlay()); - ui_->checkBoxShowPlayer->setChecked(configuration_->showAutoPlay()); - ui_->checkBoxInstantPlay->setChecked(configuration_->instantPlay()); - ui_->checkBoxDontShowAgain->setChecked(configuration_->hideWarning()); - - ui_->radioButton30FPS->setChecked(configuration_->getVideoFPS() == aap_protobuf::service::media::shared::message::VideoFrameRateType::_30); - ui_->radioButton60FPS->setChecked(configuration_->getVideoFPS() == aap_protobuf::service::media::shared::message::VideoFrameRateType::_60); - - ui_->radioButton480p->setChecked(configuration_->getVideoResolution() == aap_protobuf::service::media::shared::message::VideoCodecResolutionType_480p); - ui_->radioButton720p->setChecked(configuration_->getVideoResolution() == aap_protobuf::service::media::shared::message::VideoCodecResolutionType_720p); - ui_->radioButton1080p->setChecked(configuration_->getVideoResolution() == aap_protobuf::service::media::shared::message::VideoCodecResolutionType_1080p); - ui_->horizontalSliderScreenDPI->setValue(static_cast(configuration_->getScreenDPI())); - ui_->spinBoxOmxLayerIndex->setValue(configuration_->getOMXLayerIndex()); - - const auto& videoMargins = configuration_->getVideoMargins(); - ui_->spinBoxVideoMarginWidth->setValue(videoMargins.width()); - ui_->spinBoxVideoMarginHeight->setValue(videoMargins.height()); - - ui_->checkBoxEnableTouchscreen->setChecked(configuration_->getTouchscreenEnabled()); - this->loadButtonCheckBoxes(); - ui_->checkBoxPlayerControl->setChecked(configuration_->playerButtonControl()); - - ui_->radioButtonDisableBluetooth->setChecked(configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::NONE); - ui_->radioButtonUseLocalBluetoothAdapter->setChecked(configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::LOCAL); - ui_->radioButtonUseExternalBluetoothAdapter->setChecked(configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::REMOTE); - ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::REMOTE); - ui_->lineEditExternalBluetoothAdapterAddress->setText(QString::fromStdString(configuration_->getBluetoothRemoteAdapterAddress())); - - ui_->checkBoxMusicAudioChannel->setChecked(configuration_->musicAudioChannelEnabled()); - ui_->checkBoxSpeechAudioChannel->setChecked(configuration_->speechAudioChannelEnabled()); - - const auto& audioOutputBackendType = configuration_->getAudioOutputBackendType(); - ui_->radioButtonRtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::RTAUDIO); - ui_->radioButtonQtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::QT); - - ui_->checkBoxHardwareSave->setChecked(false); - QStorageInfo storage("/media/USBDRIVES/CSSTORAGE"); - storage.refresh(); - if (storage.isValid() && storage.isReady()) { - if (storage.isReadOnly()) { - ui_->labelStorage->setText("Storage is read only! (" + storage.device() + ") - This can be caused by demaged filesystem on CSSTORAGE. Try a reboot."); - } else { - ui_->labelStorage->setText("Device: " + storage.device() + " Label: " + storage.displayName() + " Total: " + QString::number(storage.bytesTotal()/1024/1024/1024) + "GB Free: " + QString::number(storage.bytesFree()/1024/1024/1024) + "GB (" + storage.fileSystemType() + ")"); - } - } else { - ui_->labelStorage->setText("Storage is not ready or missing!"); - } -} - -void SettingsWindow::loadButtonCheckBoxes() -{ - const auto& buttonCodes = configuration_->getButtonCodes(); - ui_->checkBoxPlayButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY) != buttonCodes.end()); - ui_->checkBoxPauseButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PAUSE) != buttonCodes.end()); - ui_->checkBoxTogglePlayButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY_PAUSE) != buttonCodes.end()); - ui_->checkBoxNextTrackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_NEXT) != buttonCodes.end()); - ui_->checkBoxPreviousTrackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PREVIOUS) != buttonCodes.end()); - ui_->checkBoxHomeButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_HOME) != buttonCodes.end()); - ui_->checkBoxPhoneButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_CALL) != buttonCodes.end()); - ui_->checkBoxCallEndButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_ENDCALL) != buttonCodes.end()); - ui_->checkBoxVoiceCommandButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_SEARCH) != buttonCodes.end()); - ui_->checkBoxLeftButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_LEFT) != buttonCodes.end()); - ui_->checkBoxRightButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_RIGHT) != buttonCodes.end()); - ui_->checkBoxUpButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_UP) != buttonCodes.end()); - ui_->checkBoxDownButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_DOWN) != buttonCodes.end()); - ui_->checkBoxScrollWheelButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_ROTARY_CONTROLLER) != buttonCodes.end()); - ui_->checkBoxBackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_BACK) != buttonCodes.end()); - ui_->checkBoxEnterButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_CENTER) != buttonCodes.end()); - ui_->checkBoxNavButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), aap_protobuf::service::media::sink::KeyCode::KEYCODE_NAVIGATION) != buttonCodes.end()); -} - -void SettingsWindow::setButtonCheckBoxes(bool value) -{ - ui_->checkBoxPlayButton->setChecked(value); - ui_->checkBoxPauseButton->setChecked(value); - ui_->checkBoxTogglePlayButton->setChecked(value); - ui_->checkBoxNextTrackButton->setChecked(value); - ui_->checkBoxPreviousTrackButton->setChecked(value); - ui_->checkBoxHomeButton->setChecked(value); - ui_->checkBoxPhoneButton->setChecked(value); - ui_->checkBoxCallEndButton->setChecked(value); - ui_->checkBoxVoiceCommandButton->setChecked(value); - ui_->checkBoxLeftButton->setChecked(value); - ui_->checkBoxRightButton->setChecked(value); - ui_->checkBoxUpButton->setChecked(value); - ui_->checkBoxDownButton->setChecked(value); - ui_->checkBoxScrollWheelButton->setChecked(value); - ui_->checkBoxBackButton->setChecked(value); - ui_->checkBoxEnterButton->setChecked(value); - ui_->checkBoxNavButton->setChecked(value); -} - -void SettingsWindow::saveButtonCheckBoxes() -{ - configuration::IConfiguration::ButtonCodes buttonCodes; - this->saveButtonCheckBox(ui_->checkBoxPlayButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY); - this->saveButtonCheckBox(ui_->checkBoxPauseButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PAUSE); - this->saveButtonCheckBox(ui_->checkBoxTogglePlayButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY_PAUSE); - this->saveButtonCheckBox(ui_->checkBoxNextTrackButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_NEXT); - this->saveButtonCheckBox(ui_->checkBoxPreviousTrackButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PREVIOUS); - this->saveButtonCheckBox(ui_->checkBoxHomeButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_HOME); - this->saveButtonCheckBox(ui_->checkBoxPhoneButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_CALL); - this->saveButtonCheckBox(ui_->checkBoxCallEndButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_ENDCALL); - this->saveButtonCheckBox(ui_->checkBoxVoiceCommandButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_SEARCH); - this->saveButtonCheckBox(ui_->checkBoxLeftButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_LEFT); - this->saveButtonCheckBox(ui_->checkBoxRightButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_RIGHT); - this->saveButtonCheckBox(ui_->checkBoxUpButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_UP); - this->saveButtonCheckBox(ui_->checkBoxDownButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_DOWN); - this->saveButtonCheckBox(ui_->checkBoxScrollWheelButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_ROTARY_CONTROLLER); - this->saveButtonCheckBox(ui_->checkBoxBackButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_BACK); - this->saveButtonCheckBox(ui_->checkBoxEnterButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_CENTER); - this->saveButtonCheckBox(ui_->checkBoxNavButton, buttonCodes, aap_protobuf::service::media::sink::KeyCode::KEYCODE_NAVIGATION); - configuration_->setButtonCodes(buttonCodes); -} - -void SettingsWindow::saveButtonCheckBox(const QCheckBox* checkBox, configuration::IConfiguration::ButtonCodes& buttonCodes, aap_protobuf::service::media::sink::KeyCode buttonCode) -{ - if(checkBox->isChecked()) - { - buttonCodes.push_back(buttonCode); - } -} - -void SettingsWindow::onUpdateScreenDPI(int value) -{ - ui_->labelScreenDPIValue->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateAlphaTrans(int value) -{ - double alpha = value/100.0; - ui_->labelAlphaTransValue->setText(QString::number(alpha)); -} - -void SettingsWindow::onUpdateBrightnessDay(int value) -{ - ui_->labelBrightnessDay->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightnessNight(int value) -{ - ui_->labelBrightnessNight->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateSystemVolume(int value) -{ - ui_->labelSystemVolumeValue->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateSystemCapture(int value) -{ - ui_->labelSystemCaptureValue->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateLux1(int value) -{ - ui_->valueLux1->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateLux2(int value) -{ - ui_->valueLux2->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateLux3(int value) -{ - ui_->valueLux3->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateLux4(int value) -{ - ui_->valueLux4->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateLux5(int value) -{ - ui_->valueLux5->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightness1(int value) -{ - ui_->valueBrightness1->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightness2(int value) -{ - ui_->valueBrightness2->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightness3(int value) -{ - ui_->valueBrightness3->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightness4(int value) -{ - ui_->valueBrightness4->setText(QString::number(value)); -} - -void SettingsWindow::onUpdateBrightness5(int value) -{ - ui_->valueBrightness5->setText(QString::number(value)); -} - -void SettingsWindow::unpairAll() -{ - system("/usr/local/bin/crankshaft bluetooth unpair &"); -} - -void SettingsWindow::setTime() -{ - // generate param string for autoapp_helper - std::string params; - params.append( std::to_string(ui_->spinBoxHour->value()) ); - params.append("#"); - params.append( std::to_string(ui_->spinBoxMinute->value()) ); - params.append("#"); - system((std::string("/usr/local/bin/autoapp_helper settime#") + std::string(params) + std::string(" &") ).c_str()); -} - -void SettingsWindow::syncNTPTime() -{ - system("/usr/local/bin/crankshaft rtc sync &"); -} - -void SettingsWindow::loadSystemValues() -{ - // set brightness slider attribs - ui_->horizontalSliderDay->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderDay->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderDay->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderDay->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderDay->setValue(configuration_->getCSValue("BR_DAY").toInt()); - - ui_->horizontalSliderNight->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderNight->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderNight->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderNight->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderNight->setValue(configuration_->getCSValue("BR_NIGHT").toInt()); - - ui_->horizontalSliderBrightness1->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderBrightness1->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderBrightness1->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderBrightness1->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - - ui_->horizontalSliderBrightness2->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderBrightness2->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderBrightness2->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderBrightness2->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - - ui_->horizontalSliderBrightness3->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderBrightness3->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderBrightness3->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderBrightness3->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - - ui_->horizontalSliderBrightness4->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderBrightness4->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderBrightness4->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderBrightness4->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - - ui_->horizontalSliderBrightness5->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); - ui_->horizontalSliderBrightness5->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); - ui_->horizontalSliderBrightness5->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); - ui_->horizontalSliderBrightness5->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); - - // set tsl2561 slider attribs - ui_->horizontalSliderLux1->setValue(configuration_->getCSValue("LUX_LEVEL_1").toInt()); - ui_->horizontalSliderBrightness1->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_1").toInt()); - ui_->horizontalSliderLux2->setValue(configuration_->getCSValue("LUX_LEVEL_2").toInt()); - ui_->horizontalSliderBrightness2->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_2").toInt()); - ui_->horizontalSliderLux3->setValue(configuration_->getCSValue("LUX_LEVEL_3").toInt()); - ui_->horizontalSliderBrightness3->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_3").toInt()); - ui_->horizontalSliderLux4->setValue(configuration_->getCSValue("LUX_LEVEL_4").toInt()); - ui_->horizontalSliderBrightness4->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_4").toInt()); - ui_->horizontalSliderLux5->setValue(configuration_->getCSValue("LUX_LEVEL_5").toInt()); - ui_->horizontalSliderBrightness5->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_5").toInt()); - ui_->comboBoxCheckInterval->setCurrentText(configuration_->getCSValue("TSL2561_CHECK_INTERVAL")); - ui_->comboBoxNightmodeStep->setCurrentText(configuration_->getCSValue("TSL2561_DAYNIGHT_ON_STEP")); - - if (std::ifstream("/tmp/return_value")) { - QString return_values = configuration_->readFileContent("/tmp/return_value"); - QStringList getparams = return_values.split("#"); - - // version string - ui_->valueSystemVersion->setText(configuration_->readFileContent("/etc/crankshaft.build")); - // date string - ui_->valueSystemBuildDate->setText(configuration_->readFileContent("/etc/crankshaft.date")); - // set volume - ui_->labelSystemVolumeValue->setText(configuration_->readFileContent("/boot/crankshaft/volume")); - ui_->horizontalSliderSystemVolume->setValue(configuration_->readFileContent("/boot/crankshaft/volume").toInt()); - // set cap volume - ui_->labelSystemCaptureValue->setText(configuration_->readFileContent("/boot/crankshaft/capvolume")); - ui_->horizontalSliderSystemCapture->setValue(configuration_->readFileContent("/boot/crankshaft/capvolume").toInt()); - // set shutdown - ui_->valueShutdownTimer->setText("- - -"); - ui_->spinBoxShutdown->setValue(configuration_->getCSValue("DISCONNECTION_POWEROFF_MINS").toInt()); - // set disconnect - ui_->valueDisconnectTimer->setText("- - -"); - ui_->spinBoxDisconnect->setValue(configuration_->getCSValue("DISCONNECTION_SCREEN_POWEROFF_SECS").toInt()); - // set day/night - ui_->spinBoxDay->setValue(configuration_->getCSValue("RTC_DAY_START").toInt()); - ui_->spinBoxNight->setValue(configuration_->getCSValue("RTC_NIGHT_START").toInt()); - // set gpios - if (configuration_->getCSValue("ENABLE_GPIO") == "1") { - ui_->checkBoxGPIO->setChecked(true); - } else { - ui_->checkBoxGPIO->setChecked(false); - } - ui_->comboBoxDevMode->setCurrentText(configuration_->getCSValue("DEV_PIN")); - ui_->comboBoxInvert->setCurrentText(configuration_->getCSValue("INVERT_PIN")); - ui_->comboBoxX11->setCurrentText(configuration_->getCSValue("X11_PIN")); - ui_->comboBoxRearcam->setCurrentText(configuration_->getCSValue("REARCAM_PIN")); - ui_->comboBoxAndroid->setCurrentText(configuration_->getCSValue("ANDROID_PIN")); - // set mode - if (configuration_->getCSValue("START_X11") == "0") { - ui_->radioButtonEGL->setChecked(true); - } else { - ui_->radioButtonX11->setChecked(true); - } - // set rotation - if (configuration_->getCSValue("FLIP_SCREEN") == "0") { - ui_->radioButtonScreenNormal->setChecked(true); - } else { - ui_->radioButtonScreenRotated->setChecked(true); - } - - if (std::ifstream("/tmp/get_inputs")) { - QFile inputsFile(QString("/tmp/get_inputs")); - inputsFile.open(QIODevice::ReadOnly); - QTextStream data_return(&inputsFile); - QStringList inputs = data_return.readAll().split("\n"); - inputsFile.close(); - int cleaner = ui_->comboBoxPulseInput->count(); - while (cleaner > -1) { - ui_->comboBoxPulseInput->removeItem(cleaner); - cleaner--; - } - int indexin = inputs.count(); - int countin = 0; - while (countin < indexin-1) { - ui_->comboBoxPulseInput->addItem(inputs[countin]); - countin++; - } - } - - if (std::ifstream("/tmp/get_outputs")) { - QFile outputsFile(QString("/tmp/get_outputs")); - outputsFile.open(QIODevice::ReadOnly); - QTextStream data_return(&outputsFile); - QStringList outputs = data_return.readAll().split("\n"); - outputsFile.close(); - int cleaner = ui_->comboBoxPulseOutput->count(); - while (cleaner > -1) { - ui_->comboBoxPulseOutput->removeItem(cleaner); - cleaner--; - } - int indexout = outputs.count(); - int countout = 0; - while (countout < indexout-1) { - ui_->comboBoxPulseOutput->addItem(outputs[countout]); - countout++; - } - } - - ui_->comboBoxPulseOutput->setCurrentText(configuration_->readFileContent("/tmp/get_default_output")); - ui_->comboBoxPulseInput->setCurrentText(configuration_->readFileContent("/tmp/get_default_input")); - - if (std::ifstream("/tmp/timezone_listing")) { - QFile zoneFile(QString("/tmp/timezone_listing")); - zoneFile.open(QIODevice::ReadOnly); - QTextStream data_return(&zoneFile); - QStringList zones = data_return.readAll().split("\n"); - zoneFile.close(); - int cleaner = ui_->comboBoxTZ->count(); - while (cleaner > 0) { - ui_->comboBoxTZ->removeItem(cleaner); - cleaner--; - } - int indexout = zones.count(); - int countzone = 0; - while (countzone < indexout-1) { - ui_->comboBoxTZ->addItem(zones[countzone]); - countzone++; - } - } - - // set rtc - QString rtcstring = configuration_->getParamFromFile("/boot/config.txt","dtoverlay=i2c-rtc"); - if (rtcstring != "") { - QStringList rtc = rtcstring.split(","); - ui_->comboBoxHardwareRTC->setCurrentText(rtc[1].trimmed()); - // set timezone - ui_->comboBoxTZ->setCurrentText(configuration_->readFileContent("/etc/timezone")); - } else { - ui_->comboBoxHardwareRTC->setCurrentText("none"); - ui_->comboBoxTZ->setCurrentText(configuration_->readFileContent("/etc/timezone")); - } - - // set dac - QString dac = "Custom"; - if (getparams[4] == "allo-boss-dac-pcm512x-audio") { - dac = "Allo - Boss"; - } - if (getparams[4] == "allo-piano-dac-pcm512x-audio") { - dac = "Allo - Piano"; - } - if (getparams[4] == "iqaudio-dacplus") { - dac = "IQaudIO - Pi-DAC Plus/Pro/Zero"; - } - if (getparams[4] == "iqaudio-dacplus,unmute_amp") { - dac = "IQaudIO - Pi-Digi Amp Plus"; - } - if (getparams[4] == "iqaudio-dacplus,auto_mute_amp") { - dac = "IQaudIO - Pi-Digi Amp Plus - Automute"; - } - if (getparams[4] == "iqaudio-digi-wm8804-audio") { - dac = "IQaudIO - Pi-Digi Plus"; - } - if (getparams[4] == "audioinjector-wm8731-audio") { - dac = "Audioinjector - Zero/Stereo"; - } - if (getparams[4] == "hifiberry-dac") { - dac = "Hifiberry - DAC"; - } - if (getparams[4] == "hifiberry-dacplus") { - dac = "Hifiberry - DAC Plus"; - } - if (getparams[4] == "hifiberry-digi") { - dac = "Hifiberry - Digi"; - } - if (getparams[4] == "hifiberry-digi-pro") { - dac = "Hifiberry - Digi Pro"; - } - if (getparams[4] == "hifiberry-amp") { - dac = "Hifiberry - DAC Amp"; - } - if (getparams[4] == "audio") { - dac = "Raspberry Pi - Onboard"; - } - ui_->comboBoxHardwareDAC->setCurrentText(dac); - - // set shutdown disable - if (configuration_->getCSValue("DISCONNECTION_POWEROFF_DISABLE") == "1") { - ui_->checkBoxDisableShutdown->setChecked(true); - } else { - ui_->checkBoxDisableShutdown->setChecked(false); - } - - // set screen off disable - if (configuration_->getCSValue("DISCONNECTION_SCREEN_POWEROFF_DISABLE") == "1") { - ui_->checkBoxDisableScreenOff->setChecked(true); - } else { - ui_->checkBoxDisableScreenOff->setChecked(false); - } - - // set custom brightness command - if (configuration_->getCSValue("CUSTOM_BRIGHTNESS_COMMAND") != "") { - ui_->labelCustomBrightnessCommand->setText(configuration_->getCSValue("CUSTOM_BRIGHTNESS_COMMAND") + " brvalue"); - } else { - ui_->labelCustomBrightnessCommand->setText("Disabled"); - } - - // set debug mode - if (configuration_->getCSValue("DEBUG_MODE") == "1") { - ui_->radioButtonDebugmodeEnabled->setChecked(true); - } else { - ui_->radioButtonDebugmodeDisabled->setChecked(true); - } - - // GPIO based shutdown - ui_->comboBoxGPIOShutdown->setCurrentText(configuration_->getCSValue("IGNITION_PIN")); - ui_->spinBoxGPIOShutdownDelay->setValue(configuration_->getCSValue("IGNITION_DELAY").toInt()); - - // Wifi Hotspot - if (configuration_->getCSValue("ENABLE_HOTSPOT") == "1") { - ui_->checkBoxHotspot->setChecked(true); - } else { - ui_->checkBoxHotspot->setChecked(false); - } - - // set cam - if (configuration_->getParamFromFile("/boot/config.txt","start_x") == "1") { - ui_->comboBoxCam->setCurrentText("enabled"); - } else { - ui_->comboBoxCam->setCurrentText("disabled"); - } - if (configuration_->getCSValue("RPICAM_HFLIP") == "1") { - ui_->checkBoxFlipX->setChecked(true); - } else { - ui_->checkBoxFlipX->setChecked(false); - } - if (configuration_->getCSValue("RPICAM_VFLIP") == "1") { - ui_->checkBoxFlipY->setChecked(true); - } else { - ui_->checkBoxFlipY->setChecked(false); - } - ui_->comboBoxRotation->setCurrentText(configuration_->getCSValue("RPICAM_ROTATION")); - ui_->comboBoxResolution->setCurrentText(configuration_->getCSValue("RPICAM_RESOLUTION")); - ui_->comboBoxFPS->setCurrentText(configuration_->getCSValue("RPICAM_FPS")); - ui_->comboBoxAWB->setCurrentText(configuration_->getCSValue("RPICAM_AWB")); - ui_->comboBoxEXP->setCurrentText(configuration_->getCSValue("RPICAM_EXP")); - ui_->comboBoxLoopTime->setCurrentText(configuration_->getCSValue("RPICAM_LOOPTIME")); - ui_->comboBoxLoopCount->setCurrentText(configuration_->getCSValue("RPICAM_LOOPCOUNT")); - - if (configuration_->getCSValue("RPICAM_AUTORECORDING") == "1") { - ui_->checkBoxAutoRecording->setChecked(true); - } else { - ui_->checkBoxAutoRecording->setChecked(false); - } - - if (configuration_->getCSValue("USBCAM_USE") == "1") { - ui_->comboBoxUSBCam->setCurrentText("enabled"); - } else { - ui_->comboBoxUSBCam->setCurrentText("none"); - } - if (configuration_->getCSValue("USBCAM_ROTATION") == "1") { - ui_->comboBoxUSBRotation->setCurrentText("180"); - } else { - ui_->comboBoxUSBRotation->setCurrentText("0"); - } - if (configuration_->getCSValue("USBCAM_HFLIP") == "1") { - ui_->checkBoxFlipXUSB->setChecked(true); - } else { - ui_->checkBoxFlipXUSB->setChecked(false); - } - if (configuration_->getCSValue("USBCAM_VFLIP") == "1") { - ui_->checkBoxFlipYUSB->setChecked(true); - } else { - ui_->checkBoxFlipYUSB->setChecked(false); - } - - // set bluetooth - if (configuration_->getCSValue("ENABLE_BLUETOOTH") == "1") { - // check external bluetooth enabled - if (configuration_->getCSValue("EXTERNAL_BLUETOOTH") == "1") { - ui_->radioButtonUseExternalBluetoothAdapter->setChecked(true); - } else { - ui_->radioButtonUseLocalBluetoothAdapter->setChecked(true); - } - // mac - //ui_->lineEditExternalBluetoothAdapterAddress->setText(getparams[37]); - } else { - ui_->radioButtonDisableBluetooth->setChecked(true); - ui_->lineEditExternalBluetoothAdapterAddress->setText(""); - } - if (configuration_->getCSValue("ENABLE_PAIRABLE") == "1") { - ui_->checkBoxBluetoothAutoPair->setChecked(true); - } else { - ui_->checkBoxBluetoothAutoPair->setChecked(false); - } - // set bluetooth type - if (configuration_->getCSValue("ENABLE_BLUETOOTH") == "1") { - QString bt = configuration_->getParamFromFile("/boot/config.txt","dtoverlay=pi3-disable-bt"); - if (bt.contains("pi3-disable-bt")) { - ui_->comboBoxBluetooth->setCurrentText("external"); - } else { - ui_->comboBoxBluetooth->setCurrentText("builtin"); - } - } else { - ui_->comboBoxBluetooth->setCurrentText("none"); - } - - // set lightsensor - if (std::ifstream("/etc/cs_lightsensor")) { - ui_->comboBoxLS->setCurrentIndex(1); - ui_->groupBoxSliderDay->hide(); - ui_->groupBoxSliderNight->hide(); - } else { - ui_->comboBoxLS->setCurrentIndex(0); - ui_->pushButtonTab9->hide(); - ui_->groupBoxSliderDay->show(); - ui_->groupBoxSliderNight->show(); - } - ui_->comboBoxDayNight->setCurrentText(configuration_->getCSValue("DAYNIGHT_PIN")); - if (configuration_->getCSValue("RTC_DAYNIGHT") == "1") { - ui_->checkBoxDisableDayNightRTC->setChecked(false); - } else { - ui_->checkBoxDisableDayNightRTC->setChecked(true); - } - QString theme = configuration_->getParamFromFile("/etc/plymouth/plymouthd.conf","Theme"); - if (theme == "csnganimation") { - ui_->radioButtonAnimatedCSNG->setChecked(true); - } - else if (theme == "crankshaft") { - ui_->radioButtonCSNG->setChecked(true); - } - else if (theme == "custom") { - ui_->radioButtonCustom->setChecked(true); - } - // wifi country code - ui_->comboBoxCountryCode->setCurrentIndex(ui_->comboBoxCountryCode->findText(configuration_->getCSValue("WIFI_COUNTRY"), Qt::MatchFlag::MatchStartsWith)); - // set screen blank instead off - if (configuration_->getCSValue("SCREEN_POWEROFF_OVERRIDE") == "1") { - ui_->checkBoxBlankOnly->setChecked(true); - } else { - ui_->checkBoxBlankOnly->setChecked(false); - } - } - // update network info - updateNetworkInfo(); -} - -void SettingsWindow::onStartHotspot() -{ - ui_->label_modeswitchprogress->setText("Wait ..."); - ui_->clientNetworkSelect->hide(); - ui_->label_notavailable->show(); - ui_->radioButtonClient->setEnabled(0); - ui_->radioButtonHotspot->setEnabled(0); - ui_->lineEdit_wlan0->setText(""); - ui_->lineEditWifiSSID->setText(""); - ui_->pushButtonNetworkAuto->hide(); - qApp->processEvents(); - std::remove("/tmp/manual_hotspot_control"); - std::ofstream("/tmp/manual_hotspot_control"); - system("/opt/crankshaft/service_hotspot.sh start &"); -} - -void SettingsWindow::onStopHotspot() -{ - ui_->label_modeswitchprogress->setText("Wait ..."); - ui_->clientNetworkSelect->hide(); - ui_->label_notavailable->show(); - ui_->radioButtonClient->setEnabled(0); - ui_->radioButtonHotspot->setEnabled(0); - ui_->lineEdit_wlan0->setText(""); - ui_->lineEditWifiSSID->setText(""); - ui_->lineEditPassword->setText(""); - ui_->pushButtonNetworkAuto->hide(); - qApp->processEvents(); - system("/opt/crankshaft/service_hotspot.sh stop &"); -} - -void SettingsWindow::updateSystemInfo() -{ - // free ram - struct sysinfo info; - sysinfo(&info); - ui_->valueSystemFreeMem->setText(QString::number(info.freeram/1024/1024) + " MB"); - // current cpu speed - QString freq = configuration_->readFileContent("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"); - int currentfreq = freq.toInt()/1000; - ui_->valueSystemCPUFreq->setText(QString::number(currentfreq) + "MHz"); - // current cpu temp - QString temp = configuration_->readFileContent("/sys/class/thermal/thermal_zone0/temp"); - int currenttemp = temp.toInt()/1000; - ui_->valueSystemCPUTemp->setText(QString::number(currenttemp) + "°C"); - // get remaining times - QProcess process; - process.start("/bin/bash", QStringList() << "-c" << "systemctl list-timers -all | grep disconnect | awk {'print $1'}"); - process.waitForFinished(-1); - QString stdout = process.readAllStandardOutput(); - if (stdout.simplified() != "n/a") { - process.start("/bin/bash", QStringList() << "-c" << "systemctl list-timers -all | grep disconnect | awk {'print $5\" \"$6'}"); - process.waitForFinished(-1); - QString stdout = process.readAllStandardOutput(); - if (stdout.simplified() != "") { - ui_->valueDisconnectTimer->setText(stdout.simplified()); - } else { - ui_->valueDisconnectTimer->setText("Stopped"); - } - } else { - ui_->valueDisconnectTimer->setText("Stopped"); - } - process.start("/bin/bash", QStringList() << "-c" << "systemctl list-timers -all | grep shutdown | awk {'print $1'}"); - process.waitForFinished(-1); - stdout = process.readAllStandardOutput(); - if (stdout.simplified() != "n/a") { - process.start("/bin/bash", QStringList() << "-c" << "systemctl list-timers -all | grep shutdown | awk {'print $5\" \"$6'}"); - process.waitForFinished(-1); - QString stdout = process.readAllStandardOutput(); - if (stdout.simplified() != "") { - ui_->valueShutdownTimer->setText(stdout.simplified()); - } else { - ui_->valueShutdownTimer->setText("Stopped"); - } - } else { - ui_->valueShutdownTimer->setText("Stopped"); - } -} - -void SettingsWindow::show_tab1() -{ - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab1->show(); -} - -void SettingsWindow::show_tab2() -{ - ui_->tab1->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab2->show(); -} - -void SettingsWindow::show_tab3() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab3->show(); -} - -void SettingsWindow::show_tab4() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab4->show(); -} - -void SettingsWindow::show_tab5() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab5->show(); -} - -void SettingsWindow::show_tab6() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab6->show(); -} - -void SettingsWindow::show_tab7() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab8->hide(); - ui_->tab9->hide(); - ui_->tab7->show(); -} - -void SettingsWindow::show_tab8() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab9->hide(); - ui_->tab8->show(); -} - -void SettingsWindow::show_tab9() -{ - ui_->tab1->hide(); - ui_->tab2->hide(); - ui_->tab3->hide(); - ui_->tab4->hide(); - ui_->tab5->hide(); - ui_->tab6->hide(); - ui_->tab7->hide(); - ui_->tab8->hide(); - ui_->tab9->show(); -} - -} -} -} -} - -void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonAudioTest_clicked() -{ - ui_->labelTestInProgress->show(); - ui_->pushButtonAudioTest->hide(); - qApp->processEvents(); - system("/usr/local/bin/crankshaft audio test"); - ui_->pushButtonAudioTest->show(); - ui_->labelTestInProgress->hide(); -} - -void f1x::openauto::autoapp::ui::SettingsWindow::updateNetworkInfo() -{ - if (std::ifstream("/tmp/samba_running")) { - ui_->labelSambaStatus->setText("running"); - if (ui_->pushButtonSambaStart->isVisible() == true) { - ui_->pushButtonSambaStart->hide(); - ui_->pushButtonSambaStop->show(); - } - } else { - ui_->labelSambaStatus->setText("stopped"); - if (ui_->pushButtonSambaStop->isVisible() == true) { - ui_->pushButtonSambaStop->hide(); - ui_->pushButtonSambaStart->show(); - } - } - - if (!std::ifstream("/tmp/mode_change_progress")) { - QNetworkInterface eth0if = QNetworkInterface::interfaceFromName("eth0"); - if (eth0if.flags().testFlag(QNetworkInterface::IsUp)) { - QList entrieseth0 = eth0if.addressEntries(); - if (!entrieseth0.isEmpty()) { - QNetworkAddressEntry eth0 = entrieseth0.first(); - //qDebug() << "eth0: " << eth0.ip(); - ui_->lineEdit_eth0->setText(eth0.ip().toString()); - } - } else { - //qDebug() << "eth0: down"; - ui_->lineEdit_eth0->setText("interface down"); - } - - QNetworkInterface wlan0if = QNetworkInterface::interfaceFromName("wlan0"); - if (wlan0if.flags().testFlag(QNetworkInterface::IsUp)) { - QList entrieswlan0 = wlan0if.addressEntries(); - if (!entrieswlan0.isEmpty()) { - QNetworkAddressEntry wlan0 = entrieswlan0.first(); - //qDebug() << "wlan0: " << wlan0.ip(); - ui_->lineEdit_wlan0->setText(wlan0.ip().toString()); - } - } else { - //qDebug() << "wlan0: down"; - ui_->lineEdit_wlan0->setText("interface down"); - } - - if (std::ifstream("/tmp/hotspot_active")) { - ui_->radioButtonClient->setEnabled(1); - ui_->radioButtonHotspot->setEnabled(1); - ui_->radioButtonHotspot->setChecked(1); - ui_->radioButtonClient->setChecked(0); - ui_->label_modeswitchprogress->setText("Ok"); - ui_->lineEditWifiSSID->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","ssid")); - ui_->lineEditPassword->show(); - ui_->label_password->show(); - ui_->lineEditPassword->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf","wpa_passphrase")); - ui_->clientNetworkSelect->hide(); +#ifdef MAC_OS +#include +#include +#include +#include +#include +#include +#endif + +namespace f1x { + namespace openauto { + namespace autoapp { + namespace ui { + + SettingsWindow::SettingsWindow(configuration::IConfiguration::Pointer configuration, QWidget *parent) + : QWidget(parent), ui_(new Ui::SettingsWindow), configuration_(std::move(configuration)) { + ui_->setupUi(this); + connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &SettingsWindow::close); + connect(ui_->pushButtonSave, &QPushButton::clicked, this, &SettingsWindow::onSave); + connect(ui_->pushButtonUnpair, &QPushButton::clicked, this, &SettingsWindow::unpairAll); + connect(ui_->pushButtonUnpair, &QPushButton::clicked, this, &SettingsWindow::close); + connect(ui_->horizontalSliderScreenDPI, &QSlider::valueChanged, this, &SettingsWindow::onUpdateScreenDPI); + connect(ui_->horizontalSliderAlphaTrans, &QSlider::valueChanged, this, &SettingsWindow::onUpdateAlphaTrans); + connect(ui_->horizontalSliderDay, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightnessDay); + connect(ui_->horizontalSliderNight, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightnessNight); + connect(ui_->horizontalSliderBrightness1, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness1); + connect(ui_->horizontalSliderBrightness2, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness2); + connect(ui_->horizontalSliderBrightness3, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness3); + connect(ui_->horizontalSliderBrightness4, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness4); + connect(ui_->horizontalSliderBrightness5, &QSlider::valueChanged, this, &SettingsWindow::onUpdateBrightness5); + connect(ui_->horizontalSliderLux1, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux1); + connect(ui_->horizontalSliderLux2, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux2); + connect(ui_->horizontalSliderLux3, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux3); + connect(ui_->horizontalSliderLux4, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux4); + connect(ui_->horizontalSliderLux5, &QSlider::valueChanged, this, &SettingsWindow::onUpdateLux5); + connect(ui_->radioButtonUseExternalBluetoothAdapter, &QRadioButton::clicked, + [&](bool checked) { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(checked); }); + connect(ui_->radioButtonDisableBluetooth, &QRadioButton::clicked, + [&]() { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(false); }); + connect(ui_->radioButtonUseLocalBluetoothAdapter, &QRadioButton::clicked, + [&]() { ui_->lineEditExternalBluetoothAdapterAddress->setEnabled(false); }); + connect(ui_->pushButtonClearSelection, &QPushButton::clicked, + std::bind(&SettingsWindow::setButtonCheckBoxes, this, false)); + connect(ui_->pushButtonSelectAll, &QPushButton::clicked, + std::bind(&SettingsWindow::setButtonCheckBoxes, this, true)); + connect(ui_->pushButtonResetToDefaults, &QPushButton::clicked, this, &SettingsWindow::onResetToDefaults); + connect(ui_->horizontalSliderSystemVolume, &QSlider::valueChanged, this, + &SettingsWindow::onUpdateSystemVolume); + connect(ui_->horizontalSliderSystemCapture, &QSlider::valueChanged, this, + &SettingsWindow::onUpdateSystemCapture); + connect(ui_->radioButtonHotspot, &QPushButton::clicked, this, &SettingsWindow::onStartHotspot); + connect(ui_->radioButtonClient, &QPushButton::clicked, this, &SettingsWindow::onStopHotspot); + connect(ui_->pushButtonSetTime, &QPushButton::clicked, this, &SettingsWindow::setTime); + connect(ui_->pushButtonSetTime, &QPushButton::clicked, this, &SettingsWindow::close); + connect(ui_->pushButtonNTP, &QPushButton::clicked, [&]() { system("/usr/local/bin/crankshaft rtc sync &"); }); + connect(ui_->pushButtonNTP, &QPushButton::clicked, this, &SettingsWindow::close); + connect(ui_->pushButtonCheckNow, &QPushButton::clicked, + [&]() { system("/usr/local/bin/crankshaft update check &"); }); + connect(ui_->pushButtonDebuglog, &QPushButton::clicked, this, &SettingsWindow::close); + connect(ui_->pushButtonDebuglog, &QPushButton::clicked, + [&]() { system("/usr/local/bin/crankshaft debuglog &"); }); + connect(ui_->pushButtonNetworkAuto, &QPushButton::clicked, + [&]() { system("/usr/local/bin/crankshaft network auto &"); }); + connect(ui_->pushButtonNetwork0, &QPushButton::clicked, this, &SettingsWindow::on_pushButtonNetwork0_clicked); + connect(ui_->pushButtonNetwork1, &QPushButton::clicked, this, &SettingsWindow::on_pushButtonNetwork1_clicked); + connect(ui_->pushButtonSambaStart, &QPushButton::clicked, + [&]() { system("/usr/local/bin/crankshaft samba start &"); }); + connect(ui_->pushButtonSambaStop, &QPushButton::clicked, + [&]() { system("/usr/local/bin/crankshaft samba stop &"); }); + + // menu + ui_->tab1->show(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + + ui_->horizontalGroupBox->hide(); + ui_->labelBluetoothAdapterAddress->hide(); + ui_->lineEditExternalBluetoothAdapterAddress->hide(); + ui_->labelTestInProgress->hide(); + + connect(ui_->pushButtonTab1, &QPushButton::clicked, this, &SettingsWindow::show_tab1); + connect(ui_->pushButtonTab2, &QPushButton::clicked, this, &SettingsWindow::show_tab2); + connect(ui_->pushButtonTab3, &QPushButton::clicked, this, &SettingsWindow::show_tab3); + connect(ui_->pushButtonTab4, &QPushButton::clicked, this, &SettingsWindow::show_tab4); + connect(ui_->pushButtonTab5, &QPushButton::clicked, this, &SettingsWindow::show_tab5); + connect(ui_->pushButtonTab5, &QPushButton::clicked, this, &SettingsWindow::updateNetworkInfo); + connect(ui_->pushButtonTab6, &QPushButton::clicked, this, &SettingsWindow::show_tab6); + connect(ui_->pushButtonTab6, &QPushButton::clicked, this, &SettingsWindow::updateSystemInfo); + connect(ui_->pushButtonTab7, &QPushButton::clicked, this, &SettingsWindow::show_tab7); + connect(ui_->pushButtonTab8, &QPushButton::clicked, this, &SettingsWindow::show_tab8); + connect(ui_->pushButtonTab9, &QPushButton::clicked, this, &SettingsWindow::show_tab9); + + QTime time = QTime::currentTime(); + QString time_text_hour = time.toString("hh"); + QString time_text_minute = time.toString("mm"); + ui_->spinBoxHour->setValue((time_text_hour).toInt()); + ui_->spinBoxMinute->setValue((time_text_minute).toInt()); + ui_->label_modeswitchprogress->setText("Ok"); + ui_->label_notavailable->hide(); + + QString wifi_ssid = configuration_->getCSValue("WIFI_SSID"); + QString wifi2_ssid = configuration_->getCSValue("WIFI2_SSID"); + + ui_->pushButtonNetwork0->setText(wifi_ssid); + ui_->pushButtonNetwork1->setText(wifi2_ssid); + + if (!std::ifstream("/boot/crankshaft/network1.conf")) { + ui_->pushButtonNetwork1->hide(); + ui_->pushButtonNetwork0->show(); + } + if (!std::ifstream("/boot/crankshaft/network0.conf")) { + ui_->pushButtonNetwork1->hide(); + ui_->pushButtonNetwork0->setText(configuration_->getCSValue("WIFI2_SSID")); + } + if (!std::ifstream("/boot/crankshaft/network0.conf") && !std::ifstream("/boot/crankshaft/network1.conf")) { + ui_->pushButtonNetwork0->hide(); + ui_->pushButtonNetwork1->hide(); ui_->pushButtonNetworkAuto->hide(); ui_->label_notavailable->show(); - } else { - ui_->radioButtonClient->setEnabled(1); - ui_->radioButtonHotspot->setEnabled(1); - ui_->radioButtonHotspot->setChecked(0); + } + + if (std::ifstream("/tmp/hotspot_active")) { + ui_->radioButtonClient->setChecked(0); + ui_->radioButtonHotspot->setChecked(1); + ui_->lineEditWifiSSID->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf", "ssid")); + ui_->lineEditPassword->show(); + ui_->label_password->show(); + ui_->lineEditPassword->setText("1234567890"); + ui_->clientNetworkSelect->hide(); + ui_->label_notavailable->show(); + } else { ui_->radioButtonClient->setChecked(1); - ui_->label_modeswitchprogress->setText("Ok"); + ui_->radioButtonHotspot->setChecked(0); ui_->lineEditWifiSSID->setText(configuration_->readFileContent("/tmp/wifi_ssid")); ui_->lineEditPassword->hide(); ui_->label_password->hide(); ui_->lineEditPassword->setText(""); - ui_->clientNetworkSelect->show(); - ui_->label_notavailable->hide(); - ui_->pushButtonNetworkAuto->show(); + ui_->clientNetworkSelect->hide(); + ui_->label_notavailable->show(); + } - if (!std::ifstream("/boot/crankshaft/network1.conf")) { - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetwork0->show(); - } - if (!std::ifstream("/boot/crankshaft/network0.conf")) { - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetwork0->setText(configuration_->getCSValue("WIFI2_SSID")); - } - if (!std::ifstream("/boot/crankshaft/network0.conf") && !std::ifstream("/boot/crankshaft/network1.conf")) { - ui_->pushButtonNetwork0->hide(); - ui_->pushButtonNetwork1->hide(); - ui_->pushButtonNetworkAuto->hide(); - ui_->label_notavailable->show(); - } + if (std::ifstream("/tmp/samba_running")) { + ui_->labelSambaStatus->setText("running"); + ui_->pushButtonSambaStart->hide(); + ui_->pushButtonSambaStop->show(); + } else { + ui_->labelSambaStatus->setText("stopped"); + ui_->pushButtonSambaStop->hide(); + ui_->pushButtonSambaStart->show(); + } + + QTimer *refresh = new QTimer(this); + connect(refresh, SIGNAL(timeout()), this, SLOT(updateInfo())); + refresh->start(5000); } + + SettingsWindow::~SettingsWindow() { + delete ui_; + } + + void SettingsWindow::updateInfo() { + if (ui_->tab6->isVisible() == true) { + updateSystemInfo(); + } + if (ui_->tab5->isVisible() == true) { + updateNetworkInfo(); + } + } + + void SettingsWindow::onSave() { + configuration_->setHandednessOfTrafficType( + ui_->radioButtonLeftHandDrive->isChecked() ? configuration::HandednessOfTrafficType::LEFT_HAND_DRIVE + : configuration::HandednessOfTrafficType::RIGHT_HAND_DRIVE); + + configuration_->showClock(ui_->checkBoxShowClock->isChecked()); + configuration_->showBigClock(ui_->checkBoxShowBigClock->isChecked()); + configuration_->oldGUI(ui_->checkBoxOldGUI->isChecked()); + configuration_->setAlphaTrans(static_cast(ui_->horizontalSliderAlphaTrans->value())); + configuration_->hideMenuToggle(ui_->checkBoxHideMenuToggle->isChecked()); + configuration_->showLux(ui_->checkBoxShowLux->isChecked()); + configuration_->showCursor(ui_->checkBoxShowCursor->isChecked()); + configuration_->hideBrightnessControl(ui_->checkBoxHideBrightnessControl->isChecked()); + configuration_->showNetworkinfo(ui_->checkBoxNetworkinfo->isChecked()); + configuration_->mp3AutoPlay(ui_->checkBoxAutoPlay->isChecked()); + configuration_->showAutoPlay(ui_->checkBoxShowPlayer->isChecked()); + configuration_->instantPlay(ui_->checkBoxInstantPlay->isChecked()); + configuration_->hideWarning(ui_->checkBoxDontShowAgain->isChecked()); + + configuration_->setVideoFPS(ui_->radioButton30FPS->isChecked() + ? aap_protobuf::service::media::shared::message::VideoFrameRateType::VIDEO_FPS_30 + : aap_protobuf::service::media::shared::message::VideoFrameRateType::VIDEO_FPS_60); + + if (ui_->radioButton480p->isChecked()) { + configuration_->setVideoResolution( + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_800x480); + } else if (ui_->radioButton720p->isChecked()) { + configuration_->setVideoResolution( + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1280x720); + } else if (ui_->radioButton1080p->isChecked()) { + configuration_->setVideoResolution( + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1920x1080); + } + + configuration_->setScreenDPI(static_cast(ui_->horizontalSliderScreenDPI->value())); + configuration_->setOMXLayerIndex(ui_->spinBoxOmxLayerIndex->value()); + + QRect videoMargins(0, 0, ui_->spinBoxVideoMarginWidth->value(), ui_->spinBoxVideoMarginHeight->value()); + configuration_->setVideoMargins(std::move(videoMargins)); + + configuration_->setTouchscreenEnabled(ui_->checkBoxEnableTouchscreen->isChecked()); + this->saveButtonCheckBoxes(); + + configuration_->playerButtonControl(ui_->checkBoxPlayerControl->isChecked()); + + if (ui_->radioButtonDisableBluetooth->isChecked()) { + configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::NONE); + } else if (ui_->radioButtonUseLocalBluetoothAdapter->isChecked()) { + configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::LOCAL); + } else if (ui_->radioButtonUseExternalBluetoothAdapter->isChecked()) { + configuration_->setBluetoothAdapterType(configuration::BluetoothAdapterType::REMOTE); + } + + configuration_->setBluetoothRemoteAdapterAddress( + ui_->lineEditExternalBluetoothAdapterAddress->text().toStdString()); + + configuration_->setMusicAudioChannelEnabled(ui_->checkBoxMusicAudioChannel->isChecked()); + configuration_->setGuidanceAudioChannelEnabled(ui_->checkBoxSpeechAudioChannel->isChecked()); + configuration_->setAudioOutputBackendType( + ui_->radioButtonRtAudio->isChecked() ? configuration::AudioOutputBackendType::RTAUDIO + : configuration::AudioOutputBackendType::QT); + + configuration_->save(); + + // generate param string for autoapp_helper + std::string params; + params.append(std::to_string(ui_->horizontalSliderSystemVolume->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderSystemCapture->value())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxDisconnect->value())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxShutdown->value())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxDay->value())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxNight->value())); + params.append("#"); + if (ui_->checkBoxGPIO->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxDevMode->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxInvert->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxX11->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxRearcam->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxAndroid->currentText().toStdString())); + params.append("#"); + if (ui_->radioButtonX11->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->radioButtonScreenRotated->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append( + std::string("'") + std::string(ui_->comboBoxPulseOutput->currentText().toStdString()) + std::string("'")); + params.append("#"); + params.append( + std::string("'") + std::string(ui_->comboBoxPulseInput->currentText().toStdString()) + std::string("'")); + params.append("#"); + params.append(std::string(ui_->comboBoxHardwareRTC->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxTZ->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxHardwareDAC->currentText().toStdString())); + params.append("#"); + if (ui_->checkBoxDisableShutdown->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->checkBoxDisableScreenOff->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->radioButtonDebugmodeEnabled->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxGPIOShutdown->currentText().toStdString())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxGPIOShutdownDelay->value())); + params.append("#"); + if (ui_->checkBoxHotspot->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxCam->currentText().toStdString())); + params.append("#"); + if (ui_->checkBoxBluetoothAutoPair->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxBluetooth->currentText().toStdString())); + params.append("#"); + if (ui_->checkBoxHardwareSave->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxUSBCam->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxLS->currentText().split(" ")[0].toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxDayNight->currentText().toStdString())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderDay->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderNight->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderLux1->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderBrightness1->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderLux2->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderBrightness2->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderLux3->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderBrightness3->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderLux4->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderBrightness4->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderLux5->value())); + params.append("#"); + params.append(std::to_string(ui_->horizontalSliderBrightness5->value())); + params.append("#"); + params.append(std::string(ui_->comboBoxCheckInterval->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxNightmodeStep->currentText().toStdString())); + params.append("#"); + if (ui_->checkBoxDisableDayNightRTC->isChecked()) { + params.append("0"); + } else { + params.append("1"); + } + params.append("#"); + if (ui_->radioButtonAnimatedCSNG->isChecked()) { + params.append("0"); + } else if (ui_->radioButtonCSNG->isChecked()) { + params.append("1"); + } else if (ui_->radioButtonCustom->isChecked()) { + params.append("2"); + } + params.append("#"); + params.append( + std::string(ui_->comboBoxCountryCode->currentText().split("|")[0].replace(" ", "").toStdString())); + params.append("#"); + if (ui_->checkBoxBlankOnly->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->checkBoxFlipX->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->checkBoxFlipY->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxRotation->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxResolution->currentText().toStdString())); + params.append("#"); + params.append(std::string((ui_->comboBoxFPS->currentText()).replace(" (not @1080)", "").toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxAWB->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxEXP->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxLoopTime->currentText().toStdString())); + params.append("#"); + params.append(std::string(ui_->comboBoxLoopCount->currentText().toStdString())); + params.append("#"); + if (ui_->checkBoxAutoRecording->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->checkBoxFlipXUSB->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + if (ui_->checkBoxFlipYUSB->isChecked()) { + params.append("1"); + } else { + params.append("0"); + } + params.append("#"); + params.append(std::string(ui_->comboBoxUSBRotation->currentText().replace("180", "1").toStdString())); + params.append("#"); + system((std::string("/usr/local/bin/autoapp_helper setparams#") + std::string(params) + + std::string(" &")).c_str()); + + this->close(); + } + + void SettingsWindow::onResetToDefaults() { + QMessageBox confirmationMessage(QMessageBox::Question, "Confirmation", + "Are you sure you want to reset settings?", + QMessageBox::Yes | QMessageBox::Cancel); + //confirmationMessage.setWindowFlags(Qt::WindowStaysOnTopHint); + if (confirmationMessage.exec() == QMessageBox::Yes) { + configuration_->reset(); + this->load(); + } + } + + void SettingsWindow::showEvent(QShowEvent *event) { + QWidget::showEvent(event); + this->load(); + } + + void SettingsWindow::load() { + ui_->radioButtonLeftHandDrive->setChecked( + configuration_->getHandednessOfTrafficType() == configuration::HandednessOfTrafficType::LEFT_HAND_DRIVE); + ui_->radioButtonRightHandDrive->setChecked( + configuration_->getHandednessOfTrafficType() == configuration::HandednessOfTrafficType::RIGHT_HAND_DRIVE); + ui_->checkBoxShowClock->setChecked(configuration_->showClock()); + ui_->horizontalSliderAlphaTrans->setValue(static_cast(configuration_->getAlphaTrans())); + + ui_->checkBoxShowBigClock->setChecked(configuration_->showBigClock()); + ui_->checkBoxOldGUI->setChecked(configuration_->oldGUI()); + ui_->checkBoxHideMenuToggle->setChecked(configuration_->hideMenuToggle()); + ui_->checkBoxShowLux->setChecked(configuration_->showLux()); + ui_->checkBoxShowCursor->setChecked(configuration_->showCursor()); + ui_->checkBoxHideBrightnessControl->setChecked(configuration_->hideBrightnessControl()); + ui_->checkBoxNetworkinfo->setChecked(configuration_->showNetworkinfo()); + ui_->checkBoxAutoPlay->setChecked(configuration_->mp3AutoPlay()); + ui_->checkBoxShowPlayer->setChecked(configuration_->showAutoPlay()); + ui_->checkBoxInstantPlay->setChecked(configuration_->instantPlay()); + ui_->checkBoxDontShowAgain->setChecked(configuration_->hideWarning()); + + ui_->radioButton30FPS->setChecked(configuration_->getVideoFPS() == + aap_protobuf::service::media::shared::message::VideoFrameRateType::VIDEO_FPS_30); + ui_->radioButton60FPS->setChecked(configuration_->getVideoFPS() == + aap_protobuf::service::media::shared::message::VideoFrameRateType::VIDEO_FPS_60); + + ui_->radioButton480p->setChecked(configuration_->getVideoResolution() == + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_800x480); + ui_->radioButton720p->setChecked(configuration_->getVideoResolution() == + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1280x720); + ui_->radioButton1080p->setChecked(configuration_->getVideoResolution() == + aap_protobuf::service::media::shared::message::VideoCodecResolutionType::VIDEO_1920x1080); + ui_->horizontalSliderScreenDPI->setValue(static_cast(configuration_->getScreenDPI())); + ui_->spinBoxOmxLayerIndex->setValue(configuration_->getOMXLayerIndex()); + + const auto &videoMargins = configuration_->getVideoMargins(); + ui_->spinBoxVideoMarginWidth->setValue(videoMargins.width()); + ui_->spinBoxVideoMarginHeight->setValue(videoMargins.height()); + + ui_->checkBoxEnableTouchscreen->setChecked(configuration_->getTouchscreenEnabled()); + this->loadButtonCheckBoxes(); + ui_->checkBoxPlayerControl->setChecked(configuration_->playerButtonControl()); + + ui_->radioButtonDisableBluetooth->setChecked( + configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::NONE); + ui_->radioButtonUseLocalBluetoothAdapter->setChecked( + configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::LOCAL); + ui_->radioButtonUseExternalBluetoothAdapter->setChecked( + configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::REMOTE); + ui_->lineEditExternalBluetoothAdapterAddress->setEnabled( + configuration_->getBluetoothAdapterType() == configuration::BluetoothAdapterType::REMOTE); + ui_->lineEditExternalBluetoothAdapterAddress->setText( + QString::fromStdString(configuration_->getBluetoothRemoteAdapterAddress())); + + ui_->checkBoxMusicAudioChannel->setChecked(configuration_->musicAudioChannelEnabled()); + ui_->checkBoxSpeechAudioChannel->setChecked(configuration_->guidanceAudioChannelEnabled()); + + const auto &audioOutputBackendType = configuration_->getAudioOutputBackendType(); + ui_->radioButtonRtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::RTAUDIO); + ui_->radioButtonQtAudio->setChecked(audioOutputBackendType == configuration::AudioOutputBackendType::QT); + + ui_->checkBoxHardwareSave->setChecked(false); + QStorageInfo storage("/media/USBDRIVES/CSSTORAGE"); + storage.refresh(); + if (storage.isValid() && storage.isReady()) { + if (storage.isReadOnly()) { + ui_->labelStorage->setText("Storage is read only! (" + storage.device() + + ") - This can be caused by demaged filesystem on CSSTORAGE. Try a reboot."); + } else { + ui_->labelStorage->setText( + "Device: " + storage.device() + " Label: " + storage.displayName() + " Total: " + + QString::number(storage.bytesTotal() / 1024 / 1024 / 1024) + "GB Free: " + + QString::number(storage.bytesFree() / 1024 / 1024 / 1024) + "GB (" + storage.fileSystemType() + ")"); + } + } else { + ui_->labelStorage->setText("Storage is not ready or missing!"); + } + } + + void SettingsWindow::loadButtonCheckBoxes() { + const auto &buttonCodes = configuration_->getButtonCodes(); + ui_->checkBoxPlayButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY) != + buttonCodes.end()); + ui_->checkBoxPauseButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PAUSE) != + buttonCodes.end()); + ui_->checkBoxTogglePlayButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY_PAUSE) != + buttonCodes.end()); + ui_->checkBoxNextTrackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_NEXT) != + buttonCodes.end()); + ui_->checkBoxPreviousTrackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PREVIOUS) != + buttonCodes.end()); + ui_->checkBoxHomeButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_HOME) != + buttonCodes.end()); + ui_->checkBoxPhoneButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_CALL) != + buttonCodes.end()); + ui_->checkBoxCallEndButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_ENDCALL) != + buttonCodes.end()); + ui_->checkBoxVoiceCommandButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_SEARCH) != + buttonCodes.end()); + ui_->checkBoxLeftButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_LEFT) != + buttonCodes.end()); + ui_->checkBoxRightButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_RIGHT) != + buttonCodes.end()); + ui_->checkBoxUpButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_UP) != + buttonCodes.end()); + ui_->checkBoxDownButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_DOWN) != + buttonCodes.end()); + ui_->checkBoxScrollWheelButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_ROTARY_CONTROLLER) != + buttonCodes.end()); + ui_->checkBoxBackButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_BACK) != + buttonCodes.end()); + ui_->checkBoxEnterButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_CENTER) != + buttonCodes.end()); + ui_->checkBoxNavButton->setChecked(std::find(buttonCodes.begin(), buttonCodes.end(), + aap_protobuf::service::media::sink::KeyCode::KEYCODE_NAVIGATION) != + buttonCodes.end()); + } + + void SettingsWindow::setButtonCheckBoxes(bool value) { + ui_->checkBoxPlayButton->setChecked(value); + ui_->checkBoxPauseButton->setChecked(value); + ui_->checkBoxTogglePlayButton->setChecked(value); + ui_->checkBoxNextTrackButton->setChecked(value); + ui_->checkBoxPreviousTrackButton->setChecked(value); + ui_->checkBoxHomeButton->setChecked(value); + ui_->checkBoxPhoneButton->setChecked(value); + ui_->checkBoxCallEndButton->setChecked(value); + ui_->checkBoxVoiceCommandButton->setChecked(value); + ui_->checkBoxLeftButton->setChecked(value); + ui_->checkBoxRightButton->setChecked(value); + ui_->checkBoxUpButton->setChecked(value); + ui_->checkBoxDownButton->setChecked(value); + ui_->checkBoxScrollWheelButton->setChecked(value); + ui_->checkBoxBackButton->setChecked(value); + ui_->checkBoxEnterButton->setChecked(value); + ui_->checkBoxNavButton->setChecked(value); + } + + void SettingsWindow::saveButtonCheckBoxes() { + configuration::IConfiguration::ButtonCodes buttonCodes; + this->saveButtonCheckBox(ui_->checkBoxPlayButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY); + this->saveButtonCheckBox(ui_->checkBoxPauseButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PAUSE); + this->saveButtonCheckBox(ui_->checkBoxTogglePlayButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PLAY_PAUSE); + this->saveButtonCheckBox(ui_->checkBoxNextTrackButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_NEXT); + this->saveButtonCheckBox(ui_->checkBoxPreviousTrackButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_MEDIA_PREVIOUS); + this->saveButtonCheckBox(ui_->checkBoxHomeButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_HOME); + this->saveButtonCheckBox(ui_->checkBoxPhoneButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_CALL); + this->saveButtonCheckBox(ui_->checkBoxCallEndButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_ENDCALL); + this->saveButtonCheckBox(ui_->checkBoxVoiceCommandButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_SEARCH); + this->saveButtonCheckBox(ui_->checkBoxLeftButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_LEFT); + this->saveButtonCheckBox(ui_->checkBoxRightButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_RIGHT); + this->saveButtonCheckBox(ui_->checkBoxUpButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_UP); + this->saveButtonCheckBox(ui_->checkBoxDownButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_DOWN); + this->saveButtonCheckBox(ui_->checkBoxScrollWheelButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_ROTARY_CONTROLLER); + this->saveButtonCheckBox(ui_->checkBoxBackButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_BACK); + this->saveButtonCheckBox(ui_->checkBoxEnterButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_DPAD_CENTER); + this->saveButtonCheckBox(ui_->checkBoxNavButton, buttonCodes, + aap_protobuf::service::media::sink::KeyCode::KEYCODE_NAVIGATION); + configuration_->setButtonCodes(buttonCodes); + } + + void SettingsWindow::saveButtonCheckBox(const QCheckBox *checkBox, + configuration::IConfiguration::ButtonCodes &buttonCodes, + aap_protobuf::service::media::sink::KeyCode buttonCode) { + if (checkBox->isChecked()) { + buttonCodes.push_back(buttonCode); + } + } + + void SettingsWindow::onUpdateScreenDPI(int value) { + ui_->labelScreenDPIValue->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateAlphaTrans(int value) { + double alpha = value / 100.0; + ui_->labelAlphaTransValue->setText(QString::number(alpha)); + } + + void SettingsWindow::onUpdateBrightnessDay(int value) { + ui_->labelBrightnessDay->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightnessNight(int value) { + ui_->labelBrightnessNight->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateSystemVolume(int value) { + ui_->labelSystemVolumeValue->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateSystemCapture(int value) { + ui_->labelSystemCaptureValue->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateLux1(int value) { + ui_->valueLux1->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateLux2(int value) { + ui_->valueLux2->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateLux3(int value) { + ui_->valueLux3->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateLux4(int value) { + ui_->valueLux4->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateLux5(int value) { + ui_->valueLux5->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightness1(int value) { + ui_->valueBrightness1->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightness2(int value) { + ui_->valueBrightness2->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightness3(int value) { + ui_->valueBrightness3->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightness4(int value) { + ui_->valueBrightness4->setText(QString::number(value)); + } + + void SettingsWindow::onUpdateBrightness5(int value) { + ui_->valueBrightness5->setText(QString::number(value)); + } + + void SettingsWindow::unpairAll() { + system("/usr/local/bin/crankshaft bluetooth unpair &"); + } + + void SettingsWindow::setTime() { + // generate param string for autoapp_helper + std::string params; + params.append(std::to_string(ui_->spinBoxHour->value())); + params.append("#"); + params.append(std::to_string(ui_->spinBoxMinute->value())); + params.append("#"); + system((std::string("/usr/local/bin/autoapp_helper settime#") + std::string(params) + + std::string(" &")).c_str()); + } + + void SettingsWindow::syncNTPTime() { + system("/usr/local/bin/crankshaft rtc sync &"); + } + + void SettingsWindow::loadSystemValues() { + // set brightness slider attribs + ui_->horizontalSliderDay->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderDay->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderDay->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderDay->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderDay->setValue(configuration_->getCSValue("BR_DAY").toInt()); + + ui_->horizontalSliderNight->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderNight->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderNight->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderNight->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderNight->setValue(configuration_->getCSValue("BR_NIGHT").toInt()); + + ui_->horizontalSliderBrightness1->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderBrightness1->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderBrightness1->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderBrightness1->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + + ui_->horizontalSliderBrightness2->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderBrightness2->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderBrightness2->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderBrightness2->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + + ui_->horizontalSliderBrightness3->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderBrightness3->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderBrightness3->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderBrightness3->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + + ui_->horizontalSliderBrightness4->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderBrightness4->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderBrightness4->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderBrightness4->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + + ui_->horizontalSliderBrightness5->setMinimum(configuration_->getCSValue("BR_MIN").toInt()); + ui_->horizontalSliderBrightness5->setMaximum(configuration_->getCSValue("BR_MAX").toInt()); + ui_->horizontalSliderBrightness5->setSingleStep(configuration_->getCSValue("BR_STEP").toInt()); + ui_->horizontalSliderBrightness5->setTickInterval(configuration_->getCSValue("BR_STEP").toInt()); + + // set tsl2561 slider attribs + ui_->horizontalSliderLux1->setValue(configuration_->getCSValue("LUX_LEVEL_1").toInt()); + ui_->horizontalSliderBrightness1->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_1").toInt()); + ui_->horizontalSliderLux2->setValue(configuration_->getCSValue("LUX_LEVEL_2").toInt()); + ui_->horizontalSliderBrightness2->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_2").toInt()); + ui_->horizontalSliderLux3->setValue(configuration_->getCSValue("LUX_LEVEL_3").toInt()); + ui_->horizontalSliderBrightness3->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_3").toInt()); + ui_->horizontalSliderLux4->setValue(configuration_->getCSValue("LUX_LEVEL_4").toInt()); + ui_->horizontalSliderBrightness4->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_4").toInt()); + ui_->horizontalSliderLux5->setValue(configuration_->getCSValue("LUX_LEVEL_5").toInt()); + ui_->horizontalSliderBrightness5->setValue(configuration_->getCSValue("DISP_BRIGHTNESS_5").toInt()); + ui_->comboBoxCheckInterval->setCurrentText(configuration_->getCSValue("TSL2561_CHECK_INTERVAL")); + ui_->comboBoxNightmodeStep->setCurrentText(configuration_->getCSValue("TSL2561_DAYNIGHT_ON_STEP")); + + if (std::ifstream("/tmp/return_value")) { + QString return_values = configuration_->readFileContent("/tmp/return_value"); + QStringList getparams = return_values.split("#"); + + // version string + ui_->valueSystemVersion->setText(configuration_->readFileContent("/etc/crankshaft.build")); + // date string + ui_->valueSystemBuildDate->setText(configuration_->readFileContent("/etc/crankshaft.date")); + // set volume + ui_->labelSystemVolumeValue->setText(configuration_->readFileContent("/boot/crankshaft/volume")); + ui_->horizontalSliderSystemVolume->setValue( + configuration_->readFileContent("/boot/crankshaft/volume").toInt()); + // set cap volume + ui_->labelSystemCaptureValue->setText(configuration_->readFileContent("/boot/crankshaft/capvolume")); + ui_->horizontalSliderSystemCapture->setValue( + configuration_->readFileContent("/boot/crankshaft/capvolume").toInt()); + // set shutdown + ui_->valueShutdownTimer->setText("- - -"); + ui_->spinBoxShutdown->setValue(configuration_->getCSValue("DISCONNECTION_POWEROFF_MINS").toInt()); + // set disconnect + ui_->valueDisconnectTimer->setText("- - -"); + ui_->spinBoxDisconnect->setValue(configuration_->getCSValue("DISCONNECTION_SCREEN_POWEROFF_SECS").toInt()); + // set day/night + ui_->spinBoxDay->setValue(configuration_->getCSValue("RTC_DAY_START").toInt()); + ui_->spinBoxNight->setValue(configuration_->getCSValue("RTC_NIGHT_START").toInt()); + // set gpios + if (configuration_->getCSValue("ENABLE_GPIO") == "1") { + ui_->checkBoxGPIO->setChecked(true); + } else { + ui_->checkBoxGPIO->setChecked(false); + } + ui_->comboBoxDevMode->setCurrentText(configuration_->getCSValue("DEV_PIN")); + ui_->comboBoxInvert->setCurrentText(configuration_->getCSValue("INVERT_PIN")); + ui_->comboBoxX11->setCurrentText(configuration_->getCSValue("X11_PIN")); + ui_->comboBoxRearcam->setCurrentText(configuration_->getCSValue("REARCAM_PIN")); + ui_->comboBoxAndroid->setCurrentText(configuration_->getCSValue("ANDROID_PIN")); + // set mode + if (configuration_->getCSValue("START_X11") == "0") { + ui_->radioButtonEGL->setChecked(true); + } else { + ui_->radioButtonX11->setChecked(true); + } + // set rotation + if (configuration_->getCSValue("FLIP_SCREEN") == "0") { + ui_->radioButtonScreenNormal->setChecked(true); + } else { + ui_->radioButtonScreenRotated->setChecked(true); + } + + if (std::ifstream("/tmp/get_inputs")) { + QFile inputsFile(QString("/tmp/get_inputs")); + inputsFile.open(QIODevice::ReadOnly); + QTextStream data_return(&inputsFile); + QStringList inputs = data_return.readAll().split("\n"); + inputsFile.close(); + int cleaner = ui_->comboBoxPulseInput->count(); + while (cleaner > -1) { + ui_->comboBoxPulseInput->removeItem(cleaner); + cleaner--; + } + int indexin = inputs.count(); + int countin = 0; + while (countin < indexin - 1) { + ui_->comboBoxPulseInput->addItem(inputs[countin]); + countin++; + } + } + + if (std::ifstream("/tmp/get_outputs")) { + QFile outputsFile(QString("/tmp/get_outputs")); + outputsFile.open(QIODevice::ReadOnly); + QTextStream data_return(&outputsFile); + QStringList outputs = data_return.readAll().split("\n"); + outputsFile.close(); + int cleaner = ui_->comboBoxPulseOutput->count(); + while (cleaner > -1) { + ui_->comboBoxPulseOutput->removeItem(cleaner); + cleaner--; + } + int indexout = outputs.count(); + int countout = 0; + while (countout < indexout - 1) { + ui_->comboBoxPulseOutput->addItem(outputs[countout]); + countout++; + } + } + + ui_->comboBoxPulseOutput->setCurrentText(configuration_->readFileContent("/tmp/get_default_output")); + ui_->comboBoxPulseInput->setCurrentText(configuration_->readFileContent("/tmp/get_default_input")); + + if (std::ifstream("/tmp/timezone_listing")) { + QFile zoneFile(QString("/tmp/timezone_listing")); + zoneFile.open(QIODevice::ReadOnly); + QTextStream data_return(&zoneFile); + QStringList zones = data_return.readAll().split("\n"); + zoneFile.close(); + int cleaner = ui_->comboBoxTZ->count(); + while (cleaner > 0) { + ui_->comboBoxTZ->removeItem(cleaner); + cleaner--; + } + int indexout = zones.count(); + int countzone = 0; + while (countzone < indexout - 1) { + ui_->comboBoxTZ->addItem(zones[countzone]); + countzone++; + } + } + + // set rtc + QString rtcstring = configuration_->getParamFromFile("/boot/config.txt", "dtoverlay=i2c-rtc"); + if (rtcstring != "") { + QStringList rtc = rtcstring.split(","); + ui_->comboBoxHardwareRTC->setCurrentText(rtc[1].trimmed()); + // set timezone + ui_->comboBoxTZ->setCurrentText(configuration_->readFileContent("/etc/timezone")); + } else { + ui_->comboBoxHardwareRTC->setCurrentText("none"); + ui_->comboBoxTZ->setCurrentText(configuration_->readFileContent("/etc/timezone")); + } + + // set dac + QString dac = "Custom"; + if (getparams[4] == "allo-boss-dac-pcm512x-audio") { + dac = "Allo - Boss"; + } + if (getparams[4] == "allo-piano-dac-pcm512x-audio") { + dac = "Allo - Piano"; + } + if (getparams[4] == "iqaudio-dacplus") { + dac = "IQaudIO - Pi-DAC Plus/Pro/Zero"; + } + if (getparams[4] == "iqaudio-dacplus,unmute_amp") { + dac = "IQaudIO - Pi-Digi Amp Plus"; + } + if (getparams[4] == "iqaudio-dacplus,auto_mute_amp") { + dac = "IQaudIO - Pi-Digi Amp Plus - Automute"; + } + if (getparams[4] == "iqaudio-digi-wm8804-audio") { + dac = "IQaudIO - Pi-Digi Plus"; + } + if (getparams[4] == "audioinjector-wm8731-audio") { + dac = "Audioinjector - Zero/Stereo"; + } + if (getparams[4] == "hifiberry-dac") { + dac = "Hifiberry - DAC"; + } + if (getparams[4] == "hifiberry-dacplus") { + dac = "Hifiberry - DAC Plus"; + } + if (getparams[4] == "hifiberry-digi") { + dac = "Hifiberry - Digi"; + } + if (getparams[4] == "hifiberry-digi-pro") { + dac = "Hifiberry - Digi Pro"; + } + if (getparams[4] == "hifiberry-amp") { + dac = "Hifiberry - DAC Amp"; + } + if (getparams[4] == "audio") { + dac = "Raspberry Pi - Onboard"; + } + ui_->comboBoxHardwareDAC->setCurrentText(dac); + + // set shutdown disable + if (configuration_->getCSValue("DISCONNECTION_POWEROFF_DISABLE") == "1") { + ui_->checkBoxDisableShutdown->setChecked(true); + } else { + ui_->checkBoxDisableShutdown->setChecked(false); + } + + // set screen off disable + if (configuration_->getCSValue("DISCONNECTION_SCREEN_POWEROFF_DISABLE") == "1") { + ui_->checkBoxDisableScreenOff->setChecked(true); + } else { + ui_->checkBoxDisableScreenOff->setChecked(false); + } + + // set custom brightness command + if (configuration_->getCSValue("CUSTOM_BRIGHTNESS_COMMAND") != "") { + ui_->labelCustomBrightnessCommand->setText( + configuration_->getCSValue("CUSTOM_BRIGHTNESS_COMMAND") + " brvalue"); + } else { + ui_->labelCustomBrightnessCommand->setText("Disabled"); + } + + // set debug mode + if (configuration_->getCSValue("DEBUG_MODE") == "1") { + ui_->radioButtonDebugmodeEnabled->setChecked(true); + } else { + ui_->radioButtonDebugmodeDisabled->setChecked(true); + } + + // GPIO based shutdown + ui_->comboBoxGPIOShutdown->setCurrentText(configuration_->getCSValue("IGNITION_PIN")); + ui_->spinBoxGPIOShutdownDelay->setValue(configuration_->getCSValue("IGNITION_DELAY").toInt()); + + // Wifi Hotspot + if (configuration_->getCSValue("ENABLE_HOTSPOT") == "1") { + ui_->checkBoxHotspot->setChecked(true); + } else { + ui_->checkBoxHotspot->setChecked(false); + } + + // set cam + if (configuration_->getParamFromFile("/boot/config.txt", "start_x") == "1") { + ui_->comboBoxCam->setCurrentText("enabled"); + } else { + ui_->comboBoxCam->setCurrentText("disabled"); + } + if (configuration_->getCSValue("RPICAM_HFLIP") == "1") { + ui_->checkBoxFlipX->setChecked(true); + } else { + ui_->checkBoxFlipX->setChecked(false); + } + if (configuration_->getCSValue("RPICAM_VFLIP") == "1") { + ui_->checkBoxFlipY->setChecked(true); + } else { + ui_->checkBoxFlipY->setChecked(false); + } + ui_->comboBoxRotation->setCurrentText(configuration_->getCSValue("RPICAM_ROTATION")); + ui_->comboBoxResolution->setCurrentText(configuration_->getCSValue("RPICAM_RESOLUTION")); + ui_->comboBoxFPS->setCurrentText(configuration_->getCSValue("RPICAM_FPS")); + ui_->comboBoxAWB->setCurrentText(configuration_->getCSValue("RPICAM_AWB")); + ui_->comboBoxEXP->setCurrentText(configuration_->getCSValue("RPICAM_EXP")); + ui_->comboBoxLoopTime->setCurrentText(configuration_->getCSValue("RPICAM_LOOPTIME")); + ui_->comboBoxLoopCount->setCurrentText(configuration_->getCSValue("RPICAM_LOOPCOUNT")); + + if (configuration_->getCSValue("RPICAM_AUTORECORDING") == "1") { + ui_->checkBoxAutoRecording->setChecked(true); + } else { + ui_->checkBoxAutoRecording->setChecked(false); + } + + if (configuration_->getCSValue("USBCAM_USE") == "1") { + ui_->comboBoxUSBCam->setCurrentText("enabled"); + } else { + ui_->comboBoxUSBCam->setCurrentText("none"); + } + if (configuration_->getCSValue("USBCAM_ROTATION") == "1") { + ui_->comboBoxUSBRotation->setCurrentText("180"); + } else { + ui_->comboBoxUSBRotation->setCurrentText("0"); + } + if (configuration_->getCSValue("USBCAM_HFLIP") == "1") { + ui_->checkBoxFlipXUSB->setChecked(true); + } else { + ui_->checkBoxFlipXUSB->setChecked(false); + } + if (configuration_->getCSValue("USBCAM_VFLIP") == "1") { + ui_->checkBoxFlipYUSB->setChecked(true); + } else { + ui_->checkBoxFlipYUSB->setChecked(false); + } + + // set bluetooth + if (configuration_->getCSValue("ENABLE_BLUETOOTH") == "1") { + // check external bluetooth enabled + if (configuration_->getCSValue("EXTERNAL_BLUETOOTH") == "1") { + ui_->radioButtonUseExternalBluetoothAdapter->setChecked(true); + } else { + ui_->radioButtonUseLocalBluetoothAdapter->setChecked(true); + } + // mac + //ui_->lineEditExternalBluetoothAdapterAddress->setText(getparams[37]); + } else { + ui_->radioButtonDisableBluetooth->setChecked(true); + ui_->lineEditExternalBluetoothAdapterAddress->setText(""); + } + if (configuration_->getCSValue("ENABLE_PAIRABLE") == "1") { + ui_->checkBoxBluetoothAutoPair->setChecked(true); + } else { + ui_->checkBoxBluetoothAutoPair->setChecked(false); + } + // set bluetooth type + if (configuration_->getCSValue("ENABLE_BLUETOOTH") == "1") { + QString bt = configuration_->getParamFromFile("/boot/config.txt", "dtoverlay=pi3-disable-bt"); + if (bt.contains("pi3-disable-bt")) { + ui_->comboBoxBluetooth->setCurrentText("external"); + } else { + ui_->comboBoxBluetooth->setCurrentText("builtin"); + } + } else { + ui_->comboBoxBluetooth->setCurrentText("none"); + } + + // set lightsensor + if (std::ifstream("/etc/cs_lightsensor")) { + ui_->comboBoxLS->setCurrentIndex(1); + ui_->groupBoxSliderDay->hide(); + ui_->groupBoxSliderNight->hide(); + } else { + ui_->comboBoxLS->setCurrentIndex(0); + ui_->pushButtonTab9->hide(); + ui_->groupBoxSliderDay->show(); + ui_->groupBoxSliderNight->show(); + } + ui_->comboBoxDayNight->setCurrentText(configuration_->getCSValue("DAYNIGHT_PIN")); + if (configuration_->getCSValue("RTC_DAYNIGHT") == "1") { + ui_->checkBoxDisableDayNightRTC->setChecked(false); + } else { + ui_->checkBoxDisableDayNightRTC->setChecked(true); + } + QString theme = configuration_->getParamFromFile("/etc/plymouth/plymouthd.conf", "Theme"); + if (theme == "csnganimation") { + ui_->radioButtonAnimatedCSNG->setChecked(true); + } else if (theme == "crankshaft") { + ui_->radioButtonCSNG->setChecked(true); + } else if (theme == "custom") { + ui_->radioButtonCustom->setChecked(true); + } + // wifi country code + ui_->comboBoxCountryCode->setCurrentIndex( + ui_->comboBoxCountryCode->findText(configuration_->getCSValue("WIFI_COUNTRY"), + Qt::MatchFlag::MatchStartsWith)); + // set screen blank instead off + if (configuration_->getCSValue("SCREEN_POWEROFF_OVERRIDE") == "1") { + ui_->checkBoxBlankOnly->setChecked(true); + } else { + ui_->checkBoxBlankOnly->setChecked(false); + } + } + // update network info + updateNetworkInfo(); + } + + void SettingsWindow::onStartHotspot() { + ui_->label_modeswitchprogress->setText("Wait ..."); + ui_->clientNetworkSelect->hide(); + ui_->label_notavailable->show(); + ui_->radioButtonClient->setEnabled(0); + ui_->radioButtonHotspot->setEnabled(0); + ui_->lineEdit_wlan0->setText(""); + ui_->lineEditWifiSSID->setText(""); + ui_->pushButtonNetworkAuto->hide(); + qApp->processEvents(); + std::remove("/tmp/manual_hotspot_control"); + std::ofstream("/tmp/manual_hotspot_control"); + system("/opt/crankshaft/service_hotspot.sh start &"); + } + + void SettingsWindow::onStopHotspot() { + ui_->label_modeswitchprogress->setText("Wait ..."); + ui_->clientNetworkSelect->hide(); + ui_->label_notavailable->show(); + ui_->radioButtonClient->setEnabled(0); + ui_->radioButtonHotspot->setEnabled(0); + ui_->lineEdit_wlan0->setText(""); + ui_->lineEditWifiSSID->setText(""); + ui_->lineEditPassword->setText(""); + ui_->pushButtonNetworkAuto->hide(); + qApp->processEvents(); + system("/opt/crankshaft/service_hotspot.sh stop &"); + } + +#ifdef MAC_OS + void SettingsWindow::getMacMemoryInfo(QString& freeMemory) { + mach_port_t host_port; + vm_size_t page_size; + vm_statistics64_data_t vm_stats; + + host_port = mach_host_self(); + mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; + host_page_size(host_port, &page_size); + if (host_statistics64(host_port, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count) != KERN_SUCCESS) { + freeMemory = "Error in getting memory info"; + return; + } + + natural_t free_count = vm_stats.free_count; + uint64_t free_memory = (uint64_t)free_count * (uint64_t)page_size; + freeMemory = QString::number(free_memory / (1024 * 1024)) + " MB"; + } +#endif + + void SettingsWindow::updateSystemInfo() { +#ifdef MAC_OS + QString freeMem; + getMacMemoryInfo(freeMem); + ui_->valueSystemFreeMem->setText(freeMem); +#else + struct sysinfo info; + sysinfo(&info); + ui_->valueSystemFreeMem->setText(QString::number(info.freeram / 1024 / 1024) + " MB"); +#endif + + // current cpu speed + QString freq = configuration_->readFileContent("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"); + int currentfreq = freq.toInt() / 1000; + ui_->valueSystemCPUFreq->setText(QString::number(currentfreq) + "MHz"); + // current cpu temp + QString temp = configuration_->readFileContent("/sys/class/thermal/thermal_zone0/temp"); + int currenttemp = temp.toInt() / 1000; + ui_->valueSystemCPUTemp->setText(QString::number(currenttemp) + "°C"); + // get remaining times + QProcess process; + process.start("/bin/bash", + QStringList() << "-c" << "systemctl list-timers -all | grep disconnect | awk {'print $1'}"); + process.waitForFinished(-1); + QString stdout = process.readAllStandardOutput(); + if (stdout.simplified() != "n/a") { + process.start("/bin/bash", QStringList() << "-c" + << "systemctl list-timers -all | grep disconnect | awk {'print $5\" \"$6'}"); + process.waitForFinished(-1); + QString stdout = process.readAllStandardOutput(); + if (stdout.simplified() != "") { + ui_->valueDisconnectTimer->setText(stdout.simplified()); + } else { + ui_->valueDisconnectTimer->setText("Stopped"); + } + } else { + ui_->valueDisconnectTimer->setText("Stopped"); + } + process.start("/bin/bash", + QStringList() << "-c" << "systemctl list-timers -all | grep shutdown | awk {'print $1'}"); + process.waitForFinished(-1); + stdout = process.readAllStandardOutput(); + if (stdout.simplified() != "n/a") { + process.start("/bin/bash", QStringList() << "-c" + << "systemctl list-timers -all | grep shutdown | awk {'print $5\" \"$6'}"); + process.waitForFinished(-1); + QString stdout = process.readAllStandardOutput(); + if (stdout.simplified() != "") { + ui_->valueShutdownTimer->setText(stdout.simplified()); + } else { + ui_->valueShutdownTimer->setText("Stopped"); + } + } else { + ui_->valueShutdownTimer->setText("Stopped"); + } + } + + void SettingsWindow::show_tab1() { + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab1->show(); + } + + void SettingsWindow::show_tab2() { + ui_->tab1->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab2->show(); + } + + void SettingsWindow::show_tab3() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab3->show(); + } + + void SettingsWindow::show_tab4() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab4->show(); + } + + void SettingsWindow::show_tab5() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab5->show(); + } + + void SettingsWindow::show_tab6() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab6->show(); + } + + void SettingsWindow::show_tab7() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab8->hide(); + ui_->tab9->hide(); + ui_->tab7->show(); + } + + void SettingsWindow::show_tab8() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab9->hide(); + ui_->tab8->show(); + } + + void SettingsWindow::show_tab9() { + ui_->tab1->hide(); + ui_->tab2->hide(); + ui_->tab3->hide(); + ui_->tab4->hide(); + ui_->tab5->hide(); + ui_->tab6->hide(); + ui_->tab7->hide(); + ui_->tab8->hide(); + ui_->tab9->show(); + } + + } } + } } -void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonNetwork0_clicked() -{ - ui_->lineEdit_wlan0->setText(""); - ui_->lineEditWifiSSID->setText(""); - ui_->lineEditPassword->setText(""); - qApp->processEvents(); - system("/usr/local/bin/crankshaft network 0 >/dev/null 2>&1 &"); +void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonAudioTest_clicked() { + ui_->labelTestInProgress->show(); + ui_->pushButtonAudioTest->hide(); + qApp->processEvents(); + system("/usr/local/bin/crankshaft audio test"); + ui_->pushButtonAudioTest->show(); + ui_->labelTestInProgress->hide(); +} + +void f1x::openauto::autoapp::ui::SettingsWindow::updateNetworkInfo() { + if (std::ifstream("/tmp/samba_running")) { + ui_->labelSambaStatus->setText("running"); + if (ui_->pushButtonSambaStart->isVisible() == true) { + ui_->pushButtonSambaStart->hide(); + ui_->pushButtonSambaStop->show(); + } + } else { + ui_->labelSambaStatus->setText("stopped"); + if (ui_->pushButtonSambaStop->isVisible() == true) { + ui_->pushButtonSambaStop->hide(); + ui_->pushButtonSambaStart->show(); + } + } + + if (!std::ifstream("/tmp/mode_change_progress")) { + QNetworkInterface eth0if = QNetworkInterface::interfaceFromName("eth0"); + if (eth0if.flags().testFlag(QNetworkInterface::IsUp)) { + QList entrieseth0 = eth0if.addressEntries(); + if (!entrieseth0.isEmpty()) { + QNetworkAddressEntry eth0 = entrieseth0.first(); + //qDebug() << "eth0: " << eth0.ip(); + ui_->lineEdit_eth0->setText(eth0.ip().toString()); + } + } else { + //qDebug() << "eth0: down"; + ui_->lineEdit_eth0->setText("interface down"); + } + + QNetworkInterface wlan0if = QNetworkInterface::interfaceFromName("wlan0"); + if (wlan0if.flags().testFlag(QNetworkInterface::IsUp)) { + QList entrieswlan0 = wlan0if.addressEntries(); + if (!entrieswlan0.isEmpty()) { + QNetworkAddressEntry wlan0 = entrieswlan0.first(); + //qDebug() << "wlan0: " << wlan0.ip(); + ui_->lineEdit_wlan0->setText(wlan0.ip().toString()); + } + } else { + //qDebug() << "wlan0: down"; + ui_->lineEdit_wlan0->setText("interface down"); + } + + if (std::ifstream("/tmp/hotspot_active")) { + ui_->radioButtonClient->setEnabled(1); + ui_->radioButtonHotspot->setEnabled(1); + ui_->radioButtonHotspot->setChecked(1); + ui_->radioButtonClient->setChecked(0); + ui_->label_modeswitchprogress->setText("Ok"); + ui_->lineEditWifiSSID->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf", "ssid")); + ui_->lineEditPassword->show(); + ui_->label_password->show(); + ui_->lineEditPassword->setText(configuration_->getParamFromFile("/etc/hostapd/hostapd.conf", "wpa_passphrase")); + ui_->clientNetworkSelect->hide(); + ui_->pushButtonNetworkAuto->hide(); + ui_->label_notavailable->show(); + } else { + ui_->radioButtonClient->setEnabled(1); + ui_->radioButtonHotspot->setEnabled(1); + ui_->radioButtonHotspot->setChecked(0); + ui_->radioButtonClient->setChecked(1); + ui_->label_modeswitchprogress->setText("Ok"); + ui_->lineEditWifiSSID->setText(configuration_->readFileContent("/tmp/wifi_ssid")); + ui_->lineEditPassword->hide(); + ui_->label_password->hide(); + ui_->lineEditPassword->setText(""); + ui_->clientNetworkSelect->show(); + ui_->label_notavailable->hide(); + ui_->pushButtonNetworkAuto->show(); + + if (!std::ifstream("/boot/crankshaft/network1.conf")) { + ui_->pushButtonNetwork1->hide(); + ui_->pushButtonNetwork0->show(); + } + if (!std::ifstream("/boot/crankshaft/network0.conf")) { + ui_->pushButtonNetwork1->hide(); + ui_->pushButtonNetwork0->setText(configuration_->getCSValue("WIFI2_SSID")); + } + if (!std::ifstream("/boot/crankshaft/network0.conf") && !std::ifstream("/boot/crankshaft/network1.conf")) { + ui_->pushButtonNetwork0->hide(); + ui_->pushButtonNetwork1->hide(); + ui_->pushButtonNetworkAuto->hide(); + ui_->label_notavailable->show(); + } + } + } +} + +void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonNetwork0_clicked() { + ui_->lineEdit_wlan0->setText(""); + ui_->lineEditWifiSSID->setText(""); + ui_->lineEditPassword->setText(""); + qApp->processEvents(); + system("/usr/local/bin/crankshaft network 0 >/dev/null 2>&1 &"); } -void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonNetwork1_clicked() -{ - ui_->lineEdit_wlan0->setText(""); - ui_->lineEditWifiSSID->setText(""); - ui_->lineEditPassword->setText(""); - qApp->processEvents(); - system("/usr/local/bin/crankshaft network 1 >/dev/null 2>&1 &"); +void f1x::openauto::autoapp::ui::SettingsWindow::on_pushButtonNetwork1_clicked() { + ui_->lineEdit_wlan0->setText(""); + ui_->lineEditWifiSSID->setText(""); + ui_->lineEditPassword->setText(""); + qApp->processEvents(); + system("/usr/local/bin/crankshaft network 1 >/dev/null 2>&1 &"); } -void f1x::openauto::autoapp::ui::SettingsWindow::keyPressEvent(QKeyEvent *event) -{ - if(event->key() == Qt::Key_Escape) - { - f1x::openauto::autoapp::ui::SettingsWindow::close(); - } - if (event->key() == Qt::Key_Return) { - QApplication::postEvent (QApplication::focusWidget(), new QKeyEvent ( QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier)); - QApplication::postEvent (QApplication::focusWidget(), new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier)); - } - if (event->key() == Qt::Key_1) { - QApplication::postEvent (QApplication::focusWidget(), new QKeyEvent ( QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier)); - } - if (event->key() == Qt::Key_2) { - QApplication::postEvent (QApplication::focusWidget(), new QKeyEvent ( QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier)); - } +void f1x::openauto::autoapp::ui::SettingsWindow::keyPressEvent(QKeyEvent *event) { + if (event->key() == Qt::Key_Escape) { + f1x::openauto::autoapp::ui::SettingsWindow::close(); + } + if (event->key() == Qt::Key_Return) { + QApplication::postEvent(QApplication::focusWidget(), + new QKeyEvent(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier)); + QApplication::postEvent(QApplication::focusWidget(), + new QKeyEvent(QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier)); + } + if (event->key() == Qt::Key_1) { + QApplication::postEvent(QApplication::focusWidget(), + new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier)); + } + if (event->key() == Qt::Key_2) { + QApplication::postEvent(QApplication::focusWidget(), new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier)); + } } diff --git a/src/autoapp/UI/dialog.cpp b/src/autoapp/UI/dialog.cpp new file mode 100644 index 0000000..3510a1d --- /dev/null +++ b/src/autoapp/UI/dialog.cpp @@ -0,0 +1,14 @@ +#include "dialog.h" +#include "ui_dialog.h" + +Dialog::Dialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::Dialog) +{ + ui->setupUi(this); +} + +Dialog::~Dialog() +{ + delete ui; +} diff --git a/src/autoapp/UI/dialog.h b/src/autoapp/UI/dialog.h new file mode 100644 index 0000000..17537d1 --- /dev/null +++ b/src/autoapp/UI/dialog.h @@ -0,0 +1,22 @@ +#ifndef DIALOG_H +#define DIALOG_H + +#include + +namespace Ui { +class Dialog; +} + +class Dialog : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog(QWidget *parent = nullptr); + ~Dialog(); + +private: + Ui::Dialog *ui; +}; + +#endif // DIALOG_H diff --git a/src/autoapp/UI/dialog.ui b/src/autoapp/UI/dialog.ui new file mode 100644 index 0000000..6444956 --- /dev/null +++ b/src/autoapp/UI/dialog.ui @@ -0,0 +1,68 @@ + + + Dialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/autoapp/UI/journey.cpp b/src/autoapp/UI/journey.cpp new file mode 100644 index 0000000..9f52ef5 --- /dev/null +++ b/src/autoapp/UI/journey.cpp @@ -0,0 +1,14 @@ +#include "journey.h" +#include "ui_journey.h" + +journey::journey(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::journey) +{ + ui->setupUi(this); +} + +journey::~journey() +{ + delete ui; +} diff --git a/src/autoapp/UI/journey.h b/src/autoapp/UI/journey.h new file mode 100644 index 0000000..d63b684 --- /dev/null +++ b/src/autoapp/UI/journey.h @@ -0,0 +1,22 @@ +#ifndef JOURNEY_H +#define JOURNEY_H + +#include + +namespace Ui { +class journey; +} + +class journey : public QMainWindow +{ + Q_OBJECT + +public: + explicit journey(QWidget *parent = nullptr); + ~journey(); + +private: + Ui::journey *ui; +}; + +#endif // JOURNEY_H diff --git a/src/autoapp/UI/journey.ui b/src/autoapp/UI/journey.ui new file mode 100644 index 0000000..052073d --- /dev/null +++ b/src/autoapp/UI/journey.ui @@ -0,0 +1,31 @@ + + + journey + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + 0 + 0 + 800 + 24 + + + + + + + + diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index 6493abb..43095ce 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -38,7 +38,8 @@ #include #include -namespace aasdk = aasdk; +//namespace aap_protobuf = aap_protobuf; +//namespace aasdk = aasdk; namespace autoapp = f1x::openauto::autoapp; using ThreadPool = std::vector;