From 63c57d8a43828d4ec7fb0d3c4fcdaff4bddb2429 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 8 Jan 2022 04:10:24 -0700 Subject: [PATCH] now with a zero purge --- DV3003.cpp | 33 ++++++++++++++++++++++++--------- DV3003.h | 1 + Main.cpp | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/DV3003.cpp b/DV3003.cpp index ccc17d2..a6131a1 100644 --- a/DV3003.cpp +++ b/DV3003.cpp @@ -138,14 +138,13 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate) if (SetBaudRate(baudrate)) return true; -#ifdef DEBUG std::cout << ttyname << " baudrate it set to " << baudrate << std::endl; -#endif devicepath.assign(ttyname); -#ifdef DEBUG std::cout << "Opened " << devicepath << " using fd " << fd << std::endl; -#endif + + if (Purge()) + return true; if (InitDV3003()) return true; @@ -158,11 +157,31 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate) return false; } +bool CDV3003::Purge() +{ + const char zeros[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + // if there is a partial command in the input, this will clear it + for (unsigned int i=0; i<35; i++) + { + auto written = write(fd, zeros, sizeof(zeros)); + if (0 > written) + { + std::cerr << "Cleanse failed to write zeros to " << devicepath << std::endl; + return true; + } + if (written < 10) + { + std::cerr << "On Cleanse pass " << i << ", only " << written << " bytes were written to " << devicepath << std::endl; + } + } + return false; +} + bool CDV3003::InitDV3003() { SDV3003_Packet responsePacket, ctrlPacket; - // ********** hard reset ************* + // ********** soft reset ************* ctrlPacket.start_byte = PKT_HEADER; ctrlPacket.header.payload_length = htons(3); ctrlPacket.header.packet_type = PKT_CONTROL; @@ -183,9 +202,7 @@ bool CDV3003::InitDV3003() std::cerr << "InitDV3003: invalid response to reset" << std::endl; return true; } -#ifdef DEBUG std::cout << "Successfully reset " << devicepath << std::endl; -#endif // ********** turn off parity ********* ctrlPacket.header.payload_length = htons(4); @@ -211,9 +228,7 @@ bool CDV3003::InitDV3003() return true; } -#ifdef DEBUG std::cout << "Successfully disabled parity on " << devicepath << std::endl; -#endif // ********* Product ID and Version ************* ctrlPacket.header.payload_length = htons(1); diff --git a/DV3003.h b/DV3003.h index 4ccba5e..d6debaf 100644 --- a/DV3003.h +++ b/DV3003.h @@ -125,6 +125,7 @@ private: void ReadDevice(); bool SetBaudRate(int baudrate); bool InitDV3003(); + bool Purge(); 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; diff --git a/Main.cpp b/Main.cpp index 4a1b9e4..578ab7b 100644 --- a/Main.cpp +++ b/Main.cpp @@ -27,7 +27,7 @@ int main() if (Controller.Start()) return EXIT_FAILURE; - std::cout << "Hybrid Transcoder version 1.0.0 successfully started" << std::endl; + std::cout << "Hybrid Transcoder version 0.0.0 successfully started" << std::endl; pause();