From 62bdcde1dea19491611542be5a5adbaaef72c8aa Mon Sep 17 00:00:00 2001 From: Tom Early Date: Tue, 21 Dec 2021 12:28:21 -0700 Subject: [PATCH] fixed some device startup problems --- Controller.cpp | 13 ++++--------- DV3003.cpp | 14 +++++++++++++- DV3003.h | 5 +++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Controller.cpp b/Controller.cpp index fd89b17..acd02fb 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -81,19 +81,14 @@ bool CController::InitDevices() return true; } - // now initialize each device - + //initialize each device if (dstar_device.OpenDevice(deviceset[0], 921600) || dmr_device.OpenDevice(deviceset[1], 921600)) return true; - if (dstar_device.InitDV3003() || dmr_device.InitDV3003()) - return true; + // and start them up! + dstar_device.Start(); + dmr_device.Start(); - for (uint8_t ch=PKT_CHANNEL0; ch<=PKT_CHANNEL2; ch++) - { - if (dstar_device.ConfigureVocoder(ch, Encoding::dstar) || dmr_device.ConfigureVocoder(ch, Encoding::dmr)) - return true; - } return false; } diff --git a/DV3003.cpp b/DV3003.cpp index 7673edb..20de81a 100644 --- a/DV3003.cpp +++ b/DV3003.cpp @@ -147,6 +147,14 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate) std::cout << "Opened " << devicepath << " using fd " << fd << std::endl; #endif + if (InitDV3003()) + return true; + + for (uint8_t ch=PKT_CHANNEL0; ch<=PKT_CHANNEL2; ch++) + { + if (ConfigureVocoder(ch, type)) + return true; + } return false; } @@ -244,9 +252,13 @@ bool CDV3003::InitDV3003() version.assign(responsePacket.payload.ctrl.data.version); std::cout << "Found " << productid << " version " << version << " at " << devicepath << std::endl; + return false; +} + +void CDV3003::Start() +{ feedFuture = std::async(std::launch::async, &CDV3003::FeedDevice, this); readFuture = std::async(std::launch::async, &CDV3003::ReadDevice, this); - return false; } bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type) diff --git a/DV3003.h b/DV3003.h index 8f39568..b083e52 100644 --- a/DV3003.h +++ b/DV3003.h @@ -105,8 +105,7 @@ public: CDV3003(Encoding t); ~CDV3003(); bool OpenDevice(const std::string &device, int baudrate); - bool InitDV3003(); - bool ConfigureVocoder(uint8_t pkt_ch, Encoding type); + void Start(); void CloseDevice(); std::string GetDevicePath() const; std::string GetProductID() const; @@ -129,6 +128,8 @@ private: void FeedDevice(); void ReadDevice(); bool SetBaudRate(int baudrate); + bool InitDV3003(); + bool ConfigureVocoder(uint8_t pkt_ch, Encoding type); bool checkResponse(SDV3003_Packet &responsePacket, uint8_t response) const; bool SendAudio(const uint8_t channel, const int16_t *audio) const; bool SendData(const uint8_t channel, const uint8_t *data) const;