-# //******************************************************************
-# //
-# // Copyright 2014 Intel Mobile Communications GmbH 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 ../../../../build/arduino/environment.mk
ARDUINO_DIR = /usr/share/arduino
-# //******************************************************************
-# //
-# // Copyright 2014 Intel Mobile Communications GmbH 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 ../../../../build/arduino/environment.mk
ARDUINO_DIR = /usr/share/arduino
-//******************************************************************
-//
-// Copyright 2014 Intel Mobile Communications GmbH 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.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+/******************************************************************
+*
+* Copyright 2014 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.
+*
+******************************************************************/
// Do not remove the include below
#include "Arduino.h"
char temp[100];
-#define LENGTH_VAR 100
+#define LENGTH_VAR 100
static int base_length = 0;
-bool JsonGenerator( THResource& th, char* jsonBuf, uint16_t buf_length )
+bool JsonGenerator( THResource &th, char *jsonBuf, uint16_t buf_length )
{
- if( (buf_length - base_length) < LENGTH_VAR )
- {
- OC_LOG_V(ERROR, TAG, "Error : length is very long.");
- return false;
- }
+ if ( (buf_length - base_length) < LENGTH_VAR )
+ {
+ OC_LOG_V(ERROR, TAG, "Error : length is very long.");
+ return false;
+ }
- sprintf(jsonBuf, JSON_BASE00 JSON_BASE01"%d",th.m_temp);
- sprintf(jsonBuf+strlen(jsonBuf), JSON_BASE02"%d"JSON_BASE03, th.m_humid);
+ sprintf(jsonBuf, JSON_BASE00 JSON_BASE01"%d", th.m_temp);
+ sprintf(jsonBuf + strlen(jsonBuf), JSON_BASE02"%d"JSON_BASE03, th.m_humid);
- Serial.println(jsonBuf);
+ Serial.println(jsonBuf);
- return true;
+ return true;
}
byte read_dht11_dat()
// This is the entity handler for the registered resource.
// This is invoked by OCStack whenever it recevies a request for this resource.
-OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest )
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest *entityHandlerRequest )
{
OCEntityHandlerResult ehRet = OC_EH_OK;
OCEntityHandlerResponse response = {0};
char payload[MAX_RESPONSE_LENGTH] = {0};
- if(entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+ if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
{
OC_LOG (INFO, TAG, PCF("Flag includes OC_REQUEST_FLAG"));
- if(OC_REST_GET == entityHandlerRequest->method)
+ if (OC_REST_GET == entityHandlerRequest->method)
{
- if(JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
- {
- }
- else
+ if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
+ {
+ }
+ else
{
ehRet = OC_EH_ERROR;
}
}
- if(OC_REST_PUT == entityHandlerRequest->method)
+ if (OC_REST_PUT == entityHandlerRequest->method)
{
//Do something with the 'put' payload
if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
{
ehRet = OC_EH_ERROR;
}
- }
+ }
if (ehRet == OC_EH_OK)
- {
- // Format the response. Note this requires some info about the request
- response.requestHandle = entityHandlerRequest->requestHandle;
- response.resourceHandle = entityHandlerRequest->resource;
- response.ehResult = ehRet;
- response.payload = (unsigned char *)payload;
- response.payloadSize = strlen(payload);
- response.numSendVendorSpecificHeaderOptions = 0;
- memset(response.sendVendorSpecificHeaderOptions, 0, sizeof response.sendVendorSpecificHeaderOptions);
- memset(response.resourceUri, 0, sizeof response.resourceUri);
- // Indicate that response is NOT in a persistent buffer
- response.persistentBufferFlag = 0;
-
- // Send the response
- if (OCDoResponse(&response) != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "Error sending response");
- ehRet = OC_EH_ERROR;
- }
- }
+ {
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = entityHandlerRequest->requestHandle;
+ response.resourceHandle = entityHandlerRequest->resource;
+ response.ehResult = ehRet;
+ response.payload = (unsigned char *)payload;
+ response.payloadSize = strlen(payload);
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response.resourceUri);
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Error sending response");
+ ehRet = OC_EH_ERROR;
+ }
+ }
}
if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG))
{
TH.m_humid = dht11_dat[0];
TH.m_temp = dht11_dat[2];
- if (g_THUnderObservation)
+ if (g_THUnderObservation)
{
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new humid level %d\n", TH.m_humid);
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new temp level %d\n", TH.m_temp);
OCStackResult res = OCCreateResource(&TH.m_handle,
"SoftSensorManager.Sensor",
"oc.mi.def",
- "/Thing_TempHumSensor1",
+ "/Thing_TempHumSensor",
OCEntityHandlerCb,
OC_DISCOVERABLE | OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created TH resource with result: %s", getResult(res));
--- /dev/null
+-include ../../../../build/arduino/environment.mk
+ARDUINO_DIR = /usr/share/arduino
+
+BUILD := release
+PLATFORM := arduinomega
+ARDUINO_PORT := ttyACM0
+
+SRC_PATH=../src
+# override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
+ARDUINOWIFI := 0
+
+APP_NAME := thserver
+
+TB_DIR = ../../../../../../resource/csdk
+LOGGER_DIR = $(TB_DIR)/logger
+OC_LOG_DIR = $(TB_DIR)/../oc_logger
+TBSTACK_DIR = $(TB_DIR)/stack
+TBSOCKET_DIR = $(TB_DIR)/ocsocket
+
+include $(TB_DIR)/local.properties
+include $(TB_DIR)/$(PLATFORM).properties
+
+VPATH := $(SDIR_ARD_PLATFORM)
+
+#include directories
+OCSOCK_DIR = $(TB_DIR)/ocsocket
+LOGGER_DIR = $(TB_DIR)/logger
+STACK_DIR = $(TB_DIR)/stack
+INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(OC_LOG_DIR)/include -I$(LOGGER_DIR)/include -I$(STACK_DIR)/include
+
+CC_FLAGS.debug := -O1 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic
+CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -fpic
+
+CFLAGS := $(CC_FLAGS.$(BUILD)) -DTB_LOG
+
+ifeq ($(ARDUINOWIFI),1)
+ CFLAGS += -DARDUINOWIFI
+ ARDUINO_SHIELD_TYPE := "/wifi_shield"
+ TRANSPORT_OBJS = $(WIFI_COBJ)
+else
+ ARDUINO_SHIELD_TYPE := "/ethernet_shield"
+ TRANSPORT_OBJS = $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ)
+endif
+
+OUT_DIR := $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
+
+OBJ_DIR := $(OUT_DIR)/bin
+
+all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).hex
+
+core.a: $(PLATFORM_OBJS)
+ @cd $(OBJ_DIR) && $(AR) -x ../../../../$(TB_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/liboctbstack.a
+ $(AR) rcs $(OBJ_DIR)/$@ $(foreach obj, $^, $(OBJ_DIR)/$(obj)) $(OBJ_DIR)/*.o
+ @cd $(OBJ_DIR) && $(RANLIB) $@
+
+prep_dirs:
+ -mkdir $(PLATFORM)
+ -mkdir $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
+ -mkdir $(OUT_DIR)
+ -mkdir $(OBJ_DIR)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
+%.o: %.cpp
+ $(CXX) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
+%.o: ${SRC_PATH}/%.cpp
+ $(CXX) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
+
+$(APP_NAME).elf: $(APP_NAME).o core.a
+ifeq ($(PLATFORM),arduinomega)
+ $(CC) -Os -Wl,--gc-sections,--relax $(CFLAGS_PLATFORM) $(foreach obj, $^, $(OBJ_DIR)/$(obj)) -lm -o $(OBJ_DIR)/$@
+else ifeq ($(PLATFORM),arduinodue)
+ $(CXX) -Os -Wl,--gc-sections -mcpu=cortex-m3 -T/$(SDIR_ARD_CORE_3)/linker_scripts/gcc/flash.ld -Wl,-Map,$(APP_NAME).map -o $(OBJ_DIR)/$@ -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group $(foreach obj, $(APP_NAME).o $(SYSCALLS_SAM3_OBJ) $(SPI_OBJ) $(TRANSPORT_OBJS) $(VARIANT_OBJ) core.a, $(OBJ_DIR)/$(obj)) $(SDIR_ARD_CORE_3)/libsam_sam3x8e_gcc_rel.a -Wl,--end-group
+else
+ $(error Wrong value for PLATFORM !!)
+endif
+
+$(APP_NAME).hex: $(APP_NAME).elf
+ifeq ($(PLATFORM),arduinomega)
+ $(AVR_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $(OBJ_DIR)/$< $(OBJ_DIR)/$(APP_NAME).eep
+ $(AVR_OBJCOPY) -O ihex -R .eeprom $(OBJ_DIR)/$< $(OUT_DIR)/$@
+else ifeq ($(PLATFORM),arduinodue)
+ $(ARDUINO_TOOLS_DIR)/arm-none-eabi-objcopy -O binary $(OBJ_DIR)/$< $(OUT_DIR)/$@
+else
+ $(error Wrong value for PLATFORM !!)
+endif
+
+install: all
+ifeq ($(PLATFORM),arduinomega)
+ $(AVR_PROGRAMMER) -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(OUT_DIR)/$(APP_NAME).hex:i
+else ifeq ($(PLATFORM),arduinodue)
+ stty -F /dev/$(ARDUINO_PORT) speed 1200 cs8 -cstopb -parenb
+ $(ARDUINO_DIR)/hardware/tools/bossac -i -d --port=$(ARDUINO_PORT) -U false -e -w -v -b $(OUT_DIR)/$(APP_NAME).hex -R
+else
+ $(error Wrong value for PLATFORM !!)
+endif
+
+.PHONY: clean
+
+clean: legacy_clean
+ rm -rf arduinomega
+ rm -rf arduinodue
+
+legacy_clean:
+ @rm -rf bin
+ @rm -f *.o *.d *.elf *.eep *.a *.hex *.bin *.map *-
--- /dev/null
+
+Followings should be done befor building Arudno applications
+
+1. Applications on arduino conform the Iotivity Base released on 22-Aug-2014.
+ (Ver. 22th Aug(oic-resource: commit: cdeeed62bd9b11beb2cdd340168e766088c18dac [cdeeed6]))
+
+ For successful execution, you have to copy the file, local.properties, into the following pathes:
+ - oic-resource/csdk/
+ - oic-resource/csdk/libcoap-4.1.1
+
+
+2. Time.c, Time.h should be copied in your machine and they should be refered in the Makefile as followings
+
+ Makefile path: / oic-resource / csdk / libcoap-4.1.1 / makefile
+
+ path to be modified:
+
+ - INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time ---> for Time.h
+ - SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time ---> for Time.c
\ No newline at end of file
--- /dev/null
+/******************************************************************
+*
+* Copyright 2014 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.
+*
+******************************************************************/
+
+// Do not remove the include below
+#include "Arduino.h"
+
+#define dht11_pin 12
+
+#include "logger.h"
+#include "ocstack.h"
+#include <string.h>
+
+#ifdef ARDUINOWIFI
+// Arduino WiFi Shield
+#include <SPI.h>
+#include <WiFi.h>
+#include <WiFiUdp.h>
+#else
+// Arduino Ethernet Shield
+#include <EthernetServer.h>
+#include <Ethernet.h>
+#include <Dns.h>
+#include <EthernetClient.h>
+#include <util.h>
+#include <EthernetUdp.h>
+#include <Dhcp.h>
+#endif
+
+const char *getResult(OCStackResult result);
+
+PROGMEM const char TAG[] = "ArduinoServer";
+
+int g_THUnderObservation = 0;
+void createTHResource();
+typedef struct THRESOURCE
+{
+ OCResourceHandle m_handle;
+ int m_temp;
+ int m_humid;
+} THResource;
+
+static THResource TH;
+
+/// This is the port which Arduino Server will use for all unicast communication with it's peers
+static uint16_t OC_WELL_KNOWN_PORT = 5683;
+
+#define JSON_BASE00 "{\"href\":\"\",\"rep\":{"
+#define JSON_BASE01 "\"0\":\"temperature\",\"1\":\"int\",\"2\":\""
+#define JSON_BASE02 "\",\"3\":\"humidity\",\"4\":\"int\",\"5\":\""
+#define JSON_BASE03 "\"}}"
+
+char temp[100];
+
+#define LENGTH_VAR 100
+static int base_length = 0;
+
+bool JsonGenerator( THResource &th, char *jsonBuf, uint16_t buf_length )
+{
+ if ( (buf_length - base_length) < LENGTH_VAR )
+ {
+ OC_LOG_V(ERROR, TAG, "Error : length is very long.");
+ return false;
+ }
+
+ sprintf(jsonBuf, JSON_BASE00 JSON_BASE01"%d", th.m_temp);
+ sprintf(jsonBuf + strlen(jsonBuf), JSON_BASE02"%d"JSON_BASE03, th.m_humid);
+
+ Serial.println(jsonBuf);
+
+ return true;
+}
+
+byte read_dht11_dat()
+{
+ byte i = 0;
+ byte result = 0;
+ for (i = 0; i < 8; i++)
+ {
+ while (!digitalRead(dht11_pin));
+ delayMicroseconds(30);
+ if (digitalRead(dht11_pin) != 0 )
+ bitSet(result, 7 - i);
+ while (digitalRead(dht11_pin));
+ }
+ return result;
+}
+
+#ifdef ARDUINOWIFI
+// Arduino WiFi Shield
+// Note : Arduino WiFi Shield currently does NOT support multicast and therefore
+// this server will NOT be listening on 224.0.1.187 multicast address.
+
+/// WiFi Shield firmware with Intel patches
+static const char INTEL_WIFI_SHIELD_FW_VER[] = "1.2.0";
+
+/// WiFi network info and credentials
+char ssid[] = "SoftSensor_AP";
+char pass[] = "1234567890";
+
+//char ssid[] = "Iotivity-1";
+//char pass[] = "1234567890";
+
+int ConnectToNetwork()
+{
+ char *fwVersion;
+ int status = WL_IDLE_STATUS;
+ // check for the presence of the shield:
+ if (WiFi.status() == WL_NO_SHIELD)
+ {
+ OC_LOG(ERROR, TAG, PCF("WiFi shield not present"));
+ return -1;
+ }
+
+ // Verify that WiFi Shield is running the firmware with all UDP fixes
+ fwVersion = WiFi.firmwareVersion();
+ OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
+ if ( strncmp(fwVersion, INTEL_WIFI_SHIELD_FW_VER, sizeof(INTEL_WIFI_SHIELD_FW_VER)) != 0 )
+ {
+ OC_LOG(DEBUG, TAG, PCF("!!!!! Upgrade WiFi Shield Firmware version !!!!!!"));
+ return -1;
+ }
+
+ // attempt to connect to Wifi network:
+ while (status != WL_CONNECTED)
+ {
+ OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
+ status = WiFi.begin(ssid, pass);
+
+ // wait 10 seconds for connection:
+ delay(10000);
+ }
+ OC_LOG(DEBUG, TAG, PCF("Connected to wifi"));
+
+ IPAddress ip = WiFi.localIP();
+ OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ return 0;
+}
+#else
+// Arduino Ethernet Shield
+int ConnectToNetwork()
+{
+ // Note: ****Update the MAC address here with your shield's MAC address****
+ uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x0E, 0xB8, 0xAC};
+
+ uint8_t error = Ethernet.begin(ETHERNET_MAC);
+ if (error == 0)
+ {
+ OC_LOG_V(ERROR, TAG, "error is: %d", error);
+ return -1;
+ }
+ IPAddress ip = Ethernet.localIP();
+ OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ return 0;
+}
+#endif //ARDUINOWIFI
+
+// On Arduino Atmel boards with Harvard memory architecture, the stack grows
+// downwards from the top and the heap grows upwards. This method will print
+// the distance(in terms of bytes) between those two.
+// See here for more details :
+// http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
+void PrintArduinoMemoryStats()
+{
+#ifdef ARDUINO_AVR_MEGA2560
+ //This var is declared in avr-libc/stdlib/malloc.c
+ //It keeps the largest address not allocated for heap
+ extern char *__brkval;
+ //address of tmp gives us the current stack boundry
+ int tmp;
+ OC_LOG_V(INFO, TAG, "Stack: %u Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
+ OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
+ ((unsigned int)&tmp - (unsigned int)__brkval));
+#endif
+}
+
+
+// This is the entity handler for the registered resource.
+// This is invoked by OCStack whenever it recevies a request for this resource.
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest *entityHandlerRequest )
+{
+ OCEntityHandlerResult ehRet = OC_EH_OK;
+ OCEntityHandlerResponse response = {0};
+ char payload[MAX_RESPONSE_LENGTH] = {0};
+
+ if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+ {
+ OC_LOG (INFO, TAG, PCF("Flag includes OC_REQUEST_FLAG"));
+ if (OC_REST_GET == entityHandlerRequest->method)
+ {
+ if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
+ {
+ }
+ else
+ {
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ if (OC_REST_PUT == entityHandlerRequest->method)
+ {
+ //Do something with the 'put' payload
+ if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
+ {
+ }
+ else
+ {
+ ehRet = OC_EH_ERROR;
+ }
+ }
+
+ if (ehRet == OC_EH_OK)
+ {
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = entityHandlerRequest->requestHandle;
+ response.resourceHandle = entityHandlerRequest->resource;
+ response.ehResult = ehRet;
+ response.payload = (unsigned char *)payload;
+ response.payloadSize = strlen(payload);
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response.resourceUri);
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Error sending response");
+ ehRet = OC_EH_ERROR;
+ }
+ }
+ }
+ if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG))
+ {
+ if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action)
+ {
+ OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_REGISTER from client"));
+ g_THUnderObservation = 1;
+ }
+ else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action)
+ {
+ OC_LOG (INFO, TAG, PCF("Received OC_OBSERVE_DEREGISTER from client"));
+ }
+ }
+
+ return ehRet;
+}
+
+// This method is used to display 'Observe' functionality of OC Stack.
+static uint8_t modCounter = 0;
+void *ChangeTHRepresentation (void *param)
+{
+ (void)param;
+ OCStackResult result = OC_STACK_ERROR;
+ modCounter += 1;
+ if (modCounter % 10 ==
+ 0) // Matching the timing that the Linux Sample Server App uses for the same functionality.
+ {
+
+ byte dht11_dat[5];
+ byte i;// start condition
+
+ digitalWrite(dht11_pin, LOW);
+ delay(18);
+ digitalWrite(dht11_pin, HIGH);
+ delayMicroseconds(1);
+ pinMode(dht11_pin, INPUT);
+ delayMicroseconds(40);
+
+ if (digitalRead(dht11_pin))
+ {
+ Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW
+ delay(1000);
+ return NULL;
+ }
+ delayMicroseconds(80);
+ if (!digitalRead(dht11_pin))
+ {
+ Serial.println("dht11 start condition 2 not met"); //wair for second response signal:HIGH
+ return NULL;
+ }
+
+ delayMicroseconds(80);// now ready for data reception
+ for (i = 0; i < 5; i++)
+ {
+ dht11_dat[i] = read_dht11_dat();
+ } //recieved 40 bits data. Details are described in datasheet
+
+ pinMode(dht11_pin, OUTPUT);
+ digitalWrite(dht11_pin, HIGH);
+ byte dht11_check_sum = dht11_dat[0] + dht11_dat[2]; // check check_sum
+ if (dht11_dat[4] != dht11_check_sum)
+ {
+ Serial.println("DHT11 checksum error");
+ }
+ Serial.print("Current humdity = ");
+ Serial.print(dht11_dat[0], DEC);
+ Serial.print("% ");
+ Serial.print("temperature = ");
+ Serial.print(dht11_dat[2], DEC);
+ Serial.println("C ");
+
+ TH.m_humid = dht11_dat[0];
+ TH.m_temp = dht11_dat[2];
+
+ if (g_THUnderObservation)
+ {
+ OC_LOG_V(INFO, TAG, " =====> Notifying stack of new humid level %d\n", TH.m_humid);
+ OC_LOG_V(INFO, TAG, " =====> Notifying stack of new temp level %d\n", TH.m_temp);
+
+ result = OCNotifyAllObservers (TH.m_handle, OC_NA_QOS);
+
+ if (OC_STACK_NO_OBSERVERS == result)
+ {
+ g_THUnderObservation = 0;
+ }
+ }
+ }
+ return NULL;
+}
+
+
+
+//The setup function is called once at startup of the sketch
+void setup()
+{
+ pinMode(dht11_pin, OUTPUT);
+ digitalWrite(dht11_pin, HIGH);
+
+ // Add your initialization code here
+ OC_LOG_INIT();
+
+ OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
+ uint16_t port = OC_WELL_KNOWN_PORT;
+
+ // Connect to Ethernet or WiFi network
+ if (ConnectToNetwork() != 0)
+ {
+ OC_LOG(ERROR, TAG, "Unable to connect to network");
+ return;
+ }
+
+ // Initialize the OC Stack in Server mode
+ if (OCInit(NULL, port, OC_SERVER) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("OCStack init error"));
+ return;
+ }
+ OCStartPresence(60);
+ // Declare and create the example resource: TH
+ createTHResource();
+
+}
+
+// The loop function is called in an endless loop
+void loop()
+{
+ // This artificial delay is kept here to avoid endless spinning
+ // of Arduino microcontroller. Modify it as per specfic application needs.
+ delay(2000);
+
+ // This call displays the amount of free SRAM available on Arduino
+ PrintArduinoMemoryStats();
+
+ if (OCProcess() != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, PCF("OCStack process error"));
+ return;
+ }
+ ChangeTHRepresentation(NULL);
+}
+
+void createTHResource()
+{
+ TH.m_humid = 0;
+ TH.m_temp = 0;
+
+ OCStackResult res = OCCreateResource(&TH.m_handle,
+ "SoftSensorManager.Sensor",
+ "oc.mi.def",
+ "/Thing_TempHumSensor1",
+ OCEntityHandlerCb,
+ OC_DISCOVERABLE | OC_OBSERVABLE);
+ OC_LOG_V(INFO, TAG, "Created TH resource with result: %s", getResult(res));
+}
+
+const char *getResult(OCStackResult result)
+{
+ switch (result)
+ {
+ case OC_STACK_OK:
+ return "OC_STACK_OK";
+ case OC_STACK_INVALID_URI:
+ return "OC_STACK_INVALID_URI";
+ case OC_STACK_INVALID_QUERY:
+ return "OC_STACK_INVALID_QUERY";
+ case OC_STACK_INVALID_IP:
+ return "OC_STACK_INVALID_IP";
+ case OC_STACK_INVALID_PORT:
+ return "OC_STACK_INVALID_PORT";
+ case OC_STACK_INVALID_CALLBACK:
+ return "OC_STACK_INVALID_CALLBACK";
+ case OC_STACK_INVALID_METHOD:
+ return "OC_STACK_INVALID_METHOD";
+ case OC_STACK_NO_MEMORY:
+ return "OC_STACK_NO_MEMORY";
+ case OC_STACK_COMM_ERROR:
+ return "OC_STACK_COMM_ERROR";
+ case OC_STACK_INVALID_PARAM:
+ return "OC_STACK_INVALID_PARAM";
+ case OC_STACK_NOTIMPL:
+ return "OC_STACK_NOTIMPL";
+ case OC_STACK_NO_RESOURCE:
+ return "OC_STACK_NO_RESOURCE";
+ case OC_STACK_RESOURCE_ERROR:
+ return "OC_STACK_RESOURCE_ERROR";
+ case OC_STACK_SLOW_RESOURCE:
+ return "OC_STACK_SLOW_RESOURCE";
+ case OC_STACK_NO_OBSERVERS:
+ return "OC_STACK_NO_OBSERVERS";
+ case OC_STACK_ERROR:
+ return "OC_STACK_ERROR";
+ default:
+ return "UNKNOWN";
+ }
+}
-# //******************************************************************
-# //
-# // Copyright 2014 Intel Mobile Communications GmbH 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 ../../../../build/arduino/environment.mk
ARDUINO_DIR = /usr/share/arduino
--- /dev/null
+/******************************************************************
+*
+* Copyright 2014 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.
+*
+******************************************************************/
+
+#ifndef GENERALDATA_H_
+#define GENERALDATA_H_
+
+#include <iostream>
+#include <map>
+#include <vector>
+
+#define TYPE_NODEFINE 0
+#define TYPE_STRING 1
+#define TYPE_CHAR 2
+#define TYPE_INT 3
+#define TYPE_SHORT 4
+#define TYPE_FLOAT 5
+#define TYPE_DOUBLE 6
+
+// Macro Function.
+#define VOIDINIT_CHECK() \
+ if ( flag == false ) { \
+ printf("Error : Not yet set data.\n"); \
+ return ; \
+ }
+
+#define BOOLINIT_CHECK() \
+ if ( flag == false ) { \
+ printf("Error : Not yet set data.\n"); \
+ return false; \
+ }
+
+
+class Virtual_data
+{
+ private :
+ int dataType;
+
+ void s2data( const char *value);
+
+ public :
+
+ Virtual_data( void );
+
+ Virtual_data(int type);
+
+ void put(std::string value);
+
+ void put(char *value);
+
+ int get( std::string *value);
+
+ template <typename TYPE>
+ int get( TYPE *value)
+ {
+ void *data = get_data();
+
+ switch (dataType)
+ {
+ case TYPE_CHAR :
+ case TYPE_INT :
+ case TYPE_SHORT :
+ *value = (TYPE)(*(int *)data);
+ return 1;
+ break;
+ case TYPE_FLOAT :
+ *value = (TYPE)(*(float *)data);
+ return 1;
+ case TYPE_DOUBLE :
+ *value = (TYPE)(*(double *)data);
+ return 1;
+ break;
+ case TYPE_NODEFINE :
+ printf("Error : Not yet defined with dataType variable.\n");
+ }
+
+ return 0;
+ }
+
+ // Virtual Function.
+ virtual void put_data( void *value ) = 0;
+
+ virtual void *get_data( void ) = 0;
+};
+
+
+
+class GeneralData
+{
+ private :
+ bool flag;
+ std::string Name;
+ int dataType;
+ class Virtual_data *pValue;
+
+ void set_dataType(const char *type);
+
+ public :
+ GeneralData( void );
+
+ GeneralData( std::string name, std::string type );
+
+ GeneralData( std::string name, std::string type, std::string value );
+
+ bool initial( std::string name, std::string type );
+
+ bool get_Name( std::string &name );
+
+ void put( std::string value );
+
+ void put( const char *value );
+
+ int get_DataType( void );
+
+ bool get( std::string *data );
+
+ template <typename TYPE>
+ bool get( TYPE *data)
+ {
+ BOOLINIT_CHECK();
+
+ if ( pValue->get(data) == NULL )
+ {
+ printf("Error : No data.\n");
+ *data = 0;
+ return false;
+ }
+
+ return true;
+ }
+
+};
+
+void Conversion_DataFormat( std::vector < std::map< std::string, std::string > > lVector ,
+ std::vector< GeneralData > &gVector );
+
+#endif /* GENERALDATA_H_ */
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2014 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.
+ *
+ ******************************************************************/
+
+/*
+ * Indoor Trajectory Soft Sensor
+ */
+
+#ifndef INDOORTRAJECTORYSENSOR_H_
+#define INDOORTRAJECTORYSENSOR_H_
+
+/**
+ * This header file is included to define _EXPORT_.
+ */
+#include "SSMModelDefinition.h"
+#include "Trajectory.h"
+
+#define _EXPORT_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+void _EXPORT_ InitializeContext(ICtxDelegate *pDelegate);
+#ifdef __cplusplus
+
+};
+#endif
+
+namespace ITSName
+{
+#define PHYSICAL_EA 1
+
+ typedef struct _physicalInput_
+ {
+ char *m_thingName;
+ int m_inputNum;
+ void *m_pInputStruct;
+ } physicalInput;
+
+ typedef enum
+ {
+ SUCCESS = 0, ERROR, NO_ELEMENT
+ } ITSResult;
+
+ class SThing
+ {
+ public:
+ std::string timestamp;
+ std::string ID;
+ float distance;
+ int proximity;
+ float SD;
+
+ SThing( void ) : timestamp(""), ID(""), distance(0.0), proximity(0), SD(0.0) {}
+ ~SThing( void ) {}
+ };
+
+ class Things
+ {
+ public :
+ SThing *things;
+ int EA;
+
+ Things(void) : EA(0), things(0) {}
+ Things( int ea ) : EA(ea), things(0)
+ {
+ things = new SThing[EA]();
+ }
+ ~Things( void )
+ {
+ if (things)
+ {
+ delete [] things;
+ things = 0;
+ }
+ }
+ };
+
+ class ITS: public ICtxEvent
+ {
+ private:
+ Things *m_TList;
+ SThing *m_closestThing;
+
+ int runLogic(std::vector< ContextData > &contextDataList);
+
+ public:
+ static physicalInput s_PHYSICAL_SENSORs[PHYSICAL_EA];
+
+ ITS();
+ ~ITS();
+
+ void onCtxEvent(enum CTX_EVENT_TYPE eventType, std::vector< ContextData > contextDataList);
+
+ ITSResult getInput(std::vector< ContextData > &contextDataList, CurrentService *CService );
+ ITSResult searchValidService( Things *things , CurrentService *CService );
+ Trajectory *makeTrajectory(CurrentService *CService);
+ ITSResult setOutput( Trajectory *m_result, ContextData *out );
+
+ friend void _EXPORT_ initializeContext(ICtxDelegate *pDelegate);
+ };
+}
+;
+
+#endif /* INDOORTRAJECTORYSENSOR_H_ */
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2014 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 MilliSecondTime();
+ static std::string MilliSecondAsString();
+ static std::string UTCSecondAsString();
+};
+
+#endif /* SYSTIMER_H_ */
--- /dev/null
+/******************************************************************
+*
+* Copyright 2014 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.
+*
+******************************************************************/
+
+#ifndef TRAJECTORY_H_
+#define TRAJECTORY_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+struct TrackeeInfo
+{
+ public :
+ std::string ID;
+};
+
+struct ThingInfo
+{
+ public :
+ std::string ID;
+ std::string ServiceType;
+ int proximity;
+};
+
+typedef std::map < std::string, ThingInfo > MAP_TYPE;
+
+class ServiceInfo
+{
+ private :
+ int things_ea;
+ MAP_TYPE validThings;
+
+ public :
+ std::string timestamp;
+
+ ServiceInfo( void );
+
+ ~ServiceInfo();
+
+ MAP_TYPE::iterator ThingBegin( void );
+
+ MAP_TYPE::iterator ThingEnd( void );
+
+ void insert( ThingInfo &thing );
+
+ ThingInfo *find( std::string thingID );
+
+ int getThingsEA( void );
+};
+
+class CurrentService
+{
+ public :
+ TrackeeInfo trackee;
+ ServiceInfo service;
+
+ CurrentService( void );
+
+ CurrentService( std::string trackeeID, std::string time );
+
+ ~CurrentService();
+};
+
+class Trajectory
+{
+ private :
+ TrackeeInfo trackee;
+ int latestServiceNum;
+ std::vector< ServiceInfo > ServiceList;
+ std::vector< ServiceInfo > *resultList;
+
+ public :
+ Trajectory( void );
+
+ Trajectory( std::string trackeeID );
+
+ ~Trajectory( void );
+
+ std::string getTrackeeID( void );
+
+// std::string getTrackeeServiceType( void );
+
+ int getTrajectoryDeepSize( void );
+
+ int TrajectoryUpdate( CurrentService &CurrentSvc );
+
+ std::vector<ServiceInfo> *getTrajectoryList( int latestNum, int ListSize );
+
+};
+
+
+
+#endif /* TRAJECTORY_H_ */
--- /dev/null
+/******************************************************************
+*
+* Copyright 2014 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "GeneralData.h"
+
+//#define __INTER_DEBUG__
+// Hidden Class define.
+template <typename TYPE>
+class AllFormat_data : public Virtual_data
+{
+ typedef Virtual_data base;
+ private :
+ TYPE data;
+
+ public :
+ AllFormat_data(int typenum) : base(typenum), data()
+ {
+#ifdef __INTER_DEBUG__
+ printf("[DEBUG] Test_data Constructor().\n");
+#endif
+ }
+
+ virtual void put_data( void *value)
+ {
+ data = *(TYPE *)value;
+ }
+
+ virtual void *get_data( void )
+ {
+ return (void *)&data;
+ }
+};
+
+
+
+/*******************************************
+ * Virtual_data class member function define.
+ */
+void Virtual_data::s2data( const char *value)
+{
+ switch (dataType)
+ {
+ case TYPE_CHAR :
+ {
+ char data = atoi(value);
+ put_data( (void *)&data );
+ }
+ break;
+ case TYPE_INT :
+ case TYPE_SHORT :
+ {
+ int data = atoi(value);
+ put_data( (void *)&data );
+ }
+ break;
+ case TYPE_FLOAT :
+ {
+ float data = atof(value);
+ put_data( (void *)&data );
+ }
+ break;
+ case TYPE_DOUBLE :
+ {
+ double data = atof(value);
+ put_data( (void *)&data );
+ }
+ break;
+ case TYPE_NODEFINE :
+ printf("Error: dataType must have defined.\n");
+ break;
+ default :
+ printf("Error: Not yet supported type.\n");
+ break;
+ }
+}
+
+Virtual_data::Virtual_data( void )
+{
+ dataType = TYPE_NODEFINE;
+}
+
+Virtual_data::Virtual_data(int type)
+{
+#ifdef __INTER_DEBUG__
+ printf("[DEBUG] Virtual_data Constructor().\n");
+#endif
+ dataType = type;
+}
+
+void Virtual_data::put(std::string value)
+{
+ if (dataType == TYPE_STRING )
+ put_data( (void *)&value );
+ else
+ s2data( value.c_str() );
+}
+
+void Virtual_data::put(char *value)
+{
+ if (dataType == TYPE_STRING )
+ {
+ std::string temp = std::string(value);
+ put_data( (void *)&temp );
+ }
+ else
+ s2data( value );
+}
+
+int Virtual_data::get( std::string *value)
+{
+ if (dataType != TYPE_STRING)
+ {
+ printf("Error : dataType is Not string.\n");
+ return 0;
+ }
+
+ void *data = get_data();
+ *value = *(std::string *)data;
+ return 1;
+}
+
+void Virtual_data::put_data( void *value )
+{
+ printf("Error: virtual function(put_data) called.\n");
+}
+
+void *Virtual_data::get_data( void )
+{
+ printf("Error: virtual function(get) called.\n");
+ return NULL;
+}
+
+
+
+
+
+
+/*******************************************
+ * GeneralData class member function define.
+ */
+void GeneralData::set_dataType(const char *type)
+{
+ if ( strstr(type, "string") != NULL )
+ {
+ dataType = TYPE_STRING;
+#ifdef __INTER_DEBUG__
+ printf("DataType is std::string.\n");
+#endif
+ return ;
+ }
+ if ( strstr(type, "char") != NULL )
+ {
+ dataType = TYPE_CHAR;
+#ifdef __INTER_DEBUG__
+ printf("DataType is Character.\n");
+#endif
+ return ;
+ }
+ if ( strstr(type, "int") != NULL )
+ {
+ dataType = TYPE_INT;
+#ifdef __INTER_DEBUG__
+ printf("DataType is Integer.\n");
+#endif
+ return ;
+ }
+ if ( strstr(type, "short") != NULL )
+ {
+ dataType = TYPE_SHORT;
+#ifdef __INTER_DEBUG__
+ printf("DataType is Short.\n");
+#endif
+ return ;
+ }
+ if ( strstr(type, "float") != NULL )
+ {
+ dataType = TYPE_FLOAT;
+#ifdef __INTER_DEBUG__
+ printf("DataType is Floating.\n");
+#endif
+ return ;
+ }
+ if ( strstr(type, "double") != NULL )
+ {
+ dataType = TYPE_DOUBLE;
+#ifdef __INTER_DEBUG__
+ printf("DataType is Double.\n");
+#endif
+ return ;
+ }
+
+ dataType = TYPE_NODEFINE;
+}
+
+GeneralData::GeneralData( void )
+{
+#ifdef __INTER_DEBUG__
+ printf("[DEBUG] Virtual_Test Constructor().\n");
+#endif
+ flag = false;
+ Name = "";
+ dataType = TYPE_NODEFINE;
+ pValue = 0;
+}
+
+GeneralData::GeneralData( std::string name, std::string type )
+{
+#ifdef __INTER_DEBUG__
+ printf("[DEBUG] Data_Normal Constructor().\n");
+#endif
+ flag = false;
+ Name = "";
+ dataType = TYPE_NODEFINE;
+ pValue = 0;
+
+ flag = initial( name, type );
+}
+
+GeneralData::GeneralData( std::string name, std::string type, std::string value )
+{
+#ifdef __INTER_DEBUG__
+ printf("[DEBUG] Data_Normal Constructor().\n");
+#endif
+ flag = false;
+ Name = "";
+ dataType = TYPE_NODEFINE;
+ pValue = 0;
+
+ flag = initial( name, type );
+ put(value);
+}
+
+bool GeneralData::initial( std::string name, std::string type )
+{
+ Name = name;
+ set_dataType( type.c_str() );
+
+ switch (dataType)
+ {
+ case TYPE_STRING :
+ pValue = new AllFormat_data<std::string>(dataType);
+ break;
+ case TYPE_CHAR :
+ pValue = new AllFormat_data<char>(dataType);
+ break;
+ case TYPE_INT :
+ pValue = new AllFormat_data<int>(dataType);
+ break;
+ case TYPE_SHORT :
+ pValue = new AllFormat_data<short>(dataType);
+ break;
+ case TYPE_FLOAT :
+ pValue = new AllFormat_data<float>(dataType);
+ break;
+ case TYPE_DOUBLE :
+ pValue = new AllFormat_data<double>(dataType);
+ break;
+ case TYPE_NODEFINE :
+ pValue = 0;
+ printf("Error : set_dataType()function is returned TYPE_NODEFINE.\n");
+ break;
+ }
+
+ return true;
+}
+
+bool GeneralData::get_Name( std::string &name )
+{
+ BOOLINIT_CHECK();
+
+ name = Name;
+ return true;
+}
+
+void GeneralData::put( std::string value )
+{
+ VOIDINIT_CHECK();
+ pValue->put(value);
+}
+
+void GeneralData::put( const char *value )
+{
+ VOIDINIT_CHECK();
+ pValue->put(value);
+}
+
+int GeneralData::get_DataType( void )
+{
+ BOOLINIT_CHECK();
+
+ return dataType;
+}
+
+bool GeneralData::get( std::string *data )
+{
+ BOOLINIT_CHECK();
+
+ if ( pValue->get(data) == NULL )
+ {
+ printf("Error : No data.\n");
+ *data = "";
+ return false;
+ }
+
+ return true;
+}
+
+
+
+void Conversion_DataFormat( std::vector < std::map< std::string, std::string > > lVector ,
+ std::vector< GeneralData > &gVector )
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ std::string name;
+ std::string type;
+ std::string value;
+
+ for (unsigned int j = 0; j < lVector.size(); j++)
+ {
+ name = lVector[j]["name"];
+ type = lVector[j]["type"];
+ value = lVector[j]["value"];
+
+ GeneralData pValue(name, type, value);
+ gVector.push_back(pValue);
+ }
+
+ /*************************************************
+ * Debugging print ( GeneralData format confirm. )
+ */
+#ifdef __INTERNAL_DEBUG__
+ for (unsigned int j = 0; j < gVector.size(); j++)
+ {
+ if ( gVector[j].get_Name(name) == false )
+ {
+ printf("Error : Not initialed.\n");
+ return ;
+ }
+
+ int dataType = gVector[j].get_DataType();
+ switch (dataType)
+ {
+ case TYPE_STRING :
+ {
+ std::string data;
+ if ( gVector[j].get(&data) == false )
+ {
+ printf("Error : Not initialed.\n");
+ return ;
+ }
+ printf("name=%s , type=%d, value=%s\n", name.c_str(), dataType, data.c_str() );
+ }
+ break;
+ case TYPE_CHAR :
+ case TYPE_SHORT :
+ case TYPE_INT :
+ {
+ int data;
+ if ( gVector[j].get(&data) == false )
+ {
+ printf("Error : Not initialed.\n");
+ return ;
+ }
+ printf("name=%s , type=%d, value=%d\n", name.c_str(), dataType, data );
+ }
+ break;
+ case TYPE_FLOAT :
+ case TYPE_DOUBLE :
+ {
+ float data;
+ if ( gVector[j].get(&data) == false )
+ {
+ printf("Error : Not initialed.\n");
+ return ;
+ }
+ printf("name=%s , type=%d, value=%f\n", name.c_str(), dataType, data );
+ }
+ break;
+ }
+ }
+#endif
+
+ printf("Conversion_DataFormat() is Successful.\n");
+}
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2014 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 "ITS.h"
+#include "GeneralData.h"
+#include "SysTimer.h"
+
+using namespace ITSName;
+
+//#define __INTERNAL_DEBUG__
+#define SENSOR_NAME "IndoorTrajectorySensor"
+
+#define INPUT_EA 4
+#define SEQ_ID 0
+#define SEQ_DISTANCE 1
+#define SEQ_PROXIMITY 2
+#define SEQ_SD 3
+
+
+
+#define TRACKEEID_NAME "trackeeID"
+#define THINGS_NAME "things"
+char *inputName[INPUT_EA] =
+{ (char *)"ID", (char *)"distance", (char *)"proximity", (char *)"SD" };
+
+#define INDEX_TRACKER_THING 0
+physicalInput ITS::s_PHYSICAL_SENSORs[PHYSICAL_EA] =
+{
+ { (char *)"Tracker_Thing", INPUT_EA, (void *) &inputName },
+// { (char*)"Thing_TempHumSensor1", INPUT_EA, (void*)&inputName }
+};
+
+ICtxDelegate *g_pDelegate;
+
+// map<TrackeeID, Trajectory>
+typedef std::map < std::string, Trajectory > TrajectoryMap;
+TrajectoryMap trajectorys;
+
+
+void parserTracker_Thing( int seq, std::vector< GeneralData > &gVector, CurrentService *CService,
+ Things **output )
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] " << __func__ << " is called." << std::endl;
+#endif
+
+ int isted_cnt = 0;
+
+ int InputNum = ITS::s_PHYSICAL_SENSORs[seq].m_inputNum;
+ char **pchar = (char **) (ITS::s_PHYSICAL_SENSORs[seq].m_pInputStruct);
+ if (InputNum == 0)
+ {
+ std::cout << "No input List." << std::endl;
+ return ;
+ }
+
+ std::string name = "";
+ gVector[0].get_Name(name);
+
+ if (name.compare(TRACKEEID_NAME) == 0 )
+ {
+ gVector[0].get( &(CService->trackee.ID) );
+ }
+
+ if ( CService->trackee.ID == "" || CService->trackee.ID.length() == 0 )
+ {
+ printf("Error : trackee.ID is NULL.\n");
+ return ;
+ }
+
+ CService->service.timestamp = SysTimer::MilliSecondTime();
+
+ name = "";
+ gVector[1].get_Name(name);
+
+ if (name.compare(THINGS_NAME) == 0 )
+ {
+ int ea = 0;
+ gVector[1].get(&ea);
+
+ if ( *output)
+ {
+ delete *output;
+ *output = 0;
+ }
+
+ if ( *output == NULL )
+ {
+ *output = new Things(ea);
+ }
+ }
+
+ if ( *output == NULL )
+ {
+ printf("Error : m_TList is NULL.\n");
+ return ;
+ }
+
+ for (unsigned int j = 2; j < gVector.size(); j++)
+ {
+ gVector[j].get_Name(name);
+
+ int l = 0;
+ for ( l = 0; l < InputNum ; l++ )
+ {
+ if (name.compare(*(pchar + l)) == 0)
+ break;
+ }
+
+ switch (l)
+ {
+ case SEQ_ID: // id
+ gVector[j].get( &((*output)->things[isted_cnt / INPUT_EA].ID) );
+ break;
+ case SEQ_DISTANCE: // distance
+ gVector[j].get( &((*output)->things[isted_cnt / INPUT_EA].distance) );
+ break;
+ case SEQ_PROXIMITY: // proximity
+ gVector[j].get( &((*output)->things[isted_cnt / INPUT_EA].proximity) );
+ break;
+ case SEQ_SD: // SD
+ gVector[j].get( &((*output)->things[isted_cnt / INPUT_EA].SD) );
+ break;
+ default:
+ std::cout << "Not Yet Supported Option." << std::endl;
+ return ;
+ } // switch
+
+ isted_cnt++;
+ } // for
+}
+
+
+void InitializeContext(ICtxDelegate *pDelegate)
+{
+ std::vector < ContextData > contextData;
+
+ ITS *eventCls = new ITS();
+ pDelegate->registerCallback(eventCls);
+ g_pDelegate = pDelegate;
+
+ std::cout << "ITS sensor loaded -01-" << std::endl;
+
+ return;
+}
+
+ITS::ITS()
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ m_TList = 0;
+ m_closestThing = 0;
+}
+
+ITS::~ITS()
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ if (m_TList)
+ {
+ delete m_TList;
+ m_TList = 0;
+ m_closestThing = 0;
+ }
+}
+
+void ITS::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 ITS::runLogic(std::vector< ContextData > &contextDataList)
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ ContextData out;
+ CurrentService CService;
+ Trajectory *tra = 0;
+ ITSResult flag = ERROR;
+
+ if (getInput(contextDataList, &CService) != SUCCESS)
+ {
+ std::cout << "Error : getInput() function failed." << std::endl;
+ return -1;
+ }
+
+ if ( (flag = searchValidService( m_TList, &CService )) != SUCCESS )
+ {
+ if ( flag == NO_ELEMENT )
+ return 0;
+
+ std::cout << "Error : searchValidService() function failed." << std::endl;
+ return -1;
+ }
+
+ if ( (tra = makeTrajectory(&CService)) == NULL)
+ {
+ std::cout << "Error : makeTrajectory() function failed." << std::endl;
+ return -1;
+ }
+
+ if ( setOutput( tra, &out ) != SUCCESS )
+ {
+ std::cout << "Error : setOutput() function failed." << std::endl;
+ return -1;
+ }
+
+ std::vector < ContextData > outList;
+ outList.push_back(out);
+ g_pDelegate->addOutput(outList);
+
+ return 0;
+}
+
+
+
+/**
+ * Get Input data (temperature, humidity) using resource Client of Iotivity base.
+ */
+ITSResult ITS::getInput(std::vector< ContextData > &contextDataList, CurrentService *CService )
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ int contextSize = 0;
+
+ if ((contextSize = contextDataList.size()) == 0)
+ {
+ std::cout << "Physical Context data is not exist." << std::endl;
+ return ERROR;
+ }
+
+ for (int i = 0; i < contextSize; i++)
+ {
+ for (int k = 0; k < PHYSICAL_EA; k++)
+ {
+ if (contextDataList[i].rootName == s_PHYSICAL_SENSORs[k].m_thingName)
+ {
+ std::vector< GeneralData > gVector;
+ Conversion_DataFormat( contextDataList[i].outputProperty,
+ gVector );
+
+ switch ( k )
+ {
+ case INDEX_TRACKER_THING:
+ parserTracker_Thing( k, gVector, CService, &m_TList);
+ break;
+ default :
+ break;
+ }
+
+ } // if
+ break;
+ } // for
+ }
+
+ std::cout << "Success : " << __func__ << std::endl;
+ return SUCCESS;
+}
+
+
+/**
+ * searchValidService Function.
+ */
+ITSResult ITS::searchValidService( Things *things , CurrentService *CService )
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ if ( things == NULL )
+ {
+ printf("Error : input Things List is null.\n");
+ return ERROR;
+ }
+
+#ifdef __INTERNAL_DEBUG__
+ for ( int i = 0; i < things->EA ; i++ )
+ {
+ printf("ID=%s, distance=%f, proximity=%d, SD=%f\n", things->things[i].ID.c_str(),
+ things->things[i].distance, things->things[i].proximity, things->things[i].SD );
+ }
+#endif
+ int validThingEA = 0;
+ for ( int i = 0; i < things->EA ; i++ )
+ {
+ if ( things->things[i].proximity <= 1 )
+ {
+ ThingInfo validThing;
+
+ validThing.ID = things->things[i].ID;
+ // validThing.ServiceType = things->things[i].ServiceType;
+ validThing.proximity = things->things[i].proximity;
+ CService->service.insert(validThing);
+ validThingEA++;
+ }
+ }
+
+ if ( CService->service.getThingsEA() == NULL )
+ {
+ printf("Valid Thing elements is not exist.\n");
+ return NO_ELEMENT;
+ }
+
+#ifdef __INTERNAL_DEBUG__
+ MAP_TYPE::iterator itr = CService->service.ThingBegin();
+ for ( ; itr != CService->service.ThingEnd() ; itr++ )
+ {
+ printf("CService: ID=%s, proximity=%d\n", itr->second.ID.c_str() , itr->second.proximity );
+ }
+#endif
+
+ return SUCCESS;
+}
+
+/**
+ * makeTrajectory Function.
+ */
+Trajectory *ITS::makeTrajectory(CurrentService *CService)
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ if ( CService == NULL )
+ {
+ printf("Error : input Current Service is null.\n");
+ return NULL;
+ }
+
+ // Trajectory Code contents.
+ Trajectory *tra = 0;
+ TrajectoryMap::iterator itr = trajectorys.find( CService->trackee.ID );
+
+ if ( itr == trajectorys.end() )
+ {
+ printf("itr == trajectorys.end().\n");
+ Trajectory tempTra(CService->trackee.ID);
+ trajectorys[CService->trackee.ID] = tempTra;
+ tra = &trajectorys[CService->trackee.ID];
+ printf("itr = %d\n", tra);
+ }
+ else
+ {
+ printf("itr is find trackeeID in trajectorys.\n");
+ tra = &itr->second;
+ }
+
+ tra->TrajectoryUpdate( *CService );
+
+ return tra;
+}
+
+std::string intToString(int n)
+{
+ std::stringstream ss;
+ ss << n;
+ return ss.str();
+}
+
+std::string floatToString(float n)
+{
+ std::stringstream ss;
+ ss << n;
+ return ss.str();
+}
+
+#define OUTPUT_TRAJECTORY_SIZE 2
+ITSResult ITS::setOutput( Trajectory *m_result, ContextData *out )
+{
+#ifdef __INTERNAL_DEBUG__
+ std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
+#endif
+
+ std::map < std::string, std::string > output_property;
+
+ out->rootName = SENSOR_NAME;
+ out->outputPropertyCount = 4 * OUTPUT_TRAJECTORY_SIZE + 1; // ref_count + 1;
+
+ std::vector< ServiceInfo > *serviceTra = m_result->getTrajectoryList(0, OUTPUT_TRAJECTORY_SIZE);
+ if ( serviceTra == NULL )
+ {
+ printf("Error : getTrajectoryList() is failed.\n");
+ return ERROR;
+ }
+ int serviceTraSize = serviceTra->size();
+
+ output_property.insert(std::make_pair("name", "trackeeID"));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", m_result->getTrackeeID()));
+
+ out->outputProperty.push_back(output_property);
+
+
+ for ( int i = 0; i < OUTPUT_TRAJECTORY_SIZE; i++ )
+ {
+ std::string time_value = "null";
+ std::string ref01_value = "null";
+ std::string ref02_value = "null";
+ std::string ref03_value = "null";
+
+ if ( i < serviceTraSize )
+ {
+ MAP_TYPE::iterator itr;
+ time_value = (*serviceTra)[i].timestamp;
+
+ switch ( (*serviceTra)[i].getThingsEA() )
+ {
+ case 0:
+ break;
+ case 1:
+ itr = (*serviceTra)[i].ThingBegin();
+ ref01_value = itr->second.ID;
+ break;
+ case 2:
+ itr = (*serviceTra)[i].ThingBegin();
+ ref01_value = itr->second.ID;
+ itr++;
+ ref02_value = itr->second.ID;
+ break;
+ default :
+ itr = (*serviceTra)[i].ThingBegin();
+ ref01_value = itr->second.ID;
+ itr++;
+ ref02_value = itr->second.ID;
+ itr++;
+ ref03_value = itr->second.ID;
+ break;
+ }
+ }
+
+ output_property.clear();
+ std::string time_name = "timeT" + intToString(i);
+ output_property.insert(std::make_pair("name", time_name));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", time_value ));
+
+ out->outputProperty.push_back(output_property);
+
+ output_property.clear();
+ std::string ref01_name = "ref01T" + intToString(i);
+ output_property.insert(std::make_pair("name", ref01_name));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", ref01_value ));
+
+ out->outputProperty.push_back(output_property);
+
+ output_property.clear();
+ std::string ref02_name = "ref02T" + intToString(i);
+ output_property.insert(std::make_pair("name", ref02_name));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", ref02_value ));
+
+ out->outputProperty.push_back(output_property);
+
+ output_property.clear();
+ std::string ref03_name = "ref03T" + intToString(i);
+ output_property.insert(std::make_pair("name", ref03_name));
+ output_property.insert(std::make_pair("type", "string"));
+ output_property.insert(std::make_pair("value", ref03_value ));
+
+ out->outputProperty.push_back(output_property);
+ }
+
+ std::cout << "Success : " << __func__ << std::endl;
+ return SUCCESS;
+}
+
--- /dev/null
+/******************************************************************
+ *
+ * Copyright 2014 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>
+#include <stdio.h>
+
+std::string SysTimer::MilliSecondTime()
+{
+ std::stringstream ss;
+ struct timeval tv;
+ time_t *p_time = NULL;
+ struct tm *localT = NULL;
+ char time_str[30] = {0,};
+
+ gettimeofday(&tv, NULL);
+ p_time = (time_t *) & (tv.tv_sec);
+ localT = localtime( p_time );
+
+ sprintf( time_str, "%04d-%02d-%02d %02d:%02d:%02d.%03ld", \
+ localT->tm_year + 1900, localT->tm_mon + 1, localT->tm_mday, \
+ localT->tm_hour, localT->tm_min, localT->tm_sec, \
+ tv.tv_usec / 1000 );
+
+ ss << time_str;
+ std::string strTime = ss.str();
+
+ return strTime;
+}
+
+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;
+}
--- /dev/null
+/******************************************************************
+*
+* Copyright 2014 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 "Trajectory.h"
+
+#include <stdlib.h>
+#include <iostream>
+
+// ServiceInfo Class member Function define.
+ServiceInfo::ServiceInfo( void ) : timestamp(""), things_ea(0) { validThings.clear(); }
+
+ServiceInfo::~ServiceInfo()
+{
+ if ( things_ea )
+ {
+ validThings.clear();
+ things_ea = 0;
+ }
+}
+
+MAP_TYPE::iterator ServiceInfo::ThingBegin( void )
+{
+ return validThings.begin();
+}
+
+MAP_TYPE::iterator ServiceInfo::ThingEnd( void )
+{
+ return validThings.end();
+}
+
+void ServiceInfo::insert( ThingInfo &thing )
+{
+ if ( find(thing.ID) == NULL )
+ {
+ validThings[thing.ID] = thing;
+ things_ea++;
+ }
+}
+
+ThingInfo *ServiceInfo::find( std::string thingID )
+{
+ MAP_TYPE::iterator itr = validThings.find( thingID );
+
+ if ( itr == validThings.end() )
+ return NULL;
+
+ return &itr->second;
+}
+
+int ServiceInfo::getThingsEA( void )
+{
+ return things_ea;
+}
+
+//
+// CurrentService Class member Function define.
+CurrentService::CurrentService( void )
+{
+ trackee.ID = "";
+}
+
+CurrentService::CurrentService( std::string trackeeID, std::string time)
+{
+ trackee.ID = trackeeID;
+ service.timestamp = time;
+}
+
+CurrentService::~CurrentService()
+{
+ trackee.ID = "";
+}
+
+//
+// Trajectory Class member Function define.
+Trajectory::Trajectory( void )
+{
+ trackee.ID = "";
+ ServiceList.clear();
+ latestServiceNum = ServiceList.size();
+ resultList = NULL;
+}
+
+Trajectory::Trajectory( std::string trackeeID )
+{
+ trackee.ID = trackeeID;
+ ServiceList.clear();
+ latestServiceNum = ServiceList.size();
+ resultList = NULL;
+}
+
+Trajectory::~Trajectory( void )
+{
+ ServiceList.clear();
+ latestServiceNum = ServiceList.size();
+ if ( resultList )
+ {
+ delete resultList;
+ resultList = NULL;
+ }
+}
+
+std::string Trajectory::getTrackeeID( void )
+{
+ return trackee.ID;
+}
+
+int Trajectory::getTrajectoryDeepSize( void )
+{
+ return latestServiceNum;
+}
+
+int Trajectory::TrajectoryUpdate( CurrentService &CurrentSvc )
+{
+ if ( latestServiceNum <= 0 )
+ goto INSERT_ELEMENT;
+
+ if ( trackee.ID.compare( CurrentSvc.trackee.ID ) == 0 )
+ {
+ // if trackee.ID of CurrentSvc == trackee.ID ,
+ ServiceInfo *recentSvc = &ServiceList[latestServiceNum - 1];
+ ServiceInfo *crtSvc = &CurrentSvc.service;
+
+ if ( recentSvc->getThingsEA() != crtSvc->getThingsEA() )
+ goto INSERT_ELEMENT ;
+
+ MAP_TYPE::iterator itr = crtSvc->ThingBegin();
+ for ( ; itr != crtSvc->ThingEnd() ; itr++ )
+ {
+ if ( recentSvc->find( itr->second.ID ) == NULL )
+ goto INSERT_ELEMENT;
+ }
+
+ return latestServiceNum;
+ }
+
+INSERT_ELEMENT :
+ ServiceList.push_back( CurrentSvc.service );
+ latestServiceNum = ServiceList.size();
+
+ return latestServiceNum;
+}
+
+std::vector<ServiceInfo> *Trajectory::getTrajectoryList( int latestNum, int ListSize )
+{
+ if ( latestServiceNum <= 0 || latestServiceNum <= latestNum )
+ return NULL;
+
+ if ( resultList )
+ {
+ delete resultList;
+ resultList = NULL;
+ }
+ resultList = new std::vector<ServiceInfo>;
+
+ int endIndex = 0;
+ if ( latestServiceNum >= (latestNum + ListSize) && ListSize > 0 )
+ {
+ endIndex = latestServiceNum - latestNum - ListSize;
+ }
+
+ for ( int i = (latestServiceNum - 1 - latestNum) ; i >= endIndex ; i-- )
+ resultList->push_back( ServiceList[i] );
+
+ return resultList;
+}
+
+
+