The xplane_io (X-Plane I/O) program is used to establish network communications, via UDP, with the X-Plane flight simulator running on a computer. The code consists of class libraries that abstract the lower-level UDP packet encoding and decoding details, according to the UDP protocol specifications in X-Plane version 9. Any X-Plane DATA packets can be sent and received, and any X-Plane DataRefs can be set by sending DREF packets to X-Plane.

Dependencies:   EthernetNetIf mbed ConfigFile

Committer:
bapowell
Date:
Wed Dec 21 22:29:59 2011 +0000
Revision:
0:a5d13af495af

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bapowell 0:a5d13af495af 1 #include "XPlaneUdpDATA.h"
bapowell 0:a5d13af495af 2
bapowell 0:a5d13af495af 3
bapowell 0:a5d13af495af 4 XPlaneUdpDATA::XPlaneUdpDATA(int messageIndex, bool reverseByteOrder) {
bapowell 0:a5d13af495af 5
bapowell 0:a5d13af495af 6 _messageIndex = messageIndex;
bapowell 0:a5d13af495af 7 _reverseByteOrder = reverseByteOrder;
bapowell 0:a5d13af495af 8 for (int i = 0; i < 8; i++) {
bapowell 0:a5d13af495af 9 _data[i] = -999.0f;
bapowell 0:a5d13af495af 10 }
bapowell 0:a5d13af495af 11
bapowell 0:a5d13af495af 12 _dataChanged = false;
bapowell 0:a5d13af495af 13 }
bapowell 0:a5d13af495af 14
bapowell 0:a5d13af495af 15 int XPlaneUdpDATA::messageIndex() const {
bapowell 0:a5d13af495af 16 return _messageIndex;
bapowell 0:a5d13af495af 17 }
bapowell 0:a5d13af495af 18
bapowell 0:a5d13af495af 19 float XPlaneUdpDATA::getData(int i) const {
bapowell 0:a5d13af495af 20 return _data[i];
bapowell 0:a5d13af495af 21 }
bapowell 0:a5d13af495af 22
bapowell 0:a5d13af495af 23 void XPlaneUdpDATA::setData(int i, float f) {
bapowell 0:a5d13af495af 24 _data[i] = f;
bapowell 0:a5d13af495af 25 setDataChanged();
bapowell 0:a5d13af495af 26 }
bapowell 0:a5d13af495af 27
bapowell 0:a5d13af495af 28 float& XPlaneUdpDATA::operator [] (int i) {
bapowell 0:a5d13af495af 29 return _data[i];
bapowell 0:a5d13af495af 30 }
bapowell 0:a5d13af495af 31
bapowell 0:a5d13af495af 32 void XPlaneUdpDATA::setAllData(char * DATAMessage) {
bapowell 0:a5d13af495af 33 memcpy(_data, DATAMessage + 4, 32);
bapowell 0:a5d13af495af 34 if (_reverseByteOrder) {
bapowell 0:a5d13af495af 35 for (int d = 0; d < 8; d++) {
bapowell 0:a5d13af495af 36 reverse4Bytes((char*) &(_data[d]));
bapowell 0:a5d13af495af 37 }
bapowell 0:a5d13af495af 38 }
bapowell 0:a5d13af495af 39 }
bapowell 0:a5d13af495af 40
bapowell 0:a5d13af495af 41 void XPlaneUdpDATA::populateDATAMessage(char * bytes) {
bapowell 0:a5d13af495af 42 memcpy(bytes, &_messageIndex, 4);
bapowell 0:a5d13af495af 43 if (_reverseByteOrder) {
bapowell 0:a5d13af495af 44 reverse4Bytes((char*) bytes);
bapowell 0:a5d13af495af 45 }
bapowell 0:a5d13af495af 46 memcpy(bytes + 4, _data, 32);
bapowell 0:a5d13af495af 47 if (_reverseByteOrder) {
bapowell 0:a5d13af495af 48 for (int d = 1; d < 9; d++) {
bapowell 0:a5d13af495af 49 reverse4Bytes((char*) bytes + (d * 4));
bapowell 0:a5d13af495af 50 }
bapowell 0:a5d13af495af 51 }
bapowell 0:a5d13af495af 52 }
bapowell 0:a5d13af495af 53
bapowell 0:a5d13af495af 54 bool XPlaneUdpDATA::isDataChanged() const {
bapowell 0:a5d13af495af 55 return _dataChanged;
bapowell 0:a5d13af495af 56 }
bapowell 0:a5d13af495af 57
bapowell 0:a5d13af495af 58 void XPlaneUdpDATA::setDataChanged() {
bapowell 0:a5d13af495af 59 _dataChanged = true;
bapowell 0:a5d13af495af 60 }
bapowell 0:a5d13af495af 61
bapowell 0:a5d13af495af 62 void XPlaneUdpDATA::resetDataChanged() {
bapowell 0:a5d13af495af 63 _dataChanged = false;
bapowell 0:a5d13af495af 64 }
bapowell 0:a5d13af495af 65
bapowell 0:a5d13af495af 66 void XPlaneUdpDATA::toString(FILE * outputStream) {
bapowell 0:a5d13af495af 67 fprintf(outputStream, "idx=%d, 0:%f 1:%f 2:%f 3:%f 4:%f 5:%f 6:%f 7:%f, revBytes=%d",
bapowell 0:a5d13af495af 68 _messageIndex,
bapowell 0:a5d13af495af 69 _data[0], _data[1], _data[2], _data[3], _data[4], _data[5], _data[6], _data[7],
bapowell 0:a5d13af495af 70 _reverseByteOrder);
bapowell 0:a5d13af495af 71 }