]> git.mxchange.org Git - flightgear.git/blob - src/ATC/voice.cxx
don't set the callsign, but use the set one
[flightgear.git] / src / ATC / voice.cxx
1
2 #include <simgear/compiler.h>
3
4 #include <stdio.h>
5 #include <malloc.h>
6 #include <sys/types.h>
7 #include <signal.h>
8 #include <netinet/in.h>
9 #include <fcntl.h>
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
12 #include <arpa/inet.h>
13 #include <unistd.h>
14 #include <setjmp.h>
15 #include <string.h>
16 #include <strings.h>
17
18 #include STL_IOSTREAM
19 SG_USING_STD(cout);
20 SG_USING_STD(endl);
21
22 #define ATC_SERVER_ADDRESS "192.168.2.15" // adddress of machine running festival server
23
24 #include "voice.hxx"
25
26 int                     atc_sockfd = 0;
27 int                     result, servlen;
28 struct sockaddr_in      atc_serv_addr, atc_cli_add;
29
30 //FGVoice *p_voice;
31
32 bool FGVoice::send_transcript( string trans, string refname, short repeat )
33 {
34         string msg;
35
36         switch ( repeat ) {
37                 case 0: msg = "S " + refname + ">" + trans;
38                         break;
39                 case 1: msg = "R " + refname + ">" + trans;
40                         break;
41                 case 2: msg = "X " + refname;
42                         break;
43                 }
44         // strip out some characters    
45         for(unsigned int i = 0; i < msg.length(); ++i) {
46                 if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
47                         msg[i] = ' ';
48                 }
49         }
50                 
51         int len = msg.length(); 
52         if (sendto(atc_sockfd, (char *) msg.c_str(), len, 0, (struct sockaddr *) &atc_serv_addr, servlen ) != len) {
53                         cout << "network write failed for " << len << " chars" << endl;
54                         return false;
55                 }
56         printf("Transmit: %s of %d chars\n", msg.c_str(), len );
57         return true;
58 }
59
60 FGVoice::FGVoice()
61 {
62         string mesg = "Welcome to the FlightGear voice synthesizer";
63         string welcome = "welcome ";
64 // Init the network stuff here
65         printf( "FGVoice created. Connecting to atc sim\n");
66   servlen = sizeof( atc_serv_addr );    
67   bzero((char *) &atc_serv_addr, servlen);
68   atc_serv_addr.sin_family = AF_INET;
69   atc_serv_addr.sin_addr.s_addr = inet_addr(ATC_SERVER_ADDRESS);
70   atc_serv_addr.sin_port = htons(7100);
71
72   if ((atc_sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
73                 {
74                 printf("Failed to obtain a socket\n");
75 //              return( 0 );
76                 }
77                 else send_transcript( mesg, welcome, 0 );
78 }
79
80 FGVoice::~FGVoice()
81 {
82         close( atc_sockfd );
83 }