@@ -118,6 +118,46 @@ basic_string<uint8_t> getInavFromSFRBXMsg(std::basic_string_view<uint8_t> msg,
118118 return inav;
119119}
120120
121+ basic_string<uint8_t > getFnavFromSFRBXMsg (std::basic_string_view<uint8_t > msg,
122+ basic_string<uint8_t >& crc)
123+ {
124+ // byte order adjustment
125+ std::basic_string<uint8_t > payload;
126+ for (unsigned int i = 0 ; i < (msg.size () - 8 ) / 4 ; ++i)
127+ for (int j=1 ; j <= 4 ; ++j)
128+ payload.append (1 , msg[8 + (i+1 ) * 4 -j]);
129+
130+ //
131+
132+ // 214 bitsof payload
133+ // 2 bits padding, 214 bits payload, 24 bits ctc
134+ // 216 bits -> 27 bytes
135+ unsigned char crc_buff[27 ]={0 };
136+ unsigned int i,j;
137+ for (i=0 ,j= 2 ;i<27 ;i++,j+=8 ) setbitu (crc_buff,j,8 ,getbitu (payload.c_str () ,i*8 ,8 ));
138+
139+ if (rtk_crc24q (crc_buff,27 ) != getbitu (payload.c_str (), 214 ,24 )) {
140+ cerr << " CRC mismatch, " << rtk_crc24q (crc_buff, 27 ) << " != " << getbitu (payload.c_str (), 214 ,24 ) <<endl;
141+ cerr << makeHexDump (payload) << " " << (int ) getbitu (payload.c_str (), 0 , 6 ) << endl;
142+ throw CRCMismatch ();
143+ }
144+ // cerr << "F/NAV CRC MATCHED!!"<<endl;
145+
146+ crc.clear ();
147+ for (i=0 ; i < 3 ; ++i)
148+ crc.append (1 , getbitu (payload.c_str (), 214 +i*8 ,8 ));
149+
150+
151+ std::basic_string<uint8_t > fnav;
152+
153+ for (i=0 ,j=0 ; i<27 ; i++, j+=8 )
154+ fnav.append (1 , (unsigned char )getbitu (payload.c_str () ,j,8 ));
155+
156+ return fnav;
157+ }
158+
159+
160+
121161// XXX this should do the parity check
122162basic_string<uint8_t > getGPSFromSFRBXMsg (std::basic_string_view<uint8_t > msg)
123163{
0 commit comments