BMISensor : SoftSensor plugin. after receiving height(m) and weight(kg) , it shows BMI(Body Mass Index)
Weight Seonsr : A dummy pseudo thing sending the weight(kg)
Height Seonsr : A dummy pseudo thing sending the height(m)
Change-Id: I5b16643113569bdaa69cf709ee9335b3b3e80e08
Signed-off-by: Rami jung <rami.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/524
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
DiscomfortIndexSensor = DiscomfortIndexSensor_env.SharedLibrary('DiscomfortIndexSensor', DiscomfortIndexSensor_src)
DiscomfortIndexSensor_env.InstallTarget(DiscomfortIndexSensor, 'libDiscomfortIndexSensor')
+
+
+
+######################################################################
+# build BMISensor plugin
+######################################################################
+BMISensor_env = soft_sensor_manager_env.Clone()
+
+BMISensor_env.AppendUnique(CCFLAGS = ['-fPIC'])
+BMISENSOR_DIR = 'SoftSensorPlugin/BMISensor/'
+BMISensor_env.AppendUnique(CPPPATH = [
+ BMISENSOR_DIR + 'include',
+ 'SSMCore/src/SSMInterface/'
+ ])
+
+BMISensor_src = [ Glob(BMISENSOR_DIR + 'src/*.cpp')]
+
+BMISensor = BMISensor_env.SharedLibrary('BMISensor', BMISensor_src)
+BMISensor_env.InstallTarget(BMISensor, 'libBMISensor')
+
+
+
######################################################################
# build SSM CORE
######################################################################
Command("SoftSensorDescription.xml", "SoftSensorPlugin/SoftSensorDescription.xml", Copy("$TARGET", "$SOURCE"))
Command("THSensorApp","SampleApp/linux/THSensorApp/THSensorApp", Copy("$TARGET", "$SOURCE"))
Command("THSensorApp1","SampleApp/linux/THSensorApp1/THSensorApp1", Copy("$TARGET", "$SOURCE"))
+ Command("HeightSensorApp","SampleApp/linux/HeightSensorApp/HeightSensorApp", Copy("$TARGET", "$SOURCE"))
+ Command("WeightSensorApp","SampleApp/linux/WeightSensorApp/WeightSensorApp", Copy("$TARGET", "$SOURCE"))
SConscript('linux/SSMTesterApp/SConscript')
SConscript('linux/THSensorApp/SConscript')
SConscript('linux/THSensorApp1/SConscript')
+ SConscript('linux/HeightSensorApp/SConscript')
+ SConscript('linux/WeightSensorApp/SConscript')
+
+
+
--- /dev/null
+##
+# linux sample app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+linux_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['oc'])
+linux_sample_env.AppendUnique(LIBS = ['octbstack'])
+linux_sample_env.AppendUnique(LIBS = ['libcoap'])
+linux_sample_env.AppendUnique(LIBS = ['liboc_logger'])
+linux_sample_env.AppendUnique(LIBS = ['pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+heightsensorapp = linux_sample_env.Program('HeightSensorApp', 'src/HeightSensorApp.cpp')
+Alias("heightsensorapp_sample", heightsensorapp)
+env.AppendTarget('heightsensorapp')
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+/*
+ * HeightSensorApp.h
+ */
+
+#ifndef HEIGHTSENSORAPP_H_
+#define HEIGHTSENSORAPP_H_
+
+#include <functional>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+
+#include <string>
+#include <cstdlib>
+
+#define COAP_IP "0.0.0.0"
+#define COAP_PORT 0
+#define COAP_MODE ModeType::Server
+#define COAP_SRVTYPE ServiceType::InProc
+
+#define COAP_TYPE_NAME "SoftSensorManager.Sensor"
+
+// testing case
+#define INTERVAL_FOR_CHECK 4 // seconds
+#define INTERVAL_FOR_MEASUREMENT 3 // seconds
+#define INIT_VAL 1 // default value
+#define DIFF_VAL 0.02 // default value
+
+
+
+// Forward declaring the entityHandler
+
+class HeightResource
+{
+ public:
+ /// Access this property from a TB client
+// int m_humid;
+// int m_temp;
+ double m_height;
+ std::string m_resourceUri;
+ std::vector<std::string> m_resourceTypes;
+ std::vector<std::string> m_resourceInterfaces;
+ OCResourceHandle m_resourceHandle;
+ OCRepresentation m_resourceRep;
+ ObservationIds m_interestedObservers;
+
+ public:
+ /// Constructor
+ HeightResource() :
+ /*m_humid(0), m_temp(0), */ m_height(0), m_resourceHandle(0)
+ {
+ m_resourceUri = "/Thing_HeightSensor";
+ m_resourceTypes.push_back(COAP_TYPE_NAME);
+ m_resourceInterfaces.push_back(DEFAULT_INTERFACE);
+
+ printf("Running thing as %s\n", m_resourceUri.c_str());
+ m_resourceRep.setUri(m_resourceUri);
+ m_resourceRep.setResourceTypes(m_resourceTypes);
+ m_resourceRep.setResourceInterfaces(m_resourceInterfaces);
+ }
+
+ ~HeightResource()
+ {
+ }
+
+ void registerResource();
+
+ OCResourceHandle getHandle();
+
+ void setResourceRepresentation(OCRepresentation &rep);
+
+ OCRepresentation getResourceRepresentation();
+};
+
+#endif /* THINGRESOURCESERVER_H_ */
--- /dev/null
+
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+#include <HeightSensorApp.h>
+
+int g_Observation = 0;
+
+OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request);
+
+/*
+ * TempResourceFunctions
+ */
+
+void HeightResource::registerResource()
+{
+ uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+ // This will internally create and register the resource.
+ OCStackResult result = OC::OCPlatform::registerResource(m_resourceHandle, m_resourceUri,
+ m_resourceTypes[0], m_resourceInterfaces[0], &entityHandler, resourceProperty);
+
+ if (OC_STACK_OK != result)
+ {
+ cout << "Resource creation was unsuccessful\n";
+ }
+}
+
+OCResourceHandle HeightResource::getHandle()
+{
+ return m_resourceHandle;
+}
+
+void HeightResource::setResourceRepresentation(OCRepresentation &rep)
+{
+ double tempHeight;
+
+
+
+ rep.getValue("2", tempHeight);
+
+
+ m_height= tempHeight;
+
+ cout << "\t\t\t" << "Received representation: " << endl;
+
+ cout << "\t\t\t\t" << "height" << m_height << endl;
+
+}
+
+OCRepresentation HeightResource::getResourceRepresentation()
+{
+
+ m_resourceRep.setValue("0", std::string("height"));
+ m_resourceRep.setValue("1", std::string("double"));
+ m_resourceRep.setValue("2", std::to_string(m_height));
+
+ return m_resourceRep;
+}
+
+// Create the instance of the TemphumidResource class
+HeightResource g_myResource;
+
+void *TestSensorVal(void *param)
+{
+
+ bool bFlag = true;
+ int nSleep_time=INTERVAL_FOR_CHECK;
+ double nHeight;
+
+ std::cout << "[HeightSensorAPP] ::" << __func__ << " is called."
+ << std::endl;
+
+// g_myResource.m_height = 1;
+
+ nHeight=INIT_VAL;
+
+ // This function continuously monitors for the changes
+ while (1)
+ {
+
+
+ sleep(nSleep_time);
+
+
+ if (g_Observation)
+ {
+
+ if(bFlag){
+
+ nSleep_time =INTERVAL_FOR_MEASUREMENT;
+ nHeight+=DIFF_VAL;
+ g_myResource.m_height=nHeight;
+ }
+ else{
+ nSleep_time =INTERVAL_FOR_CHECK;
+ g_myResource.m_height=0;
+
+
+ }
+ bFlag=bFlag^true;
+
+
+ cout << "\n height updated to : " << g_myResource.m_height << endl;
+ cout << "Notifying observers with resource handle: " << g_myResource.getHandle()
+ << endl;
+
+ OCStackResult result = OCPlatform::notifyAllObservers(g_myResource.getHandle());
+
+
+ if (OC_STACK_NO_OBSERVERS == result)
+ {
+ cout << "No More observers, stopping notifications" << endl;
+ g_Observation = 0;
+ }
+
+ }
+ else{
+
+ nSleep_time=INTERVAL_FOR_CHECK ;
+ }
+
+ }
+ return NULL;
+}
+
+OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "\tIn Server CPP entity handler:\n";
+
+ auto response = std::make_shared<OC::OCResourceResponse>();
+
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ response->setRequestHandle(request->getRequestHandle());
+ response->setResourceHandle(request->getResourceHandle());
+
+ if (requestFlag & RequestHandlerFlag::InitFlag)
+ {
+ cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+
+ if (requestFlag & RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\t\trequestFlag : Request\n";
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\t\trequestType : GET\n";
+
+ // Check for query params (if any)
+ // Process query params and do required operations ..
+
+ // Get the representation of this resource at this point and send it as response
+ OCRepresentation rep = g_myResource.getResourceRepresentation();
+
+ if (response)
+ {
+ // TODO Error Code
+ response->setErrorCode(200);
+ response->setResourceRepresentation(rep, DEFAULT_INTERFACE);
+ }
+ }
+ else if (requestType == "PUT")
+ {
+ // PUT request operations
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+
+ if (requestFlag & RequestHandlerFlag::ObserverFlag)
+ {
+ pthread_t threadId;
+
+ cout << "\t\trequestFlag : Observer\n";
+ g_Observation = 1;
+
+ static int startedThread = 0;
+
+ if (!startedThread)
+ {
+ pthread_create(&threadId, NULL, TestSensorVal, (void *) NULL);
+ startedThread = 1;
+ }
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return OCPlatform::sendResponse(response) == OC_STACK_OK ? OC_EH_OK : OC_EH_ERROR;
+}
+
+int main()
+{
+ // Create PlatformConfig object
+ PlatformConfig cfg(COAP_SRVTYPE, COAP_MODE, COAP_IP, COAP_PORT, OC::QualityOfService::LowQos);
+
+ try
+ {
+ OC::OCPlatform::Configure(cfg);
+
+ OC::OCPlatform::startPresence(60);
+
+ g_myResource.registerResource();
+
+ int input = 0;
+ cout << "Type any key to terminate" << endl;
+ cin >> input;
+
+ OC::OCPlatform::stopPresence();
+ }
+ catch (std::exception e)
+ {
+ cout << e.what() << endl;
+ }
+}
+
{
typedef enum
{
- NONE = 0, REGISTER, UNREGISTER, DISCOMFORT_SAMPLE, ITS_SAMPLE, EXIT = 9
+ NONE = 0, REGISTER, UNREGISTER, DISCOMFORT_SAMPLE, ITS_SAMPLE, BMI_SAMPLE, EXIT = 9
} APPMenu;
}
;
typedef enum
{
+ UNKOWNBMI = 0, UNDERWEIGHT, NORMALRANGE, OVERWEIGHT, OBESE
+} BMIResult;
+
+
+typedef enum
+{
ALL_DISCOMPORT = 2, HALF_DISCOMPORT, LITTLE_DISCOMPORT, ALL_COMPORT
} DIResult;
printf(" 2. Unregister Query \n");
printf(" 3. Register DiscomfortIndexSensor sample query \n");
printf(" 4. Register IndoorTrajectorySensor sample query \n");
+ printf(" 5. Register BMISensor sample query \n");
printf(" 9. exit \n");
printf("===============================================\n");
printf(" Please Enter the NO: ");
"if Device.IndoorTrajectorySensor.trackeeID == \"9059AF16FEF7\"");
break;
+ case APPMenu::BMI_SAMPLE:
+ SSMApp->registerQuery("subscribe Device.BMISensor "\
+ "if Device.BMISensor.BMIresult > 0");
+
+ break;
+
+
+
+
+
case APPMenu::EXIT:
std::cout << "program exit." << std::endl;
break;
--- /dev/null
+##
+# linux sample app build script
+##
+
+Import('env')
+
+# Add third party libraries
+lib_env = env.Clone()
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+linux_sample_env = lib_env.Clone()
+
+######################################################################
+# Build flags
+######################################################################
+linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
+linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+linux_sample_env.AppendUnique(LIBS = ['oc'])
+linux_sample_env.AppendUnique(LIBS = ['octbstack'])
+linux_sample_env.AppendUnique(LIBS = ['libcoap'])
+linux_sample_env.AppendUnique(LIBS = ['liboc_logger'])
+linux_sample_env.AppendUnique(LIBS = ['pthread'])
+
+######################################################################
+#build sampleapp
+######################################################################
+weightsensorapp = linux_sample_env.Program('WeightSensorApp', 'src/WeightSensorApp.cpp')
+Alias("weightsensorapp_sample", weightsensorapp)
+env.AppendTarget('weightsensorapp')
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+/*
+ * WeightSensorApp.h
+ */
+
+#ifndef WEIGHTSENSORAPP_H_
+#define WEIGHTSENSORAPP_H_
+
+#include <functional>
+#include <pthread.h>
+#include "OCPlatform.h"
+#include "OCApi.h"
+
+using namespace OC;
+using namespace std;
+
+#include <string>
+#include <cstdlib>
+
+#define COAP_IP "0.0.0.0"
+#define COAP_PORT 0
+#define COAP_MODE ModeType::Server
+#define COAP_SRVTYPE ServiceType::InProc
+
+#define COAP_TYPE_NAME "SoftSensorManager.Sensor"
+
+// testing case
+#define INTERVAL_FOR_CHECK 14 // seconds
+#define INTERVAL_FOR_MEASUREMENT 3 // seconds
+#define INIT_VAL 33 // default value
+#define DIFF_VAL 0.01 // default value
+
+
+
+// Forward declaring the entityHandler
+
+class WeightResource
+{
+ public:
+ /// Access this property from a TB client
+// int m_humid;
+// int m_temp;
+ double m_weight;
+ std::string m_resourceUri;
+ std::vector<std::string> m_resourceTypes;
+ std::vector<std::string> m_resourceInterfaces;
+ OCResourceHandle m_resourceHandle;
+ OCRepresentation m_resourceRep;
+ ObservationIds m_interestedObservers;
+
+ public:
+ /// Constructor
+ WeightResource() :
+ m_weight(0), m_resourceHandle(0)
+ {
+ m_resourceUri = "/Thing_WeightSensor";
+ m_resourceTypes.push_back(COAP_TYPE_NAME);
+ m_resourceInterfaces.push_back(DEFAULT_INTERFACE);
+
+ printf("Running thing as %s\n", m_resourceUri.c_str());
+ m_resourceRep.setUri(m_resourceUri);
+ m_resourceRep.setResourceTypes(m_resourceTypes);
+ m_resourceRep.setResourceInterfaces(m_resourceInterfaces);
+ }
+
+ ~WeightResource()
+ {
+ }
+
+ void registerResource();
+
+ OCResourceHandle getHandle();
+
+ void setResourceRepresentation(OCRepresentation &rep);
+
+ OCRepresentation getResourceRepresentation();
+};
+
+#endif /* THINGRESOURCESERVER_H_ */
--- /dev/null
+
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+#include <WeightSensorApp.h>
+
+int g_Observation = 0;
+
+OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request);
+
+/*
+ * TempResourceFunctions
+ */
+
+void WeightResource::registerResource()
+{
+ uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE;
+
+ // This will internally create and register the resource.
+ OCStackResult result = OC::OCPlatform::registerResource(m_resourceHandle, m_resourceUri,
+ m_resourceTypes[0], m_resourceInterfaces[0], &entityHandler, resourceProperty);
+
+ if (OC_STACK_OK != result)
+ {
+ cout << "Resource creation was unsuccessful\n";
+ }
+}
+
+OCResourceHandle WeightResource::getHandle()
+{
+ return m_resourceHandle;
+}
+
+void WeightResource::setResourceRepresentation(OCRepresentation &rep)
+{
+ double tempWeight;
+
+
+
+ rep.getValue("2", tempWeight);
+
+
+ m_weight= tempWeight;
+
+ cout << "\t\t\t" << "Received representation: " << endl;
+
+ cout << "\t\t\t\t" << "Weight" << m_weight << endl;
+
+}
+
+OCRepresentation WeightResource::getResourceRepresentation()
+{
+
+ m_resourceRep.setValue("0", std::string("weight"));
+ m_resourceRep.setValue("1", std::string("double"));
+ m_resourceRep.setValue("2", std::to_string(m_weight));
+
+ return m_resourceRep;
+}
+
+// Create the instance of the TemphumidResource class
+WeightResource g_myResource;
+
+void *TestSensorVal(void *param)
+{
+
+ bool bFlag = true;
+ int nSleep_time=INTERVAL_FOR_CHECK;
+ double nWeight;
+
+ std::cout << "[WeightSensorAPP] ::" << __func__ << " is called."
+ << std::endl;
+
+// g_myResource.m_weight = 33;
+ nWeight=INIT_VAL;
+
+ // This function continuously monitors for the changes
+ while (1)
+ {
+
+
+ sleep(nSleep_time);
+
+
+ if (g_Observation)
+ {
+
+ //g_myResource.m_weight+=0.01;
+
+ if(bFlag){
+
+ nSleep_time =INTERVAL_FOR_MEASUREMENT;
+ nWeight+=DIFF_VAL;
+ g_myResource.m_weight=nWeight;
+ }
+ else{
+ nSleep_time =INTERVAL_FOR_CHECK;
+ g_myResource.m_weight=0;
+
+
+ }
+ bFlag=bFlag^true;
+
+ cout << "\n weight updated to : " << g_myResource.m_weight << endl;
+ cout << "Notifying observers with resource handle: " << g_myResource.getHandle()
+ << endl;
+
+ OCStackResult result = OCPlatform::notifyAllObservers(g_myResource.getHandle());
+
+ if (OC_STACK_NO_OBSERVERS == result)
+ {
+ cout << "No More observers, stopping notifications" << endl;
+ g_Observation = 0;
+ }
+ }
+ else{
+
+ nSleep_time=INTERVAL_FOR_CHECK ;
+ }
+
+ }
+ return NULL;
+}
+
+OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request)
+{
+ cout << "\tIn Server CPP entity handler:\n";
+
+ auto response = std::make_shared<OC::OCResourceResponse>();
+
+ if (request)
+ {
+ // Get the request type and request flag
+ std::string requestType = request->getRequestType();
+ int requestFlag = request->getRequestHandlerFlag();
+
+ response->setRequestHandle(request->getRequestHandle());
+ response->setResourceHandle(request->getResourceHandle());
+
+ if (requestFlag & RequestHandlerFlag::InitFlag)
+ {
+ cout << "\t\trequestFlag : Init\n";
+
+ // entity handler to perform resource initialization operations
+ }
+
+ if (requestFlag & RequestHandlerFlag::RequestFlag)
+ {
+ cout << "\t\trequestFlag : Request\n";
+
+ // If the request type is GET
+ if (requestType == "GET")
+ {
+ cout << "\t\t\trequestType : GET\n";
+
+ // Check for query params (if any)
+ // Process query params and do required operations ..
+
+ // Get the representation of this resource at this point and send it as response
+ OCRepresentation rep = g_myResource.getResourceRepresentation();
+
+ if (response)
+ {
+ // TODO Error Code
+ response->setErrorCode(200);
+ response->setResourceRepresentation(rep, DEFAULT_INTERFACE);
+ }
+ }
+ else if (requestType == "PUT")
+ {
+ // PUT request operations
+ }
+ else if (requestType == "POST")
+ {
+ // POST request operations
+ }
+ else if (requestType == "DELETE")
+ {
+ // DELETE request operations
+ }
+ }
+
+ if (requestFlag & RequestHandlerFlag::ObserverFlag)
+ {
+ pthread_t threadId;
+
+ cout << "\t\trequestFlag : Observer\n";
+ g_Observation = 1;
+
+ static int startedThread = 0;
+
+ if (!startedThread)
+ {
+ pthread_create(&threadId, NULL, TestSensorVal, (void *) NULL);
+ startedThread = 1;
+ }
+ }
+ }
+ else
+ {
+ std::cout << "Request invalid" << std::endl;
+ }
+
+ return OCPlatform::sendResponse(response) == OC_STACK_OK ? OC_EH_OK : OC_EH_ERROR;
+}
+
+int main()
+{
+ // Create PlatformConfig object
+ PlatformConfig cfg(COAP_SRVTYPE, COAP_MODE, COAP_IP, COAP_PORT, OC::QualityOfService::LowQos);
+
+ try
+ {
+ OC::OCPlatform::Configure(cfg);
+
+ OC::OCPlatform::startPresence(60);
+
+ g_myResource.registerResource();
+
+ int input = 0;
+ cout << "Type any key to terminate" << endl;
+ cin >> input;
+
+ OC::OCPlatform::stopPresence();
+ }
+ catch (std::exception e)
+ {
+ cout << e.what() << endl;
+ }
+}
+
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+/*
+ * BMISensor.h
+ */
+
+#ifndef BMISENSOR_H_
+#define BMISENSOR_H_
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+#include "SSMModelDefinition.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+INTERFACE_DECLSPEC void InitializeContext(ICtxDelegate *pDelegate);
+#ifdef __cplusplus
+}
+;
+#endif
+
+
+#if 0
+Who BMI
+weight / height*hegith
+
+< 18.5 :underweight
+18.5 <= < 25 : Normal Range
+<= 25 < 30 : Overweight
+<= 30 : Obese
+#endif
+
+#define UNKOWNBMI -1
+#define OUTOFDATEBMI 0
+#define UNDERWEIGHT 1
+#define NORMALRANGE 2
+#define OVERWEIGHT 3
+#define OBESE 4
+
+
+#define UNDERWEIGHT_VAL 18.5
+#define NORMALRANGE_VAL 25.9
+#define OVERWEIGHT_VAL 30
+
+
+#define DIFFTIME 4 // valid time difference. (seconds)
+
+
+
+
+
+namespace BMISensorName
+{
+//#define PHYSICAL_EA 2
+
+
+ typedef struct _physicalInput_
+ {
+ char *m_thingName;
+ int m_inputNum;
+ void *m_pInputStruct;
+ } physicalInput;
+
+ typedef enum
+ {
+ SUCCESS = 0, ERROR
+ } DIResult;
+
+ class BMISensor: public ICtxEvent
+ {
+ private:
+
+ // static physicalInput s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA];
+
+ class InValue
+ {
+ public:
+ std::string m_usrname; // each user. ; for future
+ std::string m_timestamp;
+ double m_height; // Height.
+ double m_weight; // Weight
+ time_t m_timepstampH;
+ time_t m_timepstampW;
+ int m_BMIresult;
+
+ };
+
+ //InValue m_DI[PHYSICAL_EA];
+ InValue m_result;
+
+ int runLogic(std::vector< ContextData > &contextDataList);
+
+ public:
+ BMISensor();
+
+ void onCtxEvent(enum CTX_EVENT_TYPE eventType, std::vector< ContextData > contextDataList);
+
+ DIResult getInput(std::vector< ContextData > &contextDataList);
+ DIResult makeBMI(void);
+ ContextData setOutput(int property_count);
+
+ friend void INTERFACE_DECLSPEC initializeContext(ICtxDelegate *pDelegate);
+ };
+};
+
+#endif /* BMISENSOR_H_ */
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+/*
+ * SysTimer.h
+ */
+
+#ifndef SYSTIMER_H_
+#define SYSTIMER_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+class SysTimer
+{
+ public:
+ static std::string MilliSecondAsString();
+ static std::string UTCSecondAsString();
+};
+
+#endif /* SYSTIMER_H_ */
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+/**
+ * This file contains the exported symbol.
+ */
+#include <stdlib.h>
+#include <map>
+#include <string>
+#include <sstream>
+#include <iostream>
+
+#include "BMISensor.h"
+#include "SysTimer.h"
+
+#ifdef __ANDROID__
+#include "OCAndroid.h"
+#endif
+
+using namespace BMISensorName;
+
+#define SENSOR_NAME "BMISensor"
+
+#define WEIGHTSENSOR_NAME ((char *)"Thing_WeightSensor")
+#define HEIGHTSENSOR_NAME ((char *)"Thing_HeightSensor")
+
+#define WEIGHT_NAME ((char *)"weight")
+#define HEIGHT_NAME ((char *)"height")
+
+
+
+
+ICtxDelegate *g_pDelegate;
+
+void InitializeContext(ICtxDelegate *pDelegate)
+{
+
+ std::cout << "[BMISensor] Sensor::" << __func__ << " is called."
+ << std::endl;
+
+ std::vector < ContextData > contextData;
+
+ BMISensor *eventCls = new BMISensor();
+ pDelegate->registerCallback(eventCls);
+ g_pDelegate = pDelegate;
+
+ std::cout << "BMISensor loaded" << std::endl;
+
+ return;
+}
+
+BMISensor::BMISensor()
+{
+ m_result.m_usrname = ""; // each user.
+ m_result.m_timestamp = ""; // measured time
+ m_result.m_weight = 0; // Height
+ m_result.m_height = 0; // Weight
+ time(&(m_result.m_timepstampW));
+ time(&(m_result.m_timepstampH));
+ m_result.m_BMIresult = UNKOWNBMI;
+
+
+
+}
+
+void BMISensor::onCtxEvent(enum CTX_EVENT_TYPE eventType,
+ std::vector< ContextData > contextDataList)
+{
+
+
+ switch (eventType)
+ {
+ case SPF_START:
+ runLogic(contextDataList);
+ break;
+ default:
+ std::cout << "Not support onCtxEvent" << std::endl;
+ break;
+ }
+}
+
+int BMISensor::runLogic(std::vector< ContextData > &contextDataList)
+{
+
+ DIResult result;
+
+ if (getInput(contextDataList) == SUCCESS)
+ {
+
+
+
+
+ if ((result = makeBMI()) != SUCCESS)
+ {
+ std::cout << "Error : makeBMI() result = " << result << std::endl;
+ return -1;
+ }
+
+ std::vector < ContextData > outList;
+ ContextData out = setOutput(1);
+ outList.push_back(out);
+ g_pDelegate->addOutput(outList);
+
+ return 0;
+ }
+
+ return -1;
+}
+
+
+
+DIResult BMISensor::getInput(std::vector< ContextData > &contextDataList)
+{
+
+ int contextSize = 0;
+ double temp;
+
+// std::cout << "[BMISensor] BMISensor::" << "contextDataList.size() : "<< contextDataList.size() << std::endl;
+
+
+
+ if ((contextSize = contextDataList.size()) == 0) // number of input things
+ {
+ std::cout << "Physical Context data is not exist." << std::endl;
+ return ERROR;
+ }
+
+ for (int i = 0; i < contextSize; i++)
+ {
+
+ std::vector < std::map< std::string, std::string > > lVector =
+ contextDataList[i].outputProperty;
+ std::string name = lVector[0]["name"];
+
+
+ if (contextDataList[i].rootName == WEIGHTSENSOR_NAME)
+ {
+
+
+ if (name.compare(WEIGHT_NAME) == 0){
+
+ temp=std::stod( lVector[0]["value"]);
+
+ if (temp > 0){
+ time(&(m_result.m_timepstampW));
+ m_result.m_weight=temp;
+ }
+
+
+
+ }
+
+
+ }
+ else if (contextDataList[i].rootName == HEIGHTSENSOR_NAME)
+ {
+
+ if (name.compare(HEIGHT_NAME) == 0){
+
+ temp=std::stod( lVector[0]["value"]);
+ if (temp > 0){
+ time(&(m_result.m_timepstampH));
+ m_result.m_height=temp;
+ }
+
+ }
+
+ }
+
+ }
+
+ return SUCCESS;
+}
+
+/**
+ * Calculation of BMI with Weight&Height
+ */
+
+
+
+DIResult BMISensor::makeBMI(void)
+{
+
+
+ // std::cout << "[BMISensor] BMISensor::" << __func__ << " is called."
+ // << std::endl;
+
+ double BMIvalue, timediffsecond;
+
+ timediffsecond = abs( difftime( m_result.m_timepstampW,m_result.m_timepstampH));
+
+
+ if( timediffsecond > DIFFTIME ){
+
+ BMIvalue= 0;
+ m_result.m_BMIresult=UNKOWNBMI;
+ std::cout << "[BMISensor] : OUTOFDATEBMI: "<< m_result.m_BMIresult << std::endl;
+ }
+ else if( (m_result.m_height > 0) && (m_result.m_weight > 0 )){
+ BMIvalue= m_result.m_weight / (m_result.m_height * m_result.m_height);
+
+
+ std::cout << "[BMISensor] height : " << m_result.m_height << " weight : " << m_result.m_weight << " BMIvalue : "<< BMIvalue <<" timediff : "<<timediffsecond << std::endl;
+
+
+
+ if (BMIvalue >= OVERWEIGHT_VAL)
+ {
+ m_result.m_BMIresult = (int) OBESE;
+ std::cout << "[BMISensor] : BMIresult:" << m_result.m_BMIresult<< " OBESE "<< std::endl;
+ }
+ else if (BMIvalue >= NORMALRANGE_VAL )
+ {
+ m_result.m_BMIresult = (int) OVERWEIGHT;
+ std::cout << "[BMISensor] : BMIresult:" << m_result.m_BMIresult<< " OVERWEIGHT "<< std::endl;
+
+ }
+ else if (BMIvalue >= UNDERWEIGHT_VAL )
+ {
+ m_result.m_BMIresult = (int) NORMALRANGE;
+ std::cout << "[BMISensor] : BMIresult:" << m_result.m_BMIresult<< " NORMALRANGE "<< std::endl;
+
+ }
+ else
+ {
+ m_result.m_BMIresult = (int) UNDERWEIGHT;
+ std::cout << "[BMISensor] : BMIresult:" << m_result.m_BMIresult<< " UNDERWEIGHT "<< std::endl;
+ }
+
+ }
+ else {
+ BMIvalue= -1;
+ m_result.m_BMIresult=UNKOWNBMI;
+ std::cout << "[BMISensor] : UNKOWNBMI: "<< m_result.m_BMIresult << std::endl;
+ }
+
+
+
+ return SUCCESS;
+
+
+}
+
+
+ContextData BMISensor::setOutput(int property_count)
+{
+ ContextData out;
+
+ std::map < std::string, std::string > output_property;
+
+
+// std::cout << "[BMISensor] BMISensor::" << __func__ << " is called."
+// << std::endl;
+
+ out.rootName = SENSOR_NAME;
+ out.outputPropertyCount = property_count;
+
+
+ std::ostringstream convert;
+ convert << m_result.m_BMIresult;
+
+
+ output_property.insert(std::make_pair("name", "BMIresult"));
+ output_property.insert(std::make_pair("type", "int"));
+ output_property.insert(std::make_pair("value", convert.str() ));
+ out.outputProperty.push_back(output_property);
+
+
+
+ return out;
+}
+
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2015 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.
+ *
+ ******************************************************************/
+
+#include <cstdlib>
+#include <sys/time.h>
+#include <string>
+#include <iostream>
+#include <sstream>
+
+#include "SysTimer.h"
+
+#include <stdint.h>
+std::string SysTimer::MilliSecondAsString()
+{
+ std::stringstream ss;
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ long long val = tv.tv_sec * (long long) 1000 + tv.tv_usec / 1000;
+
+ ss << val;
+ std::string strTime = ss.str();
+
+ return strTime;
+}
+
+std::string SysTimer::UTCSecondAsString()
+{
+ std::stringstream ss;
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ unsigned long val = tv.tv_sec;
+
+ ss << val;
+ std::string strTime = ss.str();
+
+ return strTime;
+}
</inputs>
</softsensor>
+ <softsensor>
+ <name>BMISensor</name>
+ <attributes>
+ <attribute>
+ <name>version</name>
+ <type>string</type>
+ <value>1.0</value>
+ </attribute>
+ <attribute>
+ <name>lifetime</name>
+ <type>int</type>
+ <value>60</value>
+ </attribute>
+ </attributes>
+ <outputs>
+ <output>
+ <name>BMIresult</name>
+ <type>int</type>
+ </output>
+ </outputs>
+ <inputs>
+ <input>Thing_WeightSensor</input>
+ <input>Thing_HeightSensor</input>
+ </inputs>
+ </softsensor>
+
+
</softsensors>