From 71cddc2f5a2e9f01172255d0190f90dd9f7b9ce5 Mon Sep 17 00:00:00 2001 From: LX3JL Date: Mon, 25 Jun 2018 18:41:24 +0200 Subject: [PATCH] amber 1.3.2 fixed problem while running multiple 3006 or 3012 devices adjusted load sharing when running multiple devices --- ambed/cftdidevicedescr.cpp | 77 +++++++++++++++++++++++++------------ ambed/cftdidevicedescr.h | 13 ++++--- ambed/cusb3003interface.cpp | 4 +- ambed/cvocodecs.cpp | 47 +++++++++++++++++++--- ambed/main.h | 2 +- ambed/readme | 2 +- 6 files changed, 106 insertions(+), 39 deletions(-) diff --git a/ambed/cftdidevicedescr.cpp b/ambed/cftdidevicedescr.cpp index 90aaa4d..e17f4e8 100644 --- a/ambed/cftdidevicedescr.cpp +++ b/ambed/cftdidevicedescr.cpp @@ -132,6 +132,33 @@ int CFtdiDeviceDescr::CreateInterfacePair(CFtdiDeviceDescr *descr1, CFtdiDeviceD //////////////////////////////////////////////////////////////////////////////////////// // get +const char * CFtdiDeviceDescr::GetChannelDescription(int ch) const +{ + static char descr[FTDI_MAX_STRINGLENGTH]; + char tag[3] = "_X"; + + ::strcpy(descr, GetDescription()); + if ( ::strlen(descr) >= 2 ) + { + descr[::strlen(descr)-2] = 0x00; + tag[1] = (char)ch + 'A'; + ::strcat(descr, tag); + } + return descr; +} + +const char * CFtdiDeviceDescr::GetChannelSerialNumber(int ch) const +{ + static char serial[FTDI_MAX_STRINGLENGTH]; + + ::strcpy(serial, GetSerialNumber()); + if ( ::strlen(serial) >= 1 ) + { + serial[::strlen(serial)-1] = (char)ch + 'A'; + } + return serial; +} + int CFtdiDeviceDescr::GetNbChannels(void) const { int iNbChs = 0; @@ -180,13 +207,13 @@ int CFtdiDeviceDescr::CreateUsb3012(CFtdiDeviceDescr *descr, std::vectorGetVid(), descr->GetPid(), "USB-3012_A", descr->GetSerialNumber()); + new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(0), descr->GetChannelSerialNumber(0)); CUsb3003HRInterface *Usb3003B = - new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), "USB-3012_B", descr->GetSerialNumber()); + new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(1), descr->GetChannelSerialNumber(1)); CUsb3003HRInterface *Usb3003C = - new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), "USB-3012_C", descr->GetSerialNumber()); + new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(2), descr->GetChannelSerialNumber(2)); CUsb3003HRInterface *Usb3003D = - new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), "USB-3012_D", descr->GetSerialNumber()); + new CUsb3003HRInterface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(3), descr->GetChannelSerialNumber(3)); // init the interfaces if ( Usb3003A->Init(CODEC_AMBEPLUS) && Usb3003B->Init(CODEC_AMBE2PLUS) && @@ -212,31 +239,31 @@ int CFtdiDeviceDescr::CreateUsb3012(CFtdiDeviceDescr *descr, std::vectorpush_back(Channel); Usb3003B->AddChannel(Channel); // ch5 - Channel = new CVocodecChannel(Usb3003C, 0, Usb3003C, 1, CODECGAIN_AMBEPLUS); - channels->push_back(Channel); - Usb3003C->AddChannel(Channel); - // ch6 - Channel = new CVocodecChannel(Usb3003C, 1, Usb3003C, 0, CODECGAIN_AMBE2PLUS); - channels->push_back(Channel); - Usb3003C->AddChannel(Channel); - // ch7 - Channel = new CVocodecChannel(Usb3003D, 0, Usb3003D, 1, CODECGAIN_AMBEPLUS); - channels->push_back(Channel); - Usb3003D->AddChannel(Channel); - // ch8 - Channel = new CVocodecChannel(Usb3003D, 1, Usb3003D, 0, CODECGAIN_AMBE2PLUS); - channels->push_back(Channel); - Usb3003D->AddChannel(Channel); - // ch9 Channel = new CVocodecChannel(Usb3003A, 2, Usb3003B, 2, CODECGAIN_AMBEPLUS); channels->push_back(Channel); Usb3003A->AddChannel(Channel); Usb3003B->AddChannel(Channel); - // ch10 + // ch6 Channel = new CVocodecChannel(Usb3003B, 2, Usb3003A, 2, CODECGAIN_AMBE2PLUS); channels->push_back(Channel); Usb3003A->AddChannel(Channel); Usb3003B->AddChannel(Channel); + // ch7 + Channel = new CVocodecChannel(Usb3003C, 0, Usb3003C, 1, CODECGAIN_AMBEPLUS); + channels->push_back(Channel); + Usb3003C->AddChannel(Channel); + // ch8 + Channel = new CVocodecChannel(Usb3003C, 1, Usb3003C, 0, CODECGAIN_AMBE2PLUS); + channels->push_back(Channel); + Usb3003C->AddChannel(Channel); + // ch9 + Channel = new CVocodecChannel(Usb3003D, 0, Usb3003D, 1, CODECGAIN_AMBEPLUS); + channels->push_back(Channel); + Usb3003D->AddChannel(Channel); + // ch10 + Channel = new CVocodecChannel(Usb3003D, 1, Usb3003D, 0, CODECGAIN_AMBE2PLUS); + channels->push_back(Channel); + Usb3003D->AddChannel(Channel); // ch11 Channel = new CVocodecChannel(Usb3003C, 2, Usb3003D, 2, CODECGAIN_AMBEPLUS); channels->push_back(Channel); @@ -273,13 +300,13 @@ int CFtdiDeviceDescr::CreateUsb3012(CFtdiDeviceDescr *descr, std::vector*channels) { - int nStreams = 0; + int nStreams = 0; - // create the interfaces for the four 3003 chips + // create the interfaces for the two 3003 chips CUsb3003Interface *Usb3003A = - new CUsb3003Interface(descr->GetVid(), descr->GetPid(), "USB-3006_A", descr->GetSerialNumber()); + new CUsb3003Interface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(0), descr->GetChannelSerialNumber(0)); CUsb3003Interface *Usb3003B = - new CUsb3003Interface(descr->GetVid(), descr->GetPid(), "USB-3006_B", descr->GetSerialNumber()); + new CUsb3003Interface(descr->GetVid(), descr->GetPid(), descr->GetChannelDescription(1), descr->GetChannelSerialNumber(1)); // init the interfaces if ( Usb3003A->Init(CODEC_AMBEPLUS) && Usb3003B->Init(CODEC_AMBE2PLUS) ) diff --git a/ambed/cftdidevicedescr.h b/ambed/cftdidevicedescr.h index c01b485..15fa362 100644 --- a/ambed/cftdidevicedescr.h +++ b/ambed/cftdidevicedescr.h @@ -58,12 +58,15 @@ public: static int CreateInterfacePair(CFtdiDeviceDescr *, CFtdiDeviceDescr *, std::vector*); // get - bool IsUsed(void) const { return m_bUsed; } + bool IsUsed(void) const { return m_bUsed; } int GetNbChannels(void) const; - uint32 GetVid(void) const { return m_uiVid; } - uint32 GetPid(void) const { return m_uiPid; } - const char *GetDescription(void) const { return m_szDescription; } - const char *GetSerialNumber(void) const { return m_szSerial; } + uint32 GetVid(void) const { return m_uiVid; } + uint32 GetPid(void) const { return m_uiPid; } + const char *GetDescription(void) const { return m_szDescription; } + const char *GetSerialNumber(void) const { return m_szSerial; } + const char * GetChannelDescription(int) const; + const char * GetChannelSerialNumber(int) const; + // set void SetUsed(bool used) { m_bUsed = used; } diff --git a/ambed/cusb3003interface.cpp b/ambed/cusb3003interface.cpp index 309680c..471dc39 100644 --- a/ambed/cusb3003interface.cpp +++ b/ambed/cusb3003interface.cpp @@ -209,9 +209,9 @@ bool CUsb3003Interface::OpenDevice(void) 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); + 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; } - + CTimePoint::TaskSleepFor(50); FT_Purge(m_FtdiHandle, FT_PURGE_RX | FT_PURGE_TX ); CTimePoint::TaskSleepFor(50); diff --git a/ambed/cvocodecs.cpp b/ambed/cvocodecs.cpp index 3981e0a..aa28707 100644 --- a/ambed/cvocodecs.cpp +++ b/ambed/cvocodecs.cpp @@ -88,13 +88,14 @@ bool CVocodecs::Init(void) // and create interfaces for the discovered devices // first handle all even number of channels devices + std::vector Multi3003DevicesChs; for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr = m_FtdiDeviceDescrs[i]; if ( !descr->IsUsed() && IsEven(descr->GetNbChannels()) ) { // create the object - iNbCh += CFtdiDeviceDescr::CreateInterface(descr, &m_Channels); + iNbCh += CFtdiDeviceDescr::CreateInterface(descr, &Multi3003DevicesChs); // and flag as used descr->SetUsed(true); } @@ -102,6 +103,7 @@ bool CVocodecs::Init(void) // next handle all single channel devices. // they must be handeled in pair, or in pair with another // even number of channels device. + std::vector PairsOf3000DevicesChs; for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr1 = m_FtdiDeviceDescrs[i]; @@ -120,15 +122,16 @@ bool CVocodecs::Init(void) if ( found ) { // yes, create and pairboth interfaces - iNbCh += CFtdiDeviceDescr::CreateInterfacePair(descr1, descr2, &m_Channels); + iNbCh += CFtdiDeviceDescr::CreateInterfacePair(descr1, descr2, &PairsOf3000DevicesChs); // and flag as used descr1->SetUsed(true); descr2->SetUsed(true); } } } - // now we should have only remaining the 3 chennels device(s) + // now we should have only remaining the 3 channels device(s) // and possibly an unique single channel device + std::vector Single3003DeviceChannels; for ( int i = 0; i < m_FtdiDeviceDescrs.size(); i++ ) { CFtdiDeviceDescr *descr1 = m_FtdiDeviceDescrs[i]; @@ -148,7 +151,7 @@ bool CVocodecs::Init(void) if ( found ) { // yes, create and pairboth interfaces - iNbCh += CFtdiDeviceDescr::CreateInterfacePair(descr1, descr2, &m_Channels); + iNbCh += CFtdiDeviceDescr::CreateInterfacePair(descr1, descr2, &Multi3003DevicesChs); // and flag as used descr1->SetUsed(true); descr2->SetUsed(true); @@ -156,13 +159,47 @@ bool CVocodecs::Init(void) else { // no, just create a standalone 3003 interface - iNbCh += CFtdiDeviceDescr::CreateInterface(descr1, &m_Channels); + iNbCh += CFtdiDeviceDescr::CreateInterface(descr1, &Single3003DeviceChannels); // and flag as used descr1->SetUsed(true); } } } + // now agregate channels by order of priority + // for proper load sharing + // pairs of 300 devices first + { + for ( int i = 0; i < PairsOf3000DevicesChs.size(); i++ ) + { + m_Channels.push_back(PairsOf3000DevicesChs.at(i)); + } + PairsOf3000DevicesChs.clear(); + } + // next the left-over single 3003 device + { + for ( int i = 0; i < Single3003DeviceChannels.size(); i++ ) + { + m_Channels.push_back(Single3003DeviceChannels.at(i)); + } + Single3003DeviceChannels.clear(); + } + // and finally interlace multi-3003 and pairs of 3003 devices which always + // results to 6 channels per pair of 3003 + { + int n = (int)Multi3003DevicesChs.size() / 6; + for ( int i = 0; i < 6; i++ ) + { + for ( int j = 0; j < n; j++ ) + { + m_Channels.push_back(Multi3003DevicesChs.at((j*6) + i)); + } + } + Multi3003DevicesChs.clear(); + } + + + // done if ( ok ) { std::cout << "Codec interfaces initialized successfully : " << iNbCh << " channels available" << std::endl; diff --git a/ambed/main.h b/ambed/main.h index 689d43c..a432f36 100644 --- a/ambed/main.h +++ b/ambed/main.h @@ -49,7 +49,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 -#define VERSION_REVISION 1 +#define VERSION_REVISION 2 // global ------------------------------------------------------ diff --git a/ambed/readme b/ambed/readme index 52305d4..bfd8583 100644 --- a/ambed/readme +++ b/ambed/readme @@ -22,7 +22,7 @@ // along with Foobar. If not, see . // ---------------------------------------------------------------------------- -VERSION: 1.3.1 +VERSION: 1.3.2 Hardware compatibility. ======================