Skip to content
Snippets Groups Projects
Commit 2549e387 authored by am0ebe's avatar am0ebe
Browse files

add pingScan.sh to search and find cams when they get a new ip adress in direct connection

parent d161e4ba
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ _id(""), ...@@ -25,7 +25,7 @@ _id(""),
_state(disconnected), _state(disconnected),
_rec() _rec()
{ {
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << ""; // qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
} }
// Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other) // Cam::Cam(const Cam& other) : IPrinter(), std::enable_shared_from_this<Cam>(other)
...@@ -123,20 +123,33 @@ void Cam::close() ...@@ -123,20 +123,33 @@ void Cam::close()
void Cam::printFeatures( QString feature) void Cam::printFeatures( QString feature)
{ {
if(_state != opened)
return error("cant access features if cam is " + stateToString(_state) + " cam");
printFeatures(QStringList(feature)); printFeatures(QStringList(feature));
} }
void Cam::printFeatures( QStringList features) void Cam::printFeatures( QStringList features)
{ {
if(_state != opened)
return error("cant access features if cam is " + stateToString(_state) + " cam");
for( auto feature : features ) for( auto feature : features )
{ {
try try
{ {
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
qDebug() << feature << "| " << feature.toStdString().c_str();
// auto vcam = _cam->getCameraPtr();
FeaturePtr pFeature; FeaturePtr pFeature;
_cam->GetFeatureByName(feature.toStdString().c_str(), pFeature); g( _cam->GetFeatureByName(feature.toStdString().c_str(), pFeature) );
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
VmbFeatureDataType type; VmbFeatureDataType type;
g( pFeature->GetDataType(type) ); g( pFeature->GetDataType(type) );
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
switch(type) switch(type)
{ {
...@@ -183,7 +196,7 @@ void Cam::printFeatures( QStringList features) ...@@ -183,7 +196,7 @@ void Cam::printFeatures( QStringList features)
catch (const std::runtime_error& xx) catch (const std::runtime_error& xx)
{ {
qDebug() << __FUNCTION__ << "Exception caught: " << xx.what(); qDebug() << __FUNCTION__ << "Exception caught: " << xx.what();
continue; break;
} }
} }
} }
...@@ -200,8 +213,8 @@ QString Cam::camInfo() ...@@ -200,8 +213,8 @@ QString Cam::camInfo()
try try
{ {
camInfo += name() + DELIM; // camInfo += name() + DELIM;
camInfo += ip() + DELIM; // camInfo += ip() + DELIM;
camInfo += id() + DELIM; camInfo += id() + DELIM;
std::string str; std::string str;
...@@ -214,11 +227,11 @@ QString Cam::camInfo() ...@@ -214,11 +227,11 @@ QString Cam::camInfo()
g(_cam->GetInterfaceID( str )); g(_cam->GetInterfaceID( str ));
camInfo += QString::fromStdString(str) + DELIM; camInfo += QString::fromStdString(str) + DELIM;
camInfo += stateToString(_state); camInfo += stateToString(_state) + DELIM;
if( _state == recording) if( _state == recording)
_rec->showProgress(); //xxx string to add to camInfo _rec->showProgress(); //xxx string to add to camInfo
else else
camInfo += "recdur:" + formatTime( _rec->dur().count() * 1000 ) + DELIM; camInfo += "recdur: " + formatTime( _rec->dur().count() * 1000 ) + DELIM;
} }
catch(const std::exception& e) catch(const std::exception& e)
......
...@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) ...@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
// XXX add new func // XXX add new func
QTimer::singleShot(0, Console::getInstance(), SLOT(printVersion())); QTimer::singleShot(0, Console::getInstance(), SLOT(printVersion()));
QTimer::singleShot(2000, &core, SLOT(openCam())); // for testing QTimer::singleShot(4000, &core, SLOT(openCam())); // for testing
return a.exec(); return a.exec();
} }
...@@ -56,8 +56,8 @@ void Core::init() ...@@ -56,8 +56,8 @@ void Core::init()
_cameras.push_back(pcam); _cameras.push_back(pcam);
} }
// detectCams();
showInfo(); showInfo();
detectCams();
// listCams(); // listCams();
} }
...@@ -180,8 +180,11 @@ void Core::stopRecording() ...@@ -180,8 +180,11 @@ void Core::stopRecording()
void Core::showRecordingStats() void Core::showRecordingStats()
{ {
if( cam() && cam()->rec() ) qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
if( cam() && cam()->rec() && cam()->_cam )
{
cam()->rec()->showStats(); cam()->rec()->showStats();
}
} }
void Core::showInfo() void Core::showInfo()
...@@ -198,7 +201,11 @@ void Core::showInfo() ...@@ -198,7 +201,11 @@ void Core::showInfo()
print("-------------------------------"); print("-------------------------------");
if( cam() && cam()->rec() ) if( cam() && cam()->rec() )
cam()->rec()->checkDirExists(); {
print(QString("checkDirExists: %1").arg(cam()->rec()->checkDirExists()));
showRecordingStats();
// cam()->rec()->showStats();
}
//listCams //listCams
//showStats //showStats
//checkDiskSpace (show progressbar) //checkDiskSpace (show progressbar)
......
#!/bin/bash
#scans class-B subnet 169.254.i.j
#watch CPU usage and adapt max_jobs / timeout / step_size vars to ur system
step_size=8
max_jobs=50 # Maximum number of concurrent pings
timeout=3 # Timeout for each ping in seconds
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 ""
fi
# echo $i
for j in {0..255}; do
if [[ "$i" == 255 && "$j" == 255 ]]; then
continue #ignore broadcast
fi
ip="169.254.$i.$j"
(
if timeout "$timeout"s ping -c1 -W1"$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
fi
done
done
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" &) ;
...@@ -25,21 +25,12 @@ _frames(FramePtrVector(utils::threadsPerCam())) ...@@ -25,21 +25,12 @@ _frames(FramePtrVector(utils::threadsPerCam()))
_timer->setInterval( duration_cast<milliseconds>(utils::recDuration()) ); _timer->setInterval( duration_cast<milliseconds>(utils::recDuration()) );
connect(_timer, SIGNAL(timeout()), this, SLOT(stop())); connect(_timer, SIGNAL(timeout()), this, SLOT(stop()));
_updateTimer->setInterval(1000);
_updateTimer->setInterval(duration_cast<milliseconds>(updateInterval));
connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showProgress())); connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showProgress()));
connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showStats())); connect(_updateTimer, SIGNAL(timeout()), this, SLOT(showStats()));
} }
// Record::Record() : IPrinter(),
// _cam(nullptr),
// _timer(nullptr),
// _updateTimer(nullptr),
// _dir(""),
// _payloadSize(0LL),
// _pixelFormat(""),
// _frames()
// {}
void Record::init(CamPtr cam) void Record::init(CamPtr cam)
{ {
_cam = cam; _cam = cam;
...@@ -116,7 +107,7 @@ void Record::start() ...@@ -116,7 +107,7 @@ void Record::start()
_cam->setState(Cam::recording); _cam->setState(Cam::recording);
_timer->start(); _timer->start();
// _updateTimer->start(); _updateTimer->start();
} }
/* Does: /* Does:
...@@ -165,6 +156,7 @@ void Record::stop() ...@@ -165,6 +156,7 @@ void Record::stop()
void Record::showStats() void Record::showStats()
{ {
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
_cam->printFeatures("StatFrameDropped"); _cam->printFeatures("StatFrameDropped");
_cam->printFeatures({ _cam->printFeatures({
// "StatFrameDropped", //unsigned int max 4294967295 // "StatFrameDropped", //unsigned int max 4294967295
...@@ -187,6 +179,7 @@ void Record::showProgress() ...@@ -187,6 +179,7 @@ void Record::showProgress()
{ {
//TODO test //TODO test
//fps? //fps?
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
info( progressBar(_timer) ); info( progressBar(_timer) );
} }
...@@ -194,28 +187,50 @@ void Record::checkDiskSpace(const QString &dir, seconds dur) ...@@ -194,28 +187,50 @@ void Record::checkDiskSpace(const QString &dir, seconds dur)
{ {
QStorageInfo storageInfo(dir); QStorageInfo storageInfo(dir);
//in bytes // In bytes
qint64 available = storageInfo.bytesAvailable(); qint64 available = storageInfo.bytesAvailable();
qint64 total = storageInfo.bytesTotal(); qint64 total = storageInfo.bytesTotal();
qint64 used = calcDirSize(dir); qint64 used = calcDirSize(dir);
int usedPercentage = (double(used) / total) * 100; int usedPercentage = (double(used) / total) * 100;
info( progressBar(usedPercentage) ); // << cuz of this line, the function is here not in utils... info(progressBar(usedPercentage)); // << cuz of this line, the function is here not in utils...
qint64 estimated = dur.count() * utils::fps() * utils::frameSize(); qint64 estimated = dur.count() * utils::fps() * utils::frameSize();
qDebug() << "Used Space:" << used / (1024 * 1024) << "MB"; auto formatSize = [](qint64 size) -> QString {
qDebug() << "Available Space:" << available / (1024 * 1024) << "MB"; double displaySize = size;
qDebug() << "Total Space:" << total / (1024 * 1024) << "MB"; QString unit = "MB";
const qint64 ONE_MB = 1024LL * 1024LL;
const qint64 ONE_GB = ONE_MB * 1024LL;
const qint64 ONE_TB = ONE_GB * 1024LL;
if (size >= ONE_TB) {
displaySize = size / double(ONE_TB);
unit = "TB";
} else if (size >= ONE_GB) {
displaySize = size / double(ONE_GB);
unit = "GB";
} else {
displaySize = size / double(ONE_MB);
}
return QString::number(displaySize, 'f', 2) + " " + unit;
};
qDebug() << "Used Space:" << formatSize(used);
qDebug() << "Available Space:" << formatSize(available);
qDebug() << "Total Space:" << formatSize(total);
qDebug() << "Used Percentage:" << usedPercentage << "%"; qDebug() << "Used Percentage:" << usedPercentage << "%";
qDebug() << "Estimated Recording Space:" << estimated / (1024 * 1024) << "MB"; qDebug() << "Estimated Recording Space:" << formatSize(estimated);
// Check if estimated recording space exceeds available space // Check if estimated recording space exceeds available space
if (estimated > available) { if (estimated > available) {
warning("Estimated recording space exceeds available space!)"); warning("Estimated recording space exceeds available space!");
} }
} }
//calc basedir size //calc basedir size
qint64 Record::calcDirSize(const QDir &dirrr) { qint64 Record::calcDirSize(const QDir &dirrr) {
QDir dir(dirrr); QDir dir(dirrr);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "typeDefinitions.h" #include "typeDefinitions.h"
#include <QDir> #include <QDir>
#include <chrono>
class QTimer; class QTimer;
...@@ -22,8 +23,6 @@ public: ...@@ -22,8 +23,6 @@ public:
void setDur(seconds); void setDur(seconds);
seconds dur(); seconds dur();
void showStats();
void showProgress();
void checkDiskSpace(const QString &, seconds); void checkDiskSpace(const QString &, seconds);
bool checkDirExists(); bool checkDirExists();
...@@ -35,6 +34,8 @@ public: ...@@ -35,6 +34,8 @@ public:
public slots: public slots:
void stop(); void stop();
void showStats();
void showProgress();
private: private:
...@@ -48,6 +49,8 @@ private: ...@@ -48,6 +49,8 @@ private:
std::string _pixelFormat; std::string _pixelFormat;
FramePtrVector _frames; FramePtrVector _frames;
const seconds updateInterval = 2s;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment