1 /*
2 * Copyright (c) 2022 Nordic Semiconductor
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #define LOG_MODULE_NAME app_timer
8 #include <zephyr/logging/log.h>
9 LOG_MODULE_REGISTER(LOG_MODULE_NAME);
10
11 #include "modules.h"
12
13 #include <zephyr/net/lwm2m.h>
14
15 #define TIMER_NAME "Test timer"
16
17 /* An example data validation callback. */
timer_on_off_validate_cb(uint16_t obj_inst_id,uint16_t res_id,uint16_t res_inst_id,uint8_t * data,uint16_t data_len,bool last_block,size_t total_size,size_t offset)18 static int timer_on_off_validate_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id,
19 uint8_t *data, uint16_t data_len, bool last_block,
20 size_t total_size, size_t offset)
21 {
22 LOG_INF("Validating On/Off data");
23
24 if (data_len != 1) {
25 return -EINVAL;
26 }
27
28 if (*data > 1) {
29 return -EINVAL;
30 }
31
32 return 0;
33 }
34
timer_digital_state_cb(uint16_t obj_inst_id,uint16_t res_id,uint16_t res_inst_id,uint8_t * data,uint16_t data_len,bool last_block,size_t total_size,size_t offset)35 static int timer_digital_state_cb(uint16_t obj_inst_id, uint16_t res_id, uint16_t res_inst_id,
36 uint8_t *data, uint16_t data_len, bool last_block,
37 size_t total_size, size_t offset)
38 {
39 bool *digital_state = (bool *)data;
40
41 if (*digital_state) {
42 LOG_INF("TIMER: ON");
43 } else {
44 LOG_INF("TIMER: OFF");
45 }
46
47 return 0;
48 }
49
init_timer_object(void)50 void init_timer_object(void)
51 {
52 lwm2m_create_object_inst(&LWM2M_OBJ(3340, 0));
53 lwm2m_register_validate_callback(&LWM2M_OBJ(3340, 0, 5850), timer_on_off_validate_cb);
54 lwm2m_register_post_write_callback(&LWM2M_OBJ(3340, 0, 5543), timer_digital_state_cb);
55 lwm2m_set_res_buf(&LWM2M_OBJ(3340, 0, 5750), TIMER_NAME, sizeof(TIMER_NAME),
56 sizeof(TIMER_NAME), LWM2M_RES_DATA_FLAG_RO);
57 }
58