Patch 2 :Modified code for review comments.
Added more informative info in README files for Arduino Due builds.
Fixed unit test makefiles to accomodate the 'sole' local.properties file.
Patch 3 :Fixed compilation errors in unused tests.(Those test
should be removed from the repo). This would make the Build Server
stop complaining.
Patch 4 (Joey): Rebased on master.
Change-Id: Ib4a0e838a5519712bf3b0138e01abf74893593fb
the following definition(s):
ARDUINO_DIR = <PATH_TO_ARDUINO_INSTALL_DIR>/arduino-1.0.5
+ ARDUINO_TOOLS_DIR = <PATH_TO_ARDUINO_TOOLS> (location of avr-g++ and other avr tools)
To make octbstack.a in release mode:
- make PLATFORM=arduino
+ make PLATFORM=arduinomega (For Arduino Due, use <arduinodue>)
To make octbstack.a in debug mode:
- make PLATFORM=arduino BUILD=debug
+ make PLATFORM=arduinomega BUILD=debug (For Arduino Due, use <arduinodue>)
+Dependencies:
+ 1) Patch the Wiznet Ethernet library with the patch available at :
+ oic-utilities/tb/arduino_linux_ethernet_socket_cpp.patch
+ 2) Arduino builds are dependent on latest Time library. Download it from here:
+ http://www.pjrc.com/teensy/td_libs_Time.html
+ 3) Arduino Due has been tested with Arduino 1.5.7 framework.
+ 4) For Arduino Due, binary tools are located in:
+ /hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin
-------------------------------------------------------------------------------
**Clean-Up**
-------------------------------------------------------------------------------
--- /dev/null
+#Source directories
+SDIR_ARD_CORE_1 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino
+SDIR_ARD_CORE_2 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino/USB
+SDIR_ARD_CORE_3 = $(ARDUINO_DIR)/hardware/arduino/sam/variants/arduino_due_x
+SDIR_ARD_CORE_4 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino/avr
+SDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/sam/libraries/SPI
+SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet/src
+SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/src/utility
+SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
+
+SDIR_ARD_PLATFORM = $(SDIR_ARD_CORE_1):$(SDIR_ARD_CORE_2):$(SDIR_ARD_CORE_3):$(SDIR_ARD_CORE_4):$(SDIR_ARD_SPI):\
+ $(SDIR_ARD_ETH):$(SDIR_ARD_ETH_UTIL):$(SDIR_ARD_TIME)
+
+#include directories
+IDIR_ARD_CORE_1 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino
+IDIR_ARD_CORE_2 = $(ARDUINO_DIR)/hardware/arduino/sam/system/libsam
+IDIR_ARD_CORE_3 = $(ARDUINO_DIR)/hardware/arduino/sam/system/CMSIS/CMSIS/Include
+IDIR_ARD_CORE_4 = $(ARDUINO_DIR)/hardware/arduino/sam/system/CMSIS/Device/ATMEL
+IDIR_ARD_CORE_5 = $(ARDUINO_DIR)/hardware/arduino/sam/variants/arduino_due_x
+IDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/sam/libraries/SPI
+IDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet/src
+IDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/src/utility
+INCD_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
+
+
+INC_DIR_PLATFORM = -I$(IDIR_ARD_CORE_1) -I$(IDIR_ARD_CORE_2) -I$(IDIR_ARD_CORE_3) -I$(IDIR_ARD_CORE_4) -I$(IDIR_ARD_CORE_5) \
+ -I$(IDIR_ARD_SPI) -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL) -I$(INCD_ARD_TIME)
+
+#Compiler/Linker flags
+CFLAGS_PLATFORM = -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions \
+ -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=157 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM \
+ -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" \
+ -DWITH_ARDUINO -DNDEBUG
+
+#Compilers
+CCPLUS=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
+CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-gcc
+AR=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-ar
+RANLIB=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-ranlib
+AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/bossac
+
+CORE_COBJ = hooks.o dtostrf.o iar_calls_sam3.o WInterrupts.o wiring.o wiring_digital.o wiring_analog.o wiring_shift.o\
+ wiring_pulse.o USARTClass.o USBCore.o RingBuffer.o cortex_handlers.o
+CORE_CPPOBJ = itoa.o main.o Stream.o WMath.o WString.o Print.o IPAddress.o HID.o UARTClass.o CDC.o Reset.o cxxabi-compat.o
+ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o EthernetClient.o
+ETH_UTIL_CPPOBJ = socket.o w5100.o
+VARIANT_OBJ = variant.o
+SPI_OBJ = SPI.o
+SYSCALLS_SAM3_OBJ = syscalls_sam3.o
+
+PLATFORM_OBJS = $(SYSCALLS_SAM3_OBJ) $(SPI_OBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(VARIANT_OBJ) $(CORE_COBJ) $(CORE_CPPOBJ)
+
--- /dev/null
+
+#Source directories
+SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
+SDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
+SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
+SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
+SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
+SDIR_ARD_PLATFORM = $(SDIR_ARD_CORE):$(SDIR_ARD_SPI):$(SDIR_ARD_ETH):$(SDIR_ARD_ETH_UTIL):$(SDIR_ARD_TIME)
+
+#include directories
+INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
+INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/variants/mega
+INCD_ARD_SPI = -I$(ARDUINO_DIR)/libraries/SPI
+INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet
+INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/utility
+INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time
+
+INC_DIR_PLATFORM = $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_ETH) $(INCD_ARD_ETH_UTIL) $(INCD_ARD_TIME)
+
+#Compiler/Linker flags
+CFLAGS_PLATFORM = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DWITH_ARDUINO \
+ -MMD -std=c++0x -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -DATMEGA2560 -DNDEBUG
+
+#Compilers
+CCPLUS=$(ARDUINO_TOOLS_DIR)/avr-g++
+CC=$(ARDUINO_TOOLS_DIR)/avr-gcc
+AR=$(ARDUINO_TOOLS_DIR)/avr-ar
+RANLIB=$(ARDUINO_TOOLS_DIR)/avr-ranlib
+AVR_OBJCOPY=$(ARDUINO_TOOLS_DIR)/avr-objcopy
+AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/avrdude
+
+
+CORE_COBJ = WInterrupts.o wiring.o wiring_digital.o
+CORE_CPPOBJ = main.o Stream.o WMath.o WString.o HardwareSerial.o Print.o SPI.o IPAddress.o
+ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o
+ETH_UTIL_CPPOBJ = socket.o w5100.o
+OCDEPENDENT_CPPOBJ = wiring_analog.o
+
+PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(OCDEPENDENT_CPPOBJ)
+
STACK_DIR = $(ROOT_DIR)/stack
INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(LOGGER_DIR)/include -I$(RANDOM_DIR)/include
-#Arduino specific configurations
-INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
-INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/variants/mega
-INCD_ARD_SPI = -I$(ARDUINO_DIR)/libraries/SPI
-INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet
-INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/utility
-INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time
-SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
-
# Note for Arduino: The CC flag is set to the C++ compiler since Arduino build
# includes Time.h header file which has C++ style definitions.
ifeq ($(PLATFORM),android)
AR=ar
RANLIB=ranlib
CFLAGS_PLATFORM = -std=gnu99 -DWITH_POSIX
-else ifeq ($(PLATFORM),arduino)
- include local.properties
- CCPLUS=avr-g++
- CC=avr-g++
- AR=avr-ar
- RANLIB=avr-ranlib
- CFLAGS_PLATFORM = -DATMEGA2560 -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DWITH_ARDUINO -MMD -DNDEBUG
- INC_DIR_PLATFORM = $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_ETH) $(INCD_ARD_ETH_UTIL) $(INCD_ARD_TIME)
+else ifeq ($(PLATFORM),arduinomega)
+ include $(ROOT_DIR)/local.properties
+ include $(ROOT_DIR)/$(PLATFORM).properties
+ CC=$(ARDUINO_TOOLS_DIR)/avr-g++
+else ifeq ($(PLATFORM),arduinodue)
+ include $(ROOT_DIR)/local.properties
+ include $(ROOT_DIR)/$(PLATFORM).properties
+ CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
else
$(error Wrong value for PLATFORM !!)
endif
SOURCES:= pdu.c net.c debug.c encode.c uri.c coap_list.c resource.c hashkey.c \
str.c option.c async.c subscribe.c block.c logger.c ocrandom.c
VPATH := $(OCSOCK_DIR)/src:$(LOGGER_DIR)/src:$(RANDOM_DIR)/src
-ifeq ($(PLATFORM),arduino)
-SOURCES += ocsocket_arduino.c
-SOURCESCPP:= Time.cpp
-OBJECTSCPP:= $(patsubst %.cpp, %.o, $(SOURCESCPP))
-VPATH += $(SDIR_ARD_TIME)
+ifeq (arduino, $(findstring arduino,$(PLATFORM)))
+ SOURCES += ocsocket_arduino.c
+ SOURCESCPP:= Time.cpp
+ OBJECTSCPP:= $(patsubst %.cpp, %.o, $(SOURCESCPP))
+ VPATH += $(SDIR_ARD_TIME)
else
-SOURCES += ocsocket.c
+ SOURCES += ocsocket.c
endif
OBJECTS:= $(patsubst %.c, %.o, $(SOURCES))
coap_register_option(c, COAP_OPTION_BLOCK1);
#if defined(WITH_POSIX) || defined(WITH_ARDUINO)
-#if 0
- c->sockfd = socket(listen_addr->addr.sa.sa_family, SOCK_DGRAM, 0);
- if ( c->sockfd < 0 ) {
-#ifndef NDEBUG
- coap_log(LOG_EMERG, "coap_new_context: socket\n");
-#endif /* WITH_NDEBUG */
- goto onerror;
- }
-
- if ( setsockopt( c->sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse) ) < 0 ) {
-#ifndef NDEBUG
- coap_log(LOG_WARNING, "setsockopt SO_REUSEADDR\n");
-#endif
- }
-
- if (bind(c->sockfd, &listen_addr->addr.sa, listen_addr->size) < 0) {
-#ifndef NDEBUG
- coap_log(LOG_EMERG, "coap_new_context: bind\n");
-#endif
- goto onerror;
- }
-
- return c;
-
- onerror:
- if ( c->sockfd >= 0 )
- close ( c->sockfd );
- coap_free( c );
- return NULL;
-#endif //0
if (OCInitUDP((OCDevAddr *)listen_addr, (int32_t *)&(c->sockfd)) != ERR_SUCCESS) {
coap_free( c);
return NULL;
# override with `make BUILD=release`
# default to release build
BUILD := release
+PLATFORM := linux
+
+ROOT_DIR = ..
# You must create the file "local.properties" on your local machine which contains any local paths, etc
# local_settings.mk should NOT be committed to repo
-include ./local.properties
+include $(ROOT_DIR)/local.properties
# GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
# Example:
# GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
* Only defined for Arduino
*/
void OCLogInit() {
- #ifdef TB_LOG
Serial.begin(115200);
- #endif
}
/**
* @param logStr - log string
*/
void OCLogString(LogLevel level, PROGMEM const char * tag, const char * logStr) {
- #ifdef TB_LOG
if (!logStr || !tag) {
return;
}
Serial.print(F(": "));
Serial.println(logStr);
- #endif
}
/**
* @param bufferSize - max number of byte in buffer
*/
void OCLogBuffer(LogLevel level, PROGMEM const char * tag, const uint8_t * buffer, uint16_t bufferSize) {
- #ifdef TB_LOG
if (!buffer || !tag || (bufferSize == 0)) {
return;
}
if (bufferSize % 16) {
OCLogString(level, tag, lineBuffer);
}
- #endif
}
/**
* @param logStr - log string
*/
void OCLog(LogLevel level, PROGMEM const char * tag, PROGMEM const char * logStr) {
- #ifdef TB_LOG
if (!logStr || !tag) {
return;
}
logStr++;
}
Serial.println();
- #endif
}
/**
*/
void OCLogv(LogLevel level, PROGMEM const char * tag, const char * format, ...)
{
- #ifdef TB_LOG
char buffer[LINE_BUFFER_SIZE];
va_list ap;
va_start(ap, format);
}
Serial.println();
va_end(ap);
- #endif
}
/**
* Output a variable argument list log string with the specified priority level.
*/
void OCLogv(LogLevel level, PROGMEM const char * tag, const __FlashStringHelper *format, ...)
{
- #ifdef TB_LOG
char buffer[LINE_BUFFER_SIZE];
va_list ap;
va_start(ap, format);
}
Serial.println();
va_end(ap);
- #endif
}
OBJ_DIR = obj
endif
-#Arduino specific configurations
-INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
-INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/variants/mega
-INCD_ARD_SPI = -I$(ARDUINO_DIR)/libraries/SPI
-INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet
-INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/utility
-INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time
-SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
ifeq ($(PLATFORM),linux)
CCPLUS=g++
AR=ar
RANLIB=ranlib
CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
-else ifeq ($(PLATFORM),arduino)
+else ifeq ($(PLATFORM),arduinomega)
include local.properties
- CCPLUS=avr-g++
- CC=avr-g++
- AR=avr-ar
- RANLIB=avr-ranlib
- CFLAGS_PLATFORM = -std=c++0x -DATMEGA2560 -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DWITH_ARDUINO -MMD -DNDEBUG
- INC_DIR_PLATFORM = $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_ETH) $(INCD_ARD_ETH_UTIL) $(INCD_ARD_TIME)
+ include $(PLATFORM).properties
+ CC=$(ARDUINO_TOOLS_DIR)/avr-g++
+else ifeq ($(PLATFORM),arduinodue)
+ include local.properties
+ include $(PLATFORM).properties
+ CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
else
$(error Wrong value for PLATFORM !!)
endif
liboctbstack.a:
@echo "Building $@"
# Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
- @cd $(BUILD)/$(OBJ_DIR) && ar -x $(LCOAP_DIR)/$(BUILD)/libcoap.a
+ @cd $(BUILD)/$(OBJ_DIR) && $(AR) -x $(LCOAP_DIR)/$(BUILD)/libcoap.a
# Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
- ar -r $(BUILD)/$@ $(BUILD)/$(OBJ_DIR)/*.o
+ $(AR) -r $(BUILD)/$@ $(BUILD)/$(OBJ_DIR)/*.o
.PHONY: clean print_vars
#if defined(__ANDROID__) || defined(__linux__)
#include <time.h>
#elif defined ARDUINO
-//#include <Arduino.h>
-//#include <wiring_analog.c>
-#define ANALOG_IN (15)
+// MEGA has 16 input pins whereas Due has only 12 input pins
+#define ANALOG_IN (10)
#endif
-/**
+/**
* Seed the random number generator. Seeding depends on platform.
* Android and Linux uses current time. Arduino uses Analog reading on pin ANALOG_IN
* @retval 0 for Success, otherwise some error value
*/
int8_t OCSeedRandom();
-/**
+/**
* Generate a uniformly [0,2^32] distributed random number
* @retval On Success, it returns the random value.
*/
# Override with `make BUILD=release`
# default to debug build
BUILD := debug
+PLATFORM := arduinomega
# You must create the file "local.propertiessudo" on your local machine which contains any local paths, etc
# local_settings.mk should NOT be committed to repo
-include ../../local.properties
+ROOT_DIR = ../../..
+include $(ROOT_DIR)/local.properties
# Compilers
CC := avr-gcc
# override with `make BUILD=release`
# default to debug build
BUILD := debug
+PLATFORM := linux
# You must create the file "local.propertiessudo" on your local machine which contains any local paths, etc
# local_settings.mk should NOT be committed to repo
-include ../../local.properties
+ROOT_DIR = ../../..
+include $(ROOT_DIR)/local.properties
# GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
# Example:
# GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
VERIFY_NON_NULL(ardAddr);
OC_LOG(DEBUG, MOD_NAME, PCF("OCSendTo Begin"));
ret = sendto( sockfd, buf, bufLen, (uint8_t*)&(ardAddr->a), ardAddr->port);
- OC_LOG(DEBUG, MOD_NAME, PCF("OCSendTo End"));
+ OC_LOG_V(DEBUG, MOD_NAME, "OCSendTo RetVal %d", ret);
return ret;
}
-include ../local.properties
+PLATFORM := arduinomega
ROOT_DIR = ../../..
+include $(ROOT_DIR)/local.properties
OCSOCK_DIR = $(ROOT_DIR)/ocsocket
LOGGER_DIR = $(ROOT_DIR)/logger
BIN_DIR = $(OCSOCK_DIR)/bin/arduino/
-
-include ../local.properties
+PLATFORM := linux
ROOT_DIR = ../../..
+include $(ROOT_DIR)/local.properties
+
OCSOCK_DIR = $(ROOT_DIR)/ocsocket
LOGGER_DIR = $(ROOT_DIR)/logger
BIN_DIR = $(OCSOCK_DIR)/bin/linux/
+++ /dev/null
-//******************************************************************
-//
-// 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <ocstack.h>
-#include <iostream>
-#include <sstream>
-
-const char *getResult(OCStackResult result);
-std::string getIPAddrTBServer(OCClientResponse * clientResponse);
-std::string getPortTBServer(OCClientResponse * clientResponse);
-std::string getQueryStrForGetPut(unsigned const char * responsePayload);
-
-#define TAG PCF("occlient")
-#define CTX_VAL 0x99
-#ifndef MAX_LENGTH_IPv4_ADDR
-#define MAX_LENGTH_IPv4_ADDR 16
-#endif
-
-#define MAX_TEST_CASES 5
-
-static int UNICAST_DISCOVERY = 0;
-static int TEST_CASE = 0;
-static std::string putPayload = "{\"state\":\"off\",\"power\":\"0\"}";
-
-// The handle for the observe registration
-OCDoHandle gObserveDoHandle;
-// After this crosses a threshold client deregisters for further observations
-int gNumNotifies = 1;
-
-int gQuitFlag = 0;
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum) {
- if (signum == SIGINT) {
- gQuitFlag = 1;
- }
-}
-
-// Forward Declaration
-OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse);
-int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse);
-int InitObserveRequest(OCClientResponse * clientResponse);
-int InitPutRequest(OCClientResponse * clientResponse);
-int InitGetRequest(OCClientResponse * clientResponse);
-int InitDiscovery();
-
-void PrintUsage()
-{
- OC_LOG(INFO, TAG, "Usage : occlient <Unicast Discovery> <Test Case>");
- OC_LOG(INFO, TAG, "Test Case 1 : Discover Resources");
- OC_LOG(INFO, TAG, "Test Case 2 : Discover Resources and Initiate Get Request");
- OC_LOG(INFO, TAG, "Test Case 3 : Discover Resources and Initiate Get/Put Requests");
- OC_LOG(INFO, TAG, "Test Case 4 : Discover Resources and Initiate Observe Requests");
- OC_LOG(INFO, TAG, "Test Case 5 : Discover Resources and Initiate Get Request for a resource which is unavailable");
-}
-
-OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
- if(clientResponse) {}
- if(ctx == (void*)CTX_VAL) {
- OC_LOG_V(INFO, TAG, "Callback Context for PUT query recvd successfully");
- OC_LOG_V(INFO, TAG, "JSON = %s =============> Discovered", clientResponse->resJSONPayload);
- }
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) {
- OC_LOG_V(INFO, TAG, "StackResult: %s",
- getResult(clientResponse->result));
- if(ctx == (void*)CTX_VAL) {
- OC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
- if(clientResponse->sequenceNumber == 0) {
- OC_LOG_V(INFO, TAG, "Callback Context for GET query recvd successfully");
- OC_LOG_V(INFO, TAG, "Fnd' Rsrc': %s", clientResponse->resJSONPayload);
- }
- else {
- OC_LOG_V(INFO, TAG, "Callback Context for OBSERVE notification recvd successfully %d", gNumNotifies);
- OC_LOG_V(INFO, TAG, "Fnd' Rsrc': %s", clientResponse->resJSONPayload);
- gNumNotifies++;
- if (gNumNotifies == 3)
- {
- if (OCCancel (gObserveDoHandle) != OC_STACK_OK){
- OC_LOG(ERROR, TAG, "Observe cancel error");
- }
- }
- }
- }
- InitPutRequest(clientResponse);
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-// This is a function called back when a device is discovered
-OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
- OCClientResponse * clientResponse) {
- uint8_t remoteIpAddr[4];
- uint16_t remotePortNu;
-
- OC_LOG(INFO, TAG,
- "Entering discoveryReqCB (Application Layer CB)");
- OC_LOG_V(INFO, TAG, "StackResult: %s",
- getResult(clientResponse->result));
-
- if (ctx == (void*) CTX_VAL) {
- OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
- }
-
- OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
- remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
- OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
- printf(">>>>>>>>>>>>>From Printf %s\n", clientResponse->resJSONPayload);
-#if 0
- OC_LOG_V(INFO, TAG,
- "Device =============> Discovered %s @ %d.%d.%d.%d:%d",
- clientResponse->resJSONPayload, remoteIpAddr[0], remoteIpAddr[1],
- remoteIpAddr[2], remoteIpAddr[3], remotePortNu);
-#endif
-
- InitGetRequest(clientResponse);
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-int InitGetRequestToUnavailableResource(OCClientResponse * clientResponse)
-{
- OCStackResult ret;
- OCCallbackData cbData;
- OCDoHandle handle;
- std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) << "/SomeUnknownResource";
- cbData.cb = getReqCB;
- cbData.context = (void*)CTX_VAL;
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE, &cbData);
- if (ret != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "OCStack resource error");
- }
- return ret;
-}
-
-
-int InitObserveRequest(OCClientResponse * clientResponse)
-{
- OCStackResult ret;
- OCCallbackData cbData;
- OCDoHandle handle;
- std::ostringstream obsReg;
- obsReg << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) << getQueryStrForGetPut(clientResponse->resJSONPayload);
- cbData.cb = getReqCB;
- cbData.context = (void*)CTX_VAL;
- OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
- ret = OCDoResource(&handle, OC_REST_OBSERVE, obsReg.str().c_str(), 0, 0, OC_NON_CONFIRMABLE, &cbData);
- if (ret != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "OCStack resource error");
- }
- else
- {
- gObserveDoHandle = handle;
- }
- return ret;
-}
-
-
-int InitPutRequest(OCClientResponse * clientResponse)
-{
- OCStackResult ret;
- OCCallbackData cbData;
- OCDoHandle handle;
- //* Make a PUT query*/
- std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) <<
- "/a/sroom?if=oc.mi.b";
- // getQueryStrForGetPut(clientResponse->resJSONPayload);
- cbData.cb = putReqCB;
- cbData.context = (void*)CTX_VAL;
- OC_LOG_V(INFO, TAG, "PUT payload from client = %s ", putPayload.c_str());
- ret = OCDoResource(&handle, OC_REST_PUT, getQuery.str().c_str(), 0, putPayload.c_str(), OC_NON_CONFIRMABLE, &cbData);
- if (ret != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "OCStack resource error");
- }
- return ret;
-}
-
-
-int InitGetRequest(OCClientResponse * clientResponse)
-{
- OCStackResult ret;
- OCCallbackData cbData;
- OCDoHandle handle;
-
- uint8_t remoteIpAddr[4];
- uint16_t remotePortNu;
-
- OCDevAddrToIPv4Addr((OCDevAddr *) clientResponse->addr, remoteIpAddr,
- remoteIpAddr + 1, remoteIpAddr + 2, remoteIpAddr + 3);
- OCDevAddrToPort((OCDevAddr *) clientResponse->addr, &remotePortNu);
-
- //* Make a GET query*/
- std::ostringstream getQuery;
- getQuery << "coap://" << getIPAddrTBServer(clientResponse) << ":" << getPortTBServer(clientResponse) <<
- //"/a/sroom?if=oc.mi.def";
- //"/a/sroom?if=oc.mi.ll";
- "/a/sroom?if=oc.mi.b";
-
- std::cout << "Get Query: " << getQuery.str() << std::endl;
-
- cbData.cb = getReqCB;
- cbData.context = (void*)CTX_VAL;
- ret = OCDoResource(&handle, OC_REST_GET, getQuery.str().c_str(), 0, 0, OC_NON_CONFIRMABLE, &cbData);
- if (ret != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "OCStack resource error");
- }
- return ret;
-}
-
-#define TEST_APP_UNICAST_DISCOVERY_QUERY PCF("coap://0.0.0.0:5683/oc/core")
-int InitDiscovery()
-{
- OCStackResult ret;
- OCCallbackData cbData;
- OCDoHandle handle;
- /* Start a discovery query*/
- char szQueryUri[64] = { 0 };
-
- //strcpy(szQueryUri, "coap://224.0.1.187:5683/oc/core");//?rt=core.sroom");
- strcpy(szQueryUri, "coap://0.0.0.0:5683/oc/core");
-
- cbData.cb = discoveryReqCB;
- cbData.context = (void*)CTX_VAL;
- ret = OCDoResource(&handle, OC_REST_GET, szQueryUri, 0, 0, OC_NON_CONFIRMABLE, &cbData);
- if (ret != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "OCStack resource error");
- }
- return ret;
-}
-
-int main(int argc, char* argv[]) {
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = USE_RANDOM_PORT;
- uint8_t ifname[] = "eth0";
-
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr);
- paddr = addr;
- }
-
- /* Initialize OCStack*/
- if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack init error");
- return 0;
- }
-
- InitDiscovery();
-
- // Break from loop with Ctrl+C
- OC_LOG(INFO, TAG, "Entering occlient main loop...");
- signal(SIGINT, handleSigInt);
- while (!gQuitFlag) {
-
- if (OCProcess() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack process error");
- return 0;
- }
-
- sleep(3);
- }
- OC_LOG(INFO, TAG, "Exiting occlient main loop...");
-
- if (OCStop() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack stop error");
- }
-
- return 0;
-}
-
-std::string getIPAddrTBServer(OCClientResponse * clientResponse) {
- if(!clientResponse) return "";
- if(!clientResponse->addr) return "";
- uint8_t a, b, c, d = 0;
- if(0 != OCDevAddrToIPv4Addr(clientResponse->addr, &a, &b, &c, &d) ) return "";
-
- char ipaddr[16] = {'\0'};
- snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d", a,b,c,d); // ostringstream not working correctly here, hence snprintf
- //printf("IP address string of the TB server = %s\n", *out_ipaddr);
- return std::string (ipaddr);
-}
-
-
-std::string getPortTBServer(OCClientResponse * clientResponse){
- if(!clientResponse) return "";
- if(!clientResponse->addr) return "";
- uint16_t p = 0;
- if(0 != OCDevAddrToPort(clientResponse->addr, &p) ) return "";
- std::ostringstream ss;
- ss << p;
- return ss.str();
-}
-
-std::string getQueryStrForGetPut(unsigned const char * responsePayload){
- std::string jsonPayload(reinterpret_cast<char*>(const_cast<unsigned char*>(responsePayload)));
-
- return "/a/sroom";
-}
+++ /dev/null
-//******************************************************************
-//
-// 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 <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
-#include <pthread.h>
-#include <ocstack.h>
-#include <logger.h>
-
-const char *getResult(OCStackResult result);
-
-#define TAG PCF("ocservercontainer")
-
-int gQuitFlag = 0;
-int gLEDUnderObservation = 0;
-void createResources();
-typedef struct LEDRESOURCE{
- OCResourceHandle handle;
- bool state;
- int power;
-} LEDResource;
-
-static LEDResource LED;
-
-// TODO : hard coded for now, change after Sprint4
-const char rspGetLed[] = "{\"href\":\"/a/led\",\"rep\":{\"state\":\"on\",\"color\":\"yellow\"}}";
-// TODO : Needs to be changed to retrieve current status of led and return that in response
-const char rspPutLed[] = "{\"href\":\"/a/led\",\"rep\":{\"state\":\"off\",\"color\":\"off\"}}";
-const char rspFailureLed[] = "{\"href\":\"/a/led\",\"rep\":{\"error\":\"LED_OP_FAIL\"}}";
-
-
-// TODO : hard coded for now, change after Sprint4
-const char rspGetFan[] = "{\"href\":\"/a/fan\",\"rep\":{\"state\":\"on\",\"speed\":10}}";
-// TODO : Needs to be changed to retrieve current status of fan and return that in response
-const char rspPutFan[] = "{\"href\":\"/a/fan\",\"rep\":{\"state\":\"off\",\"speed\":0}}";
-const char rspFailureFan[] = "{\"href\":\"/a/fan\",\"rep\":{\"error\":\"FAN_OP_FAIL\"}}";
-
-static OCEntityHandlerResult
-HandleCallback(OCEntityHandlerRequest * ehRequest, const char* opStr, const char* errStr)
-{
- OCEntityHandlerResult ret = OC_EH_ERROR;
-
- if (strlen(opStr) < ehRequest->resJSONPayloadLen)
- {
- strncpy((char*)ehRequest->resJSONPayload, opStr, ehRequest->resJSONPayloadLen);
- }
- else if (strlen(errStr) < ehRequest->resJSONPayloadLen)
- {
- strncpy((char*)ehRequest->resJSONPayload, errStr, ehRequest->resJSONPayloadLen);
- ret = OC_EH_ERROR;
- }
- return ret;
-}
-
-static void
-PrintReceivedMsgInfo(OCEntityHandlerFlag flag, const OCEntityHandlerRequest * ehRequest )
-{
- const char* typeOfMessage;
-
- switch (flag) {
- case OC_INIT_FLAG:
- typeOfMessage = "OC_INIT_FLAG";
- break;
- case OC_REQUEST_FLAG:
- typeOfMessage = "OC_REQUEST_FLAG";
- break;
- case OC_OBSERVE_FLAG:
- typeOfMessage = "OC_OBSERVE_FLAG";
- break;
- default:
- typeOfMessage = "UNKNOWN";
- }
-
- OC_LOG_V(INFO, TAG, "Receiving message type: %s, method %s",
- typeOfMessage,
- (ehRequest->method == OC_REST_GET) ? "OC_REST_GET" : "OC_REST_PUT" );
-}
-
-OCEntityHandlerResult OCEntityHandlerLedCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * ehRequest ) {
- OCEntityHandlerResult ret = OC_EH_ERROR;
-
- OC_LOG_V(INFO, TAG, "Callback for Led");
- PrintReceivedMsgInfo(flag, ehRequest );
-
- if(ehRequest && flag == OC_REQUEST_FLAG)
- {
- if(OC_REST_GET == ehRequest->method)
- {
- ret = HandleCallback(ehRequest, rspGetLed, rspFailureLed);
- }
- if(OC_REST_PUT == ehRequest->method)
- {
- ret = HandleCallback(ehRequest, rspPutLed, rspFailureLed);
- }
- }
- else if (ehRequest && flag == OC_OBSERVE_FLAG)
- {
- gLEDUnderObservation = 1;
- }
-
- return ret;
-}
-
-OCEntityHandlerResult OCEntityHandlerFanCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * ehRequest ) {
- OCEntityHandlerResult ret = OC_EH_OK;
-
- OC_LOG_V(INFO, TAG, "Callback for Fan");
- PrintReceivedMsgInfo(flag, ehRequest );
-
- if(ehRequest && flag == OC_REQUEST_FLAG)
- {
- if(OC_REST_GET == ehRequest->method)
- {
- ret = HandleCallback(ehRequest, rspGetFan, rspFailureFan);
- }
- if(OC_REST_PUT == ehRequest->method)
- {
- ret = HandleCallback(ehRequest, rspPutFan, rspFailureFan);
- }
- }
- else if (ehRequest && flag == OC_OBSERVE_FLAG)
- {
- gLEDUnderObservation = 1;
- }
-
- return ret;
-}
-
-/* SIGINT handler: set gQuitFlag to 1 for graceful termination */
-void handleSigInt(int signum) {
- if (signum == SIGINT) {
- gQuitFlag = 1;
- }
-}
-
-void *ChangeLEDRepresentation (void *param)
-{
- (void)param;
- OCStackResult result = OC_STACK_ERROR;
-
- while (1 && !gQuitFlag)
- {
- sleep(10);
- LED.power += 5;
- if (gLEDUnderObservation)
- {
- OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", LED.power);
- result = OCNotifyObservers (LED.handle);
- if (OC_STACK_NO_OBSERVERS == result)
- {
- gLEDUnderObservation = 0;
- }
- }
- }
- return NULL;
-}
-
-int main() {
- printf("hello world from main\n");
- OC_LOG(DEBUG, TAG, "OCServer is starting...");
- uint8_t addr[20] = {0};
- uint8_t* paddr = NULL;
- uint16_t port = 5683;
- uint8_t ifname[] = "eth0";
- pthread_t threadId;
-
- /*Get Ip address on defined interface and initialize coap on it with random port number
- * this port number will be used as a source port in all coap communications*/
- if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr,
- sizeof(addr)) == ERR_SUCCESS)
- {
- OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
- paddr = addr;
- }
-
- if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack init error");
- return 0;
- }
-
- /*
- * Declare and create the example resource: LED
- */
- createResources();
-
- /*
- * Create a thread for changing the representation of the LED
- */
- pthread_create (&threadId, NULL, ChangeLEDRepresentation, (void *)NULL);
-
- // Break from loop with Ctrl-C
- OC_LOG(INFO, TAG, "Entering ocserver main loop...");
- signal(SIGINT, handleSigInt);
- while (!gQuitFlag) {
- if (OCProcess() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack process error");
- return 0;
- }
- sleep(3);
- }
-
- OC_LOG(INFO, TAG, "Exiting ocserver main loop...");
-
- if (OCStop() != OC_STACK_OK) {
- OC_LOG(ERROR, TAG, "OCStack process error");
- }
-
- return 0;
-}
-void createResources() {
- LED.state = false;
- OCResourceHandle room;
- OCStackResult res = OCCreateResource(&room,
- "core.sroom",
- "oc.mi.ll",
- "/a/sroom",
- NULL,
- OC_DISCOVERABLE);
- OC_LOG_V(INFO, TAG, "Created room resource with result: %s", getResult(res));
-
- OCResourceHandle light;
- res = OCCreateResource(&light,
- "core.light",
- "oc.mi.def",
- "/a/led",
- OCEntityHandlerLedCb,
- OC_DISCOVERABLE|OC_OBSERVABLE);
- OC_LOG_V(INFO, TAG, "Created light resource with result: %s", getResult(res));
-
- OCResourceHandle fan;
- res = OCCreateResource(&fan,
- "core.fan",
- "oc.mi.def",
- "/a/fan",
- OCEntityHandlerFanCb,
- OC_DISCOVERABLE|OC_OBSERVABLE);
- OC_LOG_V(INFO, TAG, "Created fan resource with result: %s", getResult(res));
-
- res = OCBindResource(room, light);
- OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res));
-
- res = OCBindResource(room, fan);
- OC_LOG_V(INFO, TAG, "OC Bind Contained Resource to resource: %s", getResult(res));
-}
-
-
To make ocserver in release mode:
- make
+ make (arduinomega)
+ make -f makefiledue (arduinodue)
To make & install ocserver in release mode, with <DEV_PORT> NOT specified:
- make install
+ make install (arduinomega)
+ make -f makefiledue install (arduinodue)
To make & install ocserver in release mode, with <DEV_PORT> specified:
-CC=avr-gcc
-CCPLUS=avr-g++
-AR=avr-ar
-RANLIB=avr-ranlib
-
APP_NAME := ocserver
BUILD := release
+PLATFORM := arduinomega
ARDUINO_PORT := /dev/ttyACM0
OBJ_DIR := ./bin
-include ../local.properties
-
-TB_DIR = ../../../../..
-LOGGER_DIR = $(TB_DIR)/logger
-TBSTACK_DIR = $(TB_DIR)/stack
-TBSOCKET_DIR = $(TB_DIR)/ocsocket
+ROOT_DIR = ../../../../..
+LOGGER_DIR = $(ROOT_DIR)/logger
+TBSTACK_DIR = $(ROOT_DIR)/stack
+TBSOCKET_DIR = $(ROOT_DIR)/ocsocket
-#Source directories
-SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
-SDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
-SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
-SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
-SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
+include $(ROOT_DIR)/local.properties
+include $(ROOT_DIR)/$(PLATFORM).properties
-VPATH := $(SDIR_ARD_CORE):$(SDIR_ARD_SPI):$(SDIR_ARD_ETH):$(SDIR_ARD_ETH_UTIL):$(OCSOCK_DIR)/src
+VPATH := $(SDIR_ARD_PLATFORM)
#include directories
-INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
-INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/variants/mega
-INCD_ARD_SPI = -I$(ARDUINO_DIR)/libraries/SPI
-INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet
-INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/utility
-INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time
-INCD_TBLOGGER = -I$(LOGGER_DIR)/include
-INCD_TBSTACK = -I$(TBSTACK_DIR)/include
-INCD_TBSOCKET = -I$(TBSOCKET_DIR)/include
-
-CPPFLAGSZ := -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD
-
-CPPFLAGS := -Wall -Os -c
-CPPFLAGS += $(CPPFLAGSZ) $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_ETH) $(INCD_ARD_ETH_UTIL) $(INCD_ARD_TIME) $(INCD_TBLOGGER) $(INCD_TBSTACK) $(INCD_TBSOCKET)
-CPPFLAGS += -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560 -DTB_LOG
+OCSOCK_DIR = $(ROOT_DIR)/ocsocket
+LOGGER_DIR = $(ROOT_DIR)/logger
+STACK_DIR = $(ROOT_DIR)/stack
+INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(LOGGER_DIR)/include -I$(STACK_DIR)/include
-SERVER_CPP_SRC := $(APP_NAME).cpp
-
-CORE_COBJ = WInterrupts.o wiring.o wiring_digital.o
-CORE_CPPOBJ = main.o Stream.o WMath.o WString.o HardwareSerial.o Print.o SPI.o IPAddress.o
-ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o
-ETH_UTIL_CPPOBJ = socket.o w5100.o
-OCDEPENDENT_CPPOBJ = wiring_analog.o
-
-SERVER_OBJ := $(SERVER_CPP_SRC:.cpp=.o)
+CFLAGS := -Os -Wall -c -DTB_LOG
all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).hex
-core.a: $(CORE_COBJ) $(CORE_CPPOBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ)
- @cd $(OBJ_DIR) && $(AR) -x $(TB_DIR)/../$(BUILD)/liboctbstack.a
+core.a: $(PLATFORM_OBJS)
+ @cd $(OBJ_DIR) && $(AR) -x $(ROOT_DIR)/../$(BUILD)/liboctbstack.a
$(AR) rcs $@ $^ $(OBJ_DIR)/*.o
$(RANLIB) $@
prep_dirs:
-mkdir $(OBJ_DIR)
+%.o: %.c
+ $(CC) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $@
+
%.o: %.cpp
- $(CCPLUS) $(CPPFLAGS) $< -o $@
+ $(CCPLUS) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $@
-$(APP_NAME).elf: $(APP_NAME).o core.a $(OCDEPENDENT_CPPOBJ)
- $(CC) -Os -Wl,--gc-sections,--relax $(CPPFLAGSZ) $^ -lm -o $@
+$(APP_NAME).elf: $(APP_NAME).o core.a
+ $(CC) -Os -Wl,--gc-sections,--relax $(CFLAGS_PLATFORM) $^ -lm -o $@
$(APP_NAME).hex: $(APP_NAME).elf
- avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $(APP_NAME).eep
- avr-objcopy -O ihex -R .eeprom $< $@
+ $(AVR_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $(APP_NAME).eep
+ $(AVR_OBJCOPY) -O ihex -R .eeprom $< $@
install: all
- avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(APP_NAME).hex:i
+ $(AVR_PROGRAMMER) -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(APP_NAME).hex:i
.PHONY: clean
clean:
- @rm -f *.o *.d *.elf *.eep *.a *.hex *-
+ @rm -f *.o *.d *.elf *.eep *.a *.hex *.bin *.map *-
@rm -rf $(OBJ_DIR)
--- /dev/null
+APP_NAME := ocserver
+BUILD := release
+PLATFORM := arduinodue
+ARDUINO_PORT := ttyACM0
+
+OBJ_DIR := ./bin
+
+ROOT_DIR = ../../../../..
+LOGGER_DIR = $(ROOT_DIR)/logger
+TBSTACK_DIR = $(ROOT_DIR)/stack
+TBSOCKET_DIR = $(ROOT_DIR)/ocsocket
+
+include $(ROOT_DIR)/local.properties
+include $(ROOT_DIR)/$(PLATFORM).properties
+
+VPATH := $(SDIR_ARD_PLATFORM)
+
+#include directories
+OCSOCK_DIR = $(ROOT_DIR)/ocsocket
+LOGGER_DIR = $(ROOT_DIR)/logger
+STACK_DIR = $(ROOT_DIR)/stack
+INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(LOGGER_DIR)/include -I$(STACK_DIR)/include
+
+CFLAGS := -Os -Wall -c -DTB_LOG
+
+all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).bin
+
+core.a: $(PLATFORM_OBJS)
+ @cd $(OBJ_DIR) && $(AR) -x $(ROOT_DIR)/../$(BUILD)/liboctbstack.a
+ $(AR) rcs $@ $(CORE_COBJ) $(CORE_CPPOBJ) $(OBJ_DIR)/*.o
+ $(RANLIB) $@
+
+prep_dirs:
+ -mkdir $(OBJ_DIR)
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $@
+
+%.o: %.cpp
+ $(CCPLUS) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $@
+
+
+$(APP_NAME).elf: $(APP_NAME).o core.a
+ $(CCPLUS) -Os -Wl,--gc-sections -mcpu=cortex-m3 -T/$(SDIR_ARD_CORE_3)/linker_scripts/gcc/flash.ld -Wl,-Map,$(APP_NAME).map -o $@ -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 $(APP_NAME).o $(SYSCALLS_SAM3_OBJ) $(SPI_OBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(VARIANT_OBJ) $(SDIR_ARD_CORE_3)/libsam_sam3x8e_gcc_rel.a core.a -Wl,--end-group
+
+$(APP_NAME).bin: $(APP_NAME).elf
+ $(ARDUINO_TOOLS_DIR)/arm-none-eabi-objcopy -O binary $< $@
+
+install: all
+ #Due needs Serial port speed to be set to 1200bps for uploading
+ 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 $(APP_NAME).bin -R
+
+.PHONY: clean
+
+clean:
+ @rm -f *.o *.d *.elf *.eep *.a *.hex *.bin *.map *-
+ @rm -rf $(OBJ_DIR)
case TEST_OBS_REQ_CON:
InitObserveRequest(OC_CONFIRMABLE);
break;
- default:
- PrintUsage();
- break;
}
}
//TODO: Query and URL validation is being done for virtual resource case
// using ValidateUrlQuery function. We should be able to merge it with this
// function.
- OC_LOG_V(INFO, TAG, PCF("Entering ValidateQuery"));
+ OC_LOG(INFO, TAG, PCF("Entering ValidateQuery"));
if (!query)
return OC_STACK_ERROR;
{
*rtParam = rtPtr;
}
- OC_LOG_V(INFO, TAG, "Query params: IF = %d, RT = %s\n", *ifParam, *rtParam);
+ OC_LOG_V(INFO, TAG, "Query params: IF = %d, RT = %s", *ifParam, *rtParam);
// TODO: Validate that the resource supports specified IF param
// TODO: Validate that the resource supports specified RT param
char *jsonStr;
uint16_t jsonLen;
- OC_LOG_V(INFO, TAG, PCF("Entering BuildRootResourceJSON\n"));
+ OC_LOG(INFO, TAG, PCF("Entering BuildRootResourceJSON"));
resObj = cJSON_CreateObject();
if (resource)
{
OCResource* temp = resource->rsrcResources[i];
if (temp)
{
- //TODO ("Proper Error handling");
ret = BuildDiscoveryResponse(temp, filterOn, filterValue, (char*)buffer, &remaining);
if (ret != OC_STACK_OK)
{
OCResource* temp = resource->rsrcResources[i];
if (temp)
{
- //TODO ("Proper Error handling");
-
ehRequest->resource = (OCResourceHandle) temp;
ehRet = temp->entityHandler(OC_REQUEST_FLAG, ehRequest);
OCStackIfTypes ifQueryParam;
char *rtQueryParam;
- OC_LOG(INFO, TAG, "DefaultCollectionEntityHandler\n");
+ OC_LOG(INFO, TAG, PCF("DefaultCollectionEntityHandler"));
if (flag != OC_REQUEST_FLAG)
return OC_STACK_ERROR;
// M1 release does not support attributes for collection resource, so the GET
// operation is same as the GET on LL interface.
- OC_LOG(INFO, TAG, "STACK_IF_DEFAULT\n");
+ OC_LOG(INFO, TAG, PCF("STACK_IF_DEFAULT"));
return BuildCollectionJSONResponse( (OCResource *)ehRequest->resource,
ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL);
case STACK_IF_LL:
- OC_LOG(INFO, TAG, "STACK_IF_LL\n");
+ OC_LOG(INFO, TAG, PCF("STACK_IF_LL"));
return BuildCollectionJSONResponse( (OCResource *)ehRequest->resource,
ehRequest, STACK_RES_DISCOVERY_NOFILTER, NULL);
case STACK_IF_BATCH:
- OC_LOG(INFO, TAG, "STACK_IF_BATCH\n");
+ OC_LOG(INFO, TAG, PCF("STACK_IF_BATCH"));
return BuildCollectionBatchJSONResponse(flag, (OCResource *)ehRequest->resource, ehRequest);
default:
{
char *filterParam;
- OC_LOG_V(INFO, TAG, PCF("Entering ValidateUrlQuery"));
+ OC_LOG(INFO, TAG, PCF("Entering ValidateUrlQuery"));
if (!url)
return OC_STACK_INVALID_URI;
// Other URIs not yet supported
return OC_STACK_INVALID_URI;
}
- OC_LOG_V(INFO, TAG, PCF("Exiting ValidateUrlQuery"));
+ OC_LOG(INFO, TAG, PCF("Exiting ValidateUrlQuery"));
return OC_STACK_OK;
}
OCStackResult ret = OC_STACK_OK;
uint16_t jsonLen;
- OC_LOG_V(INFO, TAG, PCF("Entering BuildDiscoveryResponse"));
+ OC_LOG(INFO, TAG, PCF("Entering BuildDiscoveryResponse"));
resObj = cJSON_CreateObject();
if (resourcePtr)
free (jsonStr);
- OC_LOG_V(INFO, TAG, PCF("Exiting BuildDiscoveryResponse"));
+ OC_LOG(INFO, TAG, PCF("Exiting BuildDiscoveryResponse"));
return ret;
}
OCResource **resource)
{
- OC_LOG(INFO, TAG, "Entering DetermineResourceHandling");
+ OC_LOG(INFO, TAG, PCF("Entering DetermineResourceHandling"));
// Check if virtual resource
if (IsVirtualResource((const char*)request->resourceUrl))
uint16_t remaining;
unsigned char *buffer;
- OC_LOG(INFO, TAG, "Entering HandleVirtualResource");
+ OC_LOG(INFO, TAG, PCF("Entering HandleVirtualResource"));
result = ValidateUrlQuery (request->resourceUrl,
request->entityHandlerRequest->query, &filterOn,
OCStackResult result = OC_STACK_OK;
OCEntityHandlerRequest *ehRequest = request->entityHandlerRequest;
- OC_LOG(INFO, TAG, "Entering HandleResourceWithEntityHandler");
+ OC_LOG(INFO, TAG, PCF("Entering HandleResourceWithEntityHandler"));
ehRequest->resource = (OCResourceHandle)resource;
// status code from entity handler is ignored unless observe call
case OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER:
{
- OC_LOG_V(INFO, TAG, PCF("OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER"));
+ OC_LOG(INFO, TAG, PCF("OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER"));
return OC_STACK_ERROR;
}
// TODO: Remove comments below before release - only for code review
// OPEN: We had decided to revisit the OCDoHandle logic for this sprint. If it
// changes and URI is passed this special case will not be needed.
- OC_LOG_V(INFO, TAG, PCF("OC_RESOURCE_NOT_SPECIFIED"));
+ OC_LOG(INFO, TAG, PCF("OC_RESOURCE_NOT_SPECIFIED"));
if (request->observe != NULL)
{
ret = ProcessObserveRequest (resource, request);
default:
{
- OC_LOG_V(INFO, TAG, PCF("Invalid Resource Determination"));
+ OC_LOG(INFO, TAG, PCF("Invalid Resource Determination"));
return OC_STACK_ERROR;
}
}
-include ../local.properties
+BUILD := release
+PLATFORM := arduinomega
ROOT_DIR = ../../..
+include $(ROOT_DIR)/local.properties
LIBCOAP_DIR = $(ROOT_DIR)/libcoap-4.1.1
OCSOCK_DIR = $(ROOT_DIR)/ocsocket
OCCOAP_DIR = $(ROOT_DIR)/occoap
LOGGER_DIR = $(ROOT_DIR)/logger
RANDOM_DIR = $(ROOT_DIR)/ocrandom
-JSON_DIR = $(ROOT_DIR)/../../../oic-utilities/tb/cJSON
+JSON_DIR = $(ROOT_DIR)/../../oic-utilities/tb/cJSON
OCSTACK_DIR = $(ROOT_DIR)/stack
BIN_DIR = $(OCSTACK_DIR)/bin/arduino/
OBJ_DIR = $(OCSTACK_DIR)/obj/arduino/
-I$(LIBCOAP_DIR)/ -I$(OCCOAP_DIR)/include -I$(JSON_DIR)
#Compiler/Linker flags
-COPTIONS_ARDUINO = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD
+COPTIONS_ARDUINO = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD -DNDEBUG
CFLAGS += -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560 -DTB_LOG -DWITH_ARDUINO
#Compilers
CORE_CPPOBJ = main.o Stream.o WMath.o WString.o HardwareSerial.o Print.o SPI.o IPAddress.o wiring_analog.o
ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o
ETH_UTIL_CPPOBJ = socket.o w5100.o
-OCSTACK_CPPOBJ = ocrandom.o ocstack.o occoap.o ocserverrequest.o occlientcb.o
+OCSTACK_CPPOBJ = ocrandom.o ocresource.o occollection.o ocobserve.o ocstack.o occoaphelper.o occoap.o occlientcb.o
OCDEPENDENT_CPPOBJ = wiring_analog.o
CJSON_COBJ = cJSON.o
%.o: %.cpp
$(CCPLUS) $(CFLAGS) $(COPTIONS_ARDUINO) $(INC_DIRS) $< -o $@
-core.a: $(CORE_COBJ) $(CORE_CPPOBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(LIBCOAP_DIR)/libcoap.a
+core.a: $(CORE_COBJ) $(CORE_CPPOBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(LIBCOAP_DIR)/$(BUILD)/libcoap.a
$(AR) rcs $@ $^
$(RANLIB) $@
-$(TESTAPP).elf: $(TESTAPP).o core.a $(OCSTACK_CPPOBJ) $(OCDEPENDENT_CPPOBJ) $(LIBCOAP_DIR)/libcoap.a $(CJSON_COBJ)
+$(TESTAPP).elf: $(TESTAPP).o core.a $(OCSTACK_CPPOBJ) $(OCDEPENDENT_CPPOBJ) $(LIBCOAP_DIR)/$(BUILD)/libcoap.a $(CJSON_COBJ)
$(CC) -Os -Wl,--gc-sections,--relax $(COPTIONS_ARDUINO) $^ -lm -o $@
$(TESTAPP).hex: $(TESTAPP).elf
/*
* Declare and create the example resource: LED
*/
- if(createLEDResource() != OC_STACK_OK)
+ if(createLEDResource() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "OCStack cannot create resource...");
}
PLATFORM := linux
CC := g++
+ifeq ($(ROOT_DIR), )
+ROOT_DIR = $(PWD)/../..
+endif
+
# You must create the file "local.properties" on your local machine which contains any local paths, etc
# local.properties should NOT be committed to repo
-include ./local.properties
+include $(ROOT_DIR)/local.properties
# GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
# Example:
# GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
OUT_DIR := $(PWD)/$(BUILD)
OBJ_DIR := $(OUT_DIR)/obj
-ifeq ($(ROOT_DIR), )
-ROOT_DIR = $(PWD)/../..
-endif
OUT_DIR := $(PWD)