Commit ab85a488ac1ee1a73d46d89779a71017a830ca9e
Committed by
David Gräff
1 parent
eaf29e59
Introduce ModelRegistry as singleton. Supersedes the global list variable of sup…
…ported models. A new model now only needs a h/cpp file and of course missing protocol commands
Showing
16 changed files
with
70 additions
and
35 deletions
docs/adddevice.md
| ... | ... | @@ -18,10 +18,18 @@ If your device needs other or slighly altered packets, you would need to modify |
| 18 | 18 | ## Add your model information |
| 19 | 19 | You will only need to touch files within `openhantek/src/hantekdso/models`. |
| 20 | 20 | |
| 21 | -Create a new class with your model name and inherit from `DSOModel`. Add an instance of your new class | |
| 22 | -to the `supportedModels` list in `models.cpp`. | |
| 21 | +1. Create a new class with your model name and inherit from `DSOModel`: | |
| 23 | 22 | |
| 24 | -The following code shows the constructor of `DSOModel` that needs to be supplied with model specific data: | |
| 23 | +``` c++ | |
| 24 | +struct ModelDSO2090 : public DSOModel { | |
| 25 | + static const int ID = 0x2090; // Freely chooseable but unique id | |
| 26 | + ModelDSO2090(); | |
| 27 | + void applyRequirements(HantekDsoControl* dsoControl) const override; | |
| 28 | +}; | |
| 29 | +``` | |
| 30 | + | |
| 31 | +2. Implement the constructor of your class, where you need to supply the constructor of `DSOModel` with | |
| 32 | + some information. The `DSOModel` constructor looks like this: | |
| 25 | 33 | |
| 26 | 34 | ``` c++ |
| 27 | 35 | 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 |
| 35 | 43 | (remember that we used `devicename-firmware.hex` and `devicename-loader.hex`). |
| 36 | 44 | * The last parameter is the user visible name of the device. |
| 37 | 45 | |
| 38 | -Add your device specific constants via the `specification` field, for instance: | |
| 46 | +3. Add your device specific constants via the `specification` field, for instance: | |
| 39 | 47 | |
| 40 | 48 | ``` c++ |
| 41 | 49 | specification.samplerate.single.base = 50e6; |
| ... | ... | @@ -48,7 +56,7 @@ Add your device specific constants via the `specification` field, for instance: |
| 48 | 56 | specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 65536}; |
| 49 | 57 | ``` |
| 50 | 58 | |
| 51 | -The actual commands that are send, need to be defined as well, for instance: | |
| 59 | +4. The actual commands that are send, need to be defined as well, for instance: | |
| 52 | 60 | |
| 53 | 61 | ``` c++ |
| 54 | 62 | specification.command.control.setOffset = CONTROL_SETOFFSET; |
| ... | ... | @@ -61,4 +69,9 @@ The actual commands that are send, need to be defined as well, for instance: |
| 61 | 69 | specification.command.bulk.setPretrigger = BulkCode::SETTRIGGERANDSAMPLERATE; |
| 62 | 70 | ``` |
| 63 | 71 | |
| 72 | +5. Add an instance of your class to the cpp file. The `DSOModel` constructor will register | |
| 73 | + your new model automatically to the ModelRegistry: | |
| 64 | 74 | |
| 75 | +``` | |
| 76 | +static ModelDSO2090 modelInstance; | |
| 77 | +``` | ... | ... |
openhantek/src/hantekdso/controlspecification.h
| ... | ... | @@ -59,7 +59,7 @@ struct ControlSpecification { |
| 59 | 59 | BulkCode cmdTriggerEnabled = BulkCode::ENABLETRIGGER; ///< Command for enabling the trigger |
| 60 | 60 | BulkCode cmdGetData = BulkCode::GETDATA; ///< Command for retrieve sample data |
| 61 | 61 | BulkCode cmdGetCaptureState = BulkCode::GETCAPTURESTATE; ///< Command for retrieve the capture state |
| 62 | - BulkCode cmdSetGain = BulkCode::SETGAIN; ///< Command for setting the gain | |
| 62 | + BulkCode cmdSetGain = BulkCode::SETGAIN; ///< Command for setting the gain | |
| 63 | 63 | |
| 64 | 64 | ControlBeginCommand beginCommandControl; |
| 65 | 65 | ControlGetLimits cmdGetLimits; | ... | ... |
openhantek/src/hantekdso/dsomodel.cpp
| ... | ... | @@ -2,8 +2,11 @@ |
| 2 | 2 | // SPDX-License-Identifier: GPL-2.0+ |
| 3 | 3 | |
| 4 | 4 | #include "dsomodel.h" |
| 5 | +#include "modelregistry.h" | |
| 5 | 6 | |
| 6 | 7 | DSOModel::DSOModel(int id, long vendorID, long productID, long vendorIDnoFirmware, |
| 7 | 8 | long productIDnoFirmware, const std::string &firmwareToken, const std::string &name, const Dso::ControlSpecification &specification) |
| 8 | 9 | : ID(id), vendorID(vendorID), productID(productID), vendorIDnoFirmware(vendorIDnoFirmware), |
| 9 | - productIDnoFirmware(productIDnoFirmware), firmwareToken(firmwareToken), name(name), specification(specification) {} | |
| 10 | + productIDnoFirmware(productIDnoFirmware), firmwareToken(firmwareToken), name(name), specification(specification) { | |
| 11 | + ModelRegistry::get()->add(this); | |
| 12 | +} | ... | ... |
openhantek/src/hantekdso/modelregistry.cpp
0 → 100644
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | |
| 2 | + | |
| 3 | +#include "modelregistry.h" | |
| 4 | + | |
| 5 | +ModelRegistry *ModelRegistry::instance = new ModelRegistry(); | |
| 6 | + | |
| 7 | +ModelRegistry *ModelRegistry::get() { return instance; } | |
| 8 | + | |
| 9 | +void ModelRegistry::add(DSOModel *model) { supportedModels.push_back(model); } | |
| 10 | + | |
| 11 | +const std::list<DSOModel *> ModelRegistry::models() const { return supportedModels; } | ... | ... |
openhantek/src/hantekdso/modelregistry.h
0 → 100644
| 1 | + | |
| 2 | +// SPDX-License-Identifier: GPL-2.0+ | |
| 3 | + | |
| 4 | +#pragma once | |
| 5 | + | |
| 6 | +#include "dsomodel.h" | |
| 7 | + | |
| 8 | +class ModelRegistry { | |
| 9 | +public: | |
| 10 | + static ModelRegistry *get(); | |
| 11 | + void add(DSOModel* model); | |
| 12 | + const std::list<DSOModel*> models() const; | |
| 13 | +private: | |
| 14 | + static ModelRegistry* instance; | |
| 15 | + std::list<DSOModel*> supportedModels; | |
| 16 | +}; | ... | ... |
openhantek/src/hantekdso/models.h deleted
openhantek/src/hantekdso/models/modelDSO2090.cpp
| ... | ... | @@ -5,6 +5,9 @@ |
| 5 | 5 | |
| 6 | 6 | using namespace Hantek; |
| 7 | 7 | |
| 8 | +static ModelDSO2090 modelInstance; | |
| 9 | +static ModelDSO2090A modelInstance2; | |
| 10 | + | |
| 8 | 11 | ModelDSO2090::ModelDSO2090() : DSOModel(ID, 0x04b5, 0x2090, 0x04b4, 0x2090, "dso2090x86", "DSO-2090", |
| 9 | 12 | Dso::ControlSpecification(2)) { |
| 10 | 13 | specification.cmdSetRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; | ... | ... |
openhantek/src/hantekdso/models/modelDSO2150.cpp
| ... | ... | @@ -5,6 +5,8 @@ |
| 5 | 5 | |
| 6 | 6 | using namespace Hantek; |
| 7 | 7 | |
| 8 | +static ModelDSO2150 modelInstance; | |
| 9 | + | |
| 8 | 10 | ModelDSO2150::ModelDSO2150() : DSOModel(ID, 0x04b5, 0x2150, 0x04b4, 0x2150, "dso2150x86", "DSO-2150", |
| 9 | 11 | Dso::ControlSpecification(2)) { |
| 10 | 12 | specification.cmdSetRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; | ... | ... |
openhantek/src/hantekdso/models/modelDSO2250.cpp
| ... | ... | @@ -5,6 +5,8 @@ |
| 5 | 5 | |
| 6 | 6 | using namespace Hantek; |
| 7 | 7 | |
| 8 | +static ModelDSO2250 modelInstance; | |
| 9 | + | |
| 8 | 10 | ModelDSO2250::ModelDSO2250() : DSOModel(ID, 0x04b5, 0x2250, 0x04b4, 0x2250, "dso2250x86", "DSO-2250", |
| 9 | 11 | Dso::ControlSpecification(2)) { |
| 10 | 12 | specification.cmdSetRecordLength = BulkCode::DSETBUFFER; | ... | ... |
openhantek/src/hantekdso/models/modelDSO5200.cpp
| ... | ... | @@ -5,6 +5,9 @@ |
| 5 | 5 | |
| 6 | 6 | using namespace Hantek; |
| 7 | 7 | |
| 8 | +static ModelDSO5200 modelInstance; | |
| 9 | +static ModelDSO5200A modelInstance2; | |
| 10 | + | |
| 8 | 11 | ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso5200x86", "DSO-5200", |
| 9 | 12 | Dso::ControlSpecification(2)) { |
| 10 | 13 | specification.cmdSetRecordLength = BulkCode::DSETBUFFER; | ... | ... |
openhantek/src/hantekdso/models/modelDSO6022.cpp
| ... | ... | @@ -5,6 +5,9 @@ |
| 5 | 5 | |
| 6 | 6 | using namespace Hantek; |
| 7 | 7 | |
| 8 | +static ModelDSO6022BE modelInstance; | |
| 9 | +static ModelDSO6022BL modelInstance2; | |
| 10 | + | |
| 8 | 11 | ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022, "dso6022be", "DSO-6022BE", |
| 9 | 12 | Dso::ControlSpecification(2)) { |
| 10 | 13 | // 6022xx do not support any bulk commands | ... | ... |
openhantek/src/hantekdso/models/models.cpp deleted
| 1 | -// SPDX-License-Identifier: GPL-2.0+ | |
| 2 | - | |
| 3 | -#include "models.h" | |
| 4 | -#include "modelDSO2090.h" | |
| 5 | -#include "modelDSO2150.h" | |
| 6 | -#include "modelDSO2250.h" | |
| 7 | -#include "modelDSO5200.h" | |
| 8 | -#include "modelDSO6022.h" | |
| 9 | - | |
| 10 | -std::list<DSOModel*> supportedModels = | |
| 11 | - std::list<DSOModel*>({new ModelDSO2090(), new ModelDSO2090A(), new ModelDSO2150(), | |
| 12 | - new ModelDSO2250(), new ModelDSO5200(), new ModelDSO5200A(), | |
| 13 | - new ModelDSO6022BE(), new ModelDSO6022BL()}); |
openhantek/src/selectdevice/newdevicemodelfromexisting.cpp
| 1 | 1 | #include "newdevicemodelfromexisting.h" |
| 2 | 2 | |
| 3 | 3 | #include "dsomodel.h" |
| 4 | -#include "models.h" | |
| 4 | +#include "modelregistry.h" | |
| 5 | 5 | #include "rawdeviceslistmodel.h" |
| 6 | 6 | |
| 7 | 7 | #include <QDebug> |
| ... | ... | @@ -21,7 +21,7 @@ NewDeviceModelFromExisting::NewDeviceModelFromExisting(QWidget *parent) : |
| 21 | 21 | ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); |
| 22 | 22 | |
| 23 | 23 | QStringList supportedModelsList; |
| 24 | - for (const DSOModel* model: supportedModels) { | |
| 24 | + for (const DSOModel* model: ModelRegistry::get()->models()) { | |
| 25 | 25 | supportedModelsList.append(QString::fromStdString(model->name)); |
| 26 | 26 | } |
| 27 | 27 | ... | ... |
openhantek/src/selectdevice/selectsupporteddevice.cpp
| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | #include "devicelistentry.h" |
| 13 | 13 | #include "deviceslistmodel.h" |
| 14 | 14 | #include "newdevicemodelfromexisting.h" |
| 15 | -#include "models.h" | |
| 15 | +#include "modelregistry.h" | |
| 16 | 16 | |
| 17 | 17 | SelectSupportedDevice::SelectSupportedDevice(QWidget *parent) : |
| 18 | 18 | QDialog(parent), |
| ... | ... | @@ -114,7 +114,7 @@ void SelectSupportedDevice::showLibUSBFailedDialogModel(int error) |
| 114 | 114 | void SelectSupportedDevice::updateSupportedDevices() |
| 115 | 115 | { |
| 116 | 116 | QString devices; |
| 117 | - for (const DSOModel* model: supportedModels) { | |
| 117 | + for (const DSOModel* model: ModelRegistry::get()->models()) { | |
| 118 | 118 | devices.append(QString::fromStdString(model->name)).append(" "); |
| 119 | 119 | } |
| 120 | 120 | ui->labelSupportedDevices->setText(devices); | ... | ... |
openhantek/src/usb/finddevices.cpp
| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | #include "utils/printutils.h" |
| 13 | 13 | #include <libusb-1.0/libusb.h> |
| 14 | 14 | |
| 15 | -#include "models.h" | |
| 15 | +#include "modelregistry.h" | |
| 16 | 16 | |
| 17 | 17 | FindDevices::FindDevices(libusb_context *context) : context(context) {} |
| 18 | 18 | |
| ... | ... | @@ -40,7 +40,7 @@ int FindDevices::updateDeviceList() { |
| 40 | 40 | continue; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - for (DSOModel* model : supportedModels) { | |
| 43 | + for (DSOModel* model : ModelRegistry::get()->models()) { | |
| 44 | 44 | // Check VID and PID for firmware flashed devices |
| 45 | 45 | bool supported = descriptor.idVendor == model->vendorID && descriptor.idProduct == model->productID; |
| 46 | 46 | // Devices without firmware have different VID/PIDs | ... | ... |
openhantek/src/usb/usbdevice.cpp
| ... | ... | @@ -6,9 +6,9 @@ |
| 6 | 6 | |
| 7 | 7 | #include "usbdevice.h" |
| 8 | 8 | |
| 9 | +#include "hantekdso/dsomodel.h" | |
| 9 | 10 | #include "hantekprotocol/bulkStructs.h" |
| 10 | 11 | #include "hantekprotocol/controlStructs.h" |
| 11 | -#include "models.h" | |
| 12 | 12 | #include "utils/printutils.h" |
| 13 | 13 | |
| 14 | 14 | UniqueUSBid USBDevice::computeUSBdeviceID(libusb_device *device) { | ... | ... |