Skip to content

Commit

Permalink
send tune tone
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ2LS committed Sep 30, 2024
1 parent e81da9e commit 6ccd680
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
31 changes: 29 additions & 2 deletions freedata_gui/src/components/main_modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getStationInfoByCallsign, setStationInfoByCallsign } from "../js/stationHandler.js";
import { settingsStore } from "../store/settingsStore.js";
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
import { sendModemTestFrame } from "../js/api";
import { sendModemTestFrame, sendSineTone } from "../js/api";
import { newMessage, deleteCallsignFromDB } from "../js/messagesHandler.js";
import main_startup_check from "./main_startup_check.vue";
Expand Down Expand Up @@ -579,7 +579,7 @@ const beaconHistogramData = computed(() => ({
@click="sendModemTestFrame()"
class="btn btn-danger"
>
Transmit
Transmit ( 5s )
</button>
</div>
<div class="input-group input-group-sm mb-1">
Expand Down Expand Up @@ -616,6 +616,33 @@ const beaconHistogramData = computed(() => ({
v-model.number="settings.remote.AUDIO.tx_audio_level"
/></span>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text">Transmit sine</span>
<button
type="button"
id="sendTestFrame"
@click="sendSineTone(true)"
class="btn btn-success"
>
Transmit ( max 30s )
</button>
<button
type="button"
id="sendTestFrame"
@click="sendSineTone(false)"
class="btn btn-danger"
>
Stop
</button>
</div>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions freedata_gui/src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export async function sendModemTestFrame() {
return await apiPost("/modem/send_test_frame");
}

export async function sendSineTone(state) {
return await apiPost("/radio/tune", {enable_tuning: state});
}

export async function startModem() {
return await apiPost("/modem/start");
}
Expand Down
30 changes: 30 additions & 0 deletions freedata_server/modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,37 @@ class Object:

return True

def transmit_sine(self):
""" Transmit a sine wave for audio tuning"""
self.states.setTransmitting(True)
self.log.info(
"[MDM] TRANSMIT", mode="SINE"
)
start_of_transmission = time.time()

f0 = 1500
fs = 48000
max_duration = 30
signal = np.array([], dtype=np.int16)
t = np.linspace(0, max_duration, int(fs * max_duration), endpoint=False)
s = 0.5 * np.sin(2 * np.pi * f0 * t)
txbuffer_out = np.concatenate((signal, np.int16(s * 32767)))

# transmit audio
self.enqueue_audio_out(txbuffer_out)

end_of_transmission = time.time()
transmission_time = end_of_transmission - start_of_transmission
self.states.setTransmitting(False)

self.log.debug("[MDM] ON AIR TIME", time=transmission_time)

def stop_sine(self):
""" Stop transmitting sine wave"""
# clear audio out queue
self.audio_out_queue.queue.clear()
self.states.setTransmitting(False)
self.log.debug("[MDM] Stopped transmitting sine")

def transmit_morse(self, repeats, repeat_delay, frames):
self.states.waitForTransmission()
Expand Down
18 changes: 18 additions & 0 deletions freedata_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import command_ping
import command_feq
import command_test
import command_transmit_sine
import command_arq_raw
import command_message_send
import event_manager
Expand Down Expand Up @@ -337,6 +338,23 @@ async def post_radio(request: Request):
radio_manager.set_tuner(data['radio_tuner'])
return api_response(data)

@app.post("/radio/tune")
async def post_radio(request: Request):
data = await request.json()
print(data)
if "enable_tuning" in data:
if data['enable_tuning']:
if not app.state_manager.is_modem_running:
api_abort("Modem not running", 503)
await enqueue_tx_command(command_transmit_sine.TransmitSine)
else:
app.service_manager.modem.stop_sine()
else:
app.service_manager.modem.stop_sine()


return api_response(data)

@app.get("/freedata/messages")
async def get_freedata_messages(request: Request):
filters = {k: v for k, v in request.query_params.items() if v}
Expand Down

0 comments on commit 6ccd680

Please sign in to comment.