mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples/openthread: call OpenThread API using Event Queue
This commit is contained in:
parent
6b6eb1cbd8
commit
0037210c5e
@ -16,15 +16,37 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ot.h"
|
#include "ot.h"
|
||||||
|
#include "openthread/thread.h"
|
||||||
|
|
||||||
|
static void _panid_handler(event_t *event);
|
||||||
|
|
||||||
|
static event_t event_panid = {
|
||||||
|
.handler = _panid_handler
|
||||||
|
};
|
||||||
|
|
||||||
|
static void _panid_handler(event_t *event)
|
||||||
|
{
|
||||||
|
(void) event;
|
||||||
|
|
||||||
|
/* It's safe here to call any OpenThread specific API, since this code runs
|
||||||
|
* in the same thread as the OpenThread tasklet handler */
|
||||||
|
|
||||||
|
/* Get PanID from OpenThread API */
|
||||||
|
uint16_t panid = otLinkGetPanId(openthread_get_instance());
|
||||||
|
printf("Current panid: 0x%x\n", panid);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
puts("This a test for OpenThread");
|
|
||||||
/* Example of how to call OpenThread stack functions */
|
/* Example of how to call OpenThread stack functions */
|
||||||
puts("Get PANID ");
|
puts("This is an OpenThread example");
|
||||||
uint16_t panid = 0;
|
|
||||||
uint8_t res = ot_call_command("panid", NULL, (void*)&panid);
|
/** OpenThread needs to synchronize otApi calls
|
||||||
printf("Current panid: 0x%x (res:%x)\n", panid, res);
|
* with its tasklet scheduler. This
|
||||||
|
* synchronization is handled by RIOT using an
|
||||||
|
* event queue (accessible via openthread_get_evq())
|
||||||
|
*/
|
||||||
|
event_post(openthread_get_evq(), &event_panid);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user