From 4b0c3d88f3aee992dc567da28892b2b53798ce6e Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 15 Apr 2020 22:41:30 +0100 Subject: [PATCH] More work on the keyer. --- FM.cpp | 8 +++++++- FMKeyer.cpp | 29 +++++++++++++++++++++++++++-- FMKeyer.h | 8 +++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/FM.cpp b/FM.cpp index 41826e2..5f2e217 100644 --- a/FM.cpp +++ b/FM.cpp @@ -89,7 +89,13 @@ void CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, u m_callsignAtStart = callsignAtStart; m_callsignAtEnd = callsignAtEnd; - m_holdoffTimer.setTimeout(holdoff, 0U); + uint16_t holdoffTime = 0U; + uint16_t callsignTime = time * 60U; + if (holdoff > 0U) + holdoffTime = callsignTime / holdoff; + + m_holdoffTimer.setTimeout(holdoffTime, 0U); + m_callsignTimer.setTimeout(callsignTime, 0U); } void CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level) diff --git a/FMKeyer.cpp b/FMKeyer.cpp index 88f3fff..3c9ec1f 100644 --- a/FMKeyer.cpp +++ b/FMKeyer.cpp @@ -21,7 +21,7 @@ #include "FMKeyer.h" const struct { - uint8_t c; + char c; uint32_t pattern; uint8_t length; } SYMBOL_LIST[] = { @@ -78,17 +78,40 @@ const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02 CFMKeyer::CFMKeyer() : m_level(128 * 128), m_wanted(false), -m_running(false) +m_running(false), +m_poBuffer(), +m_poLen(0U) { } void CFMKeyer::setParams(const char* text, uint8_t speed, uint16_t frequency, uint8_t level) { m_level = q15_t(level * 128); + + for (uint8_t i = 0U; text[i] != '\0'; i++) { + for (uint8_t j = 0U; SYMBOL_LIST[j].c != 0U; j++) { + if (SYMBOL_LIST[j].c == text[i]) { + uint32_t MASK = 0x80000000U; + for (uint8_t k = 0U; k < SYMBOL_LIST[j].length; k++, m_poLen++, MASK >>= 1) { + bool b = (SYMBOL_LIST[j].pattern & MASK) == MASK; + WRITE_BIT(m_poBuffer, m_poLen, b); + + if (m_poLen >= 995U) { + m_poLen = 0U; + return; + } + } + + break; + } + } + } } void CFMKeyer::getAudio(q15_t* samples, uint8_t length) { + if (!m_wanted && !m_running) + return; } void CFMKeyer::start() @@ -98,6 +121,8 @@ void CFMKeyer::start() void CFMKeyer::stop() { + m_wanted = false; + m_running = false; } bool CFMKeyer::isRunning() const diff --git a/FMKeyer.h b/FMKeyer.h index e0b3ca8..e34e17f 100644 --- a/FMKeyer.h +++ b/FMKeyer.h @@ -35,9 +35,11 @@ public: bool isRunning() const; private: - q15_t m_level; - bool m_wanted; - bool m_running; + q15_t m_level; + bool m_wanted; + bool m_running; + uint8_t m_poBuffer[1000U]; + uint16_t m_poLen; }; #endif