![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Version 1
source/pretty_printer.h@1:a6b119bfa56b, 2020-09-04 (annotated)
- Committer:
- d4rth_j0k3r
- Date:
- Fri Sep 04 13:35:57 2020 +0000
- Revision:
- 1:a6b119bfa56b
- Parent:
- 0:ad26a5d97cd7
Finish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
d4rth_j0k3r | 0:ad26a5d97cd7 | 1 | /* mbed Microcontroller Library |
d4rth_j0k3r | 0:ad26a5d97cd7 | 2 | * Copyright (c) 2018 ARM Limited |
d4rth_j0k3r | 0:ad26a5d97cd7 | 3 | * |
d4rth_j0k3r | 0:ad26a5d97cd7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 5 | * you may not use this file except in compliance with the License. |
d4rth_j0k3r | 0:ad26a5d97cd7 | 6 | * You may obtain a copy of the License at |
d4rth_j0k3r | 0:ad26a5d97cd7 | 7 | * |
d4rth_j0k3r | 0:ad26a5d97cd7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
d4rth_j0k3r | 0:ad26a5d97cd7 | 9 | * |
d4rth_j0k3r | 0:ad26a5d97cd7 | 10 | * Unless required by applicable law or agreed to in writing, software |
d4rth_j0k3r | 0:ad26a5d97cd7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
d4rth_j0k3r | 0:ad26a5d97cd7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
d4rth_j0k3r | 0:ad26a5d97cd7 | 13 | * See the License for the specific language governing permissions and |
d4rth_j0k3r | 0:ad26a5d97cd7 | 14 | * limitations under the License. |
d4rth_j0k3r | 0:ad26a5d97cd7 | 15 | */ |
d4rth_j0k3r | 0:ad26a5d97cd7 | 16 | |
d4rth_j0k3r | 0:ad26a5d97cd7 | 17 | #include <mbed.h> |
d4rth_j0k3r | 0:ad26a5d97cd7 | 18 | #include "ble/BLE.h" |
d4rth_j0k3r | 0:ad26a5d97cd7 | 19 | |
d4rth_j0k3r | 0:ad26a5d97cd7 | 20 | inline void print_error(ble_error_t error, const char* msg) |
d4rth_j0k3r | 0:ad26a5d97cd7 | 21 | { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 22 | printf("%s: ", msg); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 23 | switch(error) { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 24 | case BLE_ERROR_NONE: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 25 | printf("BLE_ERROR_NONE: No error"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 26 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 27 | case BLE_ERROR_BUFFER_OVERFLOW: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 28 | printf("BLE_ERROR_BUFFER_OVERFLOW: The requested action would cause a buffer overflow and has been aborted"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 29 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 30 | case BLE_ERROR_NOT_IMPLEMENTED: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 31 | printf("BLE_ERROR_NOT_IMPLEMENTED: Requested a feature that isn't yet implement or isn't supported by the target HW"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 32 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 33 | case BLE_ERROR_PARAM_OUT_OF_RANGE: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 34 | printf("BLE_ERROR_PARAM_OUT_OF_RANGE: One of the supplied parameters is outside the valid range"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 35 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 36 | case BLE_ERROR_INVALID_PARAM: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 37 | printf("BLE_ERROR_INVALID_PARAM: One of the supplied parameters is invalid"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 38 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 39 | case BLE_STACK_BUSY: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 40 | printf("BLE_STACK_BUSY: The stack is busy"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 41 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 42 | case BLE_ERROR_INVALID_STATE: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 43 | printf("BLE_ERROR_INVALID_STATE: Invalid state"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 44 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 45 | case BLE_ERROR_NO_MEM: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 46 | printf("BLE_ERROR_NO_MEM: Out of Memory"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 47 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 48 | case BLE_ERROR_OPERATION_NOT_PERMITTED: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 49 | printf("BLE_ERROR_OPERATION_NOT_PERMITTED"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 50 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 51 | case BLE_ERROR_INITIALIZATION_INCOMPLETE: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 52 | printf("BLE_ERROR_INITIALIZATION_INCOMPLETE"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 53 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 54 | case BLE_ERROR_ALREADY_INITIALIZED: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 55 | printf("BLE_ERROR_ALREADY_INITIALIZED"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 56 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 57 | case BLE_ERROR_UNSPECIFIED: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 58 | printf("BLE_ERROR_UNSPECIFIED: Unknown error"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 59 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 60 | case BLE_ERROR_INTERNAL_STACK_FAILURE: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 61 | printf("BLE_ERROR_INTERNAL_STACK_FAILURE: internal stack faillure"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 62 | break; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 63 | } |
d4rth_j0k3r | 0:ad26a5d97cd7 | 64 | printf("\r\n"); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 65 | } |
d4rth_j0k3r | 0:ad26a5d97cd7 | 66 | |
d4rth_j0k3r | 0:ad26a5d97cd7 | 67 | /** print device address to the terminal */ |
d4rth_j0k3r | 0:ad26a5d97cd7 | 68 | inline void print_address(const Gap::Address_t &addr) |
d4rth_j0k3r | 0:ad26a5d97cd7 | 69 | { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 70 | printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n", |
d4rth_j0k3r | 0:ad26a5d97cd7 | 71 | addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 72 | } |
d4rth_j0k3r | 0:ad26a5d97cd7 | 73 | |
d4rth_j0k3r | 0:ad26a5d97cd7 | 74 | inline void print_mac_address() |
d4rth_j0k3r | 0:ad26a5d97cd7 | 75 | { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 76 | /* Print out device MAC address to the console*/ |
d4rth_j0k3r | 0:ad26a5d97cd7 | 77 | Gap::AddressType_t addr_type; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 78 | Gap::Address_t address; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 79 | BLE::Instance().gap().getAddress(&addr_type, address); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 80 | printf("DEVICE MAC ADDRESS: "); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 81 | print_address(address); |
d4rth_j0k3r | 0:ad26a5d97cd7 | 82 | } |
d4rth_j0k3r | 0:ad26a5d97cd7 | 83 | |
d4rth_j0k3r | 0:ad26a5d97cd7 | 84 | inline const char* phy_to_string(Gap::Phy_t phy) { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 85 | switch(phy.value()) { |
d4rth_j0k3r | 0:ad26a5d97cd7 | 86 | case Gap::Phy_t::LE_1M: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 87 | return "LE 1M"; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 88 | case Gap::Phy_t::LE_2M: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 89 | return "LE 2M"; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 90 | case Gap::Phy_t::LE_CODED: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 91 | return "LE coded"; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 92 | default: |
d4rth_j0k3r | 0:ad26a5d97cd7 | 93 | return "invalid PHY"; |
d4rth_j0k3r | 0:ad26a5d97cd7 | 94 | } |
d4rth_j0k3r | 0:ad26a5d97cd7 | 95 | } |