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/

Committer:
Ren Boting
Date:
Tue Sep 05 11:56:13 2017 +0900
Revision:
2:b894b3508057
Parent:
0:29983394c6b6
Update all libraries and reform main.cpp

Who changed what in which revision?

UserRevisionLine numberNew 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 #ifndef M2M_INTERFACE_IMPL_H
edamame22 0:29983394c6b6 17 #define M2M_INTERFACE_IMPL_H
edamame22 0:29983394c6b6 18
edamame22 0:29983394c6b6 19 #include "mbed-client/m2minterface.h"
edamame22 0:29983394c6b6 20 #include "mbed-client/m2mserver.h"
edamame22 0:29983394c6b6 21 #include "mbed-client/m2mconnectionobserver.h"
edamame22 0:29983394c6b6 22 #include "mbed-client/m2mconnectionsecurity.h"
edamame22 0:29983394c6b6 23 #include "include/m2mnsdlobserver.h"
edamame22 0:29983394c6b6 24 #include "include/m2mnsdlinterface.h"
edamame22 0:29983394c6b6 25 #include "mbed-client/m2mtimerobserver.h"
edamame22 0:29983394c6b6 26 #include "mbed-client/m2mtimer.h"
edamame22 0:29983394c6b6 27 #include "mbed-client/m2mconnectionhandler.h"
edamame22 0:29983394c6b6 28
edamame22 0:29983394c6b6 29 //FORWARD DECLARATION
edamame22 0:29983394c6b6 30 class M2MConnectionSecurity;
edamame22 0:29983394c6b6 31 class EventData;
edamame22 0:29983394c6b6 32 class M2MUpdateRegisterData;
edamame22 0:29983394c6b6 33 /**
edamame22 0:29983394c6b6 34 * @brief M2MInterfaceImpl.
edamame22 0:29983394c6b6 35 * This class implements handling of all mbed Client Interface operations
edamame22 0:29983394c6b6 36 * defined in OMA LWM2M specifications.
edamame22 0:29983394c6b6 37 * This includes Bootstrapping, Client Registration, Device Management &
edamame22 0:29983394c6b6 38 * Service Enablement and Information Reporting.
edamame22 0:29983394c6b6 39 */
edamame22 0:29983394c6b6 40
edamame22 0:29983394c6b6 41 class M2MInterfaceImpl : public M2MInterface,
edamame22 0:29983394c6b6 42 public M2MNsdlObserver,
edamame22 0:29983394c6b6 43 public M2MConnectionObserver,
edamame22 0:29983394c6b6 44 public M2MTimerObserver
edamame22 0:29983394c6b6 45 {
edamame22 0:29983394c6b6 46 private:
edamame22 0:29983394c6b6 47 // Prevents the use of assignment operator by accident.
edamame22 0:29983394c6b6 48 M2MInterfaceImpl& operator=( const M2MInterfaceImpl& /*other*/ );
edamame22 0:29983394c6b6 49
edamame22 0:29983394c6b6 50 // Prevents the use of copy constructor by accident
edamame22 0:29983394c6b6 51 M2MInterfaceImpl( const M2MInterfaceImpl& /*other*/ );
edamame22 0:29983394c6b6 52
edamame22 0:29983394c6b6 53 friend class M2MInterfaceFactory;
edamame22 0:29983394c6b6 54
edamame22 0:29983394c6b6 55 private:
edamame22 0:29983394c6b6 56
edamame22 0:29983394c6b6 57 /**
edamame22 0:29983394c6b6 58 * @brief Constructor
edamame22 0:29983394c6b6 59 * @param observer, Observer to pass the event callbacks for various
edamame22 0:29983394c6b6 60 * interface operations.
edamame22 0:29983394c6b6 61 * @param endpoint_name Endpoint name of the client.
edamame22 0:29983394c6b6 62 * @param endpoint_type Endpoint type of the client.
edamame22 0:29983394c6b6 63 * @param life_time Life time of the client in seconds
edamame22 0:29983394c6b6 64 * @param listen_port Listening port for the endpoint, default is 8000.
edamame22 0:29983394c6b6 65 * @param domain Domain of the client.
edamame22 0:29983394c6b6 66 * @param mode Binding mode of the client, default is UDP
edamame22 0:29983394c6b6 67 * @param stack Network stack to be used for connection, default is LwIP_IPv4.
edamame22 0:29983394c6b6 68 * @param context_address Context address, default is empty.
edamame22 0:29983394c6b6 69 */
edamame22 0:29983394c6b6 70 M2MInterfaceImpl(M2MInterfaceObserver& observer,
edamame22 0:29983394c6b6 71 const String &endpoint_name,
edamame22 0:29983394c6b6 72 const String &endpoint_type,
edamame22 0:29983394c6b6 73 const int32_t life_time,
edamame22 0:29983394c6b6 74 const uint16_t listen_port,
edamame22 0:29983394c6b6 75 const String &domain = "",
edamame22 0:29983394c6b6 76 BindingMode mode = M2MInterface::NOT_SET,
edamame22 0:29983394c6b6 77 M2MInterface::NetworkStack stack = M2MInterface::LwIP_IPv4,
edamame22 0:29983394c6b6 78 const String &context_address = "");
edamame22 0:29983394c6b6 79
edamame22 0:29983394c6b6 80 public:
edamame22 0:29983394c6b6 81
edamame22 0:29983394c6b6 82 /**
edamame22 0:29983394c6b6 83 * @brief Destructor
edamame22 0:29983394c6b6 84 */
edamame22 0:29983394c6b6 85 virtual ~M2MInterfaceImpl();
edamame22 0:29983394c6b6 86
edamame22 0:29983394c6b6 87 /**
edamame22 0:29983394c6b6 88 * @brief Initiates bootstrapping of the client with the provided Bootstrap
edamame22 0:29983394c6b6 89 * server information.
edamame22 0:29983394c6b6 90 * @param security_object Security object which contains information
edamame22 0:29983394c6b6 91 * required for successful bootstrapping of the client.
edamame22 0:29983394c6b6 92 */
edamame22 0:29983394c6b6 93 virtual void bootstrap(M2MSecurity *security);
edamame22 0:29983394c6b6 94
edamame22 0:29983394c6b6 95 /**
edamame22 0:29983394c6b6 96 * @brief Cancels on going bootstrapping operation of the client. If the client has
edamame22 0:29983394c6b6 97 * already successfully bootstrapped then this function deletes existing
edamame22 0:29983394c6b6 98 * bootstrap information from the client.
edamame22 0:29983394c6b6 99 */
edamame22 0:29983394c6b6 100 virtual void cancel_bootstrap();
edamame22 0:29983394c6b6 101
edamame22 0:29983394c6b6 102 /**
edamame22 0:29983394c6b6 103 * @brief Initiates registration of the provided Security object to the
edamame22 0:29983394c6b6 104 * corresponding LWM2M server.
edamame22 0:29983394c6b6 105 * @param security_object Security object which contains information
edamame22 0:29983394c6b6 106 * required for registering to the LWM2M server.
edamame22 0:29983394c6b6 107 * If client wants to register to multiple LWM2M servers then it has call
edamame22 0:29983394c6b6 108 * this function once for each of LWM2M server object separately.
edamame22 0:29983394c6b6 109 * @param object_list Objects which contains information
edamame22 0:29983394c6b6 110 * which the client want to register to the LWM2M server.
edamame22 0:29983394c6b6 111 */
edamame22 0:29983394c6b6 112 virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list);
edamame22 0:29983394c6b6 113
edamame22 0:29983394c6b6 114 /**
edamame22 0:29983394c6b6 115 * @brief Updates or refreshes the client's registration on the LWM2M
edamame22 0:29983394c6b6 116 * server.
edamame22 0:29983394c6b6 117 * @param security_object Security object from which the device object
edamame22 0:29983394c6b6 118 * needs to update registration, if there is only one LWM2M server registered
edamame22 0:29983394c6b6 119 * then this parameter can be NULL.
edamame22 0:29983394c6b6 120 * @param lifetime Lifetime for the endpoint client in seconds.
edamame22 0:29983394c6b6 121 */
edamame22 0:29983394c6b6 122 virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0);
edamame22 0:29983394c6b6 123
edamame22 0:29983394c6b6 124 /**
edamame22 0:29983394c6b6 125 * @brief Updates or refreshes the client's registration on the LWM2M
edamame22 0:29983394c6b6 126 * server. Use this function to publish new objects to LWM2M server.
edamame22 0:29983394c6b6 127 * @param security_object The security object from which the device object
edamame22 0:29983394c6b6 128 * needs to update the registration. If there is only one LWM2M server registered,
edamame22 0:29983394c6b6 129 * this parameter can be NULL.
edamame22 0:29983394c6b6 130 * @param object_list Objects that contain information about the
edamame22 0:29983394c6b6 131 * client attempting to register to the LWM2M server.
edamame22 0:29983394c6b6 132 * @param lifetime The lifetime of the endpoint client in seconds. If the same value
edamame22 0:29983394c6b6 133 * has to be passed, set the default value to 0.
edamame22 0:29983394c6b6 134 */
edamame22 0:29983394c6b6 135 virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
edamame22 0:29983394c6b6 136 const uint32_t lifetime = 0);
edamame22 0:29983394c6b6 137
edamame22 0:29983394c6b6 138 /**
edamame22 0:29983394c6b6 139 * @brief Unregisters the registered object from the LWM2M server
edamame22 0:29983394c6b6 140 * @param security_object Security object from which the device object
edamame22 0:29983394c6b6 141 * needs to be unregistered. If there is only one LWM2M server registered
edamame22 0:29983394c6b6 142 * this parameter can be NULL.
edamame22 0:29983394c6b6 143 */
edamame22 0:29983394c6b6 144 virtual void unregister_object(M2MSecurity* security = NULL);
edamame22 0:29983394c6b6 145
edamame22 0:29983394c6b6 146 /**
edamame22 0:29983394c6b6 147 * @brief Sets the function which will be called indicating client
edamame22 0:29983394c6b6 148 * is going to sleep when the Binding mode is selected with Queue mode.
edamame22 0:29983394c6b6 149 * @param callback A function pointer that will be called when client
edamame22 0:29983394c6b6 150 * goes to sleep.
edamame22 0:29983394c6b6 151 */
edamame22 0:29983394c6b6 152 virtual void set_queue_sleep_handler(callback_handler handler);
edamame22 0:29983394c6b6 153
edamame22 0:29983394c6b6 154 /**
edamame22 0:29983394c6b6 155 * @brief Sets the network interface handler that is used by client to connect
edamame22 0:29983394c6b6 156 * to a network over IP.
edamame22 0:29983394c6b6 157 * @param handler A network interface handler that is used by client to connect.
edamame22 0:29983394c6b6 158 * This API is optional but provides a mechanism for different platforms to
edamame22 0:29983394c6b6 159 * manage usage of underlying network interface by client.
edamame22 0:29983394c6b6 160 */
edamame22 0:29983394c6b6 161 virtual void set_platform_network_handler(void *handler = NULL);
edamame22 0:29983394c6b6 162
edamame22 0:29983394c6b6 163 /**
edamame22 0:29983394c6b6 164 * \brief Sets the function callback that will be called by mbed-client for
edamame22 0:29983394c6b6 165 * fetching random number from application for ensuring strong entropy.
edamame22 0:29983394c6b6 166 * \param random_callback A function pointer that will be called by mbed-client
edamame22 0:29983394c6b6 167 * while performing secure handshake.
edamame22 0:29983394c6b6 168 * Function signature should be uint32_t (*random_number_callback)(void);
edamame22 0:29983394c6b6 169 */
edamame22 0:29983394c6b6 170 virtual void set_random_number_callback(random_number_cb callback);
edamame22 0:29983394c6b6 171
edamame22 0:29983394c6b6 172 /**
edamame22 0:29983394c6b6 173 * \brief Sets the function callback that will be called by mbed-client for
edamame22 0:29983394c6b6 174 * providing entropy source from application for ensuring strong entropy.
edamame22 0:29983394c6b6 175 * \param entropy_callback A function pointer that will be called by mbed-client
edamame22 0:29983394c6b6 176 * while performing secure handshake.
edamame22 0:29983394c6b6 177 * Function signature , if using mbed-client-mbedtls should be
edamame22 0:29983394c6b6 178 * int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output,
edamame22 0:29983394c6b6 179 * size_t len, size_t *olen);
edamame22 0:29983394c6b6 180 */
edamame22 0:29983394c6b6 181 virtual void set_entropy_callback(entropy_cb callback);
edamame22 0:29983394c6b6 182
edamame22 0:29983394c6b6 183
edamame22 0:29983394c6b6 184 protected: // From M2MNsdlObserver
edamame22 0:29983394c6b6 185
edamame22 0:29983394c6b6 186 virtual void coap_message_ready(uint8_t *data_ptr,
edamame22 0:29983394c6b6 187 uint16_t data_len,
edamame22 0:29983394c6b6 188 sn_nsdl_addr_s *address_ptr);
edamame22 0:29983394c6b6 189
edamame22 0:29983394c6b6 190 virtual void client_registered(M2MServer *server_object);
edamame22 0:29983394c6b6 191
edamame22 0:29983394c6b6 192 virtual void registration_updated(const M2MServer &server_object);
edamame22 0:29983394c6b6 193
edamame22 0:29983394c6b6 194 virtual void registration_error(uint8_t error_code, bool retry = false);
edamame22 0:29983394c6b6 195
edamame22 0:29983394c6b6 196 virtual void client_unregistered();
edamame22 0:29983394c6b6 197
edamame22 0:29983394c6b6 198 virtual void bootstrap_done(M2MSecurity *security_object);
edamame22 0:29983394c6b6 199
edamame22 0:29983394c6b6 200 virtual void bootstrap_wait(M2MSecurity *security_object);
edamame22 0:29983394c6b6 201
edamame22 0:29983394c6b6 202 virtual void bootstrap_error();
edamame22 0:29983394c6b6 203
edamame22 0:29983394c6b6 204 virtual void coap_data_processed();
edamame22 0:29983394c6b6 205
edamame22 0:29983394c6b6 206 virtual void value_updated(M2MBase *base);
edamame22 0:29983394c6b6 207
edamame22 0:29983394c6b6 208 protected: // From M2MConnectionObserver
edamame22 0:29983394c6b6 209
edamame22 0:29983394c6b6 210 virtual void data_available(uint8_t* data,
edamame22 0:29983394c6b6 211 uint16_t data_size,
edamame22 0:29983394c6b6 212 const M2MConnectionObserver::SocketAddress &address);
edamame22 0:29983394c6b6 213
edamame22 0:29983394c6b6 214 virtual void socket_error(uint8_t error_code, bool retry = true);
edamame22 0:29983394c6b6 215
edamame22 0:29983394c6b6 216 virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
edamame22 0:29983394c6b6 217 M2MConnectionObserver::ServerType server_type,
edamame22 0:29983394c6b6 218 const uint16_t server_port);
edamame22 0:29983394c6b6 219
edamame22 0:29983394c6b6 220 virtual void data_sent();
edamame22 0:29983394c6b6 221
edamame22 0:29983394c6b6 222 protected: // from M2MTimerObserver
edamame22 0:29983394c6b6 223
edamame22 0:29983394c6b6 224 virtual void timer_expired(M2MTimerObserver::Type type);
edamame22 0:29983394c6b6 225
edamame22 0:29983394c6b6 226
edamame22 0:29983394c6b6 227 private: // state machine state functions
edamame22 0:29983394c6b6 228
edamame22 0:29983394c6b6 229 /**
edamame22 0:29983394c6b6 230 * When the state is Idle.
edamame22 0:29983394c6b6 231 */
edamame22 0:29983394c6b6 232 void state_idle(EventData* data);
edamame22 0:29983394c6b6 233
edamame22 0:29983394c6b6 234 /**
edamame22 0:29983394c6b6 235 * When the client starts bootstrap.
edamame22 0:29983394c6b6 236 */
edamame22 0:29983394c6b6 237 void state_bootstrap( EventData *data);
edamame22 0:29983394c6b6 238
edamame22 0:29983394c6b6 239 /**
edamame22 0:29983394c6b6 240 * When the bootstrap server address is resolved.
edamame22 0:29983394c6b6 241 */
edamame22 0:29983394c6b6 242 void state_bootstrap_address_resolved( EventData *data);
edamame22 0:29983394c6b6 243
edamame22 0:29983394c6b6 244 /**
edamame22 0:29983394c6b6 245 * When the bootstrap resource is created.
edamame22 0:29983394c6b6 246 */
edamame22 0:29983394c6b6 247 void state_bootstrap_resource_created( EventData *data);
edamame22 0:29983394c6b6 248
edamame22 0:29983394c6b6 249 /**
edamame22 0:29983394c6b6 250 * When the server has sent response and bootstrapping is done.
edamame22 0:29983394c6b6 251 */
edamame22 0:29983394c6b6 252 void state_bootstrapped( EventData *data);
edamame22 0:29983394c6b6 253
edamame22 0:29983394c6b6 254 /**
edamame22 0:29983394c6b6 255 * When the client starts register.
edamame22 0:29983394c6b6 256 */
edamame22 0:29983394c6b6 257 void state_register( EventData *data);
edamame22 0:29983394c6b6 258
edamame22 0:29983394c6b6 259 /**
edamame22 0:29983394c6b6 260 * When the server address for register is resolved.
edamame22 0:29983394c6b6 261 */
edamame22 0:29983394c6b6 262 void state_register_address_resolved( EventData *data);
edamame22 0:29983394c6b6 263
edamame22 0:29983394c6b6 264 /**
edamame22 0:29983394c6b6 265 * When the client is registered.
edamame22 0:29983394c6b6 266 */
edamame22 0:29983394c6b6 267 void state_registered( EventData *data);
edamame22 0:29983394c6b6 268
edamame22 0:29983394c6b6 269 /**
edamame22 0:29983394c6b6 270 * When the client is updating registration.
edamame22 0:29983394c6b6 271 */
edamame22 0:29983394c6b6 272 void state_update_registration( EventData *data);
edamame22 0:29983394c6b6 273
edamame22 0:29983394c6b6 274 /**
edamame22 0:29983394c6b6 275 * When the client starts unregister.
edamame22 0:29983394c6b6 276 */
edamame22 0:29983394c6b6 277 void state_unregister( EventData *data);
edamame22 0:29983394c6b6 278
edamame22 0:29983394c6b6 279 /**
edamame22 0:29983394c6b6 280 * When the client has been unregistered.
edamame22 0:29983394c6b6 281 */
edamame22 0:29983394c6b6 282 void state_unregistered( EventData *data);
edamame22 0:29983394c6b6 283
edamame22 0:29983394c6b6 284 /**
edamame22 0:29983394c6b6 285 * When the coap data is been sent through socket.
edamame22 0:29983394c6b6 286 */
edamame22 0:29983394c6b6 287 void state_sending_coap_data( EventData *data);
edamame22 0:29983394c6b6 288
edamame22 0:29983394c6b6 289 /**
edamame22 0:29983394c6b6 290 * When the coap data is sent successfully.
edamame22 0:29983394c6b6 291 */
edamame22 0:29983394c6b6 292 void state_coap_data_sent( EventData *data);
edamame22 0:29983394c6b6 293
edamame22 0:29983394c6b6 294 /**
edamame22 0:29983394c6b6 295 * When the socket is receiving coap data.
edamame22 0:29983394c6b6 296 */
edamame22 0:29983394c6b6 297 void state_receiving_coap_data( EventData *data);
edamame22 0:29983394c6b6 298
edamame22 0:29983394c6b6 299 /**
edamame22 0:29983394c6b6 300 * When the socket has received coap data.
edamame22 0:29983394c6b6 301 */
edamame22 0:29983394c6b6 302 void state_coap_data_received( EventData *data);
edamame22 0:29983394c6b6 303
edamame22 0:29983394c6b6 304 /**
edamame22 0:29983394c6b6 305 * When the coap message is being processed.
edamame22 0:29983394c6b6 306 */
edamame22 0:29983394c6b6 307 void state_processing_coap_data( EventData *data);
edamame22 0:29983394c6b6 308
edamame22 0:29983394c6b6 309 /**
edamame22 0:29983394c6b6 310 * When the coap message has been processed.
edamame22 0:29983394c6b6 311 */
edamame22 0:29983394c6b6 312 void state_coap_data_processed( EventData *data);
edamame22 0:29983394c6b6 313
edamame22 0:29983394c6b6 314 /**
edamame22 0:29983394c6b6 315 * When the client is waiting to receive or send data.
edamame22 0:29983394c6b6 316 */
edamame22 0:29983394c6b6 317 void state_waiting( EventData *data);
edamame22 0:29983394c6b6 318
edamame22 0:29983394c6b6 319 /**
edamame22 0:29983394c6b6 320 * Start registration update.
edamame22 0:29983394c6b6 321 */
edamame22 0:29983394c6b6 322 void start_register_update(M2MUpdateRegisterData *data);
edamame22 0:29983394c6b6 323
edamame22 0:29983394c6b6 324 /**
edamame22 0:29983394c6b6 325 * State enumeration order must match the order of state
edamame22 0:29983394c6b6 326 * method entries in the state map
edamame22 0:29983394c6b6 327 */
edamame22 0:29983394c6b6 328 enum E_States {
edamame22 0:29983394c6b6 329 STATE_IDLE = 0,
edamame22 0:29983394c6b6 330 STATE_BOOTSTRAP,
edamame22 0:29983394c6b6 331 STATE_BOOTSTRAP_ADDRESS_RESOLVED,
edamame22 0:29983394c6b6 332 STATE_BOOTSTRAP_RESOURCE_CREATED,
edamame22 0:29983394c6b6 333 STATE_BOOTSTRAP_WAIT,
edamame22 0:29983394c6b6 334 STATE_BOOTSTRAPPED, //5
edamame22 0:29983394c6b6 335 STATE_REGISTER,
edamame22 0:29983394c6b6 336 STATE_REGISTER_ADDRESS_RESOLVED,
edamame22 0:29983394c6b6 337 STATE_REGISTERED,
edamame22 0:29983394c6b6 338 STATE_UPDATE_REGISTRATION,
edamame22 0:29983394c6b6 339 STATE_UNREGISTER, //10
edamame22 0:29983394c6b6 340 STATE_UNREGISTERED,
edamame22 0:29983394c6b6 341 STATE_SENDING_COAP_DATA,
edamame22 0:29983394c6b6 342 STATE_COAP_DATA_SENT,
edamame22 0:29983394c6b6 343 STATE_COAP_DATA_RECEIVED,
edamame22 0:29983394c6b6 344 STATE_PROCESSING_COAP_DATA, //15
edamame22 0:29983394c6b6 345 STATE_COAP_DATA_PROCESSED,
edamame22 0:29983394c6b6 346 STATE_WAITING,
edamame22 0:29983394c6b6 347 STATE_MAX_STATES
edamame22 0:29983394c6b6 348 };
edamame22 0:29983394c6b6 349
edamame22 0:29983394c6b6 350 /**
edamame22 0:29983394c6b6 351 * @brief Redirects the state machine to right function.
edamame22 0:29983394c6b6 352 * @param current_state Current state to be set.
edamame22 0:29983394c6b6 353 * @param data Data to be passed to the state function.
edamame22 0:29983394c6b6 354 */
edamame22 0:29983394c6b6 355 void state_function( uint8_t current_state, EventData* data );
edamame22 0:29983394c6b6 356
edamame22 0:29983394c6b6 357 /**
edamame22 0:29983394c6b6 358 * @brief State Engine maintaining state machine logic.
edamame22 0:29983394c6b6 359 */
edamame22 0:29983394c6b6 360 void state_engine(void);
edamame22 0:29983394c6b6 361
edamame22 0:29983394c6b6 362 /**
edamame22 0:29983394c6b6 363 * External event which can trigger the state machine.
edamame22 0:29983394c6b6 364 * @param New The state to which the state machine should go.
edamame22 0:29983394c6b6 365 * @param data The data to be passed to the state machine.
edamame22 0:29983394c6b6 366 */
edamame22 0:29983394c6b6 367 void external_event(uint8_t, EventData* = NULL);
edamame22 0:29983394c6b6 368
edamame22 0:29983394c6b6 369 /**
edamame22 0:29983394c6b6 370 * Internal event generated by state machine.
edamame22 0:29983394c6b6 371 * @param New State which the state machine should go to.
edamame22 0:29983394c6b6 372 * @param data The data to be passed to the state machine.
edamame22 0:29983394c6b6 373 */
edamame22 0:29983394c6b6 374 void internal_event(uint8_t, EventData* = NULL);
edamame22 0:29983394c6b6 375
edamame22 0:29983394c6b6 376 enum
edamame22 0:29983394c6b6 377 {
edamame22 0:29983394c6b6 378 EVENT_IGNORED = 0xFE,
edamame22 0:29983394c6b6 379 CANNOT_HAPPEN
edamame22 0:29983394c6b6 380 };
edamame22 0:29983394c6b6 381
edamame22 0:29983394c6b6 382 /**
edamame22 0:29983394c6b6 383 * Helper method for extracting the IP address part and port from the
edamame22 0:29983394c6b6 384 * given server address.
edamame22 0:29983394c6b6 385 * @param server_address Source URL (without "coap" or "coaps" prefix).
edamame22 0:29983394c6b6 386 * @param ip_address The extracted IP.
edamame22 0:29983394c6b6 387 * @param port The extracted port.
edamame22 0:29983394c6b6 388 */
edamame22 0:29983394c6b6 389 static void process_address(const String& server_address, String& ip_address, uint16_t& port);
edamame22 0:29983394c6b6 390
edamame22 0:29983394c6b6 391 private:
edamame22 0:29983394c6b6 392
edamame22 0:29983394c6b6 393 EventData *_event_data;
edamame22 0:29983394c6b6 394 M2MTimer *_bootstrap_timer;
edamame22 0:29983394c6b6 395 uint16_t _server_port;
edamame22 0:29983394c6b6 396 uint16_t _listen_port;
edamame22 0:29983394c6b6 397 String _endpoint_type;
edamame22 0:29983394c6b6 398 String _domain;
edamame22 0:29983394c6b6 399 int32_t _life_time;
edamame22 0:29983394c6b6 400 String _context_address;
edamame22 0:29983394c6b6 401 String _server_ip_address;
edamame22 0:29983394c6b6 402 M2MSecurity *_register_server; //TODO: to be the list not owned
edamame22 0:29983394c6b6 403 M2MTimer _queue_sleep_timer;
edamame22 0:29983394c6b6 404 M2MTimer _retry_timer;
edamame22 0:29983394c6b6 405 callback_handler _callback_handler;
edamame22 0:29983394c6b6 406 const uint8_t _max_states;
edamame22 0:29983394c6b6 407 bool _event_ignored;
edamame22 0:29983394c6b6 408 bool _event_generated;
edamame22 0:29983394c6b6 409 bool _reconnecting;
edamame22 0:29983394c6b6 410 bool _retry_timer_expired;
edamame22 0:29983394c6b6 411 bool _bootstrapped;
edamame22 0:29983394c6b6 412 uint8_t _current_state;
edamame22 0:29983394c6b6 413 uint8_t _retry_count;
edamame22 0:29983394c6b6 414 BindingMode _binding_mode;
edamame22 0:29983394c6b6 415 M2MInterfaceObserver &_observer;
edamame22 0:29983394c6b6 416 M2MConnectionSecurity *_security_connection; // Doesn't own
edamame22 0:29983394c6b6 417 M2MConnectionHandler _connection_handler;
edamame22 0:29983394c6b6 418 M2MNsdlInterface _nsdl_interface;
edamame22 0:29983394c6b6 419 M2MSecurity *_security;
edamame22 0:29983394c6b6 420
edamame22 0:29983394c6b6 421 friend class Test_M2MInterfaceImpl;
edamame22 0:29983394c6b6 422
edamame22 0:29983394c6b6 423 };
edamame22 0:29983394c6b6 424
edamame22 0:29983394c6b6 425 #define BEGIN_TRANSITION_MAP \
edamame22 0:29983394c6b6 426 static const uint8_t TRANSITIONS[] = {\
edamame22 0:29983394c6b6 427
edamame22 0:29983394c6b6 428 #define TRANSITION_MAP_ENTRY(entry)\
edamame22 0:29983394c6b6 429 entry,
edamame22 0:29983394c6b6 430
edamame22 0:29983394c6b6 431 #define END_TRANSITION_MAP(data) \
edamame22 0:29983394c6b6 432 0 };\
edamame22 0:29983394c6b6 433 external_event(TRANSITIONS[_current_state], data);
edamame22 0:29983394c6b6 434
edamame22 0:29983394c6b6 435 #endif //M2M_INTERFACE_IMPL_H
edamame22 0:29983394c6b6 436
edamame22 0:29983394c6b6 437