/* Makes a simple HTML and SVG layout for GPSD */
/* (C)2007 Jason Hecker v0.03*/
/* This is a severely mangled version of xgps.c */
/* To use call: webgps [server] [port] [path] [period] */
/* server: the gpsd server you are connecting to */
/* port: the port number of the gpsd server */
/* path: the destination path for gpsd.svg/html */
/* period: time period in seconds for webgps to update */
#include
#include
#include
#include
#include
#include
#include
#include
/* v2.33 */
#include "config.h"
/* v2.34+ */
//#include "gpsd_config.h"
#include "gps.h"
#define TRACKMAX 1024
#define SATMAX 20
#define STALECOUNT 3
typedef struct trackloc_s{
int x;
int y;
} trackloc_t;
typedef struct trackloc_head_s{
int PRN;
int count;
int stale;
trackloc_t posn[TRACKMAX];
} trackloc_head_t;
trackloc_head_t sattrack[SATMAX];
static enum deg_str_type deg_type = deg_dd;
static struct gps_data_t *gpsdata;
static time_t timer; /* time of last state change */
static int state = 0; /* or MODE_NO_FIX=1, MODE_2D=2, MODE_3D=3 */
void do_html(FILE *fh);
void do_svg(FILE *fs);
void polartocart(int *x, int *y, int el, int az){
#define DEG2RAD PI/180.0
#define DIAMETER 200
#define XYOFFSET 10
float radius, theta;
radius = DIAMETER * cos(((float)(el)) * DEG2RAD);
theta = ((float)(az - 90) * DEG2RAD);
*x = (int)(radius * cos(theta) + 0.5) + DIAMETER + XYOFFSET;
*y = (int)(radius * sin(theta) + 0.5) + DIAMETER + XYOFFSET;
}
void do_html(FILE *fh){
int i, newstate;
char s[128], *latlon;
const char pageheader[] = "\n" \
"\t\n\tGPSD Satellite Positions and Readings\n\t\n\n" \
"
\n\t
\n\t\t
\n"
"\t\t\t
\n\t\t\t\t
PRN:
Elev:
Azim:
"
"
SNR:
Used:
\n\t\t\t
\n";
const char rowhead[] = "\t\t\t
\n\t\t\t\t
%s
%s
\n\t\t\t
\n";
fprintf(fh,pageheader);
if (gpsdata->satellites) {
for (i = 0; i < MAXCHANNELS; i++) {
if (i < (unsigned int)gpsdata->satellites) {
fprintf(fh,"\t\t\t