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