BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MeshInterfaceNanostack.h Source File

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 /** Nanostack's network interface class.
00026  *
00027  * Common class that is shared between mesh interface classes
00028  */
00029 class MeshInterfaceNanostack : public MeshInterface {
00030 public:
00031 
00032     /** Attach phy and initialize the mesh
00033      *
00034      *  Initializes a mesh interface on the given phy. Not needed if
00035      *  the phy is passed to the mesh's constructor.
00036      *
00037      *  @return     0 on success, negative on failure
00038      */
00039     nsapi_error_t initialize(NanostackPhy *phy);
00040 
00041     /** Start the interface
00042      *
00043      *  @return     0 on success, negative on failure
00044      */
00045     virtual nsapi_error_t connect() = 0;
00046 
00047     /** Stop the interface
00048      *
00049      *  @return     0 on success, negative on failure
00050      */
00051     virtual nsapi_error_t disconnect() = 0;
00052 
00053     /** Get the internally stored IP address
00054     /return     IP address of the interface or null if not yet connected
00055     */
00056     virtual const char *get_ip_address();
00057 
00058     /** Get the internally stored MAC address
00059     /return     MAC address of the interface
00060     */
00061     virtual const char *get_mac_address();
00062 
00063     /** Get the interface ID
00064     /return     Interface identifier
00065     */
00066     int8_t get_interface_id() const { return _network_interface_id; }
00067 
00068     /**
00069      * \brief Callback from C-layer
00070      * \param status state of the network
00071      * */
00072     void mesh_network_handler(mesh_connection_status_t status);
00073 
00074     /** Register callback for status reporting
00075      *
00076      *  @param status_cb The callback for status changes
00077      */
00078     virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
00079 
00080     /** Get the connection status
00081      *
00082      *  @return         The connection status according to ConnectionStatusType
00083      */
00084     virtual nsapi_connection_status_t get_connection_status() const;
00085 
00086     /** Set blocking status of connect() which by default should be blocking
00087      *
00088      *  @param blocking true if connect is blocking
00089      *  @return         0 on success, negative error code on failure
00090      */
00091     virtual nsapi_error_t set_blocking(bool blocking);
00092 
00093 protected:
00094     MeshInterfaceNanostack();
00095     MeshInterfaceNanostack(NanostackPhy *phy);
00096     nsapi_error_t register_phy();
00097     virtual NetworkStack * get_stack(void);
00098 
00099     /**
00100      * \brief Read own global IP address
00101      *
00102      * \param address is where the IP address will be copied
00103      * \param len is the length of the address buffer, must be at least 40 bytes
00104      * \return true if address is read successfully, false otherwise
00105      */
00106     virtual bool getOwnIpAddress(char *address, int8_t len) = 0;
00107 
00108     NanostackPhy *phy;
00109     /** Network interface ID */
00110     int8_t _network_interface_id;
00111     /** Registered device ID */
00112     int8_t _device_id;
00113     uint8_t _eui64[8];
00114     char ip_addr_str[40];
00115     char mac_addr_str[24];
00116     Semaphore connect_semaphore;
00117 
00118     Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
00119     nsapi_connection_status_t _connect_status;
00120     bool _blocking;
00121 };
00122 
00123 #endif /* MESHINTERFACENANOSTACK_H */