mirror of
https://github.com/eddyem/eddys_snippets.git
synced 2025-12-06 02:35:12 +03:00
mean coordinates
This commit is contained in:
parent
5fb62b00ab
commit
139686f0bf
@ -35,6 +35,7 @@ glob_pars Gdefault = {
|
|||||||
,.polltmout = 10.
|
,.polltmout = 10.
|
||||||
,.stationary = 0
|
,.stationary = 0
|
||||||
,.gettimediff = 0
|
,.gettimediff = 0
|
||||||
|
,.meancoords = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -57,6 +58,7 @@ myoption cmdlnopts[] = {
|
|||||||
{"timeout", 1, NULL, 't', arg_double, APTR(&G.polltmout), N_("polling timeout")},
|
{"timeout", 1, NULL, 't', arg_double, APTR(&G.polltmout), N_("polling timeout")},
|
||||||
{"stationary",0, NULL, 's', arg_int, APTR(&G.stationary),N_("configure as stationary")},
|
{"stationary",0, NULL, 's', arg_int, APTR(&G.stationary),N_("configure as stationary")},
|
||||||
{"timediff",0, NULL, 'T', arg_int, APTR(&G.gettimediff),N_("calculate mean time difference")},
|
{"timediff",0, NULL, 'T', arg_int, APTR(&G.gettimediff),N_("calculate mean time difference")},
|
||||||
|
{"coords",0, NULL, 'C', arg_int, APTR(&G.meancoords), N_("calculate mean coordinates")},
|
||||||
// ...
|
// ...
|
||||||
end_option
|
end_option
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,6 +48,7 @@ typedef struct{
|
|||||||
double polltmout; // polling timeout (program ends after this interval)
|
double polltmout; // polling timeout (program ends after this interval)
|
||||||
int stationary; // configure as stationary
|
int stationary; // configure as stationary
|
||||||
int gettimediff; // calculate mean time difference
|
int gettimediff; // calculate mean time difference
|
||||||
|
int meancoords; // calculate mean coordinates
|
||||||
}glob_pars;
|
}glob_pars;
|
||||||
|
|
||||||
glob_pars *parce_args(int argc, char **argv);
|
glob_pars *parce_args(int argc, char **argv);
|
||||||
|
|||||||
175
GPS/main.c
175
GPS/main.c
@ -26,6 +26,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <math.h> // sqrt
|
||||||
|
|
||||||
|
|
||||||
#ifndef PIDFILE
|
#ifndef PIDFILE
|
||||||
@ -39,6 +40,7 @@ char *GPmsgs[] = {"GSV", "RMC", "GSA", "GGA", "GLL", "VTG"};
|
|||||||
|
|
||||||
static void signals(int sig){
|
static void signals(int sig){
|
||||||
DBG("Get signal %d, quit.\n", sig);
|
DBG("Get signal %d, quit.\n", sig);
|
||||||
|
unlink(PIDFILE);
|
||||||
restore_tty();
|
restore_tty();
|
||||||
exit(sig);
|
exit(sig);
|
||||||
}
|
}
|
||||||
@ -119,7 +121,7 @@ int timediff_N = 0;
|
|||||||
* difference (in seconds) in system & GPS clock
|
* difference (in seconds) in system & GPS clock
|
||||||
* @return system_time - GPS_time
|
* @return system_time - GPS_time
|
||||||
*/
|
*/
|
||||||
double timediff(int h, int m, float s){
|
double timediff(int h, int m, double s){
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
time_t tm0 = time(NULL);
|
time_t tm0 = time(NULL);
|
||||||
@ -132,48 +134,8 @@ double timediff(int h, int m, float s){
|
|||||||
return td;
|
return td;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Latt_mean = 0., Long_mean = 0., Latt_sq = 0., Long_sq = 0.;
|
||||||
/*
|
int Latt_N = 0, Long_N = 0;
|
||||||
* Satellites in View
|
|
||||||
* $GPGSV,NoMsg,MsgNo,NoSv,{,sv,elv,az,cno}*cs
|
|
||||||
* 1 = total number of GPGSV messages being output
|
|
||||||
* 2 = Number of this message
|
|
||||||
* 3 = Satellites in View
|
|
||||||
* 4-7 will be repeated 1..4 times
|
|
||||||
* sv = Satellite ID
|
|
||||||
* elv = Elevation, range 0..90deg
|
|
||||||
* az = Azimuth, range 0..359deg
|
|
||||||
* cno = SNR, range 0.99dB
|
|
||||||
* cs = control sum
|
|
||||||
* 3,1,11,01,68,278,,03,39,292,08,04,66,190,30,11,55,231,34*79
|
|
||||||
* 3,2,11,14,30,050,10,17,11,322,,19,09,202,,22,14,096,*74
|
|
||||||
* 3,3,11,23,20,232,30,31,43,118,33,32,76,352,*43
|
|
||||||
*/
|
|
||||||
void gsv(uint8_t *buf){
|
|
||||||
//DBG("gsv: %s\n", buf);
|
|
||||||
int Nrec = -1, Ncur, inview = 0;
|
|
||||||
static int sat_scanned = 0;
|
|
||||||
if(sscanf((char*)buf, "%d,%d,", &Nrec, &Ncur) != 2) goto ret;
|
|
||||||
SKIP(2);
|
|
||||||
if(sscanf((char*)buf, "%d,", &inview) != 1) goto ret;
|
|
||||||
if(inview < 1) goto ret;
|
|
||||||
NEXT();
|
|
||||||
if(Ncur == 1)
|
|
||||||
printf("%d satellites in view field: (No: ID, elevation, azimuth, SNR)\n", inview);
|
|
||||||
do{
|
|
||||||
int id, el, az, snr;
|
|
||||||
// there could be no "SNR" field if we can't find this satellite on sky
|
|
||||||
if(sscanf((char*)buf, "%d,%d,%d,%d,", &id, &el, &az, &snr) < 3) break;
|
|
||||||
printf(" (%d: %d, %d, %d, %d)", ++sat_scanned, id, el, az, snr);
|
|
||||||
SKIP(4);
|
|
||||||
}while(1);
|
|
||||||
ret:
|
|
||||||
if(inview < 1) printf("There's no GPS satellites in viewfield\n");
|
|
||||||
if(Nrec > 0 && Nrec == Ncur){
|
|
||||||
sat_scanned = 0;
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* acquire last command
|
* acquire last command
|
||||||
@ -269,6 +231,48 @@ printf("\n");
|
|||||||
}while(!get_ACK(prec) && ++i < 11);
|
}while(!get_ACK(prec) && ++i < 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Satellites in View
|
||||||
|
* $GPGSV,NoMsg,MsgNo,NoSv,{,sv,elv,az,cno}*cs
|
||||||
|
* 1 = total number of GPGSV messages being output
|
||||||
|
* 2 = Number of this message
|
||||||
|
* 3 = Satellites in View
|
||||||
|
* 4-7 will be repeated 1..4 times
|
||||||
|
* sv = Satellite ID
|
||||||
|
* elv = Elevation, range 0..90deg
|
||||||
|
* az = Azimuth, range 0..359deg
|
||||||
|
* cno = SNR, range 0.99dB
|
||||||
|
* cs = control sum
|
||||||
|
* 3,1,11,01,68,278,,03,39,292,08,04,66,190,30,11,55,231,34*79
|
||||||
|
* 3,2,11,14,30,050,10,17,11,322,,19,09,202,,22,14,096,*74
|
||||||
|
* 3,3,11,23,20,232,30,31,43,118,33,32,76,352,*43
|
||||||
|
*/
|
||||||
|
void gsv(uint8_t *buf){
|
||||||
|
//DBG("gsv: %s\n", buf);
|
||||||
|
int Nrec = -1, Ncur, inview = 0;
|
||||||
|
static int sat_scanned = 0;
|
||||||
|
if(sscanf((char*)buf, "%d,%d,", &Nrec, &Ncur) != 2) goto ret;
|
||||||
|
SKIP(2);
|
||||||
|
if(sscanf((char*)buf, "%d,", &inview) != 1) goto ret;
|
||||||
|
if(inview < 1) goto ret;
|
||||||
|
NEXT();
|
||||||
|
if(Ncur == 1)
|
||||||
|
printf("%d satellites in view field: (No: ID, elevation, azimuth, SNR)\n", inview);
|
||||||
|
do{
|
||||||
|
int id, el, az, snr;
|
||||||
|
// there could be no "SNR" field if we can't find this satellite on sky
|
||||||
|
if(sscanf((char*)buf, "%d,%d,%d,%d,", &id, &el, &az, &snr) < 3) break;
|
||||||
|
printf(" (%d: %d, %d, %d, %d)", ++sat_scanned, id, el, az, snr);
|
||||||
|
SKIP(4);
|
||||||
|
}while(1);
|
||||||
|
ret:
|
||||||
|
if(inview < 1) printf("There's no GPS satellites in viewfield\n");
|
||||||
|
if(Nrec > 0 && Nrec == Ncur){
|
||||||
|
sat_scanned = 0;
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recommended minimum specific GPS/Transit data
|
* Recommended minimum specific GPS/Transit data
|
||||||
* $GPRMC,hhmmss,status,latitude,N,longitude,E,spd,cog,ddmmyy,mv,mvE,mode*cs
|
* $GPRMC,hhmmss,status,latitude,N,longitude,E,spd,cog,ddmmyy,mv,mvE,mode*cs
|
||||||
@ -289,10 +293,9 @@ printf("\n");
|
|||||||
void rmc(uint8_t *buf){
|
void rmc(uint8_t *buf){
|
||||||
//DBG("rmc: %s\n", buf);
|
//DBG("rmc: %s\n", buf);
|
||||||
int H, M, LO, LA, d, m, y;
|
int H, M, LO, LA, d, m, y;
|
||||||
float S;
|
double S, longitude, lattitude, speed, track, mag;
|
||||||
float longitude, lattitude, speed, track, mag;
|
|
||||||
char varn = 'V', north = '0', east = '0', mageast = '0', mode = 'N';
|
char varn = 'V', north = '0', east = '0', mageast = '0', mode = 'N';
|
||||||
sscanf((char*)buf, "%2d%2d%f", &H, &M, &S);
|
sscanf((char*)buf, "%2d%2d%lf", &H, &M, &S);
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ',') varn = *buf;
|
if(*buf != ',') varn = *buf;
|
||||||
if(varn != 'A')
|
if(varn != 'A')
|
||||||
@ -302,41 +305,47 @@ void rmc(uint8_t *buf){
|
|||||||
printf(" time: %02d:%02d:%05.2f", H, M, S);
|
printf(" time: %02d:%02d:%05.2f", H, M, S);
|
||||||
printf(" timediff: %g", timediff(H, M, S));
|
printf(" timediff: %g", timediff(H, M, S));
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%2d%f", &LA, &lattitude);
|
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
north = *buf;
|
north = *buf;
|
||||||
lattitude = (float)LA + lattitude / 60.;
|
lattitude = (double)LA + lattitude / 60.;
|
||||||
if(north == 'S') lattitude = -lattitude;
|
if(north == 'S') lattitude = -lattitude;
|
||||||
printf(" latt: %f", lattitude);
|
printf(" latt: %g", lattitude);
|
||||||
|
Latt_mean += lattitude;
|
||||||
|
Latt_sq += lattitude*lattitude;
|
||||||
|
++Latt_N;
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%3d%f", &LO, &longitude);
|
sscanf((char*)buf, "%3d%lf", &LO, &longitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
east = *buf;
|
east = *buf;
|
||||||
longitude = (float)LO + longitude / 60.;
|
longitude = (double)LO + longitude / 60.;
|
||||||
if(east == 'W') longitude = -longitude;
|
if(east == 'W') longitude = -longitude;
|
||||||
printf(" long: %f", longitude);
|
printf(" long: %g", longitude);
|
||||||
|
Long_mean += longitude;
|
||||||
|
Long_sq += longitude*longitude;
|
||||||
|
++Long_N;
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
sscanf((char*)buf, "%f", &speed);
|
sscanf((char*)buf, "%lf", &speed);
|
||||||
printf(" speed: %fknots", speed);
|
printf(" speed: %gknots", speed);
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
sscanf((char*)buf, "%f", &track);
|
sscanf((char*)buf, "%lf", &track);
|
||||||
printf(" track: %fdeg,True", track);
|
printf(" track: %gdeg,True", track);
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
if(sscanf((char*)buf, "%2d%2d%2d", &d, &m, &y) == 3)
|
if(sscanf((char*)buf, "%2d%2d%2d", &d, &m, &y) == 3)
|
||||||
printf(" date(dd/mm/yy): %02d/%02d/%02d", d, m, y);
|
printf(" date(dd/mm/yy): %02d/%02d/%02d", d, m, y);
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%f,%c", &mag, &mageast);
|
sscanf((char*)buf, "%lf,%c", &mag, &mageast);
|
||||||
if(mageast == 'E' || mageast == 'W'){
|
if(mageast == 'E' || mageast == 'W'){
|
||||||
if(mageast == 'W') mag = -mag;
|
if(mageast == 'W') mag = -mag;
|
||||||
printf(" magnetic var: %f", mag);
|
printf(" magnetic var: %g", mag);
|
||||||
}
|
}
|
||||||
SKIP(2);
|
SKIP(2);
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
@ -391,8 +400,8 @@ void gsa(uint8_t *buf){
|
|||||||
for(i = 0; i < Nused; ++i)
|
for(i = 0; i < Nused; ++i)
|
||||||
printf("%d, ", used[i]);
|
printf("%d, ", used[i]);
|
||||||
}
|
}
|
||||||
float pos, hor, vert;
|
double pos, hor, vert;
|
||||||
if(sscanf((char*)buf, "%f,%f,%f", &pos, &hor, &vert) == 3){
|
if(sscanf((char*)buf, "%lf,%lf,%lf", &pos, &hor, &vert) == 3){
|
||||||
printf("DILUTION: pos=%.2f, hor=%.2f, vert=%.2f", pos, hor, vert);
|
printf("DILUTION: pos=%.2f, hor=%.2f, vert=%.2f", pos, hor, vert);
|
||||||
}
|
}
|
||||||
ret:
|
ret:
|
||||||
@ -447,33 +456,39 @@ void txt(_U_ uint8_t *buf){
|
|||||||
void pubx(uint8_t *buf){
|
void pubx(uint8_t *buf){
|
||||||
//DBG("pubx_00: %s\n", buf);
|
//DBG("pubx_00: %s\n", buf);
|
||||||
int H, M, LO, LA, gps, glo, dr;
|
int H, M, LO, LA, gps, glo, dr;
|
||||||
float S, longitude, lattitude, altitude, hacc, vacc, speed, track, vertspd,
|
double S, longitude, lattitude, altitude, hacc, vacc, speed, track, vertspd,
|
||||||
age, hdop, vdop, tdop;
|
age, hdop, vdop, tdop;
|
||||||
char north = '0', east = '0';
|
char north = '0', east = '0';
|
||||||
sscanf((char*)buf, "%2d%2d%f", &H, &M, &S);
|
sscanf((char*)buf, "%2d%2d%lf", &H, &M, &S);
|
||||||
printf("time: %02d:%02d:%05.2f", H, M, S);
|
printf("time: %02d:%02d:%05.2f", H, M, S);
|
||||||
printf(" timediff: %g", timediff(H, M, S));
|
printf(" timediff: %g", timediff(H, M, S));
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%2d%f", &LA, &lattitude);
|
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
north = *buf;
|
north = *buf;
|
||||||
lattitude = (float)LA + lattitude / 60.;
|
lattitude = (double)LA + lattitude / 60.;
|
||||||
if(north == 'S') lattitude = -lattitude;
|
if(north == 'S') lattitude = -lattitude;
|
||||||
printf(" latt: %f", lattitude);
|
printf(" latt: %g", lattitude);
|
||||||
|
Latt_mean += lattitude;
|
||||||
|
Latt_sq += lattitude*lattitude;
|
||||||
|
++Latt_N;
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%3d%f", &LO, &longitude);
|
sscanf((char*)buf, "%3d%lf", &LO, &longitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
east = *buf;
|
east = *buf;
|
||||||
longitude = (float)LO + longitude / 60.;
|
longitude = (double)LO + longitude / 60.;
|
||||||
if(east == 'W') longitude = -longitude;
|
if(east == 'W') longitude = -longitude;
|
||||||
printf(" long: %f", longitude);
|
printf(" long: %g", longitude);
|
||||||
|
Long_mean += longitude;
|
||||||
|
Long_sq += longitude*longitude;
|
||||||
|
++Long_N;
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
#define FSCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%f", &par); \
|
#define FSCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%lf", &par); \
|
||||||
printf(" " nam ": %f", par);} NEXT();}while(0)
|
printf(" " nam ": %g", par);} NEXT();}while(0)
|
||||||
FSCAN(altitude, "altitude");
|
FSCAN(altitude, "altitude");
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
printf(" nav. status: %c%c", buf[0], buf[1]);
|
printf(" nav. status: %c%c", buf[0], buf[1]);
|
||||||
@ -628,6 +643,26 @@ int main(int argc, char **argv){
|
|||||||
}
|
}
|
||||||
if(GP->gettimediff)
|
if(GP->gettimediff)
|
||||||
printf("\nAverage time difference (local-GPS) = %g seconds\n", timediff_aver/timediff_N);
|
printf("\nAverage time difference (local-GPS) = %g seconds\n", timediff_aver/timediff_N);
|
||||||
|
if(GP->meancoords){
|
||||||
|
printf("\nAverage coordinates:\n\tLattitude");
|
||||||
|
double mean, std, s;
|
||||||
|
int d, m;
|
||||||
|
if(Latt_N){
|
||||||
|
mean = Latt_mean / Latt_N;
|
||||||
|
std = sqrt(Latt_sq/Latt_N - mean*mean);
|
||||||
|
d = (int)mean; m = (int)(60.*(mean-d)); s = 3600*fabs(mean-d-m/60.);
|
||||||
|
if(m < 0) m = -m;
|
||||||
|
printf(" = %.6f (%d %d' %.2f''), std = %g (%.2f'')\n", mean, d, m, s, std, std*3600.);
|
||||||
|
}else printf(": no data\n");
|
||||||
|
printf("\tLongitude");
|
||||||
|
if(Long_N){
|
||||||
|
mean = Long_mean / Long_N;
|
||||||
|
std = sqrt(Long_sq/Long_N - mean*mean);
|
||||||
|
d = (int)mean; m = (int)(60.*(mean-d)); s = 3600*fabs(mean-d-m/60.);
|
||||||
|
if(m < 0) m = -m;
|
||||||
|
printf(" = %.6f (%d %d' %.2f''), std = %g (%.2f'')\n", mean, d, m, s, std, std*3600.);
|
||||||
|
}else printf(": no data\n");
|
||||||
|
}
|
||||||
signals(0);
|
signals(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user