diff --git a/samples/test_osnma.py b/samples/test_osnma.py index 1c77aa3..43a3278 100644 --- a/samples/test_osnma.py +++ b/samples/test_osnma.py @@ -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 @@ -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 @@ -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]) diff --git a/samples/test_qznma.py b/samples/test_qznma.py index 2266be4..1ba96aa 100644 --- a/samples/test_qznma.py +++ b/samples/test_qznma.py @@ -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' @@ -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])