2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "st_things.h"
20 static const char* PROP_TEMPERATURE = "temperature";
21 static const char* PROP_RANGE = "range";
22 static const char* PROP_UNITS = "units";
24 static double g_temperature = 0;
25 static double g_range[2] = { 0, 5000. };
26 static size_t g_length = 2;
27 static char g_unit[4] = "mV";
29 extern void resource_init_co2_sensor(void);
30 extern int resource_get_co2_sensor_parameter(void);
31 extern void resource_set_sensor_parameter(int zero_volts);
33 bool handle_get_request_on_resource_capability_thermostatcoolingsetpoint(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
35 DBG("Received a GET request on %s\n", req_msg->resource_uri);
37 if (req_msg->has_property_key(req_msg, PROP_TEMPERATURE)) {
38 DBG("requested temperature");
39 if (0 == g_temperature)
40 g_temperature = (double)resource_get_co2_sensor_parameter();
41 resp_rep->set_double_value(resp_rep, PROP_TEMPERATURE, g_temperature);
43 if (req_msg->has_property_key(req_msg, PROP_RANGE)) {
44 //DBG("requested range");
45 resp_rep->set_double_array_value(resp_rep, PROP_RANGE, (double*)&g_range, g_length);
47 if (req_msg->has_property_key(req_msg, PROP_UNITS)) {
48 //DBG("requested units");
49 resp_rep->set_str_value(resp_rep, PROP_UNITS, g_unit);
54 bool handle_set_request_on_resource_capability_thermostatcoolingsetpoint(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep)
56 DBG("Received a SET request on %s\n", req_msg->resource_uri);
59 if (req_msg->rep->get_double_value(req_msg->rep, PROP_TEMPERATURE, &dvalue)) {
60 g_temperature = dvalue;
61 resource_set_sensor_parameter((int32_t)g_temperature);
62 resource_init_co2_sensor();
63 resp_rep->set_double_value(resp_rep, PROP_TEMPERATURE, dvalue);
64 DBG("set requested: %.f\n", g_temperature);
67 char *str_value = NULL;
68 if (req_msg->rep->get_str_value(req_msg->rep, PROP_UNITS, &str_value)) {
69 resp_rep->set_str_value(resp_rep, PROP_UNITS, g_unit);
73 double davalue[2] = { 0, };
75 if (req_msg->rep->get_double_array_value(req_msg->rep, PROP_RANGE, (double**)&davalue, &dlength )) {
76 resp_rep->set_double_array_value(resp_rep, PROP_RANGE, g_range, g_length);
78 st_things_notify_observers(req_msg->resource_uri);