added log/lin toggle, AA define, rearanged into map.c

Former-commit-id: 5ccce0dd66b202b6e0178cc3cff2e4f9a70b736f
Former-commit-id: 3616fa85a3b74c0acc493e50224746adc8cf3c31
This commit is contained in:
Nathan 2017-09-15 21:25:26 -05:00
parent 345e7bf9fe
commit b63782bbf5
12 changed files with 193 additions and 106 deletions

View file

@ -0,0 +1 @@
940e255d0140b07a15ea0371695c25c02087f368

View file

@ -10,18 +10,23 @@ SHAREDIR=$(PREFIX)/share/$(PROGNAME)
EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
endif
ifdef RPI
CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -std=c99
LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl-config --libs` -lSDL -lSDL_ttf -lSDL_gfx -lwiringPi
LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl-config --libs` -lSDL -lSDL_ttf -lSDL_gfx -lwiringPi -DRPI
CC=gcc
else
CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr`
LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl-config --libs` -lSDL -lSDL_ttf -lSDL_gfx
CC=gcc
endif
all: view1090
%.o: %.c
$(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<
view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o
$(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o $(LIBS) $(LDFLAGS)
view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o
$(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o $(LIBS) $(LDFLAGS)
clean:
rm -f *.o view1090

View file

@ -1,8 +1,13 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#ifdef RPI
#include <wiringPi.h>
#endif
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

View file

@ -3,11 +3,10 @@
#include "parula.h"
#include "SDL/SDL_gfxPrimitives.h"
extern void drawString(char *, int, int, TTF_Font *, SDL_Color);
#define LOGMAXDIST 1000.0
#define MAXDIST 50.0
#define LOGPROJECTION 1
#define MAXDIST 1000.0
#define AA 0
void CROSSVP(double *v, double *u, double *w)
{
@ -25,16 +24,16 @@ SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
}
int screenDist(double d) {
if(LOGPROJECTION) {
return round((double)SCREEN_WIDTH * 0.5 * log(1.0+d) / log(1.0+MAXDIST));
if(Modes.mapLogDist) {
return round((double)SCREEN_WIDTH * 0.5 * log(1.0+fabs(d)) / log(1.0+LOGMAXDIST));
} else {
return round((double)SCREEN_WIDTH * 0.5 * d / MAXDIST);
return round((double)SCREEN_WIDTH * 0.5 * fabs(d) / MAXDIST);
}
}
void screenCoords(int *outX, int *outY, double dx, double dy) {
*outX = (SCREEN_WIDTH>>1) + screenDist(dx);
*outY = (SCREEN_HEIGHT>>1) + screenDist(dy);
*outX = (SCREEN_WIDTH>>1) + ((dx>0) ? 1 : -1) * screenDist(dx);
*outY = (SCREEN_HEIGHT>>1) + ((dy>0) ? 1 : -1) * screenDist(dy);
}
int outOfBounds(int x, int y) {
@ -45,10 +44,8 @@ int outOfBounds(int x, int y) {
}
}
void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight)
{
//int planeWidth = 2;
int x, y;
screenCoords(&x, &y, dx, dy);
@ -92,8 +89,15 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
x2 = x + round(body*vec[0]);
y2 = y + round(body*vec[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else {
thickLineRGBA(game.screen,x,y,x2,y2,2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledTrigonRGBA (game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//filledTrigonRGBA (game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x2, y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledCircleRGBA (game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
}
//wing
@ -103,17 +107,26 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
y2 = y + round(wing*out[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else {
filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(body*.35*vec[0]), y+round(body*.35*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
}
//tail
x1 = x + round(-body*vec[0]) + round(-tail*out[0]);
y1 = y + round(-body*vec[1]) + round(-tail*out[1]);
x2 = x + round(-body*vec[0]) + round(tail*out[0]);
y2 = y + round(-body*vec[1]) + round(tail*out[1]);
x1 = x + round(-body*.75*vec[0]) + round(-tail*out[0]);
y1 = y + round(-body*.75*vec[1]) + round(-tail*out[1]);
x2 = x + round(-body*.75*vec[0]) + round(tail*out[0]);
y2 = y + round(-body*.75*vec[1]) + round(tail*out[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else {
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(-body*.5*vec[0]), y+round(-body*.5*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
}
if(strlen(flight)) {
drawString(flight, x + 10, y + 10, game.font, planeColor);
@ -190,7 +203,12 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
uint8_t colorVal = (uint8_t)floor(127.0 * age);
if(AA) {
aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
} else {
//lineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 1, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
}
}
}

View file

@ -327,6 +327,9 @@ struct { // Internal state
int mlat; // Use Beast ascii format for raw data output, i.e. @...; iso *...;
int interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090
int map;
int mapLogDist;
// User details
double fUserLat; // Users receiver/antenna lat/lon needed for initial surface location
double fUserLon; // Users receiver/antenna lat/lon needed for initial surface location
@ -467,6 +470,13 @@ void modesSendAllClients (int service, void *msg, int len);
void modesQueueOutput (struct modesMessage *mm);
void modesReadFromClient(struct client *c, char *sep, int(*handler)(struct client *, char *));
//
// Functions exported from maps.c
//
void drawMap (void);
#ifdef __cplusplus
}
#endif

View file

@ -1,13 +1,10 @@
#include "init.h"
#include "SDL/SDL_getenv.h"
#include <wiringPi.h>
extern void closeFont(TTF_Font *);
void init(char *title)
{
#ifdef RPI
wiringPiSetupGpio() ;
pinMode(23, INPUT);
@ -17,6 +14,8 @@ void init(char *title)
putenv((char*)"FRAMEBUFFER=/dev/fb1");
putenv((char*)"SDL_FBDEV=/dev/fb1");
#endif
/* Initialise SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
@ -46,6 +45,10 @@ void init(char *title)
exit(1);
}
/* Load the font */
game.font = loadFont("ArialBold.ttf", 12);
/* Set the screen title */
SDL_WM_SetCaption(title, NULL);

View file

@ -1,12 +1,14 @@
#include "input.h"
#include <wiringPi.h>
#include "view1090.h"
void getInput()
{
#ifdef RPI
if(!digitalRead(23) || !digitalRead(22)) {
exit(0);
}
#endif
SDL_Event event;
@ -14,8 +16,6 @@ void getInput()
while (SDL_PollEvent(&event))
{
fprintf(stderr,"key: %d\n", event.key.keysym.sym);
switch (event.type)
{
/* Closing the Window or pressing Escape will exit the program */
@ -31,6 +31,10 @@ void getInput()
exit(0);
break;
case SDLK_l:
Modes.mapLogDist = !Modes.mapLogDist;
break;
default:
break;
}

View file

@ -29,14 +29,6 @@
//
#include "dump1090.h"
#include "structs.h"
Game game;
extern void drawPlaneHeading(double , double , double, int, char *);
extern void drawPlane(double , double, int);
extern void drawTrail(double *, double *, time_t *, int);
extern void drawGrid();
//
// ============================= Utility functions ==========================
@ -472,9 +464,6 @@ void interactiveShowData(void) {
}
printf(
"-------------------------------------------------------------------------------\n");
SDL_FillRect(game.screen, NULL, 0);
drawGrid();
while(a && (count < Modes.interactive_rows)) {
@ -540,21 +529,6 @@ void interactiveShowData(void) {
snprintf(strLat, 8,"%7.03f", a->dx);
snprintf(strLon, 9,"%8.03f", a->dy);
drawTrail(a->oldDx, a->oldDy, a->oldSeen, a->oldIdx);
int colorIdx;
if((int)(now - a->seen) > MODES_INTERACTIVE_DISPLAY_ACTIVE) {
colorIdx = -1;
} else {
colorIdx = signalAverage;
}
if(MODES_ACFLAGS_HEADING_VALID) {
drawPlaneHeading(a->dx, a->dy,a->track, colorIdx, a->flight);
} else {
drawPlane(a->dx, a->dy, colorIdx);
}
}
if (a->bFlags & MODES_ACFLAGS_AOG) {
@ -572,8 +546,6 @@ void interactiveShowData(void) {
}
a = a->next;
}
SDL_Flip(game.screen);
}
//
//=========================================================================

68
sdl1090/maps.c Normal file
View file

@ -0,0 +1,68 @@
#include "dump1090.h"
#include "structs.h"
Game game;
extern void drawPlaneHeading(double , double , double, int, char *);
extern void drawPlane(double , double, int);
extern void drawTrail(double *, double *, time_t *, int);
extern void drawGrid();
//
// ============================= Utility functions ==========================
//
static uint64_t mstime(void) {
struct timeval tv;
uint64_t mst;
gettimeofday(&tv, NULL);
mst = ((uint64_t)tv.tv_sec)*1000;
mst += tv.tv_usec/1000;
return mst;
}
void drawMap(void) {
struct aircraft *a = Modes.aircrafts;
time_t now = time(NULL);
// Refresh screen every (MODES_INTERACTIVE_REFRESH_TIME) miliseconde
if ((mstime() - Modes.interactive_last_update) < MODES_INTERACTIVE_REFRESH_TIME)
{return;}
Modes.interactive_last_update = mstime();
SDL_FillRect(game.screen, NULL, 0);
drawGrid();
while(a) {
if ((now - a->seen) < Modes.interactive_display_ttl) {
if (a->bFlags & MODES_ACFLAGS_LATLON_VALID) {
unsigned char * pSig = a->signalLevel;
unsigned int signalAverage = (pSig[0] + pSig[1] + pSig[2] + pSig[3] +
pSig[4] + pSig[5] + pSig[6] + pSig[7] + 3) >> 3;
drawTrail(a->oldDx, a->oldDy, a->oldSeen, a->oldIdx);
int colorIdx;
if((int)(now - a->seen) > MODES_INTERACTIVE_DISPLAY_ACTIVE) {
colorIdx = -1;
} else {
colorIdx = signalAverage;
}
if(MODES_ACFLAGS_HEADING_VALID) {
drawPlaneHeading(a->dx, a->dy,a->track, colorIdx, a->flight);
} else {
drawPlane(a->dx, a->dy, colorIdx);
}
}
}
a = a->next;
}
SDL_Flip(game.screen);
}

View file

@ -5,3 +5,19 @@ typedef struct Game
SDL_Surface *screen;
TTF_Font *font;
} Game;
// functions
//font.c
TTF_Font *loadFont(char *, int);
void closeFont(TTF_Font *);
void drawString(char *, int, int, TTF_Font *, SDL_Color);
//init.c
void init(char *);
void cleanup(void);
//input.c
void getInput(void);
//draw.c

View file

@ -1 +1 @@
ed63e44c0b11204e27b1007445b40aa85a15684a
8b349b0a3cce846239af437d2b37503588a29b20

View file

@ -33,15 +33,6 @@
Game game;
#define SDL_MAIN_HANDLED
extern void init(char *);
extern void cleanup(void);
extern void getInput(void);
extern void draw(void);
extern TTF_Font *loadFont(char *, int);
extern void delay(unsigned int);
int go = 1;
//
@ -91,7 +82,10 @@ void view1090InitConfig(void) {
Modes.fUserLat = MODES_USER_LATITUDE_DFLT;
Modes.fUserLon = MODES_USER_LONGITUDE_DFLT;
Modes.interactive = 1;
Modes.interactive = 0;
Modes.quiet = 1;
Modes.map = 1;
Modes.mapLogDist = 1;
}
//
//=========================================================================
@ -312,6 +306,7 @@ int main(int argc, char **argv) {
while(1) {
if ((fd = setupConnection(c)) == ANET_ERR) {
fprintf(stderr, "Waiting on %s:%d\n", View1090.net_input_beast_ipaddr, Modes.net_input_beast_port);
sleep(1);
} else {
break;
}
@ -348,19 +343,21 @@ int main(int argc, char **argv) {
go = 1;
/* Load the font */
game.font = loadFont("Arial.ttf", 10);
while (go == 1)
{
getInput();
interactiveRemoveStaleAircrafts();
if (Modes.interactive) {
interactiveShowData();
}
if (Modes.map) {
drawMap();
}
if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) {
free(c);
usleep(1000000);
@ -369,20 +366,8 @@ int main(int argc, char **argv) {
continue;
}
modesReadFromClient(c,"",decodeBinMessage);
usleep(50000);
// draw();
/* Sleep briefly to stop sucking up all the CPU time */
// delay(frameLimit);
// frameLimit = SDL_GetTicks() + 16;
}
// The user has stopped us, so close any socket we opened
if (fd != ANET_ERR)
{close(fd);}