Skip to content

Commit

Permalink
enums refac
Browse files Browse the repository at this point in the history
  • Loading branch information
baskiton committed Jul 23, 2024
1 parent 48626b0 commit 5819c9f
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 119 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,16 @@ Each frequency object contain:
* `NONE` do no write
* `WAV` default
* `WAV64`
* `OGG`
* `raw_out_subformat` WAV output subformat:
* `FLOAT` default
* `DOUBLE`
* `PCM_16`
* `PCM_24`
* `PCM_32`
* `PCM_U8`
* `VORBIS` codec, only for `OGG`
* `OPUS` codec, only for `OGG`
* `CSOFT` Constellation Soft Decoder - 1-channel binary int8. Suitable for further processing, for example, in SatDump. _Only for constellation-mode._
* `CCSDSCC` CCSDS Conv Concat Decoder - CADU data. Suitable for further processing, for example, in SatDump. _Only for constellation-mode._
* `APT` Sats-Receiver APT binary file format. See [APT](sats_receiver/systems/README.md#APT)
Expand Down
4 changes: 2 additions & 2 deletions example/send/my_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def action(self):
continue

decoder_type = x[0]
dty = decoder_type.value
dty = decoder_type.name

if decoder_type == utils.Decode.NONE:
continue
Expand All @@ -226,7 +226,7 @@ def action(self):
_, sat_name, observation_key, files, end_time = x
for ty, fp in files.items():
self.sender.push(decoder_type=dty,
file_type=ty.value,
file_type=ty.name,
sat_name=sat_name,
observation_key=observation_key,
filename=str(fp),
Expand Down
6 changes: 3 additions & 3 deletions example/send/recv_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def action(self):
elif dtype == Decode.RAW:
self.log.info('Draw Waterfall')
try:
ftype = RawFileType(params['file_type'])
ftype = RawFileType[params['file_type']]
if ftype == RawFileType.IQ:
wf = Waterfall.from_wav(fp, end_timestamp=dt.datetime.fromisoformat(params['end_time']).timestamp())
elif ftype == RawFileType.WFC:
Expand All @@ -172,7 +172,7 @@ def action(self):
self.log.warning('Unknown filetype: %s', ftype)
wf = 0
if wf:
wf.plot(fp.with_stem(f'{fp.stem}_{ftype.value}_wf').with_suffix('.png'))
wf.plot(fp.with_stem(f'{fp.stem}_{ftype.name}_wf').with_suffix('.png'))
except:
self.log.exception('waterfall')

Expand Down Expand Up @@ -269,7 +269,7 @@ def _handle(self):
out_dir.mkdir(parents=True, exist_ok=True)

try:
dtype = Decode(params['decoder_type'])
dtype = Decode[params['decoder_type']]
except ValueError:
self.log.warning('%s -> Invalid dtype. Skip', self.client_address)
return
Expand Down
28 changes: 15 additions & 13 deletions sats_receiver/gr_modules/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ def __init__(self,
super(RawDecoder, self).__init__(recorder, samp_rate, 'Raw Decoder', utils.Decode.RAW)

out_fmt = recorder.raw_out_format
out_subfmt = recorder.raw_out_subformat
self.base_kw['wf_cfg'] = recorder.iq_waterfall
self.base_kw['send_iq'] = not force_nosend_iq and out_fmt != utils.RawOutFormat.NONE
if out_fmt == utils.RawOutFormat.NONE:
out_fmt = utils.RawOutFormat.WAV
out_subfmt = utils.RawOutDefaultSub.WAV

self.ctf = gr.blocks.complex_to_float(1)
self.wav_sink = gr.blocks.wavfile_sink(
str(self.tmp_file),
2,
samp_rate,
out_fmt.value,
recorder.raw_out_subformat.value,
out_subfmt.value,
False
)
self.wav_sink.close()
Expand Down Expand Up @@ -321,14 +323,14 @@ def _apt_finalize(log: logging.Logger,

class ConstelSoftDecoder(Decoder):
CONSTELLS = {
'16QAM': gr.digital.constellation_16qam,
'8PSK': gr.digital.constellation_8psk,
'8PSK_NATURAL': gr.digital.constellation_8psk_natural,
'BPSK': gr.digital.constellation_bpsk,
'DQPSK': gr.digital.constellation_dqpsk,
'PSK': gr.digital.constellation_psk,
'QPSK': gr.digital.constellation_qpsk,
'OQPSK': gr.digital.constellation_qpsk,
# '16QAM': gr.digital.constellation_16qam,
# '8PSK': gr.digital.constellation_8psk,
# '8PSK_NATURAL': gr.digital.constellation_8psk_natural,
# 'BPSK': gr.digital.constellation_bpsk,
# 'DQPSK': gr.digital.constellation_dqpsk,
# 'PSK': gr.digital.constellation_psk,
utils.Mode.QPSK: gr.digital.constellation_qpsk,
utils.Mode.OQPSK: gr.digital.constellation_qpsk,
}

def __init__(self,
Expand All @@ -340,7 +342,7 @@ def __init__(self,
self.base_kw['suff'] = 's'

self.constell_mode = recorder.mode
self.constellation = self.CONSTELLS[self.constell_mode.value]().base()
self.constellation = self.CONSTELLS[self.constell_mode]().base()
self.constellation.gen_soft_dec_lut(8)
self.constel_soft_decoder = gr.digital.constellation_soft_decoder_cf(self.constellation)
self.rail = gr.analog.rail_ff(-1, 1)
Expand Down Expand Up @@ -402,7 +404,7 @@ def __init__(self,
super().__init__(recorder, samp_rate, 'CCSDS Conv Concat Decoder', utils.Decode.CCSDSCC)
self.base_kw['suff'] = 'cadu'

is_qpsk = self.constell_mode.value.endswith('QPSK')
is_qpsk = self.constell_mode.name.endswith('QPSK')
frame_size = recorder.ccc_frame_size or 892
pre_deint = recorder.ccc_pre_deint
diff = recorder.ccc_diff and 'differential' or None
Expand Down Expand Up @@ -723,7 +725,7 @@ def __init__(self,
channles: List[Union[int, float]]):

self.deftype = recorder.proto_deframer
name = self.deftype.value + ' Decoder'
name = self.deftype.name + ' Decoder'

chn = len(channles)
super(ProtoDecoder, self).__init__(
Expand Down Expand Up @@ -777,7 +779,7 @@ def _proto_finalize(log: logging.Logger,

st = tmp_file.stat()
d = dt.datetime.fromtimestamp(st.st_mtime, dateutil.tz.tzutc())
res_fn = tmp_file.rename(out_dir / d.strftime(f'{sat_name}_%Y-%m-%d_%H-%M-%S,%f_{deftype.value}{subname}.kss'))
res_fn = tmp_file.rename(out_dir / d.strftime(f'{sat_name}_%Y-%m-%d_%H-%M-%S,%f_{deftype.name}{subname}.kss'))
log.info('finish: %s (%s)', res_fn, utils.numbi_disp(st.st_size))
if not st.st_size:
res_fn.unlink(True)
Expand Down
28 changes: 12 additions & 16 deletions sats_receiver/gr_modules/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def _validate_config(config: Mapping) -> bool:
# 'raw_out_format', # optional, only for RAW decode
# 'raw_out_subformat',# optional, only for RAW decode
]))
and (utils.Mode(config['mode']) != utils.Mode.QPSK or 'qpsk_baudrate' in config)
and (utils.Mode[config['mode']] != utils.Mode.QPSK or 'qpsk_baudrate' in config)
and (
utils.Decode(config.get('decode')) != utils.Decode.PROTO
utils.Decode[config.get('decode')] != utils.Decode.PROTO
or (
utils.Mode(config['mode']) in (utils.Mode.FSK, utils.Mode.GFSK, utils.Mode.GMSK)
utils.Mode[config['mode']] in (utils.Mode.FSK, utils.Mode.GFSK, utils.Mode.GMSK)
and 'proto_deframer' in config
# and 'proto_options' in config
)
Expand Down Expand Up @@ -302,11 +302,11 @@ def demode_out_sr(self) -> Union[int, float]:

@property
def mode(self) -> utils.Mode:
return utils.Mode(self.config.get('mode', utils.Mode.RAW.value))
return utils.Mode[self.config.get('mode', utils.Mode.RAW.name)]

@property
def decode(self) -> utils.Decode:
return utils.Decode(self.config.get('decode', utils.Decode.RAW.value))
return utils.Decode[self.config.get('decode', utils.Decode.RAW.name)]

@property
def qpsk_baudrate(self) -> Union[int, float]:
Expand Down Expand Up @@ -346,7 +346,7 @@ def deviation_factor(self) -> Union[int, float]:

@property
def proto_deframer(self) -> utils.ProtoDeframer:
return utils.ProtoDeframer(self.config['proto_deframer'])
return utils.ProtoDeframer[self.config['proto_deframer']]

@property
def proto_options(self) -> Mapping:
Expand Down Expand Up @@ -402,17 +402,13 @@ def quad_gain(self) -> float:

@property
def raw_out_format(self) -> utils.RawOutFormat:
d = {
None: utils.RawOutFormat.WAV,
'NONE': utils.RawOutFormat.NONE,
'WAV': utils.RawOutFormat.WAV,
'WAV64': utils.RawOutFormat.WAV64,
}
return d[self.config.get('raw_out_format')]
f = self.config.get('raw_out_format', utils.RawOutFormat.WAV.name)
return utils.RawOutFormat[f]

@property
def raw_out_subformat(self) -> utils.RawOutSubFormat:
return utils.RawOutSubFormat(self.config.get('raw_out_subformat', utils.RawOutSubFormat.FLOAT.value))
return utils.RawOutSubFormat[self.config.get('raw_out_subformat',
utils.RawOutDefaultSub[self.raw_out_format.name].value.name)]

@property
def iq_waterfall(self) -> Mapping:
Expand Down Expand Up @@ -482,8 +478,8 @@ def start(self):
observation_key = sha256((self.name + str(dt.datetime.now())).encode()).hexdigest()
self.log.info('START doppler=%s mode=%s decode=%s key=%s',
self.doppler,
[r.mode.value for r in self.recorders],
[r.decode.value for r in self.recorders],
[r.mode.name for r in self.recorders],
[r.decode.name for r in self.recorders],
observation_key)
self.output_directory.mkdir(parents=True, exist_ok=True)
self.start_event = None
Expand Down
Loading

0 comments on commit 5819c9f

Please sign in to comment.