this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Fri Jul 19 16:49:26 2019 +0000
Branch:
PassingRegression
Revision:
129:590bdc2dcf5b
Parent:
75:08eff6258e1b
Implementation of Access token acquisition; 1. make request with credentials - DONE; 2. get response - DONE; 3. extract Id and refresh tokens from response - DONE; 4. integrate with code - DONE; Testing ongoing

Who changed what in which revision?

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