Commit 29704372 authored by Ashok Channa's avatar Ashok Channa Committed by Sudarshan Prasad

Fixed klockwork memory leaks and modified the logs

[IoT 252] CAGenerateToken creates the same token if it 
is called less than 500 milli seconds
Removed un-necessary files and added more test cases
Updated for compilation warning and klockwork fixes

Change-Id: I3710e92e9609441affcb40f10f92ef60f8d9f236
Signed-off-by: default avatarAshok Channa <ashok.channa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/151Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarSudarshan Prasad <sudarshan.prasad@intel.com>
parent 69d82fcb
Project Name: IoTivity
Release Version No: CA_v0.61
Release Version No: CA_v0.7
API Version: CA_v0.8
Release Description:
......@@ -22,6 +22,7 @@ Preconditions:
3)libcoap.a library ( do make @lib/libcoap-4.1.1)
4)tinyDTLS library for DTLS enabled applications( enable DTLS = 1 in makefile @connectivity\build/linux)
5)Ethernet, BLE, TimedActions, Timer libraries for arduino support.
6)scons for scon script compilation.
Scope of Release:
1. Supported APIs ( please check below APIs)
......@@ -54,7 +55,6 @@ CAGetNetworkInfo()
Known and Open Issues:
1) OIC Log, OIC Malloc will be removed once name changes applied to OIC Bases code.
2) Tizen platform BLE stack is not stable. So we may see random crashes.
3) GetDtlsPskCredentials is implemented in sample which will be replace by security call during integration
How to Build for Linux:
Follow below steps to execute CA Client / server in different systems
......
......@@ -58,7 +58,7 @@ typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
*/
typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
const CAResponseInfo_t *responseInfo);
#ifdef __WITH_DTLS__
/**
* @brief Callback function type for getting DTLS credentials.
......@@ -73,7 +73,7 @@ typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
* It will initialize adapters, thread pool and other modules based on the platform
* compilation options.
*
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CAInitialize();
......@@ -88,7 +88,7 @@ void CATerminate();
* @brief Starts listening servers.
* This API is used by resource hosting server for listening multicast requests.
* Based on the adapters configurations, different kinds of servers are started.
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED
*/
CAResult_t CAStartListeningServer();
......@@ -96,7 +96,7 @@ CAResult_t CAStartListeningServer();
* @brief Starts discovery servers.
* This API is used by resource required clients for listening multicast requests.
* Based on the adapters configurations, different kinds of servers are started.
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED
*/
CAResult_t CAStartDiscoveryServer();
......@@ -114,7 +114,7 @@ void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHand
/**
* @brief Register callback to get DTLS PSK credentials.
* @param GetDTLSCredentials [IN] GetDTLS Credetials callback
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK
*/
CAResult_t CARegisterDTLSCredentialsHandler(
CAGetDTLSCredentialsHandler GetDTLSCredentials);
......@@ -130,7 +130,7 @@ CAResult_t CARegisterDTLSCredentialsHandler(
* \n coap://10:11:12:13:45:45/resource_uri ( for BT)
* @param connectivityType [IN] Connectivity type of the endpoint
* @param object [OUT] Endpoint object which contains the above parsed data
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED
* @remark The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
* @see CADestroyRemoteEndpoint
*/
......@@ -148,7 +148,7 @@ void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
/**
* @brief Generating the token for matching the request and response.
* @param token [OUT] Token for the request
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
* @remark Token memory is destroyed by the caller using CADestroyToken().
* @see CADestroyToken
*/
......@@ -168,7 +168,7 @@ void CADestroyToken(CAToken_t token);
* @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
* path of Uri to be search.
* @param token [IN] Token for the request
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED
*/
CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
......@@ -177,7 +177,7 @@ CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
* @param object [IN] Remote Endpoint where the payload need to be sent.
* This Remote endpoint is delivered with Request or response callback.
* @param requestInfo [IN] Information for the request.
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
......@@ -186,7 +186,7 @@ CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requ
* @param object [IN] Group Endpoint where the payload need to be sent.
* This Remote endpoint is delivered with Request or response callback.
* @param requestInfo [IN] Information for the request.
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
const CARequestInfo_t *requestInfo);
......@@ -196,7 +196,7 @@ CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
* @param object [IN] Remote Endpoint where the payload need to be sent.
* This Remote endpoint is delivered with Request or response callback
* @param responseInfo [IN] Information for the response
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
......@@ -205,7 +205,7 @@ CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *re
* @param object [IN] Remote Endpoint where the payload need to be sent.
* This Remote endpoint is delivered with Request or response callback.
* @param responseInfo [IN] Information for the response.
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
CAResponseInfo_t *responseInfo);
......@@ -216,7 +216,7 @@ CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
* @param token [IN] Token for the request
* @param options [IN] Header options information
* @param numOptions [IN] Number of options
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
CAHeaderOption_t *options, uint8_t numOptions);
......@@ -224,14 +224,14 @@ CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
/**
* @brief Select network to use
* @param interestedNetwork [IN] Connectivity Type enum
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
*/
CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
/**
* @brief Select network to unuse
* @param nonInterestedNetwork [IN] Connectivity Type enum
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
*/
CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
......@@ -240,13 +240,13 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
* It should be destroyed by the caller as it Get Information.
* @param info [OUT] LocalConnectivity objects
* @param size [OUT] No Of Array objects
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or #CA_MEMORY_ALLOC_FAILED
*/
CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
/**
* @brief To Handle the Request or Response
* @return #CA_STATUS_OK or Appropriate error code
* @return #CA_STATUS_OK
*/
CAResult_t CAHandleRequestResponse();
......
......@@ -17,48 +17,48 @@ Linux Build:
2) Execute following command(s) to start build based on transport selection required :
-> Building for all transports :
scons TARGET_OS=linux TARGET_TRANSPORT=ALL
$ scons TARGET_OS=linux TARGET_TRANSPORT=ALL
-> Building for a specific transport :
scons TARGET_OS=linux TARGET_TRANSPORT=WIFI
$ scons TARGET_OS=linux TARGET_TRANSPORT=WIFI
-> Building for multiple transports :
scons TARGET_OS=linux TARGET_TRANSPORT=WIFI,ETHERNET
sudo scons TARGET_OS=linux TARGET_TRANSPORT=ALL -c ( for clean)
$ scons TARGET_OS=linux TARGET_TRANSPORT=WIFI,ETHERNET
-> Clean Build (all transports) :
scons TARGET_OS=linux TARGET_TRANSPORT=ALL -c (for clean)
3)The above command will build sample also.
For Enabling Secured server,
*Note: tinydtls libray has to copied to "connectivity/lib/tinydtls" for secured build.
3) The above command will build sample also.
Secured Server will be only used for WIFI and ETHERNET transports.
For Enabling Secured server,
* Note: tinydtls library has to copied to "connectivity/lib/tinydtls" for secured build.
Give command "sudo scons TARGET_OS=linux TARGET_TRANSPORT=WIFI SECURED=1
Secured Server will be only used for WIFI and ETHERNET transports.
or(For multiple transports will be mentioned using comma)
Give command "scons TARGET_OS=linux TARGET_TRANSPORT=WIFI SECURED=1
Give command "sudo scons TARGET_OS=linux TARGET_TRANSPORT=WIFI,ETHERNET SECURED=1
or (For multiple transports will be mentioned using comma)
Give command "scons TARGET_OS=linux TARGET_TRANSPORT=WIFI,ETHERNET SECURED=1
Android Build:
1) Go to "connectivity/build" folder.
1) Go to "connectivity/" folder.
2) Execute following command(s) to start build based on transport selection required :
-> Building for all transports :
scons TARGET_OS=android TARGET_TRANSPORT=ALL TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
$ scons TARGET_OS=android TARGET_TRANSPORT=ALL TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
-> Building for a specific transport :
scons TARGET_OS=android TARGET_TRANSPORT=WIFI TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
$ scons TARGET_OS=android TARGET_TRANSPORT=WIFI TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
-> Building for multiple transports :
scons TARGET_OS=android TARGET_TRANSPORT=WIFI,BT TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
$ scons TARGET_OS=android TARGET_TRANSPORT=WIFI,BT TARGET_ARCH=x86 ANDROID_NDK=your_ndk_path
Note :- Upon successful execution of above command(s) CA library will be generated at path
"~/connectivity/build/out/android/TARGET_ARCH/release or debug".
"~/connectivity/build/out/android/TARGET_ARCH/release or debug".
Tizen Build:
......@@ -69,13 +69,13 @@ Tizen Build:
3) Execute following command(s) to start build based on transport selection required :
-> Building for all transports :
scons TARGET_OS=tizen TARGET_TRANSPORT=ALL
$ scons TARGET_OS=tizen TARGET_TRANSPORT=ALL
-> Building for a specific transport :
scons TARGET_OS=tizen TARGET_TRANSPORT=WIFI
$ scons TARGET_OS=tizen TARGET_TRANSPORT=WIFI
-> Building for multiple transports :
scons TARGET_OS=tizen TARGET_TRANSPORT=WIFI,BT,BLE
$ scons TARGET_OS=tizen TARGET_TRANSPORT=WIFI,BT,BLE
4) By default, above command will build sample also.
To disable building sample, add BUILD_SAMPLE=OFF to the build command.
......@@ -89,33 +89,35 @@ Arduino Build:
Note :- Currently only megaADK build is supported.
1) Set up Arduino first before building. Refer to connectivity\build\arduino\Arduino_Setup_README.txt file for help.
1) Set up Arduino first before building. Refer to "connectivity\build\arduino\Arduino_Setup_README.txt" file for help.
2) Go to "connectivity/" folder.
3) Execute following command to start build :
scons TARGET_OS=arduino TARGET_TRANSPORT=<transport> TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
$ scons TARGET_OS=arduino TARGET_TRANSPORT=<transport> TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
Possible values for <transport> are:
-> ETHERNET :
scons TARGET_OS=arduino TARGET_TRANSPORT=ETHERNET TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
$ scons TARGET_OS=arduino TARGET_TRANSPORT=ETHERNET TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
-> WIFI :
scons TARGET_OS=arduino TARGET_TRANSPORT=WIFI TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
$ scons TARGET_OS=arduino TARGET_TRANSPORT=WIFI TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
-> BLE :
scons TARGET_OS=arduino TARGET_TRANSPORT=BLE TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
$ scons TARGET_OS=arduino TARGET_TRANSPORT=BLE TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation>
Note :- Only single transport can be built at a time for Arduino.
4) The above command will build sample also. The "CASample.hex" can be found at "/samples/arduino/"
5) After building sample, script will try to install on "/dev/ttyACM0" port in sudo mode.
5) After building sample, script will try to install on "/dev/ttyACM0" port in 'sudo' mode.
To skip installation, set command line argument 'UPLOAD=false'.
"scons TARGET_OS=arduino TARGET_TRANSPORT=ETHERNET TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation> UPLOAD=false"
6) To set BLE Shield Name, include the option DEVICE_NAME during scon build.
"scons TARGET_OS=arduino TARGET_TRANSPORT=ETHERNET TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation> DEVICE_NAME=OIC"
6) To set BLE Shield Name, include the option DEVICE_NAME during scons build.
-> $ scons TARGET_OS=arduino TARGET_TRANSPORT=ETHERNET TARGET_ARCH=avr BOARD=megaADK ARDUINO_HOME=<path_to_arduino_installation> DEVICE_NAME=OIC
Specified Device name length MUST be less than 10 characters. RBL Library has this limitation.
By Default DEVICE_NAME=OIC-DEVICE, if device name option is not specified
To change the port number, please modify "port" variable in __upload() function in: "/build/arduino/SConscript".
\ No newline at end of file
To change the port number, please modify "port" variable in __upload() function in: "/build/arduino/SConscript".
......@@ -37,9 +37,10 @@ BUILD_FLAG = $(BUILD_FLAG.$(BUILD))
include $(CLEAR_VARS)
LOCAL_PATH = $(PROJECT_LIB_PATH)/android
LOCAL_MODULE = Glib
LOCAL_SRC_FILES := libglib-2.0.so
LOCAL_EXPORT_C_INCLUDES = $(PROJECT_LIB_PATH)/android/glib-master \
$(PROJECT_LIB_PATH)/android/glib-master/android
LOCAL_SRC_FILES := libglib-2.40.2.so
LOCAL_EXPORT_C_INCLUDES = $(PROJECT_LIB_PATH)/android/glib-2.40.2 \
$(PROJECT_LIB_PATH)/android/glib-2.40.2/glib
include $(PREBUILT_SHARED_LIBRARY)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
......@@ -48,15 +49,15 @@ include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PATH = $(PROJECT_LIB_PATH)/android
LOCAL_MODULE = GLibThread
LOCAL_SRC_FILES := libgthread-2.0.so
LOCAL_EXPORT_C_INCLUDES = $(PROJECT_LIB_PATH)/android/glib-master \
$(PROJECT_LIB_PATH)/android/glib-master/android
LOCAL_SRC_FILES := libgthread-2.40.2.so
LOCAL_EXPORT_C_INCLUDES = $(PROJECT_LIB_PATH)/android/glib-2.40.2 \
$(PROJECT_LIB_PATH)/android/glib-2.40.2/glib
include $(PREBUILT_SHARED_LIBRARY)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include TinyDtls
#Build TinyDtls
include $(CLEAR_VARS)
include $(DTLS_LIB)/Android.mk
......@@ -72,6 +73,7 @@ LOCAL_MODULE = CACommon
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
LOCAL_SHARED_LIBRARIES = Glib GLibThread
LOCAL_CFLAGS = -D__ANDROID__ $(DEBUG_FLAG)
LOCAL_C_INCLUDES = $(PROJECT_COMMON_INC_PATH)
......@@ -133,11 +135,13 @@ LOCAL_SRC_FILES = \
camessagehandler.c canetworkconfigurator.c caprotocolmessage.c \
caretransmission.c caqueueingthread.c \
$(ADAPTER_UTILS)/caadapternetdtls.c $(ADAPTER_UTILS)/caadapterutils.c \
$(ADAPTER_UTILS)/camsgparser.c $(EDR_ADAPTER_PATH)/caedradapter.c \
$(ADAPTER_UTILS)/camsgparser.c \
$(LE_ADAPTER_PATH)/caleadapter.c $(LE_ADAPTER_PATH)/caleclient.c \
$(LE_ADAPTER_PATH)/caleserver.c $(LE_ADAPTER_PATH)/caleutils.c \
$(LE_ADAPTER_PATH)/calenwmonitor.c \
$(EDR_ADAPTER_PATH)/caedrcore.c \
bt_edr_adapter/caedradapter.c $(EDR_ADAPTER_PATH)/caedrutils.c \
$(EDR_ADAPTER_PATH)/caedrclient.c $(EDR_ADAPTER_PATH)/caedrserver.c \
$(EDR_ADAPTER_PATH)/caedrnwmonitor.c \
wifi_adapter/cawifiadapter.c $(WIFI_ADAPTER_PATH)/cawifiserver.c \
$(WIFI_ADAPTER_PATH)/cawificlient.c $(WIFI_ADAPTER_PATH)/cawifinwmonitor.c \
......
......@@ -81,8 +81,8 @@ libtiny_lib_dir = $(PROJECT_LIB_PATH)/extlibs/tinydtls
LDFLAGS := -L$(libcoap_build_dir) -L$(libtiny_lib_dir)
LDLIBS := -lcoap -ltinydtls
else
LDFLAGS := -L$(libcoap_build_dir)
LDLIBS := -lcoap
LDFLAGS := -L$(libcoap_build_dir)
LDLIBS := -lcoap
endif
BUILD_FLAG.debug = $(DEFINE_FLAG) $(DEBUG_FLAG)
......
......@@ -15,6 +15,11 @@ env.AppendUnique(CPPPATH = [
ca_common_path + 'inc/',
])
temp = env['CPPPATH']
header = ' '
for item in temp:
header = header + ' -I' + item
######################################################################
# Source files and Target(s)
######################################################################
......@@ -26,8 +31,9 @@ ca_common_src = [
]
if ca_os == 'arduino':
env.Command(env.get('BUILD_DIR') + 'logger.c.o', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c.o' + ' $LINKFLAGS $CCFLAGS $CXXFLAGS ' + header + ' ' + ca_common_src_path + 'logger.c')
platform_src = [
ca_common_src_path + 'logger.cpp',
env.get('BUILD_DIR') + 'logger.c.o',
]
else:
platform_src = [
......
......@@ -158,7 +158,7 @@ void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16
* @param tag - Module name
* @param format - variadic log string
*/
void OICLogv(LogLevel level, const char *tag, const int16_t lineNum, const char *format, ...);
void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *format, ...);
#endif
#ifdef TB_LOG
......@@ -176,6 +176,8 @@ void OICLogv(LogLevel level, const char *tag, const int16_t lineNum, const char
#define OIC_LOG_SHUTDOWN()
#define OIC_LOG(level, tag, logStr) OICLog((level), PCF(tag), __LINE__, PCF(logStr))
#define OIC_LOG_V(level, tag, ...)
// To enable OIC_LOG_V, uncomment the below
//#define OIC_LOG_V(level, tag, format, ...) OICLogv((level), PCF(tag), __LINE__, PCF(format), __VA_ARGS__)
#else
#define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
#define OIC_LOG_SHUTDOWN() OICLogShutdown()
......
......@@ -22,10 +22,6 @@
#include "string.h"
#include "oic_logger.h"
#include "oic_console_logger.h"
#ifdef ARDUINO
#include "Arduino.h"
#include <avr/pgmspace.h>
#endif
#ifndef __TIZEN__
static oic_log_ctx_t *logCtx = 0;
......@@ -53,6 +49,7 @@ static const char *LEVEL[] __attribute__ ((unused)) =
{ "DEBUG", "INFO", "WARNING", "ERROR", "FATAL"};
#elif defined ARDUINO
#include <stdarg.h>
#include "Arduino.h"
PROGMEM const char level0[] = "DEBUG";
PROGMEM const char level1[] = "INFO";
......@@ -194,7 +191,8 @@ void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16
}
}
#endif //__TIZEN__
#else
#endif //ARDUINO
#ifdef ARDUINO
/**
* Initialize the serial logger for Arduino
* Only defined for Arduino
......@@ -213,30 +211,27 @@ void OICLogInit()
* @param tag - Module name
* @param logStr - log string
*/
void OICLogString(LogLevel level, PROGMEM const char *tag, const char *logStr)
{
if (!logStr || !tag)
{
return;
}
char buffer[LINE_BUFFER_SIZE];
GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
Serial.print(buffer);
char c;
Serial.print(F(": "));
while ((c = pgm_read_byte(tag)))
{
Serial.write(c);
tag++;
}
Serial.print(F(": "));
Serial.println(logStr);
}
/*
void OCLogString(LogLevel level, PROGMEM const char * tag, const char * logStr) {
if (!logStr || !tag) {
return;
}
char buffer[LINE_BUFFER_SIZE] = {0};
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(": "));
Serial.println(logStr);
}
*/
/**
* Output the contents of the specified buffer (in hex) with the specified priority level.
*
......@@ -245,36 +240,31 @@ void OICLogString(LogLevel level, PROGMEM const char *tag, const char *logStr)
* @param buffer - pointer to buffer of bytes
* @param bufferSize - max number of byte in buffer
*/
void OICLogBuffer(LogLevel level, PROGMEM const char *tag, const uint8_t *buffer,
uint16_t bufferSize)
{
if (!buffer || !tag || (bufferSize == 0))
{
return;
}
char lineBuffer[LINE_BUFFER_SIZE] =
{ 0};
uint8_t lineIndex = 0;
for (uint8_t i = 0; i < bufferSize; i++)
{
// Format the buffer data into a line
sprintf(&lineBuffer[lineIndex++ * 3], "%02X ", buffer[i]);
// Output 16 values per line
if (((i + 1) % 16) == 0)
{
OICLogString(level, tag, lineBuffer);
memset(lineBuffer, 0, sizeof lineBuffer);
lineIndex = 0;
}
}
// Output last values in the line, if any
if (bufferSize % 16)
{
OICLogString(level, tag, lineBuffer);
}
}
/*
void OCLogBuffer(LogLevel level, PROGMEM const char * tag, const uint8_t * buffer, uint16_t bufferSize) {
if (!buffer || !tag || (bufferSize == 0)) {
return;
}
char lineBuffer[LINE_BUFFER_SIZE] = {0};
uint8_t lineIndex = 0;
for (uint8_t i = 0; i < bufferSize; i++) {
// Format the buffer data into a line
sprintf(&lineBuffer[lineIndex++ * 3], "%02X ", buffer[i]);
// Output 16 values per line
if (((i+1)%16) == 0) {
OCLogString(level, tag, lineBuffer);
memset(lineBuffer, 0, sizeof lineBuffer);
lineIndex = 0;
}
}
// Output last values in the line, if any
if (bufferSize % 16) {
OCLogString(level, tag, lineBuffer);
}
}
*/
/**
* Output a log string with the specified priority level.
* Only defined for Arduino. Uses PROGMEM strings
......@@ -283,18 +273,15 @@ void OICLogBuffer(LogLevel level, PROGMEM const char *tag, const uint8_t *buffer
* @param tag - Module name
* @param logStr - log string
*/
void OICLog(LogLevel level, PROGMEM const char *tag, PROGMEM const char *logStr)
void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *logStr)
{
if (!logStr || !tag)
{
return;
}
char buffer[LINE_BUFFER_SIZE];
GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
char buffer[LINE_BUFFER_SIZE] = {0};
strcpy_P(buffer, (char*)pgm_read_word(&(LEVEL[level])));
Serial.print(buffer);
char c;
Serial.print(F(": "));
while ((c = pgm_read_byte(tag)))
......@@ -303,7 +290,8 @@ void OICLog(LogLevel level, PROGMEM const char *tag, PROGMEM const char *logStr)
tag++;
}
Serial.print(F(": "));
Serial.print(lineNum);
Serial.print(F(": "));
while ((c = pgm_read_byte(logStr)))
{
Serial.write(c);
......@@ -320,28 +308,28 @@ void OICLog(LogLevel level, PROGMEM const char *tag, PROGMEM const char *logStr)
* @param tag - Module name
* @param format - variadic log string
*/
void OICLogv(LogLevel level, PROGMEM const char *tag, const char *format, ...)
void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *format, ...)
{
char buffer[LINE_BUFFER_SIZE];
va_list ap;
va_start(ap, format);
GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
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++;
}
while ((c = pgm_read_byte(tag))) {
Serial.write(c);
tag++;
}
Serial.print(F(": "));
Serial.print(lineNum);
Serial.print(F(": "));
vsnprintf(buffer, sizeof(buffer), format, ap);
for (char *p = &buffer[0]; *p; p++) // emulate cooked mode for newlines
vsnprintf_P(buffer, sizeof(buffer), format, ap);
for (char *p = &buffer[0]; *p; p++)
{
// emulate cooked mode for newlines
if (*p == '\n')
{
Serial.write('\r');
......@@ -359,23 +347,23 @@ void OICLogv(LogLevel level, PROGMEM const char *tag, const char *format, ...)
* @param tag - Module name
* @param format - variadic log string
*/
void OICLogv(LogLevel level, PROGMEM const char *tag, const __FlashStringHelper *format, ...)
void OICLogv(LogLevel level, const char *tag, const __FlashStringHelper *format, ...)