summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboyeon-son <bson1012@gmail.com>2018-08-19 14:14:55 +0900
committerboyeon-son <bson1012@gmail.com>2018-08-19 14:14:55 +0900
commit4eb8b52dd05006c370e760d82a136603904927e4 (patch)
tree66a0c901c067962e3d70d04a2b1c1e4a5fb4ef5d
parentf5c278b59cd844ca0b82c19ea306b2aff1fa69d6 (diff)
downloadrcc-4eb8b52dd05006c370e760d82a136603904927e4.tar.gz
rcc-4eb8b52dd05006c370e760d82a136603904927e4.tar.bz2
rcc-4eb8b52dd05006c370e760d82a136603904927e4.zip
Update controller.c file for smartthings-init
-rw-r--r--smartthings-init/src/controller.c75
1 files changed, 49 insertions, 26 deletions
diff --git a/smartthings-init/src/controller.c b/smartthings-init/src/controller.c
index 9c166e5..9e59449 100644
--- a/smartthings-init/src/controller.c
+++ b/smartthings-init/src/controller.c
@@ -55,11 +55,12 @@ static Eina_Bool __get_motion_sensor(void *data)
if (ret != 0) _E("Cannot read sensor value");
- // TODO: Set motion sensor data
+ sensor_data_set_bool(g_ad->motion_data, value);
_D("Detected motion value is: %d", value);
- // TODO: Notify motion sensor change
+ // TODO: Notify observers of the Sensor motion resource
+ /* st_things_notify_observers(const char *resource_uri); */
return ECORE_CALLBACK_RENEW;
}
@@ -79,11 +80,12 @@ static int __set_led(void *data, char *state) {
retv_if(ret != 0, -1);
- // TODO: Set LED sensor data
+ sensor_data_set_string(ad->led_data, state, strlen(state));
_D("Set LED to %s", state);
- // TODO: Notify LED sensor change
+ // TODO: Notify observers of the LED resource
+ /* st_things_notify_observers(const char *resource_uri); */
return 0;
}
@@ -141,9 +143,10 @@ static bool handle_get_request(st_things_get_request_message_s* req_msg, st_thin
if (req_msg->has_property_key(req_msg, SENSOR_MOTION_KEY)) {
bool value = false;
- // TODO: Get Motion sensor data
+ sensor_data_get_bool(g_ad->motion_data, &value);
- // TODO: Set Motion sensor value value for smart things representation
+ // TODO: Update the response representation about the Sensor property which is sent to the client
+ /* resp_rep->set_bool_value((struct _st_things_representation* rep, const char* key, bool value); */
_D("Value : %d", value);
}
@@ -155,13 +158,14 @@ static bool handle_get_request(st_things_get_request_message_s* req_msg, st_thin
if (req_msg->has_property_key(req_msg, SENSOR_LED_KEY)) {
const char *str = NULL;
- // TODO: Get LED sensor data
+ sensor_data_get_string(g_ad->led_data, &str);
if (!str) {
str = SENSOR_LED_INIT;
}
- // TODO: Set Motion sensor value value for smart things representation
+ // TODO: Update the response representation about the LED property which is sent to the client
+ /* resp_rep->set_str_value(struct _st_things_representation* rep, const char* key, const char* value); */
_D("Power : %s", str);
}
@@ -185,11 +189,13 @@ static bool handle_set_request(st_things_set_request_message_s* req_msg, st_thin
retv_if(!str, false);
_D("set [%s:%s] == %s", SENSOR_LED_URI, SENSOR_LED_KEY, str);
- // TODO: Set LED sensor data
+ sensor_data_set_string(g_ad->led_data, str, strlen(str));
- // TODO: Set Motion sensor value value for smart things representation
+ // TODO: Update the response representation about the LED property which is sent to the client
+ /* resp_rep->set_str_value(struct _st_things_representation* rep, const char* key, const char* value); */
- // TODO: Turn on LED light with __set_led()
+ // Turn on LED light with __set_led()
+ ret = __set_led(g_ad, strdup(str));
retv_if(ret != 0, false);
} else {
@@ -224,7 +230,8 @@ static int __things_init(void)
return -1;
}
- if (0 != st_things_set_configuration_prefix_path(app_res_path, app_data_path)) {
+ // TODO: Specify the read-only and read-write path
+ if (0 != /* st_things_set_configuration_prefix_path(const char* ro_path, const char* rw_path) */ ) {
_E("st_things_set_configuration_prefix_path() failed!!");
free(app_res_path);
free(app_data_path);
@@ -235,17 +242,22 @@ static int __things_init(void)
snprintf(app_json_path, sizeof(app_json_path), "%s%s", app_res_path, JSON_NAME);
free(app_res_path);
- if (0 != st_things_initialize(app_json_path, &easysetup_complete)) {
+ // TODO: Specify the device configuration JSON file and change the status of easysetup_complete
+ if (0 != /* st_things_initialize(const char *json_path, bool *easysetup_complete) */) {
_E("st_things_initialize() failed!!");
return -1;
}
_D("easysetup_complete:[%d] ", easysetup_complete);
- st_things_register_request_cb(handle_get_request, handle_set_request);
- st_things_register_reset_cb(handle_reset_request, handle_reset_result);
- st_things_register_user_confirm_cb(handle_ownership_transfer_request);
- st_things_register_things_status_change_cb(handle_things_status_change);
+ // TODO: Register callback for handling request get (handle_get_request) and request set (handle_set_request) messages
+ /* st_things_register_request_cb(st_things_get_request_cb get_cb, st_things_set_request_cb set_cb); */
+ // TODO: Register callback for reset confirmation (handle_reset_request) and reset result(handle_reset_result) functions
+ /* st_things_register_reset_cb(st_things_reset_confirm_cb confirm_cb, st_things_reset_result_cb result_cb); */
+ // TODO: Register callback for getting user confirmation for ownership transfer (handle_ownership_transfer_request)
+ /* st_things_register_user_confirm_cb(st_things_user_confirm_cb confirm_cb); */
+ // TODO: Register callback for getting notified when ST Things state changes (handle_things_status_change)
+ /* st_things_register_things_status_change_cb(st_things_status_change_cb status_cb); */
return 0;
}
@@ -272,17 +284,19 @@ static bool service_app_create(void *user_data)
{
app_data *ad = user_data;
- // TODO: Declare new sensor data for Motion data
+ // Declare new sensor data for Motion data
+ ad->motion_data = sensor_data_new(SENSOR_DATA_TYPE_BOOL);
if (!ad->motion_data)
return false;
- // TODO: Declare new sensor data for LED data
+ // Declare new sensor data for LED data
+ ad->led_data = sensor_data_new(SENSOR_DATA_TYPE_STR);
if (!ad->led_data)
return false;
- // TODO: Initialize LED sensor data
+ sensor_data_set_string(g_ad->led_data, SENSOR_LED_INIT, strlen(SENSOR_LED_INIT));
if (__things_init())
return false;
@@ -299,18 +313,27 @@ static void service_app_terminate(void *user_data)
{
app_data *ad = (app_data *)user_data;
- // TODO: Delete ecore timer
+ // Delete ecore timer
if (ad->getter_motion)
+ ecore_timer_del(ad->getter_motion);
- // TODO: Stop and deinitialize things
+ // Stop and deinitialize things
+ __things_stop();
+ __things_deinit();
- // TODO: Turn off LED light with __set_led()
+ // Turn off LED light with __set_led()
+ __set_led(ad, LED_OFF);
- // TODO: Free sensor Motion & LED data
+ // Free sensor Motion & LED data
+ sensor_data_free(ad->motion_data);
+ sensor_data_free(ad->led_data);
- // TODO: Close Motion and LED resources
+ // Close Motion and LED resources
+ resource_close_infrared_motion_sensor();
+ resource_close_led();
- // TODO: Free app data
+ // Free app data
+ free(ad);
FN_END;
}