Contiki-NG
ipso-control-template.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016, SICS Swedish ICT AB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \addtogroup ipso-objects
33 * @{
34 *
35 */
36
37/**
38 * \file
39 * Implementation of OMA LWM2M / IPSO sensor template.
40 * \author
41 * Joakim Eriksson <joakime@sics.se>
42 * Niclas Finne <nfi@sics.se>
43 */
44
45#ifndef IPSO_CONTROL_TEMPLATE_H_
46#define IPSO_CONTROL_TEMPLATE_H_
47
48#include "lwm2m-engine.h"
49
50typedef struct ipso_control ipso_control_t;
51
52#define IPSO_CONTROL_USE_DIMMER 0x01
53
54typedef lwm2m_status_t (*ipso_control_set_value_t)(ipso_control_t *control,
55 uint8_t v);
56
57/* Values of the IPSO control object */
58struct ipso_control {
59 lwm2m_object_instance_t reg_object;
60 uint8_t flags;
61 uint8_t value; /* used to emulate on/off and dim-value */
62 uint32_t on_time; /* on-time in seconds */
63 uint64_t last_on_time;
64 ipso_control_set_value_t set_value;
65};
66
67#define IPSO_CONTROL(name, oid, iid, setv) \
68 static ipso_control_t name = { \
69 .reg_object.object_id = oid, \
70 .reg_object.instance_id = iid, \
71 .set_value = setv \
72 }
73
74int ipso_control_add(ipso_control_t *control);
75int ipso_control_remove(ipso_control_t *control);
76
77static inline uint16_t
78ipso_control_get_object_id(const ipso_control_t *control)
79{
80 return control->reg_object.object_id;
81}
82
83static inline uint16_t
84ipso_control_get_instance_id(const ipso_control_t *control)
85{
86 return control->reg_object.instance_id;
87}
88
89static inline uint8_t
90ipso_control_is_on(const ipso_control_t *control)
91{
92 return (control->value & 0x80) != 0;
93}
94
95static inline uint8_t
96ipso_control_get_value(const ipso_control_t *control)
97{
98 return (control->value & 0x80) != 0 ? (control->value & 0x7f) : 0;
99}
100
101lwm2m_status_t ipso_control_set_on(ipso_control_t *control, uint8_t onoroff);
102
103lwm2m_status_t ipso_control_set_value(ipso_control_t *control, uint8_t dimm_value);
104
105#endif /* IPSO_CONTROL_TEMPLATE_H_ */
106/** @} */
Header file for the Contiki OMA LWM2M engine.