From 16b69e31452ea8a559e30ba0817c18ced79116cc Mon Sep 17 00:00:00 2001 From: am0ebe <am0ebe@gmx.de> Date: Thu, 25 Jul 2024 19:21:37 +0200 Subject: [PATCH] [crash after rec] add printfeatures to cam and stream. pingscan: add better alternative to finding cam via mac --- src/cam.cpp | 60 ++++++++++++++++++++++++------------------------- src/cam.h | 13 ++++++----- src/core.cpp | 2 +- src/pingScan.sh | 49 ++++++++++++++++++++++++++++++---------- src/record.cpp | 53 +++++++++++++++++++++++++++---------------- 5 files changed, 110 insertions(+), 67 deletions(-) diff --git a/src/cam.cpp b/src/cam.cpp index e5fb969..515244b 100644 --- a/src/cam.cpp +++ b/src/cam.cpp @@ -18,7 +18,7 @@ using namespace VmbCPP; using utils::DELIM; Cam::Cam(QString name, QString ip) : IPrinter(), -_cam(nullptr), +_vcam(nullptr), _name(name), _ip(ip), _id(""), @@ -29,12 +29,12 @@ _rec() } // Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other) -// _cam(other._cam), +// _vcam(other._vcam), // _name(other._name), // _ip(other._ip), // _id(other._id), // _state(other._state)Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other) -// _cam(other._cam), +// _vcam(other._vcam), // _name(other._name), // _ip(other._ip), // _id(other._id), @@ -57,7 +57,7 @@ _rec() Cam::~Cam() { - qDebug() << __FUNCTION__ << "():" << __LINE__ << "id:" << _id << ", usecount:" << _cam.use_count(); + qDebug() << __FUNCTION__ << "():" << __LINE__ << "id:" << _id << ", usecount:" << _vcam.use_count(); if( _state == recording ) rec()->stop(); @@ -87,7 +87,7 @@ QString Cam::id() if( _id.isEmpty() ) { std::string str; - f(_cam->GetID( str )); + f(_vcam->GetID( str )); _id = QString::fromStdString(str); } return _id; @@ -108,7 +108,7 @@ void Cam::open() if(_state != closed) return error("cant open " + stateToString(_state) + " cam"); - f(_cam->Open( VmbAccessModeFull ),"open cam #"+_id); + f(_vcam->Open( VmbAccessModeFull ),"open cam #"+_id); //state change will be handled by CamObserver::CameraStateChanged > Core::onCameraChanged > Cam::onChanged } @@ -117,39 +117,39 @@ void Cam::close() if(_state != opened) return error("cant close " + stateToString(_state) + " cam"); - f(_cam->Close(),"close cam #"+_id); + f(_vcam->Close(),"close cam #"+_id); //state change will be handled by CamObserver::CameraStateChanged > Core::onCameraChanged > Cam::onChanged } -void Cam::printFeatures( QString feature) +void Cam::printStreamFeatures( QStringList features ) { - if(_state != opened) - return error("cant access features if cam is " + stateToString(_state) + " cam"); + if(_state != opened && _state != recording ) + return error("cant access features on " + stateToString(_state) + " cam"); - printFeatures(QStringList(feature)); + StreamPtrVector streams; + _vcam->GetStreams(streams); + printFeatures(streams.at(0), features); } -void Cam::printFeatures( QStringList features) +void Cam::printCamFeatures( QStringList features ) { + if(_state != opened ) + return error("cant access features on " + stateToString(_state) + " cam"); - if(_state != opened) - return error("cant access features if cam is " + stateToString(_state) + " cam"); + printFeatures(_vcam, features); +} +void Cam::printFeatures( FeatureContainerPtr camOrStream, QStringList features) +{ for( auto feature : features ) { try { - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; - qDebug() << feature << "| " << feature.toStdString().c_str(); - - // auto vcam = _cam->getCameraPtr(); FeaturePtr pFeature; - g( _cam->GetFeatureByName(feature.toStdString().c_str(), pFeature) ); - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; + g( camOrStream->GetFeatureByName(feature.toStdString().c_str(), pFeature) ); //, QString("GetFeatureByName: %1").arg(feature) VmbFeatureDataType type; - g( pFeature->GetDataType(type) ); - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; + g( pFeature->GetDataType(type) ); //"Feature->GetDataType" switch(type) { @@ -196,7 +196,7 @@ void Cam::printFeatures( QStringList features) catch (const std::runtime_error& xx) { qDebug() << __FUNCTION__ << "Exception caught: " << xx.what(); - break; + // break; } } } @@ -218,13 +218,13 @@ QString Cam::camInfo() camInfo += id() + DELIM; std::string str; - g(_cam->GetModel( str )); + g(_vcam->GetModel( str )); camInfo += QString::fromStdString(str) + DELIM; - g(_cam->GetSerialNumber( str )); + g(_vcam->GetSerialNumber( str )); camInfo += QString::fromStdString(str) + DELIM; - g(_cam->GetInterfaceID( str )); + g(_vcam->GetInterfaceID( str )); camInfo += QString::fromStdString(str) + DELIM; camInfo += stateToString(_state) + DELIM; @@ -266,12 +266,12 @@ void Cam::onChanged(UpdateTriggerType type) case UpdateTriggerType::UpdateTriggerPluggedIn: info(name()+" connected"); setState(closed); - //_cam ptr set in core + //_vcam ptr set in core break; case UpdateTriggerType::UpdateTriggerPluggedOut: info(name()+" disconnected"); setState(disconnected); - _cam.reset(); + _vcam.reset(); break; case UpdateTriggerType::UpdateTriggerOpenStateChanged: @@ -299,7 +299,7 @@ void Cam::saveSettings() QString file="settings_"+name()+".xml"; - if (f(_cam->SaveSettings( file.toStdString().c_str(), &settingsStruct ))) + if (f(_vcam->SaveSettings( file.toStdString().c_str(), &settingsStruct ))) error( "Could not save camera settings to '" + file + "'" ); else info("Saved settings to " + file); @@ -313,7 +313,7 @@ void Cam::loadSettings() if(_state != opened) return error("can only save settings on opened cam. (its " + stateToString(_state) + ")"); - if(f(_cam->LoadSettings( settingsFile().toStdString().c_str()))) + if(f(_vcam->LoadSettings( settingsFile().toStdString().c_str()))) error( "Could not load camera settings from '" + settingsFile() + "'" ); else info("Loaded settings from " + settingsFile()); diff --git a/src/cam.h b/src/cam.h index 1887a60..837bd55 100644 --- a/src/cam.h +++ b/src/cam.h @@ -38,20 +38,23 @@ public: void close(); QString camInfo(); - void printFeatures(QStringList); - void printFeatures(QString); + void printCamFeatures( QStringList ); + void printStreamFeatures( QStringList ); + void saveSettings(); void loadSettings(); - inline CameraPtr getCameraPtr() { return _cam; } - inline void setCameraPtr( CameraPtr pCamera ) { _cam = pCamera; } + inline CameraPtr getCameraPtr() { return _vcam; } + inline void setCameraPtr( CameraPtr pCamera ) { _vcam = pCamera; } friend class FrameObserver; friend class Core; private: - CameraPtr _cam; + void printFeatures(VmbCPP::FeatureContainerPtr, QStringList); + + CameraPtr _vcam; QString _name; QString _ip; QString _id; diff --git a/src/core.cpp b/src/core.cpp index 528f974..ca0ae5d 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -181,7 +181,7 @@ void Core::stopRecording() void Core::showRecordingStats() { qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; - if( cam() && cam()->rec() && cam()->_cam ) + if( cam() && cam()->rec() && cam()->getCameraPtr() ) { cam()->rec()->showStats(); } diff --git a/src/pingScan.sh b/src/pingScan.sh index 99e6142..fe34115 100755 --- a/src/pingScan.sh +++ b/src/pingScan.sh @@ -1,32 +1,52 @@ -#!/bin/bash + #!/bin/bash #scans class-B subnet 169.254.i.j #watch CPU usage and adapt max_jobs / timeout / step_size vars to ur system +############################### Alternatives ############################### +## faster alternative: +# search MAC address (4m) !! +# sudo arp-scan --interface=enp0s31f6 --localnet | grep 00:0a:47:1d:2a:66 +############################### +## other alternatives +## can also use nmap but takes long ~45m: +# sudo nmap -sP --script=broadcast-dhcp-discover 169.254.0.0/16 +## smaller test: +# sudo nmap -sP 169.254.220.0-225.255 +## or: +# sudo nmap -sP 169.254.0.0/16 +# sudo arp-scan --localnet +## check server logs +# # http://192.168.0.1/common_page/login.html -> login? +## Wireshark +# and begin capturing packets on the network interface connected to your local network. +# Filter for Broadcast and Multicast Traffic: Look for packets that are broadcast or multicast, as these can reveal the presence of your device. +# Use filters like eth.dst == ff:ff:ff:ff:ff:ff for broadcast or ip.dst == 224.0.0.0/4 for multicast. +# Inspect the Traffic: Look for traffic that might come from the camera. If you know the MAC address of the camera, +# you can filter for it using eth.addr == xx:xx:xx:xx:xx:xx. +############################### -step_size=8 -max_jobs=50 # Maximum number of concurrent pings -timeout=3 # Timeout for each ping in seconds - +step_size=12 +max_jobs=100 # Maximum number of concurrent pings for i in {0..255}; do if [ $((i % step_size)) == 0 ]; then - read -rp "169.254.$i-$((i+step_size))" -t$timeout #wait s echo "" + echo "169.254.$i-$((i+step_size))" + sleep 1 fi + echo -n "." - # echo $i for j in {0..255}; do if [[ "$i" == 255 && "$j" == 255 ]]; then - continue #ignore broadcast + break #ignore broadcast fi ip="169.254.$i.$j" ( - if timeout "$timeout"s ping -c1 -W1"$ip" &> /dev/null; then + if ping -c2 -W2 "$ip" &> /dev/null; then echo -e "\n$ip <<<<<<<<<<<<<<<<<< !!\n" fi ) & - # Wait for jobs to finish if max_jobs limit is reached if (( $(jobs -r | wc -l) >= max_jobs )); then wait -n @@ -34,8 +54,13 @@ for i in {0..255}; do done done +wait # Wait for all REMAINING + +# timeout=1 # Timeout for each ping in seconds + # if timeout "$timeout"s ping -c1 -i0.5 "$ip" &> /dev/null; then #discard both + # if timeout "$timeout"s ping -c1 -i0.5 "$ip" > /dev/null; then #discard normal output + # if timeout "$timeout"s ping -c1 -i0.5 "$ip" 2> /dev/null; then #discard err only + # (ping "${ip}" -c 1 -W 1 &> /dev/null && echo -e "\n${ip} <<<<<<<<<<<<<<<<<< !!\n" &) ; -wait # Wait for all background pings in this step to complete before proceeding - # (ping "${ip}" -c 1 -W 1 &> /dev/null && echo -e "\n${ip} <<<<<<<<<<<<<<<<<< !!\n" &) ; diff --git a/src/record.cpp b/src/record.cpp index a317199..b6a3107 100644 --- a/src/record.cpp +++ b/src/record.cpp @@ -26,9 +26,8 @@ _frames(FramePtrVector(utils::threadsPerCam())) connect(_timer, SIGNAL(timeout()), this, SLOT(stop())); - _updateTimer->setInterval(duration_cast<milliseconds>(updateInterval)); + _updateTimer->setInterval(duration_cast<milliseconds>(updateInterval)); connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showProgress())); - connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showStats())); } void Record::init(CamPtr cam) @@ -86,7 +85,6 @@ void Record::start() { frame.reset(new Frame(_payloadSize)); g( frame->RegisterObserver( IFrameObserverPtr( new FrameObserver(_cam) )),"register frame observer"); - g( vcam->AnnounceFrame(frame), "announce frame"); } @@ -118,6 +116,7 @@ void Record::start() */ void Record::stop() { + _updateTimer->stop(); if(_timer->isActive()) { //user stop or error @@ -130,6 +129,7 @@ void Record::stop() info( progressBar(100) ); } + try { FeaturePtr pFeature; @@ -156,22 +156,37 @@ void Record::stop() void Record::showStats() { - qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; - _cam->printFeatures("StatFrameDropped"); - _cam->printFeatures({ - // "StatFrameDropped", //unsigned int max 4294967295 - "StatFrameRate", //float send by cam - "StatLocalRate", //float rcvd by observer - "StatFrameRescued", - "StatFrameShoved", - "StatFrameUnderrun", - "StatPacketErrors", - "StatPacketMissed", - "StatPacketReceived", - "StatPacketRequested", - "StatPacketResent", - "StatTimeElapsed", //float - time elapsed since start of acquisition - "StatFrameDelivered" + info("-------------------------------"); + info("get cam features:"); + _cam->printCamFeatures({ + "AcquisitionFrameRate", + "AcquisitionFrameCount", + "DeviceTemperature", + "SensorWidth", + "SensorHeight", + "ExposureTime", + "Gain", + "FileSize", + "PayloadSize", + "PixelFormat", + "PixelSize", + }); + + info("-------------------------------"); + info("get stream stats:"); + _cam->printStreamFeatures({ + "StatFrameDropped", + "StatLocalRate", + "StatFrameRescued", + "StatFrameShoved", + "StatFrameUnderrun", + "StatPacketErrors", + "StatPacketMissed", + "StatPacketReceived", + "StatPacketRequested", + "StatPacketResent", + "StatTimeElapsed", + "StatFrameDelivered", }); } -- GitLab