This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).
Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn
The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/
mbed-client/source/m2minterfacefactory.cpp@0:29983394c6b6, 2017-04-13 (annotated)
- Committer:
- edamame22
- Date:
- Thu Apr 13 04:48:11 2017 +0000
- Revision:
- 0:29983394c6b6
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edamame22 | 0:29983394c6b6 | 1 | /* |
edamame22 | 0:29983394c6b6 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
edamame22 | 0:29983394c6b6 | 3 | * SPDX-License-Identifier: Apache-2.0 |
edamame22 | 0:29983394c6b6 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
edamame22 | 0:29983394c6b6 | 5 | * not use this file except in compliance with the License. |
edamame22 | 0:29983394c6b6 | 6 | * You may obtain a copy of the License at |
edamame22 | 0:29983394c6b6 | 7 | * |
edamame22 | 0:29983394c6b6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
edamame22 | 0:29983394c6b6 | 9 | * |
edamame22 | 0:29983394c6b6 | 10 | * Unless required by applicable law or agreed to in writing, software |
edamame22 | 0:29983394c6b6 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
edamame22 | 0:29983394c6b6 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
edamame22 | 0:29983394c6b6 | 13 | * See the License for the specific language governing permissions and |
edamame22 | 0:29983394c6b6 | 14 | * limitations under the License. |
edamame22 | 0:29983394c6b6 | 15 | */ |
edamame22 | 0:29983394c6b6 | 16 | |
edamame22 | 0:29983394c6b6 | 17 | // Note: this macro is needed on armcc to get the the PRI*32 macros |
edamame22 | 0:29983394c6b6 | 18 | // from inttypes.h in a C++ code. |
edamame22 | 0:29983394c6b6 | 19 | #ifndef __STDC_FORMAT_MACROS |
edamame22 | 0:29983394c6b6 | 20 | #define __STDC_FORMAT_MACROS |
edamame22 | 0:29983394c6b6 | 21 | #endif |
edamame22 | 0:29983394c6b6 | 22 | |
edamame22 | 0:29983394c6b6 | 23 | #include "mbed-client/m2minterfacefactory.h" |
edamame22 | 0:29983394c6b6 | 24 | #include "mbed-client/m2mserver.h" |
edamame22 | 0:29983394c6b6 | 25 | #include "mbed-client/m2mdevice.h" |
edamame22 | 0:29983394c6b6 | 26 | #include "mbed-client/m2mfirmware.h" |
edamame22 | 0:29983394c6b6 | 27 | #include "mbed-client/m2mobject.h" |
edamame22 | 0:29983394c6b6 | 28 | #include "mbed-client/m2mconstants.h" |
edamame22 | 0:29983394c6b6 | 29 | #include "mbed-client/m2mconfig.h" |
edamame22 | 0:29983394c6b6 | 30 | #include "include/m2minterfaceimpl.h" |
edamame22 | 0:29983394c6b6 | 31 | #include "mbed-trace/mbed_trace.h" |
edamame22 | 0:29983394c6b6 | 32 | |
edamame22 | 0:29983394c6b6 | 33 | #include <inttypes.h> |
edamame22 | 0:29983394c6b6 | 34 | |
edamame22 | 0:29983394c6b6 | 35 | #define TRACE_GROUP "mClt" |
edamame22 | 0:29983394c6b6 | 36 | |
edamame22 | 0:29983394c6b6 | 37 | M2MInterface* M2MInterfaceFactory::create_interface(M2MInterfaceObserver &observer, |
edamame22 | 0:29983394c6b6 | 38 | const String &endpoint_name, |
edamame22 | 0:29983394c6b6 | 39 | const String &endpoint_type, |
edamame22 | 0:29983394c6b6 | 40 | const int32_t life_time, |
edamame22 | 0:29983394c6b6 | 41 | const uint16_t listen_port, |
edamame22 | 0:29983394c6b6 | 42 | const String &domain, |
edamame22 | 0:29983394c6b6 | 43 | M2MInterface::BindingMode mode, |
edamame22 | 0:29983394c6b6 | 44 | M2MInterface::NetworkStack stack, |
edamame22 | 0:29983394c6b6 | 45 | const String &context_address) |
edamame22 | 0:29983394c6b6 | 46 | { |
edamame22 | 0:29983394c6b6 | 47 | tr_debug("M2MInterfaceFactory::create_interface - IN"); |
edamame22 | 0:29983394c6b6 | 48 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint name : %s",endpoint_name.c_str()); |
edamame22 | 0:29983394c6b6 | 49 | tr_debug("M2MInterfaceFactory::create_interface - parameters endpoint type : %s",endpoint_type.c_str()); |
edamame22 | 0:29983394c6b6 | 50 | tr_debug("M2MInterfaceFactory::create_interface - parameters life time(in secs): %" PRId32,life_time); |
edamame22 | 0:29983394c6b6 | 51 | tr_debug("M2MInterfaceFactory::create_interface - parameters Listen Port : %d",listen_port); |
edamame22 | 0:29983394c6b6 | 52 | tr_debug("M2MInterfaceFactory::create_interface - parameters Binding Mode : %d",(int)mode); |
edamame22 | 0:29983394c6b6 | 53 | tr_debug("M2MInterfaceFactory::create_interface - parameters NetworkStack : %d",(int)stack); |
edamame22 | 0:29983394c6b6 | 54 | M2MInterfaceImpl *interface = NULL; |
edamame22 | 0:29983394c6b6 | 55 | |
edamame22 | 0:29983394c6b6 | 56 | |
edamame22 | 0:29983394c6b6 | 57 | bool endpoint_type_valid = true; |
edamame22 | 0:29983394c6b6 | 58 | if(!endpoint_type.empty()) { |
edamame22 | 0:29983394c6b6 | 59 | if(endpoint_type.size() > MAX_ALLOWED_STRING_LENGTH){ |
edamame22 | 0:29983394c6b6 | 60 | endpoint_type_valid = false; |
edamame22 | 0:29983394c6b6 | 61 | } |
edamame22 | 0:29983394c6b6 | 62 | } |
edamame22 | 0:29983394c6b6 | 63 | |
edamame22 | 0:29983394c6b6 | 64 | bool domain_valid = true; |
edamame22 | 0:29983394c6b6 | 65 | if(!domain.empty()) { |
edamame22 | 0:29983394c6b6 | 66 | if(domain.size() > MAX_ALLOWED_STRING_LENGTH){ |
edamame22 | 0:29983394c6b6 | 67 | domain_valid = false; |
edamame22 | 0:29983394c6b6 | 68 | } |
edamame22 | 0:29983394c6b6 | 69 | } |
edamame22 | 0:29983394c6b6 | 70 | |
edamame22 | 0:29983394c6b6 | 71 | if(((life_time == -1) || (life_time >= MINIMUM_REGISTRATION_TIME)) && |
edamame22 | 0:29983394c6b6 | 72 | !endpoint_name.empty() && (endpoint_name.size() <= MAX_ALLOWED_STRING_LENGTH) && |
edamame22 | 0:29983394c6b6 | 73 | endpoint_type_valid && domain_valid) { |
edamame22 | 0:29983394c6b6 | 74 | tr_debug("M2MInterfaceFactory::create_interface - Creating M2MInterfaceImpl"); |
edamame22 | 0:29983394c6b6 | 75 | interface = new M2MInterfaceImpl(observer, endpoint_name, |
edamame22 | 0:29983394c6b6 | 76 | endpoint_type, life_time, |
edamame22 | 0:29983394c6b6 | 77 | listen_port, domain, mode, |
edamame22 | 0:29983394c6b6 | 78 | stack, context_address); |
edamame22 | 0:29983394c6b6 | 79 | |
edamame22 | 0:29983394c6b6 | 80 | } |
edamame22 | 0:29983394c6b6 | 81 | tr_debug("M2MInterfaceFactory::create_interface - OUT"); |
edamame22 | 0:29983394c6b6 | 82 | return interface; |
edamame22 | 0:29983394c6b6 | 83 | } |
edamame22 | 0:29983394c6b6 | 84 | |
edamame22 | 0:29983394c6b6 | 85 | M2MSecurity* M2MInterfaceFactory::create_security(M2MSecurity::ServerType server_type) |
edamame22 | 0:29983394c6b6 | 86 | { |
edamame22 | 0:29983394c6b6 | 87 | tr_debug("M2MInterfaceFactory::create_security"); |
edamame22 | 0:29983394c6b6 | 88 | M2MSecurity *security = new M2MSecurity(server_type); |
edamame22 | 0:29983394c6b6 | 89 | return security; |
edamame22 | 0:29983394c6b6 | 90 | } |
edamame22 | 0:29983394c6b6 | 91 | |
edamame22 | 0:29983394c6b6 | 92 | M2MServer* M2MInterfaceFactory::create_server() |
edamame22 | 0:29983394c6b6 | 93 | { |
edamame22 | 0:29983394c6b6 | 94 | tr_debug("M2MInterfaceFactory::create_server"); |
edamame22 | 0:29983394c6b6 | 95 | M2MServer *server = new M2MServer(); |
edamame22 | 0:29983394c6b6 | 96 | return server; |
edamame22 | 0:29983394c6b6 | 97 | } |
edamame22 | 0:29983394c6b6 | 98 | |
edamame22 | 0:29983394c6b6 | 99 | M2MDevice* M2MInterfaceFactory::create_device() |
edamame22 | 0:29983394c6b6 | 100 | { |
edamame22 | 0:29983394c6b6 | 101 | tr_debug("M2MInterfaceFactory::create_device"); |
edamame22 | 0:29983394c6b6 | 102 | M2MDevice* device = M2MDevice::get_instance(); |
edamame22 | 0:29983394c6b6 | 103 | return device; |
edamame22 | 0:29983394c6b6 | 104 | } |
edamame22 | 0:29983394c6b6 | 105 | |
edamame22 | 0:29983394c6b6 | 106 | M2MFirmware* M2MInterfaceFactory::create_firmware() |
edamame22 | 0:29983394c6b6 | 107 | { |
edamame22 | 0:29983394c6b6 | 108 | tr_debug("M2MInterfaceFactory::create_firmware"); |
edamame22 | 0:29983394c6b6 | 109 | M2MFirmware* firmware = M2MFirmware::get_instance(); |
edamame22 | 0:29983394c6b6 | 110 | return firmware; |
edamame22 | 0:29983394c6b6 | 111 | } |
edamame22 | 0:29983394c6b6 | 112 | |
edamame22 | 0:29983394c6b6 | 113 | M2MObject* M2MInterfaceFactory::create_object(const String &name) |
edamame22 | 0:29983394c6b6 | 114 | { |
edamame22 | 0:29983394c6b6 | 115 | tr_debug("M2MInterfaceFactory::create_object : Name : %s", name.c_str()); |
edamame22 | 0:29983394c6b6 | 116 | if(name.size() > MAX_ALLOWED_STRING_LENGTH || name.empty()){ |
edamame22 | 0:29983394c6b6 | 117 | return NULL; |
edamame22 | 0:29983394c6b6 | 118 | } |
edamame22 | 0:29983394c6b6 | 119 | |
edamame22 | 0:29983394c6b6 | 120 | M2MObject *object = NULL; |
edamame22 | 0:29983394c6b6 | 121 | object = new M2MObject(name, M2MBase::stringdup(name.c_str())); |
edamame22 | 0:29983394c6b6 | 122 | return object; |
edamame22 | 0:29983394c6b6 | 123 | } |