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

Commit 8bbc35e

Browse files
committed
Merge pull request #350 from rge-exafore/libswiftnav-peregrine-l2c
Change libswiftnav to support L2CM tracking in Peregrine
2 parents 72f05ff + 9a85cf5 commit 8bbc35e

27 files changed

+1774
-121
lines changed

include/libswiftnav/correlate.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
* Copyright (C) 2013 Swift Navigation Inc.
2+
* Copyright (C) 2013,2016 Swift Navigation Inc.
33
* Contact: Fergus Noble <[email protected]>
4+
* Contact: Adel Mamin <[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,12 +16,22 @@
1516

1617
#include <libswiftnav/common.h>
1718

18-
void track_correlate(s8* samples, s8* code,
19-
double* init_code_phase, double code_step,
20-
double* init_carr_phase, double carr_step,
21-
double* I_E, double* Q_E,
22-
double* I_P, double* Q_P,
23-
double* I_L, double* Q_L,
24-
u32* num_samples);
19+
void l1_ca_track_correlate(const s8* samples, size_t samples_len,
20+
const s8* code,
21+
u32 chips_to_correlate,
22+
double* init_code_phase, double code_step,
23+
double* init_carr_phase, double carr_step,
24+
double* I_E, double* Q_E,
25+
double* I_P, double* Q_P,
26+
double* I_L, double* Q_L, u32* num_samples);
27+
28+
void l2c_cm_track_correlate(const s8* samples, size_t samples_len,
29+
const s8* code,
30+
u32 chips_to_correlate,
31+
double* init_code_phase, double code_step,
32+
double* init_carr_phase, double carr_step,
33+
double* I_E, double* Q_E,
34+
double* I_P, double* Q_P,
35+
double* I_L, double* Q_L, u32* num_samples);
2536

2637
#endif /* LIBSWIFTNAV_CORRELATE_H */
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Adel Mamin <[email protected]>
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
/**
14+
@file
15+
16+
This utility helps to verify the integrity of samples data from Piksi v3 HW.
17+
The regular Piksi v3 samples data format in one byte is:
18+
RF4 RF3 RF2 RF1
19+
00 00 00 00
20+
21+
RF1 - GPS L1
22+
RF2 - GLONASS L1
23+
RF3 - GLONASS L2
24+
RF4 - GPS L2
25+
26+
This utility is expecting RF3 and RF2 to have 4 bits counter,
27+
which is continuosly incremented with modulo SAMPLE_COUNTER_MODULO.
28+
RF2 is expected to have two least significant bits
29+
and RF3 - two most significant bits.
30+
Therefore, the bit indexes are:
31+
RF3 RF2
32+
5&4 3&2
33+
*/
34+
35+
#ifndef LIBSWIFTNAV_COUNTER_CHECKER_H
36+
#define LIBSWIFTNAV_COUNTER_CHECKER_H
37+
38+
#include <stdint.h>
39+
#include <stddef.h>
40+
#include <libswiftnav/common.h>
41+
42+
/** How many bytes we read from samples stream at a time. */
43+
#define SAMPLE_CHUNK_SIZE (1024 * 1024) /* [bytes] */
44+
45+
/** The counter embedded into the sample data stream is expected
46+
to have this modulo. */
47+
#define SAMPLE_COUNTER_MODULO 13
48+
49+
/** The counter bit size. */
50+
#define SAMPLE_COUNTER_BITS 4 /* [bits] */
51+
52+
/** Teh counter bit offset within a byte. */
53+
#define SAMPLE_COUNTER_OFFSET 2 /* [bits] */
54+
55+
/** How many bytes we read from samples file at a time. */
56+
#define COUNTER_CHECKER_CHUNK_SIZE (1024 * 1024) /* [bytes] */
57+
58+
/** Get \e num of bits at \e offset in \e data */
59+
#define GET_BITS(data, offset, num) \
60+
( ((data) >> (offset)) & ((1 << (num)) - 1) )
61+
62+
/** Get \e num of bits at \e offset in \e data */
63+
#define SET_BITS(data, offset, num, bits) \
64+
( ( ~( ((1 << (num)) - 1) << (offset) ) & (data) ) | \
65+
( ( (bits) & ((1 << (num)) - 1) ) << (offset) ) )
66+
67+
/** Get GPS counter
68+
* \param data Data byte
69+
* \return The counter value
70+
*/
71+
uint8_t get_gps_counter(uint8_t data);
72+
73+
/** Get Glonass counter
74+
* \param data Data byte
75+
* \return The counter value
76+
*/
77+
uint8_t get_glo_counter(uint8_t data);
78+
79+
uint8_t set_gps_counter(uint8_t data, uint8_t counter);
80+
uint8_t set_glo_counter(uint8_t data, uint8_t counter);
81+
82+
/** A data mismatch descriptor. */
83+
struct mismatch {
84+
size_t offset; /**! Data offset [bytes]. */
85+
uint8_t data; /**! Data. */
86+
uint8_t expected_counter; /**! The expected counter value. */
87+
uint8_t actual_counter; /**! The actual counter value. */
88+
};
89+
90+
/** Mismatch array data */
91+
struct mismatch_data {
92+
/** The sample data counter mismatch incidents are stored here. */
93+
struct mismatch data[COUNTER_CHECKER_CHUNK_SIZE];
94+
/** How many valid entries there are in \e mismatch array. */
95+
size_t counter;
96+
};
97+
98+
struct callbacks {
99+
size_t (*read)(void *ptr, size_t size, void *f);
100+
void (*rewind)(void *f);
101+
uint8_t (*get_counter)(uint8_t data);
102+
uint8_t (*set_counter)(uint8_t data, uint8_t counter);
103+
};
104+
105+
typedef size_t (*stream_read_t)(void *ptr, size_t size, void *stream);
106+
typedef void (*stream_rewind_t)(void *stream);
107+
108+
uint8_t get_rf32_counter(uint8_t data);
109+
uint8_t set_rf32_counter(uint8_t data, uint8_t counter);
110+
uint8_t get_rf41_counter(uint8_t data);
111+
uint8_t set_rf41_counter(uint8_t data, uint8_t counter);
112+
113+
void report_mismatch(const struct mismatch_data *mismatch);
114+
115+
void counter_checker_init(void);
116+
117+
const struct mismatch_data *counter_checker_run(struct callbacks *cbs,
118+
void *stream,
119+
size_t data_size);
120+
121+
#endif /* LIBSWIFTNAV_COUNTER_CHECKER_H */

libfec/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ add_library(fec viterbi27.c)
1111

1212
install(TARGETS fec DESTINATION lib${LIB_SUFFIX})
1313

14-
install(FILES ${libfec_HEADERS} DESTINATION include/)
14+
install(FILES ${libfec_HEADERS} DESTINATION include/libfec/)

python/setup.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,45 @@
2424
print "You don't seem to have Cython installed."
2525
sys.exit(1)
2626
os.environ['ARCHFLAGS'] = ""
27+
28+
# Additional library search directories:
29+
# - LD_LIBRARY_PATH (if present)
30+
# - User local enviroment
31+
library_dirs = []
32+
# If LD_LIBRARY_PATH has been manually specified, add it to the
33+
# library search path
34+
if 'LD_LIBRARY_PATH' in os.environ:
35+
library_dirs.append(os.environ['LD_LIBRARY_PATH'])
36+
library_dirs.append(os.path.expanduser('~/.local/lib'))
37+
38+
# Additional include directories:
39+
# - Numpy includes
40+
# - User local enviroment
41+
# - Current directory
42+
include_dirs = []
43+
include_dirs.append(np.get_include())
44+
include_dirs.append(os.path.expanduser('~/.local/include'))
45+
include_dirs.append('.')
46+
# three more includes for travis builds as it does not install libraries
47+
include_dirs.append('../include/')
48+
include_dirs.append('../libfec/include/')
49+
include_dirs.append('../tests/data/l2cbitstream/')
2750
def make_extension(ext_name):
2851
ext_path = ext_name.replace('.', os.path.sep) + '.pyx'
29-
library_dirs = []
30-
# If LD_LIBRARY_PATH has been manually specified, add it to the
31-
# library search path
32-
if 'LD_LIBRARY_PATH' in os.environ:
33-
library_dirs.append(os.environ['LD_LIBRARY_PATH'])
3452
return Extension(
3553
ext_name, [ext_path],
36-
include_dirs = [np.get_include(), '.', '../include/'],
54+
include_dirs = include_dirs,
3755
extra_compile_args = ['-O0', '-g'],
3856
extra_link_args = ['-g'],
39-
libraries = ['m', 'swiftnav'],
57+
libraries = ['m', 'swiftnav', 'l2cbitstream'],
4058
library_dirs = library_dirs,
4159
)
4260
ext_names = [
4361
'swiftnav.edc',
4462
'swiftnav.signal',
4563
'swiftnav.coord_system',
4664
'swiftnav.constants',
65+
'swiftnav.cnav_msg',
4766
'swiftnav.nav_msg',
4867
'swiftnav.pvt',
4968
'swiftnav.correlate',

python/swiftnav/bits.pyx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@
1212
Bit field packing, unpacking and utility functions.
1313
1414
"""
15-
15+
from swiftnav.bits cimport parity as c_parity
1616

1717
def parity(x):
18-
raise NotImplementedError
18+
'''
19+
Cython wrapper for parity function
20+
21+
Parameters
22+
----------
23+
x : int
24+
Value for parity computation
25+
26+
Returns
27+
-------
28+
int
29+
Parity value: 1 or 0.
30+
'''
31+
return c_parity(x)
1932

2033
def getbitu(buff, pos, length):
2134
raise NotImplementedError

python/swiftnav/cnav_msg.pxd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2016 Swift Navigation Inc.
2+
#
3+
# This source is subject to the license found in the file 'LICENSE' which must
4+
# be be distributed together with this source. All other rights reserved.
5+
#
6+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
7+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
8+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9+
10+
from common cimport *
11+
from libcpp cimport bool
12+
13+
cdef extern from "libswiftnav/cnav_msg.h":
14+
15+
ctypedef struct cnav_msg_decoder_t:
16+
pass
17+
18+
ctypedef struct cnav_msg_t:
19+
u8 prn # SV PRN. 0..31
20+
u8 msg_id # Message id. 0..31
21+
u32 tow # GPS ToW in 6-second units. Multiply to 6 to get seconds.
22+
bool alert # CNAV message alert flag
23+
24+
void cnav_msg_decoder_init(cnav_msg_decoder_t *dec)
25+
bool cnav_msg_decoder_add_symbol(cnav_msg_decoder_t *dec,
26+
u8 symbol,
27+
cnav_msg_t *msg,
28+
u32 *delay)
29+
30+
cdef extern from "libl2cbitstream/l2cbitstream.h":
31+
bool get_l2c_message(u8 *au_message, u8 prn, u8 msg_id, u32 tow)
32+
33+
cdef class CNavMsgDecoder:
34+
cdef cnav_msg_decoder_t _thisptr
35+
cdef class CNavMsg:
36+
cdef cnav_msg_t _thisptr

python/swiftnav/cnav_msg.pyx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright (C) 2016 Swift Navigation Inc.
2+
#
3+
# This source is subject to the license found in the file 'LICENSE' which must
4+
# be be distributed together with this source. All other rights reserved.
5+
#
6+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
7+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
8+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9+
10+
from fmt_utils import fmt_repr
11+
from libc.string cimport memcpy, memset
12+
cimport numpy as np
13+
import numpy as np
14+
15+
cdef class CNavMsgDecoder:
16+
17+
def __init__(self, **kwargs):
18+
memset(&self._thisptr, 0, sizeof(cnav_msg_decoder_t))
19+
cnav_msg_decoder_init(&self._thisptr)
20+
21+
def __repr__(self):
22+
return fmt_repr(self)
23+
24+
def decode(self, u8 symbol, CNavMsg msg):
25+
cdef u32 delay = 0
26+
res = cnav_msg_decoder_add_symbol(&self._thisptr,
27+
symbol,
28+
&msg._thisptr,
29+
&delay)
30+
return res, delay
31+
32+
cdef class CNavMsg:
33+
def __init__(self, **kwargs):
34+
memset(&self._thisptr, 0, sizeof(cnav_msg_t))
35+
if 'prn' in kwargs:
36+
self._thisptr.prn = kwargs.pop('prn')
37+
if 'msg_id' in kwargs:
38+
self._thisptr.msg_id = kwargs.pop('msg_id')
39+
if 'tow' in kwargs:
40+
self._thisptr.tow = kwargs.pop('tow')
41+
if 'alert' in kwargs:
42+
self._thisptr.alert = kwargs.pop('alert')
43+
44+
def __getattr__(self, k):
45+
return self._thisptr.get(k)
46+
47+
def __repr__(self):
48+
return fmt_repr(self)
49+
50+
def to_dict(self):
51+
return self._thisptr
52+
53+
def from_dict(self, d):
54+
self._thisptr = d
55+
56+
def __reduce__(self):
57+
return (rebuild_CNavMsg, tuple([tuple(self.to_dict().items())]))
58+
59+
def getPrn(self):
60+
return self._thisptr.prn
61+
62+
def getTow(self):
63+
return self._thisptr.tow
64+
65+
def getMsgId(self):
66+
return self._thisptr.msg_id
67+
68+
def getAlert(self):
69+
return self._thisptr.alert
70+
71+
def rebuild_CNavMsg(reduced):
72+
"""
73+
Rebuild CNavMsg for unpickling.
74+
75+
Parameters
76+
----------
77+
reduced: tuple
78+
Tuple of dict of NavMsg cnav_msg_t struct fields
79+
80+
Returns
81+
-------
82+
out: :class:`CNavMsg` instance
83+
Rebuilt :class:`CNavMsg` instance
84+
"""
85+
nm = CNavMsg()
86+
nm.from_dict(dict(reduced))
87+
return nm
88+
89+
90+
cdef class CNavRawMsg:
91+
@staticmethod
92+
def generate(prn, msg_id, tow):
93+
cdef np.ndarray[np.uint8_t, ndim=1, mode="c"] tmp_ = np.ndarray(38, dtype=np.uint8)
94+
res = get_l2c_message(&tmp_[0], prn, msg_id, tow)
95+
return np.unpackbits(tmp_)[4:]

0 commit comments

Comments
 (0)