initial import(release): device plugin 58/185458/9
authorjohnny nam <johnny@dignsys.com>
Tue, 31 Jul 2018 02:24:51 +0000 (11:24 +0900)
committerscott park <scott.park@dignsys.com>
Thu, 13 Sep 2018 01:17:48 +0000 (10:17 +0900)
Change-Id: I43f476fbc29e48af9c9a1bd7decf4070acebc634
Signed-off-by: johnny Nam <johnny@dignsys.com>
Signed-off-by: scott park <scott.park@dignsys.com>
18 files changed:
LICENSE [new file with mode: 0644]
inc/log.h [new file with mode: 0644]
inc/resource/resource_servo_motor.h [new file with mode: 0644]
inc/st_things.h [new file with mode: 0644]
inc/st_things_types.h [new file with mode: 0644]
inc/thing.h [new file with mode: 0644]
lib/liboicdastack.so [new file with mode: 0644]
lib/libsdkapi.so [new file with mode: 0644]
project_def.prop [new file with mode: 0644]
res/device_def.json [new file with mode: 0644]
shared/res/luxmeter.png [new file with mode: 0644]
src/capability/capability_doorcontrol.c [new file with mode: 0644]
src/capability/capability_illuminancemeasurement.c [new file with mode: 0644]
src/capability/capability_switch.c [new file with mode: 0644]
src/lux_blind_sensor.c [new file with mode: 0644]
src/resource/resource_illuminance_sensor.c [new file with mode: 0644]
src/resource/resource_servo_motor.c [new file with mode: 0644]
tizen-manifest.xml [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..a06208b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   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.
+
diff --git a/inc/log.h b/inc/log.h
new file mode 100644 (file)
index 0000000..48dd170
--- /dev/null
+++ b/inc/log.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 __LOG_H__
+#define  __LOG_H__
+
+#include <dlog.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "motor"
+
+#define ERR(fmt, args...) dlog_print(DLOG_ERROR, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args)
+#define WARN(fmt, args...) dlog_print(DLOG_WARN, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args)
+#define INFO(fmt, args...)  dlog_print(DLOG_INFO, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args)
+#define DBG(fmt, args...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s : %s(%d) > "fmt"\n", rindex(__FILE__, '/') + 1, __func__, __LINE__, ##args)
+
+#define FN_CALL dlog_print(DLOG_DEBUG, LOG_TAG, ">>>>>>>> called")
+#define FN_END dlog_print(DLOG_DEBUG, LOG_TAG, "<<<<<<<< ended")
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LOG_H__ */
diff --git a/inc/resource/resource_servo_motor.h b/inc/resource/resource_servo_motor.h
new file mode 100644 (file)
index 0000000..e97eda0
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 RESOURCE_SERVO_MOTOR_H_
+#define RESOURCE_SERVO_MOTOR_H_
+
+#include <peripheral_io.h>
+
+typedef enum {
+       DOOR_STATE_CLOSE = 0,
+       DOOR_STATE_CLOSING,
+       DOOR_STATE_OPENING,
+       DOOR_STATE_OPENED,
+       DOOR_STATE_UNKNOWN,
+} door_state_e;
+
+#endif /* RESOURCE_SERVO_MOTOR_H_ */
diff --git a/inc/st_things.h b/inc/st_things.h
new file mode 100644 (file)
index 0000000..92015d7
--- /dev/null
@@ -0,0 +1,299 @@
+/* ****************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 __ST_THINGS_H__
+#define __ST_THINGS_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __ST_THINGS_RTOS__
+#include <st_things/st_things_types.h>
+#else
+#include "st_things_types.h"
+#endif // __ST_THINGS_RTOS__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @brief Set prefix paths (ReadOnly and ReadWrite) for configuration files for the device.
+ *            This is Optional API, and should be used if relative location is used in
+ *            filePath variable in JSON Configuration file.
+ * @param[in] ro_path Prefix Path for Read Only directory location.
+ * @param[in] rw_path Prefix Path for Read Write directory location.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter(both ro_path and rw_path are NULL).
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED Stack already initialized.
+ *         To set Prefix Paths, stack should be deinitilized first by calling st_things_deinitialize().
+ * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running.
+ *         To set Prefix Paths, stack should be stopped first by calling st_things_stop()
+ *         and then deinitialized by calling st_things_deinitialize().
+ */
+int st_things_set_configuration_prefix_path(const char* ro_path, const char* rw_path);
+
+/**
+ * @brief Initializes things stack and returns whether easy-setup is completed or not.
+ *            Easy-setup enable users to acquire the ownership of things and to connect the things with the cloud.
+ *            After performing easy-setup, users can access things from anywhere through the cloud.
+ *            In things stack, easy-setup is a primary and the first operation to be performed on the thing.
+ *            Application running on the thing can know whether easy-setup is done already or not.
+ *            If easy-setup is done, app can start the things stack by calling st_things_start().
+ *            If easy-setup is not done, app can either wait for the user interaction before starting the things stack or
+ *            start the things stack directly without waiting for any events(This case is for those things which doesn't
+ *            support input capability and for all other unknown cases).
+ *            To use a new json file after initialization, stack should be deinitialized
+ *            and stopped(if its started already).
+ * @param[in] json_path Path to Json file which defines a thing. Definition includes the device information,
+ *                                       resources and their properties, configuration info for connectivity and easy-setup, etc.
+ * @param[out] easysetup_complete Indicates whether easysetup is completed already or not.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED Stack already initialized.
+ *         To initialize again, stack should be deinitilized first by calling st_things_deinitialize().
+ * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running.
+ *         To initialize again, stack should be stopped first by calling st_things_stop()
+ *         and then deinitialized by calling st_things_deinitialize().
+ */
+int st_things_initialize(const char *json_path, bool *easysetup_complete);
+
+/**
+ * @brief Deinitializes things stack.
+ *        Stack should have been initialized before calling this API.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized.
+ *         Initialize the stack by calling st_things_initialize().
+ * @retval #ST_THINGS_ERROR_STACK_RUNNING Stack is currently running.
+ *         Before deinitialize, stack needs to be stopped by calling st_things_stop().
+ */
+int st_things_deinitialize(void);
+
+/**
+ * @brief Callback for handling GET request.
+ * @param[in]  req_msg GET request message.
+ * @param[out] resp_rep Representation that will be set to payload of response.
+ * @return @c true in case of success, otherwise @c false
+ */
+typedef bool (*st_things_get_request_cb)(st_things_get_request_message_s *req_msg, st_things_representation_s *resp_rep);
+
+/**
+ * @brief Callback for handling SET(POST) request.
+ * @param[in]  req_msg SET request message.
+ * @param[out] resp_rep Representation that will be set to payload of response.
+ * @return @c true in case of success, otherwise @c false
+ */
+typedef bool (*st_things_set_request_cb)(st_things_set_request_message_s *req_msg, st_things_representation_s *resp_rep);
+
+/**
+ * @brief Callback registration function for handling request messages.
+ * @details The callbacks ensure that a request message will be carried with one of the resource uris from json file of st_things_start().
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] get_cb Reference of the callback function to handle GET request.
+ * @param[in] set_cb Reference of the callback function to handle SET(POST) request.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_request_cb(st_things_get_request_cb get_cb, st_things_set_request_cb set_cb);
+
+/**
+ * @brief Starts things stack.
+ *            Parses the thing definition(whose path is passed to st_things_initialize(), configures the thing,
+ *            creates the resources and prepares it for easy-setup.
+ *            If easy-setup is not done yet, onboarding will be started using either SoftAP or BLE connection.
+ *                Onboarding creates an ad-hoc network between the thing and the client for performing easy-setup.
+ *            If easy-setup is already done, thing will be connected with the cloud.
+ *            Application can know whether easy-setup is done or not through st_things_initialize API.
+ *            Stack should have been initialized before calling this API.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful.
+ *         It is also used for the case that the stack is started already.
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized.
+ *         Initialize the stack by calling st_things_initialize().
+ */
+int st_things_start(void);
+
+/**
+ * @brief Stops things stack.
+ *            Removes all the data being used internally and releases all the memory allocated for the stack.
+ *            Stack should have been initialized and started before calling this API.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not initialized.
+ *         Initialize the stack by calling st_things_initialize().
+ * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started.
+ *         Start the stack by calling st_things_start().
+ */
+int st_things_stop(void);
+
+/**
+ * @brief Callback for getting user's opinion regarding device reset.
+ * @return @c true to confirm, otherwise @c to deny
+ */
+typedef bool (*st_things_reset_confirm_cb)(void);
+
+/**
+ * @brief Callback for carrying the result of reset.
+ * @param[in] is_success Result of Stack-reset. (true : success, false : failure)
+ */
+typedef void (*st_things_reset_result_cb)(bool is_success);
+
+/**
+ * @brief Callback registration function for Reset-Confirmation and Reset-Result functions.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+            And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] confirm_cb Callback function that will be called to get the user's input when reset is triggered.
+ * @param[in] result_cb Callback function that will be called after the reset process is done.
+ *                      This parameter can be NULL if notification for result of reset is not needed.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_reset_cb(st_things_reset_confirm_cb confirm_cb, st_things_reset_result_cb result_cb);
+
+/**
+ * @brief Reset all the data related to security and cloud being used in the stack.
+ *        Stack should have been initialized and started before calling this API.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not intialized.
+ *         Initialize the stack by calling st_things_initialize().
+ * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started.
+ *         Start the stack by calling st_things_start().
+ */
+int st_things_reset(void);
+
+/**
+ * @brief Callback for carrying the randomly generated PIN info.
+ * @details Device should show the PIN on display.
+ * @param[in] pin_data PIN data in string format.
+ * @param[in] pin_size Length of the PIN String.
+ */
+typedef void (*st_things_pin_generated_cb)(const char *pin_data, const size_t pin_size);
+
+/**
+ * @brief Callback for informing the application to close the PIN display.
+ */
+typedef void (*st_things_pin_display_close_cb)(void);
+
+/**
+ * @brief Callback registration function for getting randomly generated PIN for the PIN-Based Ownership Transfer Request.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] generated_cb Callback function that will be called when device receives a Ownership Transfer request from client.
+ * @param[in] close_cb Callback function that will be called when Ownership Transfer is done so device can stop showing PIN on display.
+ *                     This parameter can be NULL if stop triggering is not needed.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_pin_handling_cb(st_things_pin_generated_cb generated_cb, st_things_pin_display_close_cb close_cb);
+
+/**
+ * @brief Callback for getting user's input regarding mutual verification.
+ * @return @c true true in cse of confirmed, otherwise @c false
+ */
+typedef bool (*st_things_user_confirm_cb)(void);
+
+/**
+ * @brief Callback registration function for getting user confirmation for MUTUAL VERIFICATION BASED JUST WORK Ownership transfer.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] confirm_cb Callback function that will be called when device receives a confirm request from client.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_user_confirm_cb(st_things_user_confirm_cb confirm_cb);
+
+/**
+ * @brief Callback for getting the current state of ST Things.
+ * @param[in]  things_status ST Things State
+ */
+typedef void (*st_things_status_change_cb)(st_things_status_e things_status);
+
+/**
+ * @brief Callback registration function for getting notified when ST Things state changes.
+ * @remarks Only one callback function can be set with this API.\n
+ *          If multiple callbacks are set, the last one is registered only.\n
+ *          And the callbacks are called in the internal thread, which is not detached,\n
+ *          so application should return it to get the next callbacks.
+ * @param[in] status_cb Refernce of the callback function to get ST Things status
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+ */
+int st_things_register_things_status_change_cb(st_things_status_change_cb status_cb);
+
+/**
+ * @brief Notify the observers of a specific resource.
+ *        Stack should have been initialized and started before calling this API.
+ * @param[in]  resource_uri Resource URI of the resource which will be notified to observers.
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #ST_THINGS_ERROR_NONE Successful
+ * @retval #ST_THINGS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ST_THINGS_ERROR_OPERATION_FAILED Operation failed
+  * @retval #ST_THINGS_ERROR_STACK_NOT_INITIALIZED Stack is not intialized.
+ *         Initialize the stack by calling st_things_initialize().
+ * @retval #ST_THINGS_ERROR_STACK_NOT_STARTED Stack is not started.
+ *         Start the stack by calling st_things_start().
+ */
+int st_things_notify_observers(const char *resource_uri);
+
+/**
+ * @brief Create an instance of representation.
+ * @remarks To destroy an instance, st_things_destroy_representation_inst() should be used.
+ * @return a pointer of the created representation, otherwise a null pointer if the memory is insufficient.
+ */
+st_things_representation_s *st_things_create_representation_inst(void);
+
+/**
+ * @brief Destroy an instance of representation.
+ * @param[in]  rep Representation that will be destroyed.
+ */
+void st_things_destroy_representation_inst(st_things_representation_s *rep);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __ST_THINGS_H__ */
diff --git a/inc/st_things_types.h b/inc/st_things_types.h
new file mode 100644 (file)
index 0000000..58f75b2
--- /dev/null
@@ -0,0 +1,321 @@
+/* ****************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 __ST_THINGS_TYPES_H__
+#define __ST_THINGS_TYPES_H__
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+/**
+ * @brief Enumeration for ST Things error code.
+ */
+typedef enum {
+    ST_THINGS_ERROR_NONE                         =  0, /**< Successful */
+    ST_THINGS_ERROR_INVALID_PARAMETER            = -1, /**< Invalid parameter (If parameter is null or empty)*/
+    ST_THINGS_ERROR_OPERATION_FAILED             = -2, /**< Operation Failed */
+    ST_THINGS_ERROR_STACK_NOT_INITIALIZED        = -3, /**< Stack is not yet initialized*/
+    ST_THINGS_ERROR_STACK_ALREADY_INITIALIZED    = -4, /**< Stack is already initialized*/
+    ST_THINGS_ERROR_STACK_NOT_STARTED            = -5, /**< Stack is not yet started*/
+    ST_THINGS_ERROR_STACK_RUNNING                = -6, /**< Stack is currently running*/
+} st_things_error_e;
+
+/**
+ * @brief Enumeration for ST Things status.
+ */
+typedef enum {
+    ST_THINGS_STATUS_INIT = 0,                         /**< Initial state of ST Things */
+    ST_THINGS_STATUS_ES_STARTED,                       /**< Easy-setup is started */
+    ST_THINGS_STATUS_ES_DONE,                          /**< Easy-setup is done */
+    ST_THINGS_STATUS_ES_FAILED_ON_OWNERSHIP_TRANSFER,  /**< Easy-setup failed due to Ownership-Transfer failure */
+    ST_THINGS_STATUS_CONNECTING_TO_AP,                 /**< Connecting to target Wi-Fi access point */
+    ST_THINGS_STATUS_CONNECTED_TO_AP,                  /**< Connected to target Wi-Fi access point */
+    ST_THINGS_STATUS_CONNECTING_TO_AP_FAILED,          /**< Failed to connect to target Wi-Fi access point */
+    ST_THINGS_STATUS_REGISTERING_TO_CLOUD,             /**< Trying to Sign-up/Sign-in/Publish-Resource(s) to Cloud */
+    ST_THINGS_STATUS_REGISTERED_TO_CLOUD,              /**< Publish resource(s) to cloud is complete. Now the Thing is ready to be controlled via Cloud */
+    ST_THINGS_STATUS_REGISTERING_FAILED_ON_SIGN_IN,    /**< Failed to sign-in to Cloud */
+    ST_THINGS_STATUS_REGISTERING_FAILED_ON_PUB_RES     /**< Failed to publish resources to Cloud */
+} st_things_status_e;
+
+/**
+ * @brief Structure for Representation.
+ */
+typedef struct _st_things_representation
+{
+    void*   payload; /**< Payload of representation */
+
+    /**
+     * @brief API for getting the value of string type property with a key.
+     * @remarks This API will return deep-copied string value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value String value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_str_value)            (struct _st_things_representation* rep, const char* key, char** value);
+
+    /**
+     * @brief API for getting the value of boolean type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Bool value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_bool_value)           (struct _st_things_representation* rep, const char* key, bool* value);
+
+    /**
+     * @brief API for getting the value of integer type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Integer value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_int_value)            (struct _st_things_representation* rep, const char* key, int64_t* value);
+
+    /**
+     * @brief API for getting the value of double type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Double value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_double_value)         (struct _st_things_representation* rep, const char* key, double* value);
+
+    /**
+     * @brief API for getting the value of byte array type property with a key.
+     * @remarks This API will return deep-copied byte value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Byte value
+     * @param[out] size Size of Byte value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_byte_value)           (struct _st_things_representation* rep, const char* key, uint8_t** value, size_t* size);
+
+    /**
+     * @brief API for getting the value of object type property with a key.
+     * @remarks This API will return deep-copied object value as out parameter, so application must free it after use.\n
+     *          To free an object, st_things_destroy_representation_inst() in st_things.h should be used.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[out] value Object value
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_object_value)         (struct _st_things_representation* rep, const char* key, struct _st_things_representation** value);
+
+    /**
+     * @brief API for setting the value of string type property with a key.
+     * @remarks This API will deep-copy the string value inside, so application still has an ownership of memory for the string value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value String value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_str_value)            (struct _st_things_representation* rep, const char* key, const char* value);
+
+    /**
+     * @brief API for setting the value of boolean type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Bool value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_bool_value)           (struct _st_things_representation* rep, const char* key, bool value);
+
+    /**
+     * @brief API for setting the value of integer type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Integer value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_int_value)            (struct _st_things_representation* rep, const char* key, int64_t value);
+
+    /**
+     * @brief API for setting the value of double type property with a key.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Double value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_double_value)         (struct _st_things_representation* rep, const char* key, double value);
+
+    /**
+     * @brief API for setting the value of byte array type property with a key.
+     * @remarks This API will deep-copy the byte value inside, so application still has an ownership of memory for the byte value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Byte value.
+     * @param[in]  size Size of Byte value.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_byte_value)           (struct _st_things_representation* rep, const char* key, const uint8_t* value, size_t size);
+
+    /**
+     * @brief API for setting the value of object type property with a key.
+     * @remarks This API will deep-copy the object value inside, so application still has an ownership of memory for the object value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the value.
+     * @param[in]  value Object value.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*set_object_value)         (struct _st_things_representation* rep, const char* key, const struct _st_things_representation* value);
+
+    /**
+     * @brief API for getting the value of string array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the string array to where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_str_array_value)      (struct _st_things_representation* rep, const char* key, char*** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of integer array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the integer array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_int_array_value)      (struct _st_things_representation* rep, const char* key, int64_t** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of double array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which will represent the array type of value.
+     * @param[out] array Reference of the double array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_double_array_value)   (struct _st_things_representation* rep, const char* key, double** array, size_t* length);
+
+    /**
+     * @brief API for getting the value of object array type property with a key.
+     * @remarks This API will return deep-copied array value as out parameter, so application must free it after use.\n
+     *          To free each object in array, st_things_destroy_representation_inst() in st_things.h should be used.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the array type of value.
+     * @param[out] array Reference of the object array where the value will be copied.
+     * @param[out] length Total number of elements in the array.
+     * @return @c true if value exist, otherwise @c false
+     */
+    bool    (*get_object_array_value)   (struct _st_things_representation* rep, const char* key, struct _st_things_representation*** array, size_t* length);
+
+    /**
+     * @brief API for setting the value of string array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array String array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_str_array_value)      (struct _st_things_representation* rep, const char* key, const char** array, size_t length);
+
+    /**
+     * @brief API for setting the value of integer array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Integer array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_int_array_value)      (struct _st_things_representation* rep, const char* key, const int64_t* array, size_t length);
+
+    /**
+     * @brief API for setting the value of double array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Double array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_double_array_value)   (struct _st_things_representation* rep, const char* key, const double* array, size_t length);
+
+    /**
+     * @brief API for setting the value of object array type property with a key.
+     * @remarks This API will deep-copy the array value inside, so application still has an ownership of memory for the array value.
+     * @param[in]  rep Instance of Representation.
+     * @param[in]  key Property Name which represents the value.
+     * @param[in]  array Object array type value.
+     * @param[in]  length Total number of elements in the array.
+     * @return @c true if setting value is successful, otherwise @c false
+     */
+    bool    (*set_object_array_value)   (struct _st_things_representation* rep, const char* key, const struct _st_things_representation** array, size_t length);
+
+} st_things_representation_s;
+
+/**
+ * @brief Structure for representing the Get Request Message.
+ */
+typedef struct _st_things_get_request_message
+{
+    char*                               resource_uri;   /**< Resource URI */
+    char*                               query;          /**< One or more query parameters of the request message. Ex: key1=value1;key2=value2;... */
+    char*                               property_key;   /**< One or more property key that application needs to set a value for response. Ex: key1;key2;... */
+
+    /**
+     * @brief API for getting the value of a specific query from the query parameters of the request.
+     * @param[in]  req_msg Instance of get request message.
+     * @param[in]  key Name of the query.(ex: key1, key2, etc)
+     * @param[out] value Value of the query.(value1, value2, etc)
+     * @return @c true if query exist, otherwise @c false
+     */
+    bool    (*get_query_value)          (struct _st_things_get_request_message* req_msg, const char* key, char** value);
+
+    /**
+     * @brief API for checking whether the request has a specific property key or not.
+     * @param[in]  req_msg Instance of get request message.
+     * @param[in]  key Name of the property.
+     * @return @c true if the property key exists, otherwise @c false
+     */
+    bool    (*has_property_key)         (struct _st_things_get_request_message* req_msg, const char* key);
+
+} st_things_get_request_message_s;
+
+/**
+ * @brief Structure for representing the Set Request Message.
+ */
+typedef struct _st_things_set_request_message
+{
+    char*                               resource_uri;   /**< Resource URI */
+    char*                               query;          /**< One or more query parameters of the request message. Ex: key1=value1?key2=value2?... */
+    struct _st_things_representation*   rep;            /**< Representation of the set request message */
+
+    /**
+     * @brief API for getting the value of a specific query from the query parameters of the request.
+     * @param[in]  req_msg Instance of request message.
+     * @param[in]  key Name of the query.(ex: key1, key2, etc)
+     * @param[out] value Value of the query.(value1, value2, etc)
+     * @return @c true if query exist, otherwise @c false
+     */
+    bool    (*get_query_value)          (struct _st_things_set_request_message* req_msg, const char* key, char** value);
+
+} st_things_set_request_message_s;
+
+#endif /* __ST_THINGS_TYPES_H__ */
diff --git a/inc/thing.h b/inc/thing.h
new file mode 100644 (file)
index 0000000..f186d70
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * thing.h
+ *
+ *  Created on: Jul 16, 2018
+ *      Author: ds
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+void init_thing();
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
diff --git a/lib/liboicdastack.so b/lib/liboicdastack.so
new file mode 100644 (file)
index 0000000..4a5cc91
Binary files /dev/null and b/lib/liboicdastack.so differ
diff --git a/lib/libsdkapi.so b/lib/libsdkapi.so
new file mode 100644 (file)
index 0000000..47ca354
Binary files /dev/null and b/lib/libsdkapi.so differ
diff --git a/project_def.prop b/project_def.prop
new file mode 100644 (file)
index 0000000..6b7a1cb
--- /dev/null
@@ -0,0 +1,11 @@
+APPNAME = luxmeter
+
+type = app
+profile = iot-headless-4.0
+
+USER_SRCS = src/luxmeter.c
+USER_DEFS =
+USER_INC_DIRS = inc, inc/sdk
+USER_OBJS =
+USER_LIBS = lib/liboicdastack.so, lib/libsdkapi.so
+USER_EDCS =
diff --git a/res/device_def.json b/res/device_def.json
new file mode 100644 (file)
index 0000000..8f33c0d
--- /dev/null
@@ -0,0 +1,119 @@
+{
+  "device": [
+    {
+      "specification": {
+        "device": {
+          "deviceType": "x.wwst.d.basic",
+          "deviceName": "blind",
+          "specVersion": "core.1.1.0",
+          "dataModelVersion": "res.1.1.0"
+        },
+        "platform": {
+          "manufacturerName": "*** YOUR DEVICE NAME ***",
+          "manufacturerUrl": "http://www.samsung.com/sec/",
+          "manufacturingDate": "2017-11-29",
+          "modelNumber": "BLIND-01",
+          "platformVersion": "1.0",
+          "osVersion": "1.0",
+          "hardwareVersion": "1.0",
+          "firmwareVersion": "1.0",
+          "vendorId": "*** YOUR VENDOR ID ***"
+        }
+      },
+      "resources": {
+        "single": [
+          {
+            "uri": "/capability/switch/main/0",
+            "types": [
+              "x.com.st.powerswitch"
+            ],
+            "interfaces": [
+              "oic.if.a",
+              "oic.if.baseline"
+            ],
+            "policy": 3
+          },
+          {
+            "uri": "/capability/illuminanceMeasurement/main/0",
+            "types": [
+              "oic.r.sensor.illuminance"
+            ],
+            "interfaces": [
+              "oic.if.s",
+              "oic.if.baseline"
+            ],
+            "policy": 3
+          },
+          {
+            "uri": "/capability/doorControl/main/0",
+            "types": [
+              "x.com.st.doorcontrol"
+            ],
+            "interfaces": [
+              "oic.if.baseline",
+              "oic.if.a"
+            ],
+            "policy": 3
+          }
+        ]
+      }
+    }
+  ],
+  "resourceTypes": [
+    {
+      "type": "x.com.st.powerswitch",
+      "properties": [
+        {
+          "key": "power",
+          "type": 3,
+          "mandatory": true,
+          "rw": 3
+        }
+      ]
+    },
+    {
+      "type": "oic.r.sensor.illuminance",
+      "properties": [
+        {
+          "key": "illuminance",
+          "type": 2,
+          "mandatory": true,
+          "rw": 1
+        }
+      ]
+    },
+    {
+      "type": "x.com.st.doorcontrol",
+      "properties": [
+        {
+          "key": "doorState",
+          "type": 3,
+          "mandatory": true,
+          "rw": 3
+        }
+      ]
+    }
+  ],
+  "configuration": {
+    "easySetup": {
+      "connectivity": {
+        "type": 1,
+        "softAP": {
+          "setupId": "001",
+          "artik": false
+        }
+      },
+      "ownershipTransferMethod": 2
+    },
+    "wifi": {
+      "interfaces": 15,
+      "frequency": 1
+    },
+    "filePath": {
+      "svrdb": "artikserversecured.dat",
+      "provisioning": "provisioning.dat",
+      "certificate": "certificate.pem",
+      "privateKey": "privatekey.der"
+    }
+  }
+}
diff --git a/shared/res/luxmeter.png b/shared/res/luxmeter.png
new file mode 100644 (file)
index 0000000..9765b1b
Binary files /dev/null and b/shared/res/luxmeter.png differ
diff --git a/src/capability/capability_doorcontrol.c b/src/capability/capability_doorcontrol.c
new file mode 100644 (file)
index 0000000..6c11270
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <stdio.h>
+#include <stdbool.h>
+#include "st_things.h"
+#include "log.h"
+#include <app_common.h>
+#include "resource/resource_servo_motor.h"
+
+static const char *PROP_DOORSTATE = "doorState";
+static const char *RES_CAPABILITY_DOORCONTROL_MAIN_0 = "/capability/doorControl/main/0";
+
+#define VALUE_STR_LEN_MAX 32
+#define AUTO_CLOSE_LUX_VALUE   40
+#define AUTO_OPEN_LUX_VALUE            500
+#define MAX_PATH_LEN   1024
+
+static const char *VALUE_DOOR_STATE_OPENED = "opened";
+static const char *VALUE_DOOR_STATE_OPENING = "opening";
+static const char *VALUE_DOOR_STATE_CLOSING = "closing";
+static const char *VALUE_DOOR_STATE_CLOSED = "closed";
+
+static char g_door_state[VALUE_STR_LEN_MAX] = "closed";
+
+char *door_state_file_name="door_state";
+
+extern bool get_auto_operation_status(void);
+extern void set_auto_operation_status(bool status);
+
+extern peripheral_error_e resource_motor_driving(door_state_e mode);
+
+bool get_door_state(char *door_state)
+{
+       FILE * fd;
+       char file_name_path[MAX_PATH_LEN];
+       char *app_data_path = NULL;
+
+       app_data_path = app_get_data_path();
+       sprintf(file_name_path, "%s%s", app_data_path, door_state_file_name);
+
+       if((fd = fopen(file_name_path, "r")) == NULL) {
+               ERR("ERROR: can't fopen file: %s", file_name_path);
+               free(app_data_path);
+               return false;
+       }
+       if (fgets(door_state, 8, fd) == NULL) {
+               ERR("fgets read string error");
+               free(app_data_path);
+               fclose(fd);
+               return false;
+       }
+       INFO("door_state : %s", door_state);
+
+       fclose(fd);
+       free(app_data_path);
+
+       return true;
+}
+
+bool set_door_state(const char *door_state)
+{
+       FILE *fp;
+       char buffer[16];
+       char file_name_path[MAX_PATH_LEN];
+       char *app_data_path = NULL;
+       int num;
+
+       app_data_path = app_get_data_path();
+       sprintf(file_name_path, "%s%s", app_data_path, door_state_file_name);
+
+       if((fp = fopen(file_name_path, "w+")) == NULL) {
+               ERR("ERROR: can't fopen file: %s", file_name_path);
+               strncpy(g_door_state, door_state, VALUE_STR_LEN_MAX);
+               free(app_data_path);
+               return false;
+       }
+       memset(buffer, 0, sizeof(buffer));
+       sprintf(buffer, "%s", door_state);
+       if ((num = fputs(buffer, fp)) == EOF) {
+               ERR("ERROR: fputs failed");
+               strncpy(g_door_state, door_state, VALUE_STR_LEN_MAX);
+               free(app_data_path);
+               fclose(fp);
+               return false;
+       }
+       fclose(fp);
+
+       strncpy(g_door_state, door_state, VALUE_STR_LEN_MAX);
+       free(app_data_path);
+       return true;
+}
+
+
+void set_auto_motor_driving(uint16_t sensor_value)
+{
+       bool auto_status = get_auto_operation_status();
+
+       if (auto_status == false)
+               return;
+
+       if (sensor_value <= AUTO_CLOSE_LUX_VALUE) {
+               if (0 != strncmp(g_door_state, VALUE_DOOR_STATE_CLOSING, strlen(VALUE_DOOR_STATE_CLOSING))) {
+                       resource_motor_driving(DOOR_STATE_CLOSING);
+                       set_door_state(VALUE_DOOR_STATE_CLOSING);
+                       strncpy(g_door_state, VALUE_DOOR_STATE_CLOSING, strlen(VALUE_DOOR_STATE_CLOSING));
+               }
+       }
+       else if (sensor_value > AUTO_OPEN_LUX_VALUE) {
+               if (0 != strncmp(g_door_state, VALUE_DOOR_STATE_OPENING, strlen(VALUE_DOOR_STATE_OPENING))) {
+                       resource_motor_driving(DOOR_STATE_OPENING);
+                       set_door_state(VALUE_DOOR_STATE_OPENING);
+                       strncpy(g_door_state, VALUE_DOOR_STATE_OPENING, strlen(VALUE_DOOR_STATE_OPENING));
+               }
+       }
+       else {
+               ERR("invalid sensor_value [%d]", sensor_value);
+               return;
+       }
+
+       // notify door state to cloud
+       st_things_notify_observers(RES_CAPABILITY_DOORCONTROL_MAIN_0);
+}
+
+bool handle_get_request_on_resource_capability_doorcontrol(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       //DBG("Received a GET request on %s\n", req_msg->resource_uri);
+
+       if (req_msg->has_property_key(req_msg, PROP_DOORSTATE)) {
+               if (get_door_state(g_door_state) != true) {
+                       set_door_state(VALUE_DOOR_STATE_CLOSED);
+               }
+
+               /* check door state */
+               if ((0 == strncmp(g_door_state, VALUE_DOOR_STATE_OPENED, strlen(VALUE_DOOR_STATE_OPENED))) ||
+                       (0 == strncmp(g_door_state, VALUE_DOOR_STATE_CLOSED, strlen(VALUE_DOOR_STATE_CLOSED)))) {
+                       INFO("g_door_state(%s) : Auto Operation OFF!!", g_door_state);
+                       set_auto_operation_status(false);
+               } else if ((0 == strncmp(g_door_state, VALUE_DOOR_STATE_OPENING, strlen(VALUE_DOOR_STATE_OPENING))) ||
+                                       (0 == strncmp(g_door_state, VALUE_DOOR_STATE_CLOSING, strlen(VALUE_DOOR_STATE_CLOSING)))) {
+                       INFO("g_door_state(%s) : Auto Operation ON!!", g_door_state);
+                       set_auto_operation_status(true);
+               }
+
+               resp_rep->set_str_value(resp_rep, PROP_DOORSTATE, g_door_state);
+       }
+       return true;
+}
+
+bool handle_set_request_on_resource_capability_doorcontrol(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       DBG("Received a SET request on %s\n", req_msg->resource_uri);
+
+       door_state_e state = DOOR_STATE_UNKNOWN;
+
+       char *str_value = NULL;
+       req_msg->rep->get_str_value(req_msg->rep, PROP_DOORSTATE, &str_value);
+
+       /* check validation */
+       if ((0 != strncmp(str_value, VALUE_DOOR_STATE_OPENED, strlen(VALUE_DOOR_STATE_OPENED)))
+               && (0 != strncmp(str_value, VALUE_DOOR_STATE_OPENING, strlen(VALUE_DOOR_STATE_OPENING)))
+               && (0 != strncmp(str_value, VALUE_DOOR_STATE_CLOSING, strlen(VALUE_DOOR_STATE_CLOSING)))
+               && (0 != strncmp(str_value, VALUE_DOOR_STATE_CLOSED, strlen(VALUE_DOOR_STATE_CLOSED)))) {
+               ERR("Not supported value!! str_value : %s", str_value);
+               free(str_value);
+               return false;
+       }
+
+       if (0 != strncmp(str_value, g_door_state, strlen(g_door_state))) {
+               strncpy(g_door_state, str_value, VALUE_STR_LEN_MAX);
+               free(str_value);
+
+               set_door_state(g_door_state);
+
+               if (0 == strncmp(g_door_state, VALUE_DOOR_STATE_OPENED, strlen(VALUE_DOOR_STATE_OPENED))) {
+                       INFO("Door Opened");
+                       set_auto_operation_status(false);
+                       state = DOOR_STATE_OPENED;
+               }
+               else if (0 == strncmp(g_door_state, VALUE_DOOR_STATE_OPENING, strlen(VALUE_DOOR_STATE_OPENING))) {
+                       INFO("Door Opening - AUTO");
+                       set_auto_operation_status(true);
+                       state = DOOR_STATE_UNKNOWN;
+               }
+               else if (0 == strncmp(g_door_state, VALUE_DOOR_STATE_CLOSING, strlen(VALUE_DOOR_STATE_CLOSING))) {
+                       INFO("Door Closing - AUTO");
+                       set_auto_operation_status(true);
+                       state = DOOR_STATE_UNKNOWN;
+               }
+               else if (0 == strncmp(g_door_state, VALUE_DOOR_STATE_CLOSED, strlen(VALUE_DOOR_STATE_CLOSED))) {
+                       INFO("Door Closed");
+                       set_auto_operation_status(false);
+                       state = DOOR_STATE_CLOSE;
+               }
+               else {
+                       INFO("Door state Unknown");
+                       state = DOOR_STATE_UNKNOWN;
+               }
+
+               if (state != DOOR_STATE_UNKNOWN) {
+                       if (resource_motor_driving(state) != PERIPHERAL_ERROR_NONE)
+                               return false;
+               }
+       }
+       resp_rep->set_str_value(resp_rep, PROP_DOORSTATE, g_door_state);
+
+       st_things_notify_observers(req_msg->resource_uri);
+
+       return true;
+}
diff --git a/src/capability/capability_illuminancemeasurement.c b/src/capability/capability_illuminancemeasurement.c
new file mode 100644 (file)
index 0000000..4a6834b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "st_things.h"
+#include "log.h"
+
+static const char *PROP_ILLUMINANCE = "illuminance";
+
+extern uint16_t get_sensor_value(void);
+extern void set_auto_motor_driving(uint16_t lux_value);
+
+bool handle_get_request_on_resource_capability_illuminancemeasurement(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       uint16_t sensor_value = 0;
+
+       //DBG("Received a GET request on %s\n", req_msg->resource_uri);
+
+       if (req_msg->has_property_key(req_msg, PROP_ILLUMINANCE)) {
+               // get illuminance sensor value
+               sensor_value = get_sensor_value();
+               set_auto_motor_driving(sensor_value);
+
+               // set sensor value
+               resp_rep->set_int_value(resp_rep, PROP_ILLUMINANCE, sensor_value);
+       }
+       return true;
+}
diff --git a/src/capability/capability_switch.c b/src/capability/capability_switch.c
new file mode 100644 (file)
index 0000000..e377c0c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "st_things.h"
+#include "log.h"
+
+static const char *PROP_POWER = "power";
+
+#define VALUE_STR_LEN_MAX 32
+static const char *VALUE_SWITCH_ON = "on";
+static const char *VALUE_SWITCH_OFF = "off";
+static char g_switch[VALUE_STR_LEN_MAX] = "off";
+
+extern void set_switch_status(bool status);
+
+bool handle_get_request_on_resource_capability_switch(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       DBG("Received a GET request on %s\n", req_msg->resource_uri);
+
+       if (req_msg->has_property_key(req_msg, PROP_POWER)) {
+               resp_rep->set_str_value(resp_rep, PROP_POWER, g_switch);
+       }
+
+       return true;
+}
+
+bool handle_set_request_on_resource_capability_switch(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       DBG("Received a SET request on %s\n", req_msg->resource_uri);
+
+       char *str_value = NULL;
+       req_msg->rep->get_str_value(req_msg->rep, PROP_POWER, &str_value);
+
+       /* check validation */
+       if ((0 != strncmp(str_value, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON)))
+               && (0 != strncmp(str_value, VALUE_SWITCH_OFF, strlen(VALUE_SWITCH_OFF)))) {
+               ERR("Not supported value!!");
+               free(str_value);
+               return false;
+       }
+
+       if (0 != strncmp(str_value, g_switch, strlen(g_switch))) {
+               strncpy(g_switch, str_value, VALUE_STR_LEN_MAX);
+               if (0 == strncmp(g_switch, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON))) {
+                       set_switch_status(true);
+               }
+               else  {
+                       set_switch_status(false);
+               }
+       }
+       resp_rep->set_str_value(resp_rep, PROP_POWER, g_switch);
+
+       st_things_notify_observers(req_msg->resource_uri);
+
+       free(str_value);
+
+       return true;
+}
diff --git a/src/lux_blind_sensor.c b/src/lux_blind_sensor.c
new file mode 100644 (file)
index 0000000..d4f901d
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <service_app.h>
+#include <stdio.h>
+#include "st_things.h"
+#include "log.h"
+#include <Ecore.h>
+
+#define _DEBUG_PRINT_
+#ifdef _DEBUG_PRINT_
+#include <sys/time.h>
+#endif
+
+#define SENSOR_EVENT_INTERVAL  (0.250f)        // sensor event timer : 250ms interval
+#define JSON_PATH "device_def.json"
+#define MUTEX_LOCK             pthread_mutex_lock(&mutex)
+#define MUTEX_UNLOCK   pthread_mutex_unlock(&mutex)
+
+Ecore_Timer *sensor_event_timer = NULL;
+pthread_mutex_t  mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static const char *RES_CAPABILITY_ILLUMINANCEMEASUREMENT_MAIN_0 = "/capability/illuminanceMeasurement/main/0";
+static const char *RES_CAPABILITY_DOORCONTROL_MAIN_0 = "/capability/doorControl/main/0";
+static const char *RES_CAPABILITY_SWITCH_MAIN_0 = "/capability/switch/main/0";
+static int g_lux_value = 0;
+static bool g_switch_status = false;
+static bool g_auto_operation_status = false;
+
+/* resource handler */
+extern int resource_open_i2c_handle(void);
+extern int resource_close_i2c_handle(void);
+extern int resource_read_illuminance_sensor(uint16_t *out_value);
+
+/* get and set request handlers */
+extern bool handle_get_request_on_resource_capability_illuminancemeasurement(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep);
+extern bool handle_get_request_on_resource_capability_switch(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep);
+extern bool handle_set_request_on_resource_capability_switch(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep);
+extern bool handle_get_request_on_resource_capability_doorcontrol(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep);
+extern bool handle_set_request_on_resource_capability_doorcontrol(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep);
+
+bool get_switch_status(void)
+{
+       bool status = false;
+
+       MUTEX_LOCK;
+       status = g_switch_status;
+       MUTEX_UNLOCK;
+
+       return status;
+}
+
+void set_switch_status(bool status)
+{
+       MUTEX_LOCK;
+       g_switch_status = status;
+       MUTEX_UNLOCK;
+
+}
+
+bool get_auto_operation_status(void)
+{
+       bool status = false;
+
+       MUTEX_LOCK;
+       status = g_auto_operation_status;
+       MUTEX_UNLOCK;
+
+       return status;
+}
+
+void set_auto_operation_status(bool status)
+{
+       MUTEX_LOCK;
+       g_auto_operation_status = status;
+       MUTEX_UNLOCK;
+
+}
+
+uint16_t get_sensor_value(void)
+{
+       uint16_t value = 0;
+
+       MUTEX_LOCK;
+       value = g_lux_value;
+       MUTEX_UNLOCK;
+
+       return value;
+}
+
+static void set_sensor_value(uint16_t value)
+{
+       MUTEX_LOCK;
+       g_lux_value = value;
+       MUTEX_UNLOCK;
+}
+
+static Eina_Bool _sensor_interval_event_cb(void *data)
+{
+       uint16_t sensor_value;
+       int ret = 0;
+       bool switch_status = false;
+
+       // read sensor value in lux
+       ret = resource_read_illuminance_sensor(&sensor_value);
+       if (ret != 0) {
+               ERR("Got invalid sensor value");
+               // cancle periodic event timer operation
+               return ECORE_CALLBACK_CANCEL;
+       } else {
+               // save sensor value to global variable
+               set_sensor_value(sensor_value);
+
+               #ifdef _DEBUG_PRINT_
+               struct timeval __tv;
+               gettimeofday(&__tv, NULL);
+               INFO("[%d.%06d] Lux=[%d]Lux", __tv.tv_sec, __tv.tv_usec, sensor_value);
+               #endif
+
+               // send notification when switch is on state.
+               switch_status = get_switch_status();
+               if (switch_status) {
+                       // send notification to cloud server
+                       st_things_notify_observers(RES_CAPABILITY_ILLUMINANCEMEASUREMENT_MAIN_0);
+               }
+       }
+       // reset event timer periodic
+       return ECORE_CALLBACK_RENEW;
+}
+
+/* handle : for getting request on resources */
+bool handle_get_request(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       //DBG("resource_uri [%s]", req_msg->resource_uri);
+
+       if (0 == strcmp(req_msg->resource_uri, RES_CAPABILITY_SWITCH_MAIN_0)) {
+               return handle_get_request_on_resource_capability_switch(req_msg, resp_rep);
+       }
+       if (0 == strcmp(req_msg->resource_uri, RES_CAPABILITY_ILLUMINANCEMEASUREMENT_MAIN_0)) {
+               return handle_get_request_on_resource_capability_illuminancemeasurement(req_msg, resp_rep);
+       }
+       if (0 == strcmp(req_msg->resource_uri, RES_CAPABILITY_DOORCONTROL_MAIN_0)) {
+               return handle_get_request_on_resource_capability_doorcontrol(req_msg, resp_rep);
+       }
+
+       ERR("not supported uri");
+       return false;
+}
+
+/* handle : for setting request on resources */
+bool handle_set_request(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep)
+{
+       //DBG("resource_uri [%s]", req_msg->resource_uri);
+
+       if (0 == strcmp(req_msg->resource_uri, RES_CAPABILITY_SWITCH_MAIN_0)) {
+               return handle_set_request_on_resource_capability_switch(req_msg, resp_rep);
+       }
+       if (0 == strcmp(req_msg->resource_uri, RES_CAPABILITY_DOORCONTROL_MAIN_0)) {
+               return handle_set_request_on_resource_capability_doorcontrol(req_msg, resp_rep);
+       }
+
+       ERR("not supported uri");
+       return false;
+}
+
+/* callback functions */
+bool handle_reset_request(void)
+{
+       DBG("Received a request for RESET.");
+       return true;
+}
+
+void handle_reset_result(bool result)
+{
+       DBG("Reset %s.\n", result ? "succeeded" : "failed");
+}
+
+bool handle_ownership_transfer_request(void)
+{
+       DBG("Received a request for Ownership-transfer.");
+       return true;
+}
+
+void handle_things_status_change(st_things_status_e things_status)
+{
+       DBG("Things status is changed: %d\n", things_status);
+}
+
+bool init_user()
+{
+       // initialize mutex
+       pthread_mutex_init(&mutex, NULL);
+
+       // create timer event function
+       sensor_event_timer = ecore_timer_add(SENSOR_EVENT_INTERVAL, _sensor_interval_event_cb, NULL);
+       if (!sensor_event_timer) {
+               ERR("Failed to add sensor_event_timer");
+               return false;
+       }
+
+       return true;
+}
+
+/* initialize */
+void init_thing()
+{
+       FN_CALL;
+       static bool binitialized = false;
+       if (binitialized) {
+               DBG("Already initialized!!");
+               return;
+       }
+
+       bool easysetup_complete = false;
+
+       char app_json_path[128] = {0,};
+       char *app_res_path = NULL;
+       char *app_data_path = NULL;
+
+       app_res_path = app_get_resource_path();
+       if (!app_res_path) {
+               ERR("app_res_path is NULL!!");
+               return;
+       }
+
+       app_data_path = app_get_data_path();
+       if (!app_data_path) {
+               ERR("app_data_path is NULL!!");
+               free(app_res_path);
+               return;
+       }
+
+       snprintf(app_json_path, sizeof(app_json_path), "%s/%s", app_res_path, JSON_PATH);
+
+       if (0 != st_things_set_configuration_prefix_path((const char *)app_res_path, (const char *)app_data_path)) {
+               ERR("st_things_set_configuration_prefix_path() failed!!");
+               free(app_res_path);
+               free(app_data_path);
+               return;
+       }
+
+       free(app_res_path);
+       free(app_data_path);
+
+       if (0 != st_things_initialize(app_json_path, &easysetup_complete)) {
+               ERR("st_things_initialize() failed!!");
+               return;
+       }
+
+       binitialized = true;
+       init_user();
+
+       DBG("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);
+
+       st_things_start();
+
+       FN_END;
+}
+
+static bool service_app_create(void *user_data)
+{
+       INFO("open I2C handle");
+       resource_open_i2c_handle();
+       return true;
+}
+
+static void service_app_terminate(void *user_data)
+{
+       // clear timer event
+       if (sensor_event_timer) {
+               ecore_timer_del(sensor_event_timer);
+               sensor_event_timer = NULL;
+       }
+
+       INFO("close I2C handle");
+       resource_close_i2c_handle();
+
+       int status = pthread_mutex_destroy(&mutex);
+       INFO("mutex destroy status = %d", status);
+}
+
+static void service_app_control(app_control_h app_control, void *user_data)
+{
+       if (app_control == NULL) {
+               ERR("app_control is NULL");
+               return;
+       }
+
+       init_thing();
+}
+
+int main(int argc, char *argv[])
+{
+       FN_CALL;
+
+       service_app_lifecycle_callback_s event_callback;
+
+       event_callback.create = service_app_create;
+       event_callback.terminate = service_app_terminate;
+       event_callback.app_control = service_app_control;
+
+       return service_app_main(argc, argv, &event_callback, NULL);
+}
diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c
new file mode 100644 (file)
index 0000000..d6a12ab
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 <unistd.h>
+#include <peripheral_io.h>
+#include "log.h"
+
+#define ARTIK_I2C_BUS          1
+
+#define GY302_ADDR                                     (0x23)  /* Address of GY30 light sensor */
+#define GY302_CONT_HIGH_RES_MODE       0x10    /* Start measurement at 11x resolution. Measurement time is approx 120mx */
+#define GY302_CONSTANT_NUM                     (1.2)   /* to convert sensor value to real lux value */
+
+peripheral_i2c_h g_i2c_h = NULL;
+int g_i2c_bus = ARTIK_I2C_BUS;
+int g_i2c_address = GY302_ADDR;
+
+int resource_open_i2c_handle(void)
+{
+       int ret;
+
+       // open i2c handle for I2C read/write
+       if ((ret = peripheral_i2c_open(g_i2c_bus, g_i2c_address, &g_i2c_h)) != 0 ) {
+               ERR("peripheral_i2c_open() failed!![%d]", ret);
+               return ret;
+       }
+
+    return ret;
+}
+
+int resource_close_i2c_handle(void)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       if (g_i2c_h != NULL) {
+               // close i2c handle
+               if ((ret = peripheral_i2c_close(g_i2c_h)) != 0 ) {
+                       ERR("peripheral_i2c_close() failed!![%d]", ret);
+                       return ret;
+               }
+               g_i2c_h = NULL;
+       }
+    return ret;
+}
+
+static void _reset_i2c_port(int reason)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       switch (reason) {
+               case PERIPHERAL_ERROR_RESOURCE_BUSY :
+               case PERIPHERAL_ERROR_IO_ERROR :
+               case PERIPHERAL_ERROR_TRY_AGAIN : {
+                       uint8_t data[10] = { 0, };
+
+                       // Reset 0000_0111 Reset Data register value.
+                       data[0] = 0x07; // //Reset : 0000_0111
+                       if ((ret = peripheral_i2c_write(g_i2c_h, data, 1)) != 0 ) {
+                               ERR("peripheral_i2c_write() failed!![%d]", ret);
+                               return;
+                       }
+               }
+                       break;
+               default :
+                       ERR("unknown reason [%d]", reason);
+                       break;
+       }
+}
+
+int resource_read_illuminance_sensor(uint16_t *out_value)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+       static bool continuous_read = false;
+
+       unsigned char buf[10] = { 0, };
+
+       if (g_i2c_h == NULL) {
+               // open i2c handle for I2C read/write
+               if ((ret = peripheral_i2c_open(g_i2c_bus, g_i2c_address, &g_i2c_h)) != PERIPHERAL_ERROR_NONE ) {
+                       ERR("peripheral_i2c_open() failed!![%d]", ret);
+                       return ret;
+               }
+       }
+
+       // set data for mode register
+       if (continuous_read == false) {
+               // Continuously H-Resolution Mode 0001_0000 Start measurement at 1lx resolution.
+               buf[0] = GY302_CONT_HIGH_RES_MODE;
+               // write mode command to sensor
+               if ((ret = peripheral_i2c_write(g_i2c_h, buf, 1)) != PERIPHERAL_ERROR_NONE) {
+                       ERR("peripheral_i2c_write() failed!![%d]", ret);
+                       return ret;
+               }
+               // Wait a few moments to wake up
+               // Measurement Time is typically 120ms.
+               usleep(120 * 1000);             // wait 120 ms
+
+               continuous_read = true;
+       }
+
+       // Read two bytes from the sensor, which are low and high parts of the sensor
+       if ((ret = peripheral_i2c_read(g_i2c_h, buf, 2)) != PERIPHERAL_ERROR_NONE) {
+               ERR("peripheral_i2c_read() failed!![%d]", ret);
+
+               _reset_i2c_port(ret);
+               return ret;
+       }
+
+       // Convert raw value to lux value
+       *out_value = (buf[0] << 8 | buf[1]) / GY302_CONSTANT_NUM; // Just Sum High 8bit and Low 8bit, divide by 1.2
+
+       return ret;
+}
+
+
+
diff --git a/src/resource/resource_servo_motor.c b/src/resource/resource_servo_motor.c
new file mode 100644 (file)
index 0000000..823ca4d
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 "st_things.h"
+#include "log.h"
+#include "resource/resource_servo_motor.h"
+
+#define ARTIK_PWM_CHIPID       0
+#define ARTIK_PWM_PIN          2
+
+#define MILLI_SECOND   (1000000)
+
+peripheral_pwm_h g_pwm_h = NULL;
+
+static int _get_duty_cycle(door_state_e mode, int *duty_cycle)
+{
+       if ((mode == DOOR_STATE_OPENED) || (mode == DOOR_STATE_OPENING))
+               *duty_cycle = 2 * MILLI_SECOND;         // CLOCKWISE
+       else if ((mode == DOOR_STATE_CLOSE) || (mode == DOOR_STATE_CLOSING))
+               *duty_cycle = 1 * MILLI_SECOND;         // COUNTER-CLOCKWISE
+       else {
+               ERR("get_duty_cycle unknown mode=[%d]", mode);
+               return -1;
+       }
+
+       INFO("get_duty_cycle mode=[%d:%s] : duty_cycle [%d] ms",
+                                                       mode,
+                                                       mode == DOOR_STATE_OPENED ? "OPENED " :
+                                                       (mode == DOOR_STATE_CLOSE ? "CLOSE  " :
+                                                       (mode == DOOR_STATE_CLOSING ? "CLOSING" : "OPENING")),
+                                                       *duty_cycle/(1000));
+
+       return 0;
+}
+peripheral_error_e resource_motor_driving(door_state_e mode)
+{
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       int chip = ARTIK_PWM_CHIPID;    // Chip 0
+       int pin  = ARTIK_PWM_PIN;               // Pin 2
+
+       int period = 20 * MILLI_SECOND;
+       int duty_cycle = 0;
+       bool enable = true;
+
+       ret = _get_duty_cycle(mode, &duty_cycle);
+       if (ret != 0) {
+               ERR("_get_duty_cycle unknown mode=[%d]", mode);
+               return PERIPHERAL_ERROR_INVALID_PARAMETER;
+       }
+
+       if (g_pwm_h == NULL){
+               // Opening a PWM Handle : The chip and pin parameters required for this function must be set
+               if ((ret = peripheral_pwm_open(chip, pin, &g_pwm_h)) != PERIPHERAL_ERROR_NONE ) {
+                       ERR("peripheral_pwm_open() failed!![%d]", ret);
+                       return ret;
+               }
+       }
+
+       // Setting the Period : sets the period to 20 milliseconds. The unit is nanoseconds
+       if ((ret = peripheral_pwm_set_period(g_pwm_h, period)) != PERIPHERAL_ERROR_NONE) {
+               ERR("peripheral_pwm_set_period() failed!![%d]", ret);
+               return ret;
+       }
+
+       // Setting the Duty Cycle : sets the duty cycle to 1~2 milliseconds. The unit is nanoseconds
+       if ((ret = peripheral_pwm_set_duty_cycle(g_pwm_h, duty_cycle)) != PERIPHERAL_ERROR_NONE) {
+               ERR("peripheral_pwm_set_duty_cycle() failed!![%d]", ret);
+               return ret;
+       }
+
+       // Enabling Repetition
+       if ((ret = peripheral_pwm_set_enabled(g_pwm_h, enable)) != PERIPHERAL_ERROR_NONE) {
+               ERR("peripheral_pwm_set_enabled() failed!![%d]", ret);
+               return ret;
+       }
+
+       if (g_pwm_h != NULL) {
+               // Closing a PWM Handle : close a PWM handle that is no longer used,
+               if ((ret = peripheral_pwm_close(g_pwm_h)) != PERIPHERAL_ERROR_NONE ) {
+                       ERR("peripheral_pwm_close() failed!![%d]", ret);
+                       return ret;
+               }
+               g_pwm_h = NULL;
+       }
+
+       return ret;
+}
diff --git a/tizen-manifest.xml b/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..95f81c2
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="4.0" package="org.example.luxmeter" version="1.0.0">
+    <profile name="iot-headless"/>
+    <service-application appid="org.example.luxmeter" exec="luxmeter" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp">
+        <label>luxmeter</label>
+        <icon>luxmeter.png</icon>
+        <background-category value="background-network"/>
+    </service-application>
+    <privileges>
+        <privilege>http://tizen.org/privilege/network.get</privilege>
+        <privilege>http://tizen.org/privilege/network.set</privilege>
+        <privilege>http://tizen.org/privilege/internet</privilege>
+        <privilege>http://tizen.org/privilege/alarm.set</privilege>
+        <privilege>http://tizen.org/privilege/network.profile</privilege>
+        <privilege>http://tizen.org/privilege/peripheralio</privilege>
+    </privileges>
+</manifest>