mirror of
https://github.com/eddyem/eddys_snippets.git
synced 2025-12-06 02:35:12 +03:00
add print date for initial clock setup
This commit is contained in:
parent
139686f0bf
commit
04960e8f20
@ -1,5 +1,5 @@
|
|||||||
PROGRAM = gpstest
|
PROGRAM = gpstest
|
||||||
LDFLAGS =
|
LDFLAGS = -lm
|
||||||
SRCS = $(wildcard *.c)
|
SRCS = $(wildcard *.c)
|
||||||
OBJDIR = mk
|
OBJDIR = mk
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
|||||||
@ -36,6 +36,8 @@ glob_pars Gdefault = {
|
|||||||
,.stationary = 0
|
,.stationary = 0
|
||||||
,.gettimediff = 0
|
,.gettimediff = 0
|
||||||
,.meancoords = 0
|
,.meancoords = 0
|
||||||
|
,.silent = 0
|
||||||
|
,.date = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -49,16 +51,18 @@ myoption cmdlnopts[] = {
|
|||||||
{"device",1, NULL, 'd', arg_string, APTR(&G.devpath), N_("device path")},
|
{"device",1, NULL, 'd', arg_string, APTR(&G.devpath), N_("device path")},
|
||||||
{"poll-udx", 0, NULL, 'p', arg_none, APTR(&G.pollubx), N_("poll UDX,00")},
|
{"poll-udx", 0, NULL, 'p', arg_none, APTR(&G.pollubx), N_("poll UDX,00")},
|
||||||
{"pollinterval",1,NULL, 'i', arg_double, APTR(&G.pollinterval),N_("polling interval")},
|
{"pollinterval",1,NULL, 'i', arg_double, APTR(&G.pollinterval),N_("polling interval")},
|
||||||
{"no-rmc",0,&G.block_msg[GPRMC], 0, arg_none, NULL, N_("block RMC message")},
|
{"no-rmc",0,&G.block_msg[GPRMC], 0, arg_none, NULL, N_("block RMC message")},
|
||||||
{"gsv", 0, &G.block_msg[GPGSV], 1, arg_none, NULL, N_("process GSV message")},
|
{"gsv", 0, &G.block_msg[GPGSV], 1, arg_none, NULL, N_("process GSV message")},
|
||||||
{"gsa", 0, &G.block_msg[GPGSA], 1, arg_none, NULL, N_("process GSA message")},
|
{"gsa", 0, &G.block_msg[GPGSA], 1, arg_none, NULL, N_("process GSA message")},
|
||||||
{"gga", 0, &G.block_msg[GPGGA], 1, arg_none, NULL, N_("process GGA message")},
|
{"gga", 0, &G.block_msg[GPGGA], 1, arg_none, NULL, N_("process GGA message")},
|
||||||
{"gll", 0, &G.block_msg[GPGLL], 1, arg_none, NULL, N_("process GLL message")},
|
{"gll", 0, &G.block_msg[GPGLL], 1, arg_none, NULL, N_("process GLL message")},
|
||||||
{"vtg", 0, &G.block_msg[GPVTG], 1, arg_none, NULL, N_("process VTG message")},
|
{"vtg", 0, &G.block_msg[GPVTG], 1, arg_none, NULL, N_("process VTG message")},
|
||||||
{"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")},
|
{"coords",0, NULL, 'C', arg_int, APTR(&G.meancoords),N_("calculate mean coordinates")},
|
||||||
|
{"silent",0, NULL, 'S', arg_int, APTR(&G.silent), N_("don't write intermediate messages")},
|
||||||
|
{"print-date",0,NULL, 'D', arg_int, APTR(&G.date), N_("print date in format MMDDhhmmCCYY.ss")},
|
||||||
// ...
|
// ...
|
||||||
end_option
|
end_option
|
||||||
};
|
};
|
||||||
|
|||||||
@ -49,6 +49,8 @@ typedef struct{
|
|||||||
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
|
int meancoords; // calculate mean coordinates
|
||||||
|
int silent; // don't write intermediate messages
|
||||||
|
int date; // print date for initial time setup
|
||||||
}glob_pars;
|
}glob_pars;
|
||||||
|
|
||||||
glob_pars *parce_args(int argc, char **argv);
|
glob_pars *parce_args(int argc, char **argv);
|
||||||
|
|||||||
93
GPS/main.c
93
GPS/main.c
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
glob_pars *GP = NULL;
|
glob_pars *GP = NULL;
|
||||||
|
|
||||||
|
#define PRINT(...) do{if(!GP->silent) printf(__VA_ARGS__);}while(0)
|
||||||
|
|
||||||
// Messages for blocking: GSV, RMC, GSA, GGA, GLL, VTG
|
// Messages for blocking: GSV, RMC, GSA, GGA, GLL, VTG
|
||||||
char *GPmsgs[] = {"GSV", "RMC", "GSA", "GGA", "GLL", "VTG"};
|
char *GPmsgs[] = {"GSV", "RMC", "GSA", "GGA", "GLL", "VTG"};
|
||||||
|
|
||||||
@ -123,6 +125,7 @@ int timediff_N = 0;
|
|||||||
*/
|
*/
|
||||||
double timediff(int h, int m, double s){
|
double timediff(int h, int m, double s){
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
// struct timezone tz;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
time_t tm0 = time(NULL);
|
time_t tm0 = time(NULL);
|
||||||
struct tm *gmt = gmtime(&tm0);
|
struct tm *gmt = gmtime(&tm0);
|
||||||
@ -231,6 +234,16 @@ printf("\n");
|
|||||||
}while(!get_ACK(prec) && ++i < 11);
|
}while(!get_ACK(prec) && ++i < 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show current date in appropriate format for initial clock setup (MMDDhhmmCCYY.ss)
|
||||||
|
* make from root:
|
||||||
|
* date $(gpstest -sSD)
|
||||||
|
*/
|
||||||
|
void show_date(int H, int M, double S, int d, int m, int y){
|
||||||
|
printf("--utc %02d%02d%02d%02d%02d.%02d\n", m, d, H, M, y, (int)(S + 0.3));
|
||||||
|
signals(0); // appropriate exit
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Satellites in View
|
* Satellites in View
|
||||||
* $GPGSV,NoMsg,MsgNo,NoSv,{,sv,elv,az,cno}*cs
|
* $GPGSV,NoMsg,MsgNo,NoSv,{,sv,elv,az,cno}*cs
|
||||||
@ -257,19 +270,19 @@ void gsv(uint8_t *buf){
|
|||||||
if(inview < 1) goto ret;
|
if(inview < 1) goto ret;
|
||||||
NEXT();
|
NEXT();
|
||||||
if(Ncur == 1)
|
if(Ncur == 1)
|
||||||
printf("%d satellites in view field: (No: ID, elevation, azimuth, SNR)\n", inview);
|
PRINT("%d satellites in view field: (No: ID, elevation, azimuth, SNR)\n", inview);
|
||||||
do{
|
do{
|
||||||
int id, el, az, snr;
|
int id, el, az, snr;
|
||||||
// there could be no "SNR" field if we can't find this satellite on sky
|
// 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;
|
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);
|
PRINT(" (%d: %d, %d, %d, %d)", ++sat_scanned, id, el, az, snr);
|
||||||
SKIP(4);
|
SKIP(4);
|
||||||
}while(1);
|
}while(1);
|
||||||
ret:
|
ret:
|
||||||
if(inview < 1) printf("There's no GPS satellites in viewfield\n");
|
if(inview < 1) PRINT("There's no GPS satellites in viewfield\n");
|
||||||
if(Nrec > 0 && Nrec == Ncur){
|
if(Nrec > 0 && Nrec == Ncur){
|
||||||
sat_scanned = 0;
|
sat_scanned = 0;
|
||||||
printf("\n");
|
PRINT("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,18 +305,20 @@ ret:
|
|||||||
*/
|
*/
|
||||||
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, getdate = 0;
|
||||||
double S, longitude, lattitude, speed, track, mag;
|
double S, 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%lf", &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')
|
||||||
printf("(data could be wrong)");
|
PRINT("(data could be wrong)");
|
||||||
else
|
else{
|
||||||
printf("(data valid)");
|
PRINT("(data valid)");
|
||||||
printf(" time: %02d:%02d:%05.2f", H, M, S);
|
if(GP->date) getdate = 1; // as only we have valid data we show it to user
|
||||||
printf(" timediff: %g", timediff(H, M, S));
|
}
|
||||||
|
PRINT(" time: %02d:%02d:%05.2f", H, M, S);
|
||||||
|
PRINT(" timediff: %g", timediff(H, M, S));
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
@ -311,7 +326,7 @@ void rmc(uint8_t *buf){
|
|||||||
north = *buf;
|
north = *buf;
|
||||||
lattitude = (double)LA + lattitude / 60.;
|
lattitude = (double)LA + lattitude / 60.;
|
||||||
if(north == 'S') lattitude = -lattitude;
|
if(north == 'S') lattitude = -lattitude;
|
||||||
printf(" latt: %g", lattitude);
|
PRINT(" latt: %g", lattitude);
|
||||||
Latt_mean += lattitude;
|
Latt_mean += lattitude;
|
||||||
Latt_sq += lattitude*lattitude;
|
Latt_sq += lattitude*lattitude;
|
||||||
++Latt_N;
|
++Latt_N;
|
||||||
@ -323,7 +338,7 @@ void rmc(uint8_t *buf){
|
|||||||
east = *buf;
|
east = *buf;
|
||||||
longitude = (double)LO + longitude / 60.;
|
longitude = (double)LO + longitude / 60.;
|
||||||
if(east == 'W') longitude = -longitude;
|
if(east == 'W') longitude = -longitude;
|
||||||
printf(" long: %g", longitude);
|
PRINT(" long: %g", longitude);
|
||||||
Long_mean += longitude;
|
Long_mean += longitude;
|
||||||
Long_sq += longitude*longitude;
|
Long_sq += longitude*longitude;
|
||||||
++Long_N;
|
++Long_N;
|
||||||
@ -331,29 +346,30 @@ void rmc(uint8_t *buf){
|
|||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
sscanf((char*)buf, "%lf", &speed);
|
sscanf((char*)buf, "%lf", &speed);
|
||||||
printf(" speed: %gknots", speed);
|
PRINT(" speed: %gknots", speed);
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
sscanf((char*)buf, "%lf", &track);
|
sscanf((char*)buf, "%lf", &track);
|
||||||
printf(" track: %gdeg,True", track);
|
PRINT(" 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);
|
PRINT(" date(dd/mm/yy): %02d/%02d/%02d", d, m, y);
|
||||||
|
if(getdate) show_date(H,M,S,d,m,y); // show date & exit
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%lf,%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: %g", mag);
|
PRINT(" magnetic var: %g", mag);
|
||||||
}
|
}
|
||||||
SKIP(2);
|
SKIP(2);
|
||||||
if(*buf != ','){
|
if(*buf != ','){
|
||||||
mode = *buf;
|
mode = *buf;
|
||||||
printf(" mode: %c", mode);
|
PRINT(" mode: %c", mode);
|
||||||
}
|
}
|
||||||
ret:
|
ret:
|
||||||
printf("\n");
|
PRINT("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -371,19 +387,19 @@ void gsa(uint8_t *buf){
|
|||||||
//DBG("gsa: %s\n", buf);
|
//DBG("gsa: %s\n", buf);
|
||||||
int used[12];
|
int used[12];
|
||||||
int i, Nused = 0;
|
int i, Nused = 0;
|
||||||
if(*buf == 'M') printf("Mode: manual; ");
|
if(*buf == 'M') PRINT("Mode: manual; ");
|
||||||
else if(*buf == 'A') printf("Mode: auto; ");
|
else if(*buf == 'A') PRINT("Mode: auto; ");
|
||||||
else return; // wrong data
|
else return; // wrong data
|
||||||
NEXT();
|
NEXT();
|
||||||
switch(*buf){
|
switch(*buf){
|
||||||
case '1':
|
case '1':
|
||||||
printf("no fix; ");
|
PRINT("no fix; ");
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
printf("2D fix; ");
|
PRINT("2D fix; ");
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
printf("3D fix; ");
|
PRINT("3D fix; ");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto ret;
|
goto ret;
|
||||||
@ -396,16 +412,16 @@ void gsa(uint8_t *buf){
|
|||||||
NEXT();
|
NEXT();
|
||||||
}
|
}
|
||||||
if(Nused){
|
if(Nused){
|
||||||
printf("%d satellites used: ", Nused);
|
PRINT("%d satellites used: ", Nused);
|
||||||
for(i = 0; i < Nused; ++i)
|
for(i = 0; i < Nused; ++i)
|
||||||
printf("%d, ", used[i]);
|
PRINT("%d, ", used[i]);
|
||||||
}
|
}
|
||||||
double pos, hor, vert;
|
double pos, hor, vert;
|
||||||
if(sscanf((char*)buf, "%lf,%lf,%lf", &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);
|
PRINT("DILUTION: pos=%.2f, hor=%.2f, vert=%.2f", pos, hor, vert);
|
||||||
}
|
}
|
||||||
ret:
|
ret:
|
||||||
printf("\n");
|
PRINT("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 213457.00,4340.59415,N,04127.47560,E,1,05,2.58,1275.8,M,17.0,M,,*60
|
// 213457.00,4340.59415,N,04127.47560,E,1,05,2.58,1275.8,M,17.0,M,,*60
|
||||||
@ -460,8 +476,8 @@ void pubx(uint8_t *buf){
|
|||||||
age, hdop, vdop, tdop;
|
age, hdop, vdop, tdop;
|
||||||
char north = '0', east = '0';
|
char north = '0', east = '0';
|
||||||
sscanf((char*)buf, "%2d%2d%lf", &H, &M, &S);
|
sscanf((char*)buf, "%2d%2d%lf", &H, &M, &S);
|
||||||
printf("time: %02d:%02d:%05.2f", H, M, S);
|
PRINT("time: %02d:%02d:%05.2f", H, M, S);
|
||||||
printf(" timediff: %g", timediff(H, M, S));
|
PRINT(" timediff: %g", timediff(H, M, S));
|
||||||
NEXT();
|
NEXT();
|
||||||
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
sscanf((char*)buf, "%2d%lf", &LA, &lattitude);
|
||||||
NEXT();
|
NEXT();
|
||||||
@ -469,7 +485,7 @@ void pubx(uint8_t *buf){
|
|||||||
north = *buf;
|
north = *buf;
|
||||||
lattitude = (double)LA + lattitude / 60.;
|
lattitude = (double)LA + lattitude / 60.;
|
||||||
if(north == 'S') lattitude = -lattitude;
|
if(north == 'S') lattitude = -lattitude;
|
||||||
printf(" latt: %g", lattitude);
|
PRINT(" latt: %g", lattitude);
|
||||||
Latt_mean += lattitude;
|
Latt_mean += lattitude;
|
||||||
Latt_sq += lattitude*lattitude;
|
Latt_sq += lattitude*lattitude;
|
||||||
++Latt_N;
|
++Latt_N;
|
||||||
@ -481,17 +497,17 @@ void pubx(uint8_t *buf){
|
|||||||
east = *buf;
|
east = *buf;
|
||||||
longitude = (double)LO + longitude / 60.;
|
longitude = (double)LO + longitude / 60.;
|
||||||
if(east == 'W') longitude = -longitude;
|
if(east == 'W') longitude = -longitude;
|
||||||
printf(" long: %g", longitude);
|
PRINT(" long: %g", longitude);
|
||||||
Long_mean += longitude;
|
Long_mean += longitude;
|
||||||
Long_sq += longitude*longitude;
|
Long_sq += longitude*longitude;
|
||||||
++Long_N;
|
++Long_N;
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
#define FSCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%lf", &par); \
|
#define FSCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%lf", &par); \
|
||||||
printf(" " nam ": %g", par);} NEXT();}while(0)
|
PRINT(" " 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]);
|
PRINT(" nav. status: %c%c", buf[0], buf[1]);
|
||||||
}
|
}
|
||||||
NEXT();
|
NEXT();
|
||||||
FSCAN(hacc,"hor.accuracy");
|
FSCAN(hacc,"hor.accuracy");
|
||||||
@ -505,13 +521,13 @@ void pubx(uint8_t *buf){
|
|||||||
FSCAN(tdop, "time dilution");
|
FSCAN(tdop, "time dilution");
|
||||||
#undef FSCAN
|
#undef FSCAN
|
||||||
#define ISCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%d", &par); \
|
#define ISCAN(par, nam) do{if(*buf != ','){sscanf((char*)buf, "%d", &par); \
|
||||||
printf(" " nam ": %d", par);} NEXT();}while(0)
|
PRINT(" " nam ": %d", par);} NEXT();}while(0)
|
||||||
ISCAN(gps, "GPS used");
|
ISCAN(gps, "GPS used");
|
||||||
ISCAN(glo, "GLONASS used");
|
ISCAN(glo, "GLONASS used");
|
||||||
ISCAN(dr, "DR used");
|
ISCAN(dr, "DR used");
|
||||||
#undef ISCAN
|
#undef ISCAN
|
||||||
ret:
|
ret:
|
||||||
printf("\n");
|
PRINT("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -617,6 +633,7 @@ int main(int argc, char **argv){
|
|||||||
signal(SIGQUIT, signals); // ctrl+\ - quit
|
signal(SIGQUIT, signals); // ctrl+\ - quit
|
||||||
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
||||||
int i;
|
int i;
|
||||||
|
if(GP->date) GP->block_msg[GPRMC] = 1; // we calculate date in RMC events
|
||||||
for(i = 0; i < GPMAXMSG; ++i){
|
for(i = 0; i < GPMAXMSG; ++i){
|
||||||
int block = 0;
|
int block = 0;
|
||||||
if(GP->block_msg[i])
|
if(GP->block_msg[i])
|
||||||
@ -624,15 +641,15 @@ int main(int argc, char **argv){
|
|||||||
if(nmea_fieldrate((uint8_t*)GPmsgs[i], block) != block)
|
if(nmea_fieldrate((uint8_t*)GPmsgs[i], block) != block)
|
||||||
WARN("Can't %sblock %s!", block?"un":"", GPmsgs[i]);
|
WARN("Can't %sblock %s!", block?"un":"", GPmsgs[i]);
|
||||||
else
|
else
|
||||||
printf("%sblock %s\n", block?"un":"", GPmsgs[i]);
|
PRINT("%sblock %s\n", block?"un":"", GPmsgs[i]);
|
||||||
}
|
}
|
||||||
if(GP->stationary){
|
if(GP->stationary){
|
||||||
printf("stationary config\n");
|
PRINT("stationary config\n");
|
||||||
cfg_stationary();
|
cfg_stationary();
|
||||||
}
|
}
|
||||||
double T, T0 = dtime(), Tpoll = 0., tmout = GP->polltmout;
|
double T, T0 = dtime(), Tpoll = 0., tmout = GP->polltmout;
|
||||||
uint8_t *str = NULL;
|
uint8_t *str = NULL;
|
||||||
while((T=dtime()) - T0 < tmout){
|
while(((T=dtime()) - T0 < tmout) || GP->date){ // if we want get date, we should wait a lot
|
||||||
if(GP->pollubx && T-Tpoll > GP->pollinterval){
|
if(GP->pollubx && T-Tpoll > GP->pollinterval){
|
||||||
Tpoll = T;
|
Tpoll = T;
|
||||||
write_tty((uint8_t*)"$PUBX,00*33\r\n", 13);
|
write_tty((uint8_t*)"$PUBX,00*33\r\n", 13);
|
||||||
|
|||||||
@ -270,14 +270,14 @@ void restore_tty(){
|
|||||||
#endif
|
#endif
|
||||||
// init:
|
// init:
|
||||||
void tty_init(char *comdev){
|
void tty_init(char *comdev){
|
||||||
printf("\nOpen port...\n");
|
DBG("\nOpen port...\n");
|
||||||
if ((comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0){
|
if ((comfd = open(comdev,O_RDWR|O_NOCTTY|O_NONBLOCK)) < 0){
|
||||||
WARN("Can't use port %s\n",comdev);
|
WARN("Can't use port %s\n",comdev);
|
||||||
ioctl(comfd, TCSANOW, &oldtty); // return TTY to previous state
|
ioctl(comfd, TCSANOW, &oldtty); // return TTY to previous state
|
||||||
close(comfd);
|
close(comfd);
|
||||||
exit(1); // quit?
|
exit(1); // quit?
|
||||||
}
|
}
|
||||||
printf(" OK\nGet current settings... ");
|
DBG(" OK\nGet current settings... ");
|
||||||
if(ioctl(comfd,TCGETA,&oldtty) < 0) exit(-1); // Get settings
|
if(ioctl(comfd,TCGETA,&oldtty) < 0) exit(-1); // Get settings
|
||||||
tty = oldtty;
|
tty = oldtty;
|
||||||
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
|
tty.c_lflag = 0; // ~(ICANON | ECHO | ECHOE | ISIG)
|
||||||
@ -286,7 +286,7 @@ void tty_init(char *comdev){
|
|||||||
tty.c_cc[VMIN] = 0; // non-canonical mode
|
tty.c_cc[VMIN] = 0; // non-canonical mode
|
||||||
tty.c_cc[VTIME] = 5;
|
tty.c_cc[VTIME] = 5;
|
||||||
if(ioctl(comfd,TCSETA,&tty) < 0) exit(-1); // set new mode
|
if(ioctl(comfd,TCSETA,&tty) < 0) exit(-1); // set new mode
|
||||||
printf(" OK\n");
|
DBG(" OK\n");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Read data from TTY
|
* Read data from TTY
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user