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

Former-commit-id: 71d4638e160eedca1b60df37b3d2b5d1ecf82469
Former-commit-id: 5f78e0bfefba107919a5babf344a3d51110a16fd
This commit is contained in:
Nathan 2017-09-15 21:25:26 -05:00
parent ac27da70ea
commit d7ac05e2b2
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)\" EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
endif endif
CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -std=c99 ifdef RPI
LIBS=`pkg-config --libs librtlsdr` -lpthread -lm `sdl-config --libs` -lSDL -lSDL_ttf -lSDL_gfx -lwiringPi CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -std=c99
CC=gcc 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 all: view1090
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) $(EXTRACFLAGS) -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 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 $(LIBS) $(LDFLAGS) $(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: clean:
rm -f *.o view1090 rm -f *.o view1090

View file

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

View file

@ -3,11 +3,10 @@
#include "parula.h" #include "parula.h"
#include "SDL/SDL_gfxPrimitives.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 AA 0
#define MAXDIST 1000.0
void CROSSVP(double *v, double *u, double *w) 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) { int screenDist(double d) {
if(LOGPROJECTION) { if(Modes.mapLogDist) {
return round((double)SCREEN_WIDTH * 0.5 * log(1.0+d) / log(1.0+MAXDIST)); return round((double)SCREEN_WIDTH * 0.5 * log(1.0+fabs(d)) / log(1.0+LOGMAXDIST));
} else { } 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) { void screenCoords(int *outX, int *outY, double dx, double dy) {
*outX = (SCREEN_WIDTH>>1) + screenDist(dx); *outX = (SCREEN_WIDTH>>1) + ((dx>0) ? 1 : -1) * screenDist(dx);
*outY = (SCREEN_HEIGHT>>1) + screenDist(dy); *outY = (SCREEN_HEIGHT>>1) + ((dy>0) ? 1 : -1) * screenDist(dy);
} }
int outOfBounds(int x, int y) { 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) void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight)
{ {
//int planeWidth = 2;
int x, y; int x, y;
screenCoords(&x, &y, dx, dy); 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]); x2 = x + round(body*vec[0]);
y2 = y + round(body*vec[1]); 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); 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 //wing
@ -103,17 +107,26 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
y2 = y + round(wing*out[1]); y2 = y + round(wing*out[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); //thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
aalineRGBA(game.screen,x1,y1,x2,y2,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 //tail
x1 = x + round(-body*vec[0]) + round(-tail*out[0]); x1 = x + round(-body*.75*vec[0]) + round(-tail*out[0]);
y1 = y + round(-body*vec[1]) + round(-tail*out[1]); y1 = y + round(-body*.75*vec[1]) + round(-tail*out[1]);
x2 = x + round(-body*vec[0]) + round(tail*out[0]); x2 = x + round(-body*.75*vec[0]) + round(tail*out[0]);
y2 = y + round(-body*vec[1]) + round(tail*out[1]); 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); //thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
aalineRGBA(game.screen,x1,y1,x2,y2,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)) { if(strlen(flight)) {
drawString(flight, x + 10, y + 10, game.font, planeColor); drawString(flight, x + 10, y + 10, game.font, planeColor);
@ -189,8 +202,13 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
} }
uint8_t colorVal = (uint8_t)floor(127.0 * age); uint8_t colorVal = (uint8_t)floor(127.0 * age);
aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); 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 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 interactive_rtl1090; // flight table in interactive mode is formatted like RTL1090
int map;
int mapLogDist;
// User details // User details
double fUserLat; // Users receiver/antenna lat/lon needed for initial surface location double fUserLat; // Users receiver/antenna lat/lon needed for initial surface location
double fUserLon; // 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 modesQueueOutput (struct modesMessage *mm);
void modesReadFromClient(struct client *c, char *sep, int(*handler)(struct client *, char *)); void modesReadFromClient(struct client *c, char *sep, int(*handler)(struct client *, char *));
//
// Functions exported from maps.c
//
void drawMap (void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

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

View file

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

View file

@ -29,14 +29,6 @@
// //
#include "dump1090.h" #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 ========================== // ============================= Utility functions ==========================
@ -472,9 +464,6 @@ void interactiveShowData(void) {
} }
printf( printf(
"-------------------------------------------------------------------------------\n"); "-------------------------------------------------------------------------------\n");
SDL_FillRect(game.screen, NULL, 0);
drawGrid();
while(a && (count < Modes.interactive_rows)) { while(a && (count < Modes.interactive_rows)) {
@ -539,21 +528,6 @@ void interactiveShowData(void) {
snprintf(strLat, 8,"%7.03f", a->dx); snprintf(strLat, 8,"%7.03f", a->dx);
snprintf(strLon, 9,"%8.03f", a->dy); 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);
}
} }
@ -572,8 +546,6 @@ void interactiveShowData(void) {
} }
a = a->next; 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; SDL_Surface *screen;
TTF_Font *font; TTF_Font *font;
} Game; } 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; 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; int go = 1;
// //
@ -91,7 +82,10 @@ void view1090InitConfig(void) {
Modes.fUserLat = MODES_USER_LATITUDE_DFLT; Modes.fUserLat = MODES_USER_LATITUDE_DFLT;
Modes.fUserLon = MODES_USER_LONGITUDE_DFLT; Modes.fUserLon = MODES_USER_LONGITUDE_DFLT;
Modes.interactive = 1; Modes.interactive = 0;
Modes.quiet = 1;
Modes.map = 1;
Modes.mapLogDist = 1;
} }
// //
//========================================================================= //=========================================================================
@ -311,7 +305,8 @@ int main(int argc, char **argv) {
c = (struct client *) malloc(sizeof(*c)); c = (struct client *) malloc(sizeof(*c));
while(1) { while(1) {
if ((fd = setupConnection(c)) == ANET_ERR) { if ((fd = setupConnection(c)) == ANET_ERR) {
fprintf(stderr, "Waiting on %s:%d\n", View1090.net_input_beast_ipaddr, Modes.net_input_beast_port); fprintf(stderr, "Waiting on %s:%d\n", View1090.net_input_beast_ipaddr, Modes.net_input_beast_port);
sleep(1);
} else { } else {
break; break;
} }
@ -346,13 +341,7 @@ int main(int argc, char **argv) {
atexit(cleanup); atexit(cleanup);
go = 1; go = 1;
/* Load the font */
game.font = loadFont("Arial.ttf", 10);
while (go == 1) while (go == 1)
{ {
@ -360,7 +349,15 @@ int main(int argc, char **argv) {
interactiveRemoveStaleAircrafts(); interactiveRemoveStaleAircrafts();
interactiveShowData();
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)) { 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);
@ -369,20 +366,8 @@ int main(int argc, char **argv) {
continue; continue;
} }
modesReadFromClient(c,"",decodeBinMessage); 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 // The user has stopped us, so close any socket we opened
if (fd != ANET_ERR) if (fd != ANET_ERR)
{close(fd);} {close(fd);}