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

Commit 5997479

Browse files
committed
Merge pull request #303 from jacobmcnamee/signal_t
Refactor signal_t to use a single enum for constellation and code
2 parents 0aef497 + 021861f commit 5997479

File tree

16 files changed

+586
-353
lines changed

16 files changed

+586
-353
lines changed

include/libswiftnav/signal.h

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
* Copyright (c) 2015 Swift Navigation Inc.
2+
* Copyright (c) 2016 Swift Navigation Inc.
33
* Contact: Vlad Ungureanu <[email protected]>
4+
* Pasi Miettinen <[email protected]>
45
*
56
* This source is subject to the license found in the file 'LICENSE' which must
67
* be be distributed together with this source. All other rights reserved.
@@ -15,68 +16,87 @@
1516

1617
#include <libswiftnav/common.h>
1718

19+
/** \addtogroup signal
20+
* \{ */
21+
22+
/* Number of satellites in each constellation. */
1823
#define NUM_SATS_GPS 32
1924
#define NUM_SATS_SBAS 19
2025
#define NUM_SATS (NUM_SATS_GPS + NUM_SATS_SBAS)
2126

27+
/* Number of codes in each constellation. */
28+
#define NUM_CODES_GPS 2
29+
#define NUM_CODES_SBAS 1
30+
31+
/* Number of signals in each code. */
32+
#define NUM_SIGNALS_GPS_L1CA NUM_SATS_GPS
33+
#define NUM_SIGNALS_GPS_L2CM NUM_SATS_GPS
34+
#define NUM_SIGNALS_SBAS_L1CA NUM_SATS_SBAS
35+
36+
/* Number of signals in each constellation. */
37+
#define NUM_SIGNALS_GPS (NUM_SIGNALS_GPS_L1CA + NUM_SIGNALS_GPS_L2CM)
38+
#define NUM_SIGNALS_SBAS (NUM_SIGNALS_SBAS_L1CA)
39+
#define NUM_SIGNALS (NUM_SIGNALS_GPS + NUM_SIGNALS_SBAS)
40+
41+
#define GPS_FIRST_PRN 1
42+
#define SBAS_FIRST_PRN 120
43+
44+
#define SID_STR_LEN_MAX 16
45+
46+
/** Constellation identifier. */
2247
enum constellation {
48+
CONSTELLATION_INVALID = -1,
2349
CONSTELLATION_GPS,
2450
CONSTELLATION_SBAS,
2551
CONSTELLATION_COUNT,
2652
};
2753

28-
enum band {
29-
BAND_L1,
30-
BAND_COUNT,
54+
/** Code identifier. */
55+
enum code {
56+
CODE_INVALID = -1,
57+
CODE_GPS_L1CA,
58+
CODE_GPS_L2CM,
59+
CODE_SBAS_L1CA,
60+
CODE_COUNT,
3161
};
3262

33-
#define GPS_FIRST_PRN 1
34-
#define SBAS_FIRST_PRN 120
35-
36-
#define SID_STR_LEN_MAX 16
37-
38-
typedef struct __attribute__((packed)) {
63+
/** GNSS signal identifier. */
64+
typedef struct {
3965
u16 sat;
40-
u8 band;
41-
u8 constellation;
66+
enum code code;
4267
} gnss_signal_t;
4368

69+
/** Signal comparison function. */
4470
static inline int sid_compare(const gnss_signal_t a, const gnss_signal_t b)
4571
{
4672
s32 x;
47-
if ((x = a.constellation - b.constellation))
48-
return x;
49-
if ((x = a.band - b.band))
73+
if ((x = a.code - b.code))
5074
return x;
5175
return a.sat - b.sat;
5276
}
5377

78+
/** Untyped signal comparison function. */
5479
static inline int cmp_sid_sid(const void *a, const void *b)
5580
{
5681
return sid_compare(*(gnss_signal_t *)a, *(gnss_signal_t*)b);
5782
}
5883

84+
/** Signal equality function. */
5985
static inline bool sid_is_equal(const gnss_signal_t a, const gnss_signal_t b)
6086
{
6187
return sid_compare(a, b) == 0;
6288
}
6389

64-
/** Print a string representation of sid to the buffer s of capacity n.
65-
* Returns the number of characters printed, excluding the terminating null.
66-
*/
67-
int sid_to_string(char *s, int n, gnss_signal_t sid);
90+
/* \} */
6891

69-
/** Returns true if sid corresponds to a known constellation, band, and
70-
* satellite identifier.
71-
*/
92+
gnss_signal_t construct_sid(enum code code, u16 sat);
93+
int sid_to_string(char *s, int n, gnss_signal_t sid);
7294
bool sid_valid(gnss_signal_t sid);
73-
74-
/** Converts the global index i in [0, NUM_SATS) to the corresponding sid
75-
*/
76-
gnss_signal_t sid_from_index(u32 i);
77-
78-
/** Converts sid to a global index in [0, NUM_SATS)
79-
*/
80-
u32 sid_to_index(gnss_signal_t sid);
95+
bool code_valid(enum code code);
96+
bool constellation_valid(enum constellation constellation);
97+
gnss_signal_t sid_from_code_index(enum code code, u16 code_index);
98+
u16 sid_to_code_index(gnss_signal_t sid);
99+
enum constellation sid_to_constellation(gnss_signal_t sid);
100+
enum constellation code_to_constellation(enum code code);
81101

82102
#endif /* LIBSWIFTNAV_SIGNAL_H */

python/swiftnav/signal.pxd

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2015 Swift Navigation Inc.
1+
# Copyright (C) 2016 Swift Navigation Inc.
22
#
33
# This source is subject to the license found in the file 'LICENSE' which must
44
# be be distributed together with this source. All other rights reserved.
@@ -11,32 +11,53 @@ from common cimport *
1111
from libcpp cimport bool
1212

1313
cdef extern from "libswiftnav/signal.h":
14-
enum:
15-
GPS_L1_SATS
16-
WAAS_SATS
17-
EGNOS_SATS
18-
GAGAN_SATS
19-
MSAS_SATS
20-
SDCM_SATS
21-
SBAS_SATS
22-
ALL_SATS
14+
cdef enum constellation:
15+
CONSTELLATION_INVALID = -1
2316
CONSTELLATION_GPS
2417
CONSTELLATION_SBAS
25-
BAND_L1
18+
CONSTELLATION_COUNT
19+
20+
cdef enum code:
21+
CODE_INVALID = -1
22+
CODE_GPS_L1CA
23+
CODE_GPS_L2CM
24+
CODE_SBAS_L1CA
25+
CODE_COUNT
26+
27+
enum:
28+
NUM_SATS_GPS
29+
NUM_SATS_SBAS
30+
NUM_SATS
31+
NUM_CODES_GPS
32+
NUM_CODES_SBAS
33+
NUM_SIGNALS_GPS_L1CA
34+
NUM_SIGNALS_GPS_L2CM
35+
NUM_SIGNALS_SBAS_L1CA
36+
NUM_SIGNALS_GPS
37+
NUM_SIGNALS_SBAS
38+
NUM_SIGNALS
39+
GPS_FIRST_PRN
40+
SBAS_FIRST_PRN
41+
SID_STR_LEN_MAX
2642

2743
ctypedef struct gnss_signal_t:
2844
u16 sat
29-
u8 band
30-
u8 constellation
45+
code code
3146

3247
int sid_compare(const gnss_signal_t a, const gnss_signal_t b)
3348
int cmp_sid_sid(const void *a, const void *b)
3449
bool sid_is_equal(const gnss_signal_t a, const gnss_signal_t b)
3550

51+
gnss_signal_t construct_sid(code code, u16 sat);
3652
int sid_to_string(char *s, int n, gnss_signal_t sid)
3753
bool sid_valid(gnss_signal_t sid)
38-
gnss_signal_t sid_from_index(u32 i)
39-
u32 sid_to_index(gnss_signal_t sid)
54+
bool code_valid(code code)
55+
bool constellation_valid(constellation constellation)
56+
57+
gnss_signal_t sid_from_code_index(code code, u16 code_index);
58+
u16 sid_to_code_index(gnss_signal_t sid);
59+
constellation sid_to_constellation(gnss_signal_t sid);
60+
constellation code_to_constellation(code code);
4061

4162
cdef class GNSSSignal:
4263
cdef gnss_signal_t _thisptr

python/swiftnav/signal.pyx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2015 Swift Navigation Inc.
1+
# Copyright (C) 2016 Swift Navigation Inc.
22
#
33
# This source is subject to the license found in the file 'LICENSE' which must
44
# be be distributed together with this source. All other rights reserved.
@@ -39,18 +39,24 @@ cdef class GNSSSignal:
3939
def is_valid(self):
4040
return sid_valid(self._thisptr)
4141

42-
def to_index(self):
43-
return sid_to_index(self._thisptr)
42+
def to_code_index(self):
43+
return sid_to_code_index(self._thisptr)
44+
45+
def from_code_index(self, code, code_index):
46+
self._thisptr = sid_from_code_index(code, code_index)
47+
48+
def to_constellation(self):
49+
return sid_to_constellation(self._thisptr)
4450

4551
def to_string(self):
4652
cdef u8 n = 255
4753
cdef char s[255]
4854
cdef s8 length = sid_to_string(&s[0], n, self._thisptr)
4955
return s[:length].decode('UTF-8')
5056

51-
def sid_from_index(i):
57+
def signal_from_code_index(code, code_index):
5258
sid = GNSSSignal()
53-
sid._thispr = sid_from_index(i)
59+
sid._thisptr = sid_from_code_index(code, code_index)
5460
return sid
5561

5662
cdef mk_signal_array(py_signals, u8 n_c_signals, gnss_signal_t *c_signals):
@@ -77,3 +83,4 @@ cdef read_signal_array(u8 n_c_signals, gnss_signal_t *c_signals):
7783
sd_ = (<GNSSSignal> signal)._thisptr
7884
memcpy(&sd_, &c_signals[i], sizeof(gnss_signal_t))
7985
return py_signals
86+

python/tests/test_almanac.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (C) 2015 Swift Navigation Inc.
2+
# Copyright (C) 2016 Swift Navigation Inc.
33
# Contact: Bhaskar Mookerji <[email protected]>
44
#
55
# This source is subject to the license found in the file 'LICENSE' which must
@@ -29,8 +29,7 @@ def test_init():
2929
},
3030
'healthy': 1,
3131
'sid': {
32-
'band': 0,
33-
'constellation': 0,
32+
'code': 0,
3433
'sat': 1
3534
},
3635
'valid': 1,
@@ -58,8 +57,7 @@ def test_almanac_functions():
5857
},
5958
'valid': 1,
6059
'sid': {
61-
'band': 0,
62-
'constellation': 0,
60+
'code': 0,
6361
'sat': 1
6462
}
6563
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (C) 2015 Swift Navigation Inc.
2+
# Copyright (C) 2016 Swift Navigation Inc.
33
# Contact: Bhaskar Mookerji <[email protected]>
44
#
55
# This source is subject to the license found in the file 'LICENSE' which must
@@ -15,22 +15,22 @@
1515
import swiftnav.signal as s
1616

1717
def test_update_sats_same_sats():
18-
sids = [s.GNSSSignal(sat=3, band=0, constellation=0),
19-
s.GNSSSignal(sat=1, band=0, constellation=0),
20-
s.GNSSSignal(sat=2, band=0, constellation=0),
21-
s.GNSSSignal(sat=4, band=0, constellation=0)]
18+
sids = [s.GNSSSignal(sat=3, code=0),
19+
s.GNSSSignal(sat=1, code=0),
20+
s.GNSSSignal(sat=2, code=0),
21+
s.GNSSSignal(sat=4, code=0)]
2222
sm = sat.SatsManagement(sids=sids)
2323
test = a.AmbiguityTest(sats=sm)
24-
sdiffs = [o.SingleDiff(sid={'sat':1, 'band': 0, 'constellation': 0},
24+
sdiffs = [o.SingleDiff(sid={'sat':1, 'code': 0},
2525
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
2626
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
27-
o.SingleDiff(sid={'sat':2, 'band': 0, 'constellation': 0},
27+
o.SingleDiff(sid={'sat':2, 'code': 0},
2828
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
2929
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
30-
o.SingleDiff(sid={'sat':3, 'band': 0, 'constellation': 0},
30+
o.SingleDiff(sid={'sat':3, 'code': 0},
3131
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
3232
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
33-
o.SingleDiff(sid={'sat':4, 'band': 0, 'constellation': 0},
33+
o.SingleDiff(sid={'sat':4, 'code': 0},
3434
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
3535
carrier_phase=0, raw_doppler=0, doppler=0, snr=0)]
3636
assert not test.ambiguity_update_sats(sdiffs, None, None, None, None, False)
@@ -40,35 +40,35 @@ def test_update_sats_same_sats():
4040
assert test.sats['sids'][3]['sat'] == 4
4141

4242
def test_bad_measurements():
43-
sids = [s.GNSSSignal(sat=1, band=0, constellation=0),
44-
s.GNSSSignal(sat=2, band=0, constellation=0),
45-
s.GNSSSignal(sat=3, band=0, constellation=0),
46-
s.GNSSSignal(sat=5, band=0, constellation=0),
47-
s.GNSSSignal(sat=6, band=0, constellation=0)]
43+
sids = [s.GNSSSignal(sat=1, code=0),
44+
s.GNSSSignal(sat=2, code=0),
45+
s.GNSSSignal(sat=3, code=0),
46+
s.GNSSSignal(sat=5, code=0),
47+
s.GNSSSignal(sat=6, code=0)]
4848
float_sats = sat.SatsManagement(sids=sids)
49-
sids = [s.GNSSSignal(sat=3, band=0, constellation=0),
50-
s.GNSSSignal(sat=1, band=0, constellation=0),
51-
s.GNSSSignal(sat=2, band=0, constellation=0),
52-
s.GNSSSignal(sat=5, band=0, constellation=0),
53-
s.GNSSSignal(sat=6, band=0, constellation=0)]
49+
sids = [s.GNSSSignal(sat=3, code=0),
50+
s.GNSSSignal(sat=1, code=0),
51+
s.GNSSSignal(sat=2, code=0),
52+
s.GNSSSignal(sat=5, code=0),
53+
s.GNSSSignal(sat=6, code=0)]
5454
amb_sats_init = sat.SatsManagement(sids=sids)
5555
test = a.AmbiguityTest(sats=float_sats)
56-
sdiffs = [o.SingleDiff(sid={'sat':1, 'band': 0, 'constellation': 0},
56+
sdiffs = [o.SingleDiff(sid={'sat':1, 'code': 0},
5757
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
5858
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
59-
o.SingleDiff(sid={'sat':2, 'band': 0, 'constellation': 0},
59+
o.SingleDiff(sid={'sat':2, 'code': 0},
6060
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
6161
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
62-
o.SingleDiff(sid={'sat':3, 'band': 0, 'constellation': 0},
62+
o.SingleDiff(sid={'sat':3, 'code': 0},
6363
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
6464
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
65-
o.SingleDiff(sid={'sat':4, 'band': 0, 'constellation': 0},
65+
o.SingleDiff(sid={'sat':4, 'code': 0},
6666
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
6767
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
68-
o.SingleDiff(sid={'sat':5, 'band': 0, 'constellation': 0},
68+
o.SingleDiff(sid={'sat':5, 'code': 0},
6969
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
7070
carrier_phase=0, raw_doppler=0, doppler=0, snr=0),
71-
o.SingleDiff(sid={'sat':6, 'band': 0, 'constellation': 0},
71+
o.SingleDiff(sid={'sat':6, 'code': 0},
7272
pseudorange=0, sat_pos=(0, 0, 0), sat_vel=(0, 0, 0),
7373
carrier_phase=0, raw_doppler=0, doppler=0, snr=0)]
7474
#ambiguity_update_sats(&amb_test, num_sdiffs, sdiffs, &float_sats, est, U, D, false);

0 commit comments

Comments
 (0)