diff options
author | Sven Gothel <[email protected]> | 2020-04-25 20:37:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-04-25 20:37:17 +0200 |
commit | 3460be939b76ef3a1895e27afe2dcfa53ff21b3f (patch) | |
tree | 5d7e48c78788413eebf781bf65564c354a5af0f6 /test | |
parent | cd0fbb59946a0d9ca0fd0bf1fc27228bc3d90f91 (diff) |
Use Kernel BlueZ Manager for Discovery, Connect, etc. (Initial Commit - Java part probably broken)
We have experienced the following using the official HCI communication channel:
- Lower connect performance with discovery enabled
- Instability with enabled discovery and breaking general BT adapter state
requiring a 'hciconfig hci0 reset'
- Lack of notifications: start/stop discovery/connect/...
- Lack of certain settings in general: pin, ..
This commit implements discovery including listening to all BlueZ kernel events
from the BlueZ Manager channel using DBTManager.
TODO: Figure out how to enforce quick connect!
- EInfoReport (EIR) added: FLAGS, DEVICE_CLASS, APPEARANCE, HASH, RANDOMIZER and DEVICE_ID
- including parsing new segments in read_data(..) and dataSetToString(..) exposure
- DBTManager adds:
- manager-reader thread, putting all command status/completes to its ringbuffer
and sending out all other events to its listener.
- Respecting the chosen BTMode (side-effect to discovery etc)
- add: start/stop discovery
- add: connect/disconnect (incomplete)
- DBTAdapter:
- discoverDevices -> discoverDevicesMgmt is becoming redundant,
now simply waiting for the DeviceFound event.
Will be deleted - TODO!
- mgmtEvDeviceFoundCB shall perform remaining EIR parsing
and enqueing the devices plus issuing respective discovery callbacks!
TODO.
- DBTDevice adds:
- BDAddressType
- HCISession's HCIComm is now no more used (to be deleted!)
- HCIComm adds generic read/write methods, mutex free.
- Remaining HCI 'managment' methods are also subject to deletion!
- GATTHandler / DBTManager: only use a mtx_write for communication,
as reading is performed on their respective threads using a ringbuffer.
Here only concurrent write access needs to be managed.
(DBTManager uses its own HCIComm's mutex.)
- MgmtTypes adds:
- BTMode for dual, BREDR or LE only.
- MgmtRequest -> MgmtCommand
- Unifies the command opcodes to global 'MgmtOpcode',
removing duplicate MgmtCommand::Opcode (which was also incomplete)
- Adding MgmtDisconnectCmd, MgmtEvtDiscovering, MgmtEvtDeviceFound
MgmtEvtDeviceConnected, MgmtEvtDeviceDisconnected
- TOctets adding get_int8(..) and get_eui48(..)
- TOctets adding put_eui48(..)
++++++++++++++
New ClassFunction: Introducing versatile C++ function-method type
used for our DBTManager callbacks.
In contrast to std::function and std::bind, ClassFunction allows
using its specific type (return- and argument types)
and offering the equality operation to test its identity.
The latter is essential to remove a callback ClassFunction
from a list of callbacks.
+++++++++++++++++
Further code cleanup is also included
- Address_T -> BDAddressType(incl string presentation) + HCIAddressType
- ManufactureSpecificData using POctets
- Convenient default param: uint*HexString(.., const bool leading0X=true);
- MgmtTypes's get/put for events and commands use MGMT_HEADER_SIZE offset
- MgmtTypes: Remove doubled 'btohs', as the pdu.get* commands
already perform endian conversion.
- EInfoReport::read_data(..) validate segment size before type conversion
Diffstat (limited to 'test')
-rw-r--r-- | test/direct_bt/test_basictypes01.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/direct_bt/test_basictypes01.cpp b/test/direct_bt/test_basictypes01.cpp index 92e45c84..fc94295d 100644 --- a/test/direct_bt/test_basictypes01.cpp +++ b/test/direct_bt/test_basictypes01.cpp @@ -7,6 +7,7 @@ #include <direct_bt/BasicTypes.hpp> #include <direct_bt/BTAddress.hpp> +#include <direct_bt/ClassFunction.hpp> using namespace direct_bt; @@ -38,10 +39,52 @@ class Cppunit_tests : public Cppunit { CHECKTM(msg, str == expStr); } + int func2a_member(int i) { + int res = i+100; + return res;; + } + int func2b_member(int i) { + int res = i+1000; + return res;; + } + + // template<typename R, typename... A> + typedef ClassFunction<int, int> MyClassFunction; + + void test_FunctionPointer00(std::string msg, bool expEqual, int value, int expRes, MyClassFunction & f1, MyClassFunction &f2) { + // test std::function identity + PRINTM(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() ); + int f1r = f1.invoke(value); + int f2r = f2.invoke(value); + PRINTM(msg+": FunctionPointer00 Res f1r == f2r : " + std::to_string( f1r == f2r ) + ", f1r: " + std::to_string( f1r ) + ", f2r "+std::to_string( f2r ) ); + if( expEqual ) { + CHECKM(msg, f1r, expRes); + CHECKM(msg, f2r, expRes); + CHECKTM(msg, f1 == f2); + } else { + CHECKTM(msg, f1 != f2); + } + } + public: void single_test() override { { + // FunctionPointer(Cppunit_tests &base, Func1Type func) + MyClassFunction f2a_1 = bindClassFunction<int, Cppunit_tests, int>(this, &Cppunit_tests::func2a_member); + MyClassFunction f2a_2 = bindClassFunction(this, &Cppunit_tests::func2a_member); + test_FunctionPointer00("FuncPtr2a_member_11", true, 1, 101, f2a_1, f2a_1); + test_FunctionPointer00("FuncPtr2a_member_12", true, 1, 101, f2a_1, f2a_2); + + MyClassFunction f2b_1 = bindClassFunction(this, &Cppunit_tests::func2b_member); + MyClassFunction f2b_2 = bindClassFunction(this, &Cppunit_tests::func2b_member); + test_FunctionPointer00("FuncPtr2b_member_11", true, 1, 1001, f2b_1, f2b_1); + test_FunctionPointer00("FuncPtr2b_member_12", true, 1, 1001, f2b_1, f2b_2); + + test_FunctionPointer00("FuncPtr2ab_member_11", false, 1, 0, f2a_1, f2b_1); + test_FunctionPointer00("FuncPtr2ab_member_22", false, 1, 0, f2a_2, f2b_2); + } + { test_int32_t("INT32_MIN", INT32_MIN, 14, "-2,147,483,648"); test_int32_t("int32_t -thousand", -1000, 6, "-1,000"); test_int32_t("int32_t one", 1, 1, "1"); |