diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 8d62327c..aaee6626 100755 --- a/Projects/la_mojo/build +++ b/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 .. diff --git a/lib/App/3dGUI/main-qt.cpp b/lib/App/3dGUI/main-qt.cpp deleted file mode 100644 index 79cc97db..00000000 --- a/lib/App/3dGUI/main-qt.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#ifndef __linux__ - #include -#endif -#include -//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 -#include -#include -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; -} - -*/ - diff --git a/lib/App/3dGUI/main_window.cpp b/lib/App/3dGUI/main_window.cpp deleted file mode 100644 index aff68fc1..00000000 --- a/lib/App/3dGUI/main_window.cpp +++ /dev/null @@ -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(); -}; \ No newline at end of file diff --git a/lib/App/3dGUI/main_window.h b/lib/App/3dGUI/main_window.h deleted file mode 100644 index 8891d029..00000000 --- a/lib/App/3dGUI/main_window.h +++ /dev/null @@ -1,216 +0,0 @@ -#ifndef __QT5_MAIN_WINDOW_HEADER__ -#define __QT5_MAIN_WINDOW_HEADER__ -#ifndef __linux__ - #include -#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 diff --git a/lib/App/3dSERVER/LRF_ClientHandler.cpp b/lib/App/3dSERVER/LRF_ClientHandler.cpp deleted file mode 100644 index 3eac6990..00000000 --- a/lib/App/3dSERVER/LRF_ClientHandler.cpp +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_ClientHandler.h b/lib/App/3dSERVER/LRF_ClientHandler.h deleted file mode 100644 index 307abec5..00000000 --- a/lib/App/3dSERVER/LRF_ClientHandler.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_DefenderHandler.cpp b/lib/App/3dSERVER/LRF_DefenderHandler.cpp deleted file mode 100644 index 9887a453..00000000 --- a/lib/App/3dSERVER/LRF_DefenderHandler.cpp +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_DefenderHandler.h b/lib/App/3dSERVER/LRF_DefenderHandler.h deleted file mode 100644 index 7d545456..00000000 --- a/lib/App/3dSERVER/LRF_DefenderHandler.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_Detector.cpp b/lib/App/3dSERVER/LRF_Detector.cpp deleted file mode 100644 index 07dfac96..00000000 --- a/lib/App/3dSERVER/LRF_Detector.cpp +++ /dev/null @@ -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(){ - -}; - diff --git a/lib/App/3dSERVER/LRF_Detector.h b/lib/App/3dSERVER/LRF_Detector.h deleted file mode 100644 index 807dea53..00000000 --- a/lib/App/3dSERVER/LRF_Detector.h +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_HardwareManager.cpp b/lib/App/3dSERVER/LRF_HardwareManager.cpp deleted file mode 100644 index 370bca69..00000000 --- a/lib/App/3dSERVER/LRF_HardwareManager.cpp +++ /dev/null @@ -1,2644 +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.cpp -// AUTHOR: gagua -// OVERVIEW -// ~~~~~~~~ -// Header file of LRF_HardwareManager.cpp -//---------------------------------------------------------------------------- -// - -#include "LRF_HardwareManager.h" - -#define LOG( X ) m_pLog->Log( "HW Manager", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "HW Manager", this, _LOG_ERROR, X ) - - -// Constructor implementation -LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){ - m_pLog = basicLogCollection::getInstance(); - m_pSettingsProvider = basicSettingsProvider::getInstance(); - if( m_pSettingsProvider ) { - m_pSettings = m_pSettingsProvider->getSubNode( SNode, "HARDWARE_MANAGER" ); - if( m_pSettingsProvider->isCompromised() ) { - m_pSettingsProvider->validate(); - }; - } else { - m_pSettings = NULL; - }; - m_bWorkEnable = true; - m_bInitOK = false; - m_bDumpMemoryToDisk = false; - m_nFlipEnaFLags = 0; - m_nDetectionFilter = 0; - m_nTHVisualFlags = 0; - m_eSOC = SOC_UNKNOWN; - memset( &m_sRuntimeStatus, 0, sizeof(HWM_CSTATUS)); -#ifdef IGNORE_PRU_FLIP - m_bStudyCompleteFlag = 0; - m_bDataFilledTH = 0; -#endif - -#ifdef THREADED_FLIP - m_pFlipThreadHandler = NULL; - m_bWaitFirstFlip = true; - m_bFlipUnlockRequested = false; - m_pFlipMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); - if( m_pFlipMutex != NULL ) { - memset( m_pFlipMutex, 0, sizeof(pthread_mutex_t)); - pthread_mutexattr_t attrib; - pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK ); - if( 0 != pthread_mutex_init( m_pFlipMutex, &attrib ) ){ - free( m_pFlipMutex ); - m_pFlipMutex = NULL; - LOG_ERROR("Cannot Create Flip Protector Mutex!"); - } else { - m_pFlipThreadHandler = (pthread_t *) malloc(sizeof(pthread_t)); - if( m_pFlipThreadHandler != NULL ) { - memset( m_pFlipThreadHandler, 0, sizeof(pthread_t)); - } else { - pthread_mutex_destroy(m_pFlipMutex); - free(m_pFlipMutex); - m_pFlipMutex = NULL; - LOG_ERROR("Cannot Allocate Flip Thread!"); - }; - }; - } else { - LOG_ERROR("Cannot Allocate Flip Protector Mutex!"); - }; -#endif -#ifndef PRU_SLAVE - #ifndef ONPC_TOTTAL_SIMULATOR - #ifdef THREADED_MOTORS_START - m_pMotorCtrlThreadHandler = NULL; - m_pMotorCtrlMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); - if( m_pMotorCtrlMutex != NULL ) { - memset( m_pMotorCtrlMutex, 0, sizeof(pthread_mutex_t)); - pthread_mutexattr_t attrib; - pthread_mutexattr_settype( &attrib, PTHREAD_MUTEX_ERRORCHECK ); - if( 0 != pthread_mutex_init( m_pMotorCtrlMutex, &attrib ) ){ - free( m_pMotorCtrlMutex ); - m_pMotorCtrlMutex = NULL; - LOG_ERROR("Cannot Create Motor Ctrl Protector Mutex!"); - } else { - m_pMotorCtrlThreadHandler = (pthread_t *) malloc(sizeof(pthread_t)); - if( m_pMotorCtrlThreadHandler != NULL ) { - memset( m_pMotorCtrlThreadHandler, 0, sizeof(pthread_t)); - } else { - pthread_mutex_destroy(m_pMotorCtrlMutex); - free(m_pMotorCtrlMutex); - m_pMotorCtrlMutex = NULL; - LOG_ERROR("Cannot Allocate Motor Ctrl Thread!"); - }; - }; - } else { - LOG_ERROR("Cannot Allocate Motor Ctrl Protector Mutex!"); - }; - #endif - #else - LOG("Motors are disabled by Build - TOTTAL SIMULATION BUILD!"); - #endif - //m_bMotorsViaTGZ = false; - m_pCanBus = NULL; - m_pTGZdevice = NULL; - -#else - LOG("Motors are disabled by Build - SLAVE LRF BUILD!"); -#endif - - - memset( &m_sPARAMETERS, 0 ,sizeof( LGS_3D_PARAMETERS )); - - m_sPARAMETERS.flags.BaseScanCount = BASE_SCAN_COUNT; - m_sPARAMETERS.flags.DetectorsCount = KERNEL_COUNT; - m_sPARAMETERS.flags.MirrorScanCount = Q_SCAN_COUNT; - m_sPARAMETERS.flags.MirrorsCount = Q_MIRROR_COUNT; - - m_vMemoryBlock[0] = NULL; - m_vMemoryBlock[1] = NULL; - m_vMemoryBlock[2] = NULL; - m_vMemoryBlock[3] = NULL; -#ifndef ONPC_TOTTAL_SIMULATOR - m_pSOC = classSOC::getInstance(); - if( m_pSOC!= NULL ) { - m_bInitOK = readPercs(); - } else { - LOG_ERROR( "SOC Control module failure!" ); - }; - if( m_bInitOK && m_pSettings!= NULL ){ - m_bInitOK = create( m_pSettings ); - }; -#endif -}; - -// Destructor implementation -LRF_HardwareManager::~LRF_HardwareManager(){ - endService(); - if( m_vMemoryBlock[0]!=NULL )free( m_vMemoryBlock[0]); - if( m_vMemoryBlock[1]!=NULL )free( m_vMemoryBlock[1]); - if( m_vMemoryBlock[2]!=NULL )free( m_vMemoryBlock[2]); - if( m_vMemoryBlock[3]!=NULL )free( m_vMemoryBlock[3]); - -#ifndef PRU_SLAVE - if( m_pTGZdevice ){ - LOG( "Deleting TGZ device"); - delete( m_pTGZdevice ); - }; - //ToDo: Check CAN Bus Destructor - Hangs - //ToDo: Delete Threads Mem - if( m_pCanBus ){ - LOG( "Deleting CAN bus"); - delete( m_pCanBus ); - }; -#endif - LOG( "HW manager - DONE!"); -}; - -bool LRF_HardwareManager::readPercs( void ){ - int MEM_FD; - void *PERC_MMAP; - char Buffer[256]; - - LOG("Reading SOC Percs"); - MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC ); - if( MEM_FD == -1 ) { - sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno)); - LOG_ERROR( Buffer ); - return false; - }; - PERC_MMAP = mmap( NULL, - 0x2000, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_LOCKED, - MEM_FD, - AM437X_SIGN_ZONE ); - close( MEM_FD ); - if( PERC_MMAP == MAP_FAILED ) { - sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno)); - LOG_ERROR( Buffer ); - return false; - }; - if( (*((uint32_t *)PERC_MMAP))== AM437X_SIGN_VAL ) { - LOG( "Detected AM437x SOC Machine"); - m_eSOC = SOC_AM437X; - munmap( PERC_MMAP, 0x2000 ); - return true; - }; - munmap( PERC_MMAP, 0x2000 ); - MEM_FD = open( "/dev/mem", O_RDWR | O_SYNC ); - if( MEM_FD == -1 ) { - sprintf( Buffer, "Memory File Open Failed Error: %s", strerror(errno)); - LOG_ERROR( Buffer ); - return false; - }; - PERC_MMAP = mmap( NULL, - 0x2000, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_LOCKED, - MEM_FD, - AM355X_SIGN_ZONE ); - close( MEM_FD ); - if( PERC_MMAP == MAP_FAILED ) { - sprintf( Buffer, "Memory Region Map Failed Error: %s\n", strerror(errno)); - LOG_ERROR( Buffer ); - return false; - }; - if( (*((volatile uint32_t *)PERC_MMAP))== AM355X_SIGN_VAL ) { - LOG( "Detected AM355x SOC Machine"); - m_eSOC = SOC_AM335X; - munmap( PERC_MMAP, 0x2000 ); - return true; - }; - munmap( PERC_MMAP, 0x2000 ); - LOG( "Cannot detect SOC type"); - return false; -}; - -bool LRF_HardwareManager::create( config_setting_t *Settings ){ - config_setting_t *pSetting; - int tVal; - char tBuffer[256]; - if( Settings != NULL ) { - LOG("HW Getting Settings ..."); - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_TH_DUMP, &tVal ) ){ - tVal = m_bDumpMemoryToDisk = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_TH_DUMP, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Memory Dumping defined"); - } else { - m_bDumpMemoryToDisk = (bool)tVal; - sprintf( tBuffer, "TH Memory Dumping Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_ROLE, &tVal ) ){ - tVal = m_sPARAMETERS.flags.isMaster = true; - pSetting = config_setting_add( Settings, HWM_SETTINGS_ROLE, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No role defined"); - } else { - m_sPARAMETERS.flags.isMaster = (bool)tVal; - sprintf( tBuffer, "Role Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SUNBIT, &tVal ) ){ - tVal = m_sPARAMETERS.flags.Sunbit_filter = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_SUNBIT, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No SUNBIT action defined - Disabling!"); - } else { - m_sPARAMETERS.flags.Sunbit_filter = (bool)tVal; - sprintf( tBuffer, "SUNBIT Action Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_LRF_ENABLED, &tVal ) ){ - tVal = m_sPARAMETERS.flags.LaserPulsesOn = true; - pSetting = config_setting_add( Settings, HWM_SETTINGS_LRF_ENABLED, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No LRF Enabled"); - } else { - m_sPARAMETERS.flags.LaserPulsesOn = (bool)tVal; - sprintf( tBuffer, "LRF ENA Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_SIG_SYMULATOR, &tVal ) ){ - tVal = m_sPARAMETERS.flags.SignalSimulator = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_SIG_SYMULATOR, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Sig Symulator Settings"); - } else { - m_sPARAMETERS.flags.SignalSimulator = (bool)tVal; - sprintf( tBuffer, "Sig Sym Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !m_sPARAMETERS.flags.SignalSimulator ) { - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, &tVal ) ){ - tVal = m_sPARAMETERS.flags.AutostartMotors = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTOSTART_ENABLED, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Motor Autostart Settings"); - } else { - m_sPARAMETERS.flags.AutostartMotors = (bool)tVal; - if( m_sPARAMETERS.flags.AutostartMotors ) { - m_sPARAMETERS.flags.VerticalMotorOn = true; - m_sPARAMETERS.flags.HorizontalMotorOn = true; - }; - sprintf( tBuffer, "AutoStart Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !m_sPARAMETERS.flags.AutostartMotors ) { - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_V_MOTOR, &tVal ) ){ - tVal = m_sPARAMETERS.flags.VerticalMotorOn = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_V_MOTOR, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Vertical Controll"); - } else { - m_sPARAMETERS.flags.VerticalMotorOn = (bool)tVal; - sprintf( tBuffer, "V-M Ctrl Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CTRL_H_MOTOR, &tVal ) ){ - tVal = m_sPARAMETERS.flags.HorizontalMotorOn = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_CTRL_H_MOTOR, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Horizontal Controll"); - } else { - m_sPARAMETERS.flags.HorizontalMotorOn = (bool)tVal; - sprintf( tBuffer, "H-M Ctrl Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - }; - } - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, &tVal )){ - tVal = m_sPARAMETERS.flags.VerticalFreq = Q_WORK_FREQ; - pSetting = config_setting_add(Settings, HWM_SETTINGS_V_MOTOR_SETPOINT, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Mirror Block Freq"); - } else { - m_sPARAMETERS.flags.VerticalFreq = tVal; - sprintf( tBuffer, "V-M Setpoint Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, &tVal )){ - tVal = m_sPARAMETERS.flags.HorizontalFreq = B_WORK_FREQ; - pSetting = config_setting_add(Settings, HWM_SETTINGS_H_MOTOR_SETPOINT, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Base Block Freq"); - } else { - m_sPARAMETERS.flags.HorizontalFreq = tVal; - sprintf( tBuffer, "H-M Setpoint Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, &tVal )){ - tVal = m_sPARAMETERS.flags.QQinterlace = Q_P_INTERLEAVE; - pSetting = config_setting_add(Settings, HWM_SETTINGS_V_PULSES_INTERLEAVE, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Q Pulses per LRF pulse Setting"); - } else { - m_sPARAMETERS.flags.QQinterlace = tVal; - sprintf( tBuffer, "Q-Pulses per LRF pulse Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_OFFSET, &tVal )){ - tVal = m_sPARAMETERS.nOffset = SIGNAL_OFFSET; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_OFFSET, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Offset Setting"); - } else { - m_sPARAMETERS.nOffset = tVal; - sprintf( tBuffer, "TH Offset Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_ORDER, &tVal )){ - tVal = m_sPARAMETERS.nOrder = SIGNAL_ORDER; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_ORDER, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Order Setting"); - } else { - m_sPARAMETERS.nOrder = tVal; -#if defined( STRONG_STAT ) || !defined( THREADED_FLIP ) - if( m_sPARAMETERS.nOrder > 7 ) m_sPARAMETERS.nOrder = 7; -#endif - sprintf( tBuffer, "TH Order Read From Settings: %d", m_sPARAMETERS.nOrder ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_DELTA, &tVal )){ - tVal = m_sPARAMETERS.nDelta = SIGNAL_DELTA; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_DELTA, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Delta Setting"); - } else { - m_sPARAMETERS.nDelta = tVal; -#if !defined( THREADED_FLIP ) - if( m_sPARAMETERS.nDelta > 127 ) m_sPARAMETERS.nDelta = 127; -#endif - sprintf( tBuffer, "TH Delta Read From Settings: %d", m_sPARAMETERS.nDelta ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_FLIP_SIZE, &tVal )){ - tVal = m_sPARAMETERS.nFlip = SCANS_TO_FLIP; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_FLIP_SIZE, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Flip Size Setting"); - } else { - m_sPARAMETERS.nFlip = tVal; - sprintf( tBuffer, "Flip Size Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_GOOD_POINTS, &tVal )){ - tVal = m_sPARAMETERS.nGPointSamples = TH_POINT_GOOD; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_GOOD_POINTS, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Good Points Setting"); - } else { - m_sPARAMETERS.nGPointSamples = tVal; -#if defined( STRONG_STAT ) || !defined( THREADED_FLIP ) - if( m_sPARAMETERS.nGPointSamples > 15 ) m_sPARAMETERS.nGPointSamples = 15; -#endif - sprintf( tBuffer, "TH Good Points Read From Settings: %d", m_sPARAMETERS.nGPointSamples ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, &tVal ) ){ - tVal = m_sPARAMETERS.flags.BuildThByCore = true; - pSetting = config_setting_add( Settings, HWM_SETTINGS_AUTO_TH_GENERATE, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Build By Core Setting"); - } else { - m_sPARAMETERS.flags.BuildThByCore = (bool)tVal; - sprintf( tBuffer, "TH Build by Core Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, &tVal )){ - tVal = m_sPARAMETERS.flags.Spike_TH = 1; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TH_SPIKE_SIZE, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Spike Threshold Setting"); - } else { - m_sPARAMETERS.flags.Spike_TH = tVal; - sprintf( tBuffer, "Spike Threshold Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, &tVal ) ){ - tVal = m_sPARAMETERS.flags.TGZ_canENA = false; - pSetting = config_setting_add( Settings, HWM_SETTINGS_CAN_CONTROL_ENABLE, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN Enable Setting"); - } else { - m_sPARAMETERS.flags.TGZ_canENA = (bool)tVal; - sprintf( tBuffer, "CAN ENA Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_BUS_ID, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_canBus = 1; - pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_BUS_ID, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN Bus ID Setting"); - } else { - m_sPARAMETERS.flags.TGZ_canBus = tVal; - sprintf( tBuffer, "CAN Bus ID Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_MY_ID, &tVal )){ -#ifndef TGD_VERSION_2 - tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x200; -#else - tVal = m_sPARAMETERS.flags.TGZ_canSRC = 0x300; -#endif - pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_MY_ID, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN My ID Setting"); - } else { - m_sPARAMETERS.flags.TGZ_canSRC = tVal; - sprintf( tBuffer, "CAN My ID Read From Settings: 0x%X", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_CAN_TGZ_ID, &tVal )){ -#ifndef TGD_VERSION_2 - tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x201; -#else - tVal = m_sPARAMETERS.flags.TGZ_canDST = 0x301; -#endif - pSetting = config_setting_add(Settings, HWM_SETTINGS_CAN_TGZ_ID, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN TGZ ID Setting"); - } else { - m_sPARAMETERS.flags.TGZ_canDST = tVal; - sprintf( tBuffer, "CAN TGZ ID Read From Settings: 0x%X", tVal ); - LOG( tBuffer ); - }; -#ifndef TGD_VERSION_2 - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_DIVIDER, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_divider = 1; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_DIVIDER, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Divider Setting"); - } else { - m_sPARAMETERS.flags.TGZ_divider = tVal; - sprintf( tBuffer, "TGZ Div Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_PRF, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_ParamQ = 35; // 35000 kHz - pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_PRF, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ PRF Setting"); - } else { - m_sPARAMETERS.flags.TGZ_ParamQ = tVal; - sprintf( tBuffer, "TGZ PRF Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_RATIO, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_ParamB = 64; - pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_RATIO, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Ratio Setting"); - } else { - m_sPARAMETERS.flags.TGZ_ParamB = tVal; - sprintf( tBuffer, "TGZ Ratio Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; -#else - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_ParamQ = ( Q_WORK_FREQ >> 2 ); - pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_MIRROR_SPEED, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Mirror Block Speed"); - } else { - m_sPARAMETERS.flags.TGZ_ParamQ = tVal; - sprintf( tBuffer, "TGZ Mirror Block Speed Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, &tVal )){ - tVal = m_sPARAMETERS.flags.TGZ_ParamB = ( B_WORK_FREQ >> 4 ); - pSetting = config_setting_add(Settings, HWM_SETTINGS_TGZ_BASE_SPEED, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Base Motor Speed"); - } else { - m_sPARAMETERS.flags.TGZ_ParamB = tVal; - sprintf( tBuffer, "TGZ Base Motor Speed Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; -#endif - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_B_SHIFT, &tVal )){ - tVal = m_sPARAMETERS.flags.B_shift = 0; - pSetting = config_setting_add(Settings, HWM_SETTINGS_B_SHIFT, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Base Shift Specified"); - } else { - m_sPARAMETERS.flags.B_shift = tVal; - sprintf( tBuffer, "Base Shift Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if (!config_setting_lookup_int(Settings, HWM_SETTINGS_Q_SHIFT, &tVal )){ - tVal = m_sPARAMETERS.flags.Q_shift = 0; - pSetting = config_setting_add(Settings, HWM_SETTINGS_Q_SHIFT, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Mirror Shift Specified"); - } else { - m_sPARAMETERS.flags.Q_shift = tVal; - sprintf( tBuffer, "Mirror Shift Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( m_pSettingsProvider->isCompromised() ) { - LOG("Save Settings"); - m_pSettingsProvider->validate(); - }; - LOG("HW Create(1) Started"); - beginService(); - LOG("HW Create(1) Done"); - }; - return m_bInitOK; -}; - -bool LRF_HardwareManager::getHardwareParams( HW_PARAMS &Params ){ - memcpy( &Params, &m_sPARAMETERS.flags, sizeof(HW_PARAMS) ); - return true; -}; - -bool LRF_HardwareManager::setHardwareParams( PHW_PARAMS Params ){ - memcpy( &m_sPARAMETERS.flags, &Params, sizeof(HW_PARAMS) ); - return true; -}; - -bool LRF_HardwareManager::getParams( LGS_3D_PARAMETERS &Params ){ - memcpy( &Params, &m_sPARAMETERS, sizeof(LGS_3D_PARAMETERS) ); - return true; -}; - -bool LRF_HardwareManager::create( HW_PARAMS &HS ){ - LOG("HW Create(2) Started"); - m_sPARAMETERS.flags.isMaster = HS.isMaster; - beginService(); - LOG("HW Create(2) Done"); - return m_bInitOK; -}; - -void LRF_HardwareManager::beginService( void ){ - m_bInitOK = false; - m_bWorkEnable = true; -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC != NULL ) { - LOG("Begin HW init process"); - LOG("Stoping all PRU Cores"); - if(!m_pSOC->pru_stop(0,0)){ - LOG_ERROR("Error Stoping PRU 0 0 Core"); - }; - if(!m_pSOC->pru_sreset(0,0)){ - LOG_ERROR("Error Resetting PRU 0 0 Core"); - }; - if(!m_pSOC->pru_disable(0,0)){ - LOG_ERROR("Error Disabling PRU 0 0 Core"); - }; - LOG("PRU 0 0 stoped"); - if(!m_pSOC->pru_stop(0,1)){ - LOG_ERROR("Error Stoping PRU 0 1 Core"); - }; - if(!m_pSOC->pru_sreset(0,1)){ - LOG_ERROR("Error Resetting PRU 0 1 Core"); - }; - if(!m_pSOC->pru_disable(0,1)){ - LOG_ERROR("Error Disabling PRU 0 1 Core"); - }; - LOG("PRU 0 1 stoped"); - if(!m_pSOC->pru_stop(1,0)){ - LOG_ERROR("Error Stoping PRU 1 0 Core"); - }; - if(!m_pSOC->pru_sreset(1,0)){ - LOG_ERROR("Error Resetting PRU 1 0 Core"); - }; - if(!m_pSOC->pru_disable(1,0)){ - LOG_ERROR("Error Disabling PRU 1 0 Core"); - }; - LOG("PRU 1 0 stoped"); - if(!m_pSOC->pru_stop(1,1)){ - LOG_ERROR("Error Stoping PRU 1 1 Core"); - }; - if(!m_pSOC->pru_sreset(1,1)){ - LOG_ERROR("Error Resetting PRU 1 1 Core"); - }; - if(!m_pSOC->pru_disable(1,1)){ - LOG_ERROR("Error Disabling PRU 1 1 Core"); - }; - LOG("PRU 1 1 stoped"); -#ifndef PRU_SLAVE - if( m_sPARAMETERS.flags.isMaster ) { - // If enable TGZ CAN connection - if( m_sPARAMETERS.flags.TGZ_canENA ) { - // Init TGZ connection - char tBuf[16]; - sprintf( tBuf, "can%d", m_sPARAMETERS.flags.TGZ_canBus ); - m_pCanBus = new canBus( tBuf, - m_sPARAMETERS.flags.TGZ_canSRC, - m_sPARAMETERS.flags.TGZ_canDST ); - - if( m_pCanBus != NULL ) { - LOG("CAN Bus creation success"); - m_pTGZdevice = new protocolTGZ( m_pCanBus ); - if( m_pTGZdevice == NULL ) { - LOG_ERROR("TGZ protocol creation failure"); - delete( m_pCanBus ); - m_pCanBus = NULL; - }else{ - LOG("TGZ protocol creation success"); - }; - } else { - LOG_ERROR("CAN Bus creation failure");; - }; - }; - - if( m_sPARAMETERS.flags.AutostartMotors ) { -#ifndef NO_MOTORS - LOG("Startup Motors"); - startMotors(); -#else - LOG("Startup Motors Disabled by Compilation"); -#endif - } else { - LOG("No Auto Startup Motors"); - }; - LOG("Loading MASTER set of PRU Modules"); - /* - The Order of cores to be loadedd is crucial. - The first to load - last to function (Data Acq) that depends on others - */ - if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){ - LOG_ERROR("PRU 1 1 Load - FAILURE"); - return; - }; - if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){ - LOG_ERROR("PRU 1 0 Load - FAILURE"); - return; - }; - if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){ - LOG_ERROR("PRU 0 1 Load - FAILURE"); - return; - }; -#ifdef NO_MOTORS - LOG("Loading simulation of Motors"); - if( !m_pSOC->pru_load( 0, 0, "CORE0_NOMO.bin", true ) ){ - LOG_ERROR("PRU 0 0 Load - FAILURE"); - return; - }; -#else - if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){ - LOG_ERROR("PRU 0 0 Load - FAILURE"); - return; - }; -#endif - // Make Handshake with cores - if( !m_pSOC->setCoreOnLine(3) ){ - LOG_ERROR("Core 3 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(2) ){ - LOG_ERROR("Core 2 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(1) ){ - LOG_ERROR("Core 1 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(0) ){ - LOG_ERROR("Core 0 Startup Failure"); - m_bInitOK = false; - return; - }; - - // Fill Software Info - // - if( NULL != m_pSOC ){ - gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0); - gsSOFT_INFO.FW_CORE1_TYP = m_pSOC->getPRU_TYPE(0); - gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1); - gsSOFT_INFO.FW_CORE2_TYP = m_pSOC->getPRU_TYPE(1); - gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2); - gsSOFT_INFO.FW_CORE3_TYP = m_pSOC->getPRU_TYPE(2); - gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3); - gsSOFT_INFO.FW_CORE4_TYP = m_pSOC->getPRU_TYPE(3); - gsSOFT_INFO.DATA_VALID = true; - }; - - - // Configure Cores to current Config - // Core 0 - if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){ - LOG_ERROR("Set SUNBIT Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ - LOG_ERROR("Set Motor's Monitor Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { - LOG_ERROR("Set Motor's Interleave Mode Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { - LOG_ERROR("Set Motor's Setpoints Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) { - LOG_ERROR("Set LRF Pulses Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) { - LOG_ERROR("Set LRF Simulation Mode Failure"); - m_bInitOK = false; - return; - }; - // Core 2 - // Set Shifts - if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) { - LOG_ERROR("Set B-Q Shifts Failure"); - m_bInitOK = false; - return; - }; - // Core 3 - m_sCP_Detector.delta = m_sPARAMETERS.nDelta; - m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; - m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; - m_sCP_Detector.offset = m_sPARAMETERS.nOffset; - m_sCP_Detector.order = m_sPARAMETERS.nOrder; - m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore; - m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster; - -#ifdef DEBUG - char Buffer[256]; - sprintf( Buffer, "Detector[%s] Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", - ((m_sCP_Detector.master)?"M":"S"), - m_sCP_Detector.delta, - m_sCP_Detector.flip_size, - m_sCP_Detector.good_points, - m_sCP_Detector.order, - m_sCP_Detector.offset, - m_sCP_Detector.self_build_ena - ); - LOG( Buffer ); -#endif - if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){ - LOG_ERROR("Detection Core Set Params Failure"); - m_bInitOK = false; - return; - }; - m_sCS_Detector.h_dencity = 2; - m_sCS_Detector.mode = 0; - m_sCS_Detector.online = 0; - m_sCS_Detector.param_err = 0; - m_sCS_Detector.req = 0; - m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH; - m_sCS_Detector.v_dencity = 2; - m_sCS_Detector.work_en = 0; -#ifdef DEBUG - sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]", - m_sCS_Detector.mode, - m_sCS_Detector.spike_th, - m_sCS_Detector.v_dencity, - m_sCS_Detector.h_dencity - ); - LOG( Buffer ); -#endif - if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){ - LOG_ERROR("Detection Core Set Statuses Failure"); - m_bInitOK = false; - return; - }; - // If Work is Enabled Enable Detection Work - if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) { - LOG_ERROR("Detection Core Enabling Failure"); - m_bInitOK = false; - return; - }; - m_bInitOK = true; - } else { // Slave Mode -#else // PRU_SLAVE - { -#endif - LOG_ERROR("Motors control Disabled by Slave Mode!"); - LOG("Loading SLAVE set of PRU Modules"); - /* - The Order of cores to be loadedd is crucial. - The first to load - last to function (Data Acq) that depends on others - */ - if( !m_pSOC->pru_load( 1, 1, "PRU_1_1.bin", false ) ){ - LOG_ERROR("PRU 1 1 Load - FAILURE"); - return; - }; - if( !m_pSOC->pru_load( 1, 0, "PRU_1_0.bin", false ) ){ - LOG_ERROR("PRU 1 0 Load - FAILURE"); - return; - }; - if( !m_pSOC->pru_load( 0, 1, "PRU_0_1.bin", true ) ){ - LOG_ERROR("PRU 0 1 Load - FAILURE"); - return; - }; - if( !m_pSOC->pru_load( 0, 0, "PRU_0_0.bin", true ) ){ - LOG_ERROR("PRU 0 0 Load - FAILURE"); - return; - }; - // Make Handshake with cores - if( !m_pSOC->setCoreOnLine(3) ){ - LOG_ERROR("Core 3 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(2) ){ - LOG_ERROR("Core 2 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(1) ){ - LOG_ERROR("Core 1 Startup Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setCoreOnLine(0) ){ - LOG_ERROR("Core 0 Startup Failure"); - m_bInitOK = false; - return; - }; - // Fill Software Info - // - if( NULL != m_pSOC ){ - gsSOFT_INFO.FW_CORE1_VER = m_pSOC->getPRU_ID(0); - gsSOFT_INFO.FW_CORE2_VER = m_pSOC->getPRU_ID(1); - gsSOFT_INFO.FW_CORE3_VER = m_pSOC->getPRU_ID(2); - gsSOFT_INFO.FW_CORE4_VER = m_pSOC->getPRU_ID(3); - gsSOFT_INFO.DATA_VALID = true; - }; - - // Configure Cores to current Config - // Core 0 - if( !m_pSOC->setSunbitMode( m_sPARAMETERS.flags.Sunbit_filter ) ){ - LOG_ERROR("Set SUNBIT Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ - LOG_ERROR("Set Motor's Monitor Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { - LOG_ERROR("Set Motor's Interleave Mode Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { - LOG_ERROR("Set Motor's Setpoints Failure"); - m_bInitOK = false; - return; - }; - if( !m_pSOC->setLrfPulseMode( m_sPARAMETERS.flags.LaserPulsesOn ) ) { - LOG_ERROR("Set LRF Pulses Mode Failure"); - m_bInitOK = false; - return; - }; - - if( !m_pSOC->setSimulationMode( m_sPARAMETERS.flags.SignalSimulator ) ) { - LOG_ERROR("Set LRF Simulation Mode Failure"); - m_bInitOK = false; - return; - }; - // Core 2 - // Set Shifts - if( !m_pSOC->setShifts( m_sPARAMETERS.flags.B_shift, m_sPARAMETERS.flags.Q_shift ) ) { - LOG_ERROR("Set B-Q Shifts Failure"); - m_bInitOK = false; - return; - }; - // Core 3 - m_sCP_Detector.delta = m_sPARAMETERS.nDelta; - m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; - m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; - m_sCP_Detector.offset = m_sPARAMETERS.nOffset; - m_sCP_Detector.order = m_sPARAMETERS.nOrder; - m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore; -#ifdef DEBUG - char Buffer[256]; - sprintf( Buffer, "Detector Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", - m_sCP_Detector.delta, - m_sCP_Detector.flip_size, - m_sCP_Detector.good_points, - m_sCP_Detector.order, - m_sCP_Detector.offset, - m_sCP_Detector.self_build_ena - ); - LOG( Buffer ); -#endif - if( !m_pSOC->setThCoreParams( &m_sCP_Detector )){ - LOG_ERROR("Detection Core Set Params Failure"); - m_bInitOK = false; - return; - }; - m_sCS_Detector.h_dencity = 2; - m_sCS_Detector.mode = 0; - m_sCS_Detector.online = 0; - m_sCS_Detector.param_err = 0; - m_sCS_Detector.req = 0; - m_sCS_Detector.spike_th = m_sPARAMETERS.flags.Spike_TH; - m_sCS_Detector.v_dencity = 2; - m_sCS_Detector.work_en = 0; -#ifdef DEBUG - sprintf( Buffer, "Detector Status: Mode[%d] Spike_TH[%d] V_dencity[%d] H_dencity[%d]", - m_sCS_Detector.mode, - m_sCS_Detector.spike_th, - m_sCS_Detector.v_dencity, - m_sCS_Detector.h_dencity - ); - LOG( Buffer ); -#endif - if( !m_pSOC->setThCoreStatus( &m_sCS_Detector )){ - LOG_ERROR("Detection Core Set Statuses Failure"); - m_bInitOK = false; - return; - }; - // If Work is Enabled Enable Detection Work - if( !m_pSOC->setToWork( m_sPARAMETERS.flags.LaserPulsesOn ) ) { - LOG_ERROR("Detection Core Enabling Failure"); - m_bInitOK = false; - return; - }; - memset( m_bTHSteadyCounter, ( m_sCP_Detector.flip_size && 0xFF ), KERNEL_COUNT); - m_bInitOK = true; - }; - }; -#else //#ifndef ONPC_TOTTAL_SIMULATOR - LOG("Dummy Init of Hardware"); - gsSOFT_INFO.FW_CORE1_VER = 0x01234567; - gsSOFT_INFO.FW_CORE1_TYP = 0x01234567; - gsSOFT_INFO.FW_CORE2_VER = 0x01234567; - gsSOFT_INFO.FW_CORE2_TYP = 0x01234567; - gsSOFT_INFO.FW_CORE3_VER = 0x01234567; - gsSOFT_INFO.FW_CORE3_TYP = 0x01234567; - gsSOFT_INFO.FW_CORE4_VER = 0x01234567; - gsSOFT_INFO.FW_CORE4_TYP = 0x01234567; - gsSOFT_INFO.DATA_VALID = true; - m_bInitOK = true; -#endif //#ifndef ONPC_TOTTAL_SIMULATOR -}; -void LRF_HardwareManager::endService( void ){ - m_bWorkEnable = false; -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC!=NULL ){ -#ifndef PRU_SLAVE - if( m_sPARAMETERS.flags.isMaster ) { - #ifndef NO_MOTORS - stopMotors(); - #endif - } else { - }; -#endif - LOG("Stoping all PRU Cores"); - if(!m_pSOC->pru_stop(0,0)){ - LOG_ERROR("Error Stoping PRU 0 0 Core"); - }; - if(!m_pSOC->pru_sreset(0,0)){ - LOG_ERROR("Error Resetting PRU 0 0 Core"); - }; - if(!m_pSOC->pru_disable(0,0)){ - LOG_ERROR("Error Disabling PRU 0 0 Core"); - }; - LOG("PRU 0 0 stoped"); - if(!m_pSOC->pru_stop(0,1)){ - LOG_ERROR("Error Stoping PRU 0 1 Core"); - }; - if(!m_pSOC->pru_sreset(0,1)){ - LOG_ERROR("Error Resetting PRU 0 1 Core"); - }; - if(!m_pSOC->pru_disable(0,1)){ - LOG_ERROR("Error Disabling PRU 0 1 Core"); - }; - LOG("PRU 0 1 stoped"); - if(!m_pSOC->pru_stop(1,0)){ - LOG_ERROR("Error Stoping PRU 1 0 Core"); - }; - if(!m_pSOC->pru_sreset(1,0)){ - LOG_ERROR("Error Resetting PRU 1 0 Core"); - }; - if(!m_pSOC->pru_disable(1,0)){ - LOG_ERROR("Error Disabling PRU 1 0 Core"); - }; - LOG("PRU 1 0 stoped"); - if(!m_pSOC->pru_stop(1,1)){ - LOG_ERROR("Error Stoping PRU 1 1 Core"); - }; - if(!m_pSOC->pru_sreset(1,1)){ - LOG_ERROR("Error Resetting PRU 1 1 Core"); - }; - if(!m_pSOC->pru_disable(1,1)){ - LOG_ERROR("Error Disabling PRU 1 1 Core"); - }; - LOG("PRU 1 1 stoped"); - if( !m_pSOC->pru_load( 0, 0, "halt.bin" ) ){ - LOG_ERROR("PRU 0 0 HALT - FAILURE"); - }; - if( !m_pSOC->pru_load( 0, 1, "halt.bin" ) ){ - LOG_ERROR("PRU 0 1 HALT - FAILURE"); - }; - if( !m_pSOC->pru_load( 1, 0, "halt.bin" ) ){ - LOG_ERROR("PRU 1 0 HALT - FAILURE"); - }; - if( !m_pSOC->pru_load( 1, 1, "halt.bin" ) ){ - LOG_ERROR("PRU 1 1 HALT - FAILURE"); - }; - }; -#else //#ifndef ONPC_TOTTAL_SIMULATOR - LOG("Dummy Shutdown Hardware"); -#endif //#ifndef ONPC_TOTTAL_SIMULATOR -}; -#ifndef PRU_SLAVE - #ifndef ONPC_TOTTAL_SIMULATOR - #ifdef THREADED_MOTORS_START -void LRF_HardwareManager::performStartMotors( void ){ - if( m_sPARAMETERS.flags.TGZ_canENA ) { - LOG("Starting TGZ device"); - if( m_pTGZdevice!= NULL ) { -#ifndef TGD_VERSION_2 - m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider ); - m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ ); - m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB ); -#else //TGD_VERSION_2 - m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ, - m_sPARAMETERS.flags.TGZ_ParamB ); -#endif //TGD_VERSION_2 - m_pTGZdevice->setRunMode( true ); - m_pTGZdevice->setErrorMode( true ); - - m_pTGZdevice->startDeviceStateInquiry(); - - //ToDo: Wait for TGD starts Motors! - //LOG( "Wait Startup TGZ"); - //SLEEP(30000); // 30 seconds - //LOG( "Done"); - } else { - LOG_ERROR("Error TGZ Device object!" ); - }; - } else { - volatile sysPwmss *mV_PWMSS = NULL; - volatile sysPwmss *mH_PWMSS = NULL; - LOG("StartMotorsProcedure"); - if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ - mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); - mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); - if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){ - // Disable PWM; - LOG("Disable Motors PWMs"); - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5); - LOG("Disable Motors PWMs - Done"); - // Polarity - mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; - mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; - - LOG("Set Motors PWMs Config"); - // Set PWM Period - mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD; - mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD; - mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD; - mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD; - LOG("Set Motors PWMs Period"); - // Set Intitial Zeroes DC - mV_PWMSS->ECAP_CAP4 = 1; - mH_PWMSS->ECAP_CAP4 = 1; - mV_PWMSS->ECAP_CAP2 = 1; - mH_PWMSS->ECAP_CAP2 = 1; - LOG("Set Motors PWMs DC"); - // Config Timer - // Running - //ECCTL1: 0x00008000 - //ECCTL2: 0x000006D6 - // Stoped - //ECCTL1: 0x00008000 - //ECCTL2: 0x000004C6 - - mV_PWMSS->ECAP_ECCTL1 = 0; - mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; - mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - mH_PWMSS->ECAP_ECCTL1 = 0; - mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; - mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // Set APWM mode - mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; - mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; - // Set module enable - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; - LOG("Set Motors PWMs Enabled"); - uint32_t index = 0; - LOG("Start Motors PWMs Spin Up"); - while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){ - if( index < VM_WORK_DUTY_CYCLE ){ - mV_PWMSS->ECAP_CAP4 = index; - while( mV_PWMSS->ECAP_CAP2 != index )usleep(5); - }; - if( index < HM_WORK_DUTY_CYCLE ){ - mH_PWMSS->ECAP_CAP4 = index; - while( mH_PWMSS->ECAP_CAP2 != index )usleep(5); - }; - usleep( 700 ); //700 microseconds; - index++; - }; - LOG("Motors PWMs Spin Up Done"); - // Set PRU to controll - if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ - LOG_ERROR("Set Motor's Monitor Mode Failure"); - return; - }; - - if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { - LOG_ERROR("Set Motor's Interleave Mode Failure"); - return; - }; - if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { - LOG_ERROR("Set Motor's Setpoints Failure"); - return; - }; - } else { - LOG_ERROR("Cannot get access to PWMSS module"); - } - }; - }; -}; - -void LRF_HardwareManager::performStopMotors( void ){ - if( m_sPARAMETERS.flags.TGZ_canENA ) { - LOG("Stoping TGZ device"); - if( m_pTGZdevice != NULL ) { - m_pTGZdevice->setRunMode( false ); - m_pTGZdevice->setErrorMode( true ); - m_pTGZdevice->startDeviceStateInquiry(); - } else { - LOG_ERROR("Error TGZ Device object!" ); - }; - } else { - if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ - //if( m_sPARAMETERS.flags.HorizontalMotorOn ) - { - volatile sysPwmss *mH_PWMSS = NULL; - LOG("Stop Horizontal Motor's PWM"); - mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); - if( mH_PWMSS!=NULL ){ - // Set PWM to 0 timeout 10 msec. - int to = 2000; - mH_PWMSS->ECAP_CAP4 = 1; - while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5); - // Turn Off Timer - mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // For Security switch Mode to eCap - mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; - // Disable PWM; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - LOG("Horizontal Motor's PWM Stoped"); - } else { - LOG_ERROR("Can not Stop Motors PWMs"); - return; - }; - //m_sPARAMETERS.flags.HorizontalMotorOn = 0; - }; - //if( m_sPARAMETERS.flags.VerticalMotorOn ) - { - volatile sysPwmss *mV_PWMSS = NULL; - LOG("Stop Vertical Motor's PWM"); - mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); - if( mV_PWMSS!=NULL ){ - // Set PWM to 0 timeout 10 msec. - int to = 2000; - mV_PWMSS->ECAP_CAP4 = 1; - while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5); - // Turn Off Timer - mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // For Security switch Mode to eCap - mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; - // Disable PWM; - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - LOG("Vertical Motor's PWM Stoped"); - } else { - LOG_ERROR("Can not Stop Motors PWMs"); - return; - }; - //m_sPARAMETERS.flags.VerticalMotorOn = 0; - }; - } else { - LOG_ERROR("Slave Device Can not Stop Motors PWMs"); - return; - }; - }; // TGZ - PWM -}; - #endif -bool LRF_HardwareManager::startMotors( bool Auto ){ -#ifdef THREADED_MOTORS_START - if( m_sPARAMETERS.flags.TGZ_canENA ) { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 0 ) { - m_sPARAMETERS.flags.AutostartMotors = 1; - saveCurrentParameters(); - }; - }; - } else { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) { - m_sPARAMETERS.flags.VerticalMotorOn = 1; - m_sPARAMETERS.flags.HorizontalMotorOn = 1; - m_sPARAMETERS.flags.AutostartMotors = 1; - saveCurrentParameters(); - }; - }; - }; - if( m_pMotorCtrlMutex != NULL ) { - if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){ - if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){ - LOG_ERROR("Thread Detach Failed!"); - pthread_mutex_unlock( m_pMotorCtrlMutex ); - }; - if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStartThreadFunction, ( void * ) this ) ) { - LOG_ERROR("Thread Creation Faled."); - pthread_mutex_unlock( m_pMotorCtrlMutex ); - }; -#ifdef DEBUG_EXTRA - LOG("TH Flip Thread Started"); -#endif - } else { -#ifdef DEBUG_EXTRA - LOG("TH Flip Request Overlapped!"); -#endif - }; - }; -#else //THREADED_MOTORS_START - if( m_sPARAMETERS.flags.TGZ_canENA ) { - LOG("Starting TGZ device"); - if( m_pTGZdevice!= NULL ) { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 0 ) { - m_sPARAMETERS.flags.AutostartMotors = 1; - saveCurrentParameters(); - }; - }; -#ifndef TGD_VERSION_2 - m_pTGZdevice->setDivider( m_sPARAMETERS.flags.TGZ_divider ); - m_pTGZdevice->setPrfMode( m_sPARAMETERS.flags.TGZ_ParamQ ); - m_pTGZdevice->setRatio( m_sPARAMETERS.flags.TGZ_ParamB ); -#else //TGD_VERSION_2 - m_pTGZdevice->setSpeeds( m_sPARAMETERS.flags.TGZ_ParamQ, - m_sPARAMETERS.flags.TGZ_ParamB ); -#endif //TGD_VERSION_2 - m_pTGZdevice->setRunMode( true ); - m_pTGZdevice->setErrorMode( true ); - - m_pTGZdevice->startDeviceStateInquiry(); - - //ToDo: Wait for TGD starts Motors! - //LOG( "Wait Startup TGZ"); - //SLEEP(30000); // 30 seconds - //LOG( "Done"); - } else { - LOG_ERROR("Error TGZ Device object!" ); - }; - } else { - volatile sysPwmss *mV_PWMSS = NULL; - volatile sysPwmss *mH_PWMSS = NULL; - LOG("StartMotorsProcedure"); - if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ - mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); - mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); - if( mV_PWMSS!=NULL && mH_PWMSS!=NULL ){ - // Disable PWM; - LOG("Disable Motors PWMs"); - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - while( mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 || mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN == 1 )usleep(5); - LOG("Disable Motors PWMs - Done"); - // Polarity - mV_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; - mH_PWMSS->ECAP_ECCTL2_bit.APWMPOL = PWM_POLARITY_INVERSE; - - LOG("Set Motors PWMs Config"); - // Set PWM Period - mV_PWMSS->ECAP_CAP3 = VM_WORK_PERIOD; - mH_PWMSS->ECAP_CAP3 = HM_WORK_PERIOD; - mV_PWMSS->ECAP_CAP1 = VM_WORK_PERIOD; - mH_PWMSS->ECAP_CAP1 = HM_WORK_PERIOD; - LOG("Set Motors PWMs Period"); - // Set Intitial Zeroes DC - mV_PWMSS->ECAP_CAP4 = 1; - mH_PWMSS->ECAP_CAP4 = 1; - mV_PWMSS->ECAP_CAP2 = 1; - mH_PWMSS->ECAP_CAP2 = 1; - LOG("Set Motors PWMs DC"); - // Config Timer - // Running - //ECCTL1: 0x00008000 - //ECCTL2: 0x000006D6 - // Stoped - //ECCTL1: 0x00008000 - //ECCTL2: 0x000004C6 - - mV_PWMSS->ECAP_ECCTL1 = 0; - mV_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; - mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - mH_PWMSS->ECAP_ECCTL1 = 0; - mH_PWMSS->ECAP_ECCTL1_bit.FREE_SOFT = 2; - mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // Set APWM mode - mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; - mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 1; - // Set module enable - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 1; - LOG("Set Motors PWMs Enabled"); - uint32_t index = 0; - LOG("Start Motors PWMs Spin Up"); - while( index < VM_WORK_DUTY_CYCLE || index < HM_WORK_DUTY_CYCLE ){ - if( index < VM_WORK_DUTY_CYCLE ){ - mV_PWMSS->ECAP_CAP4 = index; - while( mV_PWMSS->ECAP_CAP2 != index )usleep(5); - }; - if( index < HM_WORK_DUTY_CYCLE ){ - mH_PWMSS->ECAP_CAP4 = index; - while( mH_PWMSS->ECAP_CAP2 != index )usleep(5); - }; - usleep( 700 ); //700 microseconds; - index++; - }; - LOG("Motors PWMs Spin Up Done"); - // Set PRU to controll - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 0 || m_sPARAMETERS.flags.VerticalMotorOn == 0 || m_sPARAMETERS.flags.HorizontalMotorOn == 0 ) { - m_sPARAMETERS.flags.VerticalMotorOn = 1; - m_sPARAMETERS.flags.HorizontalMotorOn = 1; - m_sPARAMETERS.flags.AutostartMotors = 1; - saveCurrentParameters(); - }; - }; - if( !m_pSOC->setMotorMonitoringMode( m_sPARAMETERS.flags.VerticalMotorOn , m_sPARAMETERS.flags.HorizontalMotorOn ) ){ - LOG_ERROR("Set Motor's Monitor Mode Failure"); - return false; - }; - - if( !m_pSOC->setMotorInterleaveMode( m_sPARAMETERS.flags.QQinterlace ) ) { - LOG_ERROR("Set Motor's Interleave Mode Failure"); - return false; - }; - if( !m_pSOC->setMotorSetPoints( m_sPARAMETERS.flags.VerticalFreq , m_sPARAMETERS.flags.HorizontalFreq ) ) { - LOG_ERROR("Set Motor's Setpoints Failure"); - return false; - }; - } else { - LOG_ERROR("Cannot get access to PWMSS module"); - } - }; - }; -#endif //THREADED_MOTORS_START - return true; -}; -bool LRF_HardwareManager::stopMotors( bool Auto ){ -#ifdef THREADED_MOTORS_START - if( m_sPARAMETERS.flags.TGZ_canENA ) { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 1 ) { - m_sPARAMETERS.flags.AutostartMotors = 0; - saveCurrentParameters(); - }; - }; - } else { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) { - m_sPARAMETERS.flags.VerticalMotorOn = 0; - m_sPARAMETERS.flags.HorizontalMotorOn = 0; - m_sPARAMETERS.flags.AutostartMotors = 0; - saveCurrentParameters(); - }; - }; - }; - if( m_pMotorCtrlMutex != NULL ) { - if( 0 == pthread_mutex_trylock( m_pMotorCtrlMutex ) ){ - if( 0 != pthread_detach( *m_pMotorCtrlThreadHandler ) ){ - LOG_ERROR("Thread Detach Failed!"); - pthread_mutex_unlock( m_pMotorCtrlMutex ); - }; - if( 0 != pthread_create( m_pMotorCtrlThreadHandler, NULL, m_fMotorStopThreadFunction, ( void * ) this ) ) { - LOG_ERROR("Thread Creation Faled."); - pthread_mutex_unlock( m_pMotorCtrlMutex ); - }; -#ifdef DEBUG_EXTRA - LOG("TH Flip Thread Started"); -#endif - } else { -#ifdef DEBUG_EXTRA - LOG("TH Flip Request Overlapped!"); -#endif - }; - }; -#else //THREADED_MOTORS_START - if( m_sPARAMETERS.flags.TGZ_canENA ) { - LOG("Stoping TGZ device"); - if( m_pTGZdevice != NULL ) { - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 1 ) { - m_sPARAMETERS.flags.AutostartMotors = 0; - saveCurrentParameters(); - }; - }; - m_pTGZdevice->setRunMode( false ); - m_pTGZdevice->setErrorMode( true ); - m_pTGZdevice->startDeviceStateInquiry(); - } else { - LOG_ERROR("Error TGZ Device object!" ); - }; - } else { - if( m_pSOC!=NULL && m_sPARAMETERS.flags.isMaster ){ - if( m_sPARAMETERS.flags.HorizontalMotorOn ) { - volatile sysPwmss *mH_PWMSS = NULL; - LOG("Stop Horizontal Motor's PWM"); - mH_PWMSS = m_pSOC->getPWMSS_CTRL( 2 ); - if( mH_PWMSS!=NULL ){ - // Set PWM to 0 timeout 10 msec. - int to = 2000; - mH_PWMSS->ECAP_CAP4 = 1; - while( ( to-- ) && ( mH_PWMSS->ECAP_CAP2 != 1 ) ) usleep(5); - // Turn Off Timer - mH_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // For Security switch Mode to eCap - mH_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; - // Disable PWM; - mH_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - LOG("Horizontal Motor's PWM Stoped"); - } else { - LOG_ERROR("Can not Stop Motors PWMs"); - return false; - }; - }; - if( m_sPARAMETERS.flags.VerticalMotorOn ) { - volatile sysPwmss *mV_PWMSS = NULL; - LOG("Stop Vertical Motor's PWM"); - mV_PWMSS = m_pSOC->getPWMSS_CTRL( 1 ); - if( mV_PWMSS!=NULL ){ - if( !Auto ) { - if( m_sPARAMETERS.flags.AutostartMotors == 1 || m_sPARAMETERS.flags.VerticalMotorOn == 1 || m_sPARAMETERS.flags.HorizontalMotorOn == 1 ) { - m_sPARAMETERS.flags.VerticalMotorOn = 0; - m_sPARAMETERS.flags.HorizontalMotorOn = 0; - m_sPARAMETERS.flags.AutostartMotors = 0; - saveCurrentParameters(); - }; - }; - // Set PWM to 0 timeout 10 msec. - int to = 2000; - mV_PWMSS->ECAP_CAP4 = 1; - while( ( to-- ) && ( mV_PWMSS->ECAP_CAP2 != 1 ) )usleep(5); - // Turn Off Timer - mV_PWMSS->ECAP_ECCTL2_bit.TSCTRSTOP = 1; - // For Security switch Mode to eCap - mV_PWMSS->ECAP_ECCTL2_bit.CAP_APWM = 0; - // Disable PWM; - mV_PWMSS->CLKCONFIG_bit.EPWMCLK_EN = 0; - LOG("Vertical Motor's PWM Stoped"); - } else { - LOG_ERROR("Can not Stop Motors PWMs"); - return false; - }; - }; - } else { - LOG_ERROR("Slave Device Can not Stop Motors PWMs"); - return false; - }; - }; // TGZ <-> PWM - #endif // THREADED_MOTORS_START - return true; -}; - #endif //#ifndef ONPC_TOTTAL_SIMULATOR -#endif // PRU_SLAVE - -static uint32_t nMemoryDumpID = 0; -#ifdef ONPC_TOTTAL_SIMULATOR - static thresholdNode * DUMMY_TH_MEMORY = NULL; -#endif -thresholdNode *LRF_HardwareManager::getWorkingMemory( void ){ -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC!= NULL ){ - thresholdNode *tNode; - thresholdNode *rNode; - rNode = tNode = (thresholdNode *) m_pSOC->getTH_MEMORY(); - if( m_bDumpMemoryToDisk ) { - if( tNode != NULL ) { - LOG( "Save Memory Dump!"); - FILE *fd; - char tName[64]; - for( int index = 0; index < KERNEL_COUNT; index++ ) { - sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index ); - fd = fopen(tName, "wb+"); - if( fd != NULL ) { - uint32_t tSize; - tSize = TH_SIZE_NODES; - fwrite( &tSize, sizeof(uint32_t), 1, fd ); - fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd ); - fclose(fd); - } else { - LOG_ERROR( "Mem Dump Failure!"); - }; - tNode += TH_SIZE_NODES; - }; - nMemoryDumpID++; - }; - }; - return rNode; - }; - return NULL; -#else - if( DUMMY_TH_MEMORY == NULL ) { - LOG("Allocate Dummy buffer for TH memories"); - DUMMY_TH_MEMORY = (thresholdNode *)malloc( 2 * KERNEL_COUNT * TH_SIZE_NODES * sizeof(thresholdNode)); - }; - return DUMMY_TH_MEMORY; -#endif - -}; - -int LRF_HardwareManager::getWorkingMemoryID( void ){ - return ( nMemoryDumpID - 1 ); -}; - -uint32_t *LRF_HardwareManager::getEventMemory( void ){ -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC!= NULL ){ - return m_pSOC->getEVT_MEMORY(); - }; -#endif - return NULL; -}; - -bool LRF_HardwareManager::getCoreStatus( DT_STATUS &Status ){ -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC!=NULL ){ - *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus(); - Status = m_sCS_Detector; - if( Status.online ) return true; - }; - return false; -#else - return true; -#endif -}; - -bool LRF_HardwareManager::getDetectionParams( TH_PARAMS &Params ){ -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC!=NULL ){ - *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); - Params = m_sCP_Detector; - if( m_sCP_Detector.self_build_ena ) { - m_nDetectionFilter = 0xFF; - }; - return true; - }; - return false; -#else - return true; -#endif -}; - -bool LRF_HardwareManager::setParams( LGS_3D_PARAMETERS *Params ){ - if(Params == NULL) return false; - memcpy( &m_sPARAMETERS, Params, sizeof(LGS_3D_PARAMETERS) ); - // Save into settings - m_sCP_Detector.delta = m_sPARAMETERS.nDelta; - m_sCP_Detector.flip_size = m_sPARAMETERS.nFlip; - m_sCP_Detector.good_points = m_sPARAMETERS.nGPointSamples; - m_sCP_Detector.offset = m_sPARAMETERS.nOffset; - m_sCP_Detector.order = m_sPARAMETERS.nOrder; - m_sCP_Detector.self_build_ena = m_sPARAMETERS.flags.BuildThByCore; - m_sCP_Detector.master = m_sPARAMETERS.flags.isMaster; -#ifdef DEBUG - char Buffer[256]; - sprintf( Buffer, "Detector[%s] NEW Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", - ((m_sCP_Detector.master)?"M":"S"), - m_sCP_Detector.delta, - m_sCP_Detector.flip_size, - m_sCP_Detector.good_points, - m_sCP_Detector.order, - m_sCP_Detector.offset, - m_sCP_Detector.self_build_ena - ); - LOG( Buffer ); -#endif - -#ifndef ONPC_TOTTAL_SIMULATOR - if(m_pSOC == NULL ) return false; - // Apply new Parameters - if(!m_pSOC->setThCoreParams( &m_sCP_Detector )){ - LOG_ERROR("Detection Core Set NEW Params Failure"); - return false; - }; - *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); -#endif - saveCurrentParameters(); - return true; -}; - -bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){ - if( Params == NULL) return false; - memcpy( &m_sCP_Detector, Params, sizeof(TH_PARAMS) ); - #ifdef DEBUG - char Buffer[256]; - sprintf( Buffer, "Detector[%s] NEW Parameters: Delta[%d] Flip_Size[%d] Good_Points[%d] Order[%d] Offset[%d] TH_Automatic_Build[%d]", - ((m_sCP_Detector.master)?"M":"S"), - m_sCP_Detector.delta, - m_sCP_Detector.flip_size, - m_sCP_Detector.good_points, - m_sCP_Detector.order, - m_sCP_Detector.offset, - m_sCP_Detector.self_build_ena - ); - LOG( Buffer ); - #endif -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC == NULL ) return false; - // Apply new Parameters - if(!m_pSOC->setThCoreParams( &m_sCP_Detector )){ - LOG_ERROR("Detection Core Set NEW Params Failure"); - return false; - }; - *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); -#endif - saveCurrentParameters(); - return true; -}; - -#ifdef SIMULATE_FLIPS - static uint32_t pips_counter = 1; -#endif - -//static uint32_t stam = 0; -bool LRF_HardwareManager::validateCores( void ){ -#ifdef SIMULATE_FLIPS - pips_counter++; -#endif -#ifndef ONPC_TOTTAL_SIMULATOR - if( !m_bInitOK ) return false; - if( m_pSOC != NULL ){ - #ifndef PRU_SLAVE - *((uint32_t*)&m_sCS_Motors) = m_pSOC->getMotorStatus(); - if( m_sCS_Motors.online ){ - bool tErrors = false; - if( m_sCS_Motors.param_err ) { - LOG_ERROR("Motor Parameter Error!"); - tErrors = true; - }; - if( m_sCS_Motors.h_motor_en && !m_sCS_Motors.h_motor_ok ) { - LOG_ERROR("Basis Motor Error!"); - tErrors = true; - }; - if( m_sCS_Motors.v_motor_en && !m_sCS_Motors.v_motor_ok ) { - LOG_ERROR("Mirror Block Motor Error!"); - tErrors = true; - }; - if( tErrors )return false; - }; - #endif - *((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus(); - *((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams(); - if( m_sCP_Detector.self_build_ena ) { - m_nDetectionFilter = 0xFF; - }; - if( m_sCS_Detector.online ) { - #ifdef SIMULATE_FLIPS - if( ( pips_counter % 100 ) == 0 ){ - LOG("INJECT Flip Request!"); - m_pSOC->injectThCoreRequest( CORE3_REQ_FLIP_TH ); - }; - #endif - #ifdef THREADED_FLIP - if( m_bFlipUnlockRequested ){ - #ifdef DEBUG_EXTRA - LOG("Unlocking Flip protecting Mutex"); - #endif - if( m_pFlipMutex != NULL ){ - if( 0 != pthread_mutex_unlock( m_pFlipMutex ) ){ - LOG_ERROR("Error Unlocking Flip protecting Mutex!"); - }; - }; - m_bFlipUnlockRequested = false; - }; - #endif - if( m_sCS_Detector.req ) { - #ifdef DEBUG - //LOG("Detector CORE REQ"); - #endif - uint32_t mCoreReq; - mCoreReq = m_pSOC->getThCoreRequest(); - switch( mCoreReq ) { - #ifndef IGNORE_PRU_FLIP - case CORE3_REQ_FLIP_TH:{ - #ifdef THREADED_FLIP - if( m_pFlipMutex != NULL ) { - if( 0 == pthread_mutex_trylock( m_pFlipMutex ) ){ - if( !m_bWaitFirstFlip ) { - if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ - LOG_ERROR("Thread Detach Failed!"); - pthread_mutex_unlock( m_pFlipMutex ); - }; - } else m_bWaitFirstFlip = false; - #ifdef DEBUG_EXTRA - LOG("Build Working Threshold Memories MT Mode!"); - #endif - if( 0 != pthread_create( m_pFlipThreadHandler, NULL, m_fFlipThreadFunction, ( void * ) this ) ) { - LOG_ERROR("Thread Creation Faled."); - pthread_mutex_unlock( m_pFlipMutex ); - }; - #ifdef DEBUG_EXTRA - LOG("TH Flip Thread Started"); - #endif - } else { - #ifdef DEBUG_EXTRA - LOG("TH Flip Request Overlapped!"); - #endif - }; - } - #else //!THREADED_FLIP - #ifdef DEBUG_EXTRA - LOG("Build Working Threshold Memories NT Mode!"); - #endif - if( performFlip() ){ - #ifdef DEBUG_EXTRA - LOG("CORE REQ Done."); - #endif - } else { - LOG_ERROR("Building Detector's TH Error!"); - }; - #endif//!THREADED_FLIP - break; - }; - case CORE3_REQ_CLEAR_TH:{ - #ifdef DEBUG - LOG("Clear Threshold Memories"); - #endif - if( cleanTH(0) ){ - #ifdef DEBUG - //LOG("CORE REQ Done."); - #endif - } else { - LOG_ERROR("Cleanup Detector's TH Error!"); - } - break; - }; - #endif //!IGNORE_PRU_FLIP - default:{ - LOG_ERROR("Unrecognized Core Request!"); - }; - }; - m_pSOC->clearThCoreRequest(); - }; - if( m_sCS_Detector.param_err ) { - LOG_ERROR("Detector Parameter Error!"); - return false; - }; - }; - return true; - } else { - LOG_ERROR( "SOC Not Defined!"); - }; - return false; -#else //#ifndef ONPC_TOTTAL_SIMULATOR - return true; -#endif //#ifndef ONPC_TOTTAL_SIMULATOR -}; - -void LRF_HardwareManager::restartService( void ){ - m_nFlipEnaFLags = 0; - m_nDetectionFilter = 0; - m_nTHVisualFlags = 0; -}; - -bool LRF_HardwareManager::reset( bool Hard ){ - uint8_t lrfID; - m_nFlipEnaFLags = 0; - m_nDetectionFilter = 0; - m_nTHVisualFlags = 0; - if( Hard ){ -#ifdef DEBUG - LOG("Waiting Till Flip Process is Done"); -#endif - if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){ - if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ - LOG_ERROR("Thread Detach Failed!"); - }; - }; -#ifdef DEBUG - LOG("Stoping Cores!"); -#endif - endService(); -#ifdef DEBUG - LOG("Begin Reset TH Mems"); -#endif - // Clear TH + Working TH - for( lrfID = 0; lrfID < ( KERNEL_COUNT << 1 ); lrfID++ ){ -#ifdef DEBUG - LOG("Cleanup TH"); -#endif - cleanTH( lrfID ); -#ifdef DEBUG - LOG("Done Cleanup TH"); -#endif - }; -#ifdef DEBUG - LOG("Starting Cores!"); -#endif - beginService(); -#ifdef DEBUG - LOG("Core Startup is Done!"); -#endif - pthread_mutex_unlock( m_pFlipMutex ); -#ifdef DEBUG - LOG("TH Reset is Done!"); -#endif - } else { -#ifdef DEBUG - LOG("Waiting Till Flip Process is Done"); -#endif - if( 0 == pthread_mutex_lock( m_pFlipMutex ) ){ - if( 0 != pthread_detach( *m_pFlipThreadHandler ) ){ - LOG_ERROR("Thread Detach Failed!"); - }; - }; -#ifdef DEBUG - LOG("Begin Reset TH Mems"); -#endif - // Clean Only TH - for( lrfID = 0; lrfID < KERNEL_COUNT; lrfID++ ){ -#ifdef DEBUG - LOG("Cleanup TH"); -#endif - cleanTH( lrfID ); -#ifdef DEBUG - LOG("Done Cleanup TH"); -#endif - }; - pthread_mutex_unlock( m_pFlipMutex ); -#ifdef DEBUG - LOG("TH Reset is Done!"); -#endif - }; - return true; -}; -#ifndef PRU_SLAVE - #ifndef ONPC_TOTTAL_SIMULATOR - #ifdef THREADED_MOTORS_START - void *LRF_HardwareManager::m_fMotorStartThreadFunction( void *ptr ){ - LRF_HardwareManager *me; - me = (LRF_HardwareManager*)ptr; - me->performStartMotors(); - pthread_exit( NULL ); - return NULL; - }; - void *LRF_HardwareManager::m_fMotorStopThreadFunction( void *ptr ){ - LRF_HardwareManager *me; - me = (LRF_HardwareManager*)ptr; - me->performStopMotors(); - pthread_exit( NULL ); - return NULL; - }; - #endif //THREADED_MOTORS_START - #endif //#ifndef ONPC_TOTTAL_SIMULATOR -#endif //PRU_SLAVE - -#ifdef THREADED_FLIP -void *LRF_HardwareManager::m_fFlipThreadFunction( void *ptr ){ - LRF_HardwareManager *me; - me = (LRF_HardwareManager*)ptr; - me->performFlip(); - me->m_bFlipUnlockRequested = true; - pthread_exit( NULL ); - return NULL; -}; -#endif - - -static uint32_t m_sgnFlipCounter = 0; - -bool LRF_HardwareManager::performFlip( void ){ - if( !m_bInitOK ) return false; -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC != NULL ){ - volatile thresholdNode * th_node[16]; - uint32_t LBA_ID; - uint8_t LRF_ID; - uint32_t cMax; - uint32_t cMin; - thresholdNode tTN; - int32_t cNodeID; - int32_t sNodeID; // Start point - bool QAreaOK; -#ifdef STRONG_STAT - uint32_t cGPCount; - uint32_t cQGPCount; - uint32_t cWGPCount; - uint8_t bLooseQFlags; - uint8_t bGPointsFlags; -#endif - th_node[0] = (volatile thresholdNode *) m_pSOC->getTH_MEMORY(); - if( th_node[0] != NULL ){ -#ifdef DEBUG - char Buffer[256]; - #ifdef DEBUG_EXTRA - LOG("Start TH Build Cycle"); - sprintf( Buffer, "NF TH pointer is: %p", th_node ); - LOG( Buffer ); - #endif -#endif - th_node[1] = th_node[0]+ TH_SIZE_NODES; - th_node[2] = th_node[1]+ TH_SIZE_NODES; - th_node[3] = th_node[2]+ TH_SIZE_NODES; - th_node[4] = th_node[3]+ TH_SIZE_NODES; - th_node[5] = th_node[4]+ TH_SIZE_NODES; - th_node[6] = th_node[5]+ TH_SIZE_NODES; - th_node[7] = th_node[6]+ TH_SIZE_NODES; - th_node[8] = th_node[7]+ TH_SIZE_NODES; - th_node[9] = th_node[8]+ TH_SIZE_NODES; - th_node[10] = th_node[9]+ TH_SIZE_NODES; - th_node[11] = th_node[10]+ TH_SIZE_NODES; - th_node[12] = th_node[11]+ TH_SIZE_NODES; - th_node[13] = th_node[12]+ TH_SIZE_NODES; - th_node[14] = th_node[13]+ TH_SIZE_NODES; - th_node[15] = th_node[14]+ TH_SIZE_NODES; - - bGPointsFlags = 0; -#ifdef STRONG_STAT - bLooseQFlags = 0; -#endif - for( LRF_ID = 0; LRF_ID < KERNEL_COUNT; LRF_ID++ ){ - if( !m_bWorkEnable ) return false; -#ifdef STRONG_STAT - cGPCount = 0; - cQGPCount = 0; - cWGPCount = 0; -#endif - //Filter Disabled Kernels - if( ((1 << LRF_ID ) & m_nKernelFilter ) == 0 ) continue; - // Begin Scan Threshold - - for( LBA_ID = 0; LBA_ID < TH_SIZE_NODES; LBA_ID++ ){ - if( !m_bWorkEnable ) return false; - uint32_t LocalStrideX = LBA_ID % TH_LINE_NODES; - uint32_t LocalStrideY = LBA_ID / TH_LINE_NODES; - // Get Central TH Point - tTN.data = th_node[LRF_ID][LBA_ID].data; - // if point was blocked by SunBit - if( tTN.values.sbit ) { - tTN.values.sbit = 0; - tTN.values.cnt = 0; - tTN.values.min = 0; - tTN.values.max = 4095; - for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) { - for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) { - if( !m_bWorkEnable ) return false; - int LocalX = LocalStrideX+x; - int LocalY = LocalStrideY+y; - if( LocalY < 0 ) LocalY += Q_SCAN_COUNT; - if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT; - if( LocalX < 0 ) LocalX += M_SCAN_POINTS; - if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES; - uint32_t CleanID = ( LocalY * TH_LINE_NODES ) + LocalX; - //Masking out WTH Area - th_node[8|LRF_ID][CleanID].data = tTN.data; - }; - }; - //Treat as SUNBIT points as GOOD points - cGPCount++; - cQGPCount++; - cWGPCount++; - continue; - }; - if ( ((1 << LRF_ID ) & m_nFlipEnaFLags ) == 0 ) { - //If Building Working TH disabled for TH -#ifdef STRONG_STAT - if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){ - cGPCount++; - cQGPCount++; - } else { - if( tTN.values.cnt ) { - cGPCount++; - }; - }; -#else - if( tTN.values.cnt ){ - cGPCount++; - cQGPCount++; - }; -#endif - - } else { - //If Building Working TH enabled for TH -#ifdef STRONG_STAT - if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){ -#else - if( tTN.values.cnt ){ -#endif - // if point was measured - cMax = 0; - cMin = 4095; - QAreaOK = true; - for( int x = -m_sPARAMETERS.nOrder; x < (m_sPARAMETERS.nOrder+1); x++ ) { - for( int y = -m_sPARAMETERS.nOrder; y < (m_sPARAMETERS.nOrder+1); y++ ) { - if( !m_bWorkEnable ) return false; - int LocalX = LocalStrideX+x; - int LocalY = LocalStrideY+y; - if( LocalY < 0 ) LocalY += Q_SCAN_COUNT; - if( LocalY >= Q_SCAN_COUNT ) LocalY -= Q_SCAN_COUNT; - if( LocalX < 0 ) LocalX += M_SCAN_POINTS; - if( LocalX >= TH_LINE_NODES ) LocalX -= TH_LINE_NODES; - uint32_t TestID = ( LocalY * TH_LINE_NODES ) + LocalX; - - tTN.data = th_node[LRF_ID][TestID].data; -#ifdef STRONG_STAT - if( tTN.values.cnt >= m_sPARAMETERS.nGPointSamples ){ -#else - if( tTN.values.cnt ){ -#endif - if( cMax < tTN.values.max ) cMax = tTN.values.max; - if( cMin > tTN.values.min ) cMin = tTN.values.min; - } else { - QAreaOK = false; - break; - }; - }; - if( !QAreaOK ) break; - }; - if( QAreaOK ){ - tTN.values.cnt = 0x0F; - tTN.values.min =(cMin>m_sCP_Detector.offset)?cMin-m_sCP_Detector.offset:0; - tTN.values.max =(cMax<(4095-m_sCP_Detector.offset))?cMax+m_sCP_Detector.offset:4095; - } else { - // disable detection of that point - tTN.values.cnt = 0; - tTN.values.min = 0; - tTN.values.max = 4095; - }; -#ifdef STRONG_STAT - cGPCount++; - cQGPCount++; -#endif - } else { -#ifdef STRONG_STAT - if( tTN.values.cnt ) { - cGPCount++; - }; -#endif - // Not Enought points in values.cnt - // disable detection of that point - tTN.values.cnt = 0; -#ifndef TH_JUST_UPDATE_WORKING - tTN.values.min = 0; - tTN.values.max = 4095; -#endif - }; -#ifdef TH_JUST_UPDATE_WORKING - // Just Update - Without Remove TH Old Info - if( tTN.values.cnt ){ - th_node[8|LRF_ID][LBA_ID].data = tTN.data; - cWGPCount++; - }; -#else - if( tTN.values.cnt ){ - cWGPCount++; - }; - th_node[8|LRF_ID][LBA_ID].data = tTN.data; -#endif - }; // If Flip Enabled to Update Working TH - };//for lba_id -#ifdef STRONG_STAT - if ( cGPCount > 600000 ) { - bLooseQFlags |= ( 1 << LRF_ID ); - if( ( 600 + cQGPCount ) >= cGPCount ){ - //Turn On Detection on the Kernel X - bGPointsFlags |= ( 1 << LRF_ID ); - } else { - //Turn Off Detection on the Kernel X - bGPointsFlags &= ~( 1 << LRF_ID ); - }; - }; -#endif - - m_sRuntimeStatus._GP[LRF_ID] = cQGPCount; - m_sRuntimeStatus._MP[LRF_ID] = cGPCount; - - if( m_nDetectionFilter & (1<getTH_MEMORY(); - if( tNode != NULL ) { -#ifdef DEBUG - LOG( "Save Memory Dump!"); -#endif - FILE *fd; - char tName[64]; - for( int index = 0; index < KERNEL_COUNT; index++ ) { - sprintf( tName, "memdump_%03d-%02d.raw", nMemoryDumpID, index ); - fd = fopen(tName, "wb+"); - if( fd != NULL ) { - uint32_t tSize; - tSize = TH_SIZE_NODES; - fwrite( &tSize, sizeof(uint32_t), 1, fd ); - fwrite( tNode, sizeof(thresholdNode), TH_SIZE_NODES, fd ); - fclose(fd); - } else { - LOG_ERROR( "Mem Dump Failure!"); - }; - tNode += TH_SIZE_NODES; - }; - nMemoryDumpID++; - }; - }; - EVENT_CONTAINER *tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR_3D, EVT_FLIP, Buffer, NULL ); - if( tEvt != NULL ){ - basicEventHeap::getInstance()->broadcast( tEvt ); - // Evt utilisation done by EventHeap thread - tEvt = NULL; - }; -#ifdef HIBERNATE_ENABLE - return saveHibernatedTH(); -#else - return true; -#endif - } else { - LOG_ERROR("Cannot access TH Memory!"); - }; - } else { - LOG_ERROR("No SOC Object!"); - }; - return false; -#else //#ifndef ONPC_TOTTAL_SIMULATOR - return true; -#endif //#ifndef ONPC_TOTTAL_SIMULATOR -}; - - -#ifdef HIBERNATE_ENABLE -bool LRF_HardwareManager::saveHibernatedTH( CSTR fname ){ - FILE *fd; - fd = fopen( fname, "wb+" ); - if( fd!= NULL) { - uint32_t *mem; - uint32_t size; - mem = m_pSOC->getTH_MEMORY(); - if(mem!= NULL) { - size = TH_SIZE_NODES << 4; - fwrite( &mem, sizeof(mem), 1, fd ); // origin - fwrite( &size, sizeof(size), 1, fd ); // size - fwrite( mem, sizeof(size), size, fd ); // content - } else { - LOG_ERROR("Can not access to TH memories during save Hibernate!"); - return false; - }; - fclose( fd ); - } else { - LOG_ERROR("Can not create Hibernate File!"); - return false; - }; - return true; -}; -bool LRF_HardwareManager::loadHibernatedTH( CSTR fname ){ - FILE *fd; - fd = fopen( fname, "wb+" ); - if( fd!= NULL) { - uint32_t *mem; - uint32_t *pem; - uint32_t size; - mem = m_pSOC->getTH_MEMORY(); - if(mem!= NULL) { - fread( &pem, sizeof(mem), 1, fd ); // origin - fread( &size, sizeof(size), 1, fd ); // size - fread( mem, sizeof(size), size, fd ); // content - } else { - LOG_ERROR("Can not access to TH memories during load Hibernate!"); - return false; - }; - fclose( fd ); - } else { - LOG_ERROR("Can not read Hibernate File!"); - return false; - }; - return true; -}; -#endif - -bool LRF_HardwareManager::cleanTH( uint8_t tID ){ -#ifndef ONPC_TOTTAL_SIMULATOR - if( m_pSOC != NULL ) { - uint32_t *thPtr; - thPtr = m_pSOC->getTH_MEMORY(); - if( thPtr ){ - thPtr += ( tID & 0x0F ) * TH_SIZE_NODES; - int index = 0; // fl|Max|Min - for(; index < TH_SIZE_NODES; thPtr++, index++ ){ - if( !m_bWorkEnable ) return false; - *thPtr = 0x00000FFF; - } - return true; - }; - }; - return false; -#else //#ifndef ONPC_TOTTAL_SIMULATOR - return true; -#endif //#ifndef ONPC_TOTTAL_SIMULATOR -}; - -void LRF_HardwareManager::saveCurrentParameters( void ){ - if( m_pSettings != NULL ) { - config_setting_t *pSetting; - int tVal; - char tBuffer[256]; - LOG("HW Saving Settings ..."); - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DUMP ) ){ - tVal = m_bDumpMemoryToDisk; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_ROLE ) ){ - tVal = m_sPARAMETERS.flags.isMaster; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No role defined"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SUNBIT ) ){ - tVal = m_sPARAMETERS.flags.Sunbit_filter; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No SUNBIT action defined - Disabling!"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_LRF_ENABLED ) ){ - tVal = m_sPARAMETERS.flags.LaserPulsesOn; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No LRF Enabled"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_SIG_SYMULATOR ) ){ - tVal = m_sPARAMETERS.flags.SignalSimulator; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Sig Symulator Settings"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( !m_sPARAMETERS.flags.SignalSimulator ) { - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTOSTART_ENABLED ) ){ - tVal = m_sPARAMETERS.flags.AutostartMotors; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Motor Autostart Settings"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( !m_sPARAMETERS.flags.AutostartMotors ) { - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_V_MOTOR ) ){ - tVal = m_sPARAMETERS.flags.VerticalMotorOn; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Vertical Controll"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CTRL_H_MOTOR ) ){ - tVal = m_sPARAMETERS.flags.HorizontalMotorOn; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Horizontal Controll"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - }; - } - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_MOTOR_SETPOINT ) ){ - tVal = m_sPARAMETERS.flags.VerticalFreq; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Mirror Block Freq"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_H_MOTOR_SETPOINT ) ){ - tVal = m_sPARAMETERS.flags.HorizontalFreq; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Base Block Freq"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if ( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_V_PULSES_INTERLEAVE ) ){ - tVal = m_sPARAMETERS.flags.QQinterlace; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Q Pulses per LRF pulse Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_OFFSET ) ){ - tVal = m_sPARAMETERS.nOffset; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Offset Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_ORDER ) ){ - tVal = m_sPARAMETERS.nOrder; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Order Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_DELTA ) ){ - tVal = m_sPARAMETERS.nDelta; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Delta Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_FLIP_SIZE ) ){ - tVal = m_sPARAMETERS.nFlip; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Flip Size Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_GOOD_POINTS ) ){ - tVal = m_sPARAMETERS.nGPointSamples; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Good Points Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_AUTO_TH_GENERATE ) ){ - tVal = m_sPARAMETERS.flags.BuildThByCore; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TH Build By Core Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TH_SPIKE_SIZE ) ){ - tVal = m_sPARAMETERS.flags.Spike_TH; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Spike Threshold Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_CONTROL_ENABLE ) ){ - tVal = m_sPARAMETERS.flags.TGZ_canENA; - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN Enable Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_BUS_ID ) ){ - tVal = m_sPARAMETERS.flags.TGZ_canBus; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN Bus ID Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_MY_ID ) ){ - tVal = m_sPARAMETERS.flags.TGZ_canSRC; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN My ID Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_CAN_TGZ_ID ) ){ - tVal = m_sPARAMETERS.flags.TGZ_canDST; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No CAN TGZ ID Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; -#ifndef TGD_VERSION_2 - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_DIVIDER ) ){ - tVal = m_sPARAMETERS.flags.TGZ_divider; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Divider Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_PRF ) ){ - tVal = m_sPARAMETERS.flags.TGZ_ParamQ; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ PRF Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_RATIO ) ){ - tVal = m_sPARAMETERS.flags.TGZ_ParamB; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Ratio Setting"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; -#else - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_MIRROR_SPEED ) ){ - tVal = m_sPARAMETERS.flags.TGZ_ParamQ; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Mirror Block Speed"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_TGZ_BASE_SPEED ) ){ - tVal = m_sPARAMETERS.flags.TGZ_ParamB; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No TGZ Base Motor Speed"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; -#endif - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_B_SHIFT ) ){ - tVal = m_sPARAMETERS.flags.B_shift; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Base Shift"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( pSetting = config_setting_get_member( m_pSettings, HWM_SETTINGS_Q_SHIFT ) ){ - tVal = m_sPARAMETERS.flags.Q_shift; - config_setting_set_int(pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("No Mirror Shift"); - } else { - LOG_ERROR( "Error Saving Settings!" ); - return; - }; - if( m_pSettingsProvider->isCompromised() ) { - LOG("Save Settings"); - m_pSettingsProvider->validate(); - }; - }; -}; - -bool LRF_HardwareManager::getRunTimeStat( HWM_CSTATUS *ptr ){ - if ( ptr == NULL ) return false; - memcpy( ptr, &m_sRuntimeStatus, sizeof(HWM_CSTATUS)); - ptr->HW_STATUS = ((m_bWaitFirstFlip)?0x2000:0x00000000) | - ((m_bInitOK)?0x1000:0x00000000) | - #ifndef PRU_SLAVE - *(( uint32_t *) &m_sCS_Motors ) | - #endif - ((m_bDumpMemoryToDisk)?0x4000:0x00000000) | - ((m_bWorkEnable)?0x8000:0x00000000); - return true; -}; - -#undef LOG -#undef LOG_ERROR diff --git a/lib/App/3dSERVER/LRF_HardwareManager.h b/lib/App/3dSERVER/LRF_HardwareManager.h deleted file mode 100644 index a070bfd5..00000000 --- a/lib/App/3dSERVER/LRF_HardwareManager.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -#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__ diff --git a/lib/App/3dSERVER/LRF_KafkaHandler.cpp b/lib/App/3dSERVER/LRF_KafkaHandler.cpp deleted file mode 100644 index 9b1e599e..00000000 --- a/lib/App/3dSERVER/LRF_KafkaHandler.cpp +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_KafkaHandler.h b/lib/App/3dSERVER/LRF_KafkaHandler.h deleted file mode 100644 index a8fb48a2..00000000 --- a/lib/App/3dSERVER/LRF_KafkaHandler.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_Kernel.cpp b/lib/App/3dSERVER/LRF_Kernel.cpp deleted file mode 100644 index 29488a59..00000000 --- a/lib/App/3dSERVER/LRF_Kernel.cpp +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_Kernel.h b/lib/App/3dSERVER/LRF_Kernel.h deleted file mode 100644 index 74545b3c..00000000 --- a/lib/App/3dSERVER/LRF_Kernel.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_SafeShoreHandler.cpp b/lib/App/3dSERVER/LRF_SafeShoreHandler.cpp deleted file mode 100644 index d0878153..00000000 --- a/lib/App/3dSERVER/LRF_SafeShoreHandler.cpp +++ /dev/null @@ -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 diff --git a/lib/App/3dSERVER/LRF_SafeShoreHandler.h b/lib/App/3dSERVER/LRF_SafeShoreHandler.h deleted file mode 100644 index 8781e3f7..00000000 --- a/lib/App/3dSERVER/LRF_SafeShoreHandler.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_Server.cpp b/lib/App/3dSERVER/LRF_Server.cpp deleted file mode 100644 index 402458f8..00000000 --- a/lib/App/3dSERVER/LRF_Server.cpp +++ /dev/null @@ -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 - diff --git a/lib/App/3dSERVER/LRF_Server.h b/lib/App/3dSERVER/LRF_Server.h deleted file mode 100644 index 76e349f2..00000000 --- a/lib/App/3dSERVER/LRF_Server.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/lib/App/3dSERVER/LRF_SlimKernel.cpp b/lib/App/3dSERVER/LRF_SlimKernel.cpp deleted file mode 100644 index 0fd00465..00000000 --- a/lib/App/3dSERVER/LRF_SlimKernel.cpp +++ /dev/null @@ -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<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<readyToConsumeTH() ) { - //Finished Build TH - uint32_t THsize; - thresholdNode *tPTR = getTreshold( THsize, idx ); - if ( m_pTWIC->consumeTH( idx, tPTR, THsize ) ) { - m_nForcedDrawTH &=~(1<readyToConsumeTH() ) { - //Finished Build TH - uint32_t THsize; - thresholdNode *tPTR = getTreshold( THsize, idx ); - if ( m_pTWIC->consumeTH( idx, tPTR, THsize ) ) { - //mark as consumed - bDrawedTH |= (1<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 diff --git a/lib/App/3dSERVER/LRF_SlimKernel.h b/lib/App/3dSERVER/LRF_SlimKernel.h deleted file mode 100644 index cb2f8c1b..00000000 --- a/lib/App/3dSERVER/LRF_SlimKernel.h +++ /dev/null @@ -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__ diff --git a/lib/App/3dSERVER/LRF_TargetTracker.cpp b/lib/App/3dSERVER/LRF_TargetTracker.cpp deleted file mode 100644 index 8bbd198a..00000000 --- a/lib/App/3dSERVER/LRF_TargetTracker.cpp +++ /dev/null @@ -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 - - diff --git a/lib/App/3dSERVER/LRF_TargetTracker.h b/lib/App/3dSERVER/LRF_TargetTracker.h deleted file mode 100644 index 9da16907..00000000 --- a/lib/App/3dSERVER/LRF_TargetTracker.h +++ /dev/null @@ -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 - -#define TRACKER_MAX_TARGETS_POOL 128 -#define TRACKER_DEFAULT_TTL_VALUE 3 // Scans to live - -typedef vector 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__ diff --git a/lib/App/3dSERVER/LRF_TwinConnector.cpp b/lib/App/3dSERVER/LRF_TwinConnector.cpp deleted file mode 100644 index 041cdb70..00000000 --- a/lib/App/3dSERVER/LRF_TwinConnector.cpp +++ /dev/null @@ -1,1276 +0,0 @@ -#include "LRF_TwinConnector.h" - -#ifdef SLIM_KERNEL - #include "LRF_SlimKernel.h" -#else - #include "LRF_Kernel.h" -#endif - -#ifndef PRU_SLAVE - #include "LRF_TargetTracker.h" -#endif - -#define LOG( X ) m_pLog->Log( "TWINC", 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( "TWINC", this, _LOG_ERROR, _tBfrErrMSG234 );\ - } -#else - #define LOG_ERROR( X ) m_pLog->Log( "TWINC", this, _LOG_ERROR, X ); -#endif - -#define SLOG( X ) Me->m_pLog->Log( "TWINC_T", Me, X ) -#ifdef DEBUG - #define SLOG_ERROR( X ) {\ - char _tBfrErrMSG234[256];\ - sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ - Me->m_pLog->Log( "TWINC_T", Me, _LOG_ERROR, _tBfrErrMSG234 );\ - } -#else - #define SLOG_ERROR( X ) Me->m_pLog->Log( "TWINC_T", Me, _LOG_ERROR, X ); -#endif - -LRF_TwinConnector::LRF_TwinConnector( config_setting_t *Settings ): basicThread(){ - m_pLog = basicLogCollection::getInstance(); - m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, (CSTR)"TWIN_3DLRF_CONNECTION" ); - m_pEngine = NULL; - m_pCurrentTH = NULL; - m_bDrawThreadStatus = TH_PRE_INIT; - m_eWM = TWI_STAGE_NO_AKTIVE; -#ifdef PRU_SLAVE - m_nMasterPort = 0; - memset( m_cMasterAddress, 0 , 16 ); -#else - m_pSlaveShadowMask = NULL; - m_nMainSocket = -1; - m_nBindPort = 0; - memset( m_cBindAddress, 0, 16 ); -#endif - cleanupInfo(); -}; - -LRF_TwinConnector::~LRF_TwinConnector(){ - - waitDrawThreadEnd( true ); - waitThreadEnd( true ); -#ifdef PRU_SLAVE - if( m_oDataTransport != NULL ) delete( (clientPort *) m_oDataTransport ); -#else - if( m_oDataTransport != NULL ) delete( (serverPort *) m_oDataTransport ); -#endif - cleanupInfo(); -}; - -void LRF_TwinConnector::setWM( TWI_WM NWM ){ - m_mWMProtector.lock(); - m_eWM = NWM; - m_mWMProtector.unlock(); -}; - -TWI_WM LRF_TwinConnector::getWM(){ - TWI_WM rv; - m_mWMProtector.lock(); - rv = m_eWM; - m_mWMProtector.unlock(); - return rv; -}; - -void LRF_TwinConnector::setCMD( TWIN_COMMAND NCMD ){ - m_mCMDProtector.lock(); - m_eCCMD = NCMD; - m_bCMDTO = 10; // 1 sec - m_mCMDProtector.unlock(); -}; - -TWIN_COMMAND LRF_TwinConnector::getCMD(){ - TWIN_COMMAND rv; - m_mCMDProtector.lock(); - rv = m_eCCMD; - m_mCMDProtector.unlock(); - return rv; -}; - -#ifndef PRU_SLAVE - -thresholdNode *LRF_TwinConnector::getTreshold( uint32_t &size, uint8_t kID ){ - char tFN[64]; - sprintf( tFN, "data/th_data_%d.raw", kID ); - size = 0; - if( fileExist( tFN ) ){ - if ( m_pCurrentTH == NULL ) { - m_pCurrentTH = (thresholdNode *) malloc( TH_SIZE_BYTES ); - }; - if( m_pCurrentTH != NULL ) { - if( loadTHData( kID, m_pCurrentTH )){ - size = TH_SIZE_NODES; - } else { - return NULL; - }; - }; - }; - return m_pCurrentTH; -}; - -#endif - -bool LRF_TwinConnector::readyToConsumeTH( void ){ - if ( m_mDrawProtector.try_lock() ) { - m_mDrawProtector.unlock(); - return true; - }; - return false; -}; - -bool LRF_TwinConnector::consumeTH( uint8_t kID, thresholdNode *ptr, uint32_t THsize ){ - /* - // TH Saving procedure - if( cDrawTO == 0 ) { - cDrawTO = cMilliseconds; - } else if ( ( cMilliseconds - cDrawTO ) > TWI_DRAW_LOOP_MS ){ -#ifdef DEBUG - LOG("Try to Dump TH Images"); -#endif - if( m_mDrawProtector.try_lock() ) { -#ifdef DEBUG - LOG("Mutex Grabed"); -#endif - if( m_bDrawThreadStatus > TH_ARMED ) { - pthread_join( m_sDrawThreadHandler, NULL ); - }; - cDrawTO = cMilliseconds; - m_bDrawThreadStatus = TH_ARMED; - int RetVal = pthread_create( &m_sDrawThreadHandler, NULL, m_fDrawThreadEntryPoint, ( void * ) this ); - if( RetVal == -1 ) { - LOG_ERROR("Image Draw Thread Creation Failed."); - m_mDrawProtector.unlock(); - }; - }; - }; - */ - int RetVal; - if ( ptr == NULL) return false; - if ( THsize == 0 ) return false; - - m_mDrawProtector.lock(); - - m_mStatusProtector.lock(); -#ifdef PRU_SLAVE - m_sSystemStatus.TH_READY &= ~(1 << kID); -#else - m_sSystemStatus.MASTER_STATUS.TH_READY &= ~(1 << kID); -#endif - m_mStatusProtector.unlock(); - - cleanTHData( kID ); - char tBuffer[64]; - sprintf( tBuffer, "data/th_data_%d.raw", kID ); -#ifdef DEBUG - LOG("SAVE TH Data ..."); - LOG( tBuffer ); -#endif - FILE *fd; - fd = fopen( tBuffer, "wb+"); - if( fd != NULL ){ - //uint32_t Size = TH_SIZE_NODES; - fwrite( &THsize, sizeof( uint32_t ), 1, fd ); - fwrite( ptr, sizeof( thresholdNode ), THsize, fd ); - fclose( fd ); - } else { - LOG_ERROR("TH RAW save failure!"); - }; -#ifdef DEBUG - LOG("SAVE TH Data DONE!"); -#endif - /* - if( m_bDrawThreadStatus > TH_ARMED ) { - RetVal = pthread_join( m_sDrawThreadHandler, NULL ); - if( RetVal != 0 ){ - LOG_ERROR("Thread Join Error!"); - return false; - }; - }; - m_mDrawProtector.lock(); - m_pCurrentTH = ptr; - m_bDrawThreadStatus = TH_ARMED; - RetVal = pthread_create( &m_sDrawThreadHandler, NULL, m_fDrawThreadEntryPoint, ( void * ) this ); - if( RetVal == -1 ) { - LOG_ERROR("Image Draw Thread Creation Failed."); - m_mDrawProtector.unlock(); - }; - */ - m_mDrawProtector.unlock(); - return true; -}; - -#ifdef PRU_SLAVE - void LRF_TwinConnector::cleanupInfo(void){ - memset( &m_sSystemStatus, 0, sizeof( TWI_PEER_STATUS )); - m_bOldTHRecords = 0; - }; - bool LRF_TwinConnector::create(){ - if( m_pSettings!= NULL ) { - config_setting_t *pSetting; - int tVal; - char tBuffer[256]; - CSTR tcVal = NULL; - if (!config_setting_lookup_string( m_pSettings, "MASTER_ADDRESS", (const char**)&tcVal)){ //&m_cMasterAddress )) { - strncpy( m_cMasterAddress, "10.0.0.1", 15 ); - pSetting = config_setting_add(m_pSettings, "MASTER_ADDRESS", CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_cMasterAddress); - basicSettingsProvider::getInstance()->compromise(); - } else { - strncpy( m_cMasterAddress, tcVal, 16 ); - sprintf( tBuffer, "MASTER IP Address Read From Settings: %s", m_cMasterAddress ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_int( m_pSettings, "MASTER_PORT", &tVal ) ){ - tVal = m_nMasterPort = 6564; - pSetting = config_setting_add( m_pSettings, "MASTER_PORT", CONFIG_TYPE_INT ); - config_setting_set_bool( pSetting, tVal ); - basicSettingsProvider::getInstance()->compromise(); - } else { - m_nMasterPort = tVal; - sprintf( tBuffer, "MASTER PORT Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( basicSettingsProvider::getInstance()->isCompromised() ) { - LOG("Save Settings"); - basicSettingsProvider::getInstance()->validate(); - }; - } else { - LOG_ERROR("No Settings Provided!"); - return false; - }; - if( !protocolInternalLRF3D_SLAVE::create() ) return false; - m_eWM = TWI_STAGE_CONNECTING; - return init(); - }; - - bool LRF_TwinConnector::packetHandler( protocolPackage *Package ){ - char tB[128]; - if( Package == NULL ) return false; - if( Package->m_pData == NULL ) return false; - if (Package->m_nSize < TWI_CMD_INDEX ) return false; - TWIN_COMMAND cCMD = (TWIN_COMMAND)Package->m_pData[TWI_CMD_INDEX]; - //Any In Command Switchs to CMD mode - sprintf(tB,"Data IN! CODE: %d", cCMD ); - LOG( tB ); - switch( cCMD ) { - case TWC_GET_SHADOW_INFO: - case TWC_GET_CONFIG: - case TWC_GET_STATUS: - case TWC_GET_SHADOW_TRACE: - case TWC_GET_VERSION:{ - LOG("Generic CMD->Queued!"); - pushCMD( cCMD ); - break; - }; - case TWC_SET_CONFIG:{ - pushCMD( TWC_SET_CONFIG, Package->m_pData+TWI_PLS_INDEX ,sizeof(LGS_3D_PARAMETERS)); - break; - } - case TWC_GET_MODE:{ - LOG("Get Mode"); - sendMode( getWM() ); - break; - }; - case TWC_GET_SHADOW_POLY:{ - pushCMD( TWC_GET_SHADOW_POLY, Package->m_pData+TWI_PLS_INDEX , 1 ); - break; - }; - }; - return true; - }; - /// - /// Main Loop Of Slave Part Of Connector - /// - /// Nothing - void LRF_TwinConnector::m_fThreadProc( void ){ - TWI_CMD_CONTAINER * tCMD = NULL; - char tB[128]; - int ClientSocket = -1; - struct sockaddr ClientAddress; - socklen_t ClientAddressSize; - - long long cMilliseconds; - long long cStatusTO = 0; - long long cDrawTO = getMilliseconds(); - - m_bThreadStatus = TH_WORKING; - while( m_bThreadStatus < TH_ENDED ){ - - cMilliseconds = getMilliseconds(); - TWI_WM cWM = getWM(); - if ( cWM > TWI_STAGE_CONNECTING ) { - if( m_oDataTransport!= NULL ) { - if (m_oDataTransport->getConnectionStatus() == CS_DISCONNECTED) { - setWM( TWI_STAGE_CONNECTING ); - continue; - }; - } else { - LOG_ERROR("Port Object Missed!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - }; - switch( cWM ) { - case TWI_STAGE_CONNECTING:{ - if( m_oDataTransport != NULL ){ - delete( (clientPort *) m_oDataTransport ); - m_oDataTransport = NULL; - } else { - clientPort *tPort = new clientPort( m_cMasterAddress, m_nMasterPort, true ); - if( tPort!= NULL ){ - if( tPort->create() ){ - setTransport( tPort ); - setWM( TWI_STAGE_CONNECTED ); - cStatusTO = cMilliseconds; - cleanupInfo(); - } else { - delete( tPort ); - SLEEP( TWI_SLOW_LOOP_SLEEP ); - }; - } else { - LOG_ERROR( "Port Not Created!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - }; - break; - }; - case TWI_STAGE_CONNECTED:{ - //Cleanup Queue - m_mQUEUEProtector.lock(); - while( !m_qCMD.empty() ) { - TWI_CMD_CONTAINER *ptr = m_qCMD.front(); - if (ptr->DATA) free(ptr->DATA); - free( ptr ); - m_qCMD.pop(); - }; - m_mQUEUEProtector.unlock(); - setWM( TWI_STAGE_IDLE ); - break; - }; - case TWI_STAGE_IDLE:{ - //Fetch Event from Queue and send to master - tCMD = fetchCMD(); - if( tCMD != NULL ){ - LOG("CMD Fetched!"); - switch( tCMD->CMD ){ - case TWC_GET_STATUS: sendStatus( &m_sSystemStatus ); break; - case TWC_PUSH_TARGET: if( tCMD->DATA ) sendTarget( (targetRecord *) tCMD->DATA ); break; - case TWC_GET_VERSION: sendVersion( &gsSOFT_INFO ); break; - case TWC_GET_CONFIG:{ - if( m_pEngine != NULL ){ - PLGS_3D_PARAMETERS tPTR = m_pEngine->getDetectionParameters(); - if ( tPTR ) { - sendDetectionParameters( tPTR ); - free( tPTR ); - } else { - sendNACK( TWC_SET_CONFIG ); - }; - } else { - sendNACK( TWC_SET_CONFIG ); - }; - break; - }; - case TWC_SET_CONFIG:{ - if( ( m_pEngine != NULL ) && ( tCMD->DATA != NULL ) ) { - if( m_pEngine->setDetectionParameters( ( PLGS_3D_PARAMETERS ) tCMD->DATA ) ){ - sendACK( TWC_SET_CONFIG ); - } else { - sendNACK( TWC_SET_CONFIG ); - }; - } else { - sendNACK( TWC_SET_CONFIG ); - }; - break; - }; - case TWC_GET_SHADOW_INFO:{ - if( m_pEngine != NULL ) { - ShadowMask *tPTR = m_pEngine->getShadowMask(); - if( tPTR!= NULL ) { - TWI_MASK_INFO tInfo; - tInfo.active = tPTR->isActive(); - tInfo.poly_cnt = tPTR->getPolyCount(); - tInfo.ray_cnt = tPTR->getRayCount(); - sprintf( tB, "ShadowInfo: A:[%d] P:[%d] R:[%d]", tInfo.active, tInfo.poly_cnt, tInfo.ray_cnt ); - LOG( tB ); - sprintf( tB, "ShadowInfo: A:[%d] P:[%d] R:[%d]", tPTR->isActive(), tPTR->getPolyCount(), tPTR->getRayCount() ); - LOG( tB ); - sendShadowInfo( &tInfo ); - } else { - sendNACK( TWC_GET_SHADOW_INFO ); - }; - } else { - sendNACK( TWC_GET_SHADOW_INFO ); - }; - break; - }; - case TWC_GET_SHADOW_POLY:{ - if( m_pEngine != NULL ) { - uint8_t polyID = *((uint8_t *)tCMD->DATA); - ShadowMask * tPTR = m_pEngine->getShadowMask(); - if( tPTR!= NULL ) { - simplePolygone *tSP = tPTR->getPoly( polyID ); - if ( tSP ) { - sendPolygone( polyID, tSP ); - } else { - sendNACK( TWC_GET_SHADOW_POLY ); - }; - } else { - sendNACK( TWC_GET_SHADOW_POLY ); - } - } else { - sendNACK( TWC_GET_SHADOW_POLY ); - }; - break; - }; - case TWC_GET_SHADOW_TRACE:{ - if( m_pEngine != NULL ) { - ShadowMask * tPTR = m_pEngine->getShadowMask(); - if( tPTR!= NULL ) { - if( m_vShadowZM.size() == 0 ){ - if( tPTR->getZoneMask( m_vShadowZM ) ){ - sendShadowTrace( &m_vShadowZM ); - } else { - sendNACK( TWC_GET_SHADOW_TRACE ); - }; - } else { - sendShadowTrace( &m_vShadowZM ); - }; - } else { - sendNACK( TWC_GET_SHADOW_TRACE ); - }; - } else { - sendNACK( TWC_GET_SHADOW_TRACE ); - }; - break; - }; - }; - if( tCMD->DATA ) free( tCMD->DATA ); - free( tCMD ); - tCMD = NULL; - } else { - SLEEP( TWI_SLOW_LOOP_SLEEP ); - }; - if( m_pEngine ) { - m_sSystemStatus.KRNL_WM = m_pEngine->getWM(); - m_sSystemStatus.ENABLED = m_pEngine->getFilteredKernels(); - m_sSystemStatus.DETECTION = m_pEngine->getDetectionKernels(); - if( m_bOldTHRecords != m_sSystemStatus.TH_READY ) { - m_bOldTHRecords = m_sSystemStatus.TH_READY; - }; - }; - break; - }; - }; - }; - }; -#else //Master - void LRF_TwinConnector::cleanupInfo(void){ - memset( &m_sSystemStatus, 0, sizeof( TWIN_STATUS )); - memset( &m_sSlaveMaskInfo, 0, sizeof( TWI_MASK_INFO )); - memcpy( &m_sSystemStatus.MASTER_NFO, &gsSOFT_INFO, sizeof(SOFTWARE_INFO)); - if ( m_pSlaveShadowMask != NULL) delete( m_pSlaveShadowMask ); - }; - bool LRF_TwinConnector::create(){ - if( m_pSettings!= NULL ) { - config_setting_t *pSetting; - int tVal; - char tBuffer[256]; - CSTR tcVal = NULL; - if (!config_setting_lookup_string(m_pSettings, "BIND_ADDRESS", (const char**)&tcVal )){ //(const char**)&m_cBindAddress)) { - strncpy( m_cBindAddress, "10.0.0.1", 15 ); - pSetting = config_setting_add(m_pSettings, "BIND_ADDRESS", CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_cBindAddress); - basicSettingsProvider::getInstance()->compromise(); - } else { - strncpy( m_cBindAddress, tcVal, 16 ); - sprintf( tBuffer, "BIND to IP Address Read From Settings: %s", m_cBindAddress ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_int( m_pSettings, "BIND_PORT", &tVal ) ){ - tVal = m_nBindPort = 6564; - pSetting = config_setting_add( m_pSettings, "BIND_PORT", CONFIG_TYPE_INT ); - config_setting_set_bool( pSetting, tVal ); - basicSettingsProvider::getInstance()->compromise(); - } else { - m_nBindPort = tVal; - sprintf( tBuffer, "BIND to PORT Read From Settings: %d", tVal ); - LOG( tBuffer ); - }; - if( basicSettingsProvider::getInstance()->isCompromised() ) { - LOG("Save Settings"); - basicSettingsProvider::getInstance()->validate(); - }; - } else { - LOG_ERROR("No Settings Provided!"); - return false; - }; - int RetCode; - struct hostent * h_info; - struct sockaddr_in * MainSocketAddress = NULL; - - if( !protocolInternalLRF3D_MASTER::create() ) return false; - - m_nMainSocket = socket( AF_INET, SOCK_STREAM, 0 ); - - if( m_nMainSocket == -1){ - LOG_ERROR( "Some trouble with networking on this machine (Socket Error)!"); - return false; - }; - MainSocketAddress = ( struct sockaddr_in * ) malloc( sizeof( struct sockaddr_in ) ); - if( MainSocketAddress == NULL ){ - LOG_ERROR( "Some trouble with networking on this machine (Cannot Alloc Sockaddr Struct)!" ); - return false; - }; - bzero( MainSocketAddress, sizeof( struct sockaddr_in ) ); - h_info = gethostbyname ( m_cBindAddress ); - if ( h_info == NULL ){ - LOG_ERROR( "Some trouble with networking on this machine (Cannot Get Hostname)!" ); - return false; - }; - //***************************************** - //* there we building our network address * - //***************************************** - bcopy( h_info->h_addr, &(MainSocketAddress->sin_addr), h_info->h_length ); - MainSocketAddress->sin_family = h_info->h_addrtype; - MainSocketAddress->sin_port = htons( m_nBindPort ); - - RetCode = bind( m_nMainSocket ,(struct sockaddr *) MainSocketAddress, sizeof( struct sockaddr_in ) ); - if ( RetCode != 0 ){ - LOG_ERROR( "Error Binding to Port/Address" ); - return false; - }; - RetCode = listen( m_nMainSocket, 128); - if ( RetCode != 0 ){ - LOG_ERROR( "Cannot Listen Port/Address" ); - return false; - }; - - U8 dontblock; - dontblock = fcntl( m_nMainSocket, F_GETFL, NULL ); - dontblock |= O_NONBLOCK | O_NDELAY; - RetCode = ioctl( m_nMainSocket, FIONBIO, (char *) &dontblock ); - if ( RetCode == 0 ){ - LOG( "Set N-Blocking Mode of Accepting Socket" ); - } else { - LOG( "Can't set N-Blocking Mode of Accepting Socket" ); - }; - m_eWM = TWI_STAGE_CONNECTING; - return init(); - }; - - bool LRF_TwinConnector::packetHandler( protocolPackage *Package ){ - char tB[128]; - if( Package == NULL ) return false; - if( Package->m_pData == NULL ) return false; - if( Package->m_nSize < TWI_CMD_INDEX ) return false; - TWIN_COMMAND tCMD = (TWIN_COMMAND) Package->m_pData[TWI_CMD_INDEX]; - sprintf( tB,"Data IN! Code: %d", tCMD ); - LOG(tB); - switch( tCMD ) { - case TWC_ACK_CMD:{ - LOG( "CMD ACK"); - TWIN_COMMAND confirmedCMD = (TWIN_COMMAND) Package->m_pData[TWI_PLS_INDEX]; - /* - if( getCMD() != confirmedCMD ) { - setWM( TWI_STAGE_RETRY_CMD ); - } else { - //Last Command Confirmed -> Clean - setCMD( TWC_NO_COMMAND ); - switch ( confirmedCMD ) { - case TWC_DO_REBOOT:{ - //After Confirmation -> Disconnect - setWM( TWI_STAGE_DISCONNECTING ); - break; - }; - case TWC_SET_EVT_MODE:{ - setWM( TWI_STAGE_EVENT_MODE ); - break; - }; - case TWC_SET_CMD_MODE:{ - setWM( TWI_STAGE_REQUEST_STATUS ); - break; - }; - }; - };*/ - break; - }; - case TWC_NACK_CMD:{ - LOG("NACK RECEIVED!"); - setCMD( TWC_NO_COMMAND ); - break; - }; - /*case TWC_CURRENT_MODE:{ - TWI_WM tWM = ( TWI_WM ) Package->m_pData[TWI_PLS_INDEX]; - sprintf(tB,"Cur Slave Mode Is: %d", tWM ); - LOG(tB); - if ( tWM == TWI_STAGE_EVENT_MODE ) { - setWM( TWI_STAGE_SET_COMMAND_MODE ); - } else { - setWM( TWI_STAGE_REQUEST_STATUS ); - }; - break; - }; - case TWC_TH_DATA:{ - if( getWM() == TWI_STAGE_TH_TRANSFER ) { - - }; - break; - };*/ - case TWC_CURRENT_STATUS:{ - LOG( "Status"); - memcpy( &m_sSystemStatus.SLAVE_STATUS, Package->m_pData + TWI_PLS_INDEX, sizeof(TWI_PEER_STATUS)); - break; - }; - case TWC_CURRENT_VERSION:{ - LOG( "Version"); - memcpy( &m_sSystemStatus.SLAVE_NFO, Package->m_pData + TWI_PLS_INDEX, sizeof(SOFTWARE_INFO)); - m_sSystemStatus.VERSION_IS_SYNCED = true; - setCMD( TWC_NO_COMMAND ); - break; - }; - case TWC_SET_CONFIG:{ - LOG( "Detection Params"); - memcpy( &m_sSystemStatus.SLAVE_PARAMS, Package->m_pData + TWI_PLS_INDEX, sizeof(LGS_3D_PARAMETERS)); - m_sSystemStatus.SETTINGS_IS_SYNCED = true; - setCMD( TWC_NO_COMMAND ); - break; - }; - case TWC_SHADOW_INFO:{ - memcpy( &m_sSlaveMaskInfo, Package->m_pData + TWI_PLS_INDEX, sizeof(TWI_MASK_INFO)); - sprintf(tB, "Shadow Info A:[%d] P:[%d] R:[%d]", m_sSlaveMaskInfo.active, m_sSlaveMaskInfo.poly_cnt, m_sSlaveMaskInfo.ray_cnt ); - LOG( tB ); - if( m_sSlaveMaskInfo.poly_cnt == 0 && m_sSlaveMaskInfo.ray_cnt == 0 ) { - LOG("No Shadow Defined!"); - m_sSystemStatus.SHADOW_IS_SYNCED = true; - setCMD( TWC_NO_COMMAND ); - } else { - LOG("Shadow Defined!"); - if ( m_pSlaveShadowMask == NULL ) { - m_pSlaveShadowMask = new ShadowMask(); - } else { - m_pSlaveShadowMask->clear(); - }; - if ( m_pSlaveShadowMask!= NULL ) { - if (m_sSlaveMaskInfo.poly_cnt) { - uint8_t id=0; - LOG("Get POLY"); - pushCMD(TWC_GET_SHADOW_POLY, &id, 1 ); - setCMD( TWC_GET_SHADOW_POLY ); - } else { - LOG("Get TRACE"); - pushCMD( TWC_GET_SHADOW_TRACE ); - setCMD( TWC_GET_SHADOW_TRACE ); - }; - } else { - LOG_ERROR("Error Creating Slave Shadow Mask!"); - //m_sSystemStatus.SHADOW_IS_SYNCED = false; - //setCMD( TWC_NO_COMMAND ); - }; - }; - break; - }; - case TWC_SET_SHADOW_POLY:{ - uint8_t id = Package->m_pData[TWI_PLS_INDEX]; - simplePolygone * tPoly = (simplePolygone*) malloc(sizeof(simplePolygone)); - if ( tPoly ) { - tPoly->count = Package->m_pData[TWI_PLS_INDEX + 1]; - tPoly->points = (simplePoint*) calloc(tPoly->count, sizeof(simplePoint)); - if( tPoly->points != NULL ){ - tPoly->color[0] = Package->m_pData[TWI_PLS_INDEX + 2]; - tPoly->color[1] = Package->m_pData[TWI_PLS_INDEX + 3]; - tPoly->color[2] = Package->m_pData[TWI_PLS_INDEX + 4]; - uint16_t adr = TWI_PLS_INDEX + 5; - for( uint8_t i=0; i < tPoly->count; i++ ) { - uint16_t x,y; - x = Package->m_pData[adr++]; - x = ( x << 8 ) | Package->m_pData[adr++]; - y = Package->m_pData[adr++]; - y = ( y << 8 ) | Package->m_pData[adr++]; - tPoly->points[i].setX(x); - tPoly->points[i].setY(y); - }; - m_pSlaveShadowMask->addPoly( tPoly ); - id++; - } else { - free( tPoly ); - }; - }; - if( id < m_sSlaveMaskInfo.poly_cnt ) { - pushCMD(TWC_GET_SHADOW_POLY, &id, 1 ); - setCMD( TWC_GET_SHADOW_POLY ); - } else { - m_pSlaveShadowMask->saveVertexes("sl_masking.dat"); - if ( m_sSlaveMaskInfo.ray_cnt ) { - LOG("Get TRACE"); - pushCMD( TWC_GET_SHADOW_TRACE ); - setCMD( TWC_GET_SHADOW_TRACE ); - } else { - LOG("Shadow Now Synced!"); - m_sSystemStatus.SHADOW_IS_SYNCED = true; - setCMD(TWC_NO_COMMAND); - }; - }; - break; - }; - case TWC_SET_SHADOW_TRACE:{ - uint16_t traceSize = Package->m_pData[TWI_PLS_INDEX]; - traceSize = ( traceSize << 8 ) | Package->m_pData[TWI_PLS_INDEX+1]; - sprintf( tB, "Shadow Trace [%d]pp[%d]bs[%d]", traceSize, Package->m_nSize, (TWI_PLS_INDEX + (traceSize << 3) + 3) ); - LOG( tB ); - if((TWI_PLS_INDEX + (traceSize << 3) + 3) == Package->m_nSize ) { - uint16_t index; - uint16_t cColumn; - uint16_t cCount; - raySegment RS; - index = TWI_PLS_INDEX+2; - for( int i=0; i < traceSize; 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++]; - m_pSlaveShadowMask->addRay( cColumn, RS ); - }; - }; - m_pSlaveShadowMask->setActive(true); - m_pSlaveShadowMask->saveRastered("sl_shadow.dat"); - LOG("Shadow Now Synced!"); - m_sSystemStatus.SHADOW_IS_SYNCED = true; - setCMD(TWC_NO_COMMAND); - }; - break; - }; - case TWC_PUSH_TARGET:{ - LOG( "Target"); - if( m_pTracker ) { - targetRecord *tTARGET = (targetRecord * ) ( Package->m_pData + TWI_PLS_INDEX ); - //All Targets Came From Slave - m_pTracker->validateTarget( tTARGET, false ); - }; - break; - }; - }; - return true; - }; - - void LRF_TwinConnector::m_fThreadProc( void ){ - TWI_CMD_CONTAINER * tCMD = NULL; - int ClientSocket = -1; - struct sockaddr ClientAddress; - socklen_t ClientAddressSize = (socklen_t) sizeof( struct sockaddr_in ); - long long cMilliseconds; - long long cStatusTO = 0; - long long cDrawTO = 0; - - m_bThreadStatus = TH_WORKING; - - while( m_bThreadStatus < TH_ENDED ){ - cMilliseconds = getMilliseconds(); - - TWI_WM cWM = getWM(); - if ( cWM > TWI_STAGE_CONNECTING ) { - if( m_oDataTransport!= NULL ) { - if (m_oDataTransport->getConnectionStatus() == CS_DISCONNECTED) { - setWM( TWI_STAGE_CONNECTING ); - continue; - }; - } else { - LOG_ERROR("Port Object Missed!"); - m_bThreadStatus = TH_ENDED; - continue; - }; - }; - switch( cWM ) { - case TWI_STAGE_CONNECTING:{ - if( m_oDataTransport != NULL ){ - delete( (serverPort *) m_oDataTransport ); - m_oDataTransport = NULL; - } else { - serverPort *tPort = NULL; - // (re)Establish Connection - ClientSocket = accept ( m_nMainSocket, &ClientAddress, &ClientAddressSize ); - if ( ClientSocket == -1 ) { - switch( errno ){ - case EAGAIN:{ - SLEEP( TWI_QUICK_LOOP_SLEEP ); - continue; - }; - //case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break; - case EBADF: LOG_ERROR( "The descriptor is invalid." ); break; - case ECONNABORTED: LOG_ERROR( "A connection has been aborted."); break; - case EINTR: LOG_ERROR( "The system call was interrupted by a signal that was caught before a valid connection arrived."); break; - case EINVAL: LOG_ERROR( "Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break; - case EMFILE: LOG_ERROR( "The per-process limit of open file descriptors has been reached."); break; - case ENFILE: LOG_ERROR( "The system limit on the total number of open files has been reached."); break; - case ENOTSOCK: LOG_ERROR( "The descriptor references a file, not a socket."); break; - case EOPNOTSUPP: LOG_ERROR( "The referenced socket is not of type SOCK_STREAM."); break; - case EFAULT: LOG_ERROR( "The addr argument is not in a writable part of the user address space."); break; - case ENOBUFS: - case ENOMEM: LOG_ERROR( "Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break; - case EPROTO: LOG_ERROR( "Protocol error."); break; - case EPERM: LOG_ERROR( "Firewall rules forbid connection."); break; - case ENOSR: - case ESOCKTNOSUPPORT: - case EPROTONOSUPPORT: - case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break; - //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break; - default: LOG_ERROR( " Unhandled error in Kernel"); break; - }; - m_bThreadStatus = TH_ENDED; - continue; - } else { - char tstr[32]; - char tB[256]; - inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, 32 ); - sprintf( tB, "SLAVE LRF Connection Accepted[%s]", tstr ); - LOG( tB ); - tPort = new serverPort( ClientSocket ); - }; - if( tPort != NULL ){ - if ( tPort->create() ) { - setTransport( tPort ); - cleanupInfo(); - setWM( TWI_STAGE_CONNECTED ); - } else { - LOG_ERROR("Failure Create Server Connection!"); - delete( tPort ); - }; - }; - }; - break; - }; - case TWI_STAGE_CONNECTED:{ - m_mQUEUEProtector.lock(); - while( !m_qCMD.empty() ) { - TWI_CMD_CONTAINER *ptr = m_qCMD.front(); - if (ptr->DATA) free(ptr->DATA); - free( ptr ); - m_qCMD.pop(); - }; - m_mQUEUEProtector.unlock(); - cStatusTO = cMilliseconds; - setWM( TWI_STAGE_IDLE ); - break; - }; - case TWI_STAGE_IDLE:{ - tCMD = fetchCMD(); - if( tCMD != NULL ){ - switch( tCMD->CMD ){ - case TWC_GET_STATUS: - case TWC_GET_VERSION: - case TWC_GET_CONFIG: - case TWC_GET_SHADOW_INFO:{ - sendPlainCMD( tCMD->CMD ); - break; - }; - case TWC_GET_SHADOW_TRACE:{ - sendPlainCMD( TWC_GET_SHADOW_TRACE ); - //Prolong TO - cStatusTO = cMilliseconds; - break; - }; - case TWC_GET_SHADOW_POLY:{ - if( tCMD->DATA != NULL ) { - uint8_t polyID = *((uint8_t*) tCMD->DATA ); - getShadowPoly( polyID ); - //Prolong TO - cStatusTO = cMilliseconds; - }; - break; - }; - case TWC_GET_THRESHOLD:{ - if( tCMD->DATA != NULL ) { - uint8_t kID = *((uint8_t*) tCMD->DATA ); - getTHData( kID ); - }; - break; - }; - case TWC_SET_CONFIG:{ - if (tCMD->DATA != NULL && tCMD->SIZE == sizeof( LGS_3D_PARAMETERS ) ) { - if( sendDetectionParameters( (PLGS_3D_PARAMETERS)tCMD->DATA ) ) { - memcpy(&m_sSystemStatus.SLAVE_PARAMS, tCMD->DATA, tCMD->SIZE); - }; - }; - break; - }; - - }; - if (tCMD->DATA) free(tCMD->DATA); - free( tCMD ); - tCMD = NULL; - continue; // No delay After CMD - }; - //If Initial Slave Data is Read - if( m_sSystemStatus.SETTINGS_IS_SYNCED && m_sSystemStatus.SHADOW_IS_SYNCED && m_sSystemStatus.VERSION_IS_SYNCED ){ - if ((cMilliseconds - cStatusTO) > TWI_PING_PONG_TO) { - cStatusTO = cMilliseconds; - pushCMD( TWC_GET_STATUS ); - } else { - SLEEP( TWI_QUICK_LOOP_SLEEP ); - }; - } else { - TWIN_COMMAND iCMD = getCMD(); - if ( iCMD == TWC_NO_COMMAND ) { - LOG("INIT MODE"); - if( !m_sSystemStatus.VERSION_IS_SYNCED ) { - LOG("ASK VERSION"); - pushCMD( TWC_GET_VERSION ); - setCMD( TWC_GET_VERSION ); - } else if( !m_sSystemStatus.SETTINGS_IS_SYNCED ) { - LOG("ASK CONFIG"); - pushCMD( TWC_GET_CONFIG ); - setCMD( TWC_GET_CONFIG ); - } else if( !m_sSystemStatus.SHADOW_IS_SYNCED ) { - LOG("ASK SHADOW"); - pushCMD( TWC_GET_SHADOW_INFO ); - setCMD( TWC_GET_SHADOW_INFO ); - }; - cStatusTO = cMilliseconds; - } else { - if ((cMilliseconds - cStatusTO) > TWI_PING_PONG_TO) { - cStatusTO = cMilliseconds; - setCMD( TWC_NO_COMMAND ); - } else { - SLEEP( TWI_SLOW_LOOP_SLEEP ); - }; - }; - }; - break; - }; - case TWI_STAGE_DISCONNECTING:{ - delete( (serverPort *) m_oDataTransport ); - m_oDataTransport = NULL; - setWM( TWI_STAGE_CONNECTING ); - break; - }; - }; - }; - }; - - bool LRF_TwinConnector::attachTargetTracker( LRF_TargetTracker *ptr ){ - if(ptr == NULL) return false; - m_pTracker = ptr; - return false; - }; - - bool LRF_TwinConnector::updateSettings( void ){ - return true; - }; -#endif //!PRU_SLAVE - -TWI_CMD_CONTAINER *LRF_TwinConnector::fetchCMD(){ - TWI_CMD_CONTAINER *retVal = NULL; - m_mQUEUEProtector.lock(); - if( !m_qCMD.empty() ) { - retVal = m_qCMD.front(); - m_qCMD.pop(); - }; - m_mQUEUEProtector.unlock(); - return retVal; -}; - -void LRF_TwinConnector::pushCMD( TWI_CMD_CONTAINER *ptr ){ - if ( ptr ) { - m_mQUEUEProtector.lock(); - if( m_qCMD.size() < TWI_MAX_QUEUE_SIZE ) { - m_qCMD.push(ptr); - }; - m_mQUEUEProtector.unlock(); - }; -}; - -void LRF_TwinConnector::pushCMD( TWIN_COMMAND CMD, void *ptr, size_t DataSize ){ - TWI_CMD_CONTAINER *tVal = (TWI_CMD_CONTAINER *) malloc(sizeof(TWI_CMD_CONTAINER)); - if (tVal) { - tVal->CMD = CMD; - if( ptr!= NULL && DataSize > 0 ) { - tVal->DATA = malloc(DataSize); - if ( tVal->DATA ) { - memcpy( tVal->DATA, ptr, DataSize ); - tVal->SIZE = DataSize; - } else { - tVal->SIZE = 0; - }; - } else { - tVal->DATA = NULL; - tVal->SIZE = 0; - }; - pushCMD( tVal ); - }; -}; - -#ifdef PRU_SLAVE - bool LRF_TwinConnector::validateTarget( targetRecord *ptr ){ - if( ptr == NULL ) return false; - pushCMD( TWC_PUSH_TARGET, ptr, sizeof( targetRecord ) ); - return true; - }; -#endif - - -bool LRF_TwinConnector::cleanTHData( uint8_t kid ){ - char tBuffer[1024]; - FILE *FID = NULL; - if( kid > 31 ) kid = 31; - sprintf( tBuffer, "data/th_data_%d.raw", kid ); - if( !fileExist( "data" ) ){ - int RetVal = mkdir( "data", STORAGE_DIR_MODE ); - if( RetVal < 0 ) { - LOG_ERROR( "Error Creating DATA DIR!" ); - return false; - }; - }; - FID = fopen( tBuffer, "wb+" ); - if( FID == NULL ){ - LOG_ERROR( "Error Creating DATA FILE!" ); - return false; - }; - uint32_t ZZ = 0; - for( uint32_t i = 0; i < TH_SIZE_NODES; i++ ){ - fwrite( &ZZ, 4, 1, FID ); - }; - fclose( FID ); - return true; -}; - -bool LRF_TwinConnector::loadTHData( uint8_t kid, thresholdNode *ptr ){ - FILE *FID; - char tBuffer[1024]; - if( ptr == NULL ) return false; - if( kid > 31 ) kid = 31; - sprintf( tBuffer, "data/th_data_%d.raw", kid ); - FID = fopen( tBuffer, "rb" ); - if( FID == NULL ) { - LOG_ERROR( "Error Opening DATA FILE!" ); - return false; - }; - for( uint32_t i = 0; i < TH_SIZE_NODES; i++ ){ - fread( &ptr[i], TH_NODE_SIZE, 1, FID ); - }; - fclose( FID ); - return true; -}; - -bool LRF_TwinConnector::saveTHData( uint8_t kid, thresholdNode *ptr ){ - FILE *FID; - char tBuffer[1024]; - if( ptr == NULL ) return false; - if( kid > 31 ) kid = 31; - sprintf( tBuffer, "data/th_data_%d.raw", kid ); - FID = fopen( tBuffer, "wb+" ); - if( FID == NULL ) { - LOG_ERROR( "Error Creating DATA FILE!" ); - return false; - }; - for( uint32_t i = 0; i < TH_SIZE_NODES; i++ ){ - fwrite( &ptr[i], TH_NODE_SIZE, 1, FID ); - }; - fclose( FID ); - return true; -}; - - -void *LRF_TwinConnector::m_fDrawThreadEntryPoint( void *ptr ){ - LRF_TwinConnector *Me; - if( ptr == NULL ) return NULL; - Me = (LRF_TwinConnector*) ptr; -#ifdef DEBUG - SLOG("TH Thread OK"); -#endif - if( Me->m_bDrawThreadStatus == TH_ARMED ) { -#ifdef DEBUG - SLOG("TH Image Thread ARMED!"); -#endif - Me->m_bDrawThreadStatus = TH_WORKING; - if( Me!= NULL ) { - // Store Local TH Draws - thresholdNode *tMem; - //uint32_t tSize; -#ifdef DEBUG - SLOG("Kernel is Defined!"); -#endif - for( uint8_t i=0; i<16; i++ ) { - // just in case if we must end work - if( Me->m_bDrawThreadStatus != TH_WORKING ) break; - //tMem = Me->getTreshold( tSize, i ); - tMem = Me->m_pCurrentTH; - if( tMem!= NULL ) { - char tBuffer[256]; -#ifdef TH_USE_PICTURES - sprintf( tBuffer, "data/th_data_%d.png", i ); - #ifdef DEBUG - SLOG("SAVE TH Image ..."); - SLOG( tBuffer ); - #endif - if( !Me->saveTHPicture( tMem, tBuffer, false )){ - SLOG_ERROR("TH PNG save failure!"); - } - #ifdef PRU_SLAVE - else { - //Me->m_mStatusProtector.lock(); - //Me->m_nStatus |= ( 1 << i ) << 16; - //Me->m_mStatusProtector.unlock(); - } - #endif - ; - #ifdef DEBUG - SLOG("SAVE TH Image DONE!"); - #endif - SLEEP(10); -#else //TH_USE_PICTURES - sprintf( tBuffer, "data/th_data_%d.raw", i ); - #ifdef DEBUG - SLOG("SAVE TH Data ..."); - SLOG( tBuffer ); - #endif - FILE *fd; - fd = fopen( tBuffer, "wb+"); - if( fd != NULL ){ - uint32_t Size = TH_SIZE_NODES; - fwrite( &Size, sizeof( uint32_t ), 1, fd ); - fwrite( tMem, sizeof( thresholdNode ), Size, fd ); - fclose( fd ); - #ifdef PRU_SLAVE - //Me->m_mStatusProtector.lock(); - //Me->m_nStatus |= ( 1 << i ) << 16; - //Me->m_mStatusProtector.unlock(); - #endif - } else { - SLOG_ERROR("TH RAW save failure!"); - }; - #ifdef DEBUG - SLOG("SAVE TH Data DONE!"); - #endif -#endif //TWI_TH_USE_PICTURES - }; - }; - }; - }; - Me->m_bDrawThreadStatus = TH_EXIT; - Me->m_mDrawProtector.unlock(); - pthread_exit( NULL ); - return NULL; -}; - -void LRF_TwinConnector::waitDrawThreadEnd( bool forced ){ - if( m_bDrawThreadStatus > TH_WORKING || m_bDrawThreadStatus < TH_ARMED ) return; - if( forced ) m_bDrawThreadStatus = TH_ENDED; - while( m_bDrawThreadStatus != TH_EXIT ) SLEEP(DEFAULT_THREAD_SLEEP_TIME); - pthread_join( m_sDrawThreadHandler, NULL ); -}; - -#ifdef TH_USE_PICTURES - #define STB_IMAGE_IMPLEMENTATION - #include "../../data/stbi/stb_image.h" - #define STB_IMAGE_WRITE_IMPLEMENTATION - #include "../../data/stbi/stb_image_write.h" - #undef STB_IMAGE_WRITE_IMPLEMENTATION - #undef STB_IMAGE_IMPLEMENTATION - -bool LRF_TwinConnector::saveTHPicture( thresholdNode *ptr, CSTR fileName, bool monochrome, bool agressive ){ - uint8_t *tMemory = NULL; - thresholdNode *cNode = NULL; - uint8_t *cPixel = NULL; - uint8_t cSpace; - if( monochrome ) { - cSpace = 1; - } else { - cSpace = 4; - }; - tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace ); - if( tMemory == NULL ){ - LOG_ERROR("Image Memory Alloc Eror!"); - return false; - }; - for( int j = 0; j < Q_SCAN_COUNT; j++ ) { - for ( int i = 0; i < TH_LINE_NODES; i++ ) { - //cNode = ptr+(j*i); - //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ]; -#ifdef PRU_SLAVE - cNode = ptr+makeIds( i, j , false ); - cPixel = tMemory+( cSpace * makeIds( i, j , false )); -#else - cNode = ptr+makeIds( i, j , true ); - cPixel = tMemory+( cSpace * makeIds( i, j , false )); - //cNode = ptr + ( i * j ); - //cPixel = tMemory + ( cSpace * i * j ); -#endif - if( !agressive ) SLEEP(1); - if( monochrome ) { -#ifdef CHECK_SUN_BIT - if( cNode->values.sbit ) { - cPixel[0] = 0; - } else { - cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); - }; -#else - cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); -#endif - } else { -#ifdef CHECK_SUN_BIT - if( cNode->values.sbit ) { - // Set Red - cPixel[0] = 0x00; - cPixel[1] = 0xff; - cPixel[2] = 0x00; - cPixel[3] = 0xff; - } else { - if( cNode->values.cnt == 0 ) { - // Set Blue - cPixel[0] = 0x00; - cPixel[1] = 0x00; - cPixel[2] = 0xff; - cPixel[3] = 0xff; - } else { - uint32_t tColor; - float tVal = ((float) cNode->values.min ) / 4096.f; - tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); - cPixel[0] = ( tColor >> 24 ) & 0xFF; - cPixel[1] = ( tColor >> 16 ) & 0xFF; - cPixel[2] = ( tColor >> 8 ) & 0xFF; - cPixel[3] = tColor & 0xFF; - }; - }; -#else - if( cNode->values.cnt == 0 ) { - // Set Blue - cPixel[0] = 0x00; - cPixel[1] = 0x00; - cPixel[2] = 0xff; - cPixel[3] = 0xff; - } else { - uint32_t tColor; - float tVal = ((float) cNode->values.min ) / 4096.f; - tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); - cPixel[0] = ( tColor >> 24 ) & 0xFF; - cPixel[1] = ( tColor >> 16 ) & 0xFF; - cPixel[2] = ( tColor >> 8 ) & 0xFF; - cPixel[3] = tColor & 0xFF; - }; -#endif - }; - }; - }; - int RetVal = stbi_write_png( fileName, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace ); - free( tMemory ); - if( RetVal == 0 ) return false; - return true; -}; -#endif //TWI_TH_USE_PICTURES - -#undef SLOG -#undef SLOG_ERROR - -#undef LOG -#undef LOG_ERROR - diff --git a/lib/App/3dSERVER/LRF_TwinConnector.h b/lib/App/3dSERVER/LRF_TwinConnector.h deleted file mode 100644 index e9d6fbf4..00000000 --- a/lib/App/3dSERVER/LRF_TwinConnector.h +++ /dev/null @@ -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 diff --git a/lib/App/CudaWare_64_DNN_Learning/main_window.cpp b/lib/App/CudaWare_64_DNN_Learning/main_window.cpp deleted file mode 100644 index eb371a65..00000000 --- a/lib/App/CudaWare_64_DNN_Learning/main_window.cpp +++ /dev/null @@ -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)); -}; diff --git a/lib/App/CudaWare_64_DNN_Learning/main_window.h b/lib/App/CudaWare_64_DNN_Learning/main_window.h deleted file mode 100644 index 33f54b19..00000000 --- a/lib/App/CudaWare_64_DNN_Learning/main_window.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __QT5_MAIN_WINDOW_HEADER__ -#define __QT5_MAIN_WINDOW_HEADER__ - -#ifndef __linux__ - #include -#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 diff --git a/lib/App/CudaWare_64_DNN_Learning/main_window.ui b/lib/App/CudaWare_64_DNN_Learning/main_window.ui deleted file mode 100644 index f63b4845..00000000 --- a/lib/App/CudaWare_64_DNN_Learning/main_window.ui +++ /dev/null @@ -1,273 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 794 - 604 - - - - MainWindow - - - - - - 0 - 0 - 791 - 561 - - - - - - - - - - koko - - - - - kokol - - - - - - - - - - PushButton - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - 0 - - - - Tab 1 - - - - - 20 - 10 - 321 - 211 - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - Qt::DashLine - - - true - - - - 1 - - - - - 2 - - - - - kaka - - - - - Maka - - - - - Baka - - - - - 11 - - - - - 22 - - - - - 33 - - - - - 22 - - - - - 33 - - - - - 44 - - - - - - - Tab 2 - - - - - - - - - - - 0 - 0 - 794 - 21 - - - - - File - - - - - - - - - - - - toolBar - - - Qt::Horizontal - - - Qt::ToolButtonTextBesideIcon - - - true - - - TopToolBarArea - - - true - - - - - - :/general/bulb.png:/general/bulb.png - - - New Network - - - - - - :/menu/PNG/devices/030.png:/menu/PNG/devices/030.png - - - Open - - - - - Save - - - - - Save As - - - - - - - - - listWidget - clicked(QModelIndex) - MainWindow - close() - - - 353 - 160 - - - 396 - 301 - - - - - tableWidget - cellClicked(int,int) - MainWindow - show() - - - 183 - 454 - - - 396 - 301 - - - - - diff --git a/lib/App/Pathfinder/PathfinderBackend.cpp b/lib/App/Pathfinder/PathfinderBackend.cpp deleted file mode 100644 index 7221dc0a..00000000 --- a/lib/App/Pathfinder/PathfinderBackend.cpp +++ /dev/null @@ -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); -} - diff --git a/lib/App/Pathfinder/PathfinderBackend.h b/lib/App/Pathfinder/PathfinderBackend.h deleted file mode 100644 index 576cfc90..00000000 --- a/lib/App/Pathfinder/PathfinderBackend.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/lib/App/Pathfinder/Pathfinder_Kernel.cpp b/lib/App/Pathfinder/Pathfinder_Kernel.cpp deleted file mode 100644 index 2b6196f4..00000000 --- a/lib/App/Pathfinder/Pathfinder_Kernel.cpp +++ /dev/null @@ -1,769 +0,0 @@ -/******************************************************************* -* -* DESCRIPTION: ARGUS Kernel source -* -* AUTHOR: gagua -* -* HISTORY: -* -* DATE:5/29/2019 -* -*******************************************************************/ -#include "Pathfinder_Kernel.h" -#include - -#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 -#include - -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 - diff --git a/lib/App/Pathfinder/Pathfinder_Kernel.h b/lib/App/Pathfinder/Pathfinder_Kernel.h deleted file mode 100644 index a474d6eb..00000000 --- a/lib/App/Pathfinder/Pathfinder_Kernel.h +++ /dev/null @@ -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 -#include - -#include -#include -#include -#include - -#include /* getopt_long() */ - -#include /* low-level i/o */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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 - - -#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 diff --git a/lib/App/QTPro3DGUI/main.cpp b/lib/App/QTPro3DGUI/main.cpp deleted file mode 100644 index 2e6f1617..00000000 --- a/lib/App/QTPro3DGUI/main.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#ifdef _NO_STDIO_IOB_FUNC_ - extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; } -#endif -#include "mainwindow.h" -#include -#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 diff --git a/lib/App/QTPro3DGUI/mainwindow.cpp b/lib/App/QTPro3DGUI/mainwindow.cpp deleted file mode 100644 index 55c9b273..00000000 --- a/lib/App/QTPro3DGUI/mainwindow.cpp +++ /dev/null @@ -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(); -} diff --git a/lib/App/QTPro3DGUI/mainwindow.h b/lib/App/QTPro3DGUI/mainwindow.h deleted file mode 100644 index e00427c6..00000000 --- a/lib/App/QTPro3DGUI/mainwindow.h +++ /dev/null @@ -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 - -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 diff --git a/lib/App/QTPro3DGUI/mainwindow.ui b/lib/App/QTPro3DGUI/mainwindow.ui deleted file mode 100644 index 269c0d55..00000000 --- a/lib/App/QTPro3DGUI/mainwindow.ui +++ /dev/null @@ -1,609 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 1206 - 710 - - - - 3DSingleIPI - - - - :/pictures/logo-40.png:/pictures/logo-40.png - - - - - - - - - - - - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - - 16777215 - 16777215 - - - - Text-align:left;font: 12pt - - - Show Minimums - - - - :/pictures/appbar.arrow.collapsed.png:/pictures/appbar.arrow.collapsed.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - - 16777215 - 16777215 - - - - Text-align:left;font: 12pt - - - Show Maximums - - - - :/pictures/appbar.arrow.expand.png:/pictures/appbar.arrow.expand.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - - 16777215 - 16777215 - - - - Text-align:left;font: 12pt - - - Test Working TH - - - - :/pictures/appbar.alien.png:/pictures/appbar.alien.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - - 16777215 - 16777215 - - - - Text-align:left;font: 12pt - - - PushButton - - - - :/pictures/appbar.camera.png:/pictures/appbar.camera.png - - - - 40 - 40 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - QLayout::SetMinimumSize - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Clear Events Log - - - - :/pictures/appbar.new.png:/pictures/appbar.new.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Reset Detection - - - - :/pictures/appbar.transform.rotate.clockwise.png:/pictures/appbar.transform.rotate.clockwise.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Silence Alarm - - - - :/pictures/appbar.sound.0.png:/pictures/appbar.sound.0.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Report - - - - :/pictures/appbar.cabinet.files.variant.png:/pictures/appbar.cabinet.files.variant.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Exit - - - - :/pictures/appbar.power.png:/pictures/appbar.power.png - - - - 40 - 40 - - - - - - - - - 0 - 0 - - - - - 220 - 54 - - - - Text-align:left;font: 12pt - - - Settings - - - - :/pictures/appbar.cog.png:/pictures/appbar.cog.png - - - - 40 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - 16777215 - 16777215 - - - - 1 - - - - Events Log - - - - - - - - - - Video Survilence - - - - - - - - - - - - - - Start Record - - - - :/pictures/appbar.cabinet.in.png:/pictures/appbar.cabinet.in.png - - - - 40 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - Devices - - - - - - - - true - - - - - 0 - 0 - 1162 - 189 - - - - - - - - - - - - 3D View - - - - - - - - - - 2D View - - - - - - - - - - - - - - - - - TimeShowWidget - QWidget -
../../lib/gui/controls/TimeShowWidget.h
- 1 -
- - EventViewerList - QListView -
../../lib/gui/controls/EventViewWidget.h
-
- - RangeMapWidget - QWidget -
../../lib/gui/controls/RangeMapWidget.h
- 1 -
- - VideoWidget - QWidget -
../../lib/gui/controls/VideoWidget.h
- 1 -
- - VideoSourceChooser - QWidget -
../../lib/gui/controls/VideoSourceChooser.h
- 1 -
- - RadarMapWidget - QWidget -
../../lib/gui/controls/RadarMapWidget.h
- 1 -
- - GLRadar - QOpenGLWidget -
../../lib/gui/controls/OGLRadarWidget.h
-
- - DeviceChooser - QWidget -
../../lib/gui/controls/DeviceChooser.h
- 1 -
-
- - - - - - m_pButtonCmdExit - clicked() - MainWindow - close() - - - 1084 - 293 - - - 602 - 354 - - - - -
diff --git a/lib/App/argus/ArgusBackend.cpp b/lib/App/argus/ArgusBackend.cpp deleted file mode 100644 index de256caa..00000000 --- a/lib/App/argus/ArgusBackend.cpp +++ /dev/null @@ -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 - -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); -} - diff --git a/lib/App/argus/ArgusBackend.h b/lib/App/argus/ArgusBackend.h deleted file mode 100644 index c71285e4..00000000 --- a/lib/App/argus/ArgusBackend.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/lib/App/argus/RGoose_Kernel.cpp b/lib/App/argus/RGoose_Kernel.cpp deleted file mode 100644 index 4340d877..00000000 --- a/lib/App/argus/RGoose_Kernel.cpp +++ /dev/null @@ -1,637 +0,0 @@ -/******************************************************************* -* -* DESCRIPTION: ARGUS Kernel source -* -* AUTHOR: gagua -* -* HISTORY: -* -* DATE:5/29/2019 -* -*******************************************************************/ -#include "RGoose_Kernel.h" -#include - -#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 -#include - -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 - diff --git a/lib/App/argus/RGoose_Kernel.h b/lib/App/argus/RGoose_Kernel.h deleted file mode 100644 index 83919a44..00000000 --- a/lib/App/argus/RGoose_Kernel.h +++ /dev/null @@ -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 -#include - -#include -#include -#include -#include - -#include /* getopt_long() */ - -#include /* low-level i/o */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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 diff --git a/lib/App/argus_server/ArgusBackend.cpp b/lib/App/argus_server/ArgusBackend.cpp deleted file mode 100644 index cb71521d..00000000 --- a/lib/App/argus_server/ArgusBackend.cpp +++ /dev/null @@ -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 - -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); -} - diff --git a/lib/App/argus_server/ArgusBackend.h b/lib/App/argus_server/ArgusBackend.h deleted file mode 100644 index 9ec5fdc9..00000000 --- a/lib/App/argus_server/ArgusBackend.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/lib/App/argus_server/ArgusKernel.cpp b/lib/App/argus_server/ArgusKernel.cpp deleted file mode 100644 index 45c2717f..00000000 --- a/lib/App/argus_server/ArgusKernel.cpp +++ /dev/null @@ -1,637 +0,0 @@ -/******************************************************************* -* -* DESCRIPTION: ARGUS Kernel source -* -* AUTHOR: gagua -* -* HISTORY: -* -* DATE:2/25/2024 -* -*******************************************************************/ -#include "ArgusKernel.h" -#include - -#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 -#include - -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 - diff --git a/lib/App/argus_server/ArgusKernel.h b/lib/App/argus_server/ArgusKernel.h deleted file mode 100644 index aaeba6fb..00000000 --- a/lib/App/argus_server/ArgusKernel.h +++ /dev/null @@ -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 -#include - -#include -#include -#include -#include - -#include /* getopt_long() */ - -#include /* low-level i/o */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -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 diff --git a/lib/App/defender/ArgusBackend.cpp b/lib/App/defender/ArgusBackend.cpp deleted file mode 100644 index 1403b29d..00000000 --- a/lib/App/defender/ArgusBackend.cpp +++ /dev/null @@ -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); -} - diff --git a/lib/App/defender/ArgusBackend.h b/lib/App/defender/ArgusBackend.h deleted file mode 100644 index 19beec5a..00000000 --- a/lib/App/defender/ArgusBackend.h +++ /dev/null @@ -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 -#include -#include - -#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 diff --git a/lib/App/defender/RGoose_Kernel.cpp b/lib/App/defender/RGoose_Kernel.cpp deleted file mode 100644 index ea412184..00000000 --- a/lib/App/defender/RGoose_Kernel.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************* -* -* DESCRIPTION: ARGUS Kernel source -* -* AUTHOR: gagua -* -* HISTORY: -* -* DATE:5/29/2019 -* -*******************************************************************/ -#include "RGoose_Kernel.h" -#include - -#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 - diff --git a/lib/App/defender/RGoose_Kernel.h b/lib/App/defender/RGoose_Kernel.h deleted file mode 100644 index 36c101f2..00000000 --- a/lib/App/defender/RGoose_Kernel.h +++ /dev/null @@ -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 -#include - -#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 diff --git a/lib/App/mastbaumGUI/main.cpp b/lib/App/mastbaumGUI/main.cpp deleted file mode 100644 index 19889c21..00000000 --- a/lib/App/mastbaumGUI/main.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#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 -#include -#include -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; -} - -*/ - diff --git a/lib/App/mastbaumGUI/main_window.cpp b/lib/App/mastbaumGUI/main_window.cpp deleted file mode 100644 index cf21f1e0..00000000 --- a/lib/App/mastbaumGUI/main_window.cpp +++ /dev/null @@ -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(); -}; diff --git a/lib/App/mastbaumGUI/main_window.h b/lib/App/mastbaumGUI/main_window.h deleted file mode 100644 index a0a0405e..00000000 --- a/lib/App/mastbaumGUI/main_window.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef __QT5_MAIN_WINDOW_HEADER__ -#define __QT5_MAIN_WINDOW_HEADER__ - -#include - -#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 diff --git a/lib/App/mastbaumSERVER/ClientHandler.cpp b/lib/App/mastbaumSERVER/ClientHandler.cpp deleted file mode 100644 index d7b12190..00000000 --- a/lib/App/mastbaumSERVER/ClientHandler.cpp +++ /dev/null @@ -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 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 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 diff --git a/lib/App/mastbaumSERVER/ClientHandler.h b/lib/App/mastbaumSERVER/ClientHandler.h deleted file mode 100644 index 6499ed9f..00000000 --- a/lib/App/mastbaumSERVER/ClientHandler.h +++ /dev/null @@ -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__ diff --git a/lib/App/mastbaumSERVER/Kernel.cpp b/lib/App/mastbaumSERVER/Kernel.cpp deleted file mode 100644 index 50dc5ef1..00000000 --- a/lib/App/mastbaumSERVER/Kernel.cpp +++ /dev/null @@ -1,1326 +0,0 @@ -//---------------------------------------------------------------------------- -// Dr.Frucht Systems Ltd. -// Copyright © 2000-2018. All Rights Reserved. -// Version 1.0 12/12/2018 -// Last modification: 12/12/2018 -// PROJECT: -// SUBSYSTEM: -// FILE: Kernel.cpp -// AUTHOR: gagua -// OVERVIEW -// ~~~~~~~~ -// Kernel.cpp -//---------------------------------------------------------------------------- -// - -#include "Kernel.h" -//#define _GNU_SOURCE -//#include -//#include - -#define LOG( X ) m_pLog->Log( "Kernel", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "Kernel", this, _LOG_ERROR, X ) - -// Constructor implementation -Kernel::Kernel( CSTR *HM ): basicThread(){ - m_bExitCause = 0; - m_pLog = basicLogCollection::getInstance(); - m_pEventHeap = basicEventHeap::getInstance(); - m_pSettingsProvider = basicSettingsProvider::getInstance(); - m_pDataBase = NULL; - m_pNetClientsServer = NULL; - m_pVideoInputs = NULL; - m_pVideoNames = NULL; - m_pMatProtector = NULL; - m_pFinalFrame = NULL; - m_bEngineIsAvlib = false; - m_nPictureRot = 0; - m_nConvertType = 0; - m_bPictureRotated = false; - m_pDBHost = m_pDBUser = m_pDBPass = m_pDBName = m_pStorageBase = NULL; - for( uint8_t index = 0; index < MAX_LRF_SENSORS; index++ )m_nLRF_Background[index] = 0x03FF; - m_nFrameCounter = 0; - m_nAlarmCnt = 0; - m_bRecordIsActive = false; - m_bRecordIsSaving = false; - m_lStartTS = 0ll; - m_nCOnlineMask = 0; - m_nCOKMask = 0; - m_nDetectorSST = 0; - m_fDetectorMinSpeed = -1.f; - -#ifdef ASSEMBLE_MP4 - m_bAssembleMP4 = true; -#else - m_bAssembleMP4 = false; -#endif - -#ifdef AMIR_MODE - m_nCurrentRange = 0; -#endif - -#ifdef USE_TIME_LAPSE_RECORDER - m_pVideoOutput = NULL; -#else - for( int index = 0; index < MAX_RECORD_FRAMES; index++ ) { - m_pVidRecFrame[index] = NULL; - }; -#endif - m_nVideoInputs = 0; - m_nWidth = 320; - m_nHeight = 240; - m_bHorizontal = true; - m_nCLoopMask = 0xFFFFFFFF; - m_nCLoopCheck = 0; - m_nScheduledTaskCounter = 0; - LOG("K-C1"); - if( m_pSettingsProvider ) { - m_pSettings = m_pSettingsProvider->getSubNode( NULL, KNL_SETTINGS_MAIN_TAG ); - if( m_pSettingsProvider->isCompromised() ) { - m_pSettingsProvider->validate(); - }; - } else { - m_pSettings = NULL; - }; - LOG("K-CE"); -}; - -// Destructor implementation -Kernel::~Kernel(){ -#ifdef DEBUG - LOG("Destructor"); -#endif - WaitFinish(true); -#ifdef DEBUG - LOG("Deleting Components"); -#endif - if( m_pVideoInputs != NULL ) { - for( int index = 0; index < m_nVideoInputs; index++ ) { - if( m_pVideoInputs[index] != NULL ) delete( m_pVideoInputs[index] ); - if( m_pVideoFrame[index] != NULL ) delete( m_pVideoFrame[index] ); - }; - free(m_pVideoInputs); - free(m_pVideoFrame); - }; - if( m_pFinalFrame!= NULL ) { - delete(m_pFinalFrame); - m_pFinalFrame == NULL; - }; - if(m_pMatProtector != NULL ) { - m_pMatProtector->unlock(); - delete(m_pMatProtector); - }; - -#ifndef USE_TIME_LAPSE_RECORDER - for( int index = 0; index < MAX_RECORD_FRAMES; index++ ) { - if(m_pVidRecFrame[index]!= NULL )delete(m_pVidRecFrame[index]); - }; -#endif - -#ifdef DEBUG - LOG("Destructor Finished"); -#endif -}; - -bool Kernel::attachNetServer( networkServer *srvPort ){ - if( srvPort != NULL ) { - m_pNetClientsServer = srvPort; - }; - if( m_pNetClientsServer!= NULL ) { - LOG("Binding Network Manager to Kernel module"); - return srvPort->attachEngine( (basicEngine *)this ); - }; - return false; -}; - -bool Kernel::getDevicePath(CSTR Path, CSTR BusID ){ - bool tFlag = false; - if(Path == NULL ) return false; - if( BusID == NULL ) return false; - Path[0] = (char)0; - for( int i = 0; i< m_InputInfo.size(); i++ ) { - if( strcmp( m_InputInfo.at(i)->FriendlyName, BusID ) == 0 ){ - sprintf( Path, "%s", m_InputInfo.at(i)->DevicePath ); - tFlag = true; - break; - }; - }; - return tFlag; -}; -//https://www.youtube.com/watch?time_continue=84&v=a4lY6uX3q1M -//http://flv-player.net/players/mini/ -bool Kernel::create( CSTR *ptr, networkServer *srvPort ){ - char tBuffer[256]; - if( m_pSettings != NULL ) { - config_setting_t *pSetting; - config_setting_t *pVideoInputs; - int tVal, mCount; - double tFVal; - - LOG("Attach Network ..."); - attachNetServer( srvPort ); - - LOG("Getting Local Video Sources ..."); - if( !enumerateDevices( &m_InputInfo ) ){ - LOG_ERROR("Error Geting local Sources!"); - } else { - sprintf( tBuffer, "Detected %d Video Sources", m_InputInfo.size() ); - LOG( tBuffer ); - }; - - LOG("Getting Settings ..."); - - if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_CONVERT_TYPE, &tVal)){ - tVal = 0; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_CONVERT_TYPE, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - basicSettingsProvider::getInstance()->compromise(); - }; - m_nConvertType = tVal; - - if (!config_setting_lookup_int(m_pSettings, KNL_SETTINGS_VIDEO_ENGINE, &tVal)){ - tVal = 1; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_VIDEO_ENGINE, CONFIG_TYPE_INT); - config_setting_set_int(pSetting, tVal ); - basicSettingsProvider::getInstance()->compromise(); - }; - - m_bEngineIsAvlib = (tVal == 0); - - if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DATABASE_ENA, &tVal ) ){ - tVal = m_bDatabaseEnable = false; - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DATABASE_ENA, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("Database support not defined -> Disabling"); - } else { - m_bDatabaseEnable = (bool)tVal; - sprintf( tBuffer, "Database Support Read From Settings: %d", m_bDatabaseEnable ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_VIDEO_OUTPUT, &tVal ) ){ -#ifdef ASSEMBLE_MP4 - tVal = m_bAssembleMP4 = true; -#else - tVal = m_bAssembleMP4 = false; -#endif - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_VIDEO_OUTPUT, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); -#ifdef ASSEMBLE_MP4 - LOG("MP4 support not defined -> Enabling"); -#else - LOG("MP4 support not defined -> Disabling"); -#endif - } else { - m_bAssembleMP4 = (bool)tVal; - sprintf( tBuffer, "MP4 Support Read From Settings: %d", m_bAssembleMP4 ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_bool( m_pSettings, KNL_SETTINGS_DETECT_ARMED, &tVal ) ){ - tVal = m_bDetectorArmed = false; - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_ARMED, CONFIG_TYPE_BOOL ); - config_setting_set_bool( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("Detector Armed not defined -> Disabling"); - } else { - m_bDetectorArmed = (bool)tVal; - sprintf( tBuffer, "Detector Armed Read From Settings: %d", m_bDetectorArmed ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_float( m_pSettings, KNL_SETTINGS_DETECT_LAYER_DIST, &tFVal ) ){ - tFVal = (double)(m_fDetectorLayerDistance = -1.f); - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_LAYER_DIST, CONFIG_TYPE_FLOAT ); - config_setting_set_float( pSetting, tFVal ); - m_pSettingsProvider->compromise(); - LOG("Detector Layer Distance not defined -> Disabling"); - } else { - m_fDetectorLayerDistance = (float)tFVal; - sprintf( tBuffer, "Detector Layer Distance Read From Settings: %0.2f", m_fDetectorLayerDistance ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_float( m_pSettings, KNL_SETTINGS_DETECT_MAX_RANGE, &tFVal ) ){ - tFVal = (double)(m_fDetectorMaxDistance = 3.f); - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_MAX_RANGE, CONFIG_TYPE_FLOAT ); - config_setting_set_float( pSetting, tFVal ); - m_pSettingsProvider->compromise(); - LOG("Detector Max Distance not defined set 3.0 meters"); - } else { - m_fDetectorMaxDistance = (float)tFVal; - sprintf( tBuffer, "Detector Max Distance Read From Settings: %0.2f", m_fDetectorMaxDistance ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_float( m_pSettings, KNL_SETTINGS_DETECT_MIN_SPEED, &tFVal ) ){ - tFVal = (double)(m_fDetectorMinSpeed = 3.f); - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_MIN_SPEED, CONFIG_TYPE_FLOAT ); - config_setting_set_float( pSetting, tFVal ); - m_pSettingsProvider->compromise(); - LOG("Detector Min Speed not defined set to 3.0 m/s"); - } else { - m_fDetectorMinSpeed = (float)tFVal; - sprintf( tBuffer, "Detector Min Speed Read From Settings: %0.2f m/s", m_fDetectorMaxDistance ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_int( m_pSettings, KNL_SETTINGS_DETECT_OFFSET, &tVal ) ){ - tVal = m_nDetectorOffset = 20; - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_OFFSET, CONFIG_TYPE_INT ); - config_setting_set_int( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("Detector Offset not defined set 20"); - } else { - m_nDetectorOffset = tVal; - sprintf( tBuffer, "Detector Offset Read From Settings: %d", m_nDetectorOffset ); - LOG( tBuffer ); - }; - if( !config_setting_lookup_int( m_pSettings, KNL_SETTINGS_DETECT_SST, &tVal ) ){ - tVal = m_nDetectorSST = 0; - pSetting = config_setting_add( m_pSettings, KNL_SETTINGS_DETECT_SST, CONFIG_TYPE_INT ); - config_setting_set_int( pSetting, tVal ); - m_pSettingsProvider->compromise(); - LOG("Detector SST not defined set 0"); - } else { - m_nDetectorSST = tVal; - sprintf( tBuffer, "Detector SST Read From Settings: %d", m_nDetectorOffset ); - LOG( tBuffer ); - }; - - - if (!config_setting_lookup_string(m_pSettings, KNL_SETTINGS_STORAGE_BASE,(const char**)&m_pStorageBase)){ - m_pStorageBase = "./storage/"; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_STORAGE_BASE, CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pStorageBase); - basicSettingsProvider::getInstance()->compromise(); - }; - if( m_bDatabaseEnable ) { - if (!config_setting_lookup_string(m_pSettings, KNL_SETTINGS_DATABASE_HOST,(const char**)&m_pDBHost)){ - m_pDBHost = "localhost"; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DATABASE_HOST, CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pDBHost); - basicSettingsProvider::getInstance()->compromise(); - }; - if (!config_setting_lookup_string(m_pSettings, KNL_SETTINGS_DATABASE_NAME,(const char**)&m_pDBName)){ - m_pDBName = "mastbaum"; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DATABASE_NAME, CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pDBName); - basicSettingsProvider::getInstance()->compromise(); - }; - if (!config_setting_lookup_string(m_pSettings, KNL_SETTINGS_DATABASE_USER,(const char**)&m_pDBUser)){ - m_pDBUser = "dbroot"; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DATABASE_USER, CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pDBUser); - basicSettingsProvider::getInstance()->compromise(); - }; - if (!config_setting_lookup_string(m_pSettings, KNL_SETTINGS_DATABASE_PASS,(const char**)&m_pDBPass)){ - m_pDBPass = "123567"; - pSetting = config_setting_add(m_pSettings, KNL_SETTINGS_DATABASE_PASS, CONFIG_TYPE_STRING); - config_setting_set_string(pSetting, m_pDBPass); - basicSettingsProvider::getInstance()->compromise(); - }; - } - if( m_pSettingsProvider->isCompromised() ) { - LOG("Save Settings"); - m_pSettingsProvider->validate(); - }; - - - pVideoInputs = m_pSettingsProvider->getSubNode( m_pSettings, KNL_SETTINGS_VIDEO_SECTION ); - mCount = config_setting_length( pVideoInputs ); - if( mCount ){ - sprintf( tBuffer, "Defined %d Video Input", mCount ); - LOG(tBuffer); - m_pVideoNames = (CSTR *) calloc( mCount, sizeof(CSTR*) ); - //for( int i=0; i < mCount; i++ ){ m_pVideoNames[i]= (CSTR) malloc(256); }; - m_pVideoInputs = (basicMediaSource**) calloc( mCount, sizeof(basicMediaSource*) ); - m_pVideoFrame = (cv::Mat**) calloc( mCount, sizeof(cv::Mat*)); - memset( m_pVideoInputs, 0, sizeof(m_pVideoInputs)); - memset( m_pVideoFrame, 0, sizeof(m_pVideoFrame)); - if( m_pVideoInputs != NULL ) { - config_setting_t *tRec; - config_setting_t *ttRec; - int tIID, tWIDTH, tHEIGHT, tSCALEW, tSCALEH; - bool tSCALED; - double tFPS; - m_nVideoInputs = mCount; - for( int index = 0; index < m_nVideoInputs; index++ ){ - tRec = config_setting_get_elem( pVideoInputs, index ); - if( tRec != NULL ){ - mCount = config_setting_length( tRec ); - sprintf( tBuffer, "Records: %d", mCount ); - LOG(tBuffer); - tSCALED = false; - //if( !config_setting_lookup_int( tRec, KNL_SETTINGS_VIDEO_INPUT_ID, &tIID)) continue; - if( !config_setting_lookup_string( tRec, KNL_SETTINGS_VIDEO_INPUT_ID, (const char**)&m_pVideoNames[index] )) continue; - if( !config_setting_lookup_int( tRec, KNL_SETTINGS_VIDEO_INPUT_WIDTH, &tWIDTH)) continue; - if( !config_setting_lookup_int( tRec, KNL_SETTINGS_VIDEO_INPUT_HEIGHT, &tHEIGHT)) continue; - if( !config_setting_lookup_float( tRec, KNL_SETTINGS_VIDEO_INPUT_FPS, &tFPS)) continue; - if( !config_setting_lookup_int( tRec, KNL_SETTINGS_VIDEO_SCALE_WIDTH, &tSCALEW)) tSCALEW = -1; - if( !config_setting_lookup_int( tRec, KNL_SETTINGS_VIDEO_SCALE_HEIGHT, &tSCALEH)) tSCALEH = -1; - if(( tSCALEW != -1 )&&( tSCALEH != -1 )) tSCALED = true; - LOG( "Begin" ); - LOG( m_pVideoNames[index] ); - if( !getDevicePath( tBuffer, m_pVideoNames[index] ) ) continue; - LOG( "Found:" ); - LOG( tBuffer ); - //sprintf( tBuffer, "/dev/video%d", tIID); - if( m_bEngineIsAvlib ){ - m_pVideoInputs[index] = (basicMediaSource*)new videoAVLIBSource(); - if( !((videoAVLIBSource*)m_pVideoInputs[index])->_open( tBuffer, false, (float)tFPS, -1, tWIDTH, tHEIGHT, tSCALED, tSCALEW, tSCALEH )){ - delete((videoAVLIBSource*)m_pVideoInputs[index]); - m_pVideoInputs[index] = NULL; - LOG_ERROR("Source Open Failure."); - } else { - if(tSCALED) { - if( m_nWidth < tSCALEW ) m_nWidth = tSCALEW; - if( m_nHeight < tSCALEH ) m_nHeight = tSCALEH; - }else{ - if( m_nWidth < tWIDTH ) m_nWidth = tWIDTH; - if( m_nHeight < tHEIGHT ) m_nHeight = tHEIGHT; - }; - m_pVideoFrame[index] = new cv::Mat( tHEIGHT, tWIDTH, CV_8UC3 ); - m_pVideoInputs[index]->attachDestination( this ); - LOG("Source Opened OK."); - }; - } else { - m_pVideoInputs[index] = (basicMediaSource*)new videoV4L2Source(); - if( !((videoV4L2Source*)m_pVideoInputs[index])->_open( tBuffer, false, (float)tFPS, -1, tWIDTH, tHEIGHT, tSCALED, tSCALEW, tSCALEH )){ - delete((videoV4L2Source*)m_pVideoInputs[index]); - m_pVideoInputs[index] = NULL; - LOG_ERROR("Source Open Failure."); - } else { - if(tSCALED) { - if( m_nWidth < tSCALEW ) m_nWidth = tSCALEW; - if( m_nHeight < tSCALEH ) m_nHeight = tSCALEH; - }else{ - if( m_nWidth < tWIDTH ) m_nWidth = tWIDTH; - if( m_nHeight < tHEIGHT ) m_nHeight = tHEIGHT; - }; - m_pVideoFrame[index] = new cv::Mat( tHEIGHT, tWIDTH, CV_8UC3 ); - m_pVideoInputs[index]->attachDestination( this ); - LOG("Source Opened OK."); - }; - }; - } else { - LOG_ERROR("Mem Allocation Error!"); - }; - m_nCLoopCheck |=(1<setFrameLapse( MAX_RECORD_FRAMES ); - }; - }; -#endif - - if( m_bDatabaseEnable ) { - /* DataBase */ - m_pDataBase = new MySQL_Connector(); - if( m_pDataBase!= NULL ) { - if( !m_pDataBase->Connect( m_pDBName, m_pDBHost, m_pDBUser, m_pDBPass ) ){ - LOG_ERROR("Error Connecting to Database!"); - //return false; - } else { - }; - }; - }; - } else { - LOG_ERROR("Failed Read Config Settings!"); - return false; - }; - - if( m_pEventHeap == NULL ){ - LOG_ERROR("No Event Heap attached!"); - return false; - }; - -#ifdef DEBUG - LOG( "Trhead about to be created" ); -#endif - if( init() == false ){ - LOG_ERROR("Error in starting Kernel Thread!"); - return false; - }; - - m_pProtocol = new protocolMastBaum( m_pSettings ); - - if( m_pProtocol != NULL ) { - m_pProtocol->attachKernel( this ); - m_pProtocol->create(); - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_SEND_SETTINGS; - } else { - LOG_ERROR("Error in starting Kernel Protocol!"); - return false; - }; - - putEvent2FS( FSL_SYSTEM_STARTUP ); - postStatus2FS(); - m_bTargetOverflow = MAX_TARGET_ACCEPTED_AT_ONCE; -#ifdef DEBUG - LOG( "Created" ); -#endif - return true; -}; -//https://dist.plone.org/download/ -void Kernel::putEvent2FS( uint8_t code, int x1, int y1, int x2, int y2, float speed, bool has_image, CSTR path){ - FILE *fd; - fd = fopen(m_sFSReportName, "a+" ); - if( fd ){ - m_nInitialFSID++; - uint32_t ts = ( uint32_t ) time(NULL); - switch( code ) { - case FSL_OPERATOR_ALARM: - case FSL_ALARM:{ - float r1, r2; - r1 = y1;//( m_fDetectorMaxDistance / 8.0f ) * (float) y1; - r2 = y2;//( m_fDetectorMaxDistance / 8.0f ) * (float) y2; - fprintf( fd, "%d,%d,%d,%d,%0.2f,%d,%0.2f,%0.3f,%d,%s\n", - m_nInitialFSID, - ts, - code, - x1, r1, x2, r2, speed, has_image, path - ); - break; - }; - default: fprintf( fd, "%d,%d,%d\n", m_nInitialFSID, ts, code ); break; - }; - fclose(fd); - chmod( m_sFSReportName, STORAGE_FILE_MODE ); - }; -}; -//https://www.ebay.com/itm/Nvidia-Tesla-M2090-6GB-GDDR5-PCIe-Accelerator-Video-Graphics-Card-775NK/123590917738 - -//http://www.zoomify.com/free.htm - -void Kernel::postStatus2FS( bool isActive ){ - FILE *fd; - fd = fopen( m_sWEBStatus, "w+" ); - if( fd ){ - uint32_t ts = ( uint32_t ) time(NULL); - fprintf( fd, "%d,%d,%d,%d,%d,%d,%d,%0.3f,%0.3f,%0.3f \n", - ts, - isActive, - m_bDetectorArmed, - m_nCOnlineMask, - m_nCOKMask, - m_nDetectorOffset, - m_nDetectorSST, - m_fDetectorMaxDistance, - m_fDetectorLayerDistance, - m_fDetectorMinSpeed - ); - for( uint8_t index=0; index < MAX_LRF_SENSORS; index++ ) fprintf( fd, "%d\n", m_nLRF_Background[index] ); - fclose(fd); - chmod( m_sWEBStatus, STORAGE_FILE_MODE ); - }; -}; - -void Kernel::alarm( bool real ){ -#ifdef USE_TIME_LAPSE_RECORDER -#ifdef DEBUG - LOG("Get VO Status!"); -#endif - if( !m_pVideoOutput->getRecordStatus() ){ - m_nAlarmCnt++; - char Buffer[1024]; - sprintf( m_sSeriesName, "%s", m_pStorageProvider->getNewFileName()); - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); -#ifdef DEBUG - LOG("Begin VO!"); -#endif - m_bRecordIsSaving = m_pVideoOutput->beginOutput( Buffer ); - } else { -#ifdef DEBUG - LOG("Cont VO!"); -#endif - m_bRecordIsSaving = m_pVideoOutput->continueOutput(); - }; - m_bRecordIsActive = m_bRecordIsSaving; - m_bEventRegistered = false; -#else //USE_TIME_LAPSE_RECORDER - if( !m_bRecordIsActive ){ - m_nAlarmCnt++; - //m_pStorageProvider->startNewEntry(); - sprintf( m_sSeriesName, "%s", m_pStorageProvider->getNewFileName()); - m_bRecordIsActive = true; - m_bRecordIsSaving = true; - m_bEventRegistered = false; -#endif // USE_TIME_LAPSE_RECORDER -#ifdef NO_GPIO_HANDLER - if( !real ) { -#else - if( real ) { - // Request Alarm Info from HW -#ifdef DEBUG - LOG("HW ALARM is SET!"); -#endif - m_pProtocol->requestTargets(); - } else { -#endif - char Buffer[1024]; - #ifdef USE_TIME_LAPSE_RECORDER - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - #else - #ifdef ASSEMBLE_MP4 - if( m_bAssembleMP4 ) { - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - } else { - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - }; - #else - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - #endif - #endif // USE_TIME_LAPSE_RECORDER - putEvent2FS( FSL_OPERATOR_ALARM, 20,20,20,20,0,true, Buffer );//https://www.deviantart.com/mushroombrain - m_bEventRegistered = true; -#ifdef DEBUG - LOG("SYM ALARM is SET!"); -#endif - }; -#ifndef USE_TIME_LAPSE_RECORDER - }; -#endif -}; - -void 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 -}; - - -#ifndef USE_TIME_LAPSE_RECORDER -void *Kernel::t_fSavePictures_Proc(void *ptr){ - Kernel *me; - me = (Kernel*) ptr; - //Save Last Record On disk - vector 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 buf; - char Buffer[MAX_PATH]; - int DataSize; - int z_index = 0; - while( me->m_rPrerecord.count > 0 ) { - cv:Mat *tMat; - tMat = me->m_rPrerecord.pop(); - if( tMat != NULL ) { - FILE *FID; - imencode( ".jpg", *tMat, buf, compression_params ); - DataSize = buf.size(); - sprintf( Buffer, "%s_%02d_%03d.jpg", me->m_sSeriesName, me->m_nAlarmCnt, z_index ); - FID = fopen( Buffer, "wb+"); - fwrite(buf.data(),DataSize, 1,FID ); - fclose(FID); - z_index++; - }; - delete( tMat ); - }; - for( int index = MAX_RECORD_FRAMES - 1; index > -1; index -- ) { - FILE *FID; - imencode( ".jpg", (*me->m_pVidRecFrame[index]), buf, compression_params ); - DataSize = buf.size(); - sprintf( Buffer, "%s_%02d_%03d.jpg", me->m_sSeriesName, me->m_nAlarmCnt, z_index ); - FID = fopen( Buffer, "wb+"); - fwrite(buf.data(),DataSize, 1,FID ); - fclose(FID); - chmod( Buffer, STORAGE_FILE_MODE ); - z_index++; - }; -#ifdef ASSEMBLE_MP4 - if( me->m_bAssembleMP4 ) { - // Create Video From Pictures - sprintf( Buffer, - //"ffmpeg -loglevel panic -hide_banner -f image2 -r 15 -i %s_%02d_%%03d.jpg -vb 1200k -y -an -r 15 %s_%02d.flv", - "ffmpeg -loglevel panic -hide_banner -f image2 -r 15 -i %s_%02d_%%03d.jpg -vb 500k -pix_fmt yuv420p -y -an -r 15 %s_%02d.mp4", - me->m_sSeriesName, - me->m_nAlarmCnt, - me->m_sSeriesName, - me->m_nAlarmCnt - ); - basicLogCollection::getInstance()->Log( "Kernel-ST", NULL, Buffer ); - FILE *fid; - char temp; - - fid = popen( Buffer, "r" ); - if( fid!= NULL ){ - while( !feof( fid ) ) fread( &temp, 1, 1, fid ); - pclose( fid ); - sprintf( Buffer, "%s_%02d.mp4", me->m_sSeriesName, me->m_nAlarmCnt ); - chmod( Buffer, STORAGE_FILE_MODE ); - #ifndef KEEP_JPEG_IMAGES - for( int index = ( MAX_RECORD_FRAMES << 1 ) - 1; index > -1; index -- ) { - sprintf( Buffer, "%s_%02d_%03d.jpg", me->m_sSeriesName, me->m_nAlarmCnt, index ); - unlink( Buffer ); - }; - #endif - } else { - basicLogCollection::getInstance()->Log( "Kernel-ST", NULL, "ERROR CREATE POPEN!" ); - }; - }; -#endif - me->m_bRecordIsSaving = false; - me->m_nRecordCounter = MAX_RECORD_FRAMES; - return NULL; -}; -#endif //USE_TIME_LAPSE_RECORDER - -/* Main Kernel Thread Procedure */ -void Kernel::m_fThreadProc( void ){ - char Buffer[1024]; - m_bThreadStatus = TH_WORKING; - while( m_bThreadStatus < TH_ENDED ){ - int cmd = WEB_CMD_NOP, param; - float fparam1, fparam2, fparam3; - /* check Video Subsystem */ - for( int index = 0; index < m_nVideoInputs; index++ ){ - if( m_pVideoInputs[index] != NULL ){ - MediaStateStatus tMediaStatus; - tMediaStatus = ((videoAVLIBSource*)m_pVideoInputs[index])->getStatus(); - if( tMediaStatus != MS_PRESENT ) { - if( m_bEngineIsAvlib ){ - // Delete Loosed Video Input - LOG("Deleting AVLIB Video Source"); - delete((videoAVLIBSource*)m_pVideoInputs[index]); - rectangle( (*m_pVideoFrame[index]), Point( 0, 0 ), Point( m_pVideoFrame[index]->cols, m_pVideoFrame[index]->rows ), Scalar( 0, 0, 0 ), CV_FILLED ); - putText( (*m_pVideoFrame[index]), "Video Source Failure!", Point( 20 ,40 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 0, 0, 255 ), 1 ); - /* Polish Memory */ - m_pVideoInputs[index] = NULL; - m_nCLoopMask &= ~(1<cols, m_pVideoFrame[index]->rows ), Scalar( 0, 0, 0 ), CV_FILLED ); - putText( (*m_pVideoFrame[index]), "Video Source Failure!", Point( 20 ,40 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 0, 0, 255 ), 1 ); - m_pVideoInputs[index] = NULL; - m_nCLoopMask &= ~(1<_open( tBuffer, false )){ - delete((videoAVLIBSource*)m_pVideoInputs[index]); - m_pVideoInputs[index] = NULL; - LOG_ERROR("Source ReOpen Failure."); - } else { - m_pVideoInputs[index]->attachDestination( this ); - LOG("Source ReOpened OK."); - }; - } else { - m_pVideoInputs[index] = (basicMediaSource*)new videoV4L2Source(); - if( !((videoV4L2Source*)m_pVideoInputs[index])->_open( tBuffer, false )){ - delete((videoV4L2Source*)m_pVideoInputs[index]); - m_pVideoInputs[index] = NULL; - LOG_ERROR("Source ReOpen Failure."); - } else { - m_pVideoInputs[index]->attachDestination( this ); - LOG("Source ReOpened OK."); - }; - }; - }; - }; - }; - /* Get Commands Via File */ - struct stat stFileInfo; - int intStat; - char *cmdBuffer; - intStat = stat( m_sWEBAPIName ,&stFileInfo); - cmdBuffer = NULL; - if( intStat == 0 ) { - // check file size - if( stFileInfo.st_size > 0 ){ - FILE *tFD; - int RetVal; - size_t nSize; - tFD = fopen( m_sWEBAPIName, "r" ); - if( tFD != NULL ) { - RetVal = getline( &cmdBuffer, &nSize, tFD ); - fclose(tFD); - if( RetVal ) { - //sscanf( cmdBuffer, "%d %d %f %f %f", &cmd, ¶m, &fparam1, &fparam2, &fparam3 ); - sscanf( cmdBuffer, "%d", &cmd ); - }; - }; - unlink( m_sWEBAPIName ); - }; - }; - /* Get COmmands Via Database - Dont use now */ - if( m_pDataBase ) { - AAssoc *Result; - sprintf( Buffer, "SELECT * FROM web2engine LIMIT 1"); - Result = m_pDataBase->Query( Buffer ); - if( Result!= NULL ){ - int c_id; - c_id = atoi( Result->at(0)->at("id").c_str()); - cmd = atoi( Result->at(0)->at("cmd").c_str()); - param = atoi( Result->at(0)->at("param").c_str()); - // Delete Command From Queue - sprintf( Buffer, "DELETE FROM web2engine WHERE id = %d", c_id ); - m_pDataBase->SilentQuery( Buffer ); - // Free Assoc - delete( Result ); - }; - }; - switch ( cmd ) { - case WEB_CMD_NOP: break; - case WEB_CMD_RESET_DETECTION:{ - LOG( "WEB_CMD_RESET_DETECTION"); - if( m_pProtocol->sendSoftReset() ){ - putEvent2FS( FSL_SYSTEM_RESTARTED ); - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_CHECK_STATUS; - }; - break; - }; - case WEB_CMD_CLEAR_LOG:{ - m_pStorageProvider->startNewEntry(); - putEvent2FS( FSL_LOG_CLEARED ); - break; - }; - case WEB_CMD_SET_PARAMS:{ - LOG("WEB_CMD_SET_PARAMS"); - sscanf( cmdBuffer, "%d %d %d %f %f %f", &cmd, &m_nDetectorSST, &m_nDetectorOffset, &m_fDetectorMaxDistance, &m_fDetectorLayerDistance, &m_fDetectorMinSpeed ); - //m_nDetectorOffset = param; - //m_fDetectorMaxDistance = fparam1; - //m_fDetectorLayerDistance = fparam2; - //m_fDetectorMinSpeed = fparam3; - if( m_pProtocol->sendSettings( - m_nDetectorSST, - m_nDetectorOffset, - m_fDetectorLayerDistance, - m_fDetectorMinSpeed - ) - ){ - config_setting_t *pSetting; - - putEvent2FS( FSL_DETECTION_CHANGED ); - postStatus2FS(); - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_SST); - if( pSetting != NULL ) { - config_setting_set_int(pSetting, m_nDetectorSST); - basicSettingsProvider::getInstance()->compromise(); - }; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_OFFSET); - if( pSetting != NULL ) { - config_setting_set_int(pSetting, m_nDetectorOffset); - basicSettingsProvider::getInstance()->compromise(); - }; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_LAYER_DIST); - if( pSetting != NULL ) { - config_setting_set_float(pSetting, (double)m_fDetectorLayerDistance ); - basicSettingsProvider::getInstance()->compromise(); - }; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_MAX_RANGE); - if( pSetting != NULL ) { - config_setting_set_float(pSetting, (double)m_fDetectorMaxDistance); - basicSettingsProvider::getInstance()->compromise(); - }; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_MIN_SPEED); - if( pSetting != NULL ) { - config_setting_set_float(pSetting, (double)m_fDetectorMinSpeed ); - basicSettingsProvider::getInstance()->compromise(); - }; - if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_CHECK_STATUS; - }; - break; - }; - case WEB_CMD_DISABLE_DETECTION:{ - LOG("WEB_CMD_DISABLE_DETECTION"); - m_bDetectorArmed = false; - if( m_pProtocol->sendMode( m_bDetectorArmed ) ) { - putEvent2FS( FSL_OPERATOR_DISARMED ); - postStatus2FS(); - }; - config_setting_t *pSetting; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_ARMED); - if( pSetting != NULL ) { - config_setting_set_bool( pSetting, m_bDetectorArmed ); - basicSettingsProvider::getInstance()->compromise(); - }; - if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); - break; - }; - case WEB_CMD_ENABLE_DETECTION:{ - LOG("WEB_CMD_ENABLE_DETECTION"); - m_bDetectorArmed = true; - if( m_pProtocol->sendMode( m_bDetectorArmed ) ) { - putEvent2FS( FSL_OPERATOR_ARMED ); - postStatus2FS(); - }; - config_setting_t *pSetting; - pSetting = config_setting_lookup(m_pSettings, KNL_SETTINGS_DETECT_ARMED); - if( pSetting != NULL ) { - config_setting_set_bool( pSetting, m_bDetectorArmed ); - basicSettingsProvider::getInstance()->compromise(); - }; - if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate(); - break; - }; - case WEB_CMD_MAKE_TEST_ALARM:{ - LOG("WEB_CMD_MAKE_TEST_ALARM"); - if( m_pProtocol->sendLED( true ) ) { - if(m_nScheduledTaskID == WEB_CMD_NOP ) { - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_TURN_OFF_LED; - } else m_pProtocol->sendLED( false ); - alarm( false ); - }; - break; - }; - case WEB_CMD_RESET_DEVICE:{ - LOG("WEB_CMD_RESET_DEVICE"); - if( m_pProtocol->sendFullReset() ) { - putEvent2FS( FSL_SYSTEM_RESTARTED ); - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_CHECK_STATUS; - }; - break; - }; - default: - LOG("Unknown Web CMD"); - }; - if( cmdBuffer != NULL ) { - free( cmdBuffer ); - }; -#ifdef USE_TIME_LAPSE_RECORDER - if( m_bRecordIsActive ) { - m_bRecordIsActive = m_pVideoOutput->getRecordStatus(); - if( !m_bRecordIsActive ) { - if( !m_bTargetOverflow ){ - if ( m_bDetectorArmed ){ - if( m_pProtocol->sendMode( true ) ) { - putEvent2FS( FSL_DETECTION_RESTORED ); - }; - }; - }; - m_bTargetOverflow = MAX_TARGET_ACCEPTED_AT_ONCE; - }; - }; -#else - if( !m_bRecordIsActive && m_bRecordIsSaving ) { - if( m_pSaveThreadHandler == NULL ){ - int RetVal = pthread_create( &m_pSaveThreadHandler, NULL, t_fSavePictures_Proc, ( void * ) this ); - if( RetVal == -1 ) { - LOG_ERROR("File Savier Thread Creation Faled."); - m_pSaveThreadHandler = NULL; - } else { - if( !m_bEventRegistered ){ - #ifdef USE_TIME_LAPSE_RECORDER - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - #else - #ifdef ASSEMBLE_MP4 - if( m_bAssembleMP4 ) { - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - } else { - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - }; - #else - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - #endif - #endif // USE_TIME_LAPSE_RECORDER - putEvent2FS( FSL_OPERATOR_ALARM, 0,0,0,0,0,true, Buffer ); - m_bEventRegistered = true; - }; - }; - }; - }; - if(!m_bRecordIsSaving && m_pSaveThreadHandler!= NULL ){ - // Reap thread crete event - pthread_join( m_pSaveThreadHandler, NULL ); - m_pSaveThreadHandler = NULL; - }; -#endif // USE_TIME_LAPSE_RECORDER - if( m_nScheduledTaskCounter ){ - m_nScheduledTaskCounter--; - if(m_nScheduledTaskCounter == 0) { - switch( m_nScheduledTaskID ){ - case ST_CHECK_STATUS: - LOG("SCHEDULED STATUS"); - if( m_pProtocol->requestStatus() ) m_nScheduledTaskID = ST_NO_TASK; - break; - case ST_CHECK_SETTINGS: - LOG("SCHEDULED SETTTNGS"); - if( m_pProtocol->requestSettings() ) m_nScheduledTaskID = ST_NO_TASK; - break; - case ST_ISSUE_SOFT_RESET: - LOG("SCHEDULED STUDY/SOFT RESET"); - if( m_pProtocol->sendSoftReset() ) m_nScheduledTaskID = ST_NO_TASK; - break; - case ST_TURN_OFF_LED: - LOG("SCHEDULED ST_TURN_OFF_LED"); - if( m_pProtocol->sendLED( false ) ) m_nScheduledTaskID = ST_NO_TASK; - break; - case ST_SEND_SETTINGS: - LOG("SCHEDULED ST_SEND_SETTINGS"); - if( m_pProtocol->sendSettings( - m_nDetectorSST, - m_nDetectorOffset, - m_fDetectorLayerDistance, - m_fDetectorMinSpeed - ) ) m_nScheduledTaskID = ST_NO_TASK; - m_nScheduledTaskCounter = 200; // 1 = 10 mlsec - m_nScheduledTaskID = ST_SEND_WMODE; - break; - case ST_SEND_WMODE: - if( m_pProtocol->sendMode( m_bDetectorArmed ) ) m_nScheduledTaskID = ST_NO_TASK; - break; - }; - }; - }; - SLEEP( SLEEP_KERNEL_INTERVAL ); - }; -}; - -void Kernel::pushFrame( cv::Mat *Frame, void *src ){ - if( src == NULL) { - return; - }; - if( m_nFrameCounter == 0 ) m_lStartTS = getMilliseconds(); - m_nFrameCounter++; - for( int index = 0; index < m_nVideoInputs; index++ ) { - if( src == m_pVideoInputs[index] ) { - Frame->copyTo((*m_pVideoFrame[index])); - m_nCLoopMask &= ~(1<lock(); - //rectangle( (*m_pFinalFrame), Point(0,0), Point(m_nWidth, m_nHeight), Scalar(0,0,0), CV_FILLED ); - for( int index = 0; index < m_nVideoInputs; index++ ){ - if(m_bHorizontal){ - m_pVideoFrame[index]->copyTo((*m_pFinalFrame)(cv::Rect(cx,cy, m_pVideoFrame[index]->cols, m_pVideoFrame[index]->rows ))); - cx+=m_pVideoFrame[index]->cols; - }else{ - m_pVideoFrame[index]->copyTo((*m_pFinalFrame)(cv::Rect(cx,cy, m_pVideoFrame[index]->cols, m_pVideoFrame[index]->rows ))); - cy+=m_pVideoFrame[index]->rows; - }; - }; - int X, W = 260; - X = ( m_pFinalFrame->cols - W ) >> 1; - //rectangle( (*m_pFinalFrame), Point( X, 10 ), Point( X+W, 25 ), Scalar( 0, 0, 0 ), CV_FILLED ); - rectangle( (*m_pFinalFrame), Point( 0, 0 ), Point( m_pFinalFrame->cols, 15 ), Scalar( 0, 0, 0 ), CV_FILLED ); - long long aMilliseconds = getMilliseconds(); - long long tMilliseconds; - float fps = 0.f; - - tMilliseconds = aMilliseconds - m_lStartTS; - if( tMilliseconds > 0 && m_nVideoInputs > 0 ){ - fps = ((float)( m_nFrameCounter / m_nVideoInputs ) * 1000.f ) / (float)tMilliseconds; - }; - - char DateStr[200]; - sprintf( DateStr, "TS:%010lu", tMilliseconds ); - putText( (*m_pFinalFrame), DateStr, Point( X, 12 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 0, 255, 255 ), 1 ); - sprintf( DateStr, "FID:%06lu", m_nFrameCounter ); - putText( (*m_pFinalFrame), DateStr, Point( X+110, 12 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 0, 255, 0 ), 1 ); - sprintf( DateStr, "FPS:%03.2f", fps ); - putText( (*m_pFinalFrame), DateStr, Point( X+190, 12 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 255, 0, 255 ), 1 ); -#ifdef AMIR_MODE - sprintf( DateStr, "Range:%d", m_nCurrentRange ); - putText( (*m_pFinalFrame), DateStr, Point( 10, 12 ), FONT_HERSHEY_SIMPLEX, .4, Scalar( 255, 255, 0 ), 1 ); -#endif - if( m_bRecordIsActive ){ - rectangle( (*m_pFinalFrame), Point( X+260, 3 ), Point( X+275, 12 ), Scalar( 0, 0, 255 ), CV_FILLED ); -#ifndef USE_TIME_LAPSE_RECORDER - if( m_nRecordCounter ) { - m_pFinalFrame->copyTo((*m_pVidRecFrame[--m_nRecordCounter])); - } else { - m_bRecordIsActive = false; - }; -#endif - } else { - rectangle( (*m_pFinalFrame), Point( X+260, 3 ), Point( X+275, 12 ), Scalar( 0, 255, 0 ), CV_FILLED ); -#ifndef USE_TIME_LAPSE_RECORDER - if( m_bRecordIsSaving == false ) { - cv::Mat * tMat; - if( m_rPrerecord.count >= MAX_RECORD_FRAMES ){ - tMat = m_rPrerecord.pop(); - delete( tMat ); - }; - tMat = new cv::Mat(); - *tMat = m_pFinalFrame->clone(); - m_rPrerecord.add( tMat ); - }; -#endif - }; -#ifdef USE_TIME_LAPSE_RECORDER - //if( m_bAssembleMP4 ) { - m_pVideoOutput->pushFrame( m_pFinalFrame ); - //}; -#endif - m_pMatProtector->unlock(); - // Assemble Final Frame; - m_nCLoopMask = 0xFFFFFFFF; - }; - }; -}; - -bool Kernel::copyFrame( cv::Mat &Frame ){ - if( m_pFinalFrame== NULL ) return false; - m_pMatProtector->lock(); - if( m_pFinalFrame== NULL ) return false; - m_pFinalFrame->copyTo(Frame); - m_pMatProtector->unlock(); - return true; -}; - - -//https://www.pointsinfocus.com/tools/depth-of-field-and-equivalent-lens-calculator/#{%22c%22:[{%22f%22:9,%22av%22:%222%22,%22fl%22:11,%22d%22:50000,%22cm%22:%220%22}],%22m%22:1} -bool Kernel::reset( bool FullRestart ){ - if( FullRestart ) { - //Shutting down Motors and Hardware - //Starting up Motors and Hardware - shutdown( true ); - } else { - // Reset Components - //m_pHardwareManager->reset( true ); - }; - return true; -}; - -bool Kernel::shutdown( bool Restart ){ - if( Restart ) { - putEvent2FS( FSL_SYSTEM_RESTARTED ); - LOG("Restarting the Kernel by SHUTDOWN!"); - m_bExitCause = 1; - } else { - putEvent2FS( FSL_SYSTEM_SHUTDOWN ); - LOG("Shutting down the Kernel by SHUTDOWN!"); - m_bExitCause = 0; - } - postStatus2FS( false ); - setStatus( TH_ENDED ); - return true; -}; - -void Kernel::updateStatus( bool ArmMode, uint8_t nCount, uint16_t *bgArray ){ - if( nCount > MAX_LRF_SENSORS ) return; - if( bgArray == NULL ) return; - m_bDetectorArmed = ArmMode; - LOG("updateStatus"); - for( uint8_t index = 0; index < nCount; index++ ) { - m_nLRF_Background[index] = bgArray[index]; -#ifdef DEBUG - char tBuff[16]; - sprintf( tBuff, "BG[%d]=%d", index, m_nLRF_Background[index] ); - LOG( tBuff ); -#endif - }; - postStatus2FS( true ); -}; - -void Kernel::updateSettings( uint16_t offset, uint16_t min_time, uint8_t sst, uint32_t ol_status, uint32_t ok_status ){ - LOG("updateSettings"); - m_nDetectorOffset = offset; - m_fDetectorMinSpeed = m_fDetectorLayerDistance * min_time * 0.000001f; - m_nDetectorSST = sst; - m_nCOnlineMask = ol_status; - m_nCOKMask = ok_status; -#ifdef DEBUG - char tBuff[128]; - sprintf( tBuff, "OS:%d MS:%.3f SST:%d OM: 0x%02H OK: 0x%02H", m_nDetectorOffset, m_fDetectorMinSpeed, m_nDetectorSST, m_nCOnlineMask, m_nCOKMask ); - LOG( tBuff ); -#endif - postStatus2FS( true ); -}; - -void Kernel::updateTarget( uint8_t LRF, uint8_t Range ){ -// In case handaling all targets at once - see handleTargets -#ifndef MULTI_TARGETS - char Buffer[1024]; - LOG("updateTarget"); - #ifdef NO_GPIO_HANDLER - alarm( true ); - #endif - m_bEventRegistered = true; - #ifdef USE_TIME_LAPSE_RECORDER - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - #else - #ifdef ASSEMBLE_MP4 - if( m_bAssembleMP4 ) { - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - } else { - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - }; - #else - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - #endif - #endif // USE_TIME_LAPSE_RECORDER - putEvent2FS( FSL_ALARM, LRF, Range, 0, 0, 0, true, Buffer ); - LOG("Done"); -#endif // MULTI_TARGETS -}; - -void Kernel::handleTargets( uint32_t tMask, uint8_t cnt, uint8_t *tRanges ){ - if( cnt == 0 ) return; - if( tRanges == NULL ) return; - if( m_bTargetOverflow ){ - m_bTargetOverflow --; - if( !m_bTargetOverflow ) { - if( m_pProtocol->sendMode( false ) ) { - putEvent2FS( FSL_TARGET_OVERFLOW ); - }; - }; - } else return; -#ifdef MULTI_TARGETS - char Buffer[1024]; - #ifdef DEBUG - LOG("handleTargets"); - #endif - #ifdef NO_GPIO_HANDLER - alarm( true ); - #endif - - #ifdef USE_TIME_LAPSE_RECORDER - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - #else - #ifdef ASSEMBLE_MP4 - if( m_bAssembleMP4 ) { - sprintf( Buffer, "%s_%02d.%s", m_sSeriesName, m_nAlarmCnt, VIDEO_OUTPUT_CONTAINER ); - } else { - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - }; - #else - sprintf( Buffer, "%s_%02d_%%03d.jpg", m_sSeriesName, m_nAlarmCnt ); - #endif - #endif // USE_TIME_LAPSE_RECORDER - switch( m_nConvertType ) { - case 0:{ - uint16_t x1, x2, sum; - float r1, r2; - x1 = tMask & 0x1FF; // 9 bit mask - x2 = ( tMask >> 9 ) & 0x1FF; - sum = 0; - for( uint8_t index = 0; index < cnt; index++ ) { - sum += tRanges[index]; - }; - if( cnt ) { - r1 = ( m_fDetectorMaxDistance /8.f ) * ( 1.f + ((float)sum) / ((float)cnt)); - } else r1 =0; - r2 = 0; - putEvent2FS( FSL_ALARM, x1, r1, x2, r2, 0, true, Buffer ); - break; - }; - case 1:{ - uint16_t x1, x2, sum; - float r1, r2; - x1 = tMask & 0x1FF; // 9 bit mask - x2 = ( tMask >> 9 ) & 0x1FF; - sum = 0; - for( uint8_t index = 0; index < cnt; index++ ) { - sum += tRanges[index]; - }; - if( cnt ) { - r1 = ( m_fDetectorMaxDistance * (float)sum) / (float)cnt; - } else r1 = 0; - r2 = 0; - putEvent2FS( FSL_ALARM, x1, r1, x2, r2, 0, true, Buffer ); - break; - }; - case 2:{ - uint16_t x1, x2, sum; - float r1, r2; - x1 = tMask & 0x1FF; // 9 bit mask - x2 = ( tMask >> 9 ) & 0x1FF; - sum = 0; - int idx = 0; - for( uint8_t index = 0; index < MAX_LRF_SENSORS; index++ ) { - if( tMask & ( 0x00000001 << index ) ) { - sum += ( m_fDetectorMaxDistance / m_nLRF_Background[index] ) * tRanges[idx]; - idx++; - }; - }; - if( cnt ) { - r1 = ((float)sum) / ((float)cnt); - } else r1 = 0; - r2 = 0; - putEvent2FS( FSL_ALARM, x1, r1, x2, r2, 0, true, Buffer ); - break; - }; - case 3:{ - uint16_t x1, x2, sum; - float r1, r2; - x1 = tMask & 0x1FF; // 9 bit mask - x2 = ( tMask >> 9 ) & 0x1FF; - sum = 0; - r1 = tRanges[0]; - r2 = 0; - putEvent2FS( FSL_ALARM, x1, r1, x2, r2, 0, true, Buffer ); - break; - }; - }; - m_bEventRegistered = true; - #ifdef DEBUG - LOG("Done"); - #endif -#endif // MULTI_TARGETS -}; - -#undef LOG -#undef LOG_ERROR diff --git a/lib/App/mastbaumSERVER/Kernel.h b/lib/App/mastbaumSERVER/Kernel.h deleted file mode 100644 index 1970db3f..00000000 --- a/lib/App/mastbaumSERVER/Kernel.h +++ /dev/null @@ -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__ diff --git a/lib/App/mastbaumSERVER/NetworkManager.cpp b/lib/App/mastbaumSERVER/NetworkManager.cpp deleted file mode 100644 index a8b41f59..00000000 --- a/lib/App/mastbaumSERVER/NetworkManager.cpp +++ /dev/null @@ -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; -}; diff --git a/lib/App/mastbaumSERVER/NetworkManager.h b/lib/App/mastbaumSERVER/NetworkManager.h deleted file mode 100644 index 8f8fc99b..00000000 --- a/lib/App/mastbaumSERVER/NetworkManager.h +++ /dev/null @@ -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__ \ No newline at end of file diff --git a/lib/App/mastbaumSERVER/Server.cpp b/lib/App/mastbaumSERVER/Server.cpp deleted file mode 100644 index e5e2e2e2..00000000 --- a/lib/App/mastbaumSERVER/Server.cpp +++ /dev/null @@ -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 - diff --git a/lib/App/mastbaumSERVER/Server.h b/lib/App/mastbaumSERVER/Server.h deleted file mode 100644 index ccfd0f6e..00000000 --- a/lib/App/mastbaumSERVER/Server.h +++ /dev/null @@ -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 -#include -#include -#include - -#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 diff --git a/lib/App/mastbaumSERVER/interProcessProto.cpp b/lib/App/mastbaumSERVER/interProcessProto.cpp deleted file mode 100644 index 15d45071..00000000 --- a/lib/App/mastbaumSERVER/interProcessProto.cpp +++ /dev/null @@ -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; -}; - - diff --git a/lib/App/mastbaumSERVER/interProcessProto.h b/lib/App/mastbaumSERVER/interProcessProto.h deleted file mode 100644 index c27dce28..00000000 --- a/lib/App/mastbaumSERVER/interProcessProto.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __INTER_PROCESS_PROTOCOL_HEADER__ -#define __INTER_PROCESS_PROTOCOL_HEADER__ - -//#define DUBUG_COMMUNICATION - -#include -#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 diff --git a/lib/App/videoAnal/main.cpp b/lib/App/videoAnal/main.cpp deleted file mode 100644 index 72fb5781..00000000 --- a/lib/App/videoAnal/main.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include -#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 -#include -#include -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; -} - -*/ - diff --git a/lib/App/videoAnal/main_window.cpp b/lib/App/videoAnal/main_window.cpp deleted file mode 100644 index eed948aa..00000000 --- a/lib/App/videoAnal/main_window.cpp +++ /dev/null @@ -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); - }; - }; -}; diff --git a/lib/App/videoAnal/main_window.h b/lib/App/videoAnal/main_window.h deleted file mode 100644 index 1caa08c6..00000000 --- a/lib/App/videoAnal/main_window.h +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef __QT5_MAIN_WINDOW_HEADER__ -#define __QT5_MAIN_WINDOW_HEADER__ - -#include -#include -#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 diff --git a/lib/defender-dc-trig/rgooseClassAccess.h b/lib/defender-dc-trig/rgooseClassAccess.h deleted file mode 100644 index 682f0e04..00000000 --- a/lib/defender-dc-trig/rgooseClassAccess.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/defender-dc-trig/rgooseDBConnector.cpp b/lib/defender-dc-trig/rgooseDBConnector.cpp deleted file mode 100644 index b7556c82..00000000 --- a/lib/defender-dc-trig/rgooseDBConnector.cpp +++ /dev/null @@ -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;isize();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;isize();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;isize();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 - diff --git a/lib/defender-dc-trig/rgooseDBConnector.h b/lib/defender-dc-trig/rgooseDBConnector.h deleted file mode 100644 index 478065c6..00000000 --- a/lib/defender-dc-trig/rgooseDBConnector.h +++ /dev/null @@ -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 DBC_INT_LIST; - - -typedef std::vector vectorCamRecords; -typedef std::vector 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 diff --git a/lib/defender-dc-trig/rgooseIPCamera.cpp b/lib/defender-dc-trig/rgooseIPCamera.cpp deleted file mode 100644 index c2443927..00000000 --- a/lib/defender-dc-trig/rgooseIPCamera.cpp +++ /dev/null @@ -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 diff --git a/lib/defender-dc-trig/rgooseIPCamera.h b/lib/defender-dc-trig/rgooseIPCamera.h deleted file mode 100644 index a1759e85..00000000 --- a/lib/defender-dc-trig/rgooseIPCamera.h +++ /dev/null @@ -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 -#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 vectorARGUS_Cameras; - -#endif diff --git a/lib/defender-dc-trig/rgooseNode.h b/lib/defender-dc-trig/rgooseNode.h deleted file mode 100644 index 34114edd..00000000 --- a/lib/defender-dc-trig/rgooseNode.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/defender-dc-trig/rgooseNodeFactory.cpp b/lib/defender-dc-trig/rgooseNodeFactory.cpp deleted file mode 100644 index 48783f9b..00000000 --- a/lib/defender-dc-trig/rgooseNodeFactory.cpp +++ /dev/null @@ -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 diff --git a/lib/defender-dc-trig/rgooseNodeFactory.h b/lib/defender-dc-trig/rgooseNodeFactory.h deleted file mode 100644 index 19421fdd..00000000 --- a/lib/defender-dc-trig/rgooseNodeFactory.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ARGUS_NODE_FACTORY_HEADER__ -#define __ARGUS_NODE_FACTORY_HEADER__ - -#include -#include "rgooseNode.h" -#include "rgooseIPCamera.h" - -typedef std::vector 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 \ No newline at end of file diff --git a/lib/defender-dc-trig/rgooseServerModule.cpp b/lib/defender-dc-trig/rgooseServerModule.cpp deleted file mode 100644 index 0a609232..00000000 --- a/lib/defender-dc-trig/rgooseServerModule.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "rgooseServerModule.h" -argusServerModule::argusServerModule(ARGUS_DBC * DBC):basicEventHandler(){ - m_pDBC = DBC; -}; -argusServerModule::~argusServerModule(){}; - diff --git a/lib/defender-dc-trig/rgooseServerModule.h b/lib/defender-dc-trig/rgooseServerModule.h deleted file mode 100644 index f55de2ff..00000000 --- a/lib/defender-dc-trig/rgooseServerModule.h +++ /dev/null @@ -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 diff --git a/lib/defender-dc-trig/rgooseStructures.h b/lib/defender-dc-trig/rgooseStructures.h deleted file mode 100644 index 466af5ca..00000000 --- a/lib/defender-dc-trig/rgooseStructures.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef __R_GOOSE_DATA_STRUCTURES_HEADER__ -#define __R_GOOSE_DATA_STRUCTURES_HEADER__ - -#incldue - -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 \ No newline at end of file diff --git a/lib/defender-dc-trig/rgooseUSBRelayModule.cpp b/lib/defender-dc-trig/rgooseUSBRelayModule.cpp deleted file mode 100644 index 3cc14695..00000000 --- a/lib/defender-dc-trig/rgooseUSBRelayModule.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#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 ){}; - diff --git a/lib/defender-dc-trig/rgooseUSBRelayModule.h b/lib/defender-dc-trig/rgooseUSBRelayModule.h deleted file mode 100644 index 6300ebfe..00000000 --- a/lib/defender-dc-trig/rgooseUSBRelayModule.h +++ /dev/null @@ -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 \ No newline at end of file diff --git a/lib/defender-dc-trig/rgooseVideoTranscoderModule.h b/lib/defender-dc-trig/rgooseVideoTranscoderModule.h deleted file mode 100644 index 6219ac63..00000000 --- a/lib/defender-dc-trig/rgooseVideoTranscoderModule.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __ARGUS_VIDEO_TRANSCODER_MODULE_HEADER__ -#define __ARGUS_VIDEO_TRANSCODER_MODULE_HEADER__ - -class argusVideoTranscoder{ - public: - argusVideoTranscoder(); -}; - -#endif