Skip to content

Commit

Permalink
fix sharing key
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Jan 9, 2025
1 parent c177624 commit efbecc8
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 20 deletions.
14 changes: 7 additions & 7 deletions Application/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ void Config::setSharing(const std::vector<JSON::Property> &props)

bool xchange = false;
std::string uuid;
extern IO::OutputMessage *commm_feed;

for (const JSON::Property &p : props)
{
Expand All @@ -341,17 +342,16 @@ void Config::setSharing(const std::vector<JSON::Property> &props)
uuid = p.Get().to_string();
}

if (xchange && !communityFeed)
if (xchange && !commm_feed)
{
communityFeed = true;
_msg.push_back(std::unique_ptr<IO::OutputMessage>(new IO::TCPClientStreamer()));
IO::OutputMessage &p = *_msg.back();
commm_feed = _msg.back().get();

p.Set("HOST", "aiscatcher.org").Set("PORT", "4242").Set("JSON", "on").Set("FILTER", "on").Set("GPS", "off");

if (!uuid.empty())
p.Set("UUID", uuid);
commm_feed->Set("HOST", "aiscatcher.org").Set("PORT", "4242").Set("JSON", "on").Set("FILTER", "on").Set("GPS", "off");
}
if (!uuid.empty())
commm_feed->Set("UUID", uuid);

}

void Config::set(const std::string &str)
Expand Down
6 changes: 2 additions & 4 deletions Application/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int main(int argc, char *argv[])
int cb = -1;

Config c(_receivers, nrec, msg, json, screen, servers, own_mmsi);
IO::OutputMessage *commm_feed = nullptr;
extern IO::OutputMessage *commm_feed;

try
{
Expand Down Expand Up @@ -619,13 +619,11 @@ int main(int argc, char *argv[])
case 'X':
Assert(count <= 1, param, "Only one optional parameter [sharing key] allowed.");
{
if (!communityFeed)
if (!commm_feed)
{
msg.push_back(std::unique_ptr<IO::OutputMessage>(new IO::TCPClientStreamer()));
commm_feed = msg.back().get();
commm_feed->Set("HOST", "185.77.96.227").Set("PORT", "4242").Set("JSON", "on").Set("FILTER", "on").Set("GPS", "off");

communityFeed = true;
}

if (count == 1 && commm_feed)
Expand Down
7 changes: 4 additions & 3 deletions Application/WebViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include "WebViewer.h"
#include "Application/WebDB.h"

bool communityFeed = false;
IO::OutputMessage *commm_feed = nullptr;


void SSEStreamer::Receive(const JSON::JSON *data, int len, TAG &tag)
{
Expand Down Expand Up @@ -524,7 +525,7 @@ void WebViewer::Request(TCP::ServerConnection &c, const std::string &response, b
content += "\"last_hour\":" + hist_hour.lastStatToJSON() + ",";
content += "\"last_minute\":" + hist_minute.lastStatToJSON() + ",";
content += "\"tcp_clients\":" + std::to_string(numberOfClients()) + ",";
content += "\"sharing\":" + std::string(communityFeed ? "true" : "false") + ",";
content += "\"sharing\":" + std::string(commm_feed ? "true" : "false") + ",";
if (ships.getShareLatLon() && ships.getLat() != LAT_UNDEFINED && ships.getLon() != LON_UNDEFINED)
content += "\"sharing_link\":\"https://aiscatcher.org/?&zoom=10&lat=" + std::to_string(ships.getLat()) + "&lon=" + std::to_string(ships.getLon()) + "\",";
else
Expand Down Expand Up @@ -616,7 +617,7 @@ void WebViewer::Request(TCP::ServerConnection &c, const std::string &response, b
}
else if (r == "/custom/plugins.js")
{
Response(c, "application/javascript", params + plugins + plugin_code + "}\nserver_version = false;\naboutMDpresent = " + (aboutPresent ? "true" : "false") + ";\ncommunityFeed = " + (communityFeed ? "true" : "false") + ";\n", use_zlib & gzip);
Response(c, "application/javascript", params + plugins + plugin_code + "}\nserver_version = false;\naboutMDpresent = " + (aboutPresent ? "true" : "false") + ";\ncommunityFeed = " + (commm_feed ? "true" : "false") + ";\n", use_zlib & gzip);
}
else if (r == "/custom/config.css")
{
Expand Down
1 change: 0 additions & 1 deletion Application/WebViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "Receiver.h"
#include "MapTiles.h"

extern bool communityFeed;

class SSEStreamer : public StreamIn<JSON::JSON>
{
Expand Down
130 changes: 125 additions & 5 deletions Library/Beast.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Beast : public SimpleStreamInOut<RAW, Plane::ADSB>

std::cerr << "-----" << std::endl;

// Print message info
// Base message info - keep existing code
std::cerr << "Raw message: ";
for (const auto &b : buffer)
{
Expand All @@ -72,12 +72,59 @@ class Beast : public SimpleStreamInOut<RAW, Plane::ADSB>
std::cerr << "Signal level: " << signalLevel << std::endl;
std::cerr << "DF meaning: " << getDFMeaning(df) << std::endl;

// Print ICAO if available
if (icao)
{
std::cerr << "ICAO: " << std::hex << std::setw(6) << std::setfill('0') << icao << std::dec << std::endl;
}

// Enhanced decoding
if (df == 17 || df == 18)
{
uint8_t tc = getBits(buffer, 32, 5);
std::cerr << "Type Code: " << static_cast<int>(tc) << std::endl;

// Aircraft Identification (Callsign)
if (tc >= 1 && tc <= 4)
{
std::cerr << "Message Type: Aircraft Identification" << std::endl;
std::string callsign = decodeCallsign();
std::cerr << "Callsign: " << callsign << std::endl;
}
// Position messages
else if (tc >= 9 && tc <= 18)
{
std::cerr << "Message Type: Airborne Position" << std::endl;
//bool onGround = false;
if (tc >= 9 && tc <= 18)
{
std::cerr << "On Ground: No" << std::endl;
}
else if (tc >= 5 && tc <= 8)
{
std::cerr << "On Ground: Yes" << std::endl;
//onGround = true;
}
}
// Airborne velocity
else if (tc == 19)
{
std::cerr << "Message Type: Airborne Velocity" << std::endl;
decodeVelocity();
}
}

// Flight Status (existing code)
if (df == 4 || df == 5 || df == 20 || df == 21)
{
uint8_t fs = getBits(buffer, 5, 3);
std::string fs_meaning;
switch (fs)
{
// ... keep existing flight status code ...
}
std::cerr << "Flight Status: " << static_cast<int>(fs) << " (" << fs_meaning << ")" << std::endl;
}

// Flight Status for DF 4,5,20,21
if (df == 4 || df == 5 || df == 20 || df == 21)
{
Expand Down Expand Up @@ -192,6 +239,77 @@ class Beast : public SimpleStreamInOut<RAW, Plane::ADSB>
<< generateEchoCommand(full_message) << std::endl;
}

std::string decodeCallsign()
{
static const char *callsignChars =
"?ABCDEFGHIJKLMNOPQRSTUVWXYZ????? ???????????????0123456789??????";

std::string callsign;
for (int i = 0; i < 8; i++)
{
uint32_t char_code = getBits(buffer, 40 + (i * 6), 6);
if (char_code > 0 && char_code < 64)
{
char c = callsignChars[char_code];
if (c != '?' && c != ' ')
{
callsign += c;
}
}
}
return callsign;
}

void decodeVelocity()
{
// Get subtype (1-4)
uint8_t subtype = getBits(buffer, 37, 3);

if (subtype == 1 || subtype == 2)
{ // Ground speed
// East-West velocity
bool east_west_sign = getBits(buffer, 45, 1);
int east_west_vel = getBits(buffer, 46, 10) - 1;
if (east_west_sign)
east_west_vel *= -1;

// North-South velocity
bool north_south_sign = getBits(buffer, 56, 1);
int north_south_vel = getBits(buffer, 57, 10) - 1;
if (north_south_sign)
north_south_vel *= -1;

// Vertical rate
bool vert_rate_sign = getBits(buffer, 68, 1);
int vert_rate = (getBits(buffer, 69, 9) - 1) * 64;
if (vert_rate_sign)
vert_rate *= -1;

// Calculate ground speed and heading
double speed = sqrt(east_west_vel * east_west_vel +
north_south_vel * north_south_vel);
double heading = atan2(east_west_vel, north_south_vel) * 180 / M_PI;
if (heading < 0)
heading += 360;

std::cerr << "Ground Speed: " << speed << " knots" << std::endl;
std::cerr << "Heading: " << heading << " degrees" << std::endl;
std::cerr << "Vertical Rate: " << vert_rate << " ft/min" << std::endl;
}
else if (subtype == 3 || subtype == 4)
{ // Airspeed
bool airspeed_type = getBits(buffer, 56, 1); // 0 = IAS, 1 = TAS
int airspeed = getBits(buffer, 57, 10);

std::cerr << (airspeed_type ? "True" : "Indicated")
<< " Airspeed: " << airspeed << " knots" << std::endl;

// Heading
int heading = getBits(buffer, 46, 10) * 360.0 / 1024.0;
std::cerr << "Heading: " << heading << " degrees" << std::endl;
}
}

// Helper function to get bits as string
std::string getBitsString(const std::vector<uint8_t> &data, int startBit, int length)
{
Expand Down Expand Up @@ -332,11 +450,13 @@ class Beast : public SimpleStreamInOut<RAW, Plane::ADSB>
{
std::stringstream ss;
ss << "echo -en \"";
for (const auto &byte : data)
// Skip Beast format elements, just output the raw message
for (const auto &byte : data) // Changed from buffer to data
{
ss << "\\x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
ss << "\\x" << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(byte);
}
ss << "\" > test.beast";
ss << "\" > raw_message.bin"; // Changed filename to indicate raw format
return ss.str();
}

Expand Down

0 comments on commit efbecc8

Please sign in to comment.