diff --git a/Controller.cpp b/Controller.cpp index 2d65327..b25c9e6 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -52,7 +52,7 @@ void CController::Stop() reader.Close(); dstar_device.CloseDevice(); - dmr_device.CloseDevice(); + dmrst_device.CloseDevice(); } bool CController::CheckTCModules() const @@ -152,18 +152,31 @@ bool CController::InitDevices() return true; } + const auto desc(deviceset.front().second); + if (deviceset.back().second.compare(desc)) + { + std::cerr << "Both devices have to be the same type: " << desc << " != " << deviceset.back().second << std::endl; + return true; + } + + Edvtype dvtype = Edvtype::dv3003; + if (0==desc.compare("ThumbDV") || 0==desc.compare("DVstick-33") || 0==desc.compare("USB-3000")) + dvtype = Edvtype::dv3000; + //initialize each device while (! deviceset.empty()) { - dstar_device.OpenDevice(deviceset.front().first, deviceset.front().second, 921600); + if (dstar_device.OpenDevice(deviceset.front().first, deviceset.front().second, dvtype)) + return true; deviceset.pop_front(); - dmr_device.OpenDevice(deviceset.front().first, deviceset.front().second, 921600); + if (dmrst_device.OpenDevice(deviceset.front().first, deviceset.front().second, dvtype)) + return true; deviceset.pop_front(); } // and start them up! dstar_device.Start(); - dmr_device.Start(); + dmrst_device.Start(); deviceset.clear(); @@ -190,7 +203,7 @@ void CController::ReadReflectorThread() dstar_device.AddPacket(packet); break; case ECodecType::dmr: - dmr_device.AddPacket(packet); + dmrst_device.AddPacket(packet); break; case ECodecType::c2_1600: case ECodecType::c2_3200: @@ -284,7 +297,7 @@ void CController::Codec2toAudio(std::shared_ptr packet) } // the only thing left is to encode the two ambe, so push the packet onto both AMBE queues dstar_device.AddPacket(packet); - dmr_device.AddPacket(packet); + dmrst_device.AddPacket(packet); } void CController::ProcessC2Thread() @@ -329,7 +342,7 @@ void CController::RouteDstPacket(std::shared_ptr packet) { // codec_in is dstar, the audio has just completed, so now calc the M17 and DMR codec2_queue.push(packet); - dmr_device.AddPacket(packet); + dmrst_device.AddPacket(packet); } else if (packet->AllCodecsAreSet()) { diff --git a/Controller.h b/Controller.h index e860a04..b0b5e57 100644 --- a/Controller.h +++ b/Controller.h @@ -29,12 +29,10 @@ #include "UnixDgramSocket.h" #include "configure.h" -enum class EAmbeType { dstar, dmr }; - class CController { public: - std::mutex dstar_mux, dmr_mux; + std::mutex dstar_mux, dmrst_mux; CController(); bool Start(); @@ -52,7 +50,7 @@ protected: CUnixDgramWriter writer; std::unordered_map> c2_16, c2_32; CDV3003 dstar_device{Encoding::dstar}; - CDV3003 dmr_device{Encoding::dmr}; + CDV3003 dmrst_device{Encoding::dmrsf}; CPacketQueue codec2_queue; std::mutex send_mux; diff --git a/DV3003.cpp b/DV3003.cpp index 6b0bd32..738a883 100644 --- a/DV3003.cpp +++ b/DV3003.cpp @@ -7,7 +7,7 @@ */ // tcd - a hybid transcoder using DVSI hardware and Codec2 software -// Copyright © 2021 Thomas A. Early N7TAE +// Copyright © 2022 Thomas A. Early N7TAE // 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 @@ -38,7 +38,7 @@ extern CController Controller; -CDV3003::CDV3003(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0) +CDV3003::CDV3003(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true) { } @@ -145,7 +145,7 @@ std::string CDV3003::GetDescription() const return description; } -bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, int baudrate) +bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype) { auto status = FT_OpenEx((PVOID)serialno.c_str(), FT_OPEN_BY_SERIAL_NUMBER, &ftHandle); if (FT_OK != status) @@ -201,7 +201,7 @@ bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, i } } - status = FT_SetBaudRate(ftHandle, baudrate ); + status = FT_SetBaudRate(ftHandle, (Edvtype::dv3000 == dvtype) ? 460800 : 921600); if (status != FT_OK) { FTDI_Error("FT_SetBaudRate", status); @@ -237,7 +237,8 @@ bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, i if (InitDV3003()) return true; - for (uint8_t ch=PKT_CHANNEL0; ch<=PKT_CHANNEL2; ch++) + const uint8_t limit = (Edvtype::dv3000 == dvtype) ? PKT_CHANNEL0 : PKT_CHANNEL2; + for (uint8_t ch=PKT_CHANNEL0; ch<=limit; ch++) { if (ConfigureVocoder(ch, type)) return true; @@ -383,7 +384,6 @@ bool CDV3003::InitDV3003() void CDV3003::Start() { - keep_running = true; feedFuture = std::async(std::launch::async, &CDV3003::FeedDevice, this); readFuture = std::async(std::launch::async, &CDV3003::ReadDevice, this); } @@ -609,9 +609,9 @@ void CDV3003::ReadDevice() } else { - Controller.dmr_mux.lock(); + Controller.dmrst_mux.lock(); Controller.RouteDmrPacket(packet); - Controller.dmr_mux.unlock(); + Controller.dmrst_mux.unlock(); } } } diff --git a/DV3003.h b/DV3003.h index 7903092..9222624 100644 --- a/DV3003.h +++ b/DV3003.h @@ -1,7 +1,7 @@ #pragma once // tcd - a hybid transcoder using DVSI hardware and Codec2 software -// Copyright © 2021 Thomas A. Early N7TAE +// Copyright © 2022 Thomas A. Early N7TAE // 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 @@ -98,13 +98,14 @@ struct dv3003_packet { using SDV3003_Packet = struct dv3003_packet; -enum class Encoding { dstar, dmr }; +enum class Encoding { dstar, dmrsf }; +enum class Edvtype { dv3000, dv3003 }; class CDV3003 { public: CDV3003(Encoding t); ~CDV3003(); - bool OpenDevice(const std::string &serialno, const std::string &desc, int baudrate); + bool OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype); void Start(); void CloseDevice(); std::string GetDescription() const;