Improve OT_JOB + auto-init improved#4
Conversation
| msg_send(&ot_alarm_msg, thread_getpid()); | ||
| } | ||
| else { | ||
| int dt; |
|
|
||
| return !sDisabled; | ||
| netopt_state_t state = _get_state(); | ||
| if (state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) { |
There was a problem hiding this comment.
return !(state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) ?
There was a problem hiding this comment.
No I prefer to do it in 5 lines, it is more understandable
|
Looks good to me. Can you merge it @jia200x ? |
|
Good! What do you think? |
|
I see what you mean. Actually, it is useful because all OpenThread functions become available from any other thread and it will use the right OpenThread instance. However, we need an unlimited number of ARGS instead of one job context (context is arg?) |
|
I would have suggested to continue with RIOT concept and use I think OT_JOB needs to more flexible so any kind of function can be called. At the moment, only function like |
|
In fact, what you did in main.c is what we needed! It's kind of wrapper functions! |
|
In fact, there is a way to get the information back to the thread that call the OT_JOB: with context! It can be used for an arg or an answer. Good job @jia200x ! |
Thanks :). That was the idea behind OT_JOB. It's possible to pass args and read returns with the context variable (maybe this can be improved though). In the beginning I implemented IPC commands like netdev but I decided to go into the OT_JOB direction because ot API commands might change over time (also, it allows direct calls to otApi commands). |
|
@jia200x, tell me what you think about how I improved your OT_JOB |
…start thread protocol Address @aabadie comments Improve OT_JOB
|
Done, tell me what you think. |
|
Will do some comments |
| uint8_t ot_call_job(char* name, void *arg, void* answer) { | ||
| ot_job_t _job; | ||
|
|
||
| _job.function = job; |
| diagInit(sInstance); | ||
| #endif | ||
|
|
||
| /* Init default parameters */ |
There was a problem hiding this comment.
Stupid question: would it make sense to add these init calls in the openthread_bootstrap function ?
There was a problem hiding this comment.
In bootstrap, sInstance is not init so we can't
| typedef struct { | ||
| const char *mName; /**< A pointer to the job name string. */ | ||
| OT_JOB (*mFunction)(otInstance*, void*, void*); /**< function to be called when executing job */ | ||
| } ot_job_command_t; |
There was a problem hiding this comment.
why not simply use ot_command_t ?
There was a problem hiding this comment.
and rename OT_JOB to OT_COMMAND ?
| res = 1; | ||
| } | ||
| } else { | ||
| printf("ERROR: ot_exec_job needs to run in OpenThread thread\n"); |
| void output_bytes(const char* name, const uint8_t *aBytes, uint8_t aLength) | ||
| { | ||
| DEBUG("%s: ", name); | ||
| for (int i = 0; i < aLength; i++) |
| # If no BOARD is found in the environment, use this default: | ||
| BOARD ?= samr21-xpro | ||
|
|
||
| BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3 |
There was a problem hiding this comment.
would be great if we could add support to other 802.15.4 radios.
There was a problem hiding this comment.
Sure, let's merge this PR and people will add other 802.15.4 radios
tests/openthread/main.c
Outdated
| { | ||
| printf("Get PANID\n"); | ||
| uint16_t panid = 0; | ||
| uint8_t res = ot_call_job("panid", NULL, (void*)&panid); |
There was a problem hiding this comment.
I would prefer to rename ot_call_job to ot_call_command. It makes more sense to me and looks more intuitive.
|
Done @aabadie |
|
|
||
| _job.function = job; | ||
| _job.context = context; | ||
| uint8_t ot_call_command(char* name, void *arg, void* answer) { |
There was a problem hiding this comment.
maybe change name to command
| uint8_t ot_call_command(char* name, void *arg, void* answer) { | ||
| ot_job_t job; | ||
|
|
||
| job.mName = name; |
There was a problem hiding this comment.
since job is defined in RIOT contrib code, use attribute that matches the RIOT code style:
job.command, job.arg, job.answer
| * @brief Struct containing an OpenThread job command | ||
| */ | ||
| typedef struct { | ||
| const char *mName; /**< A pointer to the job name string. */ |
There was a problem hiding this comment.
use const char *name, align doxygen
|
|
||
| OT_COMMAND ot_eui64(otInstance* ot_instance, void* arg, void* answer) { | ||
| if (answer != NULL) { | ||
| otExtAddress extAddress; |
|
|
||
| OT_COMMAND ot_mode(otInstance* ot_instance, void* arg, void* answer) { | ||
| if (arg != NULL) { | ||
| otLinkModeConfig linkMode; |
There was a problem hiding this comment.
well, no leave it like this
|
Ok @aabadie, done |
|
Sorry for the late response, I was busy these days due to some IoT demos for the ITC (www.itcdigital.cl) @biboc thanks a lot for the adoption of OT_COMMANDs. Awesome work! |
|
if everything is OK, I will merge it. Let me know. Cheers! |
|
|
Great! |
|
Merged! |
The test randomly fails on `native` due to timers being not accurate but
it cannot be otherwise. So better disable it than raising fake errors.
main(): This is RIOT! (Version: buildtest)
Testing generic evtimer
This should list 2 items
ev #1 offset=1000
ev #2 offset=500
This should list 4 items
ev #1 offset=659
ev #2 offset=341
ev #3 offset=500
ev #4 offset=2454
Are the reception times of all 4 msgs close to the supposed values?
At 662 ms received msg 0: "#2 supposed to be 659"
At 1009 ms received msg 1: "#0 supposed to be 1000"
At 1511 ms received msg 2: "#1 supposed to be 1500"
Traceback (most recent call last):
File "/tmp/dwq.0.3125418833043728/ef3af88c4b3615788b164464a437df5c/tests/evtimer_msg/tests/01-run.py", line 33, in <module>
sys.exit(run(testfunc))
File "/tmp/dwq.0.3125418833043728/ef3af88c4b3615788b164464a437df5c/dist/pythonlibs/testrunner/__init__.py", line 29, in run
testfunc(child)
File "/tmp/dwq.0.3125418833043728/ef3af88c4b3615788b164464a437df5c/tests/evtimer_msg/tests/01-run.py", line 26, in testfunc
assert(actual in range(expected - ACCEPTED_ERROR, expected + ACCEPTED_ERROR))
AssertionError
18392: drivers/servo: reimplement with high level interface r=benpicco a=maribu ### Contribution description The previous servo driver didn't provide any benefit over using PWM directly, as users controlled the servo in terms of PWM duty cycles. This changes the interface to provide a high level interface that abstracts the gory PWM details. In addition, a SAUL layer and auto-initialization is provided. ### Testing procedure The test application provides access to the servo driver via the `saul` shell command. ``` > saul 2022-08-02 22:12:31,826 # saul 2022-08-02 22:12:31,827 # ID Class Name 2022-08-02 22:12:31,830 # #0 ACT_SWITCH LD1(green) 2022-08-02 22:12:31,832 # #1 ACT_SWITCH LD2(blue) 2022-08-02 22:12:31,834 # #2 ACT_SWITCH LD3(red) 2022-08-02 22:12:31,837 # #3 SENSE_BTN B1(User button) 2022-08-02 22:12:31,838 # #4 ACT_SERVO servo > saul write 4 0 2022-08-02 22:12:41,443 # saul write 4 0 2022-08-02 22:12:41,445 # Writing to device #4 - servo 2022-08-02 22:12:41,447 # Data: 0 2022-08-02 22:12:41,450 # [servo] setting 0 to 2949 (0 / 255) 2022-08-02 22:12:41,453 # data successfully written to device #4 > saul write 4 256 2022-08-02 22:12:45,343 # saul write 4 256 2022-08-02 22:12:45,346 # Writing to device #4 - servo 2022-08-02 22:12:45,347 # Data: 256 2022-08-02 22:12:45,351 # [servo] setting 0 to 6865 (255 / 255) 2022-08-02 22:12:45,354 # data successfully written to device #4 ``` Each write resulted in the MG90S servo that I connected to move to the corresponding position. ### Issues/PRs references Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
Remove OT_JOBAuto-init ifconfig with panid and channel (editable in Makefile) and start thread protocol
Address @aabadie comments