Rename NanostackRfPhy to NanostackPhy

This is to allow other types of PHY drivers than just RF.
Mesh-API does not actually care about driver type, it is drivers
responsibility to register right handlers with Nanostack.

* Implement a wrapper class NanostackRfPhy to ensure backward
  compatibility.
* Remove mesh_connect()/disconnect() functions from MeshInterface
  This job is already done in inherited classes.
* LoWPANNDInterface and ThreadInterface should only be used with
  NanostackRfPhy.
pull/3267/head
Seppo Takalo 2016-11-15 13:01:36 +02:00
parent 6ba755e444
commit 7732adb8a0
8 changed files with 71 additions and 51 deletions

View File

@ -26,17 +26,14 @@ public:
*
* Must initialize to initialize the mesh on a phy.
*/
LoWPANNDInterface() : MeshInterfaceNanostack() {
}
LoWPANNDInterface() : MeshInterfaceNanostack() { }
/** Create an initialized MeshInterface
*
*/
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
}
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
nsapi_error_t initialize(NanostackRfPhy *phy);
int connect();
int disconnect();
bool getOwnIpAddress(char *address, int8_t len);

View File

@ -32,7 +32,7 @@ public:
*
* @return 0 on success, negative on failure
*/
virtual nsapi_error_t initialize(NanostackRfPhy *phy);
virtual nsapi_error_t initialize(NanostackPhy *phy);
/** Start the interface
*
@ -64,27 +64,10 @@ public:
protected:
MeshInterfaceNanostack();
MeshInterfaceNanostack(NanostackRfPhy *phy);
nsapi_error_t register_rf();
MeshInterfaceNanostack(NanostackPhy *phy);
nsapi_error_t register_phy();
virtual NetworkStack * get_stack(void);
/**
* \brief Connect interface to the mesh network
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_PARAM in case of illegal parameters.
* \return MESH_ERROR_MEMORY in case of memory error.
* \return MESH_ERROR_STATE if interface is already connected to network.
* \return MESH_ERROR_UNKNOWN in case of unspecified error.
* */
virtual mesh_error_t mesh_connect() = 0;
/**
* \brief Disconnect interface from the mesh network
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of error.
* */
virtual mesh_error_t mesh_disconnect() = 0;
/**
* \brief Read own global IP address
*
@ -94,7 +77,7 @@ protected:
*/
virtual bool getOwnIpAddress(char *address, int8_t len) = 0;
NanostackRfPhy *phy;
NanostackPhy *phy;
/** Network interface ID */
int8_t _network_interface_id;
/** Registered device ID */

View File

@ -26,17 +26,14 @@ public:
*
* Must initialize to initialize the mesh on a phy.
*/
ThreadInterface() : MeshInterfaceNanostack() {
}
ThreadInterface() : MeshInterfaceNanostack() { }
/** Create an initialized MeshInterface
*
*/
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
}
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
nsapi_error_t initialize(NanostackRfPhy *phy);
int connect();
int disconnect();
private:

View File

@ -7,11 +7,16 @@
#include "ns_trace.h"
#define TRACE_GROUP "nslp"
nsapi_error_t LoWPANNDInterface::initialize(NanostackRfPhy *phy)
{
return MeshInterfaceNanostack::initialize(phy);
}
int LoWPANNDInterface::connect()
{
nanostack_lock();
if (register_rf() < 0) {
if (register_phy() < 0) {
nanostack_unlock();
return NSAPI_ERROR_DEVICE_ERROR;
}

View File

@ -25,13 +25,13 @@ MeshInterfaceNanostack::MeshInterfaceNanostack()
// Nothing to do
}
MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackRfPhy *phy)
MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackPhy *phy)
: phy(phy), _network_interface_id(-1), _device_id(-1), connect_semaphore(0)
{
// Nothing to do
}
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackPhy *phy)
{
mesh_system_init();
if (this->phy != NULL) {
@ -52,11 +52,11 @@ void MeshInterfaceNanostack::mesh_network_handler(mesh_connection_status_t statu
nanostack_unlock();
}
nsapi_error_t MeshInterfaceNanostack::register_rf()
nsapi_error_t MeshInterfaceNanostack::register_phy()
{
nanostack_lock();
_device_id = phy->rf_register();
_device_id = phy->phy_register();
if (_device_id < 0) {
nanostack_unlock();
return -1;

View File

@ -7,11 +7,16 @@
#include "ns_trace.h"
#define TRACE_GROUP "nsth"
nsapi_error_t ThreadInterface::initialize(NanostackRfPhy *phy)
{
return MeshInterfaceNanostack::initialize(phy);
}
int ThreadInterface::connect()
{
nanostack_lock();
if (register_rf() < 0) {
if (register_phy() < 0) {
nanostack_unlock();
return NSAPI_ERROR_DEVICE_ERROR;
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
*/
#ifndef NANOSTACK_PHY_H_
#define NANOSTACK_PHY_H_
class NanostackPhy {
public:
/** Register this physical interface with Nanostack
*
* @return Device driver ID or a negative error
* code on failure
*/
virtual int8_t phy_register() = 0;
/** Read the mac address of this physical interface
*
* Note - some devices do not have a mac address
* in hardware.
*/
virtual void get_mac_address(uint8_t *mac) = 0;
/** Set the mac address of this physical interface
*
*/
virtual void set_mac_address(uint8_t *mac) = 0;
protected:
NanostackPhy() {}
virtual ~NanostackPhy() {}
};
#endif /* NANOSTACK_INTERFACE_H_ */

View File

@ -5,7 +5,9 @@
#ifndef NANOSTACK_RF_PHY_H_
#define NANOSTACK_RF_PHY_H_
class NanostackRfPhy {
#include "NanostackPhy.h"
class NanostackRfPhy : public NanostackPhy {
public:
/** Register this physical interface with Nanostack
@ -20,21 +22,17 @@ public:
*/
virtual void rf_unregister() = 0;
/** Read the mac address of this physical interface
/** Register this physical interface with Nanostack
*
* Note - some devices do not have a mac address
* in hardware.
* @return Device driver ID or a negative error
* code on failure
*/
virtual void get_mac_address(uint8_t *mac) = 0;
int8_t phy_register() { return rf_register();}
/** Set the mac address of this physical interface
/** Unregister this physical interface
*
*/
virtual void set_mac_address(uint8_t *mac) = 0;
protected:
NanostackRfPhy() {}
virtual ~NanostackRfPhy() {}
void unregister() { rf_unregister(); }
};
#endif /* NANOSTACK_INTERFACE_H_ */
#endif /* NANOSTACK_RF_PHY_H_ */