Allow specifying NmeaSource on application startup
This adds another startup option '-s' to select the source and runs the source specific initialization routines. This patch moves source specific bits into a init_X_Y_source() function leaving the common bits in init_source()
This commit is contained in:
parent
58f3849108
commit
7701e998e1
|
@ -61,6 +61,12 @@ class SatelliteApp(Gtk.Application):
|
|||
'-c', '--console-output', dest='console_output',
|
||||
action='store_true', default=False,
|
||||
help='Output satellite data to console')
|
||||
parser.add_argument(
|
||||
'-s', '--source', dest='source',
|
||||
default='quectel',
|
||||
help='Select NMEA source. Options are '
|
||||
'\'quectel\' (default) for Quectel Modems or '
|
||||
'\'gnss-share\' when using gnss-share')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
|
||||
|
@ -176,7 +182,49 @@ class SatelliteApp(Gtk.Application):
|
|||
return True
|
||||
|
||||
def init_source(self):
|
||||
source_init = False
|
||||
|
||||
self.log_msg(f"Satellite version {__version__} started")
|
||||
|
||||
self.log_msg(f'Trying to initialize source "{self.args.source}"')
|
||||
|
||||
if self.args.source == 'quectel':
|
||||
source_init = self.init_quectel_source()
|
||||
elif self.args.source == 'gnss-share':
|
||||
source_init = self.init_gnss_share_source()
|
||||
|
||||
if not source_init:
|
||||
self.log_msg('No NmeaSource initialized')
|
||||
return False # Remove from idle_add
|
||||
|
||||
self.log_msg(
|
||||
f"Source is {self.source.manufacturer}, model {self.source.model}"
|
||||
+ f", revision {self.source.revision}"
|
||||
if self.source.revision else "")
|
||||
|
||||
if (self.source.model and self.source.model.startswith("QUECTEL")):
|
||||
constellations = quectel.get_constellations(self.source)
|
||||
if constellations is not None:
|
||||
self.log_msg("Supported constellations: "
|
||||
+ ", ".join(constellations))
|
||||
|
||||
xtradates = quectel.get_xtradata_dates(self.source, fix_week=False)
|
||||
if xtradates is not None:
|
||||
dt1, dt2 = xtradates
|
||||
self.log_msg("XTRA data is valid from %s to %s" % (
|
||||
dt1.isoformat(' ', 'minutes'),
|
||||
dt2.isoformat(' ', 'minutes')))
|
||||
self.log_msg("XTRA data is "
|
||||
+ ("VALID" if now < dt2 else "NOT valid"))
|
||||
|
||||
GLib.timeout_add(self.refresh_rate * 1000, self.timeout_cb, None)
|
||||
|
||||
return False # Remove from idle_add
|
||||
|
||||
def init_gnss_share_source(self):
|
||||
return False
|
||||
|
||||
def init_quectel_source(self):
|
||||
try:
|
||||
self.source = QuectelNmeaSource(
|
||||
self.location_update_cb,
|
||||
|
@ -205,29 +253,9 @@ class SatelliteApp(Gtk.Application):
|
|||
if fatal:
|
||||
self.quit()
|
||||
|
||||
self.log_msg(
|
||||
f"Source is {self.source.manufacturer}, model {self.source.model}"
|
||||
+ f", revision {self.source.revision}"
|
||||
if self.source.revision else "")
|
||||
return False
|
||||
|
||||
if (self.source.model and self.source.model.startswith("QUECTEL")):
|
||||
constellations = quectel.get_constellations(self.source)
|
||||
if constellations is not None:
|
||||
self.log_msg("Supported constellations: "
|
||||
+ ", ".join(constellations))
|
||||
|
||||
xtradates = quectel.get_xtradata_dates(self.source, fix_week=False)
|
||||
if xtradates is not None:
|
||||
dt1, dt2 = xtradates
|
||||
self.log_msg("XTRA data is valid from %s to %s" % (
|
||||
dt1.isoformat(' ', 'minutes'),
|
||||
dt2.isoformat(' ', 'minutes')))
|
||||
self.log_msg("XTRA data is "
|
||||
+ ("VALID" if now < dt2 else "NOT valid"))
|
||||
|
||||
GLib.timeout_add(self.refresh_rate * 1000, self.timeout_cb, None)
|
||||
|
||||
return False # Remove from idle_add
|
||||
return True
|
||||
|
||||
def quit_function(self):
|
||||
"""Called after main loop exits."""
|
||||
|
|
Loading…
Reference in a new issue