diff --git a/samples/test_osnma.py b/samples/test_osnma.py new file mode 100644 index 0000000..1c77aa3 --- /dev/null +++ b/samples/test_osnma.py @@ -0,0 +1,92 @@ +""" +test script for Galileo OSNMA + +@author Rui Hirokawa + +""" + +import numpy as np +import cssrlib.osnma as om +from binascii import unhexlify, hexlify +import matplotlib.pyplot as plt + +tofst = -2 # time offset to syncronize tow + +nma = om.osnma() + +nma.flg_slowmac = True + +file_galinav = '../data/doy2024-305/305a_galinav.txt' +doy = 305 + +dtype_ = [('tow', 'i8'), ('wn', 'i8'), ('prn', 'i8'), + ('mt', 'i8'), ('k', 'i8'), ('nma', 'S10'), + ('wt', 'i8'), ('nav', 'S32')] + +dtype_ = [('wn', 'int'), ('tow', 'float'), ('prn', 'int'), + ('type', 'int'), ('len', 'int'), ('nav', 'S512')] + +v = np.genfromtxt(file_galinav, dtype=dtype_) + +i = 0 + +v = v[v['type'] == 0] # E1 only +tow = np.unique(v['tow']) +ntow = len(tow) +nsat = np.zeros((ntow, 2), dtype=int) +vstatus = np.zeros(ntow, dtype=int) + +# nep = 90 +# nep = 180 +nep = 300 + +for i, t in enumerate(tow[0:nep]): + vi = v[v['tow'] == t] + for vn in vi: + tow_ = int(vn['tow'])+tofst + prn = int(vn['prn']) + nma.prn_a = prn + msg = unhexlify(vn['nav']) # I/NAV (120bit+120bit) + nav, nma_b = nma.load_inav(msg) + 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, 0] = len(vi) + nsat[i, 1] = nma.nsat + vstatus[i] = nma.status + + +if True: + + tmax = 240 + + fig, ax = plt.subplots() + plt.plot(tow-tow[0], nsat[:, 0], label='tracked') + plt.plot(tow-tow[0], nsat[:, 1], label='authenticated') + plt.grid() + plt.legend() + plt.xlim([0, tmax]) + ax.set_xticks(np.arange(0, 300, 30)) + plt.ylabel('number of satellites') + plt.xlabel('time [s]') + plt.savefig('osnma-{0:d}-nsat-{1:d}.png'.format(doy, tmax)) + plt.show() + + y = np.ones(ntow) + lbl_t = ['rootkey-loaded', 'rootkey-verified', 'keychain-verified', + 'utc-verified', 'auth-position'] + fig, ax = plt.subplots() + for k in range(5): + idx = np.where(vstatus & (1 << k)) + plt.plot(tow[idx]-tow[0], y[idx]*(k+1), '.', label=lbl_t[k]) + plt.grid() + ax.set_yticks(np.arange(0, 6)) + ax.set_xticks(np.arange(0, 300, 30)) + plt.legend() + plt.ylim([0, 6]) + plt.xlim([0, 240]) + plt.ylabel('status') + plt.xlabel('time [s]') + plt.savefig('osnma-{0:d}-status.png'.format(doy)) + plt.show() diff --git a/samples/test_qznma.py b/samples/test_qznma.py new file mode 100644 index 0000000..2266be4 --- /dev/null +++ b/samples/test_qznma.py @@ -0,0 +1,82 @@ +""" +sample for QZNMA + +@author Rui Hirokawa + +""" + +from binascii import unhexlify +import numpy as np +from cssrlib.qznma import qznma +import matplotlib.pyplot as plt + +prn_ref = 199 +navmode = 4 # 1:LNAV, 2:CNAV, 3:CNAV2, 4:L6 +doy = 305 + +qz = qznma(prn_ref=prn_ref) + +if navmode == 1: + navfile = '../data/doy2024-305/305a_qzslnav.txt' +elif navmode == 2: + navfile = '../data/doy2024-305/305a_qzscnav.txt' +elif navmode == 3: + navfile = '../data/doy2024-305/305a_qzscnav2.txt' +elif navmode == 4: + navfile = '../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' + navfile_galinav = '../data/doy2024-305/305a_galinav.txt' + navfile_galfnav = '../data/doy2024-305/305a_galfnav.txt' + + # load navigation message + qz.load_navmsg_lnav(navfile_gpslnav) + qz.load_navmsg_cnav(navfile_gpscnav) + 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) + +tow_ = np.unique(v['tow']) +nep = len(tow_) +# nep = 1200 + +nsat = np.zeros((nep, 2), 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 + +if True: + + tmax = 900 + + fig, ax = plt.subplots() + plt.plot(tow_-tow_[0], nsat[:, 0], label='tracked') + plt.plot(tow_-tow_[0], nsat[:, 1], label='authenticated') + plt.grid() + plt.legend() + plt.xlim([0, tmax]) + # ax.set_xticks(np.arange(0, 300, 30)) + plt.ylabel('number of satellites') + plt.xlabel('time [s]') + # plt.savefig('qznma-{0:d}-nsat-{1:d}.png'.format(doy, tmax)) + plt.show()