Porting TBStack Functionality to Arduino. The following changes were made
authorJoseph Morrow <joseph.l.morrow@intel.com>
Fri, 15 Aug 2014 20:49:36 +0000 (16:49 -0400)
committerJoseph Morrow <joseph.l.morrow@intel.com>
Fri, 15 Aug 2014 20:49:36 +0000 (16:49 -0400)
for this:

Added PCF() wrappers around const char* strings to store pre-defined debug
statements in flash, rather than RAM. This only 'affects' Arduino. It has
no affect on linux.

Removed erroneous/un-wanted #include headers from the public TB Stack API

Removed #include ocrandom.h as it was/is unneeded by ISVs.

Updated makefiles to be more friendly between Linux Vs.
Arduino builds (i.e. made both build without a hitch).

Cleaned up warnings that AVR-GCC marked as warnings that regular 'ol GCC
 did not.  Most notably line 328 or 329 "OCStopCoAP()" is being called
with a parameter. OCStopCoAP does not take ANY parameters.

Fixed bug with Arduino devices not retrieving correct IP address structs
from Linux devices (i.e. OCDevAddr needed to be #pragma packed).

Change-Id: Ided8d61ba647889d7a52fa7a4477ca67944b0fa0

24 files changed:
csdk/libcoap-4.1.1/address.h
csdk/libcoap-4.1.1/coap.h
csdk/libcoap-4.1.1/examples/server.c
csdk/libcoap-4.1.1/makefile
csdk/logger/include/logger.h
csdk/logger/src/logger.c
csdk/makefile
csdk/occoap/include/occoaphelper.h
csdk/occoap/include/occoaptoken.h
csdk/occoap/src/occoap.c
csdk/occoap/src/occoaphelper.c
csdk/ocsocket/include/ocsocket.h
csdk/ocsocket/src/ocsocket_arduino.cpp
csdk/ocsocket/test/arduino/makefile
csdk/stack/include/internal/ocstackinternal.h
csdk/stack/include/ocstack.h
csdk/stack/samples/linux/SimpleClientServer/common.cpp [moved from csdk/stack/samples/SimpleClientServer/common.cpp with 100% similarity]
csdk/stack/samples/linux/SimpleClientServer/makefile [moved from csdk/stack/samples/SimpleClientServer/makefile with 95% similarity]
csdk/stack/samples/linux/SimpleClientServer/occlient.cpp [moved from csdk/stack/samples/SimpleClientServer/occlient.cpp with 99% similarity]
csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp [moved from csdk/stack/samples/SimpleClientServer/ocserver.cpp with 99% similarity]
csdk/stack/src/ocobserve.c
csdk/stack/src/ocresource.c
csdk/stack/src/ocserverrequest.c
csdk/stack/src/ocstack.c

index 0b7caa6..39e1221 100644 (file)
@@ -159,7 +159,7 @@ _coap_is_mcast_impl(const coap_address_t *a) {
         return 0;
 
     /* TODO */
-    return 1;
+    return 0;
 }
 
 #endif /* WITH_ARDUINO */
index 3e2828c..eb2a44c 100644 (file)
@@ -9,6 +9,8 @@
 #ifndef _COAP_H_
 #define _COAP_H_
 
+#include "net.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -19,7 +21,6 @@ extern "C" {
 #include "coap_list.h"
 #include "pdu.h"
 #include "option.h"
-#include "net.h"
 #include "encode.h"
 #include "str.h"
 #include "uri.h"
index 3b638ec..ee4d73f 100644 (file)
@@ -365,7 +365,7 @@ get_context(const char *node, const char *port) {
         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;
       }
@@ -461,7 +461,7 @@ main(int argc, char **argv) {
       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 */
index 4b96e50..631fe60 100644 (file)
@@ -1,5 +1,7 @@
-# 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
@@ -10,6 +12,7 @@ ROOT_DIR = ..
 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
@@ -35,7 +38,7 @@ else ifeq ($(PLATFORM),linux)
     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++
@@ -49,8 +52,8 @@ else
 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 
index 07b6ac1..69ad41e 100644 (file)
 #include <stdio.h>
 #include <stdarg.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef __ANDROID__
     #include <android/log.h>
 #elif defined ARDUINO
@@ -36,6 +32,10 @@ extern "C" {
     #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
@@ -115,6 +115,15 @@ typedef enum {
      * @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
@@ -126,7 +135,7 @@ typedef enum {
         // 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()
index 5cd00d7..54b8fe1 100644 (file)
@@ -22,8 +22,6 @@
 #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
@@ -33,8 +31,7 @@ static const uint16_t LINE_BUFFER_SIZE = (16 * 2) + 16 + 1;  // Show 16 bytes, 2
     //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";
@@ -153,7 +150,7 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint1
           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);
 
@@ -216,7 +213,7 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint1
           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);
 
@@ -235,6 +232,91 @@ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint1
         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
 
 
index 8e7998e..dc4e25f 100644 (file)
@@ -1,15 +1,43 @@
-# 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
@@ -42,11 +70,10 @@ INC_DIRS    += -I$(OCTBSTACK_INC)
 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
@@ -70,21 +97,20 @@ make_lcoap:
        $(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
 
index 19772fe..4641b0d 100644 (file)
@@ -25,7 +25,9 @@
 //-----------------------------------------------------------------------------
 // Includes
 //-----------------------------------------------------------------------------
+#ifndef WITH_ARDUINO
 #include <unistd.h>
+#endif
 #include <limits.h>
 #include <ctype.h>
 #include "coap.h"
index 503ca80..b4a674b 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef OCCOAPTOKEN_H_
 #define OCCOAPTOKEN_H_
 
+#include <stddef.h>
+
 #define MAX_TOKEN_LENGTH (8)
 
 typedef struct {
index ac04a33..c982608 100644 (file)
@@ -25,6 +25,7 @@
 #include "occoap.h"
 #include "occlientcb.h"
 #include "ocobserve.h"
+#include "logger.h"
 #include <coap.h>
 
 #ifndef WITH_ARDUINO
@@ -38,8 +39,8 @@
 //-----------------------------------------------------------------------------
 #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)
@@ -152,7 +153,7 @@ static void HandleCoAPRequests(struct coap_context_t *ctx,
     // 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);
     }
 
@@ -238,12 +239,12 @@ static void HandleCoAPResponses(struct coap_context_t *ctx,
             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;
         }
@@ -253,7 +254,7 @@ static void HandleCoAPResponses(struct coap_context_t *ctx,
     }
     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:
@@ -285,7 +286,7 @@ int OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
     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 };
@@ -315,7 +316,6 @@ int OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
                 coap_join_wellknown_group(gCoAPCtx,
                         (coap_address_t* )&mcastAddr), 0);
     }
-
     coap_register_request_handler(gCoAPCtx, HandleCoAPRequests);
     coap_register_response_handler(gCoAPCtx, HandleCoAPResponses);
 
@@ -324,7 +324,7 @@ int OCInitCoAP(const char *address, uint16_t port, OCMode mode) {
 exit:
     if (ret != OC_COAP_OK)
     {
-        OCStopCoAP(gCoAPCtx);
+        OCStopCoAP();
     }
     return ret;
 }
@@ -421,7 +421,7 @@ int OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * toke
     // 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) {
@@ -440,7 +440,7 @@ int OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * toke
             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;
     }
 
@@ -456,7 +456,7 @@ int OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * toke
     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;
     }
@@ -503,7 +503,7 @@ int OCCoAPSendMessage (OCDevAddr *dstAddr, OCStackResult msgCode,
     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;
     }
@@ -538,13 +538,13 @@ int OCProcessCoAP() {
     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);
index 26e0581..9e42081 100644 (file)
@@ -28,7 +28,7 @@
 // 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
@@ -325,7 +325,7 @@ GenerateCoAPPdu(uint8_t msgType, uint8_t code, unsigned short id,
 
     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) {
@@ -370,7 +370,7 @@ CreateNewOptionNode(unsigned short key, unsigned int length, unsigned char *data
     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;
@@ -386,7 +386,7 @@ CreateNewOptionNode(unsigned short key, unsigned int length, unsigned char *data
     }
 
 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;
 }
index 5a62e45..ed085c4 100644 (file)
@@ -69,10 +69,12 @@ extern "C" {
  * 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
index db20d01..bb7ceac 100644 (file)
@@ -34,7 +34,7 @@
 #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
@@ -181,7 +181,6 @@ int32_t OCSendTo(int32_t sockfd, const uint8_t* buf, uint32_t bufLen, uint32_t f
 
     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"));
@@ -234,7 +233,7 @@ int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
     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;
     }
 
@@ -253,7 +252,7 @@ int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port)
     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;
     }
 
index cc9ec24..a479cb9 100644 (file)
@@ -21,7 +21,7 @@ IDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
 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
index 879ae88..fb6d2d5 100644 (file)
@@ -31,6 +31,8 @@
 #include "ocstack.h"
 #include "occoaptoken.h"
 #include "occlientcb.h"
+#include <logger.h>
+#include <ocrandom.h>
 
 #ifdef __cplusplus
 extern "C" {
index 9783e2c..1f2b51a 100644 (file)
@@ -21,9 +21,7 @@
 #ifndef OCSTACK_H_
 #define OCSTACK_H_
 
-#include <ocsocket.h>
-#include <logger.h>
-#include <ocrandom.h>
+#include "ocsocket.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -7,7 +7,7 @@ OUT_DIR   := $(PWD)/$(BUILD)
 OBJ_DIR          := $(OUT_DIR)/obj
 
 ifeq ($(ROOT_DIR), )
-ROOT_DIR       = $(PWD)/../../..
+ROOT_DIR       = $(PWD)/../../../..
 endif
 
 OUT_DIR        = $(PWD)
@@ -37,7 +37,7 @@ CC_FLAGS.debug      := -O0 -g3 -Wall -ffunction-sections -fdata-sections -fno-ex
                         -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)
 
@@ -48,7 +48,7 @@ OBJECTS:= $(patsubst %.c, $(OBJ_DIR)/%.o, $(SOURCES))
 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);
@@ -25,8 +25,8 @@
 #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);
 
index 92ab227..1d54cd6 100644 (file)
@@ -49,7 +49,7 @@ OCStackResult ProcessObserveRequest (OCResource *resource, OCRequest *request)
     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)
         {
@@ -71,7 +71,7 @@ OCStackResult ProcessObserveRequest (OCResource *resource, OCRequest *request)
         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;
     }
 }
@@ -121,7 +121,7 @@ OCStackResult SendObserverNotification (OCResourceHandle handle, OCResource *res
     }
     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;
index fdaf8fd..6e2816e 100644 (file)
@@ -51,7 +51,7 @@ uint8_t IsVirtualResource(const char* resourceUri)
 {
     for (int i = 0; i < OC_MAX_RESOURCES; i++)
     {
-        if (strcmp(resourceUri, GetVirtualResourceUri(i)) == 0)
+        if (strcmp(resourceUri, GetVirtualResourceUri((OCVirtualResources)i)) == 0)
         {
             return 1;
         }
index 66e955a..6c3c4d1 100644 (file)
@@ -47,7 +47,7 @@ OCStackResult ProcessResourceDiscoverReq (OCEntityHandlerRequest *request,
     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());
@@ -120,7 +120,7 @@ OCStackResult ProcessResourceDiscoverReq (OCEntityHandlerRequest *request,
     cJSON_Delete (ocObj);
     free (jsonStr);
 
-    OC_LOG_V(INFO, TAG, PCF("Exiting ProcessResourceDiscoverReq"));
+    OC_LOG(INFO, TAG, PCF("Exiting ProcessResourceDiscoverReq"));
     return ret;
 }
 
@@ -129,7 +129,7 @@ OCStackResult ValidateUrlQuery (unsigned char *url, unsigned char *query,
 {
     char *filterParam;
 
-    OC_LOG_V(INFO, TAG, PCF("Exiting ValidateUrlQuery"));
+    OC_LOG(INFO, TAG, PCF("Entering ValidateUrlQuery"));
     if (!url)
         return OC_STACK_INVALID_URI;
 
@@ -155,7 +155,7 @@ OCStackResult ValidateUrlQuery (unsigned char *url, unsigned char *query,
         // 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;
 }
 
index f34a492..8137eb5 100644 (file)
@@ -58,7 +58,7 @@ OCResource *headResource = NULL;
 
 //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;
@@ -90,7 +90,7 @@ OCStackResult HandleStackRequests(OCRequest * request) {
         }
         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)
@@ -105,7 +105,7 @@ OCStackResult HandleStackRequests(OCRequest * request) {
 //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"));
@@ -177,12 +177,13 @@ static void deleteAllResources();
 //-----------------------------------------------------------------------------
 // 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;
 }
 
 //-----------------------------------------------------------------------------
@@ -339,7 +340,7 @@ OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requ
     }
 
     // Make call to OCCoAP layer
-    result = OCDoCoAPResource(method, qos, token, requiredUri, request);
+    result = (OCStackResult)OCDoCoAPResource(method, qos, token, requiredUri, request);
 
 exit:
 
@@ -388,7 +389,7 @@ OCStackResult OCCancel(OCDoHandle handle) {
 
     OC_LOG(INFO, TAG, PCF("Entering OCCancel"));
 
-    ClientCB *clientCB = GetClientCB(NULL, handle);
+    ClientCB *clientCB = GetClientCB(NULL, &handle);
 
     if(clientCB) {
         switch (clientCB->method)
@@ -575,7 +576,7 @@ OCStackResult OCBindResource(
     // 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;
         }
@@ -623,7 +624,7 @@ OCStackResult OCUnBindResource(
     // 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;
         }
@@ -1030,7 +1031,7 @@ OCStackResult OCBindResourceHandler(OCResourceHandle handle,
     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;
@@ -1057,7 +1058,7 @@ OCEntityHandler OCGetResourceHandler(OCResourceHandle handle) {
     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;