Skip to content

Commit 1c9d5d7

Browse files
committed
refactoring
1 parent cbcf8f0 commit 1c9d5d7

File tree

14 files changed

+282
-594
lines changed

14 files changed

+282
-594
lines changed

Application/Receiver.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ void OutputScreen::connect(Receiver &r)
423423
if (r.OutputGPS(j).canConnect(((StreamIn<AIS::GPS>)msg2screen).getGroupsIn()))
424424
r.OutputGPS(j).Connect((StreamIn<AIS::GPS> *)&msg2screen);
425425

426-
if (r.OutputADSB(j).canConnect(((StreamIn<JSON::JSON>)msg2screen).getGroupsIn()))
427-
r.OutputADSB(j).Connect((StreamIn<JSON::JSON> *)&msg2screen);
426+
if (r.OutputADSB(j).canConnect(((StreamIn<Plane::ADSB>)msg2screen).getGroupsIn()))
427+
r.OutputADSB(j).Connect((StreamIn<Plane::ADSB> *)&msg2screen);
428428
}
429429

430430
msg2screen.setDetail(level);
@@ -438,9 +438,6 @@ void OutputScreen::connect(Receiver &r)
438438

439439
if (r.OutputGPS(j).canConnect(((StreamIn<AIS::GPS>)json2screen).getGroupsIn()))
440440
r.OutputGPS(j).Connect((StreamIn<AIS::GPS> *)&json2screen);
441-
442-
if (r.OutputADSB(j).canConnect(((StreamIn<JSON::JSON>)json2screen).getGroupsIn()))
443-
r.OutputADSB(j).Connect((StreamIn<JSON::JSON> *)&json2screen);
444441
}
445442

446443
if (level == MessageFormat::JSON_SPARSE)

Application/Receiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ 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<JSON::JSON>& OutputADSB(int i) { return models[i]->OutputADSB().out; }
163+
Connection<Plane::ADSB>& OutputADSB(int i) { return models[i]->OutputADSB().out; }
164164

165165
Connection<JSON::JSON>& OutputJSON(int i) { return jsonais[i].out; }
166166

Application/WebViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void WebViewer::connect(Receiver &r)
313313

314314
r.OutputJSON(j).Connect((StreamIn<JSON::JSON> *)&ships);
315315
r.OutputGPS(j).Connect((StreamIn<AIS::GPS> *)&ships);
316-
r.OutputADSB(j).Connect((StreamIn<JSON::JSON> *)&planes);
316+
//r.OutputADSB(j).Connect((StreamIn<JSON::JSON> *)&planes);
317317

318318
*r.device >> raw_counter;
319319
}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ set(CPP
789789
Device/FileRAW.cpp Device/HACKRF.cpp Device/UDP.cpp Device/RTLTCP.cpp Device/ZMQ.cpp Device/SoapySDR.cpp Device/SpyServer.cpp Library/Message.cpp Library/NMEA.cpp
790790
Library/Utilities.cpp Library/TCP.cpp JSON/JSON.cpp IO/Network.cpp IO/HTTPServer.cpp JSON/StringBuilder.cpp JSON/Parser.cpp Library/Logger.cpp
791791
Device/AIRSPY.cpp Device/Serial.cpp IO/HTTPClient.cpp Application/WebDB.cpp
792-
DSP/DSP.cpp Device/N2KsktCAN.cpp Library/Basestation.cpp Library/Beast.cpp
792+
DSP/DSP.cpp Device/N2KsktCAN.cpp Library/Basestation.cpp Library/Beast.cpp Library/ADSB.cpp
793793
IO/MsgOut.cpp IO/N2KStream.cpp Library/N2K.cpp IO/N2KInterface.cpp Protocol/Protocol.cpp)
794794

795795
set(HEADER

DSP/Model.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ namespace AIS
7373

7474
// idea is to avoid that message threads from different devices cause issues downstream (e.g. with sending UDP or updating the database).
7575
// can also be done further downstream
76-
class MessageMutexADSB : public SimpleStreamInOut<JSON::JSON, JSON::JSON>
76+
class MessageMutexADSB : public SimpleStreamInOut<Plane::ADSB, Plane::ADSB>
7777
{
7878
static std::mutex mtx;
7979

8080
public:
8181
virtual ~MessageMutexADSB() {}
82-
virtual void Receive(const JSON::JSON *data, int len, TAG &tag)
82+
virtual void Receive(const Plane::ADSB *data, int len, TAG &tag)
8383
{
8484
std::lock_guard<std::mutex> lock(mtx);
8585
Send(data, len, tag);
8686
}
87-
virtual void Receive(JSON::JSON *data, int len, TAG &tag)
87+
virtual void Receive(Plane::ADSB *data, int len, TAG &tag)
8888
{
8989
std::lock_guard<std::mutex> lock(mtx);
9090
Send(data, len, tag);
@@ -114,7 +114,7 @@ namespace AIS
114114

115115
StreamOut<Message> &Output() { return output; }
116116
StreamOut<GPS> &OutputGPS() { return output_gps; }
117-
StreamOut<JSON::JSON> &OutputADSB() { return outputADSB; }
117+
StreamOut<Plane::ADSB> &OutputADSB() { return outputADSB; }
118118

119119
void setName(std::string s) { name = s; }
120120
std::string getName() { return name; }

IO/MsgOut.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,11 @@ namespace IO
101101
}
102102
}
103103

104-
void MessageToScreen::Receive(const JSON::JSON *data, int len, TAG &tag)
104+
void MessageToScreen::Receive(const Plane::ADSB *data, int len, TAG &tag)
105105
{
106106
for (int i = 0; i < len; i++)
107107
{
108-
if (filter.include(*(AIS::Message *)data[i].binary))
109-
{
110-
for (const auto &p : data[i].getProperties())
111-
if (p.Key() == AIS::KEY_RAW_MESSAGE)
112-
{
113-
if(level == MessageFormat::JSON_NMEA)
114-
std::cout << "{\"raw_message\":\"" << p.Get().getString() << "\"}" << std::endl;
115-
else
116-
std::cout << "*" << p.Get().getString() << ";" << std::endl;
117-
}
118-
}
108+
data[i].Print();
119109
}
120110
}
121111

IO/MsgOut.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "Stream.h"
2525
#include "AIS.h"
2626
#include "Utilities.h"
27-
27+
#include "ADSB.h"
2828
#include "Keys.h"
2929
#include "JSON/JSON.h"
3030
#include "JSON/StringBuilder.h"
@@ -230,7 +230,7 @@ namespace IO
230230
virtual ~StringToScreen() {}
231231
};
232232

233-
class MessageToScreen : public StreamIn<AIS::Message>, public StreamIn<AIS::GPS>, public StreamIn<JSON::JSON>, public Setting
233+
class MessageToScreen : public StreamIn<AIS::Message>, public StreamIn<AIS::GPS>, public StreamIn<Plane::ADSB>, public Setting
234234
{
235235
private:
236236
MessageFormat level;
@@ -242,7 +242,7 @@ namespace IO
242242

243243
void Receive(const AIS::Message *data, int len, TAG &tag);
244244
void Receive(const AIS::GPS *data, int len, TAG &tag);
245-
void Receive(const JSON::JSON *data, int len, TAG &tag);
245+
void Receive(const Plane::ADSB *data, int len, TAG &tag);
246246

247247

248248
Setting &Set(std::string option, std::string arg)

Library/ADSB.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Copyright(c) 2021-2025 jvde.github@gmail.com
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
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, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include "ADSB.h"
19+
20+
namespace Plane
21+
{
22+
23+
void ADSB::Callsign()
24+
{
25+
static const char *cs_table = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ##### ###############0123456789######";
26+
char temp[9] = {0};
27+
int len = 0;
28+
29+
for (int i = 0; i < 8; i++)
30+
{
31+
uint32_t c = getBits( 40 + (i * 6), 6);
32+
if (cs_table[c] != '#')
33+
{
34+
temp[len++] = cs_table[c];
35+
}
36+
}
37+
38+
if (len > 0)
39+
{
40+
std::strncpy(callsign, temp, sizeof(callsign) - 1);
41+
callsign[sizeof(callsign) - 1] = '\0';
42+
}
43+
}
44+
45+
void ADSB::Decode()
46+
{
47+
if(msgtype == '1') return;
48+
49+
df = getBits(0, 5);
50+
51+
switch (df)
52+
{
53+
case 0: // Short Air-Air Surveillance
54+
case 4: // Surveillance, Altitude Reply
55+
case 20: // Comm-B, Altitude Reply
56+
{
57+
//unsigned ac = getBits( 19, 13);
58+
//if (ac)
59+
// altitude = decodeESAlt(ac);
60+
}
61+
break;
62+
63+
case 11: // All-Call Reply
64+
hexident = getBits(8, 24);
65+
break;
66+
67+
case 17: // Extended Squitter
68+
case 18: // Extended Squitter/Supplementary
69+
{
70+
hexident = getBits( 8, 24);
71+
msgtype = getBits( 32, 5);
72+
73+
switch (msgtype)
74+
{
75+
case 1:
76+
case 2:
77+
case 3:
78+
case 4: // Aircraft Identification
79+
Callsign();
80+
break;
81+
82+
case 19: // Airborne Velocity
83+
//decodeVelocity();
84+
break;
85+
86+
case 5:
87+
case 6:
88+
case 7:
89+
case 8: // Surface Position
90+
case 9:
91+
case 10:
92+
case 11:
93+
case 12: // Airborne Position
94+
case 13:
95+
case 14:
96+
case 15:
97+
case 16:
98+
case 17:
99+
case 18:
100+
if (msgtype >= 9)
101+
{
102+
//unsigned ac = getBits( 37, 12);
103+
//if (ac)
104+
// altitude = decodeESAlt(ac);
105+
}
106+
//Position( getBits(msgData, 54, 1));
107+
break;
108+
}
109+
}
110+
break;
111+
}
112+
113+
}
114+
}

0 commit comments

Comments
 (0)