File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ fn main() {
2626 . header ( format ! ( "{}/include/swiftnav/ionosphere.h" , dst. display( ) ) )
2727 . header ( format ! ( "{}/include/swiftnav/troposphere.h" , dst. display( ) ) )
2828 . header ( format ! ( "{}/include/swiftnav/ephemeris.h" , dst. display( ) ) )
29+ . header ( format ! ( "{}/include/swiftnav/edc.h" , dst. display( ) ) )
2930 // Tell cargo to invalidate the built crate whenever any of the
3031 // included header files changed.
3132 . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
@@ -80,6 +81,7 @@ fn main() {
8081 . whitelist_function ( "decode_ephemeris" )
8182 . whitelist_function ( "decode_bds_d1_ephemeris" )
8283 . whitelist_function ( "decode_gal_ephemeris" )
84+ . whitelist_function ( "crc24q" )
8385 // Finish the builder and generate the bindings.
8486 . generate ( )
8587 // Unwrap the Result and panic on failure.
Original file line number Diff line number Diff line change 1+ use crate :: c_bindings;
2+
3+ pub fn compute_crc24q ( buf : & [ u8 ] , initial_value : u32 ) -> u32 {
4+ unsafe { c_bindings:: crc24q ( buf. as_ptr ( ) , buf. len ( ) as u32 , initial_value) }
5+ }
6+
7+ #[ cfg( test) ]
8+ mod tests {
9+ const TEST_DATA : & [ u8 ] = "123456789" . as_bytes ( ) ;
10+
11+ #[ test]
12+ fn crc24q ( ) {
13+ let crc = super :: compute_crc24q ( & TEST_DATA [ 0 ..0 ] , 0 ) ;
14+ assert ! (
15+ crc == 0 ,
16+ "CRC of empty buffer with starting value 0 should be 0, not {}" ,
17+ crc
18+ ) ;
19+
20+ let crc = super :: compute_crc24q ( & TEST_DATA [ 0 ..0 ] , 22 ) ;
21+ assert ! (
22+ crc == 22 ,
23+ "CRC of empty buffer with starting value 22 should be 22, not {}" ,
24+ crc
25+ ) ;
26+
27+ /* Test value taken from python crcmod package tests, see:
28+ * http://crcmod.sourceforge.net/crcmod.predefined.html */
29+ let crc = super :: compute_crc24q ( TEST_DATA , 0xB704CE ) ;
30+ assert ! (
31+ crc == 0x21CF02 ,
32+ "CRC of \" 123456789\" with init value 0xB704CE should be {}, not 0x%06X" ,
33+ crc
34+ ) ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1616
1717mod c_bindings;
1818pub mod coords;
19+ pub mod edc;
1920pub mod ephemeris;
2021pub mod ionosphere;
2122pub mod signal;
You can’t perform that action at this time.
0 commit comments