return 0;
/* TODO */
- return 1;
+ return 0;
}
#endif /* WITH_ARDUINO */
#ifndef _COAP_H_
#define _COAP_H_
+#include "net.h"
+
#ifdef __cplusplus
extern "C" {
#endif
#include "coap_list.h"
#include "pdu.h"
#include "option.h"
-#include "net.h"
#include "encode.h"
#include "str.h"
#include "uri.h"
OCBuildIPv4Address(coap_wellknown_addr[0], coap_wellknown_addr[1],
coap_wellknown_addr[2], coap_wellknown_addr[3], coap_def_port, &mcast_addr);
if (coap_join_wellknown_group(ctx, (coap_address_t*)&mcast_addr) != 0) {
- OC_LOG(ERROR, MOD_NAME, "Unable to join to wellknown multicast group" );
+ OC_LOG(ERROR, MOD_NAME, PCF("Unable to join to wellknown multicast group") );
}
goto finish;
}
if (ctx->sockfd_wellknown != -1) {
if ( FD_ISSET( ctx->sockfd_wellknown, &readfds ) ) { /* read from multicast socket */
- OC_LOG(DEBUG, MOD_NAME, "Device Discovery request at well-known address !!" );
+ OC_LOG(DEBUG, MOD_NAME, PCF("Device Discovery request at well-known address !!"));
coap_read( ctx, ctx->sockfd_wellknown ); /* read received data */
TODO("Do we need to call coap_dispatch separately for unicast and multicast sockets")
coap_dispatch( ctx ); /* and dispatch PDUs from receivequeue */
-# override with `make BUILD=release`
+# override with `make BUILD=debug`
+# override with `make PLATFORM=arduino`
# default to release build
+# default to build for linux
BUILD := release
#other options are android, arduino
PLATFORM=linux
OCSOCK_DIR = $(ROOT_DIR)/ocsocket
LOGGER_DIR = $(ROOT_DIR)/logger
RANDOM_DIR = $(ROOT_DIR)/ocrandom
+STACK_DIR = $(ROOT_DIR)/stack
INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(LOGGER_DIR)/include -I$(RANDOM_DIR)/include
#Arduino specific configurations
CC=gcc
AR=ar
RANLIB=ranlib
- CFLAGS_PLATFORM = -DWITH_POSIX
+ CFLAGS_PLATFORM = -std=gnu99 -DWITH_POSIX
else ifeq ($(PLATFORM),arduino)
include local.properties
CCPLUS=avr-g++
endif
CC_FLAGS.debug := -O0 -g3 -Wall -ffunction-sections -fdata-sections -fno-exceptions -pedantic \
--std=gnu99 -DTB_LOG
-CC_FLAGS.release := -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions -std=gnu99
+-DTB_LOG
+CC_FLAGS.release := -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions
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
#include <stdio.h>
#include <stdarg.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#ifdef __ANDROID__
#include <android/log.h>
#elif defined ARDUINO
#include <avr/pgmspace.h>
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// Use the PCF macro to wrap strings stored in FLASH on the Arduino
// Example: OC_LOG(INFO, TAG, PCF("Entering function"));
#ifdef ARDUINO
* @param bufferSize - max number of byte in buffer
*/
void OCLogBuffer(LogLevel level, const prog_char * tag, const uint8_t * buffer, uint16_t bufferSize);
+
+ /**
+ * Output a variable argument list log string with the specified priority level.
+ *
+ * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
+ * @param tag - Module name
+ * @param format - variadic log string
+ */
+ void OCLogv(LogLevel level, const char * tag, const char * format, ...);
#endif
#ifdef TB_LOG
// Use full namespace for logInit to avoid function name collision
#define OC_LOG_INIT() OCLogInit()
// Don't define variable argument log function for Arduino
- #define OC_LOG_V(level, tag, ...)
+ #define OC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
#else
// Don't define LOG_INIT for Linux and Android
#define OC_LOG_INIT()
#include "logger.h"
#include "string.h"
-
-
static const uint16_t LINE_BUFFER_SIZE = (16 * 2) + 16 + 1; // Show 16 bytes, 2 chars/byte, spaces between bytes, null termination
// Convert LogLevel to platform-specific severity level. Store in PROGMEM on Arduino
//static const char * LEVEL[] = {"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"};
static const char * LEVEL[] __attribute__ ((unused)) = {"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"};
#elif defined ARDUINO
-
- #define MAX_ARDUINO_LEVEL_STR_SIZE (8)
+ #include <stdarg.h>
prog_char level0[] PROGMEM = "DEBUG";
prog_char level1[] PROGMEM = "INFO";
return;
}
- char buffer[MAX_ARDUINO_LEVEL_STR_SIZE] = {0};
+ char buffer[LINE_BUFFER_SIZE] = {0};
strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
Serial.print(buffer);
return;
}
- char buffer[MAX_ARDUINO_LEVEL_STR_SIZE] = {0};
+ char buffer[LINE_BUFFER_SIZE] = {0};
strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
Serial.print(buffer);
Serial.println();
#endif
}
+
+ /**
+ * Output a variable argument list log string with the specified priority level.
+ * Only defined for Arduino as depicted below.
+ *
+ * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
+ * @param tag - Module name
+ * @param format - variadic log string
+ */
+ void OCLogv(LogLevel level, const prog_char * tag, const char *format, ...)
+ {
+ #ifdef TB_LOG
+ char buffer[LINE_BUFFER_SIZE];
+ va_list ap;
+ va_start(ap, format);
+ strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
+ Serial.print(buffer);
+
+ char c;
+ Serial.print(F(": "));
+
+ while ((c = pgm_read_byte(tag))) {
+ Serial.write(c);
+ tag++;
+ }
+ Serial.print(F(": "));
+
+ vsnprintf(buffer, sizeof(buffer), format, ap);
+ for(char *p = &buffer[0]; *p; p++) // emulate cooked mode for newlines
+ {
+ if(*p == '\n')
+ {
+ Serial.write('\r');
+ }
+ Serial.write(*p);
+ }
+ Serial.println();
+ va_end(ap);
+ #endif
+ }
+ /**
+ * Output a variable argument list log string with the specified priority level.
+ * Only defined for Arduino as depicted below.
+ *
+ * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
+ * @param tag - Module name
+ * @param format - variadic log string
+ */
+ void OCLogv(LogLevel level, const prog_char * tag, const __FlashStringHelper *format, ...)
+ {
+ #ifdef TB_LOG
+ char buffer[LINE_BUFFER_SIZE];
+ va_list ap;
+ va_start(ap, format);
+ strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
+ Serial.print(buffer);
+
+ char c;
+ Serial.print(F(": "));
+
+ while ((c = pgm_read_byte(tag))) {
+ Serial.write(c);
+ tag++;
+ }
+ Serial.print(F(": "));
+
+ #ifdef __AVR__
+ vsnprintf_P(buffer, sizeof(buffer), (const char *)format, ap); // progmem for AVR
+ #else
+ vsnprintf(buffer, sizeof(buffer), (const char *)format, ap); // for the rest of the world
+ #endif
+ for(char *p = &buffer[0]; *p; p++) // emulate cooked mode for newlines
+ {
+ if(*p == '\n')
+ {
+ Serial.write('\r');
+ }
+ Serial.write(*p);
+ }
+ Serial.println();
+ va_end(ap);
+ #endif
+ }
+
+
#endif
-# override with `make BUILD=release`
+# override with `make BUILD=debug`
+# override with `make PLATFORM=arduino`
# default to release build
+# default to build for linux
BUILD := release
PLATFORM := linux
-CC := gcc
ifeq ($(ROOT_DIR), )
ROOT_DIR = $(PWD)
endif
ifeq ($(OBJ_DIR), )
-OBJ_DIR = $(ROOT_DIR)/obj
+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++
+ CC=gcc
+ AR=ar
+ RANLIB=ranlib
+ CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
+else ifeq ($(PLATFORM),arduino)
+ 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)
+else
+ $(error Wrong value for PLATFORM !!)
endif
OCLOGGER_DIR = $(ROOT_DIR)/logger
INC_DIRS += -I$(OCTBSTACK_INC)/internal
INC_DIRS += -I$(CJSON_INC)
-CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c99 -fpic \
- -DTB_LOG
-CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -std=c99 -fpic
+CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
+CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -fpic
-CFLAGS += $(CC_FLAGS.$(BUILD)) -DWITH_POSIX $(INC_DIRS)
+CFLAGS += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
LDLIBS += -lcoap
CJSON_SOURCES := $(CJSON_SRC)/cJSON.c
$(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)"
objdirs: $(ROOT_DIR)
- mkdir -p $(OBJ_DIR)
- mkdir -p $(OBJ_DIR)/$(BUILD)
mkdir -p $(BUILD)
+ mkdir -p $(BUILD)/$(OBJ_DIR)
obj_build:
@echo "Building $@"
# Output all *.o files to $(OBJ_DIR)/$(BUILD)
- $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/$(BUILD)/%, $(notdir $(source))));)
+ $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(BUILD)/$(OBJ_DIR)/%, $(notdir $(source))));)
liboctbstack.a:
@echo "Building $@"
# Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
- @cd $(OBJ_DIR)/$(BUILD) && 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)/$@ $(OBJ_DIR)/$(BUILD)/*.o
+ ar -r $(BUILD)/$@ $(BUILD)/$(OBJ_DIR)/*.o
.PHONY: clean print_vars
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
+#ifndef WITH_ARDUINO
#include <unistd.h>
+#endif
#include <limits.h>
#include <ctype.h>
#include "coap.h"
#ifndef OCCOAPTOKEN_H_
#define OCCOAPTOKEN_H_
+#include <stddef.h>
+
#define MAX_TOKEN_LENGTH (8)
typedef struct {
#include "occoap.h"
#include "occlientcb.h"
#include "ocobserve.h"
+#include "logger.h"
#include <coap.h>
#ifndef WITH_ARDUINO
//-----------------------------------------------------------------------------
#define TAG PCF("OCCoAP")
#define VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
- {OC_LOG(FATAL, TAG, #op " failed !!"); goto exit;} }
-#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
+ {OC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
+#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG_V(FATAL, TAG, "%s is NULL", #arg); goto exit;} }
#define BUF_SIZE (64)
#define BUF_SIZE_ENCODE_OPTION (3)
// in the future, the response might be queued for SLOW resources
if (pdu->hdr->type != COAP_MESSAGE_CON || tid == COAP_INVALID_TID)
{
- OC_LOG(INFO, TAG, "Deleting PDU");
+ OC_LOG(INFO, TAG, PCF("Deleting PDU"));
coap_delete_pdu(pdu);
}
OC_LOG_V(INFO, TAG, "TID %d", tid);
if (tid != COAP_INVALID_TID)
{
- OC_LOG(INFO, TAG, "Deleting PDU");
+ OC_LOG(INFO, TAG, PCF("Deleting PDU"));
coap_delete_pdu(pdu);
}
else
{
- OC_LOG(INFO, TAG, "Keeping PDU, we should handle the retry of this pdu");
+ OC_LOG(INFO, TAG, PCF("Keeping PDU, we should handle the retry of this pdu"));
}
goto exit;
}
}
else
{
- OC_LOG(DEBUG, TAG, "Do not accept other than NON in HandleCoAPResponses");
+ OC_LOG(DEBUG, TAG, PCF("Do not accept other than NON in HandleCoAPResponses"));
}
exit:
int ret = OC_COAP_ERR;
TODO ("Below should go away and be replaced by OC_LOG");
- coap_log_t log_level = LOG_DEBUG + 1;
+ coap_log_t log_level = (coap_log_t)(LOG_DEBUG + 1);
OCDevAddr devAddr;
OCDevAddr mcastAddr;
uint8_t ipAddr[4] = { 0 };
coap_join_wellknown_group(gCoAPCtx,
(coap_address_t* )&mcastAddr), 0);
}
-
coap_register_request_handler(gCoAPCtx, HandleCoAPRequests);
coap_register_response_handler(gCoAPCtx, HandleCoAPResponses);
exit:
if (ret != OC_COAP_OK)
{
- OCStopCoAP(gCoAPCtx);
+ OCStopCoAP();
}
return ret;
}
// Decide message type
if (qos == OC_CONFIRMABLE) {
coapMsgType = COAP_MESSAGE_CON;
- OC_LOG(FATAL, TAG, "qos == OC_CONFIRMABLE is not supported in OCDoCoAPResource");
+ OC_LOG(FATAL, TAG, PCF("qos == OC_CONFIRMABLE is not supported in OCDoCoAPResource"));
}
// Decide method type
switch (method) {
break;
default:
coapMethod = 0;
- OC_LOG(FATAL, TAG, "OCDoCoAPResource only supports GET, PUT, & OBSERVE methods");
+ OC_LOG(FATAL, TAG, PCF("OCDoCoAPResource only supports GET, PUT, & OBSERVE methods"));
break;
}
TODO ("Once CON implementation is available, pdu should be saved until ACK is received");
//if (pdu->hdr->type != COAP_MESSAGE_CON || tid == COAP_INVALID_TID)
{
- OC_LOG(INFO, TAG, "Deleting PDU");
+ OC_LOG(INFO, TAG, PCF("Deleting PDU"));
coap_delete_pdu(pdu);
pdu = NULL;
}
OC_LOG_V(INFO, TAG, "TID %d", tid);
if (pdu->hdr->type != COAP_MESSAGE_CON || tid == COAP_INVALID_TID)
{
- OC_LOG(INFO, TAG, "Deleting PDU");
+ OC_LOG(INFO, TAG, PCF("Deleting PDU"));
coap_delete_pdu(pdu);
pdu = NULL;
}
read = coap_read(gCoAPCtx, gCoAPCtx->sockfd);
if(read > 0)
{
- OC_LOG(INFO, TAG, "This is a Unicast<============");
+ OC_LOG(INFO, TAG, PCF("This is a Unicast<============"));
}
if (-1 != gCoAPCtx->sockfd_wellknown) {
read = coap_read(gCoAPCtx, gCoAPCtx->sockfd_wellknown);
if(read > 0)
{
- OC_LOG(INFO, TAG, "This is a Multicast<===========");
+ OC_LOG(INFO, TAG, PCF("This is a Multicast<==========="));
}
}
coap_dispatch(gCoAPCtx);
// Macros
//-----------------------------------------------------------------------------
#define TAG PCF("OCCoAPHelper")
-#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG(FATAL, TAG, #arg " is NULL"); goto exit;} }
+#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG_V(FATAL, TAG, "%s is NULL", #arg); goto exit;} }
//=============================================================================
// Helper Functions
pdu->hdr->token_length = tokenLength;
if (!coap_add_token(pdu, tokenLength, token)) {
- OC_LOG(FATAL, TAG, "coap_add_token failed");
+ OC_LOG(FATAL, TAG, PCF("coap_add_token failed"));
}
for (opt = options; opt; opt = opt->next) {
coap_list_t *node;
VERIFY_NON_NULL(data);
- option = coap_malloc(sizeof(coap_option) + length);
+ option = (coap_option *)coap_malloc(sizeof(coap_option) + length);
VERIFY_NON_NULL(option);
COAP_OPTION_KEY(*option) = key;
}
exit:
- OC_LOG(ERROR,TAG,"new_option_node: malloc: was not created");
+ OC_LOG(ERROR,TAG, PCF("new_option_node: malloc: was not created"));
coap_free(option);
return NULL;
}
* Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses
*
*/
+#pragma pack(push, 1)
typedef struct OCDevAddr {
uint32_t size; /**< length of the address stored in addr field. */
uint8_t addr[DEV_ADDR_SIZE_MAX]; /**< device address. */
}OCDevAddr;
+#pragma pack(pop)
//-- OCInitNetworkStack -----------------------------------------------------------
/** @ingroup ocsocket
#define MOD_NAME PCF("ocsocket")
/// Macro to verify the validity of input argument
-#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG(FATAL, MOD_NAME, PCF(#arg " is NULL")); \
+#define VERIFY_NON_NULL(arg) { if (!arg) {OC_LOG_V(FATAL, MOD_NAME, "%s is NULL", #arg); \
return ERR_INVALID_INPUT;} }
/// Length of the IP address decimal notation string
VERIFY_NON_NULL(buf);
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"));
ArduinoAddr* ardAddr = (ArduinoAddr*)ipAddr;
if ( !ardAddr || !a || !b || !c || !d ) {
- OC_LOG(FATAL, MOD_NAME, "Invalid argument");
+ OC_LOG(FATAL, MOD_NAME, PCF("Invalid argument"));
return ERR_INVALID_INPUT;
}
ArduinoAddr* ardAddr = (ArduinoAddr*)ipAddr;
if ( !ardAddr || !port ) {
- OC_LOG(FATAL, MOD_NAME, "Invalid argument");
+ OC_LOG(FATAL, MOD_NAME, PCF("Invalid argument"));
return ERR_INVALID_INPUT;
}
IDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
IDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
-INC_DIRS = -I$(IDIR_ARD_CORE) -I$(IDIR_ARD_VARIANT) -I$(IDIR_ARD_SPI) -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL) -I$(OCSOCK_DIR)/include -I$(LOGGER_DIR)/include
+INC_DIRS = -I$(IDIR_ARD_CORE) -I$(IDIR_ARD_VARIANT) -I$(IDIR_ARD_SPI) -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL) -I$(OCSOCK_DIR)/include -I$(LOGGER_DIR)/include -I$(ROOT_DIR)/stack/include
#Compiler/Linker flags
COPTIONS_ARDUINO = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD
#include "ocstack.h"
#include "occoaptoken.h"
#include "occlientcb.h"
+#include <logger.h>
+#include <ocrandom.h>
#ifdef __cplusplus
extern "C" {
#ifndef OCSTACK_H_
#define OCSTACK_H_
-#include <ocsocket.h>
-#include <logger.h>
-#include <ocrandom.h>
+#include "ocsocket.h"
#ifdef __cplusplus
extern "C" {
OBJ_DIR := $(OUT_DIR)/obj
ifeq ($(ROOT_DIR), )
-ROOT_DIR = $(PWD)/../../..
+ROOT_DIR = $(PWD)/../../../..
endif
OUT_DIR = $(PWD)
-std=c++0x -pedantic $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD) -DTB_LOG
CC_FLAGS.release := -Os -Wall -fdata-sections -Wl,--gc-sections -Wl,-s -fno-exceptions \
-std=c++0x $(INC_DIRS) -L$(ROOT_DIR)/$(BUILD) -DTB_LOG
-
+
LDLIBS += -loctbstack -lpthread
CPPFLAGS += $(CC_FLAGS.$(BUILD)) $(LDLIBS)
PROGRAMS += ocserver
PROGRAMS += occlient
-all: prep_dirs $(OBJECTS) $(PROGRAMS)
+all: prep_dirs $(OBJECTS) $(PROGRAMS)
prep_dirs:
-mkdir -p $(OUT_DIR)
#include <stdlib.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
-#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
-#include <ocstack.h>
+#include "ocstack.h"
+#include "logger.h"
const char *getResult(OCStackResult result);
std::string getIPAddrTBServer(OCClientResponse * clientResponse);
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
-#include <ocstack.h>
-#include <logger.h>
+#include "ocstack.h"
+#include "logger.h"
const char *getResult(OCStackResult result);
OCEntityHandlerRequest *ehReq = request->entityHandlerRequest;
OCObserveReq *obs = request->observe;
- OC_LOG(INFO, TAG, "Entering ProcessObserveRequest");
+ OC_LOG(INFO, TAG, PCF("Entering ProcessObserveRequest"));
if (strcmp ((char *)obs->option, OC_RESOURCE_OBSERVE_REGISTER) == 0) {
if (NULL == resource)
{
return result;
} else {
// Invalid option
- OC_LOG(ERROR, TAG, "Invalid CoAP observe option");
+ OC_LOG(ERROR, TAG, PCF("Invalid CoAP observe option"));
return OC_STACK_INVALID_OBSERVE_PARAM;
}
}
}
if (numObs == 0)
{
- OC_LOG(INFO, TAG, "Resource has no observers");
+ OC_LOG(INFO, TAG, PCF("Resource has no observers"));
return OC_STACK_NO_OBSERVERS;
}
return OC_STACK_OK;
{
for (int i = 0; i < OC_MAX_RESOURCES; i++)
{
- if (strcmp(resourceUri, GetVirtualResourceUri(i)) == 0)
+ if (strcmp(resourceUri, GetVirtualResourceUri((OCVirtualResources)i)) == 0)
{
return 1;
}
uint8_t encodeRes = 0;
OCStackResult ret = OC_STACK_OK;
- OC_LOG_V(INFO, TAG, PCF("Entering ProcessResourceDiscoverReq"));
+ OC_LOG(INFO, TAG, PCF("Entering ProcessResourceDiscoverReq"));
ocObj = cJSON_CreateObject();
cJSON_AddItemToObject (ocObj, OC_RSRVD_OC, pLoadObj = cJSON_CreateObject());
cJSON_AddItemToObject (pLoadObj, OC_RSRVD_PAYLOAD, resArray = cJSON_CreateArray());
cJSON_Delete (ocObj);
free (jsonStr);
- OC_LOG_V(INFO, TAG, PCF("Exiting ProcessResourceDiscoverReq"));
+ OC_LOG(INFO, TAG, PCF("Exiting ProcessResourceDiscoverReq"));
return ret;
}
{
char *filterParam;
- OC_LOG_V(INFO, TAG, PCF("Exiting 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;
}
//This function will be called back by occoap layer when a request is received
OCStackResult HandleStackRequests(OCRequest * request) {
- OC_LOG(INFO, TAG, "Entering OCStackHandleReceiveRequest (OCStack Layer)");
+ OC_LOG(INFO, TAG, PCF("Entering OCStackHandleReceiveRequest (OCStack Layer)"));
char *filterValue;
uint8_t filterOn;
}
else
{
- OC_LOG(INFO, TAG, "Resource Not found");
+ OC_LOG(INFO, TAG, PCF("Resource Not found"));
result = OC_STACK_NO_RESOURCE;
}
if (request->observe != NULL)
//This function will be called back by occoap layer when a response is received
void HandleStackResponses(OCResponse * response) {
OCStackApplicationResult result = OC_STACK_DELETE_TRANSACTION;
- OC_LOG(INFO, TAG, "Entering HandleStackResponses (OCStack Layer)");
+ OC_LOG(INFO, TAG, PCF("Entering HandleStackResponses (OCStack Layer)"));
if (response->cbNode) {
OC_LOG(INFO, TAG, PCF("Calling into application address space"));
//-----------------------------------------------------------------------------
// Default resource entity handler function
//-----------------------------------------------------------------------------
-void defaultResourceEHandler(OCEntityHandlerFlag flag,
+OCStackResult defaultResourceEHandler(OCEntityHandlerFlag flag,
OCEntityHandlerRequest * request) {
TODO ("Implement me!!!!");
// TODO: remove silence unused param warnings
(void) flag;
(void) request;
+ return OC_STACK_OK;
}
//-----------------------------------------------------------------------------
}
// Make call to OCCoAP layer
- result = OCDoCoAPResource(method, qos, token, requiredUri, request);
+ result = (OCStackResult)OCDoCoAPResource(method, qos, token, requiredUri, request);
exit:
OC_LOG(INFO, TAG, PCF("Entering OCCancel"));
- ClientCB *clientCB = GetClientCB(NULL, handle);
+ ClientCB *clientCB = GetClientCB(NULL, &handle);
if(clientCB) {
switch (clientCB->method)
// If found, add it and return success
for (i = 0; i < MAX_CONTAINED_RESOURCES; i++) {
if (!resource->rsrcResources[i]) {
- resource->rsrcResources[i] = (OCResourceHandle) resourceHandle;
+ resource->rsrcResources[i] = (OCResource *) resourceHandle;
OC_LOG(INFO, TAG, PCF("resource bound"));
return OC_STACK_OK;
}
// If found, add it and return success
for (i = 0; i < MAX_CONTAINED_RESOURCES; i++) {
if (resourceHandle == resource->rsrcResources[i]) {
- resource->rsrcResources[i] = (OCResourceHandle) 0;
+ resource->rsrcResources[i] = (OCResource *) NULL;
OC_LOG(INFO, TAG, PCF("resource unbound"));
return OC_STACK_OK;
}
VERIFY_NON_NULL(entityHandler, ERROR, OC_STACK_INVALID_PARAM);
// Use the handle to find the resource in the resource linked list
- resource = findResource(handle);
+ resource = findResource((OCResource *)handle);
if (!resource) {
OC_LOG(ERROR, TAG, PCF("Resource not found"));
return OC_STACK_ERROR;
OC_LOG(INFO, TAG, PCF("Entering OCGetResourceHandler"));
// Use the handle to find the resource in the resource linked list
- resource = findResource(handle);
+ resource = findResource((OCResource *)handle);
if (!resource) {
OC_LOG(ERROR, TAG, PCF("Resource not found"));
return NULL;