Adding RSSI calibration mode support

This commit is contained in:
Andy CA6JAU 2018-02-17 23:56:23 -03:00
parent ba9345e4e8
commit d8e74634d4
7 changed files with 182 additions and 8 deletions

74
CalRSSI.cpp Normal file
View file

@ -0,0 +1,74 @@
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Andy Uribe CA6JAU
*
* 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.
*/
#include "Config.h"
#if defined(SEND_RSSI_DATA)
#include "Globals.h"
#include "CalRSSI.h"
CCalRSSI::CCalRSSI() :
m_count(0U),
m_navg(0U),
m_accum(0U),
m_min(0xFFFFU),
m_max(0x0000U)
{
}
void CCalRSSI::process()
{
m_count++;
if (m_count >= 32000U) {
uint16_t rssi = io.readRSSI();
m_count = 0U;
m_navg++;
m_accum += rssi;
if (rssi > m_max)
m_max = rssi;
if (rssi < m_min)
m_min = rssi;
if (m_navg >= 6U) {
uint16_t ave = m_accum / 6U;
uint8_t buffer[6U];
buffer[0U] = (m_max >> 8) & 0xFFU;
buffer[1U] = (m_max >> 0) & 0xFFU;
buffer[2U] = (m_min >> 8) & 0xFFU;
buffer[3U] = (m_min >> 0) & 0xFFU;
buffer[4U] = (ave >> 8) & 0xFFU;
buffer[5U] = (ave >> 0) & 0xFFU;
serial.writeRSSIData(buffer, 6U);
m_navg = 0U;
m_accum = 0U;
m_min = 0xFFFFU;
m_max = 0x0000U;
}
}
}
#endif

44
CalRSSI.h Normal file
View file

@ -0,0 +1,44 @@
/*
* Copyright (C) 2016 by Jonathan Naylor G4KLX
* Copyright (C) 2018 by Andy Uribe CA6JAU
*
* 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(CALRSSI_H)
#define CALRSSI_H
#include "Config.h"
#if defined(SEND_RSSI_DATA)
class CCalRSSI {
public:
CCalRSSI();
void process();
private:
uint32_t m_count;
uint8_t m_navg;
uint32_t m_accum;
uint16_t m_min;
uint16_t m_max;
};
#endif
#endif

View file

@ -43,6 +43,7 @@ enum MMDVM_STATE {
// Dummy states start at 90
STATE_DMRDMO1K = 92,
STATE_RSSICAL = 96,
STATE_CWID = 97,
STATE_DMRCAL = 98,
STATE_DSTARCAL = 99
@ -75,6 +76,7 @@ const uint8_t MARK_NONE = 0x00U;
#include "NXDNRX.h"
#include "NXDNTX.h"
#include "CWIdTX.h"
#include "CalRSSI.h"
#include "CalDMR.h"
#include "Debug.h"
#include "Utils.h"
@ -128,7 +130,11 @@ extern CP25TX p25TX;
extern CNXDNRX nxdnRX;
extern CNXDNTX nxdnTX;
extern CCalDMR calDMR;
extern CCalDMR calDMR;
#if defined(SEND_RSSI_DATA)
extern CCalRSSI calRSSI;
#endif
extern CCWIdTX cwIdTX;

View file

@ -71,6 +71,10 @@ CNXDNTX nxdnTX;
CCalDMR calDMR;
#if defined(SEND_RSSI_DATA)
CCalRSSI calRSSI;
#endif
CCWIdTX cwIdTX;
CSerialPort serial;
@ -114,6 +118,11 @@ void loop()
if (m_calState == STATE_DMRCAL || m_calState == STATE_DMRDMO1K)
calDMR.process();
#if defined(SEND_RSSI_DATA)
if (m_calState == STATE_RSSICAL)
calRSSI.process();
#endif
if (m_modemState == STATE_IDLE)
cwIdTX.process();
}

View file

@ -67,6 +67,10 @@ CNXDNTX nxdnTX;
CCalDMR calDMR;
#if defined(SEND_RSSI_DATA)
CCalRSSI calRSSI;
#endif
CCWIdTX cwIdTX;
CSerialPort serial;
@ -109,6 +113,11 @@ void loop()
if (m_calState == STATE_DMRCAL || m_calState == STATE_DMRDMO1K)
calDMR.process();
#if defined(SEND_RSSI_DATA)
if (m_calState == STATE_RSSICAL)
calRSSI.process();
#endif
if (m_modemState == STATE_IDLE)
cwIdTX.process();
}

View file

@ -32,6 +32,7 @@ const uint8_t MMDVM_SET_MODE = 0x03U;
const uint8_t MMDVM_SET_FREQ = 0x04U;
const uint8_t MMDVM_CAL_DATA = 0x08U;
const uint8_t MMDVM_RSSI_DATA = 0x09U;
const uint8_t MMDVM_SEND_CWID = 0x0AU;
@ -220,7 +221,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
MMDVM_STATE modemState = MMDVM_STATE(data[3U]);
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K)
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K && modemState != STATE_RSSICAL)
return 4U;
if (modemState == STATE_DSTAR && !dstarEnable)
return 4U;
@ -260,7 +261,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
m_p25Enable = p25Enable;
m_nxdnEnable = nxdnEnable;
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K) {
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K || modemState == STATE_RSSICAL) {
m_dmrEnable = true;
m_modemState = STATE_DMR;
m_calState = modemState;
@ -291,7 +292,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
io.setLoDevYSF(ysfLoDev);
if (!m_firstCal || (modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K)) {
if (!m_firstCal || (modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K && modemState != STATE_RSSICAL)) {
if(m_dstarEnable)
io.ifConf(STATE_DSTAR, true);
else if(m_dmrEnable)
@ -309,7 +310,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length)
io.printConf();
#endif
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K)
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K || modemState == STATE_RSSICAL)
m_firstCal = true;
return 0U;
@ -326,7 +327,7 @@ uint8_t CSerialPort::setMode(const uint8_t* data, uint8_t length)
if (modemState == m_modemState)
return 0U;
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K)
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_DMRDMO1K && modemState != STATE_RSSICAL)
return 4U;
if (modemState == STATE_DSTAR && !m_dstarEnable)
return 4U;
@ -339,7 +340,7 @@ uint8_t CSerialPort::setMode(const uint8_t* data, uint8_t length)
if (modemState == STATE_NXDN && !m_nxdnEnable)
return 4U;
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K) {
if (modemState == STATE_DMRCAL || modemState == STATE_DMRDMO1K || modemState == STATE_RSSICAL) {
m_dmrEnable = true;
tmpState = STATE_DMR;
m_calState = modemState;
@ -532,8 +533,11 @@ void CSerialPort::process()
break;
case MMDVM_CAL_DATA:
if (m_calState == STATE_DMRCAL || m_calState == STATE_DMRDMO1K)
if (m_calState == STATE_DMRCAL || m_calState == STATE_DMRDMO1K) {
err = calDMR.write(m_buffer + 3U, m_len - 3U);
} else if (m_calState == STATE_RSSICAL) {
err = 0U;
}
if (err == 0U) {
sendACK();
} else {
@ -1030,6 +1034,30 @@ void CSerialPort::writeNXDNLost()
writeInt(1U, reply, 3);
}
#if defined(SEND_RSSI_DATA)
void CSerialPort::writeRSSIData(const uint8_t* data, uint8_t length)
{
if (m_calState != STATE_RSSICAL)
return;
uint8_t reply[30U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_RSSI_DATA;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
#endif
#if defined(ENABLE_DEBUG)
void CSerialPort::writeDebug(const char* text)

View file

@ -48,6 +48,10 @@ public:
void writeNXDNData(const uint8_t* data, uint8_t length);
void writeNXDNLost();
#if defined(SEND_RSSI_DATA)
void writeRSSIData(const uint8_t* data, uint8_t length);
#endif
#if defined(ENABLE_DEBUG)
void writeDebug(const char* text);
void writeDebug(const char* text, int16_t n1);