Skip to content

Commit 047b7cd

Browse files
committed
Write radarcape status message PPS offset to status file.
Clean up the statusfile json generation to be a bit more readable.
1 parent 8fd520c commit 047b7cd

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

status_writer.cc

+25-11
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,20 @@ namespace splitter {
9595
// 02: 1=tracking sats, 0=no sats
9696
// 01: 1=antenna OK, 0=antenna fault
9797

98+
int pps_offset = (std::int8_t)data[1];
99+
98100
if (!(data[0] & 0x10)) {
99101
// 12MHz mode
100-
write_status_file("red", "Not in GPS timestamp mode");
102+
write_status_file("red", "Not in GPS timestamp mode", pps_offset);
101103
return;
102104
}
103105

104106
if (!(data[2] & 0x80)) {
105107
// Old style message. Assume it's good if abs(degradation) < 45ms
106-
if (data[1] <= 3 || data[1] >= (256 - 3)) {
107-
write_status_file("green", "Receiver synchronized to GPS time");
108+
if (pps_offset <= 3 || pps_offset >= -3) {
109+
write_status_file("green", "Receiver synchronized to GPS time", pps_offset);
108110
} else {
109-
write_status_file("amber", "Receiver more than 45ns from GPS time");
111+
write_status_file("amber", "Receiver more than 45ns from GPS time", pps_offset);
110112
}
111113
return;
112114
}
@@ -116,9 +118,9 @@ namespace splitter {
116118
if (!(data[2] & 0x20)) {
117119
// FPGA is using GPS time
118120
if (data[2] & 0x10) {
119-
write_status_file("green", "Receiver synchronized to GPS time");
121+
write_status_file("green", "Receiver synchronized to GPS time", pps_offset);
120122
} else {
121-
write_status_file("amber", "Receiver more than 45ns from GPS time");
123+
write_status_file("amber", "Receiver more than 45ns from GPS time", pps_offset);
122124
}
123125
return;
124126
}
@@ -151,10 +153,10 @@ namespace splitter {
151153
status_buffer << *i;
152154
}
153155

154-
write_status_file("red", status_buffer.str());
156+
write_status_file("red", status_buffer.str(), pps_offset);
155157
}
156158

157-
void StatusWriter::write_status_file(const std::string &gps_color, const std::string &gps_message) {
159+
void StatusWriter::write_status_file(const std::string &gps_color, const std::string &gps_message, int pps_offset) {
158160
// This is simple enough we don't bother with a JSON library.
159161
// NB: we assume that the status messages do not need escaping.
160162

@@ -169,14 +171,26 @@ namespace splitter {
169171
std::string radio_color = (input->is_connected() ? "green" : "red");
170172
std::string radio_message = (input->is_connected() ? "Connected to receiver" : "Not connected to receiver");
171173

172-
outf << " \"radio\" : {" << std::endl << " \"status\" : \"" << (input->is_connected() ? "green" : "red") << "\"," << std::endl << " \"message\" : \"" << (input->is_connected() ? "Connected to receiver" : "Not connected to receiver") << "\"" << std::endl << " }," << std::endl;
174+
outf << " \"radio\" : {" << std::endl;
175+
outf << " \"status\" : \"" << (input->is_connected() ? "green" : "red") << "\"," << std::endl;
176+
outf << " \"message\" : \"" << (input->is_connected() ? "Connected to receiver" : "Not connected to receiver") << "\"" << std::endl;
177+
outf << " }," << std::endl;
173178
}
174179

175180
if (!gps_color.empty()) {
176-
outf << " \"gps\" : {" << std::endl << " \"status\" : \"" << gps_color << "\"," << std::endl << " \"message\" : \"" << gps_message << "\"" << std::endl << " }," << std::endl;
181+
outf << " \"gps\" : {" << std::endl;
182+
outf << " \"status\" : \"" << gps_color << "\"," << std::endl;
183+
if (pps_offset != -9999) {
184+
outf << " \"pps_offset\" : " << pps_offset << "," << std::endl;
185+
}
186+
outf << " \"message\" : \"" << gps_message << "\"" << std::endl;
187+
outf << " }," << std::endl;
177188
}
178189

179-
outf << " \"time\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(now - unix_epoch).count() << "," << std::endl << " \"expiry\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(expiry - unix_epoch).count() << "," << std::endl << " \"interval\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(timeout_interval).count() << std::endl << "}" << std::endl;
190+
outf << " \"time\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(now - unix_epoch).count() << "," << std::endl;
191+
outf << " \"expiry\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(expiry - unix_epoch).count() << "," << std::endl;
192+
outf << " \"interval\" : " << std::chrono::duration_cast<std::chrono::milliseconds>(timeout_interval).count() << std::endl;
193+
outf << "}" << std::endl;
180194
outf.close();
181195

182196
if (outf) {

status_writer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace splitter {
5454
void write(const modes::Message &message);
5555
void reset_timeout();
5656
void status_timeout(const boost::system::error_code &ec = boost::system::error_code());
57-
void write_status_file(const std::string &gps_color = std::string(), const std::string &gps_message = std::string());
57+
void write_status_file(const std::string &gps_color = std::string(), const std::string &gps_message = std::string(), int pps_offset = -9999);
5858

5959
boost::asio::io_service &service;
6060
modes::FilterDistributor &distributor;

0 commit comments

Comments
 (0)