Software development guidelines - alesskerbinek/FlightSimPanel GitHub Wiki
General overview:
- Software is developed in C++.
- Arduino IDE is used for compiling/linking.
- Majority of projects was written in QtCreator as development environment.
Common features
- All projects are using semantic versioning.
- All projects are developed using the same coding styles and conventions listed in section Coding below.
- Projects share common abstract classes.
- Projects share common principles for configuration and network interfacing.
- Production time configuration (Serial number, device type...) is configured using configuration protocol via programming/debug port.
- User configuration (WiFi access point parameters...) is configured using configuration protocol via programming/debug port.
- User friendlier PC software for user configuration might be developed.
- User configuration might be as well implemented by unit creating it's own access point and HTTP server serving configuration website.
Coding
When developing the software we keep in mind following conventions and coding styles:
- Code has to be divided into classes,
- each class should be in separate file,
- classes should be short and simple to increase readability. The goal is to keep it below 300 lines per file, it's fine it's below 400 and 500 is max.
- all parts of code has to be executed in at least one program flow path - no unreachable/dead code,
- use UpperCamelCase for object names,
- member variables (private, protected, private etc.) must have prefix m_ (see examples below)
- all variables has to have additional prefix (if member, just after m_) indicating variable's type:
prefix | data type |
---|---|
b | boolean (bool) |
i | all signed integers (int, int8_t, int32_t...) |
ui | all unsigned integers (uint, uint8_t, uint32_t...) |
c | char |
a | array |
p | pointer |
e | enums |
s | structures |
...and similar for less common types
Examples:
uint32_t m_uiLoopCnt; // member unsigned int
bool m_bIsSimConnected; // member boolean
std::queue<xplane::UdpDatagram> m_qTX; // member queue
std::array<char, MAX_NMEA_SIZE + 20> m_acReceive; // member array of chars
const char* pText; // local pointer
char acBuffer[6]; // local array of chars
X-Plane protocols
DATA
X-Plane output:
| DATA< | Index | 8_x_4B_of_data | Next_index | Next_8_x_4B_of_data |
Exp.: DATA< 61 00 00 00 xx xx xx xx xx xx xx xx 62 00 00 00 xx xx xx xx xx xx xx xx ...
For sending data to X-Plane we use the same format except the DATA< is replaced with DATA0.
Values are 4 byte encoded floats.
00 00 00 00 = 0 - also bool false 00 00 80 3F = 1 - also bool true 00 C0 79 C4 = -999 - empty parameter, do not change
DREF
All message has to 5+4+500 bytes long. For example if Dtaref_string is 50 characters long, you add 450 spaces (char 0x20) to the end. The 509 character has to be NULL.
| DREF0 | Value | Dataref_string | Ending_fields |
Exp.: DREF0 00 A0 2A 46 /sim/cockpit2/radios/actuators/com1_standby_freuency_hz[0]
Check: https://www.siminnovations.com/xplane/dataref/index.php
DREF0+(4byte byte value)+dref_path+0+spaces to complete the whole message to 509 bytes DREF\00\00\00\80\3Fsim/cockpit/electrical/night_visi on_on\00
char buffer[509]; memset(buffer, 0x00, 509); memcpy(buffer, "DREF", 4); u.value = 10810; memcpy(&buffer[5], u.bytes, 4); memcpy(&buffer[9], "sim/cockpit/radios/nav1_freq_hz\0", 33); int sent = sendto(xpSocket, &buffer[0], 509, 0, (SOCKADDR*)&dest, sizeof(dest));
IMPORTANT: https://github.com/dotsha747/libXPlane-UDP-Client/blob/master/src/libsrc/XPlaneUDPClient.cpp
CHAR
Sending keyboard commands to X-Plane.
| CHAR0 | Character |
Exp.: CHAR0 xx
CMND
Sedn command to X-Plane
| CMND0 | Command_string |
Exp.: CMND0 /sim/flight_controls/landing_gear_down
Check: https://www.siminnovations.com/xplane/command/index.php
Additional resources
- https://realsimcontrol.com/archive/code_archive.html
- https://questions.x-plane.com/20760/where-can-i-get-x-plane-11-complete-udp-protocol
- https://github.com/nasa/XPlaneConnect/wiki/Network-Information
- https://www.youtube.com/watch?v=vatcDu-r04s
- https://www.nuclearprojects.com/xplane/senddata.shtml
- https://developer.x-plane.com/article/pluginsandobjects/ - CMND
- https://developer.x-plane.com/2009/04/datarefs-vs-commands-iii-what-is-my-command-doing/
- https://www.siminnovations.com/xplane/dataref/index.php
- https://www.siminnovations.com/xplane/command/index.php
- https://simvim.com/index.html
- https://realsimcontrol.com/index.html
Check out the instructions folder of your X-Plane install. In "X-Plane SPECS from Austin" the doc "Exchanging Data with X-Plane.rtfd" talks more about exchanging data via UDP.