From b6155b8d1f9ff513246541c5b22c3736f6fc09d0 Mon Sep 17 00:00:00 2001 From: uvos Date: Fri, 18 Jun 2021 16:54:07 +0200 Subject: [PATCH] refactor cam::Camera::Description --- main.cpp | 9 ++++++-- uvoscam.cpp | 61 +++++++++++++++++++++++++++++------------------------ uvoscam.h | 43 +++++++++++++++++++++++++++++-------- 3 files changed, 74 insertions(+), 39 deletions(-) diff --git a/main.cpp b/main.cpp index 85c348f..4fb4d5f 100644 --- a/main.cpp +++ b/main.cpp @@ -40,7 +40,7 @@ void listDevices() std::vector cameras = Camera::getAvailableCameras(); size_t i = 0; for(auto camera : cameras) - std::cout< Camera::getAvailableCameras(bool update) std::vector cameras; for(size_t i = 0; i < arv_get_n_devices(); ++i) { - Description camera; + const char* vendor = arv_get_device_vendor(i); const char* serial = arv_get_device_serial_nbr(i); - const char* id = arv_get_device_id(i); const char* model = arv_get_device_model(i); + const char* id = arv_get_device_id(i); - if(vendor) - camera.vendor = vendor; - if(serial) - camera.serial = serial; - if(id) - camera.id = id; - if(model) - camera.model = model; - - cameras.push_back(camera); + if(!vendor || !serial || !id || !model) + continue; + + cameras.push_back(Description(vendor, model, serial, id)); } return cameras; } @@ -341,7 +336,8 @@ bool Camera::openCamera(const std::string& name) bool Camera::openCamera(const Camera::Description& camera) { - aCamera_ = arv_camera_new(camera.id.c_str(), nullptr); + description = new Description(camera); + aCamera_ = arv_camera_new(camera.getIdString().c_str(), nullptr); if(ARV_IS_CAMERA(aCamera_)) setupCamera(); else @@ -352,11 +348,12 @@ bool Camera::openCamera(const Camera::Description& camera) bool Camera::openCamera(const size_t index) { Description camera = getAvailableCameras().at(index); - aCamera_ = arv_camera_new(camera.id.c_str(), nullptr); + description = new Description(camera); + aCamera_ = arv_camera_new(camera.getIdString().c_str(), nullptr); if(ARV_IS_CAMERA(aCamera_)) setupCamera(); else - Log(Log::ERROR)<<"Can not create camera from index "<message; @@ -553,29 +550,37 @@ void Camera::trigger() arv_camera_software_trigger(aCamera_, nullptr); } +bool Camera::setMtu(int mtu) { + GError* error = nullptr; + arv_device_set_integer_feature_value(arv_camera_get_device(aCamera_), "GevSCPSPacketSize", mtu, &error); + if(!error) + arv_device_set_integer_feature_value(arv_camera_get_device(aCamera_), "GevSCBWR", 10, &error); + if(error) + Log(Log::WARN)<message; + return !error; +} + Camera::Description Camera::getDescription() { if(!description) { if(ARV_IS_CAMERA(aCamera_)) { - description = new Description; + std::string vendor; + std::string serial; + std::string model; + GError* error = nullptr; + vendor = arv_camera_get_vendor_name(aCamera_, &error); if(!error) - description->vendor = arv_camera_get_vendor_name(aCamera_, &error); + serial = arv_camera_get_device_serial_number(aCamera_, &error); if(!error) - description->serial = arv_camera_get_device_serial_number(aCamera_, &error); - if(!error) - description->id = arv_camera_get_device_id(aCamera_, &error); - if(!error) - description->model = arv_camera_get_model_name(aCamera_, &error); + model = arv_camera_get_model_name(aCamera_, &error); if(error) - { Log(Log::WARN)<message; - delete description; - description = nullptr; - } + else + description = new Description(vendor, model, serial); } } - return description ? *description : Description(); + return description ? *description : Description("VOID", "VOID", "VOID"); } diff --git a/uvoscam.h b/uvoscam.h index 50e93b8..0b4bfca 100644 --- a/uvoscam.h +++ b/uvoscam.h @@ -41,22 +41,46 @@ public: { private: size_t hash = 0; + std::string vendor_; + std::string serial_; + std::string model_; + std::string id_; public: - std::string vendor; - std::string serial; - std::string id; - std::string model; - size_t getHash() const + Description(std::string const vendor, const std::string model, const std::string serial, const std::string id = ""): + vendor_(vendor), serial_(serial), model_(model), id_(id) { - //if(hash == 0) - return /*hash =*/ std::hash{}(vendor + serial + id + model); - //return hash; + hash = std::hash{}(vendor_ + serial_ + model_); + } + + size_t getId() const + { + return hash; + } + + std::string getIdString() const + { + return id_; + } + + std::string getVendor() const + { + return vendor_; + } + + std::string getSerial() const + { + return serial_; + } + + std::string getModel() const + { + return model_; } bool operator==(const Description& in) const { - return in.getHash() == getHash(); + return in.getId() == getId(); } bool operator!=(const Description& in) const { @@ -147,6 +171,7 @@ public: bool hasExposureAuto(); bool startAcquisition(); bool stopAcquisition(); + bool setMtu(int mtu); void getSize(unsigned int* x, unsigned int* y); void setBayerMode(Camera::BayerMode mode); Camera::BayerMode getBayerMode();