Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 37490e5

Browse files
committed
Clean up PRN lookup
1 parent 29feae6 commit 37490e5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/prns.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@
1515

1616
#include <libswiftnav/prns.h>
1717

18-
static const u8 gps_ca_codes[][128];
19-
static const u8 sbas_ca_codes[][128];
18+
#define PRN_CODE_LENGTH_BYTES 128
19+
20+
static const u8 gps_l1ca_codes[][PRN_CODE_LENGTH_BYTES];
21+
static const u8 sbas_l1ca_codes[][PRN_CODE_LENGTH_BYTES];
22+
23+
/* Table of arrays of PRN codes indexed by code type */
24+
typedef const u8 (*prn_array_t)[PRN_CODE_LENGTH_BYTES];
25+
static const prn_array_t prn_array_table[CODE_COUNT] = {
26+
[CODE_GPS_L1CA] = gps_l1ca_codes,
27+
[CODE_GPS_L2CM] = NULL,
28+
[CODE_SBAS_L1CA] = sbas_l1ca_codes
29+
};
2030

2131
/** \defgroup prns Spreading Codes
2232
*
@@ -36,19 +46,13 @@ static const u8 sbas_ca_codes[][128];
3646
*/
3747
const u8* ca_code(gnss_signal_t sid)
3848
{
39-
assert(sid.code == CODE_GPS_L1CA || sid.code == CODE_SBAS_L1CA);
40-
41-
switch(sid_to_constellation(sid)) {
42-
case CONSTELLATION_GPS:
43-
assert(sid.sat - GPS_FIRST_PRN < NUM_SATS_GPS);
44-
return gps_ca_codes[sid.sat - GPS_FIRST_PRN];
45-
case CONSTELLATION_SBAS:
46-
assert(sid.sat - SBAS_FIRST_PRN < NUM_SATS_SBAS);
47-
return sbas_ca_codes[sid.sat - SBAS_FIRST_PRN];
48-
default:
49-
assert("unsupported constellation");
49+
assert(sid_valid(sid));
50+
const prn_array_t prn_array = prn_array_table[sid.code];
51+
if (prn_array == NULL) {
52+
assert(!"Unsupported code type");
53+
return NULL;
5054
}
51-
return NULL;
55+
return prn_array[sid_to_code_index(sid)];
5256
}
5357

5458
inline s8 get_chip(u8* code, u32 chip_num)
@@ -68,7 +72,7 @@ inline s8 get_chip(u8* code, u32 chip_num)
6872
* }
6973
* Where 1024'th index is 0 for all.
7074
*/
71-
static const u8 gps_ca_codes[NUM_SATS_GPS][128] = {
75+
static const u8 gps_l1ca_codes[NUM_SIGNALS_GPS_L1CA][PRN_CODE_LENGTH_BYTES] = {
7276
{0xC8,0x39,0x49,0xE5,0x13,0xEA,0xD1,0x15,0x59,0x1E,0x9F,0xB7,0x37,0xCA,0xA1,0x00,
7377
0xEA,0x44,0xDE,0x0F,0x5C,0xCF,0x60,0x2F,0x3E,0xA6,0x2D,0xC6,0xF5,0x15,0x82,0x01,
7478
0x03,0x1D,0x81,0xC6,0xFF,0xA7,0x4B,0x61,0x56,0x27,0x2D,0xD8,0xEE,0xF0,0xD8,0x64,
@@ -358,7 +362,7 @@ static const u8 gps_ca_codes[NUM_SATS_GPS][128] = {
358362
0xEF,0xFC,0xAB,0x81,0x7A,0x8A,0x13,0xE6,0x4F,0x7F,0xE7,0x4B,0x2C,0x25,0xCC,0x64}
359363
};
360364

361-
static const u8 sbas_ca_codes[NUM_SATS_SBAS][128] = {
365+
static const u8 sbas_l1ca_codes[NUM_SIGNALS_SBAS_L1CA][PRN_CODE_LENGTH_BYTES] = {
362366
{0x6E,0x61,0xF0,0xB5,0xD5,0x02,0x6D,0x98,0x6E,0x06,0xA4,0xC1,0x87,0x74,0xC2,0xCF,
363367
0x0A,0x3C,0x55,0x7C,0x31,0x80,0xF3,0x67,0x25,0x59,0x00,0xED,0x21,0x0A,0xD7,0xA1,
364368
0xA4,0x6F,0x9B,0xF5,0x10,0xCE,0xAE,0x7F,0x92,0x9A,0xD7,0x93,0x8A,0xEA,0x50,0x35,

0 commit comments

Comments
 (0)