SET-Control-System/Code/ethernet_comms_with_wrapper/ethernet_comms_with_wrapper.ino
2024-09-29 21:34:30 -05:00

54 lines
1.4 KiB
C++

#include <Ethernet.h>
#include <EthernetUDP.h>
#include "EthernetUDPWrapper.h"
#define ETHERNET_CS_PIN 25 // CS pin on PCB to the ethernet module
unsigned int port = 5000;
IPAddress ip(192, 168, 0, 115); // 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
EthernetUDPWrapper UDPWrapper(ETHERNET_CS_PIN, port, ip);
void setup() {
Serial.begin(9600);
Serial.println("Beginning ethernet_comms_with_wrapper");
if (UDPWrapper.begin() == false) {
Serial.println("Failed to start UDPWrapper");
}
}
void loop() {
if (UDPWrapper.is_message_available()) {
Serial.print("Received UDP Packet: ");
char* incoming_msg = UDPWrapper.get_incoming_packet();
//int msg_length = UDPWrapper.get_incoming_packet_length();
Serial.print(incoming_msg);
Serial.println();
if (strcmp("servo_angle", incoming_msg) == 0) {
Serial.println("UDP Packet Requested Servo Angle");
int angle = random(0, 91);
char outgoing_msg[2];
itoa(angle, outgoing_msg, 10);
UDPWrapper.send_response(outgoing_msg, 2);
Serial.print("Sent: ");
Serial.print(outgoing_msg);
Serial.println(" over UDP");
Serial.println();
}
}
}