Skip to content

Improve OT_JOB + auto-init improved#4

Merged
jia200x merged 4 commits intojia200x:openthread_corefrom
biboc:openthread-core-2
Jun 1, 2017
Merged

Improve OT_JOB + auto-init improved#4
jia200x merged 4 commits intojia200x:openthread_corefrom
biboc:openthread-core-2

Conversation

@biboc
Copy link
Copy Markdown

@biboc biboc commented May 29, 2017

Remove OT_JOB
Auto-init ifconfig with panid and channel (editable in Makefile) and start thread protocol
Address @aabadie comments

msg_send(&ot_alarm_msg, thread_getpid());
}
else {
int dt;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe int dt = aDt* ...

@biboc biboc force-pushed the openthread-core-2 branch from ec7ac90 to 1cbc34d Compare May 29, 2017 13:19

return !sDisabled;
netopt_state_t state = _get_state();
if (state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !(state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I prefer to do it in 5 lines, it is more understandable

@aabadie
Copy link
Copy Markdown
Collaborator

aabadie commented May 29, 2017

Looks good to me. Can you merge it @jia200x ?

@jia200x
Copy link
Copy Markdown
Owner

jia200x commented May 29, 2017

Good!
The only thing I'm not sure about if it's a good idea to remove the OT_JOB functions (as commented in the openthread_core PR)

What do you think?

@biboc
Copy link
Copy Markdown
Author

biboc commented May 29, 2017

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.
I thought it was only for netdev functions.
I mean, to change panid or any other setting, we have to use OpenThread function, I'll add an example in main.c, let me change my PR to see what I mean.

However, we need an unlimited number of ARGS instead of one job context (context is arg?)

@biboc
Copy link
Copy Markdown
Author

biboc commented May 29, 2017

I would have suggested to continue with RIOT concept and use gnrc_netapi_set/get functions to communicate with openthread stack but it will miss some functionalities so I understand why you suggested OT_JOB finally.

I think OT_JOB needs to more flexible so any kind of function can be called. At the moment, only function like (otInstance*, void*) can be called and no variable is returned so it is only for setter and printer.
If I need to know the channel in the thread main, I currently can't.

@biboc
Copy link
Copy Markdown
Author

biboc commented May 29, 2017

In fact, what you did in main.c is what we needed! It's kind of wrapper functions!
Let's move these function in openthread contrib folder.

@biboc
Copy link
Copy Markdown
Author

biboc commented May 29, 2017

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 !
I'll edit my PR

@jia200x
Copy link
Copy Markdown
Owner

jia200x commented May 29, 2017

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).

@biboc biboc force-pushed the openthread-core-2 branch from 1cbc34d to d2699ad Compare May 30, 2017 07:33
@biboc biboc changed the title Remove OT_JOB + auto-init improved Improve OT_JOB + auto-init improved May 30, 2017
@biboc
Copy link
Copy Markdown
Author

biboc commented May 30, 2017

@jia200x, tell me what you think about how I improved your OT_JOB
Btw, I'll do all command I think we need to access from RIOT (see in otJobs array)

…start thread protocol

Address @aabadie comments
Improve OT_JOB
@biboc biboc force-pushed the openthread-core-2 branch from d2699ad to e765b5c Compare May 30, 2017 14:58
@biboc
Copy link
Copy Markdown
Author

biboc commented May 30, 2017

Done, tell me what you think.
I tried all functions and they work. The only thing is that you need to be careful about the type of argument answer

@biboc biboc force-pushed the openthread-core-2 branch from 4a263c3 to c67ff4b Compare May 30, 2017 15:58
@biboc biboc force-pushed the openthread-core-2 branch from c67ff4b to 0b4334e Compare May 31, 2017 09:27
@biboc
Copy link
Copy Markdown
Author

biboc commented Jun 1, 2017

Guys? @jia200x @aabadie

@aabadie
Copy link
Copy Markdown
Collaborator

aabadie commented Jun 1, 2017

Will do some comments

Copy link
Copy Markdown
Collaborator

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good job @biboc. I have a few comments though. This goes into the right direction !

uint8_t ot_call_job(char* name, void *arg, void* answer) {
ot_job_t _job;

_job.function = job;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for an underscore

diagInit(sInstance);
#endif

/* Init default parameters */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid question: would it make sense to add these init calls in the openthread_bootstrap function ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bootstrap, sInstance is not init so we can't

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that's fine for now

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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply use ot_command_t ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and rename OT_JOB to OT_COMMAND ?

res = 1;
}
} else {
printf("ERROR: ot_exec_job needs to run in OpenThread thread\n");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DEBUG

void output_bytes(const char* name, const uint8_t *aBytes, uint8_t aLength)
{
DEBUG("%s: ", name);
for (int i = 0; i < aLength; i++)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for () {
[...]
}

# If no BOARD is found in the environment, use this default:
BOARD ?= samr21-xpro

BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great if we could add support to other 802.15.4 radios.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let's merge this PR and people will add other 802.15.4 radios

{
printf("Get PANID\n");
uint16_t panid = 0;
uint8_t res = ot_call_job("panid", NULL, (void*)&panid);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to rename ot_call_job to ot_call_command. It makes more sense to me and looks more intuitive.

@biboc
Copy link
Copy Markdown
Author

biboc commented Jun 1, 2017

Done @aabadie

@biboc biboc force-pushed the openthread-core-2 branch from b8ae9b1 to 69973ce Compare June 1, 2017 13:49

_job.function = job;
_job.context = context;
uint8_t ot_call_command(char* name, void *arg, void* answer) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change name to command

uint8_t ot_call_command(char* name, void *arg, void* answer) {
ot_job_t job;

job.mName = name;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use const char *name, align doxygen


OT_COMMAND ot_eui64(otInstance* ot_instance, void* arg, void* answer) {
if (answer != NULL) {
otExtAddress extAddress;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/extAddress/address/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (sorry)


OT_COMMAND ot_mode(otInstance* ot_instance, void* arg, void* answer) {
if (arg != NULL) {
otLinkModeConfig linkMode;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/linkMode/link_mode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, no leave it like this

@biboc biboc force-pushed the openthread-core-2 branch from 69973ce to 0256eff Compare June 1, 2017 14:01
@biboc
Copy link
Copy Markdown
Author

biboc commented Jun 1, 2017

Ok @aabadie, done
Your suggested changes make sense

@jia200x
Copy link
Copy Markdown
Owner

jia200x commented Jun 1, 2017

@biboc @aabadie Hi guys

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!

@jia200x
Copy link
Copy Markdown
Owner

jia200x commented Jun 1, 2017

if everything is OK, I will merge it. Let me know.

Cheers!

@aabadie
Copy link
Copy Markdown
Collaborator

aabadie commented Jun 1, 2017

if everything is OK, I will merge it. Let me know.
Yes, go ahead !

@biboc
Copy link
Copy Markdown
Author

biboc commented Jun 1, 2017

Great!

@jia200x jia200x merged commit fbea41a into jia200x:openthread_core Jun 1, 2017
@jia200x
Copy link
Copy Markdown
Owner

jia200x commented Jun 1, 2017

Merged!

jia200x pushed a commit that referenced this pull request Sep 30, 2019
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
jia200x pushed a commit that referenced this pull request Feb 23, 2023
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants