summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-04-09 01:02:40 +0200
committerSven Gothel <[email protected]>2020-04-09 01:02:40 +0200
commit8891be2fd6ecb4386ee7bdbb61ccc209b54f5bcf (patch)
tree0d54edb80e50c8389ce340e3e66dd35d0f5fa4b3 /include
parentdb63cc6278beed8a7fe2899af9f31995796a9651 (diff)
Implement direct_bt: Direct Bluetooth access via Linux's Kernel BlueZ protocol stack w/o D-Bus bluetoothd.
By dropping BlueZ userspace D-Bus bluetoothd, we target high-performance reliable bluetooth support with least dependencies for embedded device configurations. See COPYING, describing which Linux Kernel BlueZ IOCTL information has been included in the source tree. We claim Linus Torvalds's Linux Kernel license exception regarding kernel syscalls (ioctl): <https://github.com/torvalds/linux/blob/master/LICENSES/exceptions/Linux-syscall-note> and hence maintain this project's license. The new direct_bt feature set is organized as follows - include/cppunit - api/direct_bt - api/ieee11073 - src/direct_bt - examples/direct_bt Note that the C++ direct_bt layer is not backward compatible to tinyb. Since the Java layer still needs to be completed, it has to be seen whether we will achieve compatibility or drop the original D-Bus tinyb module altogether in favor of a more streamlined API and implementation. Current state allows scanning for LE devices, connecting and parsing GATT plus receiving notifications and indications. See examples/direct_bt_scanner/dbt_scanner.cpp. The Linux Kernel BlueZ is configured via module MgmtComm.[hpp/cpp]
Diffstat (limited to 'include')
-rw-r--r--include/cppunit/cppunit.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/include/cppunit/cppunit.h b/include/cppunit/cppunit.h
new file mode 100644
index 00000000..af05acc9
--- /dev/null
+++ b/include/cppunit/cppunit.h
@@ -0,0 +1,110 @@
+#ifndef CPPUNIT_H
+#define CPPUNIT_H
+
+// Required headers, or just use #include <bits/stdc++.h>
+#include <iostream>
+#include <sstream>
+#include <cstring>
+#include <string>
+#include <ctime>
+#include <cmath>
+
+
+// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
+class Cppunit {
+
+ private:
+ static float machineFloatEpsilon() {
+ float x = 1.0f, res;
+ do {
+ res = x;
+ } while (1.0f + (x /= 2.0f) > 1.0f);
+ return res;
+ }
+
+ static double machineDoubleEpsilon() {
+ double x = 1.0, res;
+ do {
+ res = x;
+ } while (1.0 + (x /= 2.0) > 1.0);
+ return res;
+ }
+
+ public:
+
+ #define PRINTM(m) print(m, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECK(a,b) check<long long>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKM(m,a,b) check<long long>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKD(m,a,b) checkDelta<double>(m, a, b, doubleEpsilon, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKDD(m,a,b,c) checkDelta<double>(m, a, b, c, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKT(a) check<bool>("", a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKTM(m,a) check<bool>(m, a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKS(a,b) check<cs>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+ #define CHECKSM(m,a,b) check<cs>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
+
+ typedef const std::string& cs;
+
+ int checks, fails; std::ostringstream serr; std::istringstream *in;
+ float floatEpsilon;
+ double doubleEpsilon;
+
+ Cppunit()
+ : checks(0), fails(0), floatEpsilon(machineFloatEpsilon()), doubleEpsilon(machineDoubleEpsilon())
+ {}
+
+ virtual ~Cppunit() {}
+
+ void test_cin(cs s){ in = new std::istringstream(s); std::cin.rdbuf(in->rdbuf()); }
+
+ void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
+ serr << "==================================================" << std::endl;
+ serr << "FAIL: " << func << std::endl;
+ serr << "--------------------------------------------------" << std::endl;
+ serr << "File \"" << file << "\", line " << line << " in " << func << std::endl;
+ serr << " Checking " << stra << " == " << strb << std::endl;
+ }
+
+ void print(cs m, cs file, int line, cs func) {
+ std::cerr << std::endl << m << "; file \"" << file << "\", line " << line << " in " << func << std::endl;
+ }
+
+ template <typename T> void check(cs m, T a, T b, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if (a == b) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\"" << std::endl << std::endl;
+ }
+
+ template <typename T> void checkDelta(cs m, T a, T b, T d, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( labs ( a - b ) < d ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (delta " << d << ")" << std::endl << std::endl;
+ }
+
+ virtual void single_test() {}
+ virtual void test_list() { single_test(); }
+ double dclock() { return double(clock()) / CLOCKS_PER_SEC; }
+ int status() {
+ std::cout << std::endl; if (fails) std::cout << serr.str();
+ std::cout << "--------------------------------------------------" << std::endl;
+ std::cout << "Ran " << checks << " checks in " << dclock() << "s" << std::endl << std::endl;
+ if (fails) std::cout << "FAILED (failures=" << fails << ")"; else std::cout << "OK" << std::endl;
+ return fails > 0;
+ }
+ int run() { std::streambuf* ocin = std::cin.rdbuf(); test_list(); std::cin.rdbuf(ocin); return status(); }
+};
+
+template<> void Cppunit::checkDelta<float>(cs m, float a, float b, float epsilon, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( fabsf( a - b ) < epsilon ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
+}
+
+template<> void Cppunit::checkDelta<double>(cs m, double a, double b, double epsilon, cs stra, cs strb, cs file, int line, cs func) {
+ checks++; if ( fabsf( a - b ) < epsilon ) { std::cout << "."; return; }
+ fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
+ serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
+}
+
+
+#endif // CPPUNIT_H
+