Subversion Repositories Projects

Rev

Rev 391 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
306 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2008 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#include <QStringList>
21
 
22
#include "cKML_Server.h"
23
 
24
cKML_Server::cKML_Server()
25
{
26
    NaviCount = 0;
27
}
28
 
29
void cKML_Server::start_Server(int Port, cSettings *Set)
30
{
31
    Settings = Set;
32
 
33
    TcpServer = new QTcpServer();
34
    if (!TcpServer->listen(QHostAddress::Any, qint16(Port)))
35
    {
36
        qDebug("Kann Serversocket nicht Einrichten..!!");
37
    }
38
    else
39
    {
40
        connect(TcpServer, SIGNAL(newConnection()), this, SLOT(slot_NewConnection()));
41
    }
42
}
43
 
44
void cKML_Server::stop_Server()
45
{
46
    delete TcpServer;
47
}
48
 
49
void cKML_Server::store_NaviString(sNaviString Navi)
50
{
51
    Route[NaviCount] = Navi;
52
    NaviCount++;
53
}
54
 
55
void cKML_Server::slot_ReadData()
56
{
57
    if (TcpSocket->canReadLine())
58
    {
59
        QStringList tokens = QString(TcpSocket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
60
 
61
        qDebug() << "QStringList ---------";
62
        for (QList<QString>::iterator i = tokens.begin(); i != tokens.end(); ++i)
63
            qDebug() << (*i);
64
    }
65
 
66
    TcpSocket->close();
67
}
68
 
69
void cKML_Server::slot_NewConnection()
70
{
71
    TcpSocket = TcpServer->nextPendingConnection();
72
    connect(TcpSocket, SIGNAL(readyRead ()),this, SLOT(slot_ReadData()));
73
 
74
    QByteArray block;
75
 
76
    block = "HTTP/1.0 200 OK\nContent-Type: application/vnd.google-earth.kml+xml; charset=iso-8859-1\nConnection: close\n\n";
77
//    block = "HTTP/1.0 200 OK\nContent-Type: text/xml; charset=utf-8\nConnection: close\n\n";
78
 
79
    TcpSocket->write(block);
80
 
81
    TcpSocket->write(get_KML());
82
 
83
    TcpSocket->close();
84
}
85
 
86
QByteArray cKML_Server::get_KML()
87
{
88
    QByteArray block;
89
 
90
    block = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
91
            "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n"
92
            "  <Document>\n"
93
            "    <name>Online Mikrokopter GPS Position</name>\n"
94
            "    <Style id=\"MK_gps-style\">\n"
95
            "      <LineStyle>\n"
96
            "        <color>ff0000ff</color>\n"
97
            "        <width>2</width>\n"
98
            "      </LineStyle>\n"
99
            "    </Style>\n"
100
            "    <Placemark>\n"
101
            "      <LookAt>\n"
102
            "        <range>400</range>\n"
103
            "        <tilt>45</tilt>\n"
104
            "      </LookAt>\n"
105
            "      <name>Flight</name>\n"
106
            "      <styleUrl>#MK_gps-style</styleUrl>\n"
107
            "      <LineString>\n";
108
    if (Settings->Server.ToGround)
109
    {
110
        block = block + "        <extrude>1</extrude>\n";
111
    }
112
 
113
    block = block +
114
            "        <tessellate>1</tessellate>\n"
115
            "        <altitudeMode>relativeToGround</altitudeMode>\n"
116
            "        <coordinates>\n";
117
 
118
    for (int a = 0; a < NaviCount; a++)
119
    {
394 Brean 120
        block = block + QString::number(Route[a].Longitude).toAscii() + "," +
121
                        QString::number(Route[a].Latitude).toAscii() + "," +
122
                        QString::number(Route[a].Altitude).toAscii();
306 KeyOz 123
        block = block + "\n";
124
    }
125
 
126
    block = block +
127
            "        </coordinates>\n"
128
            "      </LineString>\n"
129
            "    </Placemark>\n"
130
            "  </Document>\n"
131
            "  </kml>\n";
132
 
133
        return block;
134
}
135
 
136
cKML_Server::~cKML_Server()
137
{
138
}