renamed the DVSI device class

main
Tom Early 4 years ago
parent f450282c81
commit 3d48a62406

@ -25,7 +25,7 @@
#include <utility> #include <utility>
#include "codec2.h" #include "codec2.h"
#include "DV3003.h" #include "DVSIDevice.h"
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
#include "configure.h" #include "configure.h"
@ -49,8 +49,8 @@ protected:
CUnixDgramReader reader; CUnixDgramReader reader;
CUnixDgramWriter writer; CUnixDgramWriter writer;
std::unordered_map<char, std::unique_ptr<CCodec2>> c2_16, c2_32; std::unordered_map<char, std::unique_ptr<CCodec2>> c2_16, c2_32;
CDV3003 dstar_device{Encoding::dstar}; CDVDevice dstar_device{Encoding::dstar};
CDV3003 dmrst_device{Encoding::dmrsf}; CDVDevice dmrst_device{Encoding::dmrsf};
CPacketQueue codec2_queue; CPacketQueue codec2_queue;
std::mutex send_mux; std::mutex send_mux;

@ -32,22 +32,22 @@
#include <cerrno> #include <cerrno>
#include <thread> #include <thread>
#include "DV3003.h" #include "DVSIDevice.h"
#include "configure.h" #include "configure.h"
#include "Controller.h" #include "Controller.h"
extern CController Controller; extern CController Controller;
CDV3003::CDV3003(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true) CDVDevice::CDVDevice(Encoding t) : type(t), ftHandle(nullptr), buffer_depth(0), keep_running(true)
{ {
} }
CDV3003::~CDV3003() CDVDevice::~CDVDevice()
{ {
CloseDevice(); CloseDevice();
} }
void CDV3003::CloseDevice() void CDVDevice::CloseDevice()
{ {
keep_running = false; keep_running = false;
if (ftHandle) if (ftHandle)
@ -63,7 +63,7 @@ void CDV3003::CloseDevice()
readFuture.get(); readFuture.get();
} }
void CDV3003::FTDI_Error(const char *where, FT_STATUS status) const void CDVDevice::FTDI_Error(const char *where, FT_STATUS status) const
{ {
std::cerr << "FTDI ERROR: " << where << ": "; std::cerr << "FTDI ERROR: " << where << ": ";
switch (status) switch (status)
@ -132,7 +132,7 @@ void CDV3003::FTDI_Error(const char *where, FT_STATUS status) const
std::cerr << std::endl; std::cerr << std::endl;
} }
bool CDV3003::checkResponse(SDV3003_Packet &p, uint8_t response) const bool CDVDevice::checkResponse(SDV_Packet &p, uint8_t response) const
{ {
if(p.start_byte != PKT_HEADER || p.header.packet_type != PKT_CONTROL || p.field_id != response) if(p.start_byte != PKT_HEADER || p.header.packet_type != PKT_CONTROL || p.field_id != response)
return true; return true;
@ -140,12 +140,12 @@ bool CDV3003::checkResponse(SDV3003_Packet &p, uint8_t response) const
return false; return false;
} }
std::string CDV3003::GetDescription() const std::string CDVDevice::GetDescription() const
{ {
return description; return description;
} }
bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype) bool CDVDevice::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); auto status = FT_OpenEx((PVOID)serialno.c_str(), FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
if (FT_OK != status) if (FT_OK != status)
@ -215,7 +215,7 @@ bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, E
return true; return true;
} }
ULONG maxsize = sizeof(SDV3003_Packet); ULONG maxsize = sizeof(SDV_Packet);
maxsize = (maxsize % 64) ? maxsize - (maxsize % 64U) + 64U : maxsize; maxsize = (maxsize % 64) ? maxsize - (maxsize % 64U) + 64U : maxsize;
status = FT_SetUSBParameters(ftHandle, maxsize, 0); status = FT_SetUSBParameters(ftHandle, maxsize, 0);
if (status != FT_OK){ if (status != FT_OK){
@ -249,9 +249,9 @@ bool CDV3003::OpenDevice(const std::string &serialno, const std::string &desc, E
return false; return false;
} }
bool CDV3003::InitDV3003() bool CDVDevice::InitDV3003()
{ {
SDV3003_Packet responsePacket, ctrlPacket; SDV_Packet responsePacket, ctrlPacket;
// ********** soft reset ************* // ********** soft reset *************
ctrlPacket.start_byte = PKT_HEADER; ctrlPacket.start_byte = PKT_HEADER;
@ -385,15 +385,15 @@ bool CDV3003::InitDV3003()
return false; return false;
} }
void CDV3003::Start() void CDVDevice::Start()
{ {
feedFuture = std::async(std::launch::async, &CDV3003::FeedDevice, this); feedFuture = std::async(std::launch::async, &CDVDevice::FeedDevice, this);
readFuture = std::async(std::launch::async, &CDV3003::ReadDevice, this); readFuture = std::async(std::launch::async, &CDVDevice::ReadDevice, this);
} }
bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type) bool CDVDevice::ConfigureVocoder(uint8_t pkt_ch, Encoding type)
{ {
SDV3003_Packet controlPacket, responsePacket; SDV_Packet controlPacket, responsePacket;
const uint8_t ecmode[] { PKT_ECMODE, 0x0, 0x0 }; const uint8_t ecmode[] { PKT_ECMODE, 0x0, 0x0 };
const uint8_t dcmode[] { PKT_DCMODE, 0x0, 0x0 }; const uint8_t dcmode[] { PKT_DCMODE, 0x0, 0x0 };
const uint8_t dstar[] { PKT_RATEP, 0x01U, 0x30U, 0x07U, 0x63U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x48U }; const uint8_t dstar[] { PKT_RATEP, 0x01U, 0x30U, 0x07U, 0x63U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x48U };
@ -406,7 +406,7 @@ bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type)
controlPacket.start_byte = PKT_HEADER; controlPacket.start_byte = PKT_HEADER;
controlPacket.header.payload_length = htons(1 + sizeof(SDV3003_Packet::payload.codec)); controlPacket.header.payload_length = htons(1 + sizeof(SDV_Packet::payload.codec));
controlPacket.header.packet_type = PKT_CONTROL; controlPacket.header.packet_type = PKT_CONTROL;
controlPacket.field_id = pkt_ch; controlPacket.field_id = pkt_ch;
memcpy(controlPacket.payload.codec.ecmode, ecmode, 3); memcpy(controlPacket.payload.codec.ecmode, ecmode, 3);
@ -457,7 +457,7 @@ bool CDV3003::ConfigureVocoder(uint8_t pkt_ch, Encoding type)
return false; return false;
} }
bool CDV3003::GetResponse(SDV3003_Packet &packet) bool CDVDevice::GetResponse(SDV_Packet &packet)
{ {
FT_STATUS status; FT_STATUS status;
DWORD bytes_read; DWORD bytes_read;
@ -512,7 +512,7 @@ bool CDV3003::GetResponse(SDV3003_Packet &packet)
return false; return false;
} }
void CDV3003::FeedDevice() void CDVDevice::FeedDevice()
{ {
const std::string modules(TRANSCODED_MODULES); const std::string modules(TRANSCODED_MODULES);
const auto n = modules.size(); const auto n = modules.size();
@ -557,7 +557,7 @@ void CDV3003::FeedDevice()
} }
} }
void CDV3003::ReadDevice() void CDVDevice::ReadDevice()
{ {
while (keep_running) while (keep_running)
{ {
@ -587,7 +587,7 @@ void CDV3003::ReadDevice()
} }
} }
dv3003_packet p; SDV_Packet p;
if (! GetResponse(p)) if (! GetResponse(p))
{ {
unsigned int channel = p.field_id - PKT_CHANNEL0; unsigned int channel = p.field_id - PKT_CHANNEL0;
@ -631,15 +631,15 @@ void CDV3003::ReadDevice()
} }
} }
void CDV3003::AddPacket(const std::shared_ptr<CTranscoderPacket> packet) void CDVDevice::AddPacket(const std::shared_ptr<CTranscoderPacket> packet)
{ {
input_queue.push(packet); input_queue.push(packet);
} }
bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const bool CDVDevice::SendAudio(const uint8_t channel, const int16_t *audio) const
{ {
// Create Audio packet based on input int8_ts // Create Audio packet based on input int8_ts
SDV3003_Packet p; SDV_Packet p;
p.start_byte = PKT_HEADER; p.start_byte = PKT_HEADER;
const uint16_t len = 323; const uint16_t len = 323;
p.header.payload_length = htons(len); p.header.payload_length = htons(len);
@ -668,10 +668,10 @@ bool CDV3003::SendAudio(const uint8_t channel, const int16_t *audio) const
return false; return false;
} }
bool CDV3003::SendData(const uint8_t channel, const uint8_t *data) const bool CDVDevice::SendData(const uint8_t channel, const uint8_t *data) const
{ {
// Create data packet // Create data packet
SDV3003_Packet p; SDV_Packet p;
p.start_byte = PKT_HEADER; p.start_byte = PKT_HEADER;
p.header.payload_length = htons(12); p.header.payload_length = htons(12);
p.header.packet_type = PKT_CHANNEL; p.header.packet_type = PKT_CHANNEL;
@ -698,7 +698,7 @@ bool CDV3003::SendData(const uint8_t channel, const uint8_t *data) const
return false; return false;
} }
void CDV3003::dump(const char *title, void *pointer, int length) const void CDVDevice::dump(const char *title, void *pointer, int length) const
{ {
const uint8_t *data = (const uint8_t *)pointer; const uint8_t *data = (const uint8_t *)pointer;

@ -57,7 +57,7 @@
#define packet_size(a) int(4 + ntohs((a).header.payload_length)) #define packet_size(a) int(4 + ntohs((a).header.payload_length))
#pragma pack(push, 1) #pragma pack(push, 1)
struct dv3003_packet { struct dv_packet_tag {
uint8_t start_byte; uint8_t start_byte;
struct { struct {
uint16_t payload_length; uint16_t payload_length;
@ -96,15 +96,15 @@ struct dv3003_packet {
}; };
#pragma pack(pop) #pragma pack(pop)
using SDV3003_Packet = struct dv3003_packet; using SDV_Packet = struct dv_packet_tag;
enum class Encoding { dstar, dmrsf }; enum class Encoding { dstar, dmrsf };
enum class Edvtype { dv3000, dv3003 }; enum class Edvtype { dv3000, dv3003 };
class CDV3003 { class CDVDevice {
public: public:
CDV3003(Encoding t); CDVDevice(Encoding t);
~CDV3003(); ~CDVDevice();
bool OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype); bool OpenDevice(const std::string &serialno, const std::string &desc, Edvtype dvtype);
void Start(); void Start();
void CloseDevice(); void CloseDevice();
@ -127,9 +127,9 @@ private:
void ReadDevice(); void ReadDevice();
bool InitDV3003(); bool InitDV3003();
bool ConfigureVocoder(uint8_t pkt_ch, Encoding type); bool ConfigureVocoder(uint8_t pkt_ch, Encoding type);
bool checkResponse(SDV3003_Packet &responsePacket, uint8_t response) const; bool checkResponse(SDV_Packet &responsePacket, uint8_t response) const;
bool SendAudio(const uint8_t channel, const int16_t *audio) const; bool SendAudio(const uint8_t channel, const int16_t *audio) const;
bool SendData(const uint8_t channel, const uint8_t *data) const; bool SendData(const uint8_t channel, const uint8_t *data) const;
bool GetResponse(SDV3003_Packet &packet); bool GetResponse(SDV_Packet &packet);
void dump(const char *title, void *data, int length) const; void dump(const char *title, void *data, int length) const;
}; };
Loading…
Cancel
Save

Powered by TurnKey Linux.