Skip to content

Commit

Permalink
add specific TLE strings for satellite
Browse files Browse the repository at this point in the history
  • Loading branch information
baskiton committed Jul 21, 2024
1 parent 1a2c05b commit 48626b0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Each satellite object contain:
| enabled | Boolean | _Optional._ Enable/Disable this frequency. `true` by default |
| min_elevation | Number | _Optional._ Elevation angle above the horizon, degrees. `0` by default. Negative number is equivalent to 0 |
| doppler | Boolean | _Optional._ Enable/Disable doppler correction. `true` by default |
| tle_strings | 2-String Array | _Optional._ Specific TLE strings. `null` by default |


#### frequencies
Expand Down
4 changes: 4 additions & 0 deletions sats_receiver/gr_modules/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ def frequencies(self) -> list[Mapping]:
def doppler(self) -> bool:
return self.config.get('doppler', True)

@property
def tle_strings(self) -> Optional[list[str, str]]:
return self.config.get('tle_strings')

@property
def start_event(self) -> utils.Event:
return self.events[0]
Expand Down
14 changes: 11 additions & 3 deletions sats_receiver/gr_modules/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import gnuradio.soapy

from sats_receiver.gr_modules import modules
from sats_receiver.utils import num_disp
from sats_receiver import utils


class RecUpdState(enum.IntEnum):
Expand Down Expand Up @@ -258,7 +258,8 @@ def is_active(self) -> bool:
def start(self, max_noutput_items=10000000):
if self.enabled and not self.is_runned:
self.log.info('START tune=%sHz samp_rate=%sHz gain=%s biast=%s',
num_disp(self.tune, 3), num_disp(self.samp_rate, 3), self.gain, self.biast)
utils.num_disp(self.tune, 3), utils.num_disp(self.samp_rate, 3),
self.gain, self.biast)

try:
self.signal_src = gr.soapy.source(f'driver={self.source}{self.serial and f",serial={self.serial}"}',
Expand Down Expand Up @@ -338,7 +339,14 @@ def calculate_pass(self, sat: modules.Satellite):
:return: True when calculate success
"""

x = self.up.tle.get_ephem(sat.name)
x = 0
s = sat.tle_strings
if s and len(s) >= 2:
x = utils.tle_generate(sat.name, s[0], s[1], 1, self.log)
x = x and x[0]
if not x:
x = self.up.tle.get_ephem(sat.name)

if x:
t = self.up.now
tt = t + dt.timedelta(hours=24)
Expand Down
32 changes: 4 additions & 28 deletions sats_receiver/tle.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import ephem

from sats_receiver import TLEDIR
from sats_receiver import TLEDIR, utils


class Tle:
Expand All @@ -33,16 +33,6 @@ def __init__(self, config: Mapping):

self.t_next = self.last_update_tle + dt.timedelta(days=self.update_period)

@staticmethod
def calc_checksum(full_line: str):
checksum = 0
for c in full_line[:-1]:
if c.isnumeric():
checksum += int(c)
elif c == '-':
checksum += 1
return str(checksum)[-1]

def fill_objects(self, tle_f: pathlib.Path, t: dt.datetime):
if tle_f is None:
if t >= self.t_err:
Expand Down Expand Up @@ -72,23 +62,9 @@ def fill_objects(self, tle_f: pathlib.Path, t: dt.datetime):
l1 = line.rstrip()
l2 = f.readline().rstrip()
for name in names:
for i in range(2):
try:
objects[name] = ephem.readtle(str(name), l1, l2), (str(name), l1, l2)
break
except ValueError as e:
if str(e).startswith('incorrect TLE checksum'):
cs1, cs2 = self.calc_checksum(l1), self.calc_checksum(l2)
self.log.warning('%s: for `%s` expect %s:%s, got %s:%s%s',
e, name,
cs1, cs2, l1[-1], l2[-1],
self.ignore_checksum and '. Ignore' or '')
if not self.ignore_checksum:
break
l1 = l1[:-1] + cs1
l2 = l2[:-1] + cs2
else:
raise e
x = utils.tle_generate(str(name), l1, l2, self.ignore_checksum, self.log)
if x:
objects[name] = x

self.objects = objects
shutil.move(tle_f, self.tle_file)
Expand Down
30 changes: 30 additions & 0 deletions sats_receiver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,33 @@ def img_add_exif(img: Image.Image,
_HPA_MMHG_CONST = 760 / 101325
def hpa_to_mmhg(hpa: float):
return _HPA_MMHG_CONST * hpa * 100


def tle_calc_checksum(full_line: str):
checksum = 0
for c in full_line[:-1]:
if c.isnumeric():
checksum += int(c)
elif c == '-':
checksum += 1
return str(checksum)[-1]


def tle_generate(name, l1, l2, ignore_checksum=0, log=None):
for i in range(2):
try:
return ephem.readtle(name, l1, l2), (name, l1, l2)
except ValueError as e:
if str(e).startswith('incorrect TLE checksum'):
cs1, cs2 = tle_calc_checksum(l1), tle_calc_checksum(l2)
if log:
log.warning('%s: for `%s` expect %s:%s, got %s:%s%s',
e, name,
cs1, cs2, l1[-1], l2[-1],
ignore_checksum and '. Ignore' or '')
if not ignore_checksum:
break
l1 = l1[:-1] + cs1
l2 = l2[:-1] + cs2
else:
raise e

0 comments on commit 48626b0

Please sign in to comment.