CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(position-finder-server C)
+PROJECT(${P_NAME} C)
SET(INSTALL_EXEC_PREFIX "${INSTALL_PREFIX}/bin")
-SET(INSTALL_RESDIR "${INSTALL_PREFIX}/res")
-SET(INSTALL_DATADIR "/home/owner/apps_rw/org.tizen.position-finder-server/data")
SET(CMAKE_VERBOSE_MAKEFILE 0)
SET(PROJECT_ROOT_DIR "${CMAKE_SOURCE_DIR}")
SET(PROJECT_RESOURCES_DIR "${PROJECT_ROOT_DIR}/res")
-#disable web notify
-#SET(PF_TYPE "Zarie-web")
-
-MESSAGE("position-finder-server type: ${PF_TYPE}")
-
-SET(CHECK_MODULES
+INCLUDE(FindPkgConfig)
+pkg_check_modules(APP_PKGS REQUIRED
dlog
+ aul
capi-appfw-application
capi-appfw-service-application
capi-system-peripheral-io
ecore
+ eina
iotcon
+ gio-2.0
)
-IF("${PF_TYPE}" STREQUAL "Zarie-web")
- SET(CHECK_MODULES ${CHECK_MODULES}
- libcurl
- glib-2.0
- )
-ADD_DEFINITIONS (-DENABLE_WEBNOTIFY
- -DTEST_RES_URI=\"http://10.113.63.43:8080\"
-)
-ENDIF("${PF_TYPE}" STREQUAL "Zarie-web")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(APP_PKGS REQUIRED ${CHECK_MODULES})
+ADD_DEFINITIONS(-DCBOR_FILE_IN_RES="${INSTALL_RESDIR}/${CBOR_FILE}")
+ADD_DEFINITIONS(-DCBOR_FILE_IN_DATA="${INSTALL_OWNER_DATADIR}/${CBOR_FILE}")
+ADD_DEFINITIONS(-DCONF_FILE="${INSTALL_OWNER_DATADIR}/${CONF_FILE}")
FOREACH (flag ${APP_PKGS_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc)
-SET(SRCS
+ADD_EXECUTABLE(${PROJECT_NAME}
${PROJECT_ROOT_DIR}/src/controller.c
${PROJECT_ROOT_DIR}/src/controller_internal.c
${PROJECT_ROOT_DIR}/src/connectivity.c
${PROJECT_ROOT_DIR}/src/resource/resource_infrared_obstacle_avoidance_sensor.c
${PROJECT_ROOT_DIR}/src/resource/resource_touch_sensor.c
${PROJECT_ROOT_DIR}/src/resource/resource_ultrasonic_sensor.c
+ ${PROJECT_ROOT_DIR}/src/resource/resource_led.c
)
-IF("${PF_TYPE}" STREQUAL "Zarie-web")
- SET(SRCS ${SRCS} ${PROJECT_ROOT_DIR}/src/webnotify.c)
-ENDIF("${PF_TYPE}" STREQUAL "Zarie-web")
-
-ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} )
-
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${APP_PKGS_LDFLAGS})
+Message("APP_LABEL : ${APP_LABEL}")
+
+CONFIGURE_FILE(${PROJECT_ROOT_DIR}/tizen-manifest.xml.in ${ORG_PREFIX}.${PROJECT_NAME}.xml @ONLY)
# Install
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${INSTALL_EXEC_PREFIX})
-
-INSTALL(FILES ${PROJECT_ROOT_DIR}/tizen-manifest.xml DESTINATION ${SYS_PACKAGES_DIR} RENAME org.tizen.position-finder-server.xml)
-INSTALL(DIRECTORY DESTINATION ${PREFIX}/data)
-INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/position_finder_server.png DESTINATION ${SYS_ICONS_DIR})
-INSTALL(FILES ${PROJECT_ROOT_DIR}/res/iotcon-test-svr-db-server.dat DESTINATION ${INSTALL_DATADIR})
+INSTALL(DIRECTORY DESTINATION ${INSTALL_OWNER_DATADIR})
+INSTALL(FILES ${ORG_PREFIX}.${PROJECT_NAME}.xml DESTINATION ${SYS_PACKAGES_DIR})
+INSTALL(FILES ${PROJECT_ROOT_DIR}/shared/res/default_icon.png DESTINATION ${SYS_ICONS_DIR} RENAME ${PROJECT_NAME}.png)
+INSTALL(FILES ${PROJECT_ROOT_DIR}/res/${CBOR_FILE} DESTINATION ${INSTALL_RESDIR})
# End of a file
typedef struct connectivity_resource connectivity_resource_s;
-extern int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info);
+/**
+ * @brief Create connectivity resource and registers the resource in server.
+ * @param[in] path The path of the resource
+ * @param[in] type The string data to insert into the resource types (e.g. "org.tizen.light")
+ * @param[out] out_resource_info A structure containing information about connectivity resource
+ * @return 0 on success, otherwise a negative error value
+ * @see uri_path length must be less than 128.
+ * @see You must destroy resource by calling connectivity_unset_resource() if resource is no longer needed.
+ */
+extern int connectivity_set_resource(const char *path, const char *type, connectivity_resource_s **out_resource_info);
+
+/**
+ * @brief Releases all resource about connectivity.
+ * @param[in] resource_info A structure containing information about connectivity resource
+ */
extern void connectivity_unset_resource(connectivity_resource_s *resource);
+/**
+ * @brief Notifies specific clients that resource's attributes have changed with boolean value.
+ * @param[in] resource_info A structure containing information about connectivity resource
+ * @param[in] key A new key to be added into attributes
+ * @param[in] value A boolean value to be added into attributes
+ * @return 0 on success, otherwise a negative error value
+ * @see If key is already exists, current value will be replaced with new value.
+ */
extern int connectivity_notify_bool(connectivity_resource_s *resource_info, const char *key, bool value);
+
+/**
+ * @brief Notifies specific clients that resource's attributes have changed with int value.
+ * @param[in] resource_info A structure containing information about connectivity resource
+ * @param[in] key A new key to be added into attributes
+ * @param[in] value A int value to be added into attributes
+ * @return 0 on success, otherwise a negative error value
+ * @see If key is already exists, current value will be replaced with new value.
+ */
extern int connectivity_notify_int(connectivity_resource_s *resource_info, const char *key, int value);
+
+/**
+ * @brief Notifies specific clients that resource's attributes have changed with double value.
+ * @param[in] resource_info A structure containing information about connectivity resource
+ * @param[in] key A new key to be added into attributes
+ * @param[in] value A double value to be added into attributes
+ * @return 0 on success, otherwise a negative error value
+ * @see If key is already exists, current value will be replaced with new value.
+ */
extern int connectivity_notify_double(connectivity_resource_s *resource_info, const char *key, double value);
#endif /* __POSITION_FINDER_CONNECTIVITY_H__ */
#include "resource/resource_infrared_obstacle_avoidance_sensor.h"
#include "resource/resource_touch_sensor.h"
#include "resource/resource_ultrasonic_sensor.h"
+#include "resource/resource_led.h"
#endif /* __POSITION_FINDER_RESOURCE_H__ */
#ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__
#define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__
-/* You have to use this illuminance sensor ONLY ONE in the pi board */
+/**
+ * @brief Reads the value of i2c bus connected illuminance sensor.
+ * @param[in] i2c_bus The i2c bus number that the slave device is connected
+ * @param[out] out_value The value read by the illuminance sensor
+ * @return 0 on success, otherwise a negative error value
+ * @see If the i2c bus is not open, creates i2c handle before reading data from the i2c slave device.
+ */
extern int resource_read_illuminance_sensor(int i2c_bus, int *out_value);
#endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */
#ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__
#define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__
+/**
+ * @brief Destory the i2c handle and changes the gpio pin state to the close(0).
+ */
extern void resource_close_illuminance_sensor(void);
#endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ */
#ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
#define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
-extern int resource_read_infrared_motion_sensor(int pin_num, int *out_value);
+/**
+ * @brief Reads the value of gpio connected infrared motion sensor(HC-SR501).
+ * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor
+ * @param[out] out_value The value of the gpio (zero or non-zero)
+ * @return 0 on success, otherwise a negative error value
+ * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
+ */
+extern int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value);
#endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */
#ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__
#define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__
-extern void resource_close_infrared_motion_sensor(int sensor_index);
+/**
+ * @brief Releases the gpio handle and changes the gpio pin state to the close(0).
+ * @param[in] pin_num The number of the gpio pin connected to the infrared motion sensor
+ */
+extern void resource_close_infrared_motion_sensor(int pin_num);
#endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ */
#ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
#define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
-extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value);
+/**
+ * @brief Reads the value of gpio connected infrared obstacle avoidance sensor.
+ * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor
+ * @param[out] out_value The value of the gpio (zero or non-zero)
+ * @return 0 on success, otherwise a negative error value
+ * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
+ */
+extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value);
#endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
#ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__
#define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__
+/**
+ * @brief Releases the gpio handle and changes the gpio pin state to the close(0).
+ * @param[in] pin_num The number of the gpio pin connected to the infrared obstacle avoidance sensor
+ */
extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num);
#endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ */
* Geunsun Lee <gs86.lee@samsung.com>
* Eunyoung Lee <ey928.lee@samsung.com>
* Junkyu Han <junkyu.han@samsung.com>
- * Jeonghoon Park <jh1979.park@samsung.com>
*
* Licensed under the Flora License, Version 1.1 (the License);
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
+#ifndef __POSITION_FINDER_RESOURCE_LED_H__
+#define __POSITION_FINDER_RESOURCE_LED_H__
-#ifndef __POSITION_FINDER_WEBNOTIFY_H__
-#define __POSITION_FINDER_WEBNOTIFY_H__
-
-int web_notify_init(void);
-void web_notify_fini(void);
-int web_notify_data(const char *resource, const char *data);
-int web_notify_bool(const char *resource, bool value);
-int web_notify_int(const char *resource, int value);
-int web_notify_double(const char *resource, double value);
-
-#endif /* __POSITION_FINDER_WEBNOTIFY_H__ */
+extern int resource_write_led(int pin_num, int write_value);
+#endif /* __POSITION_FINDER_RESOURCE_LED_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ * Geunsun Lee <gs86.lee@samsung.com>
+ * Eunyoung Lee <ey928.lee@samsung.com>
+ * Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_LED_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_LED_INTERNAL_H__
+
+extern void resource_close_led(int pin_num);
+
+#endif /* __POSITION_FINDER_RESOURCE_LED_INTERNAL_H__ */
#ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
#define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
+/**
+ * @brief Reads the value of gpio connected touch sensor.
+ * @param[in] pin_num The number of the gpio pin connected to the touch sensor
+ * @param[out] out_value The value of the gpio (zero or non-zero)
+ * @return 0 on success, otherwise a negative error value
+ * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
+ */
extern int resource_read_touch_sensor(int pin_num, int *out_value);
#endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */
#ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__
#define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__
+/**
+ * @brief Releases the gpio handle and changes the gpio pin state to the close(0).
+ * @param[in] pin_num The number of the gpio pin connected to the touch sensor
+ */
extern void resource_close_touch_sensor(int pin_num);
#endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ */
#ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
#define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
+/**
+ * @brief Reads the value of gpio connected ultrasonic sensor(HC-SR04).
+ * @param[in] trig_pin_num The number of the gpio pin connected to the trig of the ultrasonic sensor
+ * @param[in] echo_pin_num The number of the gpio pin connected to the echo of the ultrasonic sensor
+ * @param[in] cb A callback function to be invoked when the gpio interrupt is triggered
+ * @param[in] data The data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @see If the gpio pin is not open, creates gpio handle before reading the value of gpio.
+ */
extern int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data);
#endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ */
#ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__
#define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__
-extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num);
+/**
+ * @brief Releases the gpio handle and changes the gpio pin state to the close(0).
+ * @param[in] trig_pin_num The number of the gpio pin connected to the trig of the ultrasonic sensor
+ * @param[in] echo_pin_num The number of the gpio pin connected to the echo of the ultrasonic sensor
+ */
+extern void resource_close_ultrasonic_sensor_trig(int trig_pin_num);
+extern void resource_close_ultrasonic_sensor_echo(int echo_pin_num);
#endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ */
#include "resource/resource_infrared_obstacle_avoidance_sensor_internal.h"
#include "resource/resource_touch_sensor_internal.h"
#include "resource/resource_ultrasonic_sensor_internal.h"
+#include "resource/resource_led_internal.h"
#define PIN_MAX 40
-Name: org.tizen.position-finder-server
-%define alias org.tizen.position-finder-server
+%define P_NAME position-finder-server
+%define APP_LABEL "Position Finder Server"
+%define ORG_PREFIX org.tizen
+
+Name: %{ORG_PREFIX}.%{P_NAME}
+%define alias %{name}
Summary: IoTivity Application
Group: Applications/Core Applications
Version: 0.0.1
Release: 1
License: Flora-1.1
-Provides: org.tizen.position-finder-server = %{version}-%{release}
+Provides: %{name} = %{version}-%{release}
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: hash-signer
BuildRequires: pkgconfig(capi-appfw-application)
BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(capi-appfw-service-application)
BuildRequires: pkgconfig(capi-system-peripheral-io)
BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(eina)
BuildRequires: pkgconfig(iotcon)
-BuildRequires: pkgconfig(libcurl)
-BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
%description
Server for Position Finder
%define _pkg_dir %{TZ_SYS_RO_APP}/%{alias}
%define _pkg_shared_dir %{_pkg_dir}/shared
%define _pkg_data_dir %{_pkg_dir}/data
-%define _pkg_rw_data_dir /home/owner/apps_rw/org.tizen.position-finder-server/data
+%define _pkg_rw_data_dir /home/owner/apps_rw/%{alias}/data
+%define _pkg_res_dir %{_pkg_dir}/res
%define _sys_icons_dir %{_pkg_shared_dir}/res
%define _sys_packages_dir %{TZ_SYS_RO_PACKAGES}
%define _sys_license_dir %{TZ_SYS_SHARE}/license
+%define _cbor_file iotcon-test-svr-db-server.dat
+%define _conf_file .dev_id
%ifarch %{arm}
export CFLAGS="$CFLAGS -DTIZEN_BUILD_TARGET"
export FFLAGS="$FFLAGS -DTIZEN_BUILD_EMULATOR"
%endif
-cmake . -DINSTALL_PREFIX=%{_pkg_dir} \
+cmake . -DP_NAME=%{P_NAME} \
+ -DORG_PREFIX=%{ORG_PREFIX} \
+ -DAPP_LABEL=%{APP_LABEL} \
+ -DINSTALL_PREFIX=%{_pkg_dir} \
+ -DINSTALL_OWNER_DATADIR=%{_pkg_rw_data_dir} \
+ -DINSTALL_RESDIR=%{_pkg_res_dir} \
-DSYS_ICONS_DIR=%{_sys_icons_dir} \
- -DSYS_PACKAGES_DIR=%{_sys_packages_dir}
+ -DSYS_PACKAGES_DIR=%{_sys_packages_dir} \
+ -DCBOR_FILE=%{_cbor_file} \
+ -DCONF_FILE=%{_conf_file}
make %{?jobs:-j%jobs}
%install
%post
/sbin/ldconfig
-chsmack -a "User::Pkg::org.tizen.position-finder-server" %{_pkg_rw_data_dir}/*.dat
+chsmack -a "User::Pkg::%{alias}" %{_pkg_res_dir}/*.dat
+chmod 444 %{_pkg_res_dir}/*.dat
+
+touch %{_pkg_rw_data_dir}/%{_cbor_file}
+chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/*.dat
chmod 666 %{_pkg_rw_data_dir}/*.dat
+# This routine will be used in the file of .dev_id.
+#touch %{_pkg_rw_data_dir}/%{_conf_file}
+#echo "/door/777" > %{_pkg_rw_data_dir}/%{_conf_file}
+#chsmack -a "User::Pkg::%{alias}" %{_pkg_rw_data_dir}/%{_conf_file}
+#chmod 444 %{_pkg_rw_data_dir}/%{_conf_file}
+
%postun -p /sbin/ldconfig
%files
-%manifest org.tizen.position-finder-server.manifest
-%{_pkg_rw_data_dir}/*.dat
-/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat
+%{_pkg_res_dir}/*.dat
+%manifest %{alias}.manifest
%defattr(-,root,root,-)
-%{_pkg_dir}/bin/position-finder-server
-%{_sys_packages_dir}/org.tizen.position-finder-server.xml
-%{_sys_icons_dir}/position_finder_server.png
+%{_pkg_rw_data_dir}
+%{_pkg_dir}/bin/%{P_NAME}
+%{_sys_packages_dir}/%{alias}.xml
+%{_sys_icons_dir}/*.png
%{_pkg_dir}/author-signature.xml
%{_pkg_dir}/signature1.xml
* limitations under the License.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <glib.h>
#include "log.h"
#include "connectivity.h"
-#define ULTRASONIC_RESOURCE_1_URI "/door/1"
-#define ULTRASONIC_RESOURCE_2_URI "/door/2"
#define ULTRASONIC_RESOURCE_TYPE "org.tizen.door"
+#define BUFSIZE 1024
+#define URI_PATH_LEN 64
static void _request_resource_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data);
ret = iotcon_representation_set_uri_path(representation, uri_path);
goto_if(IOTCON_ERROR_NONE != ret, error);
- ret = iotcon_attributes_add_bool(attributes, "opened", value);
+ ret = iotcon_attributes_add_bool(attributes, key, value);
goto_if(IOTCON_ERROR_NONE != ret, error);
ret = iotcon_representation_set_attributes(representation, attributes);
ret = iotcon_request_get_observe_id(request, &observe_id);
retv_if(IOTCON_ERROR_NONE != ret, -1);
+ _I("Add an observer : %d", observe_id);
+
ret = iotcon_observers_add(observers, observe_id);
retv_if(IOTCON_ERROR_NONE != ret, -1);
} else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
ret = iotcon_request_get_observe_id(request, &observe_id);
retv_if(IOTCON_ERROR_NONE != ret, -1);
+ _I("Remove an observer : %d", observe_id);
+
ret = iotcon_observers_remove(observers, observe_id);
retv_if(IOTCON_ERROR_NONE != ret, -1);
}
_send_response(request, NULL, IOTCON_RESPONSE_ERROR);
}
+static void _copy_file(const char *in_filename, const char *out_filename)
+{
+ char buf[BUFSIZE] = { 0, };
+ size_t nread = 0;
+ FILE *in = NULL;
+ FILE *out = NULL;
+
+ ret_if(!in_filename);
+ ret_if(!out_filename);
+
+ in = fopen(in_filename, "r");
+ ret_if(!in);
+
+ out = fopen(out_filename, "w");
+ goto_if(!out, error);
+
+ rewind(in);
+ while ((nread = fread(buf, 1, sizeof(buf), in)) > 0) {
+ if (fwrite (buf, 1, nread, out) < nread) {
+ _E("critical error to copy a file");
+ break;
+ }
+ }
+
+ fclose(in);
+ fclose(out);
+
+ return;
+
+error:
+ fclose(out);
+}
+
int connectivity_init(void)
{
int ret = -1;
- ret = iotcon_initialize("/home/owner/apps_rw/org.tizen.position-finder-server/data/iotcon-test-svr-db-server.dat");
+ _copy_file(CBOR_FILE_IN_RES, CBOR_FILE_IN_DATA);
+
+ ret = iotcon_initialize(CBOR_FILE_IN_DATA);
retv_if(IOTCON_ERROR_NONE != ret, -1);
ret = iotcon_set_device_name(ULTRASONIC_RESOURCE_TYPE);
free(resource_info);
}
+static int _get_default_uri_path_in_conf(char *buf, int size)
+{
+ FILE *in = NULL;
+ size_t nread = 0;
+
+ in = fopen(CONF_FILE, "r");
+ retv_if(!in, -1);
+
+ nread = fread(buf, 1, size, in);
+ if (nread <= 0) {
+ _I("No contents in the conf.");
+ return -1;
+ }
+
+ if (buf[nread - 1] == '\n')
+ buf[nread - 1] = '\0';
+
+ fclose(in);
+
+ return 0;
+}
+
int connectivity_set_resource(const char *uri_path, const char *type, connectivity_resource_s **out_resource_info)
{
iotcon_resource_types_h resource_types = NULL;
connectivity_resource_s *resource_info = NULL;
uint8_t policies;
int ret = -1;
+ const char *final_uri_path = NULL;
+ char default_uri_path[URI_PATH_LEN] = { 0, };
+
+ if (uri_path) {
+ final_uri_path = uri_path;
+ } else {
+ ret = _get_default_uri_path_in_conf(default_uri_path, URI_PATH_LEN);
+ retv_if(ret < 0, -1);
+ final_uri_path = default_uri_path;
+ }
+
+ _D("uri path : [%s]", final_uri_path);
resource_info = calloc(1, sizeof(connectivity_resource_s));
retv_if(!resource_info, -1);
IOTCON_RESOURCE_OBSERVABLE |
IOTCON_RESOURCE_SECURE;
- ret = iotcon_resource_create(uri_path,
+ ret = iotcon_resource_create(final_uri_path,
resource_types,
ifaces,
policies,
* limitations under the License.
*/
-#include <tizen.h>
-#include <Ecore.h>
-#include <service_app.h>
#include <unistd.h>
#include <glib.h>
+#include <Ecore.h>
+#include <tizen.h>
+#include <service_app.h>
#include <iotcon.h> // Please remove this after test
#include "connectivity.h"
#include "controller.h"
-#ifdef ENABLE_WEBNOTIFY
-#include "webnotify.h"
-#ifndef RESOURCE_URI
-#define RESOURCE_URI TEST_RES_URI
-#endif /* RESOURCE_URI */
-#endif /* ENABLE_WEBNOTIFY */
-
#define GPIO_ULTRASONIC_TRIG_NUM_1 20
#define GPIO_ULTRASONIC_ECHO_NUM_1 21
#define MULTIPLE_SENSOR_NUMBER 5
connectivity_resource_s *resource_info;
} app_data;
-static Eina_Bool control_read_sensors_cb(void *data)
+static Eina_Bool control_sensors_cb(void *data)
{
- int value[MULTIPLE_SENSOR_NUMBER] = { 0, };
+ uint32_t value[MULTIPLE_SENSOR_NUMBER] = { 0, };
int total = 0;
int gpio_num[MULTIPLE_SENSOR_NUMBER] = { 5, 6, 13, 19, 26 };
int i = 0;
app_data *ad = data;
+ /**
+ * This is the case when a number of the same sensors are installed.
+ * Each of the five infrared motion sensors will receive the value.
+ */
for (i = 0; i < MULTIPLE_SENSOR_NUMBER; i++) {
+ /**
+ * Infrared motion sensor outputs 1 if motion is detected, or 0 if motion is not detected.
+ */
if (resource_read_infrared_motion_sensor(gpio_num[i], &value[i]) == -1) {
_E("Failed to get Infrared Motion value [GPIO:%d]", gpio_num[i]);
continue;
}
+ /**
+ * If at least one of the five infrared motion sensors detects motion (1),
+ * it is judged that there is a person (total == 1).
+ */
total |= value[i];
}
_I("[5:%d] | [6:%d] | [13:%d] | [19:%d] | [26:%d] = [Total:%d]", value[0], value[1], value[2], value[3], value[4], total);
+ /**
+ * Notifies specific clients that resource's attributes have changed.
+ */
if (connectivity_notify_bool(ad->resource_info, CONNECTIVITY_KEY, total) == -1)
_E("Cannot notify message");
-#ifdef ENABLE_WEBNOTIFY
- if (web_notify_bool(RESOURCE_URI, total) == -1)
- _E("Cannot notify web message");
-#endif /* ENABLE_WEBNOTIFY */
-
return ECORE_CALLBACK_RENEW;
}
app_data *ad = data;
int ret = -1;
+ /**
+ * No modification required!!!
+ * Access only when modifying internal functions.
+ */
controller_init_internal_functions();
+
+ /**
+ * Create a connectivity resource and registers the resource in server.
+ */
ret = connectivity_set_resource("/door/1", "org.tizen.door", &ad->resource_info);
if (ret == -1) _E("Cannot broadcast resource");
- ad->getter_timer = ecore_timer_add(0.5f, control_read_sensors_cb, ad);
+ /**
+ * Creates a timer to call the given function in the given period of time.
+ * In the control_sensors_cb(), each sensor reads the measured value or writes a specific value to the sensor.
+ */
+ ad->getter_timer = ecore_timer_add(0.5f, control_sensors_cb, ad);
if (!ad->getter_timer) {
_E("Failed to add infrared motion getter timer");
return false;
}
}
+ /**
+ * Releases the resource about connectivity.
+ */
connectivity_unset_resource(ad->resource_info);
+
+ /**
+ * No modification required!!!
+ * Access only when modifying internal functions.
+ */
controller_fini_internal_functions();
free(ad);
app_event_handler_h handlers[5] = {NULL, };
ad = calloc(1, sizeof(app_data));
+ retv_if(!ad, -1);
event_callback.create = service_app_create;
event_callback.terminate = service_app_terminate;
#include "log.h"
#include "connectivity.h"
#include "resource.h"
-#ifdef ENABLE_WEBNOTIFY
-#include "webnotify.h"
-#endif /* ENABLE_WEBNOTIFY */
-
void controller_init_internal_functions(void)
{
connectivity_init();
-#ifdef ENABLE_WEBNOTIFY
- web_notify_init();
-#endif /* ENABLE_WEBNOTIFY */
}
void controller_fini_internal_functions(void)
_I("Terminating...");
resource_close_all();
connectivity_fini();
-#ifdef ENABLE_WEBNOTIFY
- web_notify_fini();
-#endif /* ENABLE_WEBNOTIFY */
}
{
if (!resource_sensor_s.opened) return;
- _I("Infrared Motion Sensor is finishing...");
+ _I("Illuminance Sensor is finishing...");
peripheral_i2c_close(resource_sensor_s.sensor_h);
resource_sensor_s.opened = 0;
}
resource_sensor_s.opened = 1;
}
- ret = peripheral_i2c_write_byte(resource_sensor_s.sensor_h, GY30_CONT_HIGH_RES_MODE);
+ buf[0] = GY30_CONT_HIGH_RES_MODE;
+ ret = peripheral_i2c_write(resource_sensor_s.sensor_h, buf, 1);
retv_if(ret < 0, -1);
ret = peripheral_i2c_read(resource_sensor_s.sensor_h, buf, 2);
*out_value = (buf[0] << 8 | buf[1]) / GY30_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit
- _I("Infrared Motion Sensor Value : %d", *out_value);
+ _I("Illuminance Sensor Value : %d", *out_value);
return 0;
}
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_infrared_motion_sensor(int pin_num, int *out_value)
+int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value)
+int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ * Geunsun Lee <gs86.lee@samsung.com>
+ * Eunyoung Lee <ey928.lee@samsung.com>
+ * Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <peripheral_io.h>
+
+#include "log.h"
+#include "resource_internal.h"
+
+void resource_close_led(int pin_num)
+{
+ if (!resource_get_info(pin_num)->opened) return;
+
+ _I("LED is finishing...");
+ peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
+ resource_get_info(pin_num)->opened = 0;
+}
+
+int resource_write_led(int pin_num, int write_value)
+{
+ int ret = PERIPHERAL_ERROR_NONE;
+
+ if (!resource_get_info(pin_num)->opened) {
+ ret = peripheral_gpio_open(pin_num, &resource_get_info(pin_num)->sensor_h);
+ retv_if(!resource_get_info(pin_num)->sensor_h, -1);
+
+ ret = peripheral_gpio_set_direction(resource_get_info(pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
+ retv_if(ret != 0, -1);
+
+ resource_get_info(pin_num)->opened = 1;
+ }
+
+ ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value);
+ retv_if(ret < 0, -1);
+
+ _I("LED Value : %s", write_value ? "ON":"OFF");
+
+ return 0;
+}
resource_get_info(pin_num)->opened = 0;
}
-int resource_read_touch_sensor(int pin_num, int *out_value)
+int resource_read_touch_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
#include "log.h"
#include "resource_internal.h"
-void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num)
+void resource_close_ultrasonic_sensor_trig(int trig_pin_num)
{
- if (!resource_get_info(echo_pin_num)->opened) return;
if (!resource_get_info(trig_pin_num)->opened) return;
- _I("Ultrasonic sensor is finishing...");
+ _I("Ultrasonic sensor's trig is finishing...");
- peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h);
+ resource_get_info(trig_pin_num)->opened = 0;
+}
+
+void resource_close_ultrasonic_sensor_echo(int echo_pin_num)
+{
+ if (!resource_get_info(echo_pin_num)->opened) return;
+ _I("Ultrasonic sensor's echo is finishing...");
+
+ peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
resource_get_info(echo_pin_num)->opened = 0;
- resource_get_info(trig_pin_num)->opened = 0;
}
-static void _resource_read_ultrasonic_sensor_cb(gpio_isr_cb_s *data, void *user_data)
+static unsigned long long _get_timestamp(void)
+{
+ struct timespec t;
+ clock_gettime(CLOCK_REALTIME, &t);
+ return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
+static void _resource_read_ultrasonic_sensor_cb(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data)
{
float dist = 0;
- static unsigned long long timestamp = 0;
+ uint32_t value;
+ static unsigned long long prev = 0;
+ unsigned long long now = _get_timestamp();
resource_read_s *resource_read_info = user_data;
ret_if(!resource_read_info);
ret_if(!resource_read_info->cb);
- if (timestamp > 0 && data->value == 0) {
- dist = data->timestamp - timestamp;
+ peripheral_gpio_read(gpio, &value);
+
+ if (prev > 0 && value == 0) {
+ dist = now - prev;
dist = (dist * 34300) / 2000000;
_I("Measured Distance : %0.2fcm\n", dist);
resource_read_info->cb(dist, resource_read_info->data);
- peripheral_gpio_unregister_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
+ peripheral_gpio_unset_interrupted_cb(resource_get_info(resource_read_info->pin_num)->sensor_h);
free(resource_read_info);
}
- timestamp = data->timestamp;
+ prev = now;
}
int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource_read_cb cb, void *data)
ret = peripheral_gpio_open(trig_pin_num, &resource_get_info(trig_pin_num)->sensor_h);
retv_if(!resource_get_info(trig_pin_num)->sensor_h, -1);
- ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT);
+ ret = peripheral_gpio_set_direction(resource_get_info(trig_pin_num)->sensor_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
retv_if(ret != 0, -1);
resource_get_info(trig_pin_num)->opened = 1;
+ resource_get_info(trig_pin_num)->close = resource_close_ultrasonic_sensor_trig;
}
if (!resource_get_info(echo_pin_num)->opened) {
retv_if(ret != 0, -1);
resource_get_info(echo_pin_num)->opened = 1;
+ resource_get_info(echo_pin_num)->close = resource_close_ultrasonic_sensor_echo;
}
if (resource_get_info(echo_pin_num)->sensor_h) {
- ret = peripheral_gpio_register_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info);
+ ret = peripheral_gpio_set_interrupted_cb(resource_get_info(echo_pin_num)->sensor_h, _resource_read_ultrasonic_sensor_cb, resource_read_info);
retv_if(ret != 0, -1);
}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Contact: Jin Yoon <jinny.yoon@samsung.com>
- * Geunsun Lee <gs86.lee@samsung.com>
- * Eunyoung Lee <ey928.lee@samsung.com>
- * Junkyu Han <junkyu.han@samsung.com>
- * Jeonghoon Park <jh1979.park@samsung.com>
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdbool.h>
-#include <glib.h>
-#include <curl/curl.h>
-#include "log.h"
-
-static int _web_notify(const char *resource, const char *data)
-{
- CURL *curl;
- CURLcode response;
- curl = curl_easy_init();
- int ret = 0;
-
- if(!curl) {
- _E("fail to init curl");
- return -1;
- }
-
- curl_easy_setopt(curl, CURLOPT_URL, resource);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
-
- response = curl_easy_perform(curl);
-
- if(response != CURLE_OK) {
- _E("curl_easy_perform() failed: %s",
- curl_easy_strerror(response));
- ret = -1;
- }
-
- curl_easy_cleanup(curl);
-
- return ret;
-}
-
-int web_notify_init(void)
-{
- int ret = 0;
- CURLcode result;
- result = curl_global_init(CURL_GLOBAL_DEFAULT);
- if(result != CURLE_OK) {
- _E("curl_global_init() failed: %s",
- curl_easy_strerror(result));
- ret = -1;
- }
- return ret;
-}
-
-void web_notify_fini(void)
-{
- curl_global_cleanup();
- return;
-}
-
-int web_notify_data(const char *resource, const char *data)
-{
- return _web_notify(resource, data);
-}
-
-int web_notify_bool(const char *resource, bool value)
-{
- int ret = 0;
-
- _D("Notify to %s - value[%d]", resource, value);
-
- if(value)
- ret = _web_notify(resource, "TRUE");
- else
- ret = _web_notify(resource, "FALSE");
-
- return ret;
-}
-
-int web_notify_int(const char *resource, int value)
-{
- int ret = 0;
- char *data = NULL;
-
- data = g_strdup_printf("%d", value);
- retv_if(NULL == data, -1);
-
- ret = _web_notify(resource, data);
- g_free(data);
-
- return ret;
-}
-
-int web_notify_double(const char *resource, double value)
-{
- int ret = 0;
- char *data = NULL;
-
- data = g_strdup_printf("%lf", value);
- retv_if(NULL == data, -1);
-
- ret = _web_notify(resource, data);
- g_free(data);
-
- return ret;
-}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="org.tizen.position-finder-server" version="1.0.0">
+<manifest xmlns="http://tizen.org/ns/packages" api-version="3.0" package="@ORG_PREFIX@.@PROJECT_NAME@" version="1.0.0">
<profile name="mobile"/>
<author email="jinny.yoon@samsung.com" href="www.samsung.com">Jin Yoon</author>
<author email="gs86.lee@samsung.com" href="www.samsung.com">Geunsun Lee</author>
<author email="ey928.lee@samsung.com" href="www.samsung.com">Eunyoung Lee</author>
<author email="junkyu.han@samsung.com" href="www.samsung.com">Junkyu Han</author>
- <service-application appid="org.tizen.position-finder-server" auto-restart="true" exec="position-finder-server" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp">
- <label>Position Finder</label>
- <icon>position_finder_server.png</icon>
+ <service-application appid="@ORG_PREFIX@.@PROJECT_NAME@" auto-restart="true" exec="@PROJECT_NAME@" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp">
+ <label>@APP_LABEL@</label>
+ <icon>@PROJECT_NAME@.png</icon>
</service-application>
<privileges>
<privilege>http://tizen.org/privilege/network.get</privilege>