Skip to content

Commit 7732adb

Browse files
author
Seppo Takalo
committed
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.
1 parent 6ba755e commit 7732adb

File tree

8 files changed

+71
-51
lines changed

8 files changed

+71
-51
lines changed

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/LoWPANNDInterface.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ class LoWPANNDInterface : public MeshInterfaceNanostack {
2626
*
2727
* Must initialize to initialize the mesh on a phy.
2828
*/
29-
LoWPANNDInterface() : MeshInterfaceNanostack() {
30-
31-
}
29+
LoWPANNDInterface() : MeshInterfaceNanostack() { }
3230

3331
/** Create an initialized MeshInterface
3432
*
3533
*/
36-
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
37-
38-
}
34+
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3935

36+
nsapi_error_t initialize(NanostackRfPhy *phy);
4037
int connect();
4138
int disconnect();
4239
bool getOwnIpAddress(char *address, int8_t len);

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MeshInterfaceNanostack : public MeshInterface {
3232
*
3333
* @return 0 on success, negative on failure
3434
*/
35-
virtual nsapi_error_t initialize(NanostackRfPhy *phy);
35+
virtual nsapi_error_t initialize(NanostackPhy *phy);
3636

3737
/** Start the interface
3838
*
@@ -64,27 +64,10 @@ class MeshInterfaceNanostack : public MeshInterface {
6464

6565
protected:
6666
MeshInterfaceNanostack();
67-
MeshInterfaceNanostack(NanostackRfPhy *phy);
68-
nsapi_error_t register_rf();
67+
MeshInterfaceNanostack(NanostackPhy *phy);
68+
nsapi_error_t register_phy();
6969
virtual NetworkStack * get_stack(void);
7070

71-
/**
72-
* \brief Connect interface to the mesh network
73-
* \return MESH_ERROR_NONE on success.
74-
* \return MESH_ERROR_PARAM in case of illegal parameters.
75-
* \return MESH_ERROR_MEMORY in case of memory error.
76-
* \return MESH_ERROR_STATE if interface is already connected to network.
77-
* \return MESH_ERROR_UNKNOWN in case of unspecified error.
78-
* */
79-
virtual mesh_error_t mesh_connect() = 0;
80-
81-
/**
82-
* \brief Disconnect interface from the mesh network
83-
* \return MESH_ERROR_NONE on success.
84-
* \return MESH_ERROR_UNKNOWN in case of error.
85-
* */
86-
virtual mesh_error_t mesh_disconnect() = 0;
87-
8871
/**
8972
* \brief Read own global IP address
9073
*
@@ -94,7 +77,7 @@ class MeshInterfaceNanostack : public MeshInterface {
9477
*/
9578
virtual bool getOwnIpAddress(char *address, int8_t len) = 0;
9679

97-
NanostackRfPhy *phy;
80+
NanostackPhy *phy;
9881
/** Network interface ID */
9982
int8_t _network_interface_id;
10083
/** Registered device ID */

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ class ThreadInterface : public MeshInterfaceNanostack {
2626
*
2727
* Must initialize to initialize the mesh on a phy.
2828
*/
29-
ThreadInterface() : MeshInterfaceNanostack() {
30-
31-
}
29+
ThreadInterface() : MeshInterfaceNanostack() { }
3230

3331
/** Create an initialized MeshInterface
3432
*
3533
*/
36-
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
37-
38-
}
34+
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3935

36+
nsapi_error_t initialize(NanostackRfPhy *phy);
4037
int connect();
4138
int disconnect();
4239
private:

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/LoWPANNDInterface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
#include "ns_trace.h"
88
#define TRACE_GROUP "nslp"
99

10+
nsapi_error_t LoWPANNDInterface::initialize(NanostackRfPhy *phy)
11+
{
12+
return MeshInterfaceNanostack::initialize(phy);
13+
}
14+
1015
int LoWPANNDInterface::connect()
1116
{
1217
nanostack_lock();
1318

14-
if (register_rf() < 0) {
19+
if (register_phy() < 0) {
1520
nanostack_unlock();
1621
return NSAPI_ERROR_DEVICE_ERROR;
1722
}

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/MeshInterfaceNanostack.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ MeshInterfaceNanostack::MeshInterfaceNanostack()
2525
// Nothing to do
2626
}
2727

28-
MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackRfPhy *phy)
28+
MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackPhy *phy)
2929
: phy(phy), _network_interface_id(-1), _device_id(-1), connect_semaphore(0)
3030
{
3131
// Nothing to do
3232
}
3333

34-
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
34+
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackPhy *phy)
3535
{
3636
mesh_system_init();
3737
if (this->phy != NULL) {
@@ -52,11 +52,11 @@ void MeshInterfaceNanostack::mesh_network_handler(mesh_connection_status_t statu
5252
nanostack_unlock();
5353
}
5454

55-
nsapi_error_t MeshInterfaceNanostack::register_rf()
55+
nsapi_error_t MeshInterfaceNanostack::register_phy()
5656
{
5757
nanostack_lock();
5858

59-
_device_id = phy->rf_register();
59+
_device_id = phy->phy_register();
6060
if (_device_id < 0) {
6161
nanostack_unlock();
6262
return -1;

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/ThreadInterface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
#include "ns_trace.h"
88
#define TRACE_GROUP "nsth"
99

10+
nsapi_error_t ThreadInterface::initialize(NanostackRfPhy *phy)
11+
{
12+
return MeshInterfaceNanostack::initialize(phy);
13+
}
14+
1015
int ThreadInterface::connect()
1116
{
1217
nanostack_lock();
1318

14-
if (register_rf() < 0) {
19+
if (register_phy() < 0) {
1520
nanostack_unlock();
1621
return NSAPI_ERROR_DEVICE_ERROR;
1722
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
*/
4+
5+
#ifndef NANOSTACK_PHY_H_
6+
#define NANOSTACK_PHY_H_
7+
8+
class NanostackPhy {
9+
public:
10+
11+
/** Register this physical interface with Nanostack
12+
*
13+
* @return Device driver ID or a negative error
14+
* code on failure
15+
*/
16+
virtual int8_t phy_register() = 0;
17+
18+
/** Read the mac address of this physical interface
19+
*
20+
* Note - some devices do not have a mac address
21+
* in hardware.
22+
*/
23+
virtual void get_mac_address(uint8_t *mac) = 0;
24+
25+
/** Set the mac address of this physical interface
26+
*
27+
*/
28+
virtual void set_mac_address(uint8_t *mac) = 0;
29+
30+
protected:
31+
NanostackPhy() {}
32+
virtual ~NanostackPhy() {}
33+
};
34+
35+
#endif /* NANOSTACK_INTERFACE_H_ */

features/nanostack/FEATURE_NANOSTACK/nanostack-interface/NanostackRfPhy.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#ifndef NANOSTACK_RF_PHY_H_
66
#define NANOSTACK_RF_PHY_H_
77

8-
class NanostackRfPhy {
8+
#include "NanostackPhy.h"
9+
10+
class NanostackRfPhy : public NanostackPhy {
911
public:
1012

1113
/** Register this physical interface with Nanostack
@@ -20,21 +22,17 @@ class NanostackRfPhy {
2022
*/
2123
virtual void rf_unregister() = 0;
2224

23-
/** Read the mac address of this physical interface
25+
/** Register this physical interface with Nanostack
2426
*
25-
* Note - some devices do not have a mac address
26-
* in hardware.
27+
* @return Device driver ID or a negative error
28+
* code on failure
2729
*/
28-
virtual void get_mac_address(uint8_t *mac) = 0;
30+
int8_t phy_register() { return rf_register();}
2931

30-
/** Set the mac address of this physical interface
32+
/** Unregister this physical interface
3133
*
3234
*/
33-
virtual void set_mac_address(uint8_t *mac) = 0;
34-
35-
protected:
36-
NanostackRfPhy() {}
37-
virtual ~NanostackRfPhy() {}
35+
void unregister() { rf_unregister(); }
3836
};
3937

40-
#endif /* NANOSTACK_INTERFACE_H_ */
38+
#endif /* NANOSTACK_RF_PHY_H_ */

0 commit comments

Comments
 (0)