1 // pve.cxx -- "PVE" protocal class (for Provision Entertainment)
3 // Written by Curtis Olson, started November 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <Debug/logstream.hxx>
25 #include <FDM/flight.hxx>
26 #include <Math/fg_geodesy.hxx>
27 #include <Time/fg_time.hxx>
29 #include "iochannel.hxx"
41 // "PVE" (ProVision Entertainment) output format (for some sort of
44 // Outputs a 5-byte data packet defined as follows:
46 // First bite: ASCII character "P" ( 0x50 or 80 decimal )
47 // Second byte: "roll" value (1-255) 1 being 0* and 255 being 359*
48 // Third byte: "pitch" value (1-255) 1 being 0* and 255 being 359*
49 // Fourth byte: "heave" value (or vertical acceleration?)
51 bool FGPVE::gen_message() {
52 // cout << "generating pve message" << endl;
53 FGInterface *f = cur_fdm_state;
55 // get roll and pitch, convert to degrees
56 double roll_deg = f->get_Phi() * RAD_TO_DEG;
57 while ( roll_deg <= -180.0 ) {
60 while ( roll_deg > 180.0 ) {
64 double pitch_deg = f->get_Theta() * RAD_TO_DEG;
65 while ( pitch_deg <= -180.0 ) {
68 while ( pitch_deg > 180.0 ) {
72 short int heave = (int)(f->get_W_body() * 128.0);
74 // scale roll and pitch to output format (1 - 255)
75 // straight && level == (128, 128)
77 short int roll = (int)(roll_deg * 32768 / 180.0);
78 short int pitch = (int)(pitch_deg * 32768 / 180.0);
80 unsigned char roll_b1, roll_b2, pitch_b1, pitch_b2, heave_b1, heave_b2;
82 roll_b2 = roll & 0x00ff;
83 pitch_b1 = pitch >> 8;
84 pitch_b2 = pitch & 0x00ff;
85 heave_b1 = heave >> 8;
86 heave_b2 = heave & 0x00ff;
88 sprintf( buf, "p%c%c%c%c%c%c\n",
89 roll_b1, roll_b2, pitch_b1, pitch_b2, heave_b1, heave_b2 );
92 // printf( "p [ %u %u ] [ %u %u ] [ %u %u ]\n",
93 // roll_b1, roll_b2, pitch_b1, pitch_b2, heave_b1, heave_b2 );
95 FG_LOG( FG_IO, FG_INFO, "roll=" << roll << " pitch=" << pitch <<
103 bool FGPVE::parse_message() {
104 FG_LOG( FG_IO, FG_ALERT, "PVE input not supported" );
110 // process work for this port
111 bool FGPVE::process() {
112 FGIOChannel *io = get_io_channel();
114 if ( get_direction() == out ) {
116 if ( ! io->write( buf, length ) ) {
117 FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
120 } else if ( get_direction() == in ) {
121 FG_LOG( FG_IO, FG_ALERT, "in direction not supported for RUL." );