Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit a3c20aa

Browse files
Dmitry TatarinovRoman Gezikov
authored andcommitted
Add Iono and Tropo correction usage
1 parent c2143dd commit a3c20aa

File tree

6 files changed

+122
-1
lines changed

6 files changed

+122
-1
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ CSRC := $(STARTUPSRC) \
123123
$(SWIFTNAV_ROOT)/src/decode.o \
124124
$(SWIFTNAV_ROOT)/src/signal.o \
125125
$(SWIFTNAV_ROOT)/src/l2c_capb.o \
126+
$(SWIFTNAV_ROOT)/src/iono.o \
126127
$(SWIFTNAV_ROOT)/src/sid_set.o \
127128
main.c
128129

src/base_obs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "base_obs.h"
3636
#include "ephemeris.h"
3737
#include "signal.h"
38+
#include "iono.h"
3839

3940
extern bool disable_raim;
4041

@@ -146,6 +147,21 @@ static void update_obss(obss_t *new_obss)
146147
gnss_solution soln;
147148
dops_t dops;
148149

150+
/* check if we have fix, if yes, calculate iono and tropo correction */
151+
if(base_obss.has_pos) {
152+
double llh[3];
153+
wgsecef2llh(base_obss.pos_ecef, llh);
154+
log_debug("Base: IONO/TROPO correction");
155+
ionosphere_t i_params;
156+
ionosphere_t *p_i_params = &i_params;
157+
/* get iono parameters if available */
158+
if(!gps_iono_params_read(p_i_params)) {
159+
p_i_params = NULL;
160+
}
161+
calc_iono_tropo(base_obss.n, base_obss.nm, base_obss.pos_ecef, llh,
162+
p_i_params);
163+
}
164+
149165
/* Calculate a position solution. */
150166
/* disable_raim controlled by external setting (see solution.c). */
151167
s32 ret = calc_PVT(base_obss.n, base_obss.nm, disable_raim, &soln, &dops);

src/decode/decode_gps_l1ca.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "sbp_utils.h"
2424
#include "signal.h"
2525
#include "l2c_capb.h"
26+
#include "iono.h"
2627

2728
typedef struct {
2829
nav_msg_t nav_msg;
@@ -115,6 +116,12 @@ static void decoder_gps_l1ca_process(const decoder_channel_info_t *channel_info,
115116
gps_l2cm_l2c_cap_store(dd.gps_l2c_sv_capability);
116117
}
117118

119+
if (dd.iono_corr_upd_flag) {
120+
/* store new iono parameters */
121+
log_debug("Iono parameters received");
122+
gps_iono_params_store(&dd.iono);
123+
}
124+
118125
if(dd.ephemeris_upd_flag) {
119126
/* Decoded a new ephemeris. */
120127
ephemeris_new(&dd.ephemeris);

src/iono.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Dmitry Tatarinov <[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+
#include <assert.h>
14+
#include <string.h>
15+
#include <ch.h>
16+
17+
#include "iono.h"
18+
#include "signal.h"
19+
20+
MUTEX_DECL(iono_mutex);
21+
22+
static ionosphere_t iono_params;
23+
static bool iono_params_decoded_flag = false;
24+
25+
/** Stores ionospheric parameters
26+
* \param params pointer to ionospheric parameters to be stored
27+
*/
28+
void gps_iono_params_store(ionosphere_t *params)
29+
{
30+
assert(params != NULL);
31+
chMtxLock(&iono_mutex);
32+
memcpy(&iono_params, params, sizeof(ionosphere_t));
33+
iono_params_decoded_flag = true;
34+
chMtxUnlock(&iono_mutex);
35+
}
36+
37+
/** Reads ionospheric parameters
38+
* \param params pointer to ionospheric
39+
* \return 1 if iono parameters available otherwise 0
40+
*/
41+
u8 gps_iono_params_read(ionosphere_t *params)
42+
{
43+
assert(params != NULL);
44+
chMtxLock(&iono_mutex);
45+
if (iono_params_decoded_flag) {
46+
memcpy(params, &iono_params, sizeof(ionosphere_t));
47+
chMtxUnlock(&iono_mutex);
48+
return 1;
49+
} else {
50+
chMtxUnlock(&iono_mutex);
51+
return 0;
52+
}
53+
}

src/iono.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2016 Swift Navigation Inc.
3+
* Contact: Dmitry Tatarinov <[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+
#ifndef SRC_IONO_H_
14+
#define SRC_IONO_H_
15+
16+
#include <libswiftnav/common.h>
17+
#include <libswiftnav/ionosphere.h>
18+
19+
void gps_iono_params_store(ionosphere_t *params);
20+
u8 gps_iono_params_read(ionosphere_t *params);
21+
22+
#endif /* SRC_IONO_H_ */

src/solution.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
1010
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
1111
*/
12-
1312
#include <stdio.h>
1413
#include <string.h>
1514

@@ -23,6 +22,7 @@
2322
#include <libswiftnav/dgnss_management.h>
2423
#include <libswiftnav/baseline.h>
2524
#include <libswiftnav/linear_algebra.h>
25+
#include <libswiftnav/troposphere.h>
2626

2727
#define memory_pool_t MemoryPool
2828
#include <ch.h>
@@ -43,6 +43,7 @@
4343
#include "signal.h"
4444
#include "system_monitor.h"
4545
#include "main.h"
46+
#include "iono.h"
4647
#include "sid_set.h"
4748

4849
/* Maximum CPU time the solution thread is allowed to use. */
@@ -433,6 +434,9 @@ static void sol_thd_sleep(systime_t *deadline, systime_t interval)
433434
static THD_WORKING_AREA(wa_solution_thread, 8000);
434435
static void solution_thread(void *arg)
435436
{
437+
/* The flag is true when we have a fix */
438+
bool soln_flag = false;
439+
436440
(void)arg;
437441
chRegSetThreadName("solution");
438442

@@ -534,6 +538,20 @@ static void solution_thread(void *arg)
534538
continue;
535539
}
536540

541+
/* check if we have a solution, if yes calc iono and tropo correction */
542+
if (soln_flag) {
543+
ionosphere_t i_params;
544+
ionosphere_t *p_i_params = &i_params;
545+
/* get iono parameters if available */
546+
if(!gps_iono_params_read(p_i_params)) {
547+
p_i_params = NULL;
548+
}
549+
calc_iono_tropo(n_ready_tdcp, nav_meas_tdcp,
550+
position_solution.pos_ecef,
551+
position_solution.pos_llh,
552+
p_i_params);
553+
}
554+
537555
dops_t dops;
538556
/* Calculate the SPP position
539557
* disable_raim controlled by external setting. Defaults to false. */
@@ -548,11 +566,15 @@ static void solution_thread(void *arg)
548566
log_warn("PVT solver: %s (code %d)", pvt_err_msg[-pvt_ret-1], pvt_ret);
549567
);
550568

569+
soln_flag = false;
570+
551571
/* Send just the DOPs and exit the loop */
552572
solution_send_sbp(0, &dops, clock_jump);
553573
continue;
554574
}
555575

576+
soln_flag = true;
577+
556578
if (pvt_ret == 1)
557579
log_warn("calc_PVT: RAIM repair");
558580

0 commit comments

Comments
 (0)