From 441cd0b11186d66493798551e1102eb246f1af9f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 30 Jun 2015 14:37:06 +0200 Subject: Getting started on a port to OSX. --- apps/CMakeLists.txt | 12 ++++++++++++ apps/apps.cpp | 13 +++++++++++++ apps/apps.h | 6 ++++++ apps/ble-inspect-device.h | 2 +- apps/ble-scan.h | 11 ++++------- apps/generate.cpp | 1 + apps/launcher.cpp | 1 + apps/sm-get-value.h | 6 +++++- 8 files changed, 43 insertions(+), 9 deletions(-) (limited to 'apps') diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 01252cf..a7defa2 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -3,8 +3,10 @@ list(APPEND APPS ble-scan) list(APPEND APPS sample-add-timestamp) list(APPEND APPS sample-convert) list(APPEND APPS sample-select) +if(IS_LINUX) list(APPEND APPS sm-db-insert) list(APPEND APPS sm-db-select) +endif() list(APPEND APPS sm-get-value) list(APPEND APPS sm-serial-read) list(APPEND APPS sm-serial-read-all) @@ -12,6 +14,7 @@ list(APPEND APPS sm-serial-read-all) # Boost find_package(Boost COMPONENTS regex system program_options REQUIRED) +if(IS_LINUX) # Bluez pkg_check_modules(BLUEZ bluez REQUIRED) @@ -19,6 +22,8 @@ pkg_check_modules(BLUEZ bluez REQUIRED) find_package(Threads REQUIRED) pkg_check_modules(PQXX libpqxx REQUIRED) +elseif() +endif() find_path(LOG4CPLUS_INCLUDE_DIRECTORIES log4cplus/logger.h) if(LOG4CPLUS_INCLUDE_DIRECTORIES MATCHES NOTFOUND) @@ -47,6 +52,12 @@ list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/generated/apps-list.gen.h) list(APPEND SOURCES SoilMoisture.cpp SoilMoisture.h) list(APPEND SOURCES apps.cpp apps.h) +if(IS_LINUX) + list(APPEND COMPILE_OPTIONS -DIS_LINUX) +elseif(IS_APPLE) + list(APPEND COMPILE_OPTIONS -DIS_APPLE) +endif() + add_executable(launcher launcher.cpp ${SOURCES} ${APPS_SOURCES}) @@ -65,6 +76,7 @@ target_link_libraries(launcher ${BLUEZ_LIBRARIES}) target_link_libraries(launcher ${PQXX_LIBRARIES}) target_link_libraries(launcher ${LOG4CPLUS_LIBRARIES}) target_link_libraries(launcher ${CMAKE_THREAD_LIBS_INIT}) +target_compile_options(launcher PRIVATE -Wno-deprecated-register ${COMPILE_OPTIONS}) foreach(app ${APPS}) add_custom_command( diff --git a/apps/apps.cpp b/apps/apps.cpp index e0bb631..0034ba9 100644 --- a/apps/apps.cpp +++ b/apps/apps.cpp @@ -8,6 +8,19 @@ using namespace log4cplus; using namespace std; namespace po = boost::program_options; +static string adapter_name; + +void add_ble_options(po::options_description &options) { + po::options_description bluetooth("Bluetooth"); + + bluetooth.add_options() + ("adapter", po::value(&adapter_name), "Which local adapter to use"); +} + +std::string ble_adapter_name() { + return adapter_name; +} + std::string get_hostname() { static string s = ""; diff --git a/apps/apps.h b/apps/apps.h index 7569a9f..b4de0a0 100644 --- a/apps/apps.h +++ b/apps/apps.h @@ -4,7 +4,9 @@ #include #include #include "json.hpp" +#include "ble/Bluetooth.h" #include +#include namespace trygvis { namespace apps { @@ -63,6 +65,10 @@ public: const std::string app_name; }; +void add_ble_options(po::options_description &options); + +std::string ble_adapter_name(); + std::string get_hostname(); template diff --git a/apps/ble-inspect-device.h b/apps/ble-inspect-device.h index 346f9be..d6f7255 100644 --- a/apps/ble-inspect-device.h +++ b/apps/ble-inspect-device.h @@ -56,7 +56,7 @@ public: try { Mac mac = Mac::parseMac(mac_str); - shared_ptr adapter = getAdapter(0); + shared_ptr adapter = bluetoothSystem.getAdapter(ble_adapter_name()); BluetoothDevice &device = adapter->getDevice(mac); diff --git a/apps/ble-scan.h b/apps/ble-scan.h index 9a72388..cd1d979 100644 --- a/apps/ble-scan.h +++ b/apps/ble-scan.h @@ -28,9 +28,8 @@ public: ~ble_scan() = default; - void add_options(po::options_description_easy_init &options) override { - options - ("adapter", po::value()->default_value(0), "Which adapter to use."); + void add_extra_options(po::options_description & options) { + add_ble_options(options); } int main(app_execution &execution) override { @@ -50,13 +49,11 @@ public: sigaction(SIGINT, &sigIntHandler, NULL); try { - auto adapter_index = execution.vm["adapter"].as(); - - adapter = getAdapter(adapter_index); + adapter = bluetoothSystem.getAdapter(ble_adapter_name()); set seen_devices; - cout << "Scanning with adapter #" << adapter_index << ", mac=" << adapter->getMac().str() << endl; + cout << "Scanning with adapter " << adapter->getName() << ", mac=" << adapter->getMac().str() << endl; adapter->runScan([&](BluetoothDevice &device) { auto mac = device.getMac(); diff --git a/apps/generate.cpp b/apps/generate.cpp index 9dcc271..89272d4 100644 --- a/apps/generate.cpp +++ b/apps/generate.cpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; diff --git a/apps/launcher.cpp b/apps/launcher.cpp index 2a1e039..e20a6db 100644 --- a/apps/launcher.cpp +++ b/apps/launcher.cpp @@ -2,6 +2,7 @@ #include "apps-list.gen.h" #include #include +#include namespace trygvis { namespace apps { diff --git a/apps/sm-get-value.h b/apps/sm-get-value.h index 0535f68..58e7005 100644 --- a/apps/sm-get-value.h +++ b/apps/sm-get-value.h @@ -53,6 +53,10 @@ public: ("format", default_format, "Output format"); } + void add_extra_options(po::options_description & options) override { + add_ble_options(options); + } + int main(app_execution &execution) override { __attribute__((unused)) BluetoothSystem bluetoothSystem; @@ -71,7 +75,7 @@ public: Mac mac = Mac::parseMac(MAC); - auto adapter = getAdapter(0); + auto adapter = bluetoothSystem.getAdapter(ble_adapter_name()); auto &device = adapter->getDevice(mac); -- cgit v1.2.3