Add the optional System Fusion Parrot.

This commit is contained in:
Jonathan Naylor
2016-02-22 21:13:48 +00:00
parent 7852bd53b5
commit e2c7a28fb9
11 changed files with 206 additions and 5 deletions

View File

@@ -29,20 +29,25 @@
* Uplink and downlink callsign addition.
*/
CYSFControl::CYSFControl(const std::string& callsign, IDisplay* display, unsigned int timeout, bool duplex) :
CYSFControl::CYSFControl(const std::string& callsign, IDisplay* display, unsigned int timeout, bool duplex, bool parrot) :
m_display(display),
m_duplex(duplex),
m_queue(1000U, "YSF Control"),
m_state(RS_LISTENING),
m_timeoutTimer(1000U, timeout),
m_frames(0U),
m_parrot(NULL),
m_fp(NULL)
{
assert(display != NULL);
if (parrot)
m_parrot = new CYSFParrot(timeout);
}
CYSFControl::~CYSFControl()
{
delete m_parrot;
}
bool CYSFControl::writeModem(unsigned char *data)
@@ -87,12 +92,17 @@ bool CYSFControl::writeModem(unsigned char *data)
writeQueue(data);
}
if (m_parrot != NULL) {
data[0U] = TAG_EOT;
data[1U] = 0x00U;
writeParrot(data);
}
#if defined(DUMP_YSF)
writeFile(data + 2U);
#endif
LogMessage("YSF, received RF end of transmission, %.1f seconds", float(m_frames) / 10.0F);
writeEndOfTransmission();
return false;
@@ -107,6 +117,12 @@ bool CYSFControl::writeModem(unsigned char *data)
writeQueue(data);
}
if (m_parrot != NULL) {
data[0U] = TAG_DATA;
data[1U] = 0x00U;
writeParrot(data);
}
#if defined(DUMP_YSF)
writeFile(data + 2U);
#endif
@@ -144,6 +160,19 @@ void CYSFControl::writeEndOfTransmission()
void CYSFControl::clock(unsigned int ms)
{
m_timeoutTimer.clock(ms);
if (m_parrot != NULL) {
m_parrot->clock(ms);
unsigned int space = m_queue.freeSpace();
bool hasData = m_parrot->hasData();
if (space > (YSF_FRAME_LENGTH_BYTES + 2U) && hasData) {
unsigned char data[YSF_FRAME_LENGTH_BYTES + 2U];
m_parrot->read(data);
writeQueue(data);
}
}
}
void CYSFControl::writeQueue(const unsigned char *data)
@@ -159,6 +188,16 @@ void CYSFControl::writeQueue(const unsigned char *data)
m_queue.addData(data, len);
}
void CYSFControl::writeParrot(const unsigned char *data)
{
assert(data != NULL);
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired())
return;
m_parrot->write(data);
}
bool CYSFControl::openFile()
{
if (m_fp != NULL)