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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 package org.iotivity.service.sample.androidbundle.resources;
23 import android.content.Context;
24 import android.util.Log;
26 import org.iotivity.service.resourcecontainer.AndroidBundleSoftSensorResource;
27 import org.iotivity.service.resourcecontainer.RcsResourceAttributes;
28 import org.iotivity.service.resourcecontainer.RcsValue;
30 import java.util.Vector;
32 public class DiscomfortIndexResource extends AndroidBundleSoftSensorResource {
33 private static final String LOG_TAG = DiscomfortIndexResource.class.getSimpleName();
35 public DiscomfortIndexResource(Context context){
37 this.setResourceType("oic.r.discomfortindex");
38 this.setName("discomfortIndex");
42 protected void initAttributes() {
43 this.m_attributes.put("discomfortIndex", 0);
44 this.m_attributes.put("humidity", 0);
45 this.m_attributes.put("temperature",0);
49 protected void onUpdatedInputResource(String attributeName, Vector<RcsValue> values) {
50 m_mapInputData.put(attributeName, values.get(0));
54 protected void executeLogic() {
55 if(m_mapInputData.get("humidity") != null && m_mapInputData.get("temperature") != null){
57 Vector v = new Vector();
60 int t = m_mapInputData.get("temperature").asInt();
61 int h = m_mapInputData.get("humidity").asInt();
62 double F = (9.0 * (double) t) / 5.0 + 32.0;
64 // calculation of discomfortIndex
65 dDI = F - (F - 58.0) * (double)((100 - h) * 55) / 10000.0;
67 this.setAttribute("temperature", new RcsValue(t));
68 this.setAttribute("humidity", new RcsValue(h));
69 this.setAttribute("discomfortIndex", new RcsValue(dDI));
71 Log.i(LOG_TAG, "Discomfort Index" + dDI);
76 public void handleSetAttributesRequest(RcsResourceAttributes rcsResourceAttributes) {
77 this.setAttributes(rcsResourceAttributes);
82 public RcsResourceAttributes handleGetAttributesRequest() {
83 return this.getAttributes();