BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
DBusHciConnection.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <Poco/Mutex.h>
7 #include <Poco/SharedPtr.h>
8 #include <Poco/Timespan.h>
9 #include <Poco/UUID.h>
10 
11 #include "bluetooth/GlibPtr.h"
12 #include "bluetooth/HciConnection.h"
13 #include "bluetooth/org-bluez-device1.h"
14 #include "bluetooth/org-bluez-gattcharacteristic1.h"
15 #include "net/MACAddress.h"
16 #include "util/Loggable.h"
17 
18 namespace BeeeOn {
19 
25  public HciConnection,
26  Loggable {
27 public:
28  typedef Poco::SharedPtr<DBusHciConnection> Ptr;
29 
31  const std::string& hciName,
33  const Poco::Timespan& timeout);
35 
40  std::vector<unsigned char> read(const Poco::UUID& uuid) override;
41 
46  void write(
47  const Poco::UUID& uuid,
48  const std::vector<unsigned char>& value) override;
49 
58  std::vector<unsigned char> notifiedWrite(
59  const Poco::UUID& notifyUuid,
60  const Poco::UUID& writeUuid,
61  const std::vector<unsigned char>& value,
62  const Poco::Timespan& notifyTimeout) override;
63 
64 protected:
65  static gboolean onDeviceServicesResolved(
66  OrgBluezDevice1* device,
67  GVariant* properties,
68  const gchar* const* invalidatedProperties,
69  gpointer userData);
70 
71  static gboolean onCharacteristicValueChanged(
72  OrgBluezGattCharacteristic1*,
73  GVariant* properties,
74  const gchar* const*,
75  gpointer userData);
76 
77 private:
81  void disconnect();
82 
87  void resolveServices();
88 
93  void doWrite(
94  const Poco::UUID& uuid,
95  const std::vector<unsigned char>& value);
96 
101  GlibPtr<OrgBluezGattCharacteristic1> findGATTCharacteristic(
102  const Poco::UUID& uuid);
103 
108  static GlibPtr<OrgBluezGattCharacteristic1> retrieveBluezGATTCharacteristic(
109  const std::string& path);
110 
111 private:
112  std::string m_hciName;
113  GlibPtr<OrgBluezDevice1> m_device;
114  MACAddress m_address;
115  Poco::Timespan m_timeout;
116 
117  Poco::FastMutex m_writeMutex;
118 };
119 
120 }
std::vector< unsigned char > read(const Poco::UUID &uuid) override
Reads value from the GATT characteristic defined by UUID.
Definition: DBusHciConnection.cpp:47
Definition: MACAddress.h:8
The interface class represents connection with BLE device.
Definition: HciConnection.h:16
void write(const Poco::UUID &uuid, const std::vector< unsigned char > &value) override
Writes value to the GATT characteristic defined by UUID.
Definition: DBusHciConnection.cpp:77
The class represents connection with Bluetooth Low energy device. It allows sending read/write reques...
Definition: DBusHciConnection.h:24
std::vector< unsigned char > notifiedWrite(const Poco::UUID &notifyUuid, const Poco::UUID &writeUuid, const std::vector< unsigned char > &value, const Poco::Timespan &notifyTimeout) override
The method starts notifying the characteristic given by notifyUuid. The callback is connected to sign...
Definition: DBusHciConnection.cpp:91
Definition: Loggable.h:19