51 #define PRINTF(...) printf(__VA_ARGS__)
56 static int32_t time_offset = 0;
59 read_lwtime(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
61 return ctx->writer->write_int(ctx, outbuf, outsize,
66 set_lwtime(lwm2m_context_t *ctx,
const uint8_t *inbuf,
size_t insize,
67 uint8_t *outbuf,
size_t outsize)
71 size_t len = ctx->reader->read_int(ctx, inbuf, insize, &lw_time);
73 PRINTF(
"FAIL: could not read time '%*.s'\n", (
int)insize, inbuf);
75 PRINTF(
"Got: time: %*.s => %" PRId32
"\n", (
int)insize, inbuf, lw_time);
78 PRINTF(
"Write time...%" PRId32
" => offset = %" PRId32
"\n",
79 lw_time, time_offset);
85 #ifdef PLATFORM_REBOOT
86 static struct ctimer reboot_timer;
88 do_the_reboot(
void *ptr)
93 reboot(lwm2m_context_t *ctx,
const uint8_t *arg,
size_t argsize,
94 uint8_t *outbuf,
size_t outsize)
96 PRINTF(
"Device will reboot!\n");
102 #ifdef PLATFORM_FACTORY_DEFAULT
104 factory_reset(lwm2m_context_t *ctx,
const uint8_t *arg,
size_t arg_size,
105 uint8_t *outbuf,
size_t outsize)
107 PRINTF(
"Device will do factory default!\n");
108 PLATFORM_FACTORY_DEFAULT();
113 LWM2M_RESOURCES(device_resources,
114 #ifdef LWM2M_DEVICE_MANUFACTURER
115 LWM2M_RESOURCE_STRING(0, LWM2M_DEVICE_MANUFACTURER),
117 #ifdef LWM2M_DEVICE_TYPE
118 LWM2M_RESOURCE_STRING(17, LWM2M_DEVICE_TYPE),
120 #ifdef LWM2M_DEVICE_MODEL_NUMBER
121 LWM2M_RESOURCE_STRING(1, LWM2M_DEVICE_MODEL_NUMBER),
123 #ifdef LWM2M_DEVICE_SERIAL_NO
124 LWM2M_RESOURCE_STRING(2, LWM2M_DEVICE_SERIAL_NO),
126 #ifdef LWM2M_DEVICE_FIRMWARE_VERSION
127 LWM2M_RESOURCE_STRING(3, LWM2M_DEVICE_FIRMWARE_VERSION),
129 #ifdef PLATFORM_REBOOT
130 LWM2M_RESOURCE_CALLBACK(4, {
NULL,
NULL, reboot }),
132 #ifdef PLATFORM_FACTORY_DEFAULT
133 LWM2M_RESOURCE_CALLBACK(5, {
NULL,
NULL, factory_reset }),
136 LWM2M_RESOURCE_CALLBACK(13, { read_lwtime, set_lwtime,
NULL }),
138 LWM2M_INSTANCES(device_instances, LWM2M_INSTANCE(0, device_resources));
139 LWM2M_OBJECT(device, 3, device_instances);
148 PRINTF(
"*** Init lwm2m-device\n");
149 lwm2m_engine_register_object(&device);
Header file for the Contiki OMA LWM2M device
Header file for the Contiki OMA LWM2M object API
Header file for the Contiki OMA LWM2M engine
#define NULL
The null pointer.
#define CLOCK_SECOND
A second, measured in system clock time.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.
void lwm2m_device_init(void)