Ian Coolidge | 611fcf9 | 2015-06-03 17:20:30 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 Google, Inc. |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at: |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | #include "logging_helpers.h" |
| 17 | |
| 18 | #include <string.h> |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #define CASE_RETURN_TEXT(code) \ |
| 23 | case code: \ |
| 24 | return #code |
| 25 | |
| 26 | const char *BtAvConnectionStateText(const btav_connection_state_t state) { |
| 27 | switch (state) { |
| 28 | CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTED); |
| 29 | CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTING); |
| 30 | CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_CONNECTED); |
| 31 | CASE_RETURN_TEXT(BTAV_CONNECTION_STATE_DISCONNECTING); |
| 32 | default: |
| 33 | return "Invalid AV connection state"; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | const char *BtAvAudioStateText(const btav_audio_state_t state) { |
| 38 | switch (state) { |
| 39 | CASE_RETURN_TEXT(BTAV_AUDIO_STATE_REMOTE_SUSPEND); |
| 40 | CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STOPPED); |
| 41 | CASE_RETURN_TEXT(BTAV_AUDIO_STATE_STARTED); |
| 42 | default: |
| 43 | return "Invalid audio state"; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | const char *BtTransportText(const btgatt_transport_t t) { |
| 48 | switch(t) { |
| 49 | CASE_RETURN_TEXT(GATT_TRANSPORT_AUTO); |
| 50 | CASE_RETURN_TEXT(GATT_TRANSPORT_BREDR); |
| 51 | CASE_RETURN_TEXT(GATT_TRANSPORT_LE); |
| 52 | default: |
| 53 | return "unknown transport"; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | const char *BtStateText(const bt_state_t state) { |
| 58 | switch (state) { |
| 59 | CASE_RETURN_TEXT(BT_STATE_OFF); |
| 60 | CASE_RETURN_TEXT(BT_STATE_ON); |
| 61 | default: |
| 62 | return "unknown state code"; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | const char *BtScanModeText(const bt_scan_mode_t mode) { |
| 67 | switch (mode) { |
| 68 | CASE_RETURN_TEXT(BT_SCAN_MODE_NONE); |
| 69 | CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE); |
| 70 | CASE_RETURN_TEXT(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); |
| 71 | default: |
| 72 | return "unknown scan mode"; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | const char *BtStatusText(const bt_status_t status) { |
| 77 | switch (status) { |
| 78 | CASE_RETURN_TEXT(BT_STATUS_SUCCESS); |
| 79 | CASE_RETURN_TEXT(BT_STATUS_FAIL); |
| 80 | CASE_RETURN_TEXT(BT_STATUS_NOT_READY); |
| 81 | CASE_RETURN_TEXT(BT_STATUS_NOMEM); |
| 82 | CASE_RETURN_TEXT(BT_STATUS_DONE); |
| 83 | CASE_RETURN_TEXT(BT_STATUS_BUSY); |
| 84 | CASE_RETURN_TEXT(BT_STATUS_UNSUPPORTED); |
| 85 | default: |
| 86 | return "unknown status code"; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | const char *BtPropertyText(const bt_property_type_t prop) { |
| 91 | switch (prop) { |
| 92 | CASE_RETURN_TEXT(BT_PROPERTY_BDNAME); |
| 93 | CASE_RETURN_TEXT(BT_PROPERTY_BDADDR); |
| 94 | CASE_RETURN_TEXT(BT_PROPERTY_UUIDS); |
| 95 | CASE_RETURN_TEXT(BT_PROPERTY_CLASS_OF_DEVICE); |
| 96 | CASE_RETURN_TEXT(BT_PROPERTY_TYPE_OF_DEVICE); |
| 97 | CASE_RETURN_TEXT(BT_PROPERTY_SERVICE_RECORD); |
| 98 | CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_SCAN_MODE); |
| 99 | CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_BONDED_DEVICES); |
| 100 | CASE_RETURN_TEXT(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT); |
| 101 | CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_FRIENDLY_NAME); |
| 102 | CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_RSSI); |
| 103 | CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_VERSION_INFO); |
| 104 | CASE_RETURN_TEXT(BT_PROPERTY_LOCAL_LE_FEATURES); |
| 105 | CASE_RETURN_TEXT(BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP); |
| 106 | default: |
| 107 | return "Invalid property"; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const char *BtEventText(const bt_cb_thread_evt evt) { |
| 112 | switch (evt) { |
| 113 | CASE_RETURN_TEXT(ASSOCIATE_JVM); |
| 114 | CASE_RETURN_TEXT(DISASSOCIATE_JVM); |
| 115 | default: |
| 116 | return "unknown state code"; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | const char *BtAclText(const bt_acl_state_t code) { |
| 121 | switch (code) { |
| 122 | CASE_RETURN_TEXT(BT_ACL_STATE_CONNECTED); |
| 123 | CASE_RETURN_TEXT(BT_ACL_STATE_DISCONNECTED); |
| 124 | default: |
| 125 | return "unknown ACL code"; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | std::string BtAddrString(const bt_bdaddr_t *addr) { |
| 130 | char buffer[20]; |
| 131 | snprintf(buffer, sizeof(buffer), "%02X:%02X:%02X:%02X:%02X:%02X", |
| 132 | addr->address[0], addr->address[1], addr->address[2], |
| 133 | addr->address[3], addr->address[4], addr->address[5]); |
| 134 | return std::string(buffer); |
| 135 | } |