Add USRP Header frame (text frame) and EOT frame

This commit is contained in:
Doug McLain 2021-04-08 15:09:24 -04:00
parent 45102eda5b
commit 89a55d890d
5 changed files with 80 additions and 15 deletions

View File

@ -109,6 +109,24 @@ void CModeConv::putUSRP(int16_t* data)
m_m17N += 1U; m_m17N += 1U;
} }
void CModeConv::putM17Header()
{
const int16_t zero[160U] = {0};
m_USRP.addData(&TAG_USRP_HEADER, 1U);
m_USRP.addData(zero, 160U);
m_usrpN += 1U;
}
void CModeConv::putM17EOT()
{
const int16_t zero[160U] = {0};
m_USRP.addData(&TAG_USRP_EOT, 1U);
m_USRP.addData(zero, 160U);
m_usrpN += 1U;
}
void CModeConv::putM17(uint8_t* data) void CModeConv::putM17(uint8_t* data)
{ {
int16_t audio[160U]; int16_t audio[160U];
@ -124,6 +142,7 @@ void CModeConv::putM17(uint8_t* data)
audio_adjusted[i] = m_m17Attenuate ? audio[i] / m_m17GainMultiplier : audio[i] * m_m17GainMultiplier; audio_adjusted[i] = m_m17Attenuate ? audio[i] / m_m17GainMultiplier : audio[i] * m_m17GainMultiplier;
} }
m_USRP.addData(&TAG_USRP_DATA, 1U);
m_USRP.addData(audio_adjusted, 160U); m_USRP.addData(audio_adjusted, 160U);
m_usrpN += 1U; m_usrpN += 1U;
@ -132,20 +151,25 @@ void CModeConv::putM17(uint8_t* data)
for(int i = 0; i < 160; ++i){ for(int i = 0; i < 160; ++i){
audio_adjusted[i] = m_m17Attenuate ? audio[i] / m_m17GainMultiplier : audio[i] * m_m17GainMultiplier; audio_adjusted[i] = m_m17Attenuate ? audio[i] / m_m17GainMultiplier : audio[i] * m_m17GainMultiplier;
} }
m_USRP.addData(&TAG_USRP_DATA, 1U);
m_USRP.addData(audio_adjusted, 160U); m_USRP.addData(audio_adjusted, 160U);
m_usrpN += 1U; m_usrpN += 1U;
} }
bool CModeConv::getUSRP(int16_t* data) uint32_t CModeConv::getUSRP(int16_t* data)
{ {
int16_t tag[1U];
tag[0] = TAG_USRP_NODATA;
if(m_usrpN){ if(m_usrpN){
m_USRP.getData(tag, 1U);
m_USRP.getData(data, 160U);
--m_usrpN; --m_usrpN;
return m_USRP.getData(data, 160U); //return tag[0];
}
else{
return false;
} }
return tag[0];
} }
uint32_t CModeConv::getM17(uint8_t* data) uint32_t CModeConv::getM17(uint8_t* data)

View File

@ -21,11 +21,17 @@
#include "RingBuffer.h" #include "RingBuffer.h"
#include "codec2/codec2.h" #include "codec2/codec2.h"
const unsigned char TAG_HEADER = 0x00U; const uint8_t TAG_HEADER = 0x00U;
const unsigned char TAG_DATA = 0x01U; const uint8_t TAG_DATA = 0x01U;
const unsigned char TAG_LOST = 0x02U; const uint8_t TAG_LOST = 0x02U;
const unsigned char TAG_EOT = 0x03U; const uint8_t TAG_EOT = 0x03U;
const unsigned char TAG_NODATA = 0x04U; const uint8_t TAG_NODATA = 0x04U;
const int16_t TAG_USRP_HEADER = 0x0000U;
const int16_t TAG_USRP_DATA = 0x0001U;
const int16_t TAG_USRP_LOST = 0x0002U;
const int16_t TAG_USRP_EOT = 0x0003U;
const int16_t TAG_USRP_NODATA = 0x0004U;
#if !defined(MODECONV_H) #if !defined(MODECONV_H)
#define MODECONV_H #define MODECONV_H
@ -41,8 +47,10 @@ public:
void putUSRPHeader(); void putUSRPHeader();
void putUSRPEOT(); void putUSRPEOT();
void putM17(uint8_t* data); void putM17(uint8_t* data);
void putM17Header();
void putM17EOT();
uint32_t getM17(uint8_t* data); uint32_t getM17(uint8_t* data);
bool getUSRP(int16_t* data); uint32_t getUSRP(int16_t* data);
private: private:
uint32_t m_m17N; uint32_t m_m17N;
uint32_t m_usrpN; uint32_t m_usrpN;

View File

@ -127,6 +127,7 @@ int main(int argc, char** argv)
CUSRP2M17::CUSRP2M17(const std::string& configFile) : CUSRP2M17::CUSRP2M17(const std::string& configFile) :
m_callsign(), m_callsign(),
m_m17Ref(), m_m17Ref(),
m_usrpcs(),
m_conf(configFile), m_conf(configFile),
m_usrpNetwork(NULL), m_usrpNetwork(NULL),
m_m17Network(NULL), m_m17Network(NULL),
@ -357,8 +358,10 @@ int CUSRP2M17::run()
if (!memcmp(m_m17Frame, "M17 ", 4)) { if (!memcmp(m_m17Frame, "M17 ", 4)) {
if (m_m17Frame[34] == 0 && m_m17Frame[35] == 0) { if (m_m17Frame[34] == 0 && m_m17Frame[35] == 0) {
m_m17Frames = 0; m_m17Frames = 0;
m_conv.putM17Header();
} }
else if (m_m17Frame[34U] & 0x80U) { else if (m_m17Frame[34U] & 0x80U) {
m_conv.putM17EOT();
LogMessage("M17 received end of voice transmission, %.1f seconds", float(m_m17Frames) / 25.0F); LogMessage("M17 received end of voice transmission, %.1f seconds", float(m_m17Frames) / 25.0F);
} }
else{ else{
@ -368,7 +371,7 @@ int CUSRP2M17::run()
memcpy(cs, m_m17Frame+12, 6); memcpy(cs, m_m17Frame+12, 6);
decode_callsign(cs); decode_callsign(cs);
std::string css((char *)cs); std::string css((char *)cs);
css = css.substr(0, css.find(' ')); m_usrpcs = css.substr(0, css.find(' '));
m_m17Frames++; m_m17Frames++;
} }
@ -376,7 +379,37 @@ int CUSRP2M17::run()
if (usrpWatch.elapsed() > USRP_FRAME_PER) { if (usrpWatch.elapsed() > USRP_FRAME_PER) {
int16_t pcm[160]; int16_t pcm[160];
if(m_conv.getUSRP(pcm)){ uint32_t usrpFrameType = m_conv.getUSRP(pcm);
if(usrpFrameType == TAG_USRP_HEADER){
//CUtils::dump(1U, "USRP data:", m_usrpFrame, 33U);
const uint32_t cnt = htonl(usrp_cnt);
memset(m_usrpFrame, 0, 352);
memcpy(m_usrpFrame, "USRP", 4);
memcpy(m_usrpFrame+4, &cnt, 4);
m_usrpFrame[20] = 2;
memcpy(m_usrpFrame+46, m_usrpcs.c_str(), m_usrpcs.size());
m_usrpNetwork->writeData(m_usrpFrame, 352);
usrp_cnt++;
usrpWatch.start();
}
if(usrpFrameType == TAG_USRP_EOT){
//CUtils::dump(1U, "USRP data:", m_usrpFrame, 33U);
const uint32_t cnt = htonl(usrp_cnt);
memcpy(m_usrpFrame, "USRP", 4);
memset(m_usrpFrame+4, 0, 28);
memcpy(m_usrpFrame+4, &cnt, 4);
m_usrpFrame[15] = 0;
m_usrpNetwork->writeData(m_usrpFrame, 32);
usrp_cnt++;
usrpWatch.start();
}
if(usrpFrameType == TAG_USRP_DATA){
//CUtils::dump(1U, "USRP data:", m_usrpFrame, 33U); //CUtils::dump(1U, "USRP data:", m_usrpFrame, 33U);
const uint32_t cnt = htonl(usrp_cnt); const uint32_t cnt = htonl(usrp_cnt);
memcpy(m_usrpFrame, "USRP", 4); memcpy(m_usrpFrame, "USRP", 4);

View File

@ -43,6 +43,7 @@ public:
private: private:
std::string m_callsign; std::string m_callsign;
std::string m_m17Ref; std::string m_m17Ref;
std::string m_usrpcs;
CConf m_conf; CConf m_conf;
CUSRPNetwork* m_usrpNetwork; CUSRPNetwork* m_usrpNetwork;
CM17Network* m_m17Network; CM17Network* m_m17Network;

View File

@ -40,7 +40,6 @@ public:
void putUSRP(int16_t* data); void putUSRP(int16_t* data);
void putUSRPHeader(); void putUSRPHeader();
void putUSRPEOT(); void putUSRPEOT();
void putP25(unsigned char* data); void putP25(unsigned char* data);
uint32_t getP25(uint8_t* data); uint32_t getP25(uint8_t* data);