50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
#ifndef EthernetUDPWrapper_h
|
|
#define EthernetUDPWrapper_h
|
|
|
|
#ifndef Arduino_H
|
|
#include <Arduino.h>
|
|
#endif
|
|
|
|
#ifndef Ethernet_h
|
|
#include <Ethernet.h>
|
|
#endif
|
|
|
|
#ifndef EthernetUDP_h
|
|
#include <EthernetUDP.h>
|
|
#endif
|
|
|
|
class EthernetUDPWrapper {
|
|
private:
|
|
unsigned int _CS_pin;
|
|
|
|
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // MAC address for ethernet module. Arbitrarily kept the same as example code.
|
|
unsigned int _udp_port; // UDP port we will be using. Set DAQ GUI to match. Just don't change it to one that is being used by other services
|
|
IPAddress _ip; // IP address of the Actuator Box. Set the router to bind to this IP address. Also update DAQ GUI code to match. IP address can change to whatever is needed
|
|
|
|
EthernetUDP _UDP;
|
|
|
|
char _incoming_packet_buffer[UDP_TX_PACKET_MAX_SIZE];
|
|
int _incoming_packet_size = 0;
|
|
IPAddress _remote_ip_address; // IP address of the sender
|
|
unsigned int _remote_udp_port; // UDP port used by sender
|
|
|
|
|
|
char _outgoing_packet_buffer[UDP_TX_PACKET_MAX_SIZE];
|
|
int _outgoing_packet_size = 0;
|
|
|
|
public:
|
|
EthernetUDPWrapper(unsigned int pin, unsigned int port, IPAddress ip);
|
|
bool begin();
|
|
|
|
// Checks for a new message available and buffers it into _incoming_packet_buffer
|
|
bool is_message_available();
|
|
|
|
// Returns the pointer to the c_string with the message
|
|
char* get_incoming_packet();
|
|
// Returns the length of the buffered incoming packet
|
|
int get_incoming_packet_length();
|
|
|
|
// Sends a response to the last sender
|
|
void send_response(char* msg, int length);
|
|
};
|
|
#endif |