MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_has_rs.c File Reference
#include "mrtk_has_rs.h"
#include <string.h>
Include dependency graph for mrtk_has_rs.c:

Go to the source code of this file.

Macros

#define GF_PRIM   0x11D /* primitive polynomial a^8+a^4+a^3+a^2+1 */
#define RS_N   255 /* code vector length (2^8 - 1) */
#define RS_K   32 /* information vector length */
#define RS_NPAR   (RS_N - RS_K) /* number of parity symbols = 223 */
#define PAGE_OCT   53 /* octets per page */

Functions

static uint8_t gf_mul (uint8_t a, uint8_t b)
static uint8_t gf_inv (uint8_t a)
static void gf_build_tables (void)
static void gf_build_genpoly (uint8_t gpoly[(255 - 32)+1])
static void rs_encode_column (int col, const uint8_t gpoly[(255 - 32)+1])
static int gf_invert (int k, uint8_t a[32][32], uint8_t inv[32][32])
int has_rs_init (void)
 Build the GF(256) log/antilog tables and the systematic generator matrix G. Idempotent: safe to call repeatedly; builds only once.
int has_rs_decode (const uint8_t pages[][53], const uint8_t *pids, int k, uint8_t *out)
 Decode a k-page HAS message from k distinct received encoded pages using the RS(255,32,224) erasure decoder (ICD section 6.4).

Variables

static uint8_t gf_exp [2 *255]
static uint8_t gf_log [256]
static uint8_t G [255][32]
static int rs_ready = 0

Macro Definition Documentation

◆ GF_PRIM

#define GF_PRIM   0x11D /* primitive polynomial a^8+a^4+a^3+a^2+1 */

Definition at line 30 of file mrtk_has_rs.c.

Referenced by gf_build_tables().

◆ PAGE_OCT

#define PAGE_OCT   53 /* octets per page */

Definition at line 34 of file mrtk_has_rs.c.

Referenced by has_rs_decode().

◆ RS_K

#define RS_K   32 /* information vector length */

Definition at line 32 of file mrtk_has_rs.c.

Referenced by gf_invert(), has_rs_decode(), has_rs_init(), and rs_encode_column().

◆ RS_N

#define RS_N   255 /* code vector length (2^8 - 1) */

Definition at line 31 of file mrtk_has_rs.c.

Referenced by gf_build_tables(), gf_inv(), has_rs_decode(), and rs_encode_column().

◆ RS_NPAR

#define RS_NPAR   (RS_N - RS_K) /* number of parity symbols = 223 */

Definition at line 33 of file mrtk_has_rs.c.

Referenced by gf_build_genpoly(), has_rs_init(), and rs_encode_column().

Function Documentation

◆ gf_build_genpoly()

void gf_build_genpoly ( uint8_t gpoly[(255 - 32)+1])
static

Definition at line 75 of file mrtk_has_rs.c.

References gf_exp, gf_mul(), and RS_NPAR.

Referenced by has_rs_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gf_build_tables()

void gf_build_tables ( void )
static

Definition at line 59 of file mrtk_has_rs.c.

References gf_exp, gf_log, GF_PRIM, and RS_N.

Referenced by has_rs_init().

Here is the caller graph for this function:

◆ gf_inv()

uint8_t gf_inv ( uint8_t a)
static

Definition at line 53 of file mrtk_has_rs.c.

References gf_exp, gf_log, and RS_N.

Referenced by gf_invert().

Here is the caller graph for this function:

◆ gf_invert()

int gf_invert ( int k,
uint8_t a[32][32],
uint8_t inv[32][32] )
static

Definition at line 142 of file mrtk_has_rs.c.

References gf_inv(), gf_mul(), and RS_K.

Referenced by has_rs_decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gf_mul()

uint8_t gf_mul ( uint8_t a,
uint8_t b )
static

Definition at line 47 of file mrtk_has_rs.c.

References gf_exp, and gf_log.

Referenced by gf_build_genpoly(), gf_invert(), has_rs_decode(), and rs_encode_column().

Here is the caller graph for this function:

◆ has_rs_decode()

int has_rs_decode ( const uint8_t pages[][53],
const uint8_t * pids,
int k,
uint8_t * out )

Decode a k-page HAS message from k distinct received encoded pages using the RS(255,32,224) erasure decoder (ICD section 6.4).

Each received page is a 53-octet encoded payload carrying Page ID pids[i] (1..255). The encoded page with PID p corresponds to row p-1 of G; output column j (0-based) corresponds to message page j+1.

Parameters
[in]pagesk encoded pages, pages[i] is the 53-octet payload of PID pids[i].
[in]pidsk Page IDs (each 1..255), all distinct.
[in]knumber of received pages / message pages, 1 <= k <= 32.
[out]outrecovered message, k*53 octets (message pages concatenated, page 1 first).
Returns
0 on success, -1 on invalid input (bad k, PID out of range, duplicate PID, or singular decoding matrix).

Definition at line 196 of file mrtk_has_rs.c.

References G, gf_invert(), gf_mul(), has_rs_init(), PAGE_OCT, RS_K, and RS_N.

Referenced by has_complete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ has_rs_init()

int has_rs_init ( void )

Build the GF(256) log/antilog tables and the systematic generator matrix G. Idempotent: safe to call repeatedly; builds only once.

Returns
0 on success.

Definition at line 186 of file mrtk_has_rs.c.

References gf_build_genpoly(), gf_build_tables(), rs_encode_column(), RS_K, RS_NPAR, and rs_ready.

Referenced by has_new(), and has_rs_decode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rs_encode_column()

void rs_encode_column ( int col,
const uint8_t gpoly[(255 - 32)+1] )
static

Definition at line 101 of file mrtk_has_rs.c.

References G, gf_mul(), RS_K, RS_N, and RS_NPAR.

Referenced by has_rs_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ G

uint8_t G[255][32]
static

Definition at line 42 of file mrtk_has_rs.c.

Referenced by has_rs_decode(), and rs_encode_column().

◆ gf_exp

uint8_t gf_exp[2 *255]
static

Definition at line 38 of file mrtk_has_rs.c.

Referenced by gf_build_genpoly(), gf_build_tables(), gf_inv(), and gf_mul().

◆ gf_log

uint8_t gf_log[256]
static

Definition at line 39 of file mrtk_has_rs.c.

Referenced by gf_build_tables(), gf_inv(), and gf_mul().

◆ rs_ready

int rs_ready = 0
static

Definition at line 44 of file mrtk_has_rs.c.

Referenced by has_rs_init().