Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion NanodeUIP.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "NanodeUIP.h"

#include <avr/pgmspace.h>
#include <stdio.h>
#include <inttypes.h>

#include "uip.h"
Expand All @@ -8,12 +10,15 @@
#include "dhcpc.h"
#include "resolv.h"

void nanode_log(char *msg);

void nanode_log(char *msg) {
Serial.println(msg);
}

void nanode_log_P(PGM_P msg) {
printf_P(PSTR("%lu: %S\r\n"),millis(),msg);
}

void dhcpc_configured(const struct dhcpc_state *s) {
uip_sethostaddr(s->ipaddr);
uip_setnetmask(s->netmask);
Expand Down
3 changes: 3 additions & 0 deletions NanodeUIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#else
#include <WProgram.h> // Arduino 0022
#endif
#include <avr/pgmspace.h>

#include "uip.h"
#include "timer.h"

extern void resolv_conf(const uint16_t *dnsserver);
extern void nanode_log(char *msg);
extern void nanode_log_P(PGM_P msg);

#define DHCP_STATUS_OK 1
#define DHCP_STATUS_DOWN 0
Expand Down
37 changes: 37 additions & 0 deletions examples/uip_hello_world/printf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

/**
* @file printf.h
*
* Setup necessary to direct stdout to the Arduino Serial library, which
* enables 'printf'
*/

#ifndef __PRINTF_H__
#define __PRINTF_H__

#ifdef ARDUINO

int serial_putc( char c, FILE * )
{
Serial.write( c );

return c;
}

void printf_begin(void)
{
fdevopen( &serial_putc, 0 );
}

#else
#error This example is only for use on Arduino.
#endif // ARDUINO

#endif // __PRINTF_H__
8 changes: 5 additions & 3 deletions examples/uip_hello_world/uip_hello_world.pde
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <NanodeUNIO.h>
#include <NanodeUIP.h>
#include <psock.h>
#include "printf.h"

struct hello_world_state {
struct psock p;
Expand Down Expand Up @@ -85,17 +86,18 @@ void setup() {
NanodeUNIO unio(NANODE_MAC_DEVICE);

Serial.begin(38400);
Serial.println("UIP test");
printf_begin();
printf_P(PSTR(__FILE__"\r\n"));

unio.read(macaddr,NANODE_MAC_ADDRESS,6);
uip.init(macaddr);
uip.get_mac_str(buf);
Serial.println(buf);
uip.wait_for_link();
Serial.println("Link is up");
nanode_log_P(PSTR("Link is up"));
uip.init_resolv(resolv_found);
uip.start_dhcp(dhcp_status);
Serial.println("setup() done");
nanode_log_P(PSTR("setup() done"));
}

void loop() {
Expand Down
5 changes: 5 additions & 0 deletions platform.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <avr/pgmspace.h>
#include "clock.h"
#include "uip-conf.h"

Expand All @@ -14,7 +15,11 @@ clock_time_t clock_time(void) {
void nullproc(void) {}

extern void nanode_log(char *msg);
extern void nanode_log_P(PGM_P msg);

void uip_log(char *msg) {
nanode_log(msg);
}
void uip_log_P(PGM_P msg) {
nanode_log_P(msg);
}
5 changes: 3 additions & 2 deletions uip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,10 @@ struct uip_stats uip_stat;
#endif /* UIP_STATISTICS == 1 */

#if UIP_LOGGING == 1
#include <avr/pgmspace.h>
#include <stdio.h>
void uip_log(char *msg);
#define UIP_LOG(m) uip_log(m)
void uip_log_P(PGM_P msg);
#define UIP_LOG(m) uip_log_P(PSTR(m))
#else
#define UIP_LOG(m)
#endif /* UIP_LOGGING == 1 */
Expand Down
2 changes: 2 additions & 0 deletions uipopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define UIP_BIG_ENDIAN 1234
#endif /* UIP_BIG_ENDIAN */

#include <avr/pgmspace.h>
#include "uip-conf.h"

/*------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -432,6 +433,7 @@
* is called by uIP whenever a log message is generated.
*/
void uip_log(char *msg);
void uip_log_P(PGM_P msg);

/**
* The link level header length.
Expand Down