From c2d1b8b117941b881946e0f74452a9b0009f4017 Mon Sep 17 00:00:00 2001 From: Denis Kimcherenko Date: Tue, 29 Dec 2015 15:39:45 +0200 Subject: [PATCH 1/4] APP-22: Implemented GPIO demo on Artik 5. --- gpiocontrol/assembly/src-artik5.xml | 32 +++ gpiocontrol/pom.xml | 45 ++-- .../resources/gpio_slave_artik5/icon.png | Bin 0 -> 4584 bytes gpiocontrol/resources/projects.xml | 19 ++ gpiocontrol/source/artik5/CMakeLists.txt | 83 ++++++++ gpiocontrol/source/artik5/README | 47 +++++ gpiocontrol/source/artik5/build.sh | 135 ++++++++++++ .../source/artik5/libs/kaa/PUT_SDK_HERE | 0 gpiocontrol/source/artik5/src/KaaDemo.cpp | 196 ++++++++++++++++++ .../gpiocontrol/GPIOcontrolDemoBuilder.java | 12 +- 10 files changed, 542 insertions(+), 27 deletions(-) create mode 100755 gpiocontrol/assembly/src-artik5.xml create mode 100644 gpiocontrol/resources/gpio_slave_artik5/icon.png create mode 100644 gpiocontrol/source/artik5/CMakeLists.txt create mode 100644 gpiocontrol/source/artik5/README create mode 100755 gpiocontrol/source/artik5/build.sh create mode 100644 gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE create mode 100644 gpiocontrol/source/artik5/src/KaaDemo.cpp diff --git a/gpiocontrol/assembly/src-artik5.xml b/gpiocontrol/assembly/src-artik5.xml new file mode 100755 index 000000000..44bca4410 --- /dev/null +++ b/gpiocontrol/assembly/src-artik5.xml @@ -0,0 +1,32 @@ + + + + gpio-src-artik5 + + tar.gz + + false + + + ${project.basedir}/source/artik5 + true + gpio-artik5-client + + + diff --git a/gpiocontrol/pom.xml b/gpiocontrol/pom.xml index effc3a0c0..b54b4c278 100644 --- a/gpiocontrol/pom.xml +++ b/gpiocontrol/pom.xml @@ -60,8 +60,9 @@ ${project.basedir}/assembly/src.xml - assembly/src-cc32xx.xml - assembly/src-esp.xml + ${project.basedir}/assembly/src-cc32xx.xml + ${project.basedir}/assembly/src-esp.xml + ${project.basedir}/assembly/src-artik5.xml @@ -74,26 +75,26 @@ - - maven-resources-plugin - - - copy-resources - generate-resources - - copy-resources - - - ${project.build.directory}/generated-resources/demo/gpiocontrol - - - resources - - - - - - + + maven-resources-plugin + + + copy-resources + generate-resources + + copy-resources + + + ${project.build.directory}/generated-resources/demo/gpiocontrol + + + resources + + + + + + diff --git a/gpiocontrol/resources/gpio_slave_artik5/icon.png b/gpiocontrol/resources/gpio_slave_artik5/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..53d6bcca6c861ffcf4c515288ed26856e5674e96 GIT binary patch literal 4584 zcmYjVcUTi!(_dofA|-f1q=k+Mgbo3uhTcVrNC{0YU3!&(NHfxlC{2nKg#bd3CQ%WP zW{@fv5J7^p(0h5~_x*F9eP-v`vuF0q&Y3gwn@Kh^(Pg0HpaTGaL0?bXg3M8WiH3@N z|8xsEKxW|k8pav`(2z!dilihz^SbC+7z03r5P4oa0383FzYGAuFaTI_0s#0k0ATYk zXfszKzo2q9)YS$q{$3@Wm09EwT7Ny;KmeeJ{3QzDc>z0lkUB`;7(qQpOAk@L_LjB% z1OS*C^|duD!=~2@|4p~NliM3}@P06lzPYrKl=3EpfK@GtYaCrc*NPjIiO7ajl|iHk zJP~|C&Jpf>LZ$bUmy43FMF_cruinEE9%#sGa3EMInQaldr8cz;H8*zLmfAyab=;`- ztu76SB)Per^Q{Euy;Em*_;w6Ey3+FKGYVI|ItOwQtS?!A%<}njm{V-`pB+Qfhg(pT zK1VGZUTqZe%S6pJEnNBvLV}G)ibC>*L+S5Oqg@HUUL7&teW~p5kJwTB6X;Kj?Jt&Q& z#(+wTMh(6AYap3;^E*$af)sziXtOno)e`L^FGrGmE!snzczz^$R$ZEr(346^P|6Ac zCc}OD1V`v(leX#5BMUSp9r?KURjFf!cqjbz7c8`ES-tw}KTNjE#HXnDOJ97oSLxXl zRz8~pHSM)Gl7KjfpO9iWyys3C(|rA8ZtTC#m$_o4g1}2}l9t zWOQ_tN-m*iVD|~BYif85w|tu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ymGJgHHdxb)TuZ<{g3 z;bWU_P-}3z>UlRX_%CpI7~@gO3G3i z2A5HU%SnsDWZ*EE)0!%|-SHm*A3xWB-NXMYAf*78l7q|2|G&WFv3fgpio-esp-client/libs/kaa + + GPIO control Artik 5 + GPIO control Artik 5 app that demonstrates capabilities of the Kaa Event subsystem +
+ Installation +First, read our documentation article on how to integrate Kaa with Artik 5. +

Playing around

+After you successfully installed this app on your Artik 5 device, go to Android "GPIO control" Sandbox app and follow the steps described there. + ]]> +
+ CPP + EVENT USER_VERIFIER + REGULAR + cpp/gpio-artik5-client.tar.gz + gpio-artik5-client + gpio-artik5-client/libs/kaa + +
diff --git a/gpiocontrol/source/artik5/CMakeLists.txt b/gpiocontrol/source/artik5/CMakeLists.txt new file mode 100644 index 000000000..8d585a089 --- /dev/null +++ b/gpiocontrol/source/artik5/CMakeLists.txt @@ -0,0 +1,83 @@ +# +# Copyright 2014-2015 CyberVision, Inc. +# +# 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. +# + +cmake_minimum_required(VERSION 2.8.8) + +project (Cpp-SDK-event-sample) +enable_language(CXX) + +# Path to CMake's scripts. +set(CMAKE_MODULE_PATH + ${CMAKE_MODULE_PATH} + ${CMAKE_CURRENT_SOURCE_DIR}/libs/kaa/Modules + ) + +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wno-unused-parameter -Wno-type-limits") +endif() + +if (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +endif() + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -stdlib=libc++") +endif() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEMO_ACCESS_TOKEN='\"${DEMO_ACCESS_TOKEN}\"' ") + +find_package (Boost 1.55 REQUIRED COMPONENTS log system) +find_package (Avro REQUIRED) +find_package (Botan REQUIRED) + +if (WIN32 AND NOT CYGWIN AND NOT MSYS) +add_definitions (/EHs) +add_definitions ( + -DBOOST_REGEX_DYN_LINK + -DBOOST_FILESYSTEM_DYN_LINK + -DBOOST_SYSTEM_DYN_LINK + -DBOOST_PROGRAM_OPTIONS_DYN_LINK + -DBOOST_LOG_DYN_LINK + -DBOOST_ALL_NO_LIB) +endif() + +include_directories(${Boost_INCLUDE_DIRS} + ${AVRO_INCLUDE_DIRS} + ${BOTAN_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}/libs/kaa) + +link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build) + +set (SAMPLE_SOURCE_FILES + src/KaaDemo.cpp +) + +add_executable(${APP_NAME} ${SAMPLE_SOURCE_FILES}) + +if (CMAKE_COMPILER_IS_GNUCXX) + target_link_libraries(${APP_NAME} kaacpp_s ${BOTAN_LIBRARY} ${AVRO_LIBRARIES} ${Boost_LIBRARIES} pthread) +endif() + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + target_link_libraries(${APP_NAME} kaacpp_s ${BOTAN_LIBRARY} ${AVRO_LIBRARIES} ${Boost_LIBRARIES}) +endif() + +if (MSVC) + target_link_libraries(${APP_NAME} kaacpp_s ${BOTAN_LIBRARY} ${AVRO_LIBRARIES} ${Boost_LIBRARIES} dbghelp) +endif() diff --git a/gpiocontrol/source/artik5/README b/gpiocontrol/source/artik5/README new file mode 100644 index 000000000..f7cce5fc3 --- /dev/null +++ b/gpiocontrol/source/artik5/README @@ -0,0 +1,47 @@ +# +# Copyright 2014-2015 CyberVision, Inc. +# +# 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. +# + +************************************ +PREFACE +************************************ + +This demo application illustrates the Kaa event feature using the Kaa C++ SDK. +To read more about the event feature, visit https://docs.kaaproject.org/display/KAA/Events. + +************************************ +INSTALLATION +************************************ + +To run the demo application, do the following: + +1. Install third-party libraries to build the Kaa C++ SDK. +Follow https://docs.kaaproject.org/display/KAA/Third-party+components#Third-partycomponents-Kaaendpoint to see the full +list of third-party dependencies for the Kaa C++ SDK. +2. Download and install the Kaa sandbox (https://docs.kaaproject.org/display/KAA/sandbox). +3. Before generating the C++ SDK, make sure that you provided the SDK with a user verifier and the following fields for the event class family were specified as follows: + Name: ThermostatEventClassFamily + Namespace: org.kaaproject.kaa.schema.sample.event.thermo + Class name: ThermostatEventClassFamily + (The Avro event schema required for the demo application is located in the 'avro' directory). +5. Use the build.sh script to build and run the demo application (the 'deploy' option). + +************************************ +ABOUT +************************************ + +If you are interested in the Kaa IoT framework and want to read more about it, visit our official site +http://www.kaaproject.org/. The documentation can be found at https://docs.kaaproject.org/display/KAA/Kaa+IoT+Platform+Home. + diff --git a/gpiocontrol/source/artik5/build.sh b/gpiocontrol/source/artik5/build.sh new file mode 100755 index 000000000..a8c545d39 --- /dev/null +++ b/gpiocontrol/source/artik5/build.sh @@ -0,0 +1,135 @@ +# +# Copyright 2014-2015 CyberVision, Inc. +# +# 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. +# + +#!/bin/bash + +RUN_DIR=`pwd` + +function help { + echo "Choose one of the following: {build|run|deploy|clean}" + echo "Supported platforms: x86-64, edison" + exit 1 +} + +if [ $# -eq 0 ] +then + help +fi + +APP_NAME="demo_client" +PROJECT_HOME=$(pwd) +BUILD_DIR="build" +LIBS_PATH="libs" +KAA_LIB_PATH="$LIBS_PATH/kaa" +KAA_C_LIB_HEADER_PATH="$KAA_LIB_PATH/src" +KAA_CPP_LIB_HEADER_PATH="$KAA_LIB_PATH/kaa" +KAA_SDK_TAR="kaa-client*.tar.gz" +KAA_TOOLCHAIN_PATH_SDK="-DCMAKE_TOOLCHAIN_FILE=$RUN_DIR/libs/kaa/toolchains/artik.cmake" + +if [ -z ${DEMO_ACCESS_TOKEN} ]; then + DEMO_ACCESS_TOKEN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1) +fi +echo "===================================" +echo " ACCESS TOKEN: " $DEMO_ACCESS_TOKEN +echo "===================================" + +function build_thirdparty { + if [[ ! -d "$KAA_C_LIB_HEADER_PATH" && ! -d "$KAA_CPP_LIB_HEADER_PATH" ]] + then + KAA_SDK_TAR_NAME=$(find $PROJECT_HOME -iname $KAA_SDK_TAR) + + if [ -z "$KAA_SDK_TAR_NAME" ] + then + echo "Please, put the generated C/C++ SDK tarball into the libs/kaa folder and re-run the script." + exit 1 + fi + + mkdir -p $KAA_LIB_PATH && + tar -zxf $KAA_SDK_TAR_NAME -C $KAA_LIB_PATH + fi + + if [ ! -d "$KAA_LIB_PATH/$BUILD_DIR" ] + then + cd $KAA_LIB_PATH && + chmod 755 ./avrogen.sh && + ./avrogen.sh && + mkdir -p $BUILD_DIR && cd $BUILD_DIR && + cmake -DKAA_DEBUG_ENABLED=1 \ + -DKAA_WITHOUT_LOGGING=1 \ + -DKAA_WITHOUT_CONFIGURATION=1 \ + -DKAA_WITHOUT_NOTIFICATIONS=1 \ + -DKAA_WITHOUT_OPERATION_LONG_POLL_CHANNEL=1 \ + -DKAA_WITHOUT_OPERATION_HTTP_CHANNEL=1 \ + -DKAA_MAX_LOG_LEVEL=3 \ + $KAA_TOOLCHAIN_PATH_SDK \ + .. + fi + + cd "$PROJECT_HOME/$KAA_LIB_PATH/$BUILD_DIR" + make -j4 && + cd $PROJECT_HOME +} + +function build_app { + cd $PROJECT_HOME && + mkdir -p "$PROJECT_HOME/$BUILD_DIR" && + cp "$KAA_LIB_PATH/$BUILD_DIR/"libkaa* "$PROJECT_HOME/$BUILD_DIR/" && + cd $BUILD_DIR && + cmake -DAPP_NAME=$APP_NAME $KAA_TOOLCHAIN_PATH_SDK -DDEMO_ACCESS_TOKEN=$DEMO_ACCESS_TOKEN .. + make +} + +function clean { + rm -rf "$KAA_LIB_PATH/$BUILD_DIR" + rm -rf "$PROJECT_HOME/$BUILD_DIR" +} + +function run { + cd "$PROJECT_HOME/$BUILD_DIR" + ./$APP_NAME +} + +for cmd in $@ +do + +case "$cmd" in + build) + build_thirdparty && + build_app + ;; + + run) + run + ;; + + deploy) + clean + build_thirdparty + build_app + run + ;; + + clean) + clean + ;; + + *) + help + ;; +esac + +done + diff --git a/gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE b/gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE new file mode 100644 index 000000000..e69de29bb diff --git a/gpiocontrol/source/artik5/src/KaaDemo.cpp b/gpiocontrol/source/artik5/src/KaaDemo.cpp new file mode 100644 index 000000000..86eac3119 --- /dev/null +++ b/gpiocontrol/source/artik5/src/KaaDemo.cpp @@ -0,0 +1,196 @@ +/* + * Copyright 2014-2015 CyberVision, Inc. + * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace kaa; + +#define HIGH 1 +#define LOW 0 +#define INPUT 1 +#define OUTPUT 0 + +#define LED_1 121 +#define LED_2 122 + +bool digitalPinMode(int pin, int dir) +{ + FILE *fd = nullptr; + char fName[128]; + + //Exporting the pin to be used + if(( fd = fopen("/sys/class/gpio/export", "w")) == NULL) { + printf("Error: unable to export pin\n"); + return false; + } + + fprintf(fd, "%d\n", pin); + fclose(fd); + + // Setting direction of the pin + sprintf(fName, "/sys/class/gpio/gpio%d/direction", pin); + if ((fd = fopen(fName, "w")) == NULL) { + printf("Error: can't open pin direction\n"); + return false; + } + + if (dir == OUTPUT) { + fprintf(fd, "out\n"); + } else { + fprintf(fd, "in\n"); + } + + fclose(fd); + return true; +} + + +int digitalRead(int pin) +{ + FILE *fd = nullptr; + char fName[128]; + char val[2]; + + //Open pin value file + sprintf(fName, "/sys/class/gpio/gpio%d/value", pin); + if ((fd = fopen(fName, "r")) == NULL) { + printf("Error: can't open pin value\n"); + return false; + } + + fgets(val, 2, fd); + fclose(fd); + + return atoi(val); +} + + +bool digitalWrite(int pin, int val) +{ + FILE *fd = nullptr; + char fName[128]; + + // Open pin value file + sprintf(fName, "/sys/class/gpio/gpio%d/value", pin); + if ((fd = fopen(fName, "w")) == NULL) { + printf("Error: can't open pin value\n"); + return false; + } + + if (val == HIGH) { + fprintf(fd, "1\n"); + } else { + fprintf(fd, "0\n"); + } + + fclose(fd); + return true; +} + +class ECFListener: public RemoteControlECF::RemoteControlECFListener +{ +public: + ECFListener(RemoteControlECF &rm): remote(rm) + { + nsRemoteControlECF::GpioStatus status; + status.id = LED_1; + status.status = false; + leds.push_back(status); + status.id = LED_2; + leds.push_back(status); + } + + void onEvent(const nsRemoteControlECF::DeviceInfoRequest& event, const std::string& source) + { + nsRemoteControlECF::DeviceInfoResponse response; + + response.deviceName = "artik"; + response.model = "model_5"; + response.gpioStatus = leds; + + remote.sendEvent(response); + } + + void onEvent(const nsRemoteControlECF::GpioToggleRequest& event, const std::string& source) + { + if (event.gpio.status) { + digitalWrite(event.gpio.id, 1); + setLedStatus(event.gpio.id, true); + } else { + digitalWrite(event.gpio.id, 0); + setLedStatus(event.gpio.id, false); + } + } + +protected: + RemoteControlECF &remote; + std::vector leds; + +private: + void setLedStatus(int id, bool status) + { + for (std::size_t i = 0; i < leds.size(); ++i) + if (leds[i].id == id) { + leds[i].status = status; + return; + } + } +}; + +int main() +{ + digitalPinMode(LED_1, OUTPUT); + digitalPinMode(LED_2, OUTPUT); + + digitalWrite(LED_1, 0); + digitalWrite(LED_2, 0); + + /* + * Initialize the Kaa endpoint. + */ + auto kaaClient = Kaa::newClient(); + + ECFListener ecfListener(kaaClient->getEventFamilyFactory().getRemoteControlECF()); + kaaClient->getEventFamilyFactory().getRemoteControlECF().addEventFamilyListener(ecfListener); + kaaClient->setEndpointAccessToken(DEMO_ACCESS_TOKEN); + + /* + * Run the Kaa endpoint. + */ + kaaClient->start(); + + + while (true) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + /* + * Stop the Kaa endpoint. + */ + kaaClient->stop(); + + return 0; +} diff --git a/gpiocontrol/src/main/java/org/kaaproject/kaa/examples/gpiocontrol/GPIOcontrolDemoBuilder.java b/gpiocontrol/src/main/java/org/kaaproject/kaa/examples/gpiocontrol/GPIOcontrolDemoBuilder.java index e2784c2dd..5c5efb449 100644 --- a/gpiocontrol/src/main/java/org/kaaproject/kaa/examples/gpiocontrol/GPIOcontrolDemoBuilder.java +++ b/gpiocontrol/src/main/java/org/kaaproject/kaa/examples/gpiocontrol/GPIOcontrolDemoBuilder.java @@ -38,12 +38,13 @@ @KaaDemoBuilder public class GPIOcontrolDemoBuilder extends AbstractDemoBuilder { - + private static final Logger logger = LoggerFactory.getLogger(GPIOcontrolDemoBuilder.class); private static final String GPIO_MASTER_ID = "gpio_master"; private static final String GPIO_CC32XX_ID = "gpio_slave_cc"; private static final String GPIO_ESP8266_ID = "gpio_slave_esp"; + private static final String GPIO_ARTIK5_ID = "gpio_slave_artik5"; private static final String REMOTE_CONTROL_ECF_NAME = "Remote Control Event Class Family"; @@ -63,18 +64,18 @@ public class GPIOcontrolDemoBuilder extends AbstractDemoBuilder { defaultSlaveAefMap.put("org.kaaproject.kaa.examples.gpiocontrol.GpioToggleRequest", ApplicationEventAction.SINK); } - private Map projectsSdkMap = new HashMap<>(); + private final Map projectsSdkMap = new HashMap<>(); public GPIOcontrolDemoBuilder() { super("demo/gpiocontrol"); } - + @Override protected void buildDemoApplicationImpl(AdminClient client) throws Exception { - + logger.info("Loading 'GPIO control Demo Application' data..."); - + loginTenantAdmin(client); Map ecfMap = new HashMap<>(); @@ -134,6 +135,7 @@ private void configureSlaveApp(AdminClient client, projectsSdkMap.put(GPIO_CC32XX_ID, sdkProperties); //TODO maybe just duplicate this line with "ESP8266 slave id"? projectsSdkMap.put(GPIO_ESP8266_ID, sdkProperties); + projectsSdkMap.put(GPIO_ARTIK5_ID, sdkProperties); } private EventClassFamilyDto addEventClassFamily(AdminClient client, From dd00cbfa66e9a1f7a4cbf320a40f040405c235fe Mon Sep 17 00:00:00 2001 From: Denis Kimcherenko Date: Tue, 29 Dec 2015 17:18:46 +0200 Subject: [PATCH 2/4] APP-17: Update C++ demo aplications. Use new API to create endpoint instances. --- configurationdemo/source/cpp/src/KaaDemo.cpp | 61 ++++++++++++------- datacollectiondemo/source/cpp/src/KaaDemo.cpp | 56 ++++++++--------- eventdemo/source/cpp/src/KaaDemo.cpp | 34 ++++++----- notificationdemo/source/cpp/src/KaaDemo.cpp | 54 ++++++++++------ 4 files changed, 118 insertions(+), 87 deletions(-) diff --git a/configurationdemo/source/cpp/src/KaaDemo.cpp b/configurationdemo/source/cpp/src/KaaDemo.cpp index e4bcbcb25..1b1efe4a4 100755 --- a/configurationdemo/source/cpp/src/KaaDemo.cpp +++ b/configurationdemo/source/cpp/src/KaaDemo.cpp @@ -13,24 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include -#include + #include #include - -#include #include #include -#include - -#include - using namespace kaa; -using std::cout; -using std::endl; - const char savedConfig[] = "saved_config.cfg"; class UserConfigurationReceiver : public IConfigurationReceiver { @@ -38,10 +30,10 @@ class UserConfigurationReceiver : public IConfigurationReceiver { void displayConfiguration(const KaaRootConfiguration &configuration) { if (!configuration.AddressList.is_null()) { - cout << "Configuration body:" << endl; + std::cout << "Configuration body:" << std::endl; auto links = configuration.AddressList.get_array(); for (auto& e : links) { - cout << e.label << " - " << e.url << endl; + std::cout << e.label << " - " << e.url << std::endl; } } } @@ -53,19 +45,42 @@ class UserConfigurationReceiver : public IConfigurationReceiver { int main() { - Kaa::init(); - cout << "Configuration demo started" << endl; - cout << "--= Press Enter to exit =--" << endl; - IKaaClient& kaaClient = Kaa::getKaaClient(); - // Set up a configuration subsystem. + std::cout << "Configuration demo started" << std::endl; + std::cout << "--= Press Enter to exit =--" << std::endl; + + /* + * Initialize the Kaa endpoint. + */ + auto kaaClient = Kaa::newClient(); + + /* + * Set up a configuration subsystem. + */ IConfigurationStoragePtr storage(std::make_shared(savedConfig)); - kaaClient.setConfigurationStorage(storage); + kaaClient->setConfigurationStorage(storage); + + /* + * Set configuration update receiver. + */ UserConfigurationReceiver receiver; - kaaClient.addConfigurationListener(receiver); - Kaa::start(); - // Waiting for Enter key pressed before exiting. + kaaClient->addConfigurationListener(receiver); + + /* + * Run the Kaa endpoint. + */ + kaaClient->start(); + + /* + * Wait for the Enter key before exiting. + */ std::cin.get(); - Kaa::stop(); - cout << "Configuration demo stopped" << endl; + + /* + * Stop the Kaa endpoint. + */ + kaaClient->stop(); + + std::cout << "Configuration demo stopped" << std::endl; + return 0; } diff --git a/datacollectiondemo/source/cpp/src/KaaDemo.cpp b/datacollectiondemo/source/cpp/src/KaaDemo.cpp index 96d1d68dc..67ef4695e 100755 --- a/datacollectiondemo/source/cpp/src/KaaDemo.cpp +++ b/datacollectiondemo/source/cpp/src/KaaDemo.cpp @@ -16,56 +16,44 @@ #include -#include #include #include #include #include -#include +#include #include using namespace kaa; -// The default strategy uploads logs after either a threshold logs count -// or a threshold logs size has been reached. -// The following custom strategy uploads every log record as soon as it is created. -class LogUploadStrategy : public DefaultLogUploadStrategy { -public: - LogUploadStrategy() : DefaultLogUploadStrategy() {} - - virtual LogUploadStrategyDecision isUploadNeeded(ILogStorageStatus& status) - { - if (status.getRecordsCount() >= 1) { - return LogUploadStrategyDecision::UPLOAD; - } - return LogUploadStrategyDecision::NOOP; - } -}; - /* * A demo application that shows how to use the Kaa logging API. */ int main() { - const std::size_t LOGS_TO_SEND_COUNT = 5; - std::cout << "Data collection demo started" << std::endl; std::cout << "--= Press Enter to exit =--" << std::endl; - //Create a Kaa client with the Kaa desktop context. - Kaa::init(); - IKaaClient& kaaClient = Kaa::getKaaClient(); + const std::size_t LOGS_TO_SEND_COUNT = 5; + + /* + * Initialize the Kaa endpoint. + */ + auto kaaClient = Kaa::newClient(); - // Set a custom strategy for uploading logs. - kaaClient.setLogUploadStrategy(std::make_shared()); + /* + * Set a custom strategy for uploading logs. + */ + kaaClient->setLogUploadStrategy(std::make_shared(1)); - // Start the Kaa client and connect it to the Kaa server. - Kaa::start(); + /* + * Run the Kaa endpoint. + */ + kaaClient->start(); // Send LOGS_TO_SEND_COUNT logs in a loop. - size_t logNumber = 0; + std::size_t logNumber = 0; while (logNumber++ < LOGS_TO_SEND_COUNT) { KaaUserLogRecord logRecord; logRecord.level = kaa_log::Level::KAA_INFO; @@ -74,14 +62,18 @@ int main() std::cout << "Going to send " << logNumber << "th record" << std::endl; - kaaClient.addLogRecord(logRecord); + kaaClient->addLogRecord(logRecord); } - // Wait for the Enter key before exiting. + /* + * Wait for the Enter key before exiting. + */ std::cin.get(); - // Stop the Kaa client and release all the resources which were in use. - Kaa::stop(); + /* + * Stop the Kaa endpoint. + */ + kaaClient->stop(); std::cout << "Data collection demo stopped" << std::endl; diff --git a/eventdemo/source/cpp/src/KaaDemo.cpp b/eventdemo/source/cpp/src/KaaDemo.cpp index f6a7ae855..08bccf9da 100755 --- a/eventdemo/source/cpp/src/KaaDemo.cpp +++ b/eventdemo/source/cpp/src/KaaDemo.cpp @@ -16,14 +16,15 @@ #include -#include +#include #include #include #include #include #include -#include +#include +#include using namespace kaa; @@ -136,33 +137,38 @@ class UserAttachCallback: public IUserAttachCallback { int main() { - const char * const KAA_USER_ID = "user@email.com"; - const char * const KAA_USER_ACCESS_TOKEN = "token"; + std::cout << "Event demo started" << std::endl; + std::cout << "--= Press Enter to exit =--" << std::endl; + + const std::string KAA_USER_ID("user@email.com"); + const std::string KAA_USER_ACCESS_TOKEN("token"); /* * Initialize the Kaa endpoint. */ - Kaa::init(); - IKaaClient& kaaClient = Kaa::getKaaClient(); - + auto kaaClient = Kaa::newClient(); /* * Run the Kaa endpoint. */ - Kaa::start(); + kaaClient->start(); - ThermoEventClassFamilyListener thermoListener(kaaClient.getEventFamilyFactory()); + ThermoEventClassFamilyListener thermoListener(kaaClient->getEventFamilyFactory()); - kaaClient.getEventFamilyFactory().getThermostatEventClassFamily().addEventFamilyListener(thermoListener); - kaaClient.attachUser(KAA_USER_ID, KAA_USER_ACCESS_TOKEN, std::make_shared(kaaClient)); + kaaClient->getEventFamilyFactory().getThermostatEventClassFamily().addEventFamilyListener(thermoListener); + kaaClient->attachUser(KAA_USER_ID, KAA_USER_ACCESS_TOKEN, std::make_shared(*kaaClient)); - while (1) - std::this_thread::sleep_for(std::chrono::seconds(1)); + /* + * Wait for the Enter key before exiting. + */ + std::cin.get(); /* * Stop the Kaa endpoint. */ - Kaa::stop(); + kaaClient->stop(); + + std::cout << "Event demo stopped" << std::endl; return 0; } diff --git a/notificationdemo/source/cpp/src/KaaDemo.cpp b/notificationdemo/source/cpp/src/KaaDemo.cpp index 3de750d04..3e26e706a 100755 --- a/notificationdemo/source/cpp/src/KaaDemo.cpp +++ b/notificationdemo/source/cpp/src/KaaDemo.cpp @@ -14,7 +14,6 @@ * limitations under the License. */ - #include #include @@ -92,34 +91,53 @@ int main() std::cout << "Notification demo started" << std::endl; std::cout << "--= Press Enter to exit =--" << std::endl; - // Initialize the Kaa endpoint. - Kaa::init(); - IKaaClient& kaaClient = Kaa::getKaaClient(); + /* + * Initialize the Kaa endpoint. + */ + auto kaaClient = Kaa::newClient(); - // Add the listener which receives the list of available topics. - std::unique_ptr topicListListener(new BasicNotificationTopicListListener(kaaClient)); - kaaClient.addTopicListListener(*topicListListener); + /* + * Add the listener which receives the list of available topics. + */ + std::unique_ptr topicListListener(new BasicNotificationTopicListListener(*kaaClient)); + kaaClient->addTopicListListener(*topicListListener); - // Add the listener which receives notifications on all topics. + /* + * Add the listener which receives notifications on all topics. + */ std::unique_ptr commonNotificationListener(new BasicNotificationListener); - kaaClient.addNotificationListener(*commonNotificationListener); + kaaClient->addNotificationListener(*commonNotificationListener); - // Start the Kaa client and connect it to the Kaa server. - Kaa::start(); + /* + * Run the Kaa endpoint. + */ + kaaClient->start(); - // Get available notification topics. - auto availableTopics = kaaClient.getTopics(); + /* + * Get available notification topics. + */ + auto availableTopics = kaaClient->getTopics(); - // List the obtained notification topics. + /* + * List the obtained notification topics. + */ showTopicList(availableTopics); + /* + * Wait for the Enter key before exiting. + */ std::cin.get(); - // Remove the listener which receives the list of available topics. - kaaClient.removeTopicListListener(*topicListListener); + /* + * Remove the listener which receives the list of available topics. + */ + kaaClient->removeTopicListListener(*topicListListener); + + /* + * Stop the Kaa endpoint. + */ + kaaClient->stop(); - // Stop the Kaa client and release all the resources which were in use. - Kaa::stop(); std::cout << "Notification demo stopped" << std::endl; return 0; From 9a5be1efa966865695238f65e6697397498a0873 Mon Sep 17 00:00:00 2001 From: Denis Kimcherenko Date: Tue, 29 Dec 2015 17:34:15 +0200 Subject: [PATCH 3/4] APP-22: Fix RAT warning. --- gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE diff --git a/gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE b/gpiocontrol/source/artik5/libs/kaa/PUT_SDK_HERE deleted file mode 100644 index e69de29bb..000000000 From b17d5a1e72e96a9d9f9851de6573af1c683edd50 Mon Sep 17 00:00:00 2001 From: Andrew Shvayka Date: Tue, 29 Dec 2015 17:54:50 +0200 Subject: [PATCH 4/4] APP-21: Implementation --- citylights-controller/assembly/src-java.xml | 2 +- configurationdemo/assembly/src-java.xml | 2 +- datacollectiondemo/assembly/src-java.xml | 2 +- eventdemo/assembly/src-java.xml | 2 +- notificationdemo/assembly/src-java.xml | 2 +- twitterled/twitterboard/assembly/src-java.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/citylights-controller/assembly/src-java.xml b/citylights-controller/assembly/src-java.xml index e281e8cc8..c442a05b4 100755 --- a/citylights-controller/assembly/src-java.xml +++ b/citylights-controller/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - CityLightsController + CityLightsController/lib diff --git a/configurationdemo/assembly/src-java.xml b/configurationdemo/assembly/src-java.xml index 6e48d13e4..a4a16847f 100755 --- a/configurationdemo/assembly/src-java.xml +++ b/configurationdemo/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - JConfigurationDemo + JConfigurationDemo/lib diff --git a/datacollectiondemo/assembly/src-java.xml b/datacollectiondemo/assembly/src-java.xml index c53c78ce9..e0673b01f 100755 --- a/datacollectiondemo/assembly/src-java.xml +++ b/datacollectiondemo/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - JDataCollectionDemo + JDataCollectionDemo/lib diff --git a/eventdemo/assembly/src-java.xml b/eventdemo/assembly/src-java.xml index e3902004d..4ba769c00 100755 --- a/eventdemo/assembly/src-java.xml +++ b/eventdemo/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - JEventDemo + JEventDemo/lib diff --git a/notificationdemo/assembly/src-java.xml b/notificationdemo/assembly/src-java.xml index 7abe72f5f..fb4e49b04 100755 --- a/notificationdemo/assembly/src-java.xml +++ b/notificationdemo/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - JNotificationDemo + JNotificationDemo/lib diff --git a/twitterled/twitterboard/assembly/src-java.xml b/twitterled/twitterboard/assembly/src-java.xml index 9c3b1b693..4b2e0ce85 100755 --- a/twitterled/twitterboard/assembly/src-java.xml +++ b/twitterled/twitterboard/assembly/src-java.xml @@ -31,7 +31,7 @@ ${project.build.directory}/lib true - TwitterBoard + TwitterBoard/lib