Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multicast udp, added callback for interrupt data arrival #7

Closed
wants to merge 2 commits into from
Closed
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
49 changes: 46 additions & 3 deletions src/EthernetUdp.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
*
* bjoern@cs.stanford.edu 12/30/2008
*/

#include "STM32Ethernet.h"
#include "Udp.h"
#include "Dns.h"


#include "lwip/igmp.h"
#include "lwip/ip_addr.h"
#include "Arduino.h"

/* Constructor */
EthernetUDP::EthernetUDP() {}

Expand Down Expand Up @@ -250,6 +254,45 @@ void EthernetUDP::flush()
/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::beginMulticast(IPAddress ip, uint16_t port)
{
UNUSED(ip);
return begin(port);
if(_udp.pcb != NULL) {
return 0;
}

ip_addr_t ipaddr;
ip_addr_t ipgroup;

u8_to_ip_addr(rawIPAddress(ip), &ipgroup);

_udp.pcb = udp_new();

if(_udp.pcb == NULL) {
return 0;
}



if(ERR_OK != udp_bind(_udp.pcb, IP_ADDR_ANY, port)) {
stop();
return 0;
}

err_t iret = igmp_joingroup(IP_ADDR_ANY,&ipgroup);
if(iret == ERR_OK){
udp_recv(_udp.pcb, &udp_receive_callback, &_udp);

_port = port;
_remaining = 0;

stm32_eth_scheduler();

return 1;
}else{
return 0;
}


}

void EthernetUDP::onDataArrival( std::function<void()> onDataArrival_fn){
_udp.onDataArrival = onDataArrival_fn;
}
6 changes: 4 additions & 2 deletions src/EthernetUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
#define ethernetudp_h

#include <Udp.h>
#include <functional>

extern "C" {
// extern "C" {
#include "utility/stm32_eth.h"
}
// }

#define UDP_TX_PACKET_MAX_SIZE 24

Expand Down Expand Up @@ -102,6 +103,7 @@ class EthernetUDP : public UDP {
virtual IPAddress remoteIP() { return _remoteIP; };
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() { return _remotePort; };
virtual void onDataArrival( std::function<void()> onDataArrival_fn);
};

#endif
Loading