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,
55 BMIResult result = ERROR;
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 = 0.0;
85 double timediffsecond = 0.0;
91 if (!m_weight.empty() && !m_height.empty())
93 dWeight = std::stod(m_weight);
94 dHeight = std::stod(m_height);
96 timediffsecond = std::abs(difftime(m_timepstampW, m_timepstampH));
98 // check if time difference between weight data and height data is valid
99 if (timediffsecond > DIFFTIME)
102 BMIResult = UNKOWNBMI;
103 std::cout << "[BMISensor] : OUTOFDATEBMI: " << BMIResult << std::endl;
105 else if ((dWeight > 0) && (dHeight > 0))
108 BMIvalue = dWeight / (dHeight * dHeight);
110 std::cout << "[BMISensor] height : " << m_height << " weight : " << m_weight
111 << " BMIvalue : " << BMIvalue << " timediff : " << timediffsecond
114 if (BMIvalue >= OVERWEIGHT_VAL)
116 BMIResult = (int)OBESE;
117 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OBESE " << std::endl;
119 else if (BMIvalue >= NORMALRANGE_VAL )
121 BMIResult = (int)OVERWEIGHT;
122 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " OVERWEIGHT " << std::endl;
125 else if (BMIvalue >= UNDERWEIGHT_VAL )
127 BMIResult = (int)NORMALRANGE;
128 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " NORMALRANGE " << std::endl;
133 BMIResult = (int)UNDERWEIGHT;
134 std::cout << "[BMISensor] : BMIresult:" << BMIResult << " UNDERWEIGHT " << std::endl;
140 BMIResult = UNKOWNBMI;
141 std::cout << "[BMISensor] : UNKNOWNBMI: " << BMIResult << std::endl;
144 std::cout << std::endl;
146 m_BMIResult = std::to_string(BMIResult);