1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #15664 from jia200x/pr/openthread/deprecate_jobs

pkg/openthread: deprecate ot_command related functions
This commit is contained in:
Kevin "Tristate Tom" Weiss 2021-06-14 16:44:35 +02:00 committed by GitHub
commit adf228ae7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 12 deletions

View File

@ -16,15 +16,37 @@
#include <stdio.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)
{
puts("This a test for OpenThread");
/* Example of how to call OpenThread stack functions */
puts("Get PANID ");
uint16_t panid = 0;
uint8_t res = ot_call_command("panid", NULL, (void*)&panid);
printf("Current panid: 0x%x (res:%x)\n", panid, res);
puts("This is an OpenThread example");
/** OpenThread needs to synchronize otApi calls
* 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;
}

View File

@ -13,6 +13,35 @@
* @see https://github.com/openthread/openthread
*
* Thread is a mesh oriented network stack running for IEEE802.15.4 networks.
*
* The RIOT port allows to directly call OpenThread API functions using
* @ref sys_event. For example:
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {.c}
* #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;
* uint16_t panid = otLinkGetPanId(openthread_get_instance());
* do_something_with_panid(panid);
* }
*
* int main(void)
* {
* event_post(openthread_get_evq(), &event_panid);
* return 0;
* }
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* @see https://openthread.io/releases/thread-reference-20180619
*
* @{
*
* @file
@ -73,6 +102,10 @@ typedef struct {
/**
* @brief Struct containing an OpenThread job
*
* @deprecated This structure is not needed anymore since it's possible to
* run OpenThread code via @ref sys_event (see @ref openthread_get_evq).
* Therefore it will be removed after the 2022.01 release.
*/
typedef struct {
event_t ev; /**< Event associated to the OpenThread job */
@ -142,13 +175,6 @@ void openthread_radio_init(netdev_t *dev, uint8_t *tb, uint8_t *rb);
*/
int openthread_netdev_init(char *stack, int stacksize, char priority, const char *name, netdev_t *netdev);
/**
* @brief get PID of OpenThread thread.
*
* @return PID of OpenThread thread
*/
kernel_pid_t openthread_get_pid(void);
/**
* @brief Init OpenThread random
*/
@ -157,6 +183,10 @@ void ot_random_init(void);
/**
* @brief Execute OpenThread command. Call this function only in OpenThread thread
*
* @deprecated This function is not needed anymore since it's possible to
* run OpenThread code via @ref sys_event (see @ref openthread_get_evq).
* Therefore it will be removed after the 2022.01 release.
*
* @param[in] ot_instance OpenThread instance
* @param[in] command OpenThread command name
* @param[in] arg arg for the command
@ -172,6 +202,10 @@ uint8_t ot_exec_command(otInstance *ot_instance, const char* command, void *arg,
* @note An OpenThread command allows direct calls to OpenThread API (otXXX functions) without worrying about concurrency
* issues. All API calls should be made in OT_JOB type functions.
*
* @deprecated This function is not needed anymore since it's possible to
* run OpenThread code via @ref sys_event (see @ref openthread_get_evq).
* Therefore it will be removed after the 2022.01 release.
*
* @param[in] command name of the command to call
* @param[in] arg arg for the command
* @param[out] answer answer for the command