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"
31 #include "OCAndroid.h"
34 using namespace BMISensorName;
37 BMISensor::BMISensor()
46 BMISensor::~BMISensor()
51 int BMISensor::executeBMISensorLogic(std::map<std::string, std::string> *pInputData,
56 if (pInputData->find("weight") != pInputData->end())
58 m_weight = pInputData->at("weight");
62 if (pInputData->find("height") != pInputData->end())
64 m_height = pInputData->at("height");
68 if ((result = makeBMI()) != SUCCESS)
73 (*pOutput) = m_BMIResult;
79 * Calculation of BMI with Weight&Height
81 BMIResult BMISensor::makeBMI(void)
83 double BMIvalue, timediffsecond;
84 double dWeight, dHeight;
88 if (!m_weight.empty() && !m_height.empty())
90 dWeight = std::stod(m_weight);
91 dHeight = std::stod(m_height);
93 timediffsecond = abs(difftime(m_timepstampW, m_timepstampH));
95 // check if time difference between weight data and height data is valid
96 if (timediffsecond > DIFFTIME)
99 BMIResult = UNKOWNBMI;
100 std::cout << "[BMISensor] : OUTOFDATEBMI: " << BMIResult << std::endl;
102 else if ((dWeight > 0) && (dHeight > 0))
105 BMIvalue = dWeight / (dHeight * dHeight);
107 std::cout << "[BMISensor] height : " << m_height << " weight : " << m_weight
108 << " BMIvalue : " << BMIvalue << " timediff : " << timediffsecond
111 if (BMIvalue >= OVERWEIGHT_VAL)
113 BMIResult = (int)OBESE;
114 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OBESE " << std::endl;
116 else if (BMIvalue >= NORMALRANGE_VAL )
118 BMIResult = (int)OVERWEIGHT;
119 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OVERWEIGHT " << std::endl;
122 else if (BMIvalue >= UNDERWEIGHT_VAL )
124 BMIResult = (int)NORMALRANGE;
125 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " NORMALRANGE " << std::endl;
130 BMIResult = (int)UNDERWEIGHT;
131 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " UNDERWEIGHT " << std::endl;
137 BMIResult = UNKOWNBMI;
138 std::cout << "[BMISensor] : UNKNOWNBMI: " << BMIResult << std::endl;
141 std::cout << std::endl;
143 m_BMIResult = std::to_string(BMIResult);