]> git.mxchange.org Git - flightgear.git/blob - src/Network/rul.cxx
Added PVE (ProVision Entertainment) and RUL (some guy's motion platform)
[flightgear.git] / src / Network / rul.cxx
1 // rul.cxx -- "RUL" protocal class (for some sort of motion platform
2 //            some guy was building)
3 //
4 // Written by Curtis Olson, started November 1999.
5 //
6 // Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #include <Debug/logstream.hxx>
26 #include <FDM/flight.hxx>
27 #include <Math/fg_geodesy.hxx>
28 #include <Time/fg_time.hxx>
29
30 #include "iochannel.hxx"
31 #include "rul.hxx"
32
33
34 FGRUL::FGRUL() {
35 }
36
37
38 FGRUL::~FGRUL() {
39 }
40
41
42 // generate Garmin message
43 bool FGRUL::gen_message() {
44     // cout << "generating rul message" << endl;
45     FGInterface *f = cur_fdm_state;
46
47     // get roll and pitch, convert to degrees
48     double roll_deg = f->get_Phi() * RAD_TO_DEG;
49     while ( roll_deg < -180.0 ) {
50         roll_deg += 360.0;
51     }
52     while ( roll_deg > 180.0 ) {
53         roll_deg -= 360.0;
54     }
55
56     double pitch_deg = f->get_Theta() * RAD_TO_DEG;
57     while ( pitch_deg < -180.0 ) {
58         pitch_deg += 360.0;
59     }
60     while ( pitch_deg > 180.0 ) {
61         pitch_deg -= 360.0;
62     }
63
64     // scale roll and pitch to output format (1 - 255)
65     // straight && level == (128, 128)
66
67     int roll = (int)( (roll_deg+180.0) * 255.0 / 360.0) + 1;
68     int pitch = (int)( (pitch_deg+180.0) * 255.0 / 360.0) + 1;
69
70     sprintf( buf, "p%c%c\n", roll, pitch);
71     length = 4;
72
73     FG_LOG( FG_IO, FG_INFO, "p " << roll << " " << pitch );
74
75     return true;
76 }
77
78
79 // parse RUL message
80 bool FGRUL::parse_message() {
81     FG_LOG( FG_IO, FG_ALERT, "RUL input not supported" );
82
83     return false;
84 }
85
86
87 // process work for this port
88 bool FGRUL::process() {
89     FGIOChannel *io = get_io_channel();
90
91     if ( get_direction() == out ) {
92         gen_message();
93         if ( ! io->write( buf, length ) ) {
94             FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
95             return false;
96         }
97     } else if ( get_direction() == in ) {
98         FG_LOG( FG_IO, FG_ALERT, "in direction not supported for RUL." );
99         return false;
100     }
101
102     return true;
103 }