init
Embed:
(wiki syntax)
Show/hide line numbers
MeshInterfaceNanostack.h
00001 /* 00002 * Copyright (c) 2016 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef MESHINTERFACENANOSTACK_H 00018 #define MESHINTERFACENANOSTACK_H 00019 #include "mbed.h" 00020 00021 #include "MeshInterface.h" 00022 #include "NanostackRfPhy.h" 00023 #include "mesh_interface_types.h" 00024 00025 class MeshInterfaceNanostack : public MeshInterface { 00026 public: 00027 00028 /** Attach phy and initialize the mesh 00029 * 00030 * Initializes a mesh interface on the given phy. Not needed if 00031 * the phy is passed to the mesh's constructor. 00032 * 00033 * @return 0 on success, negative on failure 00034 */ 00035 nsapi_error_t initialize(NanostackPhy *phy); 00036 00037 /** Start the interface 00038 * 00039 * @return 0 on success, negative on failure 00040 */ 00041 virtual nsapi_error_t connect() = 0; 00042 00043 /** Stop the interface 00044 * 00045 * @return 0 on success, negative on failure 00046 */ 00047 virtual nsapi_error_t disconnect() = 0; 00048 00049 /** Get the internally stored IP address 00050 /return IP address of the interface or null if not yet connected 00051 */ 00052 virtual const char *get_ip_address(); 00053 00054 /** Get the internally stored MAC address 00055 /return MAC address of the interface 00056 */ 00057 virtual const char *get_mac_address(); 00058 00059 /** Get the interface ID 00060 /return Interface identifier 00061 */ 00062 int8_t get_interface_id() const { return _network_interface_id; } 00063 00064 /** 00065 * \brief Callback from C-layer 00066 * \param state state of the network 00067 * */ 00068 void mesh_network_handler(mesh_connection_status_t status); 00069 00070 /** Register callback for status reporting 00071 * 00072 * @param status_cb The callback for status changes 00073 */ 00074 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); 00075 00076 /** Get the connection status 00077 * 00078 * @return The connection status according to ConnectionStatusType 00079 */ 00080 virtual nsapi_connection_status_t get_connection_status() const; 00081 00082 /** Set blocking status of connect() which by default should be blocking 00083 * 00084 * @param blocking true if connect is blocking 00085 * @return 0 on success, negative error code on failure 00086 */ 00087 virtual nsapi_error_t set_blocking(bool blocking); 00088 00089 protected: 00090 MeshInterfaceNanostack(); 00091 MeshInterfaceNanostack(NanostackPhy *phy); 00092 nsapi_error_t register_phy(); 00093 virtual NetworkStack * get_stack(void); 00094 00095 /** 00096 * \brief Read own global IP address 00097 * 00098 * \param address is where the IP address will be copied 00099 * \param len is the length of the address buffer, must be at least 40 bytes 00100 * \return true if address is read successfully, false otherwise 00101 */ 00102 virtual bool getOwnIpAddress(char *address, int8_t len) = 0; 00103 00104 NanostackPhy *phy; 00105 /** Network interface ID */ 00106 int8_t _network_interface_id; 00107 /** Registered device ID */ 00108 int8_t _device_id; 00109 uint8_t _eui64[8]; 00110 char ip_addr_str[40]; 00111 char mac_addr_str[24]; 00112 Semaphore connect_semaphore; 00113 00114 Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; 00115 nsapi_connection_status_t _connect_status; 00116 bool _blocking; 00117 }; 00118 00119 #endif /* MESHINTERFACENANOSTACK_H */
Generated on Tue Jul 12 2022 13:24:58 by
1.7.2