aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-11-23 16:41:24 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2018-11-23 16:41:24 +0100
commitaf416f81b14a3bee682e300b165a6efdb9739d54 (patch)
tree20c4704d5d24ed18a78970f9331aec12c9522a41
parent2034b1bb10720a2f0e6cc97427346f2320c115bc (diff)
downloadble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.gz
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.bz2
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.xz
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.zip
o Trying to improve compatibility with some feature checks.
o Misc nits.
-rw-r--r--.idea/codeStyles/codeStyleConfig.xml1
-rw-r--r--README.md12
-rw-r--r--apps/apps.cpp11
-rw-r--r--apps/ble-inspect-device.cpp3
-rw-r--r--apps/ble-read-characteristic.cpp2
-rw-r--r--ble/BluetoothImpl.h3
-rw-r--r--include/ble/Bluetooth.h4
-rw-r--r--include/ble/att.h6
-rw-r--r--include/ble/compiler-support.h62
-rw-r--r--include/ble/misc.h4
10 files changed, 89 insertions, 19 deletions
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index 79ee123..6e6eec1 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,6 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
+ <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component> \ No newline at end of file
diff --git a/README.md b/README.md
index 5b5f5b1..1ddaa1a 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,18 @@ Building:
This will build a Debug release by default. Add `-DCMAKE_BUILD_TYPE=Release` to build a release build.
+## Required packages
+
+For Debian-based systems (Debian, Ubuntu, Armbian, etc):
+
+ * cmake
+ * libmosquitto-dev
+ * libpqxx-dev
+ * libbluetooth-dev
+ * libboost-all-dev
+ * liblog4cplus-dev
+ * ninja-build # optional
+
# CMake notes
Header files are added as sources so the IDEs will search/index them properly.
diff --git a/apps/apps.cpp b/apps/apps.cpp
index 56abc7b..ef0a7fc 100644
--- a/apps/apps.cpp
+++ b/apps/apps.cpp
@@ -53,12 +53,12 @@ const po::options_description logging_options() {
return desc;
}
-void setup_logging(string app_name) {
+void setup_logging(const string &app_name) {
Appender *console = new ConsoleAppender(true, true);
string pattern = "%-5p %D{%Y-%m-%d %H:%M:%S} " + app_name + "/%-20c %m%n"; // add %M (function name)
- PatternLayout *layout = new PatternLayout(LOG4CPLUS_TEXT(pattern));
+ auto *layout = new PatternLayout(LOG4CPLUS_TEXT(pattern));
console->setLayout(auto_ptr<Layout>(layout));
Hierarchy &h = Logger::getDefaultHierarchy();
@@ -90,7 +90,7 @@ int launch_app(app *app, int argc, const char *argv[]) {
return EXIT_FAILURE;
}
- if (unrecognized.size()) {
+ if (!unrecognized.empty()) {
cerr << "Unrecognized option: " << unrecognized.at(0) << "\n";
return EXIT_FAILURE;
}
@@ -123,5 +123,6 @@ int real_main(app *app, int argc, const char *argv[]) {
return launch_app(app, argc, argv);
}
-}
-}
+
+} // namespace apps
+} // namespace trygvis
diff --git a/apps/ble-inspect-device.cpp b/apps/ble-inspect-device.cpp
index a6665b3..cb8cf0f 100644
--- a/apps/ble-inspect-device.cpp
+++ b/apps/ble-inspect-device.cpp
@@ -44,8 +44,7 @@ public:
<< endl;
for (auto &c : characteristics) {
- cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (uint16_t) c->getProperties()
- << endl;
+ cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (uint16_t) c->getProperties() << endl;
}
}
}
diff --git a/apps/ble-read-characteristic.cpp b/apps/ble-read-characteristic.cpp
index ecdb471..3ef3c70 100644
--- a/apps/ble-read-characteristic.cpp
+++ b/apps/ble-read-characteristic.cpp
@@ -117,7 +117,7 @@ public:
} while(std::chrono::system_clock::now() < end);
}
} else {
- cout << "Unsupported op mode." << endl;
+ cout << "Unsupported op mode: " << op_mode << endl;
}
return EXIT_SUCCESS;
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h
index c41712c..92f71d3 100644
--- a/ble/BluetoothImpl.h
+++ b/ble/BluetoothImpl.h
@@ -289,9 +289,6 @@ protected:
BluetoothAdapterPtr getAdapterImpl(string name);
-template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
-template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
-
} // namespace bluetooth
} // namespace trygvis
diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h
index 5f7cd17..28e2794 100644
--- a/include/ble/Bluetooth.h
+++ b/include/ble/Bluetooth.h
@@ -1,7 +1,6 @@
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
-#include <optional>
#include <iosfwd>
#include <iostream>
#include <stdexcept>
@@ -23,9 +22,6 @@ using std::vector;
using std::map;
using std::runtime_error;
-template<typename T>
-using o = std::optional<T>;
-
class BluetoothAdapter;
class BluetoothDevice;
class BluetoothGatt;
diff --git a/include/ble/att.h b/include/ble/att.h
index 152a779..7b77812 100644
--- a/include/ble/att.h
+++ b/include/ble/att.h
@@ -1,6 +1,5 @@
#pragma once
-#include <variant>
#include <vector>
#include "ble/ByteBuffer.h"
@@ -9,6 +8,9 @@
namespace trygvis {
namespace bluetooth {
+using ::trygvis::compiler::variant;
+using ::trygvis::compiler::monostate;
+
/**
* BLUETOOTH SPECIFICATION Version 4.0 [Vol 3] - Attribute Protocol (ATT) - 3.4.8 Attribute Opcode Summary
* Table 3.37
@@ -144,7 +146,7 @@ struct HandleValueIndication {
ByteBuffer data;
};
-using AttVariant = std::variant<std::monostate,
+using AttVariant = variant<monostate,
ErrorRes,
ExchangeMtuReq, ExchangeMtuRes,
FindInformationRes,
diff --git a/include/ble/compiler-support.h b/include/ble/compiler-support.h
new file mode 100644
index 0000000..1e7e185
--- /dev/null
+++ b/include/ble/compiler-support.h
@@ -0,0 +1,62 @@
+#ifndef COMPILER_SUPPORT_H
+
+#ifdef __has_include
+
+# if __has_include(<optional>)
+# include <optional>
+# define have_optional 1
+# elif __has_include(<experimental/optional>)
+# include <experimental/optional>
+# define have_optional 1
+# define have_experimental_optional 1
+# else
+# define have_optional 0
+# endif
+
+# if __has_include(<variant>)
+# include <variant>
+# define have_variant 1
+# elif __has_include(<experimental/variant>)
+# include <experimental/variant>
+# define have_variant 1
+# define have_experimental_variant 1
+# else
+# define have_variant 0
+# endif
+
+#endif
+
+namespace trygvis {
+namespace compiler {
+
+#if have_experimental_optional
+
+template<typename T>
+using o = std::experimental::optional<T>;
+
+#elif have_optional
+
+template<typename T>
+using o = std::optional<T>;
+
+#endif
+
+#if have_experimental_variant
+
+template<typename... T>
+using variant = std::experimental::variant<T>;
+using monostate = std::experimental::monostate;
+
+#elif have_variant
+
+template<typename... T>
+using variant = std::variant<T...>;
+using monostate = std::monostate;
+
+#endif
+
+} // namespace compiler
+} // namespace trygvis
+
+
+#endif
diff --git a/include/ble/misc.h b/include/ble/misc.h
index 563d039..aa0ba2e 100644
--- a/include/ble/misc.h
+++ b/include/ble/misc.h
@@ -1,5 +1,6 @@
#pragma once
+#include "ble/compiler-support.h"
#include "ByteBuffer.h"
#include <optional>
@@ -10,8 +11,7 @@
namespace trygvis {
namespace bluetooth {
-template<typename T>
-using o = std::optional<T>;
+using ::trygvis::compiler::o;
class BluetoothAdapter;
class BluetoothDevice;