Use the logging module

This commit is contained in:
George Oikonomou 2017-10-29 01:28:05 +00:00
parent 2388aa9302
commit ab68be8672
2 changed files with 28 additions and 23 deletions

View File

@ -32,15 +32,17 @@
#include "net/ipv6/uip.h" #include "net/ipv6/uip.h"
#include "net/packetbuf.h" #include "net/packetbuf.h"
#include "dev/slip.h" #include "dev/slip.h"
#include "os/sys/log.h"
#include <stdio.h> #include <stdio.h>
#define LOG_MODULE "slip-net"
#define LOG_LEVEL LOG_LEVEL_NONE
/*---------------------------------------------------------------------------*/
#define SLIP_END 0300 #define SLIP_END 0300
#define SLIP_ESC 0333 #define SLIP_ESC 0333
#define SLIP_ESC_END 0334 #define SLIP_ESC_END 0334
#define SLIP_ESC_ESC 0335 #define SLIP_ESC_ESC 0335
#define DEBUG 0
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
slipnet_init(void) slipnet_init(void)
@ -79,29 +81,28 @@ slipnet_input(void)
uip_len = packetbuf_datalen(); uip_len = packetbuf_datalen();
i = packetbuf_copyto(uip_buf); i = packetbuf_copyto(uip_buf);
if(DEBUG) { LOG_DBG("Slipnet got input of len: %d, copied: %d\n",
printf("Slipnet got input of len: %d, copied: %d\n", packetbuf_datalen(), i);
packetbuf_datalen(), i);
for(i = 0; i < uip_len; i++) { for(i = 0; i < uip_len; i++) {
printf("%02x", (unsigned char) uip_buf[i]); LOG_DBG("%02x", (unsigned char)uip_buf[i]);
if((i & 15) == 15) printf("\n"); if((i & 15) == 15) {
else if((i & 7) == 7) printf(" "); LOG_DBG_("\n");
} else if((i & 7) == 7) {
LOG_DBG_(" ");
} }
printf("\n");
} }
LOG_DBG_("\n");
/* printf("SUT: %u\n", uip_len); */
slip_send_packet(uip_buf, uip_len); slip_send_packet(uip_buf, uip_len);
} }
/*---------------------------------------------------------------------------*/
static uint8_t static uint8_t
slipnet_output(const linkaddr_t *localdest) slipnet_output(const linkaddr_t *localdest)
{ {
/* do nothing... */ /* do nothing... */
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
const struct network_driver slipnet_driver = { const struct network_driver slipnet_driver = {
"slipnet", "slipnet",

View File

@ -42,12 +42,16 @@
#include "net/netstack.h" #include "net/netstack.h"
#include "net/packetbuf.h" #include "net/packetbuf.h"
#define DEBUG DEBUG_NONE
#include "net/ipv6/uip-debug.h"
#include "cmd.h" #include "cmd.h"
#include "slip-radio.h" #include "slip-radio.h"
#include "packetutils.h" #include "packetutils.h"
#include "os/sys/log.h"
#include <stdio.h>
#define LOG_MODULE "slip-radio"
#define LOG_LEVEL LOG_LEVEL_NONE
/*---------------------------------------------------------------------------*/
#ifdef SLIP_RADIO_CONF_SENSORS #ifdef SLIP_RADIO_CONF_SENSORS
extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS; extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS;
#endif #endif
@ -114,8 +118,8 @@ packet_sent(void *ptr, int status, int transmissions)
uint8_t sid; uint8_t sid;
int pos; int pos;
sid = *((uint8_t *)ptr); sid = *((uint8_t *)ptr);
PRINTF("Slip-radio: packet sent! sid: %d, status: %d, tx: %d\n", LOG_DBG("Slip-radio: packet sent! sid: %d, status: %d, tx: %d\n",
sid, status, transmissions); sid, status, transmissions);
/* packet callback from lower layers */ /* packet callback from lower layers */
/* neighbor_info_packet_sent(status, transmissions); */ /* neighbor_info_packet_sent(status, transmissions); */
pos = 0; pos = 0;
@ -141,7 +145,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
packetbuf_clear(); packetbuf_clear();
pos = packetutils_deserialize_atts(&data[3], len - 3); pos = packetutils_deserialize_atts(&data[3], len - 3);
if(pos < 0) { if(pos < 0) {
PRINTF("slip-radio: illegal packet attributes\n"); LOG_ERR("slip-radio: illegal packet attributes\n");
return 1; return 1;
} }
pos += 3; pos += 3;
@ -152,8 +156,8 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
memcpy(packetbuf_dataptr(), &data[pos], len); memcpy(packetbuf_dataptr(), &data[pos], len);
packetbuf_set_datalen(len); packetbuf_set_datalen(len);
PRINTF("slip-radio: sending %u (%d bytes)\n", LOG_DBG("slip-radio: sending %u (%d bytes)\n",
data[2], packetbuf_datalen()); data[2], packetbuf_datalen());
/* parse frame before sending to get addresses, etc. */ /* parse frame before sending to get addresses, etc. */
parse_frame(); parse_frame();
@ -167,7 +171,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len)
return 1; return 1;
} }
} else if(uip_buf[0] == '?') { } else if(uip_buf[0] == '?') {
PRINTF("Got request message of type %c\n", uip_buf[1]); LOG_DBG("Got request message of type %c\n", uip_buf[1]);
if(data[1] == 'M') { if(data[1] == 'M') {
/* this is just a test so far... just to see if it works */ /* this is just a test so far... just to see if it works */
uip_buf[0] = '!'; uip_buf[0] = '!';
@ -192,7 +196,7 @@ slip_radio_cmd_output(const uint8_t *data, int data_len)
static void static void
slip_input_callback(void) slip_input_callback(void)
{ {
PRINTF("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]); LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]);
cmd_input(uip_buf, uip_len); cmd_input(uip_buf, uip_len);
uip_clear_buf(); uip_clear_buf();
} }