Compare commits

..

1 commit
main ... tiles

Author SHA1 Message Date
nathan 12f9dda52d starting to figure out map tiless
Former-commit-id: 824568134cd998da174616228d656fad5ecf0e61
2020-06-13 20:03:06 -07:00
43 changed files with 1741 additions and 2734 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

20
.gitignore vendored
View file

@ -6,24 +6,4 @@
.~ .~
thumbs.db thumbs.db
*.shp
*.shp*
*.shx*
*.shx
*.geojson
*.cpg
*.dbf
*.zip*
*.prj
*.xml
*.html
*.txt
airportnames
mapnames
viz1090 viz1090
result

View file

@ -1,47 +1,21 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "Aircraft.h" #include "Aircraft.h"
#include "AircraftLabel.h"
Aircraft::Aircraft(uint32_t addr) { Aircraft::Aircraft(uint32_t addr) {
this->addr = addr; this->addr = addr;
created = 0;
prev_seen = 0; prev_seen = 0;
lon = 0; x = 0;
lat = 0; y = 0;
cx = 0;
cy = 0;
label = NULL; ox = 0;
oy = 0;
next = NULL; dox = 0;
doy = 0;
ddox = 0;
ddoy = 0;
} }

View file

@ -1,48 +1,14 @@
// viz1090, a vizualizer for dump1090 ADSB output #include <stdint.h>
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <stdint.h>
#include <ctime> #include <ctime>
#include <vector> #include <vector>
#include <chrono>
class AircraftLabel;
class Aircraft { class Aircraft {
public: public:
uint32_t addr; // ICAO address uint32_t addr; // ICAO address
char flight[16]; // Flight number char flight[16]; // Flight number
unsigned char signalLevel[8]; // Last 8 Signal Amplitudes unsigned char signalLevel[8]; // Last 8 Signal Amplitudes
float messageRate; double messageRate;
int altitude; // Altitude int altitude; // Altitude
int speed; // Velocity int speed; // Velocity
int track; // Angle of flight int track; // Angle of flight
@ -50,36 +16,29 @@ public:
time_t seen; // Time at which the last packet was received time_t seen; // Time at which the last packet was received
time_t seenLatLon; // Time at which the last packet was received time_t seenLatLon; // Time at which the last packet was received
time_t prev_seen; time_t prev_seen;
float lat, lon; // Coordinated obtained from CPR encoded data double lat, lon; // Coordinated obtained from CPR encoded data
//history //history
std::vector <float> lonHistory, latHistory, headingHistory; std::vector <float> lonHistory, latHistory, headingHistory, timestampHistory;
std::vector <std::chrono::high_resolution_clock::time_point> timestampHistory;
AircraftLabel *label;
// float oldLon[TRAIL_LENGTH]; // float oldLon[TRAIL_LENGTH];
// float oldLat[TRAIL_LENGTH]; // float oldLat[TRAIL_LENGTH];
// float oldHeading[TRAIL_LENGTH]; // float oldHeading[TRAIL_LENGTH];
// time_t oldSeen[TRAIL_LENGTH]; // time_t oldSeen[TRAIL_LENGTH];
// uint8_t oldIdx; // uint8_t oldIdx;
std::chrono::high_resolution_clock::time_point created; uint64_t created;
std::chrono::high_resolution_clock::time_point msSeen; uint64_t msSeen;
std::chrono::high_resolution_clock::time_point msSeenLatLon; uint64_t msSeenLatLon;
int live; int live;
struct Aircraft *next; // Next aircraft in our linked list struct Aircraft *next; // Next aircraft in our linked list
//// label stuff -> should go to aircraft icon class //// label stuff -> should go to aircraft icon class
// int x, y, cx, cy; int x, y, cx, cy, w, h;
int x, y; float ox, oy, dox, doy, ddox, ddoy;
// float w, h, target_w, target_h; float pressure;
// float ox, oy, dox, doy, ddox, ddoy;
// float labelLevel;
// float opacity, target_opacity;
/// methods /// methods

View file

@ -1,538 +0,0 @@
#include "AircraftLabel.h"
#include "Aircraft.h"
#include <algorithm>
#include "SDL2/SDL2_gfxPrimitives.h"
using fmilliseconds = std::chrono::duration<float, std::milli>;
static std::chrono::high_resolution_clock::time_point now() {
return std::chrono::high_resolution_clock::now();
}
static float elapsed(std::chrono::high_resolution_clock::time_point ref) {
return (fmilliseconds {now() - ref}).count();
}
static float sign(float x) {
return (x > 0) - (x < 0);
}
SDL_Rect AircraftLabel::getFullRect(int labelLevel) {
SDL_Rect rect = {static_cast<int>(x),static_cast<int>(y),0,0};
SDL_Rect currentRect;
if(labelLevel < 2) {
currentRect = speedLabel.getRect();
rect.w = std::max(rect.w,currentRect.w);
rect.h += currentRect.h;
}
if(labelLevel < 1) {
currentRect = altitudeLabel.getRect();
rect.w = std::max(rect.w,currentRect.w);
rect.h += currentRect.h;
currentRect = speedLabel.getRect();
rect.w = std::max(rect.w,currentRect.w);
rect.h += currentRect.h;
}
return rect;
}
void AircraftLabel::update() {
char flight[17] = "";
snprintf(flight,17," %s", p->flight);
std::string flightString = flight;
flightString.erase(std::remove_if(flightString.begin(), flightString.end(), isspace), flightString.end());
flightLabel.setText(flightString);
char alt[10] = "";
if (metric) {
snprintf(alt,10," %dm", static_cast<int>(p->altitude / 3.2828));
} else {
snprintf(alt,10," %d'", p->altitude);
}
altitudeLabel.setText(alt);
char speed[10] = "";
if (metric) {
snprintf(speed,10," %dkm/h", static_cast<int>(p->speed * 1.852));
} else {
snprintf(speed,10," %dmph", p->speed);
}
speedLabel.setText(speed);
}
void AircraftLabel::clearAcceleration() {
ddx = 0;
ddy = 0;
}
float AircraftLabel::calculateDensity(Aircraft *check_p, int labelLevel) {
float density_max = 0;
while(check_p) {
if(check_p->addr == p->addr) {
check_p = check_p->next;
continue;
}
if(!check_p->label) {
check_p = check_p->next;
continue;
}
if(check_p->label->x + check_p->label->w < 0) {
check_p = check_p->next;
continue;
}
if(check_p->label->y + check_p->label->h < 0) {
check_p = check_p->next;
continue;
}
if(check_p->label->x > screen_width) {
check_p = check_p->next;
continue;
}
if(check_p->label->y > screen_height) {
check_p = check_p->next;
continue;
}
SDL_Rect currentRect = getFullRect(labelLevel);
float width_proportion = (currentRect.w + check_p->label->w) / fabs(x - check_p->label->x);
float height_proportion = (currentRect.h + check_p->label->h) / fabs(y - check_p->label->y);
float density = width_proportion * height_proportion;
if(density > density_max) {
density_max = density;
}
check_p = check_p -> next;
}
return density_max;
}
void AircraftLabel::calculateForces(Aircraft *check_p) {
if(w == 0 || h == 0) {
return;
}
Aircraft *head = check_p;
int p_left = x;
int p_right = x + w;
int p_top = y;
int p_bottom = y + h;
float boxmid_x = static_cast<float>(p_left + p_right) / 2.0f;
float boxmid_y = static_cast<float>(p_top + p_bottom) / 2.0f;
float offset_x = boxmid_x - p->x;
float offset_y = boxmid_y - p->y;
float target_length_x = attachment_dist + w / 2.0f;
float target_length_y = attachment_dist + h / 2.0f;
// stay icon_dist away from own icon
ddx -= sign(offset_x) * attachment_force * (fabs(offset_x) - target_length_x);
ddy -= sign(offset_y) * attachment_force * (fabs(offset_y) - target_length_y);
// screen edge
if(p_left < edge_margin) {
ddx += boundary_force * static_cast<float>(edge_margin - p_left);
}
if(p_right > screen_width - edge_margin) {
ddx += boundary_force * static_cast<float>(screen_width - edge_margin - p_right);
}
if(p_top < edge_margin) {
ddy += boundary_force * static_cast<float>(edge_margin - p_top);
}
if(p_bottom > screen_height - edge_margin) {
ddy += boundary_force * static_cast<float>(screen_height - edge_margin - p_bottom);
}
float all_x = 0;
float all_y = 0;
int count = 0;
//check against other labels
while(check_p) {
if(check_p->addr == p->addr) {
check_p = check_p->next;
continue;
}
if(!check_p->label) {
check_p = check_p->next;
continue;
}
int check_left = check_p->label->x;
int check_right = check_p->label->x + check_p->label->w;
int check_top = check_p->label->y;
int check_bottom = check_p->label->y + check_p->label->h;
float icon_x = static_cast<float>(check_p->x);
float icon_y = static_cast<float>(check_p->y);
float checkboxmid_x = static_cast<float>(check_left + check_right) / 2.0f;
float checkboxmid_y = static_cast<float>(check_top + check_bottom) / 2.0f;
float offset_x = boxmid_x - checkboxmid_x;
float offset_y = boxmid_y - checkboxmid_y;
float target_length_x = label_dist + static_cast<float>(check_p->label->w + w) / 2.0f;
float target_length_y = label_dist + static_cast<float>(check_p->label->h + h) / 2.0f;
float x_mag = std::max(0.0f,(target_length_x - fabs(offset_x)));
float y_mag = std::max(0.0f,(target_length_y - fabs(offset_y)));
// stay at least label_dist away from other icons
if(x_mag > 0 && y_mag > 0) {
ddx += sign(offset_x) * label_force * x_mag;
ddy += sign(offset_y) * label_force * y_mag;
}
// stay at least icon_dist away from other icons
offset_x = boxmid_x - check_p->x;
offset_y = boxmid_y - check_p->y;
target_length_x = icon_dist + static_cast<float>(check_p->label->w) / 2.0f;
target_length_y = icon_dist + static_cast<float>(check_p->label->h) / 2.0f;
x_mag = std::max(0.0f,(target_length_x - fabs(offset_x)));
y_mag = std::max(0.0f,(target_length_y - fabs(offset_y)));
if(x_mag > 0 && y_mag > 0) {
ddx += sign(offset_x) * icon_force * x_mag;
ddy += sign(offset_y) * icon_force * y_mag;
}
all_x += sign(boxmid_x - checkboxmid_x);
all_y += sign(boxmid_y - checkboxmid_y);
count++;
check_p = check_p -> next;
}
// move away from others
ddx += density_force * all_x / count;
ddy += density_force * all_y / count;
// char buff[100];
// snprintf(buff, sizeof(buff), "%2.2f", labelLevel);
// debugLabel.setText(buff);
float density_mult = 0.5f;
float level_rate = 0.25f;
if(elapsed(lastLevelChange) > 1000.0) {
if(labelLevel < 0.8f * density_mult * calculateDensity(head, labelLevel + 1)) {
if(labelLevel <= 2) {
labelLevel += level_rate;
lastLevelChange = now();
}
} else if (labelLevel > 1.2f * density_mult * calculateDensity(head, labelLevel - 1)) {
if(labelLevel >= 0) {
labelLevel -= level_rate;
lastLevelChange = now();
}
}
}
}
void AircraftLabel::applyForces() {
dx += ddx;
dy += ddy;
dx *= damping_force;
dy *= damping_force;
if(fabs(dx) > velocity_limit) {
dx = sign(dx) * velocity_limit;
}
if(fabs(dy) > velocity_limit) {
dy = sign(dy) * velocity_limit;
}
if(fabs(dx) < 0.01f) {
dx = 0;
}
if(fabs(dy) < 0.01f) {
dy = 0;
}
x += dx;
y += dy;
if(isnan(x)) {
x = 0;
}
if(isnan(y)) {
y = 0;
}
// x = p->cx + (int)round(p->ox);
// y = p->cy + (int)round(p->oy);
}
// SDL_Color signalToColor(int signal) {
// SDL_Color planeColor;
// if(signal > 127) {
// signal = 127;
// }
// if(signal < 0) {
// planeColor = setColor(96, 96, 96);
// } else {
// planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
// }
// return planeColor;
// }
// void View::drawSignalMarks(Aircraft *p, int x, int y) {
// unsigned char * pSig = p->signalLevel;
// unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
// pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3;
// SDL_Color barColor = signalToColor(signalAverage);
// Uint8 seenFade;
// if(elapsed(p->msSeen) < 1024) {
// seenFade = (Uint8) (255.0 - elapsed(p->msSeen) / 4.0);
// circleRGBA(renderer, x + mapFontWidth, y - 5, 2 * screen_uiscale, barColor.r, barColor.g, barColor.b, seenFade);
// }
// if(elapsed(p->msSeenLatLon) < 1024) {
// seenFade = (Uint8) (255.0 - elapsed(p->msSeenLatLon) / 4.0);
// hlineRGBA(renderer, x + mapFontWidth + 5 * screen_uiscale, x + mapFontWidth + 9 * screen_uiscale, y - 5, barColor.r, barColor.g, barColor.b, seenFade);
// vlineRGBA(renderer, x + mapFontWidth + 7 * screen_uiscale, y - 2 * screen_uiscale - 5, y + 2 * screen_uiscale - 5, barColor.r, barColor.g, barColor.b, seenFade);
// }
// }
void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) {
if(x == 0 || y == 0) {
return;
}
// char buff[100];
// snprintf(buff, sizeof(buff), "%f %f", x, y);
// debugLabel.setText(buff);
int totalWidth = 0;
int totalHeight = 0;
// int margin = 4 * screen_uiscale;
int margin = 4;
SDL_Rect outRect;
if(opacity == 0 && labelLevel < 2) {
target_opacity = 1.0f;
}
if(opacity > 0 && labelLevel >= 2) {
target_opacity = 0.0f;
}
opacity += 0.25f * (target_opacity - opacity);
if(opacity < 0.05f) {
opacity = 0;
}
if(w != 0 && h != 0 && opacity > 0) {
SDL_Color drawColor = style.labelLineColor;
drawColor.a = static_cast<int>(255.0f * opacity);
if(selected) {
drawColor = style.selectedColor;
}
int tick = 4;
int anchor_x, anchor_y, exit_x, exit_y;
if(x + w / 2 > p->x) {
anchor_x = x;
} else {
anchor_x = x + w;
}
if(y + h / 2 > p->y) {
anchor_y = y - margin;
} else {
anchor_y = y + h + margin;
}
if(abs(anchor_x - p->x) > abs(anchor_y - p->y)) {
exit_x = (anchor_x + p->x) / 2;
exit_y = anchor_y;
} else {
exit_x = anchor_x;
exit_y = (anchor_y + p->y) / 2;
}
Sint16 vx[3] = {
static_cast<Sint16>(p->x),
static_cast<Sint16>(exit_x),
static_cast<Sint16>(anchor_x)};
Sint16 vy[3] = {
static_cast<Sint16>(p->y),
static_cast<Sint16>(exit_y),
static_cast<Sint16>(anchor_y)};
boxRGBA(renderer, x, y, x + w, y + h, style.labelBackground.r, style.labelBackground.g, style.labelBackground.b, drawColor.a);
// char buff[100];
// snprintf(buff, sizeof(buff), "%d", drawColor.a);
// debugLabel.setText(buff);
bezierRGBA(renderer, vx, vy, 3, 2, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
//lineRGBA(renderer, x,y - margin, x + tick, y - margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x,y - margin, x + w, y - margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x,y - margin, x, y - margin + tick, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
// lineRGBA(renderer, x + w, y - margin, x + w - tick, y - margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x + w, y - margin, x + w, y - margin + tick, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
//lineRGBA(renderer, x, y + h + margin, x + tick, y + h + margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x, y + h + margin, x + w, y + h + margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x, y + h + margin, x, y + h + margin - tick, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
// lineRGBA(renderer, x + w, y + h + margin,x + w - tick, y + h + margin, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
lineRGBA(renderer, x + w, y + h + margin,x + w, y + h + margin - tick, drawColor.r, drawColor.g, drawColor.b, drawColor.a);
}
if(labelLevel < 2 || selected) {
// drawSignalMarks(p, x, y);
SDL_Color drawColor = style.labelColor;
drawColor.a = static_cast<int>(255.0f * opacity);
flightLabel.setColor(drawColor);
flightLabel.setPosition(x,y);
flightLabel.draw(renderer);
// outRect = drawString(flight, x, y, mapBoldFont, drawColor);
outRect = flightLabel.getRect();
totalWidth = std::max(totalWidth,outRect.w);
totalHeight += outRect.h;
}
if(labelLevel < 1 || selected) {
SDL_Color drawColor = style.subLabelColor;
drawColor.a = static_cast<int>(255.0f * opacity);
altitudeLabel.setColor(drawColor);
altitudeLabel.setPosition(x,y + totalHeight);
altitudeLabel.draw(renderer);
outRect = altitudeLabel.getRect();
totalWidth = std::max(totalWidth,outRect.w);
totalHeight += outRect.h;
speedLabel.setColor(drawColor);
speedLabel.setPosition(x,y + totalHeight);
speedLabel.draw(renderer);
outRect = speedLabel.getRect();
totalWidth = std::max(totalWidth,outRect.w);
totalHeight += outRect.h;
}
debugLabel.setPosition(x,y + totalHeight);
debugLabel.draw(renderer);
target_w = totalWidth;
target_h = totalHeight;
w += 0.25f * (target_w - w);
h += 0.25f * (target_h - h);
if(w < 0.05f) {
w = 0;
}
if(h < 0.05f) {
h = 0;
}
}
AircraftLabel::AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font) {
this->p = p;
this->metric = metric;
x = p->x;
y = p->y + 20; //*screen_uiscale
w = 0;
h = 0;
target_w = 0;
target_h = 0;
opacity = 0;
target_opacity = 0;
dx = 0;
dy = 0;
ddx = 0;
ddy = 0;
this->screen_width = screen_width;
this->screen_height = screen_height;
labelLevel = 0;
flightLabel.setFont(font);
altitudeLabel.setFont(font);
speedLabel.setFont(font);
debugLabel.setFont(font);
lastLevelChange = now();
}

View file

@ -1,76 +0,0 @@
#include <string>
#include "SDL2/SDL_ttf.h"
#include <chrono>
#include "Label.h"
#include "Style.h"
class Aircraft;
class AircraftLabel {
public:
void update();
void clearAcceleration();
void calculateForces(Aircraft *check_p);
void applyForces();
void draw(SDL_Renderer *renderer, bool selected);
AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font);
private:
SDL_Rect getFullRect(int labelLevel);
float calculateDensity(Aircraft *check_p, int labelLevel);
Aircraft *p;
Label flightLabel;
Label altitudeLabel;
Label speedLabel;
Label debugLabel;
float labelLevel;
bool metric;
float x;
float y;
float w;
float h;
float target_w;
float target_h;
float dx;
float dy;
float ddx;
float ddy;
float opacity;
float target_opacity;
float pressure;
int screen_width;
int screen_height;
std::chrono::high_resolution_clock::time_point lastLevelChange;
///////////
float label_force = 0.001f;
float label_dist = 2.0f;
float density_force = 0.05f;
float attachment_force = 0.0015f;
float attachment_dist = 10.0f;
float icon_force = 0.001f;
float icon_dist = 15.0f;
float boundary_force = 0.01f;
float damping_force = 0.85f;
float velocity_limit = 2.0f;
float edge_margin = 15.0f;
Style style;
};

View file

@ -1,38 +1,9 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "AircraftList.h" #include "AircraftList.h"
static std::chrono::high_resolution_clock::time_point now() { #include <chrono>
return std::chrono::high_resolution_clock::now();
static uint64_t now() {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
} }
@ -57,10 +28,6 @@ void AircraftList::update(Modes *modes) {
p = p->next; p = p->next;
} }
//debug
//find(1)->live = 1;
while(a) { while(a) {
p = find(a->addr); p = find(a->addr);
@ -89,38 +56,31 @@ void AircraftList::update(Modes *modes) {
memcpy(p->flight, a->flight, sizeof(p->flight)); memcpy(p->flight, a->flight, sizeof(p->flight));
memcpy(p->signalLevel, a->signalLevel, sizeof(p->signalLevel)); memcpy(p->signalLevel, a->signalLevel, sizeof(p->signalLevel));
if(p->seenLatLon == a->seenLatLon) {
a = a->next;
continue;
}
p->msSeenLatLon = now();
p->seenLatLon = a->seenLatLon;
p->altitude = a->altitude; p->altitude = a->altitude;
p->speed = a->speed; p->speed = a->speed;
p->track = a->track; p->track = a->track;
p->vert_rate = a->vert_rate; p->vert_rate = a->vert_rate;
if(p->lon == 0) {
p->created = now();
}
if(p->lon == a->lon && p->lat == a->lat) {
a = a->next;
continue;
}
p->lon = a->lon; p->lon = a->lon;
p->lat = a->lat; p->lat = a->lat;
p->lonHistory.push_back(p->lon); if(p->seenLatLon < a->seenLatLon) {
p->latHistory.push_back(p->lat); p->msSeenLatLon = now();
p->headingHistory.push_back(p->track);
p->timestampHistory.push_back(p->msSeenLatLon); // p->oldIdx = (p->oldIdx+1) % 32;
// p->oldLon[p->oldIdx] = p->lon;
// p->oldLat[p->oldIdx] = p->lat;
p->lonHistory.push_back(p->lon);
p->latHistory.push_back(p->lat);
p->headingHistory.push_back(p->track);
p->timestampHistory.push_back(p->seenLatLon);
// p->oldHeading[p->oldIdx] = p->track;
// p->oldSeen[p->oldIdx] = p->seenLatLon;
}
p->seenLatLon = a->seenLatLon;
a = a->next; a = a->next;
} }
@ -148,10 +108,6 @@ void AircraftList::update(Modes *modes) {
AircraftList::AircraftList() { AircraftList::AircraftList() {
head = nullptr; head = nullptr;
// //debug aircraft attached to mouse
// head = new Aircraft(1);
// memcpy(head->flight, "mouse", sizeof("mouse"));
} }
AircraftList::~AircraftList() { AircraftList::~AircraftList() {

View file

@ -1,34 +1,3 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "Aircraft.h" #include "Aircraft.h"
#include "dump1090.h" //for Modes #include "dump1090.h" //for Modes

View file

@ -1,40 +1,10 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "AppData.h" #include "AppData.h"
// //
//carried over from view1090.c //carried over from view1090.c
// //
int AppData::setupConnection(struct client *c) { int AppData::setupConnection(struct client *c) {
int fd; int fd;
@ -62,20 +32,16 @@ void AppData::initialize() {
void AppData::connect() { void AppData::connect() {
if(connected) {
return;
}
c = (struct client *) malloc(sizeof(*c)); c = (struct client *) malloc(sizeof(*c));
while(1) {
if ((fd = setupConnection(c)) == ANET_ERR) { if ((fd = setupConnection(c)) == ANET_ERR) {
fprintf(stderr, "Waiting on %s:%d\n", server, modes.net_input_beast_port); fprintf(stderr, "Waiting on %s:%d\n", server, modes.net_input_beast_port);
return; sleep(1);
} else {
break;
}
} }
connected = true;
fprintf(stderr, "Connected to %s:%d\n", server, modes.net_input_beast_port);
} }
@ -86,10 +52,6 @@ void AppData::disconnect() {
void AppData::update() { void AppData::update() {
if(!connected) {
return;
}
if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) { if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) {
free(c); free(c);
usleep(1000000); usleep(1000000);
@ -97,8 +59,7 @@ void AppData::update() {
fd = setupConnection(c); fd = setupConnection(c);
return; return;
} }
char empty; modesReadFromClient(&modes, c,"",decodeBinMessage);
modesReadFromClient(&modes, c, &empty,decodeBinMessage);
interactiveRemoveStaleAircrafts(&modes); interactiveRemoveStaleAircrafts(&modes);
@ -162,6 +123,4 @@ AppData::AppData(){
modes.interactive = 0; modes.interactive = 0;
modes.quiet = 1; modes.quiet = 1;
connected = false;
} }

View file

@ -1,34 +1,3 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef APPDATA_H #ifndef APPDATA_H
#define APPDATA_H #define APPDATA_H
@ -45,7 +14,6 @@ class AppData {
// //
struct client *c; struct client *c;
bool connected;
int fd; int fd;
char pk_buf[8]; char pk_buf[8];

View file

@ -1,46 +1,13 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "Input.h" #include "Input.h"
static std::chrono::high_resolution_clock::time_point now() { #include <chrono>
return std::chrono::high_resolution_clock::now();
static uint64_t now() {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
} }
// static uint64_t now() { static uint64_t elapsed(uint64_t ref) {
// return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch).count(); return now() - ref;
// }
static uint64_t elapsed(std::chrono::high_resolution_clock::time_point ref) {
return std::chrono::duration_cast<std::chrono::milliseconds>(now() - ref).count();
} }
template <typename T> int sgn(T val) { template <typename T> int sgn(T val) {
@ -88,14 +55,14 @@ void Input::getInput()
view->mapMoved = 1; view->mapMoved = 1;
if(elapsed(touchDownTime) > 100) { if(elapsed(touchDownTime) > 100) {
//touchDownTime = 0; touchDownTime = 0;
} }
break; break;
case SDL_FINGERMOTION:; case SDL_FINGERMOTION:;
if(elapsed(touchDownTime) > 150) { if(elapsed(touchDownTime) > 150) {
tapCount = 0; tapCount = 0;
//touchDownTime = 0; touchDownTime = 0;
} }
view->moveCenterRelative( view->screen_width * event.tfinger.dx, view->screen_height * event.tfinger.dy); view->moveCenterRelative( view->screen_width * event.tfinger.dx, view->screen_height * event.tfinger.dy);
break; break;

35
Input.h
View file

@ -1,42 +1,9 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef INPUT_H #ifndef INPUT_H
#define INPUT_H #define INPUT_H
#include "AppData.h" #include "AppData.h"
#include "View.h" #include "View.h"
#include <chrono>
class Input { class Input {
public: public:
void getInput(); void getInput();
@ -47,7 +14,7 @@ public:
View *view; View *view;
AppData *appData; AppData *appData;
std::chrono::high_resolution_clock::time_point touchDownTime; uint64_t touchDownTime;
int touchx; int touchx;
int touchy; int touchy;
int tapCount; int tapCount;

View file

@ -1,70 +0,0 @@
#include "Label.h"
#include <string>
void Label::draw(SDL_Renderer *renderer) {
SDL_Rect rect = getRect();
if(rect.h == 0 || rect.w == 0) {
return;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_RenderCopy(renderer, texture, NULL, &rect);
SDL_DestroyTexture(texture);
}
void Label::makeSurface() {
if(surface != NULL) {
SDL_FreeSurface(surface);
}
surface = TTF_RenderUTF8_Solid(font, text.c_str(), color);
}
SDL_Rect Label::getRect() {
SDL_Rect rect = {0,0,0,0};
if(!text.length()) {
return rect;
}
if(surface == NULL) {
return rect;
}
rect.x = x;
rect.y = y;
rect.w = surface->w;
rect.h = surface->h;
return rect;
}
void Label::setText(std::string text) {
this->text = text;
makeSurface();
}
void Label::setPosition(int x, int y) {
this->x = x;
this->y = y;
}
void Label::setFont(TTF_Font *font) {
this->font = font;
}
void Label::setColor(SDL_Color color) {
this->color = color;
}
//
Label::Label() {
this->color = {255,255,255,255};
surface = NULL;
}
Label::~Label() {
SDL_FreeSurface(surface);
}

29
Label.h
View file

@ -1,29 +0,0 @@
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include <string>
class Label {
public:
void draw(SDL_Renderer *renderer);
void setText(std::string text);
void setPosition(int x, int y);
void setFont(TTF_Font *font);
void setColor(SDL_Color color);
SDL_Rect getRect();
Label();
~Label();
private:
void makeSurface();
std::string text;
int x;
int y;
TTF_Font *font;
SDL_Color color;
SDL_Surface *surface;
};

View file

@ -3,24 +3,17 @@
# sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local # sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local
# #
CXXFLAGS=-O2 -std=c++11 -g CFLAGS=-O2 -Wno-write-strings
LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -g LIBS=-lm -lSDL2 -lSDL2_ttf -lSDL2_gfx
CXX=g++ CC=g++
all: viz1090 all: viz1090
%.o: %.c %.cpp %.o: %.c %.cpp
$(CXX) $(CXXFLAGS) $(EXTRACFLAGS) -c $< $(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<
viz1090: viz1090.o AppData.o AircraftList.o Aircraft.o Label.o AircraftLabel.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o viz1090: viz1090.o AppData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o
$(CXX) -o viz1090 viz1090.o AppData.o AircraftList.o Aircraft.o Label.o AircraftLabel.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o $(LIBS) $(LDFLAGS) $(CC) -g -o viz1090 viz1090.o AppData.o AircraftList.o Aircraft.o anet.o interactive.o mode_ac.o mode_s.o net_io.o Input.o View.o Map.o parula.o monokai.o $(LIBS) $(LDFLAGS)
clean: clean:
rm -f \ rm -f *.o viz1090
airportdata.bin \
airportnames \
mapdata/* \
mapdata.bin \
mapnames \
*.o \
viz1090

327
Map.cpp
View file

@ -1,75 +1,26 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "Map.h" #include "Map.h"
#include <stdio.h> #include <stdio.h>
#include <cstdlib> #include <cstdlib>
#include <sstream>
#include <fstream>
#include <string>
#include <iostream>
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) { bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
// printf("Inserting %d point poly\n", line->numPoints);
// if(depth > 25) {
// // printf("fail [%f %f] -> [%f %f]\n",line->start.lon,line->start.lat,line->end.lon,line->end.lat);
// // printf("bounds %f %f %f %f\n",tree->lon_min, tree->lon_max, tree->lat_min, tree->lat_max);
// // fflush(stdout);
// tree->lines.push_back(&(*line));
// return true;
// }
bool startInside = line->start.lat >= tree->lat_min && if (!(line->lat_min >= tree->lat_min &&
line->start.lat <= tree->lat_max && line->lat_max <= tree->lat_max &&
line->start.lon >= tree->lon_min && line->lon_min >= tree->lon_min &&
line->start.lon <= tree->lon_max; line->lon_max <= tree->lon_max)) {
// printf("doesnt fit: %f > %f, %f < %f, %f < %f,%f > %f \n",line->lat_min, tree->lat_min, line->lat_max, tree->lat_max, line->lon_min, tree->lon_min, line->lon_max,tree->lon_max);
bool endInside = line->end.lat >= tree->lat_min && return false;
line->end.lat <= tree->lat_max &&
line->end.lon >= tree->lon_min &&
line->end.lon <= tree->lon_max;
// if (!startInside || !endInside) {
// return false;
// }
if (!startInside && !endInside) {
return false;
} }
if (startInside != endInside) {
tree->lines.push_back(&(*line)); // //temp maxdepth for debugging
return true; // if(depth > 20) {
} // tree->lines.push_back(*line);
// return true;
// }
if (tree->nw == NULL) { if (tree->nw == NULL) {
tree->nw = new QuadTree; tree->nw = new QuadTree;
@ -123,14 +74,13 @@ bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
return true; return true;
} }
tree->lines.push_back(&(*line)); tree->lines.push_back(*line);
return true; return true;
} }
std::vector<Line*> Map::getLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) { std::vector<Line> Map::getLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) {
std::vector<Line*> retLines; std::vector<Line> retLines;
if(tree == NULL) { if(tree == NULL) {
return retLines; return retLines;
@ -144,7 +94,7 @@ std::vector<Line*> Map::getLinesRecursive(QuadTree *tree, float screen_lat_min,
return retLines; return retLines;
} }
std::vector<Line*> ret; std::vector<Line> ret;
ret = getLinesRecursive(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); ret = getLinesRecursive(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
retLines.insert(retLines.end(), ret.begin(), ret.end()); retLines.insert(retLines.end(), ret.begin(), ret.end());
@ -159,227 +109,70 @@ std::vector<Line*> Map::getLinesRecursive(QuadTree *tree, float screen_lat_min,
retLines.insert(retLines.end(), tree->lines.begin(), tree->lines.end()); retLines.insert(retLines.end(), tree->lines.begin(), tree->lines.end());
// Debug quadtree
// Point TL, TR, BL, BR;
// TL.lat = tree->lat_min;
// TL.lon = tree->lon_min;
// TR.lat = tree->lat_max;
// TR.lon = tree->lon_min;
// BL.lat = tree->lat_min;
// BL.lon = tree->lon_max;
// BR.lat = tree->lat_max;
// BR.lon = tree->lon_max;
// retLines.push_back(new Line(TL,TR));
// retLines.push_back(new Line(TR,BR));
// retLines.push_back(new Line(BL,BR));
// retLines.push_back(new Line(TL,BL));
return retLines; return retLines;
} }
std::vector<Line*> Map::getLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) { std::vector<Line> Map::getLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max) {
return getLinesRecursive(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); return getLinesRecursive(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
}; };
Map::Map() { Map::Map() {
FILE *fileptr; FILE *fileptr;
if((fileptr = fopen("mapdata.bin", "rb"))) { if(!(fileptr = fopen("mapdata.bin", "rb"))) {
printf("Couldn't read mapdata.bin\nDid you run getmap.sh?\n");
exit(0);
fseek(fileptr, 0, SEEK_END);
mapPoints_count = ftell(fileptr) / sizeof(float);
rewind(fileptr);
mapPoints = (float *)malloc(mapPoints_count * sizeof(float));
if(!fread(mapPoints, sizeof(float), mapPoints_count, fileptr)){
printf("Map read error\n");
exit(0);
}
fclose(fileptr);
printf("Read %d map points.\n",mapPoints_count / 2);
// load quad tree
for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0)
continue;
if(mapPoints[i] < root.lon_min) {
root.lon_min = mapPoints[i];
} else if(mapPoints[i] > root.lon_max) {
root.lon_max = mapPoints[i];
}
if(mapPoints[i+1] < root.lat_min) {
root.lat_min = mapPoints[i+1];
} else if(mapPoints[i+1] > root.lat_max) {
root.lat_max = mapPoints[i+1];
}
}
//printf("map bounds: %f %f %f %f\n",root.lon_min, root.lon_max, root.lat_min, root.lat_max);
Point currentPoint;
Point nextPoint;
for(int i = 0; i < mapPoints_count - 2; i+=2) {
if(mapPoints[i] == 0)
continue;
if(mapPoints[i + 1] == 0)
continue;
if(mapPoints[i + 2] == 0)
continue;
if(mapPoints[i + 3] == 0)
continue;
currentPoint.lon = mapPoints[i];
currentPoint.lat = mapPoints[i + 1];
nextPoint.lon = mapPoints[i + 2];
nextPoint.lat = mapPoints[i + 3];
// printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
QTInsert(&root, new Line(currentPoint, nextPoint), 0);
}
} else {
printf("No map file found\n");
}
//
if((fileptr = fopen("airportdata.bin", "rb"))) {
fseek(fileptr, 0, SEEK_END);
airportPoints_count = ftell(fileptr) / sizeof(float);
rewind(fileptr);
airportPoints = (float *)malloc(airportPoints_count * sizeof(float));
if(!fread(airportPoints, sizeof(float), airportPoints_count, fileptr)){
printf("Map read error\n");
exit(0);
}
fclose(fileptr);
printf("Read %d airport points.\n",airportPoints_count / 2);
// load quad tree
for(int i = 0; i < airportPoints_count; i+=2) {
if(airportPoints[i] == 0)
continue;
if(airportPoints[i] < airport_root.lon_min) {
airport_root.lon_min = airportPoints[i];
} else if(airportPoints[i] > airport_root.lon_max) {
airport_root.lon_max = airportPoints[i];
}
if(airportPoints[i+1] < airport_root.lat_min) {
airport_root.lat_min = airportPoints[i+1];
} else if(airportPoints[i+1] > airport_root.lat_max) {
airport_root.lat_max = airportPoints[i+1];
}
}
//printf("map bounds: %f %f %f %f\n",root.lon_min, root.lon_max, root.lat_min, root.lat_max);
Point currentPoint;
Point nextPoint;
for(int i = 0; i < airportPoints_count - 2; i+=2) {
if(airportPoints[i] == 0)
continue;
if(airportPoints[i + 1] == 0)
continue;
if(airportPoints[i + 2] == 0)
continue;
if(airportPoints[i + 3] == 0)
continue;
currentPoint.lon = airportPoints[i];
currentPoint.lat = airportPoints[i + 1];
nextPoint.lon = airportPoints[i + 2];
nextPoint.lat = airportPoints[i + 3];
//printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
QTInsert(&airport_root, new Line(currentPoint, nextPoint), 0);
}
} else {
printf("No airport file found\n");
} }
// fseek(fileptr, 0, SEEK_END);
mapPoints_count = ftell(fileptr) / sizeof(float);
rewind(fileptr);
mapPoints = (float *)malloc(mapPoints_count * sizeof(float));
std::string line; if(!fread(mapPoints, sizeof(float), mapPoints_count, fileptr)){
std::ifstream infile("mapnames"); printf("Read error\n");
exit(0);
while (std::getline(infile, line))
{
float lon, lat;
std::istringstream iss(line);
iss >> lon;
iss >> lat;
std::string assemble;
iss >> assemble;
for(std::string s; iss >> s; ) {
assemble = assemble + " " + s;
}
// std::cout << "[" << x << "," << y << "] " << assemble << "\n";
MapLabel *label = new MapLabel(lon,lat,assemble);
mapnames.push_back(label);
} }
std::cout << "Read " << mapnames.size() << " place names\n"; fclose(fileptr);
infile.close(); printf("Read %d map points.\n",mapPoints_count / 2);
infile.open("airportnames"); // load quad tree
for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0)
continue;
while (std::getline(infile, line)) if(mapPoints[i] < root.lon_min) {
{ root.lon_min = mapPoints[i];
float lon, lat; } else if(mapPoints[i] > root.lon_max) {
root.lon_max = mapPoints[i];
}
std::istringstream iss(line); if(mapPoints[i+1] < root.lat_min) {
root.lat_min = mapPoints[i+1];
} else if(mapPoints[i+1] > root.lat_max) {
root.lat_max = mapPoints[i+1];
}
}
iss >> lon; Point currentPoint;
iss >> lat; Point nextPoint;
std::string assemble; for(int i = 0; i < mapPoints_count - 2; i+=2) {
if(mapPoints[i] == 0)
continue;
currentPoint.lon = mapPoints[i];
currentPoint.lat = mapPoints[i + 1];
iss >> assemble; nextPoint.lon = mapPoints[i + 2];
nextPoint.lat = mapPoints[i + 3];
for(std::string s; iss >> s; ) { QTInsert(&root, new Line(currentPoint, nextPoint), 0);
assemble = assemble + " " + s; }
} }
// std::cout << "[" << x << "," << y << "] " << assemble << "\n"; Map::~Map() {
MapLabel *label = new MapLabel(lon,lat,assemble); delete mapPoints;
airportnames.push_back(label);
}
std::cout << "Read " << airportnames.size() << " airport names\n";
infile.close();
printf("done\n");
} }

70
Map.h
View file

@ -1,56 +1,13 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef MAP_H #ifndef MAP_H
#define MAP_H #define MAP_H
#include <vector> #include <vector>
#include <string>
typedef struct Point{ typedef struct Point{
float lat; float lat;
float lon; float lon;
} Point; } Point;
typedef struct MapLabel{
Point location;
std::string text;
MapLabel(float lon, float lat, std::string text) {
this->location.lon = lon;
this->location.lat = lat;
this->text = text;
}
} MapLabel;
typedef struct Line{ typedef struct Line{
float lat_min; float lat_min;
float lat_max; float lat_max;
@ -77,7 +34,7 @@ typedef struct QuadTree{
float lon_min; float lon_min;
float lon_max; float lon_max;
std::vector<Line*> lines; std::vector<Line> lines;
struct QuadTree *nw; struct QuadTree *nw;
struct QuadTree *sw; struct QuadTree *sw;
@ -117,24 +74,19 @@ typedef struct QuadTree{
class Map { class Map {
public: private:
QuadTree root;
QuadTree airport_root;
bool QTInsert(QuadTree *tree, Line *line, int depth);
std::vector<Line*> getLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
std::vector<Line*> getLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
std::vector<MapLabel*> mapnames;
std::vector<MapLabel*> airportnames;
Map();
int mapPoints_count; int mapPoints_count;
float *mapPoints; float *mapPoints;
int airportPoints_count; QuadTree root;
float *airportPoints;
bool QTInsert(QuadTree *tree, Line *line, int depth);
std::vector<Line> getLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
public:
std::vector<Line> getLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max);
Map();
~Map();
}; };
#endif #endif

111
README.md
View file

@ -1,89 +1,60 @@
# viz1090 # viz1090
![image](https://media.giphy.com/media/dJnFpEDGi1swmb3L05/giphy.gif) **This is work in progress**
There are a lot of missing pieces in this implementation so far:
**This is a work in progress** * A proper map system yet. Eventually map data should be pulled from Mapbox or similar.
* In-application menus or configuration yet.
There are some major fixes and cleanup that need to happen before a release:
* Everything is a grab bag of C and C++, need to more consistently modernize
* A full refactor, especially View.cpp, necessary for many of the new features below.
* A working Android build, as this is the best way to run this on portable hardware.
There are also a lot of missing features:
* Map improvements
* Labels, different colors/line weights for features
* Tile prerenderer for improved performance
* In-application menus for view options and configuration
* Theming/colormaps (important as this is primarily intended to be eye candy!) * Theming/colormaps (important as this is primarily intended to be eye candy!)
* Integration with handheld features like GPS, battery monitors, buttons/dials, etc. * Integration with handheld features like GPS, battery monitors, buttons/dials, etc.
* Android build is currently broken
### BUILDING ### BUILDING
Tested and working on Ubuntu 18.04, Raspbian Stretch / Buster, Windows Subsystem for Linux (with Ubuntu 18.04), and Mac Tested and working on Ubuntu 18.04, Raspbian Stretch / Buster, Windows Subsystem for Linux (with Ubuntu 18.04)
0. Install build essentials 0. Install build essentials
``` ```
sudo apt-get install build-essential sudo apt-get install build-essentials
``` ```
1. Install SDL and RTL-SDR libraries 1. Install SDL and RTL-SDR libararies
``` ```
sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-gfx-dev librtlsdr-dev libgdal-dev sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-gfx-dev librtlsdr-dev
``` ```
Note: On Raspbian the SDL2 package requires X to be running. See the Raspberry Pi section for notes on running from the terminal and other improvements.
Note: On Raspbian the SDL2 package requires X to be running. See the Raspberry Pi section for notes on running from the terminal and other improvements. 2. Download and build spidr
2. Download and build viz1090
``` ```
cd ~ cd ~
git clone https://www.github.com/nmatsuda/viz1090 git clone https://www.github.com/nmatsuda/spidr
cd viz1090 cd spidr
make clean; make make clean; make
``` ```
3. Download and process map data 3. Download and process map data
Until more comprehensive map source (e.g., Mapbox) is integrated, viz1090 uses the lat/lon SVG files from https://www.mccurley.org
The getmap.sh pulls the svg file for the contiguous 48 US states and produces a binary file for viz1090 to read.
``` ```
sudo apt install python3 python3-pip sudo apt install python3 python3-pip
pip3 install fiona tqdm shapely pip3 install lxml numpy tqdm
./getmap.sh ./getmap.sh
``` ```
This will produce files for map and airport geometry, with labels, that viz1090 reads. If any of these files don't exist then visualizer will show planes and trails without any geography. 3. (optional for Windows)
The default parameters for mapconverter should render reasonably quickly on a Raspberry Pi 4. See the mapconverter section below for other options and more information about map sources.
3. (Windows only)
As WSL does not have an X server built in, you will need to install a 3rd party X server, such as https://sourceforge.net/projects/vcxsrv/ As WSL does not have an X server built in, you will need to install a 3rd party X server, such as https://sourceforge.net/projects/vcxsrv/
* run Xlaunch from the start menu * run Xlaunch from the start menu
* Uncheck "Use Native openGL" * Uncheck "Use Native openGL"
* Add parameter ```-ac``` (WSL 2 only) * Open the Ubuntu WSL terminal
* Open the Ubuntu WSL terminal * Specify the X display to use
* Specify the X display to use (WSL 1) ```
``` export DISPLAY=:0
export DISPLAY=:0 ```
``` * Start viz1090 as described below.
* or for (WSL 2)
```
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
```
* Start viz1090 as described below.
#### Nix
Run without installing
```bash
nix shell git+https://git.vulpecula.zone/tasiaiso/viz1090
```
TODO docs
A shell is now open with viz1090 in the path
### RUNNING ### RUNNING
@ -107,36 +78,11 @@ viz1090 will open an SDL window set to the resolution of your screen.
| --port [port number] | Specify dump1090 server port | | --port [port number] | Specify dump1090 server port |
| --metric | Display metric units | | --metric | Display metric units |
| --lat | Specify your latitude in degrees | | --lat | Specify your latitude in degrees |
| --lon | Specify your longitude in degrees | | --lon | Specify your longitiude in degrees |
| --screensize [width] [height] | Specify a resolution, otherwise use resolution of display | | --screensize [width] [height] | Specify a specific resolution to pass to SDL_RenderSetLogicalSize, otherwise use resolution of display |
| --uiscale [scale] | Scale up UI elements by integer amounts for high resolution screen | | --uiscale [scale] | Scale up UI elements by integer amounts for high resolution screen |
| --fullscreen | Render fullscreen rather than in a window | | --fullscreen | Render fullscreen rather than in a window |
### MAPS
The best map data source I've found so far is https://www.naturalearthdata.com. This has a lot of useful GIS data, but not airport runways, which you can get from the FAA Aeronautical Data Delivery Service (https://adds-faa.opendata.arcgis.com/)
I've been using these files:
* [Map geometry](https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip)
* [Place names](https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip)
* [Airport IATA codes](https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_airports.zip)
* [Airport runway geometry](https://opendata.arcgis.com/datasets/4d8fa46181aa470d809776c57a8ab1f6_0.zip)
The bash script getmap.sh will download (so long as the links don't break) and convert these. Alternatively, you can pass shapefiles and other arguments to mapconverter.py directly
### MAPCONVERTER.PY RUNTIME OPTIONS
| Argument | Description |
| ----------------------------- | ----------- |
| --mapfile | shapefile for main map |
| --mapnames | shapefile for map place names |
| --airportfile | shapefile for airport runway outlines |
| --airportnames | shapefile for airport IATA names |
| --minpop | minimum population to show place names for (defaults to 100000) |
| --tolerance" | map simplification tolerance (defaults to 0.001, which works well on a Raspberry Pi 4 - smaller values will produce more detail but slow down the map refresh rate) |
### HARDWARE NOTES ### HARDWARE NOTES
This software was originally intended for Raspberry Pi devices, and it is currently optimized for the Raspberry Pi 4 with the following configuration: This software was originally intended for Raspberry Pi devices, and it is currently optimized for the Raspberry Pi 4 with the following configuration:
@ -154,7 +100,6 @@ This software was originally intended for Raspberry Pi devices, and it is curren
* [Noelec Nano V3](https://www.nooelec.com/store/nesdr-nano-three.html) * [Noelec Nano V3](https://www.nooelec.com/store/nesdr-nano-three.html)
* Stratux V2 \*very low power but hard to find * Stratux V2 \*very low power but hard to find
If you want to print the case in the GIF shown above, you can [download it here](https://github.com/nmatsuda/viz1090_case).
If running as a front end only, with a separate dump1090 server, the best option is to use an Android phone, such as the Pixel 2, which significantly outperforms a Raspberry Pi 4. If running as a front end only, with a separate dump1090 server, the best option is to use an Android phone, such as the Pixel 2, which significantly outperforms a Raspberry Pi 4.

94
Style.h
View file

@ -1,94 +0,0 @@
#ifndef STYLE_H
#define STYLE_H
#include "SDL2/SDL.h"
//
// This should go to a full theming class
//
typedef struct Style {
SDL_Color backgroundColor;
SDL_Color selectedColor;
SDL_Color planeColor;
SDL_Color planeGoneColor;
SDL_Color trailColor;
SDL_Color geoColor;
SDL_Color airportColor;
SDL_Color labelColor;
SDL_Color labelLineColor;
SDL_Color subLabelColor;
SDL_Color labelBackground;
SDL_Color scaleBarColor;
SDL_Color buttonColor;
SDL_Color buttonBackground;
SDL_Color buttonOutline;
SDL_Color clickColor;
SDL_Color black;
SDL_Color white;
SDL_Color red;
SDL_Color green;
SDL_Color blue;
//
// todo separate style stuff
//
Style() {
SDL_Color pink = {249,38,114,255};
SDL_Color purple = {85, 0, 255,255};
SDL_Color purple_dark = {33, 0, 122,255};
SDL_Color blue = {102,217,239,255};
SDL_Color blue_dark = {102,217,239,255};
SDL_Color green = {0,255,234,255};
SDL_Color green_dark = {24,100,110,255};
SDL_Color yellow = {216,255,0,255};
SDL_Color yellow_dark = {90,133,50,255};
SDL_Color orange = {253,151,31,255};
SDL_Color grey_light = {196,196,196,255};
SDL_Color grey = {127,127,127,255};
SDL_Color grey_dark = {64,64,64,255};
black = {0,0,0,255};
white = {255,255,255,255};
red = {255,0,0,255};
green = {0,255,0,255};
blue = {0,0,255,255};
backgroundColor = black;
selectedColor = pink;
planeColor = yellow;
planeGoneColor = grey;
trailColor = yellow_dark;
geoColor = purple_dark;
airportColor = purple;
labelColor = white;
labelLineColor = grey_dark;
subLabelColor = grey;
labelBackground = black;
scaleBarColor = grey_light;
buttonColor = grey_light;
buttonBackground = black;
buttonOutline = grey_light;
clickColor = grey;
}
} Style;
#endif

View file

@ -1,73 +0,0 @@
#include "SDL2/SDL2_gfxPrimitives.h"
#include "Text.h"
SDL_Rect Text::drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color)
{
SDL_Rect dest = {0,0,0,0};
if(!text.length()) {
return dest;
}
SDL_Surface *surface;
surface = TTF_RenderUTF8_Solid(font, text.c_str(), color);
if (surface == NULL)
{
printf("Couldn't create String %s: %s\n", text.c_str(), SDL_GetError());
return dest;
}
dest.x = x;
dest.y = y;
dest.w = surface->w;
dest.h = surface->h;
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_RenderCopy(renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
return dest;
}
SDL_Rect Text::drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor) {
SDL_Rect dest = {0,0,0,0};
if(!text.length()) {
return dest;
}
SDL_Surface *surface;
surface = TTF_RenderUTF8_Shaded(font, text.c_str(), color, bgColor);
if (surface == NULL)
{
printf("Couldn't create String %s: %s\n", text.c_str(), SDL_GetError());
return dest;
}
dest.x = x;
dest.y = y;
dest.w = surface->w;
dest.h = surface->h;
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_RenderCopy(renderer, texture, NULL, &dest);
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
return dest;
}
// check if text has changed and surface exists
// redraw existing surface
// or make new surface
// for BG, draw bg size of surface
// draw surface

1371
View.cpp

File diff suppressed because it is too large Load diff

203
View.h
View file

@ -1,52 +1,19 @@
// viz1090, a vizualizer for dump1090 ADSB output
//
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef VIEW_H #ifndef VIEW_H
#define VIEW_H #define VIEW_H
#include "AppData.h" #include "AppData.h"
#include "Map.h" #include "Map.h"
#include "Style.h"
#include "SDL2/SDL.h" #include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h" #include "SDL2/SDL_ttf.h"
#include <chrono>
#include <string>
//defs - should all move to config file setup //defs - should all move to config file setup
#define ROUND_RADIUS 3 //radius of text box corners #define ROUND_RADIUS 3 //radius of text box corners
#define CENTEROFFSET .5 //vertical offset for middle of screen
#define TRAIL_LENGTH 120 #define TRAIL_LENGTH 120
#define TRAIL_TTL 240.0 #define TRAIL_TTL 240.0
#define DISPLAY_ACTIVE 30.0 #define DISPLAY_ACTIVE 30
#define TRAIL_TTL_STEP 2 #define TRAIL_TTL_STEP 2
#define MIN_MAP_FEATURE 2 #define MIN_MAP_FEATURE 2
@ -55,7 +22,33 @@
#define PAD 5 #define PAD 5
#define LATLONMULT 111.195 // 6371.0 * M_PI / 180.0
//
// This should go to a full theming class
//
typedef struct Style {
SDL_Color backgroundColor;
SDL_Color selectedColor;
SDL_Color planeColor;
SDL_Color planeGoneColor;
SDL_Color mapInnerColor;
SDL_Color mapOuterColor;
SDL_Color scaleBarColor;
SDL_Color buttonColor;
} Style;
typedef struct Tile {
float lat_min;
float lat_max;
float lon_min;
float lon_max;
SDL_Texture *texture;
} Tile;
class View { class View {
@ -64,103 +57,38 @@ class View {
AppData *appData; AppData *appData;
//for cursor drawing //for cursor drawing
std::chrono::high_resolution_clock::time_point mouseMovedTime; uint64_t mouseMovedTime;
bool mouseMoved;
int mousex; int mousex;
int mousey; int mousey;
std::chrono::high_resolution_clock::time_point clickTime; uint64_t clickTime;
bool clicked;
int clickx; int clickx;
int clicky; int clicky;
int lineCount; TTF_Font* loadFont(char *name, int size);
float dx_mult;
float dy_mult;
TTF_Font* loadFont(const char *name, int size);
void closeFont(TTF_Font *font); void closeFont(TTF_Font *font);
SDL_Rect drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color); void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color);
SDL_Rect drawStringBG(std::string text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor); void drawStringBG(char * text, int x, int y, TTF_Font *font, SDL_Color color, SDL_Color bgColor);
void drawStatusBox(int *left, int *top, std::string label, std::string message, SDL_Color color); void drawStatusBox(int *left, int *top, char *label, char *message, SDL_Color color);
void drawStatus(); void drawStatus();
Aircraft *selectedAircraft; Aircraft *selectedAircraft;
Style style; Style style;
public:
int screenDist(float d);
void pxFromLonLat(float *dx, float *dy, float lon, float lat);
void latLonFromScreenCoords(float *lat, float *lon, int x, int y);
void screenCoords(int *outX, int *outY, float dx, float dy);
int outOfBounds(int x, int y);
int outOfBounds(int x, int y, int left, int top, int right, int bottom);
void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeColor);
void drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor);
void drawTrails(int left, int top, int right, int bottom);
void drawScaleBars();
void drawLinesRecursive(QuadTree *tree, float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, SDL_Color color);
void drawLines(int left, int top, int right, int bottom, int bailTime);
void drawPlaceNames();
void drawGeography();
void drawSignalMarks(Aircraft *p, int x, int y);
void drawPlaneText(Aircraft *p);
float resolveLabelConflicts();
void drawPlanes();
void animateCenterAbsolute(float x, float y);
void moveCenterAbsolute(float x, float y);
void moveCenterRelative(float dx, float dy);
void zoomMapToTarget();
void moveMapToTarget();
void drawMouse();
void drawClick();
void registerClick(int tapcount, int x, int y);
void registerMouseMove(int x, int y);
void draw();
void SDL_init();
void font_init();
View(AppData *appData);
~View();
////////////////
bool metric;
bool fps;
float maxDist;
float currentMaxDist; float currentMaxDist;
float centerLon;
float centerLat;
float mapTargetMaxDist;
float mapTargetLat; float mapTargetLat;
float mapTargetLon; float mapTargetLon;
int mapMoved;
int mapRedraw; int mapRedraw;
int mapAnimating;
float currentLon; float currentLon;
float currentLat; float currentLat;
std::chrono::high_resolution_clock::time_point lastFrameTime; uint64_t lastFrameTime;
std::chrono::high_resolution_clock::time_point drawStartTime; uint64_t drawStartTime;
std::chrono::high_resolution_clock::time_point lastRedraw;
Map map; Map map;
std::vector<Tile> tiles;
int screen_upscale;
int screen_uiscale;
int screen_width;
int screen_height;
int screen_depth;
int fullscreen;
int screen_index;
SDL_Window *window; SDL_Window *window;
SDL_Renderer *renderer; SDL_Renderer *renderer;
@ -179,6 +107,59 @@ class View {
int labelFontHeight; int labelFontHeight;
int messageFontWidth; int messageFontWidth;
int messageFontHeight; int messageFontHeight;
int screenDist(float d);
void pxFromLonLat(float *dx, float *dy, float lon, float lat);
void lonLatFromScreenCoords(float *lon, float *lat, int x, int y);
void screenCoords(int *outX, int *outY, float dx, float dy);
int outOfBounds(int x, int y);
void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeColor);
void drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor);
void drawTrail(Aircraft *p);
void drawScaleBars();
void drawLines(float screen_lat_min, float screen_lat_max, float screen_lon_min, float screen_lon_max, int bailTime);
void drawGeography(int left, int top, int right, int bottom, int bailTime);
void drawSignalMarks(Aircraft *p, int x, int y);
void drawPlaneText(Aircraft *p);
void drawSelectedAircraftText(Aircraft *p);
void resolveLabelConflicts();
void drawPlanes();
void drawTiles();
void animateCenterAbsolute(float x, float y);
void moveCenterAbsolute(float x, float y);
void zoomMapToTarget();
void moveMapToTarget();
void drawMouse();
void drawClick();
public:
void registerClick(int tapcount, int x, int y);
void registerMouseMove(int x, int y);
void draw();
void SDL_init();
void font_init();
void moveCenterRelative(float dx, float dy);
View(AppData *appData);
~View();
bool metric;
float centerLon;
float centerLat;
float maxDist;
int mapMoved;
float mapTargetMaxDist;
int screen_upscale;
int screen_uiscale;
int screen_width;
int screen_height;
int screen_depth;
int fullscreen;
int screen_index;
}; };
#endif #endif

6
anet.c
View file

@ -122,7 +122,7 @@ int anetResolve(char *err, char *host, char *ipbuf)
struct sockaddr_in sa; struct sockaddr_in sa;
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
if (inet_aton(host, &sa.sin_addr) == 0) { if (inet_aton(host, (in_addr*)&sa.sin_addr) == 0) {
struct hostent *he; struct hostent *he;
he = gethostbyname(host); he = gethostbyname(host);
@ -168,7 +168,7 @@ static int anetTcpGenericConnect(char *err, char *addr, int port, int flags)
memset(&sa,0,sizeof(sa)); memset(&sa,0,sizeof(sa));
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons((uint16_t)port); sa.sin_port = htons((uint16_t)port);
if (inet_aton(addr, &sa.sin_addr) == 0) { if (inet_aton(addr, (in_addr*)&sa.sin_addr) == 0) {
struct hostent *he; struct hostent *he;
he = gethostbyname(addr); he = gethostbyname(addr);
@ -271,7 +271,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_port = htons((uint16_t)port); sa.sin_port = htons((uint16_t)port);
sa.sin_addr.s_addr = htonl(INADDR_ANY); sa.sin_addr.s_addr = htonl(INADDR_ANY);
if (bindaddr && inet_aton(bindaddr, &sa.sin_addr) == 0) { if (bindaddr && inet_aton(bindaddr, (in_addr*)&sa.sin_addr) == 0) {
anetSetError(err, "invalid bind address"); anetSetError(err, "invalid bind address");
close(s); close(s);
return ANET_ERR; return ANET_ERR;

9
anet.h
View file

@ -39,10 +39,6 @@
#define AF_LOCAL AF_UNIX #define AF_LOCAL AF_UNIX
#endif #endif
#ifdef __cplusplus
extern "C" {
#endif
int anetTcpConnect(char *err, char *addr, int port); int anetTcpConnect(char *err, char *addr, int port);
int anetTcpNonBlockConnect(char *err, char *addr, int port); int anetTcpNonBlockConnect(char *err, char *addr, int port);
int anetUnixConnect(char *err, char *path); int anetUnixConnect(char *err, char *path);
@ -60,9 +56,4 @@ int anetTcpKeepAlive(char *err, int fd);
int anetPeerToString(int fd, char *ip, int *port); int anetPeerToString(int fd, char *ip, int *port);
int anetSetSendBuffer(char *err, int fd, int buffsize); int anetSetSendBuffer(char *err, int fd, int buffsize);
#ifdef __cplusplus
}
#endif
#endif #endif

1
drawPolys.REMOVED.git-id Normal file
View file

@ -0,0 +1 @@
85c850fc7f07d0cf30352d3385c7a2aeb57fecf3

View file

@ -428,7 +428,7 @@ extern "C" {
// Functions exported from mode_ac.c // Functions exported from mode_ac.c
// //
int detectModeA (uint16_t *m, struct modesMessage *mm); int detectModeA (uint16_t *m, struct modesMessage *mm);
//void decodeModeAMessage(Modes *modes, struct modesMessage *mm, int ModeA); void decodeModeAMessage(Modes *modes, struct modesMessage *mm, int ModeA);
int ModeAToModeC (unsigned int ModeA); int ModeAToModeC (unsigned int ModeA);
// //
@ -449,7 +449,7 @@ struct aircraft* interactiveReceiveData(Modes *modes, struct modesMessage *mm);
void interactiveShowData(void); void interactiveShowData(void);
void interactiveRemoveStaleAircrafts(Modes *modes); void interactiveRemoveStaleAircrafts(Modes *modes);
int decodeBinMessage (Modes *modes, struct client *c, char *p); int decodeBinMessage (Modes *modes, struct client *c, char *p);
// struct aircraft *interactiveFindAircraft(uint32_t addr); struct aircraft *interactiveFindAircraft(uint32_t addr);
struct stDF *interactiveFindDF (uint32_t addr); struct stDF *interactiveFindDF (uint32_t addr);
// //

View file

@ -1,61 +0,0 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1739758141,
"narHash": "sha256-uq6A2L7o1/tR6VfmYhZWoVAwb3gTy7j4Jx30MIrH0rE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c618e28f70257593de75a7044438efc1c1fc0791",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View file

@ -1,50 +0,0 @@
{
# TODO desc
description = "viz1090";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};
in rec
{
# Nix formatter, run using `$ nix fmt`
formatter = pkgs.alejandra;
# Exports the package
# Build with `$ nix build`
packages.viz1090 = pkgs.callPackage ./nix/viz1090.nix {inherit self system;};
packages.viz1090-mapdata = pkgs.callPackage ./nix/viz1090-mapdata.nix {};
packages.default = packages.viz1090;
# Creates a shell with the necessary dependencies
# Enter using `$ nix develop`
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
rtl-sdr-librtlsdr
SDL2
SDL2_ttf
SDL2_gfx
gdal
python3
python312Packages.pip
python312Packages.shapely
python312Packages.fiona
python312Packages.tqdm
unzip
python312Packages.requests
git
];
};
});
}

Binary file not shown.

View file

@ -0,0 +1 @@
eafa3a6e408def39bcd002f60a6d9a9810d54234

Binary file not shown.

View file

@ -0,0 +1 @@
9dc2aed0a76993fd7ba9c28e0f55fce873a8c790

View file

@ -1,24 +1,5 @@
#!/bin/bash #!/bin/bash
mkdir -p mapdata wget -O all.svg.gz https://www.mccurley.org/svg/data/allzips.svgz
pushd mapdata > /dev/null gunzip all.svg.gz
python3 mapconverter.py all.svg
wget --no-verbose https://naciscdn.org/naturalearth/10m/cultural/ne_10m_admin_1_states_provinces.zip
wget --no-verbose https://naciscdn.org/naturalearth/10m/cultural/ne_10m_populated_places.zip
wget --no-verbose https://naciscdn.org/naturalearth/10m/cultural/ne_10m_airports.zip
#this may not be up to date
wget --no-verbose https://opendata.arcgis.com/datasets/4d8fa46181aa470d809776c57a8ab1f6_0.zip
for file in *.zip; do
unzip -o "${file}"
rm "${file}"
done
popd > /dev/null
python3 mapconverter.py \
--mapfile mapdata/ne_10m_admin_1_states_provinces.shp \
--mapnames mapdata/ne_10m_populated_places.shp \
--airportfile mapdata/Runways.shp \
--airportnames mapdata/ne_10m_airports.shp

6
mapbox_testing Normal file
View file

@ -0,0 +1,6 @@
curl "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8/8/40/89.mvt?access_token=pk.eyJ1Ijoibm1hdHN1ZGEiLCJhIjoiY2swazhrdGNjMGZ3NzNvcmE0OGxoaGd2byJ9.PAYHqO3any_6vLdjQ44RGw"
mapbox://styles/nmatsuda/ck0k7rvvt3rkv1cq6l74wjda2
47.695,-123.489

View file

@ -1,133 +1,58 @@
import fiona from lxml import etree as ElementTree
from shapely.geometry import shape
import numpy as np import numpy as np
import sys
from tqdm import tqdm from tqdm import tqdm
import zipfile
from io import BytesIO
#from urllib.request import urlopen
import requests
import argparse
import os
def convertLinestring(linestring): filename = sys.argv[1]
outlist = []
pointx = linestring.coords.xy[0] if(len(filename) == 0):
pointy = linestring.coords.xy[1] print("No input filename given")
exit()
for j in range(len(pointx)): parser = ElementTree.XMLParser(recover=True)
outlist.extend([float(pointx[j]),float(pointy[j])]) tree = ElementTree.parse(filename, parser)
polys = tree.xpath('//polygon')
outlist.extend([0,0]) bin_file = open("mapdata.bin", "wb")
return outlist
def extractLines(shapefile, tolerance): outlist = []
print("Extracting map lines")
outlist = []
for i in tqdm(range(len(shapefile))):
if(tolerance > 0):
simplified = shape(shapefile[i]['geometry']).simplify(tolerance, preserve_topology=False)
else:
simplified =shape(shapefile[i]['geometry'])
if(simplified.geom_type == "LineString"):
outlist.extend(convertLinestring(simplified))
elif(simplified.geom_type == "MultiPolygon" or simplified.geom_type == "Polygon"):
if(simplified.boundary.geom_type == "MultiLineString"):
for boundary in simplified.boundary.geoms:
outlist.extend(convertLinestring(boundary))
else:
outlist.extend(convertLinestring(simplified.boundary))
else:
print("Unsupported type: " + simplified.geom_type)
resolution = 250
print("Reading points")
for i in tqdm(range(len(polys))):
#for i in range(40):
p = polys[i]
currentPoints = (p.attrib['points']).replace(","," ").split()
return outlist if(len(currentPoints) == 14): #remove little circles in the McCurley maps
continue
parser = argparse.ArgumentParser(description='viz1090 Natural Earth Data Map Converter') prevx = 0
parser.add_argument("--mapfile", type=str, help="shapefile for main map") prevy = 0
parser.add_argument("--mapnames", type=str, help="shapefile for map place names")
parser.add_argument("--airportfile", type=str, help="shapefile for airport runway outlines")
parser.add_argument("--airportnames", type=str, help="shapefile for airport IATA names")
parser.add_argument("--minpop", default=100000, type=int, help="map simplification tolerance")
parser.add_argument("--tolerance", default=0.001, type=float, help="map simplification tolerance")
args = parser.parse_args() temp = []
# mapfile for i in range(int(len(currentPoints)/2)):
if args.mapfile is not None: #currentPoints[2 * i + 0] = "%.*f" % (precision, float(currentPoints[2 * i + 0]))
shapefile = fiona.open(args.mapfile) #currentPoints[2 * i + 1] = "%.*f" % (precision, float(currentPoints[2 * i + 1]))
outlist = extractLines(shapefile, args.tolerance) currentPoints[2 * i + 0] = float(int(resolution * float(currentPoints[2 * i + 0]))) / resolution
currentPoints[2 * i + 1] = float(int(resolution * float(currentPoints[2 * i + 1]))) / resolution
bin_file = open("mapdata.bin", "wb") if(currentPoints[2 * i + 0] != prevx or currentPoints[2 * i + 1] != prevy):
np.asarray(outlist).astype(np.single).tofile(bin_file) temp.extend([currentPoints[2 * i + 0],currentPoints[2 * i + 1]])
bin_file.close()
print("Wrote %d points" % (len(outlist) / 2)) prevx = currentPoints[2 * i + 0]
prevy = currentPoints[2 * i + 1]
# mapnames if(len(currentPoints) > 6): #must be at least a triangle
bin_file = open("mapnames", "w") outlist.extend(temp)
#outlist.extend([temp[0],temp[1]])
if args.mapnames is not None: outlist.extend(["0","0"])
shapefile = fiona.open(args.mapnames)
count = 0
for i in tqdm(range(len(shapefile))):
xcoord = shapefile[i]['geometry']['coordinates'][0]
ycoord = shapefile[i]['geometry']['coordinates'][1]
pop = shapefile[i]['properties']['POP_MIN']
name = shapefile[i]['properties']['NAME']
if pop > args.minpop:
outstring = "{0} {1} {2}\n".format(xcoord, ycoord, name)
bin_file.write(outstring)
count = count + 1
bin_file.close()
print("Wrote %d place names" % count)
#airportfile
if args.airportfile is not None:
shapefile = fiona.open(args.airportfile)
outlist = extractLines(shapefile, 0)
bin_file = open("airportdata.bin", "wb")
np.asarray(outlist).astype(np.single).tofile(bin_file)
bin_file.close()
print("Wrote %d points" % (len(outlist) / 2))
#airportnames np.asarray(outlist).astype(np.single).tofile(bin_file)
if args.airportnames is not None: bin_file.close()
bin_file = open("airportnames", "w")
shapefile = fiona.open(args.airportnames)
count = 0
for i in tqdm(range(len(shapefile))):
xcoord = shapefile[i]['geometry']['coordinates'][0]
ycoord = shapefile[i]['geometry']['coordinates'][1]
name = shapefile[i]['properties']['iata_code']
outstring = "{0} {1} {2}\n".format(xcoord, ycoord, name)
bin_file.write(outstring)
count = count + 1
bin_file.close()
print("Wrote %d airport names" % count)
print("Wrote %d points" % (len(outlist) / 2))

View file

@ -210,7 +210,7 @@ int fixBitErrors(unsigned char *msg, int bits, int maxfix, char *fixedbits) {
int bitpos, offset, res, i; int bitpos, offset, res, i;
memset(&ei, 0, sizeof(struct errorinfo)); memset(&ei, 0, sizeof(struct errorinfo));
ei.syndrome = modesChecksum(msg, bits); ei.syndrome = modesChecksum(msg, bits);
pei = bsearch(&ei, bitErrorTable, NERRORINFO, pei = (errorinfo*)bsearch(&ei, bitErrorTable, NERRORINFO,
sizeof(struct errorinfo), cmpErrorInfo); sizeof(struct errorinfo), cmpErrorInfo);
if (pei == NULL) { if (pei == NULL) {
return 0; // No syndrome found return 0; // No syndrome found

View file

@ -1,70 +0,0 @@
{
lib,
pkgs,
stdenv,
fetchFromGitea,
}: let
runways = fetchTarball {
url = "https://opendata.arcgis.com/datasets/4d8fa46181aa470d809776c57a8ab1f6_0.zip";
sha256 = "sha256:1ivwx8glk8yk68nmqz467yzvlb3l66l1s3ibmd9p41wz737lmz88";
};
provinces = fetchTarball {
url = "https://naciscdn.org/naturalearth/10m/cultural/ne_10m_admin_1_states_provinces.zip";
sha256 = "sha256:06ai02b8rfsfzpa0gq4nsg29lxvwy4zvjw44099hc78vr7dkfsdp";
};
places = fetchTarball {
url = "https://naciscdn.org/naturalearth/10m/cultural/ne_10m_populated_places.zip";
sha256 = "sha256:1dhh569520f02yml1m5zp2znjv85cqbccl4nvpmigynxd37kid3j";
};
airports = fetchTarball {
url = "https://naciscdn.org/naturalearth/10m/cultural/ne_10m_airports.zip";
sha256 = "sha256:0893zg63ygr2l2d1wpyigls1syfkryjlygvnbbjikpqk5i5cwr56";
};
in
stdenv.mkDerivation rec {
pname = "viz1090-mapdata";
version = "0.1.0";
src = fetchFromGitea {
domain = "git.vulpecula.zone";
owner = "tasiaiso";
repo = pname;
rev = "d1f53019b22a9e605506bed90fcffcdc5f7e6186";
hash = "sha256-gtv0u7o+5fqVgA0CHDWdZr0h9A1Nbky1+okHvSv1cVU=";
};
nativeBuildInputs = with pkgs; [
python3
python312Packages.pip
python312Packages.shapely
python312Packages.fiona
python312Packages.tqdm
python312Packages.requests
];
buildPhase = ''
mkdir -p mapdata
cp ${runways}/* mapdata
cp ${provinces}/* mapdata
cp ${places}/* mapdata
cp ${airports}/* mapdata
python3 mapconverter.py \
--mapfile mapdata/ne_10m_admin_1_states_provinces.shp \
--mapnames mapdata/ne_10m_populated_places.shp \
--airportfile mapdata/Runways.shp \
--airportnames mapdata/ne_10m_airports.shp
'';
installPhase = ''
mkdir -p $out $out/font
cp airportdata.bin $out
cp airportnames $out
cp mapdata.bin $out
cp mapnames $out
cp font/* $out/font
'';
}

View file

@ -1,116 +0,0 @@
{
lib,
pkgs,
stdenv,
fetchFromGitea,
self,
system,
}: let
viz1090-mapdata = self.packages.${system}.viz1090-mapdata;
in
stdenv.mkDerivation rec {
pname = "viz1090";
version = "0.1.0";
src = fetchFromGitea {
domain = "git.vulpecula.zone";
owner = "tasiaiso";
repo = pname;
rev = "1922324b40f84fd449cec3fbfdade8aa33597bf6";
hash = "sha256-bPVFKbGtPXOitzzHb3yJ6XW3fRh8PF/7kfP7EJkJX3c=";
};
nativeBuildInputs = with pkgs; [
rtl-sdr-librtlsdr
SDL2
SDL2_ttf
SDL2_gfx
gdal
git
];
buildInputs = [
viz1090-mapdata
];
buildPhase = ''
echo "diff --git a/Makefile b/Makefile
index 5e60779..d5b30ab 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
# sure that the variable PREFIX is defined, e.g. make PREFIX=/usr/local
#
-CXXFLAGS=-O2 -std=c++11 -g
+CXXFLAGS=-O2 -std=c++11 -g -I ${pkgs.SDL2.dev}/include/SDL2/
LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -g
CXX=g++
diff --git a/Map.cpp b/Map.cpp
index cd798ec..c5736bd 100644
--- a/Map.cpp
+++ b/Map.cpp
@@ -189,7 +189,7 @@ std::vector<Line*> Map::getLines(float screen_lat_min, float screen_lat_max, flo
Map::Map() {
FILE *fileptr;
- if((fileptr = fopen(\"mapdata.bin\", \"rb\"))) {
+ if((fileptr = fopen(\"${viz1090-mapdata}/mapdata.bin\", \"rb\"))) {
fseek(fileptr, 0, SEEK_END);
@@ -255,7 +255,7 @@ Map::Map() {
//
- if((fileptr = fopen(\"airportdata.bin\", \"rb\"))) {
+ if((fileptr = fopen(\"${viz1090-mapdata}/airportdata.bin\", \"rb\"))) {
fseek(fileptr, 0, SEEK_END);
airportPoints_count = ftell(fileptr) / sizeof(float);
rewind(fileptr);
@@ -350,7 +350,7 @@ Map::Map() {
infile.close();
- infile.open(\"airportnames\");
+ infile.open(\"${viz1090-mapdata}/airportnames\");
while (std::getline(infile, line))
diff --git a/View.cpp b/View.cpp
index d5dace7..90f6165 100644
--- a/View.cpp
+++ b/View.cpp
@@ -174,13 +174,13 @@ void View::closeFont(TTF_Font *font)
void View::font_init() {
- mapFont = loadFont(\"font/TerminusTTF-4.46.0.ttf\", 12 * screen_uiscale);
- mapBoldFont = loadFont(\"font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
+ mapFont = loadFont(\"${viz1090-mapdata}/font/TerminusTTF-4.46.0.ttf\", 12 * screen_uiscale);
+ mapBoldFont = loadFont(\"${viz1090-mapdata}/font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
- listFont = loadFont(\"font/TerminusTTF-4.46.0.ttf\", 12 * screen_uiscale);
+ listFont = loadFont(\"${viz1090-mapdata}/font/TerminusTTF-4.46.0.ttf\", 12 * screen_uiscale);
- messageFont = loadFont(\"font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
- labelFont = loadFont(\"font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
+ messageFont = loadFont(\"${viz1090-mapdata}/font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
+ labelFont = loadFont(\"${viz1090-mapdata}/font/TerminusTTF-Bold-4.46.0.ttf\", 12 * screen_uiscale);
mapFontWidth = 5 * screen_uiscale;
mapFontHeight = 12 * screen_uiscale;
" | git apply -
cat Map.cpp | grep mapdata
make -j $NIX_BUILD_CORES
'';
installPhase = ''
mkdir -p $out/bin
cp -v viz1090 $out/bin
'';
}

1
out.prof.REMOVED.git-id Normal file
View file

@ -0,0 +1 @@
34c8403286643597ad193fa68d13266d3a5f07a6

234
view1090.bak Normal file
View file

@ -0,0 +1,234 @@
// view1090, a Mode S messages viewer for dump1090 devices.
//
// Copyright (C) 2014 by Malcolm Robb <Support@ATTAvionics.com>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "view1090.h"
#include "structs.h"
#include "AircraftData.h"
int go = 1;
AppData appData;
Style style;
//
// ============================= Utility functions ==========================
//
void sigintHandler(int dummy) {
NOTUSED(dummy);
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
AircraftData.modes.exit = 1; // Signal to threads that we are done
}
//
//=========================================================================
//
// Set up data connection
int setupConnection(struct client *c) {
int fd;
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
if ((fd = anetTcpConnect(AircraftData.modes.aneterr, View1090.net_input_beast_ipaddr, AircraftData.modes.net_input_beast_port)) != ANET_ERR) {
anetNonBlock(AircraftData.modes.aneterr, fd);
//
// Setup a service callback client structure for a beast binary input (from dump1090)
// This is a bit dodgy under Windows. The fd parameter is a handle to the internet
// socket on which we are receiving data. Under Linux, these seem to start at 0 and
// count upwards. However, Windows uses "HANDLES" and these don't nececeriy start at 0.
// dump1090 limits fd to values less than 1024, and then uses the fd parameter to
// index into an array of clients. This is ok-ish if handles are allocated up from 0.
// However, there is no gaurantee that Windows will behave like this, and if Windows
// allocates a handle greater than 1024, then dump1090 won't like it. On my test machine,
// the first Windows handle is usually in the 0x54 (84 decimal) region.
c->next = NULL;
c->buflen = 0;
c->fd =
c->service =
AircraftData.modes.bis = fd;
AircraftData.modes.clients = c;
}
return fd;
}
//
// ================================ Main ====================================
//
void showHelp(void) {
printf(
"-----------------------------------------------------------------------------\n"
"| view1090 dump1090 Viewer Ver : "MODES_DUMP1090_VERSION " |\n"
"-----------------------------------------------------------------------------\n"
"--server <IPv4/hosname> TCP Beast output listen IPv4 (default: 127.0.0.1)\n"
"--port <port> TCP Beast output listen port (default: 30005)\n"
"--lat <latitude> Reference/receiver latitide for surface posn (opt)\n"
"--lon <longitude> Reference/receiver longitude for surface posn (opt)\n"
"--metric Use metric units (meters, km/h, ...)\n"
"--help Show this help\n"
"--uiscale <factor> UI global scaling (default: 1)\n"
"--screensize <width> <height> Set frame buffer resolution (default: screen resolution)\n"
"--fullscreen Start fullscreen\n"
);
}
#ifdef _WIN32
void showCopyright(void) {
uint64_t llTime = time(NULL) + 1;
printf(
"-----------------------------------------------------------------------------\n"
"| view1090 ModeS Viewer Ver : " MODES_DUMP1090_VERSION " |\n"
"-----------------------------------------------------------------------------\n"
"\n"
" Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.com>\n"
" Copyright (C) 2014 by Malcolm Robb <support@attavionics.com>\n"
" Copyright (C) 2020 by Nathan Matsuda <info@nathanmatsuda.com>\n"
"\n"
" All rights reserved.\n"
"\n"
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
" ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
" HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
"\n"
" For further details refer to <https://github.com/MalcolmRobb/dump1090>\n"
"\n"
);
// delay for 1 second to give the user a chance to read the copyright
while (llTime >= time(NULL)) {}
}
#endif
//
//=========================================================================
//
int main(int argc, char **argv) {
int j, fd;
struct client *c;
char pk_buf[8];
AircraftData aircraftData;
signal(SIGINT, sigintHandler); // Define Ctrl/C handler (exit program)
aircraftData.initialize();
// Parse the command line options
for (j = 1; j < argc; j++) {
int more = ((j + 1) < argc); // There are more arguments
if (!strcmp(argv[j],"--net-bo-port") && more) {
AircraftData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--port") && more) {
AircraftData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--net-bo-ipaddr") && more) {
strcpy(View1090.net_input_beast_ipaddr, argv[++j]);
} else if (!strcmp(argv[j],"--server") && more) {
strcpy(View1090.net_input_beast_ipaddr, argv[++j]);
} else if (!strcmp(argv[j],"--lat") && more) {
AircraftData.modes.fUserLat = atof(argv[++j]);
appData.centerLat = AircraftData.modes.fUserLat;
} else if (!strcmp(argv[j],"--lon") && more) {
AircraftData.modes.fUserLon = atof(argv[++j]);
appData.centerLon = AircraftData.modes.fUserLon;
} else if (!strcmp(argv[j],"--metric")) {
AircraftData.modes.metric = 1;
} else if (!strcmp(argv[j],"--fullscreen")) {
appData.fullscreen = 1;
} else if (!strcmp(argv[j],"--uiscale") && more) {
appData.screen_uiscale = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--screensize") && more) {
appData.screen_width = atoi(argv[++j]);
appData.screen_height = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--help")) {
showHelp();
exit(0);
} else {
fprintf(stderr, "Unknown or not enough arguments for option '%s'.\n\n", argv[j]);
showHelp();
exit(1);
}
}
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
c = (struct client *) malloc(sizeof(*c));
while(1) {
if ((fd = setupConnection(c)) == ANET_ERR) {
fprintf(stderr, "Waiting on %s:%d\n", View1090.net_input_beast_ipaddr, AircraftData.modes.net_input_beast_port);
sleep(1);
} else {
break;
}
}
int go;
init("sdl1090");
atexit(cleanup);
go = 1;
while (go == 1)
{
getInput();
interactiveRemoveStaleAircrafts();
draw();
if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) {
free(c);
usleep(1000000);
c = (struct client *) malloc(sizeof(*c));
fd = setupConnection(c);
continue;
}
modesReadFromClient(c,"",decodeBinMessage);
//usleep(10000);
}
// The user has stopped us, so close any socket we opened
if (fd != ANET_ERR)
{close(fd);}
return (0);
}
//
//=========================================================================
//

149
view1090.dsp Normal file
View file

@ -0,0 +1,149 @@
# Microsoft Developer Studio Project File - Name="view1090" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=view1090 - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "view1090.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "view1090.mak" CFG="view1090 - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "view1090 - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "view1090 - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "view1090 - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I ".\pthreads\." /I ".\rtlsdr\." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /subsystem:console /machine:I386
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "view1090 - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".\pthreads\." /I ".\rtlsdr\." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "view1090 - Win32 Release"
# Name "view1090 - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\anet.c
# End Source File
# Begin Source File
SOURCE=.\interactive.c
# End Source File
# Begin Source File
SOURCE=.\mode_ac.c
# End Source File
# Begin Source File
SOURCE=.\mode_s.c
# End Source File
# Begin Source File
SOURCE=.\net_io.c
# End Source File
# Begin Source File
SOURCE=.\view1090.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\dump1090.h
# End Source File
# Begin Source File
SOURCE=.\view1090.h
# End Source File
# Begin Source File
SOURCE=.\winstubs.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Group "Library Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\pthreads\pthreadVC2.lib
# End Source File
# Begin Source File
SOURCE=.\rtlsdr\rtlsdr.lib
# End Source File
# End Group
# End Target
# End Project

View file

@ -1,8 +1,8 @@
// viz1090, a vizualizer for dump1090 ADSB output // Adapted from:
// view1090, a Mode S messages viewer for dump1090 devices.
//
// Copyright (C) 2014 by Malcolm Robb <Support@ATTAvionics.com>
// //
// Copyright (C) 2020, Nathan Matsuda <info@nathanmatsuda.com>
// Copyright (C) 2014, Malcolm Robb <Support@ATTAvionics.com>
// Copyright (C) 2012, Salvatore Sanfilippo <antirez at gmail dot com>
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -48,17 +48,16 @@ void showHelp(void) {
"-----------------------------------------------------------------------------\n" "-----------------------------------------------------------------------------\n"
"| viz1090 ADSB Viewer Ver : 0.1 |\n" "| viz1090 ADSB Viewer Ver : 0.1 |\n"
"-----------------------------------------------------------------------------\n" "-----------------------------------------------------------------------------\n"
"--fps Show current framerate\n" "--server <IPv4/hosname> TCP Beast output listen IPv4 (default: 127.0.0.1)\n"
"--fullscreen Start fullscreen\n" "--port <port> TCP Beast output listen port (default: 30005)\n"
"--help Show this help\n" "--lat <latitude> Latitide in degrees\n"
"--lat <latitude> Latitude in degrees\n" "--lon <longitude> Longitude in degrees\n"
"--lon <longitude> Longitude in degrees\n" "--metric Use metric units\n"
"--metric Use metric units\n" "--help Show this help\n"
"--port <port> TCP Beast output listen port (default: 30005)\n" "--uiscale <factor> UI global scaling (default: 1)\n"
"--server <IPv4/hosname> TCP Beast output listen IPv4 (default: 127.0.0.1)\n" "--screensize <width> <height> Set frame buffer resolution (default: screen resolution)\n"
"--screensize <width> <height> Set frame buffer resolution (default: screen resolution)\n" "--screenindex <i> Set the index of the display to use (default: 0)\n"
"--screenindex <i> Set the index of the display to use (default: 0)\n" "--fullscreen Start fullscreen\n"
"--uiscale <factor> UI global scaling (default: 1)\n"
); );
} }
@ -95,8 +94,6 @@ int main(int argc, char **argv) {
view.centerLon = appData.modes.fUserLon; view.centerLon = appData.modes.fUserLon;
} else if (!strcmp(argv[j],"--metric")) { } else if (!strcmp(argv[j],"--metric")) {
view.metric = 1; view.metric = 1;
} else if (!strcmp(argv[j],"--fps")) {
view.fps = 1;
} else if (!strcmp(argv[j],"--fullscreen")) { } else if (!strcmp(argv[j],"--fullscreen")) {
view.fullscreen = 1; view.fullscreen = 1;
} else if (!strcmp(argv[j],"--screenindex")) { } else if (!strcmp(argv[j],"--screenindex")) {
@ -118,6 +115,9 @@ int main(int argc, char **argv) {
int go; int go;
appData.connect();
view.SDL_init(); view.SDL_init();
view.font_init(); view.font_init();
@ -125,7 +125,6 @@ int main(int argc, char **argv) {
while (go == 1) while (go == 1)
{ {
appData.connect();
input.getInput(); input.getInput();
appData.update(); appData.update();
view.draw(); view.draw();

111
winstubs.h Normal file
View file

@ -0,0 +1,111 @@
// dump1090, a Mode S messages decoder for RTLSDR devices.
//
// Copyright (C) 2014 by Malcolm Robb <support@attavionics.com>
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This file provides basic Windows implementation of Linux specific functions
// used in the dump1090 project. This allows dump1090 to be compiled and debugged
// using Microsoft Visual C++ 6.0
//
// Note that not all functions actually provide equivalent functionality to their
// Linux equivalents. They are simply stubs to allow the project to compile.
//
#ifndef __WINSTUBS_H
#define __WINSTUBS_H
#include <winsock2.h>
#include <windows.h>
#include <basetsd.h>
typedef UCHAR uint8_t;
typedef USHORT uint16_t;
typedef UINT32 uint32_t;
typedef UINT64 uint64_t;
typedef UINT32 mode_t;
typedef long ssize_t;
typedef int socklen_t;
#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/stat.h>
#include <signal.h>
#include <io.h>
#include <fcntl.h>
#define M_PI 3.14159265358979323846
#include <math.h>
#include <pthread.h>
#ifdef __cplusplus
extern "C" {
#endif
//Functions not included in the MSVC maths library. This will do for our use.
_inline double round(double d) {return floor(d + 0.5);}
_inline double trunc(double d) {return (d>0) ? floor(d):ceil(d) ;}
//usleep works in microseconds, and isn't supported in Windows. This will do for our use.
_inline void usleep(UINT32 ulSleep) {Sleep(ulSleep/1000);}
_inline uint64_t strtoll(const char *p, void *e, UINT32 base) {return _atoi64(p);}
_inline int inet_aton(const char * cp, DWORD * ulAddr) { *ulAddr = inet_addr(cp); return (INADDR_NONE != *ulAddr);}
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
_inline void cls() {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOut, &csbi);
FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
SetConsoleCursorPosition(hStdOut, coord);
}
_inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
SYSTEMTIME stSystemTime;
GetLocalTime(&stSystemTime);
tv->tv_sec = stSystemTime.wSecond + (60 * (stSystemTime.wMinute + (60 * stSystemTime.wHour)));
tv->tv_usec = stSystemTime.wMilliseconds * 1000;
return 0;
}
#define STDIN_FILENO 0
#define EINPROGRESS WSAEINPROGRESS
#define EWOULDBLOCK WSAEWOULDBLOCK
#ifdef __cplusplus
}
#endif
#endif // __WINSTUBS_H