2016-02-16 07:27:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015,2016 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "YSFControl.h"
|
2016-04-21 17:00:26 +00:00
|
|
|
#include "YSFFICH.h"
|
2016-02-16 07:27:13 +00:00
|
|
|
#include "Utils.h"
|
|
|
|
#include "Sync.h"
|
|
|
|
#include "Log.h"
|
|
|
|
|
2016-03-07 20:21:55 +00:00
|
|
|
#include <cstdio>
|
2016-02-16 07:27:13 +00:00
|
|
|
#include <cassert>
|
2016-04-21 17:00:26 +00:00
|
|
|
#include <cstring>
|
2016-02-16 07:27:13 +00:00
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
// #define DUMP_YSF
|
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
CYSFControl::CYSFControl(const std::string& callsign, IDisplay* display, unsigned int timeout, bool duplex, bool parrot) :
|
2016-02-16 07:27:13 +00:00
|
|
|
m_display(display),
|
|
|
|
m_duplex(duplex),
|
2016-04-19 17:06:39 +00:00
|
|
|
m_queue(2000U, "YSF Control"),
|
2016-02-25 19:54:18 +00:00
|
|
|
m_state(RS_RF_LISTENING),
|
2016-02-16 07:27:13 +00:00
|
|
|
m_timeoutTimer(1000U, timeout),
|
2016-03-14 20:55:15 +00:00
|
|
|
m_interval(),
|
2016-02-16 07:27:13 +00:00
|
|
|
m_frames(0U),
|
2016-02-29 22:43:26 +00:00
|
|
|
m_source(NULL),
|
|
|
|
m_dest(NULL),
|
2016-02-29 19:52:11 +00:00
|
|
|
m_payload(),
|
2016-02-22 21:13:48 +00:00
|
|
|
m_parrot(NULL),
|
2016-02-16 07:27:13 +00:00
|
|
|
m_fp(NULL)
|
|
|
|
{
|
|
|
|
assert(display != NULL);
|
2016-02-22 21:13:48 +00:00
|
|
|
|
|
|
|
if (parrot)
|
|
|
|
m_parrot = new CYSFParrot(timeout);
|
2016-02-29 19:52:11 +00:00
|
|
|
|
|
|
|
m_payload.setUplink(callsign);
|
|
|
|
m_payload.setDownlink(callsign);
|
2016-03-14 20:55:15 +00:00
|
|
|
|
|
|
|
m_interval.start();
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CYSFControl::~CYSFControl()
|
|
|
|
{
|
2016-02-22 21:13:48 +00:00
|
|
|
delete m_parrot;
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CYSFControl::writeModem(unsigned char *data)
|
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
unsigned char type = data[0U];
|
|
|
|
|
2016-02-25 19:54:18 +00:00
|
|
|
if (type == TAG_LOST && m_state == RS_RF_AUDIO) {
|
2016-02-16 07:27:13 +00:00
|
|
|
LogMessage("YSF, transmission lost, %.1f seconds", float(m_frames) / 10.0F);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
|
|
|
if (m_parrot != NULL)
|
|
|
|
m_parrot->end();
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
writeEndOfTransmission();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == TAG_LOST)
|
|
|
|
return false;
|
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
CYSFFICH fich;
|
|
|
|
bool valid = fich.decode(data + 2U);
|
2016-04-12 20:33:16 +00:00
|
|
|
|
|
|
|
if (valid && m_state == RS_RF_LISTENING) {
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char fi = fich.getFI();
|
2016-04-12 20:33:16 +00:00
|
|
|
if (fi == YSF_FI_TERMINATOR)
|
|
|
|
return false;
|
2016-02-16 07:27:13 +00:00
|
|
|
|
|
|
|
m_frames = 0U;
|
|
|
|
m_timeoutTimer.start();
|
2016-02-29 22:43:26 +00:00
|
|
|
m_payload.reset();
|
2016-02-25 19:54:18 +00:00
|
|
|
m_state = RS_RF_AUDIO;
|
2016-02-16 17:37:12 +00:00
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
openFile();
|
|
|
|
#endif
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 19:54:18 +00:00
|
|
|
if (m_state != RS_RF_AUDIO)
|
2016-02-16 07:57:46 +00:00
|
|
|
return false;
|
2016-02-16 07:27:13 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char fi = fich.getFI();
|
|
|
|
if (valid && fi == YSF_FI_HEADER) {
|
2016-02-16 07:57:46 +00:00
|
|
|
CSync::addYSFSync(data + 2U);
|
2016-02-16 07:27:13 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char fn = fich.getFN();
|
|
|
|
unsigned char ft = fich.getFT();
|
|
|
|
unsigned char dt = fich.getDT();
|
|
|
|
unsigned char cm = fich.getCM();
|
2016-04-20 06:29:09 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char orig[YSF_FRAME_LENGTH_BYTES];
|
|
|
|
::memcpy(orig, data + 2U, YSF_FRAME_LENGTH_BYTES);
|
2016-02-28 20:34:37 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.encode(data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
// valid = m_payload.processHeader(data + 2U);
|
2016-04-20 06:29:09 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned int errs = calculateBER(orig, data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
LogDebug("YSF, FI=%u FN=%u FT=%u DT=%u BER=%.1f%%", fi, fn, ft, dt, float(errs) / 2.4F);
|
2016-04-21 17:00:26 +00:00
|
|
|
|
|
|
|
if (m_duplex) {
|
|
|
|
fich.setMR(YSF_MR_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
|
|
|
|
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeQueue(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_parrot != NULL) {
|
|
|
|
fich.setMR(YSF_MR_NOT_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
|
|
|
|
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeParrot(data);
|
|
|
|
}
|
2016-02-28 20:34:37 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
if (valid)
|
|
|
|
m_source = m_payload.getSource();
|
|
|
|
|
|
|
|
if (cm == YSF_CM_GROUP) {
|
|
|
|
m_dest = (unsigned char*)"CQCQCQ ";
|
|
|
|
} else {
|
|
|
|
if (valid)
|
|
|
|
m_dest = m_payload.getDest();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
writeFile(data + 2U);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (m_source != NULL && m_dest != NULL)
|
|
|
|
LogMessage("YSF, received header from %10.10s to %10.10s", m_source, m_dest);
|
|
|
|
else if (m_source == NULL && m_dest != NULL)
|
|
|
|
LogMessage("YSF, received header from ?????????? to %10.10s", m_dest);
|
|
|
|
else if (m_source != NULL && m_dest == NULL)
|
|
|
|
LogMessage("YSF, received header from %10.10s to ??????????", m_source);
|
|
|
|
else
|
|
|
|
LogMessage("YSF, received header from ?????????? to ??????????");
|
|
|
|
} else if (valid && fi == YSF_FI_TERMINATOR) {
|
|
|
|
CSync::addYSFSync(data + 2U);
|
|
|
|
|
|
|
|
unsigned char fn = fich.getFN();
|
|
|
|
unsigned char ft = fich.getFT();
|
|
|
|
unsigned char dt = fich.getDT();
|
|
|
|
|
|
|
|
unsigned char orig[YSF_FRAME_LENGTH_BYTES];
|
|
|
|
::memcpy(orig, data + 2U, YSF_FRAME_LENGTH_BYTES);
|
|
|
|
|
|
|
|
fich.encode(data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
// m_payload.processTrailer(data + 2U);
|
2016-04-21 17:00:26 +00:00
|
|
|
|
|
|
|
unsigned int errs = calculateBER(orig, data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
LogDebug("YSF, FI=%u FN=%u FT=%u DT=%u BER=%.1f%%", fi, fn, ft, dt, float(errs) / 2.4F);
|
2016-02-28 20:34:37 +00:00
|
|
|
|
2016-02-16 07:57:46 +00:00
|
|
|
m_frames++;
|
2016-02-16 07:27:13 +00:00
|
|
|
|
2016-02-16 07:57:46 +00:00
|
|
|
if (m_duplex) {
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.setMR(YSF_MR_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
2016-02-16 07:57:46 +00:00
|
|
|
data[0U] = TAG_EOT;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeQueue(data);
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
if (m_parrot != NULL) {
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.setMR(YSF_MR_NOT_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
data[0U] = TAG_EOT;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeParrot(data);
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:37:12 +00:00
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
writeFile(data + 2U);
|
|
|
|
#endif
|
|
|
|
|
2016-02-16 07:57:46 +00:00
|
|
|
LogMessage("YSF, received RF end of transmission, %.1f seconds", float(m_frames) / 10.0F);
|
|
|
|
writeEndOfTransmission();
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
return false;
|
2016-04-21 17:00:26 +00:00
|
|
|
} else if (valid) {
|
2016-02-16 07:27:13 +00:00
|
|
|
CSync::addYSFSync(data + 2U);
|
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char cm = fich.getCM();
|
|
|
|
unsigned char fn = fich.getFN();
|
|
|
|
unsigned char ft = fich.getFT();
|
|
|
|
unsigned char dt = fich.getDT();
|
2016-04-20 06:29:09 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char orig[YSF_FRAME_LENGTH_BYTES];
|
|
|
|
::memcpy(orig, data + 2U, YSF_FRAME_LENGTH_BYTES);
|
2016-02-29 21:30:26 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.encode(data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
// m_payload.processData(data + 2U, fn, dt);
|
2016-04-20 06:29:09 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned int errs = calculateBER(orig, data + 2U);
|
2016-04-21 18:57:27 +00:00
|
|
|
LogDebug("YSF, FI=%u FN=%u FT=%u DT=%u BER=%.1f%%", fi, fn, ft, dt, float(errs) / 2.4F);
|
2016-02-29 21:30:26 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
bool change = false;
|
2016-02-29 22:43:26 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
if (m_dest == NULL) {
|
|
|
|
if (cm == YSF_CM_GROUP) {
|
|
|
|
m_dest = (unsigned char*)"CQCQCQ ";
|
|
|
|
change = true;
|
|
|
|
} else {
|
|
|
|
m_dest = m_payload.getDest();
|
|
|
|
if (m_dest != NULL)
|
2016-04-19 06:45:49 +00:00
|
|
|
change = true;
|
2016-02-29 22:43:26 +00:00
|
|
|
}
|
2016-04-21 17:00:26 +00:00
|
|
|
}
|
2016-02-29 22:43:26 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
if (m_source == NULL) {
|
|
|
|
m_source = m_payload.getSource();
|
|
|
|
if (m_source != NULL)
|
|
|
|
change = true;
|
|
|
|
}
|
2016-02-29 22:43:26 +00:00
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
if (change) {
|
|
|
|
if (m_source != NULL && m_dest != NULL) {
|
|
|
|
m_display->writeFusion((char*)m_source, (char*)m_dest);
|
|
|
|
LogMessage("YSF, received transmission from %10.10s to %10.10s", m_source, m_dest);
|
|
|
|
}
|
|
|
|
if (m_source != NULL && m_dest == NULL) {
|
|
|
|
m_display->writeFusion((char*)m_source, "??????????");
|
|
|
|
LogMessage("YSF, received transmission from %10.10s to ??????????", m_source);
|
|
|
|
}
|
|
|
|
if (m_source == NULL && m_dest != NULL) {
|
|
|
|
m_display->writeFusion("??????????", (char*)m_dest);
|
|
|
|
LogMessage("YSF, received transmission from ?????????? to %10.10s", m_dest);
|
2016-02-29 22:43:26 +00:00
|
|
|
}
|
2016-02-28 20:34:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
m_frames++;
|
|
|
|
|
|
|
|
if (m_duplex) {
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.setMR(YSF_MR_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeQueue(data);
|
|
|
|
}
|
2016-02-16 17:37:12 +00:00
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
if (m_parrot != NULL) {
|
2016-04-21 17:00:26 +00:00
|
|
|
fich.setMR(YSF_MR_NOT_BUSY);
|
|
|
|
fich.encode(data + 2U);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeParrot(data);
|
|
|
|
}
|
|
|
|
|
2016-04-21 17:00:26 +00:00
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
writeFile(data + 2U);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
CSync::addYSFSync(data + 2U);
|
|
|
|
|
|
|
|
m_frames++;
|
|
|
|
|
|
|
|
if (m_duplex) {
|
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeQueue(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_parrot != NULL) {
|
|
|
|
data[0U] = TAG_DATA;
|
|
|
|
data[1U] = 0x00U;
|
|
|
|
writeParrot(data);
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:37:12 +00:00
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
writeFile(data + 2U);
|
|
|
|
#endif
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CYSFControl::readModem(unsigned char* data)
|
|
|
|
{
|
2016-03-07 20:21:55 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
if (m_queue.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_queue.getData(&len, 1U);
|
|
|
|
|
|
|
|
m_queue.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CYSFControl::writeEndOfTransmission()
|
|
|
|
{
|
2016-02-25 19:54:18 +00:00
|
|
|
m_state = RS_RF_LISTENING;
|
2016-02-16 07:27:13 +00:00
|
|
|
|
|
|
|
m_timeoutTimer.stop();
|
|
|
|
|
2016-02-29 22:43:26 +00:00
|
|
|
m_payload.reset();
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
m_display->clearFusion();
|
|
|
|
|
2016-02-29 22:43:26 +00:00
|
|
|
// These variables are free'd by YSFPayload
|
|
|
|
m_source = NULL;
|
|
|
|
m_dest = NULL;
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
#if defined(DUMP_YSF)
|
|
|
|
closeFile();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-03-14 20:55:15 +00:00
|
|
|
void CYSFControl::clock()
|
2016-02-16 07:27:13 +00:00
|
|
|
{
|
2016-03-14 20:55:15 +00:00
|
|
|
unsigned int ms = m_interval.elapsed();
|
|
|
|
m_interval.start();
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
m_timeoutTimer.clock(ms);
|
2016-02-22 21:13:48 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CYSFControl::writeQueue(const unsigned char *data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired())
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned char len = YSF_FRAME_LENGTH_BYTES + 2U;
|
2016-03-07 18:08:50 +00:00
|
|
|
|
|
|
|
unsigned int space = m_queue.freeSpace();
|
|
|
|
if (space < (len + 1U)) {
|
|
|
|
LogError("YSF, overflow in the System Fusion RF queue");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
m_queue.addData(&len, 1U);
|
|
|
|
|
|
|
|
m_queue.addData(data, len);
|
|
|
|
}
|
|
|
|
|
2016-02-22 21:13:48 +00:00
|
|
|
void CYSFControl::writeParrot(const unsigned char *data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_parrot->write(data);
|
2016-02-23 19:30:35 +00:00
|
|
|
|
|
|
|
if (data[0U] == TAG_EOT)
|
|
|
|
m_parrot->end();
|
2016-02-22 21:13:48 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
bool CYSFControl::openFile()
|
|
|
|
{
|
|
|
|
if (m_fp != NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
time_t t;
|
|
|
|
::time(&t);
|
|
|
|
|
|
|
|
struct tm* tm = ::localtime(&t);
|
|
|
|
|
|
|
|
char name[100U];
|
|
|
|
::sprintf(name, "YSF_%04d%02d%02d_%02d%02d%02d.ambe", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
|
|
|
|
|
m_fp = ::fopen(name, "wb");
|
|
|
|
if (m_fp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
::fwrite("YSF", 1U, 3U, m_fp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CYSFControl::writeFile(const unsigned char* data)
|
|
|
|
{
|
|
|
|
if (m_fp == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
::fwrite(data, 1U, YSF_FRAME_LENGTH_BYTES, m_fp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CYSFControl::closeFile()
|
|
|
|
{
|
|
|
|
if (m_fp != NULL) {
|
|
|
|
::fclose(m_fp);
|
|
|
|
m_fp = NULL;
|
|
|
|
}
|
|
|
|
}
|
2016-04-21 17:00:26 +00:00
|
|
|
|
|
|
|
unsigned int CYSFControl::calculateBER(const unsigned char* orig, const unsigned char *curr) const
|
|
|
|
{
|
|
|
|
unsigned int errors = 0U;
|
|
|
|
|
2016-04-21 18:57:27 +00:00
|
|
|
for (unsigned int i = 0U; i < (YSF_SYNC_LENGTH_BYTES + YSF_FICH_LENGTH_BYTES); i++) {
|
2016-04-21 17:00:26 +00:00
|
|
|
unsigned char v = orig[i] ^ curr[i];
|
|
|
|
while (v != 0U) {
|
|
|
|
v &= v - 1U;
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|