Skip to content

Commit 811656d

Browse files
committed
planeDB
1 parent 86499f0 commit 811656d

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

Application/Receiver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class Receiver {
160160
// Receiver output are Messages or JSON
161161
Connection<AIS::Message>& Output(int i) { return models[i]->Output().out; }
162162
Connection<AIS::GPS>& OutputGPS(int i) { return models[i]->OutputGPS().out; }
163+
Connection<Plane::ADSB>& OutputADSB(int i) { return models[i]->OutputADSB().out; }
164+
163165
Connection<JSON::JSON>& OutputJSON(int i) { return jsonais[i].out; }
164166

165167
void setSampleRate(int s) { sample_rate = s; }

Application/WebViewer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ void WebViewer::connect(Receiver &r)
312312

313313
r.OutputJSON(j).Connect((StreamIn<JSON::JSON> *)&ships);
314314
r.OutputGPS(j).Connect((StreamIn<AIS::GPS> *)&ships);
315+
r.OutputADSB(j).Connect((StreamIn<Plane::ADSB> *)&planes);
315316

316317
*r.device >> raw_counter;
317318
}
@@ -579,6 +580,11 @@ void WebViewer::Request(TCP::ServerConnection &c, const std::string &response, b
579580
{
580581
std::string content = ships.getJSONcompact();
581582
Response(c, "application/json", content, use_zlib & gzip);
583+
}
584+
else if (r == "/api/planes_array.json")
585+
{
586+
std::string content = planes.getCompactArray();
587+
Response(c, "application/json", content, use_zlib & gzip);
582588
}
583589
else if (r == "/sb")
584590
{

Application/WebViewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "Prometheus.h"
3131
#include "HTTPServer.h"
3232
#include "DB.h"
33+
#include "PlaneDB.h"
3334
#include "History.h"
3435
#include "Receiver.h"
3536
#include "MapTiles.h"
@@ -117,6 +118,7 @@ class WebViewer : public IO::HTTPServer, public Setting
117118
std::string about = "This content can be set by the station owner";
118119

119120
DB ships;
121+
PlaneDB planes;
120122

121123
// history of 180 minutes and 180 seconds
122124
History<60, 60> hist_minute;

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ set(CPP
795795
set(HEADER
796796
Application/AIS-catcher.h Application/Prometheus.h Application/Config.h Application/WebDB.h Library/Logger.h Application/WebViewer.h Application/Receiver.h Tracking/Ships.h Tracking/DB.h DBMS/PostgreSQL.h IO/HTTPClient.h Application/MapTiles.h
797797
Device/Device.h Device/FileWAV.h Device/RTLTCP.h Device/UDP.h DSP/Demod.h DSP/Filters.h Library/AIS.h Library/Message.h Library/NMEA.h Library/ZIP.h Library/Signals.h Device/SoapySDR.h Library/JSONAIS.h JSON/JSON.h Library/Basestation.h Library/ADSB.h
798-
Device/AIRSPY.h Library/FIFO.h Device/N2KsktCAN.h Device/HACKRF.h Device/SDRPLAY.h DSP/DSP.h DSP/Model.h Tracking/History.h Tracking/Statistics.h Library/Common.h Library/Stream.h Device/SpyServer.h Library/Keys.h JSON/StringBuilder.h JSON/Parser.h
798+
Device/AIRSPY.h Library/FIFO.h Device/N2KsktCAN.h Device/HACKRF.h Device/SDRPLAY.h DSP/DSP.h DSP/Model.h Tracking/History.h Tracking/Statistics.h Library/Common.h Library/Stream.h Device/SpyServer.h Library/Keys.h JSON/StringBuilder.h JSON/Parser.h Tracking/PlaneDB.h
799799
Device/Serial.h IO/N2KInterface.h Library/N2K.h IO/N2KStream.h Device/AIRSPYHF.h Device/FileRAW.h Device/RTLSDR.h Device/ZMQ.h DSP/FFT.h IO/MsgOut.h IO/Network.h IO/HTTPServer.h Library/Utilities.h Library/TCP.h Protocol/Protocol.h)
800800

801801
set(APP_INCLUDES . ./Tracking ./DBMS ./Library ./DSP ./Application ./IO ./Protocol)

Library/ADSB.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ namespace Plane
4040
ALL_CALL_REPLY = 8 // All Call Reply
4141
};
4242

43-
class ADSB
43+
struct ADSB
4444
{
45-
protected:
45+
int prev, next;
4646
std::time_t rxtime;
4747
MessageType type;
4848
TransmissionType transmission;
@@ -52,14 +52,13 @@ namespace Plane
5252
FLOAT32 groundspeed; // Speed over ground
5353
FLOAT32 track; // Track angle
5454
int vertrate; // Vertical rate
55-
char callsign[8]; // Aircraft callsign
55+
char callsign[9]; // Aircraft callsign, nul terminated
5656
int squawk; // Mode A squawk code
5757
BoolType alert; // Squawk change flag
5858
BoolType emergency; // Emergency flag
5959
BoolType spi; // Ident flag
6060
BoolType onground; // Ground squat switch flag
6161

62-
public:
6362
void Stamp(std::time_t t = (std::time_t)0L)
6463
{
6564
std::time(&rxtime);
@@ -83,7 +82,7 @@ namespace Plane
8382
vertrate = VERTRATE_UNDEFINED;
8483
squawk = SQUAWK_UNDEFINED;
8584
alert = emergency = spi = onground = BoolType::UNKNOWN;
86-
std::memset(callsign, '@', 8);
85+
callsign[8] = '\0';
8786
}
8887

8988
// Getters
@@ -97,7 +96,7 @@ namespace Plane
9796
FLOAT32 getGroundSpeed() const { return groundspeed; }
9897
FLOAT32 getTrack() const { return track; }
9998
int getVertRate() const { return vertrate; }
100-
std::string getCallsign() const { return std::string(callsign, 8); }
99+
std::string getCallsign() const { return std::string(callsign); }
101100
int getSquawk() const { return squawk; }
102101
BoolType getAlert() const { return alert; }
103102
BoolType getEmergency() const { return emergency; }
@@ -120,9 +119,17 @@ namespace Plane
120119
void setVertRate(int vr) { vertrate = vr; }
121120
void setCallsign(const std::string &c)
122121
{
123-
std::memset(callsign, '@', 8);
124-
std::strncpy(callsign, c.c_str(), MIN(c.length(), sizeof(callsign)));
122+
for(int i = 0; i < 8; i++)
123+
{
124+
if (i < c.size() && c[i] != '\0' && c[i] != '@')
125+
callsign[i] = c[i];
126+
else {
127+
callsign[i] = '\0';
128+
break;
129+
}
130+
}
125131
}
132+
126133
void setSquawk(int s) { squawk = s; }
127134
void setAlert(BoolType a) { alert = (BoolType)a; }
128135
void setEmergency(BoolType e) { emergency = (BoolType)e; }

Library/Basestation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Basestation : public SimpleStreamInOut<RAW, Plane::ADSB>
146146
msg.setOnGround((Plane::BoolType)(fields[21] == "-1"));
147147
}
148148

149-
msg.Print();
149+
//msg.Print();
150150
Send(&msg, 1, tag);
151151
}
152152

0 commit comments

Comments
 (0)