Allow ThreadInterface::device_eui64_get() before connect()

Perform necessary driver initialisation so that we can read
the EUI-64 before connecting.

Fixes #7391.
pull/7818/head
Kevin Bracey 2018-08-17 16:37:59 +03:00
parent 3a238bd7bd
commit e014104258
2 changed files with 19 additions and 5 deletions

View File

@ -102,15 +102,20 @@ int InterfaceNanostack::disconnect()
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy) nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
{ {
if (_phy) { if (_phy && phy && _phy != phy) {
error("Phy already set"); error("Phy already set");
return NSAPI_ERROR_IS_CONNECTED; return NSAPI_ERROR_IS_CONNECTED;
} }
_phy = phy; if (phy) {
return NSAPI_ERROR_OK; _phy = phy;
}
if (_phy) {
return do_initialize();
} else {
return NSAPI_ERROR_PARAMETER;
}
} }
void Nanostack::Interface::network_handler(mesh_connection_status_t status) void Nanostack::Interface::network_handler(mesh_connection_status_t status)
{ {
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL || if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
@ -148,7 +153,9 @@ nsapi_error_t Nanostack::Interface::register_phy()
{ {
NanostackLockGuard lock; NanostackLockGuard lock;
_device_id = interface_phy.phy_register(); if (_device_id < 0) {
_device_id = interface_phy.phy_register();
}
if (_device_id < 0) { if (_device_id < 0) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }

View File

@ -213,6 +213,10 @@ void ThreadInterface::device_eui64_set(const uint8_t *eui64)
void ThreadInterface::device_eui64_get(uint8_t *eui64) void ThreadInterface::device_eui64_get(uint8_t *eui64)
{ {
memset(eui64, 0, 8);
if (!get_interface()) {
return;
}
get_interface()->device_eui64_get(eui64); get_interface()->device_eui64_get(eui64);
} }
@ -226,6 +230,9 @@ void Nanostack::ThreadInterface::device_eui64_get(uint8_t *eui64)
{ {
if (!eui64_set) { if (!eui64_set) {
uint8_t eui64_buf[8]; uint8_t eui64_buf[8];
if (register_phy() < 0) {
return;
}
get_phy().get_mac_address(eui64_buf); get_phy().get_mac_address(eui64_buf);
device_eui64_set(eui64_buf); device_eui64_set(eui64_buf);
} }