diff --git a/README.md b/README.md index 714adc6..64e54b9 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,17 @@ This repository contains a Python script that converts logs from Google's GNSS measurement tools to RINEX. It was originally forked from https://github.com/rokubun/android_rinex but has been substantially modified. -See gnslogger_to_rnx.py for sample usage and a list of command line options +See gnslogger_to_rnx.py for sample usage and a list of command line options. + +`rtklibexplorer`'s fork has been modified in `plutonheaven`'s fork to use the code as a package in another project. + +To do so, add the following line to your projects `pyproject.toml`: +``` +dependencies = [ + ... + "android_rinex==0.1.0", +] + +[tool.uv.sources] +android_rinex = { git = "https://github.com/plutonheaven/android_rinex", branch = "master" } +``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..877cf95 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[project] +name = "android_rinex" +version = "0.1.0" +requires-python = ">=3.8" + +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.packages.find] +where = ["src"] diff --git a/src/android_rinex/__init__.py b/src/android_rinex/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/gnsslogger.py b/src/android_rinex/gnsslogger.py similarity index 99% rename from src/gnsslogger.py rename to src/android_rinex/gnsslogger.py index e9160df..6060b37 100644 --- a/src/gnsslogger.py +++ b/src/android_rinex/gnsslogger.py @@ -463,8 +463,9 @@ def get_glo_freq_chn_list(batches): if sat not in freq_chn_list: freq = get_frequency(measurement) - freq_chn = round((freq -FREQ1_GLO ) / DFREQ1_GLO) - freq_chn_list[sat] = freq_chn + if freq != 1575420000: + freq_chn = round((freq -FREQ1_GLO ) / DFREQ1_GLO) + freq_chn_list[sat] = freq_chn return freq_chn_list @@ -671,6 +672,9 @@ def process(measurement, model, fix_bias=True, timeadj=1e-7, pseudorange_bias=0. raise ValueError("-- WARNING: Invalid value of TimeNanos or satellite [ {0} ]\n".format(satname)) + if fullbiasnanos == "": + return None + # Compute the GPS week number and reception time (i.e. clock epoch) gpsweek = math.floor(-fullbiasnanos * NS_TO_S / GPS_WEEKSECS) local_est_GPS_time = timenanos - (fullbiasnanos + biasnanos) diff --git a/src/gnsslogger_to_rnx.py b/src/android_rinex/gnsslogger_to_rnx.py similarity index 93% rename from src/gnsslogger_to_rnx.py rename to src/android_rinex/gnsslogger_to_rnx.py index 9593ae6..0f84559 100644 --- a/src/gnsslogger_to_rnx.py +++ b/src/android_rinex/gnsslogger_to_rnx.py @@ -2,11 +2,19 @@ """ Tool to convert from logfile of GPS-measurements to RINEX format -Usage: gnsslogger_to_rnx logfile +Let us assume the following folder structure: +android_rinex/ +├── data/ +│ └── gnss_log.txt/ +└── src/ + └── android_rinex/ + ├── gnsslogger_to_rnx.py + +Usage from the root folder: +> python -m src.android_rinex.gnsslogger_to_rnx logfile Example using sample data file: - - gnsslogger_to_rnx ../data/gnss_log.txt + > python -m src.android_rinex.gnsslogger_to_rnx data/gnss_log.txt See main() below for a list of command line options """ @@ -14,8 +22,8 @@ import argparse import os, sys -import gnsslogger as alogger -import rinex3 as arinex +from . import gnsslogger as alogger +from . import rinex3 as arinex def convert2rnx(args): @@ -76,7 +84,7 @@ def convert2rnx(args): rec_version=args.receiver_version, antenna=args.antenna_number, ant_type=args.antenna_type, - pos=[0.0, 0.0, 0.0], + pos=args.pos, hen=[0.0, 0.0, 0.0], glo_slot_freq_chns=glo_freq_chns, glo_cod_phs_bis=glo_cod_phs_bis) @@ -93,7 +101,7 @@ def convert2rnx(args): fh.write(header + body) #print(args.output, outFile) -#sys.stderr.close() + sys.stderr.close() if __name__ == "__main__": diff --git a/src/rinex3.py b/src/android_rinex/rinex3.py similarity index 93% rename from src/rinex3.py rename to src/android_rinex/rinex3.py index b5b24ba..d10f02a 100644 --- a/src/rinex3.py +++ b/src/android_rinex/rinex3.py @@ -174,8 +174,8 @@ def __write_rnx3_header_firstobs__(epoch): TAIL = "TIME OF FIRST OBS" res = epoch.strftime(" %Y %m %d %H %M %S.") + \ - '{0:06d}0'.format(int(epoch.microsecond)) - + '{0:06d}'.format(int(epoch.microsecond)) + res += " GPS" res = "{0:60s}{1}\n".format(res, TAIL) return res @@ -191,8 +191,8 @@ def __write_rnx3_header_lastobs__(epoch): TAIL = "TIME OF LAST OBS" res = epoch.strftime(" %Y %m %d %H %M %S.") + \ - '{0:06d}0'.format(int(epoch.microsecond)) - + '{0:06d}'.format(int(epoch.microsecond)) + res += " GPS" res = "{0:60s}{1}\n".format(res, TAIL) return res @@ -214,21 +214,27 @@ def __write_rnx3_header_glo_slot_frq_chn__(glo_slot_freq_chns): # Gets the number of satellites in the list num_sats = len(glo_slot_freq_chns) - # Number of satellites in list + # list of lines + res_list = [] + + # First line begins with number of satellites in list res = "{0:3d} ".format(num_sats) - # Satellite numbers + frequency numbers + # Loop on satellite numbers + frequency numbers for sat in glo_slot_freq_chns: res += "{0:3s} {1:2d} ".format(sat, glo_slot_freq_chns[sat]) if len(res) == 60: - res += "{0:60s}{1}\n".format(res, TAIL) - res += " " - - # Tail specs - res = "{0:60s}{1}\n".format(res, TAIL) - - return res + # add tail and add current line to list + res_list.append("{0:60s}{1}\n".format(res, TAIL)) + # start a new line + res = " " + + # Add current line to list if not empty + if res != " ": + res_list.append("{0:60s}{1}\n".format(res, TAIL)) + + return "".join(res_list) # -----------------------------------------------------------------------------