aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/direct_bt/BTGattChar.hpp26
-rw-r--r--src/direct_bt/BTGattChar.cpp25
2 files changed, 24 insertions, 27 deletions
diff --git a/api/direct_bt/BTGattChar.hpp b/api/direct_bt/BTGattChar.hpp
index 6edcb980..68efdfca 100644
--- a/api/direct_bt/BTGattChar.hpp
+++ b/api/direct_bt/BTGattChar.hpp
@@ -94,14 +94,7 @@ namespace direct_bt {
AuthSignedWrite = (1 << 6),
ExtProps = (1 << 7)
};
- /**
- * Returns string values as defined in <https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt>
- * <pre>
- * org.bluez.GattCharacteristic1 :: array{string} Flags [read-only]
- * </pre>
- */
- static std::string getPropertiesString(const PropertyBitVal properties) noexcept;
- static jau::darray<std::unique_ptr<std::string>> getPropertiesStringList(const PropertyBitVal properties) noexcept;
+ static std::string toPropertiesString(const PropertyBitVal properties) noexcept;
/**
* {@link BTGattChar} event listener for notification and indication events.
@@ -468,6 +461,23 @@ namespace direct_bt {
inline bool operator!=(const BTGattChar& lhs, const BTGattChar& rhs) noexcept
{ return !(lhs == rhs); }
+ constexpr uint8_t number(const BTGattChar::PropertyBitVal rhs) noexcept {
+ return static_cast<uint8_t>(rhs);
+ }
+ constexpr BTGattChar::PropertyBitVal operator |(const BTGattChar::PropertyBitVal lhs, const BTGattChar::PropertyBitVal rhs) noexcept {
+ return static_cast<BTGattChar::PropertyBitVal> ( number(lhs) | number(rhs) );
+ }
+ constexpr BTGattChar::PropertyBitVal operator &(const BTGattChar::PropertyBitVal lhs, const BTGattChar::PropertyBitVal rhs) noexcept {
+ return static_cast<BTGattChar::PropertyBitVal> ( number(lhs) & number(rhs) );
+ }
+ constexpr bool operator ==(const BTGattChar::PropertyBitVal lhs, const BTGattChar::PropertyBitVal rhs) noexcept {
+ return number(lhs) == number(rhs);
+ }
+ constexpr bool operator !=(const BTGattChar::PropertyBitVal lhs, const BTGattChar::PropertyBitVal rhs) noexcept {
+ return !( lhs == rhs );
+ }
+ std::string to_string(const BTGattChar::PropertyBitVal mask) noexcept;
+
/**
* {@link BTGattChar} event listener for notification and indication events.
* <p>
diff --git a/src/direct_bt/BTGattChar.cpp b/src/direct_bt/BTGattChar.cpp
index 2099aaa0..bf5e40e0 100644
--- a/src/direct_bt/BTGattChar.cpp
+++ b/src/direct_bt/BTGattChar.cpp
@@ -91,14 +91,14 @@ static std::string _getPropertyBitValStr(const BTGattChar::PropertyBitVal prop)
return "Unknown property";
}
-std::string BTGattChar::getPropertiesString(const PropertyBitVal properties) noexcept {
- const PropertyBitVal none = static_cast<PropertyBitVal>(0);
+std::string direct_bt::to_string(const BTGattChar::PropertyBitVal mask) noexcept {
+ const BTGattChar::PropertyBitVal none = static_cast<BTGattChar::PropertyBitVal>(0);
const uint8_t one = 1;
bool has_pre = false;
std::string out("[");
for(int i=0; i<8; i++) {
- const PropertyBitVal propertyBit = static_cast<PropertyBitVal>( one << i );
- if( none != ( properties & propertyBit ) ) {
+ const BTGattChar::PropertyBitVal propertyBit = static_cast<BTGattChar::PropertyBitVal>( one << i );
+ if( none != ( mask & propertyBit ) ) {
if( has_pre ) { out.append(", "); }
out.append(_getPropertyBitValStr(propertyBit));
has_pre = true;
@@ -108,19 +108,6 @@ std::string BTGattChar::getPropertiesString(const PropertyBitVal properties) noe
return out;
}
-jau::darray<std::unique_ptr<std::string>> BTGattChar::getPropertiesStringList(const PropertyBitVal properties) noexcept {
- jau::darray<std::unique_ptr<std::string>> out;
- const PropertyBitVal none = static_cast<PropertyBitVal>(0);
- const uint8_t one = 1;
- for(int i=0; i<8; i++) {
- const PropertyBitVal propertyBit = static_cast<PropertyBitVal>( one << i );
- if( none != ( properties & propertyBit ) ) {
- out.push_back( std::unique_ptr<std::string>( new std::string( _getPropertyBitValStr(propertyBit) ) ) );
- }
- }
- return out;
-}
-
std::shared_ptr<BTGattDesc> BTGattChar::findGattDesc(const jau::uuid_t& desc_uuid) noexcept {
const size_t descriptors_size = descriptorList.size();
for(size_t j = 0; j < descriptors_size; j++) {
@@ -164,7 +151,7 @@ std::string BTGattChar::toString() const noexcept {
if( hasProperties(BTGattChar::PropertyBitVal::Notify) || hasProperties(BTGattChar::PropertyBitVal::Indicate) ) {
notify_str = ", enabled[notify "+std::to_string(enabledNotifyState)+", indicate "+std::to_string(enabledIndicateState)+"]";
}
- return "Char[handle "+to_hexstring(handle)+", props "+to_hexstring(properties)+" "+getPropertiesString(properties)+
+ return "Char[handle "+to_hexstring(handle)+", props "+to_hexstring(properties)+" "+to_string(properties)+
char_name+", value[type 0x"+value_type->toString()+", handle "+to_hexstring(value_handle)+desc_str+
"], ccd-idx "+std::to_string(clientCharConfigIndex)+notify_str+"]";
}
@@ -186,7 +173,7 @@ std::string BTGattChar::toShortString() const noexcept {
if( hasProperties(BTGattChar::PropertyBitVal::Notify) || hasProperties(BTGattChar::PropertyBitVal::Indicate) ) {
notify_str = ", enabled[notify "+std::to_string(enabledNotifyState)+", indicate "+std::to_string(enabledIndicateState)+"]";
}
- return "Char[handle "+to_hexstring(handle)+", props "+to_hexstring(properties)+" "+getPropertiesString(properties)+
+ return "Char[handle "+to_hexstring(handle)+", props "+to_hexstring(properties)+" "+to_string(properties)+
char_name+", value[handle "+to_hexstring(value_handle)+
"], ccd-idx "+std::to_string(clientCharConfigIndex)+notify_str+"]";
}