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
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
ifndef LIBNAME
QUICKSTART=1
......
......@@ -18,10 +18,8 @@ $(ARCHIVE): $(CONTIKI_OBJECTFILES) | $(OBJECTDIR)
$(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR)
ifdef REDEF_PRINTF
@echo Redefining printf
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym printf=log_printf $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym puts=log_puts $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym putchar=log_putchar $(OBJ); )
@echo Redefining printf,sprintf,vsnprintf,etc.
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-syms $(CONTIKI)/arch/platform/cooja/redefine.syms $(OBJ); )
endif ## REDEF_PRINTF
$(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 @@
#include <string.h>
#include "lib/simEnvChange.h"
#define IMPLEMENT_PRINTF 1
#ifndef MAX_LOG_LENGTH
#define MAX_LOG_LENGTH 8192
#endif /* MAX_LOG_LENGTH */
const struct simInterface simlog_interface;
/* Variables shared between COOJA and Contiki */
......@@ -64,13 +61,14 @@ simlog_char(char c)
void
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 */
return;
}
memcpy(simLoggedData + simLoggedLength, message, strlen(message));
simLoggedLength += strlen(message);
memcpy(simLoggedData + simLoggedLength, message, message_len);
simLoggedLength += message_len;
simLoggedFlag = 1;
}
/*-----------------------------------------------------------------------------------*/
......@@ -98,9 +96,8 @@ log_set_putchar_with_slip(int with)
log_putchar_with_slip = with;
}
/*-----------------------------------------------------------------------------------*/
#if IMPLEMENT_PRINTF
int
putchar(int c)
dbg_putchar(int c)
{
#define SLIP_END 0300
static char debug_frame = 0;
......@@ -124,41 +121,21 @@ putchar(int c)
simlog_char(SLIP_END);
debug_frame = 0;
}
return c;
} else {
simlog_char(c);
return c;
}
return c;
}
/*-----------------------------------------------------------------------------------*/
int
puts(const char* s)
{
simlog(s);
simlog_char('\n');
return 0;
}
/*-----------------------------------------------------------------------------------*/
int
printf(const char *fmt, ...)
unsigned int
dbg_send_bytes(const unsigned char *s, unsigned int len)
{
int res;
static char buf[MAX_LOG_LENGTH];
va_list ap;
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]);
unsigned int i;
for(i = 0; i < len && s && *s != 0; i++) {
putchar(*s++);
}
return res;
return i;
}
#endif /* IMPLEMENT_PRINTF */
/*-----------------------------------------------------------------------------------*/
SIM_INTERFACE(simlog_interface,
......
......@@ -34,6 +34,8 @@
#include <stdio.h>
#include <strformat.h>
#include <string.h>
#undef snprintf
#undef vsnprintf
/*---------------------------------------------------------------------------*/
struct fmt_buffer {
char *pos;
......
......@@ -34,6 +34,7 @@
#include <stdio.h>
#include <strformat.h>
#include <string.h>
#undef sprintf
/*---------------------------------------------------------------------------*/
static strformat_result
buffer_str(void *user_data, const char *data, unsigned int len)
......
......@@ -31,6 +31,7 @@
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include <string.h>
#include <strformat.h>
/*---------------------------------------------------------------------------*/
#define HAVE_DOUBLE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment