FlightGear next
fg_dds_log.cpp
Go to the documentation of this file.
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4
5#include <map>
6
7#include <simgear/io/SGDataDistributionService.hxx>
8
9#include "dds_fwd.hxx"
10
11/* An array of one message(aka sample in dds terms) will be used. */
12#define MAX_SAMPLES 1
13
14#ifndef _WIN32
15# include <termios.h>
16
17void set_mode(int want_key)
18{
19 static struct termios tios_old, tios_new;
20 if (!want_key) {
21 tcsetattr(STDIN_FILENO, TCSANOW, &tios_old);
22 return;
23 }
24
25 tcgetattr(STDIN_FILENO, &tios_old);
26 tios_new = tios_old;
27 tios_new.c_lflag &= ~(ICANON | ECHO);
28 tcsetattr(STDIN_FILENO, TCSANOW, &tios_new);
29}
30
32{
33 int c = 0;
34 struct timeval tv;
35 fd_set fs;
36 tv.tv_usec = tv.tv_sec = 0;
37
38 FD_ZERO(&fs);
39 FD_SET(STDIN_FILENO, &fs);
40 select(STDIN_FILENO + 1, &fs, 0, 0, &tv);
41
42 if (FD_ISSET(STDIN_FILENO, &fs)) {
43 c = getchar();
44 }
45 return c;
46}
47#else
48# include <conio.h>
49
50int get_key()
51{
52 if (kbhit()) {
53 return getch();
54 }
55 return 0;
56}
57
58void set_mode(int want_key)
59{
60}
61#endif
62
63int main()
64{
65 std::map<std::string, SG_DDS_Topic*> topics;
66 SG_DDS participant;
67
68 FG_DDS_GUI gui;
69 topics["gui"] = new SG_DDS_Topic(gui, &FG_DDS_GUI_desc);
70 participant.add(topics["gui"], SG_IO_IN);
71
72 FG_DDS_FDM fdm;
73 topics["fdm"] = new SG_DDS_Topic(fdm, &FG_DDS_FDM_desc);
74 participant.add(topics["fdm"], SG_IO_IN);
75
76 FG_DDS_Ctrls ctrls;
77 topics["ctrls"] = new SG_DDS_Topic(ctrls, &FG_DDS_Ctrls_desc);
78 participant.add(topics["ctrls"], SG_IO_IN);
79
80 FG_DDS_prop prop;
81 topics["prop"] = new SG_DDS_Topic(prop, &FG_DDS_prop_desc);
82 participant.add(topics["prop"], SG_IO_IN);
83
84 set_mode(1);
85 while(participant.wait(0.1f))
86 {
87 if (topics["gui"]->read()) {
88 printf("=== [fg_dds_log] Received : ");
89 printf("GUI Message:\n");
90 printf(" version: %i\n", gui.version);
91 printf(" tuned_freq: %lf\n", gui.longitude);
92 printf(" nav_radial: %lf\n", gui.latitude);
93 printf(" dist_nm: %lf\n", gui.altitude);
94 }
95
96 if (topics["fdm"]->read()) {
97 printf("=== [fg_dds_log] Received : ");
98 printf("FDM Message:\n");
99 printf(" version: %i\n", fdm.version);
100 printf(" longitude: %lf\n", fdm.longitude);
101 printf(" latitude: %lf\n", fdm.latitude);
102 printf(" altitude: %lf\n", fdm.altitude);
103 }
104
105 if (topics["ctrls"]->read()) {
106 printf("=== [fg_dds_log] Received : ");
107 printf("Ctrls Message:\n");
108 printf(" version: %i\n", ctrls.version);
109 printf(" aileron: %lf\n", ctrls.aileron);
110 printf(" elevator: %lf\n", ctrls.elevator);
111 printf(" rudder: %lf\n", ctrls.rudder);
112 }
113
114 if (topics["prop"]->read() &&
116 {
117 printf("=== [fg_dds_log] Received : ");
118 printf("Prop Message:\n");
119 printf(" version: %i\n", prop.version);
120 printf(" mode: %s\n", prop.mode ? "write" : "read");
121 printf(" id: %i\n", prop.id);
122 if (prop.id == FG_DDS_PROP_REQUEST) {
123 printf(" path: %s\n", prop.val._u.String);
124 printf("GUID: ");
125 for(int i=0; i<16; ++i)
126 printf("%X ", prop.guid[i]);
127 printf("\n");
128 }
129 else
130 {
131 switch(prop.val._d)
132 {
133 case FG_DDS_BOOL:
134 printf(" type: bool");
135 printf(" value: %i\n", prop.val._u.Bool);
136 break;
137 case FG_DDS_INT:
138 printf(" type: int");
139 printf(" value: %i\n", prop.val._u.Int32);
140 break;
141 case FG_DDS_LONG:
142 printf(" type: long");
143 printf(" value: %li\n", prop.val._u.Int64);
144 break;
145 case FG_DDS_FLOAT:
146 printf(" type: float");
147 printf(" value: %f\n", prop.val._u.Float32);
148 break;
149 case FG_DDS_DOUBLE:
150 printf(" type: double");
151 printf(" value: %lf\n", prop.val._u.Float64);
152 break;
153 case FG_DDS_STRING:
154 printf(" type: string");
155 printf(" value: %s\n", prop.val._u.String);
156 break;
157 default:
158 break;
159 }
160 }
161 }
162
163 fflush(stdout);
164
165 if (get_key()) break;
166 }
167 set_mode(0);
168
169 return EXIT_SUCCESS;
170}
#define i(x)
const dds_topic_descriptor_t FG_DDS_Ctrls_desc
Definition dds_ctrls.c:77
const dds_topic_descriptor_t FG_DDS_FDM_desc
Definition dds_fdm.c:85
const dds_topic_descriptor_t FG_DDS_GUI_desc
Definition dds_gui.c:44
const dds_topic_descriptor_t FG_DDS_prop_desc
Definition dds_props.c:36
#define FG_DDS_PROP_VERSION
Definition dds_props.h:20
#define FG_DDS_PROP_REQUEST
Definition dds_props.h:21
@ FG_DDS_LONG
Definition dds_props.h:30
@ FG_DDS_FLOAT
Definition dds_props.h:31
@ FG_DDS_INT
Definition dds_props.h:29
@ FG_DDS_BOOL
Definition dds_props.h:28
@ FG_DDS_DOUBLE
Definition dds_props.h:32
@ FG_DDS_STRING
Definition dds_props.h:33
int get_key()
void set_mode(int want_key)
int main()
float elevator
Definition dds_ctrls.h:31
float aileron
Definition dds_ctrls.h:30
int16_t version
Definition dds_ctrls.h:29
float rudder
Definition dds_ctrls.h:32
double longitude
Definition dds_fdm.h:30
int16_t version
Definition dds_fdm.h:29
double altitude
Definition dds_fdm.h:32
double latitude
Definition dds_fdm.h:31
float altitude
Definition dds_gui.h:30
double latitude
Definition dds_gui.h:29
double longitude
Definition dds_gui.h:28
int16_t version
Definition dds_gui.h:27
FG_propValue val
Definition dds_props.h:64
uint8_t version
Definition dds_props.h:62
uint8_t guid[16]
Definition dds_props.h:65
int32_t id
Definition dds_props.h:61
int32_t Int32
Definition dds_props.h:47
float Float32
Definition dds_props.h:49
char * String
Definition dds_props.h:51
int64_t Int64
Definition dds_props.h:48
FG_propType _d
Definition dds_props.h:43
union FG_propValue::@155153037146116023270074041102065253170142315045 _u
double Float64
Definition dds_props.h:50