Skip to content

Commit

Permalink
nanostack: fix astyle coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
0xc0170 committed Nov 7, 2018
1 parent 884a774 commit 567eedc
Show file tree
Hide file tree
Showing 33 changed files with 846 additions and 781 deletions.
5 changes: 0 additions & 5 deletions CONTRIBUTING.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,35 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;

void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
void get_mac_address(uint8_t *buf) const
{
interface_phy.get_mac_address(buf);
}

/**
* \brief Callback from C-layer
* \param status state of the network
* */
void network_handler(mesh_connection_status_t status);

int8_t get_interface_id() const { return interface_id; }
int8_t get_driver_id() const { return _device_id; }
int8_t get_interface_id() const
{
return interface_id;
}
int8_t get_driver_id() const
{
return _device_id;
}

private:
NanostackPhy &interface_phy;
protected:
Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy();
NanostackPhy &get_phy() const { return interface_phy; }
NanostackPhy &get_phy() const
{
return interface_phy;
}
int8_t interface_id;
int8_t _device_id;
rtos::Semaphore connect_semaphore;
Expand All @@ -62,7 +74,10 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
class Nanostack::MeshInterface : public Nanostack::Interface {
protected:
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
NanostackRfPhy &get_phy() const
{
return static_cast<NanostackRfPhy &>(Interface::get_phy());
}
};


Expand Down Expand Up @@ -116,12 +131,18 @@ class InterfaceNanostack : public virtual NetworkInterface {
/** Get the interface ID
/return Interface identifier
*/
int8_t get_interface_id() const { return _interface->get_interface_id(); }
int8_t get_interface_id() const
{
return _interface->get_interface_id();
}

protected:
InterfaceNanostack();
virtual Nanostack *get_stack(void);
Nanostack::Interface *get_interface() const { return _interface; }
Nanostack::Interface *get_interface() const
{
return _interface;
}
virtual nsapi_error_t do_initialize() = 0;

Nanostack::Interface *_interface;
Expand All @@ -147,7 +168,10 @@ class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface,
protected:
MeshInterfaceNanostack() : _phy(NULL) { }
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
Nanostack::MeshInterface *get_interface() const
{
return static_cast<Nanostack::MeshInterface *>(_interface);
}
NanostackRfPhy *_phy;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Nanostack::EthernetInterface : public Nanostack::Interface {
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
nsapi_error_t initialize();
protected:
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
NanostackEthernetPhy &get_phy() const
{
return static_cast<NanostackEthernetPhy &>(Interface::get_phy());
}
};

/** Ethernet interface for Nanostack.
Expand All @@ -50,7 +53,10 @@ class NanostackEthernetInterface : public InterfaceNanostack, public EthInterfac
nsapi_error_t initialize(NanostackEthernetPhy *phy);

protected:
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
Nanostack::EthernetInterface *get_interface() const
{
return static_cast<Nanostack::EthernetInterface *>(_interface);
}
virtual nsapi_error_t do_initialize();

};
Expand Down
5 changes: 2 additions & 3 deletions features/nanostack/mbed-mesh-api/source/LoWPANNDInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nslp"

class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface
{
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
Expand All @@ -29,7 +28,7 @@ class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface

Nanostack::LoWPANNDInterface *LoWPANNDInterface::get_interface() const
{
return static_cast<Nanostack::LoWPANNDInterface*>(_interface);
return static_cast<Nanostack::LoWPANNDInterface *>(_interface);
}

nsapi_error_t LoWPANNDInterface::do_initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Nanostack::Interface::attach(
}

Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interface_id(-1), _device_id(-1),
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
{
mesh_system_init();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
{
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
status == MESH_CONNECTED_GLOBAL) && _blocking) {
status == MESH_CONNECTED_GLOBAL) && _blocking) {
connect_semaphore.release();
}

Expand All @@ -131,10 +131,10 @@ void Nanostack::Interface::network_handler(mesh_connection_status_t status)
_connect_status = NSAPI_STATUS_LOCAL_UP;
}
if (arm_net_address_get(interface_id, ADDR_IPV6_GP, temp_ipv6_global) == 0
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
&& (memcmp(temp_ipv6_global, temp_ipv6_local, 16) != 0)) {
_connect_status = NSAPI_STATUS_GLOBAL_UP;
}
} else if (status == MESH_CONNECTED_LOCAL ) {
} else if (status == MESH_CONNECTED_LOCAL) {
_connect_status = NSAPI_STATUS_LOCAL_UP;
} else if (status == MESH_CONNECTED_GLOBAL) {
_connect_status = NSAPI_STATUS_GLOBAL_UP;
Expand Down
113 changes: 56 additions & 57 deletions features/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
#include "arm_hal_phy.h"
#include "EMAC.h"

class EMACPhy : public NanostackEthernetPhy
{
class EMACPhy : public NanostackEthernetPhy {
public:
EMACPhy(NanostackMemoryManager &mem, EMAC &m);
virtual int8_t phy_register();
virtual void get_mac_address(uint8_t *mac);
virtual void set_mac_address(uint8_t *mac);

int8_t address_write(phy_address_type_e , uint8_t *);
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow);
int8_t address_write(phy_address_type_e, uint8_t *);
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);

void emac_phy_rx(emac_mem_buf_t *mem);

Expand All @@ -34,65 +33,65 @@ static EMACPhy *single_phy;

extern "C"
{
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
{
return single_phy->address_write(address_type, address_ptr);
}
static int8_t emac_phy_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
{
return single_phy->address_write(address_type, address_ptr);
}

static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
{
return -1;
}
static int8_t emac_phy_interface_state_control(phy_interface_state_e, uint8_t)
{
return -1;
}

static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
{
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
}
static int8_t emac_phy_tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
{
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
}

EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
{
/* Same default address logic as lwIP glue uses */
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1)
{
/* Same default address logic as lwIP glue uses */
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
mac_addr[0] = MBED_MAC_ADDR_0;
mac_addr[1] = MBED_MAC_ADDR_1;
mac_addr[2] = MBED_MAC_ADDR_2;
mac_addr[3] = MBED_MAC_ADDR_3;
mac_addr[4] = MBED_MAC_ADDR_4;
mac_addr[5] = MBED_MAC_ADDR_5;
mac_addr[0] = MBED_MAC_ADDR_0;
mac_addr[1] = MBED_MAC_ADDR_1;
mac_addr[2] = MBED_MAC_ADDR_2;
mac_addr[3] = MBED_MAC_ADDR_3;
mac_addr[4] = MBED_MAC_ADDR_4;
mac_addr[5] = MBED_MAC_ADDR_5;
#else
mbed_mac_address((char *) mac_addr);
mbed_mac_address((char *) mac_addr);
#endif
/* We have a default MAC address, so do don't force them to supply one */
/* They may or may not update hwaddr with their address */
emac.get_hwaddr(mac_addr);
}
/* We have a default MAC address, so do don't force them to supply one */
/* They may or may not update hwaddr with their address */
emac.get_hwaddr(mac_addr);
}


void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
{
const uint8_t *ptr = NULL;
uint8_t *tmpbuf = NULL;
uint32_t total_len;

if (memory_manager.get_next(mem) == NULL) {
// Easy contiguous case
ptr = static_cast<const uint8_t*>(memory_manager.get_ptr(mem));
total_len = memory_manager.get_len(mem);
} else {
// Nanostack can't accept chunked data - make temporary contiguous copy
total_len = memory_manager.get_total_len(mem);
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
if (tmpbuf) {
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
void EMACPhy::emac_phy_rx(emac_mem_buf_t *mem)
{
const uint8_t *ptr = NULL;
uint8_t *tmpbuf = NULL;
uint32_t total_len;

if (memory_manager.get_next(mem) == NULL) {
// Easy contiguous case
ptr = static_cast<const uint8_t *>(memory_manager.get_ptr(mem));
total_len = memory_manager.get_len(mem);
} else {
// Nanostack can't accept chunked data - make temporary contiguous copy
total_len = memory_manager.get_total_len(mem);
ptr = tmpbuf = static_cast<uint8_t *>(ns_dyn_mem_temporary_alloc(total_len));
if (tmpbuf) {
memory_manager.copy_from_buf(tmpbuf, total_len, mem);
}
}
}

if (ptr && phy.phy_rx_cb) {
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
if (ptr && phy.phy_rx_cb) {
phy.phy_rx_cb(ptr, total_len, 0xff, 0, device_id);
}
ns_dyn_mem_free(tmpbuf);
memory_manager.free(mem);
}
ns_dyn_mem_free(tmpbuf);
memory_manager.free(mem);
}

} // extern "C"

Expand All @@ -106,7 +105,7 @@ int8_t EMACPhy::address_write(phy_address_type_e address_type, uint8_t *address_
return 0;
}

int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle,data_protocol_e data_flow)
int8_t EMACPhy::tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow)
{
emac_mem_buf_t *mem = memory_manager.alloc_pool(data_len, 0);
if (!mem) {
Expand All @@ -126,7 +125,7 @@ int8_t EMACPhy::phy_register()

phy.PHY_MAC = mac_addr;
phy.address_write = emac_phy_address_write;
phy.driver_description = const_cast<char*>("ETH");
phy.driver_description = const_cast<char *>("ETH");
phy.link_type = PHY_LINK_ETHERNET_TYPE;
phy.phy_MTU = 0;
phy.phy_header_length = 0;
Expand All @@ -153,9 +152,9 @@ int8_t EMACPhy::phy_register()
emac.set_all_multicast(true);

device_id = arm_net_phy_register(&phy);
// driver_readiness_status_callback = driver_status_cb;
// driver_readiness_status_callback = driver_status_cb;

if (device_id < 0){
if (device_id < 0) {
//tr_error("Ethernet Driver failed to register with Stack. RetCode=%i", eth_driver_enabled);
//driver_readiness_status_callback(0, eth_interface_id);
emac.power_down();
Expand Down Expand Up @@ -188,7 +187,7 @@ nsapi_error_t Nanostack::add_ethernet_interface(EMAC &emac, bool default_if, Nan
}

if (mac_addr) {
single_phy->set_mac_address(const_cast<uint8_t*>(mac_addr));
single_phy->set_mac_address(const_cast<uint8_t *>(mac_addr));
}

Nanostack::EthernetInterface *interface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ nsapi_error_t NanostackEthernetInterface::initialize(NanostackEthernetPhy *phy)
}

return get_interface()->initialize();
}
}

nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack, bool blocking)
const char *netmask, const char *gw,
nsapi_ip_stack_t stack, bool blocking)
{
if (stack == IPV4_STACK) {
return NSAPI_ERROR_UNSUPPORTED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include "mbed_assert.h"
#include "NanostackMemoryManager.h"

struct ns_stack_mem_t
{
struct ns_stack_mem_t {
ns_stack_mem_t *next;
void *payload;
uint32_t len;
Expand Down
5 changes: 2 additions & 3 deletions features/nanostack/mbed-mesh-api/source/ThreadInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include "ns_trace.h"
#define TRACE_GROUP "nsth"

class Nanostack::ThreadInterface : public Nanostack::MeshInterface
{
class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
Expand Down Expand Up @@ -73,7 +72,7 @@ class Nanostack::ThreadInterface : public Nanostack::MeshInterface

Nanostack::ThreadInterface *ThreadInterface::get_interface() const
{
return static_cast<Nanostack::ThreadInterface*>(_interface);
return static_cast<Nanostack::ThreadInterface *>(_interface);
}

nsapi_error_t ThreadInterface::do_initialize()
Expand Down
Loading

0 comments on commit 567eedc

Please sign in to comment.