|
|
|
@ -53,17 +53,17 @@ CUsb3003Interface::CUsb3003Interface(uint32 uiVid, uint32 uiPid, const char *szD
|
|
|
|
bool CUsb3003Interface::Init(uint8 uiOddCodec)
|
|
|
|
bool CUsb3003Interface::Init(uint8 uiOddCodec)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
|
|
|
|
// init the odd channel
|
|
|
|
// init the odd channel
|
|
|
|
m_uiChCodecs[2] = uiOddCodec;
|
|
|
|
m_uiChCodecs[2] = uiOddCodec;
|
|
|
|
|
|
|
|
|
|
|
|
// base class
|
|
|
|
// base class
|
|
|
|
ok &= CUsb3xxxInterface::Init();
|
|
|
|
ok &= CUsb3xxxInterface::Init();
|
|
|
|
|
|
|
|
|
|
|
|
// do not create our channels now
|
|
|
|
// do not create our channels now
|
|
|
|
// this is delegated to caller (CVocodecs) as our channel
|
|
|
|
// this is delegated to caller (CVocodecs) as our channel
|
|
|
|
// may be hybrids between 2 interfaces in case of odd n' of channel device)
|
|
|
|
// may be hybrids between 2 interfaces in case of odd n' of channel device)
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
// done
|
|
|
|
return ok;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -88,7 +88,7 @@ CVocodecChannel *CUsb3003Interface::GetChannelWithChannelIn(int iCh)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CVocodecChannel *Channel = NULL;
|
|
|
|
CVocodecChannel *Channel = NULL;
|
|
|
|
bool done = false;
|
|
|
|
bool done = false;
|
|
|
|
for ( int i = 0; (i < m_Channels.size()) && !done; i++ )
|
|
|
|
for ( unsigned i = 0; (i < m_Channels.size()) && !done; i++ )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( iCh == 2 )
|
|
|
|
if ( iCh == 2 )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -114,7 +114,7 @@ CVocodecChannel *CUsb3003Interface::GetChannelWithChannelOut(int iCh)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CVocodecChannel *Channel = NULL;
|
|
|
|
CVocodecChannel *Channel = NULL;
|
|
|
|
bool done = false;
|
|
|
|
bool done = false;
|
|
|
|
for ( int i = 0; (i < m_Channels.size()) && !done; i++ )
|
|
|
|
for ( unsigned i = 0; (i < m_Channels.size()) && !done; i++ )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ( (m_Channels[i]->GetChannelOut() == iCh) && (m_Channels[i]->IsInterfaceOut(this)) )
|
|
|
|
if ( (m_Channels[i]->GetChannelOut() == iCh) && (m_Channels[i]->IsInterfaceOut(this)) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -132,7 +132,7 @@ bool CUsb3003Interface::IsValidChannelPacket(const CBuffer &buffer, int *ch, CAm
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool valid = false;
|
|
|
|
bool valid = false;
|
|
|
|
uint8 tag[] = { PKT_HEADER,0x00,0x0C,PKT_CHANNEL };
|
|
|
|
uint8 tag[] = { PKT_HEADER,0x00,0x0C,PKT_CHANNEL };
|
|
|
|
|
|
|
|
|
|
|
|
if ( (buffer.size() == 16) && (buffer.Compare(tag, sizeof(tag)) == 0))
|
|
|
|
if ( (buffer.size() == 16) && (buffer.Compare(tag, sizeof(tag)) == 0))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*ch = buffer.data()[4] - PKT_CHANNEL0;
|
|
|
|
*ch = buffer.data()[4] - PKT_CHANNEL0;
|
|
|
|
@ -152,7 +152,7 @@ bool CUsb3003Interface::IsValidChannelPacket(const CBuffer &buffer, int *ch, CAm
|
|
|
|
bool CUsb3003Interface::IsValidSpeechPacket(const CBuffer &buffer, int *ch, CVoicePacket *packet)
|
|
|
|
bool CUsb3003Interface::IsValidSpeechPacket(const CBuffer &buffer, int *ch, CVoicePacket *packet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool valid = false;
|
|
|
|
bool valid = false;
|
|
|
|
|
|
|
|
|
|
|
|
if ( (buffer.size() > 6) &&
|
|
|
|
if ( (buffer.size() > 6) &&
|
|
|
|
(buffer.data()[0] == PKT_HEADER) && (buffer.data()[3] == PKT_SPEECH) &&
|
|
|
|
(buffer.data()[0] == PKT_HEADER) && (buffer.data()[3] == PKT_SPEECH) &&
|
|
|
|
(buffer.data()[5] == PKT_SPEECHD) )
|
|
|
|
(buffer.data()[5] == PKT_SPEECHD) )
|
|
|
|
@ -204,44 +204,44 @@ bool CUsb3003Interface::OpenDevice(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FT_STATUS ftStatus;
|
|
|
|
FT_STATUS ftStatus;
|
|
|
|
int baudrate = 921600;
|
|
|
|
int baudrate = 921600;
|
|
|
|
|
|
|
|
|
|
|
|
//sets serial VID/PID for a Standard Device NOTE: This is for legacy purposes only. This can be ommitted.
|
|
|
|
//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);
|
|
|
|
ftStatus = FT_SetVIDPID(m_uiVid, m_uiPid);
|
|
|
|
if (ftStatus != FT_OK) {FTDI_Error((char *)"FT_SetVIDPID", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) {FTDI_Error((char *)"FT_SetVIDPID", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_OpenEx((PVOID)m_szDeviceSerial, FT_OPEN_BY_SERIAL_NUMBER, &m_FtdiHandle);
|
|
|
|
ftStatus = FT_OpenEx((PVOID)m_szDeviceSerial, FT_OPEN_BY_SERIAL_NUMBER, &m_FtdiHandle);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_OpenEx", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_OpenEx", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
CTimePoint::TaskSleepFor(50);
|
|
|
|
CTimePoint::TaskSleepFor(50);
|
|
|
|
FT_Purge(m_FtdiHandle, FT_PURGE_RX | FT_PURGE_TX );
|
|
|
|
FT_Purge(m_FtdiHandle, FT_PURGE_RX | FT_PURGE_TX );
|
|
|
|
CTimePoint::TaskSleepFor(50);
|
|
|
|
CTimePoint::TaskSleepFor(50);
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetDataCharacteristics(m_FtdiHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
|
|
|
|
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; }
|
|
|
|
if ( ftStatus != FT_OK ) { FTDI_Error((char *)"FT_SetDataCharacteristics", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetFlowControl(m_FtdiHandle, FT_FLOW_RTS_CTS, 0x11, 0x13);
|
|
|
|
ftStatus = FT_SetFlowControl(m_FtdiHandle, FT_FLOW_RTS_CTS, 0x11, 0x13);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetFlowControl", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetFlowControl", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetRts (m_FtdiHandle);
|
|
|
|
ftStatus = FT_SetRts (m_FtdiHandle);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetRts", ftStatus ); return false; }
|
|
|
|
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 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
|
|
|
|
//for other devices noting is connected to DTR so it is a dont care
|
|
|
|
ftStatus = FT_ClrDtr(m_FtdiHandle);
|
|
|
|
ftStatus = FT_ClrDtr(m_FtdiHandle);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_ClrDtr", ftStatus); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_ClrDtr", ftStatus); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetBaudRate(m_FtdiHandle, baudrate );
|
|
|
|
ftStatus = FT_SetBaudRate(m_FtdiHandle, baudrate );
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetBaudRate", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetBaudRate", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetLatencyTimer(m_FtdiHandle, 4);
|
|
|
|
ftStatus = FT_SetLatencyTimer(m_FtdiHandle, 4);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetLatencyTimer", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetLatencyTimer", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetUSBParameters(m_FtdiHandle, USB3XXX_MAXPACKETSIZE, 0);
|
|
|
|
ftStatus = FT_SetUSBParameters(m_FtdiHandle, USB3XXX_MAXPACKETSIZE, 0);
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetUSBParameters", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetUSBParameters", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
ftStatus = FT_SetTimeouts(m_FtdiHandle, 200, 200 );
|
|
|
|
ftStatus = FT_SetTimeouts(m_FtdiHandle, 200, 200 );
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetTimeouts", ftStatus ); return false; }
|
|
|
|
if (ftStatus != FT_OK) { FTDI_Error((char *)"FT_SetTimeouts", ftStatus ); return false; }
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
// done
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -265,20 +265,20 @@ bool CUsb3003Interface::ResetDevice(void)
|
|
|
|
PKT_PARITYBYTE,
|
|
|
|
PKT_PARITYBYTE,
|
|
|
|
3 ^ PKT_RESET ^ PKT_PARITYBYTE
|
|
|
|
3 ^ PKT_RESET ^ PKT_PARITYBYTE
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//the chip might be in a state where it is waiting to receive bytes from a prior incomplete packet.
|
|
|
|
//the chip might be in a state where it is waiting to receive bytes from a prior incomplete packet.
|
|
|
|
//first send 350 zeros in case, the chip's receive state is still waiting for characters
|
|
|
|
//first send 350 zeros in case, the chip's receive state is still waiting for characters
|
|
|
|
//if we send more than needed, the exta characters will just get discarded since they do not match the header byte
|
|
|
|
//if we send more than needed, the exta characters will just get discarded since they do not match the header byte
|
|
|
|
//after that we send PKT_RESET to reset the device
|
|
|
|
//after that we send PKT_RESET to reset the device
|
|
|
|
//As long as the AMBE3000 is able to receive via uart, this method will succeed in resetting it.
|
|
|
|
//As long as the AMBE3000 is able to receive via uart, this method will succeed in resetting it.
|
|
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < 35 ; i++ )
|
|
|
|
for ( int i = 0; i < 35 ; i++ )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FTDI_write_packet(m_FtdiHandle, zeropacket, sizeof(zeropacket));
|
|
|
|
FTDI_write_packet(m_FtdiHandle, zeropacket, sizeof(zeropacket));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// write soft-reset packet
|
|
|
|
// write soft-reset packet
|
|
|
|
if ( FTDI_write_packet(m_FtdiHandle, txpacket, sizeof(txpacket)) )
|
|
|
|
if ( FTDI_write_packet(m_FtdiHandle, txpacket, sizeof(txpacket)) )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -290,7 +290,7 @@ bool CUsb3003Interface::ResetDevice(void)
|
|
|
|
std::cout << "USB-3003 soft reset failed" << std::endl;
|
|
|
|
std::cout << "USB-3003 soft reset failed" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
// done
|
|
|
|
return ok;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -300,7 +300,7 @@ bool CUsb3003Interface::ConfigureDevice(void)
|
|
|
|
bool ok = true;
|
|
|
|
bool ok = true;
|
|
|
|
uint8 pkt_ratep_ambeplus[] = { 0x01,0x30,0x07,0x63,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x48 };
|
|
|
|
uint8 pkt_ratep_ambeplus[] = { 0x01,0x30,0x07,0x63,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x48 };
|
|
|
|
uint8 pkt_ratep_ambe2plus[] = { 0x04,0x31,0x07,0x54,0x24,0x00,0x00,0x00,0x00,0x00,0x6F,0x48 };
|
|
|
|
uint8 pkt_ratep_ambe2plus[] = { 0x04,0x31,0x07,0x54,0x24,0x00,0x00,0x00,0x00,0x00,0x6F,0x48 };
|
|
|
|
|
|
|
|
|
|
|
|
// configure each channels for desired codec
|
|
|
|
// configure each channels for desired codec
|
|
|
|
for ( int i = 0; i < USB3003_NB_CH; i++ )
|
|
|
|
for ( int i = 0; i < USB3003_NB_CH; i++ )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -321,4 +321,3 @@ bool CUsb3003Interface::ConfigureDevice(void)
|
|
|
|
// done
|
|
|
|
// done
|
|
|
|
return ok;
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|