-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg/wakaama: add on off switch #21109
base: master
Are you sure you want to change the base?
pkg/wakaama: add on off switch #21109
Conversation
3621c59
to
2254a35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👁️ 👁️
@@ -159,6 +172,25 @@ static int _parse_lwm2m_light_cmd(int argc, char **argv) | |||
return 0; | |||
} | |||
|
|||
static int _parse_lwm2m_switch_cmd(int argc, char **argv) | |||
{ | |||
if (argc < 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (argc < 3) { | |
if (argc != 3) { |
Or, if the <on|off> is optional (in which case the follow up printf should be changed to [on|off]
imo)
if (argc < 3) { | |
if ((argc != 3) && (argc != 2)) { |
return 0; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: whitespace
bool status; /**< digital input status */ | ||
uint32_t counter; /**< counter for the digital input */ | ||
ztimer_stopwatch_t stopwatch; /**< stopwatch for time periods */ | ||
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool status; /**< digital input status */ | |
uint32_t counter; /**< counter for the digital input */ | |
ztimer_stopwatch_t stopwatch; /**< stopwatch for time periods */ | |
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */ | |
bool status; /**< wether the switch is on or off */ | |
uint32_t counter; /**< how often the switch was flipped */ | |
ztimer_stopwatch_t stopwatch; /**< ??? How long the switch was on ? */ | |
char app_type[CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE]; /**< application type */ |
* @return COAP_404_NOT_FOUND if the instance was not found | ||
* @return COAP_500_INTERNAL_SERVER_ERROR otherwise | ||
*/ | ||
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It bugs me that the return type is uint8_t
instead of e.g. lwm2m_cb_result_t
. But I don't think it is up to you to change?
static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, | ||
lwm2m_data_t ** data_array, lwm2m_object_t * object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How sure are you that the pointer, in this cb and the write_cb, can not be NULL
? If you have doubt, please add asserts or additional checks.
break; | ||
} | ||
|
||
case LWM2M_ON_OFF_SWITCH_APP_TYPE_ID: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify to me why we have this functionality here and lower in the lwm2m_object_on_off_switch_update_app_type()
? It's not a drop-in replacement due to the mutex tho.
} | ||
|
||
for (int i = 0; i < num_data && result == COAP_204_CHANGED; i++) { | ||
switch (data_array[i].id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no default case. Does it matter?
client_data = (lwm2m_client_data_t *)_on_off_switch_object.wakaama_object.userData; | ||
lwm2m_resource_value_changed(client_data->lwm2m_ctx, &uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client_data
might be NULL
!
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data) | ||
{ | ||
/* initialize the instances */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data) | |
{ | |
/* initialize the instances */ | |
lwm2m_object_t *lwm2m_object_on_off_switch_init(lwm2m_client_data_t *client_data) | |
{ | |
assert(client_data); | |
/* initialize the instances */ |
Alternatively, ensure all code can handle NULL
in the field.
/* if app is specified, copy locally */ | ||
if (args->app_type) { | ||
if (args->app_type_len > CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE) { | ||
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string\n"); | |
DEBUG("[lwm2m:on_off_switch]: not enough space for app_type string, got %d but max is %d\n", args->app_type_len, CONFIG_LWM2M_ON_OFF_SWITCH_APP_TYPE_MAX_SIZE -1); |
Contribution description
This adds a simple on/off switch object to the supported LwM2M objects: Object 3342. From the specs:
Testing procedure
Use the lwm2m example, the 'switch' can be controlled via shell.
Issues/PRs references
None