-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathG0ORX_Ethernet.cpp
More file actions
55 lines (46 loc) · 1.29 KB
/
G0ORX_Ethernet.cpp
File metadata and controls
55 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
*/
#ifndef BEENHERE
#include "SDT.h"
#endif
#ifdef NETWORK
#define PORT 1024
static EthernetUDP Udp;
bool connected=false;
bool EthernetInit() {
Serial.println("Configuring Ethernet using DHCP");
if (Ethernet.begin(my_mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
return false;
}
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
Serial.print("Server listeneing on: ");
Serial.println(PORT);
Udp.begin(PORT);
return true;
}
extern char *processCATCommand(char *catCommand);
void EthernetEvent() {
char inputbuffer[256];
char *outputBuffer;
int bytesread=0;
int packetsize=Udp.parsePacket();
if(packetsize!=0) {
while(bytesread!=packetsize) {
bytesread+=Udp.read(&inputbuffer[bytesread], packetsize-bytesread);
}
outputBuffer=processCATCommand(inputbuffer);
if(outputBuffer[0]!='\0') {
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(outputBuffer,strlen(outputBuffer));
Udp.endPacket();
}
}
}
#endif