| 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 | |
| 17 | void 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 | |
| 31 | int get_key() |
| 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 | |
| 50 | int get_key() |
| 51 | { |
| 52 | if (kbhit()) { |
| 53 | return getch(); |
| 54 | } |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | void set_mode(int want_key) |
| 59 | { |
| 60 | } |
| 61 | #endif |
| 62 | |
| 63 | int 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() && |
| 115 | prop.version == FG_DDS_PROP_VERSION ) |
| 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 | } |