From 4a8066bd5365c954882fe89e036e22d448d2206c Mon Sep 17 00:00:00 2001 From: Tom Early Date: Wed, 22 Dec 2021 10:15:28 -0700 Subject: [PATCH] more debug packet msgs --- Controller.cpp | 104 +++++++++++++++++++++++++------------------------ DV3003.cpp | 26 +++++++------ DV3003.h | 1 - 3 files changed, 68 insertions(+), 63 deletions(-) diff --git a/Controller.cpp b/Controller.cpp index 335457a..a23b5ce 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -109,17 +109,29 @@ void CController::ReadReflectorThread() switch (packet->GetCodecIn()) { case ECodecType::dstar: + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Ref packet to dstar device:"); + #endif add_dst_mux.lock(); dstar_device.AddPacket(packet); add_dst_mux.unlock(); break; case ECodecType::dmr: + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Ref packet to dmr device:"); + #endif add_dmr_mux.lock(); dmr_device.AddPacket(packet); add_dmr_mux.unlock(); break; case ECodecType::c2_1600: case ECodecType::c2_3200: + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Ref packet to Codec2 vocoder:"); + #endif c2_mux.lock(); codec2_queue.push(packet); c2_mux.unlock(); @@ -155,6 +167,10 @@ void CController::AudiotoCodec2(std::shared_ptr packet) } // put the M17 data into the packet packet->SetM17Data(m17data); + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Encoded M17:"); + #endif // we might be all done... if (packet->AllCodecsAreSet()) { @@ -210,6 +226,10 @@ void CController::Codec2toAudio(std::shared_ptr packet) add_dmr_mux.lock(); dmr_device.AddPacket(packet); add_dmr_mux.unlock(); + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Sent to both dstar and dmr device:"); + #endif } void CController::ProcessC2Thread() @@ -251,9 +271,10 @@ void CController::SendToReflector(std::shared_ptr packet) // send the packet over the socket socket.Send(packet->GetTCPacket()); // the socket will automatically close after sending -//#ifdef DEBUG - //AppendWave(packet); -//#endif + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Sent to reflector:"); + #endif } void CController::RouteDstPacket(std::shared_ptr packet) @@ -264,6 +285,10 @@ void CController::RouteDstPacket(std::shared_ptr packet) add_dmr_mux.lock(); dmr_device.AddPacket(packet); add_dmr_mux.unlock(); + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Routed to dmr:"); + #endif } else if (packet->AllCodecsAreSet()) { @@ -280,6 +305,10 @@ void CController::RouteDmrPacket(std::shared_ptr packet) add_dst_mux.lock(); dstar_device.AddPacket(packet); add_dst_mux.unlock(); + #ifdef DEBUG + if (packet->IsLast()) + Dump(packet, "Routed to dstar:"); + #endif } else if (packet->AllCodecsAreSet()) { @@ -322,54 +351,29 @@ void CController::AppendM17(const std::shared_ptr packet) con void CController::Dump(const std::shared_ptr p, const std::string &title) const { - std::string codec; - switch (p->GetCodecIn()) - { - case ECodecType::dstar: - codec.assign("DStar"); - break; - case ECodecType::dmr: - codec.assign("DMR"); - break; - case ECodecType::c2_1600: - codec.assign("C2-1600"); - break; - case ECodecType::c2_3200: - codec.assign("C2-3200"); - break; - default: - codec.assign("NONE"); - break; - } - std::cout << title << ": Module='" << p->GetModule() << "' Stream ID=" << std::showbase << std::hex << ntohs(p->GetStreamId()) << std::noshowbase << " Codec in is " << codec; + std::stringstream line; + line << title << ": Mod='" << p->GetModule() << "' SID=" << std::showbase << std::hex << ntohs(p->GetStreamId()) << std::noshowbase; + + ECodecType in = p->GetCodecIn(); + if (p->DStarIsSet()) + line << " D-Star"; + if (ECodecType::dstar == in) + line << '*'; + if (p->DMRIsSet()) + line << " DMR"; + if (ECodecType::dmr == in) + line << '*'; + if (p->M17IsSet()) + line << " M17"; + if (ECodecType::c2_1600 == in) + line << "**"; + else if (ECodecType::c2_3200 == in) + line << '*'; if (p->IsSecond()) - std::cout << " IsSecond"; + line << " IsSecond"; if (p->IsLast()) - std::cout << " IsLast"; - std::cout << std::endl; - - // if (p->DStarIsSet()) - // { - // std::cout << "DStar data: "; - // for (unsigned int i=0; i<9; i++) - // std::cout << std::setw(2) << std::setfill('0') << unsigned(*(p->GetDStarData()+i)); - // std::cout << std::endl; - // } - // if (p->DMRIsSet()) - // { - // std::cout << "DMR Data: "; - // for (unsigned int i=0; i<9; i++) - // std::cout << std::setw(2) << std::setfill('0') << unsigned(*(p->GetDMRData()+i)); - // std::cout << std::endl; - // } - // if (p->M17IsSet()) - // { - // std::cout << "M17 Data: "; - // for (unsigned int i=0; i<16; i++) - // std::cout << std::setw(2) << std::setfill('0') << unsigned(*(p->GetM17Data()+i)); - // std::cout << std::endl; - // } - - std::cout << std::dec; + line << " IsLast"; + + std::cout << line.str() << std::dec << std::endl; } #endif diff --git a/DV3003.cpp b/DV3003.cpp index c4182d8..010cb3a 100644 --- a/DV3003.cpp +++ b/DV3003.cpp @@ -38,7 +38,7 @@ extern CController Controller; -CDV3003::CDV3003(Encoding t) : type(t), fd(-1), ch_depth(0), sp_depth(0), current_vocoder(0) +CDV3003::CDV3003(Encoding t) : type(t), fd(-1), ch_depth(0), sp_depth(0) { } @@ -138,14 +138,14 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate) if (SetBaudRate(baudrate)) return true; -#ifdef DEBUG + #ifdef DEBUG std::cout << ttyname << " baudrate it set to " << baudrate << std::endl; -#endif + #endif devicepath.assign(ttyname); -#ifdef DEBUG + #ifdef DEBUG std::cout << "Opened " << devicepath << " using fd " << fd << std::endl; -#endif + #endif if (InitDV3003()) return true; @@ -183,9 +183,9 @@ bool CDV3003::InitDV3003() std::cerr << "InitDV3003: invalid response to reset" << std::endl; return true; } -#ifdef DEBUG + #ifdef DEBUG std::cout << "Successfully reset " << devicepath << std::endl; -#endif + #endif // ********** turn off parity ********* ctrlPacket.header.payload_length = htons(4); @@ -211,9 +211,9 @@ bool CDV3003::InitDV3003() return true; } -#ifdef DEBUG + #ifdef DEBUG std::cout << "Successfully disabled parity on " << devicepath << std::endl; -#endif + #endif // ********* Product ID and Version ************* ctrlPacket.header.payload_length = htons(1); @@ -313,9 +313,9 @@ bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type) dump("Configuration response was:", &responsePacket, sizeof(responsePacket)); return true; }; -#ifdef DEBUG + #ifdef DEBUG std::cout << devicepath << " channel " << (unsigned int)(pkt_ch - PKT_CHANNEL0) << " is now configured for " << ((Encoding::dstar == type) ? "D-Star" : "DMR") << std::endl; -#endif + #endif return false; } @@ -377,6 +377,7 @@ bool CDV3003::GetResponse(SDV3003_Packet &packet) void CDV3003::FeedDevice() { keep_running = true; + uint8_t current_vocoder = 0; while (keep_running) { in_mux.lock(); @@ -422,7 +423,8 @@ void CDV3003::FeedDevice() SendAudio(current_vocoder, packet->GetAudio()); sp_depth++; #ifdef DEBUG - std::cout << "Sent audio to " << devicepath << std::endl; + if (packet->IsLast()) + std::cout << "Sent audio to " << devicepath << std::endl; #endif } if(++current_vocoder > 2) diff --git a/DV3003.h b/DV3003.h index b083e52..253172c 100644 --- a/DV3003.h +++ b/DV3003.h @@ -116,7 +116,6 @@ private: const Encoding type; int fd; std::atomic ch_depth, sp_depth; - uint8_t current_vocoder; std::atomic keep_running; CPacketQueue vocq[3]; // we need a queue for each vocoder std::mutex voc_mux[3];