mirror of
https://github.com/LX3JL/xlxd.git
synced 2026-04-05 22:45:24 +00:00
amber version 1.1.0
Added ThumDV / USB-3000 support
This commit is contained in:
parent
cf9fc5181f
commit
41465e236d
9 changed files with 604 additions and 225 deletions
|
|
@ -125,10 +125,128 @@ CVocodecChannel *CUsb3003Interface::GetChannelWithChannelOut(int iCh)
|
|||
return Channel;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// decoder helper
|
||||
|
||||
bool CUsb3003Interface::IsValidChannelPacket(const CBuffer &buffer, int *ch, CAmbePacket *packet)
|
||||
{
|
||||
bool valid = false;
|
||||
uint8 tag[] = { PKT_HEADER,0x00,0x0C,PKT_CHANNEL };
|
||||
|
||||
if ( (buffer.size() == 16) && (buffer.Compare(tag, sizeof(tag)) == 0))
|
||||
{
|
||||
*ch = buffer.data()[4] - PKT_CHANNEL0;
|
||||
if ( *ch == 0 )
|
||||
packet->SetCodec(CODEC_AMBEPLUS);
|
||||
else if ( *ch == 1 )
|
||||
packet->SetCodec(CODEC_AMBE2PLUS);
|
||||
else
|
||||
packet->SetCodec(CODEC_NONE);
|
||||
packet->SetAmbe(&(buffer.data()[7]));
|
||||
valid = (*ch < GetNbChannels());
|
||||
//std::cout << "CHAN " << *ch << " " << buffer.size() << " " << (int)buffer[6] << std::endl;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool CUsb3003Interface::IsValidSpeechPacket(const CBuffer &buffer, int *ch, CVoicePacket *packet)
|
||||
{
|
||||
bool valid = false;
|
||||
|
||||
if ( (buffer.size() > 6) &&
|
||||
(buffer.data()[0] == PKT_HEADER) && (buffer.data()[3] == PKT_SPEECH) &&
|
||||
(buffer.data()[5] == PKT_SPEECHD) )
|
||||
{
|
||||
*ch = buffer.data()[4] - PKT_CHANNEL0;
|
||||
packet->SetVoice(&(buffer.data()[7]), buffer.data()[6] * 2);
|
||||
valid = (*ch < GetNbChannels());
|
||||
//std::cout << "SPCH " << *ch << " " << buffer.size() << std::endl;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// encoder helpers
|
||||
|
||||
void CUsb3003Interface::EncodeChannelPacket(CBuffer *buffer, int ch, CAmbePacket *packet)
|
||||
{
|
||||
uint size = (uint16)packet->GetAmbeSize() + 3;
|
||||
buffer->clear();
|
||||
buffer->Append((uint8)PKT_HEADER);
|
||||
buffer->Append((uint8)HIBYTE(size));
|
||||
buffer->Append((uint8)LOBYTE(size));
|
||||
buffer->Append((uint8)PKT_CHANNEL);
|
||||
buffer->Append((uint8)(PKT_CHANNEL0+ch));
|
||||
buffer->Append((uint8)(PKT_CHAND));
|
||||
buffer->Append((uint8)(packet->GetAmbeSize()*8));
|
||||
buffer->Append(packet->GetAmbe(), packet->GetAmbeSize());
|
||||
}
|
||||
|
||||
void CUsb3003Interface::EncodeSpeechPacket(CBuffer *buffer, int ch, CVoicePacket *packet)
|
||||
{
|
||||
uint16 size = (uint16)packet->GetVoiceSize() + 3;
|
||||
buffer->clear();
|
||||
buffer->Append((uint8)PKT_HEADER);
|
||||
buffer->Append((uint8)HIBYTE(size));
|
||||
buffer->Append((uint8)LOBYTE(size));
|
||||
buffer->Append((uint8)PKT_SPEECH);
|
||||
buffer->Append((uint8)(PKT_CHANNEL0+ch));
|
||||
buffer->Append((uint8)PKT_SPEECHD);
|
||||
buffer->Append((uint8)(packet->GetVoiceSize()/2));
|
||||
buffer->Append(packet->GetVoice(), packet->GetVoiceSize());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// low level
|
||||
|
||||
bool CUsb3003Interface::SoftResetDevice(void)
|
||||
bool CUsb3003Interface::OpenDevice(void)
|
||||
{
|
||||
FT_STATUS ftStatus;
|
||||
int baudrate = 921600;
|
||||
|
||||
//sets serial VID/PID for a Standard Device NOTE: This is for legacy purposes only. This can be ommitted.
|
||||
ftStatus = FT_SetVIDPID(m_uiVid, m_uiPid);
|
||||
if (ftStatus != FT_OK) {FTDI_Error((char *)"FT_SetVIDPID", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_OpenEx((PVOID)m_szDeviceName, FT_OPEN_BY_DESCRIPTION, &m_FtdiHandle);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_OpenEx", ftStatus ); return false; }
|
||||
|
||||
CTimePoint::TaskSleepFor(50);
|
||||
FT_Purge(m_FtdiHandle, FT_PURGE_RX | FT_PURGE_TX );
|
||||
CTimePoint::TaskSleepFor(50);
|
||||
|
||||
ftStatus = FT_SetDataCharacteristics(m_FtdiHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
|
||||
if ( ftStatus != FT_OK ) { FTDI_Error((char *)"FT_SetDataCharacteristics", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_SetFlowControl(m_FtdiHandle, FT_FLOW_RTS_CTS, 0x11, 0x13);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetFlowControl", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_SetRts (m_FtdiHandle);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetRts", ftStatus ); return false; }
|
||||
|
||||
//for usb-3012 pull DTR high to take AMBE3003 out of reset.
|
||||
//for other devices noting is connected to DTR so it is a dont care
|
||||
ftStatus = FT_ClrDtr(m_FtdiHandle);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_ClrDtr", ftStatus); return false; }
|
||||
|
||||
ftStatus = FT_SetBaudRate(m_FtdiHandle, baudrate );
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetBaudRate", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_SetLatencyTimer(m_FtdiHandle, 4);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetLatencyTimer", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_SetUSBParameters(m_FtdiHandle, USB3XXX_MAXPACKETSIZE, 0);
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetUSBParameters", ftStatus ); return false; }
|
||||
|
||||
ftStatus = FT_SetTimeouts(m_FtdiHandle, 200, 200 );
|
||||
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetTimeouts", ftStatus ); return false; }
|
||||
|
||||
// done
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CUsb3003Interface::ResetDevice(void)
|
||||
{
|
||||
bool ok = false;
|
||||
FT_STATUS ftStatus;
|
||||
|
|
@ -146,7 +264,7 @@ bool CUsb3003Interface::SoftResetDevice(void)
|
|||
ok = ((len == 7) && (rxpacket[4] == PKT_READY));
|
||||
if ( !ok )
|
||||
{
|
||||
std::cout << "USB-3xxx soft reset failed" << std::endl;
|
||||
std::cout << "USB-3003 hard reset failed" << std::endl;
|
||||
}
|
||||
|
||||
// done
|
||||
|
|
@ -168,9 +286,6 @@ bool CUsb3003Interface::ConfigureDevice(void)
|
|||
ok &= ConfigureChannel(PKT_CHANNEL0+i, pkt_ratep_ambeplus, 0, 0);
|
||||
break;
|
||||
case CODEC_AMBE2PLUS:
|
||||
//ok &= ConfigureChannel(PKT_CHANNEL0+i, pkt_ratep_ambe2plus, -12, 0); // DSTAR->DMR ok
|
||||
//ok &= ConfigureChannel(PKT_CHANNEL0+i, pkt_ratep_ambe2plus, 0, +10); // DMR->DSTAR ok
|
||||
//ok &= ConfigureChannel(PKT_CHANNEL0+i, pkt_ratep_ambe2plus, -12, +10); // not ok!
|
||||
ok &= ConfigureChannel(PKT_CHANNEL0+i, pkt_ratep_ambe2plus, 0, 0);
|
||||
break;
|
||||
case CODEC_NONE:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue