mirror of
https://github.com/espressif/openthread.git
synced 2026-07-23 20:44:07 +00:00
[posix-app] add option to print version of radio spinel (#3205)
This commit is contained in:
+8
-11
@@ -60,7 +60,7 @@ void otTaskletsSignalPending(otInstance *aInstance)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
otInstance *sInstance;
|
||||
otInstance *instance;
|
||||
|
||||
if (setjmp(gResetJump))
|
||||
{
|
||||
@@ -71,28 +71,25 @@ int main(int argc, char *argv[])
|
||||
execvp(argv[0], argv);
|
||||
}
|
||||
|
||||
otSysInit(argc, argv);
|
||||
|
||||
sInstance = otInstanceInitSingle();
|
||||
assert(sInstance);
|
||||
instance = otSysInit(argc, argv);
|
||||
|
||||
#if OPENTHREAD_POSIX_APP == OPENTHREAD_POSIX_APP_NCP
|
||||
otNcpInit(sInstance);
|
||||
otNcpInit(instance);
|
||||
#elif OPENTHREAD_POSIX_APP == OPENTHREAD_POSIX_APP_CLI
|
||||
otCliUartInit(sInstance);
|
||||
otCliUartInit(instance);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
otDiagInit(sInstance);
|
||||
otDiagInit(instance);
|
||||
#endif
|
||||
|
||||
while (true)
|
||||
{
|
||||
otTaskletsProcess(sInstance);
|
||||
otSysProcessDrivers(sInstance);
|
||||
otTaskletsProcess(instance);
|
||||
otSysProcessDrivers(instance);
|
||||
}
|
||||
|
||||
otInstanceFinalize(sInstance);
|
||||
otInstanceFinalize(instance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,10 @@ extern "C" {
|
||||
* @param[in] argc Number of arguments in @p argv.
|
||||
* @param[in] argv Argument vector.
|
||||
*
|
||||
* @returns A pointer to the OpenThread instance.
|
||||
*
|
||||
*/
|
||||
void otSysInit(int argc, char *argv[]);
|
||||
otInstance *otSysInit(int argc, char *argv[]);
|
||||
|
||||
/**
|
||||
* This function performs all platform-specific deinitialization for OpenThread's drivers.
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
#include <openthread/tasklet.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
uint64_t gNodeId = 0;
|
||||
|
||||
@@ -55,29 +56,34 @@ static void PrintUsage(const char *aProgramName, FILE *aStream, int aExitCode)
|
||||
"Syntax:\n"
|
||||
" %s [Options] NodeId|Device|Command [DeviceConfig|CommandArgs]\n"
|
||||
"Options:\n"
|
||||
" -s --time-speed factor Time speed up factor.\n"
|
||||
" -n --dry-run Just verify if arguments is valid and radio spinel is compatible.\n"
|
||||
" --radio-version Print radio firmware version\n"
|
||||
" -s --time-speed factor Time speed up factor.\n"
|
||||
" -h --help Display this usage information.\n",
|
||||
aProgramName);
|
||||
exit(aExitCode);
|
||||
}
|
||||
|
||||
void otSysInit(int aArgCount, char *aArgVector[])
|
||||
otInstance *otSysInit(int aArgCount, char *aArgVector[])
|
||||
{
|
||||
uint32_t speedUpFactor = 1;
|
||||
bool isDryRun = false;
|
||||
const char *radioFile = NULL;
|
||||
const char *radioConfig = "";
|
||||
const char *radioFile = NULL;
|
||||
const char *radioConfig = "";
|
||||
otInstance *instance = NULL;
|
||||
uint32_t speedUpFactor = 1;
|
||||
bool isDryRun = false;
|
||||
bool printRadioVersion = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
int index = 0;
|
||||
int option;
|
||||
const struct option options[] = {{"dry-run", no_argument, NULL, 'n'},
|
||||
{"radio-version", no_argument, NULL, 0},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"time-speed", required_argument, NULL, 's'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
option = getopt_long(aArgCount, aArgVector, "hns:", options, NULL);
|
||||
option = getopt_long(aArgCount, aArgVector, "hns:", options, &index);
|
||||
|
||||
if (option == -1)
|
||||
{
|
||||
@@ -104,6 +110,12 @@ void otSysInit(int aArgCount, char *aArgVector[])
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
if (!strcmp(options[index].name, "radio-version"))
|
||||
{
|
||||
printRadioVersion = true;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
PrintUsage(aArgVector[0], stderr, OT_EXIT_INVALID_ARGUMENTS);
|
||||
break;
|
||||
@@ -136,10 +148,20 @@ void otSysInit(int aArgCount, char *aArgVector[])
|
||||
platformUdpInit();
|
||||
#endif
|
||||
|
||||
instance = otInstanceInitSingle();
|
||||
assert(instance);
|
||||
|
||||
if (printRadioVersion)
|
||||
{
|
||||
printf("%s\n", otPlatRadioGetVersionString(instance));
|
||||
}
|
||||
|
||||
if (isDryRun)
|
||||
{
|
||||
exit(OT_EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void otSysDeinit(void)
|
||||
|
||||
Reference in New Issue
Block a user