From a2da7df0347bf4e420c2cd42ff3b8ef7cbd818be Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 18 Jul 2015 23:24:13 +0200 Subject: o Consistent ordering when storing the MAC address's bytes. --- ble/Bluetooth.cpp | 26 +++++++++++++------------- ble/LinuxBluetooth.cpp | 2 +- include/ble/Bluetooth.h | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ble/Bluetooth.cpp b/ble/Bluetooth.cpp index 14a8cda..3db0bfc 100644 --- a/ble/Bluetooth.cpp +++ b/ble/Bluetooth.cpp @@ -16,12 +16,12 @@ string Mac::str() const { std::ostringstream buf; buf - << setw(2) << hex << setfill('0') << (int) bytes[0] << ":" - << setw(2) << hex << setfill('0') << (int) bytes[1] << ":" - << setw(2) << hex << setfill('0') << (int) bytes[2] << ":" - << setw(2) << hex << setfill('0') << (int) bytes[3] << ":" + << setw(2) << hex << setfill('0') << (int) bytes[5] << ":" << setw(2) << hex << setfill('0') << (int) bytes[4] << ":" - << setw(2) << hex << setfill('0') << (int) bytes[5]; + << 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(); } @@ -39,25 +39,25 @@ bool operator<(const Mac &a, const Mac &b) { return memcmp(a.bytes, b.bytes, sizeof(a.bytes)) < 0; } -void Mac::copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const { - _0 = bytes[0]; - _1 = bytes[1]; - _2 = bytes[2]; - _3 = bytes[3]; - _4 = bytes[4]; +void Mac::copy(uint8_t &_5, uint8_t &_4, uint8_t &_3, uint8_t &_2, uint8_t &_1, uint8_t &_0) const { _5 = bytes[5]; + _4 = bytes[4]; + _3 = bytes[3]; + _2 = bytes[2]; + _1 = bytes[1]; + _0 = bytes[0]; } 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]); + &bytes[5], &bytes[4], &bytes[3], &bytes[2], &bytes[1], &bytes[0]); if (count != 6) { throw BluetoothException("Unable to parse mac: " + s); } - return Mac((uint8_t) bytes[0], (uint8_t) bytes[1], (uint8_t) bytes[2], (uint8_t) bytes[3], (uint8_t) bytes[4], (uint8_t) bytes[5]); + return Mac((uint8_t) bytes[5], (uint8_t) bytes[4], (uint8_t) bytes[3], (uint8_t) bytes[2], (uint8_t) bytes[1], (uint8_t) bytes[0]); } AttPdu::AttPdu(ByteBuffer &bytes) : bytes(bytes) { diff --git a/ble/LinuxBluetooth.cpp b/ble/LinuxBluetooth.cpp index d48bfcd..0c6c387 100644 --- a/ble/LinuxBluetooth.cpp +++ b/ble/LinuxBluetooth.cpp @@ -107,7 +107,7 @@ string errnoAsString() { // ----------------------------------------------------------------------- Mac parseMac(bdaddr_t &a) { - return Mac(a.b[0], a.b[1], a.b[2], a.b[3], a.b[4], a.b[5]); + return Mac(a.b[5], a.b[4], a.b[3], a.b[2], a.b[1], a.b[0]); } // ----------------------------------------------------------------------- diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 6a974d5..e9916e9 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -55,13 +55,13 @@ public: class Mac { public: - Mac(uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5) { - bytes[0] = _0; - bytes[1] = _1; - bytes[2] = _2; - bytes[3] = _3; - bytes[4] = _4; + Mac(uint8_t _5, uint8_t _4, uint8_t _3, uint8_t _2, uint8_t _1, uint8_t _0) { bytes[5] = _5; + bytes[4] = _4; + bytes[3] = _3; + bytes[2] = _2; + bytes[1] = _1; + bytes[0] = _0; }; string str() const; @@ -70,7 +70,7 @@ public: bool operator!=(Mac &other) const; - void copy(uint8_t &_0, uint8_t &_1, uint8_t &_2, uint8_t &_3, uint8_t &_4, uint8_t &_5) const; + void copy(uint8_t &_5, uint8_t &_4, uint8_t &_3, uint8_t &_2, uint8_t &_1, uint8_t &_0) const; static Mac parseMac(string s); -- cgit v1.2.3