Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two devices manual selection #210

Merged
merged 10 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/FX3Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class fx3class
virtual bool ReadDebugTrace(uint8_t* pdata, uint8_t len) = 0;
virtual void StartStream(ringbuffer<int16_t>& input, int numofblock) = 0;
virtual void StopStream() = 0;

virtual bool Enumerate(unsigned char& idx, char* lbuf, uint8_t* fw_data, uint32_t fw_size) = 0;
};

extern "C" fx3class* CreateUsbHandler();
Expand Down
5 changes: 5 additions & 0 deletions Core/arch/linux/FX3handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,8 @@ bool fx3handler::ReadDebugTrace(uint8_t* pdata, uint8_t len)
{
return true;
}

bool fx3handler::Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size)
{
return true; // TBD
}
1 change: 1 addition & 0 deletions Core/arch/linux/FX3handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class fx3handler : public fx3class
bool ReadDebugTrace(uint8_t* pdata, uint8_t len);
void StartStream(ringbuffer<int16_t>& input, int numofblock);
void StopStream();
bool Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size);

private:
bool ReadUsb(uint8_t command, uint16_t value, uint16_t index, uint8_t *data, size_t size);
Expand Down
131 changes: 39 additions & 92 deletions Core/arch/win32/FX3handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ fx3class* CreateUsbHandler()

fx3handler::fx3handler():
fx3dev (nullptr),
Fx3IsOn (false)
Fx3IsOn (false),
devidx (0)
{

}
Expand All @@ -33,111 +34,57 @@ fx3handler::~fx3handler() // reset USB device and exit
Close();
}

bool fx3handler::GetFx3Device() {
bool r = false;
if (fx3dev == nullptr) return r; // no device
int n = fx3dev->DeviceCount();
if (n == 0) return r; // no one

// Walk through all devices looking for VENDOR_ID/STREAMER_ID
for (int i = 0; i <= n; i++) {
fx3dev->Open(i); // go down the list of devices to find our device
if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID))
{
r = true;
break;
}
char* wchar2char(const wchar_t* wchar)
{
char* m_char;
int len = WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), NULL, 0, NULL, NULL);
m_char = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, wchar, wcslen(wchar), m_char, len, NULL, NULL);
m_char[len] = '\0';
return m_char;
}

if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == BOOTLOADER_ID))
{
r = true;
break;
}
}
bool fx3handler::GetFx3DeviceStreamer() { // open class
bool r = false;
if (fx3dev == NULL) return r;
fx3dev->Open(devidx);
if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID)) r = true;
if (r == false)
fx3dev->Close();
return r;
}

bool fx3handler::GetFx3DeviceStreamer(void) { // open class
bool fx3handler::Enumerate(unsigned char& idx, char* lbuf, uint8_t* fw_data, uint32_t fw_size)
{
bool r = false;
if (fx3dev == NULL) return r;
int n = fx3dev->DeviceCount();
// Walk through all devices looking for VENDOR_ID/STREAMER_ID
if (n == 0) return r;
// go down the list of devices to find STREAMER_ID device
for (int i = 0; i <= n; i++) {
fx3dev->Open(i);
if ((fx3dev->VendorID == VENDOR_ID) && (fx3dev->ProductID == STREAMER_ID))
{
r = true;
break;
strcpy(lbuf, "");
if (fx3dev == nullptr)
fx3dev = new CCyFX3Device; // instantiate the device
if (fx3dev == nullptr) return r; // return if failed
if (!fx3dev->Open(idx)) return r;
if (fx3dev->IsBootLoaderRunning()) {
if (fx3dev->DownloadFwToRam(fw_data, fw_size) != SUCCESS) {
DbgPrintf("Failed to DownloadFwToRam device(%x)\n", idx);
}
else {
fx3dev->Close();
Sleep(800); // wait after firmware change ?
fx3dev->Open(idx);
}
}
if (r == false)
fx3dev->Close();
return r;
strcpy (lbuf, fx3dev->DeviceName);
while (strlen(lbuf) < 18) strcat(lbuf, " ");
strcat(lbuf, "sn:");
strcat(lbuf, wchar2char((wchar_t*)fx3dev->SerialNumber));
fx3dev->Close();
devidx = idx; // -> devidx
return true;
}

bool fx3handler::Open(uint8_t* fw_data, uint32_t fw_size) {
bool r = false;
fx3dev = new CCyFX3Device; // instantiate the device
if (fx3dev == nullptr) return r; // return if failed
int n = fx3dev->DeviceCount();
if (n == 0) return r; // return if no devices connected
if (!GetFx3Device()) return r; // NO FX3 device connected

#ifdef _DEBUG
if (!fx3dev->IsBootLoaderRunning()) { // if not bootloader device
Control(RESETFX3); // reset the fx3 firmware via CyU3PDeviceReset(false)
DbgPrintf("DEBUG - Reset Firmware\n");
Sleep(300);
fx3dev->Close(); // close class
delete fx3dev; // destroy class
Sleep(300);
fx3dev = new CCyFX3Device; // create class
GetFx3Device(); // open class
}
#endif

FX3_FWDWNLOAD_ERROR_CODE dlf = SUCCESS;
if (fx3dev->IsBootLoaderRunning())
{
dlf = fx3dev->DownloadFwToRam(fw_data, fw_size);
Sleep(500); // wait for download to finish
}

if (dlf != 0)
{
DbgPrintf("MISSING/OLD FIRMWARE\n");
return false;
}
int x = 0;
int maxretry = 30;
CCyFX3Device* expdev = nullptr;
while (x++ < maxretry) // wait new firmware setup
{
bool r = false;
expdev = new CCyFX3Device; // instantiate the device
if (expdev != NULL)
int n = expdev->DeviceCount();
if (n > 0)
{
expdev->Open(0);
// go down the list of devices to find our device
for (int i = 1; i <= n; i++)
{
if ((expdev->VendorID == VENDOR_ID) && (expdev->ProductID == STREAMER_ID))
{
x = maxretry; //got it exit
}
}
}
expdev->Close(); // close class
delete expdev; // destroy class
}
GetFx3DeviceStreamer(); // open class with new ram firmware
if (!fx3dev->IsOpen()) {
if (!GetFx3DeviceStreamer()) {
DbgPrintf("Failed to open device\n");
return r;
}
Expand Down
5 changes: 3 additions & 2 deletions Core/arch/win32/FX3handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class fx3handler : public fx3class
public:
fx3handler();
virtual ~fx3handler(void);

bool Open(uint8_t* fw_data, uint32_t fw_size);
bool IsOn() { return Fx3IsOn; }
bool Control(FX3Command command, uint8_t data);
Expand All @@ -44,7 +45,7 @@ class fx3handler : public fx3class
bool ReadDebugTrace(uint8_t* pdata, uint8_t len);
void StartStream(ringbuffer<int16_t>& input, int numofblock);
void StopStream();

bool Enumerate(unsigned char &idx, char *lbuf, uint8_t* fw_data, uint32_t fw_size);
private:
bool SendI2cbytes(uint8_t i2caddr, uint8_t regaddr, uint8_t* pdata, uint8_t len);
bool ReadI2cbytes(uint8_t i2caddr, uint8_t regaddr, uint8_t* pdata, uint8_t len);
Expand All @@ -58,7 +59,6 @@ class fx3handler : public fx3class

std::thread *adc_samples_thread;

bool GetFx3Device();
bool GetFx3DeviceStreamer();
bool Fx3IsOn;
bool Close(void);
Expand All @@ -67,6 +67,7 @@ class fx3handler : public fx3class
ringbuffer<int16_t> *inputbuffer;
int numofblock;
bool run;
UCHAR devidx;
};


Expand Down
6 changes: 4 additions & 2 deletions Core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ inline void null_func(const char *format, ...) { }
#define DbgPrintf DbgEmpty
#endif

#define VERSION (1.2) // Dll version number x.xx
#define SWVERSION "1.2.1"
#define SWVERSION "1.3.0 RC1"
#define SETTINGS_IDENTIFIER "sddc_1.06"
#define SWNAME "ExtIO_sddc.dll"

Expand Down Expand Up @@ -77,6 +76,9 @@ enum rf_mode { NOMODE = 0, HFMODE = 0x1, VHFMODE = 0x2 };
#define URL_HDSR "http://www.hdsdr.de/"
#define URL_HDSDRA "<a>http://www.hdsdr.de/</a>"

#define MAXNDEV (4) // max number of SDR device connected to PC
#define MAXDEVSTRLEN (64) //max char len of SDR device description

extern bool saveADCsamplesflag;
extern uint32_t adcnominalfreq;

Expand Down
25 changes: 23 additions & 2 deletions ExtIO_sddc/ExtIO_sddc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ RadioHandlerClass RadioHandler;

HWND h_dialog = NULL;

DevContext devicelist; // list of FX3 devices

SplashWindow splashW;

#define IDD_SDDC_SETTINGS 100
Expand Down Expand Up @@ -212,12 +214,31 @@ bool __declspec(dllexport) __stdcall InitHW(char *name, char *model, int& type)
}

auto Fx3 = CreateUsbHandler();
unsigned char idx = 0;
int selected = 0;
while (Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size) && (idx < MAXNDEV))
{
// https://en.wikipedia.org/wiki/West_Bridge
int retry = 2;
while ((strncmp("WestBridge", devicelist.dev[idx],sizeof("WestBridge")) != NULL) && retry-- > 0)
Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size); // if it enumerates as BootLoader retry
idx++;
}
devicelist.numdev = idx;
if (idx > 1){
selected = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SELECTDEVICE), NULL, DlgSelectDevice, (LPARAM) &devicelist);
}
DbgPrintf("selected %d \n",selected);
idx = selected;
Fx3->Enumerate(idx, devicelist.dev[idx], res_data, res_size);

gbInitHW = Fx3->Open(res_data, res_size) &&
RadioHandler.Init(Fx3, Callback ); // Check if it there hardware
RadioHandler.Init(Fx3, Callback); // Check if it there hardware

#ifdef _DEBUG
RadioHandler.EnableDebug( printf_USB_cb , GetConsoleInput);
#endif

if (!gbInitHW)
{
MessageBox(NULL, "Is SDR powered on and connected ?\r\n\r\nPlease start HDSDR again",
Expand Down
2 changes: 2 additions & 0 deletions ExtIO_sddc/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define IDB_BITMAP2 106
#define IDD_DLG_HDSDR 107
#define IDD_DLG_HDSDR281 108
#define IDD_SELECTDEVICE 109
#define IDC_LW 1001
#define IDC_HF 1002
#define IDC_VHF 1003
Expand All @@ -30,6 +31,7 @@
#define IDC_CORRUPDATE 1019
#define IDC_FREQCANC 1020
#define IDC_CORRCANC 1021
#define IDC_LISTDEV 1030
#define RES_BIN_FIRMWARE 2000
#define IHK_CR 5001
#define IDE_EDIT_MAIN 40002
Expand Down
15 changes: 15 additions & 0 deletions ExtIO_sddc/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ PUSHBUTTON "Save ADC", IDC_ADCSAMPLES, 150, 70, 48, 13, BS_FLAT

END

/////////////////////////////////////////////////////////////////////////////
//
// Dialog SELECT DEVICE
//

IDD_SELECTDEVICE DIALOG DISCARDABLE 0, 0, 200, 68
STYLE DS_SETFONT | WS_CAPTION | WS_SYSMENU | DS_CENTER
CAPTION "ExtIO_sddc.dll Select FX3 Device"
//FONT 8, "Ms Shell Dlg"
FONT 10, "Lucida Console"
BEGIN
DEFPUSHBUTTON "OK", IDOK, 80, 48, 40, 14, WS_DISABLED | WS_TABSTOP
LISTBOX IDC_LISTDEV, 5, 5, 190, 48, WS_TABSTOP
END

/////////////////////////////////////////////////////////////////////////////
//
// RT_MANIFEST
Expand Down
63 changes: 63 additions & 0 deletions ExtIO_sddc/tdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,66 @@ BOOL CALLBACK DlgMainFn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE;

}



BOOL CALLBACK DlgSelectDevice(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int selindex = 0;
DevContext* p_devicelist;

// check message type
switch (uMsg)
{
case WM_INITDIALOG:
p_devicelist = (DevContext*) lParam;
for (int i = 0; i < p_devicelist->numdev; i++) {
ListBox_AddString(GetDlgItem(hWnd, IDC_LISTDEV), p_devicelist->dev[i]);
}
break;

case WM_CTLCOLORDLG:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
{
HDC hDc = (HDC)wParam;
SetBkMode(hDc, TRANSPARENT);
return (LONG)g_hbrBackground;
}
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
selindex = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_LISTDEV));
if (selindex < 0) selindex = 0; // if not selected select 0
EndDialog(hWnd, selindex);
break;

case IDC_LISTDEV:
switch (HIWORD(wParam))
{
case LBN_SELCHANGE:
EnableWindow(GetDlgItem(hWnd, IDOK), TRUE);
break;
case LBN_DBLCLK:
selindex = ListBox_GetCurSel(GetDlgItem(hWnd, IDC_LISTDEV));
if (selindex < 0) selindex = 0; // if not selected select 0
EndDialog(hWnd, selindex);
break;
}
break;
}
break;


default:
// return zero if we do not process this message
return FALSE;
}

// return nonzero if we did process the message
return TRUE;
}
7 changes: 7 additions & 0 deletions ExtIO_sddc/tdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ extern void UpdatePPM(HWND hWnd);

BOOL CALLBACK DlgMainFn(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

BOOL CALLBACK DlgSelectDevice(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

struct DevContext
{
unsigned char numdev;
char dev[MAXNDEV][MAXDEVSTRLEN];
};
#endif // _TABDIALOGH_
Loading