forked from dgiannakop/Arduino-CoAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoapSensor.cpp
101 lines (82 loc) · 3.16 KB
/
CoapSensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/********************************************************************************
** The Arduino-CoAP is free software: you can redistribute it and/or modify **
** it under the terms of the GNU Lesser General Public License as **
** published by the Free Software Foundation, either version 3 of the **
** License, or (at your option) any later version. **
** **
** The Arduino-CoAP is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU Lesser General Public License for more details. **
** **
** You should have received a copy of the GNU Lesser General Public **
** License along with the Arduino-CoAP. **
** If not, see <http://www.gnu.org/licenses/>. **
*******************************************************************************/
#include "CoapSensor.h"
uint8_t CoapSensor::get_method() {
return method;
}
String CoapSensor::get_name() {
return name;
}
bool CoapSensor::get_fast() {
return fast;
}
uint16_t CoapSensor::get_notify_time() {
return notify_time;
}
uint8_t CoapSensor::get_content_type() {
return content_type;
}
uint8_t CoapSensor::set_method(uint8_t method) {
this->method = method;
}
String CoapSensor::set_name(String name) {
this->name = name;
}
bool CoapSensor::set_fast(bool fast) {
this->fast = fast;
}
uint16_t CoapSensor::set_notify_time(uint16_t notify_time) {
this->notify_time = notify_time;
}
uint8_t CoapSensor::set_content_type(uint8_t content_type) {
this->content_type = content_type;
}
coap_status_t CoapSensor::callback(uint8_t method, uint8_t* input_data, size_t input_data_len, uint8_t* output_data, size_t* output_data_len, queries_t queries) {
char bla[] = "default";
memcpy(output_data, bla, strlen(bla) + 1);
*output_data_len = strlen(bla) + 1;
if (method == GET) {
this->get_value(output_data, output_data_len);
return CONTENT;
} else if (method == POST) {
this->set_value(input_data, input_data_len, output_data, output_data_len);
return CHANGED;
}
}
void CoapSensor::get_value(uint8_t* output_data, size_t* output_data_len) {
this->disable_method(GET);
}
void CoapSensor::set_value(uint8_t* input_data, size_t input_data_len, uint8_t* output_data, size_t* output_data_len) {
this->disable_method(POST);
}
void CoapSensor::check(void) {
}
uint8_t CoapSensor::enable_method(uint8_t method) {
uint8_t tempmethod = this->get_method();
tempmethod = tempmethod | method;
this->set_method(tempmethod);
}
uint8_t CoapSensor::disable_method(uint8_t method) {
uint8_t tempmethod = this->get_method();
tempmethod = tempmethod & (~method);
this->set_method(tempmethod);
}
bool CoapSensor::is_changed() {
return changed;
}
void CoapSensor::mark_notified() {
changed = false;
}