Browse Source

AGP clean#1

AGP
Evgeny Gagua 12 months ago
parent
commit
9ab1c27715
  1. 7
      Projects/la_mojo/build
  2. 180
      lib/App/3dGUI/main-qt.cpp
  3. 454
      lib/App/3dGUI/main_window.cpp
  4. 216
      lib/App/3dGUI/main_window.h
  5. 741
      lib/App/3dSERVER/LRF_ClientHandler.cpp
  6. 62
      lib/App/3dSERVER/LRF_ClientHandler.h
  7. 105
      lib/App/3dSERVER/LRF_DefenderHandler.cpp
  8. 29
      lib/App/3dSERVER/LRF_DefenderHandler.h
  9. 24
      lib/App/3dSERVER/LRF_Detector.cpp
  10. 29
      lib/App/3dSERVER/LRF_Detector.h
  11. 2644
      lib/App/3dSERVER/LRF_HardwareManager.cpp
  12. 229
      lib/App/3dSERVER/LRF_HardwareManager.h
  13. 111
      lib/App/3dSERVER/LRF_KafkaHandler.cpp
  14. 29
      lib/App/3dSERVER/LRF_KafkaHandler.h
  15. 972
      lib/App/3dSERVER/LRF_Kernel.cpp
  16. 143
      lib/App/3dSERVER/LRF_Kernel.h
  17. 105
      lib/App/3dSERVER/LRF_SafeShoreHandler.cpp
  18. 33
      lib/App/3dSERVER/LRF_SafeShoreHandler.h
  19. 513
      lib/App/3dSERVER/LRF_Server.cpp
  20. 40
      lib/App/3dSERVER/LRF_Server.h
  21. 966
      lib/App/3dSERVER/LRF_SlimKernel.cpp
  22. 142
      lib/App/3dSERVER/LRF_SlimKernel.h
  23. 579
      lib/App/3dSERVER/LRF_TargetTracker.cpp
  24. 73
      lib/App/3dSERVER/LRF_TargetTracker.h
  25. 1276
      lib/App/3dSERVER/LRF_TwinConnector.cpp
  26. 137
      lib/App/3dSERVER/LRF_TwinConnector.h
  27. 275
      lib/App/CudaWare_64_DNN_Learning/main_window.cpp
  28. 88
      lib/App/CudaWare_64_DNN_Learning/main_window.h
  29. 273
      lib/App/CudaWare_64_DNN_Learning/main_window.ui
  30. 275
      lib/App/Pathfinder/PathfinderBackend.cpp
  31. 46
      lib/App/Pathfinder/PathfinderBackend.h
  32. 769
      lib/App/Pathfinder/Pathfinder_Kernel.cpp
  33. 157
      lib/App/Pathfinder/Pathfinder_Kernel.h
  34. 127
      lib/App/QTPro3DGUI/main.cpp
  35. 198
      lib/App/QTPro3DGUI/mainwindow.cpp
  36. 92
      lib/App/QTPro3DGUI/mainwindow.h
  37. 609
      lib/App/QTPro3DGUI/mainwindow.ui
  38. 286
      lib/App/argus/ArgusBackend.cpp
  39. 50
      lib/App/argus/ArgusBackend.h
  40. 637
      lib/App/argus/RGoose_Kernel.cpp
  41. 133
      lib/App/argus/RGoose_Kernel.h
  42. 286
      lib/App/argus_server/ArgusBackend.cpp
  43. 46
      lib/App/argus_server/ArgusBackend.h
  44. 637
      lib/App/argus_server/ArgusKernel.cpp
  45. 125
      lib/App/argus_server/ArgusKernel.h
  46. 246
      lib/App/defender/ArgusBackend.cpp
  47. 50
      lib/App/defender/ArgusBackend.h
  48. 217
      lib/App/defender/RGoose_Kernel.cpp
  49. 58
      lib/App/defender/RGoose_Kernel.h
  50. 151
      lib/App/mastbaumGUI/main.cpp
  51. 437
      lib/App/mastbaumGUI/main_window.cpp
  52. 135
      lib/App/mastbaumGUI/main_window.h
  53. 126
      lib/App/mastbaumSERVER/ClientHandler.cpp
  54. 34
      lib/App/mastbaumSERVER/ClientHandler.h
  55. 1326
      lib/App/mastbaumSERVER/Kernel.cpp
  56. 239
      lib/App/mastbaumSERVER/Kernel.h
  57. 16
      lib/App/mastbaumSERVER/NetworkManager.cpp
  58. 16
      lib/App/mastbaumSERVER/NetworkManager.h
  59. 516
      lib/App/mastbaumSERVER/Server.cpp
  60. 33
      lib/App/mastbaumSERVER/Server.h
  61. 136
      lib/App/mastbaumSERVER/interProcessProto.cpp
  62. 24
      lib/App/mastbaumSERVER/interProcessProto.h
  63. 165
      lib/App/videoAnal/main.cpp
  64. 119
      lib/App/videoAnal/main_window.cpp
  65. 170
      lib/App/videoAnal/main_window.h
  66. 14
      lib/defender-dc-trig/rgooseClassAccess.h
  67. 471
      lib/defender-dc-trig/rgooseDBConnector.cpp
  68. 79
      lib/defender-dc-trig/rgooseDBConnector.h
  69. 68
      lib/defender-dc-trig/rgooseIPCamera.cpp
  70. 56
      lib/defender-dc-trig/rgooseIPCamera.h
  71. 40
      lib/defender-dc-trig/rgooseNode.h
  72. 143
      lib/defender-dc-trig/rgooseNodeFactory.cpp
  73. 28
      lib/defender-dc-trig/rgooseNodeFactory.h
  74. 6
      lib/defender-dc-trig/rgooseServerModule.cpp
  75. 16
      lib/defender-dc-trig/rgooseServerModule.h
  76. 127
      lib/defender-dc-trig/rgooseStructures.h
  77. 298
      lib/defender-dc-trig/rgooseUSBRelayModule.cpp
  78. 43
      lib/defender-dc-trig/rgooseUSBRelayModule.h
  79. 9
      lib/defender-dc-trig/rgooseVideoTranscoderModule.h

7
Projects/la_mojo/build

@ -1,14 +1,7 @@
#! /bin/sh
#make clean -e "CFG=Debug"
#make -e "CFG=Debug" -j$(nproc)
make clean -e "CFG=Debug86"
make -e "CFG=Debug86" -j$(nproc)
#make clean -e "CFG=Release86"
#make -e "CFG=Release86" -j$(nproc)
#cd Release86
#strip ./mojo
#cd ..

180
lib/App/3dGUI/main-qt.cpp

@ -1,180 +0,0 @@
#ifndef __linux__
#include <winsock2.h>
#endif
#include <stdio.h>
//https://autotire.co.il/%D7%92%D7%A0%D7%98%D7%99%D7%9D-%D7%92%D7%A0%D7%98%D7%99%D7%9D-5x114.3-15
#ifdef _NO_STDIO_IOB_FUNC_
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }
#endif
#include "main_window.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "../../data/media/mediaVideoSourceManager.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectSystemAnchor.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../data/net/onvifDeviceNode.h"
#include "../../components/object/objectEventReport.h"
#define LOG(X) mpLog->Log( "Main", NULL, X )
#define LOG_DEBUG( X ) mpLog->Log( "Main", NULL, _LOG_DEBUG, X )
#define LOG_ERROR( X ) mpLog->Log( "Main", NULL, _LOG_ERROR, X )
#ifdef __linux__
int main(int argc, char *argv[]) {
#else
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){
Beep(512, 512);
Beep(256, 512);
Beep(128, 1024);
#endif
guiClass * GUI;
systemAnchor * ANCH;
GUI = guiClass::getInstance();
#ifdef __linux__
GUI->init( argc, argv);
#else
GUI->init(0, NULL);
#endif
ANCH = systemAnchor::getInstance();
basicLogCollection *mpLog = basicLogCollection::getInstance();
objectFileLoggingService *fLog;
char tPath[1024];
char *ttPtz=NULL;
//ttPtz = (char *)GUI->getApp()->applicationDirPath().toStdString().c_str();
if( ttPtz!= NULL ){
sprintf(tPath, "%s/my.log", ttPtz);
} else {
sprintf(tPath, "my.log" );
};
fLog = new objectFileLoggingService(tPath);
mpLog->addHandler((basicLoggingService *)fLog);
printf("From now - refer to log file\n");
LOG_DEBUG("ENTER APPLICATION");
basicSettingsProvider *mpSettingsProvider = basicSettingsProvider::getInstance();
basicEventHeap *mpEventHeap = basicEventHeap::getInstance();
mediaVideoSourceManager *LS = mediaVideoSourceManager::getInstance();
//sprintf(tPath, "%s/data/storage", GUI->getApp()->applicationDirPath().toStdString().c_str());
sprintf(tPath, "data/storage");
//ToDO: Check Report Object!
//objectEventReport *mpReporter = objectEventReport::getInstance();
//storageProvider *mpStorPro = storageProvider::getInstance(tPath);
config_setting_t *mpSettings;
//mpStorPro->startNewSeries(); // Each prog start starts new Series
#ifdef __linux__
LOG_DEBUG("SS Disabled");
#else
//UINT lActiveFlag = 0;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, NULL, NULL);
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
UINT timeoutLowPower;
UINT timeoutPowerOff;
UINT timeoutScreenSave;
{
SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0, &(timeoutLowPower), 0);
SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, &(timeoutPowerOff), 0);
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &(timeoutScreenSave), 0);
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
}
LOG_DEBUG("SS Disabled");
#endif
mpSettings = mpSettingsProvider->getSubNode(NULL, "APPLICATION_GUI");
mainWinow *window;
window = mainWinow::getInstance();
//Check Startup Mode
int gAppStartupMode;
config_setting_t *pSetting;
if (!config_setting_lookup_int(mpSettings, "STARTUP_WINDOW_MODE", &gAppStartupMode )){
gAppStartupMode = 0;
pSetting = config_setting_add(mpSettings, "STARTUP_WINDOW_MODE", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
};
switch( gAppStartupMode ){
case 0: window->show(); break;
case 1: window->showMaximized(); break;
case 2: window->showFullScreen(); break;
default:
gAppStartupMode = 0;
pSetting = config_setting_lookup(mpSettings, "STARTUP_WINDOW_MODE");
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
window->showMaximized();
};
joysticObject::getInstance();
delete GUI;
delete window;
delete LS;
delete mpEventHeap;
delete mpSettingsProvider;
#ifdef __linux__
LOG_DEBUG("SS Enabled");
#else
{
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, timeoutLowPower, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, timeoutPowerOff, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, timeoutScreenSave, NULL, 0);
}
LOG_DEBUG("SS Enabled");
//lActiveFlag = 1;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0);
//lActiveFlag = 20;
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
//LOG_DEBUG("SS Enabled");
#endif
LOG_DEBUG("EXIT APPLICATION");
delete mpLog;
return 0;
};
#undef LOG
#undef LOG_DEBUG
#undef LOG_ERROR
/*---------------------------------------*/
/* A sample program to play C major */
/* through a PC speaker */
/*---------------------------------------*/
/* This won't work if standard output is */
/* re-directed to a non-tty device, or */
/* PC speaker wave output is active */
/*---------------------------------------*/
/* M.G. 27-Nov-99 */
/*---------------------------------------*/
/*
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/kd.h>
int main(void)
{
int freq[] = { // C D E F G A B C
523, 587, 659, 698, 784, 880, 988, 1046 };
int i;
for (i = 0; i<8; i++)
{
ioctl(STDOUT_FILENO, KIOCSOUND, 1193180 / freq[i]);
usleep(500000);
}
ioctl(STDOUT_FILENO, KIOCSOUND, 0); // Stop silly sound
return 0;
}
*/

454
lib/App/3dGUI/main_window.cpp

@ -1,454 +0,0 @@
#include "main_window.h"
mainWinow* mainWinow::_instance = 0;
void mainWinow::changeEvent(QEvent *event){
if(event->type() == QEvent::WindowStateChange ){
if (!isMinimized()) {
setAttribute(Qt::WA_Mapped);
};
};
};
mainWinow::mainWinow() : QMainWindow(){
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "APPLICATION_GUI");
//m_pJoyStick = joysticObject::getInstance();
m_pReportManager = NULL;
m_pReportCreator = objectEventReport::getInstance();
m_pMainWidget = new QWidget(NULL);
m_pMainWidget->setObjectName("m_pMainWidget");
setCentralWidget(m_pMainWidget);
/*
Layout:
https://www.youtube.com/watch?v=T15mFICDV-U
+--------v--------+
| +---+---+---+ |
| | | |-v-| |
| +---+-h-+---+ |
+-----------------+
| +-----------+ |
| +-----------+ |
+-----------------+
*/
setObjectName("Mainwindow");
m_bUserRecordsVideo = false;
m_pVerticalLayout = new QVBoxLayout( m_pMainWidget );
qDebug() << "m_pVerticalLayout";
m_pVerticalLayout->setSpacing(0);//6
m_pVerticalLayout->setContentsMargins(10, 10, 10, 10);
m_pVerticalLayout->setObjectName("m_pVerticalLayout");
m_pTitleWidget = new TimeShowWidget( m_pMainWidget );
qDebug() << "m_pTitleWidget";
m_pVerticalLayout->addWidget(m_pTitleWidget);
m_pHorizontalLayout = new QHBoxLayout();
qDebug() << "m_pHorizontalLayout";
m_pHorizontalLayout->setObjectName("m_pHorizontalLayout");
m_pHorizontalLayout->setSpacing(0);//6
m_pRangeMap = new RangeMapWidget( m_pMainWidget );
qDebug() << "m_pRangeMap";
m_pRangeMap->setObjectName("m_pRangeMap");
m_pVerticalMapLayout = new QVBoxLayout();
qDebug() << "m_pVerticalMapLayout";
m_pVerticalMapLayout->setObjectName("m_pVerticalMapLayout");
m_pVerticalMapLayout->setContentsMargins(0, 0, 0, 0);
m_pVerticalMapLayout->addWidget(m_pRangeMap);
/* Range Map Mode Controls */
//QHBoxLayout *mpLayout;
mpLayout = new QHBoxLayout();
qDebug() << "mpLayout";
mpLayout->setObjectName("mpLayout");
m_pButton5 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton5";
m_pButton5->setIcon(QIcon(":pictures/appbar.arrow.collapsed.png"));
m_pButton5->setObjectName("MainwindowBtnHBox1B1");
m_pButton5->setIconSize(QSize(40, 40));
m_pButton5->setFixedSize(220, 40);
m_pButton5->setText(QStringLiteral("Show Minimums"));
m_pButton5->setCheckable(true);
m_pButton5->setChecked(true);
m_pButton5->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton5, &QPushButton::clicked, this, &mainWinow::handleMinimumsPress);
mpLayout->addWidget(m_pButton5);
m_pButton6 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton6";
m_pButton6->setIcon(QIcon(":pictures/appbar.arrow.expand.png"));
m_pButton6->setObjectName("m_pButton6");
m_pButton6->setIconSize(QSize(40, 40));
m_pButton6->setFixedSize(220, 40);
m_pButton6->setText(QStringLiteral("Show Maximums"));
m_pButton6->setCheckable(true);
m_pButton6->setChecked(false);
m_pButton6->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton6, &QPushButton::clicked, this, &mainWinow::handleMaximumsPress);
mpLayout->addWidget(m_pButton6);
m_pButton7 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton7";
m_pButton7->setIcon(QIcon(":pictures/appbar.alien.png"));
m_pButton7->setObjectName("m_pButton7");
m_pButton7->setIconSize(QSize(40, 40));
m_pButton7->setFixedSize(220, 40);
m_pButton7->setText(QStringLiteral("Test Working TH"));
m_pButton7->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton7, &QPushButton::clicked, this, &mainWinow::handleGenerateWS);
mpLayout->addWidget(m_pButton7);
m_pButton8 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton8";
m_pButton8->setIcon(QIcon(":pictures/appbar.camera.png"));
m_pButton8->setObjectName("m_pButton8");
m_pButton8->setIconSize(QSize(40, 40));
m_pButton8->setFixedSize(220, 40);
m_pButton8->setText(QStringLiteral("Take Snap"));
m_pButton8->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton8, &QPushButton::clicked, this, &mainWinow::handleSave2DPicture);
mpLayout->addWidget(m_pButton8);
mpSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
qDebug() << "mpSpacer";
mpLayout->addItem(mpSpacer);
m_pVerticalMapLayout->addItem(mpLayout);
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
qDebug() << "verticalSpacer";
m_pVerticalMapLayout->addItem(verticalSpacer);
m_pHorizontalLayout->addItem(m_pVerticalMapLayout);
m_pHorizontalLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);// , 0, Qt::AlignLeft | Qt::AlignTop);
m_pVerticalSideLayout = new QVBoxLayout();
qDebug() << "m_pVerticalSideLayout";
m_pVerticalSideLayout->setObjectName("m_pVerticalSideLayout");
//m_pVerticalSideLayout->setSpacing(3);
m_pVerticalSideLayout->setContentsMargins(0, 0, 11, 0);
m_pButtonCmdClear = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdClear";
m_pButtonCmdClear->setIcon(QIcon(":pictures/appbar.new.png"));
m_pButtonCmdClear->setIconSize(QSize(40, 40));
m_pButtonCmdClear->setFixedSize(220,54);
m_pButtonCmdClear->setText(QStringLiteral("Clear Events Log"));
m_pButtonCmdClear->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdClear, &QPushButton::clicked, this, &mainWinow::callbackClear);
m_pButtonCmdReset = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdReset";
m_pButtonCmdReset->setIcon(QIcon(":pictures/appbar.radar.screen.png"));
m_pButtonCmdReset->setIconSize(QSize(40, 40));
m_pButtonCmdReset->setFixedSize(220,54);
m_pButtonCmdReset->setText(QStringLiteral("Reset Target Detection"));
m_pButtonCmdReset->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
m_pButtonCmdSilence = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdSilence";
m_pButtonCmdSilence->setIcon(QIcon(":pictures/appbar.sound.0.png"));
m_pButtonCmdSilence->setIconSize(QSize(40, 40));
m_pButtonCmdSilence->setFixedSize(220, 54);
m_pButtonCmdSilence->setText(QStringLiteral("Silence Alarm"));
m_pButtonCmdSilence->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdSilence, &QPushButton::clicked, this, &mainWinow::handleSilencePress);
m_pButtonCmdSettings = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdSettings";
m_pButtonCmdSettings->setIcon(QIcon(":pictures/appbar.cog.png"));
m_pButtonCmdSettings->setIconSize(QSize(40, 40));
m_pButtonCmdSettings->setFixedSize(220, 54);
m_pButtonCmdSettings->setText(QStringLiteral("Settings"));
m_pButtonCmdSettings->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdSettings, &QPushButton::clicked, this, &mainWinow::callbackSettings);
m_pButtonCmdReport = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdReport";
m_pButtonCmdReport->setIcon(QIcon(":pictures/appbar.cabinet.files.variant.png"));
m_pButtonCmdReport->setIconSize(QSize(40, 40));
m_pButtonCmdReport->setFixedSize(220, 54);
m_pButtonCmdReport->setText(QStringLiteral("Report"));
m_pButtonCmdReport->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdReport, &QPushButton::clicked, this, &mainWinow::handleReports);
m_pButtonCmdExit = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdExit";
m_pButtonCmdExit->setIcon(QIcon(":pictures/appbar.power.png"));
m_pButtonCmdExit->setIconSize(QSize(40, 40));
m_pButtonCmdExit->setFixedSize(220, 54);
m_pButtonCmdExit->setText(QStringLiteral("Exit"));
m_pButtonCmdExit->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdExit, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
m_pVerticalSideLayout->addWidget(m_pButtonCmdClear);// , 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdReset);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdSilence);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdReport);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdExit);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdSettings);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
verticalSideSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
qDebug() << "verticalSideSpacer";
m_pVerticalSideLayout->addItem(verticalSideSpacer);
// End Right Menu Layout */
m_pHorizontalLayout->addItem(m_pVerticalSideLayout);
m_pVerticalLayout->addItem(m_pHorizontalLayout);
// Control Panels
m_pTabWidget = new QTabWidget( m_pMainWidget );
qDebug() << "m_pTabWidget";
m_pTabWidget->setObjectName("m_pTabWidget");
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(1);
sizePolicy.setHeightForWidth(m_pTabWidget->sizePolicy().hasHeightForWidth());
m_pTabWidget->setSizePolicy(sizePolicy);
//m_pTabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
/* Layout 1 */
m_pPage1 = new QWidget(m_pTabWidget);
m_pPage1->setObjectName("m_pPage1");
m_pPage1Layout = new QHBoxLayout(m_pPage1);
m_pPage1Layout->setObjectName("m_pPage1Layout");
m_pEventsList = new EventViewerList(m_pPage1);
m_pEventsList->setObjectName("m_pEventsList");
//m_pEventsList->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_pPage1Layout->addWidget(m_pEventsList);// , 0, Qt::AlignLeft | Qt::AlignTop);
//m_pPage1->setLayout(m_pPage1Layout);
m_pTabWidget->addTab(m_pPage1, QString("Events Log"));
/* Layout 2 */
m_pPage2 = new QWidget(m_pTabWidget);
m_pPage2Layout = new QHBoxLayout(m_pPage2);
m_pPage2Layout->setObjectName("m_pPage2Layout");
m_pMainVideoWidget = new VideoWidget( m_pPage2 );
m_pMainVideoWidget->init();
m_pMainVideoWidget->setError( true, "No Source Choisen" );
//
m_pScrollArea = new QScrollArea(m_pPage2);
QSizePolicy sPolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
sPolicy.setHeightForWidth(m_pScrollArea->sizePolicy().hasHeightForWidth());
m_pScrollArea->setSizePolicy(sPolicy);
m_pScrollArea->setMinimumSize(QSize(0, 100)); // 200
m_pScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pScrollArea->setWidgetResizable(true);
m_pScrollAreaWidgetContents = new VideoSourceChooser( m_pPage2 );
m_pScrollArea->setWidget(m_pScrollAreaWidgetContents);
m_pScrollAreaWidgetContents->setMainMediaViewer( m_pMainVideoWidget );
m_pMainVideoWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_pVVVLayout = new QVBoxLayout(m_pPage2);
m_pVVVLayout->setObjectName("m_pVVVLayout");
m_pVVVLayout->addWidget(m_pMainVideoWidget);
//m_pPage2Layout->addWidget(m_pMainVideoWidget);// , 0, Qt::AlignHCenter | Qt::AlignTop);
//m_pVSpacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
//m_pVVVLayout->addItem(m_pVSpacer1);
m_pPage2Layout->addItem( m_pVVVLayout );
m_pVCVLayout = new QVBoxLayout(m_pPage2);
m_pVCVLayout->setObjectName("m_pVCVLayout");
m_pVCVLayout->addWidget(m_pScrollArea);
m_pButtonCmdVideoRecord = new QPushButton( m_pPage2 );
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
m_pButtonCmdVideoRecord->setIconSize(QSize(40, 40));
//m_pButtonCmdVideoRecord->setFixedSize(220, 54);
m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
m_pButtonCmdVideoRecord->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdVideoRecord, &QPushButton::clicked, this, &mainWinow::handleVideoRecorder);
m_pVCVLayout->addWidget(m_pButtonCmdVideoRecord);
m_pVSpacer2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
m_pVCVLayout->addItem(m_pVSpacer2);
//m_pPage2Layout->addWidget(m_pScrollArea);
m_pPage2Layout->addItem(m_pVCVLayout);
m_pTabWidget->addTab(m_pPage2, QString("Video Surveillance"));
/* Layout 3 */
m_pPage3 = new QWidget(m_pTabWidget);
m_pPage3Layout = new QVBoxLayout(m_pPage3);
m_pPage3Layout->setObjectName("m_pPage3Layout");
//m_pPage3Layout->addItem(mpLayout);
/* New Device Management */
m_pDevScrollArea = new QScrollArea(m_pPage3);
QSizePolicy sDPolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
sDPolicy.setHeightForWidth(m_pScrollArea->sizePolicy().hasHeightForWidth());
m_pDevScrollArea->setSizePolicy(sDPolicy);
m_pDevScrollArea->setMinimumSize(QSize(0, 400));
m_pDevScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_pDevScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pDevScrollArea->setWidgetResizable(true);
m_pDevScrollAreaWidgetContents = new DeviceChooser( this );
m_pDevScrollArea->setWidget( m_pDevScrollAreaWidgetContents );
//m_pDevScrollAreaWidgetContents->setMainMediaViewer(m_pMainVideoWidget);
m_pPage3Layout->addWidget(m_pDevScrollArea);
m_pTabWidget->addTab(m_pPage3, QString("Device Controll"));
/* Tab 4 */
m_pPage4 = new QWidget(m_pTabWidget);
m_pPage4Layout = new QVBoxLayout(m_pPage4);
m_pPage4Layout->setObjectName("m_pPage4Layout");
m_pGLRadar = new GLRadar(m_pPage4);// , QColor(0, 0, 0));
m_pPage4Layout->addWidget(m_pGLRadar);
m_pTabWidget->addTab(m_pPage4, QString("3D View"));
/* Tab 5 */
m_pPage5 = new QWidget(m_pTabWidget);
m_pPage5Layout = new QVBoxLayout(m_pPage5);
m_pPage5Layout->setObjectName("m_pPage5Layout");
m_pRangeRadar = new RadarMapWidget(m_pPage5);
//m_pGLRadar = new GLRadar(NULL, QColor(0, 0, 0));
m_pPage5Layout->addWidget(m_pRangeRadar);
m_pTabWidget->addTab(m_pPage5, QString("2D View"));
m_pVerticalLayout->addWidget(m_pTabWidget);
//connect(m_pScrollAreaWidgetContents->m_pButtonCmdAdd, SIGNAL(clicked()), m_pScrollAreaWidgetContents, SLOT(m_pScrollAreaWidgetContents->showAddSourceDialog()));
resize(800, 600);
setWindowTitle( "3D Single IPI" );
setWindowIcon( QIcon(":pictures/status/gray-240.png") );
m_pStatusBar = new QStatusBar(this);
m_pStatusBar->setObjectName(QStringLiteral("statusBar"));
m_pStatusBar->setStyleSheet(QStringLiteral("background-color: rgb(255, 170, 0);"));
setStatusBar(m_pStatusBar);
m_pDevScrollAreaWidgetContents->setSelectedDevice(0);
};
mainWinow::~mainWinow(){
delete(m_pScrollAreaWidgetContents);
};
/**
* Returns the single instance of the object.
*/
mainWinow* mainWinow::getInstance() {
// check if the instance has been created yet
if (0 == _instance){
// if not, then create it
_instance = new mainWinow();
};
// return the single instance
return _instance;
};
void mainWinow::callbackSettings(void){
//if (m_pDeviceSettings == NULL){
// m_pDeviceSettings = new DialogSettingsLGS(this);
// m_pDeviceSettings->attachMasterDevice( m_pMasterDevice );
// m_pDeviceSettings->attachSlaveDevice( m_pSlaveDevice );
//};
//m_pDeviceSettings->updateValues();
//m_pDeviceSettings->show();
};
void mainWinow::callbackClear(void){
m_pEventsList->clear();
m_pGLRadar->clearTargets();
m_pRangeRadar->clearTargets();
m_pRangeMap->clearTargets();
m_pTitleWidget->setStatus( TSW_ARMING );
};
void mainWinow::handleButtonPress(){
QString fileName;
fileName = QFileDialog::getOpenFileName(this, "Open Data", "data/", "Data Files (*.raw *.jpg *.bmp)");
char fName[MAX_PATH];
sprintf(fName, "%s", fileName.toStdString().c_str() );
m_pRangeMap->loadFromFile(fName);
m_pGLRadar->loadFromFile(fName);
};
void mainWinow::handleMaximumsPress(){
m_pButton5->setChecked(false);
m_pButton6->setChecked(true);
m_pRangeMap->setMaximums();
m_pRangeRadar->setMaximums();
};
void mainWinow::handleMinimumsPress(){
m_pButton5->setChecked(true);
m_pButton6->setChecked(false);
m_pRangeMap->setMinimums();
m_pRangeRadar->setMinimums();
};
void mainWinow::handleGenerateWS(){
m_pRangeMap->startGenerateWS();
};
void mainWinow::handleSave2DPicture( void ){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save 2D Map As", "data/", "Picture Files (*.png *.jpg *.bmp)");
m_pRangeMap->savePicture(fileName);
};
void mainWinow::handleSave3DPicture( void ){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save 3D Picture As", "data/", "Picture Files (*.png)");
QPixmap image = QPixmap::grabWidget(m_pGLRadar);
if(!image.save(fileName, "PNG")){
QMessageBox::warning(this, "Save Image", "Error saving image.");
};
};
void mainWinow::handleAddMask(){
if( m_pRangeMap!= NULL ){
m_pRangeMap->setAddMaskMode();
};
};
void mainWinow::handleDeleteMask(){
if (m_pRangeMap != NULL){
m_pRangeMap->setDeleteMaskMode();
};
};
void mainWinow::handleSilencePress(){
basicEvent *pEvt;
basicCameraCommand *tData;
absCameraMoveParam *tParam;
tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
if (tData != NULL) {
tParam = (absCameraMoveParam*)malloc(sizeof(absCameraMoveParam));
if (tParam != NULL) {
tData->m_cCode = CMD_CAMERA_SET_PTZ;
tData->m_pParam = tParam;
tParam->m_fPan = 180.f;
tParam->m_fTilt = 0.f;
tParam->m_fRange = 1.f;
pEvt = createBasicEvent(0, EVT_CLASS_IMAGE, EVT_COMMAND, "Test Event", tData);
basicEventHeap::getInstance()->broadcast(pEvt);
};
};
};
void mainWinow::handleVideoRecorder(){
basicEvent *pEvt;
basicCameraCommand *tData;
tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
tData->m_pParam = NULL;
if(!m_bUserRecordsVideo){
// Generate Video Event -> Starts Record
tData->m_cCode = CMD_CAMERA_START_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_VIDEO, EVT_COMMAND, "User Starts Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = true;
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.control.stop.png"));
m_pButtonCmdVideoRecord->setText(QStringLiteral("Stop Record"));
} else {
tData->m_cCode = CMD_CAMERA_STOP_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_VIDEO, EVT_COMMAND, "User Stops Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = false;
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
};
};
void mainWinow::handleReports(){
if (m_pReportManager == NULL ){
m_pReportManager = new guiReportsManagerDialog((QDialog *)this);
};
m_pReportManager->showMaximized();
};

216
lib/App/3dGUI/main_window.h

@ -1,216 +0,0 @@
#ifndef __QT5_MAIN_WINDOW_HEADER__
#define __QT5_MAIN_WINDOW_HEADER__
#ifndef __linux__
#include <WinSock2.h>
#endif
#include "../../components/base/basicSettingsProvider.h"
#include "../../gui/guiClass.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../gui/controls/VideoWidget.h"
#include "../../gui/controls/OpenGLWidget.h"
#include "../../gui/controls/OGLRadarWidget.h"
#include "../../gui/controls/RangeMapWidget.h"
#include "../../gui/controls/RadarMapWidget.h"
#include "../../gui/controls/VideoSourceChooser.h"
#include "../../gui/controls/DeviceChooser.h"
#include "../../gui/controls/TimeShowWidget.h"
#include "../../gui/controls/EventViewWidget.h"
#include "../../gui/dialogs/ReportsManagerDialog.h"
#include "../../gui/controls/mapControl/QMapControl"
#include "../../gui/controls/mapControl/openaerialmapadapter.h"
#include "../../components/object/objectLGS.h"
#include "../../components/object/objectEventReport.h"
//#include "../../gui/controls/SettingsLGS.h"
#include "../../hardware/stick/joystick.h"
class mainWinow : public QMainWindow{
private:
config_setting_t *m_pSettings;
/* Main Widget */
QWidget *m_pMainWidget;
/* Layouts */
//QMainWindowLayout *m_pMainLayout;
QVBoxLayout *m_pVerticalLayout;
QVBoxLayout *m_pVerticalMapLayout;
QVBoxLayout *m_pVerticalSideLayout;
QHBoxLayout *m_pHorizontalLayout;
QHBoxLayout *m_pScrolbarLayout;
QVBoxLayout *m_pVVVLayout;
QVBoxLayout *m_pVCVLayout;
QPushButton *m_pButtonCmdVideoRecord;
QSpacerItem *m_pVSpacer1;
QSpacerItem *m_pVSpacer2;
QSpacerItem *m_pVSpacer3;
joysticObject *m_pJoyStick;
/* Widgets */
QFrame *m_pTitleFrame;
TimeShowWidget *m_pTitleWidget;
QStatusBar *m_pStatusBar;
QSpacerItem *verticalSpacer;
QSpacerItem *verticalSideSpacer;
QSpacerItem *horisontalSpacer;
QSpacerItem *scrolbarSpacer;
QPushButton *m_pButtonCmdClear;
QPushButton *m_pButtonCmdReset;
QPushButton *m_pButtonCmdSilence;
QPushButton *m_pButtonCmdReport;
QPushButton *m_pButtonCmdExit;
QPushButton *m_pButtonCmdSettings;
QScrollArea *m_pScrollArea;
QScrollArea *m_pDevScrollArea;
EventViewerList *m_pEventsList;
//QWidget *m_pScrollAreaWidgetContents;
DeviceChooser *m_pDevScrollAreaWidgetContents;
VideoSourceChooser *m_pScrollAreaWidgetContents;
QPushButton *m_pAddVideoSource;
VideoWidget *m_pMainVideoWidget;
//clientPort *m_pMasterSocket;
//clientPort *m_pSlaveSocket;
//objectLGS *m_pMasterDevice;
//objectLGS *m_pSlaveDevice;
guiReportsManagerDialog *m_pReportManager;
objectEventReport *m_pReportCreator;
//Control Panels
QTabWidget *m_pTabWidget;
QWidget *m_pPage1;
QWidget *m_pPage2;
QWidget *m_pPage3;
QWidget *m_pPage4;
QWidget *m_pPage5;
QHBoxLayout *m_pPage1Layout;
QHBoxLayout *m_pPage2Layout;
QVBoxLayout *m_pPage3Layout;
QVBoxLayout *m_pPage4Layout;
QVBoxLayout *m_pPage5Layout;
QPushButton *m_pButton1;
QPushButton *m_pButton2;
QPushButton *m_pButton3;
QPushButton *m_pButton4;
QPushButton *m_pButton5;//Add Mask
QPushButton *m_pButton6;//Delete Mask
QPushButton *m_pButton7;//Activate Masks
QPushButton *m_pButton8;//Deactivate Masks
QHBoxLayout *mpLayout;
QSpacerItem *mpSpacer;
QProgressBar *m_pProgressBar;
QHBoxLayout *m_pHorizontalLayout1;
QHBoxLayout *m_pHorizontalLayout2;
QHBoxLayout *m_pHorizontalLayout3;
QRadioButton *m_pRadioButton1;
QRadioButton *m_pRadioButton2;
QGroupBox *m_pRadioGroup;
QGroupBox *m_pSampleGroup;
QComboBox *m_pLRFCombo;
QLabel *m_pStMiRalabel;
QLabel *m_pStMaRalabel;
QLabel *m_pStMiSalabel;
QLabel *m_pStMaSalabel;
QLabel *m_pStMiRaVal;
QLabel *m_pStMaRaVal;
QLabel *m_pStMiSaVal;
QLabel *m_pStMaSaVal;
QLabel *m_pOpLabel;
bool m_bUserRecordsVideo;
private slots:
void handleSilencePress();
void handleButtonPress();
void handleButton2Press();
void handleMaximumsPress();
void handleMinimumsPress();
void handleGenerateWS();
void handleSave2DPicture( void );
void handleSave3DPicture(void);
void handleAddMask();
void handleDeleteMask();
void handleUpdateMask();
void handleSetStatusMask();
void handleVideoRecorder();
void handleReports();
/*Map*/
MapControl *m_pMapControl;
MapAdapter *m_pMapAdapter;
/* OpenGL */
RangeMapWidget *m_pRangeMap;
RadarMapWidget *m_pRangeRadar;
GLRadar *m_pGLRadar;
QPixmap *notepixmap;
Layer* sights;
Layer* museum;
Layer* pubs;
Layer* notes;
Layer* base;
/*Map*/
/*
mediaBus *m_pVideoBus1;
videoAVLIBSource *m_pVideoIpput1;
VideoThumbWidget *m_pVideoWidget1;
mediaBus *m_pVideoBus2;
videoAVLIBSource *m_pVideoIpput2;
VideoThumbWidget *m_pVideoWidget2;
mediaBus *m_pVideoBus3;
videoAVLIBSource *m_pVideoIpput3;
VideoThumbWidget *m_pVideoWidget3;
*/
//serialPort *mSerial;
//protocolPTZ_VISCA *mCamera;
public:
// Method to fetch singleton instance.
static mainWinow* getInstance();
// Destructor
virtual ~mainWinow();
RangeMapWidget *getRangeMap( void ){
return m_pRangeMap;
};
RadarMapWidget *getRadarMap( void ){
return m_pRangeRadar;
};
GLRadar *getGLRadar( void ){
return m_pGLRadar;
};
protected:
mainWinow();
void changeEvent(QEvent *event);
private:
// private static member referencing the single instance of the object
// TODO: Replace basicLogCollection with the type of object you want to
// return the single instance of
static mainWinow* _instance;
// Copy constructor
// Declared but not defined to prevent auto-generated
// copy constructor. Refer to "Effective C++" by Meyers
mainWinow(const mainWinow& src);
// Assignment operator
// Declared but not defined to prevent auto-generated
// assignment operator. Refer to "Effective C++" by Meyers
mainWinow& operator=(const mainWinow& src);
public slots:
void callbackSettings(void);
void callbackClear(void);
};
#endif

741
lib/App/3dSERVER/LRF_ClientHandler.cpp

@ -1,741 +0,0 @@
#include "LRF_ClientHandler.h"
#ifndef PRU_SLAVE
#define LOG( X ) m_pLog->Log( "LRF_NCH", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LRF_NCH", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LRF_NCH", this, _LOG_ERROR, X );
#endif
#define SIZE_IDX_A 1
#define SIZE_IDX_B 2
#define DEV_ID_IDX 3
#define CMD_IDX 4
#define SUB_CMD_IDX 5
#define DATA_BEGIN_IDX 6
// Constructor implementation
LRF_ClientHandler::LRF_ClientHandler( int SockFD, networkServiceEngine *ptr ) : networkClientHandler( SockFD, ptr ), protocolLGS3D_Server(){
m_pLog = basicLogCollection::getInstance();
m_pWorkingSAF = NULL;
m_bKernelWM = WM_NONE;
m_bClientWM = CWM_INIT;
m_pKernelEngine = NULL;
m_pPort = new serverPort( SockFD );
if( m_pPort != NULL ){
#ifdef DEBUG
LOG("Server port is OK");
#endif
if( m_pPort->create() ) {
setTransport( m_pPort );
if( create() ){
attachEngine( ptr );
} else {
LOG_ERROR( "Protocol Parser Creation Failed!");
};
} else LOG_ERROR( "Create Port Failure!");
} else LOG_ERROR( "NEW Port Failure!");
};
// Destructor implementation
LRF_ClientHandler::~LRF_ClientHandler(){
# ifdef DEBUG
LOG("Destructor Start");
# endif
m_pKernelEngine = NULL;
# ifdef DEBUG
LOG("Destructor Finished!");
# endif
};
bool LRF_ClientHandler::attachEngine( networkServiceEngine *ptr ){
m_pKernelEngine = (LRF_Kernel *) ptr;
if( m_pKernelEngine!= NULL ) {
m_bKernelWM = (LRF3D_WORK_MODE) m_pKernelEngine->getWM();
} else {
m_bKernelWM = WM_NONE;
};
sendState( m_bKernelWM );
return true;
};
bool LRF_ClientHandler::getStatus( void ){
if( m_pPort == NULL ) return false;
return m_pPort->getStatus();
};
bool LRF_ClientHandler::packetHandler( protocolPackage *Package ){
if( Package != NULL ) {
#ifdef DEBUG
char tBuffer[256];
#ifdef DUBUG_COMMUNICATION
LOG("Package Handler");
sprintf( tBuffer, "Package Code: %d 0x%02X", Package->m_nCode, Package->m_nCode );
LOG( tBuffer );
#endif
#endif
switch(Package->m_nCode){
case CMD_STATE:
#ifdef DEBUG
LOG("Handshaking STATUS Request");
#endif
if( m_pKernelEngine != NULL ) {
m_bKernelWM = (LRF3D_WORK_MODE) m_pKernelEngine->getWM();
} else {
m_bKernelWM = WM_NONE;
};
sendState( m_bKernelWM );
// Set Working to translate Targets
//m_bClientWorkingMode = CWM_PINGPONG;
setWM( CWM_INIT );
//setWM( CWM_IDLE );
break;
case CMD_QUIT:
#ifdef DEBUG
LOG("QUIT Request");
#endif
m_pKernelEngine->shutdown();
setWM( CWM_INIT );
break;
case CMD_RESET:
#ifdef DEBUG
LOG("RESET Request");
#endif
sendResetACK();
setWM( CWM_INIT );
m_pKernelEngine->reset( false );
break;
case CMD_QUERY_TWINK_LINK:
#ifdef DEBUG
LOG("TWINC Check");
#endif
#ifdef SLIM_KERNEL
if( m_pKernelEngine != NULL ) {
LRF_TwinConnector *tTWINC = m_pKernelEngine->getTwinConnector();
if( tTWINC != NULL ) {
TWIN_STATUS *tSTATUS = tTWINC->getSystemStatus();
uint8_t status = 0;
if( tSTATUS->VERSION_IS_SYNCED ) status = 0x01;
if( tSTATUS->SETTINGS_IS_SYNCED ) status |= 0x02;
if( tSTATUS->SHADOW_IS_SYNCED ) status |= 0x04;
sendTwinLinkACK( status );
} else {
sendNACK( CMD_QUERY_TWINK_LINK );
};
} else {
sendNACK( CMD_QUERY_TWINK_LINK );
};
#else
sendNACK( CMD_QUERY_TWINK_LINK );
#endif
setWM( CWM_IDLE );
break;
case CMD_MODE:
if( Package->m_pData[SUB_CMD_IDX] & 0x80 ){ // Flag to SET Mode
U8 Byte = Package->m_pData[SUB_CMD_IDX] & MODE_MASK;
switch( Byte ){
case MODE_BORDER:
m_pWorkingSAF = (thresholdNode *) m_pKernelEngine->getTreshold( m_nWorkingSAF, 0 );
//if( m_bWorkinMode != Byte ) BorderEnable( Byte == MODE_BORDER );
break;
case MODE_DETECTOR:
case MODE_FILESYSTEM:
//BorderEnable( FALSE );
break;
};
#ifdef DEBUG
LOG("SET MODE Request");
#endif
sendMode( (E_CLIENT_WORK_MODE) Byte );
}
#ifdef DEBUG
else LOG("GET MODE Request");
#endif
sendMode( m_bClientWM );
break;
case CMD_GETFILE:
#ifdef DEBUG
LOG("GET_FILE Request");
#endif
setWM( CWM_FILE );
break;
case CMD_RESTART:
#ifdef DEBUG
LOG("RESTART Request");
#endif
sendResetACK();
setWM( CWM_INIT );
m_pKernelEngine->reset( false );
break;
case CMD_SET_ACTIVE_PROFILE: // Work Around oold 3D Client Software
case CMD_GET_PARAMETERS:
case CMD_PARAMETERS:
#ifdef DEBUG
LOG("PARAMETERS Request");
#endif
if( m_pKernelEngine != NULL ) {
PLGS_3D_PARAMETERS tPtr;
tPtr = m_pKernelEngine->getDetectionParameters();
if( tPtr != NULL ) {
sendParameters( tPtr );
free( tPtr );
} else {
// Handle error getting parameters
LOG_ERROR( "Can't get Parameters from Kernel!" );
sendParameters( NULL );
};
setWM( CWM_PARAMS );
} else {
LOG_ERROR("Kernel Engine not attached!");
sendParameters( NULL );
};
break;
case CMD_SET_PARAMETERS:
#ifdef DEBUG
LOG("SET PARAMETERS Request");
#endif
if( m_pKernelEngine != NULL ) {
PLGS_3D_PARAMETERS tPtr;
tPtr = (PLGS_3D_PARAMETERS) ( Package->m_pData + SUB_CMD_IDX );
if( !m_pKernelEngine->setDetectionParameters( tPtr ) ){
// Handle error setting parameters
LOG_ERROR( "Can't set Parameters!" );
};
setWM( CWM_PARAMS );
} else {
LOG_ERROR("Kernel Engine not attached!");
};
break;
case CMD_GET_SERIAL_NUMBER:
#ifdef DEBUG
LOG("GET SERIAL Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_SET_ADDRESS:
#ifdef DEBUG
LOG("SET ADDRESS Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_GET_SOFTWARE_VERSION:
#ifdef DEBUG
LOG("GET SOFTWARE VER Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_UNSUPPORTED:
#ifdef DEBUG
LOG("UNSUPORTED Request");
#endif
setWM( CWM_ERROR );
break;
case CMD_SET_COMM_SPEED:
setWM( CWM_PARAMS );
break;
case CMD_BORDER:
case CMD_FULL_BORDER:{
// Full Draw By LRF
U32 SampleID = Package->m_pData[5] << 24;
SampleID |= Package->m_pData[6] << 16;
SampleID |= Package->m_pData[7] << 8;
SampleID |= Package->m_pData[8];
U8 SelectedLRF = Package->m_pData[9];
# ifdef DEBUG
char tBuf[256];
sprintf( tBuf, "Requested Border Samples From: %d of %d",SampleID,TH_SIZE_NODES );
LOG( tBuf );
# endif
if( m_bClientWM != CWM_BORDER ) {
# ifdef DEBUG
LOG("Current Mode Isn't BORDER!");
# endif
if( SampleID == 0 ){
# ifdef DEBUG
LOG("Requesting TH access");
# endif
#ifdef SLIM_KERNEL
if ( m_pKernelEngine ) {
LRF_TwinConnector *tTWINC = m_pKernelEngine->getTwinConnector();
m_pWorkingSAF = tTWINC->getTreshold( m_nWorkingSAF, SelectedLRF );
};
#else
m_pWorkingSAF = m_pKernelEngine->getTreshold( m_nWorkingSAF, SelectedLRF );
#endif
};
if( m_pWorkingSAF != NULL ) {
m_nCurrentSampleIDofBoardData = 0;
# ifdef DEBUG
LOG("Requested TH access Granted");
# endif
sendBorderData( m_nCurrentSampleIDofBoardData, 0, m_pWorkingSAF );
// Will Ignore Other Events;
setWM( CWM_BORDER );
} else {
LOG_ERROR( "BORDER not Ready!");
sendBorderError( BD_NOTREADY );
setWM( CWM_IDLE );
};
} else {
if( SampleID < TH_SIZE_NODES ) {
m_nCurrentSampleIDofBoardData = SampleID;
sendBorderData( m_nCurrentSampleIDofBoardData, 0, m_pWorkingSAF );
if( SampleID > ( TH_SIZE_NODES - BOARDDATA_PACKAGE_SIZE_NODES ) ) {
# ifdef DEBUG
LOG( "Finishing Border Upload" );
# endif
setWM( CWM_IDLE );
};
};
};
break;
};
case CMD_FULL_RESET:
#ifdef DEBUG
LOG("FULL RESET Request");
#endif
sendFullResetACK();
setWM( CWM_INIT );
m_pKernelEngine->reset( true );
break;
case CMD_CAMERA:
#ifdef DEBUG
LOG("CAMERA Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_SET_SERIAL_NUMBER:
#ifdef DEBUG
LOG("SET SERIAL Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_BOARDDATA:
#ifdef DEBUG
LOG("BORDER DATA Request");
#endif
break;
case CMD_GET_CAMERA_PARAMETERS:
#ifdef DEBUG
LOG("GET CAMERA PARAMS Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_SET_CAMERA_PARAMETERS:
setWM( CWM_PARAMS );
break;
case CMD_RELAY:
setWM( CWM_PARAMS );
break;
case CMD_GET_RELAY_PARAMETERS:
setWM( CWM_PARAMS );
break;
case CMD_SET_RELAY_PARAMETERS:
setWM( CWM_PARAMS );
break;
case CMD_FS_SUB_PACKET:
setWM( CWM_FILE );
break;
case CMD_STATE_2:
if( m_bClientWM != CWM_BORDER ){
if( m_pKernelEngine != NULL ) {
if( m_pKernelEngine->getRuntimeStatus( &m_sRuntimeStatus ) ){
m_bKernelWM = (LRF3D_WORK_MODE)m_pKernelEngine->getWM();
} else {
m_bKernelWM = WM_NONE;
};
} else {
m_bKernelWM = WM_NONE;
};
m_mOutputProtector.lock();
uint8_t tCount = m_oOutputFIFO.size();
m_mOutputProtector.unlock();
sendState2( m_bKernelWM, tCount, &m_sRuntimeStatus );
/*
uint8_t tCount = 0;
uint8_t * tPData = NULL;
m_mOutputProtector.lock();
tCount = m_oOutputFIFO.size();
if( tCount > 0 ) {
tPData = (uint8_t *) malloc( tCount * sizeof(CLIENT_EVENT));
if( tPData!= NULL ) {
CLIENT_EVENT * tElm = NULL;
uint8_t * cPtr = tPData;
for( uint8_t index = 0; index < tCount; index++) {
tElm = m_oOutputFIFO.front();
memcpy( cPtr, tElm, sizeof(CLIENT_EVENT));
cPtr += sizeof(CLIENT_EVENT);
m_oOutputFIFO.pop();
free(tElm);
};
m_mOutputProtector.unlock();
sendState2( m_bKernelWM, tCount, tPData );
free(tPData);
} else {
m_mOutputProtector.unlock();
sendState2( m_bKernelWM );
};
} else {
m_mOutputProtector.unlock();
sendState2( m_bKernelWM );
};
*/
setWM( CWM_IDLE );
};
break;
case CMD_GET_LAST_EVENTS:{
uint8_t tCount = 0;
uint8_t * tPData = NULL;
m_mOutputProtector.lock();
tCount = m_oOutputFIFO.size();
if( tCount > 0 ) {
tPData = (uint8_t *) malloc( tCount * sizeof(CLIENT_EVENT));
if( tPData!= NULL ) {
CLIENT_EVENT * tElm = NULL;
uint8_t * cPtr = tPData;
for( uint8_t index = 0; index < tCount; index++) {
tElm = m_oOutputFIFO.front();
memcpy( cPtr, tElm, sizeof(CLIENT_EVENT));
cPtr += sizeof(CLIENT_EVENT);
m_oOutputFIFO.pop();
free(tElm);
};
m_mOutputProtector.unlock();
sendEvents( tCount, tPData );
free(tPData);
} else m_mOutputProtector.unlock();
} else m_mOutputProtector.unlock();
setWM( CWM_IDLE );
break;
};
case CMD_GET_WIDTH_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_SET_WIDTH_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_GET_VOLTAGE:
#ifdef DEBUG
LOG("Get Voltage Request");
#endif
setWM( CWM_PARAMS );
break;
case CMD_GET_VOLTAGE_PARAMETERS:
setWM( CWM_PARAMS );
break;
case CMD_SET_VOLTAGE_PARAMETERS:
setWM( CWM_PARAMS );
break;
case CMD_GET_CALIBRATION_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_SET_CALIBRATION_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_GET_LRF_DISABLE:
setWM( CWM_PARAMS );
break;
case CMD_SET_LRF_DISABLE:
setWM( CWM_PARAMS );
break;
case CMD_GET_ZOOM_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_SET_ZOOM_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_GET_TILT_TABLE:
setWM( CWM_PARAMS );
break;
case CMD_SET_TILT_TABLE:
setWM( CWM_PARAMS );
break;
/* Shadow Masking Hidden Zones */
case CMD_GET_HZ_DATA:
setWM( CWM_MASK );
break;
case CMD_SET_HZ_DATA:{
setWM( CWM_MASK );
LOG("Set RayTraced Mask");
ShadowMask *tShMaskObj;
tShMaskObj = m_pKernelEngine->getShadowMask();
if( tShMaskObj != NULL ){
uint16_t tCount;
uint16_t index;
uint16_t cColumn,cCount;
raySegment RS;
tCount = Package->m_pData[SUB_CMD_IDX];
tCount = ( tCount << 8 ) | Package->m_pData[SUB_CMD_IDX+1];
index = SUB_CMD_IDX+2;
for( int i=0; i < tCount; i++ ){
cColumn = Package->m_pData[index++];
cColumn = ( cColumn << 8 ) | Package->m_pData[index++];
cCount = Package->m_pData[index++];
cCount = ( cCount << 8 ) | Package->m_pData[index++];
for( int j = 0; j < cCount; j++ ){
RS.start = Package->m_pData[index++];
RS.start = ( RS.start << 8 ) | Package->m_pData[index++];
RS.stop = Package->m_pData[index++];
RS.stop = ( RS.stop << 8 ) | Package->m_pData[index++];
tShMaskObj->addRay( cColumn, RS );
};
};
tShMaskObj->setActive(true);
tShMaskObj->saveRastered();
};
};
break;
case CMD_GET_HZ_ENABLE:
setWM( CWM_MASK );
break;
case CMD_SET_HZ_ENABLE:
setWM( CWM_MASK );
break;
case CMD_GET_HZ_INFO:{
setWM( CWM_MASK );
ShadowMask *tShMaskObj;
sendShadowInfo( m_pKernelEngine->getShadowMask());
};
break;
//case CMD_SET_HZ_STATUS:??
//case CMD_HZ_INFO:??
case CMD_GET_HZ_POLY:{
ShadowMask *tShMaskObj;
uint8_t mPolyID;
setWM( CWM_MASK );
mPolyID = Package->m_pData[SUB_CMD_IDX];
tShMaskObj = m_pKernelEngine->getShadowMask();
if( tShMaskObj != NULL ) {
vectorMasking VM;
tShMaskObj->getMPoly(VM);
if( VM.size() > mPolyID ) {
sendShadowPoly( VM.at(mPolyID) );
};
};
};
break;
case CMD_SET_HZ_POLY:{
uint8_t mCount;
ShadowMask *tShMaskObj;
setWM( CWM_MASK );
mCount = Package->m_pData[SUB_CMD_IDX];
tShMaskObj = m_pKernelEngine->getShadowMask();
if( tShMaskObj != NULL ) {
if( mCount == 0 ) {
// Clean All Existed Zones
LOG("CLear All Poly");
tShMaskObj->clear();
} else {
simplePolygone *tPolygone;
tPolygone = new simplePolygone();
if( tPolygone!=NULL ){
#ifdef DEBUG
char tBuffer[120];
sprintf(tBuffer, "Add Poly: %d Vertexes", mCount );
LOG( tBuffer );
#endif
tPolygone->count = mCount;
tPolygone->color[0] = Package->m_pData[6];
tPolygone->color[1] = Package->m_pData[7];
tPolygone->color[2] = Package->m_pData[8];
tPolygone->points = (simplePoint*) malloc( sizeof(simplePoint) * tPolygone->count );
if( tPolygone->count && tPolygone->points!= NULL ){
uint16_t x, y;
int index = 9;
for( int i=0; i< tPolygone->count; i++ ){
x = Package->m_pData[index++];
x = ( x << 8 ) | Package->m_pData[index++];
y = Package->m_pData[index++];
y = ( y << 8 ) | Package->m_pData[index++];
tPolygone->points[i].setX(x);
tPolygone->points[i].setY(y);
};
tShMaskObj->addPoly( tPolygone );
tShMaskObj->saveVertexes();
} else {
free( tPolygone );
};
};
};
sendSetPolyACK( tShMaskObj->getPolyCount() );
} else {
LOG_ERROR("Access to ShadowMap Failure!");
};
};
break;
case CMD_GET_HZ_STATUS:
setWM( CWM_MASK );
break;
case CMD_DHWM_START_MOTORS:
if( m_pKernelEngine != NULL ) {
//ToDo: Make This in Thread Child Function // Done
if( !m_pKernelEngine->startMotors() ){
// Handle error setting parameters
LOG_ERROR( "Can't start Motors!" );
};
} else {
LOG_ERROR("Kernel Engine not attached!");
};
sendGenericACK(true);
break;
case CMD_DHWM_STOP_MOTORS:
if( m_pKernelEngine != NULL ) {
if( !m_pKernelEngine->stopMotors() ){
// Handle error setting parameters
LOG_ERROR( "Can't stop Motors!" );
};
} else {
LOG_ERROR("Kernel Engine not attached!");
};
sendGenericACK(true);
break;
default:
LOG_ERROR( "Not Implemented Command Was received" );
#ifdef DEBUG
sprintf( tBuffer, "Package Code: %d 0x%02X SUB: 0x%02X", Package->m_nCode, Package->m_nCode, Package->m_pData[SUB_CMD_IDX] );
LOG( tBuffer );
#endif
break;
};
//free( Package->m_pData );
//free( Package );
};
return true;
};
void LRF_ClientHandler::dispatchEvent( EVENT_CONTAINER *Evt ){
if ( Evt == NULL ) return;
if ( getWM() != CWM_IDLE) return;
if( Evt->m_eClass == EVT_CLASS_SENSOR_3D ) {
CLIENT_EVENT * tCEVT = NULL;
switch( Evt->m_eType ) {
case EVT_TARGET_1D:
case EVT_TARGET_2D_WHITE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_3D_WHITE:
case EVT_TARGET_3D_BLACK:
case EVT_ALARM:{
#ifdef COM_SERVER_PULL
if( Evt->m_pEvtData != NULL ) {
tCEVT = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
if( tCEVT!= NULL ){
memcpy( tCEVT , Evt->m_pEvtData, sizeof(CLIENT_EVENT) );
//tCEVT->type = EVT_TARGET_2D_WHITE;
} else LOG_ERROR("No MEM FOR EVT");
};
#else
if( Evt->m_pEvtData != NULL ) {
CLIENT_EVENT *tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData;
bool isBlack = ( Evt->m_eType == EVT_TARGET_3D_BLACK );
//if ( k_id < 8 ) {
//}
//a_th_node
#ifdef DEBUG
char zoppA[128];
sprintf( zoppA, "Encoded Data: 0x%02X TH: %d K:%d R:%d WC:%d", Evt->m_eType, tCEVT->th_id, tCEVT->k_id, tCEVT->range, tCEVT->w_cnt );
LOG( zoppA );
#endif
sendTargetM( tCEVT->th_id, tCEVT->k_id, tCEVT->range, tCEVT->w_cnt, isBlack );
};
#endif
break;
};
case EVT_ERROR:
#ifndef COM_SERVER_PULL
//sendEvent( 0xA5 );
#endif
break;
case EVT_SCAN:
#ifndef COM_SERVER_PULL
sendScan();
#endif
break;
case EVT_FLIP:{
#ifdef COM_SERVER_PULL
if( Evt->m_pEvtData != NULL ) {
tCEVT = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
if( tCEVT!= NULL ){
memcpy( tCEVT , Evt->m_pEvtData, sizeof(CLIENT_EVENT) );
} else LOG_ERROR("No MEM FOR EVT");
};
#else
sendFlip( 1212 );
#endif
break;
};
case EVT_COMMAND:
break;
default:
LOG_ERROR("Unknown Event!");
};
if( tCEVT!= NULL ) {
m_mOutputProtector.lock();
while( m_oOutputFIFO.size() >= EVENTS_OUTPUT_QUEUE_MAX ) { //MAXIMAL_EVENT_COUNT_IN_PACKET
CLIENT_EVENT * tt;
tt = m_oOutputFIFO.front();
m_oOutputFIFO.pop();
free(tt);
#ifdef DEBUG
LOG("Events Overflow!");
#endif
};
m_oOutputFIFO.push( tCEVT );
m_mOutputProtector.unlock();
#ifdef DEBUG
LOG("Event Queued");
#endif
};
} else {
#ifdef DEBUG
LOG( "No SENSOR CLASS EVT ");
#endif
};
};
void LRF_ClientHandler::setWM( CLIENT_WORK_MODE NM ){
m_mWMProtector.lock();
if ( m_bClientWM != NM ) {
m_bClientWM = NM;
};
m_mWMProtector.unlock();
};
CLIENT_WORK_MODE LRF_ClientHandler::getWM(){
CLIENT_WORK_MODE rV;
m_mWMProtector.lock();
rV = m_bClientWM;
m_mWMProtector.unlock();
return rV;
};
#undef SIZE_IDX
#undef DEV_ID_IDX
#undef CMD_IDX
#undef SUB_CMD_IDX
#undef DATA_BEGIN_IDX
#undef LOG
#undef LOG_ERROR
#endif //PRU_SLAVE

62
lib/App/3dSERVER/LRF_ClientHandler.h

@ -1,62 +0,0 @@
#ifndef __LRF_CLIENTHANDLER_H_INCL__
#define __LRF_CLIENTHANDLER_H_INCL__
#ifndef PRU_SLAVE
#include "../../data/protocol/protocolLGS3D_server.h"
#include "../../data/net/netClientHandler.h"
#ifdef SLIM_KERNEL
#include "LRF_SlimKernel.h"
#else
#include "LRF_Kernel.h"
#endif
#include "LRF_SlimKernel.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMutex.h"
//#define COM_SERVER_PULL
/**
* TODO: Add class description
*
* @author Gagua
*/
class LRF_ClientHandler : public networkClientHandler, public protocolLGS3D_Server {
private:
basicLogCollection * m_pLog;
LRF_Kernel * m_pKernelEngine;
LRF3D_WORK_MODE m_bKernelWM;
CLIENT_WORK_MODE m_bClientWM;
basicMutex m_mWMProtector;
thresholdNode * m_pWorkingSAF;
uint32_t m_nWorkingSAF;
uint32_t m_nCurrentSampleIDofBoardData;
EventsFIFO m_oOutputFIFO;
basicMutex m_mOutputProtector;
ALG_RUN_STATUS m_sRuntimeStatus;
void setWM( CLIENT_WORK_MODE );
CLIENT_WORK_MODE getWM();
protected:
bool packetHandler( protocolPackage *Package );
public:
// Constructor
explicit LRF_ClientHandler( int SockFD, networkServiceEngine *ptr = NULL );
// Destructor
virtual ~LRF_ClientHandler();
virtual bool attachEngine( networkServiceEngine *ptr );
virtual bool getStatus( void );
void dispatchEvent( EVENT_CONTAINER *Evt );
};
#endif // PRU_SLAVE
#endif // __LRF_CLIENTHANDLER_H_INCL__

105
lib/App/3dSERVER/LRF_DefenderHandler.cpp

@ -1,105 +0,0 @@
#include "LRF_DefenderHandler.h"
#define LOG( X ) m_pLog->Log( "LRF_DefenderHandler", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LRF_DefenderHandler", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LRF_DefenderHandler", this, _LOG_ERROR, X );
#endif
// Constructor implementation
LRF_DefenderHandler::LRF_DefenderHandler( config_setting_t *SNode ) : basicThread(), basicEventHandler(), protocolDefender( SNode ){
m_pLog = basicLogCollection::getInstance();
basicThread::init();
};
// Destructor implementation
LRF_DefenderHandler::~LRF_DefenderHandler(){
};
/* Periodical Job Handler */
void LRF_DefenderHandler::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
m_llTicks ++;//= getMilliseconds();
if( m_llTicks % 20 == 0 ) { // each 2 seconds
StatusUpdate();
//m_lCycleCounter == 0;
};
/* No need for time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
StartTimeSynch();
//m_lCycleCounter == 0;
};
*/
SLEEP(100);
};
};
void LRF_DefenderHandler::dispatchEvent( EVENT_CONTAINER *Evt ){
#ifdef DEBUG
LOG( "CLIENT's DISPATCHER");
#endif
if( Evt == NULL ) {
LOG( "Evt NULL");
return;
};
if( Evt->m_eClass == EVT_CLASS_SENSOR_3D ) {
#ifdef DEBUG
char tBuffer[256];
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
LOG( tBuffer );
#endif
switch( Evt->m_eType ) {
case EVT_TARGET_1D:
case EVT_TARGET_2D_WHITE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_3D_WHITE:
case EVT_TARGET_3D_BLACK:
case EVT_ALARM:{
CLIENT_EVENT *tCEVT;
tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData;
if( tCEVT != NULL ){
float Az, El;
uint32_t cRange;
cRange = (uint32_t)(((float) tCEVT->range ) * 0.0732421875f ) ; // To meters
#ifdef PRU_SLAVE
make3Ddeg( tCEVT->th_id, Az, El, false );
#else
make3Ddeg( tCEVT->th_id, Az, El, true );
#endif
Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id );
};
};
break;
case EVT_ERROR:
SetStatus( false );
break;
case EVT_SCAN:
//StatusUpdate();
//break;
case EVT_FLIP:
SetStatus( true );
//StatusUpdate();
break;
case EVT_COMMAND:
break;
default:
LOG_ERROR("Unknown Event!");
};
} else {
#ifdef DEBUG
LOG( "No SENSOR EVT ");
#endif
}
};
#undef LOG
#undef LOG_ERROR

29
lib/App/3dSERVER/LRF_DefenderHandler.h

@ -1,29 +0,0 @@
#ifndef __LRF_DEFENDER_HANDLER_H_INCL__
#define __LRF_DEFENDER_HANDLER_H_INCL__
#include "../../data/protocol/protocolLGS.h"
#include "../../data/net/netClientHandler.h"
#include "../../components/base/basicLogCollection.h"
#include "../../data/protocol/protocolDefender.h"
#include "../../data/net/clientPort.h"
/**
* TODO: Add class description
*
* @author Gagua
*/
class LRF_DefenderHandler : public basicThread, public basicEventHandler, public protocolDefender {
private:
basicLogCollection * m_pLog;
EventsFIFO m_oOutputFIFO;
clientPort * m_pSocketPort;
unsigned long long m_llTicks;
protected:
virtual void m_fThreadProc( void );
public:
explicit LRF_DefenderHandler( config_setting_t *SNode );
virtual ~LRF_DefenderHandler();
virtual bool dispatchEvent( EVENT_CONTAINER *Evt );
};
#endif // __LRF_CLIENTHANDLER_H_INCL__

24
lib/App/3dSERVER/LRF_Detector.cpp

@ -1,24 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Detector.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Detector.cpp
//----------------------------------------------------------------------------
//
#include "LRF_Detector.h"
LRF_Detector::LRF_Detector(): targetDetector(){
};
LRF_Detector::~LRF_Detector(){
};

29
lib/App/3dSERVER/LRF_Detector.h

@ -1,29 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Detector.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Detector.h
//----------------------------------------------------------------------------
//
#ifndef __LRF_DETECTOR_HEADER__
#define __LRF_DETECTOR_HEADER__
#include "../../alg/lgs/detector.h"
class LRF_Detector: public targetDetector{
bool m_bModeIsSet;
public:
LRF_Detector();
~LRF_Detector();
};
#endif

2644
lib/App/3dSERVER/LRF_HardwareManager.cpp
File diff suppressed because it is too large
View File

229
lib/App/3dSERVER/LRF_HardwareManager.h

@ -1,229 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_HardwareManager.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_HardwareManager.h
//----------------------------------------------------------------------------
//
#ifndef __LRF_HARDWAREMANAGER_H_INCL__
#define __LRF_HARDWAREMANAGER_H_INCL__
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "../../hardware/soc/classSOC.h"
#include "../../hardware/soc/general/3DLRF.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../hardware/soc/general/sitara-am437x.h"
#ifndef PRU_SLAVE
#include "../../hardware/can/canbus.h"
#include "../../data/protocol/protocolTGZ.h"
#endif
//#define IGNORE_PRU_FLIP
#define IGNORE_PRU_SCAN
#define AM355X_SIGN_ZONE (0x44E10000)
#define AM355X_SIGN_VAL (0x00000000)
#define AM437X_SIGN_ZONE (0x44E10000)
#define AM437X_SIGN_VAL (0x4F000100)
typedef enum{
SOC_UNKNOWN = 0,
SOC_AM335X = 1,
SOC_AM437X = 2
} E_SOC_TYPE;
typedef enum eDataStatuses{
BUFFER_UNDERRUN = -1,
BUFFER_EMPTY = 0,
BUFFER_OK = 1
} E_DATA_STATUS;
#define HWM_SETTINGS_ROLE "MASTER_ROLE"
#define HWM_SETTINGS_TH_DUMP "DUMP_TH_ON_DISK"
#define HWM_SETTINGS_CTRL_V_MOTOR "VERTICAL_MOTOR_CTRL"
#define HWM_SETTINGS_CTRL_H_MOTOR "HORIZONTAL_MOTOR_CTRL"
#define HWM_SETTINGS_V_MOTOR_SETPOINT "VERTICAL_ENC_FREQ"
#define HWM_SETTINGS_H_MOTOR_SETPOINT "HORIZONTAL_ENC_FREQ"
#define HWM_SETTINGS_V_PULSES_INTERLEAVE "LRF_PULSES_INTERLEAVE"
#define HWM_SETTINGS_LRF_ENABLED "LRF_ENABLED"
#define HWM_SETTINGS_SYM_ENABLED "SIMULATION_ENABLED"
#define HWM_SETTINGS_SYM_FREQ "SIMULATION_FREQ"
#define HWM_SETTINGS_AUTOSTART_ENABLED "MOTORS_AUTOSTART"
#define HWM_SETTINGS_AUTO_TH_GENERATE "TH_GENERATED_BY_PRU"
#define HWM_SETTINGS_TH_OFFSET "TH_OFFSET"
#define HWM_SETTINGS_TH_ORDER "TH_ORDER"
#define HWM_SETTINGS_TH_DELTA "TH_DELTA"
#define HWM_SETTINGS_TH_FLIP_SIZE "TH_FLIP"
#define HWM_SETTINGS_TH_SPIKE_SIZE "TH_SPIKE_SIZE"
#define HWM_SETTINGS_TH_GOOD_POINTS "TH_GOOD_POINTS"
#define HWM_SETTINGS_SIG_SYMULATOR "SIG_SYM_ENABLE"
#define HWM_SETTINGS_CAN_CONTROL_ENABLE "CAN_BUS_ENABLE"
#define HWM_SETTINGS_CAN_BUS_ID "CAN_BUS_ID"
#define HWM_SETTINGS_CAN_MY_ID "CAN_MY_ID"
#define HWM_SETTINGS_CAN_TGZ_ID "CAN_TGZ_ID"
#define HWM_SETTINGS_LRF_PRF "LRF_PRF"
#define HWM_SETTINGS_Q_TO_B_BOUNCE "QB_BOUNCE"
#define HWM_SETTINGS_SUNBIT "SUNBIT_ENABLE"
#define HWM_SETTINGS_B_SHIFT "BASE_SHIFT"
#define HWM_SETTINGS_Q_SHIFT "MIRROR_SHIFT"
#define HWM_SETTINGS_DENCITY "SCAN_DENCITY"
#ifndef TGD_VERSION_2
#define HWM_SETTINGS_TGZ_DIVIDER "TGZ_DIV"
#define HWM_SETTINGS_TGZ_PRF "TGZ_PRF"
#define HWM_SETTINGS_TGZ_RATIO "TGZ_RATIO"
#else
#define HWM_SETTINGS_TGZ_MIRROR_SPEED "TGZ_MIRROR_SPEED"
#define HWM_SETTINGS_TGZ_BASE_SPEED "TGZ_BASE_SPEED"
#endif
/**
* Class to talk with Hardware via MemMap
*
* @author gagua
*/
class LRF_HardwareManager {
private:
LGS_3D_PARAMETERS m_sPARAMETERS;
/* General System Variables*/
basicLogCollection *m_pLog;
config_setting_t *m_pSettings;
basicSettingsProvider *m_pSettingsProvider;
E_SOC_TYPE m_eSOC;
bool m_bDumpMemoryToDisk;
bool m_bWorkEnable;
DT_STATUS m_sCS_Detector;
TH_PARAMS m_sCP_Detector;
HW_PARAMS m_sHW_Params;
HWM_CSTATUS m_sRuntimeStatus;
#ifdef IGNORE_PRU_FLIP
uint8_t m_bStudyCompleteFlag; // Used to clean Primary (learning TH)
uint8_t m_bDataFilledTH;
#endif
#ifndef PRU_SLAVE
MO_STATUS m_sCS_Motors;
canBus *m_pCanBus;
protocolTGZ *m_pTGZdevice;
#endif
bool m_bInitOK;
bool readPercs( void );
uint32_t m_iDataIndex;
uint32_t m_nKernelFilter;
void *m_vMemoryBlock[4];
#ifndef ONPC_TOTTAL_SIMULATOR
classSOC *m_pSOC;
#endif
bool performFlip();
uint8_t m_bTHSteadyCounter[KERNEL_COUNT];
bool cleanTH( uint8_t tID );
void beginService( void );
void restartService( void );
void endService( void );
void saveCurrentParameters( void );
/* For Flip Purposes */
uint8_t m_nFlipEnaFLags;
uint8_t m_nDetectionFilter;
uint8_t m_nTHVisualFlags;
#ifdef THREADED_FLIP
pthread_t *m_pFlipThreadHandler;
static void *m_fFlipThreadFunction(void *);
pthread_mutex_t *m_pFlipMutex;
bool m_bFlipUnlockRequested;
bool m_bWaitFirstFlip;
#endif
#ifndef PRU_SLAVE
#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_MOTORS_START
pthread_t *m_pMotorCtrlThreadHandler;
static void *m_fMotorStartThreadFunction(void *);
static void *m_fMotorStopThreadFunction(void *);
pthread_mutex_t *m_pMotorCtrlMutex;
void performStartMotors( void );
void performStopMotors( void );
#endif
#endif
#endif
public:
// Constructor
explicit LRF_HardwareManager( config_setting_t *SNode = NULL );
// Destructor
virtual ~LRF_HardwareManager();
#ifndef ONPC_TOTTAL_SIMULATOR
bool isSitara( void ){ return m_eSOC>SOC_UNKNOWN; };
#else
bool isSitara( void ){ return true; };
#endif
#ifdef PRU_SLAVE
bool isMaster( void ){ return false; };
#else
bool isMaster( void ){ return true; };
#endif
bool getCoreStatus( DT_STATUS &Status );
bool getDetectionParams( TH_PARAMS &Params );
bool setDetectionParams( TH_PARAMS *Params );
bool getHardwareParams( HW_PARAMS &Params );
bool setHardwareParams( PHW_PARAMS Params );
bool getParams( LGS_3D_PARAMETERS &Params );
bool setParams( LGS_3D_PARAMETERS *Params );
thresholdNode *getWorkingMemory( void );
int getWorkingMemoryID( void );
uint32_t *getEventMemory( void );
uint8_t getTargetFilter( void ){ return m_nDetectionFilter; };
uint8_t getTHVisual( void ){ return m_nTHVisualFlags; };
bool reset( bool Hard );
bool create( HW_PARAMS &HardwareSettings );
bool create( config_setting_t *SNode );
bool validateCores( void );
#ifndef PRU_SLAVE
#ifndef ONPC_TOTTAL_SIMULATOR
bool startMotors( bool Auto = true );
bool stopMotors( bool Auto = true );
#endif
#endif
void setKernelFilter( uint32_t KF ){ m_nKernelFilter = KF; };
#ifdef HIBERNATE_ENABLE
bool saveHibernatedTH( CSTR fname = "hibernate.dat" );
bool loadHibernatedTH( CSTR fname = "hibernate.dat" );
#endif
uint8_t getDetectionStatus(){ return m_nDetectionFilter; };
#ifdef IGNORE_PRU_FLIP
uint8_t getFilledTH( void ){ return m_bDataFilledTH; };
#endif
bool getRunTimeStat( HWM_CSTATUS *tHWS );
};
#endif // __LRF_HARDWAREMANAGER_H_INCL__

111
lib/App/3dSERVER/LRF_KafkaHandler.cpp

@ -1,111 +0,0 @@
#include "LRF_KafkaHandler.h"
#define LOG( X ) m_pLog->Log( "LRF_KafkaHandler", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LRF_KafkaHandler", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LRF_KafkaHandler", this, _LOG_ERROR, X );
#endif
// Constructor implementation
LRF_KafkaHandler::LRF_KafkaHandler( config_setting_t *SNode ) : basicThread(), basicEventHandler(), protocolInfoStress( SNode ){
m_pLog = basicLogCollection::getInstance();
if(!basicThread::init()){
LOG_ERROR("Error Create Thread!");
} else {
if( !protocolInfoStress::init() ) {
LOG_ERROR("Error INIT KAFKA!");
};
};
};
// Destructor implementation
LRF_KafkaHandler::~LRF_KafkaHandler(){
};
/* Periodical Job Handler */
void LRF_KafkaHandler::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
m_llTicks ++;//= getMilliseconds();
if( m_llTicks % 20 == 0 ) { // each 2 seconds
StatusUpdate();
//m_lCycleCounter == 0;
};
/* No need for time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
StartTimeSynch();
//m_lCycleCounter == 0;
};
*/
SLEEP(100);
};
};
void LRF_KafkaHandler::dispatchEvent( EVENT_CONTAINER *Evt ){
#ifdef DEBUG
LOG( "CLIENT's DISPATCHER");
#endif
if( Evt == NULL ) {
LOG( "Evt NULL");
return;
};
if( Evt->m_eClass == EVT_CLASS_SENSOR_3D ) {
#ifdef DEBUG
char tBuffer[256];
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
LOG( tBuffer );
#endif
switch( Evt->m_eType ) {
case EVT_TARGET_1D:
case EVT_TARGET_2D_WHITE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_3D_WHITE:
case EVT_TARGET_3D_BLACK:
case EVT_ALARM:{
CLIENT_EVENT *tCEVT;
tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData;
if( tCEVT != NULL ){
float Az, El;
uint32_t cRange;
cRange = (uint32_t)(((float) tCEVT->range ) * 0.0732421875f ) ; // To meters
#ifdef PRU_SLAVE
make3Ddeg( tCEVT->th_id, Az, El, false );
#else
make3Ddeg( tCEVT->th_id, Az, El, true );
#endif
Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id );
};
};
break;
case EVT_ERROR:
SetStatus( false );
break;
case EVT_SCAN:
//StatusUpdate();
//break;
case EVT_FLIP:
SetStatus( true );
//StatusUpdate();
break;
case EVT_COMMAND:
break;
default:
LOG_ERROR("Unknown Event!");
};
} else {
#ifdef DEBUG
LOG( "No SENSOR EVT ");
#endif
}
};
#undef LOG
#undef LOG_ERROR

29
lib/App/3dSERVER/LRF_KafkaHandler.h

@ -1,29 +0,0 @@
#ifndef __LRF_KAFKA_HANDLER_H_INCL__
#define __LRF_KAFKA_HANDLER_H_INCL__
#include "../../data/protocol/protocolLGS.h"
#include "../../data/net/netClientHandler.h"
#include "../../components/base/basicLogCollection.h"
#include "../../data/protocol/protocolInfoStress.h"
#include "../../data/net/clientPort.h"
/**
* TODO: Add class description
*
* @author Gagua
*/
class LRF_KafkaHandler : public basicThread, public basicEventHandler, public protocolInfoStress {
private:
basicLogCollection * m_pLog;
EventsFIFO m_oOutputFIFO;
clientPort * m_pSocketPort;
unsigned long long m_llTicks;
protected:
virtual void m_fThreadProc( void );
public:
explicit LRF_KafkaHandler( config_setting_t *SNode );
virtual ~LRF_KafkaHandler();
virtual bool dispatchEvent( EVENT_CONTAINER *Evt );
};
#endif // __LRF_CLIENTHANDLER_H_INCL__

972
lib/App/3dSERVER/LRF_Kernel.cpp

@ -1,972 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Kernel.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// LRF_Kernel.cpp
//----------------------------------------------------------------------------
//
#include "LRF_Kernel.h"
#include "LRF_Detector.h"
#include "LRF_ClientHandler.h"
#define LOG( X ) m_pLog->Log( "Kernel", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "Kernel", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "Kernel", this, _LOG_ERROR, X );
#endif
// Constructor implementation
LRF_Kernel::LRF_Kernel( LRF_HardwareManager *HM ): basicThread(), networkServiceEngine(){
m_bExitCause = 0;
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_pSettingsProvider = basicSettingsProvider::getInstance();
if( m_pSettingsProvider ) {
m_pSettings = m_pSettingsProvider->getSubNode( NULL, "KERNEL" );
if( m_pSettingsProvider->isCompromised() ) {
m_pSettingsProvider->validate();
};
} else {
m_pSettings = NULL;
};
m_pHardwareManager = HM;
m_nKernelFilter = 0x000000FF;
m_nFlipCounter = 0;
m_nFlipSavierID = 0;
m_pShadow = NULL;
m_pTWIC = NULL;
#ifdef __EU_PROJECT__
m_pSafeShoreHandler = NULL;
m_bSafeShoreSupport = false;
m_pDefenderHandler = NULL;
m_bDefenderSupport = false;
m_pKafkaHandler = NULL;
m_bKafkaSupport = false;
#endif
#ifdef PRU_SLAVE
#else
m_pTracker = NULL;
m_pNetClientsServer = NULL;
m_nSST = 0;
#endif
m_pThreshold = NULL;
m_eWorkMode = WM_NONE;
m_nWidth = 800;
};
// Destructor implementation
LRF_Kernel::~LRF_Kernel(){
#ifdef DEBUG
LOG("Destructor");
#endif
WaitFinish(true);
#ifdef DEBUG
LOG("Deleting Components");
#endif
#ifdef __EU_PROJECT__
if( m_pSafeShoreHandler ) delete( m_pSafeShoreHandler );
#ifdef DEBUG
LOG("Safe Shore - Done");
#endif
if( m_pDefenderHandler ) delete( m_pDefenderHandler );
#ifdef DEBUG
LOG("Defender - Done");
#endif
if( m_pKafkaHandler ) delete( m_pKafkaHandler );
#ifdef DEBUG
LOG("KAFKA - Done");
#endif
#endif
if( m_pTWIC ) delete( m_pTWIC );
#ifdef DEBUG
LOG("Twin Connector - Done");
#endif
if( m_pShadow ) delete( m_pShadow );
#ifdef DEBUG
LOG("Shadow Mask - Done");
#endif
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
#ifdef PRU_SLAVE
bool LRF_Kernel::create( LRF_HardwareManager *ptr ){
#else
bool LRF_Kernel::attachNetServer( networkServer *srvPort ){
if( srvPort != NULL ) {
m_pNetClientsServer = srvPort;
};
if( m_pNetClientsServer!= NULL ) {
return srvPort->attachEngine( (networkServiceEngine *)this );
};
return false;
};
bool LRF_Kernel::create( LRF_HardwareManager *ptr, networkServer *srvPort ){
#endif
if( m_pSettings != NULL ) {
config_setting_t *pSetting;
int tVal;
char tBuffer[256];
LOG("Getting Settings ...");
#ifndef PRU_SLAVE
#ifdef __EU_PROJECT__
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
tVal = m_bSafeShoreSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Safe-Shore support not defined");
} else {
m_bSafeShoreSupport = (bool)tVal;
sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
tVal = m_bDefenderSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Defender support not defined");
} else {
m_bDefenderSupport = (bool)tVal;
sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_KAFKA, &tVal ) ){
tVal = m_bKafkaSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_KAFKA, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("KAFKA support not defined");
} else {
m_bKafkaSupport = (bool)tVal;
sprintf( tBuffer, "KAFKA support Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
m_eWorkMode = WM_INIT;
m_nFlipCounter = 0;
m_nFlipSavierID = 0;
m_pShadow = new ShadowMask();
if( m_pShadow == NULL ) {
LOG_ERROR("Failed to create Shadow Mask!");
return false;
};
if( m_pShadow->isActive() ) {
LOG("Shadow Mask is ACTIVE");
} else {
LOG("Shadow Mask is NOT ACTIVE");
}
if( m_pEventHeap == NULL ){
LOG_ERROR("No Event Heap attached!");
return false;
};
if( ptr != NULL ) {
m_pHardwareManager = ptr;
m_pHardwareManager->setKernelFilter( m_nKernelFilter );
};
if( m_pHardwareManager == NULL ) {
LOG_ERROR("No Hardware manager attached!");
return false;
};
#ifdef HIBERNATE_ENABLE
if( fileExist("hibernate.dat")) {
LOG("Loading Hibernated Data.");
if(!m_pHardwareManager->loadHibernatedTH("hibernate.dat")){
LOG_ERROR("Hibernate Data Load failure!");
};
};
#endif
m_lCycleCounter = 2;
#ifndef PRU_SLAVE
if( !attachNetServer( srvPort ) ) {
LOG_ERROR("No Network manager attached!");
return false;
};
#ifdef __EU_PROJECT__
if( m_bSafeShoreSupport ){
m_pSafeShoreHandler = new LRF_SafeShoreHandler( m_pSettings );
if( m_pSafeShoreHandler == NULL ) {
LOG_ERROR("SafeShore Protocol failed!");
};
};
if( m_bDefenderSupport ) {
m_pDefenderHandler = new LRF_DefenderHandler( m_pSettings );
if( m_pDefenderHandler == NULL ) {
LOG_ERROR("Defender Protocol failed!");
};
};
if( m_bKafkaSupport ) {
m_pKafkaHandler = new LRF_KafkaHandler( m_pSettings );
if( m_pKafkaHandler == NULL ) {
LOG_ERROR("Kafka Protocol failed!");
};
};
#endif
#ifdef DEBUG
LOG( "Target Tracker about to be created" );
#endif
m_pTracker = new LRF_TargetTracker( m_nSST, m_nWidth );
if( m_pTracker == NULL ) {
LOG_ERROR("Error in starting Target Tracker!");
return false;
};
#ifdef DEBUG
LOG( "Created" );
#endif
#endif // !PRU_SLAVE
#ifdef DEBUG
LOG( "Twin Connector about to be created" );
#endif
m_pTWIC = new LRF_TwinConnector( m_pSettings );
if( m_pTWIC == NULL ) {
LOG_ERROR("Error creating TWIN object!");
return false;
} else {
#ifdef DEBUG
LOG( "TWIN object - OK" );
#endif
if( m_pTWIC->create() ){
#ifdef DEBUG
LOG( "TWIN create - OK" );
#endif
m_pTWIC->setKernel( this );
#ifndef PRU_SLAVE
m_pTWIC->attachTargetTracker( m_pTracker );
#endif
} else {
LOG_ERROR("Error in TWIN create!");
return false;
};
};
#ifdef DEBUG
LOG( "TWIN connector Created" );
#endif
#ifdef DEBUG
LOG( "Trhead about to be created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Created" );
#endif
m_eWorkMode = WM_STUDY;
return true;
};
void LRF_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
if( Force ) {
LOG( "Thread forced to be Detached" );
} else {
LOG( "Thread is Detached by itself" );
};
#endif
};
/* Main Kernel Thread Procedure */
void LRF_Kernel::m_fThreadProc( void ){
#ifdef SIMULATE_TARGETS
uint8_t CCNT = 0;
uint16_t CNNT = 0;
#endif
char Buffer[256];
DT_STATUS tStatus = {0};
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
if( !m_pHardwareManager->validateCores() ){
//Handle Error in PRU Cores
LOG_ERROR("PRU Core Trouble Detected!");
m_eWorkMode = WM_ERROR;
while( ( m_bThreadStatus < TH_ENDED ) && ( !m_pHardwareManager->validateCores()) ) SLEEP( 100 ); //Stop Kernel
#ifdef DEBUG
LOG( "Cores Became OK!" );
#endif
m_eWorkMode = WM_INIT;
};
#ifdef SIMULATE_TARGETS
#ifdef SIMULATE_DOS_TARGETS
if( m_lCycleCounter % 10 == 0 ) {
#else
if( m_lCycleCounter % 1000 == 0 ) {
#endif
// Generate Target
CNNT++;
targetRecord cNode;
cNode.begin_id = ((TH_SIZE_NODES>>1)+CCNT*(TH_LINE_NODES>>3)+CNNT)%TH_SIZE_NODES;
cNode.end_id = (cNode.begin_id+TH_LINE_NODES)%TH_SIZE_NODES;
cNode.status = 0;
cNode.flags.active = 1;
cNode.flags.lrf = CCNT;
cNode.flags.w_cnt = 2;
cNode.width = ((4095>>3)*(8-CCNT))<<1;
cNode.flags.type = TARGET_WHITE;
m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster() );
CCNT++;
CCNT &= 7;
};
#endif
// Check Working Mode
if( tStatus.mode != WM_DETECTOR ){
//if( m_eWorkMode != WM_DETECTOR ){
if( m_pHardwareManager->getCoreStatus( tStatus ) ){
if( tStatus.mode == WM_DETECTOR ) {
// Detection Mode
m_eWorkMode = WM_DETECTOR;
#ifdef DEBUG
LOG( "Switching to detection mode!" );
#ifdef NO_BLACK_TARGETS
LOG( "B-Target Will be Ignored by Build" );
#endif
#endif
#ifdef __EU_PROJECT__
if( m_bSafeShoreSupport ){
if( m_pSafeShoreHandler != NULL ) {
m_pSafeShoreHandler->SetStatus( true );
};
};
if( m_bDefenderSupport ) {
if( m_pDefenderHandler != NULL ) {
m_pDefenderHandler->SetStatus( true );
};
};
if( m_bKafkaSupport ) {
if( m_pKafkaHandler != NULL ) {
m_pKafkaHandler->SetStatus( true );
};
};
#endif
thresholdNode *ptr;
ptr = m_pHardwareManager->getWorkingMemory();
if( ptr!= NULL ){
m_nThresholdSize = TH_SIZE_NODES;
m_pThreshold = (thresholdNode *) malloc( sizeof(thresholdNode)* m_nThresholdSize);
if( m_pThreshold!= NULL ) {
memcpy( m_pThreshold, ptr, m_nThresholdSize );
} else m_nThresholdSize = 0;
};
};
};
} else { //m_eWorkMode == WM_DETECTOR
// Readout Events
int index;
bool bActiveRecordsPresent;
targetRecord cNode;
volatile targetRecord *tNode;
tNode = (volatile targetRecord *) m_pHardwareManager->getEventMemory();
if( tNode != NULL ) {
//LOG( "Event Mem accessed OK");
EVENT_CONTAINER * tEvt = NULL;
uint32_t cRange;
uint32_t cTrackID = 0;
bActiveRecordsPresent = true;
while( bActiveRecordsPresent && ( m_bThreadStatus < TH_ENDED ) ) {
bActiveRecordsPresent = false;
for( index = 0; index < MAX_TARGETS_COUNT; index++){
// Copy record from MEM
//LOG("Checking Event Record");
cNode.width = tNode[index].width;
cNode.begin_id = tNode[index].begin_id;
cNode.end_id = tNode[index].end_id;
cNode.status = tNode[index].status;
// Unlock record for PRU
tNode[index].status = 0;
// Check by Working TH Complete for LRF
// if( cNode.flags.type == TARGET_WHITE || cNode.flags.type == TARGET_BLACK ) {
// // If not -> cancel analyze
// if((m_pHardwareManager->getTargetFilter() & ( 1 << cNode.flags.lrf )) == 0 ) continue;
// };
if( cNode.flags.active ){
// Filter Events from Disabled Kernels -> goes to flip
if( ((1 << cNode.flags.lrf ) & m_nKernelFilter ) == 0 ){
// Abort checking this target since Kernel Disabled
continue;
};
if( cNode.flags.w_cnt ){
cRange = cNode.width / cNode.flags.w_cnt;
#ifdef SHIFT_50
cRange += SHIFT_50;
// width must be updated accordingly
cNode.width = cRange * cNode.flags.w_cnt;
#endif
// Filter Target's Width in Da Tracker!
// if( m_nWidth > 0 ) {
// if( cNode.width < m_nWidth ) {
// Abort Detection of this target since small width
// continue;
// };
// };
};// else {
// Abort checking this target since no width
// continue;
//};
tEvt = NULL;
bActiveRecordsPresent = true;
switch( cNode.flags.type ){
case TARGET_WHITE:{
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
LOG( "Push W-Target Into Tracker" );
#endif
#endif
if( m_pShadow != NULL ) {
if( m_pShadow->isActive() ) {
uint16_t cPointX, cPointY;
makeXY( cNode.begin_id, cPointX, cPointY, m_pHardwareManager->isMaster() );
if( m_pShadow->isOutside( cPointX, cPointY )){
#ifdef PRU_SLAVE
#else
cTrackID = m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster());
#endif
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
sprintf( Buffer, "Assigned ID [%d] area: %d CNT: %d bID: %d eID: %d",
cTrackID,
cNode.width,
cNode.flags.w_cnt,
cNode.begin_id,
cNode.end_id
);
LOG( Buffer );
#endif
#endif
} else {
#ifndef SKIP_TARGET_LOG
LOG( "Target Shadowed" );
#endif
};
} else { // Shadow is Disabled
#ifdef PRU_SLAVE
#else
cTrackID = m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster());
#endif
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
sprintf( Buffer, "Assigned ID [%d] area: %d CNT: %d bID: %d eID: %d",
cTrackID,
cNode.width,
cNode.flags.w_cnt,
cNode.begin_id,
cNode.end_id
);
LOG( Buffer );
#endif
#endif
}
} else {
LOG_ERROR("NO SHADOW OBJECT!");
m_bThreadStatus = TH_ENDED;
continue;
}
break;
};
case TARGET_BLACK:{
#ifdef NO_BLACK_TARGETS
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
// LOG( "B-Target Ignored by Build" );
#endif
#endif
};
break;
#else
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
LOG( "Push B-Target Into Tracker" );
#endif
#endif
if( m_pShadow != NULL ) {
if( m_pShadow->isActive() ) {
uint16_t cPointX, cPointY;
makeXY( cNode.begin_id, cPointX, cPointY, m_pHardwareManager->isMaster() );
if( m_pShadow->isOutside( cPointX, cPointY )){
cTrackID = m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster());
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
sprintf( Buffer, "Assigned ID [%d] area: %d CNT: %d bID: %d eID: %d",
cTrackID,
cNode.width,
cNode.flags.w_cnt,
cNode.begin_id,
cNode.end_id
);
LOG( Buffer );
#endif
#endif
};
} else { // Shadow is Disabled
cTrackID = m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster());
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
sprintf( Buffer, "Assigned ID [%d] area: %d CNT: %d bID: %d eID: %d",
cTrackID,
cNode.width,
cNode.flags.w_cnt,
cNode.begin_id,
cNode.end_id
);
LOG( Buffer );
#endif
#endif
}
} else {
LOG_ERROR("NO SHADOW OBJECT!");
m_bThreadStatus = TH_ENDED;
continue;
}
};
break;
#endif // NO_BLACK_TARGETS
// nohup sleep 30 & echo $! > pidfile
#ifndef IGNORE_PRU_SCAN
case SCAN_COMPLETE:{
//CLIENT_EVENT *tData;
//tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
#ifndef PRU_SLAVE
m_pTracker->ScanComplete();
#endif
//sprintf( Buffer,"Scan Complete [%d,%d]", cNode.width, cNode.begin_id );
#ifdef DEBUG
//LOG( Buffer );
#endif
//if( tData!= NULL ) {
// long long tMS = getMilliseconds();
// tData->uts = tMS / 1000;
// tData->ums = tMS % 1000;
// tData->type = EVT_SCAN;
// tData->a_th_node = cNode.width;
// tData->th_id = cNode.begin_id;
// tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_SCAN, NULL, Buffer, tData );
//} else {
// tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_SCAN, NULL, Buffer, NULL );
//};
break;
}
case SCAN_FROZEN:
#ifndef PRU_SLAVE
m_pTracker->ScanComplete();
#endif
//sprintf( Buffer,"Scan was Frozen", cNode.width, cNode.begin_id );
#ifdef DEBUG
//LOG( Buffer );
#endif
//tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_SCAN, Buffer, NULL );
break;
#endif //!IGNORE_PRU_SCAN
#ifndef IGNORE_PRU_FLIP
case FLIP_COMPLETE:{
CLIENT_EVENT *tData;
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
m_nFlipCounter = cNode.begin_id;
sprintf( Buffer,"Flip Complete [%d,%d]", cNode.width, m_nFlipCounter );
#ifdef DEBUG
LOG( Buffer );
#endif
if( tData!= NULL ) {
long long tMS = getMilliseconds();
tData->uts = tMS / 1000;
tData->ums = tMS % 1000;
tData->type = EVT_FLIP;
tData->a_th_node = cNode.width;
tData->th_id = m_nFlipCounter;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, NULL, Buffer, tData );
} else {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, NULL, Buffer, NULL );
};
break;
};
#endif //!IGNORE_PRU_FLIP
#ifndef PRU_SLAVE
case MIRROR_FINISHED:
m_pTracker->MirrorComplete();
break;
#endif
#ifndef IGNORE_ERROR_ANGLE
case ERROR_ANGLE:
sprintf( Buffer,"Error Angle [%d,%d]", cNode.width, cNode.begin_id );
#ifdef DEBUG
LOG_ERROR( Buffer );
#endif
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_ERROR, Buffer, NULL );
break;
#endif
};
if( tEvt != NULL) {
m_pEventHeap->broadcast( tEvt );
// Evt utilisation done by EventHeap thread
tEvt = NULL;
};// else { LOG("No Event Created!" ); };
};
};
};
//LOG("End Event Check");
} else {
LOG_ERROR("No access to Event Memory");
m_bThreadStatus = TH_ENDED;
};
};
SLEEP( SLEEP_KERNEL_INTERVAL );
if(( m_lCycleCounter >> 31 )!= 0 ) {
m_lCycleCounter = 0;
} else m_lCycleCounter++;
};
};
/*
bool LRF_Kernel::setMode( LRF3D_WORK_MODE nMode ){
if( m_eWorkMode == nMode ) return true;
#ifndef NO_MOTORS
if( m_eWorkMode == WM_DETECTOR || nMode == WM_DETECTOR ){
#endif
if( nMode == WM_BORDER ) {
LOG("Switched to Mode BORDER");
};
if( nMode == WM_DETECTOR ) {
LOG("Switched to Mode DETECTOR");
};
// No other cleints demand specoal mode
m_eWorkMode = nMode;
return true;
#ifndef NO_MOTORS
};
return false;
#endif
};
*/
PLGS_3D_PARAMETERS LRF_Kernel::getDetectionParameters( void ){
PLGS_3D_PARAMETERS tParam = NULL;
if( m_pHardwareManager != NULL ){
tParam = (PLGS_3D_PARAMETERS) malloc(sizeof(LGS_3D_PARAMETERS));
memset( tParam, 0 , sizeof(LGS_3D_PARAMETERS));
if( tParam != NULL ){
/*TH_PARAMS tThParams;
if( m_pHardwareManager->getDetectionParams( tThParams ) ){
tParam->flags.BuildThByCore = tThParams.self_build_ena;
tParam->bSST = m_nSST;
tParam->nDelta = tThParams.delta;
tParam->nFlip = tThParams.flip_size;
tParam->nGPointSamples = tThParams.good_points;
tParam->nOffset = tThParams.offset;
tParam->nOrder = tThParams.order;
tParam->nSun = 0;
tParam->nWidth = m_nWidth;
};
//DT_STATUS tThStatus;
m_pHardwareManager->getHardwareParams( tParam->flags );
//if( m_pHardwareManager->getDetectionStatus( tThStatus ) ) {
// tParam->flags.LaserPulsesOn = 1;
//};
*/
if( !m_pHardwareManager->getParams( *tParam ) ) {
LOG_ERROR("getParams ERROR!");
free( tParam );
tParam = NULL;
} else {
char tBuf[123];
for( int i = 0; i < sizeof(HW_PARAMS); i++ ) {
sprintf( tBuf, "FLAGS_BIN[%d]: %d", i, tParam->flags_binary[i] );
LOG( tBuf );
};
sprintf( tBuf, "Sunbit: %d", tParam->flags.Sunbit_filter );
LOG( tBuf );
sprintf( tBuf, "CAN My ID: %d", tParam->flags.TGZ_canSRC );
LOG( tBuf );
sprintf( tBuf, "CAN TGZ ID: %d", tParam->flags.TGZ_canDST );
LOG( tBuf );
};
};
};
return tParam;
};
bool LRF_Kernel::setDetectionParameters( PLGS_3D_PARAMETERS ptr ){
bool isCompromised = false;
HW_PARAMS tHwParams;
TH_PARAMS tThParams;
if( m_pHardwareManager != NULL ){
if( m_pHardwareManager->getDetectionParams(tThParams)){
if( tThParams.delta != ptr->nDelta ){
tThParams.delta = ptr->nDelta; isCompromised = true;
};
if( tThParams.flip_size != ptr->nFlip ){
tThParams.flip_size = ptr->nFlip; isCompromised = true;
};
if( tThParams.good_points != ptr->nGPointSamples ){
tThParams.good_points = ptr->nGPointSamples; isCompromised = true;
};
if( tThParams.offset != ptr->nOffset ){
tThParams.offset = ptr->nOffset; isCompromised = true;
};
if( tThParams.order != ptr->nOrder ){
tThParams.order = ptr->nOrder; isCompromised = true;
};
if( tThParams.self_build_ena != ptr->flags.BuildThByCore ){
tThParams.self_build_ena = ptr->flags.BuildThByCore; isCompromised = true;
};
if( tThParams.master != ptr->flags.isMaster ) {
tThParams.master = ptr->flags.isMaster; isCompromised = true;
};
if( isCompromised ) m_pHardwareManager->setDetectionParams( &tThParams );
} else {
LOG_ERROR("Cannot Get Actual Detection Settings!");
return false;
};
isCompromised = false;
if( m_pHardwareManager->getHardwareParams( tHwParams ) ) {
if( tHwParams.AutostartMotors != ptr->flags.AutostartMotors ){
tHwParams.AutostartMotors = ptr->flags.AutostartMotors; isCompromised = true;
};
if( tHwParams.BaseScanCount != ptr->flags.BaseScanCount ){
tHwParams.BaseScanCount = ptr->flags.BaseScanCount; isCompromised = true;
};
if( tHwParams.BBinterlace != ptr->flags.BBinterlace ){
tHwParams.BBinterlace = ptr->flags.BBinterlace; isCompromised = true;
};
if( tHwParams.BuildThByCore != ptr->flags.BuildThByCore ){
tHwParams.BuildThByCore = ptr->flags.BuildThByCore; isCompromised = true;
};
if( tHwParams.DetectorsCount != ptr->flags.DetectorsCount ){
tHwParams.DetectorsCount = ptr->flags.DetectorsCount; isCompromised = true;
};
if( tHwParams.DryContactMode1 != ptr->flags.DryContactMode1 ){
tHwParams.DryContactMode1 = ptr->flags.DryContactMode1; isCompromised = true;
};
if( tHwParams.DryContactMode2 != ptr->flags.DryContactMode2 ){
tHwParams.DryContactMode2 = ptr->flags.DryContactMode2; isCompromised = true;
};
if( tHwParams.DryContactStatus1 != ptr->flags.DryContactStatus1 ){
tHwParams.DryContactStatus1 = ptr->flags.DryContactStatus1; isCompromised = true;
};
if( tHwParams.DryContactStatus2 != ptr->flags.DryContactStatus2 ){
tHwParams.DryContactStatus2 = ptr->flags.DryContactStatus2; isCompromised = true;
};
if( tHwParams.HorizontalFreq != ptr->flags.HorizontalFreq ){
tHwParams.HorizontalFreq = ptr->flags.HorizontalFreq; isCompromised = true;
};
if( tHwParams.HorizontalMotorOn != ptr->flags.HorizontalMotorOn ){
tHwParams.HorizontalMotorOn = ptr->flags.HorizontalMotorOn; isCompromised = true;
};
if( tHwParams.LaserPulsesOn != ptr->flags.LaserPulsesOn ){
tHwParams.LaserPulsesOn = ptr->flags.LaserPulsesOn; isCompromised = true;
};
if( tHwParams.MirrorScanCount != ptr->flags.MirrorScanCount ){
tHwParams.MirrorScanCount = ptr->flags.MirrorScanCount; isCompromised = true;
};
if( tHwParams.QQinterlace != ptr->flags.QQinterlace ){
tHwParams.QQinterlace = ptr->flags.QQinterlace; isCompromised = true;
};
if( isCompromised ) m_pHardwareManager->setHardwareParams( &tHwParams );
} else {
LOG_ERROR("Cannot Get Actual Hardware Settings!");
return false;
};
return true;
};
return false;
};
thresholdNode *LRF_Kernel::getTreshold( uint32_t &size, uint8_t kID ){
if( m_pTWIC != NULL ) {
};
if( m_pHardwareManager!= NULL ) {
thresholdNode *ptr;
ptr = m_pHardwareManager->getWorkingMemory();
#ifdef TH_PER_MIRROR
kID = (kID>39)?39:kID;
#else
kID = (kID>15)?15:kID;
#endif
if( ptr!= NULL ){
m_nThresholdSize = TH_SIZE_NODES;
if( m_pThreshold == NULL ) {
//m_pThreshold = (thresholdNode *) malloc( sizeof(thresholdNode)* m_nThresholdSize );
m_pThreshold = (thresholdNode *) malloc( TH_SIZE_BYTES );
};
if( m_pThreshold != NULL ) {
//memcpy( m_pThreshold, ptr+(kID*TH_SIZE_NODES), sizeof(thresholdNode)* m_nThresholdSize );
memcpy( m_pThreshold, ptr+(kID*TH_SIZE_NODES), TH_SIZE_BYTES );
} else m_nThresholdSize = 0;
};
};
size = m_nThresholdSize;
return m_pThreshold;
};
bool LRF_Kernel::reset( bool FullRestart ){
if( FullRestart ) {
//Shutting down Motors and Hardware
//Starting up Motors and Hardware
shutdown( true );
} else {
m_pHardwareManager->reset( true );
};
return true;
};
bool LRF_Kernel::shutdown( bool Restart ){
if( Restart ) {
LOG("Restarting the Kernel by SHUTDOWN!");
m_bExitCause = 1;
} else {
LOG("Shutting down the Kernel by SHUTDOWN!");
m_bExitCause = 0;
}
setStatus( TH_ENDED );
return true;
};
networkClientHandler *LRF_Kernel::attachNewClient( int SocketID ){
LOG("Creating Client Handler!");
LRF_ClientHandler *tal;
tal = new LRF_ClientHandler( SocketID, this );
if( tal!= NULL ) {
LOG("Client Handler Created!");
};
return (networkClientHandler *) tal;
};
bool LRF_Kernel::detachClient( networkClientHandler *ptr ){
LOG("Delete Client Handler!");
if( ptr == NULL ) return false;
delete( (LRF_ClientHandler *) ptr );
return true;
};
#ifndef PRU_SLAVE //Just Master Stuff
bool LRF_Kernel::stopMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->stopMotors( false );
};
return false;
#else
return true;
#endif
};
bool LRF_Kernel::startMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->startMotors( false );
};
return false;
#else
return true;
#endif
};
bool LRF_Kernel::getRuntimeStatus( ALG_RUN_STATUS *ptr ){
if( ptr == NULL ) return false;
memset( ptr, 0, sizeof( ALG_RUN_STATUS ));
ptr->ENABLED_LRF = m_nKernelFilter;
if( m_pHardwareManager ) {
HWM_CSTATUS tHWS;
if( m_pHardwareManager->getRunTimeStat( &tHWS ) ){
ptr->HW_STATUS = tHWS.HW_STATUS;
ptr->DETECTING_LRF = tHWS._DETECTING_LRF;
ptr->ENABLED_LRF = m_nKernelFilter;
ptr->MASTER_FLIP_CNT = tHWS._FLIP_CNT;
memcpy( ptr->MASTER_MP, tHWS._MP, sizeof(uint32_t) * 8 );
memcpy( ptr->MASTER_GP, tHWS._GP, sizeof(uint32_t) * 8 );
memcpy( ptr->MASTER_WP, tHWS._WP, sizeof(uint32_t) * 8 );
};
} else return false;
if( m_pTWIC ) {
TWIN_STATUS * tPPP = m_pTWIC->getSystemStatus();
if (tPPP->VERSION_IS_SYNCED ) ptr->TWINC_STATUS = 1;
if (tPPP->SETTINGS_IS_SYNCED ) ptr->TWINC_STATUS |= 2;
if (tPPP->SHADOW_IS_SYNCED ) ptr->TWINC_STATUS |= 4;
} else return false;
return true;
};
#endif
#undef LOG
#undef LOG_ERROR

143
lib/App/3dSERVER/LRF_Kernel.h

@ -1,143 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Kernel.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Kernel.cpp
//----------------------------------------------------------------------------
//
#ifndef __LRF_KERNEL_H_INCL__
#define __LRF_KERNEL_H_INCL__
#include "../../components/base/basicThread.h"
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "LRF_HardwareManager.h"
#include "LRF_TwinConnector.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../alg/lgs/detector.h"
#include "../../alg/lgs/mask.h"
#include "../../data/net/netServiceEngine.h"
#ifndef PRU_SLAVE
#include "../../data/net/netServer.h"
#include "LRF_TargetTracker.h"
#ifdef __EU_PROJECT__
#include "LRF_SafeShoreHandler.h"
#include "LRF_DefenderHandler.h"
#include "LRF_KafkaHandler.h"
#define KNL_SETTINGS_SAFE_SHORE "ENABLE_SAFE_SHORE"
#define KNL_SETTINGS_DEFENDER "ENABLE_DEFENDER"
#define KNL_SETTINGS_KAFKA "ENABLE_INFOSTRESS"
#endif
#endif
//#define DUMP_TH_AFTER_FLIP_ON_DISK
#define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF;
#define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond
#define TIME_SYNC_INTERVAL 900000 // 15 minute(s) in 1 millisecond units
#define STATUS_OK_INTERVAL 2000 // 2 Sec in 1 millisecond units
#define KNL_SETTINGS_DETECTOR_WIDTH "DETECTOR_WIDTH"
#define KNL_SETTINGS_FILTER_KERNELS "ENABLED_LRF"
#define KNL_SETTINGS_DETECTOR_SST "DETECTOR_SST"
//#define KNL_SETTINGS_V_MOTOR_SETPOINT "VERTICAL_ENC_FREQ"
/**
* LRF_Kernel class - manages communication between client
* handlers and PRU cores bseide of Event management.
*
*
* @author gagua
*/
class LRF_Kernel: public basicThread, public networkServiceEngine{
private:
basicLogCollection * m_pLog;
LRF_HardwareManager * m_pHardwareManager;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
basicSettingsProvider * m_pSettingsProvider;
uint32_t m_nKernelFilter;
uint32_t m_lCycleCounter;
uint32_t m_nFlipCounter;
uint32_t m_nFlipSavierID;
uint8_t m_bExitCause;
LRF3D_WORK_MODE m_eWorkMode;
LRF_TwinConnector * m_pTWIC;
#ifdef PRU_SLAVE
#else
LRF_TargetTracker * m_pTracker;
#ifdef __EU_PROJECT__
bool m_bSafeShoreSupport;
LRF_SafeShoreHandler * m_pSafeShoreHandler;
bool m_bDefenderSupport;
LRF_DefenderHandler * m_pDefenderHandler;
bool m_bKafkaSupport;
LRF_KafkaHandler * m_pKafkaHandler;
#endif
// Argus/LGS proto
networkServer * m_pNetClientsServer;
// Detection Stuff
uint32_t m_nSST;
#endif
uint32_t m_nWidth;
// Shadow
ShadowMask * m_pShadow;
thresholdNode * m_pThreshold;
uint32_t m_nThresholdSize;
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit LRF_Kernel( LRF_HardwareManager *HM = NULL );
// Destructor
virtual ~LRF_Kernel();
bool attachNetServer( networkServer *srvPort );
virtual networkClientHandler * attachNewClient( int SocketID );
virtual bool detachClient( networkClientHandler *ptr );
#ifndef PRU_SLAVE //Just Master Stuff
bool create( LRF_HardwareManager *ptr = NULL, networkServer *srvPort = NULL );
bool stopMotors( void );
bool startMotors( void );
bool getRuntimeStatus( ALG_RUN_STATUS *ptr );
#endif
ShadowMask * getShadowMask( void ){ return m_pShadow; };
bool create( LRF_HardwareManager *ptr = NULL );
void WaitFinish( bool Force = false );
/* functional API */
bool askReset( void );
//LRF3D_WORK_MODE getWM( void );
//void setWM( LRF3D_WORK_MODE nMode );
//LRF3D_WORK_MODE getMode( void ){ return m_eWorkMode; };
bool getParameters( void );
thresholdNode * getTreshold( uint32_t &size, uint8_t kID=0 );
//bool setMode( LRF3D_WORK_MODE nMode );
bool setOffset( uint8_t nOffset );
bool setOrder( uint8_t nOrder );
PLGS_3D_PARAMETERS getDetectionParameters( void );
bool setDetectionParameters( PLGS_3D_PARAMETERS ptr );
bool reset( bool FullRestart = false );
bool shutdown( bool Restart = false );
uint8_t getExitCause( void ){ return m_bExitCause; };
};
#endif // __LRF_KERNEL_H_INCL__

105
lib/App/3dSERVER/LRF_SafeShoreHandler.cpp

@ -1,105 +0,0 @@
#include "LRF_SafeShoreHandler.h"
#define LOG( X ) m_pLog->Log( "LRF_SafeShoreHandler", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LRF_SafeShoreHandler", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LRF_SafeShoreHandler", this, _LOG_ERROR, X );
#endif
// Constructor implementation
LRF_SafeShoreHandler::LRF_SafeShoreHandler( config_setting_t *SNode ) : basicThread(), basicEventHandler(), protocolSafeShore( SNode ){
m_pLog = basicLogCollection::getInstance();
basicThread::init();
};
// Destructor implementation
LRF_SafeShoreHandler::~LRF_SafeShoreHandler(){
};
/* Periodical Job Handler */
void LRF_SafeShoreHandler::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
m_llTicks ++;//= getMilliseconds();
if( m_llTicks % 20 == 0 ) { // each 2 seconds
StatusUpdate();
//m_lCycleCounter == 0;
};
/* No need for Time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
StartTimeSynch();
//m_lCycleCounter == 0;
};
*/
SLEEP(100);
};
};
void LRF_SafeShoreHandler::dispatchEvent( EVENT_CONTAINER *Evt ){
#ifdef DEBUG
LOG( "CLIENT's DISPATCHER");
#endif
if( Evt == NULL ) {
LOG( "Evt NULL");
return;
};
if( Evt->m_eClass == EVT_CLASS_SENSOR_3D ) {
#ifdef DEBUG
char tBuffer[256];
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
LOG( tBuffer );
#endif
switch( Evt->m_eType ) {
case EVT_TARGET_1D:
case EVT_TARGET_2D_WHITE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_3D_WHITE:
case EVT_TARGET_3D_BLACK:
case EVT_ALARM:{
CLIENT_EVENT *tCEVT;
tCEVT = (CLIENT_EVENT *) Evt->m_pEvtData;
if( tCEVT != NULL ){
float Az, El;
uint32_t cRange;
cRange = (uint32_t)(((float) tCEVT->range ) * 0.732421875f ) ; // To Decimeters
#ifdef PRU_SLAVE
make3Dmildeg( tCEVT->th_id, Az, El, false );
#else
make3Dmildeg( tCEVT->th_id, Az, El, true );
#endif
Alarm3D( (int)Az, (int)El, cRange , tCEVT->k_id );
};
};
break;
case EVT_ERROR:
SetStatus( false );
break;
case EVT_SCAN:
//StatusUpdate();
//break;
case EVT_FLIP:
SetStatus( true );
//StatusUpdate();
break;
case EVT_COMMAND:
break;
default:
LOG_ERROR("Unknown Event!");
};
} else {
#ifdef DEBUG
LOG( "No SENSOR EVT ");
#endif
}
};
#undef LOG
#undef LOG_ERROR

33
lib/App/3dSERVER/LRF_SafeShoreHandler.h

@ -1,33 +0,0 @@
#ifndef __LRF_SAFESHORE_HANDLER_H_INCL__
#define __LRF_SAFESHORE_HANDLER_H_INCL__
#include "../../data/protocol/protocolLGS.h"
#include "../../data/net/netClientHandler.h"
#include "../../components/base/basicLogCollection.h"
#include "../../data/protocol/protocolSafeShore.h"
#include "../../data/net/clientPort.h"
/**
* TODO: Add class description
*
* @author Gagua
*/
class LRF_SafeShoreHandler : public basicThread, public basicEventHandler, public protocolSafeShore {
private:
basicLogCollection *m_pLog;
EventsFIFO m_oOutputFIFO;
clientPort *m_pSocketPort;
unsigned long long m_llTicks;
protected:
virtual void m_fThreadProc( void );
public:
// Constructor
explicit LRF_SafeShoreHandler( config_setting_t *SNode );
// Destructor
virtual ~LRF_SafeShoreHandler();
virtual bool dispatchEvent( EVENT_CONTAINER *Evt );
};
#endif // __LRF_CLIENTHANDLER_H_INCL__

513
lib/App/3dSERVER/LRF_Server.cpp

@ -1,513 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Server.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Server.cpp
//----------------------------------------------------------------------------
//
#include "LRF_Server.h"
typedef enum {
ST_NONE = -1,
ST_SN = 0,
ST_BIND_ADDRESS,
ST_BIND_PORT,
ST_PID_FILE,
ST_LOG_FILE,
ST_LOG_ENABLE,
ST_INTERACTIVE,
ST_SMS_ENABLE,
ST_EMAIL_ENABLE,
ST_SMS_PROVIDER,
ST_DATABASE_SERVER,
ST_DATABASE_USER,
ST_DATABASE_PASSWORD,
ST_DATABASE_NAME,
ST_SOCKET_NAME
} SETTING_TYPE;
CSTR m_pSetting[] = {
(CSTR)"SN",
(CSTR)"BIND_ADDRESS",
(CSTR)"BIND_PORT",
(CSTR)"PID_FILE",
(CSTR)"LOG_FILE" ,
(CSTR)"LOG_ENABLED",
(CSTR)"INTERACTIVE",
(CSTR)"SMS_ENABLE",
(CSTR)"EMAIL_ENABLE",
(CSTR)"SMS_PROVIDER",
(CSTR)"DATABASE_SERVER",
(CSTR)"DATABASE_USER",
(CSTR)"DATABASE_PASSWORD",
(CSTR)"DATABASE_NAME",
(CSTR)"SOCKET_NAME"
};
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
LRF_Kernel *Kernel = NULL;
LRF_HardwareManager *HWManager = NULL;
basicLogCollection *m_pLog = NULL;
#ifndef PRU_SLAVE
networkServer *NetworkManager = NULL;
ssdpAnnouncer *NetworkAnnouncer = NULL;
#endif
basicSettingsProvider *SettingsProvider = NULL;
config_setting_t *Settings = NULL;
void (*old_kill_handler_9)(int);
void (*old_kill_handler_15)(int);
void signal_kill_handler( int SIG ){
if( Kernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
int main( int argc, char *argv[] ){
//_Core_Channel_Collection *CDC = NULL;
//MySQL_Connector *DBC = NULL;
bool WBG; // Working Background
bool FLE; // File Logging Engine
bool SSE; // Server Statistics Engine
bool NDC; // No Default Configuration
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
// default init
WBG = true;
FLE = true;
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
SSE = true;
NDC = true;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems LRF Server\n");
printf( "Software version <%s>\n", VERSION_NUMBER );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
sprintf( DCF_NAME, "%s", argv[i+1] );
break;
};
};
break;
};
};
};
};
if ( fileExist( DCF_NAME ) ){
NDC = false;
} else {
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_FILE;
if( fileExist( DCF_NAME ) ){
NDC = false;
};
}
if ( !NDC ){
// read serial number
FILE *pFile = fopen( DCF_NAME, "rt" );
printf("Trying open file %s\n", DCF_NAME );
if( pFile != NULL ){
char pLine[1024];
while( fgets( pLine, 1024, pFile ) ){
SETTING_TYPE eType = ST_NONE;
CSTR pTemp = NULL;
for( int i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ ){
pTemp = strstr( pLine, m_pSetting[i] );
if( pTemp ){
eType = (SETTING_TYPE)i;
pTemp = strstr( pTemp, "=" );
if( pTemp ) pTemp = strtok( pTemp + 1, " \t\n\r" );
break;
};
};
if( eType == ST_NONE || !pTemp ) continue;
switch( eType ){
case ST_SN:{
gsCFG_LICENSE = (CSTR) malloc(strlen( pTemp ));
//memcpy( gsCFG_LICENSE, pTemp, strlen( pTemp ) );
sprintf( gsCFG_LICENSE, "%s", pTemp );
break;
};
case ST_BIND_ADDRESS:{
gsCFG_ADDRESS = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_ADDRESS, "%s", pTemp );
break;
};
case ST_BIND_PORT:{
guCFG_PORT = ( uint16_t ) atoi( pTemp );
break;
};
case ST_PID_FILE:{
gsCFG_PID_FILE = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_PID_FILE, "%s", pTemp );
break;
};
case ST_LOG_FILE:{
FLE_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( FLE_NAME, "%s", pTemp );
break;
};
case ST_INTERACTIVE:{
WBG = (atoi( pTemp ))? false: true;
break;
};
case ST_SMS_ENABLE:{
gModule_SMS_Enabled = (bool)atoi( pTemp );
break;
};
case ST_EMAIL_ENABLE:{
gModule_Email_Enabled = (bool)atoi( pTemp );
break;
};
case ST_SMS_PROVIDER:{
break;
};
case ST_DATABASE_SERVER:{
gsCFG_DB_SERVER = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_SERVER, "%s", pTemp );
break;
};
case ST_DATABASE_USER:{
gsCFG_DB_USER = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_USER, "%s", pTemp );
break;
};
case ST_DATABASE_PASSWORD:{
gsCFG_DB_PASSWORD = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_PASSWORD, "%s", pTemp );
break;
};
case ST_DATABASE_NAME:{
gsCFG_DB_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_NAME, "%s", pTemp );
break;
};
case ST_SOCKET_NAME:{
SSP_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( SSP_NAME, "%s", pTemp );
break;
};
};
};
fclose( pFile );
} else {
NDC = true;
};
};
if( NDC ){//Default config
gsCFG_LICENSE = (CSTR) "FRUCHT_DEMO_LICENSE";
gsCFG_DB_SERVER = (CSTR) "localhost";
gsCFG_ADDRESS = gsCFG_DB_SERVER;
gsCFG_DB_NAME = (CSTR) "tgdos";
gsCFG_DB_USER = (CSTR) "tgdos";
gsCFG_DB_PASSWORD = (CSTR) "NoGud4U@";
};
SettingsProvider = basicSettingsProvider::getInstance( DCF_NAME );
Settings = SettingsProvider->getSubNode( NULL, "GENERAL" );
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. %s\n", VERSION_NUMBER );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
//Block Some Signals
//sigset_t signal_mask;
//sigfillset( &signal_mask );
//sigaddset(&signal_mask, SIGUSR1);
//pthread_sigmask( SIG_BLOCK, &signal_mask, NULL );
// Clear to start Service
m_pLog = basicLogCollection::getInstance( _LOG_LVL_TIME_PTR );
//CDC = new _GP_Core_Dispatching_Collection();
//DBC = new MySQL_Connector();
//m_pLog->setLogLevel( _LOG_ALL ); // All Messages
//m_pLog->setLogLevel( _LOG_VERBOSE );
m_pLog->setLogLevel( _LOG_ERROR ); // Most Silent Mode
if ( FLE ){// Init File Logging Engine
m_pLog->addHandler((basicLoggingService *) new objectFileLoggingService( FLE_NAME ));
};
if ( !WBG ){// Init Curses class to handle UI
//m_pLog->addHandler((_Core_Logging_Service *) new _Core_CLUI());
};
uint8_t m_bKernelExitCode = 0;
#ifndef PRU_SLAVE
// Starting Services
NetworkManager = new networkServer();
if( NetworkManager == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Net Server failed to born ++++" );
//delete( HWManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
if( !NetworkManager->BootUp() ){
// Aborting Work
LOG_ERROR( "++++ Net Server failed to init ++++" );
//delete( HWManager );
delete( NetworkManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
NetworkAnnouncer = new ssdpAnnouncer();
if( NetworkAnnouncer != NULL ) {
NetworkAnnouncer->init();
};
#endif // PRU_SLAVE
// Start Loop of Restarted Kernel
do{
HWManager = new LRF_HardwareManager();
// Init Objects
if( HWManager != NULL ){
if( HWManager->isSitara() ) {
/*
S_HARDWARE_SETTINGS m_sHWS;
if(!m_sHWS.readFromFile( "hw.ini" )){
LOG("Default HW settings are applyied");
};
if( gbCFG_MASTER_ROLE ) {
LOG("ROLE - MASTER");
m_sHWS.isMaster = true;
} else {
LOG("ROLE - SLAVE");
m_sHWS.isMaster = false;
};
*/
if( HWManager->isMaster() ) {
LOG("ROLE - MASTER");
} else {
LOG("ROLE - SLAVE");
};
/*
if( !HWManager->create( m_sHWS ) ){
// Aborting Work
LOG_ERROR( "++++ Hardware failed to init ++++" );
delete( HWManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
*/
Kernel = new LRF_Kernel();
if( Kernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
delete( HWManager );
#ifndef PRU_SLAVE
delete( NetworkAnnouncer );
delete( NetworkManager );
#endif
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( Kernel != NULL ){
LOG( "++++ Server Started ++++" );
#ifdef PRU_SLAVE
if ( Kernel->create( HWManager ) == false ){
#else
if ( Kernel->create( HWManager, NetworkManager ) == false ){
#endif
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_kill_handler );
old_kill_handler_9 = signal( 9, signal_kill_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();
#ifndef PRU_SLAVE
if( m_bKernelExitCode ) {
// Detach Kernel From Clients
NetworkManager->attachEngine( NULL );
};
#endif
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
};
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
delete( HWManager );
} else {
LOG_ERROR( "SOC Module Unknown" );
}
} else {
LOG_ERROR( "++++ Unknown Hardware ++++" );
};
} while( m_bKernelExitCode > 0 );
#ifndef PRU_SLAVE
delete( NetworkAnnouncer );
delete( NetworkManager );
#endif
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return 0;
};
#undef LOG
#undef LOG_ERROR

40
lib/App/3dSERVER/LRF_Server.h

@ -1,40 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Server.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Server.h
//----------------------------------------------------------------------------
//
#ifndef __LRF_SERVER_HEADER__
#define __LRF_SERVER_HEADER__
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMemoryOperation.h"
#include "../../components/object/objectFileLoggingService.h"
#ifndef PRU_SLAVE
#include "../../data/net/netServer.h"
#include "../../data/ssdp/ssdpAnnouncer.h"
#endif
#ifdef SLIM_KERNEL
#include "LRF_SlimKernel.h"
#else
#include "LRF_Kernel.h"
#endif
#include "LRF_HardwareManager.h"
#endif

966
lib/App/3dSERVER/LRF_SlimKernel.cpp

@ -1,966 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Kernel.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// LRF_Kernel.cpp
//----------------------------------------------------------------------------
//
#include "LRF_SlimKernel.h"
#include "LRF_Detector.h"
#include "LRF_ClientHandler.h"
#define LOG( X ) m_pLog->Log( "SLKRNL", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "SLKRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "SLKRNL", this, _LOG_ERROR, X );
#endif
// Constructor implementation
#ifdef PRU_SLAVE
LRF_Kernel::LRF_Kernel( LRF_HardwareManager *HM ): basicThread(), basicEngine(){
#else
LRF_Kernel::LRF_Kernel( LRF_HardwareManager *HM ): basicThread(), networkServiceEngine(){
#endif
m_bExitCause = 0;
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_pSettingsProvider = basicSettingsProvider::getInstance();
if( m_pSettingsProvider ) {
m_pSettings = m_pSettingsProvider->getSubNode( NULL, "KERNEL" );
if( m_pSettingsProvider->isCompromised() ) {
m_pSettingsProvider->validate();
};
} else {
m_pSettings = NULL;
};
m_pHardwareManager = HM;
m_nKernelFilter = 0x000000FF;
m_nFlipCounter = 0;
m_nFlipSavierID = 0;
m_pShadow = NULL;
m_pTWIC = NULL;
#ifndef PRU_SLAVE
m_pTracker = NULL;
m_pNetClientsServer = NULL;
m_nSST = 0;
#endif
m_pCurrentTH = NULL;
m_nCurrentTH = 0;
m_bCurrentTH = 0;
m_nForcedDrawTH = 0;
//m_eWM = WM_NONE;
m_nWidth = 800;
};
// Destructor implementation
LRF_Kernel::~LRF_Kernel(){
#ifdef DEBUG
LOG("Destructor");
LOG("End Main Thread");
#endif
WaitFinish( true );
#ifdef DEBUG
LOG("Deleting Components");
LOG("TWINC");
#endif
if( m_pTWIC ) delete( m_pTWIC );
#ifdef DEBUG
LOG("Twin Connector - Done");
LOG("SHADOW");
#endif
if( m_pShadow ) delete( m_pShadow );
#ifdef DEBUG
LOG("Shadow Mask - Done");
#endif
if ( m_pCurrentTH ) free( m_pCurrentTH );
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
#ifdef PRU_SLAVE
bool LRF_Kernel::create( LRF_HardwareManager *ptr ){
#else
bool LRF_Kernel::attachNetServer( networkServer *srvPort ){
if( srvPort != NULL ) {
m_pNetClientsServer = srvPort;
};
if( m_pNetClientsServer!= NULL ) {
return srvPort->attachEngine( this );
};
return false;
};
bool LRF_Kernel::create( LRF_HardwareManager *ptr, networkServer *srvPort ){
#endif
if( m_pSettings != NULL ) {
config_setting_t *pSetting;
int tVal;
char tBuffer[256];
LOG("Getting Settings ...");
#ifndef PRU_SLAVE
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
//m_eWM = WM_INIT;
setWM( WM_INIT );
m_nFlipCounter = 0;
m_nFlipSavierID = 0;
m_pShadow = new ShadowMask();
if( m_pShadow == NULL ) {
LOG_ERROR("Failed to create Shadow Mask!");
return false;
} else {
//Load Default Masks
if( m_pShadow->loadVertexes() ) LOG("Vertexeses Loadded!");
if( m_pShadow->loadRastered() ) LOG("Traces Loadded!");
};
if( m_pShadow->isActive() ) {
LOG("Shadow Mask is ACTIVE");
} else {
LOG("Shadow Mask is NOT ACTIVE");
};
if( m_pEventHeap == NULL ){
LOG_ERROR("No Event Heap attached!");
return false;
};
if( ptr != NULL ) {
m_pHardwareManager = ptr;
m_pHardwareManager->setKernelFilter( m_nKernelFilter );
};
if( m_pHardwareManager == NULL ) {
LOG_ERROR("No Hardware manager attached!");
return false;
};
#ifdef HIBERNATE_ENABLE
if( fileExist("hibernate.dat")) {
LOG("Loading Hibernated Data.");
if(!m_pHardwareManager->loadHibernatedTH("hibernate.dat")){
LOG_ERROR("Hibernate Data Load failure!");
};
};
#endif
m_lCycleCounter = 2;
#ifndef PRU_SLAVE
if( !attachNetServer( srvPort ) ) {
LOG_ERROR("No Network manager attached!");
return false;
};
#ifdef DEBUG
LOG( "Target Tracker about to be created" );
#endif
m_pTracker = new LRF_TargetTracker( m_nSST, m_nWidth );
if( m_pTracker == NULL ) {
LOG_ERROR("Error in starting Target Tracker!");
return false;
};
#ifdef DEBUG
LOG( "Created" );
#endif
#endif // !PRU_SLAVE
#ifdef DEBUG
LOG( "Twin Connector about to be created" );
#endif
m_pTWIC = new LRF_TwinConnector( m_pSettings );
if( m_pTWIC == NULL ) {
LOG_ERROR("Error creating TWIN object!");
return false;
} else {
#ifdef DEBUG
LOG( "TWIN object - OK" );
#endif
if( m_pTWIC->create() ){
#ifdef DEBUG
LOG( "TWIN create - OK" );
#endif
m_pTWIC->setKernel( this );
#ifndef PRU_SLAVE
m_pTWIC->attachTargetTracker( m_pTracker );
#endif
} else {
LOG_ERROR("Error in TWIN create!");
return false;
};
};
#ifdef DEBUG
LOG( "TWIN connector Created" );
#endif
#ifdef DEBUG
LOG( "Trhead about to be created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Created" );
#endif
//m_eWM = WM_STUDY;
setWM( WM_STUDY );
return true;
};
void LRF_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
if( Force ) {
LOG( "Thread forced to be Detached" );
} else {
LOG( "Thread is Detached by itself" );
};
#endif
};
/*
LRF3D_WORK_MODE LRF_Kernel::getWM( void ){
LRF3D_WORK_MODE rv;
m_mWMProtector.lock();
rv = m_eWM;
m_mWMProtector.unlock();
return rv;
};
void LRF_Kernel::setWM( LRF3D_WORK_MODE nMode ){
m_mWMProtector.lock();
m_eWM = nMode;
m_mWMProtector.unlock();
};
*/
/* Main Kernel Thread Procedure */
void LRF_Kernel::m_fThreadProc( void ){
char Buffer[256];
DT_STATUS tStatus = {0};
uint8_t bActiveTH = 0;
uint8_t bMeasuredTH = 0;
uint8_t bDrawedTH = 0;
#ifdef SIMULATE_TARGETS
uint8_t CCNT = 0;
uint16_t CNNT = 0;
#endif
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
#ifdef SIMULATE_TARGETS
#ifdef SIMULATE_DOS_TARGETS
if( m_lCycleCounter % 10 == 0 ) {
#else
if( m_lCycleCounter % 1000 == 0 ) {
#endif
// Generate Target
/*CNNT++;
targetRecord cNode;
cNode.begin_id = ((TH_SIZE_NODES>>1)+CCNT*(TH_LINE_NODES>>3)+CNNT)%TH_SIZE_NODES;
cNode.end_id = (cNode.begin_id+TH_LINE_NODES)%TH_SIZE_NODES;
cNode.status = 0;
cNode.flags.active = 1;
cNode.flags.lrf = CCNT;
cNode.flags.w_cnt = 2;
cNode.range_min = 140;
cNode.range_max = cNode.range_min;
cNode.width = cNode.flags.w_cnt * cNode.range_min;
//cNode.width = ((4095>>3)*(8-CCNT))<<1;
cNode.flags.type = TARGET_WHITE;
m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster() );
CCNT++;
CCNT &= 7;
*/
// Generate Target
CNNT++;
targetRecord cNode;
cNode.begin_id = ((TH_SIZE_NODES>>1)+CCNT*(TH_LINE_NODES>>3)+CNNT)%TH_SIZE_NODES;
cNode.end_id = (cNode.begin_id+TH_LINE_NODES)%TH_SIZE_NODES;
cNode.status = 0;
cNode.flags.active = 1;
cNode.flags.lrf = CCNT;
cNode.flags.w_cnt = 2;
cNode.width = ((4095>>3)*(8-CCNT))<<1;
cNode.flags.type = TARGET_WHITE;
m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster() );
CCNT++;
CCNT &= 7;
};
#endif
if( !m_pHardwareManager->validateCores() ){
if( getWM() != WM_ERROR ){
setWM(WM_ERROR);
LOG_ERROR("PRU Core Trouble Detected!");
};
} else {
// PRU Cores are valid
bActiveTH = m_nKernelFilter & m_pHardwareManager->getDetectionStatus();
bMeasuredTH = m_nKernelFilter & m_pHardwareManager->getTHVisual();
switch( getWM() ) {
case WM_INIT:{
LOG("INIT");
if( m_pHardwareManager->getCoreStatus( tStatus ) ){
if( m_pHardwareManager->reset( false ) ){
//if( tStatus.mode == WM_DETECTOR ){
LOG("**********SWITCHING TO STUDY MODE**********");
setWM( WM_STUDY );
//};
};
};
break;
};
case WM_STUDY:{
if( bActiveTH ){
LOG("**********SWITCHING TO DETECTOR MODE**********");
setWM( WM_DETECTOR );
} else {
if( bMeasuredTH != bDrawedTH ){
LOG("**********SWITCHING TO BORDER MODE**********");
setWM( WM_BORDER );
};
};
break;
};
case WM_DETECTOR:{
bActiveTH = m_nKernelFilter & m_pHardwareManager->getTHVisual(); //m_pHardwareManager->getDetectionStatus();
if( bMeasuredTH != bDrawedTH ) {
LOG("**********SWITCHING TO BORDER MODE**********");
setWM( WM_BORDER );
continue;
};
volatile targetRecord *tNode = (volatile targetRecord *)m_pHardwareManager->getEventMemory();
if( tNode != NULL ) {
bool bActiveRecordsPresent = true;
while( bActiveRecordsPresent && ( m_bThreadStatus < TH_ENDED ) ) {
targetRecord cNode;
uint32_t cRange;
uint32_t cTrackID = 0;
EVENT_CONTAINER * tEvt = NULL;
uint8_t bFilter = m_nKernelFilter & m_pHardwareManager->getTargetFilter();
bActiveRecordsPresent = false;
for( int idx = 0; idx < MAX_TARGETS_COUNT; idx++ ){
// Filter Not Active Events
if ( tNode[idx].flags.active == 0 ) continue;
cNode.width = tNode[idx].width;
cNode.begin_id = tNode[idx].begin_id;
cNode.end_id = tNode[idx].end_id;
cNode.status = tNode[idx].status;
// Unlock record for PRU
tNode[idx].status = 0;
// Filter Events from Disabled Kernels -> goes to flip
//if( ((1 << cNode.flags.lrf ) & m_nKernelFilter ) == 0 ){
// // Abort checking this target since Kernel Disabled
// continue;
//};
// Filter Events from Disabled Kernels -> goes to flip
if( ((1 << cNode.flags.lrf ) & bFilter ) == 0 ){
// Abort checking this target since Kernel not Detecting
continue;
};
// Abort checking this target since no width
if( cNode.flags.w_cnt ){
cRange = cNode.width / cNode.flags.w_cnt;
#ifdef SHIFT_50
cRange += SHIFT_50;
cNode.width = cRange * cNode.flags.w_cnt;
#endif
} else continue;
bActiveRecordsPresent = true;
switch( cNode.flags.type ){
case TARGET_WHITE:{
if( m_pShadow != NULL ) {
if( m_pShadow->isActive() ) {
uint16_t cPointX, cPointY;
#ifdef PRU_SLAVE
makeXY( cNode.begin_id, cPointX, cPointY, false );
#else
makeXY( cNode.begin_id, cPointX, cPointY, true );
#endif
if( m_pShadow->isOutside( cPointX, cPointY )){
#ifdef PRU_SLAVE
m_pTWIC->validateTarget( &cNode );
#else
cTrackID = m_pTracker->validateTarget( &cNode, true );
#endif
};
} else { // Shadow is Disabled
#ifdef PRU_SLAVE
m_pTWIC->validateTarget( &cNode );
#else
cTrackID = m_pTracker->validateTarget( &cNode, true );
#endif
};
} else {
LOG_ERROR("NO SHADOW OBJECT!");
m_bThreadStatus = TH_ENDED;
continue;
};
break;
};
case TARGET_BLACK:{
#ifdef NO_BLACK_TARGETS
break;
};
#else
if( m_pShadow != NULL ) {
if( m_pShadow->isActive() ) {
uint16_t cPointX, cPointY;
#ifdef PRU_SLAVE
makeXY( cNode.begin_id, cPointX, cPointY, false );
#else
makeXY( cNode.begin_id, cPointX, cPointY, true );
#endif
if( m_pShadow->isOutside( cPointX, cPointY )){
#ifdef PRU_SLAVE
m_pTWIC->validateTarget( &cNode );
#else
cTrackID = m_pTracker->validateTarget( &cNode, true );
#endif
};
} else {
#ifdef PRU_SLAVE
m_pTWIC->validateTarget( &cNode );
#else
cTrackID = m_pTracker->validateTarget( &cNode, true );
#endif
};
} else {
LOG_ERROR("NO SHADOW OBJECT!");
m_bThreadStatus = TH_ENDED;
continue;
};
break;
};
#endif // NO_BLACK_TARGETS
// nohup sleep 30 & echo $! > pidfile
#ifndef IGNORE_PRU_SCAN
#ifndef PRU_SLAVE
case SCAN_COMPLETE: m_pTracker->ScanComplete(); break;
case SCAN_FROZEN: m_pTracker->ScanComplete(); break;
case MIRROR_FINISHED: m_pTracker->MirrorComplete(); break;
#endif
#endif //!IGNORE_PRU_SCAN
#ifndef IGNORE_PRU_FLIP
case FLIP_COMPLETE:{
CLIENT_EVENT *tData;
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
m_nFlipCounter = cNode.begin_id;
if( tData!= NULL ) {
long long tMS = getMilliseconds();
tData->uts = tMS / 1000;
tData->ums = tMS % 1000;
tData->type = EVT_FLIP;
tData->a_th_node = cNode.width;
tData->th_id = m_nFlipCounter;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, NULL, NULL, tData );
} else {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, NULL, NULL, NULL );
};
break;
};
#endif //!IGNORE_PRU_FLIP
#ifndef IGNORE_ERROR_ANGLE
case ERROR_ANGLE: tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_ERROR, NULL, NULL, NULL ); break;
#endif
};
if( tEvt != NULL) {
m_pEventHeap->broadcast( tEvt );
// Evt utilisation done by EventHeap thread
tEvt = NULL;
};
};
};
} else {
LOG_ERROR("No access to Event Memory");
m_bThreadStatus = TH_ENDED;
continue;
};
break;
};
case WM_BORDER:{
if( ( bMeasuredTH == 0 ) && ( m_nForcedDrawTH == 0 ) ){
LOG("No Measured No Force!");
bDrawedTH = bMeasuredTH;
if( bActiveTH ) {
LOG("**********SWITCHING TO DETECTOR MODE**********");
setWM( WM_DETECTOR );
} else {
LOG("**********SWITCHING TO STUDY MODE**********");
setWM( WM_STUDY );
};
} else {
if ( m_nForcedDrawTH ) {
LOG("Forced DRAW");
if( ( m_nForcedDrawTH & 0xFF00 ) != 0x00000 ) { // Force Remote TH Draw
#ifndef PRU_SLAVE
uint8_t chVal = ( m_nForcedDrawTH >> 8 ) & 0xFF;
// Force Local TH Draw
for ( uint8_t idx = 0; idx < 16; idx++ ) {
if( ( chVal & (1<<idx) ) != 0 ) {
if( m_pTWIC ){
if( m_pTWIC->requestRemoteDraw( idx ) ){
m_nForcedDrawTH &=~(1<<(idx+8)); // Clear Flag
break; // from for
};
};
};
};
#endif
} else {
// Force Local TH Draw
for ( uint8_t idx = 0; idx < 16; idx++ ) {
if( ( m_nForcedDrawTH & (1<<idx) ) != 0 ) {
if ( m_pTWIC->readyToConsumeTH() ) {
//Finished Build TH
uint32_t THsize;
thresholdNode *tPTR = getTreshold( THsize, idx );
if ( m_pTWIC->consumeTH( idx, tPTR, THsize ) ) {
m_nForcedDrawTH &=~(1<<idx); // Clear Flag
break; // from for
} else LOG("Error Consuming TH");
} else LOG("TWINC not ready to consume TH");
};
};
};
} else {
LOG("Measured!");
if( bDrawedTH != bMeasuredTH ) {
for( uint8_t idx = 0; idx < 8; idx++ ){
if( ( ( bMeasuredTH & (1<<idx) ) != 0 ) && ( ( bDrawedTH & (1<<idx) ) == 0 ) ){
sprintf( Buffer, "NEW [%d]TH READY!", idx );
LOG( Buffer );
if( m_pTWIC ){
if ( m_pTWIC->readyToConsumeTH() ) {
//Finished Build TH
uint32_t THsize;
thresholdNode *tPTR = getTreshold( THsize, idx );
if ( m_pTWIC->consumeTH( idx, tPTR, THsize ) ) {
//mark as consumed
bDrawedTH |= (1<<idx);
} else LOG("Error Consuming TH");
} else {
LOG("TWINC not ready to consume TH");
SLEEP(10);
break;
}
} else LOG("TWINC not exists!");
} else {
// If Th is cleared - remove old flag to consume newly build TH
if( ( bMeasuredTH & (1<<idx) ) == 0 ) bDrawedTH &= ~(1<<idx);
};
};
//bDrawedTH = bMeasuredTH;
};
};
if( ( m_nForcedDrawTH == 0 ) && ( bDrawedTH == bMeasuredTH ) ) {
if( bActiveTH ) {
LOG("**********SWITCHING TO DETECTOR MODE**********");
setWM( WM_DETECTOR );
} else {
LOG("**********SWITCHING TO STUDY MODE**********");
setWM( WM_STUDY );
};
}
};
break;
};
case WM_ERROR:{
if( m_pHardwareManager->validateCores() ){
LOG("**********SWITCHING TO INIT MODE**********");
setWM( WM_INIT );
}
break;
};
};
};
#ifdef ONPC_TOTTAL_SIMULATOR
//Simulation Stuff
//bActiveTH = 199;
#endif
SLEEP( SLEEP_KERNEL_INTERVAL );
if(( m_lCycleCounter >> 31 )!= 0 ) {
m_lCycleCounter = 0;
} else m_lCycleCounter++;
};
};
PLGS_3D_PARAMETERS LRF_Kernel::getDetectionParameters( void ){
PLGS_3D_PARAMETERS tParam = NULL;
if( m_pHardwareManager != NULL ){
tParam = (PLGS_3D_PARAMETERS) malloc(sizeof(LGS_3D_PARAMETERS));
if( tParam != NULL ){
memset( tParam, 0 , sizeof(LGS_3D_PARAMETERS));
/*TH_PARAMS tThParams;
if( m_pHardwareManager->getDetectionParams( tThParams ) ){
tParam->flags.BuildThByCore = tThParams.self_build_ena;
tParam->bSST = m_nSST;
tParam->nDelta = tThParams.delta;
tParam->nFlip = tThParams.flip_size;
tParam->nGPointSamples = tThParams.good_points;
tParam->nOffset = tThParams.offset;
tParam->nOrder = tThParams.order;
tParam->nSun = 0;
tParam->nWidth = m_nWidth;
};
//DT_STATUS tThStatus;
m_pHardwareManager->getHardwareParams( tParam->flags );
//if( m_pHardwareManager->getDetectionStatus( tThStatus ) ) {
// tParam->flags.LaserPulsesOn = 1;
//};
*/
if( !m_pHardwareManager->getParams( *tParam ) ) {
LOG_ERROR("getParams ERROR!");
free( tParam );
tParam = NULL;
}
#ifdef DEBUG
else {
char tBuf[123];
for( int i = 0; i < sizeof(HW_PARAMS); i++ ) {
sprintf( tBuf, "FLAGS_BIN[%d]: %d", i, tParam->flags_binary[i] );
LOG( tBuf );
};
sprintf( tBuf, "Sunbit: %d", tParam->flags.Sunbit_filter );
LOG( tBuf );
sprintf( tBuf, "CAN My ID: %d", tParam->flags.TGZ_canSRC );
LOG( tBuf );
sprintf( tBuf, "CAN TGZ ID: %d", tParam->flags.TGZ_canDST );
LOG( tBuf );
}
#endif
;
};
};
return tParam;
};
bool LRF_Kernel::setDetectionParameters( PLGS_3D_PARAMETERS ptr ){
bool isCompromised = false;
HW_PARAMS tHwParams;
TH_PARAMS tThParams;
if( m_pHardwareManager != NULL ){
if( m_pHardwareManager->getDetectionParams(tThParams)){
if( tThParams.delta != ptr->nDelta ){
tThParams.delta = ptr->nDelta; isCompromised = true;
};
if( tThParams.flip_size != ptr->nFlip ){
tThParams.flip_size = ptr->nFlip; isCompromised = true;
};
if( tThParams.good_points != ptr->nGPointSamples ){
tThParams.good_points = ptr->nGPointSamples; isCompromised = true;
};
if( tThParams.offset != ptr->nOffset ){
tThParams.offset = ptr->nOffset; isCompromised = true;
};
if( tThParams.order != ptr->nOrder ){
tThParams.order = ptr->nOrder; isCompromised = true;
};
if( tThParams.self_build_ena != ptr->flags.BuildThByCore ){
tThParams.self_build_ena = ptr->flags.BuildThByCore; isCompromised = true;
};
if( tThParams.master != ptr->flags.isMaster ) {
tThParams.master = ptr->flags.isMaster; isCompromised = true;
};
if( isCompromised ) m_pHardwareManager->setDetectionParams( &tThParams );
} else {
LOG_ERROR("Cannot Get Actual Detection Settings!");
return false;
};
isCompromised = false;
if( m_pHardwareManager->getHardwareParams( tHwParams ) ) {
if( tHwParams.AutostartMotors != ptr->flags.AutostartMotors ){
tHwParams.AutostartMotors = ptr->flags.AutostartMotors; isCompromised = true;
};
if( tHwParams.BaseScanCount != ptr->flags.BaseScanCount ){
tHwParams.BaseScanCount = ptr->flags.BaseScanCount; isCompromised = true;
};
if( tHwParams.BBinterlace != ptr->flags.BBinterlace ){
tHwParams.BBinterlace = ptr->flags.BBinterlace; isCompromised = true;
};
if( tHwParams.BuildThByCore != ptr->flags.BuildThByCore ){
tHwParams.BuildThByCore = ptr->flags.BuildThByCore; isCompromised = true;
};
if( tHwParams.DetectorsCount != ptr->flags.DetectorsCount ){
tHwParams.DetectorsCount = ptr->flags.DetectorsCount; isCompromised = true;
};
if( tHwParams.DryContactMode1 != ptr->flags.DryContactMode1 ){
tHwParams.DryContactMode1 = ptr->flags.DryContactMode1; isCompromised = true;
};
if( tHwParams.DryContactMode2 != ptr->flags.DryContactMode2 ){
tHwParams.DryContactMode2 = ptr->flags.DryContactMode2; isCompromised = true;
};
if( tHwParams.DryContactStatus1 != ptr->flags.DryContactStatus1 ){
tHwParams.DryContactStatus1 = ptr->flags.DryContactStatus1; isCompromised = true;
};
if( tHwParams.DryContactStatus2 != ptr->flags.DryContactStatus2 ){
tHwParams.DryContactStatus2 = ptr->flags.DryContactStatus2; isCompromised = true;
};
if( tHwParams.HorizontalFreq != ptr->flags.HorizontalFreq ){
tHwParams.HorizontalFreq = ptr->flags.HorizontalFreq; isCompromised = true;
};
if( tHwParams.HorizontalMotorOn != ptr->flags.HorizontalMotorOn ){
tHwParams.HorizontalMotorOn = ptr->flags.HorizontalMotorOn; isCompromised = true;
};
if( tHwParams.LaserPulsesOn != ptr->flags.LaserPulsesOn ){
tHwParams.LaserPulsesOn = ptr->flags.LaserPulsesOn; isCompromised = true;
};
if( tHwParams.MirrorScanCount != ptr->flags.MirrorScanCount ){
tHwParams.MirrorScanCount = ptr->flags.MirrorScanCount; isCompromised = true;
};
if( tHwParams.QQinterlace != ptr->flags.QQinterlace ){
tHwParams.QQinterlace = ptr->flags.QQinterlace; isCompromised = true;
};
if( isCompromised ) m_pHardwareManager->setHardwareParams( &tHwParams );
} else {
LOG_ERROR("Cannot Get Actual Hardware Settings!");
return false;
};
return true;
};
return false;
};
// KIID 0-7 Master Study 8-15 - Master Work - 16-23 - Slave Study 24-31 - Slave Work
thresholdNode *LRF_Kernel::getTreshold( uint32_t &size, uint8_t kID ){
thresholdNode * retVal = 0;
//if ( kID < 16 ) { // Local TH
#ifdef TH_PER_MIRROR
kID = (kID>39)?39:kID;
#else
kID = (kID>15)?15:kID;
#endif
#ifdef ONPC_TOTTAL_SIMULATOR
if( m_pCurrentTH == NULL ) {
m_pCurrentTH = (thresholdNode *) malloc( TH_SIZE_BYTES );
};
if( m_pCurrentTH != NULL ) {
char fName[64];
sprintf( fName, "sim_data_%d.raw", kID );
if( fileExist( fName ) ) {
FILE *fd = fopen( fName, "rb" );
if( fd != NULL ) {
uint32_t Size = TH_SIZE_NODES;
fread( &Size, sizeof( uint32_t ), 1, fd );
fread( m_pCurrentTH, sizeof( thresholdNode ), Size, fd );
fclose( fd );
};
} else {
for (int i = 0; i < TH_SIZE_NODES; i++) {
m_pCurrentTH[i].values.min = i;
m_pCurrentTH[i].values.max = i;
m_pCurrentTH[i].values.cnt = 1;
m_pCurrentTH[i].values.sbit = 0;
};
}
m_bCurrentTH = kID;
size = TH_SIZE_NODES;
return m_pCurrentTH;
};
#else
if( m_pCurrentTH != NULL ) {
if ( m_bCurrentTH == kID ) {
size = TH_SIZE_NODES;
return m_pCurrentTH;
} else {
if( m_pHardwareManager != NULL ) {
thresholdNode *ptr = m_pHardwareManager->getWorkingMemory();
if( ptr!= NULL ){
memcpy( m_pCurrentTH, ptr+(kID*TH_SIZE_NODES), TH_SIZE_BYTES );
m_bCurrentTH = kID;
size = TH_SIZE_NODES;
return m_pCurrentTH;
} else {
size = 0;
return NULL;
};
};
};
} else {
if( m_pHardwareManager != NULL ){
thresholdNode *ptr = m_pHardwareManager->getWorkingMemory();
if( ptr!= NULL ){
m_pCurrentTH = (thresholdNode *) malloc( TH_SIZE_BYTES );
if( m_pCurrentTH != NULL ) {
memcpy( m_pCurrentTH, ptr+(kID*TH_SIZE_NODES), TH_SIZE_BYTES );
m_bCurrentTH = kID;
size = TH_SIZE_NODES;
return m_pCurrentTH;
};
};
};
};
#endif
size = 0;
return NULL;
};
bool LRF_Kernel::reset( bool FullRestart ){
if( FullRestart ) {
//Shutting down Motors and Hardware
//Starting up Motors and Hardware
shutdown( true );
} else {
m_pHardwareManager->reset( true );
};
return true;
};
bool LRF_Kernel::shutdown( bool Restart ){
if( Restart ) {
LOG("Restarting the Kernel by SHUTDOWN!");
m_bExitCause = 1;
} else {
LOG("Shutting down the Kernel by SHUTDOWN!");
m_bExitCause = 0;
}
setStatus( TH_ENDED );
return true;
};
void LRF_Kernel::forceDrawTH( uint16_t kMASK ){
m_nForcedDrawTH |= kMASK;
};
#ifndef PRU_SLAVE //Just Master Stuff
networkClientHandler *LRF_Kernel::attachNewClient( int SocketID ){
LOG("Creating Client Handler!");
LRF_ClientHandler *tal;
tal = new LRF_ClientHandler( SocketID, this );
if( tal!= NULL ) {
LOG("Client Handler Created!");
};
return (networkClientHandler *) tal;
};
bool LRF_Kernel::detachClient( networkClientHandler *ptr ){
LOG("Delete Client Handler!");
if( ptr == NULL ) return false;
delete( (LRF_ClientHandler *) ptr );
return true;
};
bool LRF_Kernel::stopMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->stopMotors( false );
};
return false;
#else
return true;
#endif
};
bool LRF_Kernel::startMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->startMotors( false );
};
return false;
#else
return true;
#endif
};
bool LRF_Kernel::getRuntimeStatus( ALG_RUN_STATUS *ptr ){
if( ptr == NULL ) return false;
memset( ptr, 0, sizeof( ALG_RUN_STATUS ));
ptr->ENABLED_LRF = m_nKernelFilter;
if( m_pHardwareManager ) {
HWM_CSTATUS tHWS;
if( m_pHardwareManager->getRunTimeStat( &tHWS ) ){
ptr->HW_STATUS = tHWS.HW_STATUS;
ptr->DETECTING_LRF = tHWS._DETECTING_LRF;
ptr->ENABLED_LRF = m_nKernelFilter;
ptr->MASTER_FLIP_CNT = tHWS._FLIP_CNT;
memcpy( ptr->MASTER_MP, tHWS._MP, sizeof(uint32_t) * 8 );
memcpy( ptr->MASTER_GP, tHWS._GP, sizeof(uint32_t) * 8 );
memcpy( ptr->MASTER_WP, tHWS._WP, sizeof(uint32_t) * 8 );
};
} else return false;
if( m_pTWIC ) {
TWIN_STATUS * tPPP = m_pTWIC->getSystemStatus();
if (tPPP->VERSION_IS_SYNCED ) ptr->TWINC_STATUS = 1;
if (tPPP->SETTINGS_IS_SYNCED ) ptr->TWINC_STATUS |= 2;
if (tPPP->SHADOW_IS_SYNCED ) ptr->TWINC_STATUS |= 4;
} else return false;
return true;
};
#endif
#undef LOG
#undef LOG_ERROR

142
lib/App/3dSERVER/LRF_SlimKernel.h

@ -1,142 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Kernel.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Kernel.cpp
//----------------------------------------------------------------------------
//
#ifndef __LRF_KERNEL_H_INCL__
#define __LRF_KERNEL_H_INCL__
//#define TH_USE_PICTURES
#include "../../components/base/basicThread.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "LRF_HardwareManager.h"
#include "LRF_TwinConnector.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../alg/lgs/detector.h"
#include "../../alg/lgs/mask.h"
#ifdef PRU_SLAVE
#include "../../components/base/basicEngine.h"
#else
#include "../../data/net/netServiceEngine.h"
#include "../../data/net/netServer.h"
#include "LRF_TargetTracker.h"
#endif
//#define DUMP_TH_AFTER_FLIP_ON_DISK
#define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF;
#define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond
#define TIME_SYNC_INTERVAL 900000 // 15 minute(s) in 1 millisecond units
#define STATUS_OK_INTERVAL 2000 // 2 Sec in 1 millisecond units
#define KNL_SETTINGS_DETECTOR_WIDTH "DETECTOR_WIDTH"
#define KNL_SETTINGS_FILTER_KERNELS "ENABLED_LRF"
#define KNL_SETTINGS_DETECTOR_SST "DETECTOR_SST"
//#define KNL_SETTINGS_V_MOTOR_SETPOINT "VERTICAL_ENC_FREQ"
/**
* LRF_Kernel class - manages communication between client
* handlers and PRU cores bseide of Event management.
*
*
* @author gagua
*/
#ifdef PRU_SLAVE
class LRF_Kernel: public basicThread, public basicEngine{
#else
class LRF_Kernel: public basicThread, public networkServiceEngine{
#endif
private:
basicLogCollection * m_pLog;
LRF_HardwareManager * m_pHardwareManager;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
basicSettingsProvider * m_pSettingsProvider;
uint32_t m_nKernelFilter;
uint32_t m_lCycleCounter;
uint32_t m_nFlipCounter;
uint32_t m_nFlipSavierID;
uint8_t m_bExitCause;
//LRF3D_WORK_MODE m_eWM;
basicMutex m_mWMProtector;
LRF_TwinConnector * m_pTWIC;
#ifndef PRU_SLAVE
LRF_TargetTracker * m_pTracker;
networkServer * m_pNetClientsServer;
uint32_t m_nSST;
#endif
uint32_t m_nWidth;
ShadowMask * m_pShadow;
thresholdNode * m_pCurrentTH;
uint32_t m_nCurrentTH;
uint8_t m_bCurrentTH;
uint16_t m_nForcedDrawTH;
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit LRF_Kernel( LRF_HardwareManager *HM = NULL );
// Destructor
virtual ~LRF_Kernel();
#ifdef PRU_SLAVE
bool create( LRF_HardwareManager *ptr = NULL );
#else
bool attachNetServer( networkServer *srvPort );
virtual networkClientHandler * attachNewClient( int SocketID );
virtual bool detachClient( networkClientHandler *ptr );
bool create( LRF_HardwareManager *ptr = NULL, networkServer *srvPort = NULL );
bool stopMotors( void );
bool startMotors( void );
bool getRuntimeStatus( ALG_RUN_STATUS *ptr );
#endif
void WaitFinish( bool Force = false );
/* functional API */
bool askReset( void );
PLGS_3D_PARAMETERS getDetectionParameters( void );
//LRF3D_WORK_MODE getWM( void );
bool getParameters( void );
thresholdNode * getTreshold( uint32_t &size, uint8_t kID=0 );
ShadowMask * getShadowMask( void ){ return m_pShadow; };
uint8_t getFilteredKernels(void){ return (m_nKernelFilter & 0xff); };
uint8_t getDetectionKernels(void){ return 0xff; };
void forceDrawTH( uint16_t kMASK );
//void setWM( LRF3D_WORK_MODE nMode );
bool setOffset( uint8_t nOffset );
bool setOrder( uint8_t nOrder );
bool setDetectionParameters( PLGS_3D_PARAMETERS ptr );
bool reset( bool FullRestart = false );
bool shutdown( bool Restart = false );
uint8_t getExitCause( void ){ return m_bExitCause; };
LRF_TwinConnector * getTwinConnector( void ){ return m_pTWIC; };
};
#endif // __LRF_KERNEL_H_INCL__

579
lib/App/3dSERVER/LRF_TargetTracker.cpp

@ -1,579 +0,0 @@
#include "LRF_TargetTracker.h"
#define LOG( X ) m_pLog->Log( "TRK", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "TRK", this, _LOG_ERROR, X )
// Constructor implementation
LRF_TargetTracker::LRF_TargetTracker( int SST, uint32_t Width, uint32_t Delta ){
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_nSST = SST;
m_nSTS = 0;
m_nSTS_R = 0;
m_nWidth = Width;
m_bPoolOverflow = false;
m_nDelta = Delta;
for( int index = 0; index < TRACKER_MAX_TARGETS_POOL; index++ ){
m_aTargetsPool[index].bActive = false;
};
};
// Destructor implementation
LRF_TargetTracker::~LRF_TargetTracker(){
};
TRACKING_RECORD *LRF_TargetTracker::createTrackingRecord( targetRecord *TR, bool master ){
TRACKING_RECORD *pTREC;
if( TR == NULL ) return NULL;
pTREC = (TRACKING_RECORD *) malloc(sizeof(TRACKING_RECORD));
if( pTREC != NULL ) {
long long tMS;
tMS = getMilliseconds();
pTREC->nUTS = tMS / 1000;
pTREC->nUTmS = tMS % 1000;
pTREC->beginID = TR->begin_id;
pTREC->endID = TR->end_id;
pTREC->kernelID = TR->flags.lrf;
if( master ){
pTREC->beginRow = TR->begin_id / TH_LINE_NODES;
pTREC->endRow = TR->end_id / TH_LINE_NODES;
} else {
pTREC->beginRow = Q_SCAN_COUNT - ( TR->begin_id / TH_LINE_NODES );
pTREC->endRow = Q_SCAN_COUNT - ( TR->end_id / TH_LINE_NODES );
};
pTREC->endColumn = pTREC->beginColumn = TR->begin_id % TH_LINE_NODES;
pTREC->area = TR->width;
pTREC->areaCount = TR->flags.w_cnt;
if( pTREC->areaCount ){
pTREC->reducedRange = pTREC->area / pTREC->areaCount;
} else pTREC->reducedRange = 4095;// Set Range to Infinity
pTREC->bMaster = master;
pTREC->bType = ( TR->flags.type == TARGET_WHITE );
pTREC->mTTL = TRACKER_DEFAULT_TTL_VALUE; // Scans to live
pTREC->mSST = m_nSST;
pTREC->bActive = true;
};
return pTREC;
};
void LRF_TargetTracker::clearTrackingRecord( int index ){
if( index < TRACKER_MAX_TARGETS_POOL ){
m_aTargetsPool[index].bActive = false;
};
};
//const LONG FULL_RADIUS = 300L; // meters
//const LONG RADIUS = 48L; // meters per scan
//const INT OFFSET = (INT)( ( RADIUS * ACTUAL_LGS_MAX_DETECTOR_RANGE ) / FULL_RADIUS );
//const LONG KORDER = (LONG)( ( ( RADIUS * ACTUAL_LGS_MAX_DETECTOR_ANGLES * ACTUAL_LGS_MAX_DETECTOR_RANGE ) / ( FULL_RADIUS * 6.28 ) ) );
//float 48.f * 40.f / 3.f;
#define DIFF_CONST 640
inline bool QuickCompare(uint32_t A, uint32_t B){
uint16_t Ax, Ay, Bx, By;
// No difference wheathe master/slave for Tracking Analysis
#ifdef PRU_SLAVE
makeXY( A, Ax, Ay, false );
makeXY( B, Bx, By, false );
#else
makeXY( A, Ax, Ay, true );
makeXY( B, Bx, By, true );
#endif
if( Ax > Bx ) {
if( ( Ax - Bx ) > 8 ) return false;
} else {
if( ( Bx - Ax ) > 8 ) return false;
};
if( Ay > By ) {
if(( Ay - By ) > 8 ) return false;
} else {
if(( By - Ay ) > 8 ) return false;
};
return true;
};
bool LRF_TargetTracker::compareTrackingRecords( TRACKING_RECORD *OLD, TRACKING_RECORD *NEW ){
uint32_t cDelta = 0;
bool bColsInRange = false;
bool bRowsInRange = false;
cDelta =(OLD->reducedRange>NEW->reducedRange)?(OLD->reducedRange-NEW->reducedRange):(NEW->reducedRange-OLD->reducedRange);
if( cDelta <= m_nDelta ){
// Range Difference passed
if(
NEW->beginColumn == OLD->endColumn ||
OLD->beginColumn == NEW->endColumn ||
NEW->beginColumn == OLD->beginColumn ||
OLD->endColumn == NEW->endColumn
){
bColsInRange = true;
} else {
//check if old target NOT overlaps 0
if( OLD->endColumn >= OLD->beginColumn ){
// Check if New Target starts beyand the old's end
if( NEW->beginColumn > OLD->endColumn ) {
// Check if new target overlaps 0
if( NEW->endColumn < NEW->beginColumn ) {
// Must be checked if Overlapped part of New target lays under Old target
if( NEW->endColumn > OLD->beginColumn ) {
bColsInRange = true;
};
};
} else {
//check if new target overlaps 0
if( NEW->endColumn < NEW->beginColumn ) {
bColsInRange = true;
} else {
// Check that New target reaches Old one
if( NEW->endColumn > OLD->beginColumn ) {
bColsInRange = true;
};
};
};
} else {
// If Both Targets overlapes 0 then matched!
if( NEW->endColumn < NEW->beginColumn ) {
bColsInRange = true;
} else {
// Check if New Target starts beyand the old's end
if( NEW->beginColumn > OLD->endColumn ) {
// Check if new target overlaps 0
if( NEW->endColumn < NEW->beginColumn ) {
bColsInRange = true;
} else {
if( NEW->endColumn > OLD->beginColumn ) {
bColsInRange = true;
};
};
} else {
//check if new target overlaps 0
if( NEW->endColumn < NEW->beginColumn ) {
bColsInRange = true;
} else {
// Check that New target reaches Old one
if( NEW->endColumn > OLD->beginColumn ) {
bColsInRange = true;
};
};
};
};
};
};
if( bColsInRange && bRowsInRange ) {
//
return true;
};
};
return false;
};
void LRF_TargetTracker::extentTrackingRecord( TRACKING_RECORD *A, TRACKING_RECORD *B ){
A->mTTL = TRACKER_DEFAULT_TTL_VALUE;
A->beginColumn = (A->beginColumn>B->beginColumn)?B->beginColumn:A->beginColumn;
A->endColumn = (A->endColumn>B->endColumn)?A->endColumn:B->endColumn;
A->beginRow = (A->beginRow>B->beginRow)?B->beginRow:A->beginRow;
A->endRow = (A->endRow>B->endRow)?A->endRow:B->endRow;
A->area += B->area;
A->areaCount += B->areaCount;
A->reducedRange = A->area/A->areaCount;
};
int LRF_TargetTracker::validateTarget( targetRecord *TR, bool bIsMaster ){
TRACKING_RECORD *pTREC;
char tBuff[256];
#ifdef DEBUG
LOG("Validate Target");
#endif
if( TR == NULL ){
LOG_ERROR( "Target Record is Invalid!" );
return -1;
};
if( TR->flags.type != TARGET_BLACK && TR->flags.type != TARGET_WHITE ){
#ifdef DEBUG
LOG("Unknown Target Type [possible error!]");
#endif
return 0;
};
// Filter Width
if( TR->width < m_nWidth ){
#ifdef DEBUG
sprintf( tBuff, "Target Dropped By Filter Width[%d] > %d !", m_nWidth, TR->width );
LOG( tBuff );
#endif
return 0;
};
if ( TR->begin_id > TH_SIZE_NODES ) {
#ifdef DEBUG
sprintf( tBuff, "Target Dropped By Filter Begin ID[%d] > %d !", TR->begin_id, TH_SIZE_NODES );
LOG( tBuff );
#endif
return 0;
};
if ( TR->end_id > TH_SIZE_NODES ) {
#ifdef DEBUG
sprintf( tBuff, "Target Dropped By Filter End ID[%d] > %d !", TR->end_id, TH_SIZE_NODES );
LOG( tBuff );
#endif
return 0;
};
if( TR->range_max > 4000 ) {
#ifdef DEBUG
sprintf( tBuff, "Target Dropped By Range Max[%d] > %d !", TR->range_max, 4000 );
LOG( tBuff );
#endif
return 0;
};
if( TR->range_min > 4000 ) {
#ifdef DEBUG
sprintf( tBuff, "Target Dropped By Range Min[%d] > %d !", TR->range_min, 4000 );
LOG( tBuff );
#endif
return 0;
};
#ifdef DEBUG
LOG("All Seems to be OK");
#endif
m_nSTS++;
pTREC = createTrackingRecord( TR, bIsMaster );
if( pTREC == NULL ) {
LOG_ERROR("No MEMORY to create record!");
return -1;
};
#ifdef TRACKER_INSTANT_TARGET
// Imidiate alarm on any target!
// Do not put it in queue
CLIENT_EVENT *tData;
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
if( tData!= NULL ) {
EVENT_CONTAINER *tEvt = NULL;
tData->a_th_node = pTREC->beginID;//0;
tData->k_id = pTREC->kernelID | ( (pTREC->bMaster )?0x00:0x08 );
tData->range = pTREC->reducedRange;
//tData->th_id = (( pTREC->beginColumn + pTREC->endColumn ) >> 1 ) + ( ( pTREC->beginRow + pTREC->endRow ) >> 1 ) * TH_LINE_NODES;
tData->th_id = pTREC->endID;//pTREC->beginID + ((pTREC->endID - pTREC->beginID ) >> 1 );
tData->w_cnt = pTREC->areaCount;
tData->uts = pTREC->nUTS;
tData->ums = pTREC->nUTmS;
#ifdef DISABLE_FRENDLY_MESSAGES
if( pTREC->bType ) {
tData->type = EVT_TARGET_3D_WHITE;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, NULL, NULL, (void *)tData );
} else {
tData->type = EVT_TARGET_3D_BLACK;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_BLACK, NULL, NULL, (void *)tData );
};
#else
/*sprintf( tBuff, "Target[%d] T:[%d] R:[%d] C:[%d] R:[%d] W:[%d]",
0,
pTREC->bType,
pTREC->reducedRange,
pTREC->beginColumn,
pTREC->beginRow,
pTREC->area );*/
sprintf( tBuff, "Type[%d] K[%d] R[%d] THA[%d] THB[%d] AA[%d] W[%d]",
tData->type,
tData->k_id,
tData->range,
tData->a_th_node,
tData->th_id,
TH_SIZE_NODES,
tData->w_cnt );
if( pTREC->bType ) {
tData->type = EVT_TARGET_3D_WHITE;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, NULL, tBuff, (void *)tData );
} else {
tData->type = EVT_TARGET_3D_BLACK;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_BLACK, NULL, tBuff, (void *)tData );
};
#endif
if( tEvt != NULL ) {
tEvt->m_eClass = EVT_CLASS_SENSOR_3D;
m_pEventHeap->broadcast( tEvt );
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
LOG( tBuff );
#endif
#endif
} else {
free( tData );
LOG_ERROR( "Event Memory Allocation Error!" );
};
} else {
LOG_ERROR("Not Enought Memory to create Event Data!");
};
free( pTREC );
return 0;
#else //TRACKER_INSTANT_TARGET
//if( m_nSST == 0 ) {
//alarmDataEvent *tData;
//tData->mInfo = pTREC->kernelID;
//tData->mInfo |= ( ( pTREC->bType)? 0x00FF0000:0 )|( ( pTREC->bMaster )?0xFF000000:0 );
//tData->mRange = pTREC->reducedRange;
//tData->mSampleID = (( pTREC->beginColumn + pTREC->endColumn ) >> 1 ) + ( ( pTREC->beginRow + pTREC->endRow ) >> 1 ) * TH_LINE_NODES;
//tData->mStartID = pTREC->beginID;
//tData->mEndID = pTREC->endID;
//tData->mWidth = pTREC->area;
//tData->mCount = pTREC->areaCount;
//};
#ifdef DEBUG
LOG("Tracking Record Created");
#endif
for( int index = 0; index < TRACKER_MAX_TARGETS_POOL; index++ ){
if( m_aTargetsPool[index].bActive ){
#ifdef TRACKER_FULL_COMPARE
if( compareTrackingRecords( &m_aTargetsPool[index], pTREC ) ) {
#ifdef DEBUG_EXTRA
LOG("Compared[FullCompare] - found EQ");
#endif
extentTrackingRecord( &m_aTargetsPool[index], pTREC );
free( pTREC );
return index;
};
#else // TRACKER_FULL_COMPARE
bool A, B, C, D;
A = QuickCompare( m_aTargetsPool[index].beginID, pTREC->beginID );
B = QuickCompare( m_aTargetsPool[index].endID, pTREC->beginID );
C = QuickCompare( m_aTargetsPool[index].beginID, pTREC->endID );
D = QuickCompare( m_aTargetsPool[index].endID, pTREC->endID );
if( A | B | C | D ) {
#ifdef DEBUG_EXTRA
LOG("Compared[QuickCompare] - found EQ");
#endif
extentTrackingRecord( &m_aTargetsPool[index], pTREC );
free( pTREC );
return index;
};
#endif // TRACKER_FULL_COMPARE
};
};
#ifdef DEBUG_EXTRA
LOG("Not Found EQ Targets");
#endif
for( int index = 0; index < TRACKER_MAX_TARGETS_POOL; index++ ){
if( !m_aTargetsPool[index].bActive ){
#ifdef DEBUG_EXTRA
LOG("Assigning to Empty Tracking Record");
#endif
m_aTargetsPool[index].bActive = true;
memcpy( &m_aTargetsPool[index], pTREC, sizeof( TRACKING_RECORD ));
free( pTREC );
return index;
};
};
// Overflow!
m_bPoolOverflow = true;
free( pTREC );
LOG_ERROR("Targets Pool Overflow!");
return -1;
#endif // TRACKER_INSTANT_TARGET
};
void LRF_TargetTracker::MirrorComplete( void ){
char tBuff[256];
uint32_t Q_Width = m_nWidth;//( m_nWidth * m_nWidth );
//if( m_nSST == 0 ) return;
for( int index = 0; index < TRACKER_MAX_TARGETS_POOL; index++ ){
if( m_aTargetsPool[index].bActive ){
if( m_aTargetsPool[index].area > Q_Width ) {
/* Output all target and clean queue */
CLIENT_EVENT *tData = NULL;
tData = (CLIENT_EVENT *) malloc(sizeof(CLIENT_EVENT));
if( tData!= NULL ) {
EVENT_CONTAINER *tEvt = NULL;
tData->a_th_node = 0;
tData->k_id = m_aTargetsPool[index].kernelID | ( (m_aTargetsPool[index].bMaster )?0x00:0x08 );
tData->range = m_aTargetsPool[index].reducedRange;
tData->th_id = (( m_aTargetsPool[index].beginColumn + m_aTargetsPool[index].endColumn ) >> 1 ) +
(( m_aTargetsPool[index].beginRow + m_aTargetsPool[index].endRow ) >> 1 ) * TH_LINE_NODES;
tData->w_cnt = m_aTargetsPool[index].areaCount;
tData->uts = m_aTargetsPool[index].nUTS;
tData->ums = m_aTargetsPool[index].nUTmS;
#ifdef DISABLE_FRENDLY_MESSAGES
if( m_aTargetsPool[index].bType ) {
tData->type = EVT_TARGET_3D_WHITE;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, NULL, NULL, (void *)tData );
} else {
tData->type = EVT_TARGET_3D_BLACK;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_BLACK, NULL, NULL, (void *)tData );
};
#else
sprintf( tBuff, "Target[%d] T:[%d] R:[%d] C:[%d] R:[%d] W:[%d]",
0,
m_aTargetsPool[index].bType,
m_aTargetsPool[index].reducedRange,
m_aTargetsPool[index].beginColumn,
m_aTargetsPool[index].beginRow,
m_aTargetsPool[index].area );
if( m_aTargetsPool[index].bType ) {
tData->type = EVT_TARGET_3D_WHITE;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_WHITE, NULL, tBuff, (void *)tData );
} else {
tData->type = EVT_TARGET_3D_BLACK;
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_3D_BLACK, NULL, tBuff, (void *)tData );
};
#endif
if( tEvt != NULL ) {
tEvt->m_eClass = EVT_CLASS_SENSOR_3D;
m_pEventHeap->broadcast( tEvt );
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
LOG( tBuff );
#endif
#endif
} else {
free( tData );
LOG_ERROR( "Event Memory Allocation Error!" );
};
} else {
LOG_ERROR("Not Enought Memory to create Event Data!");
};
}; // Filter Width
// each tarhet must be cleared before new mirror cycle
#ifdef DEBUG
sprintf( tBuff, "Clear Active Target Record#%d", index );
LOG( tBuff );
#endif
clearTrackingRecord( index );
#ifdef JANGANANGA
if( m_aTargetsPool[index].mTTL ) m_aTargetsPool[index].mTTL--;
if( m_aTargetsPool[index].mTTL == 0 ){
if( m_aTargetsPool[index].area > Q_Width ) {
/* Prepare Target Data */
m_nSTS_R++;
alarmDataEvent *tData;
tData = (alarmDataEvent *) malloc(sizeof(alarmDataEvent));
if( tData!= NULL ) {
basicEvent *tEvt = NULL;
tData->mInfo = m_aTargetsPool[index].kernelID;
tData->mInfo |= ( ( m_aTargetsPool[index].bType)? 0x00FF0000:0 )|( ( m_aTargetsPool[index].bMaster )?0xFF000000:0 );
tData->mRange = m_aTargetsPool[index].reducedRange;
//tData->mSampleID = (( pTREC->beginColumn + pTREC->endColumn ) >> 1 ) + ( ( pTREC->beginRow + pTREC->endRow ) >> 1 ) * TH_LINE_NODES;
tData->mStartID = m_aTargetsPool[index].beginID;
tData->mEndID = m_aTargetsPool[index].endID;
tData->mWidth = m_aTargetsPool[index].area;
tData->mCount = m_aTargetsPool[index].areaCount;
#ifdef DISABLE_FRENDLY_MESSAGES
if( m_aTargetsPool[index].bType ) {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_WHITE, NULL, NULL, (void *)tData );
} else {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_BLACK, NULL, NULL, (void *)tData );
};
#else
sprintf( tBuff, "Target[%d] T:[%d] R:[%d] C:[%d] R:[%d] W:[%d]",
index,
m_aTargetsPool[index].bType,
m_aTargetsPool[index].reducedRange,
m_aTargetsPool[index].beginColumn,
m_aTargetsPool[index].beginRow,
m_aTargetsPool[index].area );
if( m_aTargetsPool[index].bType ) {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_WHITE, NULL, tBuff, (void *)tData );
} else {
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_BLACK, NULL, tBuff, (void *)tData );
};
#endif
if( tEvt != NULL ) {
tEvt->m_eClass = EVT_CLASS_SENSOR_3D;
m_pEventHeap->broadcast( tEvt );
#ifndef SKIP_TARGET_LOG
#ifdef DEBUG
LOG( tBuff );
#endif
#endif
} else {
LOG_ERROR( "Event Memory Allocation Error!" );
};
} else {
LOG_ERROR("Not Enought Memory to create Event Data!");
};
} else {
//sprintf( tBuff, "Filtered Target[%d] A:%d W2W:%d", index, m_aTargetsPool[index].area, Q_Width );
//LOG( tBuff );
};
clearTrackingRecord( index );
};
#endif
};
};
};
/*
Master 1: 192.168.1.60 - C4:BE:84:CD:AA:60
Slave 1: 192.168.1.61 - C4:BE:84:CD:BE:46
Master 2: 192.168.1.62 -
Slave 2: 192.168.1.63 -
*/
void LRF_TargetTracker::ScanComplete( void ){
char tBuff[64];
if( m_nSST == 0 ) return;
for( int index = 0; index < TRACKER_MAX_TARGETS_POOL; index++ ){
if( m_aTargetsPool[index].bActive ) {
/*LOG("Active Target!");
if( m_aTargetsPool[index].mSST == 0 ){
LOG("SST Passed");
if( m_aTargetsPool[index].area > m_nWidth ) {
LOG("Width Filter Passed");
// Prepare Target Data
alarmDataEvent *tData;
tData = (alarmDataEvent *) malloc(sizeof(alarmDataEvent));
if( tData!= NULL ) {
basicEvent *tEvt = NULL;
tData->mInfo = ( m_aTargetsPool[index].bMaster )?0xFF0000FF:0xFF;
tData->mRange = m_aTargetsPool[index].reducedRange;
tData->mSampleID = m_aTargetsPool[index].beginColumn;
sprintf( tBuff, "Target[%d] R:[%d] C:[%d] R:[%d] W:[%d]",
m_aTargetsPool[index].bType,
m_aTargetsPool[index].reducedRange,
m_aTargetsPool[index].beginColumn,
m_aTargetsPool[index].beginRow,
m_aTargetsPool[index].area
);
tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_TARGET_WHITE, NULL, tBuff, (void *)tData );
if( tEvt != NULL ) {
tEvt->m_eClass = EVT_CLASS_SENSOR_3D;
m_pEventHeap->broadcast( tEvt );
LOG( tBuff );
} else {
LOG_ERROR( "Event Memory Allocation Error!" );
};
} else {
LOG_ERROR("Not Enought Memory to create Event Data!");
};
} else {
LOG("Width Filtered! Clear Target Record");
clearTrackingRecord( index );
};
};
*/
};
};
//sprintf( tBuff, "Scan Done with %d Active Targets - %d PASSED Filters ", m_nSTS, m_nSTS_R );
m_nSTS = 0;
m_nSTS_R = 0;
};
#undef LOG
#undef LOG_ERROR

73
lib/App/3dSERVER/LRF_TargetTracker.h

@ -1,73 +0,0 @@
#ifndef __LRF_TARGETTRACKER_H_INCL__
#define __LRF_TARGETTRACKER_H_INCL__
#include "../../components/base/basicFunctionality.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicEventHeap.h"
#include "../../hardware/soc/general/3DLRF.h"
#include <math.h>
#define TRACKER_MAX_TARGETS_POOL 128
#define TRACKER_DEFAULT_TTL_VALUE 3 // Scans to live
typedef vector<uint32_t> vectorIDS;
typedef struct S_TRACKING_RECORD{
bool bActive;
bool bMaster;
bool bType;
// Time
uint32_t nUTS;
uint32_t nUTmS;
// Legacy
uint32_t beginID;
uint32_t endID;
uint8_t kernelID;
// Position in Sample Matrix
uint32_t beginColumn;
uint16_t beginRow;
uint32_t endColumn;
uint16_t endRow;
// Detected Sample Data
uint32_t area;
uint32_t reducedRange;
uint32_t areaCount;
// Tracking Purpose variables
uint32_t mTTL;
uint32_t mSST;
}TRACKING_RECORD;
/**
* TODO: Add class description
*
* @author gagua
*/
class LRF_TargetTracker {
private:
basicLogCollection * m_pLog;
basicEventHeap * m_pEventHeap;
uint32_t m_nSST;
bool m_bPoolOverflow;
uint32_t m_nWidth;
uint32_t m_nDelta;
uint32_t m_nSTS;
uint32_t m_nSTS_R;
TRACKING_RECORD m_aTargetsPool[TRACKER_MAX_TARGETS_POOL];
TRACKING_RECORD * createTrackingRecord( targetRecord *TR, bool master = true );
void clearTrackingRecord( int index );
bool compareTrackingRecords( TRACKING_RECORD *A, TRACKING_RECORD *B );
void extentTrackingRecord( TRACKING_RECORD *A, TRACKING_RECORD *B );
public:
// Constructor
explicit LRF_TargetTracker( int SST = 0, uint32_t Width = 0, uint32_t Delta = 32 );
// Destructor
virtual ~LRF_TargetTracker();
int validateTarget( targetRecord *TR, bool master = true );
void ScanComplete( void );
void MirrorComplete( void );
uint32_t getSST( void ){ return m_nSST; };
};
#endif // __LRF_TARGETTRACKER_H_INCL__

1276
lib/App/3dSERVER/LRF_TwinConnector.cpp
File diff suppressed because it is too large
View File

137
lib/App/3dSERVER/LRF_TwinConnector.h

@ -1,137 +0,0 @@
#ifndef __LRF_TWINCONNECTOR_H_INCL__
#define __LRF_TWINCONNECTOR_H_INCL__
#include "../../data/protocol/protocolInternalLRF3D.h"
#include "../../components/base/basicFunctionality.h"
#ifdef PRU_SLAVE
#include "../../data/net/clientPort.h"
#else
#include "../../data/net/serverPort.h"
#endif
//#define TH_USE_PICTURES
#define TWI_QUICK_LOOP_SLEEP 15
#define TWI_SLOW_LOOP_SLEEP 100
#define TWI_STATUS_LOOP_MS 500
#define TWI_RECONNECT_LOOP_SLEEP 1000
#define TWI_DRAW_LOOP_MS 300000 // 5 minutes
#define TWI_PING_PONG_TO 2000 // 2 seconds
#define TWI_MAX_QUEUE_SIZE 200
#define STORAGE_DIR_MODE 0x1FF
#define STORAGE_FILE_MODE 0x1B6
typedef enum E_TWI_WM{
TWI_STAGE_NO_AKTIVE = 0,
TWI_STAGE_CONNECTING = 1,
TWI_STAGE_CONNECTED,
TWI_STAGE_BORDER,
TWI_STAGE_IDLE,
TWI_STAGE_DISCONNECTING
} TWI_WM;
class LRF_Kernel;
#ifdef PRU_SLAVE
class LRF_TwinConnector: public basicThread, protocolInternalLRF3D_SLAVE {
#else
class LRF_TargetTracker;
class LRF_TwinConnector: public basicThread, protocolInternalLRF3D_MASTER {
#endif
private:
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
LRF_Kernel * m_pEngine;
TWIN_COMMAND m_eCCMD;
TWI_WM m_eWM;
void setWM( TWI_WM NWM );
TWI_WM getWM();
TWI_CMD_QUEUE m_qCMD;
void setCMD( TWIN_COMMAND NCMD );
uint8_t m_bCMDTO;
TWIN_COMMAND getCMD();
TWI_CMD_CONTAINER * fetchCMD();
void pushCMD( TWI_CMD_CONTAINER *ptr );
void pushCMD( TWIN_COMMAND CMD, void *ptr = NULL, size_t DataSize = 0 );
basicMutex m_mStatusProtector;
basicMutex m_mWMProtector;
basicMutex m_mQUEUEProtector;
basicMutex m_mCMDProtector;
//TH FLIP-DROW STUFF
bool m_bDrawByRAW;
bool m_bDrawMonochrome;
basicMutex m_mDrawProtector;
thresholdNode * m_pCurrentTH;
uint32_t m_nCurrentTH;
void waitDrawThreadEnd( bool forced = false );
pthread_t m_sDrawThreadHandler;
thredStatus m_bDrawThreadStatus;
static void * m_fDrawThreadEntryPoint(void *);
#ifdef TH_USE_PICTURES
bool saveTHPicture( thresholdNode *ptr, CSTR fileName, bool monochrome = false, bool agressive = false );
#endif
bool cleanTHData( uint8_t kid );
bool loadTHData( uint8_t kid, thresholdNode *ptr );
bool saveTHData( uint8_t kid, thresholdNode *ptr );
void cleanupInfo(void);
#ifdef PRU_SLAVE
uint16_t m_nMasterPort;
char m_cMasterAddress[16];
TWI_PEER_STATUS m_sSystemStatus;
uint8_t m_bOldTHRecords;
vectorZoneMask m_vShadowZM;
#else
int m_nMainSocket;
LRF_TargetTracker * m_pTracker;
uint16_t m_nBindPort;
char m_cBindAddress[16];
TWIN_STATUS m_sSystemStatus;
ShadowMask * m_pSlaveShadowMask;
TWI_MASK_INFO m_sSlaveMaskInfo;
#endif
protected:
void m_fThreadProc( void ); // Connection/THDraw Handling Thread
virtual bool packetHandler( protocolPackage *Package );
public:
explicit LRF_TwinConnector( config_setting_t *Settings = NULL );
virtual ~LRF_TwinConnector();
bool create();
void setKernel( LRF_Kernel *ptr ){ m_pEngine = ptr; };
bool readyToConsumeTH( void );
bool requestRemoteDraw( uint8_t kID ){ return true; };
bool consumeTH( uint8_t kID, thresholdNode *ptr, uint32_t THsize );
#ifdef PRU_SLAVE
bool sendCurrentSettings( void );
bool sendSoftwareVersion( void );
bool sendEvent();
bool validateTarget( targetRecord *ptr );
#else
bool attachTargetTracker( LRF_TargetTracker *ptr );
bool updateSettings( void );
TWIN_STATUS * getSystemStatus(){ return &m_sSystemStatus; };
ShadowMask * getShadowMask( void ){ return m_pSlaveShadowMask; };
thresholdNode * getTreshold( uint32_t &size, uint8_t kID=0 );
#endif
};
#endif

275
lib/App/CudaWare_64_DNN_Learning/main_window.cpp

@ -1,275 +0,0 @@
#include "main_window.h"
mainWinow* mainWinow::_instance = 0;
void mainWinow::changeEvent(QEvent *event){
if(event->type() == QEvent::WindowStateChange ){
if (!isMinimized()) {
setAttribute(Qt::WA_Mapped);
};
};
};
mainWinow::mainWinow() : QMainWindow(){
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, (CSTR)"APPLICATION_GUI");
m_pFactory = cortexLayersFactory::getInstance();
m_pCortex = NULL;
m_bChangesAreSaved = true;
m_pMainWidget = new QWidget( NULL );
m_pMainWidget->setObjectName("m_pMainWidget");
setCentralWidget( m_pMainWidget );
QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins(5, 5, 5, 5);
//m_pMainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_pLayerTable = new QTableWidget( this );
m_pLayerTable->setColumnCount( 5 );
m_pLayerTable->setSortingEnabled( false );
m_pLayerTable->setSelectionMode( QAbstractItemView::SingleSelection );
m_pLayerTable->setSelectionBehavior( QAbstractItemView::SelectRows );
m_pLayerTable->setGridStyle( Qt::DashLine );
m_pLayerTable->setCornerButtonEnabled( true );
layout->addWidget(m_pLayerTable);
QTableWidgetItem* __qtablewidgetitem;
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText("Type");
m_pLayerTable->setHorizontalHeaderItem( 0, __qtablewidgetitem );
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText("Filter");
m_pLayerTable->setHorizontalHeaderItem( 1, __qtablewidgetitem );
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText("FIlter Size");
m_pLayerTable->setHorizontalHeaderItem( 2, __qtablewidgetitem );
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText("Input");
m_pLayerTable->setHorizontalHeaderItem( 3, __qtablewidgetitem );
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText("Output");
m_pLayerTable->setHorizontalHeaderItem( 4, __qtablewidgetitem );
connect(m_pLayerTable, &QTableWidget::cellClicked, this, &mainWinow::selectLayerRow );
QHBoxLayout* hlayout = new QHBoxLayout;
hlayout->setContentsMargins(5, 5, 5, 5);
m_pTabWidget = new QTabWidget( this );
m_pTabWidget->setObjectName( "m_pTabWidget" );
m_pTabLayerVisual = new QWidget();
m_pTabLayerVisual->setObjectName("m_pTabLayerVisual");
QHBoxLayout* hlayout1 = new QHBoxLayout;
hlayout1->setContentsMargins(5, 5, 5, 5);
m_pLayerPreview = new CortexLayerWidget( m_pTabLayerVisual );
if( m_pLayerPreview->init() ){
};
hlayout1->addWidget(m_pLayerPreview);
m_pTabLayerVisual->setLayout(hlayout1);
m_pTabWidget->addTab(m_pTabLayerVisual, "Layer Visual");
m_pTabCategories = new QWidget();
m_pTabCategories->setObjectName("m_pTabCategories");
m_pTabWidget->addTab(m_pTabCategories, "Classes");
m_pTabLearning = new QWidget();
m_pTabLearning->setObjectName("m_pTabLearning");
m_pTabWidget->addTab(m_pTabLearning, "Learning");
m_pTabInput = new QWidget();
m_pTabInput->setObjectName("m_pTabInput");
QHBoxLayout* hlayout2 = new QHBoxLayout;
hlayout2->setContentsMargins(5, 5, 5, 5);
m_pInputStream = new MediaDestWidget( m_pTabInput );
if( m_pInputStream->init() ){
m_pAVLIBSource = new videoAVLIBSource();
if (m_pAVLIBSource != NULL) {
if( m_pAVLIBSource->_open("C:\\KeepVid Pro Downloaded\\The Renter.mp4") ){
m_pAVLIBSource->attachDestination(m_pInputStream);
};
};
};
hlayout2->addWidget(m_pInputStream);
m_pTabInput->setLayout(hlayout2);
m_pTabWidget->addTab(m_pTabInput, "Input");
m_pTabOutput = new QWidget();
m_pTabOutput->setObjectName("m_pTabOutput");
m_pOutputStream = new MediaDestWidget( m_pTabOutput );
m_pOutputStream->init();
m_pTabWidget->addTab(m_pTabOutput, "Output");
m_pTabProcessingUnits = new QWidget();
m_pTabProcessingUnits->setObjectName("m_pTabProcessingUnits");
m_pTabWidget->addTab(m_pTabProcessingUnits, "Processing Unit");
hlayout->addWidget(m_pTabWidget);
layout->addItem( hlayout );
m_pMainWidget->setLayout(layout);
setObjectName("Mainwindow");
/* Menu Things */
actionNew_Network = new QAction( QIcon(":/general/file.png"), "&New", this );
actionNew_Network->setShortcuts(QKeySequence::New);
actionNew_Network->setStatusTip(tr("Create a new Network"));
connect( actionNew_Network, &QAction::triggered, this, &mainWinow::newNetwork );
actionOpen = new QAction( QIcon(":/layout/PNG/layout/049.png"), "&Open", this );
actionOpen->setShortcuts(QKeySequence::Open);
actionOpen->setStatusTip(tr("Open Network Config"));
connect( actionOpen, &QAction::triggered, this, &mainWinow::open );
actionSave = new QAction( QIcon(":/layout/PNG/layout/048.png"), "&Save", this );
actionSave->setShortcuts(QKeySequence::Save);
actionSave->setStatusTip(tr("Save Network Config"));
connect(actionSave, &QAction::triggered, this, &mainWinow::save);
actionSave_As = new QAction( QIcon(":/layout/PNG/layout/048.png"), "Save &As", this );
actionSave_As->setShortcuts(QKeySequence::SaveAs);
actionSave_As->setStatusTip(tr("Save Network Config in Another File"));
connect(actionSave_As, &QAction::triggered, this, &mainWinow::saveAs);
actionExit = new QAction( QIcon(":/layout/PNG/layout/076.png"), "&Exit", this);
actionExit->setShortcuts(QKeySequence::Close);
actionExit->setStatusTip(tr("Exit Application"));
connect(actionExit, &QAction::triggered, this, &mainWinow::exitApp);
menuFile = menuBar()->addMenu(QIcon(":/menu/PNG/devices/008.png"),"&File");
menuFile->setObjectName("menuFile");
menuFile->addAction(actionNew_Network);
menuFile->addAction(actionOpen);
menuFile->addAction(actionSave);
menuFile->addAction(actionSave_As);
menuFile->addAction(actionExit);
toolBar = addToolBar("Yoba!");
toolBar->setObjectName("toolBar");
toolBar->setOrientation(Qt::Horizontal);
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolBar->setFloatable(true);
tbActionAdd = toolBar->addAction(QIcon(":/layout/PNG/layout/064.png"), "Add Layer");
tbActionInsert = toolBar->addAction(QIcon(":/layout/PNG/layout/067.png"), "Insert Layer");
tbActionEdit = toolBar->addAction(QIcon(":/layout/PNG/layout/073.png"), "Edit Layer");
tbActionEdit->setEnabled(false);
tbActionDelete = toolBar->addAction(QIcon(":/layout/PNG/layout/066.png"), "Delete Layer");
tbActionDelete->setEnabled(false);
toolBar->addSeparator();
tbActionLoadWeights = toolBar->addAction(QIcon(":/layout/PNG/layout/024.png"), "Load Weights");
tbActionLoadWeights->setEnabled(false);
insertToolBarBreak(toolBar);
statusBar()->showMessage("Init Done.");
setWindowTitle(tr("Neural Network Manager"));
setMinimumSize(160, 160);
};
mainWinow::~mainWinow(){
if (m_pAVLIBSource != NULL) {
m_pAVLIBSource->_stop();
delete(m_pAVLIBSource);
};
};
/**
* Returns the single instance of the object.
*/
mainWinow* mainWinow::getInstance() {
// check if the instance has been created yet
if (0 == _instance){
// if not, then create it
_instance = new mainWinow();
};
// return the single instance
return _instance;
};
void mainWinow::newNetwork(){
if (m_pFactory != NULL) {
m_pFactory->cleanFactory();
};
};
void mainWinow::open(){
QString fileName;
fileName = QFileDialog::getOpenFileName(this, "Open Data", "data/", "Data Files (*.cfg *.raw *.jpg *.bmp)");
char fName[MAX_PATH];
sprintf( fName, "%s", fileName.toStdString().c_str() );
if( strlen(fName) ){
char tBuff[1024];
sprintf(tBuff, "Neural Network Manager: %s", fName );
setWindowTitle(tBuff);
if (m_pCortex != NULL) {
for (uint32_t index = m_pLayerTable->rowCount(); index > -1; index-- ) m_pLayerTable->removeRow(index);
delete(m_pCortex);
m_pCortex = NULL;
};
m_pCortex = m_pFactory->parseConfig(fName);
if( m_pCortex!= NULL ) {
for( uint32_t index = 0; index < m_pCortex->getLayersCount(); index++ ){
char tBuff[256];
m_pLayerTable->insertRow(index);
QTableWidgetItem * __qtablewidgetitem;
__qtablewidgetitem = new QTableWidgetItem();
__qtablewidgetitem->setText( m_pCortex->getLayer(index)->getString() );
m_pLayerTable->setItem( index, 0, __qtablewidgetitem );
__qtablewidgetitem = new QTableWidgetItem();
sprintf(tBuff, "%dx%dx%d", m_pCortex->getLayer(index)->getInputSizeWidth(), m_pCortex->getLayer(index)->getInputSizeHeight(), m_pCortex->getLayer(index)->getInputSizeChannels() );
__qtablewidgetitem->setText(tBuff );
m_pLayerTable->setItem(index, 3, __qtablewidgetitem);
__qtablewidgetitem = new QTableWidgetItem();
sprintf(tBuff, "%dx%dx%d", m_pCortex->getLayer(index)->getOutputSizeWidth(), m_pCortex->getLayer(index)->getOutputSizeHeight(), m_pCortex->getLayer(index)->getOutputSizeChannels());
__qtablewidgetitem->setText(tBuff);
m_pLayerTable->setItem(index, 4, __qtablewidgetitem);
};
tbActionLoadWeights->setEnabled(true);
};
};
};
void mainWinow::save(){
m_bChangesAreSaved = true;
};
void mainWinow::saveAs(){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save Data As ...", "data/", "Data Files (*.raw *.jpg *.bmp)");
m_bChangesAreSaved = true;
};
void mainWinow::exitApp() {
if (m_bChangesAreSaved) {
QApplication::quit();
} else {
QMessageBox::StandardButton reply;
reply = QMessageBox::question( this, "Unsaved Data", "Are you sure to Quit?", QMessageBox::Yes | QMessageBox::No);
if( reply == QMessageBox::Yes ){
QApplication::quit();
};
};
};
void mainWinow::contextMenuEvent(QContextMenuEvent* event){
QMenu menu(this);
//menu.addAction(cutAct);
//menu.addAction(copyAct);
//menu.addAction(pasteAct);
menu.exec(event->globalPos());
};
void mainWinow::selectLayerRow( int row, int col ){
tbActionEdit->setEnabled(true);
tbActionDelete->setEnabled(true);
m_pLayerPreview->attachCortexLayer(m_pCortex->getLayer(row));
};

88
lib/App/CudaWare_64_DNN_Learning/main_window.h

@ -1,88 +0,0 @@
#ifndef __QT5_MAIN_WINDOW_HEADER__
#define __QT5_MAIN_WINDOW_HEADER__
#ifndef __linux__
#include <WinSock2.h>
#endif
#include "../../components/base/basicSettingsProvider.h"
#include "../../gui/guiClass.h"
#include "../../data/cortex/layers/layersFactory.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../gui/controls/MediaDestWidget.h"
#include "../../gui/controls/CortexLayerWidget.h"
class mainWinow : public QMainWindow{
//Q_OBJECT
private:
config_setting_t * m_pSettings;
QWidget * m_pMainWidget;
bool m_bChangesAreSaved;
cortexLayersFactory * m_pFactory;
basicCortex * m_pCortex;
QTableWidget * m_pLayerTable;
QTabWidget * m_pTabWidget;
QWidget * m_pTabProcessingUnits;
QWidget * m_pTabNetworkStageVisual;
QWidget * m_pTabLayerVisual;
QWidget * m_pTabCategories;
QWidget * m_pTabLearning;
QWidget * m_pTabInput;
QWidget * m_pTabOutput;
videoAVLIBSource * m_pAVLIBSource;
MediaDestWidget * m_pInputStream;
MediaDestWidget * m_pOutputStream;
CortexLayerWidget * m_pLayerPreview;
void * m_pInputImage;
private slots:
void newNetwork();
void open();
void save();
void saveAs();
void exitApp();
void selectLayerRow( int, int );
public:
QAction * actionNew_Network;
QAction * actionOpen;
QAction * actionSave;
QAction * actionSave_As;
QAction * actionExit;
QAction * tbActionInsert;
QAction * tbActionAdd;
QAction * tbActionEdit;
QAction * tbActionDelete;
QAction * tbActionLoadWeights;
QMenu * menuFile;
QToolBar * toolBar;
// Method to fetch singleton instance.
static mainWinow * getInstance();
// Destructor
virtual ~mainWinow();
protected:
mainWinow();
void changeEvent(QEvent *event);
void contextMenuEvent(QContextMenuEvent* event) override;
private:
// private static member referencing the single instance of the object
// TODO: Replace basicLogCollection with the type of object you want to
// return the single instance of
static mainWinow* _instance;
// Copy constructor
// Declared but not defined to prevent auto-generated
// copy constructor. Refer to "Effective C++" by Meyers
mainWinow(const mainWinow& src);
// Assignment operator
// Declared but not defined to prevent auto-generated
// assignment operator. Refer to "Effective C++" by Meyers
mainWinow& operator=(const mainWinow& src);
public slots:
// void callbackSettings(void);
// void callbackClear(void);
};
#endif

273
lib/App/CudaWare_64_DNN_Learning/main_window.ui

@ -1,273 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>794</width>
<height>604</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<height>561</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<item>
<property name="text">
<string>koko</string>
</property>
</item>
<item>
<property name="text">
<string>kokol</string>
</property>
</item>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Tab 1</string>
</attribute>
<widget class="QTableWidget" name="tableWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>321</width>
<height>211</height>
</rect>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="gridStyle">
<enum>Qt::DashLine</enum>
</property>
<property name="cornerButtonEnabled">
<bool>true</bool>
</property>
<row>
<property name="text">
<string>1</string>
</property>
</row>
<row>
<property name="text">
<string>2</string>
</property>
</row>
<column>
<property name="text">
<string>kaka</string>
</property>
</column>
<column>
<property name="text">
<string>Maka</string>
</property>
</column>
<column>
<property name="text">
<string>Baka</string>
</property>
</column>
<item row="0" column="0">
<property name="text">
<string>11</string>
</property>
</item>
<item row="0" column="1">
<property name="text">
<string>22</string>
</property>
</item>
<item row="0" column="2">
<property name="text">
<string>33</string>
</property>
</item>
<item row="1" column="0">
<property name="text">
<string>22</string>
</property>
</item>
<item row="1" column="1">
<property name="text">
<string>33</string>
</property>
</item>
<item row="1" column="2">
<property name="text">
<string>44</string>
</property>
</item>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Tab 2</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>794</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionNew_Network"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="floatable">
<bool>true</bool>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
</widget>
<action name="actionNew_Network">
<property name="icon">
<iconset resource="../../resources/cudawork_resources.qrc">
<normaloff>:/general/bulb.png</normaloff>:/general/bulb.png</iconset>
</property>
<property name="text">
<string>New Network</string>
</property>
</action>
<action name="actionOpen">
<property name="icon">
<iconset resource="../../resources/cudawork_resources.qrc">
<normaloff>:/menu/PNG/devices/030.png</normaloff>:/menu/PNG/devices/030.png</iconset>
</property>
<property name="text">
<string>Open</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="actionSave_As">
<property name="text">
<string>Save As</string>
</property>
</action>
</widget>
<resources>
<include location="../../resources/cudawork_resources.qrc"/>
</resources>
<connections>
<connection>
<sender>listWidget</sender>
<signal>clicked(QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>353</x>
<y>160</y>
</hint>
<hint type="destinationlabel">
<x>396</x>
<y>301</y>
</hint>
</hints>
</connection>
<connection>
<sender>tableWidget</sender>
<signal>cellClicked(int,int)</signal>
<receiver>MainWindow</receiver>
<slot>show()</slot>
<hints>
<hint type="sourcelabel">
<x>183</x>
<y>454</y>
</hint>
<hint type="destinationlabel">
<x>396</x>
<y>301</y>
</hint>
</hints>
</connection>
</connections>
</ui>

275
lib/App/Pathfinder/PathfinderBackend.cpp

@ -1,275 +0,0 @@
#include "PathfinderBackend.h"
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
PF_Kernel * Kernel = NULL;
//LRF_HardwareManager * HWManager = NULL;
basicLogCollection * m_pLog = NULL;
//networkServer * NetworkManager = NULL;
void (*old_update_handler_2)(int); //SIGINT
void (*old_kill_handler_3)(int); //SIGQUIT
void (*old_kill_handler_9)(int); //SIGKILL
void (*old_alarm_handler_14)(int); //SIGALRM
void (*old_kill_handler_15)(int); //SIGTERM
void signal_SIGKILL_handler( int SIG ){
if( Kernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
void myInterrupt4(void){
//LOG("HW_SIGNAL_PIO4");
Kernel->armStatusChanged();
};
int main (int argc, char *argv[]){
MySQL_Connector * DBC = NULL;
basicSettingsProvider * SETTINGS = NULL;
bool WBG; // Working Background
bool SSE; // Server Statistics Engine
bool NDC; // No Default Configuration
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
objectFileLoggingService * FLE = NULL;
objectConsoleLoggingService * CLE = NULL;
// default init
WBG = true;
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
SSE = true;
NDC = true;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
m_pLog = basicLogCollection::getInstance();
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems R-Goose Server\n");
printf( "Software version <%s>\n", VERSION_NUMBER );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
CLE = new objectConsoleLoggingService();
if( CLE != NULL ) {
m_pLog->addHandler( CLE );
};
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
if( DCF_NAME != NULL ) {
sprintf( DCF_NAME, "%s", argv[i+1] );
} else {
printf("ERROR!\n\n");
return -1;
};
break;
};
};
break;
};
};
};
};
FLE = new objectFileLoggingService( FLE_NAME );
if( FLE != NULL ) {
m_pLog->addHandler( FLE );
};
LOG("Starting Log Engne!");
if ( fileExist( DCF_NAME ) ){
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
} else {
SETTINGS = basicSettingsProvider::getInstance();
};
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. %s\n", VERSION_NUMBER );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
if( wiringPiSetup() == -1 ){
LOG_ERROR("WiringPI Init failure!");
char tBuffer[256];
sprintf( tBuffer, "Error code: %d", errno );
LOG_ERROR( tBuffer );
return -1;
} else {
#ifdef DEBUG
LOG("WiringPI Init OK");
#endif
//wiringPiSetupGpio();
pinMode( 4, INPUT ); // ARM BTN
pinMode( 21, OUTPUT ); // Reset ADNS
//pinMode( 10, OUTPUT ); // NCS ADNS
//pinMode( 30, OUTPUT );
};
// Starting Services^
uint8_t m_bKernelExitCode = 0;
do{
Kernel = new PF_Kernel();
if( Kernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( Kernel != NULL ){
LOG( "++++ Server Started ++++" );
if ( Kernel->create() == false ){
LOG_ERROR("Kernel create failure!");
} else {
//Instal HW ISR Listener
if( wiringPiISR( 4, INT_EDGE_RISING, &myInterrupt4 ) == -1 ){
LOG_ERROR("Can not setup ISR handler!");
char tBuffer[256];
sprintf( tBuffer, "Error code: %d", errno );
LOG_ERROR( tBuffer );
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_SIGKILL_handler );
old_kill_handler_9 = signal( 9, signal_SIGKILL_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
};
};
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
} while( m_bKernelExitCode > 0 );
//delete( NetworkManager );
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
if( FLE!= NULL ) delete( FLE );
if( CLE!= NULL ) delete( CLE );
delete( m_pLog );
return(0);
}

46
lib/App/Pathfinder/PathfinderBackend.h

@ -1,46 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: Argus project main header file
*
* AUTHOR: Gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#ifndef __ARGUS_BACKEND_MAIN_HEADER__
#define __ARGUS_BACKEND_MAIN_HEADER__
/** include files **/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMemoryOperation.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectConsoleLoggingService.h"
#include "Pathfinder_Kernel.h"
/** local definitions **/
//http://xmsecu.com:8080/ocx/NewActive.exe
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
#endif

769
lib/App/Pathfinder/Pathfinder_Kernel.cpp

@ -1,769 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel source
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#include "Pathfinder_Kernel.h"
#include <sys/types.h>
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
PF_Kernel::PF_Kernel( config_setting_t *Settings ):basicThread(){
m_bExitCause = 0;
m_bCreatedDBC = false;
m_pDBC = NULL;
m_pBNO = NULL;
m_pGPS = NULL;
m_pCamera = NULL;
m_pScanner = NULL;
m_tTimeTSeconds = time( NULL );
m_bArmed = ( bool ) digitalRead ( 4 );
m_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
m_pBLOG = objectPathfinderBinaryLog::getInstance();
m_bGPSis3D = false;
m_bStartMode = PF_START_ON_ALT;
m_bHWFlags = PF_HW_NONE;
m_bActive = false;
m_bForced = false;
};
PF_Kernel::~PF_Kernel(){
#ifdef DEBUG
LOG("Destructor");
#endif
WaitFinish(true);
#ifdef DEBUG
LOG("Deleting Components");
#endif
if( m_pGPS!= NULL ) delete( m_pGPS );
if( m_pBNO!= NULL ) delete( m_pBNO );
if( m_pCamera!= NULL ) delete( m_pCamera );
if( m_pScanner!= NULL ) delete( m_pScanner );
#ifdef DEBUG
LOG("Unregister Server DBC");
#endif
if( m_pDBC != NULL ) {
m_pDBC->unregisterServer();
if(m_bCreatedDBC) {
delete( m_pDBC );
};
};
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
#include <sys/types.h>
#include <ifaddrs.h>
bool PF_Kernel::create( void ){
char tBuffer[256];
if( m_pSettings != NULL ) {
config_setting_t * pSetting;
int tVal;
const char * tBuf;
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
LOG("Getting Settings ...");
/*if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
char * tTS;
tTS = getTStr(NULL);
tVar = MD5String(tTS);
free(tTS);
sprintf( m_sIdentity, tVar );
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
config_setting_set_string( pSetting, tVar );
free( tVar );
basicSettingsProvider::getInstance()->compromise();
LOG("Server Identity not defined - generating new!");
} else {
sprintf( m_sIdentity, tBuf );
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
LOG( tBuffer );
};
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
tVal = m_nSiteID = 1;
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
config_setting_set_int( pSetting, tVal );
basicSettingsProvider::getInstance()->compromise();
LOG("Site ID not defined - using [1] as number!");
} else {
m_nSiteID = tVal;
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
LOG( tBuffer );
};
*/
/*
#ifdef __EU_PROJECT__
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
tVal = m_bSafeShoreSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Safe-Shore support not defined");
} else {
m_bSafeShoreSupport = (bool)tVal;
sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
tVal = m_bDefenderSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Defender support not defined");
} else {
m_bDefenderSupport = (bool)tVal;
sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
*/
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
m_bCreatedDBC = false;
if( m_pDBC == NULL ) {
LOG("Explicitly Create DBC Object");
m_bCreatedDBC = true;
m_pDBC = new PATHFINDER_DBC( m_pSettings );
if( m_pDBC == NULL ){
LOG_ERROR("DBC Object Creation Failure!");
return false;
};
if( !m_pDBC->connect() ){
LOG_ERROR("DBC Connection Failure!");
SLEEP(5000);
//ToDO: Set Restart Kernel!
return false;
};
};
//char tBuffer[CTEXT];
struct ifaddrs * ifaddr = NULL;
struct ifaddrs * ifa;
/* Add Network Interfaces */
if( -1 == getifaddrs(&ifaddr)) {
LOG_ERROR("Cannot get Net Integfaces!");
m_pDBC->registerServer( "--NA--" );
} else {
bool regs = false;
for( ifa = ifaddr; ifa; ifa = ifa->ifa_next ) {
if (ifa->ifa_addr->sa_family != AF_INET) continue;
char ip[16];
struct sockaddr_in *inn;
unsigned char A,B,C,D;
inn = (struct sockaddr_in *)ifa->ifa_addr;
D = ( inn->sin_addr.s_addr >> 24) & 0xFF;
C = ( inn->sin_addr.s_addr >> 16) & 0xFF;
B = ( inn->sin_addr.s_addr >> 8) & 0xFF;
A = ( inn->sin_addr.s_addr >> 0) & 0xFF;
sprintf( ip, "%d.%d.%d.%d", A, B, C, D );
sprintf( tBuffer, "Network Interface: %s [%s]", ifa->ifa_name, ip );
if( strncmp( ifa->ifa_name,"eth", 3) == 0 ) {
regs = true;
m_pDBC->registerServer( ip );
};
LOG(tBuffer);
//m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_NETWORK, ifa->ifa_name, ip );
};
if(!regs) {
LOG_ERROR("Ethernet IP address Not Defined!");
m_pDBC->registerServer( "--NA--" );
};
freeifaddrs( ifaddr );
};
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
m_pDBC->clenupCommandQueue();
m_pDBC->setArmMode( m_bArmed );
m_pBLOG->attachDBC( m_pDBC );
#ifdef DEBUG
LOG("Init Optic Flow");
#endif
m_pFlow = new opticFlow( m_pSettings, m_pDBC );
if( m_pFlow != NULL ) {
if( !m_pFlow->create() ){
LOG_ERROR("FLOW Creation failure!");
} else {
m_bHWFlags |= PF_HW_OPF;
};
} else {
LOG_ERROR("FLOW Construction failure!");
};
#ifdef DEBUG
LOG("Init IMU");
#endif
m_pBNO = new sensorBNO( m_pSettings, m_pDBC );
if( m_pBNO != NULL ) {
if( !m_pBNO->create() ){
LOG_ERROR("BNO Creation failure!");
} else {
m_bHWFlags |= PF_HW_BNO;
};
} else {
LOG_ERROR("BNO Construction failure!");
};
#ifdef DEBUG
LOG("Init GPS");
#endif
m_pGPS = new sensorXA1110( m_pSettings, m_pDBC );
if( m_pGPS != NULL ) {
if( !m_pGPS->create() ){
LOG_ERROR("GPS Creation failure!");
} else {
m_bHWFlags |= PF_HW_GPS;
};
};
#ifdef DEBUG
LOG( "Start SSDP Beacon" );
#endif
if( m_pServiceAnnouncer != NULL ) {
if( !m_pServiceAnnouncer->init() ){
delete(m_pServiceAnnouncer);
m_pServiceAnnouncer = NULL;
};
};
#ifdef DEBUG
LOG("Init Camera");
#endif
m_pCamera = new gPhotoCamera( m_pSettings, m_pDBC );
if( m_pCamera != NULL ) {
if( !m_pCamera->create() ){
LOG_ERROR("Photo Creation failure!");
} else {
m_bHWFlags |= PF_HW_PHO;
};
};
#ifdef DEBUG
LOG("Init LRF Scanner");
#endif
m_pScanner = new LRF_techScanner( m_pSettings, m_pDBC );
if( m_pScanner != NULL ) {
if( !m_pScanner->create() ){
LOG_ERROR( "Error Create LRF Scanner!" );
} else {
m_bHWFlags |= PF_HW_LRF;
};
};
m_pDBC->updateHW_STATUS( m_bHWFlags );
if( ( m_bHWFlags & PF_HW_LRF ) == PF_HW_LRF ) {
uint8_t tStartModeLRF;
if( m_pDBC->getStartModeLRF( &tStartModeLRF )) {
if ( tStartModeLRF == PF_START_ON_PWR ) {
m_pScanner->startScan();
};
if( tStartModeLRF == PF_START_ON_ARM ) {
if( m_bArmed ) m_pScanner->startScan();
};
};
};
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
#endif
#ifdef DEBUG
//sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
//LOG( tBuffer );
#endif
return true;
};
void PF_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
LOG( "Thread is Detached" );
#endif
};
/* Main Kernel Thread Procedure */
void PF_Kernel::m_fThreadProc( void ){
char Buffer[CTEXT];
time_t tTimeTSeconds;
int lastTSS = 0;
int lastTMS = 0;
DB_COMMAND * tCMD;
char pidBuf[16];
pid_t pid = gettid();
sprintf(pidBuf,"pid:%d", pid);
LOG(pidBuf);
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
// Command Processing Loop
tCMD = m_pDBC->fetchCommand();
if( tCMD != NULL ){
switch( tCMD->cmd ) {
case PF_CMD_START_SCANER:{
LOG("KK - Start Scanner");
if( m_pScanner!= NULL ) {
m_pScanner->startScan();
};
break;
};
case PF_CMD_RESET_SCANER:{
LOG("KK - Reset Scanner");
if( m_pScanner!= NULL ) {
m_pScanner->resetDevice();
};
break;
};
case PF_CMD_STOP_SCANER:{
LOG("KK - Stop Scanner");
if( m_pScanner!= NULL ) {
m_pScanner->stopScan();
};
break;
};
case PF_CMD_SHOT_CAMERA:{
LOG("KK - Shot");
if( m_pCamera!= NULL ) {
m_pCamera->makeShot();
};
break;
};
case PF_CMD_START_BURST_CAMERA:{
LOG("KK - Burst Start");
if( m_pCamera!= NULL ) {
m_pCamera->startBurst();
};
break;
};
case PF_CMD_STOP_BURST_CAMERA:{
LOG("KK - Burst Stop");
if( m_pCamera!= NULL ) {
m_pCamera->stopBurst();
};
break;
};
case PF_CMD_SWITCH_CAMERA:{
LOG("KK - Switch Camera");
if( m_pCamera!= NULL ) {
m_pCamera->switchToCamera();
};
break;
};
case PF_CMD_SWITCH_STORAGE:{
LOG("KK - Switch Storage");
if( m_pCamera!= NULL ) {
m_pCamera->switchToStorage();
};
break;
};
case PF_CMD_PREV_CAMERA:{
LOG("KK - Switch Preview");
if( m_pCamera!= NULL ) {
m_pCamera->startPreview();
};
break;
};
case PF_CMD_UPDATE_IMU:{
LOG("KK - Update IMU");
if( m_pBNO!= NULL ) {
if( !m_pBNO->updateSettings() ) LOG_ERROR("Failure IMU Settings Update");
};
break;
};
case PF_CMD_START_PROCESS:{
LOG("KK - Start Log");
m_bForced = true;
startDataAsqusition();
break;
};
case PF_CMD_STOP_PROCESS:{
LOG("KK - Stop Log");
stopDataAsqusition();
break;
};
case PF_CMD_SET_CURRENT_ALT:{
if( m_pGPS ) {
m_fGSAlt = m_pGPS->getCurrentAlt();
if( m_pDBC != NULL ) {
m_pDBC->updateGS_ALT( m_fGSAlt );
};
};
break;
};
case PF_CMD_OFSENSOR_SET_CAM:{
LOG("KK - Set OF Cam");
if( m_pFlow ) {
m_pFlow->setMode( OF_WM_PICTURES );
};
break;
};
case PF_CMD_OFSENSOR_SET_OF:{
LOG("KK - Set OF OF");
if( m_pFlow ) {
m_pFlow->setMode( OF_WM_MOVEMENT );
};
break;
};
case PF_CMD_DELETE_CAM_PHOTOS:{
LOG("KK - Delete Photos");
if( m_pCamera ) {
m_pCamera->deleteAllPictures();
};
break;
};
case PF_CMD_DELETE_DATA_FILE:{
LOG("KK - Delete Data File");
if( m_pBLOG ) {
if( m_pBLOG->deleteDataFile( tCMD->param ) ){
if( m_pDBC ) {
m_pDBC->deleteDataRecord( tCMD->param );
};
};
};
break;
};
};
m_pDBC->finishCommand( tCMD->id );
free( tCMD );
tCMD = NULL;
};
if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
tTimeTSeconds = m_tTimeTSeconds;
if( m_bHWFlags != PF_HW_ALL ) {
if( ( m_bHWFlags & PF_HW_GPS ) != PF_HW_GPS ) {
if( m_pGPS ) {
delete( m_pGPS );
m_pGPS = NULL;
};
m_pGPS = new sensorXA1110( m_pSettings, m_pDBC );
if( m_pGPS != NULL ) {
if( !m_pGPS->create() ){
LOG_ERROR("GPS ReCreation failure!");
} else {
m_bHWFlags |= PF_HW_GPS;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
} else {
LOG_ERROR("GPS ReConstruction failure!");
};
};
if( ( m_bHWFlags & PF_HW_BNO ) != PF_HW_BNO ) {
if( m_pBNO ) {
delete( m_pBNO );
m_pBNO = NULL;
};
m_pBNO = new sensorBNO( m_pSettings, m_pDBC );
if( m_pBNO != NULL ) {
if( !m_pBNO->create() ){
LOG_ERROR("BNO ReCreation failure!");
} else {
m_bHWFlags |= PF_HW_BNO;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
} else {
LOG_ERROR("BNO ReConstruction failure!");
};
};
if( ( m_bHWFlags & PF_HW_OPF ) != PF_HW_OPF ) {
if( m_pFlow ) {
delete( m_pFlow );
m_pFlow = NULL;
};
m_pFlow = new opticFlow( m_pSettings, m_pDBC );
if( m_pFlow != NULL ) {
if( !m_pFlow->create() ){
LOG_ERROR("FLOW ReCreation failure!");
} else {
m_bHWFlags |= PF_HW_OPF;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
} else {
LOG_ERROR("FLOW ReConstruction failure!");
};
};
if( ( m_bHWFlags & PF_HW_LRF ) != PF_HW_LRF ) {
if( m_pScanner ) {
delete( m_pScanner );
m_pScanner = NULL;
};
m_pScanner = new LRF_techScanner( m_pSettings, m_pDBC );
if( m_pScanner != NULL ) {
if( !m_pScanner->create() ){
LOG_ERROR( "Error ReCreate LRF Scanner!" );
} else {
m_bHWFlags |= PF_HW_LRF;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
} else {
LOG_ERROR("LRF ReConstruction failure!");
};
};
} else {
if( m_pGPS->isDead() ) {
m_bHWFlags &= ~PF_HW_GPS;
delete( m_pGPS );
m_pGPS = NULL;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
if( m_pBNO->isDead() ) {
m_bHWFlags &= ~PF_HW_BNO;
delete( m_pBNO );
m_pBNO = NULL;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
if( m_pFlow->isDead() ) {
m_bHWFlags &= ~PF_HW_OPF;
delete( m_pFlow );
m_pFlow = NULL;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
if( m_pScanner->isDead() ) {
m_bHWFlags &= ~PF_HW_LRF;
delete( m_pScanner );
m_pScanner = NULL;
m_pDBC->updateHW_STATUS( m_bHWFlags );
};
};
if( !m_bGPSis3D ) {
if( m_pGPS != NULL ) {
if( m_pGPS->getCurrentFixType() == PF_GPS_FIX_3D ) {
m_bGPSis3D = true;
m_fGSAlt = m_pGPS->getCurrentAlt();
if( m_pDBC != NULL ) {
m_pDBC->updateGS_ALT( m_fGSAlt );
};
};
};
};
if( !m_bActive ) {
// Entering Active Mode
switch( m_bStartMode ){
case PF_START_ON_ALT:{
float tAlt;
if( !m_bArmed ) break;
if( !m_bGPSis3D ) break;
if( m_pBLOG == NULL ) break;
tAlt = m_pGPS->getCurrentAlt();
if( tAlt > m_fGSAlt ) {
// Start Scan
if( m_pFlow != NULL ) {
m_pFlow->setMode( OF_WM_MOVEMENT );
};
startDataAsqusition();
};
break;
};
case PF_START_ON_ARM:{
if( !m_bArmed ) break;
if( m_pBLOG == NULL ) break;
// Start Scan
if( m_pFlow != NULL ) {
m_pFlow->setMode( OF_WM_MOVEMENT );
};
startDataAsqusition();
break;
};
};
} else {
if( !m_bForced && m_bActive ) {
// Exit Active Mode
switch( m_bStartMode ){
case PF_START_ON_ALT:{
float tAlt;
if( !m_bArmed || !m_bGPSis3D ){
// Stop Scan
stopDataAsqusition();
} else {
tAlt = m_pGPS->getCurrentAlt();
if( tAlt < ( m_fGSAlt / 2.f ) ) {
// Stop Scan
stopDataAsqusition();
};
}
break;
};
case PF_START_ON_ARM:{
if( m_bArmed ) break;
// Stop Scan
stopDataAsqusition();
break;
};
};
}
};
};
SLEEP( SLEEP_KERNEL_INTERVAL );
};
};
bool PF_Kernel::setStatus( int A ){
m_bThreadStatus = (thredStatus)A;
return true;
};
bool PF_Kernel::signalEvent( void ){
//if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
//};
return true;
};
void PF_Kernel::armStatusChanged( void ){
int tPinVal = digitalRead ( 4 );
if( tPinVal == 1 && !m_bArmed ) {
LOG("!!!!!!!ARMED!!!!!!!");
m_bArmed = true;
} else {
if( tPinVal == 0 && m_bArmed ) {
LOG("!!!!!DISARMED!!!!!!");
m_bArmed = false;
};
};
if( m_pDBC == NULL ) return;
m_pDBC->setArmMode( m_bArmed );
if( ( m_bHWFlags & PF_HW_LRF ) == PF_HW_LRF ) {
uint8_t tStartModeLRF;
if( m_pDBC->getStartModeLRF( &tStartModeLRF )) {
if( tStartModeLRF == PF_START_ON_ARM ) {
if( m_bArmed ) {
m_pScanner->startScan();
} else {
if( !m_bActive ) m_pScanner->stopScan();
};
};
};
};
};
void PF_Kernel::startDataAsqusition( void ){
LOG("Start Data");
if( m_pDBC == NULL ) return;
if( m_pBLOG == NULL ) return;
if( m_pBLOG->activate() ) {
m_pDBC->setAsqusitionMode( 1 );
if( m_pCamera!= NULL ) {
m_pCamera->switchToCamera();
m_pCamera->startBurst();
};
if( m_pFlow!= NULL ) {
m_pFlow->setMode( OF_WM_MOVEMENT );
};
if( m_pScanner != NULL ) {
m_pScanner->startScan();
};
m_bActive = true;
};
};
void PF_Kernel::stopDataAsqusition( void ){
LOG("Stop Data");
if( m_pDBC == NULL ) return;
if( m_pBLOG == NULL ) return;
if( m_pBLOG->finish() ) {
if( m_pCamera != NULL ) m_pCamera->switchToStorage();
if( m_pScanner != NULL ){
uint8_t tStartModeLRF;
if( m_pDBC->getStartModeLRF( &tStartModeLRF )) {
if( tStartModeLRF == PF_START_ON_ARM ) {
if( !m_bArmed ) m_pScanner->stopScan();
} else {
m_pScanner->stopScan();
};
} else {
m_pScanner->stopScan();
};
};
if( m_pDBC != NULL ) m_pDBC->setAsqusitionMode( 0 );
m_bForced = false;
m_bActive = false;
};
};
#undef LOG
#undef LOG_ERROR

157
lib/App/Pathfinder/Pathfinder_Kernel.h

@ -1,157 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: Pathfinder Kernel Header File
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:1/20/2020
*
*******************************************************************/
#ifndef __ARGUS_KERNEL_HEADER__
#define __ARGUS_KERNEL_HEADER__
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> /* getopt_long() */
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/types.h>
struct serial_struct {
int type;
int line;
unsigned int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char io_type;
char reserved_char[1];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
unsigned char * iomem_base;
unsigned short iomem_reg_shift;
unsigned int port_high;
unsigned long iomap_base; /* cookie passed into ioremap */
};
#include "../../alg/generic/md5.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/object/objectPathfinderBinaryLog.h"
#include "../../data/ponvif/ponvif.h"
#include "../../data/protocol/onvifMediaObserver.h"
#include "../../data/ssdp/ssdpAnnouncer.h"
#include "../../components/base/basicEventHeap.h"
#include "../../data/net/netServer.h"
#include "../../pathfinder/pathfinderDBConnector.h"
#include "../../hardware/sensors/9dof/BNO055.h"
#include "../../hardware/sensors/gps/XA1110_I2C.h"
#include "../../hardware/sensors/gphoto/gPhotoCamera.h"
#include "../../hardware/sensors/optic_flow/adns3080/opticFlowADNS.h"
#include "../../hardware/sensors/lrf/lrfScanner.h"
#include <wiringPi.h>
#define SLEEP_KERNEL_INTERVAL 10
#define ONVIF_DISCOVERY_INTERVAL 300 // 5 min
#define ONVIF_DISCOVERY_RESULT_TIME 5
typedef enum E_PF_COMMANDS{
PF_CMD_ARM_APPLICATION = 1,
PF_CMD_DISARM_APPLICATION = 2,
PF_CMD_OFSENSOR_SET_CAM = 3,
PF_CMD_OFSENSOR_SET_OF = 4,
PF_CMD_START_SCANER = 10,
PF_CMD_RESET_SCANER = 13,
PF_CMD_STOP_SCANER = 15,
PF_CMD_SHOT_CAMERA = 22,
PF_CMD_START_BURST_CAMERA = 23,
PF_CMD_STOP_BURST_CAMERA = 24,
PF_CMD_SWITCH_CAMERA = 25,
PF_CMD_SWITCH_STORAGE = 26,
PF_CMD_PREV_CAMERA = 27,
PF_CMD_UPDATE_IMU = 28,
PF_CMD_START_PROCESS = 29,
PF_CMD_STOP_PROCESS = 30,
PF_CMD_SET_CURRENT_ALT = 31,
PF_CMD_DELETE_CAM_PHOTOS = 32,
PF_CMD_DELETE_DATA_FILE = 33
} PF_COMMANDS;
#define PF_HW_NONE 0
#define PF_HW_GPS 1
#define PF_HW_BNO 2
#define PF_HW_OPF 4
#define PF_HW_LRF 8
#define PF_HW_PHO 16
#define PF_HW_ALL 31
class PF_Kernel: public basicThread {
private:
time_t m_tTimeTSeconds;
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
ssdpAnnouncer * m_pServiceAnnouncer;
uint8_t m_bExitCause;
bool m_bCreatedDBC;
uint8_t m_bStartMode;
uint8_t m_bHWFlags;
float m_fStartAlt;
float m_fGSAlt;
bool m_bGPSis3D;
PATHFINDER_DBC * m_pDBC;
objectPathfinderBinaryLog * m_pBLOG;
/* Sensors and Devices */
sensorBNO * m_pBNO;
sensorXA1110 * m_pGPS;
LRF_techScanner * m_pScanner;
gPhotoCamera * m_pCamera;
opticFlow * m_pFlow;
/* Flags */
bool m_bArmed;
bool m_bForced;
bool m_bActive;
protected:
void m_fThreadProc( void );
void startDataAsqusition( void );
void stopDataAsqusition( void );
public:
// Constructor
explicit PF_Kernel( config_setting_t *Settings = NULL );
// Destructor
virtual ~PF_Kernel();
bool create( void );
bool signalEvent( void );
void WaitFinish( bool Force = false );
bool setStatus( int );
uint8_t getExitCause( void ){ return m_bExitCause;};
void armStatusChanged(void);
};
#endif

127
lib/App/QTPro3DGUI/main.cpp

@ -1,127 +0,0 @@
#include <stdio.h>
#ifdef _NO_STDIO_IOB_FUNC_
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }
#endif
#include "mainwindow.h"
#include <QApplication>
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "../../data/media/mediaVideoSourceManager.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectSystemAnchor.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../data/net/onvifDeviceNode.h"
#include "../../components/object/objectEventReport.h"
#define LOG(X) mpLog->Log( "Main", NULL, X )
#define LOG_DEBUG( X ) mpLog->Log( "Main", NULL, _LOG_DEBUG, X )
#define LOG_ERROR( X ) mpLog->Log( "Main", NULL, _LOG_ERROR, X )
int main(int argc, char *argv[]){
QApplication a(argc, argv);
systemAnchor *ANCH;
ANCH = systemAnchor::getInstance();
basicLogCollection *mpLog = basicLogCollection::getInstance();
objectFileLoggingService *fLog;
char tPath[1024];
char *ttPtz=NULL;
//ttPtz = (char *)GUI->getApp()->applicationDirPath().toStdString().c_str();
if( ttPtz!= NULL ){
sprintf(tPath, "%s/my.log", ttPtz);
} else {
sprintf(tPath, "my.log" );
};
fLog = new objectFileLoggingService(tPath);
mpLog->addHandler((basicLoggingService *)fLog);
printf("From now - refer to log file\n");
LOG_DEBUG("ENTER APPLICATION");
basicSettingsProvider *mpSettingsProvider = basicSettingsProvider::getInstance();
basicEventHeap *mpEventHeap = basicEventHeap::getInstance();
mediaVideoSourceManager *LS = mediaVideoSourceManager::getInstance();
//sprintf(tPath, "%s/data/storage", a.applicationDirPath().toStdString().c_str());
sprintf(tPath, "data/storage");
//ToDO: Check Report Object!
objectEventReport *mpReporter = objectEventReport::getInstance();
storageProvider *mpStorPro = storageProvider::getInstance(tPath);
config_setting_t *mpSettings;
//mpStorPro->startNewSeries(); // Each prog start starts new Series
#ifdef __linux__
LOG_DEBUG("SS Disabled");
#else
//UINT lActiveFlag = 0;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, NULL, NULL);
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
UINT timeoutLowPower;
UINT timeoutPowerOff;
UINT timeoutScreenSave;
{
SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0, &(timeoutLowPower), 0);
SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, &(timeoutPowerOff), 0);
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &(timeoutScreenSave), 0);
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
}
LOG_DEBUG("SS Disabled");
#endif
mpSettings = mpSettingsProvider->getSubNode(NULL, "APPLICATION_GUI");
MainWindow *window;
window = new MainWindow();// mainWinow::getInstance();
//Check Startup Mode
int gAppStartupMode;
config_setting_t *pSetting;
if (!config_setting_lookup_int(mpSettings, "STARTUP_WINDOW_MODE", &gAppStartupMode )){
gAppStartupMode = 0;
pSetting = config_setting_add(mpSettings, "STARTUP_WINDOW_MODE", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
};
switch( gAppStartupMode ){
case 0: window->show(); break;
case 1: window->showMaximized(); break;
case 2: window->showFullScreen(); break;
default:
gAppStartupMode = 0;
pSetting = config_setting_lookup(mpSettings, "STARTUP_WINDOW_MODE");
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
window->showMaximized();
};
joysticObject::getInstance();
//delete GUI;
a.exec();
delete window;
delete LS;
delete mpEventHeap;
delete mpSettingsProvider;
#ifdef __linux__
LOG_DEBUG("SS Enabled");
#else
{
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, timeoutLowPower, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, timeoutPowerOff, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, timeoutScreenSave, NULL, 0);
}
LOG_DEBUG("SS Enabled");
//lActiveFlag = 1;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0);
//lActiveFlag = 20;
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
//LOG_DEBUG("SS Enabled");
#endif
LOG_DEBUG("EXIT APPLICATION");
delete mpLog;
}
#undef LOG
#undef LOG_DEBUG
#undef LOG_ERROR

198
lib/App/QTPro3DGUI/mainwindow.cpp

@ -1,198 +0,0 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow){
m_bUserRecordsVideo = false;
ui->setupUi(this);
ui->m_pMainVideoWidget->init();
ui->m_pMainVideoWidget->setError( true, "No Source Choisen" );
ui->m_pScrollAreaWidgetContents->setMainMediaViewer( ui->m_pMainVideoWidget );
m_pReportManager = NULL;
//ui->m_pDevScrollAreaWidgetContents->setSelectedDevice(0);
}
MainWindow::~MainWindow(){
delete ui;
}
RangeMapWidget *MainWindow::getRangeMap( void ){
return ui->m_pRangeMap;
}
RadarMapWidget *MainWindow::getRadarMap( void ){
return ui->m_pRangeRadar;
}
GLRadar *MainWindow::getGLRadar( void ){
return ui->m_pGLRadar;
}
void MainWindow::callbackSettings(void){
//if (m_pDeviceSettings == NULL){
// m_pDeviceSettings = new DialogSettingsLGS(this);
// m_pDeviceSettings->attachMasterDevice( m_pMasterDevice );
// m_pDeviceSettings->attachSlaveDevice( m_pSlaveDevice );
//};
//m_pDeviceSettings->updateValues();
//m_pDeviceSettings->show();
}
//void MainWindow::handleScreenShotPress(){
//QString fileName;
//fileName = QFileDialog::getOpenFileName(this, "Open Data", "data/", "Data Files (*.raw *.jpg *.bmp)");
//char fName[MAX_PATH];
//sprintf(fName, "%s", fileName.toStdString().c_str() );
//m_pRangeMap->loadFromFile(fName);
//m_pGLRadar->loadFromFile(fName);
//}
void MainWindow::handleSave3DPicture( void ){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save 3D Picture As", "data/", "Picture Files (*.png)");
QPixmap image = QPixmap::grabWidget(m_pGLRadar);
if(!image.save(fileName, "PNG")){
QMessageBox::warning(this, "Save Image", "Error saving image.");
};
}
void MainWindow::handleAddMask(){
if( m_pRangeMap!= NULL ){
m_pRangeMap->setAddMaskMode();
};
}
void MainWindow::handleDeleteMask(){
if (m_pRangeMap != NULL){
m_pRangeMap->setDeleteMaskMode();
};
}
void MainWindow::handleSilencePress(){
basicEvent *pEvt;
basicCameraCommand *tData;
absCameraMoveParam *tParam;
tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
if (tData != NULL) {
tParam = (absCameraMoveParam*)malloc(sizeof(absCameraMoveParam));
if (tParam != NULL) {
tData->m_cCode = CMD_CAMERA_SET_PTZ;
tData->m_pParam = tParam;
tParam->m_fPan = 180.f;
tParam->m_fTilt = 0.f;
tParam->m_fRange = 1.f;
pEvt = createBasicEvent(0, EVT_CLASS_IMAGE, EVT_COMMAND, "Test Event", tData);
basicEventHeap::getInstance()->broadcast(pEvt);
};
};
}
void MainWindow::handleVideoRecorder(){
basicEvent *pEvt;
basicCameraCommand *tData;
tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
tData->m_pParam = NULL;
if(!m_bUserRecordsVideo){
// Generate Video Event -> Starts Record
tData->m_cCode = CMD_CAMERA_START_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "User Starts Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = true;
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.control.stop.png"));
m_pButtonCmdVideoRecord->setText(QStringLiteral("Stop Record"));
} else {
tData->m_cCode = CMD_CAMERA_STOP_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "User Stops Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = false;
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
};
}
void MainWindow::handleReports(){
//if (m_pReportManager == NULL ){
// m_pReportManager = new guiReportsManagerWindow((QDialog *)this);
//};
//m_pReportManager->showMaximized();
}
void MainWindow::on_m_pButtonCmdClear_clicked()
{
m_pEventsList->clear();
m_pGLRadar->clearTargets();
m_pRangeRadar->clearTargets();
m_pRangeMap->clearTargets();
m_pTitleWidget->setStatus( TSW_ARMING );
}
void MainWindow::on_m_pButton5_clicked(bool checked)
{
if(!checked){
m_pButton5->setChecked(true);
m_pButton6->setChecked(false);
m_pRangeMap->setMinimums();
m_pRangeRadar->setMinimums();
}
}
void MainWindow::on_m_pButton6_clicked(bool checked)
{
if(!checked){
m_pButton5->setChecked(false);
m_pButton6->setChecked(true);
m_pRangeMap->setMaximums();
m_pRangeRadar->setMaximums();
}
}
void MainWindow::on_pushButton_3_clicked()
{
m_pRangeMap->startGenerateWS();
}
void MainWindow::on_pushButton_4_clicked()
{
QString fileName;
fileName = QFileDialog::getSaveFileName(this, tr("Save 2D Map As"), "/", tr("Picture Files (*.png *.jpg *.bmp)"));
if( !fileName.isEmpty() ){
m_pRangeMap->savePicture(fileName);
} else {
};
}
void MainWindow::on_m_pButtonCmdVideoRecord_clicked()
{
basicEvent *pEvt;
basicCameraCommand *tData;
tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
tData->m_pParam = NULL;
if(!m_bUserRecordsVideo){
// Generate Video Event -> Starts Record
tData->m_cCode = CMD_CAMERA_START_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_VIDEO, EVT_COMMAND, "User Starts Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = true;
ui->m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.control.stop.png"));
ui->m_pButtonCmdVideoRecord->setText(QStringLiteral("Stop Record"));
} else {
tData->m_cCode = CMD_CAMERA_STOP_RECORD;
pEvt = createBasicEvent( 0, EVT_CLASS_VIDEO, EVT_COMMAND, "User Stops Record Video", tData );
basicEventHeap::getInstance()->broadcast(pEvt);
m_bUserRecordsVideo = false;
ui->m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
ui->m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
};
}
void MainWindow::on_m_pButtonCmdReport_clicked()
{
if(m_pReportManager==NULL){
m_pReportManager = new guiReportsManagerDialog(this);
};
m_pReportManager->show();
}

92
lib/App/QTPro3DGUI/mainwindow.h

@ -1,92 +0,0 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "../../components/base/basicSettingsProvider.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../gui/controls/VideoWidget.h"
#include "../../gui/controls/OpenGLWidget.h"
#include "../../gui/controls/OGLRadarWidget.h"
#include "../../gui/controls/RangeMapWidget.h"
#include "../../gui/controls/RadarMapWidget.h"
#include "../../gui/controls/VideoSourceChooser.h"
#include "../../gui/controls/DeviceChooser.h"
#include "../../gui/controls/TimeShowWidget.h"
#include "../../gui/controls/EventViewWidget.h"
#include "../../gui/dialogs/ReportsManagerDialog.h"
#include "../../gui/controls/mapControl/QMapControl"
#include "../../gui/controls/mapControl/openaerialmapadapter.h"
#include "../../components/object/objectLGS.h"
#include "../../components/object/objectEventReport.h"
#include "../../hardware/stick/joystick.h"
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow{
Q_OBJECT
private:
config_setting_t *m_pSettings;
/* Main Widget */
joysticObject *m_pJoyStick;
/* Widgets */
TimeShowWidget *m_pTitleWidget;
EventViewerList *m_pEventsList;
DeviceChooser *m_pDevScrollAreaWidgetContents;
VideoSourceChooser *m_pScrollAreaWidgetContents;
VideoWidget *m_pMainVideoWidget;
guiReportsManagerDialog *m_pReportManager;
objectEventReport *m_pReportCreator;
RangeMapWidget *m_pRangeMap;
RadarMapWidget *m_pRangeRadar;
GLRadar *m_pGLRadar;
bool m_bUserRecordsVideo;
QPushButton *m_pButtonCmdVideoRecord;
QPushButton *m_pButton5;
QPushButton *m_pButton6;
private slots:
void handleSilencePress();
//void handleScreenShotPress();
//void handleButton2Press();
//void handleMaximumsPress();
//void handleMinimumsPress();
//void handleGenerateWS();
//void handleSave2DPicture();
void handleSave3DPicture();
void handleAddMask();
void handleDeleteMask();
//void handleUpdateMask();
//void handleSetStatusMask();
void handleVideoRecorder();
void handleReports();
void on_m_pButtonCmdClear_clicked();
void on_m_pButton5_clicked(bool checked);
void on_m_pButton6_clicked(bool checked);
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
void on_m_pButtonCmdVideoRecord_clicked();
void on_m_pButtonCmdReport_clicked();
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
RangeMapWidget * getRangeMap( void );
RadarMapWidget * getRadarMap( void );
GLRadar * getGLRadar( void );
private:
Ui::MainWindow *ui;
public slots:
void callbackSettings(void);
//void callbackClear(void);
//void changeEvent(QEvent *event);
};
#endif // MAINWINDOW_H

609
lib/App/QTPro3DGUI/mainwindow.ui

@ -1,609 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1206</width>
<height>710</height>
</rect>
</property>
<property name="windowTitle">
<string>3DSingleIPI</string>
</property>
<property name="windowIcon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/logo-40.png</normaloff>:/pictures/logo-40.png</iconset>
</property>
<widget class="QWidget" name="m_pMainWidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="TimeShowWidget" name="m_pTitleWidget" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="RangeMapWidget" name="m_pRangeMap" native="true"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="m_pButton5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Show Minimums</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.arrow.collapsed.png</normaloff>:/pictures/appbar.arrow.collapsed.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="m_pButton6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Show Maximums</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.arrow.expand.png</normaloff>:/pictures/appbar.arrow.expand.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="pushButton_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Test Working TH</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.alien.png</normaloff>:/pictures/appbar.alien.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="pushButton_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>PushButton</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.camera.png</normaloff>:/pictures/appbar.camera.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdClear">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Clear Events Log</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.new.png</normaloff>:/pictures/appbar.new.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdReset">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Reset Detection</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.transform.rotate.clockwise.png</normaloff>:/pictures/appbar.transform.rotate.clockwise.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdSilence">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Silence Alarm</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.sound.0.png</normaloff>:/pictures/appbar.sound.0.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdReport">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Report</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.cabinet.files.variant.png</normaloff>:/pictures/appbar.cabinet.files.variant.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdExit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Exit</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.power.png</normaloff>:/pictures/appbar.power.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="m_pButtonCmdSettings">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>220</width>
<height>54</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">Text-align:left;font: 12pt</string>
</property>
<property name="text">
<string>Settings</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.cog.png</normaloff>:/pictures/appbar.cog.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Events Log</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="EventViewerList" name="m_pEventsList"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Video Survilence</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="VideoWidget" name="m_pMainVideoWidget" native="true"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="VideoSourceChooser" name="m_pScrollAreaWidgetContents" native="true"/>
</item>
<item>
<widget class="QPushButton" name="m_pButtonCmdVideoRecord">
<property name="text">
<string>Start Record</string>
</property>
<property name="icon">
<iconset resource="../../resources/3dGui/resources/pictures/resources.qrc">
<normaloff>:/pictures/appbar.cabinet.in.png</normaloff>:/pictures/appbar.cabinet.in.png</iconset>
</property>
<property name="iconSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Devices</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="DeviceChooser" name="m_pDevScrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1162</width>
<height>189</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>3D View</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="GLRadar" name="m_pGLRadar"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>2D View</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="RadarMapWidget" name="m_pRangeRadar" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>TimeShowWidget</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/TimeShowWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>EventViewerList</class>
<extends>QListView</extends>
<header>../../lib/gui/controls/EventViewWidget.h</header>
</customwidget>
<customwidget>
<class>RangeMapWidget</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/RangeMapWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>VideoWidget</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/VideoWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>VideoSourceChooser</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/VideoSourceChooser.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>RadarMapWidget</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/RadarMapWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLRadar</class>
<extends>QOpenGLWidget</extends>
<header>../../lib/gui/controls/OGLRadarWidget.h</header>
</customwidget>
<customwidget>
<class>DeviceChooser</class>
<extends>QWidget</extends>
<header>../../lib/gui/controls/DeviceChooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../resources/3dGui/resources/pictures/resources.qrc"/>
</resources>
<connections>
<connection>
<sender>m_pButtonCmdExit</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>1084</x>
<y>293</y>
</hint>
<hint type="destinationlabel">
<x>602</x>
<y>354</y>
</hint>
</hints>
</connection>
</connections>
</ui>

286
lib/App/argus/ArgusBackend.cpp

@ -1,286 +0,0 @@
#include "ArgusBackend.h"
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
argusKernel * Kernel = NULL;
basicLogCollection * m_pLog = NULL;
networkServer * NetworkManager = NULL;
void (*old_update_handler_2)(int); //SIGINT
void (*old_kill_handler_3)(int); //SIGQUIT
void (*old_kill_handler_9)(int); //SIGKILL
void (*old_alarm_handler_14)(int); //SIGALRM
void (*old_kill_handler_15)(int); //SIGTERM
void signal_SIGKILL_handler( int SIG ){
if( Kernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
//#include <sys/resource.h>
int main (int argc, char *argv[]){
/*
const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0){
printf( "Stack Size: %d\n", rl.rlim_cur );
if ( rl.rlim_cur < kStackSize ){
printf( "Resize Stack to: %d\n", kStackSize );
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0){
fprintf(stderr, "setrlimit returned result = %d\n", result);
return -1;
};
};
};
*/
MySQL_Connector * DBC = NULL;
basicSettingsProvider * SETTINGS = NULL;
bool WBG = true; // Working Background
bool SSE = true; // Server Statistics Engine
bool NDC = true; // No Default Configuration
bool COLD_START = true;
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
objectFileLoggingService * FLE = NULL;
objectConsoleLoggingService * CLE = NULL;
// default init
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
m_pLog = basicLogCollection::getInstance( _LOG_LVL_TIME_PTR );
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems R-Goose Server\n");
printf( "Software version <%s>\n", ARGUS_BUILD_STRING );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
CLE = new objectConsoleLoggingService();
if( CLE != NULL ) {
m_pLog->addHandler( CLE );
};
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
if( DCF_NAME != NULL ) {
sprintf( DCF_NAME, "%s", argv[i+1] );
} else {
printf("ERROR!\n\n");
return -1;
};
break;
};
};
break;
};
};
};
};
FLE = new objectFileLoggingService( FLE_NAME );
if( FLE != NULL ) {
m_pLog->addHandler( FLE );
};
LOG("Starting Log Engne!");
if ( fileExist( DCF_NAME ) ){
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
} else {
SETTINGS = basicSettingsProvider::getInstance();
};
if ( fileExist( gsCFG_PID_FILE ) ){
COLD_START = false;
//check if process already running
FILE *tFD = fopen( gsCFG_PID_FILE, "r" );
if( tFD ) {
pid_t pid;
char tBuff[256];
//fscanf( tFD, "%d\n", pid );
fread( tBuff, 1, 255, tFD );
pid = atoi( tBuff );
printf("Old Process PID: %d\n", pid );
if( kill( pid, 0 )==0 ){
printf("Process Already Running --> exiting!\n");
delete( FLE );
fclose( tFD );
exit(12);
} else {
printf("No Running Process --> Hot Restart Detected!\n");
};
fclose( tFD );
};
};
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. <%s>\n", ARGUS_BUILD_STRING );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
uint8_t m_bKernelExitCode = 0;
do{
Kernel = argusKernel::getInstance( COLD_START );
if( Kernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( Kernel != NULL ){
LOG( "++++ Server Started ++++" );
if ( Kernel->create() == false ){
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( SIGTERM /* 15 */, signal_SIGKILL_handler );
old_kill_handler_9 = signal( SIGKILL /* 9 */, signal_SIGKILL_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
};
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
} while( m_bKernelExitCode > 0 );
delete( NetworkManager );
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
if( FLE!= NULL ) delete( FLE );
if( CLE!= NULL ) delete( CLE );
delete( m_pLog );
return(0);
}

50
lib/App/argus/ArgusBackend.h

@ -1,50 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: Argus project main header file
*
* AUTHOR: Gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#ifndef __ARGUS_BACKEND_MAIN_HEADER__
#define __ARGUS_BACKEND_MAIN_HEADER__
/** include files **/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMemoryOperation.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectConsoleLoggingService.h"
#include "../../data/net/netServer.h"
//#include "../../data/ponvif/ponvif.h"
//#include "../../data/protocol/onvifMediaObserver.h"
#include "../../data/mysql/database_class.h"
#include "../../rgoose/rgooseKernel.h"
/** local definitions **/
//http://xmsecu.com:8080/ocx/NewActive.exe
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
#endif

637
lib/App/argus/RGoose_Kernel.cpp

@ -1,637 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel source
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#include "RGoose_Kernel.h"
#include <sys/types.h>
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
ARGUS_Kernel::ARGUS_Kernel( config_setting_t *Settings ):basicThread(){
m_bExitCause = 0;
m_nServerID = 0;
m_nSiteID = 0;
m_pDBC = NULL;
m_tTimeTSeconds = time( NULL );
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_pOnvifMediaObserver = onvifMediaObserver::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
if( basicSettingsProvider::getInstance()->isCompromised() ) {
basicSettingsProvider::getInstance()->validate();
};
m_pNodeFactory = argusNodeFactory::getInstance();
m_pModuleFactory = argusModuleFactory::getInstance();
};
ARGUS_Kernel::~ARGUS_Kernel(){
m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
#ifdef DEBUG
LOG("Destructor");
#endif
WaitFinish(true);
#ifdef DEBUG
LOG("Deleting Components");
#endif
delete( m_pStreamManager );
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
bool ARGUS_Kernel::create( void ){
char tBuffer[256];
if( m_pSettings != NULL ) {
config_setting_t * pSetting;
int tVal;
const char * tBuf;
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
LOG("Getting Settings ...");
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
char * tTS;
tTS = getTStr(NULL);
tVar = MD5String(tTS);
free(tTS);
sprintf( m_sIdentity, tVar );
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
config_setting_set_string( pSetting, tVar );
free( tVar );
basicSettingsProvider::getInstance()->compromise();
LOG("Server Identity not defined - generating new!");
} else {
sprintf( m_sIdentity, tBuf );
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
LOG( tBuffer );
};
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
tVal = m_nSiteID = 1;
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
config_setting_set_int( pSetting, tVal );
basicSettingsProvider::getInstance()->compromise();
LOG("Site ID not defined - using [1] as number!");
} else {
m_nSiteID = tVal;
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
LOG( tBuffer );
};
/*
#ifdef __EU_PROJECT__
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
tVal = m_bSafeShoreSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Safe-Shore support not defined");
} else {
m_bSafeShoreSupport = (bool)tVal;
sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
tVal = m_bDefenderSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Defender support not defined");
} else {
m_bDefenderSupport = (bool)tVal;
sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
*/
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
if( m_pDBC == NULL ) {
LOG("Explicitly Create DBC Object");
m_pDBC = new ARGUS_DBC(m_pSettings);
};
if( m_pDBC == NULL ){
LOG_ERROR("DBC Object Creation Failure!");
return false;
};
if(!m_pDBC->connect()){
LOG_ERROR("DBC Connection Failure!");
SLEEP(5000);
//ToDO: Set Restart Kernel!
return false;
};
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
m_pDBC->registerServer( m_nSiteID, m_sIdentity );
m_nServerID = m_pDBC->getServerID( m_sIdentity );
m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
enumerateHardware();
m_pNodeFactory->setDBC( m_pDBC );
m_pNodeFactory->loadNodes( m_nSiteID );
m_pModuleFactory->setDBC( m_pDBC ); //m_pDBC->getIPCamRecords( m_vCamRecords );
m_pModuleFactory->loadModules( m_nSiteID );
#ifdef DEBUG
LOG( "Start SSDP Beacon" );
#endif
if( m_pServiceAnnouncer != NULL ) {
if( !m_pServiceAnnouncer->init() ){
delete(m_pServiceAnnouncer);
m_pServiceAnnouncer = NULL;
};
};
m_pStreamManager = mediaNginxManager::getInstance();
if( m_pStreamManager != NULL ) {
m_pStreamManager->attachStream("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", true, 12, "12918" );
};
/*
#ifdef DEBUG
LOG("Init IP Cameras");
#endif
if( m_vCamRecords.size() ) {
ARGUS_Camera *tPtr = NULL;
for( int i=0; i < m_vCamRecords.size(); i++ ) {
tPtr = new ARGUS_Camera();
if( tPtr != NULL ) {
if( tPtr->create( m_vCamRecords.at(i)->ip, m_vCamRecords.at(i)->username, m_vCamRecords.at(i)->password ) ){
#ifdef DEBUG
LOG("Camera Created!");
#endif
m_vCameras.push_back( tPtr );
tPtr = NULL;
} else {
LOG_ERROR("Camera Creation Failure!");
delete( tPtr );
tPtr = NULL;
};
};
};
};
*/
#ifdef DEBUG
LOG("Start OnVIF Discovery");
#endif
if( m_pOnvifMediaObserver!= NULL ) {
m_pOnvifMediaObserver->startDiscovery();
m_bDiscoveryStarted = true;
};
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
#endif
/*
m_pServletWS = new servletWS();
if( m_pServletWS != NULL ) {
LOG("ServletWS Created");
if(m_pServletWS->create(8080)){
LOG("ServletWS Started");
//if( ! m_pServletWS->attachChannel("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", false ) ){
// LOG("Error Adding Channel!");
//} else {
// LOG("Channel Attached");
//};
};
};
*/
#ifdef DEBUG
sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
LOG( tBuffer );
#endif
return true;
};
int xioctl(int fh, int request, void *arg){
int r;
do {
r = ioctl( fh, request, arg );
} while (-1 == r && EINTR == errno);
return r;
};
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#include <sys/types.h>
#include <ifaddrs.h>
void ARGUS_Kernel::enumerateHardware( void ){
DIR * dFD;
struct dirent * pDR = NULL;
char tBuffer[CTEXT];
struct ifaddrs * ifaddr = NULL;
struct ifaddrs * ifa;
/* Add Network Interfaces */
if( -1 == getifaddrs(&ifaddr)) {
} else {
for( ifa = ifaddr; ifa; ifa = ifa->ifa_next ) {
if (ifa->ifa_addr->sa_family != AF_INET) continue;
char ip[16];
struct sockaddr_in *inn;
unsigned char A,B,C,D;
inn = (struct sockaddr_in *)ifa->ifa_addr;
D = ( inn->sin_addr.s_addr >> 24) & 0xFF;
C = ( inn->sin_addr.s_addr >> 16) & 0xFF;
B = ( inn->sin_addr.s_addr >> 8) & 0xFF;
A = ( inn->sin_addr.s_addr >> 0) & 0xFF;
sprintf( ip, "%d.%d.%d.%d", A, B, C, D );
sprintf( tBuffer, "Network Interface: %s [%s]", ifa->ifa_name, ip );
LOG(tBuffer);
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_NETWORK, ifa->ifa_name, ip );
};
freeifaddrs( ifaddr );
};
/* Add devices from DEV */
dFD = opendir("/dev");
if( dFD != NULL ) {
while( ( pDR = readdir( dFD ))!= NULL ){
if( strcasestr( pDR->d_name, "video" ) == pDR->d_name ) {
/* Enumerate Video Capture */
sprintf( tBuffer, "Video Source: %s", pDR->d_name );
LOG( tBuffer );
struct v4l2_capability cap;
//struct v4l2_cropcap cropcap;
//struct v4l2_crop crop;
struct v4l2_format fmt;
char dev_name[CTEXT];
int fd = -1;
struct stat st;
sprintf( dev_name, "/dev/%s", pDR->d_name );
if (-1 == stat( dev_name, &st )) {
sprintf( tBuffer, "Cannot identify '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
};
if (!S_ISCHR(st.st_mode)) {
sprintf( tBuffer, "%s is no devicen", dev_name);
LOG_ERROR( tBuffer );
continue;
};
fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
sprintf( tBuffer, "%s is no V4L2 device", dev_name );
LOG_ERROR( tBuffer );
} else {
LOG_ERROR( "VIDIOC_QUERYCAP" );
};
close(fd);
continue;
};
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
sprintf(tBuffer, "%s is no video capture device\\n", dev_name);
LOG_ERROR( tBuffer );
close(fd);
continue;
};
CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
/* Preserve original settings as set by v4l2-ctl for example */
if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt)){
LOG_ERROR("VIDIOC_G_FMT");
} else {
sprintf( tBuffer, "Grabber[%dx%d]",fmt.fmt.pix.width,fmt.fmt.pix.height);
LOG( tBuffer );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER, dev_name, tBuffer );
};
close(fd);
continue;
};
};
if( strcasestr( pDR->d_name, "ttyS" ) == pDR->d_name ){
/* Enumerate BuiltIn Serial */
sprintf( tBuffer, "Native Serial: %s", pDR->d_name );
LOG( tBuffer );
char dev_name[CTEXT];
int fd = -1;
struct serial_struct ss;
sprintf( dev_name, "/dev/%s", pDR->d_name );
fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK );
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){
LOG_ERROR("TIOCGSERIAL");
} else {
sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]",
ss.port,
ss.irq,
ss.baud_base,
ss.line,
ss.type,
ss.flags
);
LOG( tBuffer );
char comName[16];
int pn = atoi( pDR->d_name+4) + 1;
sprintf( comName,"COM%d", pn );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name, comName );
};
close(fd);
continue;
};
continue;
};
if( strcasestr( pDR->d_name, "ttyUSB" ) == pDR->d_name ){
/* Enumerate USB Serial devices */
sprintf( tBuffer, "USB Serial: %s", pDR->d_name );
LOG( tBuffer );
char dev_name[CTEXT];
int fd = -1;
struct serial_struct ss;
sprintf( dev_name, "/dev/%s", pDR->d_name );
fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK );
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){
LOG_ERROR("TIOCGSERIAL");
} else {
sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]",
ss.port,
ss.irq,
ss.baud_base,
ss.line,
ss.type,
ss.flags
);
LOG( tBuffer );
char comName[16];
int pn = atoi( pDR->d_name+4) + 1;
sprintf( comName,"USB-COM%d", pn );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name, comName );
};
close(fd);
continue;
};
continue;
};
};
closedir( dFD );
};
};
void ARGUS_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
LOG( "Thread is Detached" );
#endif
};
/* Main Kernel Thread Procedure */
void ARGUS_Kernel::m_fThreadProc( void ){
char Buffer[CTEXT];
time_t tTimeTSeconds;
int lastTSS = 0;
int lastTMS = 0;
EventRecordDBC * tEvtPtr;
pid_t pid = gettid();
char pidBuf[16];
sprintf(pidBuf,"pid:%d", pid);
LOG(pidBuf);
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
// Network IP OnVif Discovery
//*
if( m_pOnvifMediaObserver!= NULL ){
if( !m_bDiscoveryStarted ) {
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==0){
#ifdef DEBUG
LOG("Start OnVIF Discovery");
#endif
m_pOnvifMediaObserver->startDiscovery();
m_bDiscoveryStarted = true;
};
} else {
/*
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){
#ifdef DEBUG
LOG("Validate IP Cameras");
#endif
validateCameras();
m_bDiscoveryStarted = false;
};
*/
};
};
//*/
//*
// Event Processing Loop
if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){
// Error In DB Access
m_bThreadStatus = TH_ENDED;
m_bExitCause = 1;
continue;
};
/* if( m_vEvtRecords.size() > 0 ){
validateEvents( lastTSS, lastTMS );
};
*/
//*/
if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
tTimeTSeconds = m_tTimeTSeconds;
if( m_pModuleFactory != NULL ) {
m_pModuleFactory->validate();
};
//if( m_pNodeFactory != NULL ) {
//m_pNodeFactory->validate();
//};
};
SLEEP( SLEEP_KERNEL_INTERVAL );
};
};
/*
int ARGUS_Kernel::isCameraListed( CSTR uid ){
if( m_vCamRecords.size() )
for( int index = 0; index < m_vCamRecords.size(); index++ )
if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
m_vCamRecords.at(index)->online = true;
return index;
};
return -1;
};
void ARGUS_Kernel::validateCameras( void ){
vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
if( DiscoverResults->size() > 0 ) {
for (int index = 0; index < DiscoverResults->size(); index++) {
char tBuffer[256];
sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
LOG( tBuffer );
int cid = isCameraListed(DiscoverResults->at(index)->RefID);
if( cid != -1 ) {
sprintf( tBuffer, "Camera is Listed as %d", cid );
LOG( tBuffer );
if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
m_pDBC->updateIPCam( m_nSiteID, DiscoverResults->at(index));
};
} else {
// Uncknown camera - no checking
LOG("Camera is Not Listed");
m_pDBC->updateIPCam( m_nSiteID, DiscoverResults->at(index) );
};
};
} else {
LOG("No Online IP Cameras in Network");
};
};
void ARGUS_Kernel::validateEvents( int &lastTSS, int &lastTMS ){
EventRecordDBC *tPtr = NULL;
basicEvent *tEvt = NULL;
if(m_vEvtRecords.size()) {
lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
#ifndef ONE_EVENT_PER_LOOP
while(m_vEvtRecords.size()) {
#endif
tPtr = *m_vEvtRecords.begin();
if( tPtr != NULL ) {
if( tEvt != NULL ) {
m_pEventHeap->broadcast( tEvt );
//free( tEvt );
};
free( tPtr );
};
m_vEvtRecords.erase(m_vEvtRecords.begin());
#ifndef ONE_EVENT_PER_LOOP
};
#endif
};
};
*/
bool ARGUS_Kernel::signalEvent( void ){
if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
};
return true;
};
int ARGUS_Kernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
RA = NULL;
int cnt = 0;
if( m_pNodeFactory != NULL ){
cnt = m_pNodeFactory->getNodeCount( type );
if( cnt ) {
RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
m_pNodeFactory->fetchNodes(type, RA );
};
};
return cnt;
};
argusNetNode *ARGUS_Kernel::getNetNode( int id ){
return NULL;
};
int ARGUS_Kernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
return 0;
};
argusKernelModule *ARGUS_Kernel::getModule( int id ){
return NULL;
};
#undef LOG
#undef LOG_ERROR

133
lib/App/argus/RGoose_Kernel.h

@ -1,133 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel Header File
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#ifndef __ARGUS_KERNEL_HEADER__
#define __ARGUS_KERNEL_HEADER__
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> /* getopt_long() */
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/types.h>
struct serial_struct {
int type;
int line;
unsigned int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char io_type;
char reserved_char[1];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
unsigned char *iomem_base;
unsigned short iomem_reg_shift;
unsigned int port_high;
unsigned long iomap_base; /* cookie passed into ioremap */
};
#include "../../alg/generic/md5.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicSettingsProvider.h"
//#include "../../data/ponvif/ponvif.h"
//#include "../../data/protocol/onvifMediaObserver.h"
//#include "../../data/ssdp/ssdpAnnouncer.h"
//#include "../../data/NginxMediaServer/mediaNginxStreamingProxyManager.h"
#include "../../components/base/basicEventHeap.h"
#include "../../rgoose/rgooseDBConnector.h"
#include "../../rgoose/rgooseIPCamera.h"
#include "../../rgoose/rgooseNodeFactory.h"
#include "../../rgoose/rgooseModuleFactory.h"
#include "../../data/net/netServer.h"
//#include "../../data/servletWS/servletWS.h"
#define SLEEP_KERNEL_INTERVAL 10
#define ONVIF_DISCOVERY_INTERVAL 300 // 5 min
#define ONVIF_DISCOVERY_RESULT_TIME 5
#define ARGUS_KERNEL_TAG_SITE_ID "SITE_ID"
#define ARGUS_KERNEL_TAG_SERVER_IDENTITY "IDENTITY"
#define ARGUS_NODE_SOCK_TYPE_SERIAL_PORT 1
#define ARGUS_NODE_SOCK_TYPE_NETWORK 2
#define ARGUS_NODE_SOCK_TYPE_DC 3
#define ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER 4
#define ARGUS_NODE_SOCK_TYPE_AUDIO_GRABBER 5
#define ARGUS_NODE_SOCK_TYPE_VIDEO_DIGITAL 6
class ARGUS_Kernel: public basicThread {
private:
uint32_t m_nSiteID;
uint32_t m_nServerID;
uint32_t m_nServerNodeID;
char m_sIdentity[33];
time_t m_tTimeTSeconds;
basicLogCollection * m_pLog;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
ssdpAnnouncer * m_pServiceAnnouncer;
uint8_t m_bExitCause;
ARGUS_DBC * m_pDBC;
networkServer * m_pNetClientsServer;
onvifMediaObserver * m_pOnvifMediaObserver;
bool m_bDiscoveryStarted;
vectorARGUS_Cameras m_vCameras;
vectorCamRecords m_vCamRecords;
vectorEventRecords m_vEvtRecords;
argusNodeFactory * m_pNodeFactory;
argusModuleFactory * m_pModuleFactory;
mediaNginxManager * m_pStreamManager;
//servletWS * m_pServletWS;
//int isCameraListed( CSTR uid );
//void validateCameras( void );
//void validateEvents( int &lastTSS, int &lastTMS );
void enumerateHardware( void );
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit ARGUS_Kernel( config_setting_t *Settings = NULL );
// Destructor
virtual ~ARGUS_Kernel();
bool create( void );
bool signalEvent( void );
void WaitFinish( bool Force = false );
uint8_t getExitCause( void ){ return m_bExitCause;};
int getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA );
argusNetNode * getNetNode( int id );
int getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA );
argusKernelModule * getModule( int id );
};
#endif

286
lib/App/argus_server/ArgusBackend.cpp

@ -1,286 +0,0 @@
#include "ArgusBackend.h"
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
argusKernel * Kernel = NULL;
basicLogCollection * m_pLog = NULL;
networkServer * NetworkManager = NULL;
void (*old_update_handler_2)(int); //SIGINT
void (*old_kill_handler_3)(int); //SIGQUIT
void (*old_kill_handler_9)(int); //SIGKILL
void (*old_alarm_handler_14)(int); //SIGALRM
void (*old_kill_handler_15)(int); //SIGTERM
void signal_SIGKILL_handler( int SIG ){
if( Kernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
//#include <sys/resource.h>
int main (int argc, char *argv[]){
/*
const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0){
printf( "Stack Size: %d\n", rl.rlim_cur );
if ( rl.rlim_cur < kStackSize ){
printf( "Resize Stack to: %d\n", kStackSize );
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0){
fprintf(stderr, "setrlimit returned result = %d\n", result);
return -1;
};
};
};
*/
MySQL_Connector * DBC = NULL;
basicSettingsProvider * SETTINGS = NULL;
bool WBG = true; // Working Background
bool SSE = true; // Server Statistics Engine
bool NDC = true; // No Default Configuration
bool COLD_START = true;
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
objectFileLoggingService * FLE = NULL;
objectConsoleLoggingService * CLE = NULL;
// default init
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
m_pLog = basicLogCollection::getInstance( _LOG_LVL_TIME_PTR );
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems ARGUS Server\n");
printf( "Software version <%s>\n", ARGUS_BUILD_STRING );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
CLE = new objectConsoleLoggingService();
if( CLE != NULL ) {
m_pLog->addHandler( CLE );
};
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
if( DCF_NAME != NULL ) {
sprintf( DCF_NAME, "%s", argv[i+1] );
} else {
printf("ERROR!\n\n");
return -1;
};
break;
};
};
break;
};
};
};
};
FLE = new objectFileLoggingService( FLE_NAME );
if( FLE != NULL ) {
m_pLog->addHandler( FLE );
};
LOG("Starting Log Engne!");
if ( fileExist( DCF_NAME ) ){
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
} else {
SETTINGS = basicSettingsProvider::getInstance();
};
if ( fileExist( gsCFG_PID_FILE ) ){
COLD_START = false;
//check if process already running
FILE *tFD = fopen( gsCFG_PID_FILE, "r" );
if( tFD ) {
pid_t pid;
char tBuff[256];
//fscanf( tFD, "%d\n", pid );
fread( tBuff, 1, 255, tFD );
pid = atoi( tBuff );
printf("Old Process PID: %d\n", pid );
if( kill( pid, 0 )==0 ){
printf("Process Already Running --> exiting!\n");
delete( FLE );
fclose( tFD );
exit(12);
} else {
printf("No Running Process --> Hot Restart Detected!\n");
};
fclose( tFD );
};
};
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. <%s>\n", ARGUS_BUILD_STRING );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
uint8_t m_bKernelExitCode = 0;
do{
Kernel = argusKernel::getInstance( COLD_START );
if( Kernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( Kernel != NULL ){
LOG( "++++ Server Started ++++" );
if ( Kernel->create() == false ){
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( SIGTERM /* 15 */, signal_SIGKILL_handler );
old_kill_handler_9 = signal( SIGKILL /* 9 */, signal_SIGKILL_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
};
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
} while( m_bKernelExitCode > 0 );
delete( NetworkManager );
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
if( FLE!= NULL ) delete( FLE );
if( CLE!= NULL ) delete( CLE );
delete( m_pLog );
return(0);
}

46
lib/App/argus_server/ArgusBackend.h

@ -1,46 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: Argus project main header file
*
* AUTHOR: Gagua
*
* HISTORY:
*
* DATE:2/25/2024
*
*******************************************************************/
#ifndef __ARGUS_BACKEND_MAIN_HEADER__
#define __ARGUS_BACKEND_MAIN_HEADER__
/** include files **/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMemoryOperation.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectConsoleLoggingService.h"
#include "ArgusKernel.h"
/** local definitions **/
//http://xmsecu.com:8080/ocx/NewActive.exe
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
#endif

637
lib/App/argus_server/ArgusKernel.cpp

@ -1,637 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel source
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:2/25/2024
*
*******************************************************************/
#include "ArgusKernel.h"
#include <sys/types.h>
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
ARGUS_Kernel::ARGUS_Kernel( config_setting_t *Settings ):basicThread(){
m_bExitCause = 0;
m_nServerID = 0;
m_nSiteID = 0;
m_pDBC = NULL;
m_tTimeTSeconds = time( NULL );
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_pOnvifMediaObserver = onvifMediaObserver::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
m_pServiceAnnouncer = new ssdpAnnouncer( m_pSettings );
if( basicSettingsProvider::getInstance()->isCompromised() ) {
basicSettingsProvider::getInstance()->validate();
};
m_pNodeFactory = argusNodeFactory::getInstance();
m_pModuleFactory = argusModuleFactory::getInstance();
};
ARGUS_Kernel::~ARGUS_Kernel(){
m_pDBC->unregisterServer( m_nSiteID, m_nServerNodeID );
#ifdef DEBUG
LOG("Destructor");
#endif
WaitFinish(true);
#ifdef DEBUG
LOG("Deleting Components");
#endif
delete( m_pStreamManager );
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
bool ARGUS_Kernel::create( void ){
char tBuffer[256];
if( m_pSettings != NULL ) {
config_setting_t * pSetting;
int tVal;
const char * tBuf;
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
LOG("Getting Settings ...");
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
char * tTS;
tTS = getTStr(NULL);
tVar = MD5String(tTS);
free(tTS);
sprintf( m_sIdentity, tVar );
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
config_setting_set_string( pSetting, tVar );
free( tVar );
basicSettingsProvider::getInstance()->compromise();
LOG("Server Identity not defined - generating new!");
} else {
sprintf( m_sIdentity, tBuf );
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
LOG( tBuffer );
};
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
tVal = m_nSiteID = 1;
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
config_setting_set_int( pSetting, tVal );
basicSettingsProvider::getInstance()->compromise();
LOG("Site ID not defined - using [1] as number!");
} else {
m_nSiteID = tVal;
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
LOG( tBuffer );
};
/*
#ifdef __EU_PROJECT__
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
tVal = m_bSafeShoreSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Safe-Shore support not defined");
} else {
m_bSafeShoreSupport = (bool)tVal;
sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
tVal = m_bDefenderSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Defender support not defined");
} else {
m_bDefenderSupport = (bool)tVal;
sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
*/
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
if( m_pDBC == NULL ) {
LOG("Explicitly Create DBC Object");
m_pDBC = new ARGUS_DBC(m_pSettings);
};
if( m_pDBC == NULL ){
LOG_ERROR("DBC Object Creation Failure!");
return false;
};
if(!m_pDBC->connect()){
LOG_ERROR("DBC Connection Failure!");
SLEEP(5000);
//ToDO: Set Restart Kernel!
return false;
};
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
m_pDBC->registerServer( m_nSiteID, m_sIdentity );
m_nServerID = m_pDBC->getServerID( m_sIdentity );
m_nServerNodeID = m_pDBC->getServerNode( m_nServerID );
enumerateHardware();
m_pNodeFactory->setDBC( m_pDBC );
m_pNodeFactory->loadNodes( m_nSiteID );
m_pModuleFactory->setDBC( m_pDBC ); //m_pDBC->getIPCamRecords( m_vCamRecords );
m_pModuleFactory->loadModules( m_nSiteID );
#ifdef DEBUG
LOG( "Start SSDP Beacon" );
#endif
if( m_pServiceAnnouncer != NULL ) {
if( !m_pServiceAnnouncer->init() ){
delete(m_pServiceAnnouncer);
m_pServiceAnnouncer = NULL;
};
};
m_pStreamManager = mediaNginxManager::getInstance();
if( m_pStreamManager != NULL ) {
m_pStreamManager->attachStream("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", true, 12, "12918" );
};
/*
#ifdef DEBUG
LOG("Init IP Cameras");
#endif
if( m_vCamRecords.size() ) {
ARGUS_Camera *tPtr = NULL;
for( int i=0; i < m_vCamRecords.size(); i++ ) {
tPtr = new ARGUS_Camera();
if( tPtr != NULL ) {
if( tPtr->create( m_vCamRecords.at(i)->ip, m_vCamRecords.at(i)->username, m_vCamRecords.at(i)->password ) ){
#ifdef DEBUG
LOG("Camera Created!");
#endif
m_vCameras.push_back( tPtr );
tPtr = NULL;
} else {
LOG_ERROR("Camera Creation Failure!");
delete( tPtr );
tPtr = NULL;
};
};
};
};
*/
#ifdef DEBUG
LOG("Start OnVIF Discovery");
#endif
if( m_pOnvifMediaObserver!= NULL ) {
m_pOnvifMediaObserver->startDiscovery();
m_bDiscoveryStarted = true;
};
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
#endif
/*
m_pServletWS = new servletWS();
if( m_pServletWS != NULL ) {
LOG("ServletWS Created");
if(m_pServletWS->create(8080)){
LOG("ServletWS Started");
//if( ! m_pServletWS->attachChannel("rtsp://gagua:4GetMyID@192.168.0.109:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", false ) ){
// LOG("Error Adding Channel!");
//} else {
// LOG("Channel Attached");
//};
};
};
*/
#ifdef DEBUG
sprintf( tBuffer, "Server is registered as id[%d]", m_nServerID );
LOG( tBuffer );
#endif
return true;
};
int xioctl(int fh, int request, void *arg){
int r;
do {
r = ioctl( fh, request, arg );
} while (-1 == r && EINTR == errno);
return r;
};
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#include <sys/types.h>
#include <ifaddrs.h>
void ARGUS_Kernel::enumerateHardware( void ){
DIR * dFD;
struct dirent * pDR = NULL;
char tBuffer[CTEXT];
struct ifaddrs * ifaddr = NULL;
struct ifaddrs * ifa;
/* Add Network Interfaces */
if( -1 == getifaddrs(&ifaddr)) {
} else {
for( ifa = ifaddr; ifa; ifa = ifa->ifa_next ) {
if (ifa->ifa_addr->sa_family != AF_INET) continue;
char ip[16];
struct sockaddr_in *inn;
unsigned char A,B,C,D;
inn = (struct sockaddr_in *)ifa->ifa_addr;
D = ( inn->sin_addr.s_addr >> 24) & 0xFF;
C = ( inn->sin_addr.s_addr >> 16) & 0xFF;
B = ( inn->sin_addr.s_addr >> 8) & 0xFF;
A = ( inn->sin_addr.s_addr >> 0) & 0xFF;
sprintf( ip, "%d.%d.%d.%d", A, B, C, D );
sprintf( tBuffer, "Network Interface: %s [%s]", ifa->ifa_name, ip );
LOG(tBuffer);
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_NETWORK, ifa->ifa_name, ip );
};
freeifaddrs( ifaddr );
};
/* Add devices from DEV */
dFD = opendir("/dev");
if( dFD != NULL ) {
while( ( pDR = readdir( dFD ))!= NULL ){
if( strcasestr( pDR->d_name, "video" ) == pDR->d_name ) {
/* Enumerate Video Capture */
sprintf( tBuffer, "Video Source: %s", pDR->d_name );
LOG( tBuffer );
struct v4l2_capability cap;
//struct v4l2_cropcap cropcap;
//struct v4l2_crop crop;
struct v4l2_format fmt;
char dev_name[CTEXT];
int fd = -1;
struct stat st;
sprintf( dev_name, "/dev/%s", pDR->d_name );
if (-1 == stat( dev_name, &st )) {
sprintf( tBuffer, "Cannot identify '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
};
if (!S_ISCHR(st.st_mode)) {
sprintf( tBuffer, "%s is no devicen", dev_name);
LOG_ERROR( tBuffer );
continue;
};
fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) {
sprintf( tBuffer, "%s is no V4L2 device", dev_name );
LOG_ERROR( tBuffer );
} else {
LOG_ERROR( "VIDIOC_QUERYCAP" );
};
close(fd);
continue;
};
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
sprintf(tBuffer, "%s is no video capture device\\n", dev_name);
LOG_ERROR( tBuffer );
close(fd);
continue;
};
CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
/* Preserve original settings as set by v4l2-ctl for example */
if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt)){
LOG_ERROR("VIDIOC_G_FMT");
} else {
sprintf( tBuffer, "Grabber[%dx%d]",fmt.fmt.pix.width,fmt.fmt.pix.height);
LOG( tBuffer );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER, dev_name, tBuffer );
};
close(fd);
continue;
};
};
if( strcasestr( pDR->d_name, "ttyS" ) == pDR->d_name ){
/* Enumerate BuiltIn Serial */
sprintf( tBuffer, "Native Serial: %s", pDR->d_name );
LOG( tBuffer );
char dev_name[CTEXT];
int fd = -1;
struct serial_struct ss;
sprintf( dev_name, "/dev/%s", pDR->d_name );
fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK );
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){
LOG_ERROR("TIOCGSERIAL");
} else {
sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]",
ss.port,
ss.irq,
ss.baud_base,
ss.line,
ss.type,
ss.flags
);
LOG( tBuffer );
char comName[16];
int pn = atoi( pDR->d_name+4) + 1;
sprintf( comName,"COM%d", pn );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name, comName );
};
close(fd);
continue;
};
continue;
};
if( strcasestr( pDR->d_name, "ttyUSB" ) == pDR->d_name ){
/* Enumerate USB Serial devices */
sprintf( tBuffer, "USB Serial: %s", pDR->d_name );
LOG( tBuffer );
char dev_name[CTEXT];
int fd = -1;
struct serial_struct ss;
sprintf( dev_name, "/dev/%s", pDR->d_name );
fd = open( dev_name, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK );
if (-1 == fd) {
sprintf( tBuffer, "Cannot open '%s': %d, %s\\n", dev_name, errno, strerror(errno));
LOG_ERROR( tBuffer );
continue;
} else {
if (-1 == xioctl(fd, TIOCGSERIAL, &ss)){
LOG_ERROR("TIOCGSERIAL");
} else {
sprintf( tBuffer, "Serial Port[Port:0x%X IRQ:%d BB:%d Line:%d Type:%d Flags:%X]",
ss.port,
ss.irq,
ss.baud_base,
ss.line,
ss.type,
ss.flags
);
LOG( tBuffer );
char comName[16];
int pn = atoi( pDR->d_name+4) + 1;
sprintf( comName,"USB-COM%d", pn );
m_pDBC->addNodeSocket( m_nServerNodeID, ARGUS_NODE_SOCK_TYPE_SERIAL_PORT, dev_name, comName );
};
close(fd);
continue;
};
continue;
};
};
closedir( dFD );
};
};
void ARGUS_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
LOG( "Thread is Detached" );
#endif
};
/* Main Kernel Thread Procedure */
void ARGUS_Kernel::m_fThreadProc( void ){
char Buffer[CTEXT];
time_t tTimeTSeconds;
int lastTSS = 0;
int lastTMS = 0;
EventRecordDBC * tEvtPtr;
pid_t pid = gettid();
char pidBuf[16];
sprintf(pidBuf,"pid:%d", pid);
LOG(pidBuf);
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
// Network IP OnVif Discovery
//*
if( m_pOnvifMediaObserver!= NULL ){
if( !m_bDiscoveryStarted ) {
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==0){
#ifdef DEBUG
LOG("Start OnVIF Discovery");
#endif
m_pOnvifMediaObserver->startDiscovery();
m_bDiscoveryStarted = true;
};
} else {
/*
if((m_tTimeTSeconds%ONVIF_DISCOVERY_INTERVAL)==ONVIF_DISCOVERY_RESULT_TIME){
#ifdef DEBUG
LOG("Validate IP Cameras");
#endif
validateCameras();
m_bDiscoveryStarted = false;
};
*/
};
};
//*/
//*
// Event Processing Loop
if( !m_pDBC->getLastEvents( m_vEvtRecords, lastTSS, lastTMS ) ){
// Error In DB Access
m_bThreadStatus = TH_ENDED;
m_bExitCause = 1;
continue;
};
/* if( m_vEvtRecords.size() > 0 ){
validateEvents( lastTSS, lastTMS );
};
*/
//*/
if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
tTimeTSeconds = m_tTimeTSeconds;
if( m_pModuleFactory != NULL ) {
m_pModuleFactory->validate();
};
//if( m_pNodeFactory != NULL ) {
//m_pNodeFactory->validate();
//};
};
SLEEP( SLEEP_KERNEL_INTERVAL );
};
};
/*
int ARGUS_Kernel::isCameraListed( CSTR uid ){
if( m_vCamRecords.size() )
for( int index = 0; index < m_vCamRecords.size(); index++ )
if(strstr(m_vCamRecords.at(index)->uuid,uid)!=NULL){
m_vCamRecords.at(index)->online = true;
return index;
};
return -1;
};
void ARGUS_Kernel::validateCameras( void ){
vectorWoWoResults *DiscoverResults = m_pOnvifMediaObserver->getResults();
if( DiscoverResults->size() > 0 ) {
for (int index = 0; index < DiscoverResults->size(); index++) {
char tBuffer[256];
sprintf( tBuffer,"Found Camwera [%s] %s", DiscoverResults->at(index)->XAddrs, DiscoverResults->at(index)->RefID );
LOG( tBuffer );
int cid = isCameraListed(DiscoverResults->at(index)->RefID);
if( cid != -1 ) {
sprintf( tBuffer, "Camera is Listed as %d", cid );
LOG( tBuffer );
if( strstr(DiscoverResults->at(index)->XAddrs,m_vCamRecords.at(cid)->ip)==NULL ) {
m_pDBC->updateIPCam( m_nSiteID, DiscoverResults->at(index));
};
} else {
// Uncknown camera - no checking
LOG("Camera is Not Listed");
m_pDBC->updateIPCam( m_nSiteID, DiscoverResults->at(index) );
};
};
} else {
LOG("No Online IP Cameras in Network");
};
};
void ARGUS_Kernel::validateEvents( int &lastTSS, int &lastTMS ){
EventRecordDBC *tPtr = NULL;
basicEvent *tEvt = NULL;
if(m_vEvtRecords.size()) {
lastTSS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_s;
lastTMS = m_vEvtRecords.at(m_vEvtRecords.size()-1)->ts_ms;
#ifndef ONE_EVENT_PER_LOOP
while(m_vEvtRecords.size()) {
#endif
tPtr = *m_vEvtRecords.begin();
if( tPtr != NULL ) {
if( tEvt != NULL ) {
m_pEventHeap->broadcast( tEvt );
//free( tEvt );
};
free( tPtr );
};
m_vEvtRecords.erase(m_vEvtRecords.begin());
#ifndef ONE_EVENT_PER_LOOP
};
#endif
};
};
*/
bool ARGUS_Kernel::signalEvent( void ){
if( m_pDBC->getLastEvents( m_vEvtRecords, 0,0 ) ){
};
return true;
};
int ARGUS_Kernel::getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA ){
RA = NULL;
int cnt = 0;
if( m_pNodeFactory != NULL ){
cnt = m_pNodeFactory->getNodeCount( type );
if( cnt ) {
RA = (argusNetNode **) calloc( cnt, sizeof( argusNetNode * ) );
m_pNodeFactory->fetchNodes(type, RA );
};
};
return cnt;
};
argusNetNode *ARGUS_Kernel::getNetNode( int id ){
return NULL;
};
int ARGUS_Kernel::getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA ){
return 0;
};
argusKernelModule *ARGUS_Kernel::getModule( int id ){
return NULL;
};
#undef LOG
#undef LOG_ERROR

125
lib/App/argus_server/ArgusKernel.h

@ -1,125 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel Header File
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:2/25/2024
*
*******************************************************************/
#ifndef __ARGUS_KERNEL_HEADER__
#define __ARGUS_KERNEL_HEADER__
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <getopt.h> /* getopt_long() */
#include <fcntl.h> /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/types.h>
struct serial_struct {
int type;
int line;
unsigned int port;
int irq;
int flags;
int xmit_fifo_size;
int custom_divisor;
int baud_base;
unsigned short close_delay;
char io_type;
char reserved_char[1];
int hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
unsigned char *iomem_base;
unsigned short iomem_reg_shift;
unsigned int port_high;
unsigned long iomap_base; /* cookie passed into ioremap */
};
#include "../../alg/generic/md5.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "../../data/net/netServer.h"
#define SLEEP_KERNEL_INTERVAL 10
#define ONVIF_DISCOVERY_INTERVAL 300 // 5 min
#define ONVIF_DISCOVERY_RESULT_TIME 5
#define ARGUS_KERNEL_TAG_SITE_ID "SITE_ID"
#define ARGUS_KERNEL_TAG_SERVER_IDENTITY "IDENTITY"
#define ARGUS_NODE_SOCK_TYPE_SERIAL_PORT 1
#define ARGUS_NODE_SOCK_TYPE_NETWORK 2
#define ARGUS_NODE_SOCK_TYPE_DC 3
#define ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER 4
#define ARGUS_NODE_SOCK_TYPE_AUDIO_GRABBER 5
#define ARGUS_NODE_SOCK_TYPE_VIDEO_DIGITAL 6
class ARGUS_Kernel: public basicThread {
private:
uint32_t m_nSiteID;
uint32_t m_nServerID;
uint32_t m_nServerNodeID;
char m_sIdentity[33];
time_t m_tTimeTSeconds;
basicLogCollection * m_pLog;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
ssdpAnnouncer * m_pServiceAnnouncer;
uint8_t m_bExitCause;
ARGUS_DBC * m_pDBC;
networkServer * m_pNetClientsServer;
onvifMediaObserver * m_pOnvifMediaObserver;
bool m_bDiscoveryStarted;
vectorARGUS_Cameras m_vCameras;
vectorCamRecords m_vCamRecords;
vectorEventRecords m_vEvtRecords;
argusNodeFactory * m_pNodeFactory;
argusModuleFactory * m_pModuleFactory;
mediaNginxManager * m_pStreamManager;
//servletWS * m_pServletWS;
//int isCameraListed( CSTR uid );
//void validateCameras( void );
//void validateEvents( int &lastTSS, int &lastTMS );
void enumerateHardware( void );
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit ARGUS_Kernel( config_setting_t *Settings = NULL );
// Destructor
virtual ~ARGUS_Kernel();
bool create( void );
bool signalEvent( void );
void WaitFinish( bool Force = false );
uint8_t getExitCause( void ){ return m_bExitCause;};
int getNetNodes( ARGUS_NODE_TYPE type, argusNetNode **&RA );
argusNetNode * getNetNode( int id );
int getModules( ARGUS_MODULE_TYPE type, argusKernelModule **&RA );
argusKernelModule * getModule( int id );
};
#endif

246
lib/App/defender/ArgusBackend.cpp

@ -1,246 +0,0 @@
#include "ArgusBackend.h"
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
ARGUS_Kernel * Kernel = NULL;
//LRF_HardwareManager * HWManager = NULL;
basicLogCollection * m_pLog = NULL;
networkServer * NetworkManager = NULL;
void (*old_update_handler_2)(int); //SIGINT
void (*old_kill_handler_3)(int); //SIGQUIT
void (*old_kill_handler_9)(int); //SIGKILL
void (*old_alarm_handler_14)(int); //SIGALRM
void (*old_kill_handler_15)(int); //SIGTERM
void signal_SIGKILL_handler( int SIG ){
if( Kernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
int main (int argc, char *argv[]){
MySQL_Connector * DBC = NULL;
basicSettingsProvider * SETTINGS = NULL;
bool WBG; // Working Background
bool SSE; // Server Statistics Engine
bool NDC; // No Default Configuration
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
objectFileLoggingService * FLE = NULL;
objectConsoleLoggingService * CLE = NULL;
// default init
WBG = true;
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
SSE = true;
NDC = true;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
m_pLog = basicLogCollection::getInstance();
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems R-Goose Server\n");
printf( "Software version <%s>\n", VERSION_NUMBER );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
CLE = new objectConsoleLoggingService();
if( CLE != NULL ) {
m_pLog->addHandler( CLE );
};
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
if( DCF_NAME != NULL ) {
sprintf( DCF_NAME, "%s", argv[i+1] );
} else {
printf("ERROR!\n\n");
return -1;
};
break;
};
};
break;
};
};
};
};
FLE = new objectFileLoggingService( FLE_NAME );
if( FLE != NULL ) {
m_pLog->addHandler( FLE );
};
LOG("Starting Log Engne!");
if ( fileExist( DCF_NAME ) ){
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME);
} else {
SETTINGS = basicSettingsProvider::getInstance();
};
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. %s\n", VERSION_NUMBER );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
uint8_t m_bKernelExitCode = 0;
do{
Kernel = new ARGUS_Kernel();
if( Kernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( Kernel != NULL ){
LOG( "++++ Server Started ++++" );
if ( Kernel->create() == false ){
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_SIGKILL_handler );
old_kill_handler_9 = signal( 9, signal_SIGKILL_handler );
// Waiting for Worker to Shut Down
Kernel->WaitFinish( false );
m_bKernelExitCode = Kernel->getExitCause();
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
};
delete( Kernel );
LOG( "++++ Server Ended ++++" );
};
} while( m_bKernelExitCode > 0 );
delete( NetworkManager );
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
if( FLE!= NULL ) delete( FLE );
if( CLE!= NULL ) delete( CLE );
delete( m_pLog );
return(0);
}

50
lib/App/defender/ArgusBackend.h

@ -1,50 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: Argus project main header file
*
* AUTHOR: Gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#ifndef __ARGUS_BACKEND_MAIN_HEADER__
#define __ARGUS_BACKEND_MAIN_HEADER__
/** include files **/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicMemoryOperation.h"
#include "../../components/object/objectFileLoggingService.h"
#include "../../components/object/objectConsoleLoggingService.h"
#include "../../data/net/netServer.h"
#include "../../data/ponvif/ponvif.h"
#include "../../data/protocol/onvifMediaObserver.h"
#include "../../data/mysql/database_class.h"
#include "RGoose_Kernel.h"
/** local definitions **/
//http://xmsecu.com:8080/ocx/NewActive.exe
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
#endif

217
lib/App/defender/RGoose_Kernel.cpp

@ -1,217 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel source
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#include "RGoose_Kernel.h"
#include <sys/types.h>
#define LOG( X ) m_pLog->Log( "KRNL", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X )
ARGUS_Kernel::ARGUS_Kernel( config_setting_t *Settings ):basicThread(){
m_bExitCause = 0;
m_nSiteID = 0;
m_tTimeTSeconds = time( NULL );
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "KERNEL" );
if( basicSettingsProvider::getInstance()->isCompromised() ) {
basicSettingsProvider::getInstance()->validate();
};
};
ARGUS_Kernel::~ARGUS_Kernel(){
#ifdef DEBUG
LOG("Destructor");
#endif
WaitFinish(true);
#ifdef DEBUG
LOG("Deleting Components");
#endif
#ifdef DEBUG
LOG("Destructor Finished");
#endif
};
bool ARGUS_Kernel::create( void ){
char tBuffer[256];
if( m_pSettings != NULL ) {
config_setting_t * pSetting;
int tVal;
const char * tBuf;
//Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 );
LOG("Getting Settings ...");
if( !config_setting_lookup_string( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, &tBuf ) ){
char * tVar;
char * tTS;
tTS = getTStr(NULL);
tVar = MD5String(tTS);
free(tTS);
sprintf( m_sIdentity, tVar );
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SERVER_IDENTITY, CONFIG_TYPE_STRING );
config_setting_set_string( pSetting, tVar );
free( tVar );
basicSettingsProvider::getInstance()->compromise();
LOG("Server Identity not defined - generating new!");
} else {
sprintf( m_sIdentity, tBuf );
sprintf( tBuffer, "Server Identity Read From Settings: %s", tBuf );
LOG( tBuffer );
};
if( !config_setting_lookup_int( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, &tVal ) ){
tVal = m_nSiteID = 1;
pSetting = config_setting_add( m_pSettings, ARGUS_KERNEL_TAG_SITE_ID, CONFIG_TYPE_INT );
config_setting_set_int( pSetting, tVal );
basicSettingsProvider::getInstance()->compromise();
LOG("Site ID not defined - using [1] as number!");
} else {
m_nSiteID = tVal;
sprintf( tBuffer, "Site ID Read From Settings: %d", m_nSiteID );
LOG( tBuffer );
};
/*
#ifdef __EU_PROJECT__
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_SAFE_SHORE, &tVal ) ){
tVal = m_bSafeShoreSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_SAFE_SHORE, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Safe-Shore support not defined");
} else {
m_bSafeShoreSupport = (bool)tVal;
sprintf( tBuffer, "Safe-Shore support Read From Settings: %d", tVal );
LOG( tBuffer );
};
#endif
if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DEFENDER, &tVal ) ){
tVal = m_bDefenderSupport = true;
pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DEFENDER, CONFIG_TYPE_BOOL );
config_setting_set_bool( pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("Defender support not defined");
} else {
m_bDefenderSupport = (bool)tVal;
sprintf( tBuffer, "Defender support Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, &tVal )){
tVal = m_nWidth = 1000;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_WIDTH, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector Width");
} else {
m_nWidth = tVal;
sprintf( tBuffer, "Detector Width Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, &tVal )){
tVal = m_nKernelFilter = 0x000000ff;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_FILTER_KERNELS, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Fltered Kernels Defined - All LRF Will Work");
} else {
m_nKernelFilter = tVal;
sprintf( tBuffer, "Filter Kernels Read From Settings: %d", tVal );
LOG( tBuffer );
};
if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_DETECTOR_SST, &tVal )){
tVal = m_nSST = 0;
pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DETECTOR_SST, CONFIG_TYPE_INT);
config_setting_set_int(pSetting, tVal );
m_pSettingsProvider->compromise();
LOG("No Detector SST");
} else {
m_nSST = tVal;
sprintf( tBuffer, "Detector SST Read From Settings: %d", tVal );
LOG( tBuffer );
};
if( m_pSettingsProvider->isCompromised() ) {
LOG("Save Settings");
m_pSettingsProvider->validate();
};
*/
} else {
LOG_ERROR("Failed Read Config Settings!");
return false;
};
#ifdef DEBUG
LOG( "Settings Read Done" );
#endif
#ifdef DEBUG
LOG( "Kernel Trhead is about to be Created" );
#endif
if( init() == false ){
LOG_ERROR("Error in starting Kernel Thread!");
return false;
};
#ifdef DEBUG
LOG( "Kernel Thread Created" );
#endif
return true;
};
void ARGUS_Kernel::WaitFinish( bool Force ){
if( Force ){
#ifdef DEBUG
LOG( "Thread End Forced" );
#endif
} else {
// 3 seconds sleep to settle down processes
SLEEP(3000);
};
waitThreadEnd( Force );
#ifdef DEBUG
LOG( "Thread is Detached" );
#endif
};
/* Main Kernel Thread Procedure */
void ARGUS_Kernel::m_fThreadProc( void ){
char Buffer[CTEXT];
time_t tTimeTSeconds;
int lastTSS = 0;
int lastTMS = 0;
#ifdef DEBUG
pid_t pid = gettid();
char pidBuf[16];
sprintf(pidBuf,"pid:%d", pid);
LOG(pidBuf);
#endif
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
if( m_tTimeTSeconds != tTimeTSeconds ){ // Each Second Process
tTimeTSeconds = m_tTimeTSeconds;
};
SLEEP( SLEEP_KERNEL_INTERVAL );
};
};
bool ARGUS_Kernel::setStatus( int A ){
m_bThreadStatus = (thredStatus)A;
};
#undef LOG
#undef LOG_ERROR

58
lib/App/defender/RGoose_Kernel.h

@ -1,58 +0,0 @@
/*******************************************************************
*
* DESCRIPTION: ARGUS Kernel Header File
*
* AUTHOR: gagua
*
* HISTORY:
*
* DATE:5/29/2019
*
*******************************************************************/
#ifndef __ARGUS_KERNEL_HEADER__
#define __ARGUS_KERNEL_HEADER__
#include <linux/videodev2.h>
#include <linux/types.h>
#include "../../alg/generic/md5.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#define SLEEP_KERNEL_INTERVAL 10
#define ONVIF_DISCOVERY_INTERVAL 300 // 5 min
#define ONVIF_DISCOVERY_RESULT_TIME 5
#define ARGUS_KERNEL_TAG_SITE_ID "SITE_ID"
#define ARGUS_KERNEL_TAG_SERVER_IDENTITY "IDENTITY"
#define ARGUS_NODE_SOCK_TYPE_SERIAL_PORT 1
#define ARGUS_NODE_SOCK_TYPE_VIDEO_GRABBER 2
#define ARGUS_NODE_SOCK_TYPE_NETWORK 3
class ARGUS_Kernel: public basicThread {
private:
uint32_t m_nSiteID;
char m_sIdentity[33];
time_t m_tTimeTSeconds;
basicLogCollection * m_pLog;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
uint8_t m_bExitCause;
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit ARGUS_Kernel( config_setting_t *Settings = NULL );
// Destructor
virtual ~ARGUS_Kernel();
bool create( void );
void WaitFinish( bool Force = false );
bool setStatus( int );
uint8_t getExitCause( void ){ return m_bExitCause;};
};
#endif

151
lib/App/mastbaumGUI/main.cpp

@ -1,151 +0,0 @@
#include <winsock2.h>
#include "main_window.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/object/objectFileLoggingService.h"
#define LOG(X) mpLog->Log( "Main", NULL, X )
#define LOG_DEBUG( X ) mpLog->Log( "Main", NULL, _LOG_DEBUG, X )
#define LOG_ERROR( X ) mpLog->Log( "Main", NULL, _LOG_ERROR, X )
//int main(int argc, char *argv[]) {
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){
//Beep(512, 512);
//Beep(256, 256);
//Beep(128, 128);
guiClass *GUI;
GUI = guiClass::getInstance();
GUI->init(0, NULL);//argc, argv);
basicLogCollection *mpLog = basicLogCollection::getInstance();
objectFileLoggingService *fLog;
char tPath[1024];
char *ttPtz=NULL;
//ttPtz = (char *)GUI->getApp()->applicationDirPath().toStdString().c_str();
if( ttPtz!= NULL ){
sprintf(tPath, "%s/my.log", ttPtz);
} else {
sprintf(tPath, "my.log" );
};
fLog = new objectFileLoggingService(tPath);
mpLog->addHandler((basicLoggingService *)fLog);
printf("From now - refer to log file\n");
LOG_DEBUG("ENTER APPLICATION");
basicSettingsProvider *mpSettingsProvider = basicSettingsProvider::getInstance();
config_setting_t *mpSettings;
//mpStorPro->startNewSeries(); // Each prog start starts new Series
#ifdef __linux__
LOG_DEBUG("SS Disabled");
#else
UINT lActiveFlag = 0;
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, NULL, NULL);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
UINT timeoutLowPower;
UINT timeoutPowerOff;
UINT timeoutScreenSave;
{
SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0, &(timeoutLowPower), 0);
SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, &(timeoutPowerOff), 0);
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &(timeoutScreenSave), 0);
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
}
LOG_DEBUG("SS Disabled");
#endif
mpSettings = mpSettingsProvider->getSubNode(NULL, "APPLICATION_GUI");
mainWinow *window;
window = mainWinow::getInstance();
//Check Startup Mode
int gAppStartupMode;
config_setting_t *pSetting;
if (!config_setting_lookup_int(mpSettings, "STARTUP_WINDOW_MODE", &gAppStartupMode )){
gAppStartupMode = 1;
pSetting = config_setting_add(mpSettings, "STARTUP_WINDOW_MODE", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
};
switch( gAppStartupMode ){
case 0: window->show(); break;
case 1: window->showMaximized(); break;
case 2: window->showFullScreen(); break;
default:
gAppStartupMode = 1;
pSetting = config_setting_lookup(mpSettings, "STARTUP_WINDOW_MODE");
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
window->showMaximized();
};
#ifdef __linux__
LOG_DEBUG("SS Enabled");
#else
{
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, timeoutLowPower, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, timeoutPowerOff, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, timeoutScreenSave, NULL, 0);
}
LOG_DEBUG("SS Enabled");
#endif
delete GUI;
delete window;
delete mpSettingsProvider;
#ifdef __linux__
#else
lActiveFlag = 1;
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0);
lActiveFlag = 20;
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
LOG_DEBUG("SS Enabled");
#endif
LOG_DEBUG("EXIT APPLICATION");
delete mpLog;
return 0;
};
#undef LOG
#undef LOG_DEBUG
#undef LOG_ERROR
/*---------------------------------------*/
/* A sample program to play C major */
/* through a PC speaker */
/*---------------------------------------*/
/* This won't work if standard output is */
/* re-directed to a non-tty device, or */
/* PC speaker wave output is active */
/*---------------------------------------*/
/* M.G. 27-Nov-99 */
/*---------------------------------------*/
/*
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/kd.h>
int main(void)
{
int freq[] = { // C D E F G A B C
523, 587, 659, 698, 784, 880, 988, 1046 };
int i;
for (i = 0; i<8; i++)
{
ioctl(STDOUT_FILENO, KIOCSOUND, 1193180 / freq[i]);
usleep(500000);
}
ioctl(STDOUT_FILENO, KIOCSOUND, 0); // Stop silly sound
return 0;
}
*/

437
lib/App/mastbaumGUI/main_window.cpp

@ -1,437 +0,0 @@
#include "main_window.h"
mainWinow* mainWinow::_instance = 0;
void mainWinow::changeEvent(QEvent *event){
if(event->type() == QEvent::WindowStateChange ){
if (!isMinimized()) {
setAttribute(Qt::WA_Mapped);
};
};
};
mainWinow::mainWinow() : QMainWindow(){
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "APPLICATION_GUI");
m_pMainWidget = new QWidget(NULL);
m_pMainWidget->setObjectName("m_pMainWidget");
setCentralWidget(m_pMainWidget);
/*
Layout:
https://www.youtube.com/watch?v=T15mFICDV-U
+--------v--------+
| +---+---+---+ |
| | | |-v-| |
| +---+-h-+---+ |
+-----------------+
| +-----------+ |
| +-----------+ |
+-----------------+
B8-27-EB-78-6A-49
*/
setObjectName("Mainwindow");
m_bUserRecordsVideo = false;
m_pVerticalLayout = new QVBoxLayout( m_pMainWidget );
qDebug() << "m_pVerticalLayout";
m_pVerticalLayout->setSpacing(0);//6
m_pVerticalLayout->setContentsMargins(10, 10, 10, 10);
m_pVerticalLayout->setObjectName("m_pVerticalLayout");
m_pTitleWidget = new TimeShowWidget( m_pMainWidget );
qDebug() << "m_pTitleWidget";
m_pVerticalLayout->addWidget(m_pTitleWidget);
m_pHorizontalLayout = new QHBoxLayout();
qDebug() << "m_pHorizontalLayout";
m_pHorizontalLayout->setObjectName("m_pHorizontalLayout");
m_pHorizontalLayout->setSpacing(0);//6
m_pVerticalMapLayout = new QVBoxLayout();
m_pVerticalMapLayout->setObjectName("m_pVerticalMapLayout");
m_pVerticalMapLayout->setContentsMargins(0, 0, 0, 0);
m_pMapWidget = new MastbaumWidget(m_pMainWidget);
m_pVerticalMapLayout->addWidget(m_pMapWidget);
/* Range Map Mode Controls */
//QHBoxLayout *mpLayout;
mpLayout = new QHBoxLayout();
qDebug() << "mpLayout";
mpLayout->setObjectName("mpLayout");
m_pButton5 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton5";
m_pButton5->setIcon(QIcon(":pictures/appbar.arrow.collapsed.png"));
m_pButton5->setObjectName("MainwindowBtnHBox1B1");
m_pButton5->setIconSize(QSize(40, 40));
m_pButton5->setFixedSize(220, 40);
m_pButton5->setText(QStringLiteral("Show Minimums"));
m_pButton5->setCheckable(true);
m_pButton5->setChecked(true);
m_pButton5->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton5, &QPushButton::clicked, this, &mainWinow::handleMinimumsPress);
mpLayout->addWidget(m_pButton5);
m_pButton6 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton6";
m_pButton6->setIcon(QIcon(":pictures/appbar.arrow.expand.png"));
m_pButton6->setObjectName("m_pButton6");
m_pButton6->setIconSize(QSize(40, 40));
m_pButton6->setFixedSize(220, 40);
m_pButton6->setText(QStringLiteral("Show Maximums"));
m_pButton6->setCheckable(true);
m_pButton6->setChecked(false);
m_pButton6->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton6, &QPushButton::clicked, this, &mainWinow::handleMaximumsPress);
mpLayout->addWidget(m_pButton6);
m_pButton7 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton7";
m_pButton7->setIcon(QIcon(":pictures/appbar.alien.png"));
m_pButton7->setObjectName("m_pButton7");
m_pButton7->setIconSize(QSize(40, 40));
m_pButton7->setFixedSize(220, 40);
m_pButton7->setText(QStringLiteral("Test Working TH"));
m_pButton7->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton7, &QPushButton::clicked, this, &mainWinow::handleGenerateWS);
mpLayout->addWidget(m_pButton7);
m_pButton8 = new QPushButton(m_pMainWidget);
qDebug() << "m_pButton8";
m_pButton8->setIcon(QIcon(":pictures/appbar.camera.png"));
m_pButton8->setObjectName("m_pButton8");
m_pButton8->setIconSize(QSize(40, 40));
m_pButton8->setFixedSize(220, 40);
m_pButton8->setText(QStringLiteral("Take Snap"));
m_pButton8->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButton8, &QPushButton::clicked, this, &mainWinow::handleSave2DPicture);
mpLayout->addWidget(m_pButton8);
mpSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
qDebug() << "mpSpacer";
mpLayout->addItem(mpSpacer);
m_pVerticalMapLayout->addItem(mpLayout);
verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
qDebug() << "verticalSpacer";
m_pVerticalMapLayout->addItem(verticalSpacer);
m_pHorizontalLayout->addItem(m_pVerticalMapLayout);
m_pHorizontalLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);// , 0, Qt::AlignLeft | Qt::AlignTop);
m_pVerticalSideLayout = new QVBoxLayout();
qDebug() << "m_pVerticalSideLayout";
m_pVerticalSideLayout->setObjectName("m_pVerticalSideLayout");
//m_pVerticalSideLayout->setSpacing(3);
m_pVerticalSideLayout->setContentsMargins(0, 0, 11, 0);
m_pButtonCmdClear = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdClear";
m_pButtonCmdClear->setIcon(QIcon(":pictures/appbar.new.png"));
m_pButtonCmdClear->setIconSize(QSize(40, 40));
m_pButtonCmdClear->setFixedSize(220,54);
m_pButtonCmdClear->setText(QStringLiteral("Clear Events Log"));
m_pButtonCmdClear->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdClear, &QPushButton::clicked, this, &mainWinow::callbackClear);
m_pButtonCmdReset = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdReset";
m_pButtonCmdReset->setIcon(QIcon(":pictures/appbar.radar.screen.png"));
m_pButtonCmdReset->setIconSize(QSize(40, 40));
m_pButtonCmdReset->setFixedSize(220,54);
m_pButtonCmdReset->setText(QStringLiteral("Reset Target Detection"));
m_pButtonCmdReset->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
m_pButtonCmdSilence = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdSilence";
m_pButtonCmdSilence->setIcon(QIcon(":pictures/appbar.sound.0.png"));
m_pButtonCmdSilence->setIconSize(QSize(40, 40));
m_pButtonCmdSilence->setFixedSize(220, 54);
m_pButtonCmdSilence->setText(QStringLiteral("Silence Alarm"));
m_pButtonCmdSilence->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdSilence, &QPushButton::clicked, this, &mainWinow::handleSilencePress);
m_pButtonCmdSettings = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdSettings";
m_pButtonCmdSettings->setIcon(QIcon(":pictures/appbar.cog.png"));
m_pButtonCmdSettings->setIconSize(QSize(40, 40));
m_pButtonCmdSettings->setFixedSize(220, 54);
m_pButtonCmdSettings->setText(QStringLiteral("Settings"));
m_pButtonCmdSettings->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdSettings, &QPushButton::clicked, this, &mainWinow::callbackSettings);
m_pButtonCmdReport = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdReport";
m_pButtonCmdReport->setIcon(QIcon(":pictures/appbar.cabinet.files.variant.png"));
m_pButtonCmdReport->setIconSize(QSize(40, 40));
m_pButtonCmdReport->setFixedSize(220, 54);
m_pButtonCmdReport->setText(QStringLiteral("Report"));
m_pButtonCmdReport->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdReport, &QPushButton::clicked, this, &mainWinow::handleReports);
m_pButtonCmdExit = new QPushButton( m_pMainWidget );
qDebug() << "m_pButtonCmdExit";
m_pButtonCmdExit->setIcon(QIcon(":pictures/appbar.power.png"));
m_pButtonCmdExit->setIconSize(QSize(40, 40));
m_pButtonCmdExit->setFixedSize(220, 54);
m_pButtonCmdExit->setText(QStringLiteral("Exit"));
m_pButtonCmdExit->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdExit, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
m_pVerticalSideLayout->addWidget(m_pButtonCmdClear);// , 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdReset);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdSilence);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdReport);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdExit);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
m_pVerticalSideLayout->addWidget(m_pButtonCmdSettings);//, 0, Qt::AlignLeft | Qt::AlignVCenter);
verticalSideSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
qDebug() << "verticalSideSpacer";
m_pVerticalSideLayout->addItem(verticalSideSpacer);
// End Right Menu Layout */
m_pHorizontalLayout->addItem(m_pVerticalSideLayout);
m_pVerticalLayout->addItem(m_pHorizontalLayout);
// Control Panels
m_pTabWidget = new QTabWidget( m_pMainWidget );
qDebug() << "m_pTabWidget";
m_pTabWidget->setObjectName("m_pTabWidget");
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(1);
sizePolicy.setHeightForWidth(m_pTabWidget->sizePolicy().hasHeightForWidth());
m_pTabWidget->setSizePolicy(sizePolicy);
//m_pTabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
/* Layout 1 */
m_pPage1 = new QWidget(m_pTabWidget);
m_pPage1->setObjectName("m_pPage1");
m_pPage1Layout = new QHBoxLayout(m_pPage1);
m_pPage1Layout->setObjectName("m_pPage1Layout");
//m_pEventsList = new EventViewerList(m_pPage1);
//m_pEventsList->setObjectName("m_pEventsList");
//m_pPage1Layout->addWidget(m_pEventsList);// , 0, Qt::AlignLeft | Qt::AlignTop);
m_pTabWidget->addTab(m_pPage1, QString("Events Log"));
/* Layout 2 */
m_pPage2 = new QWidget(m_pTabWidget);
m_pPage2Layout = new QHBoxLayout(m_pPage2);
m_pPage2Layout->setObjectName("m_pPage2Layout");
m_pMainVideoWidget = new VideoWidget( m_pPage2 );
m_pMainVideoWidget->init();
m_pMainVideoWidget->setError( true, "No Source Choisen" );
//
m_pScrollArea = new QScrollArea(m_pPage2);
QSizePolicy sPolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
sPolicy.setHeightForWidth(m_pScrollArea->sizePolicy().hasHeightForWidth());
m_pScrollArea->setSizePolicy(sPolicy);
m_pScrollArea->setMinimumSize(QSize(0, 100)); // 200
m_pScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pScrollArea->setWidgetResizable(true);
m_pScrollAreaWidgetContents = new VideoSourceChooser( m_pPage2 );
m_pScrollArea->setWidget(m_pScrollAreaWidgetContents);
m_pScrollAreaWidgetContents->setMainMediaViewer( m_pMainVideoWidget );
m_pMainVideoWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
m_pVVVLayout = new QVBoxLayout(m_pPage2);
m_pVVVLayout->setObjectName("m_pVVVLayout");
m_pVVVLayout->addWidget(m_pMainVideoWidget);
m_pPage2Layout->addItem( m_pVVVLayout );
m_pVCVLayout = new QVBoxLayout(m_pPage2);
m_pVCVLayout->setObjectName("m_pVCVLayout");
m_pVCVLayout->addWidget(m_pScrollArea);
m_pButtonCmdVideoRecord = new QPushButton( m_pPage2 );
m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
m_pButtonCmdVideoRecord->setIconSize(QSize(40, 40));
//m_pButtonCmdVideoRecord->setFixedSize(220, 54);
m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
m_pButtonCmdVideoRecord->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdVideoRecord, &QPushButton::clicked, this, &mainWinow::handleVideoRecorder);
m_pVCVLayout->addWidget(m_pButtonCmdVideoRecord);
m_pVSpacer2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
m_pVCVLayout->addItem(m_pVSpacer2);
m_pPage2Layout->addWidget(m_pScrollArea);
m_pPage2Layout->addItem(m_pVCVLayout);
m_pTabWidget->addTab(m_pPage2, QString("Video Surveillance"));
/* Layout 3 */
m_pPage3 = new QWidget(m_pTabWidget);
m_pPage3Layout = new QVBoxLayout(m_pPage3);
m_pPage3Layout->setObjectName("m_pPage3Layout");
//m_pPage3Layout->addItem(mpLayout);
/* New Device Management */
m_pDevScrollArea = new QScrollArea(m_pPage3);
QSizePolicy sDPolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
sDPolicy.setHeightForWidth(m_pScrollArea->sizePolicy().hasHeightForWidth());
m_pDevScrollArea->setSizePolicy(sDPolicy);
m_pDevScrollArea->setMinimumSize(QSize(0, 400));
m_pDevScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
m_pDevScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pDevScrollArea->setWidgetResizable(true);
//m_pDevScrollAreaWidgetContents = new DeviceChooser( this );
//m_pDevScrollArea->setWidget( m_pDevScrollAreaWidgetContents );
//m_pDevScrollAreaWidgetContents->setMainMediaViewer(m_pMainVideoWidget);
m_pPage3Layout->addWidget(m_pDevScrollArea);
m_pTabWidget->addTab(m_pPage3, QString("Device Controll"));
/* Tab 4 */
m_pPage4 = new QWidget(m_pTabWidget);
m_pPage4Layout = new QVBoxLayout(m_pPage4);
m_pPage4Layout->setObjectName("m_pPage4Layout");
//m_pGLRadar = new GLRadar( m_pPage4, QColor(0, 0, 0));
//m_pPage4Layout->addWidget(m_pGLRadar);
m_pTabWidget->addTab(m_pPage4, QString("3D View"));
/* Tab 5 */
m_pPage5 = new QWidget(m_pTabWidget);
m_pPage5Layout = new QVBoxLayout(m_pPage5);
m_pPage5Layout->setObjectName("m_pPage5Layout");
//m_pRangeRadar = new RadarMapWidget(m_pPage5);
//m_pPage5Layout->addWidget(m_pRangeRadar);
m_pTabWidget->addTab(m_pPage5, QString("2D View"));
m_pVerticalLayout->addWidget(m_pTabWidget);
//connect(m_pScrollAreaWidgetContents->m_pButtonCmdAdd, SIGNAL(clicked()), m_pScrollAreaWidgetContents, SLOT(m_pScrollAreaWidgetContents->showAddSourceDialog()));
resize(800, 600);
setWindowTitle( "3D Single IPI" );
setWindowIcon( QIcon(":pictures/status/gray-240.png") );
m_pStatusBar = new QStatusBar(this);
m_pStatusBar->setObjectName(QStringLiteral("statusBar"));
m_pStatusBar->setStyleSheet(QStringLiteral("background-color: rgb(255, 170, 0);"));
setStatusBar(m_pStatusBar);
//m_pDevScrollAreaWidgetContents->setSelectedDevice(0);
};
mainWinow::~mainWinow(){
//delete(m_pScrollAreaWidgetContents);
};
/**
* Returns the single instance of the object.
*/
mainWinow* mainWinow::getInstance() {
// check if the instance has been created yet
if (0 == _instance){
// if not, then create it
_instance = new mainWinow();
};
// return the single instance
return _instance;
};
void mainWinow::callbackSettings(void){
//if (m_pDeviceSettings == NULL){
// m_pDeviceSettings = new DialogSettingsLGS(this);
// m_pDeviceSettings->attachMasterDevice( m_pMasterDevice );
// m_pDeviceSettings->attachSlaveDevice( m_pSlaveDevice );
//};
//m_pDeviceSettings->updateValues();
//m_pDeviceSettings->show();
};
void mainWinow::callbackClear(void){
//m_pEventsList->clear();
//m_pGLRadar->clearTargets();
//m_pRangeRadar->clearTargets();
//m_pRangeMap->clearTargets();
//m_pTitleWidget->setStatus( TSW_ARMING );
};
void mainWinow::handleButtonPress(){
QString fileName;
fileName = QFileDialog::getOpenFileName(this, "Open Data", "data/", "Data Files (*.raw *.jpg *.bmp)");
char fName[MAX_PATH];
sprintf(fName, "%s", fileName.toStdString().c_str() );
//m_pRangeMap->loadFromFile(fName);
//m_pGLRadar->loadFromFile(fName);
};
void mainWinow::handleMaximumsPress(){
m_pButton5->setChecked(false);
m_pButton6->setChecked(true);
//m_pRangeMap->setMaximums();
//m_pRangeRadar->setMaximums();
};
void mainWinow::handleMinimumsPress(){
m_pButton5->setChecked(true);
m_pButton6->setChecked(false);
//m_pRangeMap->setMinimums();
//m_pRangeRadar->setMinimums();
};
void mainWinow::handleGenerateWS(){
//m_pRangeMap->startGenerateWS();
};
void mainWinow::handleSave2DPicture( void ){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save 2D Map As", "data/", "Picture Files (*.png *.jpg *.bmp)");
//m_pRangeMap->savePicture(fileName);
};
void mainWinow::handleSave3DPicture( void ){
QString fileName;
fileName = QFileDialog::getSaveFileName(this, "Save 3D Picture As", "data/", "Picture Files (*.png)");
//QPixmap image = QPixmap::grabWidget(m_pGLRadar);
//if(!image.save(fileName, "PNG")){
// QMessageBox::warning(this, "Save Image", "Error saving image.");
//};
};
void mainWinow::handleAddMask(){
//if( m_pRangeMap!= NULL ){
// m_pRangeMap->setAddMaskMode();
//};
};
void mainWinow::handleDeleteMask(){
//if (m_pRangeMap != NULL){
// m_pRangeMap->setDeleteMaskMode();
//};
};
void mainWinow::handleSilencePress(){
//basicEvent *pEvt;
//basicCameraCommand *tData;
//absCameraMoveParam *tParam;
//tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
//tParam = (absCameraMoveParam*) malloc(sizeof(absCameraMoveParam));
//tData->m_cCode = CMD_CAMERA_SET_PTZ;
//tData->m_pParam = tParam;
//tParam->m_fPan = 180.f;
//tParam->m_fTilt = 0.f;
//tParam->m_fRange = 1.f;
//pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "Test Event", tData );
//basicEventHeap::getInstance()->broadcast(pEvt);
};
void mainWinow::handleVideoRecorder(){
//basicEvent *pEvt;
//basicCameraCommand *tData;
//tData = (basicCameraCommand*) malloc(sizeof(basicCameraCommand));
//tData->m_pParam = NULL;
//if(!m_bUserRecordsVideo){
// Generate Video Event -> Starts Record
//tData->m_cCode = CMD_CAMERA_START_RECORD;
//pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "User Starts Record Video", tData );
//basicEventHeap::getInstance()->broadcast(pEvt);
//m_bUserRecordsVideo = true;
//m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.control.stop.png"));
//m_pButtonCmdVideoRecord->setText(QStringLiteral("Stop Record"));
//} else {
//tData->m_cCode = CMD_CAMERA_STOP_RECORD;
//pEvt = createBasicEvent( 0, EVT_CLASS_IMAGE, EVT_COMMAND, "User Stops Record Video", tData );
//basicEventHeap::getInstance()->broadcast(pEvt);
//m_bUserRecordsVideo = false;
//m_pButtonCmdVideoRecord->setIcon(QIcon(":pictures/appbar.cabinet.in.png"));
//m_pButtonCmdVideoRecord->setText(QStringLiteral("Start Record"));
//};
};
void mainWinow::handleReports(){
//if (m_pReportManager == NULL ){
// m_pReportManager = new guiReportsManagerWindow((QDialog *)this);
//};
//m_pReportManager->showMaximized();
};

135
lib/App/mastbaumGUI/main_window.h

@ -1,135 +0,0 @@
#ifndef __QT5_MAIN_WINDOW_HEADER__
#define __QT5_MAIN_WINDOW_HEADER__
#include <WinSock2.h>
#include "../../components/base/basicSettingsProvider.h"
#include "../../gui/guiClass.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../gui/controls/VideoWidget.h"
#include "../../gui/controls/VideoSourceChooser.h"
#include "../../gui/controls/TimeShowWidget.h"
#include "../../gui/controls/MastBaumWidget.h"
class mainWinow : public QMainWindow{
private:
config_setting_t *m_pSettings;
/* Main Widget */
QWidget *m_pMainWidget;
/* Layouts */
QMainWindowLayout *m_pMainLayout;
QVBoxLayout *m_pVerticalLayout;
QVBoxLayout *m_pVerticalMapLayout;
QVBoxLayout *m_pVerticalSideLayout;
QHBoxLayout *m_pHorizontalLayout;
QHBoxLayout *m_pScrolbarLayout;
QVBoxLayout *m_pVVVLayout;
QVBoxLayout *m_pVCVLayout;
QPushButton *m_pButtonCmdVideoRecord;
QSpacerItem *m_pVSpacer1;
QSpacerItem *m_pVSpacer2;
QSpacerItem *m_pVSpacer3;
/* Widgets */
TimeShowWidget *m_pTitleWidget;
MastbaumWidget *m_pMapWidget;
QFrame *m_pTitleFrame;
QStatusBar *m_pStatusBar;
QSpacerItem *verticalSpacer;
QSpacerItem *verticalSideSpacer;
QSpacerItem *horisontalSpacer;
QSpacerItem *scrolbarSpacer;
QPushButton *m_pButtonCmdClear;
QPushButton *m_pButtonCmdReset;
QPushButton *m_pButtonCmdSilence;
QPushButton *m_pButtonCmdReport;
QPushButton *m_pButtonCmdExit;
QPushButton *m_pButtonCmdSettings;
QScrollArea *m_pScrollArea;
VideoSourceChooser *m_pScrollAreaWidgetContents;
QScrollArea *m_pDevScrollArea;
QPushButton *m_pAddVideoSource;
VideoWidget *m_pMainVideoWidget;
//Control Panels
QTabWidget *m_pTabWidget;
QWidget *m_pPage1;
QWidget *m_pPage2;
QWidget *m_pPage3;
QWidget *m_pPage4;
QWidget *m_pPage5;
QHBoxLayout *m_pPage1Layout;
QHBoxLayout *m_pPage2Layout;
QVBoxLayout *m_pPage3Layout;
QVBoxLayout *m_pPage4Layout;
QVBoxLayout *m_pPage5Layout;
QPushButton *m_pButton1;
QPushButton *m_pButton2;
QPushButton *m_pButton3;
QPushButton *m_pButton4;
QPushButton *m_pButton5;//Add Mask
QPushButton *m_pButton6;//Delete Mask
QPushButton *m_pButton7;//Activate Masks
QPushButton *m_pButton8;//Deactivate Masks
QHBoxLayout *mpLayout;
QSpacerItem *mpSpacer;
QProgressBar *m_pProgressBar;
QHBoxLayout *m_pHorizontalLayout1;
QHBoxLayout *m_pHorizontalLayout2;
QHBoxLayout *m_pHorizontalLayout3;
QRadioButton *m_pRadioButton1;
QRadioButton *m_pRadioButton2;
QGroupBox *m_pRadioGroup;
QGroupBox *m_pSampleGroup;
QComboBox *m_pLRFCombo;
QLabel *m_pStMiRalabel;
QLabel *m_pStMaRalabel;
QLabel *m_pStMiSalabel;
QLabel *m_pStMaSalabel;
QLabel *m_pStMiRaVal;
QLabel *m_pStMaRaVal;
QLabel *m_pStMiSaVal;
QLabel *m_pStMaSaVal;
QLabel *m_pOpLabel;
bool m_bUserRecordsVideo;
private slots:
void handleSilencePress();
void handleButtonPress();
void handleButton2Press();
void handleMaximumsPress();
void handleMinimumsPress();
void handleGenerateWS();
void handleSave2DPicture( void );
void handleSave3DPicture(void);
void handleAddMask();
void handleDeleteMask();
void handleUpdateMask();
void handleSetStatusMask();
void handleVideoRecorder();
void handleReports();
QPixmap *notepixmap;
public:
static mainWinow* getInstance();
virtual ~mainWinow();
protected:
mainWinow();
void changeEvent(QEvent *event);
private:
static mainWinow* _instance;
mainWinow(const mainWinow& src);
mainWinow& operator=(const mainWinow& src);
public slots:
void callbackSettings(void);
void callbackClear(void);
};
#endif

126
lib/App/mastbaumSERVER/ClientHandler.cpp

@ -1,126 +0,0 @@
#include "ClientHandler.h"
#include "Kernel.h"
#define LOG( X ) m_pLog->Log( "ClientHandler", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "ClientHandler", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "ClientHandler", this, _LOG_ERROR, X );
#endif
ClientHandler::ClientHandler( int SockFD ): networkClientHandler( SockFD ), interProcProto(){
m_pLog = basicLogCollection::getInstance();
m_bRunning = false;
if( m_pPort != NULL ){
LOG("server port is OK");
if( create() ){
setConnectionStatus( CS_INIT );
m_pPort->addRecipient(( protocolParser *)this );
m_bRunning = true;
#ifdef DEBUG
LOG( "Protocol Parser Created!");
#endif
} else {
LOG_ERROR( "Protocol Parser Creation Failed!");
};
} else {
LOG_ERROR( "Port Error In Client Handler Constructor!");
};
};
// Destructor implementation
ClientHandler::~ClientHandler(){
# ifdef DEBUG
LOG("Destructor Start");
# endif
# ifdef DEBUG
LOG("Destructor Finished!");
# endif
};
bool ClientHandler::create(void){
return interProcProto::create();
};
bool ClientHandler::sendFrame( cv::Mat &frame ){
//LOG("SendFrame!");
vector<int> compression_params;
//compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
//compression_params.push_back(9);
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(75);
vector<uchar> buf;
int DataSize;
imencode( ".jpg", frame, buf, compression_params );
DataSize = buf.size();
//uint8_t Buffer[32768];
uint8_t *pData = buf.data();
//memcpy( Buffer+3, pData, buf.size() );
//return m_pPort->sendData( Buffer, FinishUpPackage( Buffer, DataSize + 3 ) );
return m_pPort->sendData( pData, DataSize );
};
bool ClientHandler::packetHandler( protocolPackage *Package ){
if( Package != NULL ) {
#ifdef DUBUG_COMMUNICATION
LOG("Package Handler");
char tBuffer[256];
sprintf( tBuffer, "Package Code: %d 0x%02X", Package->m_nCode, Package->m_nCode );
LOG( tBuffer );
#endif
switch(Package->m_nCode){
case CMD_FRAME:
#ifdef DEBUG
//LOG("Get Frame Request");
#endif
if( m_pEngine!= NULL ) {
((Kernel*)m_pEngine)->copyFrame(tFrame);
//LOG("Frame Copied");
sendFrame(tFrame);
//LOG("Frame Sent");
} else {
setConnectionStatus( CS_DISCONNECTED );
};
break;
case CMD_QUIT:
#ifdef DEBUG
LOG("QUIT Request");
#endif
break;
default:
#ifdef DEBUG
LOG_ERROR( "Not Implemented Command Was received" );
#endif
break;
};
free( Package->m_pData );
free( Package );
};
return true;
};
void ClientHandler::dispatchEvent( basicEvent *Evt ){
//LOG( "CLIENT's DISPATCHER");
if( Evt == NULL ) return;
if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
switch( Evt->m_eType ) {
case EVT_TARGET_WHITE:
case EVT_TARGET_BLACK:
case EVT_TARGET:
default:
LOG_ERROR("Unknown Event!");
};
} else {
#ifdef DEBUG
LOG( "No SENSOR EVT ");
#endif
};
};
#undef LOG
#undef LOG_ERROR

34
lib/App/mastbaumSERVER/ClientHandler.h

@ -1,34 +0,0 @@
#ifndef __CLIENTHANDLER_H_INCL__
#define __CLIENTHANDLER_H_INCL__
//#define DUBUG_COMMUNICATION
#include "../../data/net/netClientHandler.h"
#include "interProcessProto.h"
#define CMD_FRAME 0xA5
#define CMD_QUIT 0xE3
/**
* TODO: Add class description
*
* @author Gagua
*/
class ClientHandler : public networkClientHandler, public interProcProto{
private:
basicLogCollection * m_pLog;
bool m_bRunning;
cv::Mat tFrame;
protected:
bool packetHandler( protocolPackage *Package );
bool sendFrame( cv::Mat &frame );
public:
// Constructor
explicit ClientHandler( int SockFD );
virtual ~ClientHandler();
bool create(void);
void dispatchEvent( basicEvent *Evt );
bool getStatus( void ){ return CS_CONNECTED == getConnectionStatus(); };
};
#endif // __LRF_CLIENTHANDLER_H_INCL__

1326
lib/App/mastbaumSERVER/Kernel.cpp
File diff suppressed because it is too large
View File

239
lib/App/mastbaumSERVER/Kernel.h

@ -1,239 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: LRF_Kernel.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of LRF_Kernel.cpp
//----------------------------------------------------------------------------
//
#ifndef __KERNEL_H_INCL__
#define __KERNEL_H_INCL__
#define MULTI_TARGETS
#define NO_GPIO_HANDLER
#define DUMP_TH_AFTER_FLIP_ON_DISK
#define MAX_LOCAL_VIDEO_SOURCES 5
#define MAX_LRF_SENSORS 9
#define USE_TIME_LAPSE_RECORDER
#include "../../components/base/basicEngine.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicMutex.h"
#include "../../components/base/basicRing.h"
#include "../../components/base/basicMediaDestination.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicEventHeap.h"
#include "../../data/storage/storageProvider.h"
#include "../../data/mysql/database_class.h"
#include "../../data/net/netServer.h"
#include "../../alg/lgs/detector.h"
#include "../../alg/lgs/mask.h"
#include "../../data/media/videoNode.h"
#include "../../data/media/video/videoAVLIBSource.h"
#include "../../data/media/video/videoV4L2Source.h"
#include "../../data/protocol/protocolMastBaum.h"
#ifdef USE_TIME_LAPSE_RECORDER
#include "../../data/media/lapsedVideoRecorder.h"
#else
#define ASSEMBLE_MP4
#ifdef ASSEMBLE_MP4
#include "../../data/media/video/videoAVLIBDestination.h"
//#define KEEP_JPEG_IMAGES
#endif
#endif
#define MAX_CYCLE_COUNTER_VALUE 0xFFFFFFFF;
#define SLEEP_KERNEL_INTERVAL 10 // 10 millisecond
#define TIME_SYNC_INTERVAL 900000 // 15 minute(s) in 1 millisecond units
#define STATUS_OK_INTERVAL 2000 // 2 Sec in 1 millisecond units
#define KNL_SETTINGS_MAIN_TAG ((CSTR)"KERNEL")
#define KNL_SETTINGS_DETECT_ARMED ((CSTR)"DETECTION_ARMED") //bool
#define KNL_SETTINGS_DETECT_OFFSET ((CSTR)"DETECTION_OFFSET") //int
#define KNL_SETTINGS_DETECT_SST ((CSTR)"DETECTION_SST") //int
#define KNL_SETTINGS_DETECT_LAYER_DIST ((CSTR)"DETECTION_LAYER_DIST") //float
#define KNL_SETTINGS_DETECT_MAX_RANGE ((CSTR)"DETECTION_MAX_RANGE") //float
#define KNL_SETTINGS_DETECT_MIN_SPEED ((CSTR)"DETECTION_MIN_SPEED") //float
#define KNL_SETTINGS_VIDEO_ENGINE ((CSTR)"VIDEO_ENGINE") //bool
#define KNL_SETTINGS_VIDEO_OUTPUT ((CSTR)"MP4_ENABLE") //bool
#define KNL_SETTINGS_DATABASE_ENA ((CSTR)"DB_ENABLE") //bool
#define KNL_SETTINGS_DATABASE_HOST ((CSTR)"DB_HOST") //str
#define KNL_SETTINGS_DATABASE_NAME ((CSTR)"DB_NAME") //str
#define KNL_SETTINGS_DATABASE_USER ((CSTR)"DB_USER") //str
#define KNL_SETTINGS_DATABASE_PASS ((CSTR)"DB_PASS") //str
#define KNL_SETTINGS_STORAGE_BASE ((CSTR)"STORAGE_BASE") //str
#define KNL_SETTINGS_SERIAL_PORT ((CSTR)"COM_PORT") //str
#define KNL_SETTINGS_SERIAL_SPEED ((CSTR)"COM_SPEED") //int
#define KNL_SETTINGS_FRAME_COMPOSE ((CSTR)"FRAME_COMPOSITION") //??
#define KNL_SETTINGS_FRAME_COMPOSE_DIM ((CSTR)"FRAME_DIMENTION") //??
#define KNL_SETTINGS_VIDEO_ROTATION ((CSTR)"VIDEO_ROT") //int
#define KNL_SETTINGS_VIDEO_SECTION ((CSTR)"VIDEO_INPUTS")
#define KNL_SETTINGS_VIDEO_INPUT_ID ((CSTR)"VIDEO_INPUT_ID") //int
#define KNL_SETTINGS_VIDEO_INPUT_WIDTH ((CSTR)"VIDEO_INPUT_WIDTH") //int
#define KNL_SETTINGS_VIDEO_INPUT_HEIGHT ((CSTR)"VIDEO_INPUT_HEIGHT") //int
#define KNL_SETTINGS_VIDEO_SCALE_WIDTH ((CSTR)"VIDEO_SCALE_WIDTH") //int
#define KNL_SETTINGS_VIDEO_SCALE_HEIGHT ((CSTR)"VIDEO_SCALE_HEIGHT") //int
#define KNL_SETTINGS_VIDEO_INPUT_FPS ((CSTR)"VIDEO_INPUT_FPS") //float
#define KNL_SETTINGS_CONVERT_TYPE ((CSTR)"CONVERT_TYPE") //int
#define WEB_CMD_NOP 0
#define WEB_CMD_RESET_DETECTION 1
#define WEB_CMD_SET_PARAMS 2
#define WEB_CMD_CLEAR_LOG 3
#define WEB_CMD_DISABLE_DETECTION 4
#define WEB_CMD_ENABLE_DETECTION 5
#define WEB_CMD_MAKE_TEST_ALARM 6
#define WEB_CMD_RESET_DEVICE 7
#define FSL_SYSTEM_STARTUP 0
#define FSL_CONNECT_DISARMED 1
#define FSL_CONNECT_ARMED 2
#define FSL_OPERATOR_DISARMED 3
#define FSL_OPERATOR_ARMED 4
#define FSL_ALARM 5
#define FSL_OPERATOR_ALARM 6
#define FSL_DETECTION_CHANGED 7
#define FSL_LOG_CLEARED 8
#define FSL_TARGET_OVERFLOW 9
#define FSL_DETECTION_RESTORED 10
#define FSL_SYSTEM_RESTARTED 251
#define FSL_SYSTEM_SHUTDOWN 255
#define ST_NO_TASK 0
#define ST_CHECK_STATUS 1
#define ST_CHECK_SETTINGS 2
#define ST_ISSUE_SOFT_RESET 3
#define ST_TURN_OFF_LED 4
#define ST_SEND_SETTINGS 5
#define ST_SEND_WMODE 6
// https://www.bhphotovideo.com/c/product/1076400-REG/sony_ilce_5100l_b_alpha_a5100_mirrorless_digital.html
// https://www.bhphotovideo.com/c/product/1354807-REG/canon_eos_m20_mirrorless_digital.html
//https://github.com/gphoto
//http://www.gphoto.org/proj/libgphoto2/support.php
/**
* LRF_Kernel class - manages communication between client
* handlers and PRU cores bseide of Event management.
*
*
* @author gagua
*/
#define MAX_RECORD_FRAMES 120
#define MAX_TARGET_ACCEPTED_AT_ONCE 100
typedef basicRing< cv::Mat > MatRing;
class Kernel: public basicEngine, public basicThread, public basicMediaDestination {
private:
bool m_bDetectorArmed;
int m_nDetectorOffset;
int m_nDetectorSST;
float m_fDetectorMaxDistance;
// Not Using for Now
float m_fDetectorLayerDistance;
float m_fDetectorMinSpeed;
basicLogCollection * m_pLog;
basicEventHeap * m_pEventHeap;
config_setting_t * m_pSettings;
basicSettingsProvider * m_pSettingsProvider;
networkServer * m_pNetClientsServer;
storageProvider * m_pStorageProvider;
MySQL_Connector * m_pDataBase;
CSTR m_pDBHost, m_pDBUser, m_pDBPass, m_pDBName, m_pStorageBase;
uint8_t m_bExitCause;
uint8_t m_bTargetOverflow;
int m_nVideoInputs;
int m_nAlarmCnt;
bool m_bEngineIsAvlib;
int m_nConvertType;
basicMediaSource ** m_pVideoInputs;
#ifdef USE_TIME_LAPSE_RECORDER
lapsedVideoRecorder * m_pVideoOutput;
#endif
CSTR * m_pVideoNames;
int m_nWidth;
int m_nHeight;
int m_nPictureRot;
bool m_bDatabaseEnable;
bool m_bPictureRotated;
bool m_bHorizontal;
bool m_bRecordIsActive;
bool m_bRecordIsSaving;
bool m_bEventRegistered;
bool m_bScaleFrames;
bool m_bAssembleMP4;
char m_sSeriesName[MAX_PATH];
char m_sWEBAPIName[MAX_PATH];
char m_sWEBStatus[MAX_PATH];
char m_sFSReportName[MAX_PATH];
uint16_t m_nLRF_Background[MAX_LRF_SENSORS];
#ifdef AMIR_MODE
uint32_t m_nCurrentRange;
#endif
uint32_t m_nInitialFSID;
uint32_t m_nRecordCounter;
uint32_t m_nFrameCounter;
basicMutex * m_pMatProtector;
cv::Mat * m_pFinalFrame;
cv::Mat ** m_pVideoFrame;
#ifndef USE_TIME_LAPSE_RECORDER
cv::Mat * m_pVidRecFrame[MAX_RECORD_FRAMES];
MatRing m_rPrerecord;
#endif
uint32_t m_nCLoopMask;
uint32_t m_nCLoopCheck;
uint32_t m_nCOnlineMask;
uint32_t m_nCOKMask;
uint32_t m_nScheduledTaskCounter;
uint8_t m_nScheduledTaskID;
long long m_lStartTS;
#ifndef USE_TIME_LAPSE_RECORDER
pthread_t m_pSaveThreadHandler;
static void * t_fSavePictures_Proc(void *ptr);
#endif
void putEvent2FS( uint8_t code, int x1=0, int y1=0, int x2=0, int y2=0, float speed = 0, bool has_image=false, CSTR path = NULL );
void postStatus2FS( bool isActive = true );
bool getDevicePath(CSTR Path, CSTR BusID );
protocolMastBaum * m_pProtocol;
enumeratorInfo m_InputInfo;
protected:
void m_fThreadProc( void );
public:
// Constructor
explicit Kernel( CSTR *HM = NULL );
// Destructor
virtual ~Kernel();
bool create( CSTR *ptr = NULL, networkServer *srvPort = NULL );
bool attachNetServer( networkServer *srvPort );
void WaitFinish( bool Force = false );
virtual void pushFrame( cv::Mat *Frame, void *src = NULL );
bool copyFrame( cv::Mat &Frame );
#ifdef AMIR_MODE
void setRange( uint32_t r ){ m_nCurrentRange = r; };
#endif
/* functional API */
void alarm( bool real = true );
void updateStatus( bool ArmMode, uint8_t nCount, uint16_t *bgArray = NULL );
void updateSettings( uint16_t offset, uint16_t min_time, uint8_t sst, uint32_t ol_status, uint32_t ok_status );
void updateTarget( uint8_t LRF, uint8_t Range );
void handleTargets( uint32_t tMask, uint8_t cnt, uint8_t *Ranges );
bool askReset( void );
bool reset( bool FullRestart = false );
bool shutdown( bool Restart = false );
uint8_t getExitCause( void ){ return m_bExitCause; };
};
#endif // __LRF_KERNEL_H_INCL__

16
lib/App/mastbaumSERVER/NetworkManager.cpp

@ -1,16 +0,0 @@
#include "NetworkManager.h"
#include "ClientHandler.h"
NetworkManager::NetworkManager(): networkServer(){
};
NetworkManager::~NetworkManager(){
};
networkClientHandler *NetworkManager::attachHandler( int SID ){
ClientHandler *ptr;
ptr = new ClientHandler(SID);
return ptr;
};
bool NetworkManager::deleteHandler( networkClientHandler *ptr ){
if( ptr == NULL ) return false;
delete((ClientHandler *) ptr );
return true;
};

16
lib/App/mastbaumSERVER/NetworkManager.h

@ -1,16 +0,0 @@
#ifndef __NETWORK_MANAGER_HEADERS__
#define __NETWORK_MANAGER_HEADERS__
#include "../../data/net/netServer.h"
class NetworkManager: public networkServer{
private:
public:
NetworkManager();
virtual ~NetworkManager();
virtual networkClientHandler * attachHandler( int SID );
virtual bool deleteHandler( networkClientHandler *ptr );
};
#endif //__NETWORK_MANAGER_HEADERS__

516
lib/App/mastbaumSERVER/Server.cpp

@ -1,516 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2018. All Rights Reserved.
// Version 1.0 12/12/2018
// Last modification: 12/12/2018
// PROJECT: MastBaum
// SUBSYSTEM: Raspbery Pi Raspbian Linux
// FILE: Server.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of Server.cpp
//----------------------------------------------------------------------------
//
#include "Server.h"
typedef enum {
ST_NONE = -1,
ST_SN = 0,
ST_BIND_ADDRESS,
ST_BIND_PORT,
ST_PID_FILE,
ST_LOG_FILE,
ST_LOG_ENABLE,
ST_INTERACTIVE,
ST_SMS_ENABLE,
ST_EMAIL_ENABLE,
ST_SMS_PROVIDER,
ST_DATABASE_SERVER,
ST_DATABASE_USER,
ST_DATABASE_PASSWORD,
ST_DATABASE_NAME,
ST_SOCKET_NAME
} SETTING_TYPE;
CSTR m_pSetting[] = {
(CSTR)"SN",
(CSTR)"BIND_ADDRESS",
(CSTR)"BIND_PORT",
(CSTR)"PID_FILE",
(CSTR)"LOG_FILE" ,
(CSTR)"LOG_ENABLED",
(CSTR)"INTERACTIVE",
(CSTR)"SMS_ENABLE",
(CSTR)"EMAIL_ENABLE",
(CSTR)"SMS_PROVIDER",
(CSTR)"DATABASE_SERVER",
(CSTR)"DATABASE_USER",
(CSTR)"DATABASE_PASSWORD",
(CSTR)"DATABASE_NAME",
(CSTR)"SOCKET_NAME"
};
// Global Variables
CSTR gsCFG_ADDRESS;
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT;
CSTR gsCFG_LICENSE;
CSTR gsCFG_DB_SERVER;
CSTR gsCFG_DB_NAME;
CSTR gsCFG_DB_USER;
CSTR gsCFG_DB_PASSWORD;
CSTR gsCFG_PID_FILE = (CSTR) DEFAULT_SERVER_PID_FILE;
SOFTWARE_INFO gsSOFT_INFO;
bool gbCFG_MASTER_ROLE = true;
bool gModule_GeoFence_Enabled = true;
bool gModule_SMS_Enabled = false;
bool gModule_Email_Enabled = false;
bool gSignal_Handler_Enabled = true;
#define LOG( X ) m_pLog->Log( "main", 0, X )
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
Kernel *m_pKernel = NULL;
//LRF_HardwareManager *HWManager = NULL;
basicLogCollection *m_pLog = NULL;
NetworkManager *mpNetworkManager = NULL;
void (*old_kill_handler_9)(int);
void (*old_kill_handler_15)(int);
void signal_kill_handler( int SIG ){
if( m_pKernel!= NULL ){
if( gSignal_Handler_Enabled ){
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" );
//m_pKernel->setStatus( TH_ENDED ); // Closing all Connections;
m_pKernel->shutdown(false);
} else {
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" );
};
};
};
#ifndef NO_GPIO_HANDLER
void myInterrupt4(void){
//LOG("HW_SIGNAL_PIO4");
m_pKernel->alarm();
};
#endif
int main( int argc, char *argv[] ){
//_Core_Channel_Collection *CDC = NULL;
//MySQL_Connector *DBC = NULL;
bool WBG; // Working Background
bool FLE; // File Logging Engine
bool SSE; // Server Statistics Engine
bool NDC; // No Default Configuration
CSTR FLE_NAME;
CSTR DCF_NAME;
CSTR SSP_NAME;
// default init
WBG = true;
FLE = true;
FLE_NAME = (CSTR) DEFAULT_SERVER_LOG_FILE;
SSE = true;
NDC = true;
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH;
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH;
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP;
gsSOFT_INFO.DATA_VALID = false;
gsSOFT_INFO.SW_MODE_FLAGS = 0
#ifdef SKIP_TARGET_LOG
| SW_INFO_NO_TARGET_LOG
#endif
#ifdef HIBERNATE_ENABLE
| SW_INFO_HIBERNATE_ENA
#endif
#ifdef TGD
| SW_INFO_TGD_MOTORS
#ifdef TGD_VERSION_2
| SW_INFO_TGD_VER_2
#endif
#endif
#ifdef ENCODER_8192
| SW_INFO_EU_PROJECT
#endif
#ifdef NO_BLACK_TARGETS
| SW_INFO_NO_BLACK_TARGETS
#endif
#ifndef NO_MOTORS
| SW_INFO_MOTOR_CTRL_ENA
#endif
#ifdef THREADED_FLIP
| SW_INFO_THREAD_FLIP
#endif
#ifndef PRU_SLAVE
| SW_INFO_FLAG_MASTER
#endif
#ifdef DEBUG
| SW_INFO_DEBUG_MODE
#endif
;
// Reading Config
if( argc > 1 ){
for( int i = 0; i < argc; i++ ){
switch( argv[i][0] ){
case '-':
case '\\':
case '/':{
switch( argv[i][1] ){
case 'h': case 'H': case 'v': case 'V': case '?':{
printf( "Dr Frucht Systems MastBaum Server\n");
printf( "Software version <%s>\n", VERSION_NUMBER );
printf( " -h -H This Message\n" );
printf( " -i -I Interactive Mode\n" );
return 0;
break;
};
case 'i': case 'I':{
WBG = false;
break;
};
case 'c': case 'C':{
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN );
sprintf( DCF_NAME, "%s", argv[i+1] );
break;
};
};
break;
};
};
};
};
if ( fileExist( DCF_NAME ) ){
NDC = false;
} else {
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_FILE;
if( fileExist( DCF_NAME ) ){
NDC = false;
};
}
if ( !NDC ){
// read serial number
FILE *pFile = fopen( DCF_NAME, "rt" );
printf("Trying open file %s\n", DCF_NAME );
if( pFile != NULL ){
char pLine[1024];
while( fgets( pLine, 1024, pFile ) ){
SETTING_TYPE eType = ST_NONE;
CSTR pTemp = NULL;
for( int i = 0; i < sizeof( m_pSetting ) / sizeof( *m_pSetting ); i++ ){
pTemp = strstr( pLine, m_pSetting[i] );
if( pTemp ){
eType = (SETTING_TYPE)i;
pTemp = strstr( pTemp, "=" );
if( pTemp ) pTemp = strtok( pTemp + 1, " \t\n\r" );
break;
};
};
if( eType == ST_NONE || !pTemp ) continue;
switch( eType ){
case ST_SN:{
gsCFG_LICENSE = (CSTR) malloc(strlen( pTemp ));
//memcpy( gsCFG_LICENSE, pTemp, strlen( pTemp ) );
sprintf( gsCFG_LICENSE, "%s", pTemp );
break;
};
case ST_BIND_ADDRESS:{
gsCFG_ADDRESS = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_ADDRESS, "%s", pTemp );
break;
};
case ST_BIND_PORT:{
guCFG_PORT = ( uint16_t ) atoi( pTemp );
break;
};
case ST_PID_FILE:{
gsCFG_PID_FILE = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_PID_FILE, "%s", pTemp );
break;
};
case ST_LOG_FILE:{
FLE_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( FLE_NAME, "%s", pTemp );
break;
};
case ST_INTERACTIVE:{
WBG = (atoi( pTemp ))? false: true;
break;
};
case ST_SMS_ENABLE:{
gModule_SMS_Enabled = (bool)atoi( pTemp );
break;
};
case ST_EMAIL_ENABLE:{
gModule_Email_Enabled = (bool)atoi( pTemp );
break;
};
case ST_SMS_PROVIDER:{
break;
};
case ST_DATABASE_SERVER:{
gsCFG_DB_SERVER = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_SERVER, "%s", pTemp );
break;
};
case ST_DATABASE_USER:{
gsCFG_DB_USER = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_USER, "%s", pTemp );
break;
};
case ST_DATABASE_PASSWORD:{
gsCFG_DB_PASSWORD = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_PASSWORD, "%s", pTemp );
break;
};
case ST_DATABASE_NAME:{
gsCFG_DB_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( gsCFG_DB_NAME, "%s", pTemp );
break;
};
case ST_SOCKET_NAME:{
SSP_NAME = (CSTR) malloc(strlen( pTemp ));
sprintf( SSP_NAME, "%s", pTemp );
break;
};
};
};
fclose( pFile );
} else {
NDC = true;
};
};
if( NDC ){//Default config
gsCFG_LICENSE = (CSTR) "FRUCHT_DEMO_LICENSE";
gsCFG_DB_SERVER = (CSTR) "localhost";
gsCFG_ADDRESS = gsCFG_DB_SERVER;
gsCFG_DB_NAME = (CSTR) "tgdos";
gsCFG_DB_USER = (CSTR) "tgdos";
gsCFG_DB_PASSWORD = (CSTR) "NoGud4U@";
};
umask( 0 ); // Clear File Modes Mask
// Demonizing or not
if( WBG ){
printf( "Dr Frucht Systems LRF Server ver. %s\n", VERSION_NUMBER );
printf( "Configuration Applied:\n");
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT );
printf( " PID File: %s\n", gsCFG_PID_FILE );
printf( " Log File: %s\n", FLE_NAME );
printf( " License: %s\n", gsCFG_LICENSE );
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME );
if( NDC ){
printf( " No configuration file (%s) supplied.\n", DCF_NAME);
} else {
printf( " Configuration read from: %s\n", DCF_NAME );
};
//Demonizing
pid_t pid, sid;
sync();
close( STDIN_FILENO );
close( STDOUT_FILENO );
close( STDERR_FILENO );
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
return 0;
};
//umask(0);
sid = setsid();
if (sid < 0) {
return sid;
};
pid = fork();
if( pid < 0 ){
return pid;
};
if( pid > 0 ){
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" );
if( pPIDF ){
fprintf( pPIDF, "%d\n", pid );
fclose( pPIDF );
}
return 0;
};
};
//Block Some Signals
//sigset_t signal_mask;
//sigfillset( &signal_mask );
//sigaddset(&signal_mask, SIGUSR1);
//pthread_sigmask( SIG_BLOCK, &signal_mask, NULL );
// Clear to start Service
m_pLog = basicLogCollection::getInstance();
//CDC = new _GP_Core_Dispatching_Collection();
//DBC = new MySQL_Connector();
//m_pLog->setLogLevel( _LOG_ALL ); // All Messages
//m_pLog->setLogLevel( _LOG_VERBOSE );
m_pLog->setLogLevel( _LOG_ERROR ); // Most Silent Mode
if ( FLE ){// Init File Logging Engine
m_pLog->addHandler((basicLoggingService *) new objectFileLoggingService( FLE_NAME ));
};
if ( !WBG ){// Init Curses class to handle UI
//m_pLog->addHandler((_Core_Logging_Service *) new _Core_CLUI());
};
uint8_t m_bKernelExitCode = 0;
// Start HW layer;
#ifndef NO_GPIO_HANDLER
if( wiringPiSetup() == -1 ){
LOG_ERROR("WiringPI Init failure!");
char tBuffer[256];
sprintf( tBuffer, "Error code: %d", errno );
LOG_ERROR( tBuffer );
return -1;
};
//wiringPiSetupGpio();
pinMode( 4, INPUT );
// Starting Services
#endif
mpNetworkManager = new NetworkManager(); //new networkServer();
if( mpNetworkManager == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Net Server failed to born ++++" );
//delete( HWManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
if( !mpNetworkManager->BootUp() ){
// Aborting Work
LOG_ERROR( "++++ Net Server failed to init ++++" );
//delete( HWManager );
delete( mpNetworkManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
// Start Loop of Restarted Kernel
do{
//HWManager = new LRF_HardwareManager();
// Init Objects
//if( HWManager != NULL ){
// if( HWManager->isSitara() ) {
/*
S_HARDWARE_SETTINGS m_sHWS;
if(!m_sHWS.readFromFile( "hw.ini" )){
LOG("Default HW settings are applyied");
};
if( gbCFG_MASTER_ROLE ) {
LOG("ROLE - MASTER");
m_sHWS.isMaster = true;
} else {
LOG("ROLE - SLAVE");
m_sHWS.isMaster = false;
};
*/
//if( HWManager->isMaster() ) {
// LOG("ROLE - MASTER");
//} else {
// LOG("ROLE - SLAVE");
//};
/*
if( !HWManager->create( m_sHWS ) ){
// Aborting Work
LOG_ERROR( "++++ Hardware failed to init ++++" );
delete( HWManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
*/
LOG("KK-PREB");
m_pKernel = new Kernel();
if( m_pKernel == NULL ) {
// Aborting Work
LOG_ERROR( "++++ Kernel failed to born ++++" );
//delete( HWManager );
delete( mpNetworkManager );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return -1;
};
//Loop till some Restart action
if( m_pKernel != NULL ){
LOG( "++++ Server Started ++++" );
if ( m_pKernel->create( NULL, mpNetworkManager ) == false ){
LOG_ERROR("Kernel create failure!");
} else {
//Install Signal Listeners
old_kill_handler_15 = signal( 15, signal_kill_handler );
old_kill_handler_9 = signal( 9, signal_kill_handler );
#ifndef NO_GPIO_HANDLER
//Instal ISR Listener
if( wiringPiISR( 4, INT_EDGE_RISING, &myInterrupt4 ) == -1 ){
LOG_ERROR("Can not setup ISP handler!");
char tBuffer[256];
sprintf( tBuffer, "Error code: %d", errno );
LOG_ERROR( tBuffer );
} else {
#endif
// Waiting for Worker to Shut Down
m_pKernel->WaitFinish( false );
m_bKernelExitCode = m_pKernel->getExitCause();
if( m_bKernelExitCode ) {
// Detach Kernel From Clients
mpNetworkManager->attachEngine( NULL );
};
signal( 9, old_kill_handler_9 );
signal( 15, old_kill_handler_15 );
#ifndef NO_GPIO_HANDLER
};
#endif
};
delete( m_pKernel );
LOG( "++++ Server Ended ++++" );
};
//delete( HWManager );
//} else {
// LOG_ERROR( "SOC Module Unknown" );
// }
//} else {
// LOG_ERROR( "++++ Unknown Hardware ++++" );
//};
} while( m_bKernelExitCode > 0 );
delete( mpNetworkManager );
//LOG( "++++ CDC DEL ++++" );
unlink( gsCFG_PID_FILE );
LOG( "PID File Deleted" );
delete( m_pLog );
return 0;
};
#undef LOG
#undef LOG_ERROR

33
lib/App/mastbaumSERVER/Server.h

@ -1,33 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 7/20/2017
// Last modification: 7/20/2017
// PROJECT:
// SUBSYSTEM:
// FILE: Server.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of Server.h
//----------------------------------------------------------------------------
//
#ifndef __SERVER_HEADER__
#define __SERVER_HEADER__
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <wiringPi.h>
#include "../../components/base/basicSettings.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicBuildTimeStamp.h"
#include "../../components/object/objectFileLoggingService.h"
#include "NetworkManager.h"
//#include "../../data/mysql/database_class.h"
//#include "../include/device/general/am437x_prmcm.h"
#include "Kernel.h"
#endif

136
lib/App/mastbaumSERVER/interProcessProto.cpp

@ -1,136 +0,0 @@
#include "interProcessProto.h"
#define LOG( X ) m_pLog->Log( "InterProcProto", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "InterProcProto", this, _LOG_ERROR, _tBfrErrMSG234 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "InterProcProto", this, _LOG_ERROR, X );
#endif
interProcProto::interProcProto():protocolParser(), m_mInquiryMutex(){
m_pLog = basicLogCollection::getInstance();
};
interProcProto::~interProcProto(){
# ifdef DEBUG
LOG("Destructor Begin");
# endif
m_mInquiryMutex.unlock();
# ifdef DEBUG
LOG("Destructor End");
# endif
};
size_t interProcProto::FinishUpPackage( uint8_t *Buffer, size_t Size ){
uint16_t tVal;
Buffer[0] = 0x55;
Buffer[1] = ((( Size - 2 ) >> 8 ) & 0xFF ) ;//| SEND_TAG;
Buffer[2] = ( Size - 2 ) & 0xFF;
tVal = checksum16( Buffer, Size );
Buffer[Size] = tVal >> 8;
Buffer[Size] = tVal & 0xFF;
return Size+2;
};
/*
Data[0] = 0x55;
Data[1] = 0x00;
Data[2] = 0x01;
Data[3] = 0xA5;
Data[4] = 0x00;
Data[5] = 0xFB;
BufferSize = 6;
*/
int interProcProto::packetChecker(U8 *Buffer, size_t BufferSize){
#ifdef DUBUG_COMMUNICATION
char tmp[32];
int i;
for( i=0;i< BufferSize; i++ ) {
sprintf( tmp, " 0x%02X", Buffer[i] );
LOG(tmp);
};
#endif
if( Buffer[0] == 0x55 ){
if( BufferSize > 3 ) {
size_t pLength;
pLength = ( Buffer[1] << 8) | Buffer[2];
if( BufferSize >= ( pLength + 5 ) ) {
uint16_t pCheckSum1;
uint16_t pCheckSum2;
pCheckSum1 = checksum16(Buffer, pLength + 3 );
pCheckSum2 = ( Buffer[pLength+3] << 8) | Buffer[pLength+4];
if( pCheckSum2 == pCheckSum1 ) {
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketChecker: Packet Is Recognized (0)");
#endif
return 0; // Ok
} else {
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)");
#endif
return -1; // To shift
};
};
};
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)");
#endif
return 1; // To grow
};
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)");
#endif
return -1; // To shift
};
protocolPackage *interProcProto::packetExtractor(U8 *Buffer, size_t BufferSize){
protocolPackage *RetVal;
#ifdef DUBUG_COMMUNICATION
char tmp[32];
int i;
for( i=0;i< BufferSize; i++ ) {
sprintf( tmp, " 0x%02X", Buffer[i] );
LOG(tmp);
};
#endif
if( Buffer[0] == 0x55 ){
if( BufferSize > 5 ){
size_t pLength;
pLength = ( Buffer[1] << 8) | Buffer[2];
if( BufferSize >= ( pLength+3 ) ) {
uint16_t pCheckSum1;
uint16_t pCheckSum2;
pCheckSum1 = checksum16(Buffer, pLength+3 );
pCheckSum2 = ( Buffer[pLength+3] << 8) | Buffer[pLength+4];
if( pCheckSum2 == pCheckSum1 ) {
RetVal = (protocolPackage *) malloc(sizeof(protocolPackage));
if( RetVal == NULL ) return NULL;
RetVal->m_pData =(U8*)malloc( pLength+4 );
if( RetVal->m_pData == NULL ) {
free( RetVal );
return NULL;
};
RetVal->m_nSize = pLength+4;
RetVal->m_nCode = Buffer[3];
memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize );
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)");
#endif
return RetVal;
};
};
};
#ifdef DUBUG_COMMUNICATION
LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!");
#endif
return NULL;
};
//LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)");
return NULL;
};

24
lib/App/mastbaumSERVER/interProcessProto.h

@ -1,24 +0,0 @@
#ifndef __INTER_PROCESS_PROTOCOL_HEADER__
#define __INTER_PROCESS_PROTOCOL_HEADER__
//#define DUBUG_COMMUNICATION
#include <opencv2/opencv.hpp>
#include "../../data/protocol/protocol.h"
#include "../../components/base/basicTransport.h"
class interProcProto: public protocolParser{
private:
basicLogCollection * m_pLog;
basicMutex m_mInquiryMutex;
protected:
int packetChecker( uint8_t *Buffer, size_t BufferSize);
protocolPackage * packetExtractor( uint8_t *Buffer, size_t BufferSize);
size_t FinishUpPackage( uint8_t *Buffer, size_t Size );
public:
interProcProto();
virtual ~interProcProto();
virtual bool create(void){ return protocolParser::create(); };
};
#endif

165
lib/App/videoAnal/main.cpp

@ -1,165 +0,0 @@
#include <winsock2.h>
#include "main_window.h"
#include "../../../lib/components/base/basicSettingsProvider.h"
#include "../../../lib/components/base/basicEventHeap.h"
#include "../../../lib/components/object/objectFileLoggingService.h"
#include "../../../lib/components/object/objectSystemAnchor.h"
#include "../../../lib/data/media/video/videoAVLIBSource.h"
#include "../../../lib/data/net/onvifDeviceNode.h"
#define LOG(X) mpLog->Log( "Main", NULL, X )
#define LOG_DEBUG( X ) mpLog->Log( "Main", NULL, _LOG_DEBUG, X )
#define LOG_ERROR( X ) mpLog->Log( "Main", NULL, _LOG_ERROR, X )
int main(int argc, char *argv[])
/*int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)*/
{
Beep(512, 256);
Beep(256, 256);
Beep(128, 512);
guiClass *GUI;
systemAnchor *ANCH;
GUI = guiClass::getInstance();
GUI->init(0, NULL);//argc, argv);
ANCH = systemAnchor::getInstance();
basicLogCollection *mpLog = basicLogCollection::getInstance();
objectFileLoggingService *fLog;
char tPath[1024];
char *ttPtz=NULL;
//ttPtz = (char *)GUI->getApp()->applicationDirPath().toStdString().c_str();
if( ttPtz!= NULL ){
sprintf(tPath, "%s/my.log", ttPtz);
} else {
sprintf(tPath, "my.log" );
};
fLog = new objectFileLoggingService(tPath);
mpLog->addHandler((basicLoggingService *)fLog);
printf("From now - refer to log file\n");
LOG_DEBUG("ENTER APPLICATION");
basicSettingsProvider *mpSettingsProvider = basicSettingsProvider::getInstance();
basicEventHeap *mpEventHeap = basicEventHeap::getInstance();
//sprintf(tPath, "%s/data/storage", GUI->getApp()->applicationDirPath().toStdString().c_str());
sprintf(tPath, "data/storage");
//storageProvider *mpStorPro = storageProvider::getInstance(tPath);
config_setting_t *mpSettings;
//mpStorPro->startNewSeries(); // Each prog start starts new Series
#ifdef __linux__
LOG_DEBUG("SS Disabled");
#else
//UINT lActiveFlag = 0;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, NULL, NULL);
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
UINT timeoutLowPower;
UINT timeoutPowerOff;
UINT timeoutScreenSave;
{
SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0, &(timeoutLowPower), 0);
SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, &(timeoutPowerOff), 0);
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &(timeoutScreenSave), 0);
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
}
LOG_DEBUG("SS Disabled");
#endif
mpSettings = mpSettingsProvider->getSubNode(NULL, "APPLICATION_GUI");
mainWinow *window;
window = mainWinow::getInstance();
//Check Startup Mode
int gAppStartupMode;
config_setting_t *pSetting;
if (!config_setting_lookup_int(mpSettings, "STARTUP_WINDOW_MODE", &gAppStartupMode )){
gAppStartupMode = 1;
pSetting = config_setting_add(mpSettings, "STARTUP_WINDOW_MODE", CONFIG_TYPE_INT);
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
};
switch( gAppStartupMode ){
case 0: window->show(); break;
case 1: window->showMaximized(); break;
case 2: window->showFullScreen(); break;
default:
gAppStartupMode = 1;
pSetting = config_setting_lookup(mpSettings, "STARTUP_WINDOW_MODE");
config_setting_set_int(pSetting, gAppStartupMode);
mpSettingsProvider->compromise();
window->showMaximized();
};
joysticObject::getInstance();
#ifdef __linux__
LOG_DEBUG("SS Enabled");
#else
{
SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, timeoutLowPower, NULL, 0);
SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, timeoutPowerOff, NULL, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, timeoutScreenSave, NULL, 0);
}
LOG_DEBUG("SS Enabled");
#endif
delete GUI;
delete window;
delete mpEventHeap;
delete mpSettingsProvider;
#ifdef __linux__
#else
//lActiveFlag = 1;
//SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, lActiveFlag, 0, 0);
//lActiveFlag = 20;
//SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, lActiveFlag, NULL, NULL);
//LOG_DEBUG("SS Enabled");
#endif
LOG_DEBUG("EXIT APPLICATION");
delete mpLog;
return 0;
};
#undef LOG
#undef LOG_DEBUG
#undef LOG_ERROR
/*---------------------------------------*/
/* A sample program to play C major */
/* through a PC speaker */
/*---------------------------------------*/
/* This won't work if standard output is */
/* re-directed to a non-tty device, or */
/* PC speaker wave output is active */
/*---------------------------------------*/
/* M.G. 27-Nov-99 */
/*---------------------------------------*/
/*
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/kd.h>
int main(void)
{
int freq[] = { // C D E F G A B C
523, 587, 659, 698, 784, 880, 988, 1046 };
int i;
for (i = 0; i<8; i++)
{
ioctl(STDOUT_FILENO, KIOCSOUND, 1193180 / freq[i]);
usleep(500000);
}
ioctl(STDOUT_FILENO, KIOCSOUND, 0); // Stop silly sound
return 0;
}
*/

119
lib/App/videoAnal/main_window.cpp

@ -1,119 +0,0 @@
#include "main_window.h"
mainWinow* mainWinow::_instance = 0;
void mainWinow::changeEvent(QEvent *event){
if(event->type() == QEvent::WindowStateChange ){
if (!isMinimized()) {
setAttribute(Qt::WA_Mapped);
};
};
};
mainWinow::mainWinow() : QMainWindow(){
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "APPLICATION_GUI");
//m_pJoyStick = joysticObject::getInstance();
m_pVideoSettings = NULL;
m_pMainWidget = new QWidget(NULL);
m_pMainWidget->setObjectName("m_pMainWidget");
setCentralWidget(m_pMainWidget);
resize(800, 600);
setWindowTitle( "Video Analizator" );
setWindowIcon( QIcon(":pictures/status/gray-240.png") );
m_pHorizontalLayout = new QHBoxLayout(m_pMainWidget);
m_pVerticalLayout = new QVBoxLayout();
m_pMainVideoWidget = new VideoWidget(m_pMainWidget);
m_pMainVideoWidget->init();
m_pVideoSource = new objectCameraPTZ(basicSettingsProvider::getInstance()->getSubNode(m_pSettings, "VIDEO_SRC"));
m_pMainVideoWidget->setCameraControl(m_pVideoSource, m_pVideoSource->getCaps());
m_pVerticalLayout->addWidget(m_pMainVideoWidget);
m_pHorizontalLayout->addItem(m_pVerticalLayout);
m_pVerticalSideLayout = new QVBoxLayout();
m_pHorizontalLayout->addItem(m_pVerticalSideLayout);
m_pButtonCmdSourceSettings = new QPushButton(m_pMainWidget);
m_pButtonCmdSourceSettings->setIcon(QIcon(":pictures/appbar.cog.png"));
m_pButtonCmdSourceSettings->setIconSize(QSize(40, 40));
m_pButtonCmdSourceSettings->setFixedSize(220, 54);
m_pButtonCmdSourceSettings->setText(QStringLiteral("Video Source Settings"));
m_pButtonCmdSourceSettings->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdSourceSettings, &QPushButton::clicked, this, &mainWinow::handleVideoSettings);
m_pVerticalSideLayout->addWidget(m_pButtonCmdSourceSettings);
m_pButtonCmdVideoAnaliticsSettings = new QPushButton(m_pMainWidget);
m_pButtonCmdVideoAnaliticsSettings->setIcon(QIcon(":pictures/appbar.diagram.png"));
m_pButtonCmdVideoAnaliticsSettings->setIconSize(QSize(40, 40));
m_pButtonCmdVideoAnaliticsSettings->setFixedSize(220, 54);
m_pButtonCmdVideoAnaliticsSettings->setText(QStringLiteral("Video Analitycs Settings"));
m_pButtonCmdVideoAnaliticsSettings->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
//connect(m_pButtonCmdVideoAnaliticsSettings, &QPushButton::clicked, this, &mainWinow::handleSilencePress);
m_pVerticalSideLayout->addWidget(m_pButtonCmdVideoAnaliticsSettings);
m_pButtonCmdAppSettings = new QPushButton(m_pMainWidget);
m_pButtonCmdAppSettings->setIcon(QIcon(":pictures/appbar.cogs.png"));
m_pButtonCmdAppSettings->setIconSize(QSize(40, 40));
m_pButtonCmdAppSettings->setFixedSize(220, 54);
m_pButtonCmdAppSettings->setText(QStringLiteral("Application Settings"));
m_pButtonCmdAppSettings->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
//connect(m_pButtonCmdAppSettings, &QPushButton::clicked, this, &mainWinow::handleSilencePress);
m_pVerticalSideLayout->addWidget(m_pButtonCmdAppSettings);
m_pButtonCmdExit = new QPushButton(m_pMainWidget);
m_pButtonCmdExit->setIcon(QIcon(":pictures/appbar.power.png"));
m_pButtonCmdExit->setIconSize(QSize(40, 40));
m_pButtonCmdExit->setFixedSize(220, 54);
m_pButtonCmdExit->setText(QStringLiteral("Exit Application"));
m_pButtonCmdExit->setStyleSheet(QStringLiteral("Text-align:left;font: 12pt"));
connect(m_pButtonCmdExit, &QPushButton::clicked, this, &mainWinow::handleClose);
m_pVerticalSideLayout->addWidget(m_pButtonCmdExit);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
m_pVerticalSideLayout->addItem(verticalSpacer);
m_pStatusBar = new QStatusBar(this);
m_pStatusBar->setObjectName(QStringLiteral("statusBar"));
m_pStatusBar->setStyleSheet(QStringLiteral("background-color: rgb(255, 170, 0);"));
setStatusBar(m_pStatusBar);
};
mainWinow::~mainWinow(){
delete(m_pMainWidget);
};
/**
* Returns the single instance of the object.
*/
mainWinow* mainWinow::getInstance() {
// check if the instance has been created yet
if (0 == _instance){
// if not, then create it
_instance = new mainWinow();
};
// return the single instance
return _instance;
};
void mainWinow::handleClose(void){
exit(0);
};
void mainWinow::handleVideoSettings(void){
if (m_pVideoSettings == NULL){
m_pVideoSettings = new guiEditCameraDialog();
};
if (m_pVideoSettings != NULL){
m_pVideoSettings->attachCamera(m_pVideoSource);
int dialogCode = m_pVideoSettings->exec();
if( dialogCode == QDialog::Accepted ){
m_pMainVideoWidget->setError("BOBO");
m_pMainVideoWidget->setCameraControl(NULL, OC_PASSIVE);
delete m_pVideoSource;
m_pVideoSource = new objectCameraPTZ();
m_pMainVideoWidget->setCameraControl(m_pVideoSource, m_pVideoSource->getCaps());
m_pMainVideoWidget->setError(NULL);
};
};
};

170
lib/App/videoAnal/main_window.h

@ -1,170 +0,0 @@
#ifndef __QT5_MAIN_WINDOW_HEADER__
#define __QT5_MAIN_WINDOW_HEADER__
#include <WinSock2.h>
#include <stdint.h>
#include "../../../lib/components/base/basicSettingsProvider.h"
#include "../../../lib/gui/guiClass.h"
#include "../../../lib/data/media/video/videoAVLIBSource.h"
#include "../../../lib/gui/controls/VideoWidget.h"
#include "../../../lib/gui/controls/TimeShowWidget.h"
#include "../../../lib/hardware/stick/joystick.h"
#include "../../../lib/components/object/objectCameraPTZ.h"
#include "../../../lib/gui/controls/editCameraDialog.h"
class mainWinow : public QMainWindow{
private:
config_setting_t *m_pSettings;
/* Main Widget */
QWidget *m_pMainWidget;
/* Layouts */
QMainWindowLayout *m_pMainLayout;
QVBoxLayout *m_pVerticalLayout;
QVBoxLayout *m_pVerticalSideLayout;
QHBoxLayout *m_pHorizontalLayout;
QHBoxLayout *m_pScrolbarLayout;
QVBoxLayout *m_pVVVLayout;
QVBoxLayout *m_pVCVLayout;
QPushButton *m_pButtonCmdVideoRecord;
QSpacerItem *m_pVSpacer1;
QSpacerItem *m_pVSpacer2;
QSpacerItem *m_pVSpacer3;
joysticObject *m_pJoyStick;
/* Widgets */
QFrame *m_pTitleFrame;
TimeShowWidget *m_pTitleWidget;
QStatusBar *m_pStatusBar;
QSpacerItem *verticalSpacer;
QSpacerItem *verticalSideSpacer;
QSpacerItem *horisontalSpacer;
QSpacerItem *scrolbarSpacer;
QPushButton *m_pButtonCmdSourceSettings;
QPushButton *m_pButtonCmdVideoAnaliticsSettings;
QPushButton *m_pButtonCmdAppSettings;
QPushButton *m_pButtonCmdExit;
VideoWidget *m_pMainVideoWidget;
objectCameraPTZ *m_pVideoSource;
guiEditCameraDialog *m_pVideoSettings;
//clientPort *m_pMasterSocket;
//clientPort *m_pSlaveSocket;
//objectLGS *m_pMasterDevice;
//objectLGS *m_pSlaveDevice;
//Control Panels
QTabWidget *m_pTabWidget;
QWidget *m_pPage1;
QWidget *m_pPage2;
QWidget *m_pPage3;
QWidget *m_pPage4;
QWidget *m_pPage5;
QHBoxLayout *m_pPage1Layout;
QHBoxLayout *m_pPage2Layout;
QVBoxLayout *m_pPage3Layout;
QVBoxLayout *m_pPage4Layout;
QVBoxLayout *m_pPage5Layout;
QPushButton *m_pButton1;
QPushButton *m_pButton2;
QPushButton *m_pButton3;
QPushButton *m_pButton4;
QPushButton *m_pButton5;//Add Mask
QPushButton *m_pButton6;//Delete Mask
QPushButton *m_pButton7;//Activate Masks
QPushButton *m_pButton8;//Deactivate Masks
QHBoxLayout *mpLayout;
QSpacerItem *mpSpacer;
QProgressBar *m_pProgressBar;
QHBoxLayout *m_pHorizontalLayout1;
QHBoxLayout *m_pHorizontalLayout2;
QHBoxLayout *m_pHorizontalLayout3;
QRadioButton *m_pRadioButton1;
QRadioButton *m_pRadioButton2;
QGroupBox *m_pRadioGroup;
QGroupBox *m_pSampleGroup;
QComboBox *m_pLRFCombo;
QLabel *m_pStMiRalabel;
QLabel *m_pStMaRalabel;
QLabel *m_pStMiSalabel;
QLabel *m_pStMaSalabel;
QLabel *m_pStMiRaVal;
QLabel *m_pStMaRaVal;
QLabel *m_pStMiSaVal;
QLabel *m_pStMaSaVal;
QLabel *m_pOpLabel;
bool m_bUserRecordsVideo;
private slots:
void handleSilencePress();
void handleButtonPress();
void handleButton2Press();
void handleMaximumsPress();
void handleMinimumsPress();
void handleGenerateWS();
void handleSave2DPicture( void );
void handleSave3DPicture(void);
void handleAddMask();
void handleDeleteMask();
void handleUpdateMask();
void handleSetStatusMask();
void handleVideoRecorder();
void handleReports();
QPixmap *notepixmap;
/*Map*/
/*
mediaBus *m_pVideoBus1;
videoAVLIBSource *m_pVideoIpput1;
VideoThumbWidget *m_pVideoWidget1;
mediaBus *m_pVideoBus2;
videoAVLIBSource *m_pVideoIpput2;
VideoThumbWidget *m_pVideoWidget2;
mediaBus *m_pVideoBus3;
videoAVLIBSource *m_pVideoIpput3;
VideoThumbWidget *m_pVideoWidget3;
*/
//serialPort *mSerial;
//protocolPTZ_VISCA *mCamera;
public:
// Method to fetch singleton instance.
static mainWinow* getInstance();
// Destructor
virtual ~mainWinow();
protected:
mainWinow();
void changeEvent(QEvent *event);
private:
// private static member referencing the single instance of the object
// TODO: Replace basicLogCollection with the type of object you want to
// return the single instance of
static mainWinow* _instance;
// Copy constructor
// Declared but not defined to prevent auto-generated
// copy constructor. Refer to "Effective C++" by Meyers
mainWinow(const mainWinow& src);
// Assignment operator
// Declared but not defined to prevent auto-generated
// assignment operator. Refer to "Effective C++" by Meyers
mainWinow& operator=(const mainWinow& src);
public slots:
void handleVideoSettings(void);
void handleClose(void);
};
#endif

14
lib/defender-dc-trig/rgooseClassAccess.h

@ -1,14 +0,0 @@
#ifndef __R_GOOSE_DATA_CLASS_ACCESS_HEADER__
#define __R_GOOSE_DATA_CLASS_ACCESS_HEADER__
typedef enum E_NC_ACCESS_Types{
NS_UNDEFINED = 0,
NS_CONSOLE = 1,
NS_RFID_READER,
NS_MAG_CARD_READER,
NS_LOCK,
NS_CODE_INPUT,
NS_PROXYMITY
} nodeAccessSubClassTypes;
#endif

471
lib/defender-dc-trig/rgooseDBConnector.cpp

@ -1,471 +0,0 @@
#include "rgooseDBConnector.h"
#define LOG( X ) m_pLog->Log( "ADBC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X )
ARGUS_DBC::ARGUS_DBC( config_setting_t * Settings ){
m_pLog = basicLogCollection::getInstance();
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
m_bIsConnected = false;
m_pDatabase = NULL;
};
ARGUS_DBC::~ARGUS_DBC(){
};
bool ARGUS_DBC::connect( void ){
config_setting_t * tSetting;
m_bIsConnected = false;
if( m_pSettings!= NULL ) {
tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
if( tSetting == NULL ){
tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
config_setting_set_string( tSetting, "localhost" );
basicSettingsProvider::getInstance()->compromise();
LOG("No DB Host Setting! Using default!");
};
sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
if( tSetting == NULL ){
tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
config_setting_set_string( tSetting, "dfsl_gunter" );
basicSettingsProvider::getInstance()->compromise();
LOG("No DB Database Setting! Using default!");
};
sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
if( tSetting == NULL ){
tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
config_setting_set_string( tSetting, "dbroot" );
basicSettingsProvider::getInstance()->compromise();
LOG("No DB User Setting! Using default!");
};
sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
if( tSetting == NULL ){
tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
config_setting_set_string( tSetting, "123567" );
basicSettingsProvider::getInstance()->compromise();
LOG("No DB Password Setting! Using default!");
};
sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
basicSettingsProvider::getInstance()->validate();
m_pDatabase = new MySQL_Connector();
if( m_pDatabase == NULL )return false;
m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
} else {
LOG_ERROR("No Settings Provided!");
};
return m_bIsConnected;
};
bool ARGUS_DBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
if(m_bIsConnected) {
char tQBuf[MAX_PATH_LEN];
char tIpBuf[CTEXT];
char *tPos;
char *tPos2;
LOG("Cam Update");
tPos = strstr(Addr,"//");
if( tPos != NULL ) {
tPos2 = strstr( tPos + 2,"/");
if( tPos2 != NULL ) {
int len;
len = tPos2 - tPos - 2;
strncpy(tIpBuf,tPos + 2,len);
tIpBuf[len] = (char)0;
} else {
LOG("Pos 2 - err");
tIpBuf[0] = (char)0;
};
} else {
LOG("Pos 0 - err");
tIpBuf[0] = (char)0;
};
sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'",
uuid,
Addr,
tIpBuf,
SiteID,
Addr,
tIpBuf
);
LOG(tQBuf);
m_pDatabase->SilentQuery( tQBuf );
return true;
};
return false;
};
bool ARGUS_DBC::updateIPCam( uint32_t SiteID, resultWoWo *tPtr ){
if(m_bIsConnected) {
char tQBuf[MAX_PATH_LEN];
char tIpBuf[CTEXT];
char *tPos;
char *tPos2;
LOG("Cam Update WoWo");
tPos = strstr(tPtr->XAddrs,"//");
if( tPos != NULL ) {
tPos2 = strstr( tPos + 2,"/");
if( tPos2 != NULL ) {
int len;
len = tPos2 - tPos - 2;
strncpy(tIpBuf,tPos + 2,len);
tIpBuf[len] = (char)0;
} else {
LOG("Pos 2 - err");
tIpBuf[0] = (char)0;
};
} else {
LOG("Pos 0 - err");
tIpBuf[0] = (char)0;
};
sprintf(tQBuf,"INSERT INTO cameras SET `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s' ON DUPLICATE KEY UPDATE `onvif_ctrl`='%s', `ip`='%s'",
tPtr->RefID,
tPtr->XAddrs,
tIpBuf,
SiteID,
tPtr->MAC,
tPtr->Hardware,
tPtr->Name,
tPtr->XAddrs,
tIpBuf
);
LOG(tQBuf);
m_pDatabase->SilentQuery( tQBuf );
return true;
};
return false;
};
bool ARGUS_DBC::transferEvtToArchive( uint32_t SECONDS ){
if(m_bIsConnected) {
if( SECONDS > 0 ) {
char tQBuf[CTEXT];
sprintf(tQBuf,"INSERT INTO events_archive ( SELECT * FROM events_cloud ec WHERE ec.ts < ( UNIX_TIMESTAMP(NOW()) - %d ) ); DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - %d );", SECONDS, SECONDS );
m_pDatabase->SilentQuery( tQBuf );
return true;
};
};
return false;
}
bool ARGUS_DBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
if(m_bIsConnected){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
EventRecordDBC *tPtr;
Assoc *cArr;
for(int i=0;i<result->size();i++) {
cArr = result->at(i);
tPtr = (EventRecordDBC*)malloc(sizeof(EventRecordDBC));
if( tPtr!= NULL ) {
Assoc::iterator it;
memset(tPtr,0,sizeof(EventRecordDBC));
it = cArr->find("ts");
if( it != cArr->end() ){
tPtr->ts_s = atoi( it->second.c_str() );
};
it = cArr->find("ts_ms");
if( it != cArr->end() ){
tPtr->ts_ms = atoi( it->second.c_str() );
};
it = cArr->find("evt_type");
if( it != cArr->end() ){
tPtr->type = atoi( it->second.c_str() );
};
char tBuf[CLOG];
sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
LOG(tBuf);
VR.push_back(tPtr);
};
delete(cArr);
};
result->clear();
delete(result);
};
if( m_pDatabase->isConnected()) return true;
};
return false;
};
bool ARGUS_DBC::getIPCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
if(m_bIsConnected){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
CamRecordDBC *tPtr;
Assoc *cArr;
for(int i=0;i<result->size();i++) {
LOG("Cam_Record!");
cArr = result->at(i);
tPtr = (CamRecordDBC*)malloc(sizeof(CamRecordDBC));
if( tPtr!= NULL ) {
Assoc::iterator it;
memset(tPtr,0,sizeof(CamRecordDBC));
it = cArr->find("id");
if( it != cArr->end() ){
tPtr->id = atoi( it->second.c_str() );
};
it = cArr->find("uuid");
if( it != cArr->end() ){
sprintf( tPtr->uuid, "%s", it->second.c_str() );
};
it = cArr->find("ip");
if( it != cArr->end() ){
sprintf( tPtr->ip, "%s", it->second.c_str() );
};
it = cArr->find("access_login");
if( it != cArr->end() ){
sprintf( tPtr->username, "%s", it->second.c_str() );
};
it = cArr->find("access_pass");
if( it != cArr->end() ){
sprintf( tPtr->password, "%s", it->second.c_str() );
};
VR.push_back(tPtr);
};
delete(cArr);
};
result->clear();
delete(result);
};
sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
LOG(tQBuf);
if( m_pDatabase->isConnected()) return true;
};
return false;
};
DBC_INT_LIST *ARGUS_DBC::listNodes( uint32_t SiteID ){
DBC_INT_LIST * tVal = NULL;
if(m_bIsConnected){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d", SiteID );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = new DBC_INT_LIST();
if( tVal != NULL ) {
Assoc::iterator it;
for(int i=0;i<result->size();i++) {
cArr = result->at(i);
it = cArr->find("id");
if( it != cArr->end() ){
tVal->push_back( atoi( it->second.c_str() ));
};
};
};
};
};
};
return tVal;
};
DBC_NODE_DATA *ARGUS_DBC::getNodeData( uint32_t ID ){
DBC_NODE_DATA * tVal = NULL;
if(m_bIsConnected){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
if( tVal != NULL ) {
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("id");
if( it != cArr->end() ){
tVal->node_id = atoi( it->second.c_str() );
};
it = cArr->find("type");
if( it != cArr->end() ){
tVal->type = atoi( it->second.c_str() );
};
it = cArr->find("aux_id");
if( it != cArr->end() ){
tVal->aux_id = atoi( it->second.c_str() );
};
it = cArr->find("name");
if( it != cArr->end() ){
sprintf( tVal->name, it->second.c_str() );
};
it = cArr->find("ts_s");
if( it != cArr->end() ){
tVal->tss = atoi( it->second.c_str() );
};
it = cArr->find("ts_ms");
if( it != cArr->end() ){
tVal->tsm = atoi( it->second.c_str() );
};
it = cArr->find("online");
if( it != cArr->end() ){
tVal->online = (bool)atoi( it->second.c_str() );
};
};
result->clear();
};
delete( result );
};
};
return tVal;
};
void ARGUS_DBC::registerServer(uint32_t SiteID, CSTR identity ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1", SiteID, identity );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
uint32_t sid = getServerID( identity );
if( sid ) {
sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", SiteID, sid );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
};
};
};
void ARGUS_DBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"UPDATE servers SET `online`=0 WHERE `id` = %d", ServerID );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
setNodeOffline( NodeID );
};
};
void ARGUS_DBC::setNodeOnline( uint32_t NodeID ){
if(m_bIsConnected){
char tQBuf[CTEXT];
if( NodeID ) {
sprintf(tQBuf,"UPDATE nodes SET `online`=1 WHERE `id` = %d", NodeID );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE sockets SET `state`=1 WHERE `node_id` = %d", NodeID );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
};
};
};
void ARGUS_DBC::setNodeOffline( uint32_t NodeID ){
if(m_bIsConnected){
char tQBuf[CTEXT];
if( NodeID ) {
sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
sprintf(tQBuf,"UPDATE sockets SET `state`=0 WHERE `node_id` = %d", NodeID );
#ifdef DEBUG
LOG(tQBuf);
#endif
m_pDatabase->SilentQuery( tQBuf );
};
};
};
uint32_t ARGUS_DBC::getServerID( CSTR identity ){
uint32_t RetVal = 0;
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
#ifdef DEBUG
LOG(tQBuf);
#endif
AAssoc *result;
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc * cArr;
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("id");
if( it != cArr->end() ){
RetVal = atoi( it->second.c_str() );
};
result->clear();
};
delete( result );
};
};
return RetVal;
};
uint32_t ARGUS_DBC::getServerNode( uint32_t SID ){
uint32_t RetVal = 0;
if(m_bIsConnected){
char tQBuf[CTEXT];
sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
#ifdef DEBUG
LOG(tQBuf);
#endif
AAssoc *result;
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc * cArr;
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("id");
if( it != cArr->end() ){
RetVal = atoi( it->second.c_str() );
};
result->clear();
};
delete( result );
};
};
return RetVal;
};
void ARGUS_DBC::addNodeSocket( uint32_t NodeID, uint8_t SocketType, CSTR path, CSTR name ){
if(m_bIsConnected){
char tQBuf[CTEXT];
CSTR tMD5;
tMD5 = MD5String( path );
sprintf(tQBuf,"INSERT INTO sockets SET `node_id`=%d, `type`=%d, `md5`='%s', `path`='%s', `state`=1, `name`='%s' ON DUPLICATE KEY UPDATE `state`=1",
NodeID, SocketType, tMD5, path, name );
#ifdef DEBUG
LOG(tQBuf);
#endif
free( tMD5 );
m_pDatabase->SilentQuery( tQBuf );
};
};
#undef LOG
#undef LOG_ERROR

79
lib/defender-dc-trig/rgooseDBConnector.h

@ -1,79 +0,0 @@
#ifndef __ARGUS_DATABASE_CONNECTOR_HEADER__
#define __ARGUS_DATABASE_CONNECTOR_HEADER__
#include "../components/base/basicSettingsProvider.h"
#include "../data/mysql/database_class.h"
#include "../data/protocol/onvifMediaObserver.h"
#include "../alg/generic/md5.h"
#define ONE_DAY_HISTORY 86400
#define ONE_HOUR_HISTORY 3600
#define ONE_SECOND_HISTORY 1
typedef struct S_CamRecordDBC{
int id;
bool online;
char uuid[CLOG];
char ip[16];
char username[CLOG];
char password[CLOG];
}CamRecordDBC;
typedef struct S_EventRecordDBC{
int ts_s;
int ts_ms;
int type;
}EventRecordDBC;
typedef struct S_DBC_NODE_DATA{
uint32_t node_id;
uint32_t aux_id;
uint32_t type;
bool online;
uint32_t tss;
uint32_t tsm;
char name[128];
}DBC_NODE_DATA;
typedef std::vector<int> DBC_INT_LIST;
typedef std::vector<CamRecordDBC*> vectorCamRecords;
typedef std::vector<EventRecordDBC*> vectorEventRecords;
class ARGUS_DBC{
private:
basicLogCollection * m_pLog;
config_setting_t * m_pSettings;
MySQL_Connector * m_pDatabase;
bool m_bIsConnected;
char m_pDbHost[CLOG];
char m_pDbUsername[CLOG];
char m_pDbPassword[CLOG];
char m_pDbDatabase[CLOG];
public:
explicit ARGUS_DBC( config_setting_t * Settings );
~ARGUS_DBC();
/* Functionality */
bool connect( void );
bool getConnectionStatus(void){return m_bIsConnected;};
bool setOnlineStatus( bool Status );
int getIPCamCount( uint32_t SiteID );
bool getIPCamRecords( uint32_t SiteID, vectorCamRecords &VR );
bool updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr );
bool updateIPCam( uint32_t SiteID, resultWoWo *tPtr );
bool updateNetworkNode( bool OnlineStatus );
bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY );
DBC_INT_LIST * listNodes( uint32_t SiteID );
DBC_NODE_DATA * getNodeData( uint32_t ID );
void registerServer(uint32_t SiteID, CSTR identity );
void unregisterServer(uint32_t ServerID, uint32_t NodeID );
uint32_t getServerID( CSTR identity );
uint32_t getServerNode( uint32_t SID );
void addNodeSocket( uint32_t NodeID, uint8_t SocketType, CSTR path, CSTR name );
void setNodeOnline( uint32_t NodeID );
void setNodeOffline( uint32_t NodeID );
};
#endif

68
lib/defender-dc-trig/rgooseIPCamera.cpp

@ -1,68 +0,0 @@
#include "rgooseIPCamera.h"
#define LOG( X ) m_pLog->Log( "ARGUS_CAM", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "ARGUS_CAM", this, _LOG_ERROR, X )
ARGUS_Camera::ARGUS_Camera():basicEventHandler(),basicThread(){
m_pLog = basicLogCollection::getInstance();
m_pOnVif = NULL;
m_pPos = NULL;
m_bOnline = false;
};
ARGUS_Camera::~ARGUS_Camera(){
waitThreadEnd( true );
if(m_pOnVif != NULL) delete(m_pOnVif);
if(m_pPos != NULL ) delete(m_pPos);
};
bool ARGUS_Camera::create( CSTR ip, CSTR username, CSTR password ){
m_pOnVif = new pOnvif();
if(m_pOnVif != NULL) {
m_pOnVif->setIPAddress( ip );
m_pOnVif->setUsername( username );
m_pOnVif->setPassword( password );
if(m_pOnVif->create()){
videoSourceProfile *tPtr;
tPtr = m_pOnVif->getProfiles()->at(0);
sprintf( m_pProfileToken, "%s", tPtr->profiletoken );
LOG( m_pProfileToken );
sprintf( m_pDevToken, "%s", tPtr->sourcetoken );
LOG( m_pDevToken );
m_bOnline = basicThread::init();
return m_bOnline;
};
};
return false;
};
void ARGUS_Camera::m_fThreadProc( void ){
pid_t pid = gettid();
char pidBuf[16];
sprintf(pidBuf,"pid:%d", pid);
LOG(pidBuf);
m_bThreadStatus = TH_WORKING;
float Direction = 1.f;
while( m_bThreadStatus < TH_ENDED ){
m_tTimeTSeconds = time( NULL );
if( ( m_tTimeTSeconds % 30 ) == 0 ) {
m_pOnVif->ptz_AbsoluteMove( m_pProfileToken, 0, -1, 0 );
SLEEP(1000);
}
if( ( ( m_tTimeTSeconds - 15 ) % 30 ) == 0 ) {
m_pOnVif->ptz_AbsoluteMove( m_pProfileToken, Direction, -1, 0 );
Direction *= -1.f;
SLEEP(1000);
}
SLEEP( 100 );
};
};
void ARGUS_Camera::dispatchEvent( basicEvent *Evt ){
if( m_bOnline ) {
LOG("EVENT!");
};
};
#undef LOG
#undef LOG_ERROR

56
lib/defender-dc-trig/rgooseIPCamera.h

@ -1,56 +0,0 @@
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2017. All Rights Reserved.
// Version 2.0 6/11/2019
// Last modification: 6/11/2019
// PROJECT:
// SUBSYSTEM:
// FILE: rgooseIPCamera.h
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of rgooseIPCamera.h
//----------------------------------------------------------------------------
//
#ifndef __ARGUS_IP_CAMERA_HEADER__
#define __ARGUS_IP_CAMERA_HEADER__
#include <vector>
#include "rgooseNode.h"
#include "../components/base/basicEventHandler.h"
#include "../components/base/basicThread.h"
#include "../data/ponvif/ponvif.h"
//https://www.ebay.com/itm/Professional-Rolling-Makeup-Case-Bulb-Mirror-Cosmetic-Artist-Dressing-Train-Case/233264525474
//ffmpeg -i input.mp4 -af loudnorm=I=-23:LRA=7:tp=-2:print_format=json -f null -
//ffmpeg -i input.mp4 -af loudnorm=I=-23:LRA=7:tp=-2:measured_I=-30:measured_LRA=1.1:measured_tp=-11 04:measured_thresh=-40.21:offset=-0.47 -ar 48k -y output.mp4
class ARGUS_Camera: public argusNetNode, public basicEventHandler, public basicThread{
private:
basicLogCollection * m_pLog;
pOnvif * m_pOnVif;
bool m_bOnline;
bool m_bPtzCapable;
char m_pIP[16];
time_t m_tTimeTSeconds;
char m_pPassword[CTEXT];
char m_pUserName[CTEXT];
char m_pDevToken[CTEXT];
char m_pProfileToken[CTEXT];
char m_pPtzToken[CTEXT];
protected:
void m_fThreadProc( void );
public:
ARGUS_Camera();
~ARGUS_Camera();
bool create( CSTR ip, CSTR username, CSTR password );
bool isOnline( void ){ return m_bOnline; };
virtual bool dispatchEvent( basicEvent *Evt );
};
typedef std::vector<ARGUS_Camera *> vectorARGUS_Cameras;
#endif

40
lib/defender-dc-trig/rgooseNode.h

@ -1,40 +0,0 @@
#ifndef __ARGUS_NODE_HEADER__
#define __ARGUS_NODE_HEADER__
#include "../components/base/basicPosition.h"
#include "rgooseDBConnector.h"
typedef enum E_ARGUS_NODE_TYPE{
ARGUS_UNKNOWN = 0,
ARGUS_SERVER = 1,
ARGUS_ANALOG_STATIC_CAMERA,
ARGUS_ANALOG_PTZ_CAMERA,
ARGUS_IP_STATIC_CAMERA,
ARGUS_IP_PTZ_CAMERA,
ARGUS_IP_UART_GATEWAY,
ARGUS_IP_VIDEO_SERVER,
ARGUS_LFS_SENSOR,
ARGUS_ALS_SENSOR,
ARGUS_PLS_200_SENSOR,
ARGUS_PLS_360_SENSOR,
ARGUS_3D_SENSOR,
ARGUS_JAMER,
ARGUS_NET_PLS_200,
ARGUS_DRONE_CONTROL
}ARGUS_NODE_TYPE;
class argusNetNode{
protected:
ARGUS_DBC * m_pDBC;
int id;
basicPosition * m_pPos;
public:
ARGUS_NODE_TYPE type;
public:
explicit argusNetNode(ARGUS_NODE_TYPE param = ARGUS_UNKNOWN){ type = param; m_pPos = NULL; id = 0; };
virtual ~argusNetNode(){};
void setDBC( ARGUS_DBC *tPtr ){ m_pDBC = tPtr; };
};
#endif

143
lib/defender-dc-trig/rgooseNodeFactory.cpp

@ -1,143 +0,0 @@
#include "rgooseNodeFactory.h"
#define LOG( X ) m_pLog->Log( "NFAC", this, X )
#define LOG_ERROR( X ) m_pLog->Log( "NFAC", this, _LOG_ERROR, X )
argusNodeFactory * argusNodeFactory::_instance = 0;
/**
* Returns the single instance of the object.
*/
argusNodeFactory* argusNodeFactory::getInstance() {
// check if the instance has been created yet
if (0 == _instance) {
// if not, then create it
_instance = new argusNodeFactory;
}
// return the single instance
return _instance;
};
argusNodeFactory::argusNodeFactory(){
m_pLog = basicLogCollection::getInstance();
m_pDBC = NULL;
};
argusNodeFactory::~argusNodeFactory(){
if( m_vNetNodes.size() > 0 ){
for( vectorNetNodes::iterator index = m_vNetNodes.begin(); index < m_vNetNodes.end(); index++ ){
switch( (*index)->type ){
//case ARGUS_ANALOG_STATIC_CAMERA: delete( (chucha*) (*index) ); break;
case ARGUS_IP_STATIC_CAMERA: delete( (ARGUS_Camera*) (*index) ); break;
};
};
m_vNetNodes.clear();
};
};
void argusNodeFactory::setDBC(ARGUS_DBC * tPtr){
if( (m_pDBC == NULL) && (tPtr != NULL) ) m_pDBC = tPtr;
};
bool argusNodeFactory::loadNodes( uint32_t SiteID ){
if(m_pDBC == NULL) return false;
m_nSiteID = SiteID;
DBC_INT_LIST *tList = NULL;
tList = m_pDBC->listNodes( SiteID );
if( tList != NULL ) {
for(int index=0; index< tList->size(); index++) {
createNode( tList->at(index) );
};
tList->clear();
delete( tList );
return true;
};
return false;
};
argusNetNode *argusNodeFactory::createNode( int id ){
argusNetNode *tVal = NULL;
if( m_pDBC != NULL ){
DBC_NODE_DATA *tData = NULL;
tData = m_pDBC->getNodeData( id );
if( tData!= NULL ) {
switch( tData->type ) {
case ARGUS_ANALOG_STATIC_CAMERA:
#ifdef DEBUG
LOG("Creating Analog Static Camera");
#endif
break;
case ARGUS_ANALOG_PTZ_CAMERA:
#ifdef DEBUG
LOG("Creating Analog PTZ Camera");
#endif
break;
case ARGUS_IP_STATIC_CAMERA:
#ifdef DEBUG
LOG("Creating Network Static Camera");
#endif
break;
case ARGUS_IP_PTZ_CAMERA:
#ifdef DEBUG
LOG("Creating Network PTZ Camera");
#endif
break;
case ARGUS_IP_UART_GATEWAY:
#ifdef DEBUG
LOG("Creating Ethernet to UART Gateway");
#endif
break;
case ARGUS_IP_VIDEO_SERVER:
#ifdef DEBUG
LOG("Creating Network Video Encoder");
#endif
break;
case ARGUS_LFS_SENSOR:
#ifdef DEBUG
LOG("Creating LFS Sensor");
#endif
break;
case ARGUS_ALS_SENSOR:
#ifdef DEBUG
LOG("Creating ALS Sensor");
#endif
break;
case ARGUS_PLS_200_SENSOR:
#ifdef DEBUG
LOG("Creating PLS200 Sensor");
#endif
break;
case ARGUS_PLS_360_SENSOR:
#ifdef DEBUG
LOG("Creating PLS360 Sensor");
#endif
break;
case ARGUS_3D_SENSOR:
#ifdef DEBUG
LOG("Creating 3D Sensor");
#endif
break;
case ARGUS_JAMER:
#ifdef DEBUG
LOG("Creating RF Jamer");
#endif
break;
case ARGUS_NET_PLS_200:
#ifdef DEBUG
LOG("Creating Network-PLS200 Sensor");
#endif
break;
case ARGUS_DRONE_CONTROL:
#ifdef DEBUG
LOG("Creating Drone Controll");
#endif
break;
};
free(tData);
};
};
if( tVal != NULL ) m_vNetNodes.push_back( tVal );
return tVal;
};
#undef LOG
#undef LOG_ERROR

28
lib/defender-dc-trig/rgooseNodeFactory.h

@ -1,28 +0,0 @@
#ifndef __ARGUS_NODE_FACTORY_HEADER__
#define __ARGUS_NODE_FACTORY_HEADER__
#include <vector>
#include "rgooseNode.h"
#include "rgooseIPCamera.h"
typedef std::vector<argusNetNode*> vectorNetNodes;
class argusNodeFactory{
private:
basicLogCollection * m_pLog;
ARGUS_DBC * m_pDBC;
uint32_t m_nSiteID;
vectorNetNodes m_vNetNodes;
public:
static argusNodeFactory * getInstance();
virtual ~argusNodeFactory();
argusNetNode * createNode( int id );
bool loadNodes( uint32_t SiteID = 0 );
void setDBC(ARGUS_DBC * tPtr);
protected:
argusNodeFactory();
private:
static argusNodeFactory * _instance;
};
#endif

6
lib/defender-dc-trig/rgooseServerModule.cpp

@ -1,6 +0,0 @@
#include "rgooseServerModule.h"
argusServerModule::argusServerModule(ARGUS_DBC * DBC):basicEventHandler(){
m_pDBC = DBC;
};
argusServerModule::~argusServerModule(){};

16
lib/defender-dc-trig/rgooseServerModule.h

@ -1,16 +0,0 @@
#ifndef __ARGUS_SERVER_MODULE_HEADER__
#define __ARGUS_SERVER_MODULE_HEADER__
#include "rgooseDBConnector.h"
#include "../components/base/basicEventHandler.h"
class argusServerModule: public basicEventHandler{
private:
ARGUS_DBC * m_pDBC;
public:
explicit argusServerModule( ARGUS_DBC * DBC );
virtual ~argusServerModule();
virtual bool dispatchEvent( basicEvent *Evt ){ return true; };
};
#endif

127
lib/defender-dc-trig/rgooseStructures.h

@ -1,127 +0,0 @@
#ifndef __R_GOOSE_DATA_STRUCTURES_HEADER__
#define __R_GOOSE_DATA_STRUCTURES_HEADER__
#incldue <stdint.h>
typedef enum E_MeasurementUnits{
MU_COUNTS = 0,
MU_METERS = 1,
MU_DEG,
MU_RAD,
MU_CELSIUS,
MU_SECONDS,
MU_PIXELS
} measurementUnits;
typedef struct S_WGS84_Location{
float lat;
float lon;
float alt;
} locationWGS84, locationAnchore, * p_locationWGS84, * p_locationAnchore;
typedef struct S_XYZ_Location{
float x;
float y;
float z;
} locationXYZ, locationRelative, * p_locationXYZ, * p_locationRelative;
typedef struct S_Orientation{
float phi;
float sigma;
float tau;
} orientation;
typedef struct S_Position{
locationXYZ d;
locationAnchore at;
orientation world;
} position;
typedef enum E_RGooseNodeClasses{
NC_NODEF = 0,
NC_ACCESS = 1,
NC_IMAGER,
NC_STORAGE,
NC_ANALYTIC,
NC_UI_IO
} rgooseNodeClass, * p_RgooseNodeClass;
#ifdef __linux__
typedef unsigned long long timeStamp;
#else
typedef unsigned __int64 timeStamp;
#endif
typedef char[32] UOID, * PUOID;
typedef struct S_Event_Source{
uint32_t db_id;
position pos;
rgooseNodeClass cls;
uint8_t sub;
timeStamp utc;
UOID uid;
} eventSource;
typedef enum E_Capabilities{
FC_ALARM_INIT = 0,
FC_ALARM_RCPT = 1,
FC_IMAGE_ASC = 2,
FC_VIDEO_ASC = 3,
FC_AUDIO_ASC = 4,
FC_FINGER_ASC = 5,
FC_CODE_ASC = 6,
FC_RFID_ASC = 7,
FC_MOVE_PAN = 8,
FC_MOVE_TILT = 9,
FC_MOVE_ZOOM = 10,
FC_HAVE_PRESET = 11,
FC_CAN_APROVE = 12,
FC_CAN_CLEANUP = 13,
FC_RESET = 14,
FC_RECORD_DATA = 15,
FC_LIGHT_ON = 16,
FC_SUGGEST = 17
} nodeCaps;
typedef enum E_CapabilityFlags{
FCF_ALARM_INIT = 1,
FCF_ALARM_RCPT = 2,
FCF_IMAGE_ASC = 4,
FCF_VIDEO_ASC = 8,
FCF_AUDIO_ASC = 16,
FCF_FINGER_ASC = 32,
FCF_CODE_ASC = 64,
FCF_RFID_ASC = 128,
FCF_MOVE_PAN = 256,
FCF_MOVE_TILT = 512,
FCF_MOVE_ZOOM = 1024,
FCF_HAVE_PRESET = 2048,
FCF_CAN_APROVE = 4096,
FCF_CAN_CLEANUP = 8192,
FCF_RESET = 16384,
FCF_RECORD_DATA = 32768,
FCF_LIGHT_ON = 65536,
FCF_SUGGEST = 131072
} nodeCapFlag;
typedef enum E_AccessLevels{
AL_NONE = 0,
AL_TREAT = 1,
AL_SUSPISIOUSE,
AL_IDENT,
AL_GUEST,
AL_OPERATOR,
AL_OPERATOR_PLUS,
AL_ADMINISTRATOR,
AL_GOD
} rgooseAccesLevel, * p_RgooseAccesLevel;
typedef struct S_Persone{
uint32_t db_id;
rgooseAccesLevel access;
UOID uid;
} rgoosePersone, *pRgoosePersone;
#endif

298
lib/defender-dc-trig/rgooseUSBRelayModule.cpp

@ -1,298 +0,0 @@
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <hidapi/hidapi.h>
#include "rgooseUSBRelayModule.h"
//Global variables
unsigned short vendor_id = 0x16c0;
unsigned short product_id = 0x05df;
relay_board *relay_boards = 0;
int relay_board_count = 0;
int i, k;
//Private function prototypes
static int get_board_features(relay_board *board, hid_device *handle);
/**
* Enumerate all possible relay devices in the system
*/
int enumerate_relay_boards(const char *product, int verbose, int debug){
char *vendor;
int result = 0;
struct hid_device_info *devs, *cur_dev;
//If we were given a product code, use it
if (product != NULL)
{
vendor = strsep((char **)&product, ":");
if (vendor && *vendor)
{
vendor_id = strtol(vendor, NULL, 16);
}
if (product && *product)
{
product_id = strtol(product, NULL, 16);
}
}
//Enumerate USB devices with the given IDs
devs = hid_enumerate(vendor_id, product_id);
//Count the number of returned devices
cur_dev = devs;
for (relay_board_count = 0; cur_dev != NULL; relay_board_count++)
{
cur_dev = cur_dev->next;
}
//Allocate a buffer for the relays
if (relay_board_count > 0)
{
relay_boards = (relay_board *) malloc((relay_board_count) * sizeof(relay_board));
//Fill the relay structs
cur_dev = devs;
for (i = 0; i < relay_board_count; i++)
{
//Save the path to this device
relay_boards[i].path = (char *) malloc(strlen(cur_dev->path)+1);
memcpy(relay_boards[i].path, cur_dev->path, strlen(cur_dev->path) + 1);
// The product string is USBRelayx where x is number of relays read to the \0 in case there are more than 9
relay_boards[i].relay_count = atoi((const char *)&cur_dev->product_string[8]);
//Open it to get more details
hid_device *handle;
handle = hid_open_path(cur_dev->path);
if (handle)
{
result = get_board_features(&relay_boards[i], handle);
hid_close(handle);
}
else
{
perror("unable to open device\n");
result = -1;
}
//Output the device enumeration details if verbose is on
if (verbose)
{
fprintf(stderr, "Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
fprintf(stderr, "\n");
fprintf(stderr, " Manufacturer: %ls\n", cur_dev->manufacturer_string);
fprintf(stderr, " Product: %ls\n", cur_dev->product_string);
fprintf(stderr, " Release: %hx\n", cur_dev->release_number);
fprintf(stderr, " Interface: %d\n", cur_dev->interface_number);
fprintf(stderr, " Number of Relays = %d\n", relay_boards[i].relay_count);
//If verbose and debug are on, output individual relay details
if (debug)
{
for (k = 0; k < relay_boards[i].relay_count; k++)
{
if (relay_boards[i].state & 1 << k)
{
printf("%s_%d=1\n", relay_boards[i].serial, k + 1);
}
else
{
printf("%s_%d=0\n", relay_boards[i].serial, k + 1);
}
}
}
}
cur_dev = cur_dev->next;
}
}
hid_free_enumeration(devs);
return result;
}
/**
* Command a relay at a particular /dev path to switch to a given state
*/
int operate_relay(const char *serial, unsigned char relay, unsigned char target_state)
{
unsigned char buf[9]; // 1 extra byte for the report ID
int res = -1;
hid_device *handle;
relay_board *board = find_board(serial);
if (board != NULL && relay >0 && relay <= board->relay_count)
{
handle = hid_open_path(board->path);
if (handle)
{
buf[0] = 0x0; //report number
buf[1] = target_state;
buf[2] = relay;
buf[3] = 0x00;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
buf[7] = 0x00;
buf[8] = 0x00;
res = hid_write(handle, buf, sizeof(buf));
}
else
{
res = -1;
}
if (res > 0)
{
//Update our relay status
res = get_board_features(board, handle);
}
else
{
fprintf(stderr, "Unable to write()\n");
fprintf(stderr, "Error: %ls\n", hid_error(handle));
}
hid_close(handle);
}
return (res);
}
int set_serial(const char *serial, char *newserial)
{
unsigned char buf[9]; // 1 extra byte for the report ID
int res = -1;
hid_device *handle;
relay_board *board = find_board(serial);
if (board != NULL)
{
handle = hid_open_path(board->path);
if (handle)
{
buf[0] = 0x0; //report number
buf[1] = CMD_SET_SERIAL;
buf[2] = newserial[0];
buf[3] = newserial[1];
buf[4] = newserial[2];
buf[5] = newserial[3];
buf[6] = newserial[4];
buf[7] = 0x00;
buf[8] = 0x00;
res = hid_write(handle, buf, sizeof(buf));
}
else
{
res = -1;
}
if (res > 0)
{
//Update our copy of the serial number
res = get_board_features(board, handle);
}
else
{
fprintf(stderr, "Unable to write()\n");
fprintf(stderr, "Error: %ls\n", hid_error(handle));
}
hid_close(handle);
}
return (res);
}
/**
* Find a board path given a relay board serial
*/
relay_board *find_board(const char *serial)
{
for (i = 0; i < relay_board_count; i++)
{
if (strcmp(relay_boards[i].serial, serial) == 0)
{
return &relay_boards[i];
}
}
return NULL;
}
/**
* Return the count of relay boards
*/
int get_relay_board_count()
{
return relay_board_count;
}
/**
* Return the actual relay_board structs
*/
relay_board *get_relay_boards()
{
return relay_boards;
}
/**
* Return all allocated resources and perform any other cleanup
*/
void shutdown()
{
/* Free static HIDAPI objects. */
hid_exit();
for (i = 0; i < relay_board_count; i++)
{
free(relay_boards[i].path);
}
if (relay_board_count > 0)
{
free(relay_boards);
}
}
//Private functions
/**
* Load the board serial and relay status
* This intentionally reuses a handle as it's meant to be called by the
* other functions while they have one already open
*/
static int get_board_features(relay_board *board, hid_device *handle)
{
unsigned char buf[9];
//Get the features of the device
buf[0] = 0x01;
int ret = hid_get_feature_report(handle, buf, sizeof(buf));
if (ret == -1)
{
perror("hid_get_feature_report\n");
}
//Set the serial number (0x0 for termination)
memset(board->serial, 0x0, sizeof(board->serial));
memcpy(board->serial, buf, Serial_Length);
//Byte 7 in the response contains the target_state of the relays
board->state = buf[7];
return ret;
}
argusUSBRelayModule::argusUSBRelayModule( uint32_t ModuleID, ARGUS_DBC *DBC ) : argusServerModule( DBC ){
m_nModuleID = ModuleID;
};
argusUSBRelayModule::~argusUSBRelayModule(){};
void argusUSBRelayModule::dispatchEvent( basicEvent *Evt ){};

43
lib/defender-dc-trig/rgooseUSBRelayModule.h

@ -1,43 +0,0 @@
#ifndef __ARGUS_USB_RELAY_MODULE_HEADER__
#define __ARGUS_USB_RELAY_MODULE_HEADER__
#include "rgooseServerModule.h"
//Configuration
#define CMD_ON 0xff
#define CMD_OFF 0xfd
#define CMD_SET_SERIAL 0xfa
#define Serial_Length 6 // 5+1 for the \0 string terminator
//Struct for relay boards
typedef struct S_relay_board {
char serial[Serial_Length];
unsigned char relay_count;
unsigned char state;
char *path;
} relay_board;
int enumerate_relay_boards( const char *product, int verbose, int debug);
int operate_relay( const char *path,unsigned char relay, unsigned char state);
int set_serial( const char *path,char *newserial);
relay_board *find_board( const char *serial);
int get_relay_board_count( void);
relay_board* get_relay_boards(void);
void shutdown(void);
class argusUSBRelayModule: public argusServerModule {
private:
relay_board m_sBoardDef;
uint32_t m_nModuleID;
uint32_t m_nNO_CONFIG;
uint32_t m_nCURRENT_STATE;
uint32_t m_aCHANNEL_CONFIGS[32];
public:
explicit argusUSBRelayModule( uint32_t ModuleID, ARGUS_DBC *DBC );
virtual ~argusUSBRelayModule();
virtual void dispatchEvent( basicEvent *Evt );
};
#endif

9
lib/defender-dc-trig/rgooseVideoTranscoderModule.h

@ -1,9 +0,0 @@
#ifndef __ARGUS_VIDEO_TRANSCODER_MODULE_HEADER__
#define __ARGUS_VIDEO_TRANSCODER_MODULE_HEADER__
class argusVideoTranscoder{
public:
argusVideoTranscoder();
};
#endif
Loading…
Cancel
Save