aboutsummaryrefslogtreecommitdiff
path: root/ble/Bluetooth.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-02-21 23:58:39 +0100
commit5926b05afa21eaac36c185e7fc458710efa30b02 (patch)
tree1d835b53fcb3dbc44b07084155a37874ce8325dc /ble/Bluetooth.cpp
parenta76e09808905d280282a81958cb4c68f71f18ca4 (diff)
downloadble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.gz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.bz2
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.tar.xz
ble-toys-5926b05afa21eaac36c185e7fc458710efa30b02.zip
o Support for reading and writing characteristics.
Diffstat (limited to 'ble/Bluetooth.cpp')
-rw-r--r--ble/Bluetooth.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/ble/Bluetooth.cpp b/ble/Bluetooth.cpp
index 31f82e3..fe63b4f 100644
--- a/ble/Bluetooth.cpp
+++ b/ble/Bluetooth.cpp
@@ -3,7 +3,6 @@
#include <sstream>
#include <iomanip>
-#include <string.h>
namespace trygvis {
namespace bluetooth {
@@ -49,7 +48,7 @@ void Mac::copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4,
_5 = bytes[5];
}
-Mac Mac::parseMac(string s) throw(BluetoothException) {
+Mac Mac::parseMac(string s) {
unsigned int bytes[6];
int count = sscanf(s.c_str(), "%02x:%02x:%02x:%02x:%02x:%02x",
&bytes[0], &bytes[1], &bytes[2], &bytes[3], &bytes[4], &bytes[5]);
@@ -86,6 +85,17 @@ void AttPdu::makeReadByType(ByteBuffer &bytes, uint16_t startHandle, uint16_t en
bytes.write16le(uuid.value);
}
+void AttPdu::makeRead(ByteBuffer &bytes, uint16_t handle) {
+ bytes.write8(AttPduType::READ_REQ);
+ bytes.write16le(handle);
+}
+
+void AttPdu::makeWrite(ByteBuffer &req, uint16_t handle, const ByteBuffer &bytes) {
+ req.write8(AttPduType::WRITE_REQ);
+ req.write16le(handle);
+ req.write(bytes);
+}
+
vector<AttributeData> AttPdu::parse(ByteBuffer &bytes, AttPduType type) {
DF << "bytes: " << bytes.toString();
@@ -128,6 +138,22 @@ vector<AttributeData> AttPdu::parseReadByType(ByteBuffer &bytes) {
return parse(bytes, READ_BY_TYPE_RES);
}
+void AttPdu::parseRead(ByteBuffer &bytes) {
+ AttPduType t = (AttPduType) bytes.read8();
+
+ if (t != READ_RES) {
+ throw BluetoothException("Unexpected type: " + to_string(t));
+ }
+}
+
+void AttPdu::parseWrite(ByteBuffer &bytes) {
+ AttPduType t = (AttPduType) bytes.read8();
+
+ if (t != WRITE_RES) {
+ throw BluetoothException("Unexpected type: " + to_string(t));
+ }
+}
+
// -----------------------------------------------------------------------
// AttributeData
// -----------------------------------------------------------------------