diff --git a/docs/adddevice.md b/docs/adddevice.md index 284a06c..ade9bc9 100644 --- a/docs/adddevice.md +++ b/docs/adddevice.md @@ -18,10 +18,18 @@ If your device needs other or slighly altered packets, you would need to modify ## Add your model information You will only need to touch files within `openhantek/src/hantekdso/models`. -Create a new class with your model name and inherit from `DSOModel`. Add an instance of your new class -to the `supportedModels` list in `models.cpp`. +1. Create a new class with your model name and inherit from `DSOModel`: -The following code shows the constructor of `DSOModel` that needs to be supplied with model specific data: +``` c++ +struct ModelDSO2090 : public DSOModel { + static const int ID = 0x2090; // Freely chooseable but unique id + ModelDSO2090(); + void applyRequirements(HantekDsoControl* dsoControl) const override; +}; +``` + +2. Implement the constructor of your class, where you need to supply the constructor of `DSOModel` with + some information. The `DSOModel` constructor looks like this: ``` c++ DSOModel(int ID, long vendorID, long productID, long vendorIDnoFirmware, long productIDnoFirmware, @@ -35,7 +43,7 @@ DSOModel(int ID, long vendorID, long productID, long vendorIDnoFirmware, long pr (remember that we used `devicename-firmware.hex` and `devicename-loader.hex`). * The last parameter is the user visible name of the device. -Add your device specific constants via the `specification` field, for instance: +3. Add your device specific constants via the `specification` field, for instance: ``` c++ specification.samplerate.single.base = 50e6; @@ -48,7 +56,7 @@ Add your device specific constants via the `specification` field, for instance: specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 65536}; ``` -The actual commands that are send, need to be defined as well, for instance: +4. The actual commands that are send, need to be defined as well, for instance: ``` c++ specification.command.control.setOffset = CONTROL_SETOFFSET; @@ -61,4 +69,9 @@ The actual commands that are send, need to be defined as well, for instance: specification.command.bulk.setPretrigger = BulkCode::SETTRIGGERANDSAMPLERATE; ``` +5. Add an instance of your class to the cpp file. The `DSOModel` constructor will register + your new model automatically to the ModelRegistry: +``` +static ModelDSO2090 modelInstance; +``` diff --git a/openhantek/src/hantekdso/controlspecification.h b/openhantek/src/hantekdso/controlspecification.h index 7abb9f8..ecb8fc7 100644 --- a/openhantek/src/hantekdso/controlspecification.h +++ b/openhantek/src/hantekdso/controlspecification.h @@ -59,7 +59,7 @@ struct ControlSpecification { BulkCode cmdTriggerEnabled = BulkCode::ENABLETRIGGER; ///< Command for enabling the trigger BulkCode cmdGetData = BulkCode::GETDATA; ///< Command for retrieve sample data BulkCode cmdGetCaptureState = BulkCode::GETCAPTURESTATE; ///< Command for retrieve the capture state - BulkCode cmdSetGain = BulkCode::SETGAIN; ///< Command for setting the gain + BulkCode cmdSetGain = BulkCode::SETGAIN; ///< Command for setting the gain ControlBeginCommand beginCommandControl; ControlGetLimits cmdGetLimits; diff --git a/openhantek/src/hantekdso/dsomodel.cpp b/openhantek/src/hantekdso/dsomodel.cpp index f9a10d9..ab25cf7 100644 --- a/openhantek/src/hantekdso/dsomodel.cpp +++ b/openhantek/src/hantekdso/dsomodel.cpp @@ -2,8 +2,11 @@ // SPDX-License-Identifier: GPL-2.0+ #include "dsomodel.h" +#include "modelregistry.h" DSOModel::DSOModel(int id, long vendorID, long productID, long vendorIDnoFirmware, long productIDnoFirmware, const std::string &firmwareToken, const std::string &name, const Dso::ControlSpecification &specification) : ID(id), vendorID(vendorID), productID(productID), vendorIDnoFirmware(vendorIDnoFirmware), - productIDnoFirmware(productIDnoFirmware), firmwareToken(firmwareToken), name(name), specification(specification) {} + productIDnoFirmware(productIDnoFirmware), firmwareToken(firmwareToken), name(name), specification(specification) { + ModelRegistry::get()->add(this); +} diff --git a/openhantek/src/hantekdso/modelregistry.cpp b/openhantek/src/hantekdso/modelregistry.cpp new file mode 100644 index 0000000..7c3f9c5 --- /dev/null +++ b/openhantek/src/hantekdso/modelregistry.cpp @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include "modelregistry.h" + +ModelRegistry *ModelRegistry::instance = new ModelRegistry(); + +ModelRegistry *ModelRegistry::get() { return instance; } + +void ModelRegistry::add(DSOModel *model) { supportedModels.push_back(model); } + +const std::list ModelRegistry::models() const { return supportedModels; } diff --git a/openhantek/src/hantekdso/modelregistry.h b/openhantek/src/hantekdso/modelregistry.h new file mode 100644 index 0000000..31289db --- /dev/null +++ b/openhantek/src/hantekdso/modelregistry.h @@ -0,0 +1,16 @@ + +// SPDX-License-Identifier: GPL-2.0+ + +#pragma once + +#include "dsomodel.h" + +class ModelRegistry { +public: + static ModelRegistry *get(); + void add(DSOModel* model); + const std::list models() const; +private: + static ModelRegistry* instance; + std::list supportedModels; +}; diff --git a/openhantek/src/hantekdso/models.h b/openhantek/src/hantekdso/models.h deleted file mode 100644 index 1709068..0000000 --- a/openhantek/src/hantekdso/models.h +++ /dev/null @@ -1,8 +0,0 @@ - -// SPDX-License-Identifier: GPL-2.0+ - -#pragma once - -#include "dsomodel.h" - -extern std::list supportedModels; diff --git a/openhantek/src/hantekdso/models/modelDSO2090.cpp b/openhantek/src/hantekdso/models/modelDSO2090.cpp index 788f402..61dce4b 100644 --- a/openhantek/src/hantekdso/models/modelDSO2090.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2090.cpp @@ -5,6 +5,9 @@ using namespace Hantek; +static ModelDSO2090 modelInstance; +static ModelDSO2090A modelInstance2; + ModelDSO2090::ModelDSO2090() : DSOModel(ID, 0x04b5, 0x2090, 0x04b4, 0x2090, "dso2090x86", "DSO-2090", Dso::ControlSpecification(2)) { specification.cmdSetRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; diff --git a/openhantek/src/hantekdso/models/modelDSO2150.cpp b/openhantek/src/hantekdso/models/modelDSO2150.cpp index b0e4c8d..0334eea 100644 --- a/openhantek/src/hantekdso/models/modelDSO2150.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2150.cpp @@ -5,6 +5,8 @@ using namespace Hantek; +static ModelDSO2150 modelInstance; + ModelDSO2150::ModelDSO2150() : DSOModel(ID, 0x04b5, 0x2150, 0x04b4, 0x2150, "dso2150x86", "DSO-2150", Dso::ControlSpecification(2)) { specification.cmdSetRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; diff --git a/openhantek/src/hantekdso/models/modelDSO2250.cpp b/openhantek/src/hantekdso/models/modelDSO2250.cpp index 51c7eb1..e562665 100644 --- a/openhantek/src/hantekdso/models/modelDSO2250.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2250.cpp @@ -5,6 +5,8 @@ using namespace Hantek; +static ModelDSO2250 modelInstance; + ModelDSO2250::ModelDSO2250() : DSOModel(ID, 0x04b5, 0x2250, 0x04b4, 0x2250, "dso2250x86", "DSO-2250", Dso::ControlSpecification(2)) { specification.cmdSetRecordLength = BulkCode::DSETBUFFER; diff --git a/openhantek/src/hantekdso/models/modelDSO5200.cpp b/openhantek/src/hantekdso/models/modelDSO5200.cpp index 1618e1c..b7b11d4 100644 --- a/openhantek/src/hantekdso/models/modelDSO5200.cpp +++ b/openhantek/src/hantekdso/models/modelDSO5200.cpp @@ -5,6 +5,9 @@ using namespace Hantek; +static ModelDSO5200 modelInstance; +static ModelDSO5200A modelInstance2; + ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso5200x86", "DSO-5200", Dso::ControlSpecification(2)) { specification.cmdSetRecordLength = BulkCode::DSETBUFFER; diff --git a/openhantek/src/hantekdso/models/modelDSO6022.cpp b/openhantek/src/hantekdso/models/modelDSO6022.cpp index 57a1f7d..78de535 100644 --- a/openhantek/src/hantekdso/models/modelDSO6022.cpp +++ b/openhantek/src/hantekdso/models/modelDSO6022.cpp @@ -5,6 +5,9 @@ using namespace Hantek; +static ModelDSO6022BE modelInstance; +static ModelDSO6022BL modelInstance2; + ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022, "dso6022be", "DSO-6022BE", Dso::ControlSpecification(2)) { // 6022xx do not support any bulk commands diff --git a/openhantek/src/hantekdso/models/models.cpp b/openhantek/src/hantekdso/models/models.cpp deleted file mode 100644 index 7190948..0000000 --- a/openhantek/src/hantekdso/models/models.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ - -#include "models.h" -#include "modelDSO2090.h" -#include "modelDSO2150.h" -#include "modelDSO2250.h" -#include "modelDSO5200.h" -#include "modelDSO6022.h" - -std::list supportedModels = - std::list({new ModelDSO2090(), new ModelDSO2090A(), new ModelDSO2150(), - new ModelDSO2250(), new ModelDSO5200(), new ModelDSO5200A(), - new ModelDSO6022BE(), new ModelDSO6022BL()}); diff --git a/openhantek/src/selectdevice/newdevicemodelfromexisting.cpp b/openhantek/src/selectdevice/newdevicemodelfromexisting.cpp index 76f1e47..013e6ad 100644 --- a/openhantek/src/selectdevice/newdevicemodelfromexisting.cpp +++ b/openhantek/src/selectdevice/newdevicemodelfromexisting.cpp @@ -1,7 +1,7 @@ #include "newdevicemodelfromexisting.h" #include "dsomodel.h" -#include "models.h" +#include "modelregistry.h" #include "rawdeviceslistmodel.h" #include @@ -21,7 +21,7 @@ NewDeviceModelFromExisting::NewDeviceModelFromExisting(QWidget *parent) : ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); QStringList supportedModelsList; - for (const DSOModel* model: supportedModels) { + for (const DSOModel* model: ModelRegistry::get()->models()) { supportedModelsList.append(QString::fromStdString(model->name)); } diff --git a/openhantek/src/selectdevice/selectsupporteddevice.cpp b/openhantek/src/selectdevice/selectsupporteddevice.cpp index 42c326c..a8183e4 100644 --- a/openhantek/src/selectdevice/selectsupporteddevice.cpp +++ b/openhantek/src/selectdevice/selectsupporteddevice.cpp @@ -12,7 +12,7 @@ #include "devicelistentry.h" #include "deviceslistmodel.h" #include "newdevicemodelfromexisting.h" -#include "models.h" +#include "modelregistry.h" SelectSupportedDevice::SelectSupportedDevice(QWidget *parent) : QDialog(parent), @@ -114,7 +114,7 @@ void SelectSupportedDevice::showLibUSBFailedDialogModel(int error) void SelectSupportedDevice::updateSupportedDevices() { QString devices; - for (const DSOModel* model: supportedModels) { + for (const DSOModel* model: ModelRegistry::get()->models()) { devices.append(QString::fromStdString(model->name)).append(" "); } ui->labelSupportedDevices->setText(devices); diff --git a/openhantek/src/usb/finddevices.cpp b/openhantek/src/usb/finddevices.cpp index 1dec832..67b338e 100644 --- a/openhantek/src/usb/finddevices.cpp +++ b/openhantek/src/usb/finddevices.cpp @@ -12,7 +12,7 @@ #include "utils/printutils.h" #include -#include "models.h" +#include "modelregistry.h" FindDevices::FindDevices(libusb_context *context) : context(context) {} @@ -40,7 +40,7 @@ int FindDevices::updateDeviceList() { continue; } - for (DSOModel* model : supportedModels) { + for (DSOModel* model : ModelRegistry::get()->models()) { // Check VID and PID for firmware flashed devices bool supported = descriptor.idVendor == model->vendorID && descriptor.idProduct == model->productID; // Devices without firmware have different VID/PIDs diff --git a/openhantek/src/usb/usbdevice.cpp b/openhantek/src/usb/usbdevice.cpp index 6189095..33256a7 100644 --- a/openhantek/src/usb/usbdevice.cpp +++ b/openhantek/src/usb/usbdevice.cpp @@ -6,9 +6,9 @@ #include "usbdevice.h" +#include "hantekdso/dsomodel.h" #include "hantekprotocol/bulkStructs.h" #include "hantekprotocol/controlStructs.h" -#include "models.h" #include "utils/printutils.h" UniqueUSBid USBDevice::computeUSBdeviceID(libusb_device *device) {