Move the C version of fgfdm_log.c to examples/dds/ and convert it to C++ as fg_dds_log.cpp using the SimGear provided hepper classes.
This commit is contained in:
parent
3276c9a754
commit
1467a8a170
4 changed files with 160 additions and 16 deletions
18
examples/dds/README
Normal file
18
examples/dds/README
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
Data Distribution Service (DDS) logger
|
||||||
|
|
||||||
|
This example uses a waitset to listens to the FlightGear GUI, FDM adn Ctrls
|
||||||
|
DDS topics and logs some data for any of them when new data arrives.
|
||||||
|
|
||||||
|
Run FlightGear with any combination of the following command line arguments to
|
||||||
|
get it to produce new DDS samples:
|
||||||
|
|
||||||
|
fgfs
|
||||||
|
--native-gui=dds,out,30
|
||||||
|
--native-fdm=dds,out,60
|
||||||
|
--native-ctrls=dds,out,10
|
||||||
|
|
||||||
|
|
||||||
|
The executable has to be linkes against the CycloneDDS ddsc component and
|
||||||
|
all *.c files in src/Network/DDS:
|
||||||
|
|
||||||
|
gcc -I ../../src fgfdm_log.c ../../src/Network/DDS/*.c -l ddsc -o fgfdm_log
|
|
@ -1,11 +1,14 @@
|
||||||
#include "dds/dds.h"
|
|
||||||
#include "dds_gui.h"
|
|
||||||
#include "dds_fdm.h"
|
|
||||||
#include "dds_ctrls.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <dds/dds.h>
|
||||||
|
|
||||||
|
#include <Network/DDS/dds_gui.h>
|
||||||
|
#include <Network/DDS/dds_fdm.h>
|
||||||
|
#include <Network/DDS/dds_ctrls.h>
|
||||||
|
|
||||||
|
|
||||||
/* An array of one message(aka sample in dds terms) will be used. */
|
/* An array of one message(aka sample in dds terms) will be used. */
|
||||||
#define MAX_SAMPLES 1
|
#define MAX_SAMPLES 1
|
||||||
|
|
||||||
|
@ -119,7 +122,7 @@ int main()
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
DDS_FATAL("ds_waitset_attach: %s\n", dds_strretcode(-status));
|
DDS_FATAL("ds_waitset_attach: %s\n", dds_strretcode(-status));
|
||||||
|
|
||||||
/* Create an Ctrls Topic. */
|
/* Create a Ctrls Topic. */
|
||||||
ctrls_topic = dds_create_topic(
|
ctrls_topic = dds_create_topic(
|
||||||
participant, &FG_DDS_Ctrls_desc, "FG_DDS_Ctrls", NULL, NULL);
|
participant, &FG_DDS_Ctrls_desc, "FG_DDS_Ctrls", NULL, NULL);
|
||||||
if(ctrls_topic < 0)
|
if(ctrls_topic < 0)
|
||||||
|
@ -160,7 +163,7 @@ int main()
|
||||||
printf("GUI Message:\n");
|
printf("GUI Message:\n");
|
||||||
printf(" version: %i\n", gui->version);
|
printf(" version: %i\n", gui->version);
|
||||||
printf(" tuned_freq: %lf\n", gui->longitude);
|
printf(" tuned_freq: %lf\n", gui->longitude);
|
||||||
printf(" nav_radial %lf\n", gui->latitude);
|
printf(" nav_radial: %lf\n", gui->latitude);
|
||||||
printf(" dist_nm: %lf\n", gui->altitude);
|
printf(" dist_nm: %lf\n", gui->altitude);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ set(HEADERS
|
||||||
dds_gui.h
|
dds_gui.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(fgfdm_log
|
add_executable(fg_dds_log
|
||||||
WIN32
|
WIN32
|
||||||
MACOSX_BUNDLE
|
MACOSX_BUNDLE
|
||||||
fgfdm_log.c
|
fg_dds_log.cpp
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
)
|
)
|
||||||
target_link_libraries(fgfdm_log CycloneDDS::ddsc)
|
setup_fgfs_libraries(fg_dds_log)
|
||||||
|
|
||||||
flightgear_component(Network "${SOURCES}" "${HEADERS}")
|
flightgear_component(Network "${SOURCES}" "${HEADERS}")
|
||||||
|
|
123
src/Network/DDS/fg_dds_log.cpp
Normal file
123
src/Network/DDS/fg_dds_log.cpp
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <simgear/io/SGDataDistributionService.hxx>
|
||||||
|
|
||||||
|
#include "dds_gui.h"
|
||||||
|
#include "dds_fdm.h"
|
||||||
|
#include "dds_ctrls.h"
|
||||||
|
|
||||||
|
/* An array of one message(aka sample in dds terms) will be used. */
|
||||||
|
#define MAX_SAMPLES 1
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
# include <termios.h>
|
||||||
|
|
||||||
|
void set_mode(int want_key)
|
||||||
|
{
|
||||||
|
static struct termios tios_old, tios_new;
|
||||||
|
if (!want_key) {
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &tios_old);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tcgetattr(STDIN_FILENO, &tios_old);
|
||||||
|
tios_new = tios_old;
|
||||||
|
tios_new.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &tios_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_key()
|
||||||
|
{
|
||||||
|
int c = 0;
|
||||||
|
struct timeval tv;
|
||||||
|
fd_set fs;
|
||||||
|
tv.tv_usec = tv.tv_sec = 0;
|
||||||
|
|
||||||
|
FD_ZERO(&fs);
|
||||||
|
FD_SET(STDIN_FILENO, &fs);
|
||||||
|
select(STDIN_FILENO + 1, &fs, 0, 0, &tv);
|
||||||
|
|
||||||
|
if (FD_ISSET(STDIN_FILENO, &fs)) {
|
||||||
|
c = getchar();
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# include <conio.h>
|
||||||
|
|
||||||
|
int get_key()
|
||||||
|
{
|
||||||
|
if (kbhit()) {
|
||||||
|
return getch();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_mode(int want_key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
SG_DDS participant;
|
||||||
|
std::map<std::string, SG_DDS_Topic *> topics;
|
||||||
|
|
||||||
|
topics["gui"] = new SG_DDS_Topic();
|
||||||
|
topics["fdm"] = new SG_DDS_Topic();
|
||||||
|
topics["ctrls"] = new SG_DDS_Topic();
|
||||||
|
|
||||||
|
topics["gui"]->setup("FG_DDS_GUI", &FG_DDS_GUI_desc, sizeof(FG_DDS_GUI));
|
||||||
|
topics["fdm"]->setup("FG_DDS_FDM", &FG_DDS_FDM_desc, sizeof(FG_DDS_FDM));
|
||||||
|
topics["ctrls"]->setup("FG_DDS_Ctrls", &FG_DDS_Ctrls_desc, sizeof(FG_DDS_Ctrls));
|
||||||
|
|
||||||
|
participant.add(topics["gui"], SG_IO_IN);
|
||||||
|
participant.add(topics["fdm"], SG_IO_IN);
|
||||||
|
participant.add(topics["ctrls"], SG_IO_IN);
|
||||||
|
|
||||||
|
set_mode(1);
|
||||||
|
while(participant.wait(0.1f))
|
||||||
|
{
|
||||||
|
FG_DDS_Ctrls ctrls;
|
||||||
|
FG_DDS_FDM fdm;
|
||||||
|
FG_DDS_GUI gui;
|
||||||
|
|
||||||
|
if (topics["gui"]->read((char*)&gui, sizeof(gui)) == sizeof(gui)) {
|
||||||
|
printf("=== [fgfdm_log] Received : ");
|
||||||
|
printf("GUI Message:\n");
|
||||||
|
printf(" version: %i\n", gui.version);
|
||||||
|
printf(" tuned_freq: %lf\n", gui.longitude);
|
||||||
|
printf(" nav_radial: %lf\n", gui.latitude);
|
||||||
|
printf(" dist_nm: %lf\n", gui.altitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topics["fdm"]->read((char*)&fdm, sizeof(fdm)) == sizeof(fdm)) {
|
||||||
|
printf("=== [fgfdm_log] Received : ");
|
||||||
|
printf("FDM Message:\n");
|
||||||
|
printf(" version: %i\n", fdm.version);
|
||||||
|
printf(" longitude: %lf\n", fdm.longitude);
|
||||||
|
printf(" latitude: %lf\n", fdm.latitude);
|
||||||
|
printf(" altitude: %lf\n", fdm.altitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topics["ctrls"]->read((char*)&ctrls, sizeof(ctrls)) == sizeof(ctrls)) {
|
||||||
|
printf("=== [fgfdm_log] Received : ");
|
||||||
|
printf("Ctrls Message:\n");
|
||||||
|
printf(" version: %i\n", ctrls.version);
|
||||||
|
printf(" aileron: %lf\n", ctrls.aileron);
|
||||||
|
printf(" elevator: %lf\n", ctrls.elevator);
|
||||||
|
printf(" rudder: %lf\n", ctrls.rudder);
|
||||||
|
}
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
if (get_key()) break;
|
||||||
|
}
|
||||||
|
set_mode(0);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in a new issue