From 83e663b3f0b4df6e7ceb9d8fe15f2a017d56cf0f Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Thu, 8 Apr 2021 16:42:15 -0400 Subject: [PATCH] Use USRP callsign for M17 source if found, and add header and EOT frames to USRP2P25 --- USRP2M17/ModeConv.cpp | 1 - USRP2M17/USRP2M17.cpp | 18 ++++++++++++++++++ USRP2P25/ModeConv.cpp | 33 ++++++++++++++++++++++++++++----- USRP2P25/ModeConv.h | 10 +++++++++- USRP2P25/USRP2P25.cpp | 39 +++++++++++++++++++++++++++++++++++---- 5 files changed, 90 insertions(+), 11 deletions(-) diff --git a/USRP2M17/ModeConv.cpp b/USRP2M17/ModeConv.cpp index 0e9f71c..d075013 100644 --- a/USRP2M17/ModeConv.cpp +++ b/USRP2M17/ModeConv.cpp @@ -166,7 +166,6 @@ uint32_t CModeConv::getUSRP(int16_t* data) m_USRP.getData(tag, 1U); m_USRP.getData(data, 160U); --m_usrpN; - //return tag[0]; } return tag[0]; diff --git a/USRP2M17/USRP2M17.cpp b/USRP2M17/USRP2M17.cpp index 41348eb..9378c6b 100644 --- a/USRP2M17/USRP2M17.cpp +++ b/USRP2M17/USRP2M17.cpp @@ -307,6 +307,19 @@ int CUSRP2M17::run() if (m17Watch.elapsed() > M17_FRAME_PER) { uint32_t m17FrameType = m_conv.getM17(m_m17Frame); + if( (m_usrpcs.size()) > 3 && (m_usrpcs.size() < 8) ){ + memset(m17_src, ' ', 9); + memcpy(m17_src, m_usrpcs.c_str(), m_usrpcs.size()); + m17_src[8] = 'D'; + m17_src[9] = 0x00; + encode_callsign(m17_src); + } + else{ + memcpy(m17_src, m_callsign.c_str(), 9); + m17_src[9] = 0x00; + encode_callsign(m17_src); + } + if(m17FrameType == TAG_HEADER) { m17_cnt = 0U; m17Watch.start(); @@ -432,10 +445,15 @@ int CUSRP2M17::run() if((len == 32) && !memcmp(m_usrpFrame, "USRP", 4)) { LogMessage("USRP received end of voice transmission, %.1f seconds", float(m_usrpFrames) / 50.0F); m_conv.putUSRPEOT(); + m_usrpcs.clear(); m_usrpFrames = 0U; } if( (!memcmp(m_usrpFrame, "USRP", 4)) && len == 352) { + if( (m_usrpFrame[20] == 0x02) && (m_usrpFrame[32] == 0x08) ){ + m_usrpcs = (char *)(m_usrpFrame + 46); + } + if(!m_usrpFrames){ m_conv.putUSRPHeader(); LogMessage("USRP first frame received"); diff --git a/USRP2P25/ModeConv.cpp b/USRP2P25/ModeConv.cpp index dfcfdb7..240e8c5 100644 --- a/USRP2P25/ModeConv.cpp +++ b/USRP2P25/ModeConv.cpp @@ -100,6 +100,24 @@ void CModeConv::putUSRP(int16_t* data) m_p25N += 1U; } +void CModeConv::putP25Header() +{ + const int16_t zero[160U] = {0}; + + m_USRP.addData(&TAG_USRP_HEADER, 1U); + m_USRP.addData(zero, 160U); + m_usrpN += 1U; +} + +void CModeConv::putP25EOT() +{ + const int16_t zero[160U] = {0}; + + m_USRP.addData(&TAG_USRP_EOT, 1U); + m_USRP.addData(zero, 160U); + m_usrpN += 1U; +} + void CModeConv::putP25(uint8_t* data) { int16_t audio[160U]; @@ -171,20 +189,25 @@ void CModeConv::putP25(uint8_t* data) audio_adjusted[i] = m_p25Attenuate ? audio[i] / m_p25GainMultiplier : audio[i] * m_p25GainMultiplier; } + m_USRP.addData(&TAG_USRP_DATA, 1U); m_USRP.addData(audio_adjusted, 160U); 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){ + m_USRP.getData(tag, 1U); + m_USRP.getData(data, 160U); --m_usrpN; - return m_USRP.getData(data, 160U); - } - else{ - return false; } + + return tag[0]; } uint32_t CModeConv::getP25(uint8_t* data) diff --git a/USRP2P25/ModeConv.h b/USRP2P25/ModeConv.h index 4ea1c42..99496e2 100644 --- a/USRP2P25/ModeConv.h +++ b/USRP2P25/ModeConv.h @@ -27,6 +27,12 @@ const unsigned char TAG_LOST = 0x02U; const unsigned char TAG_EOT = 0x03U; const unsigned char 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) #define MODECONV_H @@ -40,10 +46,12 @@ public: void putUSRP(int16_t* data); void putUSRPHeader(); void putUSRPEOT(); + void putP25Header(); + void putP25EOT(); void putP25(unsigned char* data); uint32_t getP25(uint8_t* data); - bool getUSRP(int16_t* data); + uint32_t getUSRP(int16_t* data); private: uint32_t m_p25N; uint32_t m_usrpN; diff --git a/USRP2P25/USRP2P25.cpp b/USRP2P25/USRP2P25.cpp index b554603..605366b 100644 --- a/USRP2P25/USRP2P25.cpp +++ b/USRP2P25/USRP2P25.cpp @@ -441,7 +441,7 @@ int CUSRP2P25::run() if (m_p25Frame[0U] != 0xF0U && m_p25Frame[0U] != 0xF1U) { if (m_p25Frame[0U] == 0x62U && !m_p25info) { m_p25Frames = 0; - //m_conv.putP25Header(); + m_conv.putP25Header(); } else if (m_p25Frame[0U] == 0x65U && !m_p25info) { m_p25Dst = (m_p25Frame[1U] << 16) & 0xFF0000U; m_p25Dst |= (m_p25Frame[2U] << 8) & 0x00FF00U; @@ -455,16 +455,47 @@ int CUSRP2P25::run() } else if (m_p25Frame[0U] == 0x80U) { LogMessage("P25 received end of voice transmission, %.1f seconds", float(m_p25Frames) / 50.0F); m_p25info = false; - //m_conv.putP25EOT(); + m_conv.putP25EOT(); } m_conv.putP25(m_p25Frame); m_p25Frames++; } } - if (usrpWatch.elapsed() > USRP_FRAME_PER) { + if ( (usrpWatch.elapsed() > USRP_FRAME_PER) && (m_p25Frames > 4U) ) { 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); + //const uint32_t 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); const uint32_t cnt = htonl(usrp_cnt); memcpy(m_usrpFrame, "USRP", 4);