Skip to content
Snippets Groups Projects
Unverified Commit 5867094f authored by Nicolas Tsiftes's avatar Nicolas Tsiftes Committed by GitHub
Browse files

Merge pull request #1778 from nfi/contrib/cooja-dbg-io

Use dbg-io for printf, snprintf, etc., in Contiki motes for Cooja
parents 521e9af9 ce8c3612
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,9 @@ endif ...@@ -13,6 +13,9 @@ endif
COOJA_DIR = $(CONTIKI_NG_TOOLS_DIR)/cooja COOJA_DIR = $(CONTIKI_NG_TOOLS_DIR)/cooja
# Use dbg-io for IO functions like printf()
MODULES += os/lib/dbg-io
### Assuming simulator quickstart if no JNI library name set from Cooja ### Assuming simulator quickstart if no JNI library name set from Cooja
ifndef LIBNAME ifndef LIBNAME
QUICKSTART=1 QUICKSTART=1
......
...@@ -18,10 +18,8 @@ $(ARCHIVE): $(CONTIKI_OBJECTFILES) | $(OBJECTDIR) ...@@ -18,10 +18,8 @@ $(ARCHIVE): $(CONTIKI_OBJECTFILES) | $(OBJECTDIR)
$(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR) $(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR)
ifdef REDEF_PRINTF ifdef REDEF_PRINTF
@echo Redefining printf @echo Redefining printf,sprintf,vsnprintf,etc.
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym printf=log_printf $(OBJ); ) -$(foreach OBJ,$^, $(OBJCOPY) --redefine-syms $(CONTIKI)/arch/platform/cooja/redefine.syms $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym puts=log_puts $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym putchar=log_putchar $(OBJ); )
endif ## REDEF_PRINTF endif ## REDEF_PRINTF
$(LINK_COMMAND_1) $^ $(LINK_COMMAND_2) $(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
......
# Symbols to redefine to ensure use of Contiki-NG implementations
printf log_printf
sprintf log_sprintf
snprintf log_snprintf
vsnprintf log_vsnprintf
puts log_puts
putchar log_putchar
...@@ -33,13 +33,10 @@ ...@@ -33,13 +33,10 @@
#include <string.h> #include <string.h>
#include "lib/simEnvChange.h" #include "lib/simEnvChange.h"
#define IMPLEMENT_PRINTF 1
#ifndef MAX_LOG_LENGTH #ifndef MAX_LOG_LENGTH
#define MAX_LOG_LENGTH 8192 #define MAX_LOG_LENGTH 8192
#endif /* MAX_LOG_LENGTH */ #endif /* MAX_LOG_LENGTH */
const struct simInterface simlog_interface; const struct simInterface simlog_interface;
/* Variables shared between COOJA and Contiki */ /* Variables shared between COOJA and Contiki */
...@@ -64,13 +61,14 @@ simlog_char(char c) ...@@ -64,13 +61,14 @@ simlog_char(char c)
void void
simlog(const char *message) simlog(const char *message)
{ {
if (simLoggedLength + strlen(message) > MAX_LOG_LENGTH) { int message_len = strlen(message);
if(simLoggedLength + message_len > MAX_LOG_LENGTH) {
/* Dropping message due to buffer overflow */ /* Dropping message due to buffer overflow */
return; return;
} }
memcpy(simLoggedData + simLoggedLength, message, strlen(message)); memcpy(simLoggedData + simLoggedLength, message, message_len);
simLoggedLength += strlen(message); simLoggedLength += message_len;
simLoggedFlag = 1; simLoggedFlag = 1;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
...@@ -98,9 +96,8 @@ log_set_putchar_with_slip(int with) ...@@ -98,9 +96,8 @@ log_set_putchar_with_slip(int with)
log_putchar_with_slip = with; log_putchar_with_slip = with;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
#if IMPLEMENT_PRINTF
int int
putchar(int c) dbg_putchar(int c)
{ {
#define SLIP_END 0300 #define SLIP_END 0300
static char debug_frame = 0; static char debug_frame = 0;
...@@ -124,41 +121,21 @@ putchar(int c) ...@@ -124,41 +121,21 @@ putchar(int c)
simlog_char(SLIP_END); simlog_char(SLIP_END);
debug_frame = 0; debug_frame = 0;
} }
return c;
} else { } else {
simlog_char(c); simlog_char(c);
return c;
} }
return c;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
int unsigned int
puts(const char* s) dbg_send_bytes(const unsigned char *s, unsigned int len)
{
simlog(s);
simlog_char('\n');
return 0;
}
/*-----------------------------------------------------------------------------------*/
int
printf(const char *fmt, ...)
{ {
int res; unsigned int i;
static char buf[MAX_LOG_LENGTH]; for(i = 0; i < len && s && *s != 0; i++) {
va_list ap; putchar(*s++);
int i;
va_start(ap, fmt);
res = vsnprintf(buf, MAX_LOG_LENGTH, fmt, ap);
va_end(ap);
// simlog(buf);
for(i = 0; i < res; i++) {
putchar(buf[i]);
} }
return res; return i;
} }
#endif /* IMPLEMENT_PRINTF */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SIM_INTERFACE(simlog_interface, SIM_INTERFACE(simlog_interface,
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <stdio.h> #include <stdio.h>
#include <strformat.h> #include <strformat.h>
#include <string.h> #include <string.h>
#undef snprintf
#undef vsnprintf
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
struct fmt_buffer { struct fmt_buffer {
char *pos; char *pos;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <stdio.h> #include <stdio.h>
#include <strformat.h> #include <strformat.h>
#include <string.h> #include <string.h>
#undef sprintf
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static strformat_result static strformat_result
buffer_str(void *user_data, const char *data, unsigned int len) buffer_str(void *user_data, const char *data, unsigned int len)
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include "contiki.h" #include "contiki.h"
#include <string.h>
#include <strformat.h> #include <strformat.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#define HAVE_DOUBLE #define HAVE_DOUBLE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment