mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
adjusted morse module
This commit is contained in:
parent
b2a068dbfe
commit
4a47c3f58c
3 changed files with 26 additions and 37 deletions
42
modem/cw.py
42
modem/cw.py
|
@ -6,8 +6,10 @@ import numpy as np
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class MorseCodePlayer:
|
class MorseCodePlayer:
|
||||||
def __init__(self, wpm=150, f=1500, fs=48000):
|
def __init__(self, wpm=25, f=1500, fs=48000):
|
||||||
self.wpm = wpm
|
self.wpm = wpm
|
||||||
self.f0 = f
|
self.f0 = f
|
||||||
self.fs = fs
|
self.fs = fs
|
||||||
|
@ -39,28 +41,26 @@ class MorseCodePlayer:
|
||||||
signal = np.array([], dtype=np.int16)
|
signal = np.array([], dtype=np.int16)
|
||||||
for char in morse:
|
for char in morse:
|
||||||
if char == '.':
|
if char == '.':
|
||||||
duration = int(self.dot_duration * self.fs)
|
duration = self.dot_duration # Using class-defined duration
|
||||||
s = np.sin(2 * np.pi * self.f0 * np.arange(duration) / self.fs)
|
t = np.linspace(0, duration, int(self.fs * duration), endpoint=False)
|
||||||
signal = np.concatenate((signal, s * 32767))
|
s = 0.5 * np.sin(2 * np.pi * self.f0 * t)
|
||||||
pause_duration = int(self.pause_duration * self.fs)
|
signal = np.concatenate((signal, np.int16(s * 32767)))
|
||||||
signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16)))
|
pause_samples = int(self.pause_duration * self.fs)
|
||||||
|
signal = np.concatenate((signal, np.zeros(pause_samples, dtype=np.int16)))
|
||||||
|
|
||||||
elif char == '-':
|
elif char == '-':
|
||||||
duration = int(self.dash_duration * self.fs)
|
duration = self.dash_duration # Using class-defined duration
|
||||||
s = np.sin(2 * np.pi * self.f0 * np.arange(duration) / self.fs)
|
t = np.linspace(0, duration, int(self.fs * duration), endpoint=False)
|
||||||
signal = np.concatenate((signal, s * 32767))
|
s = 0.5 * np.sin(2 * np.pi * self.f0 * t)
|
||||||
pause_duration = int(self.pause_duration * self.fs)
|
signal = np.concatenate((signal, np.int16(s * 32767)))
|
||||||
signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16)))
|
pause_samples = int(self.pause_duration * self.fs)
|
||||||
|
signal = np.concatenate((signal, np.zeros(pause_samples, dtype=np.int16)))
|
||||||
|
|
||||||
elif char == ' ':
|
elif char == ' ':
|
||||||
pause_duration = int(self.word_pause_duration * self.fs)
|
pause_samples = int(self.word_pause_duration * self.fs)
|
||||||
signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16)))
|
signal = np.concatenate((signal, np.zeros(pause_samples, dtype=np.int16)))
|
||||||
pause_duration = int(self.pause_duration * self.fs)
|
pause_samples = int(self.pause_duration * self.fs)
|
||||||
signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16)))
|
signal = np.concatenate((signal, np.zeros(pause_samples, dtype=np.int16)))
|
||||||
|
|
||||||
pause_duration = int(self.word_pause_duration * self.fs)
|
|
||||||
#signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16)))
|
|
||||||
|
|
||||||
# Convert the signal to mono (single-channel)
|
|
||||||
#signal = signal.reshape(-1, 1)
|
|
||||||
|
|
||||||
return signal
|
return signal
|
||||||
|
|
||||||
|
|
|
@ -2856,9 +2856,7 @@ class DATA:
|
||||||
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
|
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value)
|
||||||
else:
|
else:
|
||||||
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)
|
self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0)
|
||||||
# FIXME Remove or change this in later versions for full CW support
|
#modem.MODEM_TRANSMIT_QUEUE.put(["morse", 1, 0, self.mycallsign])
|
||||||
# Modem.transmitting = True
|
|
||||||
# modem.MODEM_TRANSMIT_QUEUE.put(["morse", 1, 0, "123"])
|
|
||||||
|
|
||||||
def received_cq(self, data_in: bytes) -> None:
|
def received_cq(self, data_in: bytes) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -29,7 +29,7 @@ import structlog
|
||||||
import ujson as json
|
import ujson as json
|
||||||
import tci
|
import tci
|
||||||
# FIXME used for def transmit_morse
|
# FIXME used for def transmit_morse
|
||||||
# import cw
|
import cw
|
||||||
from queues import DATA_QUEUE_RECEIVED, MODEM_RECEIVED_QUEUE, MODEM_TRANSMIT_QUEUE, RIGCTLD_COMMAND_QUEUE, \
|
from queues import DATA_QUEUE_RECEIVED, MODEM_RECEIVED_QUEUE, MODEM_TRANSMIT_QUEUE, RIGCTLD_COMMAND_QUEUE, \
|
||||||
AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE
|
AUDIO_RECEIVED_QUEUE, AUDIO_TRANSMIT_QUEUE, MESH_RECEIVED_QUEUE
|
||||||
|
|
||||||
|
@ -745,18 +745,7 @@ class RF:
|
||||||
)
|
)
|
||||||
start_of_transmission = time.time()
|
start_of_transmission = time.time()
|
||||||
|
|
||||||
txbuffer = cw.MorseCodePlayer().text_to_signal("DJ2LS-1")
|
txbuffer_out = cw.MorseCodePlayer().text_to_signal("DJ2LS-1")
|
||||||
print(txbuffer)
|
|
||||||
print(type(txbuffer))
|
|
||||||
x = np.frombuffer(txbuffer, dtype=np.int16)
|
|
||||||
print(type(x))
|
|
||||||
txbuffer_out = x
|
|
||||||
print(txbuffer_out)
|
|
||||||
|
|
||||||
#if not HamlibParam.hamlib_radiocontrol in ["tci"]:
|
|
||||||
# txbuffer_out = self.resampler.resample8_to_48(x)
|
|
||||||
#else:
|
|
||||||
# txbuffer_out = x
|
|
||||||
|
|
||||||
self.mod_out_locked = True
|
self.mod_out_locked = True
|
||||||
self.enqueue_modulation(txbuffer_out)
|
self.enqueue_modulation(txbuffer_out)
|
||||||
|
@ -808,6 +797,8 @@ class RF:
|
||||||
self.log.debug("[MDM] ON AIR TIME", time=transmission_time)
|
self.log.debug("[MDM] ON AIR TIME", time=transmission_time)
|
||||||
|
|
||||||
def enqueue_modulation(self, txbuffer_out):
|
def enqueue_modulation(self, txbuffer_out):
|
||||||
|
|
||||||
|
|
||||||
chunk_length = self.AUDIO_FRAMES_PER_BUFFER_TX # 4800
|
chunk_length = self.AUDIO_FRAMES_PER_BUFFER_TX # 4800
|
||||||
chunk = [
|
chunk = [
|
||||||
txbuffer_out[i: i + chunk_length]
|
txbuffer_out[i: i + chunk_length]
|
||||||
|
|
Loading…
Reference in a new issue