aboutsummaryrefslogtreecommitdiff
path: root/Bluetooth.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Bluetooth.cpp')
-rw-r--r--Bluetooth.cpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/Bluetooth.cpp b/Bluetooth.cpp
index 22f67ec..43faf0a 100644
--- a/Bluetooth.cpp
+++ b/Bluetooth.cpp
@@ -14,12 +14,12 @@ namespace trygvis {
std::ostringstream buf;
buf
- << setw(2) << hex << setfill('0') << (int)bytes[5] << ":"
- << setw(2) << hex << setfill('0') << (int)bytes[4] << ":"
- << setw(2) << hex << setfill('0') << (int)bytes[3] << ":"
- << setw(2) << hex << setfill('0') << (int)bytes[2] << ":"
- << setw(2) << hex << setfill('0') << (int)bytes[1] << ":"
- << setw(2) << hex << setfill('0') << (int)bytes[0];
+ << setw(2) << hex << setfill('0') << (int) bytes[5] << ":"
+ << setw(2) << hex << setfill('0') << (int) bytes[4] << ":"
+ << setw(2) << hex << setfill('0') << (int) bytes[3] << ":"
+ << setw(2) << hex << setfill('0') << (int) bytes[2] << ":"
+ << setw(2) << hex << setfill('0') << (int) bytes[1] << ":"
+ << setw(2) << hex << setfill('0') << (int) bytes[0];
return buf.str();
}
@@ -46,6 +46,39 @@ namespace trygvis {
return new Mac(bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]);
}
+ AttPdu::AttPdu(ByteBuffer &bytes) : bytes(bytes) {
+ }
+
+ AttPdu::AttPdu(ByteBuffer &bytes, AttPduType type) : bytes(bytes) {
+ bytes.add8(type);
+ }
+
+ AttPduType AttPdu::getType() {
+ return (AttPduType) bytes.get8(0);
+ }
+
+ AttPdu AttPdu::parse(ByteBuffer & bytes) {
+ if(size == 0) {
+ throw BluetoothException("PDU is too small");
+ }
+
+ AttPdu pdu = AttPdu(bytes, size);
+
+ AttPduType type = pdu.getType();
+
+ switch (type) {
+ case READ_BY_GROUP_TYPE_RES:
+ if (size < 4) {
+ throw BluetoothException("Bad READ_BY_GROUP_TYPE_RES packet, expected at least 4 octets, got " + size);
+ }
+ return pdu;
+ default:
+ throw BluetoothException("Uknown PDU type: " + type);
+ }
+
+ return pdu;
+ }
+
// -----------------------------------------------------------------------
// Adapter
// -----------------------------------------------------------------------