find /dev/ttyUSBx devices automatically

main
Tom Early 4 years ago
parent b7ea3cf617
commit 3f484df49a

@ -14,12 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <unistd.h>
#include <sys/select.h>
#include <iostream>
#include "TranscoderPacket.h"
#include "Controller.h"
CController::CController() : dmr_vocoder_count(0), current_dmr_vocoder(0), dstar_vocoder_count(0), current_dstar_vocoder(0), keep_running(true)
{
}
bool CController::Start()
{
if (InitDevices() || reader.Open(REF2TC))
@ -56,12 +61,27 @@ void CController::Stop()
bool CController::InitDevices()
{
// unpack all the device paths
std::set<std::string> deviceset;
CSVtoSet(DEVICES, deviceset);
std::string device;
for (int i=0; i<32; i++) {
device.assign("/dev/ttyUSB");
device += std::to_string(i);
if (access(device.c_str(), R_OK | W_OK))
break;
else
deviceset.insert(device);
}
if (deviceset.empty()) {
std::cerr << "could not find a device!" << std::endl;
return true;
}
if (2 > deviceset.size())
{
std::cerr << "You must specify at least two DVSI 3003 devices" << std::endl;
std::cerr << "You need at least two DVSI 3003 devices" << std::endl;
return true;
}
@ -107,21 +127,6 @@ bool CController::InitDevices()
return false;
}
void CController::CSVtoSet(const std::string &str, std::set<std::string> &set, const std::string &delimiters)
{
auto lastPos = str.find_first_not_of(delimiters, 0); // Skip delimiters at beginning.
auto pos = str.find_first_of(delimiters, lastPos); // Find first non-delimiter.
while (std::string::npos != pos || std::string::npos != lastPos)
{
std::string element = str.substr(lastPos, pos-lastPos);
set.insert(element);
lastPos = str.find_first_not_of(delimiters, pos); // Skip delimiters.
pos = str.find_first_of(delimiters, lastPos); // Find next non-delimiter.
}
}
void CController::IncrementDMRVocoder()
{
current_dmr_vocoder = (current_dmr_vocoder + 1) % dmr_vocoder_count;

@ -25,7 +25,6 @@
#include "codec2.h"
#include "DV3003.h"
#include "configure.h"
#include "UnixDgramSocket.h"
enum class EAmbeType { dstar, dmr };
@ -33,10 +32,9 @@ enum class EAmbeType { dstar, dmr };
class CController
{
public:
CController() : dmr_vocoder_count(0), current_dmr_vocoder(0), dstar_vocoder_count(0), current_dstar_vocoder(0), keep_running(true) {}
CController();
bool Start();
void Stop();
bool IsRunning() { return keep_running; }
protected:
unsigned int dmr_vocoder_count, current_dmr_vocoder, dstar_vocoder_count, current_dstar_vocoder;
@ -56,6 +54,4 @@ protected:
void ReadAmbeDevices();
void ReadDevice(std::shared_ptr<CDV3003> dv3003, EAmbeType type);
void AddFDSet(int &max, int newfd, fd_set *set) const;
void CSVtoSet(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ",");
};

@ -125,10 +125,10 @@ bool CDV3003::OpenDevice(const std::string &ttyname, int baudrate)
if (SetBaudRate(baudrate))
return true;
std::cout << "Baudrade it set to " << baudrate << std::endl;
//std::cout << "Baudrate it set to " << baudrate << std::endl;
devicepath.assign(ttyname);
std::cout << "Opened " << devicepath << std::endl;
//std::cout << "Opened " << devicepath << std::endl;
return false;
}
@ -159,7 +159,7 @@ bool CDV3003::InitDV3003()
return true;
}
std::cout << "Successfully reset " << devicepath << std::endl;
//std::cout << "Successfully reset " << devicepath << std::endl;
// ********** turn off parity *********
ctrlPacket.header.payload_length = htons(4);
@ -185,7 +185,7 @@ bool CDV3003::InitDV3003()
return true;
}
std::cout << "Successfully disabled parity on " << devicepath << std::endl;
//std::cout << "Successfully disabled parity on " << devicepath << std::endl;
// ********* Product ID and Version *************
ctrlPacket.header.payload_length = htons(1);
@ -262,7 +262,7 @@ bool CDV3003::ConfigureCodec(uint8_t pkt_ch, Encoding type)
std::cerr << "codec config response packet failed" << std::endl;
return true;
};
std::cout << "channel " << (unsigned int)pkt_ch << " is now configured for " << ((Encoding::dstar == type) ? "D-Star" : "DMR") << std::endl;
//std::cout << "channel " << (unsigned int)pkt_ch << " is now configured for " << ((Encoding::dstar == type) ? "D-Star" : "DMR") << std::endl;
return false;
}

@ -1,4 +1,4 @@
// urfd -- The universal reflector
// tcd - a hybrid transcoder using DVSI hardware and Codec2 software
// Copyright © 2021 Thomas A. Early N7TAE
//
// This program is free software: you can redistribute it and/or modify
@ -25,6 +25,8 @@ int main()
if (controller.Start())
return EXIT_FAILURE;
std::cout << "Hybrid Transcoder Version #211205 Successfully started" << std::endl;
pause();
controller.Stop();

@ -2,7 +2,7 @@
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// urfd -- The universal reflector
// tcd - a hybrid transcoder using DVSI hardware and Codec2 software
// Copyright © 2021 Thomas A. Early N7TAE
//
// This program is free software: you can redistribute it and/or modify

Loading…
Cancel
Save

Powered by TurnKey Linux.