]> git.mxchange.org Git - flightgear.git/blob - src/ATC/transmission.cxx
The most important part is that it fixes possible
[flightgear.git] / src / ATC / transmission.cxx
1 // FGTransmission - a class to provide transmission control at larger airports.
2 //
3 // Written by Alexander Kappes, started March 2002.
4 // Based on ground.cxx by David Luff, started March 2002.
5 //
6 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
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 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include "transmission.hxx"
27
28 #include <simgear/misc/sg_path.hxx>
29
30
31 //Constructor
32 FGTransmission::FGTransmission(){
33 }
34
35 //Destructor
36 FGTransmission::~FGTransmission(){
37 }
38
39 void FGTransmission::Init() {
40 }
41
42 // ============================================================================
43 // extract parameters from transmission
44 // ============================================================================
45 TransPar FGTransmission::Parse() {
46   TransPar   tpar;
47   string     tokens[20];
48   int        msglen,toklen;
49   //char       dum;
50   int        i,j,k;
51   const char *capl = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
52
53   msglen = strlen( TransText.c_str() );
54
55   int tkn  = 0;
56   for ( i=0; i < msglen; ++i ) {
57     if ( TransText.c_str()[i] != ' ' ) {
58       if ( TransText.c_str()[i] != ',' ) tokens[tkn] += TransText.c_str()[i];
59     } else if ( !tokens[tkn].empty() ) {
60       if ( tkn <= 20 ) {
61         tkn += 1;
62       } else {
63         cout << "Too many tokens" << endl;
64       }
65     }
66   }
67
68   for ( i=0; i<20; ++i) {
69     
70     if ( tokens[i] == "request" ) {
71       tpar.request = true;
72     } else if ( tokens[i] == "approach"  ) { 
73       tpar.station = "approach";
74       tpar.airport = tokens[i-1];
75     } else if ( tokens[i] == "landing"  ) { 
76       tpar.intention = "landing";
77       for ( j=i+1; j<=i+2; ++j ) {
78         if ( !tokens[j].empty() ) {
79           toklen = strlen( tokens[j].c_str() );
80           bool aid = true;
81           for ( k=0; k<toklen; ++k )
82             if ( ! strpbrk( &tokens[j].c_str()[k], capl )) {
83               aid = false;
84               break;
85             }
86           if ( aid ) tpar.intid = tokens[j];
87         }
88       }
89     } else if ( tokens[i] == "Player"  ) { 
90       tpar.callsign = tokens[i];
91     }
92   }
93
94   //cout << tpar.airport << endl;
95   //cout << tpar.request << endl;
96   //cout << tpar.intention << endl;
97   //cout << tpar.intid << endl;
98
99   return tpar;
100 }