Skip to content

Commit

Permalink
Merge branch 'master' into Arduino_1.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Feb 11, 2014
2 parents 1cec7c6 + 9fbcf47 commit 3e11bbb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
6 changes: 3 additions & 3 deletions UIPEthernet/src/UIPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,13 @@ UIPClient::_eatBlock(memhandle* block)
memhandle* start = block;
Serial.print(F("eatblock("));
Serial.print(*block);
Serial.print("): ");
Serial.print(F("): "));
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
{
Serial.print(start[i]);
Serial.print(" ");
Serial.print(F(" "));
}
Serial.print("-> ");
Serial.print(F("-> "));
#endif
memhandle* end = block+(UIP_SOCKET_NUMPACKETS-1);
UIPEthernet.network.freeBlock(*block);
Expand Down
5 changes: 4 additions & 1 deletion UIPEthernet/src/UIPEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "HardwareSerial.h"
#endif

#include "UIPUdp.h"

extern "C"
{
#include "utility/uip-conf.h"
Expand Down Expand Up @@ -234,7 +236,7 @@ UIPEthernetClass::tick()
// uip_len is set to a value > 0. */
if (uip_len > 0)
{
network_send();
UIPUDP::_send((uip_udp_userdata_t *)(uip_udp_conns[i].appstate));
}
}
#endif /* UIP_UDP */
Expand Down Expand Up @@ -281,6 +283,7 @@ void UIPEthernetClass::init(const uint8_t* mac) {
uip_seteth_addr(mac);

uip_init();
uip_arp_init();
}

void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {
Expand Down
43 changes: 24 additions & 19 deletions UIPEthernet/src/UIPUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ UIPUDP::endPacket()
uip_udp_periodic_conn(_uip_udp_conn);
if (uip_len > 0)
{
UIPEthernet.network_send();
_send(&appdata);
return 1;
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ uipudp_appcall(void) {

void
UIPUDP::uip_callback() {
if (appdata_t *data = (appdata_t *)(uip_udp_conn->appstate))
if (uip_udp_userdata_t *data = (uip_udp_userdata_t *)(uip_udp_conn->appstate))
{
if (uip_newdata())
{
Expand Down Expand Up @@ -396,29 +396,34 @@ UIPUDP::uip_callback() {
Serial.println(UIPEthernet.network.blockSize(data->packet_out));
#endif
UIPEthernet.uip_packet = data->packet_out;
data->packet_out = NOBLOCK;
UIPEthernet.uip_hdrlen = UIP_UDP_PHYH_LEN;
UIPEthernet.packetstate |= UIPETHERNET_SENDPACKET;
uip_udp_send(data->out_pos - (UIP_UDP_PHYH_LEN));
uip_process(UIP_UDP_SEND_CONN); //generate udp + ip headers
uip_arp_out(); //add arp
if (uip_len == UIP_ARPHDRSIZE)
{
UIPEthernet.packetstate &= ~UIPETHERNET_SENDPACKET;
}
}
}

void
UIPUDP::_send(uip_udp_userdata_t *data) {
uip_arp_out(); //add arp
if (uip_len == UIP_ARPHDRSIZE)
{
UIPEthernet.uip_packet = NOBLOCK;
UIPEthernet.packetstate &= ~UIPETHERNET_SENDPACKET;
#ifdef UIPETHERNET_DEBUG_UDP
Serial.println(F("udp, uip_poll results in ARP-packet"));
Serial.println(F("udp, uip_poll results in ARP-packet"));
#endif
}
else
//arp found ethaddr for ip (otherwise packet is replaced by arp-request)
{
data->send = false;
}
else
//arp found ethaddr for ip (otherwise packet is replaced by arp-request)
{
data->send = false;
data->packet_out = NOBLOCK;
UIPEthernet.packetstate |= UIPETHERNET_SENDPACKET;
#ifdef UIPETHERNET_DEBUG_UDP
Serial.print(F("udp, uip_packet to send: "));
Serial.println(UIPEthernet.uip_packet);
Serial.print(F("udp, uip_packet to send: "));
Serial.println(UIPEthernet.uip_packet);
#endif
}
}
}
UIPEthernet.network_send();
}
#endif
21 changes: 13 additions & 8 deletions UIPEthernet/src/UIPUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ extern "C" {
#define UIP_UDP_NUMPACKETS 5
#endif

typedef struct {
memaddress out_pos;
memhandle packets_in[UIP_UDP_NUMPACKETS];
memhandle packet_in;
memhandle packet_out;
boolean send;
} uip_udp_userdata_t;

class UIPUDP : public UDP
{

private:
struct uip_udp_conn *_uip_udp_conn;

struct appdata_t
{
memaddress out_pos;
memhandle packets_in[UIP_UDP_NUMPACKETS];
memhandle packet_in;
memhandle packet_out;
boolean send;
} appdata;
uip_udp_userdata_t appdata;

public:
UIPUDP(); // Constructor
Expand Down Expand Up @@ -121,6 +122,10 @@ class UIPUDP : public UDP
friend void uipudp_appcall(void);

static void uip_callback();

friend class UIPEthernetClass;
static void _send(uip_udp_userdata_t *data);

};

#endif

0 comments on commit 3e11bbb

Please sign in to comment.