mirror of https://github.com/g4klx/MMDVM.git
Add the timer class functionality.
This commit is contained in:
parent
db6fde90e0
commit
a9a985182f
36
FM.cpp
36
FM.cpp
|
@ -39,15 +39,13 @@ m_hangTimer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
void CFM::samples(q15_t* samples, uint8_t length)
|
||||||
{
|
{
|
||||||
// De-emphasis
|
// De-emphasis
|
||||||
|
|
||||||
bool ctcss = m_goertzel.process(samples, length);
|
bool validSignal = m_goertzel.process(samples, length);
|
||||||
|
|
||||||
bool validSignal = ctcss && cos;
|
stateMachine(validSignal, length);
|
||||||
|
|
||||||
stateMachine(validSignal);
|
|
||||||
|
|
||||||
if (m_modemState != STATE_FM)
|
if (m_modemState != STATE_FM)
|
||||||
return;
|
return;
|
||||||
|
@ -88,15 +86,15 @@ void CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, u
|
||||||
m_callsignAtStart = callsignAtStart;
|
m_callsignAtStart = callsignAtStart;
|
||||||
m_callsignAtEnd = callsignAtEnd;
|
m_callsignAtEnd = callsignAtEnd;
|
||||||
|
|
||||||
m_holdoffTimer.setTimeout(holdoff);
|
m_holdoffTimer.setTimeout(holdoff, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level)
|
void CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level)
|
||||||
{
|
{
|
||||||
m_rfAck.setParams(rfAck, speed, frequency, level);
|
m_rfAck.setParams(rfAck, speed, frequency, level);
|
||||||
|
|
||||||
m_ackDelayTimer.setTimeout(delay);
|
m_ackDelayTimer.setTimeout(0U, delay);
|
||||||
m_ackMinTimer.setTimeout(minTime);
|
m_ackMinTimer.setTimeout(minTime, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime)
|
void CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime)
|
||||||
|
@ -105,20 +103,20 @@ void CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency
|
||||||
m_goertzel.setParams(ctcssFrequency, ctcssThreshold);
|
m_goertzel.setParams(ctcssFrequency, ctcssThreshold);
|
||||||
m_ctcss.setParams(ctcssFrequency, ctcssLevel);
|
m_ctcss.setParams(ctcssFrequency, ctcssLevel);
|
||||||
|
|
||||||
m_timeoutTimer.setTimeout(timeout);
|
m_timeoutTimer.setTimeout(timeout, 0U);
|
||||||
m_kerchunkTimer.setTimeout(kerchunkTime);
|
m_kerchunkTimer.setTimeout(kerchunkTime, 0U);
|
||||||
m_hangTimer.setTimeout(hangTime);
|
m_hangTimer.setTimeout(hangTime, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFM::stateMachine(bool validSignal)
|
void CFM::stateMachine(bool validSignal, uint8_t length)
|
||||||
{
|
{
|
||||||
m_callsignTimer.clock();
|
m_callsignTimer.clock(length);
|
||||||
m_timeoutTimer.clock();
|
m_timeoutTimer.clock(length);
|
||||||
m_holdoffTimer.clock();
|
m_holdoffTimer.clock(length);
|
||||||
m_kerchunkTimer.clock();
|
m_kerchunkTimer.clock(length);
|
||||||
m_ackMinTimer.clock();
|
m_ackMinTimer.clock(length);
|
||||||
m_ackDelayTimer.clock();
|
m_ackDelayTimer.clock(length);
|
||||||
m_hangTimer.clock();
|
m_hangTimer.clock(length);
|
||||||
|
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case FS_LISTENING:
|
case FS_LISTENING:
|
||||||
|
|
4
FM.h
4
FM.h
|
@ -41,7 +41,7 @@ class CFM {
|
||||||
public:
|
public:
|
||||||
CFM();
|
CFM();
|
||||||
|
|
||||||
void samples(bool cos, q15_t* samples, uint8_t length);
|
void samples(q15_t* samples, uint8_t length);
|
||||||
|
|
||||||
void process();
|
void process();
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ private:
|
||||||
CFMTimer m_ackDelayTimer;
|
CFMTimer m_ackDelayTimer;
|
||||||
CFMTimer m_hangTimer;
|
CFMTimer m_hangTimer;
|
||||||
|
|
||||||
void stateMachine(bool validSignal);
|
void stateMachine(bool validSignal, uint8_t length);
|
||||||
void listeningState(bool validSignal);
|
void listeningState(bool validSignal);
|
||||||
void kerchunkState(bool validSignal);
|
void kerchunkState(bool validSignal);
|
||||||
void relayingState(bool validSignal);
|
void relayingState(bool validSignal);
|
||||||
|
|
28
FMTimer.cpp
28
FMTimer.cpp
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2009,2010,2015,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,36 +21,50 @@
|
||||||
#include "FMTimer.h"
|
#include "FMTimer.h"
|
||||||
|
|
||||||
CFMTimer::CFMTimer() :
|
CFMTimer::CFMTimer() :
|
||||||
m_timeout(0U)
|
m_timeout(0U),
|
||||||
|
m_timer(0U)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMTimer::setTimeout(uint16_t timeout)
|
void CFMTimer::setTimeout(uint16_t secs, uint32_t msecs)
|
||||||
{
|
{
|
||||||
m_timeout = timeout;
|
m_timeout = (secs * 24000U) + (msecs * 24U);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t CFMTimer::getTimeout() const
|
uint32_t CFMTimer::getTimeout() const
|
||||||
{
|
{
|
||||||
return m_timeout;
|
return m_timeout / 24U;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMTimer::start()
|
void CFMTimer::start()
|
||||||
{
|
{
|
||||||
|
if (m_timeout > 0U)
|
||||||
|
m_timer = 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMTimer::stop()
|
void CFMTimer::stop()
|
||||||
{
|
{
|
||||||
|
m_timer = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMTimer::clock()
|
void CFMTimer::clock(uint8_t length)
|
||||||
{
|
{
|
||||||
|
if (m_timer > 0U && m_timeout > 0U)
|
||||||
|
m_timer += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMTimer::isRunning() const
|
bool CFMTimer::isRunning() const
|
||||||
{
|
{
|
||||||
|
return m_timer > 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMTimer::hasExpired() const
|
bool CFMTimer::hasExpired() const
|
||||||
{
|
{
|
||||||
|
if (m_timeout == 0U || m_timer == 0U)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (m_timer > m_timeout)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
11
FMTimer.h
11
FMTimer.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2009,2010,2015,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -25,22 +25,23 @@ class CFMTimer {
|
||||||
public:
|
public:
|
||||||
CFMTimer();
|
CFMTimer();
|
||||||
|
|
||||||
void setTimeout(uint16_t timeout);
|
void setTimeout(uint16_t secs, uint32_t msecs);
|
||||||
|
|
||||||
uint16_t getTimeout() const;
|
uint32_t getTimeout() const;
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
void clock();
|
void clock(uint8_t length);
|
||||||
|
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
bool hasExpired() const;
|
bool hasExpired() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_timeout;
|
uint32_t m_timeout;
|
||||||
|
uint32_t m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
6
IO.cpp
6
IO.cpp
|
@ -348,7 +348,6 @@ void CIO::process()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_fmEnable) {
|
if (m_fmEnable) {
|
||||||
bool cos = getCOSInt();
|
|
||||||
q15_t FMVals[RX_BLOCK_SIZE];
|
q15_t FMVals[RX_BLOCK_SIZE];
|
||||||
#if defined(USE_DCBLOCKER)
|
#if defined(USE_DCBLOCKER)
|
||||||
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
||||||
|
@ -361,7 +360,7 @@ void CIO::process()
|
||||||
FMVals[i] = q15_t(__SSAT((res1 >> 15), 16));
|
FMVals[i] = q15_t(__SSAT((res1 >> 15), 16));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fm.samples(cos, FMVals, RX_BLOCK_SIZE);
|
fm.samples(FMVals, RX_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
} else if (m_modemState == STATE_DSTAR) {
|
} else if (m_modemState == STATE_DSTAR) {
|
||||||
if (m_dstarEnable) {
|
if (m_dstarEnable) {
|
||||||
|
@ -422,7 +421,6 @@ void CIO::process()
|
||||||
nxdnRX.samples(NXDNVals, rssi, RX_BLOCK_SIZE);
|
nxdnRX.samples(NXDNVals, rssi, RX_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
} else if (m_modemState == STATE_FM) {
|
} else if (m_modemState == STATE_FM) {
|
||||||
bool cos = getCOSInt();
|
|
||||||
q15_t FMVals[RX_BLOCK_SIZE];
|
q15_t FMVals[RX_BLOCK_SIZE];
|
||||||
#if defined(USE_DCBLOCKER)
|
#if defined(USE_DCBLOCKER)
|
||||||
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
||||||
|
@ -435,7 +433,7 @@ void CIO::process()
|
||||||
FMVals[i] = q15_t(__SSAT((res1 >> 15), 16));
|
FMVals[i] = q15_t(__SSAT((res1 >> 15), 16));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fm.samples(cos, FMVals, RX_BLOCK_SIZE);
|
fm.samples(FMVals, RX_BLOCK_SIZE);
|
||||||
} else if (m_modemState == STATE_DSTARCAL) {
|
} else if (m_modemState == STATE_DSTARCAL) {
|
||||||
q15_t GMSKVals[RX_BLOCK_SIZE];
|
q15_t GMSKVals[RX_BLOCK_SIZE];
|
||||||
::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE);
|
::arm_fir_fast_q15(&m_gaussianFilter, samples, GMSKVals, RX_BLOCK_SIZE);
|
||||||
|
|
|
@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U;
|
||||||
#define HW_TYPE "MMDVM"
|
#define HW_TYPE "MMDVM"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DESCRIPTION "20200411 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)"
|
#define DESCRIPTION "20200415 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)"
|
||||||
|
|
||||||
#if defined(GITVERSION)
|
#if defined(GITVERSION)
|
||||||
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
||||||
|
@ -413,7 +413,7 @@ uint8_t CSerialPort::setFMParams2(const uint8_t* data, uint8_t length)
|
||||||
|
|
||||||
uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length)
|
uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length)
|
||||||
{
|
{
|
||||||
if (length < 8U)
|
if (length < 7U)
|
||||||
return 4U;
|
return 4U;
|
||||||
|
|
||||||
uint16_t timeout = data[0U] * 5U;
|
uint16_t timeout = data[0U] * 5U;
|
||||||
|
@ -426,12 +426,6 @@ uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint8_t length)
|
||||||
uint8_t kerchunkTime = data[5U];
|
uint8_t kerchunkTime = data[5U];
|
||||||
uint8_t hangTime = data[6U];
|
uint8_t hangTime = data[6U];
|
||||||
|
|
||||||
char ack[50U];
|
|
||||||
uint8_t n = 0U;
|
|
||||||
for (uint8_t i = 7U; i < length; i++, n++)
|
|
||||||
ack[n] = data[i];
|
|
||||||
ack[n] = '\0';
|
|
||||||
|
|
||||||
fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssThreshold, ctcssLevel, kerchunkTime, hangTime);
|
fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssThreshold, ctcssLevel, kerchunkTime, hangTime);
|
||||||
|
|
||||||
return 0U;
|
return 0U;
|
||||||
|
|
Loading…
Reference in New Issue