2020-04-11 23:08:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if !defined(FM_H)
|
|
|
|
|
#define FM_H
|
|
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
|
|
2020-04-25 23:32:10 +02:00
|
|
|
#include "FMBlanking.h"
|
2020-04-18 14:55:34 +02:00
|
|
|
#include "FMCTCSSRX.h"
|
2020-04-15 16:24:01 +02:00
|
|
|
#include "FMCTCSSTX.h"
|
|
|
|
|
#include "FMTimeout.h"
|
|
|
|
|
#include "FMKeyer.h"
|
|
|
|
|
#include "FMTimer.h"
|
2020-05-09 10:57:16 +02:00
|
|
|
#include "RingBuffer.h"
|
2020-04-24 09:10:50 +02:00
|
|
|
#include "FMDirectForm1.h"
|
2020-06-30 13:44:02 +02:00
|
|
|
#include "FMDownSampler.h"
|
2020-05-12 22:06:26 +02:00
|
|
|
#include "FMUpSampler.h"
|
2020-04-15 16:24:01 +02:00
|
|
|
|
|
|
|
|
enum FM_STATE {
|
|
|
|
|
FS_LISTENING,
|
2020-05-07 23:39:17 +02:00
|
|
|
FS_KERCHUNK_RF,
|
|
|
|
|
FS_RELAYING_RF,
|
|
|
|
|
FS_RELAYING_WAIT_RF,
|
|
|
|
|
FS_TIMEOUT_RF,
|
|
|
|
|
FS_TIMEOUT_WAIT_RF,
|
|
|
|
|
FS_KERCHUNK_EXT,
|
|
|
|
|
FS_RELAYING_EXT,
|
|
|
|
|
FS_RELAYING_WAIT_EXT,
|
|
|
|
|
FS_TIMEOUT_EXT,
|
|
|
|
|
FS_TIMEOUT_WAIT_EXT,
|
2020-04-15 16:24:01 +02:00
|
|
|
FS_HANG
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-23 21:16:52 +02:00
|
|
|
|
2020-04-11 23:08:17 +02:00
|
|
|
class CFM {
|
|
|
|
|
public:
|
|
|
|
|
CFM();
|
|
|
|
|
|
2020-05-11 22:32:24 +02:00
|
|
|
void samples(bool cos, q15_t* samples, uint8_t length);
|
2020-04-11 23:08:17 +02:00
|
|
|
|
|
|
|
|
void process();
|
|
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
2020-05-04 23:18:51 +02:00
|
|
|
uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch);
|
2020-04-16 15:00:31 +02:00
|
|
|
uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level);
|
2020-06-20 22:03:11 +02:00
|
|
|
uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, bool kerchunkTX, uint8_t hangTime, bool useCOS, bool cosInvert, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel);
|
2020-05-07 23:01:48 +02:00
|
|
|
uint8_t setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t frequency, uint8_t level);
|
2020-04-12 16:28:56 +02:00
|
|
|
|
2020-05-07 17:17:00 +02:00
|
|
|
uint8_t getSpace() const;
|
|
|
|
|
|
|
|
|
|
uint8_t writeData(const uint8_t* data, uint8_t length);
|
|
|
|
|
|
2020-04-11 23:08:17 +02:00
|
|
|
private:
|
2020-04-17 19:45:42 +02:00
|
|
|
CFMKeyer m_callsign;
|
|
|
|
|
CFMKeyer m_rfAck;
|
2020-05-07 23:01:48 +02:00
|
|
|
CFMKeyer m_extAck;
|
2020-04-18 14:55:34 +02:00
|
|
|
CFMCTCSSRX m_ctcssRX;
|
|
|
|
|
CFMCTCSSTX m_ctcssTX;
|
2020-04-17 19:45:42 +02:00
|
|
|
CFMTimeout m_timeoutTone;
|
|
|
|
|
FM_STATE m_state;
|
|
|
|
|
bool m_callsignAtStart;
|
|
|
|
|
bool m_callsignAtEnd;
|
2020-05-04 23:18:51 +02:00
|
|
|
bool m_callsignAtLatch;
|
2020-04-17 19:45:42 +02:00
|
|
|
CFMTimer m_callsignTimer;
|
|
|
|
|
CFMTimer m_timeoutTimer;
|
|
|
|
|
CFMTimer m_holdoffTimer;
|
|
|
|
|
CFMTimer m_kerchunkTimer;
|
2020-06-20 22:03:11 +02:00
|
|
|
bool m_kerchunkTX;
|
2020-04-17 19:45:42 +02:00
|
|
|
CFMTimer m_ackMinTimer;
|
|
|
|
|
CFMTimer m_ackDelayTimer;
|
|
|
|
|
CFMTimer m_hangTimer;
|
2020-05-11 14:15:13 +02:00
|
|
|
CFMTimer m_statusTimer;
|
2020-04-24 14:13:25 +02:00
|
|
|
CFMDirectFormI m_filterStage1;
|
|
|
|
|
CFMDirectFormI m_filterStage2;
|
|
|
|
|
CFMDirectFormI m_filterStage3;
|
2020-04-25 23:32:10 +02:00
|
|
|
CFMBlanking m_blanking;
|
2020-04-25 16:17:11 +02:00
|
|
|
bool m_useCOS;
|
2020-05-06 12:34:04 +02:00
|
|
|
bool m_cosInvert;
|
2020-04-28 15:43:40 +02:00
|
|
|
q15_t m_rfAudioBoost;
|
2020-05-07 23:01:48 +02:00
|
|
|
q15_t m_extAudioBoost;
|
2020-06-30 13:44:02 +02:00
|
|
|
CFMDownSampler m_downSampler;
|
2020-05-07 23:01:48 +02:00
|
|
|
bool m_extEnabled;
|
2020-05-08 09:01:00 +02:00
|
|
|
q15_t m_rxLevel;
|
2020-05-09 14:06:32 +02:00
|
|
|
CRingBuffer<q15_t> m_inputRFRB;
|
2020-05-09 10:57:16 +02:00
|
|
|
CRingBuffer<q15_t> m_outputRFRB;
|
2020-05-12 22:06:26 +02:00
|
|
|
CFMUpSampler m_inputExtRB;
|
2020-04-15 17:31:49 +02:00
|
|
|
|
2020-05-07 23:39:17 +02:00
|
|
|
void stateMachine(bool validRFSignal, bool validExtSignal);
|
|
|
|
|
void listeningState(bool validRFSignal, bool validExtSignal);
|
|
|
|
|
void kerchunkRFState(bool validSignal);
|
|
|
|
|
void relayingRFState(bool validSignal);
|
|
|
|
|
void relayingRFWaitState(bool validSignal);
|
|
|
|
|
void timeoutRFState(bool validSignal);
|
|
|
|
|
void timeoutRFWaitState(bool validSignal);
|
|
|
|
|
void kerchunkExtState(bool validSignal);
|
|
|
|
|
void relayingExtState(bool validSignal);
|
|
|
|
|
void relayingExtWaitState(bool validSignal);
|
|
|
|
|
void timeoutExtState(bool validSignal);
|
|
|
|
|
void timeoutExtWaitState(bool validSignal);
|
|
|
|
|
void hangState(bool validRFSignal, bool validExtSignal);
|
2020-04-15 17:31:49 +02:00
|
|
|
|
2020-05-03 14:08:33 +02:00
|
|
|
void clock(uint8_t length);
|
|
|
|
|
|
2020-04-15 17:31:49 +02:00
|
|
|
void sendCallsign();
|
|
|
|
|
void beginRelaying();
|
2020-05-09 14:01:02 +02:00
|
|
|
|
|
|
|
|
void insertDelay(uint16_t ms);
|
2020-05-12 14:45:03 +02:00
|
|
|
void insertSilence(uint16_t ms);
|
2020-04-11 23:08:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|