mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 04:37:47 +00:00
[posix-app] rename global variable to gNodeId (#3118)
This commit renames `NODE_ID` to `gNodeId` in posix app and posix platform example code. It also ensures to use correct encoding (byte order) to calculate the `gNodeId` (as `uint64_t`) in posix app.
This commit is contained in:
committed by
Jonathan Hui
parent
67f3880165
commit
ad3ea71c59
@@ -71,7 +71,7 @@ otError utilsFlashInit(void)
|
||||
offset = "0";
|
||||
}
|
||||
|
||||
snprintf(fileName, sizeof(fileName), "%s/%s_%d.flash", path, offset, NODE_ID);
|
||||
snprintf(fileName, sizeof(fileName), "%s/%s_%d.flash", path, offset, gNodeId);
|
||||
|
||||
if (access(fileName, 0))
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const
|
||||
|
||||
offset = 0;
|
||||
|
||||
LOG_PRINTF("[%d] ", NODE_ID);
|
||||
LOG_PRINTF("[%d] ", gNodeId);
|
||||
|
||||
va_start(args, aFormat);
|
||||
charsWritten = vsnprintf(&logString[offset], sizeof(logString) - offset, aFormat, args);
|
||||
|
||||
@@ -102,17 +102,16 @@ struct Event
|
||||
uint8_t mData[OT_EVENT_DATA_MAX_SIZE];
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
enum
|
||||
{
|
||||
WELLKNOWN_NODE_ID = 34, ///< Well-known Unique ID used by a simulated radio that supports promiscuous mode.
|
||||
};
|
||||
|
||||
/**
|
||||
* Unique node ID.
|
||||
*
|
||||
*/
|
||||
extern uint32_t NODE_ID;
|
||||
|
||||
/**
|
||||
* Well-known Unique ID used by a simulated radio that supports promiscuous mode.
|
||||
*
|
||||
*/
|
||||
extern uint32_t WELLKNOWN_NODE_ID;
|
||||
extern uint32_t gNodeId;
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
|
||||
@@ -345,10 +345,10 @@ void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
aIeeeEui64[1] = 0xb4;
|
||||
aIeeeEui64[2] = 0x30;
|
||||
aIeeeEui64[3] = 0x00;
|
||||
aIeeeEui64[4] = (NODE_ID >> 24) & 0xff;
|
||||
aIeeeEui64[5] = (NODE_ID >> 16) & 0xff;
|
||||
aIeeeEui64[6] = (NODE_ID >> 8) & 0xff;
|
||||
aIeeeEui64[7] = NODE_ID & 0xff;
|
||||
aIeeeEui64[4] = (gNodeId >> 24) & 0xff;
|
||||
aIeeeEui64[5] = (gNodeId >> 16) & 0xff;
|
||||
aIeeeEui64[6] = (gNodeId >> 8) & 0xff;
|
||||
aIeeeEui64[7] = gNodeId & 0xff;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
@@ -409,7 +409,7 @@ void platformRadioInit(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
sockaddr.sin_port = htons(9000 + sPortOffset + NODE_ID);
|
||||
sockaddr.sin_port = htons(9000 + sPortOffset + gNodeId);
|
||||
}
|
||||
|
||||
sockaddr.sin_addr.s_addr = INADDR_ANY;
|
||||
@@ -728,7 +728,7 @@ void radioTransmit(struct RadioMessage *aMessage, const struct otRadioFrame *aFr
|
||||
{
|
||||
ssize_t rval;
|
||||
|
||||
if (NODE_ID == i)
|
||||
if (gNodeId == i)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ void platformRandomInit(void)
|
||||
|
||||
#else // __SANITIZE_ADDRESS__
|
||||
|
||||
// Multiplying NODE_ID assures that no two nodes gets the same seed within an hour.
|
||||
sState = (uint32_t)time(NULL) + (3600 * NODE_ID);
|
||||
// Multiplying gNodeId assures that no two nodes gets the same seed within an hour.
|
||||
sState = (uint32_t)time(NULL) + (3600 * gNodeId);
|
||||
|
||||
#endif // __SANITIZE_ADDRESS__
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/uart.h>
|
||||
|
||||
uint32_t NODE_ID = 1;
|
||||
uint32_t WELLKNOWN_NODE_ID = 34;
|
||||
uint32_t gNodeId = 1;
|
||||
|
||||
extern bool gPlatformPseudoResetWasRequested;
|
||||
static volatile bool gTerminate = false;
|
||||
@@ -191,7 +190,7 @@ static void socket_init(void)
|
||||
sPortOffset *= WELLKNOWN_NODE_ID;
|
||||
}
|
||||
|
||||
sockaddr.sin_port = htons(9000 + sPortOffset + NODE_ID);
|
||||
sockaddr.sin_port = htons(9000 + sPortOffset + gNodeId);
|
||||
sockaddr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
sSockFd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
@@ -230,11 +229,11 @@ void otSysInit(int argc, char *argv[])
|
||||
gArgumentsCount = argc;
|
||||
gArguments = argv;
|
||||
|
||||
NODE_ID = (uint32_t)strtol(argv[1], &endptr, 0);
|
||||
gNodeId = (uint32_t)strtol(argv[1], &endptr, 0);
|
||||
|
||||
if (*endptr != '\0' || NODE_ID < 1 || NODE_ID >= WELLKNOWN_NODE_ID)
|
||||
if (*endptr != '\0' || gNodeId < 1 || gNodeId >= WELLKNOWN_NODE_ID)
|
||||
{
|
||||
fprintf(stderr, "Invalid NODE_ID: %s\n", argv[1]);
|
||||
fprintf(stderr, "Invalid NodeId: %s\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,10 +333,10 @@ void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
aIeeeEui64[1] = 0xb4;
|
||||
aIeeeEui64[2] = 0x30;
|
||||
aIeeeEui64[3] = 0x00;
|
||||
aIeeeEui64[4] = (NODE_ID >> 24) & 0xff;
|
||||
aIeeeEui64[5] = (NODE_ID >> 16) & 0xff;
|
||||
aIeeeEui64[6] = (NODE_ID >> 8) & 0xff;
|
||||
aIeeeEui64[7] = NODE_ID & 0xff;
|
||||
aIeeeEui64[4] = (gNodeId >> 24) & 0xff;
|
||||
aIeeeEui64[5] = (gNodeId >> 16) & 0xff;
|
||||
aIeeeEui64[6] = (gNodeId >> 8) & 0xff;
|
||||
aIeeeEui64[7] = gNodeId & 0xff;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
|
||||
@@ -51,8 +51,7 @@
|
||||
#include <openthread/tasklet.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
|
||||
uint32_t NODE_ID = 1;
|
||||
uint32_t WELLKNOWN_NODE_ID = 34;
|
||||
uint32_t gNodeId = 1;
|
||||
|
||||
extern bool gPlatformPseudoResetWasRequested;
|
||||
|
||||
@@ -91,9 +90,9 @@ void otSysInit(int aArgCount, char *aArgVector[])
|
||||
signal(SIGHUP, &handleSignal);
|
||||
#endif
|
||||
|
||||
NODE_ID = (uint32_t)strtol(aArgVector[1], &endptr, 0);
|
||||
gNodeId = (uint32_t)strtol(aArgVector[1], &endptr, 0);
|
||||
|
||||
if (*endptr != '\0' || NODE_ID < 1 || NODE_ID >= WELLKNOWN_NODE_ID)
|
||||
if (*endptr != '\0' || gNodeId < 1 || gNodeId >= WELLKNOWN_NODE_ID)
|
||||
{
|
||||
fprintf(stderr, "Invalid NodeId: %s\n", aArgVector[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -73,7 +73,7 @@ otError utilsFlashInit(void)
|
||||
offset = "0";
|
||||
}
|
||||
|
||||
snprintf(fileName, sizeof(fileName), "%s/%s_%" PRIx64 ".flash", path, offset, NODE_ID);
|
||||
snprintf(fileName, sizeof(fileName), "%s/%s_%" PRIx64 ".flash", path, offset, gNodeId);
|
||||
|
||||
if (access(fileName, 0))
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const
|
||||
|
||||
offset = 0;
|
||||
|
||||
charsWritten = snprintf(&logString[offset], sizeof(logString), "[%" PRIx64 "] ", NODE_ID);
|
||||
charsWritten = snprintf(&logString[offset], sizeof(logString), "[%" PRIx64 "] ", gNodeId);
|
||||
otEXPECT_ACTION(charsWritten >= 0, logString[offset] = 0);
|
||||
offset += (unsigned int)charsWritten;
|
||||
otEXPECT_ACTION(offset < sizeof(logString), logString[sizeof(logString) - 1] = 0);
|
||||
|
||||
@@ -84,13 +84,7 @@ struct Event
|
||||
* Unique node ID.
|
||||
*
|
||||
*/
|
||||
extern uint64_t NODE_ID;
|
||||
|
||||
/**
|
||||
* Well-known Unique ID used by a simulated radio that supports promiscuous mode.
|
||||
*
|
||||
*/
|
||||
#define WELLKNOWN_NODE_ID 34
|
||||
extern uint64_t gNodeId;
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <common/encoding.hpp>
|
||||
#include <common/logging.hpp>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
@@ -402,7 +403,9 @@ void RadioSpinel::Init(const char *aRadioFile, const char *aRadioConfig)
|
||||
|
||||
SuccessOrExit(error = WaitResponse());
|
||||
VerifyOrExit(mIsReady, error = OT_ERROR_FAILED);
|
||||
SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_UINT64_S, &NODE_ID));
|
||||
|
||||
SuccessOrExit(error = Get(SPINEL_PROP_HWADDR, SPINEL_DATATYPE_UINT64_S, &gNodeId));
|
||||
gNodeId = ot::Encoding::BigEndian::HostSwap64(gNodeId);
|
||||
|
||||
{
|
||||
unsigned int caps;
|
||||
|
||||
@@ -54,8 +54,8 @@ void platformRandomInit(void)
|
||||
|
||||
#else // __SANITIZE_ADDRESS__
|
||||
|
||||
// Multiplying NODE_ID assures that no two nodes gets the same seed within an hour.
|
||||
sState = (uint32_t)time(NULL) + (3600 * NODE_ID);
|
||||
// Multiplying gNodeId assures that no two nodes gets the same seed within an hour.
|
||||
sState = (uint32_t)time(NULL) + (3600 * gNodeId);
|
||||
|
||||
#endif // __SANITIZE_ADDRESS__
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@
|
||||
|
||||
#if OPENTHREAD_POSIX_VIRTUAL_TIME
|
||||
|
||||
static const int kBasePort = 18000; ///< This base port for posix app simulation.
|
||||
static const int kUsPerSecond = 1000000; ///< Number of microseconds per second.
|
||||
static const int kWellKnownNodeId = 34; ///< Well-known ID used by a simulated radio supporting promiscuous mode.
|
||||
static const int kBasePort = 18000; ///< This base port for posix app simulation.
|
||||
static const int kUsPerSecond = 1000000; ///< Number of microseconds per second.
|
||||
|
||||
static uint64_t sNow = 0; ///< Time of simulation.
|
||||
static int sSockFd = -1; ///< Socket used to communicating with simulator.
|
||||
@@ -69,7 +70,7 @@ void otSimInit(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sPortOffset *= WELLKNOWN_NODE_ID;
|
||||
sPortOffset *= kWellKnownNodeId;
|
||||
}
|
||||
|
||||
// node id is required for virtual time simulation
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <openthread/tasklet.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
|
||||
uint64_t NODE_ID = 0;
|
||||
uint64_t gNodeId = 0;
|
||||
|
||||
extern bool gPlatformPseudoResetWasRequested;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user