Skip to content

Commit

Permalink
update sample for QZNMA/OSNMA.
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokawa committed Jan 2, 2025
1 parent d695011 commit 934751c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 35 deletions.
8 changes: 5 additions & 3 deletions samples/test_osnma.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
v = v[v['type'] == 0] # E1 only
tow = np.unique(v['tow'])
ntow = len(tow)
nsat = np.zeros((ntow, 2), dtype=int)
nsat = np.zeros((ntow, 3), dtype=int)
vstatus = np.zeros(ntow, dtype=int)

# nep = 90
Expand All @@ -51,9 +51,10 @@
nma.load_nav(nav, prn, tow_)
if nma_b[0] != 0: # for connected satellite
nma.decode(nma_b, int(vn['wn']), tow_, prn)
nsat[i, 1] += 1

nsat[i, 0] = len(vi)
nsat[i, 1] = nma.nsat
nsat[i, 2] = nma.nsat # authenticated sat
vstatus[i] = nma.status


Expand All @@ -63,7 +64,8 @@

fig, ax = plt.subplots()
plt.plot(tow-tow[0], nsat[:, 0], label='tracked')
plt.plot(tow-tow[0], nsat[:, 1], label='authenticated')
plt.plot(tow-tow[0], nsat[:, 1], label='connected')
plt.plot(tow-tow[0], nsat[:, 2], label='authenticated')
plt.grid()
plt.legend()
plt.xlim([0, tmax])
Expand Down
86 changes: 54 additions & 32 deletions samples/test_qznma.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@

from binascii import unhexlify
import numpy as np
from cssrlib.qznma import qznma
from cssrlib.gnss import prn2sat, uGNSS
from cssrlib.qznma import qznma, uNavId
import matplotlib.pyplot as plt

dtype = [('wn', 'int'), ('tow', 'float'), ('prn', 'int'),
('type', 'int'), ('len', 'int'), ('nav', 'S512')]
msg_nav_t = {uNavId.GPS_LNAV: 'LNAV', uNavId.GPS_CNAV: 'CNAV',
uNavId.GPS_CNAV2: 'CNAV2',
uNavId.GAL_FNAV: 'F/NAV', uNavId.GAL_INAV: 'I/NAV'}

# prn_ref = -1
prn_ref = 199
navmode = 4 # 1:LNAV, 2:CNAV, 3:CNAV2, 4:L6
navmode = uNavId.GPS_LNAV # 1:LNAV, 2:CNAV, 3:CNAV2
doy = 305
flg_gnss = True

qz = qznma(prn_ref=prn_ref)
qz = qznma()
qz.monlevel = 1

if navmode == 1:
if navmode == uNavId.GPS_LNAV:
navfile = '../data/doy2024-305/305a_qzslnav.txt'
elif navmode == 2:
elif navmode == uNavId.GPS_CNAV:
navfile = '../data/doy2024-305/305a_qzscnav.txt'
elif navmode == 3:
elif navmode == uNavId.GPS_CNAV2:
navfile = '../data/doy2024-305/305a_qzscnav2.txt'
elif navmode == 4:
navfile = '../data/doy2024-305/305a_qzsl6.txt'

v = np.genfromtxt(navfile, dtype=dtype)

if navmode == uNavId.GPS_CNAV:
v = v[v['type'] == 26] # L5 CNAV only

if flg_gnss:
navfile_n = '../data/doy2024-305/305a_qzsl6.txt'
navfile_gpslnav = '../data/doy2024-305/305a_gpslnav.txt'
navfile_gpscnav = '../data/doy2024-305/305a_gpscnav.txt'
# navfile_gpscnav2 = '../data/doy2024-305/305a_gpscnav2.txt'
Expand All @@ -36,42 +52,48 @@
qz.load_navmsg_inav(navfile_galinav)
qz.load_navmsg_fnav(navfile_galfnav)

dtype = [('wn', 'int'), ('tow', 'float'), ('prn', 'int'),
('type', 'int'), ('len', 'int'), ('nav', 'S512')]
v = np.genfromtxt(navfile, dtype=dtype)
vn = np.genfromtxt(navfile_n, dtype=dtype)

tow_ = np.unique(v['tow'])

# tow_ = np.unique(v['tow'])
tow_ = np.arange(v['tow'][0], v['tow'][-1])
nep = len(tow_)
# nep = 1200

nsat = np.zeros((nep, 2), dtype=int)
nsat = np.zeros((nep, 4), dtype=int)
vstatus = np.zeros(nep, dtype=int)

for k in range(nep):
if navmode != 4:
vi = v[(v['tow'] == tow_[k]) & (v['prn'] == prn_ref)]
else: # L6E
vi = v[(v['tow'] == tow_[k]) &
(v['prn'] == prn_ref) & (v['type'] == 1)]
if len(vi) == 0:
qz.flag_e = 0
continue
msg = unhexlify(vi['nav'][0])
prn = vi['prn'][0]
tow = vi['tow'][0]

qz.decode(tow, msg, navmode)

nsat[k, 0] = qz.count_tracked_sat(tow)
nsat[k, 1] = qz.nsat
vi_ = v[v['tow'] == tow_[k]]

for vi in vi_:
msg = unhexlify(vi['nav'])
sat = prn2sat(uGNSS.QZS, vi['prn'])
qz.decode(tow_[k], msg, None, sat, navmode)

if flg_gnss:
vin_ = vn[(vn['tow'] == tow_[k]) & (vn['type'] == 1)]
if prn_ref > 0:
vin_ = vin_[vin_['prn'] == prn_ref]

for vin in vin_:
msg_n = unhexlify(vin['nav'])
qz.decode(tow_[k], None, msg_n, sat, navmode)

nsat[k, 0] = qz.count_tracked_sat(tow_[k])
nsat[k, 1:] = np.array([qz.nsat[d] for d in qz.nsat])

if True:

tmax = 900
tmax = 500

fig, ax = plt.subplots()
plt.plot(tow_-tow_[0], nsat[:, 0], label='tracked')
plt.plot(tow_-tow_[0], nsat[:, 1], label='authenticated')
# plt.plot(tow_-tow_[0], nsat[:, 0], label='tracked')
plt.plot(tow_-tow_[0], nsat[:, 1], label='GPS ' +
msg_nav_t[qz.navmode[uGNSS.GPS]])
plt.plot(tow_-tow_[0], nsat[:, 2], label='GAL ' +
msg_nav_t[qz.navmode[uGNSS.GAL]])
plt.plot(tow_-tow_[0], nsat[:, 3], label='QZS '+msg_nav_t[navmode])
plt.grid()
plt.legend()
plt.xlim([0, tmax])
Expand Down

0 comments on commit 934751c

Please sign in to comment.