2021-08-04 02:32:40 +00:00
|
|
|
// Copyright 2015-2021 Mobilinkd LLC <rob@mobilinkd.com>
|
2018-07-30 02:34:53 +00:00
|
|
|
// All rights reserved.
|
|
|
|
|
|
|
|
#include "ModulatorTask.hpp"
|
2021-01-03 03:59:59 +00:00
|
|
|
#include "HDLCEncoder.hpp"
|
|
|
|
#include "Modulator.hpp"
|
|
|
|
#include "M17Modulator.h"
|
|
|
|
#include "M17Encoder.h"
|
|
|
|
#include "Fsk9600Modulator.hpp"
|
|
|
|
#include "AFSKModulator.hpp"
|
2018-07-30 02:34:53 +00:00
|
|
|
#include "KissHardware.hpp"
|
2021-01-03 03:59:59 +00:00
|
|
|
#include "main.h"
|
2021-08-04 02:32:40 +00:00
|
|
|
#include "Log.h"
|
2018-07-30 02:34:53 +00:00
|
|
|
|
|
|
|
mobilinkd::tnc::SimplexPTT simplexPtt;
|
|
|
|
mobilinkd::tnc::MultiplexPTT multiplexPtt;
|
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
mobilinkd::tnc::Modulator* modulator;
|
|
|
|
mobilinkd::Encoder* encoder;
|
2018-07-30 02:34:53 +00:00
|
|
|
|
|
|
|
// DMA Conversion half complete.
|
|
|
|
extern "C" void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef*) {
|
|
|
|
osEvent evt = osMessageGet(dacOutputQueueHandle, 0);
|
|
|
|
if (evt.status == osEventMessage) {
|
|
|
|
modulator->fill_first(evt.value.v);
|
|
|
|
} else {
|
2021-01-03 03:59:59 +00:00
|
|
|
modulator->empty_first();
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef*) {
|
|
|
|
osEvent evt = osMessageGet(dacOutputQueueHandle, 0);
|
|
|
|
if (evt.status == osEventMessage) {
|
|
|
|
modulator->fill_last(evt.value.v);
|
|
|
|
} else {
|
2021-01-03 03:59:59 +00:00
|
|
|
modulator->empty_last();
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef*) {
|
|
|
|
modulator->abort();
|
|
|
|
}
|
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
mobilinkd::tnc::Modulator& getModulator()
|
|
|
|
{
|
|
|
|
using namespace mobilinkd::tnc;
|
|
|
|
|
|
|
|
static AFSKModulator afsk1200modulator(dacOutputQueueHandle, &simplexPtt);
|
|
|
|
static Fsk9600Modulator fsk9600modulator(dacOutputQueueHandle, &simplexPtt);
|
|
|
|
static M17Modulator m17modulator(dacOutputQueueHandle, &simplexPtt);
|
|
|
|
|
|
|
|
switch (kiss::settings().modem_type)
|
|
|
|
{
|
|
|
|
case kiss::Hardware::ModemType::FSK9600:
|
|
|
|
return fsk9600modulator;
|
|
|
|
case kiss::Hardware::ModemType::AFSK1200:
|
|
|
|
return afsk1200modulator;
|
|
|
|
case kiss::Hardware::ModemType::M17:
|
|
|
|
return m17modulator;
|
|
|
|
default:
|
|
|
|
CxxErrorHandler();
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
mobilinkd::Encoder& getEncoder()
|
|
|
|
{
|
|
|
|
using namespace mobilinkd::tnc;
|
|
|
|
|
|
|
|
static hdlc::Encoder hdlcEncoder(hdlcOutputQueueHandle);
|
|
|
|
static mobilinkd::M17Encoder m17Encoder(hdlcOutputQueueHandle);
|
|
|
|
|
|
|
|
switch (kiss::settings().modem_type)
|
|
|
|
{
|
|
|
|
case kiss::Hardware::ModemType::FSK9600:
|
|
|
|
return hdlcEncoder;
|
|
|
|
case kiss::Hardware::ModemType::AFSK1200:
|
|
|
|
return hdlcEncoder;
|
|
|
|
case kiss::Hardware::ModemType::M17:
|
|
|
|
return m17Encoder;
|
|
|
|
default:
|
2021-08-04 02:32:40 +00:00
|
|
|
ERROR("Invalid modem type %d", int(kiss::settings().modem_type));
|
2021-01-03 03:59:59 +00:00
|
|
|
CxxErrorHandler();
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setPtt(PTT ptt)
|
|
|
|
{
|
|
|
|
switch (ptt) {
|
|
|
|
case PTT::SIMPLEX:
|
|
|
|
getModulator().set_ptt(&simplexPtt);
|
|
|
|
break;
|
|
|
|
case PTT::MULTIPLEX:
|
|
|
|
getModulator().set_ptt(&multiplexPtt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updatePtt()
|
|
|
|
{
|
|
|
|
using namespace mobilinkd::tnc::kiss;
|
|
|
|
|
|
|
|
if (settings().options & KISS_OPTION_PTT_SIMPLEX)
|
2021-01-03 03:59:59 +00:00
|
|
|
getModulator().set_ptt(&simplexPtt);
|
2018-07-30 02:34:53 +00:00
|
|
|
else
|
2021-01-03 03:59:59 +00:00
|
|
|
getModulator().set_ptt(&multiplexPtt);
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
void updateModulator()
|
|
|
|
{
|
|
|
|
using namespace mobilinkd::tnc::kiss;
|
|
|
|
|
|
|
|
modulator = &getModulator();
|
|
|
|
encoder = &getEncoder();
|
|
|
|
modulator->init(settings());
|
|
|
|
updatePtt();
|
|
|
|
encoder->updateModulator();
|
|
|
|
encoder->update_settings();
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
void startModulatorTask(void const*)
|
|
|
|
{
|
2018-07-30 02:34:53 +00:00
|
|
|
using namespace mobilinkd::tnc::kiss;
|
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
// Wait until hardware is initialized before creating modulator.
|
|
|
|
osMutexWait(hardwareInitMutexHandle, osWaitForever);
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
modulator = &(getModulator());
|
|
|
|
encoder = &(getEncoder());
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
updatePtt();
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
getModulator().init(settings());
|
2018-07-30 02:34:53 +00:00
|
|
|
|
2021-01-03 03:59:59 +00:00
|
|
|
encoder->update_settings();
|
|
|
|
encoder->run();
|
|
|
|
}
|
2018-07-30 02:34:53 +00:00
|
|
|
}
|