Add --silent option to supress non essential logging

pull/110/head
Stijn Jonker 2020-02-28 20:24:43 +01:00
parent febbbd0582
commit 71a62e4bba
1 changed files with 26 additions and 17 deletions

View File

@ -41,6 +41,7 @@ static char program[]="ubxtool";
bool doDEBUG{false};
bool doLOGFILE{false};
bool doVERSION{false};
bool doSILENT{false};
struct timespec g_gnssutc;
uint16_t g_galwn;
@ -239,7 +240,7 @@ UBXMessage sendAndWaitForUBX(int fd, int seconds, basic_string_view<uint8_t> msg
catch(...) {
if(n==1)
throw;
cerr<<"Retransmit"<<endl;
if (!doSILENT) { cerr<<"Retransmit"<<endl; }
}
}
// we actually never get here, but if you remove this line, we get a warning
@ -287,7 +288,7 @@ bool sendAndWaitForUBXAckNack(int fd, int seconds, basic_string_view<uint8_t> ms
catch(...) {
if(n==1)
throw;
cerr<<"Retransmit"<<endl;
if (!doSILENT) { cerr<<"Retransmit"<<endl; }
}
}
return false;
@ -498,7 +499,7 @@ void readSome(int fd)
if (doDEBUG) { cerr<<humanTimeNow()<<" "<<string((char*)msg.getPayload().c_str(), msg.getPayload().size()) <<endl; }
}
catch(TimeoutError& te) {
cerr<<"Timeout"<<endl;
if (!doSILENT) { cerr<<"Timeout"<<endl; }
}
}
@ -615,6 +616,7 @@ int main(int argc, char** argv)
app.add_flag("--survey-reset", doSurveyReset, "Reset the Surveyed-in state");
app.add_flag("--debug", doDEBUG, "Display debug information");
app.add_flag("--logfile", doLOGFILE, "Create logfile");
app.add_flag("--silent", doSILENT, "Supress non essential logging");
app.add_flag("--version", doVERSION, "show program version and copyright");
try {
app.parse(argc, argv);
@ -628,14 +630,19 @@ int main(int argc, char** argv)
}
if(! *pn) {
cerr<<"you must provide the --port"<<endl;
cerr<<"Error: you must provide the --port"<<endl;
exit(1);
}
g_baudval = getBaudrate(baudrate);
if(!(doGPS || doGalileo || doGlonass || doBeidou)) {
cerr<<"Enable at least one of --gps, --galileo, --glonass, --beidou"<<endl;
cerr<<"Error: Enable at least one of --gps, --galileo, --glonass, --beidou"<<endl;
return EXIT_FAILURE;
}
if(doDEBUG && doSILENT) {
cerr<<"--silent and --debug are mutually exclusive."<<endl;
return EXIT_FAILURE;
}
@ -644,7 +651,7 @@ int main(int argc, char** argv)
for(const auto& s : destinations) {
auto res=resolveName(s, true, true);
if(res.empty()) {
cerr<<"Unable to resolve '"<<s<<"' as destination for data, exiting"<<endl;
cerr<<"Error: Unable to resolve '"<<s<<"' as destination for data, exiting"<<endl;
exit(EXIT_FAILURE);
}
ns.addDestination(s); // ComboAddress(s, 29603));
@ -782,7 +789,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on GNSS setting"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on GNSS setting"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on GNSS setting"<<endl;
exit(-1);
}
}
@ -812,7 +819,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on F9P GNSS setting"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on F9P GNSS setting"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on F9P GNSS setting"<<endl;
exit(-1);
}
/* VALSET
@ -826,7 +833,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on F9P UART1 setting"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on F9P UART1 setting"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on F9P UART1 setting"<<endl;
exit(-1);
}
}
@ -862,7 +869,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on survey-reset"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on survey-reset"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on survey-reset"<<endl;
exit(-1);
}
exit(0);
@ -906,7 +913,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on survey-in"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on survey-in"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on survey-in"<<endl;
exit(-1);
}
}
@ -918,7 +925,7 @@ int main(int argc, char** argv)
if (doDEBUG) { cerr<<humanTimeNow()<<" Got ack on SBAS setting"<<endl; }
}
else {
cerr<<humanTimeNow()<<" Got nack on SBAS setting"<<endl;
cerr<<humanTimeNow()<<" Error: Got nack on SBAS setting"<<endl;
exit(-1);
}
}
@ -1039,7 +1046,7 @@ int main(int argc, char** argv)
int curCycleTOW{-1}; // means invalid
ns.launch();
cerr<<humanTimeNow()<<" Entering main loop"<<endl;
if (!doSILENT) { cerr<<humanTimeNow()<<" Entering main loop"<<endl; }
for(;;) {
try {
auto [msg, timestamp] = getUBXMessage(fd, nullptr);
@ -1254,11 +1261,13 @@ int main(int argc, char** argv)
svseen.insert({id.first, id.second, payload[2]});
if(time(0)- lastStat > 30) {
cerr<<humanTimeNow()<<" src "<<g_srcid<< " (fix: "<<g_fixtype<<") currently receiving: ";
for(auto& s : svseen) {
cerr<<get<0>(s)<<","<<get<1>(s)<<"@"<<get<2>(s)<<" ";
if (!doSILENT) {
cerr<<humanTimeNow()<<" src "<<g_srcid<< " (fix: "<<g_fixtype<<") currently receiving: ";
for(auto& s : svseen) {
cerr<<get<0>(s)<<","<<get<1>(s)<<"@"<<get<2>(s)<<" ";
}
cerr<<endl;
}
cerr<<endl;
lastStat = time(0);
svseen.clear();
}