diff --git a/beidou.cc b/beidou.cc index cb8f78e..8b2106e 100644 --- a/beidou.cc +++ b/beidou.cc @@ -1,13 +1,57 @@ #include "beidou.hh" #include "bits.hh" +#include +using namespace std; + +// with immense gratitude to https://stackoverflow.com/questions/24612436/how-to-check-a-bch15-11-1-code-checksum-for-bds-beidou-satellite-system + +static int checkbds(int bits) +{ + static int const at[15] = {1, 2, 4, 8, 3, 6, 12, 11, 5, 10, 7, 14, 15, 13, 9}; + int s, i, j; + + for(i = 1; i <= 2; i++) + { + s = 0; + for(j = 0; j < 15; j++) + { + if(bits & (1< getCondensedBeidouMessage(std::basic_string_view payload) { + + // payload consists of 32 bit words where we have to ignore the first 2 bits of every word + + int chunk = getbitu(&payload[0], 17, 15); + // cout <<"w0 checkbds(chunk0): "< getCondensedBeidouMessage(std::basic_string_view payload); int beidouBitconv(int their); +/* Geostationary, so D2, so not to be parsed by this parser: + C01 (140E) + C02 (80E) + C03 (110.5E) + C04 (160E) + C05 (58.75E) +*/ + + + struct BeidouMessage { diff --git a/navdump.cc b/navdump.cc index 378ddde..c70e65c 100644 --- a/navdump.cc +++ b/navdump.cc @@ -36,14 +36,43 @@ static std::string humanTime(time_t t) } +string beidouHealth(int in) +{ + string ret; + if(in == 256) { + return "NO CLOCK"; + } + if(in==511) { + return "NO SAT"; + } + + if(in & (1<<7)) + ret += "B1I abnormal "; + if(in & (1<<6)) + ret += "B2I abnormal "; + if(in & (1<<5)) + ret += "B3I abnormal "; + if(in & (1<<1)) + ret += "navigation abnormal "; + + if(ret.empty()) + return "OK"; + return ret; +} + int main(int argc, char** argv) { for(;;) { char bert[4]; - if(read(0, bert, 4) != 4 || bert[0]!='b' || bert[1]!='e' || bert[2] !='r' || bert[3]!='t') { - cerr<<"EOF or bad magic"< inav((uint8_t*)nmm.gi().contents().c_str(), nmm.gi().contents().size()); @@ -109,17 +138,51 @@ int main(int argc, char** argv) } cout<<"\n"; } - else if(nmm.type() == NavMonMessage::BeidouInavType) { - int sv = nmm.bi().gnsssv(); - auto cond = getCondensedBeidouMessage(std::basic_string((uint8_t*)nmm.bi().contents().c_str(), nmm.bi().contents().size())); + else if(nmm.type() == NavMonMessage::BeidouInavTypeD1) { + int sv = nmm.bid1().gnsssv(); + auto cond = getCondensedBeidouMessage(std::basic_string((uint8_t*)nmm.bid1().contents().c_str(), nmm.bid1().contents().size())); BeidouMessage bm; uint8_t pageno; int fraid = bm.parse(cond, &pageno); cout<<"BeiDou "<((uint8_t*)nmm.bid2().contents().c_str(), nmm.bid2().contents().size())); + BeidouMessage bm; + uint8_t pageno; + int fraid = bm.parse(cond, &pageno); + + cout<<"BeiDou "< getUBXMessage(int fd) readn2(fd, b, 4); msg.append(b, 4); // class, type, len1, len2 - - - uint16_t len = b[2] + 256*b[3]; // cerr<<"Got class "<<(int)msg[2]<<" type "<<(int)msg[3]<<", len = "<set_gnsswn(bm.wn); - nmm.mutable_bi()->set_gnsstow(bm.sow); - nmm.mutable_bi()->set_gnssid(id.first); - nmm.mutable_bi()->set_gnsssv(id.second); - nmm.mutable_bi()->set_contents(string((char*)gstr.c_str(), gstr.size())); + nmm.set_sourceid(g_srcid); + if(id.second > 5) { + // this **HARDCODES** that C01,02,03,04,05 emit D2 messages! + nmm.set_type(NavMonMessage::BeidouInavTypeD1); + nmm.mutable_bid1()->set_gnsswn(bm.wn); + nmm.mutable_bid1()->set_gnsstow(bm.sow); + nmm.mutable_bid1()->set_gnssid(id.first); + nmm.mutable_bid1()->set_gnsssv(id.second); + nmm.mutable_bid1()->set_contents(string((char*)gstr.c_str(), gstr.size())); + } + else { + nmm.set_type(NavMonMessage::BeidouInavTypeD2); + nmm.mutable_bid2()->set_gnsswn(bm.wn); + nmm.mutable_bid2()->set_gnsstow(bm.sow); + nmm.mutable_bid2()->set_gnssid(id.first); + nmm.mutable_bid2()->set_gnsssv(id.second); + nmm.mutable_bid2()->set_contents(string((char*)gstr.c_str(), gstr.size())); + } emitNMM(1, nmm); continue; }