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

Add support for QZSS (WIP - do not merge) #253

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DEVELOPMENT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Tools needed:
- doxygen
- convert from ImageMagick
- pip install gcovr diff-cover
- pdflatex from TeX Live

To get started, run::

Expand Down
6 changes: 4 additions & 2 deletions include/libswiftnav/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

#define NUM_SATS_GPS 32
#define NUM_SATS_SBAS 22
#define NUM_SATS (NUM_SATS_GPS + NUM_SATS_SBAS)
#define NUM_SATS_QZSS 5
#define NUM_SATS (NUM_SATS_GPS + NUM_SATS_SBAS + NUM_SATS_QZSS)

enum constellation {
CONSTELLATION_GPS,
CONSTELLATION_SBAS,
CONSTELLATION_QZSS,
CONSTELLATION_COUNT,
};

Expand All @@ -32,6 +34,7 @@ enum band {

#define GPS_FIRST_PRN 1
#define SBAS_FIRST_PRN 120
#define QZSS_FIRST_PRN 192

#define SID_STR_LEN_MAX 16

Expand Down Expand Up @@ -80,4 +83,3 @@ gnss_signal_t sid_from_index(u32 i);
u32 sid_to_index(gnss_signal_t sid);

#endif /* LIBSWIFTNAV_SIGNAL_H */

9 changes: 1 addition & 8 deletions python/swiftnav/signal.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@ from libcpp cimport bool

cdef extern from "libswiftnav/signal.h":
enum:
GPS_L1_SATS
WAAS_SATS
EGNOS_SATS
GAGAN_SATS
MSAS_SATS
SDCM_SATS
SBAS_SATS
ALL_SATS
CONSTELLATION_GPS
CONSTELLATION_SBAS
CONSTELLATION_QZSS
BAND_L1

ctypedef struct gnss_signal_t:
Expand Down
4 changes: 3 additions & 1 deletion src/almanac.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static void gps_calc_sat_state_almanac(const almanac_t* alm_, double t, s16 week
double ea = ma; /* Starting value for E. */
double ea_old;
double temp;
// TODO: inclination offset for QZSS different from GPS
double ecc = alm->ecc;
u32 count = 0;

Expand Down Expand Up @@ -144,6 +145,7 @@ static void gps_calc_sat_state_almanac(const almanac_t* alm_, double t, s16 week

/* Compute the satellite's position in Earth-Centered Earth-Fixed
* coordinates. */
// TODO: inclination offset for QZSS different from GPS
pos[0] = x * cos(om) - y * cos(alm->inc) * sin(om);
pos[1] = x * sin(om) + y * cos(alm->inc) * cos(om);
pos[2] = y * sin(alm->inc);
Expand Down Expand Up @@ -176,6 +178,7 @@ void calc_sat_state_almanac(const almanac_t* alm, double t, s16 week,
{
switch(alm->sid.constellation) {
case CONSTELLATION_GPS:
case CONSTELLATION_QZSS:
gps_calc_sat_state_almanac(alm, t, week, pos, vel);
break;
case CONSTELLATION_SBAS:
Expand Down Expand Up @@ -241,4 +244,3 @@ double calc_sat_doppler_almanac(const almanac_t* alm, double t, s16 week,
}

/** \} */

6 changes: 4 additions & 2 deletions src/ephemeris.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ s8 calc_sat_state(const ephemeris_t *e, gps_time_t t,

switch (e->sid.constellation) {
case CONSTELLATION_GPS:
case CONSTELLATION_QZSS:
return calc_sat_state_kepler(e, t, pos, vel, clock_err, clock_rate_err);
case CONSTELLATION_SBAS:
return calc_sat_state_xyz(e, t, pos, vel, clock_err, clock_rate_err);
Expand Down Expand Up @@ -276,7 +277,7 @@ void decode_ephemeris(u32 frame_words[3][8], ephemeris_t *e)
{
assert(frame_words != NULL);
assert(e != NULL);
assert(e->sid.constellation == CONSTELLATION_GPS);
assert((e->sid.constellation == CONSTELLATION_GPS) || (e->sid.constellation == CONSTELLATION_QZSS));
ephemeris_kepler_t *k = &e->kepler;

/* These unions facilitate signed/unsigned conversion and sign extension. */
Expand Down Expand Up @@ -308,6 +309,7 @@ void decode_ephemeris(u32 frame_words[3][8], ephemeris_t *e)
e->healthy = !(frame_words[0][3-3] >> (30-17) & 1);

/* t_gd: Word 7, bits 17-24 */
// TODO
onebyte.u8 = frame_words[0][7-3] >> (30-24) & 0xFF;
k->tgd = onebyte.s8 * pow(2,-31);

Expand Down Expand Up @@ -468,6 +470,7 @@ bool ephemeris_equal(const ephemeris_t *a, const ephemeris_t *b)

switch (a->sid.constellation) {
case CONSTELLATION_GPS:
case CONSTELLATION_QZSS:
return ephemeris_kepler_equal(&a->kepler, &b->kepler);
case CONSTELLATION_SBAS:
return ephemeris_xyz_equal(&a->xyz, &b->xyz);
Expand All @@ -476,4 +479,3 @@ bool ephemeris_equal(const ephemeris_t *a, const ephemeris_t *b)
return false;
}
}

50 changes: 50 additions & 0 deletions src/prns.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

static const u8 gps_ca_codes[][128];
static const u8 sbas_ca_codes[][128];
static const u8 qzss_ca_codes[][128];

/** \defgroup prns Spreading Codes
*
Expand Down Expand Up @@ -44,6 +45,9 @@ const u8* ca_code(gnss_signal_t sid)
case CONSTELLATION_SBAS:
assert(sid.sat - SBAS_FIRST_PRN < NUM_SATS_SBAS);
return sbas_ca_codes[sid.sat - SBAS_FIRST_PRN];
case CONSTELLATION_QZSS:
assert(sid.sat - QZSS_FIRST_PRN < NUM_SATS_QZSS);
return qzss_ca_codes[sid.sat - QZSS_FIRST_PRN];
default:
assert("unsupported constellation");
}
Expand Down Expand Up @@ -557,3 +561,49 @@ static const u8 sbas_ca_codes[NUM_SATS_SBAS][128] = {
0xA3,0x24,0xB3,0x35,0x07,0x0E,0x45,0x50,0x67,0xBD,0x77,0xAE,0x06,0x54,0x7B,0x66}
};

static const u8 qzss_ca_codes[NUM_SATS_QZSS][128] = {
{0x75,0xC3,0x02,0x81,0x09,0x62,0x80,0x42,0xAC,0xFF,0x2B,0xFE,0x06,0x96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E0,0x5B,0xEE,0x2B,0x85,0x1C,0xC4,0xE8,0xBE,0xE6,0xA8,0x42,0x7A,0x99,0xF4,
0x89,0x34,0xF9,0x29,0x16,0xEC,0x91,0x27,0x11,0x7F,0x26,0x74,0xD1,0xFA,0x83,0x89,
0x22,0x95,0xC4,0x13,0xB1,0xE5,0x84,0x8D,0x35,0x0F,0x1C,0x87,0x2C,0x44,0xB4,0xB2,
0x69,0x70,0x50,0x5B,0x03,0xCD,0xA2,0xC9,0x31,0xED,0x3E,0x4D,0x8E,0x31,0x99,0x98},

{0xA7,0xC5,0xFD,0x4A,0x43,0x97,0x87,0x97,0xC4,0xD6,0xF7,0x78,0x8A,0x6D,0x35,0x7B,
0xF8,0xB3,0x37,0x22,0xCC,0xA5,0x41,0x6A,0x61,0x71,0xAB,0x17,0xD1,0xD0,0xF3,0x39,
0x0A,0x48,0x9A,0xDF,0xB3,0xAD,0x87,0xFE,0xCB,0x09,0x24,0x36,0x4B,0xD7,0x84,0x91,
0x2C,0x06,0x7B,0xDB,0xC3,0xA4,0x06,0x3A,0x74,0xA6,0xAC,0x5D,0xFE,0x3A,0x58,0x54,
0xE1,0xCE,0x0F,0xDF,0x91,0xAA,0x3F,0x89,0x2E,0xB0,0x3B,0x04,0x6D,0xE2,0x6A,0x0C,
0x97,0x16,0x25,0xF2,0x45,0x08,0x43,0x21,0xEE,0xB4,0x6C,0x81,0xD6,0x2F,0xEB,0xA0,
0xFE,0x13,0x48,0xE8,0x6B,0x9C,0xC3,0x3C,0x1A,0x71,0x8E,0x5E,0x2A,0xE6,0xA0,0xE7,
0x94,0x08,0x3D,0x49,0x4F,0x9A,0xB1,0x49,0xA4,0xBC,0x8F,0xD9,0x4E,0x9D,0x50,0x60}
};
19 changes: 18 additions & 1 deletion src/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ typedef struct {

static const char * constellation_strs[CONSTELLATION_COUNT] = {
[CONSTELLATION_GPS] = "GPS",
[CONSTELLATION_SBAS] = "SBAS"
[CONSTELLATION_SBAS] = "SBAS",
[CONSTELLATION_QZSS] = "QZSS"
};

static const char * band_strs[BAND_COUNT] = {
Expand All @@ -36,8 +37,10 @@ static const char * unknown_str = "?";

static u16 sat_get_gps(u32 local_index);
static u16 sat_get_sbas(u32 local_index);
static u16 sat_get_qzss(u32 local_index);
static u32 local_index_get_gps(u16 sat);
static u32 local_index_get_sbas(u16 sat);
static u32 local_index_get_qzss(u16 sat);

static const sat_group_t sat_groups[CONSTELLATION_COUNT] = {
[CONSTELLATION_GPS] = {
Expand All @@ -47,6 +50,10 @@ static const sat_group_t sat_groups[CONSTELLATION_COUNT] = {
[CONSTELLATION_SBAS] = {
CONSTELLATION_SBAS, BAND_L1, NUM_SATS_SBAS,
sat_get_sbas, local_index_get_sbas
},
[CONSTELLATION_QZSS] = {
CONSTELLATION_QZSS, BAND_L1, NUM_SATS_QZSS,
sat_get_qzss, local_index_get_qzss
}
};

Expand All @@ -60,6 +67,11 @@ static u16 sat_get_sbas(u32 local_index)
return local_index + SBAS_FIRST_PRN;
}

static u16 sat_get_qzss(u32 local_index)
{
return local_index + QZSS_FIRST_PRN;
}

static u32 local_index_get_gps(u16 sat)
{
return sat - GPS_FIRST_PRN;
Expand All @@ -70,6 +82,11 @@ static u32 local_index_get_sbas(u16 sat)
return sat - SBAS_FIRST_PRN;
}

static u32 local_index_get_qzss(u16 sat)
{
return sat - QZSS_FIRST_PRN;
}

int sid_to_string(char *s, int n, gnss_signal_t sid)
{
const char *constellation_str = (sid.constellation < CONSTELLATION_COUNT) ?
Expand Down