diff --git a/navcat.cc b/navcat.cc index 48350d9..d5e0f9f 100644 --- a/navcat.cc +++ b/navcat.cc @@ -26,7 +26,7 @@ using namespace std; extern const char* g_gitHash; - +// get all stations (numerical) from a directory vector getSources(string_view dirname) { DIR *dir = opendir(&dirname[0]); @@ -54,8 +54,13 @@ vector getSources(string_view dirname) return ret; } +static bool operator==(const timespec& a, const timespec& b) +{ + return a.tv_sec == b.tv_sec && a.tv_nsec && b.tv_nsec; +} -void sendProtobuf(string_view dir, vector stations, time_t startTime, time_t stopTime=0) +// send protobuf data from the named directories and stations, between start and stoptime +void sendProtobuf(const vector& dirs, vector stations, time_t startTime, time_t stopTime=0) { timespec start; start.tv_sec = startTime; @@ -66,44 +71,54 @@ void sendProtobuf(string_view dir, vector stations, time_t startTime, vector > rnmms; for(;;) { - cerr<<"Gathering data"< srcs = stations.empty() ? getSources(dir) : stations; rnmms.clear(); - for(const auto& src: srcs) { - string fname = getPath(dir, start.tv_sec, src); - FILE* fp = fopen(fname.c_str(), "r"); - if(!fp) - continue; - uint32_t offset= fpos[fname]; - if(fseek(fp, offset, SEEK_SET) < 0) { - cerr<<"Error seeking: "<= make_pair(start.tv_sec, start.tv_nsec)) { - rnmms.push_back({ts, msg}); + for(const auto& dir : dirs) { + cerr<<"Gathering data from "< srcs = stations.empty() ? getSources(dir) : stations; + int count=0; + for(const auto& src: srcs) { + string fname = getPath(dir, start.tv_sec, src); + FILE* fp = fopen(fname.c_str(), "r"); + if(!fp) + continue; + uint32_t offset= fpos[fname]; + if(fseek(fp, offset, SEEK_SET) < 0) { + cerr<<"Error seeking: "<= make_pair(start.tv_sec, start.tv_nsec)) { + rnmms.push_back({ts, msg}); + ++count; + } + } + // cerr<<"Harvested "< stopTime) break; @@ -113,8 +128,9 @@ void sendProtobuf(string_view dir, vector stations, time_t startTime, buf += nmm.second; //fwrite(buf.c_str(), 1, buf.size(), stdout); writen2(1, buf.c_str(), buf.size()); + ++count; } - cerr<<"Done sending"< storages; + int galwn{-1}; + app.add_option("--storage,-s", storages, "Locations of storage files"); vector stations; app.add_flag("--version", doVERSION, "show program version and copyright"); - app.add_option("--begin,-b", beginarg, "Begin time (2020-01-01 00:00, or 12:30)")->required(); + app.add_option("--begin,-b", beginarg, "Begin time (2020-01-01 00:00, or 12:30)"); app.add_option("--end,-e", endarg, "End time. Now if omitted"); app.add_option("--stations", stations, "only send data from listed stations"); - + app.add_option("--gal-wn", galwn, "Galileo week number to report on"); CLI11_PARSE(app, argc, argv); @@ -145,9 +163,19 @@ int main(int argc, char** argv) exit(0); } - time_t startTime = parseTime(beginarg); - - time_t stopTime = endarg.empty() ? time(0) : parseTime(endarg); + time_t startTime, stopTime; + if(galwn >=0) { + startTime=utcFromGST(galwn, 0); + stopTime=startTime + 7*86400; + } + else if(!beginarg.empty()) { + startTime = parseTime(beginarg); + stopTime = endarg.empty() ? time(0) : parseTime(endarg); + } + else { + cerr<<"No time range specified, use -b or --gal-wn"<