5. ArdSimX
4. ArdSim
3. ARDref
2. XPData library
1. Plain I/O code for Baron 58
First Tests with UDP
One of the first successful test to receive UDP packets from X-Plane. X-Plane UDP Data Structure analysis.(May 2012)
It receives UDP packets from X-Plane and show it in the terminal in the raw view.
/*
X-Plane UDP Data Structure
Test sketch that receives UDP packets from X-Plane in the raw view.
and prints to Serial terminal data of the group #131 ("ground location")
Check this group in the Data Input & Output Screen of the X-Plane for sending.
Packet size: 41
Xplane Data:
68-65-84-65-60-131-0-0-0-166-138-16-71-193-114-2-195-58-143-139-70-244-238-135-59-61-207-225-58-
0-192-121-196-0-192-121-196-0-192-121-196-
May 2012
Vlad S
http://simvim.com
*/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 6); // local IP - address of my Arduino
unsigned int localPort = 49001; // local port to listen - default X-Plane port
byte buf = 00; // buffer for UDP packet (BYTE, not char)
EthernetUDP Udp; // An EthernetUDP instance to send and receive packets over UDP
//-------------------------------------------------------------------------------
void setup()
{
Ethernet.begin(mac,ip); // start the Ethernet
Udp.begin(localPort); //..and UDP:
Serial.begin(9600); // init serial port
}
void loop() {
int packetSize = Udp.parsePacket(); // Checks for the presence of a UDP packet, and returns its size
if(packetSize) // UDP packet was received and its size defined
{
Serial.println();
Serial.print("Packet size: ");
Serial.println(packetSize); // Packet Size in bytes
// When Udp.read used without parameters, it returns next char (byte in this case) :
Serial.println("Xplane Data:");
for (int i =0; i < packetSize; i++)
{
buf = Udp.read();
Serial.print(buf);
Serial.print("-");
}
}
delay(10);
}