Compare commits

...

18 commits

Author SHA1 Message Date
nathan 0467c09598 removed rtlsdr dependency 2025-01-26 22:17:08 -08:00
nmatsuda 90bf09b331
added note about KMS vs FMKS 2024-06-04 16:40:14 -07:00
nmatsuda 71d9546124
added harfbuzz disable flag for SDL_TTF 2024-06-04 08:42:31 -07:00
nmatsuda 8c3ab912f6
Updated SDL build commands 2023-08-28 14:57:16 -07:00
nathan 0440a5c393 AppData handles source disconnect 2023-06-14 21:37:41 -07:00
nathan c80f55141c reverted to deleting stale trails 2023-05-31 17:12:26 -07:00
nathan 49fcc50a1d Merge branch 'volcano' of https://github.com/nmatsuda/viz1090 into volcano 2023-05-31 16:58:35 -07:00
nathan 26a6f001c9 fixed aircraft trail bug! 2023-05-31 16:58:22 -07:00
nmatsuda 2179ca7810
added notes for rebuilding SDL2 libraries 2023-03-30 22:14:10 -07:00
nathan cd80aec3ab in progress plane trail fade 2022-10-29 16:06:00 -07:00
nathan 4bcaa46c4e Merge branch 'volcano' of https://www.github.com/nmatsuda/viz1090 into volcano 2022-10-27 12:19:14 -07:00
nathan a003086fb2 added plane dissapearing animation 2022-10-27 12:18:47 -07:00
nmatsuda cf422f480d
added note about running viz1090 without X 2022-10-23 18:51:56 -07:00
nathan 66385a328f testing startup time optimizations 2022-10-23 11:34:22 -07:00
nathan 03fd9ec4df added startup status messages for connection and map loading 2022-10-21 17:37:39 -07:00
nathan e6e372c019 fixed framerate checks 2022-10-21 11:06:07 -07:00
nathan b7b5b69914 set up multiframerate for power saving but commented out. Discovered that thread sleep wasn't working, switched to SDL_Delay. added animated plane position updates 2022-10-19 22:11:44 -07:00
nathan 472aa85cb7 new lava color palette 2022-09-22 06:22:09 +01:00
21 changed files with 689 additions and 399 deletions

View file

@ -32,6 +32,24 @@
#include "Aircraft.h" #include "Aircraft.h"
#include "AircraftLabel.h" #include "AircraftLabel.h"
float Aircraft::getLastLon() {
if(lonHistory.size() > 1) {
return lonHistory.end()[-2];
}
}
float Aircraft::getLastLat() {
if(latHistory.size() > 1) {
return latHistory.end()[-2];
}
}
float Aircraft::getLastHeading() {
if(headingHistory.size() > 1) {
return headingHistory.end()[-2];
}
}
Aircraft::Aircraft(uint32_t addr) { Aircraft::Aircraft(uint32_t addr) {
this->addr = addr; this->addr = addr;
prev_seen = 0; prev_seen = 0;

View file

@ -39,6 +39,12 @@ class AircraftLabel;
class Aircraft { class Aircraft {
public: public:
float getLastLon();
float getLastLat();
float getLastHeading();
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

View file

@ -32,12 +32,12 @@ SDL_Rect AircraftLabel::getFullRect(int labelLevel) {
} }
if(labelLevel < 1) { if(labelLevel < 1) {
currentRect = altitudeLabel.getRect(); currentRect = altitudeLabel.getRect();
rect.w = std::max(rect.w,currentRect.w); rect.w = std::max(rect.w,currentRect.w);
rect.h += currentRect.h; rect.h += currentRect.h;
currentRect = speedLabel.getRect(); currentRect = speedLabel.getRect();
rect.w = std::max(rect.w,currentRect.w); rect.w = std::max(rect.w,currentRect.w);
rect.h += currentRect.h; rect.h += currentRect.h;
@ -132,20 +132,20 @@ float AircraftLabel::calculateDensity(Aircraft *check_p, int labelLevel) {
} }
void AircraftLabel::calculateForces(Aircraft *check_p) { void AircraftLabel::calculateForces(Aircraft *check_p) {
if(w == 0 || h == 0) { //if(w == 0 || h == 0) {
return; // return;
} // }
Aircraft *head = check_p; Aircraft *head = check_p;
int p_left = x; float p_left = static_cast<float>(x);
int p_right = x + w; float p_right = static_cast<float>(x + w);
int p_top = y; float p_top = static_cast<float>(y);
int p_bottom = y + h; float p_bottom = static_cast<float>(y + h);
float boxmid_x = static_cast<float>(p_left + p_right) / 2.0f; float boxmid_x = (p_left + p_right) / 2.0f;
float boxmid_y = static_cast<float>(p_top + p_bottom) / 2.0f; float boxmid_y = (p_top + p_bottom) / 2.0f;
float offset_x = boxmid_x - p->x; float offset_x = boxmid_x - p->x;
float offset_y = boxmid_y - p->y; float offset_y = boxmid_y - p->y;
@ -162,19 +162,19 @@ void AircraftLabel::calculateForces(Aircraft *check_p) {
// screen edge // screen edge
if(p_left < edge_margin) { if(p_left < edge_margin) {
ddx += boundary_force * static_cast<float>(edge_margin - p_left); ddx += boundary_force * (edge_margin - p_left);
} }
if(p_right > screen_width - edge_margin) { if(p_right > screen_width - edge_margin) {
ddx += boundary_force * static_cast<float>(screen_width - edge_margin - p_right); ddx += boundary_force * (screen_width - edge_margin - p_right);
} }
if(p_top < edge_margin) { if(p_top < edge_margin) {
ddy += boundary_force * static_cast<float>(edge_margin - p_top); ddy += boundary_force * (edge_margin - p_top);
} }
if(p_bottom > screen_height - edge_margin) { if(p_bottom > screen_height - edge_margin) {
ddy += boundary_force * static_cast<float>(screen_height - edge_margin - p_bottom); ddy += boundary_force * (screen_height - edge_margin - p_bottom);
} }
@ -194,17 +194,18 @@ void AircraftLabel::calculateForces(Aircraft *check_p) {
continue; continue;
} }
int check_left = check_p->label->x; float check_left = static_cast<float>(check_p->label->x);
int check_right = check_p->label->x + check_p->label->w; float check_right = static_cast<float>(check_p->label->x + check_p->label->w);
int check_top = check_p->label->y; float check_top = static_cast<float>(check_p->label->y);
int check_bottom = check_p->label->y + check_p->label->h; float check_bottom = static_cast<float>(check_p->label->y + check_p->label->h);
float icon_x = static_cast<float>(check_p->x); float icon_x = static_cast<float>(check_p->x);
float icon_y = static_cast<float>(check_p->y); float icon_y = static_cast<float>(check_p->y);
float checkboxmid_x = static_cast<float>(check_left + check_right) / 2.0f; 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 checkboxmid_y = static_cast<float>(check_top + check_bottom) / 2.0f;
/*
float offset_x = boxmid_x - checkboxmid_x; float offset_x = boxmid_x - checkboxmid_x;
float offset_y = boxmid_y - checkboxmid_y; float offset_y = boxmid_y - checkboxmid_y;
@ -213,16 +214,83 @@ void AircraftLabel::calculateForces(Aircraft *check_p) {
float x_mag = std::max(0.0f,(target_length_x - fabs(offset_x))); 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))); float y_mag = std::max(0.0f,(target_length_y - fabs(offset_y)));
*/
bool overlap = true;
if (p_left >= check_right + 10 || check_left >= p_right + 10)
overlap = false;
if (p_top >= check_bottom + 10|| check_top >= p_bottom + 10)
overlap = false;
if(overlap) {
float td = fabs(p_top - check_bottom);
float bd = fabs(p_bottom - check_top);
float ld = fabs(p_left - check_right);
float rd = fabs(p_right - check_left);
float x_mag, y_mag;
if(boxmid_y > checkboxmid_y) {
y_mag = check_bottom - p_top + 10;
} else {
y_mag = check_top - p_bottom - 10;
td = bd;
}
if(boxmid_x > checkboxmid_x) {
x_mag = check_right - p_left + 10;
} else {
x_mag = check_left - p_right - 10;
ld = rd;
}
if(td < ld) {
x_mag = 0;
} else {
y_mag = 0;
}
ddx += label_force * x_mag;
ddy += label_force * y_mag;
}
// stay at least label_dist away from other icons // stay at least label_dist away from other icons
if(p_right >= check_p->x && check_p->x >= p_left && p_bottom >= check_p->y && check_p->y >= p_top) {
float x_mag, y_mag;
if(boxmid_x - check_p->x > 0) {
x_mag = check_p->x - p_left + 10;
} else {
x_mag = check_p->x - p_right - 10;
}
if(boxmid_y - check_p->y > 0) {
y_mag = check_p->y - p_top + 10;
} else {
y_mag = check_p->y - p_bottom - 10;
}
ddx += icon_force * x_mag;
ddy += icon_force * y_mag;
}
/*
if(x_mag > 0 && y_mag > 0) { if(x_mag > 0 && y_mag > 0) {
ddx += sign(offset_x) * label_force * x_mag; ddx += sign(offset_x) * label_force * x_mag;
ddy += sign(offset_y) * label_force * y_mag; ddy += sign(offset_y) * label_force * y_mag;
} }
// stay at least icon_dist away from other icons */
// stay at least icon_dist away from other icons
/*
offset_x = boxmid_x - check_p->x; offset_x = boxmid_x - check_p->x;
offset_y = boxmid_y - check_p->y; offset_y = boxmid_y - check_p->y;
@ -237,9 +305,10 @@ void AircraftLabel::calculateForces(Aircraft *check_p) {
ddy += sign(offset_y) * icon_force * y_mag; ddy += sign(offset_y) * icon_force * y_mag;
} }
*/
all_x += sign(boxmid_x - checkboxmid_x); all_x += sign(boxmid_x - checkboxmid_x);
all_y += sign(boxmid_y - checkboxmid_y); all_y += sign(boxmid_y - checkboxmid_y);
count++; count++;
check_p = check_p -> next; check_p = check_p -> next;
@ -250,34 +319,65 @@ void AircraftLabel::calculateForces(Aircraft *check_p) {
ddy += density_force * all_y / count; ddy += density_force * all_y / count;
// char buff[100]; // char buff[100];
// snprintf(buff, sizeof(buff), "%2.2f", labelLevel); // snprintf(buff, sizeof(buff), "l:%2.2f d:%2.2f", labelLevel, calculateDensity(head, labelLevel));
// debugLabel.setText(buff); // debugLabel.setText(buff);
float density_mult = 0.5f; float density_mult = 0.15f;
float level_rate = 0.25f; float level_rate = 0.25f;
if(elapsed(lastLevelChange) > 1000.0) { float randtime = 5000.0f + 5000.0f * static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
if(labelLevel < 0.8f * density_mult * calculateDensity(head, labelLevel + 1)) { if(elapsed(lastLevelChange) > randtime) {
if(labelLevel <= 2) { if(labelLevel < -1.2f + density_mult * calculateDensity(head, labelLevel - 1)) {
labelLevel += level_rate; if(labelLevel <= 2) {
lastLevelChange = now(); if(ceil(labelLevel) - labelLevel <= level_rate) {
} labelLevel += 0.5f;
} else if (labelLevel > 1.2f * density_mult * calculateDensity(head, labelLevel - 1)) { }
if(labelLevel >= 0) {
labelLevel += level_rate;
isChanging = true;
lastLevelChange = now();
}
} else if (labelLevel > 1.2f + density_mult * calculateDensity(head, labelLevel + 1)) {
if(labelLevel >= 0) {
if(labelLevel - floor(labelLevel) <= level_rate) {
labelLevel -= 0.5f;
}
labelLevel -= level_rate; labelLevel -= level_rate;
lastLevelChange = now(); isChanging = true;
} lastLevelChange = now();
}
} }
} }
//add drag force
ddx -= drag_force * dx * dx * sign(dx);
ddy -= drag_force * dy * dy * sign(dy);
} }
void AircraftLabel::applyForces() { void AircraftLabel::applyForces() {
dx += ddx; float new_dx = dx + ddx;
dy += ddy; float new_dy = dy + ddy;
new_dx *= damping_force;
new_dy *= damping_force;
/*
if(sign(new_dx) != sign(dx) && dx != 0) {
new_dx = 0;
}
if(sign(new_dy) != sign(dy) && dy != 0) {
new_dy = 0;
}
*/
//if(dx > 0 || dy > 0 || new_dx > 0.01 || new_dy > 0.01) {
dx = new_dx;
dy = new_dy;
//}
dx *= damping_force;
dy *= damping_force;
if(fabs(dx) > velocity_limit) { if(fabs(dx) > velocity_limit) {
dx = sign(dx) * velocity_limit; dx = sign(dx) * velocity_limit;
} }
@ -294,9 +394,37 @@ void AircraftLabel::applyForces() {
dy = 0; dy = 0;
} }
x += dx; if(dx < 1 || dy < 1) {
y += dy; isChanging = true;
}
float new_x = 0;
float new_y = 0;
for(int i = 0; i < buffer_length; i++) {
new_x += x_buffer[i] / static_cast<float>(buffer_length);
new_y += y_buffer[i] / static_cast<float>(buffer_length);
}
x_buffer[buffer_idx] = new_x + dx;
y_buffer[buffer_idx] = new_y + dy;
buffer_idx = (buffer_idx + 1) % buffer_length;
//new_x += dx;
//new_y += dy;
//new_x = x + dx;
//new_y = y + dy;
//if(abs(new_x - x) > 1 || abs(new_y - y) > 1) {
x = new_x;
y = new_y;
//}
//x += dx;
//y += dy;
if(isnan(x)) { if(isnan(x)) {
x = 0; x = 0;
} }
@ -347,6 +475,15 @@ void AircraftLabel::applyForces() {
// } // }
// } // }
void AircraftLabel::move(float dx, float dy) {
for(int i = 0; i < buffer_length; i++ ){
x_buffer[i] += dx;
y_buffer[i] += dy;
}
x+=dx;
y+=dy;
}
void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) { void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) {
if(x == 0 || y == 0) { if(x == 0 || y == 0) {
@ -374,9 +511,9 @@ void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) {
target_opacity = 0.0f; target_opacity = 0.0f;
} }
opacity += 0.25f * (target_opacity - opacity); opacity += 0.15f * (target_opacity - opacity);
if(opacity < 0.05f) { if(opacity < 0.005f) {
opacity = 0; opacity = 0;
} }
@ -502,6 +639,13 @@ void AircraftLabel::draw(SDL_Renderer *renderer, bool selected) {
if(h < 0.05f) { if(h < 0.05f) {
h = 0; h = 0;
} }
isChanging = false;
}
bool AircraftLabel::getIsChanging() {
return isChanging;
} }
AircraftLabel::AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font) { AircraftLabel::AircraftLabel(Aircraft *p, bool metric, int screen_width, int screen_height, TTF_Font *font) {
@ -516,23 +660,31 @@ AircraftLabel::AircraftLabel(Aircraft *p, bool metric, int screen_width, int scr
target_w = 0; target_w = 0;
target_h = 0; target_h = 0;
opacity = 0; opacity = 0.0f;
target_opacity = 0; target_opacity = 0.0f;
dx = 0; dx = 0;
dy = 0; dy = 0;
ddx = 0; ddx = 0;
ddy = 0; ddy = 0;
for(int i = 0; i < buffer_length; i++) {
x_buffer[i] = x;
y_buffer[i] = y;
}
buffer_idx = 0;
this->screen_width = screen_width; this->screen_width = screen_width;
this->screen_height = screen_height; this->screen_height = screen_height;
labelLevel = 0; labelLevel = 0;
isChanging = false;
flightLabel.setFont(font); flightLabel.setFont(font);
altitudeLabel.setFont(font); altitudeLabel.setFont(font);
speedLabel.setFont(font); speedLabel.setFont(font);
debugLabel.setFont(font); debugLabel.setFont(font);
lastLevelChange = now(); lastLevelChange = now();
} }

View file

@ -15,6 +15,8 @@ class AircraftLabel {
void clearAcceleration(); void clearAcceleration();
void calculateForces(Aircraft *check_p); void calculateForces(Aircraft *check_p);
void applyForces(); void applyForces();
void move(float dx, float dy);
bool getIsChanging();
void draw(SDL_Renderer *renderer, bool selected); void draw(SDL_Renderer *renderer, bool selected);
@ -45,6 +47,12 @@ class AircraftLabel {
float dx; float dx;
float dy; float dy;
float x_buffer[15];
float y_buffer[15];
int buffer_idx;
int buffer_length = 15;
float ddx; float ddx;
float ddy; float ddy;
@ -56,21 +64,25 @@ class AircraftLabel {
int screen_width; int screen_width;
int screen_height; int screen_height;
bool isChanging;
std::chrono::high_resolution_clock::time_point lastLevelChange; std::chrono::high_resolution_clock::time_point lastLevelChange;
/////////// ///////////
float label_force = 0.001f; float label_force = 0.01f;
float label_dist = 2.0f; float label_dist = 2.0f;
float density_force = 0.05f; float density_force = 0.01f;
float attachment_force = 0.0015f; float attachment_force = 0.01f;
float attachment_dist = 10.0f; float attachment_dist = 10.0f;
float icon_force = 0.001f; float icon_force = 0.01f;
float icon_dist = 15.0f; float icon_dist = 15.0f;
float boundary_force = 0.01f; float boundary_force = 0.01f;
float damping_force = 0.85f; float damping_force = 0.65f;
float velocity_limit = 2.0f; float velocity_limit = 1.0f;
float edge_margin = 15.0f; float edge_margin = 15.0f;
float drag_force = 0.00f;
Style style; Style style;
}; };

View file

@ -51,16 +51,11 @@ void AircraftList::update(Modes *modes) {
struct aircraft *a = modes->aircrafts; struct aircraft *a = modes->aircrafts;
Aircraft *p = head; Aircraft *p = head;
while(p) { while(p) {
p->live = 0; p->live = 0;
p = p->next; p = p->next;
} }
//debug
//find(1)->live = 1;
while(a) { while(a) {
p = find(a->addr); p = find(a->addr);

View file

@ -86,11 +86,12 @@ void AppData::disconnect() {
void AppData::update() { void AppData::update() {
if(!connected) { if(!connected) {
return; 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)) {
connected = false;
free(c); free(c);
usleep(1000000); usleep(1000000);
c = (struct client *) malloc(sizeof(*c)); c = (struct client *) malloc(sizeof(*c));
@ -152,9 +153,9 @@ AppData::AppData(){
memset(&modes, 0, sizeof(Modes)); memset(&modes, 0, sizeof(Modes));
modes.check_crc = 1; modes.check_crc = 1;
strcpy(server,VIEW1090_NET_OUTPUT_IP_ADDRESS); strcpy(server,"127.0.0.1");
modes.net_input_beast_port = MODES_NET_OUTPUT_BEAST_PORT; modes.net_input_beast_port = MODES_NET_OUTPUT_BEAST_PORT;
modes.interactive_rows = MODES_INTERACTIVE_ROWS; // modes.interactive_rows = MODES_INTERACTIVE_ROWS;
modes.interactive_delete_ttl = MODES_INTERACTIVE_DELETE_TTL; modes.interactive_delete_ttl = MODES_INTERACTIVE_DELETE_TTL;
modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL; modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
modes.fUserLat = MODES_USER_LATITUDE_DFLT; modes.fUserLat = MODES_USER_LATITUDE_DFLT;

View file

@ -32,9 +32,8 @@
#ifndef APPDATA_H #ifndef APPDATA_H
#define APPDATA_H #define APPDATA_H
#include "view1090.h" //for Modes
#include "AircraftList.h" #include "AircraftList.h"
#include "dump1090.h"
class AppData { class AppData {
private: private:
@ -45,7 +44,6 @@ class AppData {
// //
struct client *c; struct client *c;
bool connected;
int fd; int fd;
char pk_buf[8]; char pk_buf[8];
@ -57,6 +55,8 @@ class AppData {
void updateStatus(); void updateStatus();
AppData(); AppData();
bool connected;
AircraftList aircraftList; AircraftList aircraftList;
Modes modes; Modes modes;
@ -72,4 +72,4 @@ class AppData {
double msgRateAccumulate; double msgRateAccumulate;
}; };
#endif #endif

View file

@ -59,7 +59,7 @@ void Label::setColor(SDL_Color color) {
} }
// //
Label::Label() { Label::Label() {
this->color = {255,255,255,255}; this->color = {0,0,0,0};
surface = NULL; surface = NULL;
} }

View file

@ -4,7 +4,7 @@
# #
CXXFLAGS=-O2 -std=c++11 -g CXXFLAGS=-O2 -std=c++11 -g
LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -g LIBS= -lm -lSDL2 -lSDL2_ttf -lSDL2_gfx -lpthread -g
CXX=g++ CXX=g++
all: viz1090 all: viz1090

67
Map.cpp
View file

@ -36,7 +36,7 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <cmath>
bool Map::QTInsert(QuadTree *tree, Line *line, int depth) { bool Map::QTInsert(QuadTree *tree, Line *line, int depth) {
// if(depth > 25) { // if(depth > 25) {
@ -186,7 +186,8 @@ std::vector<Line*> Map::getLines(float screen_lat_min, float screen_lat_max, flo
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() {
void Map::load() {
FILE *fileptr; FILE *fileptr;
if((fileptr = fopen("mapdata.bin", "rb"))) { if((fileptr = fopen("mapdata.bin", "rb"))) {
@ -205,9 +206,31 @@ Map::Map() {
fclose(fileptr); fclose(fileptr);
printf("Read %d map points.\n",mapPoints_count / 2); printf("Read %d map points.\n",mapPoints_count / 2);
}
// load quad tree
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);
}
int total = mapPoints_count / 2 + airportPoints_count / 2;
int processed = 0;
// load quad tree
if(mapPoints_count > 0) {
for(int i = 0; i < mapPoints_count; i+=2) { for(int i = 0; i < mapPoints_count; i+=2) {
if(mapPoints[i] == 0) if(mapPoints[i] == 0)
continue; continue;
@ -248,6 +271,10 @@ Map::Map() {
// printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat); // printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
QTInsert(&root, new Line(currentPoint, nextPoint), 0); QTInsert(&root, new Line(currentPoint, nextPoint), 0);
processed++;
loaded = floor(100.0f * (float)processed / (float)total);
} }
} else { } else {
printf("No map file found\n"); printf("No map file found\n");
@ -255,23 +282,9 @@ Map::Map() {
// //
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 // load quad tree
if(airportPoints_count > 0) {
for(int i = 0; i < airportPoints_count; i+=2) { for(int i = 0; i < airportPoints_count; i+=2) {
if(airportPoints[i] == 0) if(airportPoints[i] == 0)
continue; continue;
@ -312,6 +325,10 @@ Map::Map() {
//printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat); //printf("inserting [%f %f] -> [%f %f]\n",currentPoint.lon,currentPoint.lat,nextPoint.lon,nextPoint.lat);
QTInsert(&airport_root, new Line(currentPoint, nextPoint), 0); QTInsert(&airport_root, new Line(currentPoint, nextPoint), 0);
processed++;
loaded = floor(100.0f * (float)processed / (float)total);
} }
} else { } else {
printf("No airport file found\n"); printf("No airport file found\n");
@ -379,7 +396,17 @@ Map::Map() {
infile.close(); infile.close();
printf("done\n"); printf("done\n");
loaded = 100;
} }
Map::Map() {
loaded = 0;
mapPoints_count = 0;
mapPoints = NULL;
airportPoints_count = 0;
airportPoints = NULL;
}

6
Map.h
View file

@ -128,7 +128,9 @@ public:
std::vector<MapLabel*> mapnames; std::vector<MapLabel*> mapnames;
std::vector<MapLabel*> airportnames; std::vector<MapLabel*> airportnames;
Map(); void load();
int loaded;
Map();
int mapPoints_count; int mapPoints_count;
float *mapPoints; float *mapPoints;
@ -137,4 +139,4 @@ public:
float *airportPoints; float *airportPoints;
}; };
#endif #endif

View file

@ -29,10 +29,41 @@ sudo apt-get install build-essential
1. Install SDL and RTL-SDR libraries 1. Install SDL and RTL-SDR libraries
``` ```
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 libgdal-dev
``` ```
1b. (Raspberry Pi only)
If you are running viz1090 on the Raspbian desktop (or any form of X) you can skip this step, but if you want to be able to start it directly from the command line, do the following to build SDL with KMS driver support. This is taken from [this stackoverflow question](https://stackoverflow.com/questions/57672568/sdl2-on-raspberry-pi-without-x)
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. ```
git clone https://github.com/libsdl-org/SDL
sudo apt build-dep libsdl2
sudo apt install libdrm-dev libgbm-dev
cd ~/SDL
git checkout SDL2
./configure --enable-video-kmsdrm
make -j4 && sudo make install
```
Then download and build SDL2_gfx
```
wget http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-1.0.4.tar.gz
tar -zxvf SDL2_gfx-1.0.4.tar.gz
cd SDL2_gfx-1.0.4
./configure --build=arm-linux-gnueabihf --disable-mmx
make -j4 && sudo make install
```
And finally SDL2_ttf
```
git clone https://github.com/libsdl-org/SDL_ttf.git
cd SDL_ttf
git checkout SDL2
./configure --disable-freetype-builtin --without-x --enable-harfbuzz=no
make -j4 && sudo make install
```
Now make sure that you are using the "Fake KMS" driver, not the newer "KMS" driver in /boot/config.txt:
```
dtoverlay=vc4-fkms-v3d
#dtoverlay=vc4-kms-v3d
```
2. Download and build viz1090 2. Download and build viz1090
``` ```
@ -54,8 +85,6 @@ This will produce files for map and airport geometry, with labels, that viz1090
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. 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) 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/

21
Style.h
View file

@ -35,6 +35,9 @@ typedef struct Style {
SDL_Color red; SDL_Color red;
SDL_Color green; SDL_Color green;
SDL_Color blue; SDL_Color blue;
SDL_Color orange;
SDL_Color grey;
SDL_Color grey_dark;
// //
// todo separate style stuff // todo separate style stuff
@ -56,10 +59,10 @@ typedef struct Style {
SDL_Color yellow = {216,255,0,255}; SDL_Color yellow = {216,255,0,255};
SDL_Color yellow_dark = {90,133,50,255}; SDL_Color yellow_dark = {90,133,50,255};
SDL_Color orange = {253,151,31,255}; orange = {253,151,31,255};
SDL_Color grey_light = {196,196,196,255}; SDL_Color grey_light = {196,196,196,255};
SDL_Color grey = {127,127,127,255}; grey = {127,127,127,255};
SDL_Color grey_dark = {64,64,64,255}; grey_dark = {64,64,64,255};
black = {0,0,0,255}; black = {0,0,0,255};
white = {255,255,255,255}; white = {255,255,255,255};
@ -68,20 +71,20 @@ typedef struct Style {
blue = {0,0,255,255}; blue = {0,0,255,255};
backgroundColor = {200,200,200,255}; backgroundColor = {0,0,0,255};
selectedColor = pink; selectedColor = pink;
planeColor = black; planeColor = {0,255,174};
planeGoneColor = grey; planeGoneColor = grey;
trailColor = grey; trailColor = {0,255,174};
geoColor = grey_dark; geoColor = grey_dark;
airportColor = grey; airportColor = grey;
labelColor = black; labelColor = white;
labelLineColor = grey_dark; labelLineColor = grey_dark;
subLabelColor = grey; subLabelColor = grey;
labelBackground = grey_light; labelBackground = black;
scaleBarColor = grey_light; scaleBarColor = grey_light;
buttonColor = grey_light; buttonColor = grey_light;
buttonBackground = black; buttonBackground = black;
@ -91,4 +94,4 @@ typedef struct Style {
} }
} Style; } Style;
#endif #endif

287
View.cpp
View file

@ -68,6 +68,7 @@ static float clamp(float in, float min, float max) {
return out; return out;
} }
static void CROSSVP(float *v, float *u, float *w) static void CROSSVP(float *v, float *u, float *w)
{ {
v[0] = u[1]*w[2] - u[2]*(w)[1]; v[0] = u[1]*w[2] - u[2]*(w)[1];
@ -83,6 +84,40 @@ SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
return out; return out;
} }
float lerp(float a, float b, float factor) {
if(factor > 1.0f) {
factor = 1.0f;
}
if(factor < 0.0f) {
factor = 0.0f;
}
return (1.0f - factor) * a + factor * b;
}
float lerpAngle(float a, float b, float factor) {
float diff = fabs(b - a);
if (diff > 180.0f)
{
if (b > a)
{
a += 360.0f;
}
else
{
b += 360.0f;
}
}
float value = (a + ((b - a) * factor));
if (value >= 0.0f && value <= 360.0f)
return value;
return fmod(value,360.0f);
}
SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) { SDL_Color lerpColor(SDL_Color aColor, SDL_Color bColor, float factor) {
if(factor > 1.0f) { if(factor > 1.0f) {
factor = 1.0f; factor = 1.0f;
@ -199,7 +234,6 @@ void View::font_init() {
// //
void View::SDL_init() { void View::SDL_init() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("Could not initialize SDL: %s\n", SDL_GetError()); printf("Could not initialize SDL: %s\n", SDL_GetError());
exit(1); exit(1);
@ -226,7 +260,7 @@ void View::SDL_init() {
} }
window = SDL_CreateWindow("viz1090", SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), screen_width, screen_height, flags); window = SDL_CreateWindow("viz1090", SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), SDL_WINDOWPOS_CENTERED_DISPLAY(screen_index), screen_width, screen_height, flags);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
mapTexture = SDL_CreateTexture(renderer, mapTexture = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET, SDL_TEXTUREACCESS_TARGET,
@ -288,27 +322,56 @@ void View::drawStatusBox(int *left, int *top, std::string label, std::string mes
*left = *left + labelWidth + messageWidth + PAD; *left = *left + labelWidth + messageWidth + PAD;
} }
void View::drawCenteredStatusBox(std::string label, std::string message, SDL_Color color) {
int labelWidth = (label.length() + ((label.length() > 0 ) ? 1 : 0)) * labelFontWidth;
int messageWidth = (message.length() + ((message.length() > 0 ) ? 1 : 0)) * messageFontWidth;
int left = (screen_width - (labelWidth + messageWidth)) / 2;
int top = (screen_height - labelFontHeight) / 2;
drawStatusBox(&left, &top, label, message, color);
}
void View::drawStatus() { void View::drawStatus() {
int left = PAD; int left = PAD;
int top = screen_height - messageFontHeight - PAD; int top = screen_height - messageFontHeight - PAD;
char strLoc[20] = " "; if(fps) {
snprintf(strLoc, 20, "%3.3fN %3.3f%c", centerLat, fabs(centerLon),(centerLon > 0) ? 'E' : 'W'); char fps[60] = " ";
drawStatusBox(&left, &top, "loc", strLoc, style.buttonColor); snprintf(fps,40,"%.1f", 1000.0 / lastFrameTime);
char strPlaneCount[10] = " "; drawStatusBox(&left, &top, "fps", fps, style.grey_dark);
snprintf(strPlaneCount, 10,"%d/%d", appData->numVisiblePlanes, appData->numPlanes); }
drawStatusBox(&left, &top, "disp", strPlaneCount, style.buttonColor);
char strMsgRate[18] = " ";
snprintf(strMsgRate, 18,"%.0f/s", appData->msgRate);
drawStatusBox(&left, &top, "rate", strMsgRate, style.buttonColor);
char strSig[18] = " "; if(!appData->connected) {
snprintf(strSig, 18, "%.0f%%", 100.0 * appData->avgSig / 1024.0); drawStatusBox(&left,&top,"init", "connecting", style.red);
drawStatusBox(&left, &top, "sAvg", strSig, style.buttonColor); } else {
char strLoc[20] = " ";
snprintf(strLoc, 20, "%3.3fN %3.3f%c", centerLat, fabs(centerLon),(centerLon > 0) ? 'E' : 'W');
drawStatusBox(&left, &top, "loc", strLoc, style.buttonColor);
char strPlaneCount[10] = " ";
snprintf(strPlaneCount, 10,"%d/%d", appData->numVisiblePlanes, appData->numPlanes);
drawStatusBox(&left, &top, "disp", strPlaneCount, style.buttonColor);
char strMsgRate[18] = " ";
snprintf(strMsgRate, 18,"%.0f/s", appData->msgRate);
drawStatusBox(&left, &top, "rate", strMsgRate, style.buttonColor);
char strSig[18] = " ";
snprintf(strSig, 18, "%.0f%%", 100.0 * appData->avgSig / 1024.0);
drawStatusBox(&left, &top, "sAvg", strSig, style.buttonColor);
}
if(map.loaded < 100) {
char loaded[20] = " ";
snprintf(loaded, 20, "loading map %d%%", map.loaded);
drawStatusBox(&left,&top,"init", loaded, style.orange);
}
} }
// //
@ -358,7 +421,7 @@ void View::drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color p
y2 = (screen_height>>1) + outy - 2.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]); y2 = (screen_height>>1) + outy - 2.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]);
x3 = (screen_width>>1) + outx - arrowWidth * vec[0]; x3 = (screen_width>>1) + outx - arrowWidth * vec[0];
y3 = (screen_height>>1) + outy - arrowWidth * vec[1]; y3 = (screen_height>>1) + outy - arrowWidth * vec[1];
trigonRGBA(renderer, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(renderer, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
// arrow 2 // arrow 2
x1 = (screen_width>>1) + outx - 3.0 * arrowWidth * vec[0] + round(-arrowWidth*out[0]); x1 = (screen_width>>1) + outx - 3.0 * arrowWidth * vec[0] + round(-arrowWidth*out[0]);
@ -367,7 +430,7 @@ void View::drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color p
y2 = (screen_height>>1) + outy - 3.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]); y2 = (screen_height>>1) + outy - 3.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]);
x3 = (screen_width>>1) + outx - 2.0 * arrowWidth * vec[0]; x3 = (screen_width>>1) + outx - 2.0 * arrowWidth * vec[0];
y3 = (screen_height>>1) + outy - 2.0 * arrowWidth * vec[1]; y3 = (screen_height>>1) + outy - 2.0 * arrowWidth * vec[1];
trigonRGBA(renderer, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(renderer, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
*returnx = x3; *returnx = x3;
*returny = y3; *returny = y3;
@ -377,9 +440,9 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
{ {
float body = 8.0 * screen_uiscale; float body = 8.0 * screen_uiscale;
float wing = 6.0 * screen_uiscale; float wing = 6.0 * screen_uiscale;
float wingThick = 0.35; float wingThick = 0.5;
float tail = 3.0 * screen_uiscale; float tail = 3.0 * screen_uiscale;
float tailThick = 0.5; float tailThick = 0.35;
float bodyWidth = screen_uiscale; float bodyWidth = screen_uiscale;
float vec[3]; float vec[3];
@ -401,15 +464,15 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
x2 = x + round(bodyWidth*out[0]); x2 = x + round(bodyWidth*out[0]);
y2 = y + round(bodyWidth*out[1]); y2 = y + round(bodyWidth*out[1]);
trigonRGBA (renderer, x1, y1, x2, y2, x+round(-body * vec[0]), y+round(-body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(-body * vec[0]), y+round(-body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
trigonRGBA (renderer, x1, y1, x2, y2, x+round(body * vec[0]), y+round(body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(body * vec[0]), y+round(body*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
// x1 = x + round(-body*vec[0] - bodyWidth*out[0]); //x1 = x + round(8*vec[0]);
// y1 = y + round(-body*vec[1] - bodyWidth*out[1]); //y1 = y + round(8*vec[1]);
// x2 = x + round(body*vec[0] - bodyWidth*out[0]); //x2 = x + round(16*vec[0]);
// y2 = y + round(body*vec[1] - bodyWidth*out[1]); //y2 = y + round(16*vec[1]);
// lineRGBA(renderer,x,y,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); //lineRGBA(renderer,x1,y1,x2,y2, style.white.r, style.white.g, style.white.b, SDL_ALPHA_OPAQUE);
// x1 = x + round(-body*vec[0] + bodyWidth*out[0]); // x1 = x + round(-body*vec[0] + bodyWidth*out[0]);
// y1 = y + round(-body*vec[1] + bodyWidth*out[1]); // y1 = y + round(-body*vec[1] + bodyWidth*out[1]);
@ -427,7 +490,7 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
x2 = x + round(wing*out[0]); x2 = x + round(wing*out[0]);
y2 = y + round(wing*out[1]); y2 = y + round(wing*out[1]);
trigonRGBA(renderer, x1, y1, x2, y2, x+round(body*wingThick*vec[0]), y+round(body*wingThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(renderer, x1, y1, x2, y2, x+round(body*wingThick*vec[0]), y+round(body*wingThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//tail //tail
x1 = x + round(-body*.75*vec[0] - tail*out[0]); x1 = x + round(-body*.75*vec[0] - tail*out[0]);
@ -435,26 +498,20 @@ void View::drawPlaneIcon(int x, int y, float heading, SDL_Color planeColor)
x2 = x + round(-body*.75*vec[0] + tail*out[0]); x2 = x + round(-body*.75*vec[0] + tail*out[0]);
y2 = y + round(-body*.75*vec[1] + tail*out[1]); y2 = y + round(-body*.75*vec[1] + tail*out[1]);
trigonRGBA (renderer, x1, y1, x2, y2, x+round(-body*tailThick*vec[0]), y+round(-body*tailThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA (renderer, x1, y1, x2, y2, x+round(-body*tailThick*vec[0]), y+round(-body*tailThick*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} }
void View::drawTrails(int left, int top, int right, int bottom) { void View::drawTrails(int left, int top, int right, int bottom) {
int currentX, currentY, prevX, prevY; int currentX, currentY, prevX, prevY, colorVal;
float dx, dy; float dx, dy;
Aircraft *p = appData->aircraftList.head; Aircraft *p = appData->aircraftList.head;
int count = 0;
while(p) { while(p) {
if (p->lon && p->lat) {
if(p->lonHistory.empty()) { if(p->lonHistory.empty()) {
return; p = p->next;
} continue;
}
SDL_Color color = lerpColor(style.trailColor, style.planeGoneColor, static_cast<float>(elapsed_s(p->msSeen)) / DISPLAY_ACTIVE);
if(p == selectedAircraft) {
color = style.selectedColor;
}
std::vector<float>::iterator lon_idx = p->lonHistory.begin(); std::vector<float>::iterator lon_idx = p->lonHistory.begin();
std::vector<float>::iterator lat_idx = p->latHistory.begin(); std::vector<float>::iterator lat_idx = p->latHistory.begin();
@ -474,13 +531,23 @@ void View::drawTrails(int left, int top, int right, int bottom) {
continue; continue;
} }
uint8_t colorVal = (uint8_t)floor(127.0 * (age / static_cast<float>(p->lonHistory.size())));
//thickLineRGBA(renderer, prevX, prevY, currentX, currentY, 2 * screen_uiscale, 255, 255, 255, colorVal);
lineRGBA(renderer, prevX, prevY, currentX, currentY, color.r, color.g, color.b, colorVal);
SDL_Color color = lerpColor({255,0,0,255}, {255,200,0,255}, age / static_cast<float>(p->lonHistory.size()));
color = lerpColor(color, style.planeGoneColor, elapsed_s(p->msSeen) / DISPLAY_ACTIVE);
color = lerpColor(color, style.black, -1.0f + (elapsed_s(p->msSeen) / DISPLAY_ACTIVE));
colorVal = (uint8_t)clamp(512.0 * (age / static_cast<float>(p->lonHistory.size())), 0, 255);
lineRGBA(renderer, prevX, prevY, currentX, currentY, color.r, color.g, color.b, colorVal);
}
if(elapsed_s(p->msSeen) > DISPLAY_ACTIVE) {
//lineRGBA(renderer, currentX-4, currentY-4, currentX+4, currentY+4, style.planeGoneColor.r, style.planeGoneColor.g, style.planeGoneColor.b, colorVal);
//lineRGBA(renderer, currentX+4, currentY-4, currentX-4, currentY+4, style.planeGoneColor.r, style.planeGoneColor.g, style.planeGoneColor.b, colorVal);
SDL_Color color = lerpColor(style.planeGoneColor, style.black, -1.0f + (elapsed_s(p->msSeen) / DISPLAY_ACTIVE));
circleRGBA(renderer, currentX, currentY, 5, color.r, color.g, color.b, colorVal);
} }
}
p = p->next; p = p->next;
} }
} }
@ -569,8 +636,6 @@ void View::drawLinesRecursive(QuadTree *tree, float screen_lat_min, float screen
pxFromLonLat(&dx, &dy, (*currentLine)->end.lon, (*currentLine)->end.lat); pxFromLonLat(&dx, &dy, (*currentLine)->end.lon, (*currentLine)->end.lat);
screenCoords(&x2, &y2, dx, dy); screenCoords(&x2, &y2, dx, dy);
lineCount++;
if(outOfBounds(x1,y1) && outOfBounds(x2,y2)) { if(outOfBounds(x1,y1) && outOfBounds(x2,y2)) {
continue; continue;
} }
@ -654,7 +719,7 @@ void View::drawPlaceNames() {
void View::drawGeography() { void View::drawGeography() {
if((mapRedraw && !mapMoved) || (mapAnimating && elapsed(lastRedraw) > 8 * FRAMETIME) || elapsed(lastRedraw) > 2000) { if((mapRedraw && !mapMoved) || (mapAnimating && elapsed(lastRedraw) > 8 * FRAMETIME) || elapsed(lastRedraw) > 2000 || (map.loaded < 100 && elapsed(lastRedraw) > 250)) {
SDL_SetRenderTarget(renderer, mapTexture); SDL_SetRenderTarget(renderer, mapTexture);
@ -744,9 +809,20 @@ void View::drawPlaneText(Aircraft *p) {
p->label->draw(renderer, (p == selectedAircraft)); p->label->draw(renderer, (p == selectedAircraft));
} }
float View::resolveLabelConflicts() { void View::moveLabels(float dx, float dy) {
float maxV = 0.0f; Aircraft *p = appData->aircraftList.head;
while(p) {
if(p->label) {
p->label->move(dx,dy);
}
p = p->next;
}
}
void View::resolveLabelConflicts() {
Aircraft *p = appData->aircraftList.head; Aircraft *p = appData->aircraftList.head;
while(p) { while(p) {
@ -773,12 +849,14 @@ float View::resolveLabelConflicts() {
if(p->label) { if(p->label) {
p->label->applyForces(); p->label->applyForces();
// if(p->label->getIsChanging()) {
// highFramerate = true;
// }
} }
p = p->next; p = p->next;
} }
return maxV;
} }
void View::drawPlanes() { void View::drawPlanes() {
@ -803,47 +881,62 @@ void View::drawPlanes() {
int x, y; int x, y;
float dx, dy; float dx, dy;
pxFromLonLat(&dx, &dy, p->lon, p->lat); pxFromLonLat(&dx, &dy, p->lon, p->lat);
screenCoords(&x, &y, dx, dy); screenCoords(&x, &y, dx, dy);
float age_ms = elapsed(p->created); float age_ms = elapsed(p->created);
if(age_ms < 500) { if(age_ms < 500) {
//highFramerate = true;
float ratio = age_ms / 500.0f; float ratio = age_ms / 500.0f;
float radius = (1.0f - ratio * ratio) * screen_width / 8; float radius = (1.0f - ratio * ratio) * screen_width / 8;
for(float theta = 0; theta < 2*M_PI; theta += M_PI / 4) { for(float theta = 0; theta < 2*M_PI; theta += M_PI / 4) {
pixelRGBA(renderer, x + radius * cos(theta), y + radius * sin(theta), style.planeColor.r, style.planeColor.g, style.planeColor.b, 255 * ratio); pixelRGBA(renderer, x + radius * cos(theta), y + radius * sin(theta), style.planeColor.r, style.planeColor.g, style.planeColor.b, 255 * ratio);
} }
// circleRGBA(renderer, x, y, 500 - age_ms, 255,255, 255, (uint8_t)(255.0 * age_ms / 500.0)); // circleRGBA(renderer, x, y, 500 - age_ms, 255,255, 255, (uint8_t)(255.0 * age_ms / 500.0));
} else { } else if(1000 * DISPLAY_ACTIVE - elapsed(p->msSeen) > 500) {
if(MODES_ACFLAGS_HEADING_VALID) { if(MODES_ACFLAGS_HEADING_VALID) {
int usex = x; int usex = x;
int usey = y; int usey = y;
float useHeading = static_cast<float>(p->track);
p->x = usex;
p->y = usey;
planeColor = lerpColor(style.planeColor, style.planeGoneColor, elapsed_s(p->msSeen) / DISPLAY_ACTIVE); planeColor = lerpColor(style.planeColor, style.planeGoneColor, elapsed_s(p->msSeen) / DISPLAY_ACTIVE);
if(elapsed_s(p->msSeen) > DISPLAY_ACTIVE / 2) {
arcRGBA(renderer, x, y, 8, 0, 360 * 2.0 * (elapsed_s(p->msSeen) / DISPLAY_ACTIVE - 0.5), planeColor.r, planeColor.g, planeColor.b, 255);
}
if(p == selectedAircraft) { if(p == selectedAircraft) {
planeColor = style.selectedColor; planeColor = style.selectedColor;
} }
if(outOfBounds(x,y)) { if(outOfBounds(x,y)) {
drawPlaneOffMap(x, y, &(p->x), &(p->y), planeColor); drawPlaneOffMap(x, y, &(p->x), &(p->y), planeColor);
} else { } else {
drawPlaneIcon(usex, usey, p->track, planeColor); if(elapsed(p->msSeenLatLon) < 500) {
//highFramerate = true;
circleRGBA(renderer, p->x, p->y, elapsed(p->msSeenLatLon) * screen_width / (8192), 127,127, 127, 255 - (uint8_t)(255.0 * elapsed(p->msSeenLatLon) / 500.0));
pxFromLonLat(&dx, &dy, p->getLastLon(), p->getLastLat());
screenCoords(&x, &y, dx, dy);
p->x = usex; usex = lerp(x,usex,elapsed(p->msSeenLatLon) / 500.0);
p->y = usey; usey = lerp(y,usey,elapsed(p->msSeenLatLon) / 500.0);
} useHeading = lerpAngle(p->getLastHeading(),useHeading,elapsed(p->msSeenLatLon) / 500.0);
}
//show latlon ping drawPlaneIcon(usex, usey, useHeading, planeColor);
if(elapsed(p->msSeenLatLon) < 500) {
circleRGBA(renderer, p->x, p->y, elapsed(p->msSeenLatLon) * screen_width / (8192), 127,127, 127, 255 - (uint8_t)(255.0 * elapsed(p->msSeenLatLon) / 500.0));
} }
drawPlaneText(p); drawPlaneText(p);
} }
} } else {
circleRGBA(renderer, x, y, 8 * (1000 * DISPLAY_ACTIVE - elapsed(p->msSeen)) / 500, style.planeGoneColor.r, style.planeGoneColor.g, style.planeGoneColor.b, 255);
}
} }
p = p->next; p = p->next;
} }
@ -855,6 +948,8 @@ void View::animateCenterAbsolute(float x, float y) {
float dx = -1.0 * (0.75*(double)screen_width / (double)screen_height) * (x - screen_width/2) * maxDist / (0.95 * scale_factor * 0.5); float dx = -1.0 * (0.75*(double)screen_width / (double)screen_height) * (x - screen_width/2) * maxDist / (0.95 * scale_factor * 0.5);
float dy = 1.0 * (y - screen_height/2) * maxDist / (0.95 * scale_factor * 0.5); float dy = 1.0 * (y - screen_height/2) * maxDist / (0.95 * scale_factor * 0.5);
moveLabels(x,y);
float outLat = dy * (1.0/6371.0) * (180.0f / M_PI); float outLat = dy * (1.0/6371.0) * (180.0f / M_PI);
float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((centerLat)/2.0f) * M_PI / 180.0f); float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((centerLat)/2.0f) * M_PI / 180.0f);
@ -865,6 +960,8 @@ void View::animateCenterAbsolute(float x, float y) {
mapTargetMaxDist = 0.25 * maxDist; mapTargetMaxDist = 0.25 * maxDist;
mapMoved = 1; mapMoved = 1;
highFramerate = true;
} }
void View::moveCenterAbsolute(float x, float y) { void View::moveCenterAbsolute(float x, float y) {
@ -873,6 +970,8 @@ void View::moveCenterAbsolute(float x, float y) {
float dx = -1.0 * (0.75*(double)screen_width / (double)screen_height) * (x - screen_width/2) * maxDist / (0.95 * scale_factor * 0.5); float dx = -1.0 * (0.75*(double)screen_width / (double)screen_height) * (x - screen_width/2) * maxDist / (0.95 * scale_factor * 0.5);
float dy = 1.0 * (y - screen_height/2) * maxDist / (0.95 * scale_factor * 0.5); float dy = 1.0 * (y - screen_height/2) * maxDist / (0.95 * scale_factor * 0.5);
moveLabels(x,y);
float outLat = dy * (1.0/6371.0) * (180.0f / M_PI); float outLat = dy * (1.0/6371.0) * (180.0f / M_PI);
float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((centerLat)/2.0f) * M_PI / 180.0f); float outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((centerLat)/2.0f) * M_PI / 180.0f);
@ -884,6 +983,7 @@ void View::moveCenterAbsolute(float x, float y) {
mapTargetLat = 0; mapTargetLat = 0;
mapMoved = 1; mapMoved = 1;
highFramerate = true;
} }
void View::moveCenterRelative(float dx, float dy) { void View::moveCenterRelative(float dx, float dy) {
@ -891,6 +991,8 @@ void View::moveCenterRelative(float dx, float dy) {
// need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets // need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets
// //
moveLabels(dx,dy);
float scale_factor = (screen_width > screen_height) ? screen_width : screen_height; float scale_factor = (screen_width > screen_height) ? screen_width : screen_height;
dx = -1.0 * dx * maxDist / (0.95 * scale_factor * 0.5); dx = -1.0 * dx * maxDist / (0.95 * scale_factor * 0.5);
@ -907,6 +1009,7 @@ void View::moveCenterRelative(float dx, float dy) {
mapTargetLat = 0; mapTargetLat = 0;
mapMoved = 1; mapMoved = 1;
highFramerate = true;
} }
void View::zoomMapToTarget() { void View::zoomMapToTarget() {
@ -915,6 +1018,7 @@ void View::zoomMapToTarget() {
maxDist += 0.1 * (mapTargetMaxDist - maxDist); maxDist += 0.1 * (mapTargetMaxDist - maxDist);
mapAnimating = 1; mapAnimating = 1;
mapMoved = 1; mapMoved = 1;
highFramerate = true;
} else { } else {
mapTargetMaxDist = 0; mapTargetMaxDist = 0;
} }
@ -929,6 +1033,7 @@ void View::moveMapToTarget() {
mapAnimating = 1; mapAnimating = 1;
mapMoved = 1; mapMoved = 1;
highFramerate = true;
} else { } else {
mapTargetLon = 0; mapTargetLon = 0;
mapTargetLat = 0; mapTargetLat = 0;
@ -954,6 +1059,7 @@ void View::moveMapToTarget() {
void View::drawClick() { void View::drawClick() {
if(clickx && clicky) { if(clickx && clicky) {
highFramerate = true;
int radius = .25 * elapsed(clickTime); int radius = .25 * elapsed(clickTime);
int alpha = 128 - static_cast<int>(0.5 * elapsed(clickTime)); int alpha = 128 - static_cast<int>(0.5 * elapsed(clickTime));
@ -1036,6 +1142,7 @@ void View::registerMouseMove(int x, int y) {
// latLonFromScreenCoords(&(mouse->lat), &(mouse->lon), x, screen_height-y); // latLonFromScreenCoords(&(mouse->lat), &(mouse->lon), x, screen_height-y);
// mouse->live = 1; // mouse->live = 1;
// } // }
highFramerate = true;
} }
// //
@ -1045,44 +1152,48 @@ void View::registerMouseMove(int x, int y) {
void View::draw() { void View::draw() {
drawStartTime = now(); drawStartTime = now();
int targetFrameTime = 30;
// if(highFramerate) {
// targetFrameTime = 15;
// }
// highFramerate = false;
if (lastFrameTime < targetFrameTime) {
SDL_Delay(static_cast<Uint32>(targetFrameTime - lastFrameTime));
}
moveMapToTarget(); moveMapToTarget();
zoomMapToTarget(); zoomMapToTarget();
drawGeography();
for(int i = 0; i < 8; i++) { drawGeography();
// if(resolveLabelConflicts() < 0.001f) { drawScaleBars();
// break;
// } if(appData->connected) {
resolveLabelConflicts(); for(int i = 0; i < 8; i++) {
// if(resolveLabelConflicts() < 0.001f) {
// break;
// }
resolveLabelConflicts();
}
drawPlanes();
} }
lineCount = 0;
drawScaleBars();
drawPlanes();
drawStatus(); drawStatus();
//drawMouse(); //drawMouse();
drawClick(); drawClick();
// if(fps) {
// char fps[60] = " ";
// snprintf(fps,40," %d lines @ %.1ffps", lineCount, 1000.0 / elapsed(lastFrameTime));
// drawStringBG(fps, 0,0, mapFont, style.subLabelColor, style.backgroundColor);
// }
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
if (elapsed(drawStartTime) < FRAMETIME) { lastFrameTime = elapsed(drawStartTime);
std::this_thread::sleep_for(fmilliseconds{FRAMETIME} - (now() - drawStartTime));
}
lastFrameTime = now();
} }
View::View(AppData *appData){ View::View(AppData *appData){
this->appData = appData; this->appData = appData;
startupState = 0;
// Display options // Display options
screen_uiscale = 1; screen_uiscale = 1;
screen_width = 0; screen_width = 0;
@ -1092,6 +1203,9 @@ View::View(AppData *appData){
fullscreen = 0; fullscreen = 0;
screen_index = 0; screen_index = 0;
highFramerate = false;
lastFrameTime = 0;
centerLon = 0; centerLon = 0;
centerLat = 0; centerLat = 0;
@ -1101,6 +1215,9 @@ View::View(AppData *appData){
mapRedraw = 1; mapRedraw = 1;
selectedAircraft = NULL; selectedAircraft = NULL;
std::thread t1(&Map::load, &map);
t1.detach();
} }
View::~View() { View::~View() {

14
View.h
View file

@ -84,7 +84,9 @@ class View {
SDL_Rect drawString(std::string text, int x, int y, TTF_Font *font, SDL_Color color); SDL_Rect drawString(std::string 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); SDL_Rect drawStringBG(std::string 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, std::string label, std::string message, SDL_Color color);
void drawCenteredStatusBox(std::string label, std::string message, SDL_Color color);
void drawStatus(); void drawStatus();
void moveLabels(float dx, float dy);
Aircraft *selectedAircraft; Aircraft *selectedAircraft;
@ -107,7 +109,7 @@ class View {
void drawGeography(); void drawGeography();
void drawSignalMarks(Aircraft *p, int x, int y); void drawSignalMarks(Aircraft *p, int x, int y);
void drawPlaneText(Aircraft *p); void drawPlaneText(Aircraft *p);
float resolveLabelConflicts(); void resolveLabelConflicts();
void drawPlanes(); void drawPlanes();
void animateCenterAbsolute(float x, float y); void animateCenterAbsolute(float x, float y);
void moveCenterAbsolute(float x, float y); void moveCenterAbsolute(float x, float y);
@ -132,6 +134,8 @@ class View {
bool fps; bool fps;
int startupState;
float maxDist; float maxDist;
float currentMaxDist; float currentMaxDist;
@ -146,11 +150,13 @@ class View {
int mapRedraw; int mapRedraw;
int mapAnimating; int mapAnimating;
bool highFramerate;
float currentLon; float currentLon;
float currentLat; float currentLat;
std::chrono::high_resolution_clock::time_point lastFrameTime; float lastFrameTime;
std::chrono::high_resolution_clock::time_point drawStartTime; std::chrono::high_resolution_clock::time_point drawStartTime;
std::chrono::high_resolution_clock::time_point lastRedraw; std::chrono::high_resolution_clock::time_point lastRedraw;
Map map; Map map;

View file

@ -1,47 +1,47 @@
// dump1090, a Mode S messages decoder for RTLSDR devices. // // dump1090, a Mode S messages decoder for RTLSDR devices.
// // //
// Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.com> // // Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.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
// modification, are permitted provided that the following conditions are // // modification, are permitted provided that the following conditions are
// met: // // met:
// // //
// * Redistributions of source code must retain the above copyright // // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // // notice, this list of conditions and the following disclaimer.
// // //
// * Redistributions in binary form must reproduce the above copyright // // * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the // // notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution. // // documentation and/or other materials provided with the distribution.
// // //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// // //
#ifndef __DUMP1090_H #ifndef __DUMP1090_H
#define __DUMP1090_H #define __DUMP1090_H
// File Version number // // File Version number
// ==================== // // ====================
// Format is : MajorVer.MinorVer.DayMonth.Year" // // Format is : MajorVer.MinorVer.DayMonth.Year"
// MajorVer changes only with significant changes // // MajorVer changes only with significant changes
// MinorVer changes when additional features are added, but not for bug fixes (range 00-99) // // MinorVer changes when additional features are added, but not for bug fixes (range 00-99)
// DayDate & Year changes for all changes, including for bug fixes. It represent the release date of the update // // DayDate & Year changes for all changes, including for bug fixes. It represent the release date of the update
// // //
#define MODES_DUMP1090_VERSION "1.10.3010.14" // #define MODES_DUMP1090_VERSION "1.10.3010.14"
// ============================= Include files ========================== // // ============================= Include files ==========================
#ifndef _WIN32 // #ifndef _WIN32
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -50,26 +50,28 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/socket.h>
// #include <sys/time.h>
#include <sys/timeb.h> #include <sys/timeb.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h> // #include <fcntl.h>
#include <ctype.h> #include <ctype.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h> // #include <sys/ioctl.h>
#include "rtl-sdr.h" // // #include "rtl-sdr.h"
#include "anet.h" #include "anet.h"
#else // #else
#include "winstubs.h" //Put everything Windows specific in here // #include "winstubs.h" //Put everything Windows specific in here
#include "rtl-sdr.h" // #include "rtl-sdr.h"
#include "anet.h" // #include "anet.h"
#endif // #endif
// ============================= #defines =============================== // // ============================= #defines ===============================
// // //
// If you have a valid coaa.h, these values will come from it. If not, // // If you have a valid coaa.h, these values will come from it. If not,
// then you can enter your own values in the #else section here // // then you can enter your own values in the #else section here
// // //
#ifdef USER_LATITUDE #ifdef USER_LATITUDE
#define MODES_USER_LATITUDE_DFLT (USER_LATITUDE) #define MODES_USER_LATITUDE_DFLT (USER_LATITUDE)
#define MODES_USER_LONGITUDE_DFLT (USER_LONGITUDE) #define MODES_USER_LONGITUDE_DFLT (USER_LONGITUDE)
@ -78,27 +80,27 @@
#define MODES_USER_LONGITUDE_DFLT (0.0) #define MODES_USER_LONGITUDE_DFLT (0.0)
#endif #endif
#define MODES_DEFAULT_PPM 52 // #define MODES_DEFAULT_PPM 52
#define MODES_DEFAULT_RATE 2000000 // #define MODES_DEFAULT_RATE 2000000
#define MODES_DEFAULT_FREQ 1090000000 // #define MODES_DEFAULT_FREQ 1090000000
#define MODES_DEFAULT_WIDTH 1000 // #define MODES_DEFAULT_WIDTH 1000
#define MODES_DEFAULT_HEIGHT 700 // #define MODES_DEFAULT_HEIGHT 700
#define MODES_ASYNC_BUF_NUMBER 16 #define MODES_ASYNC_BUF_NUMBER 16
#define MODES_ASYNC_BUF_SIZE (16*16384) // 256k // #define MODES_ASYNC_BUF_SIZE (16*16384) // 256k
#define MODES_ASYNC_BUF_SAMPLES (MODES_ASYNC_BUF_SIZE / 2) // Each sample is 2 bytes // #define MODES_ASYNC_BUF_SAMPLES (MODES_ASYNC_BUF_SIZE / 2) // Each sample is 2 bytes
#define MODES_AUTO_GAIN -100 // Use automatic gain // #define MODES_AUTO_GAIN -100 // Use automatic gain
#define MODES_MAX_GAIN 999999 // Use max available gain // #define MODES_MAX_GAIN 999999 // Use max available gain
#define MODES_MSG_SQUELCH_LEVEL 0x02FF // Average signal strength limit // #define MODES_MSG_SQUELCH_LEVEL 0x02FF // Average signal strength limit
#define MODES_MSG_ENCODER_ERRS 3 // Maximum number of encoding errors // #define MODES_MSG_ENCODER_ERRS 3 // Maximum number of encoding errors
// When changing, change also fixBitErrors() and modesInitErrorTable() !! // // When changing, change also fixBitErrors() and modesInitErrorTable() !!
#define MODES_MAX_BITERRORS 2 // Global max for fixable bit erros #define MODES_MAX_BITERRORS 2 // Global max for fixable bit erros
#define MODEAC_MSG_SAMPLES (25 * 2) // include up to the SPI bit // #define MODEAC_MSG_SAMPLES (25 * 2) // include up to the SPI bit
#define MODEAC_MSG_BYTES 2 #define MODEAC_MSG_BYTES 2
#define MODEAC_MSG_SQUELCH_LEVEL 0x07FF // Average signal strength limit #define MODEAC_MSG_SQUELCH_LEVEL 0x07FF // Average signal strength limit
#define MODEAC_MSG_FLAG (1<<0) #define MODEAC_MSG_FLAG (1<<0)
#define MODEAC_MSG_MODES_HIT (1<<1) // #define MODEAC_MSG_MODES_HIT (1<<1)
#define MODEAC_MSG_MODEA_HIT (1<<2) #define MODEAC_MSG_MODEA_HIT (1<<2)
#define MODEAC_MSG_MODEC_HIT (1<<3) #define MODEAC_MSG_MODEC_HIT (1<<3)
#define MODEAC_MSG_MODEA_ONLY (1<<4) #define MODEAC_MSG_MODEA_ONLY (1<<4)
@ -112,13 +114,13 @@
#define MODES_LONG_MSG_BITS (MODES_LONG_MSG_BYTES * 8) #define MODES_LONG_MSG_BITS (MODES_LONG_MSG_BYTES * 8)
#define MODES_SHORT_MSG_BITS (MODES_SHORT_MSG_BYTES * 8) #define MODES_SHORT_MSG_BITS (MODES_SHORT_MSG_BYTES * 8)
#define MODES_LONG_MSG_SAMPLES (MODES_LONG_MSG_BITS * 2) #define MODES_LONG_MSG_SAMPLES (MODES_LONG_MSG_BITS * 2)
#define MODES_SHORT_MSG_SAMPLES (MODES_SHORT_MSG_BITS * 2) // #define MODES_SHORT_MSG_SAMPLES (MODES_SHORT_MSG_BITS * 2)
#define MODES_LONG_MSG_SIZE (MODES_LONG_MSG_SAMPLES * sizeof(uint16_t)) // #define MODES_LONG_MSG_SIZE (MODES_LONG_MSG_SAMPLES * sizeof(uint16_t))
#define MODES_SHORT_MSG_SIZE (MODES_SHORT_MSG_SAMPLES * sizeof(uint16_t)) // #define MODES_SHORT_MSG_SIZE (MODES_SHORT_MSG_SAMPLES * sizeof(uint16_t))
#define MODES_RAWOUT_BUF_SIZE (1500) // #define MODES_RAWOUT_BUF_SIZE (1500)
#define MODES_RAWOUT_BUF_FLUSH (MODES_RAWOUT_BUF_SIZE - 200) // #define MODES_RAWOUT_BUF_FLUSH (MODES_RAWOUT_BUF_SIZE - 200)
#define MODES_RAWOUT_BUF_RATE (1000) // 1000 * 64mS = 1 Min approx // #define MODES_RAWOUT_BUF_RATE (1000) // 1000 * 64mS = 1 Min approx
#define MODES_ICAO_CACHE_LEN 1024 // Power of two required #define MODES_ICAO_CACHE_LEN 1024 // Power of two required
#define MODES_ICAO_CACHE_TTL 60 // Time to live of cached addresses #define MODES_ICAO_CACHE_TTL 60 // Time to live of cached addresses
@ -146,45 +148,45 @@
#define MODES_ACFLAGS_LLEITHER_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID) #define MODES_ACFLAGS_LLEITHER_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID)
#define MODES_ACFLAGS_LLBOTH_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID) #define MODES_ACFLAGS_LLBOTH_VALID (MODES_ACFLAGS_LLEVEN_VALID | MODES_ACFLAGS_LLODD_VALID)
#define MODES_ACFLAGS_AOG_GROUND (MODES_ACFLAGS_AOG_VALID | MODES_ACFLAGS_AOG) // #define MODES_ACFLAGS_AOG_GROUND (MODES_ACFLAGS_AOG_VALID | MODES_ACFLAGS_AOG)
#define MODES_DEBUG_DEMOD (1<<0) // #define MODES_DEBUG_DEMOD (1<<0)
#define MODES_DEBUG_DEMODERR (1<<1) // #define MODES_DEBUG_DEMODERR (1<<1)
#define MODES_DEBUG_BADCRC (1<<2) // #define MODES_DEBUG_BADCRC (1<<2)
#define MODES_DEBUG_GOODCRC (1<<3) // #define MODES_DEBUG_GOODCRC (1<<3)
#define MODES_DEBUG_NOPREAMBLE (1<<4) // #define MODES_DEBUG_NOPREAMBLE (1<<4)
#define MODES_DEBUG_NET (1<<5) #define MODES_DEBUG_NET (1<<5)
#define MODES_DEBUG_JS (1<<6) // #define MODES_DEBUG_JS (1<<6)
// When debug is set to MODES_DEBUG_NOPREAMBLE, the first sample must be // // When debug is set to MODES_DEBUG_NOPREAMBLE, the first sample must be
// at least greater than a given level for us to dump the signal. // // at least greater than a given level for us to dump the signal.
#define MODES_DEBUG_NOPREAMBLE_LEVEL 25 // #define MODES_DEBUG_NOPREAMBLE_LEVEL 25
#define MODES_INTERACTIVE_REFRESH_TIME 250 // Milliseconds // #define MODES_INTERACTIVE_REFRESH_TIME 250 // Milliseconds
#define MODES_INTERACTIVE_ROWS 22 // Rows on screen // #define MODES_INTERACTIVE_ROWS 22 // Rows on screen
#define MODES_INTERACTIVE_DELETE_TTL 300 // Delete from the list after 300 seconds #define MODES_INTERACTIVE_DELETE_TTL 300 // Delete from the list after 300 seconds
#define MODES_INTERACTIVE_DISPLAY_TTL 60 // Delete from display after 60 seconds #define MODES_INTERACTIVE_DISPLAY_TTL 60 // Delete from display after 60 seconds
#define MODES_NET_HEARTBEAT_RATE 900 // Each block is approx 65mS - default is > 1 min // #define MODES_NET_HEARTBEAT_RATE 900 // Each block is approx 65mS - default is > 1 min
#define MODES_NET_SERVICES_NUM 6 #define MODES_NET_SERVICES_NUM 6
#define MODES_NET_INPUT_RAW_PORT 30001 // #define MODES_NET_INPUT_RAW_PORT 30001
#define MODES_NET_OUTPUT_RAW_PORT 30002 // #define MODES_NET_OUTPUT_RAW_PORT 30002
#define MODES_NET_OUTPUT_SBS_PORT 30003 // #define MODES_NET_OUTPUT_SBS_PORT 30003
#define MODES_NET_INPUT_BEAST_PORT 30004 // #define MODES_NET_INPUT_BEAST_PORT 30004
#define MODES_NET_OUTPUT_BEAST_PORT 30005 #define MODES_NET_OUTPUT_BEAST_PORT 30005
#define MODES_NET_HTTP_PORT 8080 // #define MODES_NET_HTTP_PORT 8080
#define MODES_CLIENT_BUF_SIZE 1024 #define MODES_CLIENT_BUF_SIZE 1024
#define MODES_NET_SNDBUF_SIZE (1024*64) // #define MODES_NET_SNDBUF_SIZE (1024*64)
#define MODES_NET_SNDBUF_MAX (7) // #define MODES_NET_SNDBUF_MAX (7)
#ifndef HTMLPATH // #ifndef HTMLPATH
#define HTMLPATH "./public_html" // default path for gmap.html etc // #define HTMLPATH "./public_html" // default path for gmap.html etc
#endif // #endif
#define MODES_NOTUSED(V) ((void) V) #define MODES_NOTUSED(V) ((void) V)
//======================== structure declarations ========================= // //======================== structure declarations =========================
// Structure used to describe a networking client // Structure used to describe a networking client
struct client { struct client {
@ -263,7 +265,7 @@ typedef struct Modes{ // Internal state
int dev_index; int dev_index;
int gain; int gain;
int enable_agc; int enable_agc;
rtlsdr_dev_t *dev; // rtlsdr_dev_t *dev;
int freq; int freq;
int ppm_error; int ppm_error;
@ -418,7 +420,7 @@ struct modesMessage {
int bFlags; // Flags related to fields in this structure int bFlags; // Flags related to fields in this structure
}; };
// ======================== function declarations ========================= // // ======================== function declarations =========================
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -449,7 +451,8 @@ 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(Modes *modes, uint32_t addr);
struct stDF *interactiveFindDF (uint32_t addr); struct stDF *interactiveFindDF (uint32_t addr);
// //

BIN
gmon.out Normal file

Binary file not shown.

3
run.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
../dump1090/dump1090 --fix --aggressive --net --quiet &
./viz1090 --fps --fullscreen --screensize 240 320 --lat 47.6 --lon -122.3

View file

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
./viz1090 --screensize 640 360 --fullscreen --server adsb --lat 47.6 --lon -122.3 ./viz1090 --screensize 1920 1080 --fullscreen --server adsb --lat 47.6 --lon -122.3

View file

@ -1,84 +0,0 @@
// view1090, a Mode S messages viewer for dump1090 devices.
//
// Copyright (C) 2013 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.
//
#ifndef __VIEW1090_H
#define __VIEW1090_H
// ============================= Include files ==========================
#include "dump1090.h"
#ifndef _WIN32
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "rtl-sdr.h"
#include "anet.h"
#else
#include "winstubs.h" //Put everything Windows specific in here
#endif
// ============================= #defines ===============================
#define VIEW1090_NET_OUTPUT_IP_ADDRESS "127.0.0.1"
#define NOTUSED(V) ((void) V)
// ======================== structure declarations ========================
// Program global state
struct { // Internal state
// Networking
char net_input_beast_ipaddr[32]; // IPv4 address or network name of server/RPi
} View1090;
// ======================== function declarations =========================
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // __VIEW1090_H

View file

@ -33,7 +33,6 @@
#include "View.h" #include "View.h"
#include "Input.h" #include "Input.h"
#include <cstring> #include <cstring>
int go = 1; int go = 1;
@ -69,24 +68,18 @@ void showHelp(void) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int j;
AppData appData; AppData appData;
View view(&appData); View view(&appData);
Input input(&appData,&view);
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
appData.initialize();
// Parse the command line options // Parse the command line options
for (j = 1; j < argc; j++) { for (int j = 1; j < argc; j++) {
int more = ((j + 1) < argc); // There are more arguments int more = ((j + 1) < argc); // There are more arguments
if (!strcmp(argv[j],"--port") && more) { if (!strcmp(argv[j],"--port") && more) {
appData.modes.net_input_beast_port = atoi(argv[++j]); appData.modes.net_input_beast_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--server") && more) { } else if (!strcmp(argv[j],"--server") && more) {
std::strcpy(appData.server, argv[++j]); std::strcpy(appData.server, argv[++j]);
} else if (!strcmp(argv[j],"--lat") && more) { } else if (!strcmp(argv[j],"--lat") && more) {
appData.modes.fUserLat = atof(argv[++j]); appData.modes.fUserLat = atof(argv[++j]);
view.centerLat = appData.modes.fUserLat; view.centerLat = appData.modes.fUserLat;
@ -96,16 +89,16 @@ int main(int argc, char **argv) {
} else if (!strcmp(argv[j],"--metric")) { } else if (!strcmp(argv[j],"--metric")) {
view.metric = 1; view.metric = 1;
} else if (!strcmp(argv[j],"--fps")) { } else if (!strcmp(argv[j],"--fps")) {
view.fps = 1; 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")) {
view.screen_index = atoi(argv[++j]); view.screen_index = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--uiscale") && more) { } else if (!strcmp(argv[j],"--uiscale") && more) {
view.screen_uiscale = atoi(argv[++j]); view.screen_uiscale = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--screensize") && more) { } else if (!strcmp(argv[j],"--screensize") && more) {
view.screen_width = atoi(argv[++j]); view.screen_width = atoi(argv[++j]);
view.screen_height = atoi(argv[++j]); view.screen_height = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--help")) { } else if (!strcmp(argv[j],"--help")) {
showHelp(); showHelp();
exit(0); exit(0);
@ -115,20 +108,27 @@ int main(int argc, char **argv) {
exit(1); exit(1);
} }
} }
int go;
appData.initialize();
view.SDL_init(); view.SDL_init();
view.font_init(); view.font_init();
Input input(&appData,&view);
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
int go;
go = 1; go = 1;
while (go == 1) while (go == 1)
{ {
appData.connect();
input.getInput(); input.getInput();
appData.update();
view.draw(); view.draw();
appData.connect();
appData.update();
} }
appData.disconnect(); appData.disconnect();