1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 * This file contains the exported symbol.
24 #include "BMISensor.h"
32 #include "OCAndroid.h"
35 using namespace BMISensorName;
38 BMISensor::BMISensor()
47 BMISensor::~BMISensor()
52 int BMISensor::executeBMISensorLogic(std::map<std::string, std::string> *pInputData,
57 if (pInputData->find("weight") != pInputData->end())
59 m_weight = pInputData->at("weight");
63 if (pInputData->find("height") != pInputData->end())
65 m_height = pInputData->at("height");
69 if ((result = makeBMI()) != SUCCESS)
74 (*pOutput) = m_BMIResult;
80 * Calculation of BMI with Weight&Height
82 BMIResult BMISensor::makeBMI(void)
84 double BMIvalue, timediffsecond;
85 double dWeight, dHeight;
89 if (!m_weight.empty() && !m_height.empty())
91 dWeight = std::stod(m_weight);
92 dHeight = std::stod(m_height);
94 timediffsecond = std::abs(difftime(m_timepstampW, m_timepstampH));
96 // check if time difference between weight data and height data is valid
97 if (timediffsecond > DIFFTIME)
100 BMIResult = UNKOWNBMI;
101 std::cout << "[BMISensor] : OUTOFDATEBMI: " << BMIResult << std::endl;
103 else if ((dWeight > 0) && (dHeight > 0))
106 BMIvalue = dWeight / (dHeight * dHeight);
108 std::cout << "[BMISensor] height : " << m_height << " weight : " << m_weight
109 << " BMIvalue : " << BMIvalue << " timediff : " << timediffsecond
112 if (BMIvalue >= OVERWEIGHT_VAL)
114 BMIResult = (int)OBESE;
115 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OBESE " << std::endl;
117 else if (BMIvalue >= NORMALRANGE_VAL )
119 BMIResult = (int)OVERWEIGHT;
120 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OVERWEIGHT " << std::endl;
123 else if (BMIvalue >= UNDERWEIGHT_VAL )
125 BMIResult = (int)NORMALRANGE;
126 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " NORMALRANGE " << std::endl;
131 BMIResult = (int)UNDERWEIGHT;
132 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " UNDERWEIGHT " << std::endl;
138 BMIResult = UNKOWNBMI;
139 std::cout << "[BMISensor] : UNKNOWNBMI: " << BMIResult << std::endl;
142 std::cout << std::endl;
144 m_BMIResult = std::to_string(BMIResult);