MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_bits.h
Go to the documentation of this file.
1/*------------------------------------------------------------------------------
2 * mrtk_bits.h : bit manipulation and CRC functions
3 *
4 * Copyright (C) 2026 H.SHIONO (MRTKLIB Project)
5 * Copyright (C) 2023-2025 Cabinet Office, Japan
6 * Copyright (C) 2024-2025 Lighthouse Technology & Consulting Co. Ltd.
7 * Copyright (C) 2023-2025 Japan Aerospace Exploration Agency
8 * Copyright (C) 2023-2025 TOSHIBA ELECTRONIC TECHNOLOGIES CORPORATION
9 * Copyright (C) 2015- Mitsubishi Electric Corp.
10 * Copyright (C) 2014 Geospatial Information Authority of Japan
11 * Copyright (C) 2014 T.SUZUKI
12 * Copyright (C) 2007-2023 T.TAKASU
13 *
14 * SPDX-License-Identifier: BSD-2-Clause
15 *----------------------------------------------------------------------------*/
16/**
17 * @file mrtk_bits.h
18 * @brief MRTKLIB Bits Module — Binary bit operations and CRC functions.
19 *
20 * This header provides bit-level extraction/insertion functions
21 * (getbitu, getbits, setbitu, setbits), CRC parity computation
22 * (rtk_crc32, rtk_crc24q, rtk_crc16), and GPS navigation word
23 * decoding (decode_word), extracted from rtkcmn.c with zero
24 * algorithmic changes.
25 *
26 * @note Functions declared here are implemented in mrtk_bits.c.
27 */
28#ifndef MRTK_BITS_H
29#define MRTK_BITS_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#include <stdint.h>
36
37/*============================================================================
38 * Bit Extraction / Insertion Functions
39 *===========================================================================*/
40
41/**
42 * @brief Extract unsigned bits from byte data.
43 * @param[in] buff Byte data
44 * @param[in] pos Bit position from start of data (bits)
45 * @param[in] len Bit length (bits) (len<=32)
46 * @return Extracted unsigned bits
47 */
48uint32_t getbitu(const uint8_t* buff, int pos, int len);
49
50/**
51 * @brief Extract signed bits from byte data.
52 * @param[in] buff Byte data
53 * @param[in] pos Bit position from start of data (bits)
54 * @param[in] len Bit length (bits) (len<=32)
55 * @return Extracted signed bits
56 */
57int32_t getbits(const uint8_t* buff, int pos, int len);
58
59/**
60 * @brief Set unsigned bits in byte data.
61 * @param[in,out] buff Byte data
62 * @param[in] pos Bit position from start of data (bits)
63 * @param[in] len Bit length (bits) (len<=32)
64 * @param[in] data Unsigned data to set
65 */
66void setbitu(uint8_t* buff, int pos, int len, uint32_t data);
67
68/**
69 * @brief Set signed bits in byte data.
70 * @param[in,out] buff Byte data
71 * @param[in] pos Bit position from start of data (bits)
72 * @param[in] len Bit length (bits) (len<=32)
73 * @param[in] data Signed data to set
74 */
75void setbits(uint8_t* buff, int pos, int len, int32_t data);
76
77/*============================================================================
78 * CRC Parity Functions
79 *===========================================================================*/
80
81/**
82 * @brief Compute CRC-32 parity for NovAtel raw data.
83 * @param[in] buff Data buffer
84 * @param[in] len Data length (bytes)
85 * @return CRC-32 parity
86 * @note See NovAtel OEMV firmware manual 1.7 32-bit CRC
87 */
88uint32_t rtk_crc32(const uint8_t* buff, int len);
89
90/**
91 * @brief Compute CRC-24Q parity for SBAS and RTCM3.
92 * @param[in] buff Data buffer
93 * @param[in] len Data length (bytes)
94 * @return CRC-24Q parity
95 */
96uint32_t rtk_crc24q(const uint8_t* buff, int len);
97
98/**
99 * @brief Compute CRC-16 parity for BINEX and NVS.
100 * @param[in] buff Data buffer
101 * @param[in] len Data length (bytes)
102 * @return CRC-16 parity
103 */
104uint16_t rtk_crc16(const uint8_t* buff, int len);
105
106/*============================================================================
107 * Navigation Data Word Decoding
108 *===========================================================================*/
109
110/**
111 * @brief Check parity and decode GPS navigation data word.
112 * @param[in] word Navigation data word (2+30 bit)
113 * (previous word D29*-30* + current word D1-30)
114 * @param[out] data Decoded navigation data without parity (8bit x 3)
115 * @return Status (1:ok, 0:parity error)
116 * @note See reference [1] 20.3.5.2 user parity algorithm
117 */
118int decode_word(uint32_t word, uint8_t* data);
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /* MRTK_BITS_H */
uint32_t rtk_crc24q(const uint8_t *buff, int len)
Compute CRC-24Q parity for SBAS and RTCM3.
Definition mrtk_bits.c:181
uint16_t rtk_crc16(const uint8_t *buff, int len)
Compute CRC-16 parity for BINEX and NVS.
Definition mrtk_bits.c:199
void setbitu(uint8_t *buff, int pos, int len, uint32_t data)
Set unsigned bits in byte data.
Definition mrtk_bits.c:122
uint32_t getbitu(const uint8_t *buff, int pos, int len)
Extract unsigned bits from byte data.
Definition mrtk_bits.c:99
int32_t getbits(const uint8_t *buff, int pos, int len)
Extract signed bits from byte data.
Definition mrtk_bits.c:107
void setbits(uint8_t *buff, int pos, int len, int32_t data)
Set signed bits in byte data.
Definition mrtk_bits.c:136
uint32_t rtk_crc32(const uint8_t *buff, int len)
Compute CRC-32 parity for NovAtel raw data.
Definition mrtk_bits.c:156
int decode_word(uint32_t word, uint8_t *data)
Check parity and decode GPS navigation data word.
Definition mrtk_bits.c:224