From d392340e9c60e038ad853bbeede7a87b96298466 Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Wed, 23 Aug 2017 11:07:00 +0900 Subject: [PATCH] update sensor data structure Change-Id: I1dd63cdbfe359e0bca7b9495d2339fad390dde4c --- inc/webutil.h | 8 ++++---- src/controller.c | 4 ++-- src/webutil.c | 53 +++++++++++++++++++++++++++-------------------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/inc/webutil.h b/inc/webutil.h index ed184c8..2a40e62 100755 --- a/inc/webutil.h +++ b/inc/webutil.h @@ -37,11 +37,11 @@ typedef enum { typedef struct _web_util_sensor_data_s web_util_sensor_data_s; struct _web_util_sensor_data_s { - bool pir; - bool flame; + int motion; + int flame; double humidity; double temperature; - bool virbration; + int virbration; double co2; int soundlevel; web_util_sensor_type_e enabled_sensor; @@ -56,7 +56,7 @@ int web_util_json_init(void); int web_util_json_fini(void); int web_util_json_data_array_begin(void); int web_util_json_data_array_end(void); -int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s sensor_data); +int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s *sensor_data); char *web_util_get_json_string(void); #endif /* __POSITION_FINDER_WEBUTIL_H__ */ \ No newline at end of file diff --git a/src/controller.c b/src/controller.c index 0cf76d4..02fb465 100755 --- a/src/controller.c +++ b/src/controller.c @@ -97,8 +97,8 @@ static void _foreach_resource_list(connectivity_resource_s *resource_info, const sensor_data.hash = NULL; sensor_data.enabled_sensor |= WEB_UTIL_SENSOR_MOTION; - sensor_data.pir = value; - web_util_json_add_sensor_data(uri_path, sensor_data); + sensor_data.motion = value; + web_util_json_add_sensor_data(uri_path, &sensor_data); return; } diff --git a/src/webutil.c b/src/webutil.c index 6f37744..2c4bf76 100755 --- a/src/webutil.c +++ b/src/webutil.c @@ -174,7 +174,7 @@ int web_util_json_data_array_end(void) return 0; } -int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s sensor_data) +int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_s *sensor_data) { const char n_id[] = "SensorPiID"; const char n_motion[] = "Motion"; @@ -191,6 +191,7 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_ retv_if(Json_h.is_begin == false, -1); retv_if(Json_h.is_end == true, -1); retv_if(sensorpi_id == NULL, -1); + retv_if(sensor_data == NULL, -1); /* JSON structure : { @@ -202,82 +203,82 @@ int web_util_json_add_sensor_data(const char* sensorpi_id, web_util_sensor_data_ Vibration: boolean, CO2: double, SoundLevel: int, - SensorEnabled: [PIR, ], + SensorEnabled: [Motion, ], Hash: string, } */ - _I("id : %s, value : %d", sensorpi_id, sensor_data.pir); + _I("id : %s, value : %d", sensorpi_id, sensor_data->motion); json_builder_begin_object(Json_h.builder); json_builder_set_member_name(Json_h.builder, n_id); json_builder_add_string_value(Json_h.builder, sensorpi_id); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_MOTION) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_MOTION) { json_builder_set_member_name(Json_h.builder, n_motion); - json_builder_add_int_value(Json_h.builder, sensor_data.pir); + json_builder_add_int_value(Json_h.builder, sensor_data->motion); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_FLAME) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_FLAME) { json_builder_set_member_name(Json_h.builder, n_flame); - json_builder_add_int_value(Json_h.builder, sensor_data.flame); + json_builder_add_int_value(Json_h.builder, sensor_data->flame); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_HUMIDITY) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_HUMIDITY) { json_builder_set_member_name(Json_h.builder, n_hum); - json_builder_add_double_value(Json_h.builder, sensor_data.humidity); + json_builder_add_double_value(Json_h.builder, sensor_data->humidity); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_TEMPERATURE) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_TEMPERATURE) { json_builder_set_member_name(Json_h.builder, n_temp); - json_builder_add_double_value(Json_h.builder, sensor_data.temperature); + json_builder_add_double_value(Json_h.builder, sensor_data->temperature); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_VIB) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_VIB) { json_builder_set_member_name(Json_h.builder, n_vib); - json_builder_add_int_value(Json_h.builder, sensor_data.virbration); + json_builder_add_int_value(Json_h.builder, sensor_data->virbration); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_CO2) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_CO2) { json_builder_set_member_name(Json_h.builder, n_co2); - json_builder_add_double_value(Json_h.builder, sensor_data.co2); + json_builder_add_double_value(Json_h.builder, sensor_data->co2); } - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_SOUND) { + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_SOUND) { json_builder_set_member_name(Json_h.builder, n_sound); - json_builder_add_int_value(Json_h.builder, sensor_data.soundlevel); + json_builder_add_int_value(Json_h.builder, sensor_data->soundlevel); } json_builder_set_member_name(Json_h.builder, n_e_sensor); json_builder_begin_array(Json_h.builder); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_MOTION) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_MOTION) json_builder_add_string_value(Json_h.builder, n_motion); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_FLAME) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_FLAME) json_builder_add_string_value(Json_h.builder, n_flame); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_HUMIDITY) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_HUMIDITY) json_builder_add_string_value(Json_h.builder, n_hum); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_TEMPERATURE) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_TEMPERATURE) json_builder_add_string_value(Json_h.builder, n_temp); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_VIB) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_VIB) json_builder_add_string_value(Json_h.builder, n_vib); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_CO2) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_CO2) json_builder_add_string_value(Json_h.builder, n_co2); - if(sensor_data.enabled_sensor & WEB_UTIL_SENSOR_SOUND) + if(sensor_data->enabled_sensor & WEB_UTIL_SENSOR_SOUND) json_builder_add_string_value(Json_h.builder, n_sound); json_builder_end_array(Json_h.builder); - if(sensor_data.hash) { + if(sensor_data->hash) { json_builder_set_member_name(Json_h.builder, n_hash); - json_builder_add_string_value(Json_h.builder, sensor_data.hash); + json_builder_add_string_value(Json_h.builder, sensor_data->hash); } json_builder_end_object(Json_h.builder); -- 2.7.4