diff options
author | Sven Gothel <[email protected]> | 2020-05-25 00:56:17 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-25 00:56:17 +0200 |
commit | 95989de74073cfa0065300ba4522049898f88adc (patch) | |
tree | 3e3867e7f60c760bf3adf1d4a52a1e7cb4679b67 /src/direct_bt | |
parent | 0b5d5f2f594ba4566b9cdba6a73aebb4c626cf3a (diff) |
Use AppearanceCat type in DBTDevice, EIR and GenericAccess
as well as using its string representation in respective toString() methods.
Diffstat (limited to 'src/direct_bt')
-rw-r--r-- | src/direct_bt/BTTypes.cpp | 78 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/GATTNumbers.cpp | 70 |
4 files changed, 82 insertions, 76 deletions
diff --git a/src/direct_bt/BTTypes.cpp b/src/direct_bt/BTTypes.cpp index b3f1c013..e0c79293 100644 --- a/src/direct_bt/BTTypes.cpp +++ b/src/direct_bt/BTTypes.cpp @@ -106,6 +106,78 @@ static inline const int8_t * const_uint8_to_const_int8_ptr(const uint8_t* p) { return static_cast<const int8_t *>( static_cast<void *>( const_cast<uint8_t*>( p ) ) ); } +#define GENERIC_ACCESS_APPEARANCECAT_ENUM(X) \ + X(UNKNOWN) \ + X(GENERIC_PHONE) \ + X(GENERIC_COMPUTER) \ + X(GENERIC_WATCH) \ + X(SPORTS_WATCH) \ + X(GENERIC_CLOCK) \ + X(GENERIC_DISPLAY) \ + X(GENERIC_REMOTE_CLOCK) \ + X(GENERIC_EYE_GLASSES) \ + X(GENERIC_TAG) \ + X(GENERIC_KEYRING) \ + X(GENERIC_MEDIA_PLAYER) \ + X(GENERIC_BARCODE_SCANNER) \ + X(GENERIC_THERMOMETER) \ + X(GENERIC_THERMOMETER_EAR) \ + X(GENERIC_HEART_RATE_SENSOR) \ + X(HEART_RATE_SENSOR_BELT) \ + X(GENERIC_BLOD_PRESSURE) \ + X(BLOD_PRESSURE_ARM) \ + X(BLOD_PRESSURE_WRIST) \ + X(HID) \ + X(HID_KEYBOARD) \ + X(HID_MOUSE) \ + X(HID_JOYSTICK) \ + X(HID_GAMEPAD) \ + X(HID_DIGITIZER_TABLET) \ + X(HID_CARD_READER) \ + X(HID_DIGITAL_PEN) \ + X(HID_BARCODE_SCANNER) \ + X(GENERIC_GLUCOSE_METER) \ + X(GENERIC_RUNNING_WALKING_SENSOR) \ + X(RUNNING_WALKING_SENSOR_IN_SHOE) \ + X(RUNNING_WALKING_SENSOR_ON_SHOE) \ + X(RUNNING_WALKING_SENSOR_HIP) \ + X(GENERIC_CYCLING) \ + X(CYCLING_COMPUTER) \ + X(CYCLING_SPEED_SENSOR) \ + X(CYCLING_CADENCE_SENSOR) \ + X(CYCLING_POWER_SENSOR) \ + X(CYCLING_SPEED_AND_CADENCE_SENSOR) \ + X(GENERIC_PULSE_OXIMETER) \ + X(PULSE_OXIMETER_FINGERTIP) \ + X(PULSE_OXIMETER_WRIST) \ + X(GENERIC_WEIGHT_SCALE) \ + X(GENERIC_PERSONAL_MOBILITY_DEVICE) \ + X(PERSONAL_MOBILITY_DEVICE_WHEELCHAIR) \ + X(PERSONAL_MOBILITY_DEVICE_SCOOTER) \ + X(GENERIC_CONTINUOUS_GLUCOSE_MONITOR) \ + X(GENERIC_INSULIN_PUMP) \ + X(INSULIN_PUMP_DURABLE) \ + X(INSULIN_PUMP_PATCH) \ + X(INSULIN_PUMP_PEN) \ + X(GENERIC_MEDICATION_DELIVERY) \ + X(GENERIC_OUTDOOR_SPORTS_ACTIVITY) \ + X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_DISPLAY_DEVICE) \ + X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE) \ + X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_POD) \ + X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_AND_NAVIGATION_POD) \ + +std::string direct_bt::AppearanceCatToString(const AppearanceCat v) { + switch(v) { + GENERIC_ACCESS_APPEARANCECAT_ENUM(CASE_TO_STRING) + default: ; // fall through intended + } + return "Unknown"; +} + +// ************************************************* +// ************************************************* +// ************************************************* + static std::string bt_compidtostr(const uint16_t companyid) { return std::to_string(companyid); } @@ -212,8 +284,8 @@ std::string EInfoReport::toString() const { ", evt-type "+std::to_string(evt_type)+", rssi "+std::to_string(rssi)+ ", tx-power "+std::to_string(tx_power)+ ", dev-class "+uint32HexString(device_class, true)+ - ", appearance "+uint16HexString(appearance, true)+ - ", hash["+hash.toString()+ + ", appearance "+uint16HexString(appearance, true)+" ("+AppearanceCatToString(appearance)+ + "), hash["+hash.toString()+ "], randomizer["+randomizer.toString()+ "], device-id[source "+uint16HexString(did_source, true)+ ", vendor "+uint16HexString(did_vendor, true)+ @@ -359,7 +431,7 @@ int EInfoReport::read_data(uint8_t const * data, uint8_t const data_length) { case GAP_T::RND_TRGT_ADDR: case GAP_T::GAP_APPEARANCE: if( 2 <= elem_len ) { - setAppearance(get_uint16(elem_data, 0, true /* littleEndian */)); + setAppearance(static_cast<AppearanceCat>( get_uint16(elem_data, 0, true /* littleEndian */) )); } break; case SSP_HASH_C192: diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 50c9d170..f028691d 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -120,7 +120,9 @@ std::string DBTDevice::toString() const { std::string msdstr = nullptr != msd ? msd->toString() : "MSD[null]"; std::string out("Device[address["+getAddressString()+", "+getBDAddressTypeString(getAddressType())+"], name['"+name+ "'], age "+std::to_string(t0-ts_creation)+" ms, lup "+std::to_string(t0-ts_update)+" ms, rssi "+std::to_string(getRSSI())+ - ", tx-power "+std::to_string(tx_power)+", appearance "+uint16HexString(appearance)+", "+msdstr+", "+javaObjectToString()+"]"); + ", tx-power "+std::to_string(tx_power)+ + ", appearance "+uint16HexString(appearance)+" ("+AppearanceCatToString(appearance)+ + "), "+msdstr+", "+javaObjectToString()+"]"); if(services.size() > 0 ) { out.append("\n"); int i=0; diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index d5d7a331..63b9e888 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -830,7 +830,7 @@ std::shared_ptr<GenericAccess> GATTHandler::getGenericAccess(std::vector<GATTCha std::shared_ptr<GenericAccess> res = nullptr; POctets value(GATTHandler::ClientMaxMTU, 0); std::string deviceName = ""; - GenericAccess::AppearanceCat category = GenericAccess::AppearanceCat::UNKNOWN; + AppearanceCat appearance = AppearanceCat::UNKNOWN; PeriphalPreferredConnectionParameters * prefConnParam = nullptr; for(size_t i=0; i<genericAccessCharDeclList.size(); i++) { @@ -844,7 +844,7 @@ std::shared_ptr<GenericAccess> GATTHandler::getGenericAccess(std::vector<GATTCha } } else if( _APPEARANCE == *charDecl.value_type ) { if( readCharacteristicValue(charDecl, value.resize(0)) ) { - category = static_cast<GenericAccess::AppearanceCat>(value.get_uint16(0)); + appearance = static_cast<AppearanceCat>(value.get_uint16(0)); } } else if( _PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS == *charDecl.value_type ) { if( readCharacteristicValue(charDecl, value.resize(0)) ) { @@ -853,7 +853,7 @@ std::shared_ptr<GenericAccess> GATTHandler::getGenericAccess(std::vector<GATTCha } } if( deviceName.size() > 0 && nullptr != prefConnParam ) { - res = std::shared_ptr<GenericAccess>(new GenericAccess(deviceName, category, *prefConnParam)); + res = std::shared_ptr<GenericAccess>(new GenericAccess(deviceName, appearance, *prefConnParam)); } if( nullptr != prefConnParam ) { delete prefConnParam; diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp index 564e5427..3535a0c9 100644 --- a/src/direct_bt/GATTNumbers.cpp +++ b/src/direct_bt/GATTNumbers.cpp @@ -367,76 +367,8 @@ std::string PeriphalPreferredConnectionParameters::toString() const { ", csTimeoutMul "+std::to_string(connectionSupervisionTimeoutMultiplier)+"]"; } -#define GENERIC_ACCESS_APPEARANCECAT_ENUM(X) \ - X(UNKNOWN) \ - X(GENERIC_PHONE) \ - X(GENERIC_COMPUTER) \ - X(GENERIC_WATCH) \ - X(SPORTS_WATCH) \ - X(GENERIC_CLOCK) \ - X(GENERIC_DISPLAY) \ - X(GENERIC_REMOTE_CLOCK) \ - X(GENERIC_EYE_GLASSES) \ - X(GENERIC_TAG) \ - X(GENERIC_KEYRING) \ - X(GENERIC_MEDIA_PLAYER) \ - X(GENERIC_BARCODE_SCANNER) \ - X(GENERIC_THERMOMETER) \ - X(GENERIC_THERMOMETER_EAR) \ - X(GENERIC_HEART_RATE_SENSOR) \ - X(HEART_RATE_SENSOR_BELT) \ - X(GENERIC_BLOD_PRESSURE) \ - X(BLOD_PRESSURE_ARM) \ - X(BLOD_PRESSURE_WRIST) \ - X(HID) \ - X(HID_KEYBOARD) \ - X(HID_MOUSE) \ - X(HID_JOYSTICK) \ - X(HID_GAMEPAD) \ - X(HID_DIGITIZER_TABLET) \ - X(HID_CARD_READER) \ - X(HID_DIGITAL_PEN) \ - X(HID_BARCODE_SCANNER) \ - X(GENERIC_GLUCOSE_METER) \ - X(GENERIC_RUNNING_WALKING_SENSOR) \ - X(RUNNING_WALKING_SENSOR_IN_SHOE) \ - X(RUNNING_WALKING_SENSOR_ON_SHOE) \ - X(RUNNING_WALKING_SENSOR_HIP) \ - X(GENERIC_CYCLING) \ - X(CYCLING_COMPUTER) \ - X(CYCLING_SPEED_SENSOR) \ - X(CYCLING_CADENCE_SENSOR) \ - X(CYCLING_POWER_SENSOR) \ - X(CYCLING_SPEED_AND_CADENCE_SENSOR) \ - X(GENERIC_PULSE_OXIMETER) \ - X(PULSE_OXIMETER_FINGERTIP) \ - X(PULSE_OXIMETER_WRIST) \ - X(GENERIC_WEIGHT_SCALE) \ - X(GENERIC_PERSONAL_MOBILITY_DEVICE) \ - X(PERSONAL_MOBILITY_DEVICE_WHEELCHAIR) \ - X(PERSONAL_MOBILITY_DEVICE_SCOOTER) \ - X(GENERIC_CONTINUOUS_GLUCOSE_MONITOR) \ - X(GENERIC_INSULIN_PUMP) \ - X(INSULIN_PUMP_DURABLE) \ - X(INSULIN_PUMP_PATCH) \ - X(INSULIN_PUMP_PEN) \ - X(GENERIC_MEDICATION_DELIVERY) \ - X(GENERIC_OUTDOOR_SPORTS_ACTIVITY) \ - X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_DISPLAY_DEVICE) \ - X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_AND_NAVIGATION_DISPLAY_DEVICE) \ - X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_POD) \ - X(OUTDOOR_SPORTS_ACTIVITY_LOCATION_AND_NAVIGATION_POD) \ - -std::string GenericAccess::AppearanceCatToString(const AppearanceCat v) { - switch(v) { - GENERIC_ACCESS_APPEARANCECAT_ENUM(CASE_TO_STRING) - default: ; // fall through intended - } - return "Unknown"; -} - std::string GenericAccess::toString() const { - return "'"+deviceName+"'[cat "+AppearanceCatToString(category)+", "+prefConnParam.toString()+"]"; + return "'"+deviceName+"'[appearance "+uint16HexString(appearance)+" ("+AppearanceCatToString(appearance)+"), "+prefConnParam.toString()+"]"; } PnP_ID::PnP_ID(const TROOctets &source) |