124 changed files with 39197 additions and 191 deletions
-
3.gitignore
-
1Linux_Workspace.vpw
-
2Projects/argus/argus.vpj
-
300Projects/argus/file12
-
16Projects/la_mojo/Debug/server.conf
-
9Projects/la_mojo/build
-
401Projects/la_mojo/la_mojo.vpj
-
468Projects/la_mojo/makefile
-
BINProjects/la_mojo/mem_db.db
-
BINProjects/la_mojo/mysqlitedb.db
-
4818lib/App/common/MySQL_dataBinder.cpp
-
198lib/App/common/MySQL_dataBinder.h
-
1305lib/App/common/SQLite_dataBinder.cpp
-
88lib/App/common/SQLite_dataBinder.h
-
3lib/App/common/dataBinder.cpp
-
177lib/App/common/dataBinder.h
-
645lib/App/common/dataBinder_structures.h
-
119lib/App/common/deviceNode.cpp
-
42lib/App/common/deviceNode.h
-
2157lib/App/common/deviceNode2D.cpp
-
148lib/App/common/deviceNode2D.h
-
1769lib/App/common/deviceNode3D.cpp
-
140lib/App/common/deviceNode3D.h
-
1432lib/App/common/deviceNodeCamera.cpp
-
202lib/App/common/deviceNodeCamera.h
-
703lib/App/common/deviceNodeEthernet2Serial.cpp
-
55lib/App/common/deviceNodeEthernet2Serial.h
-
611lib/App/common/deviceNodeFactory.cpp
-
36lib/App/common/deviceNodeFactory.h
-
194lib/App/common/deviceNodePTZCamControl.cpp
-
44lib/App/common/deviceNodePTZCamControl.h
-
656lib/App/common/deviceNodeSensor.cpp
-
106lib/App/common/deviceNodeSensor.h
-
170lib/App/common/deviceNodeStaticCamControl.cpp
-
44lib/App/common/deviceNodeStaticCamControl.h
-
1380lib/App/common/hardwareManager.cpp
-
56lib/App/common/hardwareManager.h
-
255lib/App/common/hardwareResource.cpp
-
67lib/App/common/hardwareResource.h
-
24lib/App/common/hardwareResourceDryContactProvider.cpp
-
11lib/App/common/hardwareResourceDryContactProvider.h
-
115lib/App/common/hardwareResourceNetworkProvider.cpp
-
19lib/App/common/hardwareResourceNetworkProvider.h
-
1140lib/App/common/hardwareResourceSerialProvider.cpp
-
77lib/App/common/hardwareResourceSerialProvider.h
-
48lib/App/common/hardwareResourceVideoProvider.cpp
-
15lib/App/common/hardwareResourceVideoProvider.h
-
27lib/App/common/kernelEventFilter.cpp
-
33lib/App/common/kernelEventFilter.h
-
226lib/App/common/kernelEventFilterAPF.cpp
-
41lib/App/common/kernelEventFilterAPF.h
-
38lib/App/common/kernelModule.cpp
-
58lib/App/common/kernelModule.h
-
2211lib/App/common/kernelModuleEmbedVideo.cpp
-
319lib/App/common/kernelModuleEmbedVideo.h
-
397lib/App/common/kernelModuleFactory.cpp
-
40lib/App/common/kernelModuleFactory.h
-
474lib/App/common/kernelModuleFlyHunter.cpp
-
73lib/App/common/kernelModuleFlyHunter.h
-
760lib/App/common/kernelModuleKafka.cpp
-
86lib/App/common/kernelModuleKafka.h
-
324lib/App/common/kernelModuleModemManager.cpp
-
24lib/App/common/kernelModuleModemManager.h
-
603lib/App/common/kernelModuleOnvifObserver.cpp
-
94lib/App/common/kernelModuleOnvifObserver.h
-
1041lib/App/common/kernelModuleSSDP.cpp
-
211lib/App/common/kernelModuleSSDP.h
-
317lib/App/common/kernelModuleUSBRelay.cpp
-
40lib/App/common/kernelModuleUSBRelay.h
-
96lib/App/common/kernelPrototype.cpp
-
63lib/App/common/kernelPrototype.h
-
476lib/App/mojo/mojoBackend.cpp
-
29lib/App/mojo/mojoBackend.h
-
264lib/App/mojo/mojoDBConnector.cpp
-
202lib/App/mojo/mojoDBConnector.h
-
916lib/App/mojo/mojoHardwareManager.cpp
-
163lib/App/mojo/mojoHardwareManager.h
-
390lib/App/mojo/mojoKernel.cpp
-
81lib/App/mojo/mojoKernel.h
-
28lib/App/mojo/rgooseModule.cpp
-
57lib/App/mojo/rgooseModule.h
-
1464lib/App/mojo/rgooseModuleEmbedVideo - Copy.cpp
-
225lib/App/mojo/rgooseModuleEmbedVideo - Copy.h
-
2208lib/App/mojo/rgooseModuleEmbedVideo.cpp
-
320lib/App/mojo/rgooseModuleEmbedVideo.h
-
386lib/App/mojo/rgooseModuleFactory.cpp
-
40lib/App/mojo/rgooseModuleFactory.h
-
474lib/App/mojo/rgooseModuleFlyHunter.cpp
-
73lib/App/mojo/rgooseModuleFlyHunter.h
-
760lib/App/mojo/rgooseModuleKafka.cpp
-
86lib/App/mojo/rgooseModuleKafka.h
-
323lib/App/mojo/rgooseModuleModemManager.cpp
-
24lib/App/mojo/rgooseModuleModemManager.h
-
602lib/App/mojo/rgooseModuleOnvifObserver.cpp
-
88lib/App/mojo/rgooseModuleOnvifObserver.h
-
46lib/App/mojo/rgooseModuleSSDP.cpp
-
23lib/App/mojo/rgooseModuleSSDP.h
-
317lib/App/mojo/rgooseModuleUSBRelay.cpp
-
40lib/App/mojo/rgooseModuleUSBRelay.h
-
188lib/alg/generic/heapDebug.cpp
300
Projects/argus/file12
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,16 @@ |
|||
GENERAL : |
|||
{ |
|||
SSDP_ENABLE = true; |
|||
DATABASE : |
|||
{ |
|||
DATA_FILE_NAME = "data/mysqlitedb.db"; |
|||
WEB_ACCESS_USER = "www-data"; |
|||
WEB_ACCESS_GROUP = "www-data"; |
|||
DATA_MEMORY_NAME = "mem_db.db"; |
|||
}; |
|||
KERNEL : |
|||
{ |
|||
IDENTITY = "f96cc595a9122000d9448cefde7289a4"; |
|||
SITE_ID = 1; |
|||
}; |
|||
}; |
|||
@ -0,0 +1,9 @@ |
|||
#! /bin/sh |
|||
|
|||
|
|||
make clean -e "CFG=Debug_MASTER" |
|||
make -e "CFG=Debug_MASTER" -j4 |
|||
|
|||
|
|||
#make clean -e "CFG=Debug_SLAVE" |
|||
#make -e "CFG=Debug_SLAVE" -j4 |
|||
@ -0,0 +1,401 @@ |
|||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd"> |
|||
<Project |
|||
Version="10.0" |
|||
VendorName="SlickEdit" |
|||
TemplateName="GNU C/C++" |
|||
WorkingDir="." |
|||
BuildSystem="automakefile" |
|||
BuildMakeFile="makefile" |
|||
VCSProject="Git:"> |
|||
<Config |
|||
Name="Debug" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdmojo_d" |
|||
CompilerConfigName="Latest Version" |
|||
Defines='"/DDEBUG" "/D__STDC_CONSTANT_MACROS" "/D_CLIENT_APPLICATION_" "/D_OPENCV_" "/DRASPI_HARDWARE"'> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec |
|||
CmdLine='g++ -c %xup -x c++ %defd -O0 -g1 -ggdb -w -Wpointer-arith %~other -o "%bd%n%oe" %i %f' |
|||
OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia -I/usr/local/include/BasicUsageEnvironment -I/usr/local/include/UsageEnvironment -I/usr/local/include/groupsock `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ %xup -O0 -g1 -ggdb -w -o "%o" %objs'/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes></Includes> |
|||
<Libs PreObjects="0"> |
|||
<Lib File="-lsqlite3"/> |
|||
<Lib File="-lpthread"/> |
|||
<Lib File="-lmysqlclient"/> |
|||
<Lib File="-lssl"/> |
|||
<Lib File="-lcurl"/> |
|||
<Lib File="-lm"/> |
|||
<Lib File="-lcrypto"/> |
|||
<Lib File="-lconfig"/> |
|||
<Lib File="-lz"/> |
|||
<Lib File="-lv4l1"/> |
|||
<Lib File="-lv4l2"/> |
|||
<Lib File="-lhidapi-libusb"/> |
|||
<Lib File="`pkg-config"/> |
|||
<Lib File="libavcodec"/> |
|||
<Lib File="libavdevice"/> |
|||
<Lib File="libavfilter"/> |
|||
<Lib File="libavformat"/> |
|||
<Lib File="libavutil"/> |
|||
<Lib File="libpostproc"/> |
|||
<Lib File="libswresample"/> |
|||
<Lib File="libswscale"/> |
|||
<Lib File="--libs`"/> |
|||
<Lib File="-latomic"/> |
|||
<Lib File="`pkg-config"/> |
|||
<Lib File="--libs"/> |
|||
<Lib File="openssl"/> |
|||
<Lib File="opencv4"/> |
|||
<Lib File="rdkafka++`"/> |
|||
<Lib File="-lwiringPi"/> |
|||
<Lib File="-lliveMedia"/> |
|||
<Lib File="-lgroupsock"/> |
|||
<Lib File="-lBasicUsageEnvironment"/> |
|||
<Lib File="-lUsageEnvironment"/> |
|||
</Libs> |
|||
</Config> |
|||
<Config |
|||
Name="Release" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdmojo" |
|||
CompilerConfigName="Latest Version" |
|||
Defines='"/DSLIM_KERNEL" "/D_THREAD_SAFE" "/D_BSD_SOURCE" "/D_REENTRANT"'> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec |
|||
CmdLine='g++ -c %xup -x c++ %defd -O3 -w -Wpointer-arith %~other -o "%bd%n%oe" %i %f' |
|||
OtherOptions="-std=gnu++11 -I../../lib/include"/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec |
|||
CmdLine='g++ %xup -O3 -w %~other -o "%o" %objs' |
|||
OtherOptions="-lconfig -lpthread -lelf -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -lsqlite3 -s"/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes></Includes> |
|||
<Libs PreObjects="0"/> |
|||
</Config> |
|||
<Files> |
|||
<Folder |
|||
Name="Source Files" |
|||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d" |
|||
GUID="{502FD7D9-3DD6-4F47-A8F2-7805FC79B3AA}"> |
|||
<F N="../../lib/alg/generic/base64.cpp"/> |
|||
<F N="../../lib/components/base/basicCameraInfo.cpp"/> |
|||
<F N="../../lib/components/base/basicDualThread.cpp"/> |
|||
<F N="../../lib/components/base/basicEngine.cpp"/> |
|||
<F N="../../lib/components/base/basicEvent.cpp"/> |
|||
<F N="../../lib/components/base/basicEventHandler.cpp"/> |
|||
<F N="../../lib/components/base/basicEventHeap.cpp"/> |
|||
<F N="../../lib/components/base/basicFunctionality.cpp"/> |
|||
<F N="../../lib/components/base/basicLIBAV.cpp"/> |
|||
<F N="../../lib/components/base/basicLogCollection.cpp"/> |
|||
<F N="../../lib/components/base/basicLoggingService.cpp"/> |
|||
<F N="../../lib/components/base/basicMemoryOperation.cpp"/> |
|||
<F N="../../lib/components/base/basicObject.cpp"/> |
|||
<F N="../../lib/components/base/basicPosition.cpp"/> |
|||
<F N="../../lib/components/base/basicRing.cpp"/> |
|||
<F N="../../lib/components/base/basicSettings.cpp"/> |
|||
<F N="../../lib/components/base/basicSettingsProvider.cpp"/> |
|||
<F N="../../lib/components/base/basicThread.cpp"/> |
|||
<F N="../../lib/components/base/basicTransport.cpp"/> |
|||
<F N="../../lib/data/net/clientPort.cpp"/> |
|||
<F N="../../lib/data/curl/curlRequest.cpp"/> |
|||
<F N="../../lib/data/curl/curlRequestsManager.cpp"/> |
|||
<F N="../../lib/App/common/dataBinder.cpp"/> |
|||
<F N="../../lib/alg/lgs/detector.cpp"/> |
|||
<F N="../../lib/App/common/deviceNode.cpp"/> |
|||
<F N="../../lib/App/common/deviceNode2D.cpp"/> |
|||
<F N="../../lib/App/common/deviceNode3D.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodeCamera.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodeEthernet2Serial.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodeFactory.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodePTZCamControl.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodeSensor.cpp"/> |
|||
<F N="../../lib/App/common/deviceNodeStaticCamControl.cpp"/> |
|||
<F N="../../lib/App/common/hardwareManager.cpp"/> |
|||
<F N="../../lib/App/common/hardwareResource.cpp"/> |
|||
<F N="../../lib/App/common/hardwareResourceDryContactProvider.cpp"/> |
|||
<F N="../../lib/App/common/hardwareResourceNetworkProvider.cpp"/> |
|||
<F N="../../lib/App/common/hardwareResourceSerialProvider.cpp"/> |
|||
<F N="../../lib/App/common/hardwareResourceVideoProvider.cpp"/> |
|||
<F N="../../lib/alg/generic/heapDebug.cpp"/> |
|||
<F N="../../lib/hardware/hid/hid_dc.cpp"/> |
|||
<F N="../../lib/data/json/json_reader.cpp"/> |
|||
<F N="../../lib/data/json/json_value.cpp"/> |
|||
<F N="../../lib/data/json/json_writer.cpp"/> |
|||
<F N="../../lib/App/common/kernelEventFilter.cpp"/> |
|||
<F N="../../lib/App/common/kernelEventFilterAPF.cpp"/> |
|||
<F N="../../lib/App/common/kernelModule.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleEmbedVideo.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleFactory.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleFlyHunter.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleKafka.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleModemManager.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleOnvifObserver.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleSSDP.cpp"/> |
|||
<F N="../../lib/App/common/kernelModuleUSBRelay.cpp"/> |
|||
<F N="../../lib/App/common/kernelPrototype.cpp"/> |
|||
<F N="../../lib/alg/generic/libzip.cpp"/> |
|||
<F N="../../lib/alg/lgs/mask.cpp"/> |
|||
<F N="../../lib/alg/generic/md5.cpp"/> |
|||
<F N="../../lib/App/mojo/mojoBackend.cpp"/> |
|||
<F N="../../lib/App/mojo/mojoKernel.cpp"/> |
|||
<F N="../../lib/data/mysql/mysql_class.cpp"/> |
|||
<F N="../../lib/App/common/MySQL_dataBinder.cpp"/> |
|||
<F N="../../lib/data/net/netClientHandler.cpp"/> |
|||
<F N="../../lib/data/net/netServer.cpp"/> |
|||
<F N="../../lib/components/object/objectFileLoggingService.cpp"/> |
|||
<F N="../../lib/components/object/objectSystemAnchor.cpp"/> |
|||
<F N="../../lib/data/ponvif/ponvif.cpp"/> |
|||
<F N="../../lib/data/protocol/protocol.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolHTTP.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolKAFKA.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolLGS2D.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolLGS3D.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolLGS3D_client.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolONVIF.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolPTZ.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolPTZ_ONVIF.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolPTZ_PELCO.cpp"/> |
|||
<F N="../../lib/data/protocol/protocolPTZ_VISCA.cpp"/> |
|||
<F N="../../lib/data/net/serverPort.cpp"/> |
|||
<F N="../../lib/data/sqlite/sqlite_class.cpp"/> |
|||
<F N="../../lib/App/common/SQLite_dataBinder.cpp"/> |
|||
<F N="../../lib/alg/generic/Transform.cpp"/> |
|||
<F N="../../lib/data/transport/transportSerial.cpp"/> |
|||
<F N="../../lib/data/transport/transportSocket.cpp"/> |
|||
<F N="../../lib/alg/generic/utm.cpp"/> |
|||
<F N="../../lib/data/media/video/videoAVLIBSource.cpp"/> |
|||
<F N="../../lib/data/media/video/videoLive555AVLibSource.cpp"/> |
|||
<F N="../../lib/data/protocol/xmlParser.cpp"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Header Files" |
|||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if" |
|||
GUID="{AC1A2E44-6BBF-481F-81E4-5466FA3801D3}"> |
|||
<F N="../../lib/components/base/basicDualThread.h"/> |
|||
<F N="../../lib/components/base/basicEngine.h"/> |
|||
<F N="../../lib/components/base/basicEvent.h"/> |
|||
<F N="../../lib/components/base/basicEventHandler.h"/> |
|||
<F N="../../lib/components/base/basicEventHeap.h"/> |
|||
<F N="../../lib/components/base/basicFunctionality.h"/> |
|||
<F N="../../lib/components/base/basicLogCollection.h"/> |
|||
<F N="../../lib/components/base/basicLoggingService.h"/> |
|||
<F N="../../lib/components/base/basicMemoryOperation.h"/> |
|||
<F N="../../lib/components/base/basicObject.h"/> |
|||
<F N="../../lib/components/base/basicSettings.h"/> |
|||
<F N="../../lib/components/base/basicSettingsProvider.h"/> |
|||
<F N="../../lib/components/base/basicThread.h"/> |
|||
<F N="../../lib/components/base/basicTypes.h"/> |
|||
<F N="../../lib/hardware/soc/classSOC.h"/> |
|||
<F N="../../lib/data/net/clientPort.h"/> |
|||
<F N="../../lib/App/common/dataBinder.h"/> |
|||
<F N="../../lib/alg/lgs/detector.h"/> |
|||
<F N="../../lib/alg/lgs/detectorStructures.h"/> |
|||
<F N="../../lib/alg/generic/heapDebug.h"/> |
|||
<F N="../../lib/LgsLib.h"/> |
|||
<F N="../../lib/alg/lgs/mask.h"/> |
|||
<F N="../../lib/App/mojo/mojoBackend.h"/> |
|||
<F N="../../lib/App/mojo/mojoDBConnector.h"/> |
|||
<F N="../../lib/App/mojo/mojoHardwareManager.h"/> |
|||
<F N="../../lib/App/mojo/mojoKernel.h"/> |
|||
<F N="../../lib/data/net/netClientHandler.h"/> |
|||
<F N="../../lib/data/net/netServer.h"/> |
|||
<F N="../../lib/components/object/objectFileLoggingService.h"/> |
|||
<F N="../../lib/data/protocol/protocolInternalLRF3D.h"/> |
|||
<F N="../../lib/data/protocol/protocolTGZ.h"/> |
|||
<F N="../../lib/hardware/soc/modules/pru/pru_ss.h"/> |
|||
<F N="../../lib/hardware/soc/modules/pwmss/pwm_ss.h"/> |
|||
<F N="../../lib/data/net/serverPort.h"/> |
|||
<F N="../../lib/data/sqlite/sqlite_class.h"/> |
|||
<F N="../../lib/data/ssdp/ssdpAnnouncer.h"/> |
|||
<F N="../../lib/data/transport/transportSerial.h"/> |
|||
<F N="../../lib/data/transport/transportSocket.h"/> |
|||
<F N="../../lib/hardware/soc/modules/pru/tupus_ext.h"/> |
|||
<F N="../../lib/data/net/xmlParser.h"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Resource Files" |
|||
Filters="*.ico;*.cur;*.dlg" |
|||
GUID="{8BD78378-5860-4905-AF1A-33114B24439C}"/> |
|||
<Folder |
|||
Name="Bitmaps" |
|||
Filters="*.bmp" |
|||
GUID="{6D406F40-545E-41FC-BD64-2DB7171E51C3}"/> |
|||
<Folder |
|||
Name="Other Files" |
|||
Filters="" |
|||
GUID="{26D67376-8D5A-4FD5-8D31-C3A5719A77AA}"> |
|||
<F |
|||
N="makefile" |
|||
Type="Makefile"/> |
|||
</Folder> |
|||
</Files> |
|||
<List Name="RTE"> |
|||
</List> |
|||
</Project> |
|||
@ -0,0 +1,468 @@ |
|||
# SlickEdit generated file. Do not edit this file except in designated areas.
|
|||
|
|||
# Make command to use for dependencies
|
|||
MAKE=make |
|||
RM=rm |
|||
MKDIR=mkdir |
|||
|
|||
# -----Begin user-editable area-----
|
|||
|
|||
# -----End user-editable area-----
|
|||
|
|||
# If no configuration is specified, "Debug" will be used
|
|||
ifndef CFG |
|||
CFG=Debug |
|||
endif |
|||
|
|||
#
|
|||
# Configuration: Debug
|
|||
#
|
|||
ifeq "$(CFG)" "Debug" |
|||
OUTDIR=Debug |
|||
OUTFILE=$(OUTDIR)/mojo_d |
|||
CFG_INC= |
|||
CFG_LIB=-lsqlite3 -lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto \
|
|||
-lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec \
|
|||
libavdevice libavfilter libavformat libavutil libpostproc \
|
|||
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
|
|||
opencv4 rdkafka++` -lwiringPi -lliveMedia -lgroupsock \
|
|||
-lBasicUsageEnvironment -lUsageEnvironment |
|||
CFG_OBJ= |
|||
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
|
|||
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
|
|||
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \
|
|||
$(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
|
|||
$(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
|
|||
$(OUTDIR)/dataBinder.o $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o \
|
|||
$(OUTDIR)/deviceNode2D.o $(OUTDIR)/deviceNode3D.o \
|
|||
$(OUTDIR)/deviceNodeCamera.o $(OUTDIR)/deviceNodeEthernet2Serial.o \
|
|||
$(OUTDIR)/deviceNodeFactory.o $(OUTDIR)/deviceNodePTZCamControl.o \
|
|||
$(OUTDIR)/deviceNodeSensor.o $(OUTDIR)/deviceNodeStaticCamControl.o \
|
|||
$(OUTDIR)/hardwareManager.o $(OUTDIR)/hardwareResource.o \
|
|||
$(OUTDIR)/hardwareResourceDryContactProvider.o \
|
|||
$(OUTDIR)/hardwareResourceNetworkProvider.o \
|
|||
$(OUTDIR)/hardwareResourceSerialProvider.o \
|
|||
$(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \
|
|||
$(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \
|
|||
$(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \
|
|||
$(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \
|
|||
$(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \
|
|||
$(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \
|
|||
$(OUTDIR)/kernelModuleModemManager.o \
|
|||
$(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \
|
|||
$(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \
|
|||
$(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \
|
|||
$(OUTDIR)/mysql_class.o $(OUTDIR)/MySQL_dataBinder.o \
|
|||
$(OUTDIR)/netClientHandler.o $(OUTDIR)/netServer.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
|
|||
$(OUTDIR)/ponvif.o $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o \
|
|||
$(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS2D.o \
|
|||
$(OUTDIR)/protocolLGS3D.o $(OUTDIR)/protocolLGS3D_client.o \
|
|||
$(OUTDIR)/protocolONVIF.o $(OUTDIR)/protocolPTZ.o \
|
|||
$(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \
|
|||
$(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \
|
|||
$(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \
|
|||
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
|
|||
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \
|
|||
$(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \
|
|||
$(OUTDIR)/xmlParser.o |
|||
OBJ=$(COMMON_OBJ) $(CFG_OBJ) |
|||
ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
|
|||
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
|
|||
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \
|
|||
$(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
|
|||
$(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
|
|||
$(OUTDIR)/dataBinder.o $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o \
|
|||
$(OUTDIR)/deviceNode2D.o $(OUTDIR)/deviceNode3D.o \
|
|||
$(OUTDIR)/deviceNodeCamera.o $(OUTDIR)/deviceNodeEthernet2Serial.o \
|
|||
$(OUTDIR)/deviceNodeFactory.o $(OUTDIR)/deviceNodePTZCamControl.o \
|
|||
$(OUTDIR)/deviceNodeSensor.o $(OUTDIR)/deviceNodeStaticCamControl.o \
|
|||
$(OUTDIR)/hardwareManager.o $(OUTDIR)/hardwareResource.o \
|
|||
$(OUTDIR)/hardwareResourceDryContactProvider.o \
|
|||
$(OUTDIR)/hardwareResourceNetworkProvider.o \
|
|||
$(OUTDIR)/hardwareResourceSerialProvider.o \
|
|||
$(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \
|
|||
$(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \
|
|||
$(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \
|
|||
$(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \
|
|||
$(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \
|
|||
$(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \
|
|||
$(OUTDIR)/kernelModuleModemManager.o \
|
|||
$(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \
|
|||
$(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \
|
|||
$(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \
|
|||
$(OUTDIR)/mysql_class.o $(OUTDIR)/MySQL_dataBinder.o \
|
|||
$(OUTDIR)/netClientHandler.o $(OUTDIR)/netServer.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
|
|||
$(OUTDIR)/ponvif.o $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o \
|
|||
$(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS2D.o \
|
|||
$(OUTDIR)/protocolLGS3D.o $(OUTDIR)/protocolLGS3D_client.o \
|
|||
$(OUTDIR)/protocolONVIF.o $(OUTDIR)/protocolPTZ.o \
|
|||
$(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \
|
|||
$(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \
|
|||
$(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \
|
|||
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
|
|||
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \
|
|||
$(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \
|
|||
$(OUTDIR)/xmlParser.o -lsqlite3 -lpthread -lmysqlclient -lssl -lcurl \
|
|||
-lm -lcrypto -lconfig -lz -lv4l1 -lv4l2 -lhidapi-libusb `pkg-config \
|
|||
libavcodec libavdevice libavfilter libavformat libavutil libpostproc \
|
|||
libswresample libswscale --libs` -latomic `pkg-config --libs openssl \
|
|||
opencv4 rdkafka++` -lwiringPi -lliveMedia -lgroupsock \
|
|||
-lBasicUsageEnvironment -lUsageEnvironment |
|||
|
|||
COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" "-D_CLIENT_APPLICATION_" "-D_OPENCV_" "-DRASPI_HARDWARE" -O0 -g1 -ggdb -w -Wpointer-arith -std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia -I/usr/local/include/BasicUsageEnvironment -I/usr/local/include/UsageEnvironment -I/usr/local/include/groupsock `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags` -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< |
|||
LINK=g++ -O0 -g1 -ggdb -w -o "$(OUTFILE)" $(ALL_OBJ) |
|||
|
|||
# Pattern rules
|
|||
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/App/common/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp |
|||
$(COMPILE) |
|||
|
|||
# Build rules
|
|||
all: $(OUTFILE) |
|||
|
|||
$(OUTFILE): $(OUTDIR) $(OBJ) |
|||
$(LINK) |
|||
|
|||
$(OUTDIR): |
|||
$(MKDIR) -p "$(OUTDIR)" |
|||
|
|||
# Rebuild this project
|
|||
rebuild: cleanall |
|||
@$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all |
|||
|
|||
# Clean this project
|
|||
clean: |
|||
$(RM) -f $(OUTFILE) |
|||
$(RM) -f $(OBJ) |
|||
|
|||
# Clean this project and all dependencies
|
|||
cleanall: clean |
|||
endif |
|||
|
|||
#
|
|||
# Configuration: Release
|
|||
#
|
|||
ifeq "$(CFG)" "Release" |
|||
OUTDIR=Release |
|||
OUTFILE=$(OUTDIR)/mojo |
|||
CFG_INC= |
|||
CFG_LIB= |
|||
CFG_OBJ= |
|||
COMMON_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
|
|||
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
|
|||
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \
|
|||
$(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
|
|||
$(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
|
|||
$(OUTDIR)/dataBinder.o $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o \
|
|||
$(OUTDIR)/deviceNode2D.o $(OUTDIR)/deviceNode3D.o \
|
|||
$(OUTDIR)/deviceNodeCamera.o $(OUTDIR)/deviceNodeEthernet2Serial.o \
|
|||
$(OUTDIR)/deviceNodeFactory.o $(OUTDIR)/deviceNodePTZCamControl.o \
|
|||
$(OUTDIR)/deviceNodeSensor.o $(OUTDIR)/deviceNodeStaticCamControl.o \
|
|||
$(OUTDIR)/hardwareManager.o $(OUTDIR)/hardwareResource.o \
|
|||
$(OUTDIR)/hardwareResourceDryContactProvider.o \
|
|||
$(OUTDIR)/hardwareResourceNetworkProvider.o \
|
|||
$(OUTDIR)/hardwareResourceSerialProvider.o \
|
|||
$(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \
|
|||
$(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \
|
|||
$(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \
|
|||
$(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \
|
|||
$(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \
|
|||
$(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \
|
|||
$(OUTDIR)/kernelModuleModemManager.o \
|
|||
$(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \
|
|||
$(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \
|
|||
$(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \
|
|||
$(OUTDIR)/mysql_class.o $(OUTDIR)/MySQL_dataBinder.o \
|
|||
$(OUTDIR)/netClientHandler.o $(OUTDIR)/netServer.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
|
|||
$(OUTDIR)/ponvif.o $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o \
|
|||
$(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS2D.o \
|
|||
$(OUTDIR)/protocolLGS3D.o $(OUTDIR)/protocolLGS3D_client.o \
|
|||
$(OUTDIR)/protocolONVIF.o $(OUTDIR)/protocolPTZ.o \
|
|||
$(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \
|
|||
$(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \
|
|||
$(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \
|
|||
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
|
|||
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \
|
|||
$(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \
|
|||
$(OUTDIR)/xmlParser.o |
|||
OBJ=$(COMMON_OBJ) $(CFG_OBJ) |
|||
ALL_OBJ=$(OUTDIR)/base64.o $(OUTDIR)/basicCameraInfo.o \
|
|||
$(OUTDIR)/basicDualThread.o $(OUTDIR)/basicEngine.o \
|
|||
$(OUTDIR)/basicEvent.o $(OUTDIR)/basicEventHandler.o \
|
|||
$(OUTDIR)/basicEventHeap.o $(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLIBAV.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicObject.o $(OUTDIR)/basicPosition.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/basicTransport.o $(OUTDIR)/clientPort.o \
|
|||
$(OUTDIR)/curlRequest.o $(OUTDIR)/curlRequestsManager.o \
|
|||
$(OUTDIR)/dataBinder.o $(OUTDIR)/detector.o $(OUTDIR)/deviceNode.o \
|
|||
$(OUTDIR)/deviceNode2D.o $(OUTDIR)/deviceNode3D.o \
|
|||
$(OUTDIR)/deviceNodeCamera.o $(OUTDIR)/deviceNodeEthernet2Serial.o \
|
|||
$(OUTDIR)/deviceNodeFactory.o $(OUTDIR)/deviceNodePTZCamControl.o \
|
|||
$(OUTDIR)/deviceNodeSensor.o $(OUTDIR)/deviceNodeStaticCamControl.o \
|
|||
$(OUTDIR)/hardwareManager.o $(OUTDIR)/hardwareResource.o \
|
|||
$(OUTDIR)/hardwareResourceDryContactProvider.o \
|
|||
$(OUTDIR)/hardwareResourceNetworkProvider.o \
|
|||
$(OUTDIR)/hardwareResourceSerialProvider.o \
|
|||
$(OUTDIR)/hardwareResourceVideoProvider.o $(OUTDIR)/heapDebug.o \
|
|||
$(OUTDIR)/hid_dc.o $(OUTDIR)/json_reader.o $(OUTDIR)/json_value.o \
|
|||
$(OUTDIR)/json_writer.o $(OUTDIR)/kernelEventFilter.o \
|
|||
$(OUTDIR)/kernelEventFilterAPF.o $(OUTDIR)/kernelModule.o \
|
|||
$(OUTDIR)/kernelModuleEmbedVideo.o $(OUTDIR)/kernelModuleFactory.o \
|
|||
$(OUTDIR)/kernelModuleFlyHunter.o $(OUTDIR)/kernelModuleKafka.o \
|
|||
$(OUTDIR)/kernelModuleModemManager.o \
|
|||
$(OUTDIR)/kernelModuleOnvifObserver.o $(OUTDIR)/kernelModuleSSDP.o \
|
|||
$(OUTDIR)/kernelModuleUSBRelay.o $(OUTDIR)/kernelPrototype.o \
|
|||
$(OUTDIR)/libzip.o $(OUTDIR)/mask.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/mojoBackend.o $(OUTDIR)/mojoKernel.o \
|
|||
$(OUTDIR)/mysql_class.o $(OUTDIR)/MySQL_dataBinder.o \
|
|||
$(OUTDIR)/netClientHandler.o $(OUTDIR)/netServer.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
|
|||
$(OUTDIR)/ponvif.o $(OUTDIR)/protocol.o $(OUTDIR)/protocolHTTP.o \
|
|||
$(OUTDIR)/protocolKAFKA.o $(OUTDIR)/protocolLGS2D.o \
|
|||
$(OUTDIR)/protocolLGS3D.o $(OUTDIR)/protocolLGS3D_client.o \
|
|||
$(OUTDIR)/protocolONVIF.o $(OUTDIR)/protocolPTZ.o \
|
|||
$(OUTDIR)/protocolPTZ_ONVIF.o $(OUTDIR)/protocolPTZ_PELCO.o \
|
|||
$(OUTDIR)/protocolPTZ_VISCA.o $(OUTDIR)/serverPort.o \
|
|||
$(OUTDIR)/sqlite_class.o $(OUTDIR)/SQLite_dataBinder.o \
|
|||
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
|
|||
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o \
|
|||
$(OUTDIR)/videoAVLIBSource.o $(OUTDIR)/videoLive555AVLibSource.o \
|
|||
$(OUTDIR)/xmlParser.o |
|||
|
|||
COMPILE=g++ -c -x c++ "-DSLIM_KERNEL" "-D_THREAD_SAFE" "-D_BSD_SOURCE" "-D_REENTRANT" -O3 -w -Wpointer-arith -std=gnu++11 -I../../lib/include -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< |
|||
LINK=g++ -O3 -w -lconfig -lpthread -lelf -lcurses -lcdk -lcurl `pkg-config --libs rdkafka++` -lsqlite3 -s -o "$(OUTFILE)" $(ALL_OBJ) |
|||
|
|||
# Pattern rules
|
|||
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/json/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/protocol/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/App/mojo/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/App/common/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/net/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/media/video/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/hardware/hid/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/mysql/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/curl/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/sqlite/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/data/ponvif/%.cpp |
|||
$(COMPILE) |
|||
|
|||
# Build rules
|
|||
all: $(OUTFILE) |
|||
|
|||
$(OUTFILE): $(OUTDIR) $(OBJ) |
|||
$(LINK) |
|||
|
|||
$(OUTDIR): |
|||
$(MKDIR) -p "$(OUTDIR)" |
|||
|
|||
# Rebuild this project
|
|||
rebuild: cleanall |
|||
@$(MAKE) -f "$(strip $(MAKEFILE_LIST))" $(MAKEFLAGS) all |
|||
|
|||
# Clean this project
|
|||
clean: |
|||
$(RM) -f $(OUTFILE) |
|||
$(RM) -f $(OBJ) |
|||
|
|||
# Clean this project and all dependencies
|
|||
cleanall: clean |
|||
endif |
|||
|
|||
#
|
|||
# include dependencies:
|
|||
#
|
|||
$(OUTDIR)/base64.o: ../../lib/alg/generic/base64.cpp ../../lib/alg/generic/base64.h |
|||
$(OUTDIR)/basicCameraInfo.o: ../../lib/components/base/basicCameraInfo.cpp ../../lib/components/base/basicCameraInfo.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/basicDualThread.o: ../../lib/components/base/basicDualThread.cpp ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/basicEngine.o: ../../lib/components/base/basicEngine.cpp ../../lib/components/base/basicEngine.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/basicEvent.o: ../../lib/components/base/basicEvent.cpp ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h |
|||
$(OUTDIR)/basicEventHandler.o: ../../lib/components/base/basicEventHandler.cpp ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h |
|||
$(OUTDIR)/basicEventHeap.o: ../../lib/components/base/basicEventHeap.cpp ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h |
|||
$(OUTDIR)/basicFunctionality.o: ../../lib/components/base/basicFunctionality.cpp ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/alg/generic/md5.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/basicLIBAV.o: ../../lib/components/base/basicLIBAV.cpp ../../lib/components/base/basicLIBAV.h |
|||
$(OUTDIR)/basicLogCollection.o: ../../lib/components/base/basicLogCollection.cpp ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/alg/generic/heapDebug.h |
|||
$(OUTDIR)/basicLoggingService.o: ../../lib/components/base/basicLoggingService.cpp ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h |
|||
$(OUTDIR)/basicMemoryOperation.o: ../../lib/components/base/basicMemoryOperation.cpp ../../lib/components/base/basicMemoryOperation.h |
|||
$(OUTDIR)/basicObject.o: ../../lib/components/base/basicObject.cpp ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/generic/md5.h |
|||
$(OUTDIR)/basicPosition.o: ../../lib/components/base/basicPosition.cpp ../../lib/components/base/basicPosition.h |
|||
$(OUTDIR)/basicRing.o: ../../lib/components/base/basicRing.cpp ../../lib/components/base/basicRing.h |
|||
$(OUTDIR)/basicSettings.o: ../../lib/components/base/basicSettings.cpp ../../lib/components/base/basicSettings.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h |
|||
$(OUTDIR)/basicSettingsProvider.o: ../../lib/components/base/basicSettingsProvider.cpp ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h |
|||
$(OUTDIR)/basicThread.o: ../../lib/components/base/basicThread.cpp ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/basicTransport.o: ../../lib/components/base/basicTransport.cpp ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h |
|||
$(OUTDIR)/clientPort.o: ../../lib/data/net/clientPort.cpp ../../lib/data/net/clientPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h |
|||
$(OUTDIR)/curlRequest.o: ../../lib/data/curl/curlRequest.cpp ../../lib/data/curl/curlRequest.h |
|||
$(OUTDIR)/curlRequestsManager.o: ../../lib/data/curl/curlRequestsManager.cpp ../../lib/data/curl/curlRequestsManager.h |
|||
$(OUTDIR)/dataBinder.o: ../../lib/App/common/dataBinder.cpp ../../lib/App/common/dataBinder.h ../../lib/App/common/dataBinder_structures.h |
|||
$(OUTDIR)/detector.o: ../../lib/alg/lgs/detector.cpp ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h |
|||
$(OUTDIR)/deviceNode.o: ../../lib/App/common/deviceNode.cpp ../../lib/App/common/deviceNode.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/deviceNode2D.o: ../../lib/App/common/deviceNode2D.cpp ../../lib/App/common/deviceNode2D.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/hardwareManager.h |
|||
$(OUTDIR)/deviceNode3D.o: ../../lib/App/common/deviceNode3D.cpp ../../lib/App/common/deviceNode3D.h |
|||
$(OUTDIR)/deviceNodeCamera.o: ../../lib/App/common/deviceNodeCamera.cpp ../../lib/App/common/deviceNodeCamera.h ../../lib/components/base/basicCameraInfo.h ../../lib/components/object/objectSystemAnchor.h ../../lib/hardware/uart/serialPort.h ../../lib/hardware/uart/serialSOL.h ../../lib/data/protocol/protocolPTZ_VISCA.h ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/data/protocol/protocolPTZ_PELCO.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceSerialProvider.h |
|||
$(OUTDIR)/deviceNodeEthernet2Serial.o: ../../lib/App/common/deviceNodeEthernet2Serial.cpp ../../lib/App/common/deviceNodeEthernet2Serial.h ../../lib/App/common/hardwareManager.h ../../lib/data/protocol/protocol.h |
|||
$(OUTDIR)/deviceNodeFactory.o: ../../lib/App/common/deviceNodeFactory.cpp ../../lib/App/common/deviceNodeFactory.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/deviceNode3D.h ../../lib/App/common/deviceNode2D.h ../../lib/App/common/deviceNodePTZCamControl.h ../../lib/App/common/deviceNodeStaticCamControl.h ../../lib/App/common/deviceNodeEthernet2Serial.h |
|||
$(OUTDIR)/deviceNodePTZCamControl.o: ../../lib/App/common/deviceNodePTZCamControl.cpp ../../lib/App/common/deviceNodePTZCamControl.h |
|||
$(OUTDIR)/deviceNodeSensor.o: ../../lib/App/common/deviceNodeSensor.cpp ../../lib/App/common/deviceNodeSensor.h ../../lib/components/object/objectSystemAnchor.h |
|||
$(OUTDIR)/deviceNodeStaticCamControl.o: ../../lib/App/common/deviceNodeStaticCamControl.cpp ../../lib/App/common/deviceNodeStaticCamControl.h |
|||
$(OUTDIR)/hardwareManager.o: ../../lib/App/common/hardwareManager.cpp ../../lib/App/common/hardwareManager.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h ../../lib/App/common/hardwareResourceSerialProvider.h ../../lib/App/common/hardwareResourceNetworkProvider.h |
|||
$(OUTDIR)/hardwareResource.o: ../../lib/App/common/hardwareResource.cpp ../../lib/App/common/hardwareResource.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/hardwareResourceDryContactProvider.o: ../../lib/App/common/hardwareResourceDryContactProvider.cpp ../../lib/App/common/hardwareResourceDryContactProvider.h |
|||
$(OUTDIR)/hardwareResourceNetworkProvider.o: ../../lib/App/common/hardwareResourceNetworkProvider.cpp ../../lib/App/common/hardwareResourceNetworkProvider.h |
|||
$(OUTDIR)/hardwareResourceSerialProvider.o: ../../lib/App/common/hardwareResourceSerialProvider.cpp ../../lib/App/common/hardwareResourceSerialProvider.h |
|||
$(OUTDIR)/hardwareResourceVideoProvider.o: ../../lib/App/common/hardwareResourceVideoProvider.cpp ../../lib/App/common/hardwareResourceVideoProvider.h |
|||
$(OUTDIR)/heapDebug.o: ../../lib/alg/generic/heapDebug.cpp ../../lib/alg/generic/heapDebug.h |
|||
$(OUTDIR)/hid_dc.o: ../../lib/hardware/hid/hid_dc.cpp |
|||
$(OUTDIR)/json_reader.o: ../../lib/data/json/json_reader.cpp ../../lib/data/json/json_tool.h |
|||
$(OUTDIR)/json_value.o: ../../lib/data/json/json_value.cpp ../../lib/data/json/json_valueiterator.inl |
|||
$(OUTDIR)/json_writer.o: ../../lib/data/json/json_writer.cpp ../../lib/data/json/json_tool.h |
|||
$(OUTDIR)/kernelEventFilter.o: ../../lib/App/common/kernelEventFilter.cpp ../../lib/App/common/kernelEventFilter.h |
|||
$(OUTDIR)/kernelEventFilterAPF.o: ../../lib/App/common/kernelEventFilterAPF.cpp ../../lib/App/common/kernelEventFilterAPF.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/kernelModule.o: ../../lib/App/common/kernelModule.cpp ../../lib/App/common/kernelModule.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/kernelModuleEmbedVideo.o: ../../lib/App/common/kernelModuleEmbedVideo.cpp ../../lib/App/common/kernelModuleEmbedVideo.h |
|||
$(OUTDIR)/kernelModuleFactory.o: ../../lib/App/common/kernelModuleFactory.cpp ../../lib/App/common/kernelModuleFactory.h ../../lib/App/common/kernelModuleUSBRelay.h ../../lib/App/common/kernelModuleKafka.h ../../lib/App/common/kernelModuleFlyHunter.h ../../lib/App/common/kernelModuleSSDP.h ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/kernelModuleEmbedVideo.h ../../lib/App/common/kernelModuleModemManager.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/kernelModuleFlyHunter.o: ../../lib/App/common/kernelModuleFlyHunter.cpp ../../lib/App/common/kernelModuleFlyHunter.h |
|||
$(OUTDIR)/kernelModuleKafka.o: ../../lib/App/common/kernelModuleKafka.cpp ../../lib/App/common/kernelModuleKafka.h |
|||
$(OUTDIR)/kernelModuleModemManager.o: ../../lib/App/common/kernelModuleModemManager.cpp ../../lib/App/common/kernelModuleModemManager.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h |
|||
$(OUTDIR)/kernelModuleOnvifObserver.o: ../../lib/App/common/kernelModuleOnvifObserver.cpp ../../lib/App/common/kernelModuleOnvifObserver.h ../../lib/App/common/hardwareManager.h ../../lib/App/common/hardwareResourceNetworkProvider.h |
|||
$(OUTDIR)/kernelModuleSSDP.o: ../../lib/App/common/kernelModuleSSDP.cpp ../../lib/App/common/kernelModuleSSDP.h |
|||
$(OUTDIR)/kernelModuleUSBRelay.o: ../../lib/App/common/kernelModuleUSBRelay.cpp ../../lib/App/common/kernelModuleUSBRelay.h |
|||
$(OUTDIR)/kernelPrototype.o: ../../lib/App/common/kernelPrototype.cpp ../../lib/App/common/kernelPrototype.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/libzip.o: ../../lib/alg/generic/libzip.cpp ../../lib/alg/generic/libzip.h |
|||
$(OUTDIR)/mask.o: ../../lib/alg/lgs/mask.cpp ../../lib/alg/lgs/mask.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/gui/gui.h |
|||
$(OUTDIR)/md5.o: ../../lib/alg/generic/md5.cpp ../../lib/alg/generic/md5.h |
|||
$(OUTDIR)/mojoBackend.o: ../../lib/App/mojo/mojoBackend.cpp ../../lib/App/mojo/mojoBackend.h ../../lib/components/base/basicSettings.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMemoryOperation.h ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/App/mojo/mojoKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/gui/gui.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/MySQL_dataBinder.h ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/mojoKernel.o: ../../lib/App/mojo/mojoKernel.cpp ../../lib/App/mojo/mojoKernel.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/object/objectSystemAnchor.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/detector.h ../../lib/components/base/basicObject.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicValidatable.h ../../lib/alg/lgs/detectorStructures.h ../../lib/components/base/basicTypes.h ../../lib/alg/lgs/mask.h ../../lib/components/base/basicTypes.h ../../lib/hardware/soc/general/3DLRF.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/gui/gui.h ../../lib/alg/generic/md5.h ../../lib/App/common/kernelPrototype.h ../../lib/App/common/kernelEventFilterAPF.h |
|||
$(OUTDIR)/mysql_class.o: ../../lib/data/mysql/mysql_class.cpp ../../lib/data/mysql/mysql_class.h |
|||
$(OUTDIR)/MySQL_dataBinder.o: ../../lib/App/common/MySQL_dataBinder.cpp ../../lib/App/common/MySQL_dataBinder.h |
|||
$(OUTDIR)/netClientHandler.o: ../../lib/data/net/netClientHandler.cpp ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/net/netServiceEngine.h |
|||
$(OUTDIR)/netServer.o: ../../lib/data/net/netServer.cpp ../../lib/data/net/netServer.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicSettingsProvider.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicEventHeap.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/data/protocol/protocol.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/net/netServiceEngine.h ../../lib/data/net/netClientHandler.h ../../lib/data/protocol/protocol.h ../../lib/components/base/basicEventHandler.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicEvent.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicPosition.h ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/net/netServiceEngine.h |
|||
$(OUTDIR)/objectFileLoggingService.o: ../../lib/components/object/objectFileLoggingService.cpp ../../lib/components/object/objectFileLoggingService.h ../../lib/components/base/basicFunctionality.h ../../lib/components/base/basicBuildTimeStamp.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h |
|||
$(OUTDIR)/objectSystemAnchor.o: ../../lib/components/object/objectSystemAnchor.cpp ../../lib/components/object/objectSystemAnchor.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/ponvif.o: ../../lib/data/ponvif/ponvif.cpp ../../lib/data/ponvif/ponvif.h |
|||
$(OUTDIR)/protocol.o: ../../lib/data/protocol/protocol.cpp ../../lib/data/protocol/protocol.h |
|||
$(OUTDIR)/protocolHTTP.o: ../../lib/data/protocol/protocolHTTP.cpp ../../lib/data/protocol/protocolHTTP.h |
|||
$(OUTDIR)/protocolKAFKA.o: ../../lib/data/protocol/protocolKAFKA.cpp ../../lib/data/protocol/protocolKAFKA.h ../../lib/alg/generic/md5.h ../../lib/data/json/json_tool.h |
|||
$(OUTDIR)/protocolLGS2D.o: ../../lib/data/protocol/protocolLGS2D.cpp ../../lib/data/protocol/protocolLGS2D.h |
|||
$(OUTDIR)/protocolLGS3D.o: ../../lib/data/protocol/protocolLGS3D.cpp ../../lib/data/protocol/protocolLGS3D.h |
|||
$(OUTDIR)/protocolLGS3D_client.o: ../../lib/data/protocol/protocolLGS3D_client.cpp ../../lib/data/protocol/protocolLGS3D_client.h |
|||
$(OUTDIR)/protocolONVIF.o: ../../lib/data/protocol/protocolONVIF.cpp ../../lib/data/protocol/protocolONVIF.h |
|||
$(OUTDIR)/protocolPTZ.o: ../../lib/data/protocol/protocolPTZ.cpp ../../lib/data/protocol/protocolPTZ.h |
|||
$(OUTDIR)/protocolPTZ_ONVIF.o: ../../lib/data/protocol/protocolPTZ_ONVIF.cpp ../../lib/data/protocol/protocolPTZ_ONVIF.h ../../lib/hardware/uart/serialPort.h |
|||
$(OUTDIR)/protocolPTZ_PELCO.o: ../../lib/data/protocol/protocolPTZ_PELCO.cpp ../../lib/data/protocol/protocolPTZ_PELCO.h |
|||
$(OUTDIR)/protocolPTZ_VISCA.o: ../../lib/data/protocol/protocolPTZ_VISCA.cpp ../../lib/data/protocol/protocolPTZ_VISCA.h |
|||
$(OUTDIR)/serverPort.o: ../../lib/data/net/serverPort.cpp ../../lib/data/net/serverPort.h ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h |
|||
$(OUTDIR)/sqlite_class.o: ../../lib/data/sqlite/sqlite_class.cpp ../../lib/data/sqlite/sqlite_class.h ../../lib/components/base/basicTypes.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/SQLite_dataBinder.o: ../../lib/App/common/SQLite_dataBinder.cpp ../../lib/App/common/SQLite_dataBinder.h |
|||
$(OUTDIR)/Transform.o: ../../lib/alg/generic/Transform.cpp ../../lib/alg/generic/Transform.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h |
|||
$(OUTDIR)/transportSerial.o: ../../lib/data/transport/transportSerial.cpp ../../lib/data/transport/transportSerial.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h |
|||
$(OUTDIR)/transportSocket.o: ../../lib/data/transport/transportSocket.cpp ../../lib/data/transport/transportSocket.h ../../lib/components/base/basicDualThread.h ../../lib/components/base/basicThread.h ../../lib/components/base/basicLogCollection.h ../../lib/components/base/basicLoggingService.h ../../lib/components/base/basicRing.h ../../lib/components/base/basicMutex.h ../../lib/components/base/basicTransport.h ../../lib/data/protocol/protocol.h |
|||
$(OUTDIR)/utm.o: ../../lib/alg/generic/utm.cpp ../../lib/alg/generic/utm.h |
|||
$(OUTDIR)/videoAVLIBSource.o: ../../lib/data/media/video/videoAVLIBSource.cpp ../../lib/data/media/video/videoAVLIBSource.h |
|||
$(OUTDIR)/videoLive555AVLibSource.o: ../../lib/data/media/video/videoLive555AVLibSource.cpp ../../lib/data/media/video/videoLive555AVLibSource.h |
|||
$(OUTDIR)/xmlParser.o: ../../lib/data/protocol/xmlParser.cpp ../../lib/data/protocol/xmlParser.h |
|||
Binary file not shown.
Binary file not shown.
4818
lib/App/common/MySQL_dataBinder.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,198 @@ |
|||
#ifndef __MYSQL_DATA_BINDER_HEADER__ |
|||
#define __MYSQL_DATA_BINDER_HEADER__ |
|||
|
|||
#include "dataBinder.h" |
|||
#include "../../data/mysql/mysql_class.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "../../alg/generic/md5.h" |
|||
#include "../../alg/lgs/mask.h" |
|||
|
|||
|
|||
class mysqlDBC: public dataBinder { |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
config_setting_t * m_pSettings; |
|||
MySQL_Connector * m_pDatabase; |
|||
bool m_bIsConnected; |
|||
bool m_bIsServerLocal; |
|||
char m_pDbHost[CLOG]; |
|||
char m_pDbUsername[CLOG]; |
|||
char m_pDbPassword[CLOG]; |
|||
char m_pDbDatabase[CLOG]; |
|||
uint32_t m_nSiteID; |
|||
uint32_t m_nServerID; |
|||
uint32_t m_nServerNodeID; |
|||
|
|||
static mysqlDBC * _instance; |
|||
explicit mysqlDBC( config_setting_t * Settings = NULL ); |
|||
public: |
|||
static mysqlDBC * getInstance( config_setting_t * Settings = NULL ); |
|||
virtual ~mysqlDBC(); |
|||
/* Functionality */ |
|||
bool connect( void ); |
|||
bool isLocal( void ) const { return m_bIsServerLocal; }; |
|||
|
|||
//SET GLOBAL tmp_table_size = 1024 * 1024 * 1024 * 2; |
|||
//SET GLOBAL max_heap_table_size = 1024 * 1024 * 1024 * 2; |
|||
//SELECT @@max_heap_table_size; |
|||
//SHOW VARIABLES LIKE 'max_heap_table_size'; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
uint32_t addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id=0, uint16_t dig_r=0, float EL=.0f, float AZ=.0f, float RANGE=.0f, float AREA=.0f, float lat=.0f, float lon=.0f, float alt=.0f, uint32_t RefID=0, CSTR RefUUID=NULL ); |
|||
bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ); |
|||
|
|||
bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false ); |
|||
uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 ); |
|||
uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ); |
|||
bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ); |
|||
|
|||
bool addIPCam( OBSERVER_RESULT *tPtr ); |
|||
uint32_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ); |
|||
uint32_t addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ); |
|||
uint32_t addLocalUART( /*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode=0, uint16_t port=0 ); |
|||
uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 ); |
|||
uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ); |
|||
uint32_t addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp=false, CSTR BRANG=NULL, CSTR ERANG=NULL, CSTR MASK=NULL, CSTR LEASE_TIME=NULL ); |
|||
uint32_t addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id=0 ); |
|||
bool addNotification( uint32_t MSG_ID, uint8_t DIS_LVL = 0, uint32_t OBJ_ID=0 ); |
|||
bool addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ); |
|||
|
|||
//bool addPictureEvent( uint32_t evtID, uint32_t pictureoID ); |
|||
virtual uint32_t addResource( uint8_t type, CSTR devName, uint32_t auxID = 0 ); |
|||
//uint32_t addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID = 0 ); |
|||
//uint32_t addUploadFile( uint32_t NodeID, CSTR uid, CSTR fileName ); |
|||
|
|||
bool addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ); |
|||
uint32_t addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ); |
|||
|
|||
bool cleanResources( bool all = false ); |
|||
bool cleanLRFMask( uint32_t maskID, bool deleteMask = false ); |
|||
bool cleanNodeEvents( uint32_t NodeID, bool all = false ); |
|||
bool cleanEvents2PictureBinding( uint32_t PicID ); |
|||
bool cleanEvents2VideoBinding( uint32_t PicID ); |
|||
|
|||
|
|||
void lazyEventArchiver( uint32_t DalayTime = 10 ); |
|||
DBC_INT_LIST * listCamMediaStreams( uint32_t CAMID ); |
|||
DBC_INT_LIST * listStreamCapPictures( uint32_t StreamID, uint32_t cnt ); |
|||
DBC_INT_LIST * listDetectionProfileIDs( uint32_t nodeID ); |
|||
DBC_INT_LIST * listDetectionProfiles( uint32_t nodeID ); |
|||
DBC_INT_LIST * listFilters( uint32_t ServerID ); |
|||
DBC_INT_LIST * listLRFMaskVertexes( uint32_t MaskID ); |
|||
DBC_INT_LIST * listLRFMaskVertexPoints( uint32_t VertexID ); |
|||
DBC_INT_LIST * listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS ); |
|||
DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS ); |
|||
DBC_INT_LIST * listModules(); |
|||
DBC_INT_LIST * listNetworks( uint32_t nif_id ); |
|||
DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids ); |
|||
|
|||
DBC_INT_LIST * listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST * old_ids ); |
|||
DBC_INT_LIST * listNodes( uint32_t SiteID, uint32_t ServerID, bool all = false ); |
|||
//DBC_INT_LIST * listSockets( uint32_t NodeID ); |
|||
DBC_INT_LIST * listResources( uint32_t NodeID = 0 ); |
|||
simplePolygone * loadLRFMaskVertex( uint32_t vid ); |
|||
|
|||
bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ); |
|||
DBC_APF_DATA * getAPFData( uint32_t APFID ); |
|||
DBC_CAM_DATA * getCamData( uint32_t CamID ); |
|||
uint32_t getCamId( CSTR UUID ); |
|||
|
|||
bool getConnectionStatus(void){return m_bIsConnected;}; |
|||
DBC_CAP_DATA * getCamCapPictureData( uint32_t PicID ); |
|||
DBC_EVT_RECORD * getEventByUUID( CSTR UUID ); |
|||
DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID ); |
|||
DBC_FH_DATA * getFlyHunterData( uint32_t ID ); |
|||
//int getIPCamCount( uint32_t SiteID ); |
|||
KAFKA_TEMPLATE * getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ); |
|||
//bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ); |
|||
DBC_LRF_DATA * getLRFData( uint32_t ID ); |
|||
uint8_t getLRFDataStatus( uint32_t ID ); |
|||
PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ); |
|||
CSTR getLRFDraw( uint32_t DBID ); |
|||
uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 ); |
|||
DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_DATA * getMediaServerData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamDataBySource( uint32_t ID ); |
|||
DBC_MODULE_DATA * getModuleData( uint32_t ID ); |
|||
CSTR getNodeName( uint32_t NodeID ); |
|||
uint32_t getNodeAuxParam( uint32_t NodeID ); |
|||
uint32_t getNodeAuxID( uint32_t NodeID ); |
|||
DBC_NETWORK_DATA * getNetworkData( uint32_t net_id ); |
|||
uint32_t getNetworkInfrastructureID( uint32_t nif_id ); |
|||
DBC_NET_IF_DATA * getNIF_Data( uint32_t ID ); |
|||
uint32_t getNIF_ID( CSTR key ); |
|||
uint32_t getNIF_IDbyDevice( CSTR device ); |
|||
DBC_NODE_DATA * getNodeData( uint32_t ID ); |
|||
|
|||
DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID ); |
|||
DBC_PUSHED_CMD * getActivePushedCMD( uint32_t NodeID ); |
|||
DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID ); |
|||
|
|||
//uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ); |
|||
DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ); |
|||
uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ); |
|||
uint32_t getServerID( CSTR identity ); |
|||
uint32_t getServerNode( uint32_t SID ); |
|||
KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID ); |
|||
DBC_SITE_DATA * getSiteData( uint32_t ID ); |
|||
//DBC_SOCKET_DATA * getSocketData( uint32_t ID ); |
|||
DBC_TARGET_FLITER_DATA * getTargetFilterData( uint32_t ID ); |
|||
DBC_UART_DATA * getUartData( uint32_t UartID ); |
|||
uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ); |
|||
uint32_t getWiFi_ID( uint32_t nif_id ); |
|||
bool fillShadow2D( uint32_t ID, SHADOW & SH ); |
|||
|
|||
void deleteCamCapPicture( uint32_t PicID ); |
|||
void deleteNode( uint32_t NodeID ); |
|||
void deleteCamera( uint32_t CamID ); |
|||
void deleteConnections( uint32_t NodeID ); |
|||
void deleteNodeEvents( uint32_t NodeID ); |
|||
void deleteMediaStream( uint32_t MediaID ); |
|||
void deleteNIF( uint32_t NifID ); |
|||
void deleteNIS( uint32_t NisID ); |
|||
void deleteResource( uint32_t ResourceID ); |
|||
void deleteSensor( uint32_t SensorID ); |
|||
void deleteUART( uint32_t UARTID ); |
|||
|
|||
//void finalizeVideoRecord( uint32_t videoID, uint32_t clen ); |
|||
|
|||
void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ); |
|||
void unregisterServer(); |
|||
|
|||
bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY ); |
|||
|
|||
|
|||
|
|||
bool setNodeOnline( uint32_t NodeID, uint8_t status=NODE_STATUS_WORK ); |
|||
bool setNodeOffline( uint32_t NodeID ); |
|||
//bool setOnlineStatus( bool Status ); |
|||
bool setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ); |
|||
bool setLRFDataStatus( uint32_t lrfID, uint8_t ST ); |
|||
bool setLRFAltSerial( uint32_t lrfID, CSTR Serial ); |
|||
bool setLRFAltVerison( uint32_t lrfID, CSTR version ); |
|||
bool setLRFMaskStatus( uint32_t maskID, bool status ); |
|||
bool setStreamValid( uint32_t streamID, bool status = true ); |
|||
//bool syncEventArchive( void ); ALTER TABLE table_name AUTO_INCREMENT = start_value; |
|||
bool update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ); |
|||
bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ); |
|||
bool updateCamRange( uint32_t camID, float range ); |
|||
bool updateIPCam( CSTR uuid, CSTR Addr ); |
|||
bool updateIPCam( uint32_t CamID, CSTR Addr ); |
|||
bool updateLRFSerial( uint32_t lrfID, CSTR Serial ); |
|||
bool updateLRFVerison( uint32_t lrfID, CSTR version ); |
|||
bool updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP=0, uint32_t spikes=0 ); |
|||
bool updateMediaServerStream( uint32_t id, CSTR mrl=NULL, CSTR key = NULL ); |
|||
//bool updateNetworkNode( bool OnlineStatus ); |
|||
bool updateNodePushedCMD( uint32_t CmdID, uint8_t status ); |
|||
bool updateResourceAUX( uint32_t ResID, uint32_t AUX ); |
|||
//bool updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ); |
|||
virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ); |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
1305
lib/App/common/SQLite_dataBinder.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,88 @@ |
|||
#ifndef __SQLITE_DATA_BINDER_HEADER__ |
|||
#define __SQLITE_DATA_BINDER_HEADER__ |
|||
|
|||
#include "dataBinder.h" |
|||
#include "../data/sqlite/sqlite_class.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "../../alg/generic/md5.h" |
|||
#include "../../alg/lgs/mask.h" |
|||
|
|||
|
|||
#define DB_SHMEM_POINT "/dev/shm/argus" |
|||
|
|||
|
|||
class sqliteDBC: public dataBinder { |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
config_setting_t * m_pSettings; |
|||
SQLite_Connector * m_pDataStorage; |
|||
SQLite_Connector * m_pDataMemory; |
|||
bool m_bIsConnected; |
|||
bool m_bRecreateMemStructures; |
|||
char m_pDbFile[CLOG]; |
|||
char m_pDbMemory[CLOG]; |
|||
char m_pDbUsername[CLOG]; |
|||
char m_pDbPassword[CLOG]; |
|||
char m_pDbDatabase[CLOG]; |
|||
|
|||
uint32_t m_nSiteID; |
|||
uint32_t m_nServerID; |
|||
uint32_t m_nServerNodeID; |
|||
|
|||
void initMemDB( uint32_t sid = 1 ); |
|||
|
|||
static sqliteDBC * _instance; |
|||
explicit sqliteDBC( config_setting_t * Settings ); |
|||
public: |
|||
static sqliteDBC * getInstance( config_setting_t * Settings = NULL ); |
|||
virtual ~sqliteDBC(); |
|||
/* Functionality */ |
|||
bool connect( void ); |
|||
virtual bool cleanResources( bool all = false ); |
|||
virtual bool isLocal( void ) const { return true; }; |
|||
virtual bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ); |
|||
virtual bool addIPCam( OBSERVER_RESULT *tPtr ); |
|||
virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height ); |
|||
virtual uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ); |
|||
virtual uint32_t addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp=false, CSTR BRANG=NULL, CSTR ERANG=NULL, CSTR MASK=NULL, CSTR LEASE_TIME=NULL ); |
|||
virtual uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 ); |
|||
virtual uint32_t addLocalUART( uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode=0, uint16_t port=0 ); |
|||
virtual uint32_t addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id=0 ); |
|||
virtual uint32_t addResource( uint8_t type, CSTR devName, uint32_t auxID = 0 ); |
|||
virtual bool cleanNodePushedCMD( void ); |
|||
virtual uint32_t getCamId( CSTR UUID ); |
|||
virtual DBC_MODULE_DATA * getModuleData( uint32_t ID ); |
|||
virtual uint32_t getMediaStreamID( uint32_t source_id, CSTR token ); |
|||
virtual DBC_NET_IF_DATA * getNIF_Data( uint32_t ID ); |
|||
virtual uint32_t getNIF_ID( CSTR key ); |
|||
virtual uint32_t getNIF_IDbyDevice( CSTR device ); |
|||
virtual uint32_t getWiFi_ID( uint32_t nif_id ); |
|||
virtual uint32_t getNetworkInfrastructureID( uint32_t nif_id ); |
|||
virtual DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID ); |
|||
virtual DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ); |
|||
virtual uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ); |
|||
virtual uint32_t getServerID( CSTR identity ); |
|||
virtual uint32_t getServerNode( uint32_t SID ); |
|||
virtual uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ); |
|||
|
|||
virtual DBC_INT_LIST * listModules(); |
|||
virtual DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids ); |
|||
virtual DBC_INT_LIST * listResources( uint32_t NodeID = 0 ); |
|||
|
|||
virtual void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ); |
|||
virtual bool setNodeOffline( uint32_t NodeID ); |
|||
virtual bool setNodeOnline( uint32_t NodeID, uint8_t status=NODE_STATUS_WORK ); |
|||
virtual bool setStreamValid( uint32_t streamID, bool status = true ); |
|||
virtual void unregisterServer( void ); |
|||
virtual bool updateIPCam( uint32_t CamID, CSTR Addr ); |
|||
virtual bool updateIPCam( CSTR uuid, CSTR Addr ); |
|||
virtual bool updateLocalCam( CSTR uuid ); |
|||
virtual bool updateLocalCam( uint32_t CamID ); |
|||
virtual bool updateNodePushedCMD( uint32_t CmdID, uint8_t status ); |
|||
virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ); |
|||
virtual bool updateSystemInfo( DBC_SYS_INFO *ptr ); |
|||
virtual CSTR getDataParam( uint8_t pid = 0 ); |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,3 @@ |
|||
#include "dataBinder.h"
|
|||
dataBinder::dataBinder(){}; |
|||
dataBinder::~dataBinder(){}; |
|||
@ -0,0 +1,177 @@ |
|||
#ifndef __DFSL_DATA_BINDER_HEADER__ |
|||
#define __DFSL_DATA_BINDER_HEADER__ |
|||
|
|||
#include "dataBinder_structures.h" |
|||
|
|||
|
|||
class dataBinder{ |
|||
protected: |
|||
dataBinder(); |
|||
public: |
|||
virtual ~dataBinder(); |
|||
virtual bool isLocal(){ return true; }; |
|||
//virtual uint32_t addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id=0, uint16_t dig_r=0, float EL=.0f, float AZ=.0f, float RANGE=.0f, float AREA=.0f, float lat=.0f, float lon=.0f, float alt=.0f, uint32_t RefID=0, CSTR RefUUID=NULL ); |
|||
virtual uint32_t addEvent( DBC_EVT_RECORD *ptr ){ return 0;}; |
|||
virtual bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){ return false;}; |
|||
|
|||
virtual bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false ){ return false;}; |
|||
virtual uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 ){ return 0;}; |
|||
virtual uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){ return 0;}; |
|||
virtual bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){ return false;}; |
|||
|
|||
//virtual bool addIPCam( uint32_t SiteID, resultWoWo *tPtr ); |
|||
|
|||
virtual bool addIPCam( OBSERVER_RESULT *tPtr ){ return false;}; |
|||
virtual uint32_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){ return 0;}; |
|||
virtual uint32_t addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){ return 0;}; |
|||
virtual uint32_t addLocalCam( CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height ){ return 0;}; |
|||
virtual uint32_t addLocalUART( /*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode=0, uint16_t port=0 ){ return 0;}; |
|||
virtual uint32_t addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id = 0 ){ return 0;}; |
|||
virtual uint32_t addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){ return 0;}; |
|||
virtual uint32_t addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp=false, CSTR BRANG=NULL, CSTR ERANG=NULL, CSTR MASK=NULL, CSTR LEASE_TIME=NULL ){ return 0;}; |
|||
virtual uint32_t addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id=0 ){ return 0;}; |
|||
virtual bool addNotification( uint32_t MSG_ID, uint8_t DIS_LVL = 0, uint32_t OBJ_ID=0 ){ return false;}; |
|||
virtual bool addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){ return false;}; |
|||
|
|||
//virtual bool addPictureEvent( uint32_t evtID, uint32_t pictureoID ){ return false;}; |
|||
virtual uint32_t addResource( /*uint32_t NodeID,*/ uint8_t type, CSTR devName, uint32_t auxID = 0 ){ return 0;}; |
|||
virtual uint32_t addUploadFile( uint32_t NodeID, CSTR uid, CSTR fileName ){ return 0;}; |
|||
|
|||
virtual bool addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ){ return false;}; |
|||
virtual uint32_t addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ){ return 0;}; |
|||
|
|||
virtual bool cleanResources( bool all = false ){ return false;}; |
|||
virtual bool cleanLRFMask( uint32_t maskID, bool deleteMask = false ){ return false;}; |
|||
virtual bool cleanNodeEvents( uint32_t NodeID, bool all = false ){ return false;}; |
|||
virtual bool cleanEvents2PictureBinding( uint32_t PicID ){ return false;}; |
|||
virtual bool cleanEvents2VideoBinding( uint32_t PicID ){ return false;}; |
|||
virtual bool cleanNodePushedCMD( void ){ return false;}; |
|||
|
|||
|
|||
virtual void lazyEventArchiver( uint32_t DalayTime = 10 ){}; |
|||
virtual DBC_INT_LIST * listCamMediaStreams( uint32_t CAMID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listStreamCapPictures( uint32_t StreamID, uint32_t cnt ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listDetectionProfileIDs( uint32_t nodeID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listDetectionProfiles( uint32_t nodeID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listFilters( uint32_t ServerID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listLRFMaskVertexes( uint32_t MaskID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listLRFMaskVertexPoints( uint32_t VertexID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listModules(){ return NULL;}; |
|||
virtual DBC_INT_LIST * listNetworks( uint32_t nif_id ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids ){ return NULL;}; |
|||
|
|||
virtual DBC_INT_LIST * listNewNodes( DBC_INT_LIST * old_ids ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listNodes( bool all = false ){ return NULL;}; |
|||
//virtual DBC_INT_LIST * listSockets( uint32_t NodeID ){ return NULL;}; |
|||
virtual DBC_INT_LIST * listResources( uint32_t NodeID = 0 ){ return NULL;}; |
|||
virtual simplePolygone * loadLRFMaskVertex( uint32_t vid ){ return NULL;}; |
|||
|
|||
virtual bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ return false;}; |
|||
virtual DBC_APF_DATA * getAPFData( uint32_t APFID ){ return NULL;}; |
|||
virtual DBC_CAM_DATA * getCamData( uint32_t CamID ){ return NULL;}; |
|||
virtual uint32_t getCamId( CSTR UUID ){ return 0;}; |
|||
|
|||
virtual bool getConnectionStatus(void){return false;}; |
|||
virtual DBC_CAP_DATA * getCamCapPictureData( uint32_t PicID ){ return NULL;}; |
|||
virtual DBC_EVT_RECORD * getEventByUUID( CSTR UUID ){ return NULL;}; |
|||
virtual DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_FH_DATA * getFlyHunterData( uint32_t ID ){ return NULL;}; |
|||
virtual int getIPCamCount( uint32_t SiteID ){ return 0;}; |
|||
virtual KAFKA_TEMPLATE * getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){ return NULL;}; |
|||
//virtual bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ); |
|||
virtual DBC_LRF_DATA * getLRFData( uint32_t ID ){ return NULL;}; |
|||
virtual uint8_t getLRFDataStatus( uint32_t ID ){ return 0;}; |
|||
virtual PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){ return NULL;}; |
|||
virtual CSTR getLRFDraw( uint32_t DBID ){ return NULL;}; |
|||
virtual uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 ){ return 0;}; |
|||
virtual DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID ){ return NULL;}; |
|||
virtual uint32_t getMediaStreamID( uint32_t source_id, CSTR token ){ return NULL;}; |
|||
virtual DBC_MEDIA_SERVER_DATA * getMediaServerData( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamDataBySource( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_MODULE_DATA * getModuleData( uint32_t ID ){ return NULL;}; |
|||
//virtual * getModuleEveSettings( uint32_t ID ){}; |
|||
//virtual * getModuleSSDPSettings( uint32_t ID ){}; |
|||
virtual CSTR getNodeName( uint32_t NodeID ){ return NULL;}; |
|||
virtual uint32_t getNodeAuxParam( uint32_t NodeID ){ return 0;}; |
|||
virtual uint32_t getNodeAuxID( uint32_t NodeID ){ return 0;}; |
|||
virtual DBC_NETWORK_DATA * getNetworkData( uint32_t net_id ){ return NULL;}; |
|||
virtual uint32_t getNetworkInfrastructureID( uint32_t nif_id ){ return 0;}; |
|||
virtual DBC_NET_IF_DATA * getNIF_Data( uint32_t ID ){ return NULL;}; |
|||
virtual uint32_t getNIF_ID( CSTR key ){ return 0;}; |
|||
virtual uint32_t getNIF_IDbyDevice( CSTR device ){ return 0;}; |
|||
virtual DBC_NODE_DATA * getNodeData( uint32_t ID ){ return NULL;}; |
|||
|
|||
virtual DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID ){ return NULL;}; |
|||
virtual DBC_PUSHED_CMD * getActivePushedCMD( uint32_t NodeID ){ return NULL;}; |
|||
virtual DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID ){ return NULL;}; |
|||
|
|||
//virtual uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ); |
|||
virtual DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ){ return NULL;}; |
|||
virtual uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){ return 0;}; |
|||
virtual uint32_t getServerID( CSTR identity ){ return 0;}; |
|||
virtual uint32_t getServerNode( uint32_t SID ){ return 0;}; |
|||
virtual KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID ){ return NULL;}; |
|||
virtual DBC_SITE_DATA * getSiteData( uint32_t ID ){ return NULL;}; |
|||
//virtual DBC_SOCKET_DATA * getSocketData( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_TARGET_FLITER_DATA * getTargetFilterData( uint32_t ID ){ return NULL;}; |
|||
virtual DBC_UART_DATA * getUartData( uint32_t UartID ){ return NULL;}; |
|||
virtual uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){ return 0;}; |
|||
virtual uint32_t getWiFi_ID( uint32_t nif_id ){ return 0;}; |
|||
virtual bool fillShadow2D( uint32_t ID, SHADOW & SH ){ return false;}; |
|||
|
|||
virtual void deleteCamCapPicture( uint32_t PicID ){}; |
|||
virtual void deleteNode( uint32_t NodeID ){}; |
|||
virtual void deleteCamera( uint32_t CamID ){}; |
|||
virtual void deleteConnections( uint32_t NodeID ){}; |
|||
virtual void deleteNodeEvents( uint32_t NodeID ){}; |
|||
virtual void deleteMediaStream( uint32_t MediaID ){}; |
|||
virtual void deleteNIF( uint32_t NifID ){}; |
|||
virtual void deleteNIS( uint32_t NisID ){}; |
|||
virtual void deleteResource( uint32_t ResourceID ){}; |
|||
virtual void deleteSensor( uint32_t SensorID ){}; |
|||
virtual void deleteUART( uint32_t UARTID ){}; |
|||
|
|||
virtual void finalizeVideoRecord( uint32_t videoID, uint32_t clen ){}; |
|||
|
|||
virtual void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){}; |
|||
virtual void unregisterServer( void ){}; |
|||
|
|||
virtual bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY ){ return false;}; |
|||
|
|||
|
|||
|
|||
virtual bool setNodeOnline( uint32_t NodeID, uint8_t status=NODE_STATUS_WORK ){ return false;}; |
|||
virtual bool setNodeOffline( uint32_t NodeID ){ return false;}; |
|||
virtual bool setOnlineStatus( bool Status ){ return false;}; |
|||
virtual bool setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){ return false;}; |
|||
virtual bool setLRFDataStatus( uint32_t lrfID, uint8_t ST ){ return false;}; |
|||
virtual bool setLRFAltSerial( uint32_t lrfID, CSTR Serial ){ return false;}; |
|||
virtual bool setLRFAltVerison( uint32_t lrfID, CSTR version ){ return false;}; |
|||
virtual bool setLRFMaskStatus( uint32_t maskID, bool status ){ return false;}; |
|||
virtual bool setStreamValid( uint32_t streamID, bool status = true ){ return false;}; |
|||
//virtual bool syncEventArchive( void ); ALTER TABLE table_name AUTO_INCREMENT = start_value; |
|||
virtual bool update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){ return false;}; |
|||
virtual bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){ return false;}; |
|||
virtual bool updateCamRange( uint32_t camID, float range ){ return false;}; |
|||
virtual bool updateIPCam( CSTR uuid, CSTR Addr ){ return false;}; |
|||
virtual bool updateIPCam( uint32_t CamID, CSTR Addr ){ return false;}; |
|||
virtual bool updateLocalCam( CSTR uuid ){ return false;}; |
|||
virtual bool updateLocalCam( uint32_t CamID ){ return false;}; |
|||
virtual bool updateLRFSerial( uint32_t lrfID, CSTR Serial ){ return false;}; |
|||
virtual bool updateLRFVerison( uint32_t lrfID, CSTR version ){ return false;}; |
|||
virtual bool updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP=0, uint32_t spikes=0 ){ return false;}; |
|||
virtual bool updateMediaServerStream( uint32_t id, CSTR mrl=NULL, CSTR key = NULL ){ return false;}; |
|||
virtual bool updateNetworkNode( bool OnlineStatus ){ return false;}; |
|||
virtual bool updateNodePushedCMD( uint32_t CmdID, uint8_t status ){ return false;}; |
|||
virtual bool updateResourceAUX( uint32_t ResID, uint32_t AUX ){ return false;}; |
|||
virtual bool updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){ return false;}; |
|||
virtual bool updateSystemInfo( DBC_SYS_INFO *ptr ){ return false; }; |
|||
virtual CSTR getDataParam( uint8_t pid = 0 ){ return NULL; }; |
|||
|
|||
}; |
|||
|
|||
|
|||
#endif |
|||
@ -0,0 +1,645 @@ |
|||
#ifndef __DFSL_DATABINDING_STRUCTURES_HEADER__ |
|||
#define __DFSL_DATABINDING_STRUCTURES_HEADER__ |
|||
|
|||
#define __STDC_FORMAT_MACROS 1 |
|||
#include <inttypes.h> |
|||
|
|||
#include "../../alg/lgs/mask.h" |
|||
#include "../../alg/lgs/detectorStructures.h" |
|||
#include "../../data/protocol/protocolLGS_data.h" |
|||
|
|||
#define MAX_BUFF_SIZE 102400 //100K |
|||
|
|||
#define LIST_ALL_RECORDS 0 |
|||
#define LIST_VALID_RECORDS 1 |
|||
#define LIST_INVALID_RECORDS 2 |
|||
|
|||
#define ONE_DAY_HISTORY 86400 |
|||
#define ONE_HOUR_HISTORY 3600 |
|||
#define ONE_SECOND_HISTORY 1 |
|||
|
|||
#define NM_DISMISS_LEVEL_VIEWER 1 |
|||
#define NM_DISMISS_LEVEL_OPERATOR 2 |
|||
#define NM_DISMISS_LEVEL_ADMIN 5 |
|||
#define NM_DISMISS_LEVEL_FOUNDER 9 |
|||
|
|||
#define NM_DEVICE_MISTMATCH 1 |
|||
|
|||
#define NODE_STATUS_WORK 1 |
|||
#define NODE_STATUS_INIT 2 |
|||
#define NODE_STATUS_TROUBLE 3 |
|||
#define NODE_STATUS_ALARM 4 |
|||
|
|||
typedef enum E_ARGUS_NODE_TYPE{ |
|||
ARGUS_SERVER = 0, |
|||
ARGUS_ALS_SENSOR = 1, |
|||
ARGUS_LFS_SENSOR = 2, |
|||
ARGUS_PLS_200_SENSOR = 3, |
|||
ARGUS_PLS_360_SENSOR = 4, |
|||
ARGUS_3D_SENSOR = 5, |
|||
ARGUS_NET_PLS_200 = 6, |
|||
ARGUS_CLD_SENSOR = 7, |
|||
ARGUS_LGS_SENSOR = 8, |
|||
ARGUS_ACC_SENSOR = 9, |
|||
ARGUS_ANALOG_STATIC_CAMERA = 10, |
|||
ARGUS_ANALOG_PTZ_CAMERA = 11, |
|||
ARGUS_IP_STATIC_CAMERA = 12, |
|||
ARGUS_IP_PTZ_CAMERA = 13, |
|||
ARGUS_IP_UART_GATEWAY = 20, |
|||
ARGUS_JAMER = 40, |
|||
ARGUS_IP_VIDEO_SERVER = 50, |
|||
ARGUS_DRONE_CONTROL = 60, |
|||
ARGUS_CELLULAR_GATEWAY = 61, |
|||
|
|||
ARGUS_NAPD_FILTER = 100, |
|||
ARGUS_METRO_FILTER = 101, |
|||
ARGUS_UNKNOWN = 255 |
|||
}ARGUS_NODE_TYPE; |
|||
|
|||
#ifdef __linux__ |
|||
#ifdef __arm__ |
|||
#ifdef RASPI_HARDWARE |
|||
#define _BUILD_STRING_ ( "RPI_22.06.17 [" __DATE__ " " __TIME__ "]") |
|||
#else |
|||
#define _BUILD_STRING_ ( "ALS_22.06.17 [" __DATE__ " " __TIME__ "]") |
|||
#endif |
|||
#else |
|||
#define _BUILD_STRING_ ( "ILS_22.06.17 [" __DATE__ " " __TIME__ "]") |
|||
#endif |
|||
#else |
|||
#define _BUILD_STRING_ ( "WIN_22.06.17 [" __DATE__ " " __TIME__ "]") |
|||
#endif |
|||
|
|||
typedef uint8_t NODE_TYPE; |
|||
|
|||
typedef struct S_OBSERVER_RESULT{ |
|||
int resultID; |
|||
char RefID[CTEXT]; |
|||
char Type[CTEXT]; |
|||
char MAC[CTEXT]; |
|||
char Hardware[CTEXT]; |
|||
char Name[CTEXT]; |
|||
char XAddrs[CTEXT]; |
|||
}OBSERVER_RESULT; |
|||
|
|||
typedef struct S_MEDIA_SOURCE_DESC{ |
|||
uint32_t mediaStreamId; |
|||
uint32_t mediaSourceId; |
|||
char mediaName[128]; |
|||
}MEDIA_SOURCE_DESC; |
|||
|
|||
typedef enum E_HARDWARE_PROVIDERS{ |
|||
HARDWARE_PROVIDER_UNKNOWN = 0, |
|||
HARDWARE_PROVIDER_SERIAL = 1, |
|||
HARDWARE_PROVIDER_NETWORK = 2, |
|||
HARDWARE_PROVIDER_VIDEO = 3, |
|||
HARDWARE_PROVIDER_DRY_CONTACT = 4 |
|||
} HARDWARE_PROVIDERS; |
|||
|
|||
typedef std::vector<CSTR> vectorCSTR; |
|||
|
|||
typedef enum E_RESOURCE_CLASS{ |
|||
HARDWARE_CLASS_UNKNOWN = 0, |
|||
HARDWARE_CLASS_SERIAL = 1, |
|||
HARDWARE_CLASS_GPIO = 2, |
|||
HARDWARE_CLASS_NETWORK = 3, |
|||
HARDWARE_CLASS_MEDIA = 4 |
|||
} RESOURCE_CLASS; |
|||
|
|||
typedef enum E_RESOURCE_TYPE{ |
|||
HARDWARE_UNKNOWN = 0, |
|||
HARDWARE_UART = 1, |
|||
HARDWARE_USB_DC = 6, |
|||
HARDWARE_GPIO_IN = 7, |
|||
HARDWARE_GPIO_OUT = 8, |
|||
|
|||
HARDWARE_ANALOG_VIDEO_OUT = 30, |
|||
HARDWARE_ANALOG_VIDEO_IN = 31, |
|||
HARDWARE_DIGITAL_VIDEO_OUT = 32, |
|||
HARDWARE_DIGITAL_VIDEO_IN = 33, |
|||
|
|||
HARDWARE_NIF_LOOPBACK = 100, |
|||
HARDWARE_NIF_ETHERNET = 101, |
|||
HARDWARE_NIF_WIFI = 102, |
|||
HARDWARE_NIF_VIRTUAL = 103, |
|||
HARDWARE_NIF_TUNEL = 104, |
|||
HARDWARE_NIF_WAN = 105, |
|||
|
|||
HARDWARE_MODEM = 120, |
|||
HARDWARE_IP_UART = 129, |
|||
HARDWARE_IP_VIDEO_OUT = 130, |
|||
HARDWARE_IP_VIDEO_IN = 131 |
|||
} RESOURCE_TYPE; |
|||
|
|||
typedef enum E_NIF_TYPE{ |
|||
NIF_LOOPBACK = 0, |
|||
NIF_ETHERNET = 1, |
|||
NIF_ETHERNET_VIRTUAL = 2, |
|||
NIF_WIFI = 3, |
|||
NIF_VPN_TUNEL = 4, |
|||
NIF_WAN = 5 |
|||
}NIF_TYPE; |
|||
|
|||
typedef enum E_NIF_MODE{ |
|||
ADDRESS_DISABLED = 0, |
|||
ADDRESS_DYNAMIC = 1, |
|||
ADDRESS_STATIC = 2, |
|||
ADDRESS_STATIC_RAP = 3 |
|||
} NIF_MODE; |
|||
|
|||
typedef enum E_WIFI_MODE{ |
|||
WIFI_DISABLED = 0, |
|||
WIFI_ADHOC = 1, |
|||
WIFI_CONNECTED_TO_AP = 2, |
|||
WIFI_IS_AP = 3 |
|||
}WIFI_MODE; |
|||
|
|||
typedef enum E_WIFI_ENCRIPTION{ |
|||
ENCRIPTION_NONE = 0, |
|||
ENCRIPTION_WPA_PSK = 1, |
|||
ENCRIPTION_WPE = 2, |
|||
ENCRIPTION_TKIP = 3 |
|||
}WIFI_ENCRIPTION; |
|||
|
|||
typedef enum E_NETWORK_TYPE{ |
|||
NETWORK_IPV4 = 0, |
|||
NETWORK_IPV6 = 1, |
|||
} NETWORK_TYPE; |
|||
|
|||
typedef enum E_CAM_TRIGGER_MODE{ |
|||
CAM_TRIGGER_STRICT = 0, |
|||
CAM_TRIGGER_ALL_NEAR = 1, |
|||
CAM_TRIGGER_ALL_FAR = 2, |
|||
CAM_TRIGGER_ALL = 3 |
|||
} CAM_TRIGGER_MODE; |
|||
|
|||
typedef struct S_DBC_CAM_DATA{ |
|||
uint32_t id; |
|||
uint32_t site_id; |
|||
uint32_t node_id; |
|||
bool online; |
|||
uint8_t type; |
|||
char name[65]; |
|||
char hardware[33]; |
|||
uint8_t status; |
|||
char session[33]; |
|||
uint8_t protocol; |
|||
uint8_t protocol_aux; |
|||
uint32_t uart_id; |
|||
float x; |
|||
float y; |
|||
float z; |
|||
float x_rot; |
|||
float y_rot; |
|||
float z_rot; |
|||
uint8_t imager_type; |
|||
uint8_t lens_f; |
|||
//float max_range; |
|||
float ptz_speed_step; |
|||
uint8_t pan_model; |
|||
uint16_t pan_angles; |
|||
uint8_t tilt_model; |
|||
uint8_t tilt_angles; |
|||
uint8_t zoom_model; |
|||
float zoom; |
|||
char username[33]; |
|||
char password[33]; |
|||
char uuid[65]; |
|||
char ip[18]; |
|||
uint16_t port; |
|||
char mac[18]; |
|||
char onvif_access[6]; |
|||
char onvif_ctrl[251]; |
|||
char ptz_token[65]; |
|||
uint8_t triggering_mode; |
|||
uint8_t auth_mode; |
|||
}DBC_CAM_DATA; |
|||
|
|||
typedef struct S_DBC_NETWORK_DATA{ |
|||
uint32_t id; |
|||
uint32_t nif_id; |
|||
char address[65]; |
|||
char netmask[65]; |
|||
char broadcast[65]; |
|||
char gateway[65]; |
|||
NETWORK_TYPE type; |
|||
}DBC_NETWORK_DATA; |
|||
|
|||
typedef struct S_DBC_WIFI_DATA{ |
|||
uint32_t id; |
|||
uint32_t if_id; |
|||
char SSID[65]; |
|||
char password[65]; |
|||
uint8_t mode; // disabled connected_to_ap ap |
|||
uint32_t aux_id; // ap_router |
|||
}DBC_WIFI_DATA; |
|||
|
|||
typedef struct S_DBC_NET_ROUTER_DATA{ |
|||
char address_range[128]; |
|||
}DBC_NET_ROUTER_DATA; |
|||
|
|||
typedef struct S_DBC_NET_IF_DATA{ |
|||
uint32_t id; |
|||
uint8_t type; // Ethernet Wifi |
|||
uint8_t mode; // dynamic static static-router |
|||
char device_name[11]; |
|||
char mac[33]; |
|||
uint32_t aux_id; // wifi_id router_id |
|||
|
|||
DBC_NETWORK_DATA ** networks; |
|||
uint8_t networkCount; |
|||
} DBC_NET_IF_DATA; |
|||
|
|||
|
|||
typedef struct S_DBC_NODE_DATA{ |
|||
uint32_t node_id; |
|||
uint32_t aux_id; |
|||
uint32_t aux_parameter; |
|||
uint8_t type; |
|||
bool online; |
|||
uint32_t tss; |
|||
uint32_t tsm; |
|||
char name[128]; |
|||
}DBC_NODE_DATA; |
|||
|
|||
typedef struct S_DBC_MODULE_DATA{ |
|||
uint32_t module_id; |
|||
uint32_t aux_id; |
|||
uint32_t type; |
|||
bool enabled; |
|||
char name[128]; |
|||
}DBC_MODULE_DATA; |
|||
|
|||
typedef struct S_DBC_MODULE_EMBED_VIDEO_DATA{ |
|||
uint8_t output_mode; |
|||
uint16_t port; |
|||
bool show_ts; |
|||
bool show_label; |
|||
bool show_logo; |
|||
uint16_t width; |
|||
uint16_t height; |
|||
uint8_t compression_quality; |
|||
int ts_x; |
|||
int ts_y; |
|||
uint8_t ts_font_face; |
|||
float ts_font_scale; |
|||
int8_t ts_font_thickness; |
|||
int ts_line_type; |
|||
bool ts_transperant; |
|||
int label_x; |
|||
int label_y; |
|||
uint8_t label_font_face; |
|||
float label_font_scale; |
|||
int8_t label_font_thickness; |
|||
int label_line_type; |
|||
bool label_transperant; |
|||
uint8_t logo_w; |
|||
uint8_t logo_h; |
|||
int logo_x; |
|||
int logo_y; |
|||
char logo_md5[33]; |
|||
}DBC_MODULE_EMBED_VIDEO_DATA; |
|||
|
|||
/* |
|||
typedef struct S_DBC_SOCKET_DATA{ |
|||
uint32_t socket_id; |
|||
uint32_t node_id; |
|||
uint32_t aux_id; |
|||
uint32_t type; |
|||
uint32_t state; |
|||
uint32_t mode; |
|||
bool binded; |
|||
char path[128]; |
|||
char name[128]; |
|||
}DBC_SOCKET_DATA; |
|||
*/ |
|||
|
|||
typedef struct S_DBC_RESOURCE_DATA{ |
|||
uint32_t id; |
|||
uint32_t node_id; |
|||
uint32_t aux_id; |
|||
uint8_t type; |
|||
char device[64]; |
|||
}DBC_RESOURCE_DATA; |
|||
|
|||
|
|||
#define CMD_KRNL_SYSTEM_TASK 120 |
|||
#define CMD_KRNL_RELOAD 128 |
|||
#define CMD_KRNL_DELNODE 240 |
|||
#define CMD_KRNL_RESET_SITE 245 |
|||
#define CMD_KRNL_RESTART 250 |
|||
#define CMD_KRNL_PNP 251 |
|||
#define CMD_KRNL_SYNC_TIME 252 |
|||
#define CMD_KRNL_OS_REBOOT 253 |
|||
#define CMD_KRNL_FACTORY_RESET 254 |
|||
#define CMD_KRNL_SHUTDOWN 255 |
|||
|
|||
|
|||
#define CMD_MODULES_RELOAD 60 |
|||
#define CMD_MODULE_ENABLE 61 |
|||
#define CMD_MODULE_DISABLE 62 |
|||
#define CMD_NODES_RELOAD 80 |
|||
#define CMD_NODE_RELOAD 81 |
|||
#define CMD_NODE_UPDATE 82 |
|||
#define CMD_ROI_GEO 40 |
|||
#define CMD_PTZ_GEO 41 |
|||
#define CMD_PTZ_ONVIF 42 |
|||
#define CMD_PTZ_MOVE 43 |
|||
#define CMD_HARDWARE_DETECT 27 |
|||
|
|||
#define CMD_STATUS_NEW 0 |
|||
#define CMD_STATUS_ACTIVE 1 |
|||
#define CMD_STATUS_FINISHED 2 |
|||
|
|||
#define DBC_CMD_STARTED 1 |
|||
#define DBC_CMD_FINISHED 100 |
|||
#define DBC_CMD_FINISHED_ERROR 128 |
|||
#define DBC_CMD_READY_TO_CLEAN 250 |
|||
|
|||
|
|||
typedef struct S_DBC_PUSHED_CMD{ |
|||
uint32_t id; |
|||
uint8_t CMD; |
|||
char PARAM[256]; |
|||
}DBC_PUSHED_CMD; |
|||
|
|||
typedef struct S_ROI_CMD_DATA{ |
|||
uint16_t az_d; |
|||
uint16_t el_d; |
|||
uint16_t r_d; |
|||
}ROI_CMD_DATA; |
|||
|
|||
typedef struct S_DBC_MEDIA_STREAM_DATA{ |
|||
uint32_t id; |
|||
uint32_t source_id; |
|||
char source_type[2]; |
|||
bool valid; |
|||
char token[65]; |
|||
uint32_t width; |
|||
uint32_t height; |
|||
uint8_t fps; |
|||
char c_type[7]; |
|||
char mrl_proto[6]; |
|||
uint16_t mrl_port; |
|||
char mrl[251]; |
|||
}DBC_MEDIA_STREAM_DATA; |
|||
|
|||
typedef struct S_DBC_MEDIA_SERVER_DATA{ |
|||
uint32_t id; |
|||
char key[46]; |
|||
char ip[16]; |
|||
uint16_t port; |
|||
char host[64]; |
|||
bool recording; |
|||
bool local; |
|||
char docRoot[256]; |
|||
char name[128]; |
|||
}DBC_MEDIA_SERVER_DATA; |
|||
|
|||
typedef struct S_DBC_MEDIA_SERVER_STREAM_DATA{ |
|||
uint32_t id; |
|||
uint32_t media_stream_id; |
|||
bool online; |
|||
char key[64]; |
|||
char mrl[128]; |
|||
} DBC_MEDIA_SERVER_STREAM_DATA; |
|||
|
|||
#define LRF_MAX_DETECTION_PROFILES 4 |
|||
|
|||
typedef struct S_LRF_DETECTION_PROFILE{ |
|||
uint16_t order; |
|||
uint16_t offset; |
|||
uint16_t delta; |
|||
uint16_t flip; |
|||
uint32_t width; |
|||
uint16_t sst; |
|||
uint16_t sun; |
|||
uint16_t gp; |
|||
uint16_t spikes; |
|||
}LRF_DETECTION_PROFILE; |
|||
|
|||
typedef struct S_DBC_LRF_DATA{ |
|||
uint32_t id; |
|||
uint8_t data_status; |
|||
char serial[65]; |
|||
char version[129]; |
|||
float x; |
|||
float y; |
|||
float z; |
|||
float x_rot; |
|||
float y_rot; |
|||
float z_rot; |
|||
uint32_t filter_id; |
|||
uint32_t uart_id; |
|||
uint32_t device_id; |
|||
char master_host[64]; |
|||
uint16_t master_port; |
|||
char slave_host[64]; |
|||
uint8_t auto_draw; |
|||
uint16_t slave_port; |
|||
uint16_t enabled_lrf; |
|||
float max_range; |
|||
int32_t base_shift; |
|||
int32_t mirror_shift; |
|||
uint8_t detection_profile_id; |
|||
uint8_t draw_lrf_id; |
|||
uint32_t width_table_id; |
|||
uint32_t zoom_table_id; |
|||
uint8_t embd_cam; |
|||
bool embd_cam_auto; |
|||
uint8_t embd_dc; |
|||
bool autoreset; |
|||
bool force_settings; |
|||
//LRF_DETECTION_PROFILE mlrf_profile[LRF_MAX_DETECTION_PROFILES]; |
|||
//LRF_DETECTION_PROFILE slrf_profile[LRF_MAX_DETECTION_PROFILES]; |
|||
//LRF_DETECTION_PROFILE *mlrf_profile; |
|||
//LRF_DETECTION_PROFILE *slrf_profile; |
|||
}DBC_LRF_DATA; |
|||
|
|||
typedef struct S_DBC_UART_DATA{ |
|||
uint8_t type; |
|||
uint8_t mode; |
|||
char path[128]; |
|||
uint16_t port; |
|||
uint32_t speed; |
|||
float stop_bits; |
|||
uint8_t flow_ctrl; |
|||
}DBC_UART_DATA; |
|||
|
|||
typedef struct S_EVT_DATA{ |
|||
uint32_t id; |
|||
uint32_t node_id; |
|||
char uuid[65]; |
|||
uint32_t ts_s; |
|||
uint32_t ts_ms; |
|||
uint8_t type; |
|||
uint32_t ref_id; |
|||
char ref_uuid[65]; |
|||
}EVT_DATA; |
|||
|
|||
typedef struct S_DBC_EVT_RECORD{ |
|||
uint32_t id; |
|||
uint32_t node_id; |
|||
char uuid[65]; |
|||
uint32_t ts_s; |
|||
uint32_t ts_ms; |
|||
uint8_t type; |
|||
uint8_t lrf_id; |
|||
uint32_t range_digital; |
|||
float az; |
|||
float el; |
|||
float ra; |
|||
float area; |
|||
float lat; |
|||
float lon; |
|||
float alt; |
|||
uint32_t ref_id; |
|||
char ref_uuid[65]; |
|||
}DBC_EVT_RECORD; |
|||
|
|||
typedef struct S_DBC_SITE_DATA{ |
|||
uint32_t account_id; |
|||
char name[129]; |
|||
char ident[33]; |
|||
float lat; |
|||
float lon; |
|||
float alt; |
|||
bool SH; |
|||
uint8_t map_id; |
|||
bool local_binding; |
|||
}DBC_SITE_DATA; |
|||
|
|||
typedef struct S_DBC_FH_DATA{ |
|||
char name[129]; |
|||
float lat; |
|||
float lon; |
|||
float alt; |
|||
uint32_t dc_id; |
|||
uint32_t uart_id; |
|||
}DBC_FH_DATA; |
|||
|
|||
typedef struct S_DBC_TARGET_FLITER_DATA{ |
|||
uint32_t id; |
|||
uint8_t type; |
|||
uint32_t aux_id; |
|||
}DBC_TARGET_FLITER_DATA; |
|||
|
|||
|
|||
typedef struct S_DBC_APF_DATA{ |
|||
uint16_t port; |
|||
char mode[3]; |
|||
float lat; |
|||
float lon; |
|||
float alt; |
|||
float pitch; |
|||
float yaw; |
|||
float roll; |
|||
float dx; |
|||
float dy; |
|||
float dz; |
|||
}DBC_APF_DATA; |
|||
|
|||
typedef struct S_DBC_MODEM_MANAGER_DATA{ |
|||
uint32_t id; |
|||
uint32_t time_window; |
|||
uint32_t evt_trigers; |
|||
}DBC_MODEM_MANAGER_DATA; |
|||
|
|||
typedef struct S_DBC_MODEM_DATA{ |
|||
uint32_t id; |
|||
uint32_t modem_id; |
|||
char imei[17]; |
|||
char dbus_dev_id[65]; |
|||
char hw_model[65]; |
|||
char hw_manufac[65]; |
|||
char hw_revision[65]; |
|||
char hw_version[33]; |
|||
char hw_id[33]; |
|||
uint32_t at_uart_id; |
|||
uint32_t at_uart_id_aux; |
|||
char sim_pin[7]; |
|||
char sim_pin2[7]; |
|||
char sim_puk[7]; |
|||
char sim_puk2[7]; |
|||
char status[2]; |
|||
char power[2]; |
|||
uint8_t signal; |
|||
uint32_t operator_id; |
|||
char conmection_tech[6]; |
|||
char registration[65]; |
|||
}DBC_MODEM_DATA; |
|||
|
|||
typedef struct S_DBC_3DLRF_WSTAT{ |
|||
|
|||
}DBC_3DLRF_WSTAT; |
|||
|
|||
typedef struct S_DBC_MASKING_POINT{ |
|||
|
|||
}DBC_MASKING_POINT; |
|||
|
|||
typedef struct S_DBC_MASKING_RAY{ |
|||
|
|||
}DBC_MASKING_RAY; |
|||
|
|||
typedef struct S_DBC_MASKING_VERTEX{ |
|||
uint32_t mask_id; |
|||
uint8_t color[3]; |
|||
uint32_t vertex_id; |
|||
uint16_t points_cnt; |
|||
DBC_MASKING_POINT * points; |
|||
}DBC_MASKING_VERTEX; |
|||
|
|||
typedef struct S_DBC_ZONE_MASK{ |
|||
uint32_t id; |
|||
uint8_t status; |
|||
uint16_t vertexes_cnt; |
|||
DBC_MASKING_VERTEX * vertexes; |
|||
uint16_t rays_cnt; |
|||
DBC_MASKING_RAY rays; |
|||
}DBC_ZONE_MASK; |
|||
|
|||
typedef struct S_DBC_CAP_DATA{ |
|||
char md5[33]; |
|||
char ext[5]; |
|||
}DBC_CAP_DATA; |
|||
|
|||
typedef std::vector<uint32_t> DBC_INT_LIST; |
|||
typedef std::vector<DBC_CAM_DATA*> vectorCamRecords; |
|||
typedef std::vector<DBC_EVT_RECORD*> vectorEventRecords; |
|||
|
|||
typedef struct S_DBC_SNAPSHOT_DATA{ |
|||
char md5[33]; |
|||
DBC_INT_LIST assoc_event_ids; |
|||
uint32_t stream_id; |
|||
uint32_t ts; |
|||
uint32_t data_size; |
|||
uint8_t * data; |
|||
}DBC_SNAPSHOT_DATA; |
|||
|
|||
typedef struct S_DBC_SYS_INFO{ |
|||
char OS_INFO[128]; |
|||
char HW_INFO[128]; |
|||
char SW_INFO[128]; |
|||
}DBC_SYS_INFO; |
|||
|
|||
typedef struct S_DBC_SYS_LOAD_INFO{ |
|||
//Percs |
|||
float cpu1; |
|||
float cpu5; |
|||
float cpu15; |
|||
float mem; |
|||
float disk; |
|||
float temperature; |
|||
// Abs |
|||
uint64_t T_MEM; |
|||
uint64_t T_DISK; |
|||
uint64_t C_MEM; |
|||
uint64_t C_DISK; |
|||
uint32_t CPU_CORES; |
|||
}DBC_SYS_LOAD_INFO; |
|||
|
|||
typedef struct S_DBC_SSDP_SETTINGS{ |
|||
|
|||
}DBC_SSDP_SETTINGS; |
|||
|
|||
#endif |
|||
@ -0,0 +1,119 @@ |
|||
#include "deviceNode.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "NODE", 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( "NODE", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "NODE", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
deviceNode::deviceNode( uint32_t id ):basicEngine(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
m_mCommandProtector.unlock(); |
|||
if( m_pDBC != NULL ) { |
|||
DBC_NODE_DATA *tData = m_pDBC->getNodeData( id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sNodeData , tData, sizeof(DBC_NODE_DATA)); |
|||
m_sNodeData.online = m_pDBC->setNodeOnline( m_sNodeData.node_id ); |
|||
free( tData ); |
|||
} else { |
|||
memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA)); |
|||
m_sNodeData.type = ARGUS_UNKNOWN; |
|||
m_sNodeData.node_id = id; |
|||
}; |
|||
} else { |
|||
memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA)); |
|||
m_sNodeData.type = ARGUS_UNKNOWN; |
|||
m_sNodeData.node_id = id; |
|||
}; |
|||
}; |
|||
|
|||
deviceNode::deviceNode( DBC_NODE_DATA *Data ):basicEngine(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
m_mCommandProtector.unlock(); |
|||
if( Data ) { |
|||
memcpy( &m_sNodeData , Data, sizeof(DBC_NODE_DATA)); |
|||
if( m_pDBC ) { |
|||
m_sNodeData.online = m_pDBC->setNodeOnline( m_sNodeData.node_id ); |
|||
}; |
|||
} else { |
|||
memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA)); |
|||
m_sNodeData.type = ARGUS_UNKNOWN; |
|||
}; |
|||
}; |
|||
|
|||
deviceNode::~deviceNode(){ |
|||
m_mCommandProtector.lock(); |
|||
if( m_qCommands.size() ) { |
|||
NI_COMMAND *tVal = NULL; |
|||
while( tVal = m_qCommands.front() ){ |
|||
m_qCommands.pop(); |
|||
if( tVal->parameter ) { |
|||
free( tVal->parameter ); |
|||
}; |
|||
free( tVal ); |
|||
}; |
|||
}; |
|||
m_mCommandProtector.unlock(); |
|||
m_pDBC->setNodeOffline( m_sNodeData.node_id ); |
|||
}; |
|||
|
|||
|
|||
NI_COMMAND *deviceNode::fetchCommand(){ |
|||
NI_COMMAND *RetVal = NULL; |
|||
m_mCommandProtector.lock(); |
|||
if( m_qCommands.size() ) { |
|||
RetVal = m_qCommands.front(); |
|||
m_qCommands.pop(); |
|||
}; |
|||
m_mCommandProtector.unlock(); |
|||
return RetVal; |
|||
}; |
|||
|
|||
void deviceNode::enqueueCommand( NI_COMMAND *ptr ){ |
|||
if( ptr ) { |
|||
m_mCommandProtector.lock(); |
|||
m_qCommands.push( ptr ); |
|||
m_mCommandProtector.unlock(); |
|||
}; |
|||
}; |
|||
|
|||
bool deviceNode::validate(){ |
|||
DBC_NODE_DATA *tDATA = m_pDBC->getNodeData( m_sNodeData.node_id ); |
|||
if( tDATA ) { |
|||
if( memcmp( &m_sNodeData, tDATA, sizeof(DBC_NODE_DATA)) != 0 ){ |
|||
free( tDATA ); |
|||
LOG("Node Settings Changed!"); |
|||
return false; |
|||
}; |
|||
free( tDATA ); |
|||
} else { |
|||
LOG("Node is Deleted!"); |
|||
return false; |
|||
}; |
|||
return true; |
|||
}; |
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,42 @@ |
|||
#ifndef __DEVICE_NODE_HEADER__ |
|||
#define __DEVICE_NODE_HEADER__ |
|||
|
|||
#include "../../components/base/basicEngine.h" |
|||
#include "dataBinder.h" |
|||
#include <queue> |
|||
#include <vector> |
|||
#include <map> |
|||
|
|||
typedef struct S_NI_COMMAND{ |
|||
uint8_t cmd; |
|||
uint32_t db_cmd; |
|||
void * parameter; |
|||
}NI_COMMAND; |
|||
|
|||
typedef std::queue<NI_COMMAND *> queueNI_COMMANDS; |
|||
|
|||
class deviceNode: public basicEngine{ |
|||
private: |
|||
queueNI_COMMANDS m_qCommands; |
|||
basicMutex m_mCommandProtector; |
|||
protected: |
|||
basicLogCollection * m_pLog; |
|||
dataBinder * m_pDBC; |
|||
DBC_NODE_DATA m_sNodeData; |
|||
NI_COMMAND * fetchCommand(); |
|||
public: |
|||
explicit deviceNode( uint32_t id ); |
|||
explicit deviceNode( DBC_NODE_DATA *Data ); |
|||
virtual ~deviceNode(); |
|||
uint32_t getNodeID() const { return m_sNodeData.node_id; }; |
|||
uint32_t getDeviceID() const { return m_sNodeData.aux_id; }; |
|||
ARGUS_NODE_TYPE getNodeType() const { return (ARGUS_NODE_TYPE) m_sNodeData.type; }; |
|||
bool isNodeOnline( void ) const { return m_sNodeData.online; }; |
|||
void enqueueCommand( NI_COMMAND *ptr ); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
typedef std::vector<deviceNode*> vectorDeviceNodes; |
|||
typedef std::map<uint32_t,deviceNode*> mapDeviceNode2Id; |
|||
|
|||
#endif |
|||
2157
lib/App/common/deviceNode2D.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,148 @@ |
|||
#ifndef __OBJECT_NET_NODE_2D_HEADERS__ |
|||
#define __OBJECT_NET_NODE_2D_HEADERS__ |
|||
|
|||
#include "deviceNodeSensor.h" |
|||
#include <cfloat> //For DBL_MAX |
|||
#include <stdlib.h> |
|||
|
|||
#include "../../components/base/basicObject.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../components/base/basicThread.h" |
|||
#include "../../components/base/basicLogCollection.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "../../alg/lgs/mask.h" |
|||
#include "../../data/protocol/protocolLGS2D.h" |
|||
|
|||
#define LGS_DEFAULT_SLEEP_TIME 100 |
|||
#define LGS_ALERT_SLEEP_TIME 1 |
|||
#define LGS_DEFAULT_TO_COUNTER 10 |
|||
#define LGS_INITIAL_FLIPS 8 |
|||
|
|||
#define ANODE_WM_2D_BEFORE_START 0 |
|||
#define ANODE_WM_2D_CREATE_PORT 1 |
|||
#define ANODE_WM_2D_CONNECT 2 |
|||
#define ANODE_WM_2D_WAIT_CONNECT 3 |
|||
#define ANODE_WM_2D_SET_INIT_MODE 4 |
|||
#define ANODE_WM_2D_GET_SERIAL_NUM 6 |
|||
#define ANODE_WM_2D_GET_VERSION 8 |
|||
#define ANODE_WM_2D_GET_DETECTION_PROFILE 10 |
|||
#define ANODE_WM_2D_GET_MASTER_PARAM 12 |
|||
#define ANODE_WM_2D_GET_SLAVE_PARAM 14 |
|||
#define ANODE_WM_2D_GET_MASK_INFO 16 |
|||
#define ANODE_WM_2D_SET_MASK_INFO 18 |
|||
|
|||
|
|||
|
|||
#define ANODE_WM_2D_SET_BORDER_MODE 32 |
|||
#define ANODE_WM_2D_GET_FAST_DRAW 34 |
|||
#define ANODE_WM_2D_SET_DETECTION_MODE 36 |
|||
#define ANODE_WM_2D_SET_FILESYSTEM_MODE 38 |
|||
#define ANODE_WM_2D_FS_TRANSFER_MODE 39 |
|||
|
|||
#define ANODE_WM_2D_SET_SHADOW_DONE 40 |
|||
#define ANODE_WM_2D_GET_SHADOW_POLY_INFO 41 |
|||
#define ANODE_WM_2D_GET_SHADOW_POLY_POINT 43 |
|||
#define ANODE_WM_2D_SET_SHADOW_POLY_INFO 45 |
|||
#define ANODE_WM_2D_SET_SHADOW_POLY_POINT 47 |
|||
#define ANODE_WM_2D_SET_SHADOW_RAY_LINE 48 |
|||
#define ANODE_WM_2D_SET_SHADOW_RAY 49 |
|||
|
|||
#define ANODE_WM_2D_SET_GETFILE_MODE 50 |
|||
#define ANODE_WM_2D_SEND_GETFILE_MODE 52 |
|||
#define ANODE_WM_2D_SET_MASTER_PARAM 58 |
|||
#define ANODE_WM_2D_SET_SLAVE_PARAM 59 |
|||
#define ANODE_WM_2D_ISSUE_FULL_RESET 64 |
|||
|
|||
#define ANODE_WM_2D_ISSUE_RESET 66 |
|||
|
|||
#define ANODE_WM_2D_PING 128 |
|||
#define ANODE_WM_2D_PONG 129 |
|||
|
|||
#define ANODE_WM_2D_SLEEP_AND_RECONNECT 130 |
|||
#define ANODE_WM_2D_WAIT_DEVICE_REPLAY 254 |
|||
#define ANODE_WM_2D_WAIT_CHECK_REPLAY 255 |
|||
|
|||
#define ANODE_2D_MAX_DRAW_ANGLES 6000 |
|||
|
|||
#define ARGUS_DS_NONE 0 |
|||
#define ARGUS_DS_CREATED 1 |
|||
#define ARGUS_DS_GET_CONFIG 2 |
|||
#define ARGUS_DS_VALID 3 |
|||
#define ARGUS_DS_CONF_MISTMATCH 4 |
|||
|
|||
typedef struct S_SHADOW_IO_HELPER{ |
|||
uint16_t m_nCurrentPolygon; |
|||
uint16_t m_nCurrentPoint; |
|||
uint16_t m_nCurrentRayLine; |
|||
uint16_t m_nCurrentRay; |
|||
}SHADOW_IO_HELPER; |
|||
|
|||
typedef struct S_GETFILE_IO_HELPER{ |
|||
uint32_t fileSize; |
|||
uint32_t index; |
|||
char destName[33]; |
|||
char sourceName[33]; |
|||
uint8_t state; |
|||
FILE * fd; |
|||
uint8_t data[250]; |
|||
uint8_t data_size; |
|||
}GETFILE_IO_HELPER; |
|||
|
|||
typedef struct S_TEST_POINT{ |
|||
float x; |
|||
float y; |
|||
}TEST_POINT; |
|||
|
|||
class device2DSensor: public deviceNodeSensor, public basicThread, public protocolLGS_2D{ |
|||
private: |
|||
//basicLogCollection * m_pLog; |
|||
uint8_t m_bPortType; |
|||
basicTransport * m_pPort; |
|||
|
|||
uint8_t m_bDeviceWM; |
|||
uint32_t m_nSleepTime; |
|||
uint16_t m_bTimeOutCounter; |
|||
uint8_t m_bInitialFlips; |
|||
uint16_t m_nCurrentAngle; |
|||
uint8_t m_bDrawType; |
|||
uint8_t m_bOpRetryCnt; |
|||
uint32_t m_nProcessingCmdId; |
|||
uint32_t m_vDrawRanges[ANODE_2D_MAX_DRAW_ANGLES]; |
|||
bool m_bDeviceIsSynced; |
|||
bool m_bSerialStringValid; |
|||
bool m_bVersionStringValid; |
|||
char m_tSN[65]; |
|||
char m_tSV[129]; |
|||
char m_sCurrentFile[MAX_PATH]; |
|||
uint32_t m_nUploadID; |
|||
uint8_t m_nActiveDetectionProfile; |
|||
//Shadow |
|||
SHADOW_IO_HELPER m_sShadowHelper; |
|||
SHADOW m_sShadow; |
|||
//GetFile |
|||
GETFILE_IO_HELPER m_sGetFileHelper; |
|||
|
|||
TARGET_DATA * prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0 ); |
|||
//void saveRawDrawData( uint16_t alngles ); |
|||
void cleanupDeviceStructures(); |
|||
CSTR generateSettingFile(); |
|||
void cleanShadowStructs(); |
|||
bool PtInPolygons( TEST_POINT& point, uint8_t F ); |
|||
bool PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point ); |
|||
bool rasterizeShadow(); |
|||
#ifdef DEBUG_EXTRA |
|||
void makeShadowPic( CSTR picname ); |
|||
#endif |
|||
protected: |
|||
virtual bool packetHandler( protocolPackage *Package ); |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit device2DSensor( uint32_t id ); |
|||
~device2DSensor(); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual bool validate(); |
|||
virtual void simulateTarget( void ); |
|||
}; |
|||
|
|||
#endif |
|||
1769
lib/App/common/deviceNode3D.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,140 @@ |
|||
#ifndef __DEVICE_NODE_3D_HEADERS__ |
|||
#define __DEVICE_NET_NODE_3D_HEADERS__ |
|||
|
|||
#include "../components/base/basicEngine.h" |
|||
#include "../components/base/basicDualThread.h" |
|||
#include "../components/base/basicLogCollection.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
#include "../components/base/basicPosition.h" |
|||
#include "../components/object/objectSystemAnchor.h" |
|||
#include "../components/base/basicSettingsProvider.h" |
|||
#include "../alg/lgs/mask.h" |
|||
|
|||
#include "../data/net/clientPort.h" |
|||
#include "../data/protocol/protocolLGS3D_client.h" |
|||
#include "../hardware/soc/general/3DLRF.h" |
|||
|
|||
|
|||
//#include "../hardware/sensors/lrf/lrf_3d.h" |
|||
|
|||
#include "deviceNodeSensor.h" |
|||
|
|||
//#define SIMULATE_3D_TARGETS |
|||
|
|||
#ifdef SIMULATE_3D_TARGETS |
|||
#include "../components/base/basicSettingsProvider.h" |
|||
#endif |
|||
|
|||
#define LGS_TIMEOUT_COUNT 100 |
|||
#define LGS_MAX_IDLE_DELAY 40 // x10 msec |
|||
#define LGS_MIN_IDLE_DELAY 1 // x10 msec |
|||
|
|||
#define USE_MUTEX true |
|||
#define DONT_USE_MUTEX false |
|||
|
|||
class device3DSensor: public deviceNodeSensor, public basicThread, public protocolLGS3D_Client{ |
|||
private: |
|||
//basicLogCollection * m_pLog; |
|||
//basicEventHeap * m_pEventHeap; |
|||
|
|||
//DBC_LRF_DATA m_sDATA; |
|||
|
|||
//LGS_3D_PARAMETERS m_sLGS_MASTER_PARAMETERS; |
|||
//LGS_3D_PARAMETERS m_sLGS_SLAVE_PARAMETERS; |
|||
|
|||
//DEVICE_STATUS m_sDeviceStatus; |
|||
//SOFTWARE_INFO m_sDeviceSoftNFO; |
|||
|
|||
//char m_pHost[255]; |
|||
//uint16_t m_nPort; |
|||
bool m_bTWINC; |
|||
uint8_t m_bSlaveConnectionStatus; |
|||
int m_nBusyCounter; |
|||
int m_nIdleCounter; |
|||
int m_nIdleTarget; |
|||
|
|||
basicMutex m_mPackageMutex; |
|||
basicMutex m_mStatusMutex; |
|||
basicMutex m_mDataMutex; |
|||
|
|||
thresholdNode * m_pThresholdData; |
|||
|
|||
uint32_t m_nFullBorderDataIndex; |
|||
uint8_t m_nFullBorderKernelIndex; |
|||
|
|||
uint8_t m_nDevicePolyCount; |
|||
uint32_t m_nCurrentPolyID; |
|||
uint32_t m_nCurrentMaskID; |
|||
ShadowMask * m_pShadow; |
|||
|
|||
#ifdef SIMULATE_3D_TARGETS |
|||
config_setting_t * m_pSimulationConfig; |
|||
basicPosition m_oIntruder_Start; |
|||
basicPosition m_oIntruder_Finish; |
|||
|
|||
basicPosition m_oIntruder_; |
|||
C3D_DECART m_dIntruderMove; |
|||
float m_dIntruderSpeed; |
|||
|
|||
int m_nIntruder_time; |
|||
|
|||
basicPosition m_oHunter_Home; |
|||
basicPosition m_oHunter_; |
|||
C3D_DECART m_dHunterMove; |
|||
float m_dHunterSpeed; |
|||
|
|||
uint8_t m_bSymStage; |
|||
|
|||
bool IntruderIsVisible(); |
|||
bool HunterIsVisible(); |
|||
void headIntruderTo( basicPosition &bp ); |
|||
void headHunterTo( basicPosition &bp ); |
|||
void restartSimulation( void ); |
|||
TARGET_DATA * prepareSimData( basicPosition &bp ); |
|||
uint32_t m_nAutoScript; |
|||
#endif |
|||
|
|||
bool setOperation( E_LGS_CMD opCode, bool fNOW = false ); |
|||
bool forceOperation( E_LGS_CMD opCode ); |
|||
void setCompelition( uint8_t Perc ); |
|||
E_LGS_CMD getOperation( void ); |
|||
void promoteOperation( void ); |
|||
void completeOperation( bool success = true ); |
|||
void cleanOperation( void ); |
|||
void comSetIdle( bool useMutex = true ); |
|||
void comSetBusy( bool useMutex = true ); |
|||
bool comIsIdle( void ); |
|||
void cleanDataTH( void ); |
|||
bool saveTHPicture( thresholdNode *ptr, CSTR uid, bool master = true, bool byMinimum = false, bool monochrome = false ); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
virtual bool packetHandler( protocolPackage* Package ); |
|||
public: |
|||
TARGET_DATA * prepareTargetData(CLIENT_EVENT* CE); |
|||
explicit device3DSensor( uint32_t dbID ); |
|||
virtual ~device3DSensor(); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual bool validate(); |
|||
virtual void simulateTarget( void ); |
|||
|
|||
bool startGetScanData( uint8_t kID = 0, uint32_t *th_zone = NULL ); |
|||
bool startGetParameters( uint32_t timeout=0 ); |
|||
bool startUploadMask(void); |
|||
bool startDeviceReset( bool FullReset = true ); |
|||
bool startStopMotors( void ); |
|||
bool startStartMotors( void ); |
|||
bool startMasksStatus(bool Active); |
|||
|
|||
basicPosition * getPosition(void){ return &m_oPosition; }; |
|||
void updateSettings(void); |
|||
|
|||
// New Order |
|||
thresholdNode * grabDataAccess( void ); |
|||
void releaseDataAccess( void ); |
|||
|
|||
bool lastTaskComplete( void ); |
|||
void cleanLastTaskStatus( void ); |
|||
}; |
|||
|
|||
#endif |
|||
1432
lib/App/common/deviceNodeCamera.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,202 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// 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 __DEVICE_NODE_CAMERA_HEADER__ |
|||
#define __DEVICE_NODE_CAMERA_HEADER__ |
|||
|
|||
#include <vector> |
|||
#include <queue> |
|||
#include "../../components/base/basicThread.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../data/protocol/protocolPTZ.h" |
|||
|
|||
#include "../../components/base/basicEventHeap.h" |
|||
//#include "rgooseDBConnector.h" |
|||
#include "deviceNode.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 |
|||
|
|||
#define CAM_CTRL_PROTO_VISCA 1 |
|||
#define CAM_CTRL_PROTO_PELCO 2 |
|||
#define CAM_CTRL_PROTO_ONVIF 3 |
|||
#define CAM_CTRL_PROTO_PSIA 4 |
|||
#define CAM_CTRL_PROTO_T28181 5 |
|||
|
|||
#define UART_TYPE_HARDWARE 1 |
|||
#define UART_TYPE_SOL 2 |
|||
|
|||
#define ARGUS_CAM_PCMD_MOVE_MASK 0x7F |
|||
#define ARGUS_CAM_PCMD_CMD_MASK 0x80 |
|||
#define ARGUS_CAM_PCMD_STOP 1 |
|||
|
|||
|
|||
typedef struct S_CAM_PTZ_CMD{ |
|||
uint8_t CMD; |
|||
float PAN; |
|||
float TILT; |
|||
float ZOOM; |
|||
}CAM_PTZ_CMD; |
|||
|
|||
typedef enum E_CAM_PTZ_CMD{ |
|||
PTZ_STOP = 0, |
|||
PTZ_MOVE = 1, |
|||
PTZ_ABSOLUTE = 2, |
|||
PTZ_RELOAD_CAMERA = 3, |
|||
PTZ_CAPTURE_ONLY = 4 |
|||
}PTZ_CMD; |
|||
|
|||
typedef std::queue<CAM_PTZ_CMD *> CAM_PTZ_CMD_QUEUE; |
|||
|
|||
typedef enum E_CAM_WORKING_STATE{ |
|||
CAM_WS_INIT = 0, |
|||
CAM_WS_WHITE_BALLANCE = 1, |
|||
CAM_WS_BACKLIGHT = 2, |
|||
CAM_WS_AUTO_FOCUS = 3, |
|||
CAM_WS_INIT_GO_HOME = 4, |
|||
CAM_WS_AUTOMATED_MOVE = 10, |
|||
CAM_WS_STOP_MOVE = 11, |
|||
CAM_WS_GO_ABS_POSITION = 12, |
|||
CAM_WS_READY = 64, |
|||
CAM_WS_BUSY = 128, |
|||
CAM_WS_END = 255 |
|||
}CAM_WORK_STATE; |
|||
|
|||
typedef struct S_CAM_TASK{ |
|||
bool isDone; |
|||
uint32_t source_evt_id; |
|||
bool movemet_needed; |
|||
CAM_PTZ_CMD * CMD; |
|||
} CAM_TASK; |
|||
|
|||
typedef std::queue<CAM_TASK *> CAM_TASK_QUEUE; |
|||
|
|||
typedef struct S_CAM_TRACK_RECORD{ |
|||
C3D_SPH_DEGREES target_direction; |
|||
uint32_t evt_db_ID; |
|||
uint64_t ts_ms; |
|||
}CAM_TRACK_RECORD; |
|||
|
|||
typedef std::vector<CAM_TRACK_RECORD*> vCAM_TRACK_RECORDS; |
|||
|
|||
|
|||
|
|||
typedef struct S_CAM_ROI{ |
|||
C3D_ORIENT_ONVIF cam_orientation; |
|||
vCAM_TRACK_RECORDS targets; |
|||
uint64_t ts_ms; |
|||
/** to do fusion things - consume more targets **/ |
|||
C3D_SPH_DEGREES cam_position; |
|||
float h_fov; |
|||
float v_fov; |
|||
float min_range; |
|||
float max_range; |
|||
}CAM_ROI; |
|||
|
|||
typedef std::vector<CAM_ROI *> vCAM_ROIS; |
|||
|
|||
#define LOSE_INTERES_TIME_MS 2000 |
|||
|
|||
class deviceNodeCamera: public deviceNode, public basicThread { |
|||
private: |
|||
basicPosition m_oPosition; |
|||
time_t m_tTimeTSeconds; |
|||
CAM_ROI * m_pCurrentROI; |
|||
|
|||
float m_fMaxRange; |
|||
float m_fMinRange; |
|||
float m_fMaxFL; |
|||
float m_fMinFL; |
|||
float m_fR2FL; // Range to Focal Length |
|||
|
|||
uint16_t m_nRealFrameWidth; |
|||
uint16_t m_nRealFrameHeight; |
|||
float m_fMinHFov; |
|||
float m_fMaxHFov; |
|||
float m_fMinVFov; |
|||
float m_fMaxVFov; |
|||
|
|||
protocolPTZ * m_pProtocol; |
|||
basicTransport * m_pTransport; |
|||
|
|||
CAM_TASK_QUEUE m_qCAM_TASK; |
|||
basicMutex m_mQPROTECTOR; |
|||
|
|||
//videoAVLIBSource * m_pSource; |
|||
//videoLIVE555Source * m_pSource; |
|||
//basicMediaSource * m_pSource; |
|||
uint32_t m_nRelativeMoveCounter; |
|||
uint8_t m_bRelativeMoveMatrix; |
|||
float m_fSpeedRise; |
|||
float m_fRM_Pan; |
|||
float m_fRM_Tilt; |
|||
float m_fRM_Zoom; |
|||
|
|||
/* Methotds Sutable to Control Camera */ |
|||
bool relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ); |
|||
bool relativeStop(); |
|||
bool absoluteMove( uint32_t RefID, float PanPOS, float TiltPOS, float ZoomPOS ); |
|||
bool absoluteMove( uint32_t RefID, C3D_ORIENT_ONVIF O ); |
|||
|
|||
/* tracking Fusion methods */ |
|||
vCAM_ROIS m_vROIS; |
|||
basicMutex m_mROIsProtector; |
|||
bool fusion_consumeData( uint32_t db_id, C3D_SPH_DEGREES tOR ); |
|||
bool fusion_validateROI( uint64_t cts, CAM_ROI *ptr ); |
|||
bool fusion_compare( CAM_ROI *ptr, C3D_SPH_DEGREES tp ); |
|||
void fusion_validate( void ); |
|||
CAM_ROI * fusion_fetchROI( void ); |
|||
DBC_SNAPSHOT_DATA * fusion_translate_ROI( CAM_ROI *(&ptr) ); |
|||
void updateOpticalParameters( uint16_t frame_width, uint16_t frame_heigth ); |
|||
protected: |
|||
DBC_CAM_DATA m_sCamData; |
|||
MEDIA_SOURCE_DESC m_sMediaSource; |
|||
basicEventHeap * m_pBEH; |
|||
//bool m_bSourceConnected; |
|||
//uint32_t m_nActiveStreamID; |
|||
//bool inTheFOV( float lat, float lon, float alt ); |
|||
|
|||
bool testFOV( C3D_WGS84_LOC ); //Global Coords |
|||
bool testFOV( C3D_DECART ); //System Coords |
|||
bool testFOV( C3D_SPH_RADIANS ); //Local Coords |
|||
bool testFOV( C3D_SPH_DEGREES ); //Local Coords |
|||
|
|||
//bool lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt ); |
|||
bool lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ); // GLobal |
|||
bool lookAt( uint32_t TargetRefID, C3D_DECART L ); // System |
|||
bool lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ); // Local |
|||
bool lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ); // Local |
|||
|
|||
bool makeSnap( uint32_t TargetRefID ); |
|||
//void setBusy( bool Status ); |
|||
bool connectToStream( uint32_t id ); |
|||
bool disconnectFromStream( void ); |
|||
bool validateStream( void ); |
|||
CAM_TASK * fetchCamTask( void ); |
|||
bool pushCamTask( CAM_TASK * ); |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit deviceNodeCamera( uint32_t NodeID ); |
|||
explicit deviceNodeCamera( DBC_NODE_DATA *Data ); |
|||
virtual ~deviceNodeCamera(); |
|||
bool create(); |
|||
virtual bool validate(); |
|||
|
|||
}; |
|||
|
|||
typedef std::vector<deviceNodeCamera *> vectorNodeCameras; |
|||
|
|||
#endif |
|||
@ -0,0 +1,703 @@ |
|||
#include "deviceNodeEthernet2Serial.h"
|
|||
#include "hardwareManager.h"
|
|||
#include "../../data/protocol/protocol.h"
|
|||
|
|||
#define LOG( X ) deviceNode::m_pLog->Log( "E2UART", 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 );\ |
|||
deviceNode::m_pLog->Log( "E2UART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) deviceNode::m_pLog->Log( "E2UART", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
deviceETH2UART::deviceETH2UART( uint32_t nodeID ) : deviceNode( nodeID ), hardwareResource(), basicTransport(), basicDualThread(){ |
|||
//m_pLog = basicLogCollection::getInstance();
|
|||
memset( &m_sUartData, 0, sizeof(m_sUartData)); |
|||
m_nInputBufferSize = 0; |
|||
m_nOutputBufferSize = 0; |
|||
m_iDeviceFD = -1; |
|||
m_iMasterFD = -1; |
|||
m_iInFID = -1; |
|||
m_iOutFID = -1; |
|||
LOG("CREATE res!"); |
|||
hardwareResource::create( m_sNodeData.aux_parameter, HARDWARE_PROVIDER_SERIAL ); |
|||
}; |
|||
|
|||
deviceETH2UART::~deviceETH2UART(){ |
|||
closePort(); |
|||
hardwareManager *tH = hardwareManager::getInstance(); |
|||
if( tH ) tH->resignResource( this ); |
|||
}; |
|||
|
|||
bool deviceETH2UART::create( void ){ |
|||
DBC_UART_DATA *tDATA = NULL; |
|||
LOG("CREATE!"); |
|||
if( m_sResourceSettings.id == 0 ) return false; |
|||
if( m_sResourceSettings.aux_id == 0 ) return false; |
|||
|
|||
tDATA = deviceNode::m_pDBC->getUartData( m_sResourceSettings.aux_id ); |
|||
if( tDATA!= NULL ) { |
|||
memcpy( &m_sUartData, tDATA, sizeof(DBC_UART_DATA)); |
|||
#ifdef DEBUG
|
|||
LOG("KOKO!"); |
|||
LOG( m_sUartData.path ); |
|||
#endif
|
|||
free( tDATA ); |
|||
m_bValid = create_SOL(); |
|||
}; |
|||
|
|||
if ( m_bValid ) { |
|||
hardwareManager * tH = hardwareManager::getInstance(); |
|||
if( tH ) tH->assignResource( this ); |
|||
}; |
|||
return m_bValid; |
|||
}; |
|||
|
|||
bool deviceETH2UART::validate( void ){ |
|||
if( m_bValid ) { |
|||
m_bValid = pingDevice(); |
|||
if( !m_bValid ){ |
|||
LOG_ERROR("No Ping to device!"); |
|||
closePort(); |
|||
}; |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Check Settings For Changes"); |
|||
#endif
|
|||
DBC_UART_DATA *tDATA = deviceNode::m_pDBC->getUartData( m_sResourceSettings.aux_id ); |
|||
if( tDATA!= NULL ){ |
|||
bool bFlag = true; |
|||
if( strcmp(tDATA->path,m_sUartData.path)!= 0 ) bFlag = false; |
|||
//if( bFlag && ( m_sUartData.speed != tDATA->speed ) ) bFlag = false; //Speed for SOL port Erelevant
|
|||
if( bFlag && ( m_sUartData.mode != tDATA->mode ) ) bFlag = false; |
|||
if( bFlag && ( m_sUartData.port != tDATA->port ) ) bFlag = false; |
|||
if( !bFlag ) { |
|||
#ifdef DEBUG
|
|||
LOG("Settings Has been Changed!"); |
|||
#endif
|
|||
if( m_bValid ) closePort(); // if port not closed
|
|||
// Apply new settings
|
|||
memcpy( &m_sUartData, tDATA, sizeof(DBC_UART_DATA)); |
|||
#ifdef DEBUG
|
|||
LOG("Reconect with new settings"); |
|||
#endif
|
|||
m_bValid = create_SOL(); |
|||
}; |
|||
free( tDATA ); |
|||
} else { |
|||
LOG_ERROR("Error Fetch DB Data!"); |
|||
}; |
|||
// Finally in any case If Not Connected -> try to Connect!
|
|||
if( !m_bValid ) { |
|||
#ifdef DEBUG
|
|||
LOG("Try to Conncet"); |
|||
#endif
|
|||
m_bValid = create_SOL(); |
|||
}; |
|||
if( m_bValid ) m_bValid = deviceNode::validate(); |
|||
return m_bValid; |
|||
}; |
|||
|
|||
|
|||
#include <netinet/ip_icmp.h>
|
|||
// Define the Packet Constants
|
|||
// ping packet size
|
|||
#define PING_PKT_S 64
|
|||
|
|||
// Automatic port number
|
|||
#define PORT_NO 0
|
|||
|
|||
// Automatic port number
|
|||
#define PING_SLEEP_RATE 1000000
|
|||
|
|||
// Gives the timeout delay for receiving packets
|
|||
// in seconds
|
|||
#define RECV_TIMEOUT 1
|
|||
|
|||
// ping packet structure
|
|||
struct ping_pkt { |
|||
struct icmphdr hdr; |
|||
char msg[PING_PKT_S-sizeof(struct icmphdr)]; |
|||
}; |
|||
|
|||
bool deviceETH2UART::pingDevice(){ |
|||
bool RetVal = false; |
|||
if( m_bValid ) { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Pinging Device!"); |
|||
#endif
|
|||
int sockfd; |
|||
int ttl_val=64, msg_count=0, i, flag=1, msg_received_count=0; |
|||
struct ping_pkt pckt; |
|||
struct sockaddr_in ping_addr; |
|||
struct sockaddr_in r_addr; |
|||
struct timeval tv_out; |
|||
|
|||
tv_out.tv_sec = 0; |
|||
tv_out.tv_usec = 300000; // 1/3 of second
|
|||
|
|||
|
|||
ping_addr.sin_family = AF_INET; |
|||
ping_addr.sin_addr.s_addr = inet_addr( m_sUartData.path ); |
|||
//ping_addr.sin_port = htons( m_nPort );
|
|||
#ifdef DEBUG_EXTRA
|
|||
LOG( m_sUartData.path ); |
|||
#endif
|
|||
sockfd = socket( AF_INET, SOCK_RAW, IPPROTO_ICMP ); |
|||
if( sockfd < 0 ){ |
|||
LOG_ERROR("Socket file descriptor not received!"); |
|||
return false; |
|||
}; |
|||
|
|||
// set socket options at ip to TTL and value to 64,
|
|||
// change to what you want by setting ttl_val
|
|||
if( setsockopt( sockfd, SOL_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) != 0 ){ |
|||
LOG_ERROR("Setting socket options to TTL failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
}; |
|||
|
|||
// setting timeout of recv setting
|
|||
setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv_out, sizeof tv_out ); |
|||
|
|||
// flag is whether packet was sent or not
|
|||
flag=1; |
|||
|
|||
//filling packet
|
|||
bzero(&pckt, sizeof(pckt)); |
|||
|
|||
pckt.hdr.type = ICMP_ECHO; |
|||
pckt.hdr.un.echo.id = getpid(); |
|||
|
|||
for ( i = 0; i < sizeof(pckt.msg)-1; i++ ) pckt.msg[i] = i+'0'; |
|||
|
|||
pckt.msg[i] = 0; |
|||
pckt.hdr.un.echo.sequence = msg_count++; |
|||
pckt.hdr.checksum = checksumPing( &pckt, sizeof(pckt)); //checksum(&pckt, sizeof(pckt));
|
|||
|
|||
|
|||
//SLEEP( 300 );
|
|||
|
|||
//send packet
|
|||
if( sendto( sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&ping_addr, sizeof(ping_addr)) <= 0 ){ |
|||
LOG_ERROR("Packet Sending Failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
}; |
|||
|
|||
//receive packet
|
|||
socklen_t addr_len = sizeof(r_addr); |
|||
|
|||
if( recvfrom( sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&r_addr, &addr_len) <= 0 ){ |
|||
LOG_ERROR("Packet receive failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
} else { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Device Is OK!"); |
|||
#endif
|
|||
RetVal = true; |
|||
}; |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool deviceETH2UART::create_SOL(){ |
|||
|
|||
/*
|
|||
if( m_sUartData.mode == SOL_NOT_DEFINED ) { |
|||
LOG_ERROR("No Connection Type Defined!"); |
|||
return false; |
|||
}; |
|||
*/ |
|||
if( m_sUartData.port == 0 ) { |
|||
LOG_ERROR("No Port Defined!"); |
|||
return false; |
|||
}; |
|||
if( m_sUartData.speed == 0 ){ |
|||
LOG_ERROR("No Speed Defined!"); |
|||
return false; |
|||
}; |
|||
if( m_sUartData.path[0] == (char)0 ) { |
|||
LOG_ERROR("No Adress Defined!"); |
|||
return false; |
|||
}; |
|||
|
|||
switch( m_sUartData.mode ) { |
|||
case SOL_UDP_CLIENT:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS CLIENT - Create UDP Server"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
// Creating socket file descriptor
|
|||
if ( (m_iDeviceFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { |
|||
LOG_ERROR("UDP Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_iDeviceFD, F_SETFL, O_NONBLOCK); |
|||
// Filling server information
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; // IPv4
|
|||
tServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
|
|||
// Bind the socket with the server address
|
|||
if ( bind( m_iDeviceFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr)) < 0 ){ |
|||
LOG_ERROR("UDP Bind Failed"); |
|||
return false; |
|||
}; |
|||
#else
|
|||
WSADATA wsaData; |
|||
// Initialize Winsock version 2.2
|
|||
char tBuff[128]; |
|||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { |
|||
sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
return false; |
|||
} else { |
|||
sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus); |
|||
LOG(tBuff); |
|||
}; |
|||
// Set up a SOCKADDR_IN structure that will tell bind that we
|
|||
// want to receive datagrams from all interfaces using port 5150.
|
|||
// The IPv4 family
|
|||
ReceiverAddr.sin_family = AF_INET; |
|||
// Port no. 5150
|
|||
ReceiverAddr.sin_port = htons( m_nPort ); |
|||
// From all interface (0.0.0.0)
|
|||
ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY); |
|||
// Associate the address information with the socket using bind.
|
|||
// At this point you can receive datagrams on your bound socket.
|
|||
if( bind(m_sSocket, (SOCKADDR*)&ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR ){ |
|||
sprintf( tBuff, "Server: bind() failed!Error : %ld.", WSAGetLastError()); |
|||
// Close the socket
|
|||
closesocket(m_sSocket); |
|||
// Do the clean up
|
|||
WSACleanup(); |
|||
// and exit with error
|
|||
LOG_ERROR(tBuff); |
|||
return false; |
|||
} else { |
|||
LOG("UDP Server: bind() is OK!"); |
|||
}; |
|||
// Some info on the receiver side...
|
|||
SOCKADDR_IN tAddr; |
|||
int tLen = sizeof(SOCKADDR_IN); |
|||
getsockname(m_sSocket, (SOCKADDR*)&tAddr, &tLen); |
|||
sprintf( tBuff, "Receiving IP(s) used : %s", inet_ntoa(tAddr.sin_addr)); |
|||
LOG(tBuff); |
|||
sprintf(tBuff,"Receiving port used : %d", htons(tAddr.sin_port)); |
|||
LOG(tBuff); |
|||
SelectTiming = recvfromTimeOutUDP(m_sSocket, 10, 0); |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_CLIENT:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS CLIENT - Create TCP Server"); |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_UDP_SERVER:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS SERVER - Create UDP Client"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
// Creating socket file descriptor
|
|||
if ( (m_iDeviceFD = socket( AF_INET, SOCK_DGRAM, 0)) < 0 ) { |
|||
LOG_ERROR("Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_iDeviceFD, F_SETFL, O_NONBLOCK ); |
|||
|
|||
// Filling server information
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; |
|||
tServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
#else
|
|||
|
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_SERVER:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS SERVER - Create TCP Client"); |
|||
#endif
|
|||
|
|||
// socket create and varification
|
|||
m_iDeviceFD = socket( AF_INET, SOCK_STREAM, 0 ); |
|||
if( m_iDeviceFD == -1) { |
|||
LOG_ERROR("Socket creation failed!"); |
|||
return false; |
|||
} |
|||
#ifdef DEBUG
|
|||
else LOG("Socket successfully created"); |
|||
#endif
|
|||
|
|||
|
|||
// assign IP, PORT
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; |
|||
tServerAddr.sin_addr.s_addr = inet_addr( m_sUartData.path ); |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
|
|||
// connect the client socket to server socket
|
|||
if( connect( m_iDeviceFD, (struct sockaddr *)&tServerAddr, sizeof(tServerAddr) ) !=0 ){ |
|||
char cBuffer[128]; |
|||
sprintf(cBuffer,"ERROR connect to [%s:%d] (%s)", m_sUartData.path, m_sUartData.port, strerror(errno) ); |
|||
LOG_ERROR( cBuffer ); |
|||
return false; |
|||
} |
|||
#ifdef DEBUG
|
|||
else LOG("Connected to the server"); |
|||
#endif
|
|||
|
|||
// Set non-blocking
|
|||
int arg; |
|||
if( (arg = fcntl( m_iDeviceFD, F_GETFL, NULL)) < 0) { |
|||
char tBuf[128]; |
|||
sprintf( tBuf, "Error fcntl(..., F_GETFL) (%s)", strerror(errno)); |
|||
LOG_ERROR( tBuf ); |
|||
return false; |
|||
}; |
|||
arg |= O_NONBLOCK; |
|||
if( fcntl( m_iDeviceFD, F_SETFL, arg) < 0) { |
|||
char tBuf[128]; |
|||
sprintf( tBuf, "Error fcntl(..., F_SETFL) (%s)", strerror(errno)); |
|||
LOG_ERROR( tBuf ); |
|||
return false; |
|||
}; |
|||
setConnectionStatus( CS_CONNECTED ); |
|||
break; |
|||
}; |
|||
}; |
|||
return init(); |
|||
}; |
|||
|
|||
bool deviceETH2UART::closePort(){ |
|||
char tBuff[128]; |
|||
|
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
|
|||
if( m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT ){ |
|||
uninit(); |
|||
}; |
|||
if( m_iDeviceFD != -1 ) { |
|||
switch( m_sUartData.mode ) { |
|||
case SOL_UDP_CLIENT: |
|||
case SOL_TCP_CLIENT: |
|||
case SOL_UDP_SERVER: { |
|||
#ifdef __linux__
|
|||
close( m_iDeviceFD ); |
|||
#else
|
|||
// When your application is finished receiving datagrams close the socket.
|
|||
LOG("Server: Finished receiving.Closing the listening socket..."); |
|||
if( closesocket(m_sSocket) != 0 ){ |
|||
sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
} else { |
|||
LOG("closesocket() is OK..."); |
|||
}; |
|||
// When your application is finished call WSACleanup.
|
|||
LOG("Server: Cleaning up..."); |
|||
if (WSACleanup() != 0) { |
|||
sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
} else { |
|||
LOG("WSACleanup() is OK"); |
|||
}; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_SERVER:{ |
|||
close( m_iDeviceFD ); |
|||
break; |
|||
}; |
|||
}; |
|||
m_iDeviceFD = -1; |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
void deviceETH2UART::m_fThreadAProc(void){ |
|||
int index; |
|||
int RetVal; |
|||
m_bThreadAStatus = TH_WORKING; |
|||
#ifdef DEBUG
|
|||
LOG("Sender Thread Started!"); |
|||
#endif
|
|||
while (m_bThreadAStatus < TH_ENDED) { |
|||
m_mBufferProtectorMutex.lock(); |
|||
if( m_nOutputBufferSize > 0 ){ |
|||
index = 0; |
|||
while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ |
|||
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); |
|||
if( RetVal > 0 ) index += RetVal; |
|||
if( RetVal == -1 ){ |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
m_nOutputBufferSize = 0; |
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
LOG_ERROR("Connection Droped on Sending Data"); |
|||
}; |
|||
}; |
|||
m_nOutputBufferSize = 0; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
} else { |
|||
m_mBufferProtectorMutex.unlock(); |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void deviceETH2UART::m_fThreadBProc(void){ |
|||
m_bThreadBStatus = TH_WORKING; |
|||
int RetVal; |
|||
#ifdef DEBUG
|
|||
LOG("Recipient Thread Started!"); |
|||
#endif
|
|||
while( m_bThreadBStatus < TH_ENDED ){ |
|||
RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); |
|||
if( RetVal == -1 ){ |
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
m_nInputBufferSize = 0; |
|||
//if(!getStatus()) {
|
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
//} else SLEEP(100);
|
|||
LOG_ERROR("Connection Droped on Reception Data"); |
|||
} else if( m_nInputBufferSize > 0 ){ |
|||
do{ |
|||
m_mQueueProtectorMutex.lock(); |
|||
if( m_vParsers.size() ){ |
|||
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) (*index)->parse(m_pInputBuffer, m_nInputBufferSize); |
|||
m_nInputBufferSize = 0; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
} else { |
|||
m_nInputBufferSize = 0; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG_ERROR("Try to parse data but No Parsers Assigned!"); |
|||
#endif
|
|||
SLEEP(100); |
|||
}; |
|||
} while( ( m_vParsers.size() == 0 ) && ( m_bThreadBStatus < TH_ENDED ) && ( m_bThreadBStatus < TH_ENDED ) ); |
|||
} else { |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool deviceETH2UART::sendData( uint8_t *Data, int DataSize ){ |
|||
if( m_bThreadAStatus != TH_WORKING ) { |
|||
if( m_bThreadAStatus < TH_WORKING ) { |
|||
LOG_ERROR("Trying to Send Data Before Thread is Started!"); |
|||
} else { |
|||
LOG_ERROR("Trying to Send Data After Thread is Dead!"); |
|||
} |
|||
return false; |
|||
}; |
|||
m_mBufferProtectorMutex.lock(); |
|||
if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH ){ |
|||
m_mBufferProtectorMutex.unlock(); |
|||
LOG_ERROR("Data Too BIG"); |
|||
return false; |
|||
}; |
|||
memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); |
|||
m_nOutputBufferSize += DataSize; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
return true; |
|||
}; |
|||
|
|||
bool deviceETH2UART::reconnect( void ){ |
|||
closePort(); |
|||
m_bValid = create_SOL(); |
|||
return m_bValid; |
|||
}; |
|||
|
|||
int deviceETH2UART::recptBlock( unsigned char *Buffer, int *BufferLength ){ |
|||
|
|||
#ifdef __linux__
|
|||
int RetVal = 0; |
|||
#else
|
|||
DWORD RetVal = 0; |
|||
#endif
|
|||
|
|||
if( m_eConnectionStatus == CS_CONNECTED ){ |
|||
#ifdef __linux__
|
|||
if( m_iDeviceFD > -1 ) { |
|||
struct sockaddr ClientAddress; |
|||
socklen_t addr_len = sizeof( ClientAddress ); //len is value/resuslt
|
|||
//RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len );
|
|||
RetVal = recvfrom( m_iDeviceFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_DONTWAIT, ( struct sockaddr *) &ClientAddress, &addr_len ); |
|||
if( RetVal < 1 ){ |
|||
if( errno!=EAGAIN && errno!=EINTR ) { |
|||
LOG_ERROR("Peer Closes Connection!"); |
|||
shutdown( m_iDeviceFD, 2 ); |
|||
close( m_iDeviceFD ); |
|||
*BufferLength = 0; |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
}; |
|||
|
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
*BufferLength = 0; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
#else
|
|||
switch ( m_eType ) { |
|||
case SOL_UDP_CLIENT: |
|||
case SOL_TCP_CLIENT: |
|||
case SOL_UDP_SERVER: { |
|||
SOCKADDR_IN tAddr; |
|||
int tLen = sizeof(SOCKADDR_IN); |
|||
RetVal = recvfrom( m_sSocket, (char*)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0, (struct sockaddr*) &tAddr, &tLen); |
|||
if (RetVal == SOCKET_ERROR){ |
|||
char cBuffer[165]; |
|||
sprintf(cBuffer,"recvfrom() failed with error code : %d", WSAGetLastError()); |
|||
LOG_ERROR(cBuffer); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
#endif
|
|||
} else { |
|||
//make prep for connection SOL_TCP_SERVER
|
|||
if( m_sUartData.mode == SOL_TCP_CLIENT ){ |
|||
//ACCEPT
|
|||
struct sockaddr ClientAddress; |
|||
socklen_t size = (socklen_t) sizeof( struct sockaddr_in ); |
|||
//int ClientSocket;
|
|||
m_iDeviceFD = accept( m_iMasterFD, &ClientAddress, &size ); |
|||
if( m_iDeviceFD < 0 ) { |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
LOG_ERROR("Connection Accept Failure!"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("RCPT ON not connected!"); |
|||
shutdown( m_iDeviceFD, 2 ); |
|||
close( m_iDeviceFD ); |
|||
*BufferLength = 0; |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
}; |
|||
return -1; // Exit after unsuccess reconnect
|
|||
}; |
|||
|
|||
if( RetVal > 0 ){ |
|||
#ifdef DEBUG_SERIAL_COMMUNICATION
|
|||
char MsgBuffer[CLOG]; |
|||
if( RetVal > 1 || RetVal == 0 ) { |
|||
sprintf( MsgBuffer, "Received %d bytes", RetVal ); |
|||
} else { |
|||
sprintf( MsgBuffer, "Received 1 byte"); |
|||
}; |
|||
LOG( MsgBuffer ); |
|||
for (int i = 0; i < RetVal; i++) { |
|||
sprintf(MsgBuffer, "0x%02X", Buffer[i]); |
|||
LOG(MsgBuffer); |
|||
}; |
|||
#endif
|
|||
*BufferLength = RetVal; |
|||
return RetVal; |
|||
}; |
|||
|
|||
*BufferLength = 0; |
|||
|
|||
if (RetVal == -1) return 0; |
|||
|
|||
if (RetVal == 0){ |
|||
errno = 0; |
|||
return 0; |
|||
}; |
|||
|
|||
/* r < -1, should never happen. */ |
|||
errno = EIO; |
|||
return 0; |
|||
}; |
|||
|
|||
int deviceETH2UART::sendBlock(unsigned char* Data, int DataSize) { |
|||
#ifdef __linux__
|
|||
int RetVal = 0; |
|||
#else
|
|||
DWORD RetVal = 0; |
|||
#endif
|
|||
|
|||
if( m_eConnectionStatus == CS_CONNECTED ){ |
|||
#ifdef __linux__
|
|||
if( m_iDeviceFD > -1 ){ |
|||
|
|||
#ifdef DEBUG_EXTRA
|
|||
char cBuffer[256]; |
|||
sprintf(cBuffer, "Write into Port %d bytes", DataSize); |
|||
LOG(cBuffer); |
|||
#endif
|
|||
struct sockaddr ClientAddress; |
|||
socklen_t addr_len = sizeof(ClientAddress); |
|||
RetVal = sendto( m_iDeviceFD, (const char*)Data, DataSize, MSG_CONFIRM, (const struct sockaddr*) &ClientAddress, addr_len); |
|||
|
|||
if ((RetVal == -1) && (errno != EINTR) && (errno != EWOULDBLOCK)) { |
|||
LOG_ERROR("Error acures while writing data into the Socket"); |
|||
shutdown( m_iDeviceFD, 2); |
|||
close( m_iDeviceFD); |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
return -1; |
|||
}; |
|||
|
|||
if (RetVal < 0) RetVal = 0; |
|||
|
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf(cBuffer, "Bytes Sent: %ld", RetVal); |
|||
LOG(cBuffer); |
|||
#ifdef DEBUG_SERIAL_COMMUNICATION
|
|||
for(int zz=0; zz < RetVal; zz++ ) { |
|||
sprintf(cBuffer, "SD: 0x%02X", (uint8_t)Data[zz]); |
|||
LOG(cBuffer); |
|||
}; |
|||
#endif
|
|||
#endif
|
|||
|
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
//m_bConnected = false;
|
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
return -1; |
|||
}; |
|||
#else // Windows
|
|||
if (sendto( m_sSocket, (char *)Data, DataSize, 0, (struct sockaddr*) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR) { |
|||
char cBuffer[256]; |
|||
sprintf(cBuffer, "sendto() failed with error code : %d", WSAGetLastError()); |
|||
LOG_ERROR( cBuffer ); |
|||
return -1; |
|||
}; |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG( "Port is not Ready to Send" ); |
|||
#endif
|
|||
return -1; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
|
|||
#undef LOG_ERROR
|
|||
#undef LOG
|
|||
@ -0,0 +1,55 @@ |
|||
#ifndef __DEVICE_NODE_ETHERNET2SERIAL_HEADER__ |
|||
#define __DEVICE_NODE_ETHERNET2SERIAL_HEADER__ |
|||
|
|||
#include "deviceNode.h" |
|||
#include "hardwareResource.h" |
|||
#include "../../components/base/basicTransport.h" |
|||
#include "../../components/base/basicDualThread.h" |
|||
|
|||
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
#endif |
|||
|
|||
#ifndef MAXIMAL_SERIAL_PACKET_LENGTH |
|||
#define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#endif |
|||
|
|||
class deviceETH2UART: public deviceNode, public hardwareResource, public basicTransport, public basicDualThread{ |
|||
private: |
|||
//basicLogCollection * m_pLog; |
|||
DBC_UART_DATA m_sUartData; |
|||
|
|||
int m_iDeviceFD; |
|||
int m_iMasterFD; |
|||
#ifdef __linux__ |
|||
int m_iInFID; |
|||
int m_iOutFID; |
|||
#else |
|||
DCB PortDCB; |
|||
HANDLE m_ioFID; |
|||
#endif |
|||
bool pingDevice(); |
|||
bool create_SOL(); |
|||
bool closePort(); |
|||
int sendBlock(unsigned char *Data, int DataSize); |
|||
int recptBlock(unsigned char *Buffer, int *BufferLength); |
|||
protected: |
|||
U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
int m_nInputBufferSize; |
|||
int m_nOutputBufferSize; |
|||
|
|||
virtual void m_fThreadAProc(void); |
|||
virtual void m_fThreadBProc(void); |
|||
public: |
|||
explicit deviceETH2UART( uint32_t nodeID ); |
|||
~deviceETH2UART(); |
|||
virtual bool create( void ); |
|||
virtual bool validate( void ); |
|||
virtual bool sendData( uint8_t *Data, int DataSize ); |
|||
virtual bool reconnect( void ); |
|||
}; |
|||
|
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,611 @@ |
|||
#include "deviceNodeFactory.h"
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
#include "deviceNode3D.h"
|
|||
#include "deviceNode2D.h"
|
|||
#include "deviceNodePTZCamControl.h"
|
|||
#include "deviceNodeStaticCamControl.h"
|
|||
#include "deviceNodeEthernet2Serial.h"
|
|||
|
|||
#ifdef MEM_DEBUG
|
|||
#include "../alg/generic/heapDebug.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "NFAC", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "NFAC", this, _LOG_ERROR, X )
|
|||
|
|||
deviceNodeFactory *deviceNodeFactory::_instance = NULL; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
deviceNodeFactory* deviceNodeFactory::getInstance() { |
|||
if( NULL == _instance ) { |
|||
_instance = new deviceNodeFactory(); |
|||
}; |
|||
return _instance; |
|||
}; |
|||
|
|||
deviceNodeFactory::deviceNodeFactory(): basicThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
init(); |
|||
}; |
|||
|
|||
deviceNodeFactory::~deviceNodeFactory(){ |
|||
waitThreadEnd( true ); |
|||
unloadNodes(); |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
bool deviceNodeFactory::unloadNodes( void ){ |
|||
if( m_pDBC != NULL ){ |
|||
if( m_vDeviceNodes.size() > 0 ){ |
|||
for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ){ |
|||
LOG(" Unload Node... BEGIN"); |
|||
switch( (*index)->getNodeType() ){ |
|||
case ARGUS_ANALOG_STATIC_CAMERA: |
|||
LOG(" Static Analog Cam"); |
|||
delete( (deviceNodeStaticCamControl*) (*index) ); |
|||
break; |
|||
case ARGUS_ANALOG_PTZ_CAMERA: |
|||
LOG(" PTZ Analog Cam"); |
|||
delete( (deviceNodePTZCamControl*) (*index) ); |
|||
break; |
|||
case ARGUS_IP_PTZ_CAMERA:{ |
|||
LOG(" PTZ IP Cam"); |
|||
delete( (deviceNodePTZCamControl*) (*index) ); |
|||
break; |
|||
}; |
|||
case ARGUS_IP_STATIC_CAMERA:{ |
|||
LOG(" Static IP Cam"); |
|||
delete( (deviceNodeStaticCamControl*) (*index) ); |
|||
break; |
|||
}; |
|||
case ARGUS_IP_UART_GATEWAY:{ |
|||
LOG(" UART Gateway"); |
|||
delete( (deviceETH2UART*) (*index) ); |
|||
break; |
|||
}; |
|||
case ARGUS_ALS_SENSOR: |
|||
case ARGUS_PLS_200_SENSOR: |
|||
case ARGUS_PLS_360_SENSOR: |
|||
case ARGUS_LFS_SENSOR:{ |
|||
LOG(" 2D LRF"); |
|||
delete( (device2DSensor*) (*index) ); |
|||
LOG(" 2D LRF done"); |
|||
break; |
|||
}; |
|||
case ARGUS_3D_SENSOR:{ |
|||
LOG(" 3D LRF"); |
|||
delete( (device3DSensor*) (*index) ); |
|||
break; |
|||
}; |
|||
}; |
|||
LOG(" Unload Node... DONE!"); |
|||
}; |
|||
m_vDeviceNodes.clear(); |
|||
m_mDeviceNodesIDS.clear(); |
|||
}; |
|||
}; |
|||
return true; |
|||
}; |
|||
/*
|
|||
bool deviceNodeFactory::loadNodes( uint32_t SiteID ){ |
|||
LOG("Node Loader"); |
|||
if(m_pDBC == NULL) return false; |
|||
m_nSiteID = SiteID; |
|||
DBC_INT_LIST *tList = m_pDBC->listNodes( SiteID ); |
|||
if( tList != NULL ) { |
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ){ |
|||
uint32_t id = *idx; |
|||
char msg[64]; |
|||
sprintf( msg, "Creating Node[%d]", id ); |
|||
createNode( id ); |
|||
}; |
|||
tList->clear(); |
|||
delete( tList ); |
|||
return true; |
|||
}; |
|||
return false; |
|||
}; |
|||
*/ |
|||
bool deviceNodeFactory::loadNodes(){ |
|||
if( m_pDBC == NULL ) return false; |
|||
DBC_INT_LIST *tList = m_pDBC->listNodes(); |
|||
if( tList != NULL ) { |
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode((*idx)); |
|||
tList->clear(); |
|||
delete( tList ); |
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("No Nodes Defined"); |
|||
} |
|||
#endif
|
|||
return true; |
|||
}; |
|||
|
|||
bool deviceNodeFactory::reloadNodes( ){ |
|||
if(!unloadNodes()) return false; |
|||
return loadNodes( ); |
|||
}; |
|||
|
|||
bool deviceNodeFactory::reloadNode( uint32_t NodeID ){ |
|||
deleteNode( NodeID ); |
|||
deviceNode *tNode = createNode( NodeID ); |
|||
if( tNode ) { |
|||
return true; |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
deviceNode *deviceNodeFactory::createNode( uint32_t id ){ |
|||
deviceNode *tVal = NULL; |
|||
if( m_pDBC != NULL ){ |
|||
DBC_NODE_DATA *tData = NULL; |
|||
tData = m_pDBC->getNodeData( id ); |
|||
if( tData!= NULL ) { |
|||
#ifdef DEBUG
|
|||
char tB[256]; |
|||
sprintf( tB, "Node id: %d AUX id: %d", id, tData->aux_id ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Node type: %d", tData->type ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Node Name: %s", tData->name ); |
|||
LOG( tB ); |
|||
#endif
|
|||
switch( tData->type ) { |
|||
case ARGUS_ANALOG_STATIC_CAMERA:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating Analog Static Camera"); |
|||
#endif
|
|||
deviceNodeStaticCamControl *tCamera; |
|||
tCamera = new deviceNodeStaticCamControl( id ); |
|||
if( tCamera ) { |
|||
LOG("Starting Service"); |
|||
tCamera->startService(); |
|||
tVal = ( deviceNode *) tCamera; |
|||
LOG("Success"); |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_ANALOG_PTZ_CAMERA:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating Analog PTZ Camera"); |
|||
#endif
|
|||
deviceNodePTZCamControl *tCamera; |
|||
tCamera = new deviceNodePTZCamControl( id ); |
|||
if( tCamera ) { |
|||
LOG("Starting Service"); |
|||
tCamera->startService(); |
|||
tVal = ( deviceNode *) tCamera; |
|||
LOG("Success"); |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_IP_STATIC_CAMERA:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating IP Static Camera"); |
|||
#endif
|
|||
deviceNodeStaticCamControl *tCamera; |
|||
tCamera = new deviceNodeStaticCamControl( id ); |
|||
if( tCamera ) { |
|||
#ifdef DEBUG
|
|||
LOG("Starting Service"); |
|||
#endif
|
|||
if( tCamera->startService() ){ |
|||
tVal = ( deviceNode *) tCamera; |
|||
#ifdef DEBUG
|
|||
LOG("Success"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG_ERROR("Error Sterting Service"); |
|||
#endif
|
|||
delete( tCamera ); |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_IP_PTZ_CAMERA:{ |
|||
|
|||
#ifdef DEBUG
|
|||
LOG("Creating IP PTZ Camera"); |
|||
#endif
|
|||
deviceNodePTZCamControl *tCamera; |
|||
tCamera = new deviceNodePTZCamControl( id ); |
|||
if( tCamera ) { |
|||
#ifdef DEBUG
|
|||
LOG("Starting Service"); |
|||
#endif
|
|||
if( tCamera->startService() ){ |
|||
tVal = ( deviceNode *) tCamera; |
|||
#ifdef DEBUG
|
|||
LOG("Success"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG_ERROR("Error Starting Service!"); |
|||
#endif
|
|||
delete( tCamera ); |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_IP_UART_GATEWAY:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating Ethernet to UART Gateway"); |
|||
#endif
|
|||
deviceETH2UART *tGW; |
|||
tGW = new deviceETH2UART( id ); |
|||
if ( tGW ) { |
|||
if ( tGW->create() ) { |
|||
tVal = ( deviceNode *) tGW; |
|||
} else { |
|||
delete( tGW ); |
|||
}; |
|||
}; |
|||
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
|
|||
device2DSensor *tSensor; |
|||
tSensor = new device2DSensor( id ); |
|||
if( tSensor ) { |
|||
LOG("Success"); |
|||
tSensor->startService(); |
|||
tVal = ( deviceNode *) tSensor; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_ALS_SENSOR:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating ALS Sensor"); |
|||
#endif
|
|||
device2DSensor *tSensor; |
|||
tSensor = new device2DSensor( id ); |
|||
if( tSensor ) { |
|||
LOG("Success"); |
|||
tSensor->startService(); |
|||
tVal = ( deviceNode *) tSensor; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_PLS_200_SENSOR:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating PLS200 Sensor"); |
|||
#endif
|
|||
device2DSensor *tSensor; |
|||
tSensor = new device2DSensor( id ); |
|||
if( tSensor ) { |
|||
LOG("Success"); |
|||
tSensor->startService(); |
|||
tVal = ( deviceNode *) tSensor; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_PLS_360_SENSOR:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating PLS360 Sensor"); |
|||
#endif
|
|||
device2DSensor *tSensor; |
|||
tSensor = new device2DSensor( id ); |
|||
if( tSensor ) { |
|||
LOG("Success"); |
|||
tSensor->startService(); |
|||
tVal = ( deviceNode *) tSensor; |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_3D_SENSOR:{ |
|||
#ifdef DEBUG
|
|||
LOG("Creating 3D Sensor"); |
|||
#endif
|
|||
device3DSensor *t3DRadar; |
|||
t3DRadar = new device3DSensor( id ); |
|||
if( t3DRadar ) { |
|||
LOG("Success"); |
|||
t3DRadar->startService(); |
|||
tVal = ( deviceNode *) t3DRadar; |
|||
}; |
|||
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 ){ |
|||
#ifdef DEBUG
|
|||
char tB[64]; |
|||
sprintf( tB, "Node PTR: %p", tVal ); |
|||
LOG( tB ); |
|||
#endif
|
|||
m_vDeviceNodes.push_back( tVal ); |
|||
m_mDeviceNodesIDS[id] = tVal; |
|||
}; |
|||
return tVal; |
|||
}; |
|||
|
|||
void deviceNodeFactory::deleteNode( deviceNode *ptr ){ |
|||
if( ptr == NULL ) return; |
|||
// if some troubles move this to an end of the function!
|
|||
for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin() ; index < m_vDeviceNodes.end(); index++ ){ |
|||
if( (*index) == ptr ) { |
|||
m_mDeviceNodesIDS.erase( ptr->getNodeID() ); |
|||
m_vDeviceNodes.erase( index ); |
|||
break; |
|||
}; |
|||
}; |
|||
switch( ptr->getNodeType() ) { |
|||
case ARGUS_ANALOG_STATIC_CAMERA: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Analog Static Camera"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_ANALOG_PTZ_CAMERA: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Analog PTZ Camera"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_IP_STATIC_CAMERA: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Network Static Camera"); |
|||
#endif
|
|||
//SLEEP(2000);
|
|||
LOG("Actual Destroying Network Static Camera"); |
|||
delete((deviceNodePTZCamControl *) ptr ); |
|||
break; |
|||
case ARGUS_IP_PTZ_CAMERA: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Network PTZ Camera"); |
|||
#endif
|
|||
//SLEEP(2000);
|
|||
delete((deviceNodePTZCamControl *) ptr ); |
|||
#ifdef DEBUG
|
|||
LOG("Done Successfuly"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_IP_UART_GATEWAY: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Ethernet to UART Gateway"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_IP_VIDEO_SERVER: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Network Video Encoder"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_LFS_SENSOR: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying LFS Sensor"); |
|||
#endif
|
|||
delete((device2DSensor *) ptr ); |
|||
break; |
|||
case ARGUS_ALS_SENSOR: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying ALS Sensor"); |
|||
#endif
|
|||
delete((device2DSensor *) ptr ); |
|||
break; |
|||
case ARGUS_PLS_200_SENSOR: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying PLS200 Sensor"); |
|||
#endif
|
|||
delete((device2DSensor *) ptr ); |
|||
break; |
|||
case ARGUS_PLS_360_SENSOR: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying PLS360 Sensor"); |
|||
#endif
|
|||
delete((device2DSensor *) ptr ); |
|||
break; |
|||
case ARGUS_3D_SENSOR: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying 3D Sensor"); |
|||
#endif
|
|||
delete((device3DSensor *) ptr ); |
|||
break; |
|||
case ARGUS_JAMER: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying RF Jamer"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_NET_PLS_200: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Network-PLS200 Sensor"); |
|||
#endif
|
|||
break; |
|||
case ARGUS_DRONE_CONTROL: |
|||
#ifdef DEBUG
|
|||
LOG("Destroying Drone Controll"); |
|||
#endif
|
|||
break; |
|||
}; |
|||
}; |
|||
|
|||
/*
|
|||
@id Database ID of Node to be deleted |
|||
*/ |
|||
deviceNode *deviceNodeFactory::getNode( uint32_t id ){ |
|||
mapDeviceNode2Id::iterator it; |
|||
it = m_mDeviceNodesIDS.find( id ); |
|||
if( it != m_mDeviceNodesIDS.end() ) { |
|||
return m_mDeviceNodesIDS[id]; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
|
|||
/*
|
|||
@id Database ID of Node to be deleted |
|||
*/ |
|||
void deviceNodeFactory::deleteNode( uint32_t id ){ |
|||
deviceNode *tNode = getNode( id ); |
|||
deleteNode( tNode ); |
|||
}; |
|||
|
|||
bool deviceNodeFactory::validate( void ){ |
|||
return ( m_bThreadStatus < TH_ENDED ); |
|||
}; |
|||
|
|||
void deviceNodeFactory::m_fThreadProc( void ){ |
|||
if( m_pDBC == NULL ){ |
|||
m_bThreadStatus = TH_ENDED; |
|||
} else { |
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
|
|||
DBC_INT_LIST *tList = NULL; |
|||
#ifdef DEBUG
|
|||
#ifdef MEM_DEBUG
|
|||
size_t memStart, memEnd, memDiff; |
|||
char MEM_MSG[256]; |
|||
memStart = getCurrentRSS(); |
|||
#endif
|
|||
#endif
|
|||
if( m_vDeviceNodes.size() ) { |
|||
DBC_INT_LIST tL; |
|||
for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ) tL.push_back( (*idx)->getNodeID() ); |
|||
tList = m_pDBC->listNewNodes( &tL ); |
|||
tL.clear(); |
|||
} else { |
|||
tList = m_pDBC->listNewNodes( NULL ); |
|||
}; |
|||
if( tList != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("New Nodes Added!"); |
|||
#endif
|
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createNode( *idx ); |
|||
tList->clear(); |
|||
delete( tList ); |
|||
} |
|||
#ifdef DEBUG_EXTRA
|
|||
else { |
|||
LOG( "No New Nodes Added"); |
|||
} |
|||
#endif
|
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
|
|||
if( m_vDeviceNodes.size() ) { |
|||
//Get Full List
|
|||
tList = m_pDBC->listNodes(); |
|||
if( tList != NULL ) { |
|||
for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ){ |
|||
bool tRemoved = true; |
|||
// Check if Removed By changes in DB
|
|||
for( DBC_INT_LIST::iterator idz = tList->begin(); idz < tList->end(); idz++ ) if( (*idz) == (*idx)->getNodeID() ) tRemoved = false; |
|||
// If Not - check validation
|
|||
if( !tRemoved ){ |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Node Among Active Nodes.... make Validation"); |
|||
#endif
|
|||
tRemoved = !(*idx)->validate(); |
|||
}; |
|||
// If Node is Invalid - Removing
|
|||
if( tRemoved ) { |
|||
#ifdef DEBUG
|
|||
LOG("Node not passed Validation!"); |
|||
#endif
|
|||
deleteNode((*idx)); |
|||
}; |
|||
}; |
|||
tList->clear(); |
|||
delete( tList ); |
|||
} else { |
|||
#ifdef DEUBG
|
|||
LOG("All Modules Must be Deleted!"); |
|||
#endif
|
|||
for( vectorDeviceNodes::iterator idx = m_vDeviceNodes.begin(); idx < m_vDeviceNodes.end(); idx++ ) deleteNode((*idx)); |
|||
m_vDeviceNodes.clear(); |
|||
m_mDeviceNodesIDS.clear(); |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
} else { |
|||
LOG("No Nodes to Validate"); |
|||
#endif
|
|||
}; |
|||
#ifdef DEBUG
|
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
#endif
|
|||
// Sleep for 1 second
|
|||
for( int i = ( 1000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
}; |
|||
LOG("EXIT FROM CTRL THREAD"); |
|||
}; |
|||
|
|||
uint32_t deviceNodeFactory::getNodesCount( ARGUS_NODE_TYPE type ){ |
|||
uint32_t RetVal = 0; |
|||
if( m_vDeviceNodes.size() ) for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) if( (*index)->getNodeType() == type ) RetVal++; |
|||
return RetVal; |
|||
}; |
|||
|
|||
uint32_t deviceNodeFactory::fetchNodes( ARGUS_NODE_TYPE type, deviceNode **&RA ){ |
|||
uint32_t RetVal = 0; |
|||
if( RA == NULL ) { |
|||
RetVal = getNodesCount( type ); |
|||
if( RetVal > 0 ) { |
|||
RA = (deviceNode **) calloc( RetVal, sizeof(deviceNode *)); |
|||
if( RA == NULL ) return 0; |
|||
uint32_t cnt = 0; |
|||
for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) { |
|||
if( (*index)->getNodeType() == type ) { |
|||
RA[cnt] = (*index); |
|||
cnt++; |
|||
}; |
|||
}; |
|||
}; |
|||
} else { |
|||
if( m_vDeviceNodes.size() ) { |
|||
for( vectorDeviceNodes::iterator index = m_vDeviceNodes.begin(); index < m_vDeviceNodes.end(); index++ ) { |
|||
if( (*index)->getNodeType() == type ) { |
|||
RA[RetVal] = (*index); |
|||
RetVal++; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,36 @@ |
|||
#ifndef __DEVICE_NODE_FACTORY_HEADER__ |
|||
#define __DEVICE_NODE_FACTORY_HEADER__ |
|||
|
|||
#include "dataBinder.h" |
|||
#include "deviceNode.h" |
|||
#include "../components/base/basicThread.h" |
|||
|
|||
|
|||
class deviceNodeFactory: public basicThread{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
dataBinder * m_pDBC; |
|||
vectorDeviceNodes m_vDeviceNodes; |
|||
mapDeviceNode2Id m_mDeviceNodesIDS; |
|||
public: |
|||
static deviceNodeFactory * getInstance(); |
|||
virtual ~deviceNodeFactory(); |
|||
deviceNode * createNode( uint32_t id ); |
|||
void deleteNode( deviceNode *ptr ); |
|||
void deleteNode( uint32_t id ); |
|||
uint32_t fetchNodes( ARGUS_NODE_TYPE type, deviceNode **&RA ); |
|||
deviceNode * getNode( uint32_t id ); |
|||
uint32_t getNodesCount( ARGUS_NODE_TYPE type ); |
|||
bool loadNodes(); |
|||
bool unloadNodes( void ); |
|||
bool reloadNodes( ); |
|||
bool reloadNode( uint32_t NodeID ); |
|||
bool validate( void ); |
|||
protected: |
|||
explicit deviceNodeFactory( ); |
|||
virtual void m_fThreadProc( void ); |
|||
private: |
|||
static deviceNodeFactory * _instance; |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,194 @@ |
|||
#include "deviceNodePTZCamControl.h"
|
|||
|
|||
#define LOG( X ) deviceNode::m_pLog->Log( "PTZ_CAM", this, X )
|
|||
#define LOG_ERROR( X ) deviceNode::m_pLog->Log( "PTZ_CAM", this, _LOG_ERROR, X )
|
|||
|
|||
deviceNodePTZCamControl::deviceNodePTZCamControl( DBC_NODE_DATA *Data ): deviceNodeCamera( Data ), basicEventHandler(){ |
|||
//m_pLog = basicLogCollection::getInstance();
|
|||
/*
|
|||
DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id ); |
|||
|
|||
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f; |
|||
|
|||
if( tData != NULL ) { |
|||
memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) ); |
|||
free( tData ); |
|||
}; |
|||
memset( &m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA) ); |
|||
if( m_sCamData.max_range == .0f ){ |
|||
m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 ); |
|||
} else { |
|||
m_fMaxRange = m_sCamData.max_range; |
|||
}; |
|||
m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f ); |
|||
m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f ); |
|||
m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f ); |
|||
m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f ); |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
LOG("Camera Info:"); |
|||
sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange); |
|||
LOG(tB); |
|||
sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov ); |
|||
LOG(tB); |
|||
sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov ); |
|||
LOG(tB); |
|||
#endif
|
|||
m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw ); |
|||
*/ |
|||
}; |
|||
|
|||
deviceNodePTZCamControl::deviceNodePTZCamControl( uint32_t id ): deviceNodeCamera( id ), basicEventHandler(){ |
|||
m_sMediaSource.mediaSourceId = m_sNodeData.aux_id; |
|||
strncpy( m_sMediaSource.mediaName, m_sNodeData.name, 128 ); |
|||
m_sMediaSource.mediaName[127] = (char)0; |
|||
memset( &m_sCtrlData, 0, sizeof( CAMERA_CTRL_DATA )); |
|||
}; |
|||
|
|||
deviceNodePTZCamControl::~deviceNodePTZCamControl(){ |
|||
LOG("Destructor"); |
|||
stopService(); |
|||
}; |
|||
|
|||
bool deviceNodePTZCamControl::startService(){ |
|||
return create(); |
|||
}; |
|||
|
|||
bool deviceNodePTZCamControl::stopService(){ |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
|
|||
void deviceNodePTZCamControl::dispatchEvent( EVENT_CONTAINER *E ){ |
|||
if( E == NULL ) return; |
|||
//if( !m_sCamData.online ) return;
|
|||
//if( m_bBusy ) return;
|
|||
switch( E->m_eClass ) { |
|||
case EVT_CLASS_SENSOR_CLD: |
|||
case EVT_CLASS_SENSOR_LGS: |
|||
case EVT_CLASS_SENSOR_LFS: |
|||
case EVT_CLASS_SENSOR_MND: |
|||
case EVT_CLASS_SENSOR_PLS_210: |
|||
case EVT_CLASS_SENSOR_PLS_360: |
|||
case EVT_CLASS_SENSOR_ALS: |
|||
case EVT_CLASS_SENSOR_3D: |
|||
case EVT_CLASS_SENSOR_ACC:{ |
|||
switch( E->m_eType ) { |
|||
case EVT_TARGET_1D: |
|||
case EVT_TARGET_2D_BLACK: |
|||
case EVT_TARGET_2D_WHITE: |
|||
case EVT_TARGET_3D_BLACK: |
|||
case EVT_TARGET_3D_WHITE: |
|||
case EVT_ROI_ACTIVE:{ |
|||
TARGET_DATA *tDATA; |
|||
tDATA = (TARGET_DATA *)E->m_pEvtData; |
|||
if( tDATA ) { |
|||
#ifdef DEBUG
|
|||
LOG( "CHECK CAMERA FOV" ); |
|||
#endif
|
|||
if (testFOV(tDATA->system_target)) { |
|||
#ifdef DEBUG
|
|||
LOG("TARGET IN CAMERA FOV"); |
|||
#endif
|
|||
if(lookAt(E->m_db_id, tDATA->system_target)){ |
|||
/*
|
|||
AnyDesk 958906475 |
|||
#ifdef DEBUG
|
|||
LOG("CHECK CAMERA STREAMS"); |
|||
#endif
|
|||
EVENT_CONTAINER *tEVT; |
|||
DBC_INT_LIST *tStreams; |
|||
tStreams = m_pDBC->listCamMediaStreams( m_sNodeData.aux_id ); |
|||
if( tStreams!= NULL ) { |
|||
for( uint32_t idx = 0; idx < tStreams->size(); idx++ ) { |
|||
tEVT = createBasicTargetedEvent( m_nDBID, tStreams->at(idx), EVT_CLASS_VIDEO, EVT_CAPTURE_START, E->m_UUID ); |
|||
if( tEVT != NULL ) { |
|||
tEVT->m_ref_id = E->m_db_id; |
|||
m_pEvtHeap->broadcast( tEVT ); |
|||
}; |
|||
}; |
|||
delete( tStreams ); |
|||
}; |
|||
*/ |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_CLASS_CAMERA_CTRL:{ |
|||
/*
|
|||
if( E->m_nDestinationUID == m_sCamData.node_id ) { |
|||
switch( E->m_eType ) { |
|||
case EVT_CAMERA_DM:{ |
|||
CAMERA_CTRL_DATA *tDATA = (CAMERA_CTRL_DATA *)E->m_pEvtData; |
|||
if( tDATA != NULL ) { |
|||
if( tDATA->moveMask & 0x08 == 0x08 ){ |
|||
//Relative Move cmd
|
|||
if( tDATA->moveMask & 0x07 == 0 ){ |
|||
relativeStop(); |
|||
} else { |
|||
relativeMove( tDATA->spdPAN, tDATA->spdTILT, tDATA->spdZOOM ); |
|||
}; |
|||
} else { |
|||
if( tDATA->moveMask & 0xF0 != 0x00 ) { |
|||
absoluteMove( tDATA->absPAN, tDATA->absTILT, tDATA->absZOOM ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
} |
|||
;*/ |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
bool deviceNodePTZCamControl::validate(){ |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("VALIDATE"); |
|||
#endif
|
|||
if( CAM_WS_END == getWM() ) return false; |
|||
// Validate Camera Settings
|
|||
/*{
|
|||
DBC_CAM_DATA *tDATA = argusNetNode::m_pDBC->getCamData( m_sNodeData.aux_id ); |
|||
if( tDATA ) { |
|||
if( memcmp( &m_sCamData, tDATA, sizeof(DBC_CAM_DATA)) != 0 ){ |
|||
free( tDATA ); |
|||
LOG("Cam Settings Changed!"); |
|||
return false; |
|||
}; |
|||
free( tDATA ); |
|||
} else{ |
|||
LOG("Cam Deleted!"); |
|||
return false; |
|||
}; |
|||
}*/ |
|||
// Validate Stream - > moved to Video Encoder!
|
|||
/*
|
|||
{ |
|||
if( m_sNodeData.aux_parameter ) { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("VALIDATE Stream"); |
|||
#endif
|
|||
if( !m_bSourceConnected ) { |
|||
if( connectToStream( m_sNodeData.aux_parameter ) ) { |
|||
argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter ); |
|||
} else { |
|||
argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter, false ); |
|||
}; |
|||
} else { |
|||
validateStream(); |
|||
}; |
|||
}; |
|||
} |
|||
*/ |
|||
return deviceNodeCamera::validate(); |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,44 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// 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 __DEVICE_PTZ_CAMERA_CTRL_HEADER__ |
|||
#define __DEVICE_PTZ_CAMERA_CTRL_HEADER__ |
|||
|
|||
#include "deviceNodeCamera.h" |
|||
#include "../../components/base/basicEventHandler.h" |
|||
#include "../../components/base/basicEventHeap.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 deviceNodePTZCamControl: public deviceNodeCamera, public basicEventHandler { |
|||
protected: |
|||
CAMERA_CTRL_DATA m_sCtrlData; |
|||
|
|||
//virtual bool relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ); |
|||
//virtual bool relativeStop(); |
|||
//virtual bool absoluteMove( float PanPOS, float TiltPOS, float ZoomPOS ); |
|||
public: |
|||
explicit deviceNodePTZCamControl( uint32_t id ); |
|||
explicit deviceNodePTZCamControl( DBC_NODE_DATA *Data = NULL ); |
|||
~deviceNodePTZCamControl(); |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,656 @@ |
|||
#include "deviceNodeSensor.h"
|
|||
#include "../../components/object/objectSystemAnchor.h"
|
|||
|
|||
#include <opencv2/opencv.hpp>
|
|||
|
|||
#define LOG( X ) deviceNode::m_pLog->Log( "NODSEN", this, X )
|
|||
#define LOG_ERROR( X ) deviceNode::m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
|
|||
|
|||
deviceNodeSensor::deviceNodeSensor( uint32_t id ):deviceNode( id ),m_oPosition(){ |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
switch( m_sNodeData.type ){ |
|||
case ARGUS_CLD_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_CLD; break; |
|||
case ARGUS_LGS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_LGS; break; |
|||
case ARGUS_ALS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_ALS; break; |
|||
case ARGUS_LFS_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_LFS; break; |
|||
case ARGUS_PLS_200_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_210; break; |
|||
case ARGUS_PLS_360_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_PLS_360; break; |
|||
case ARGUS_3D_SENSOR: m_eEventClass = EVT_CLASS_SENSOR_3D; break; |
|||
default: m_eEventClass = EVT_CLASS_SYSTEM; break; |
|||
}; |
|||
m_pTargetFilter = NULL; |
|||
memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA)); |
|||
if( m_pDBC ){ |
|||
DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id); |
|||
if( tDATA != NULL ) { |
|||
memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA)); |
|||
free( tDATA ); |
|||
}; |
|||
}; |
|||
systemAnchor *SA = systemAnchor::getInstance(); |
|||
if( SA ){ |
|||
LOG("SysAnchor OK"); |
|||
if ( SA->beLocal() ) { |
|||
LOG("SysAnchor beLocal!"); |
|||
m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0 ); //SA->getUTMZone() );
|
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
} else { |
|||
LOG("SysAnchor is Global Position System!"); |
|||
C3D_DECART LD = SA->getXYZ(); |
|||
m_oPosition.setPositionXYZ( LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getUTMZone() ); |
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
}; |
|||
} else { |
|||
LOG("No SysAnchor!"); |
|||
m_oPosition.setPositionXYZ( m_sLRF_DATA.x , m_sLRF_DATA.y, m_sLRF_DATA.z ); |
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
}; |
|||
m_oPosition.updateMatrix(); |
|||
|
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() ); |
|||
LOG( tB ); |
|||
#endif
|
|||
|
|||
}; |
|||
|
|||
deviceNodeSensor::deviceNodeSensor( DBC_NODE_DATA *Data ):deviceNode( Data ),m_oPosition(){ |
|||
m_pTargetFilter = NULL; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA)); |
|||
if( m_pDBC ){ |
|||
DBC_LRF_DATA *tDATA = m_pDBC->getLRFData(m_sNodeData.aux_id); |
|||
if( tDATA != NULL ) { |
|||
memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA)); |
|||
free( tDATA ); |
|||
}; |
|||
}; |
|||
systemAnchor *SA = systemAnchor::getInstance(); |
|||
if( SA ){ |
|||
LOG("SysAnchor OK"); |
|||
if ( SA->beLocal() ) { |
|||
LOG("SysAnchor beLocal!"); |
|||
m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0 ); //SA->getUTMZone() );
|
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
} else { |
|||
LOG("SysAnchor is Global Position System!"); |
|||
C3D_DECART LD = SA->getXYZ(); |
|||
m_oPosition.setPositionXYZ( LD.x + m_sLRF_DATA.x, LD.y + m_sLRF_DATA.y, LD.z + m_sLRF_DATA.z, SA->getUTMZone() ); |
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
}; |
|||
} else { |
|||
LOG("No SysAnchor!"); |
|||
m_oPosition.setPositionXYZ( m_sLRF_DATA.x , m_sLRF_DATA.y, m_sLRF_DATA.z ); |
|||
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot ); |
|||
}; |
|||
m_oPosition.updateMatrix(); |
|||
|
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() ); |
|||
LOG( tB ); |
|||
#endif
|
|||
}; |
|||
|
|||
|
|||
deviceNodeSensor::~deviceNodeSensor(){ |
|||
|
|||
}; |
|||
|
|||
#define SKIP_LINE_PIXELS 28
|
|||
#define HEIGHT 512
|
|||
#define WIDTH 1024
|
|||
// scale factor -> 4/9
|
|||
|
|||
uint8_t *deviceNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum ){ |
|||
uint8_t *RetVal = NULL; |
|||
*out_size = 0; |
|||
LOG("C2DD"); |
|||
if( th_data != NULL && th_size != 0 ) { |
|||
if ( fileExist( tpl ) ) { |
|||
LOG(tpl); |
|||
cv::Mat tImage = cv::imread( tpl, cv::IMREAD_UNCHANGED ); |
|||
int psize = th_size / ( sizeof( uint32_t )); |
|||
float stp = 2.0f * ( M_PI / (float) psize ); |
|||
//float MR = m_sLRF_DATA.max_range;
|
|||
float S = ( M_PI / 3000.0f) * (float) radial_shift; |
|||
int x0 = (tImage.cols >> 1); |
|||
int y0 = (tImage.rows >> 1); |
|||
float maxR = ((float) x0 ) * 0.98f; |
|||
LOG("C2DD - Start"); |
|||
|
|||
cv::Point pts[(psize << 1)]; |
|||
cv::Point ptt[(psize+2)]; |
|||
const cv::Point * ppt[1]; |
|||
int npp[1]; |
|||
|
|||
const cv::Point * ppz[1]; |
|||
int npz[1]; |
|||
|
|||
float rst; |
|||
|
|||
int rpt; |
|||
uint16_t RANGE = 0; |
|||
|
|||
ptt[0].x = x0; |
|||
ptt[0].y = y0; |
|||
rst = maxR / ((float)(max_digital+1)); |
|||
rpt = 1; |
|||
for( int i=0; i < psize; i++ ){ |
|||
if( byMinimum ) { |
|||
RANGE = ( th_data[i] >> 16 ) & 0xFFFF; |
|||
} else { |
|||
RANGE = th_data[i] & 0xFFFF; |
|||
}; |
|||
|
|||
float ca = 0.0 - ( S + i * stp ); |
|||
if( RANGE > 0 ){ |
|||
pts[psize+i].x = x0 + maxR * cosf( ca ); |
|||
pts[psize+i].y = y0 + maxR * sinf( ca ); |
|||
if( RANGE > max_digital ){ |
|||
pts[i].x = pts[psize+i].x; |
|||
pts[i].y = pts[psize+i].y; |
|||
} else { |
|||
float cr = (rst * RANGE); |
|||
pts[i].x = x0 + cr * cosf( ca ); |
|||
pts[i].y = y0 + cr * sinf( ca ); |
|||
}; |
|||
} else { |
|||
ptt[rpt].x = pts[psize+i].x = pts[i].x = x0 + maxR * cosf( ca ); |
|||
ptt[rpt].y = pts[psize+i].y = pts[i].y = y0 + maxR * sinf( ca ); |
|||
rpt++; |
|||
}; |
|||
}; |
|||
ppt[0] = pts; |
|||
npp[0] = ( psize<<1 ); |
|||
|
|||
ppz[0] = ptt; |
|||
npz[0] = ( rpt - 1); |
|||
|
|||
LOG("C2DD -> draw finish"); |
|||
|
|||
cv::Mat ttMOMO = cv::imread( tpl, cv::IMREAD_UNCHANGED ); |
|||
LOG("C2DD -> read tpl2 finish"); |
|||
cv::fillPoly( ttMOMO, ppt, npp, 1, cv::Scalar( 0, 128, 255, 50 ), cv::LINE_8 ); |
|||
LOG("C2DD -> poly1 finish"); |
|||
//try {
|
|||
// cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
|
|||
// LOG("C2DD -> poly2 finish");
|
|||
//} catch ( cv::Exception& e ) {
|
|||
// LOG("C2DD -> poly2 Error!");
|
|||
// LOG( e.what() );
|
|||
//};
|
|||
cv::addWeighted( tImage, 0.5, ttMOMO, 0.5, 0.0, tImage ); |
|||
LOG("C2DD -> add img finish"); |
|||
ttMOMO.release(); |
|||
LOG("C2DD -> img release finish"); |
|||
vector<int> compression_params; |
|||
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION ); |
|||
compression_params.push_back(9); |
|||
|
|||
|
|||
vector<uchar> buf; |
|||
cv::imencode( ".png", tImage, buf, compression_params ); |
|||
tImage.release(); |
|||
LOG("C2DD -> compress finish"); |
|||
*out_size = buf.size(); |
|||
RetVal = (uint8_t *) malloc( *out_size ); |
|||
if( RetVal ) { |
|||
memcpy( RetVal, buf.data(), *out_size ); |
|||
} else *out_size =0; |
|||
buf.clear(); |
|||
}; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool deviceNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){ |
|||
if( th_data == NULL ) return false; |
|||
if( th_size == 0 ) return false; |
|||
if( m_pDBC == NULL ) return false; |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_RAW_DATA, kID, th_data, th_size ); |
|||
/*
|
|||
//Clear Old Draw
|
|||
CSTR old = m_pDBC->getLRFDraw( getNodeID() ); |
|||
if ( old ) { |
|||
// delete old draw
|
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_50.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_25.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_12.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_map.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
free( old ); |
|||
}; |
|||
*/ |
|||
CSTR uid = getUniqID_MD5(); |
|||
if( uid == NULL ) return false; |
|||
switch( getNodeType() ){ |
|||
case ARGUS_ALS_SENSOR: |
|||
case ARGUS_LFS_SENSOR: |
|||
case ARGUS_PLS_200_SENSOR: |
|||
case ARGUS_PLS_360_SENSOR: |
|||
case ARGUS_NET_PLS_200:{ |
|||
uint32_t tSize; |
|||
uint8_t *tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_100.png" ); |
|||
if ( tBuff ) { |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_100, kID, tBuff, tSize ); |
|||
free( tBuff ); |
|||
}; |
|||
tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 512, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_50.png" ); |
|||
if ( tBuff ) { |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_50, kID, tBuff, tSize ); |
|||
free( tBuff ); |
|||
}; |
|||
tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 256, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_25.png" ); |
|||
if ( tBuff ) { |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_25, kID, tBuff, tSize ); |
|||
free( tBuff ); |
|||
}; |
|||
tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 128, m_sLRF_DATA.base_shift, "data/assets/images/lfs_draw_empty_12.png" ); |
|||
if ( tBuff ) { |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_2D_12, kID, tBuff, tSize ); |
|||
free( tBuff ); |
|||
}; |
|||
tBuff = create2dDraw( &tSize, (uint32_t *) th_data, th_size, 1024, m_sLRF_DATA.base_shift, "data/assets/images/2d_MAP.png" ); |
|||
if ( tBuff ) { |
|||
m_pDBC->addDeviceDraw( getNodeID(), DRAW_MODE_MAP, kID, tBuff, tSize ); |
|||
free( tBuff ); |
|||
}; |
|||
break; |
|||
}; |
|||
case ARGUS_3D_SENSOR:{ |
|||
char * emptyBG = "data/assets/images/empty_3d.png"; |
|||
thresholdNode * ptr = (thresholdNode *) th_data; |
|||
|
|||
if ( fileExist( emptyBG ) ) { |
|||
cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED ); |
|||
if( tImage.rows != 512 || tImage.cols != 1024 ){ |
|||
LOG_ERROR( "Background Image wrong size (should be 1024x512)!" ); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
|
|||
uint8_t * tMemory = tImage.data; |
|||
thresholdNode * cNode = NULL; |
|||
uint8_t * cPixel = NULL; |
|||
int pix = 0; |
|||
int mem = 0; |
|||
bool s_bit = false; |
|||
bool no_data = false; |
|||
float tVal; |
|||
bool master = ( kID < 16 ); |
|||
|
|||
for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|||
if( ( idx % 4 ) == 0 ){ |
|||
mem++; |
|||
if ( master ) { |
|||
cNode = ptr + TH_SIZE_NODES - mem - 1; |
|||
} else { |
|||
cNode = ptr + mem - 1; |
|||
}; |
|||
if( !s_bit ) s_bit = cNode->values.sbit; |
|||
if( !no_data ) no_data = ( cNode->values.cnt == 0 ); |
|||
if( !s_bit && !no_data ){ |
|||
if( byMinimum ) { |
|||
tVal = ((float)cNode->values.min) / 4096.f; |
|||
} else { |
|||
tVal = ((float)cNode->values.max) / 4096.f; |
|||
}; |
|||
}; |
|||
}; |
|||
if( ( idx % 9 ) == 0 ){ |
|||
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) { |
|||
cPixel = tMemory + (pix << 2); |
|||
pix++; |
|||
if( s_bit ) { // Set Red
|
|||
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff; |
|||
} else { |
|||
if( no_data ) { // Set Blue
|
|||
cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
s_bit = false; |
|||
no_data = false; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", uid ); |
|||
//int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
|
|||
vector<int> compression_params; |
|||
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION ); |
|||
compression_params.push_back(9); |
|||
if(! cv::imwrite( filename, tImage, compression_params ) ){ |
|||
tImage.release(); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
tImage.release(); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Draw Saved!"); |
|||
#endif
|
|||
cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 ); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Map Creating"); |
|||
#endif
|
|||
tMemory = tMap.data; |
|||
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 ];
|
|||
int ids = 0; |
|||
int idd = 0; |
|||
if ( master ) { |
|||
//cNode = ptr+makeIds( i, j , true );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , true ); |
|||
idd = 4 * makeIds( i, j , false ); |
|||
//cNode = ptr + ( i * j );
|
|||
//cPixel = tMemory + ( cSpace * i * j );
|
|||
} else { |
|||
//cNode = ptr+makeIds( i, j , false );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , false ); |
|||
idd = 4 * makeIds( i, j , false ); |
|||
}; |
|||
|
|||
cNode = ptr + ids ; |
|||
cPixel = tMemory + idd; |
|||
|
|||
if( 0 ) { // 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] = 0x00; |
|||
cPixel[2] = 0xff; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
if( cNode->values.cnt == 0 ) { |
|||
// Set Blue
|
|||
cPixel[0] = 0xff; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0x00; |
|||
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] = 0xff; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0x00; |
|||
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
|
|||
}; |
|||
}; |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_map.png", uid ); |
|||
LOG(filename); |
|||
if(! cv::imwrite( filename, tMap, compression_params ) ){ |
|||
tMap.release(); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
tMap.release(); |
|||
m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true ); |
|||
} else { |
|||
LOG_ERROR( "Background Image is Not Found!" ); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
free( uid ); |
|||
return true; |
|||
}; |
|||
|
|||
/*
|
|||
#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 argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){ |
|||
uint8_t *tMemory = NULL; |
|||
thresholdNode *cNode = NULL; |
|||
uint8_t *cPixel = NULL; |
|||
int cSpace; |
|||
|
|||
|
|||
int x, y; |
|||
tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default ); |
|||
|
|||
if( tMemory == NULL ){ |
|||
LOG_ERROR("Draw Memory Alloc Eror!"); |
|||
return false; |
|||
}; |
|||
|
|||
if( x != 1024 || y != 512 ){ |
|||
LOG("Wrong IMG Size!"); |
|||
free( tMemory ); |
|||
return NULL; |
|||
}; |
|||
|
|||
int pix = 0; |
|||
int mem = 0; |
|||
bool s_bit = false; |
|||
bool no_data = false; |
|||
float tVal; |
|||
|
|||
for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|||
|
|||
if( ( idx % 4 ) == 0 ){ |
|||
mem++; |
|||
if ( master ) { |
|||
cNode = ptr + TH_SIZE_NODES - mem - 1; |
|||
} else { |
|||
cNode = ptr + mem - 1; |
|||
}; |
|||
if( !s_bit ) s_bit = cNode->values.sbit; |
|||
if( !no_data ) no_data = ( cNode->values.cnt == 0 ); |
|||
if( !s_bit && !no_data ){ |
|||
if( byMinimum ) { |
|||
tVal = ((float)cNode->values.min) / 4096.f; |
|||
} else { |
|||
tVal = ((float)cNode->values.max) / 4096.f; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
if( ( idx % 9 ) == 0 ){ |
|||
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) { |
|||
cPixel = tMemory + (pix << 2); |
|||
pix++; |
|||
if( s_bit ) { // Set Red
|
|||
cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff; |
|||
} else { |
|||
if( no_data ) { // Set Blue
|
|||
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
s_bit = false; |
|||
no_data = false; |
|||
} |
|||
}; |
|||
}; |
|||
|
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", uid ); |
|||
int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace ); |
|||
free( tMemory ); |
|||
if( RetVal == 0 ) return false; |
|||
|
|||
if( monochrome ) { |
|||
cSpace = 1; |
|||
} else { |
|||
cSpace = 4; |
|||
}; |
|||
|
|||
tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace ); |
|||
if( tMemory == NULL ){ |
|||
LOG_ERROR("Map 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 ];
|
|||
int ids = 0; |
|||
int idd = 0; |
|||
if ( master ) { |
|||
//cNode = ptr+makeIds( i, j , true );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , true ); |
|||
idd = cSpace * makeIds( i, j , false ); |
|||
//cNode = ptr + ( i * j );
|
|||
//cPixel = tMemory + ( cSpace * i * j );
|
|||
} else { |
|||
//cNode = ptr+makeIds( i, j , false );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , false ); |
|||
idd = cSpace * makeIds( i, j , false ); |
|||
}; |
|||
|
|||
cNode = ptr + ids ; |
|||
cPixel = tMemory + idd; |
|||
|
|||
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
|
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
sprintf( filename, "data/device_draws/%s_map.png", uid ); |
|||
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; |
|||
}; |
|||
*/ |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,106 @@ |
|||
#ifndef __ARGUS_NODE_SENSOR_HEADER__ |
|||
#define __ARGUS_NODE_SENSOR_HEADER__ |
|||
|
|||
#include "deviceNode.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../components/base/basicPosition.h" |
|||
#include "../../components/object/objectSystemAnchor.h" |
|||
#include "kernelEventFilter.h" |
|||
|
|||
#define ARGUS_LRF_PCMD_FULL_RESET 1 |
|||
#define ARGUS_LRF_PCMD_RESET 2 |
|||
#define ARGUS_LRF_PCMD_DRAW 3 |
|||
#define ARGUS_LRF_PCMD_GET_PROFILE 3 |
|||
|
|||
#define ARGUS_LRF_ROI_ACTIVATION 42 |
|||
#define ARGUS_LRF_PUSH_FALSE_TARGET 45 |
|||
|
|||
#define ARGUS_LRF_PCMD_SET_MASK_1 60 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_2 61 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_3 62 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_4 63 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_5 64 |
|||
|
|||
#define ARGUS_LRF_PCMD_MASK_1_ON 65 |
|||
#define ARGUS_LRF_PCMD_MASK_2_ON 66 |
|||
#define ARGUS_LRF_PCMD_MASK_3_ON 67 |
|||
#define ARGUS_LRF_PCMD_MASK_4_ON 68 |
|||
#define ARGUS_LRF_PCMD_MASK_5_ON 69 |
|||
|
|||
#define ARGUS_LRF_PCMD_MASK_1_OFF 70 |
|||
#define ARGUS_LRF_PCMD_MASK_2_OFF 71 |
|||
#define ARGUS_LRF_PCMD_MASK_3_OFF 72 |
|||
#define ARGUS_LRF_PCMD_MASK_4_OFF 73 |
|||
#define ARGUS_LRF_PCMD_MASK_5_OFF 74 |
|||
|
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_1 75 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_2 76 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_3 77 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_4 78 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_5 79 |
|||
|
|||
#define ARGUS_LRF_PCMD_SET_DP_0 100 |
|||
#define ARGUS_LRF_PCMD_SET_DP_1 101 |
|||
#define ARGUS_LRF_PCMD_SET_DP_2 102 |
|||
#define ARGUS_LRF_PCMD_SET_DP_3 103 |
|||
#define ARGUS_LRF_PCMD_UPLOAD_FILE 120 |
|||
|
|||
#define ARGUS_SYM_CMD_0 200 |
|||
#define ARGUS_SYM_CMD_1 201 |
|||
#define ARGUS_SYM_CMD_2 202 |
|||
#define ARGUS_SYM_CMD_3 203 |
|||
#define ARGUS_SYM_CMD_4 204 |
|||
#define ARGUS_SYM_CMD_5 205 |
|||
#define ARGUS_SYM_CMD_6 206 |
|||
#define ARGUS_SYM_CMD_7 207 |
|||
#define ARGUS_SYM_CMD_8 208 |
|||
#define ARGUS_SYM_CMD_9 209 |
|||
#define ARGUS_SYM_CMD_10 210 |
|||
|
|||
|
|||
|
|||
#define ARGUS_LRF_PCMD_UPDATE_ALL 255 |
|||
|
|||
|
|||
#define DRAW_MODE_RAW_DATA 0 |
|||
#define DRAW_MODE_MAP 1 |
|||
#define DRAW_MODE_3D 2 |
|||
#define DRAW_MODE_2D_100 3 |
|||
#define DRAW_MODE_2D_50 4 |
|||
#define DRAW_MODE_2D_25 5 |
|||
#define DRAW_MODE_2D_12 6 |
|||
|
|||
|
|||
#define NODE_CMD_RESET_STUDY 230 |
|||
#define NODE_CMD_FULL_RESET 235 |
|||
#define NODE_CMD_UPLOAD_SHADOW 234 |
|||
#define NODE_CMD_UPLOAD_FILE 240 |
|||
#define NODE_CMD_GET_DEVICE_DRAW 100 |
|||
#define NODE_CMD_ROI_ACTIVE 65 |
|||
#define NODE_CMD_ALARM 66 |
|||
#define NODE_CMD_UPDATE_SHADOW 67 |
|||
#define NODE_CMD_UPLOAD_SETTINGS_0 80 |
|||
#define NODE_CMD_UPLOAD_SETTINGS_1 81 |
|||
#define NODE_CMD_UPLOAD_SETTINGS_2 82 |
|||
#define NODE_CMD_UPLOAD_SETTINGS_3 83 |
|||
|
|||
class deviceNodeSensor: public deviceNode{ |
|||
protected: |
|||
DBC_LRF_DATA m_sLRF_DATA; |
|||
basicPosition m_oPosition; |
|||
basicEventHeap * m_pEventHeap; |
|||
basicEventClassID m_eEventClass; |
|||
kernelEventFilter * m_pTargetFilter; |
|||
bool handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum = true ); |
|||
uint8_t * create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum = true ); |
|||
public: |
|||
explicit deviceNodeSensor( uint32_t id ); |
|||
explicit deviceNodeSensor( DBC_NODE_DATA *Data ); |
|||
virtual ~deviceNodeSensor(); |
|||
virtual void simulateTarget( void ){}; |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,170 @@ |
|||
#include "deviceNodeStaticCamControl.h"
|
|||
|
|||
#define LOG( X ) deviceNode::m_pLog->Log( "STATIC_CAM", this, X )
|
|||
#define LOG_ERROR( X ) deviceNode::m_pLog->Log( "STATIC_CAM", this, _LOG_ERROR, X )
|
|||
|
|||
deviceNodeStaticCamControl::deviceNodeStaticCamControl( DBC_NODE_DATA *Data ): deviceNodeCamera( Data ), basicEventHandler(){ |
|||
//m_pLog = basicLogCollection::getInstance();
|
|||
/*
|
|||
DBC_CAM_DATA * tData = m_pDBC->getCamData( m_sNodeData.aux_id ); |
|||
|
|||
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f; |
|||
|
|||
if( tData != NULL ) { |
|||
memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) ); |
|||
free( tData ); |
|||
}; |
|||
memset( &m_sCtrlData, 0, sizeof(CAMERA_CTRL_DATA) ); |
|||
if( m_sCamData.max_range == .0f ){ |
|||
m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 ); |
|||
} else { |
|||
m_fMaxRange = m_sCamData.max_range; |
|||
}; |
|||
m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f ); |
|||
m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f ); |
|||
m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f ); |
|||
m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f ); |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
LOG("Camera Info:"); |
|||
sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange); |
|||
LOG(tB); |
|||
sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov ); |
|||
LOG(tB); |
|||
sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov ); |
|||
LOG(tB); |
|||
#endif
|
|||
m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw ); |
|||
*/ |
|||
}; |
|||
|
|||
deviceNodeStaticCamControl::deviceNodeStaticCamControl( uint32_t id ): deviceNodeCamera( id ), basicEventHandler() { |
|||
m_sMediaSource.mediaSourceId = m_sNodeData.aux_id; |
|||
strncpy( m_sMediaSource.mediaName, m_sNodeData.name, 128 ); |
|||
m_sMediaSource.mediaName[127] = (char)0; |
|||
memset( &m_sCtrlData, 0, sizeof( CAMERA_CTRL_DATA )); |
|||
}; |
|||
|
|||
deviceNodeStaticCamControl::~deviceNodeStaticCamControl(){ |
|||
LOG("Destructor"); |
|||
stopService(); |
|||
}; |
|||
|
|||
bool deviceNodeStaticCamControl::startService(){ |
|||
return create(); |
|||
}; |
|||
|
|||
bool deviceNodeStaticCamControl::stopService(){ |
|||
return true; |
|||
}; |
|||
|
|||
void deviceNodeStaticCamControl::dispatchEvent( EVENT_CONTAINER *E ){ |
|||
if( E == NULL ) return; |
|||
//if( !m_bSourceConnected ) return;
|
|||
//if( m_bBusy ) return;
|
|||
switch( E->m_eClass ) { |
|||
case EVT_CLASS_SENSOR_CLD: |
|||
case EVT_CLASS_SENSOR_LGS: |
|||
case EVT_CLASS_SENSOR_LFS: |
|||
case EVT_CLASS_SENSOR_MND: |
|||
case EVT_CLASS_SENSOR_PLS_210: |
|||
case EVT_CLASS_SENSOR_PLS_360: |
|||
case EVT_CLASS_SENSOR_ALS: |
|||
case EVT_CLASS_SENSOR_3D: |
|||
case EVT_CLASS_SENSOR_ACC:{ |
|||
switch( E->m_eType ) { |
|||
case EVT_TARGET_1D: |
|||
case EVT_TARGET_2D_BLACK: |
|||
case EVT_TARGET_2D_WHITE: |
|||
case EVT_TARGET_3D_BLACK: |
|||
case EVT_TARGET_3D_WHITE:{ |
|||
TARGET_DATA *tDATA; |
|||
tDATA = (TARGET_DATA *)E->m_pEvtData; |
|||
if( tDATA ) { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG( "CHECK CAMERA FOV" ); |
|||
#endif
|
|||
if (testFOV(tDATA->system_target)) { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("TARGET IN CAMERA FOV"); |
|||
#endif
|
|||
makeSnap(E->m_db_id); |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_CLASS_CAMERA_CTRL:{ |
|||
/*
|
|||
if( E->m_nDestinationUID == m_sCamData.node_id ) { |
|||
switch( E->m_eType ) { |
|||
case EVT_CAMERA_DM:{ |
|||
CAMERA_CTRL_DATA *tDATA = (CAMERA_CTRL_DATA *)E->m_pEvtData; |
|||
if( tDATA != NULL ) { |
|||
if( tDATA->moveMask & 0x08 == 0x08 ){ |
|||
//Relative Move cmd
|
|||
if( tDATA->moveMask & 0x07 == 0 ){ |
|||
relativeStop(); |
|||
} else { |
|||
relativeMove( tDATA->spdPAN, tDATA->spdTILT, tDATA->spdZOOM ); |
|||
}; |
|||
} else { |
|||
if( tDATA->moveMask & 0xF0 != 0x00 ) { |
|||
absoluteMove( tDATA->absPAN, tDATA->absTILT, tDATA->absZOOM ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
} |
|||
;*/ |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool deviceNodeStaticCamControl::validate(){ |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("VALIDATE"); |
|||
#endif
|
|||
if( CAM_WS_END == getWM() ) return false; |
|||
// Validate Camera Settings
|
|||
/*{
|
|||
DBC_CAM_DATA *tDATA = argusNetNode::m_pDBC->getCamData( m_sNodeData.aux_id ); |
|||
if( tDATA ) { |
|||
if( memcmp( &m_sCamData, tDATA, sizeof(DBC_CAM_DATA)) != 0 ){ |
|||
free( tDATA ); |
|||
LOG("Cam Settings Changed!"); |
|||
return false; |
|||
}; |
|||
free( tDATA ); |
|||
} else{ |
|||
LOG("Cam Deleted!"); |
|||
return false; |
|||
}; |
|||
}*/ |
|||
// Validate Stream -> Moved to Video Encooder
|
|||
/*
|
|||
{ |
|||
if( m_sNodeData.aux_parameter ) { |
|||
//LOG("VALIDATE Stream");
|
|||
if( !m_bSourceConnected ) { |
|||
if( connectToStream( m_sNodeData.aux_parameter ) ) { |
|||
argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter ); |
|||
} else { |
|||
argusNetNode::m_pDBC->setStreamValid( m_sNodeData.aux_parameter, false ); |
|||
}; |
|||
} else { |
|||
validateStream(); |
|||
}; |
|||
}; |
|||
} |
|||
*/ |
|||
return deviceNodeCamera::validate(); |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,44 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// 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 __DEVICE_STATIC_CAMERA_CTRL_HEADER__ |
|||
#define __DEVICE_STATIC_CAMERA_CTRL_HEADER__ |
|||
|
|||
#include "deviceNodeCamera.h" |
|||
#include "../components/base/basicEventHandler.h" |
|||
#include "../components/base/basicEventHeap.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 deviceNodeStaticCamControl: public deviceNodeCamera, public basicEventHandler { |
|||
protected: |
|||
CAMERA_CTRL_DATA m_sCtrlData; |
|||
public: |
|||
explicit deviceNodeStaticCamControl( uint32_t id ); |
|||
explicit deviceNodeStaticCamControl( DBC_NODE_DATA *Data ); |
|||
virtual ~deviceNodeStaticCamControl(); |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
1380
lib/App/common/hardwareManager.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,56 @@ |
|||
#ifndef __DFSL_HARDWARE_MANAGER_HEADER__ |
|||
#define __DFSL_HARDWARE_MANAGER_HEADER__ |
|||
|
|||
#include "../components/base/basicLogCollection.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "hardwareResource.h" |
|||
|
|||
|
|||
|
|||
class hardwareManager{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
VECTOR_HW_RESOURCES m_vResources; |
|||
basicMutex m_mVectorProtector; |
|||
dataBinder * m_pDBC; |
|||
DBC_SYS_INFO m_sSYS_INFO; |
|||
uint32_t m_nServerNodeID; |
|||
uint32_t m_nServerID; // Prop of DBC |
|||
uint32_t m_nSiteID; // Prop of Kernel |
|||
|
|||
size_t m_nMemoryLimitHeapSize; |
|||
|
|||
//bool m_bHardwareEnumerated; |
|||
void loadResources( void ); |
|||
void unloadResources( void ); |
|||
|
|||
uint32_t createResourceUART( CSTR devName ); |
|||
uint32_t createResourceVIDEO( CSTR devName ); |
|||
uint32_t createResourceUDCB( CSTR devName ); |
|||
uint32_t createResourceNETWORK( CSTR devName ); |
|||
void enumerateNIFS( void ); |
|||
void getMAC( CSTR if_name, CSTR buf ); |
|||
void getGW( CSTR if_name, CSTR buf ); |
|||
void getTTyDesc( CSTR dev_name, CSTR buf ); |
|||
/* Linux System Parsers */ |
|||
PARSE_RESULT_NET_INTERFACES * parse_neconfig( CSTR if_name ); |
|||
PARSE_RESULT_WIFI_SETTINGS * parse_wifi( CSTR if_name ); |
|||
public: |
|||
virtual ~hardwareManager(); |
|||
static hardwareManager * getInstance( bool cold_start = true ); |
|||
bool validate( void ); |
|||
hardwareResource * requestResource( HARDWARE_PROVIDERS type, uint32_t id ); |
|||
DBC_INT_LIST * requestResourcesByType( HARDWARE_PROVIDERS type ); |
|||
void enumerateHardware( void ); |
|||
bool assignResource( hardwareResource *ptr ); |
|||
bool resignResource( hardwareResource *ptr ); |
|||
bool updateSysInfo( DBC_SYS_LOAD_INFO *ptr ); |
|||
private: |
|||
static hardwareManager * _instance; |
|||
explicit hardwareManager( bool cold_start ); |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,255 @@ |
|||
#include "hardwareResource.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "HWR", 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( "HWR", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "HWR", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
hardwareResource::hardwareResource(): basicObject(){ |
|||
m_bValid = false; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_UNKNOWN; |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
|
|||
hardwareResource::hardwareResource( uint32_t id, HARDWARE_PROVIDERS type ): basicObject(){ |
|||
m_bValid = false; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
m_eProviderType = type; |
|||
if( id > 0 ){ |
|||
if( m_pDBC!=NULL ){ |
|||
DBC_RESOURCE_DATA *tData = m_pDBC->getResourceData( id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sResourceSettings, tData, sizeof(DBC_RESOURCE_DATA)); |
|||
free( tData ); |
|||
#ifdef DEBUG
|
|||
char tBuff[256]; |
|||
#endif
|
|||
switch( m_sResourceSettings.type ) { |
|||
case HARDWARE_USB_DC:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "USB Dry Contact [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_DRY_CONTACT; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_VIDEO_IN:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_VIDEO_OUT:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_UART:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP UART [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_SERIAL; |
|||
break; |
|||
}; |
|||
case HARDWARE_ANALOG_VIDEO_IN:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Analog Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_ANALOG_VIDEO_OUT:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Analog Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_NIF_LOOPBACK: |
|||
case HARDWARE_NIF_ETHERNET: |
|||
case HARDWARE_NIF_WIFI: |
|||
case HARDWARE_NIF_VIRTUAL: |
|||
case HARDWARE_NIF_TUNEL:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Network Interface [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_NETWORK; |
|||
break; |
|||
}; |
|||
case HARDWARE_UART:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "HW UART [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_SERIAL; |
|||
break; |
|||
}; |
|||
default:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Unknown Resource Type [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_UNKNOWN; |
|||
break; |
|||
}; |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG( tBuff ); |
|||
#endif
|
|||
} else { |
|||
LOG_ERROR("Cannot Fetch Hardware Data from DB!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Database Object!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Resource ID not set!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
}; |
|||
|
|||
hardwareResource::~hardwareResource(){ |
|||
}; |
|||
|
|||
bool hardwareResource::create( uint32_t id, HARDWARE_PROVIDERS type ){ |
|||
m_bValid = false; |
|||
m_eProviderType = type; |
|||
if( id > 0 ){ |
|||
if( m_pDBC!=NULL ){ |
|||
DBC_RESOURCE_DATA *tData = m_pDBC->getResourceData( id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sResourceSettings, tData, sizeof(DBC_RESOURCE_DATA)); |
|||
free( tData ); |
|||
#ifdef DEBUG
|
|||
char tBuff[256]; |
|||
#endif
|
|||
switch( m_sResourceSettings.type ) { |
|||
case HARDWARE_USB_DC:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "USB Dry Contact [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_DRY_CONTACT; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_VIDEO_IN:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_VIDEO_OUT:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_IP_UART:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "IP UART [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_SERIAL; |
|||
break; |
|||
}; |
|||
case HARDWARE_ANALOG_VIDEO_IN:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Analog Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_ANALOG_VIDEO_OUT:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Analog Video IN [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_VIDEO; |
|||
break; |
|||
}; |
|||
case HARDWARE_NIF_LOOPBACK: |
|||
case HARDWARE_NIF_ETHERNET: |
|||
case HARDWARE_NIF_WIFI: |
|||
case HARDWARE_NIF_VIRTUAL: |
|||
case HARDWARE_NIF_TUNEL:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Network Interface [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_NETWORK; |
|||
break; |
|||
}; |
|||
case HARDWARE_UART:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "HW UART [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_SERIAL; |
|||
break; |
|||
}; |
|||
default:{ |
|||
#ifdef DEBUG
|
|||
sprintf( tBuff, "Unknown Resource Type [%d] id: %d aux: %d", m_sResourceSettings.type, id, m_sResourceSettings.aux_id ); |
|||
#endif
|
|||
m_eProviderType = HARDWARE_PROVIDER_UNKNOWN; |
|||
break; |
|||
}; |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG( tBuff ); |
|||
#endif
|
|||
} else { |
|||
LOG_ERROR("Cannot Fetch Hardware Data from DB!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Database Object!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
return true; |
|||
} else { |
|||
LOG_ERROR("Resource ID not set!"); |
|||
memset( &m_sResourceSettings, 0, sizeof( DBC_RESOURCE_DATA )); |
|||
m_sResourceSettings.id = id; |
|||
m_sResourceSettings.type = HARDWARE_UNKNOWN; |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,67 @@ |
|||
#ifndef __DFSL_HARDWARE_RESOURCE_HEADER__ |
|||
#define __DFSL_HARDWARE_RESOURCE_HEADER__ |
|||
|
|||
#include "../components/base/basicObject.h" |
|||
#include "../components/base/basicLogCollection.h" |
|||
#include "dataBinder.h" |
|||
|
|||
#include <linux/types.h> |
|||
#include <arpa/inet.h> |
|||
|
|||
#include <vector> |
|||
|
|||
#define DBC_RESOURCE_DESC_SIZE 64 |
|||
|
|||
typedef struct S_PARSE_RESULT_NET_INTERFACES{ |
|||
bool enabled; |
|||
bool if_static; |
|||
bool hot_plug; |
|||
char address[INET6_ADDRSTRLEN]; |
|||
char netmask[INET6_ADDRSTRLEN]; |
|||
char gateway[INET6_ADDRSTRLEN]; |
|||
}PARSE_RESULT_NET_INTERFACES; |
|||
|
|||
typedef struct S_PARSE_RESULT_WIFI_SETTINGS{ |
|||
char SSID[64]; |
|||
char password[64]; |
|||
WIFI_ENCRIPTION encryption; |
|||
bool access_point; |
|||
uint8_t channel; |
|||
char country_code[3]; |
|||
bool hiden_ssid; |
|||
/* Router Settings */ |
|||
bool router_enabled; |
|||
char router_outbond[INET6_ADDRSTRLEN]; |
|||
/* DHCP */ |
|||
bool dhcp_enabled; |
|||
char range_start[INET6_ADDRSTRLEN]; |
|||
char range_stop[INET6_ADDRSTRLEN]; |
|||
char netmask[INET6_ADDRSTRLEN]; |
|||
char lease_period[INET6_ADDRSTRLEN]; |
|||
}PARSE_RESULT_WIFI_SETTINGS; |
|||
|
|||
|
|||
class hardwareResource: public basicObject{ |
|||
protected: |
|||
HARDWARE_PROVIDERS m_eProviderType; |
|||
DBC_RESOURCE_DATA m_sResourceSettings; |
|||
dataBinder * m_pDBC; |
|||
basicLogCollection * m_pLog; |
|||
bool m_bValid; |
|||
public: |
|||
hardwareResource(); |
|||
hardwareResource( uint32_t id, HARDWARE_PROVIDERS type = HARDWARE_PROVIDER_UNKNOWN ); |
|||
virtual ~hardwareResource(); |
|||
virtual bool create( void ){ return false; }; |
|||
virtual bool create( uint32_t id, HARDWARE_PROVIDERS type ); |
|||
virtual bool validate( void ){ return m_bValid; }; |
|||
bool isValid( void ){ return m_bValid; }; |
|||
uint32_t getDbId( void ){ return m_sResourceSettings.aux_id; }; |
|||
RESOURCE_TYPE getHardwareType( void ){ return (RESOURCE_TYPE) m_sResourceSettings.type; }; |
|||
HARDWARE_PROVIDERS getProviderType( void ){ return m_eProviderType; }; |
|||
}; |
|||
|
|||
|
|||
typedef std::vector<hardwareResource *> VECTOR_HW_RESOURCES; |
|||
|
|||
#endif |
|||
@ -0,0 +1,24 @@ |
|||
#include "hardwareResourceDryContactProvider.h"
|
|||
|
|||
#define LOG( X ) hardwareResource::m_pLog->Log( "HWR_DRYC", 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 );\ |
|||
hardwareResource::m_pLog->Log( "HWR_DRYC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) hardwareResource::m_pLog->Log( "HWR_DRYC", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
hardwareResourceUSBDCB::hardwareResourceUSBDCB( uint32_t id ): hardwareResource( id, HARDWARE_PROVIDER_DRY_CONTACT ){ |
|||
|
|||
}; |
|||
|
|||
hardwareResourceUSBDCB::~hardwareResourceUSBDCB(){ |
|||
|
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,11 @@ |
|||
#ifndef __DFSL_HARDWARE_RESOURCE_USB_DCB_HEADER__ |
|||
#define __DFSL_HARDWARE_RESOURCE_USB_DCB_HEADER__ |
|||
#include "hardwareResource.h" |
|||
|
|||
class hardwareResourceUSBDCB: public hardwareResource { |
|||
public: |
|||
explicit hardwareResourceUSBDCB( uint32_t id ); |
|||
virtual ~hardwareResourceUSBDCB(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,115 @@ |
|||
#include "hardwareResourceNetworkProvider.h"
|
|||
|
|||
#define LOG( X ) hardwareResource::m_pLog->Log( "HWR_NETWORK", 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 );\ |
|||
hardwareResource::m_pLog->Log( "HWR_NETWORK", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) hardwareResource::m_pLog->Log( "HWR_NETWORK", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
hardwareResourceNetwork::hardwareResourceNetwork( uint32_t id, HARDWARE_PROVIDERS type ):hardwareResource( id, type ){ |
|||
if( m_pDBC!= NULL ){ |
|||
DBC_NET_IF_DATA *tData = m_pDBC->getNIF_Data( m_sResourceSettings.aux_id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sNetworkData, tData, sizeof(DBC_NET_IF_DATA)); |
|||
DBC_INT_LIST *nIDS = m_pDBC->listNetworks( m_sNetworkData.id ); |
|||
if( nIDS ){ |
|||
if( nIDS->size() ){ |
|||
LOG("Hawe Network Records!"); |
|||
m_sNetworkData.networkCount = nIDS->size(); |
|||
m_sNetworkData.networks = (DBC_NETWORK_DATA **)calloc(m_sNetworkData.networkCount, sizeof(DBC_NETWORK_DATA)); |
|||
if( m_sNetworkData.networks ){ |
|||
int i = 0; |
|||
for( DBC_INT_LIST::iterator idx=nIDS->begin(); idx<nIDS->end(); i++, idx++){ |
|||
m_sNetworkData.networks[i] = m_pDBC->getNetworkData( *idx ); |
|||
#ifdef DEBUG
|
|||
if ( m_sNetworkData.networks[i] ) { |
|||
LOG( m_sNetworkData.networks[i]->address ); |
|||
LOG( m_sNetworkData.networks[i]->netmask ); |
|||
}; |
|||
#endif
|
|||
}; |
|||
m_bValid = true; |
|||
} else { |
|||
LOG_ERROR("NOMEM FOR Network Records!"); |
|||
m_sNetworkData.networkCount = 0; |
|||
}; |
|||
}; |
|||
delete( nIDS ); |
|||
}; |
|||
free( tData ); |
|||
} else { |
|||
LOG_ERROR("No Data FROM DBC!"); |
|||
memset( &m_sNetworkData, 0, sizeof(DBC_NET_IF_DATA)); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No DBC!"); |
|||
memset( &m_sNetworkData, 0, sizeof(DBC_NET_IF_DATA)); |
|||
}; |
|||
}; |
|||
|
|||
hardwareResourceNetwork::~hardwareResourceNetwork(){ |
|||
|
|||
}; |
|||
|
|||
CSTR hardwareResourceNetwork::getAddress( NETWORK_TYPE nt ){ |
|||
if( m_sNetworkData.networkCount ) { |
|||
for ( int i = 0; i < m_sNetworkData.networkCount; i++ ){ |
|||
if (m_sNetworkData.networks[i]->type == nt ) { |
|||
if(m_sNetworkData.networks[i]->address[0] != (char)0) { |
|||
return strdup( m_sNetworkData.networks[i]->address ); |
|||
}; |
|||
break; |
|||
} |
|||
}; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR hardwareResourceNetwork::getBroadcast( NETWORK_TYPE nt ){ |
|||
if( m_sNetworkData.networkCount ) { |
|||
for ( int i = 0; i < m_sNetworkData.networkCount; i++ ){ |
|||
if (m_sNetworkData.networks[i]->type == nt ) { |
|||
if( m_sNetworkData.networks[i]->broadcast[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.networks[i]->broadcast ); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR hardwareResourceNetwork::getMask( NETWORK_TYPE nt ){ |
|||
if( m_sNetworkData.networkCount ) { |
|||
for ( int i = 0; i < m_sNetworkData.networkCount; i++ ){ |
|||
if (m_sNetworkData.networks[i]->type == nt ) { |
|||
if( m_sNetworkData.networks[i]->netmask[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.networks[i]->netmask ); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR hardwareResourceNetwork::getGateway( NETWORK_TYPE nt ){ |
|||
if( m_sNetworkData.networkCount ) { |
|||
for ( int i = 0; i < m_sNetworkData.networkCount; i++ ){ |
|||
if (m_sNetworkData.networks[i]->type == nt ) { |
|||
if (m_sNetworkData.networks[i]->gateway[0] != (char)0) { |
|||
return strdup( m_sNetworkData.networks[i]->gateway ); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,19 @@ |
|||
#ifndef __DFSL_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
#define __DFSL_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
|
|||
#include "hardwareResource.h" |
|||
|
|||
class hardwareResourceNetwork: public hardwareResource { |
|||
private: |
|||
DBC_NET_IF_DATA m_sNetworkData; |
|||
public: |
|||
explicit hardwareResourceNetwork( uint32_t id, HARDWARE_PROVIDERS type = HARDWARE_PROVIDER_NETWORK ); |
|||
virtual ~hardwareResourceNetwork(); |
|||
CSTR getAddress( NETWORK_TYPE nt=NETWORK_IPV4 ); |
|||
CSTR getBroadcast( NETWORK_TYPE nt=NETWORK_IPV4 ); |
|||
CSTR getMask( NETWORK_TYPE nt=NETWORK_IPV4 ); |
|||
CSTR getGateway( NETWORK_TYPE nt=NETWORK_IPV4 ); |
|||
virtual bool create( void ){ return true; }; |
|||
}; |
|||
|
|||
#endif |
|||
1140
lib/App/common/hardwareResourceSerialProvider.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,77 @@ |
|||
#ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__ |
|||
#define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__ |
|||
|
|||
#include "hardwareResource.h" |
|||
#include "../components/base/basicTransport.h" |
|||
#include "../components/base/basicDualThread.h" |
|||
|
|||
#include <stdio.h> // standard input / output functions |
|||
#include <stdlib.h> |
|||
#include <string.h> // string function definitions |
|||
#include <fcntl.h> // File control definitions |
|||
#include <errno.h> // Error number definitions |
|||
#ifdef __linux__ |
|||
#include <unistd.h> // UNIX standard function definitions |
|||
#include <termios.h> // POSIX terminal control definitions |
|||
#ifdef __arm__ |
|||
#ifdef RASPI_HARDWARE |
|||
#define USE_WIRINGPI |
|||
#include <wiringPi.h> |
|||
#endif |
|||
#endif |
|||
#endif |
|||
|
|||
|
|||
#ifdef DEBUG_EXTRA |
|||
#define DEBUG_SERIAL_COMMUNICATION |
|||
#endif |
|||
|
|||
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
#endif |
|||
|
|||
#ifndef MAXIMAL_SERIAL_PACKET_LENGTH |
|||
#define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#endif |
|||
|
|||
class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicDualThread { |
|||
private: |
|||
DBC_UART_DATA m_sUartData; |
|||
|
|||
int m_iDeviceFD; |
|||
int m_iMasterFD; |
|||
#ifdef __linux__ |
|||
struct termios m_sTTY; |
|||
int m_iInFID; |
|||
int m_iOutFID; |
|||
bool m_bManualRTS; |
|||
void setRTS( uint8_t Val ); |
|||
#else |
|||
DCB PortDCB; |
|||
HANDLE m_ioFID; |
|||
#endif |
|||
bool pingDevice(); |
|||
bool create_SOL(); |
|||
bool create_HW(); |
|||
bool closePort(); |
|||
int sendBlock(unsigned char *Data, int DataSize); |
|||
int recptBlock(unsigned char *Buffer, int *BufferLength); |
|||
protected: |
|||
U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
int m_nInputBufferSize; |
|||
int m_nOutputBufferSize; |
|||
|
|||
virtual void m_fThreadAProc(void); |
|||
virtual void m_fThreadBProc(void); |
|||
public: |
|||
explicit hardwareResourceSerialProvider( uint32_t dbID ); |
|||
virtual ~hardwareResourceSerialProvider(); |
|||
virtual bool create( void ); |
|||
virtual bool validate( void ); |
|||
virtual bool sendData( uint8_t *Data, int DataSize ); |
|||
virtual bool reconnect( void ); |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,48 @@ |
|||
#include "hardwareResourceVideoProvider.h"
|
|||
|
|||
#define LOG( X ) hardwareResource::m_pLog->Log( "HWR_VIDEO", 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 );\ |
|||
hardwareResource::m_pLog->Log( "HWR_VIDEO", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) hardwareResource::m_pLog->Log( "HWR_VIDEO", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
hardwareResourceVideoProvider::hardwareResourceVideoProvider( uint32_t id, HARDWARE_PROVIDERS type ):hardwareResource( id, type ){ |
|||
if( m_pDBC!= NULL ){ |
|||
DBC_MEDIA_STREAM_DATA *tData = m_pDBC->getMediaStreamData( m_sResourceSettings.aux_id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sStreamData, tData, sizeof(DBC_MEDIA_STREAM_DATA)); |
|||
#ifdef DEBUG
|
|||
|
|||
#endif
|
|||
free( tData ); |
|||
} else { |
|||
memset( &m_sStreamData, 0, sizeof(DBC_MEDIA_STREAM_DATA)); |
|||
}; |
|||
} else { |
|||
memset( &m_sStreamData, 0, sizeof(DBC_MEDIA_STREAM_DATA)); |
|||
}; |
|||
}; |
|||
|
|||
hardwareResourceVideoProvider::~hardwareResourceVideoProvider(){ |
|||
m_pDBC->setStreamValid( m_sStreamData.id, false ); |
|||
}; |
|||
|
|||
bool hardwareResourceVideoProvider::create( void ){ |
|||
LOG("Creating Local Video Source!"); |
|||
if( m_pDBC->updateLocalCam( m_sStreamData.source_id ) ){ |
|||
LOG("Cam Updated!"); |
|||
return m_pDBC->setStreamValid( m_sStreamData.id ); |
|||
}; |
|||
LOG("Cam NOT! Updated!"); |
|||
return false; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,15 @@ |
|||
#ifndef __DFSL_HARDWARE_RESOURCE_VIDEO_HEADER__ |
|||
#define __DFSL_HARDWARE_RESOURCE_VIDEO_HEADER__ |
|||
|
|||
#include "hardwareResource.h" |
|||
|
|||
class hardwareResourceVideoProvider: public hardwareResource { |
|||
private: |
|||
DBC_MEDIA_STREAM_DATA m_sStreamData; |
|||
public: |
|||
explicit hardwareResourceVideoProvider( uint32_t id, HARDWARE_PROVIDERS type = HARDWARE_PROVIDER_VIDEO ); |
|||
virtual ~hardwareResourceVideoProvider(); |
|||
virtual bool create( void ); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,27 @@ |
|||
#include "kernelEventFilter.h"
|
|||
|
|||
kernelEventFilter::kernelEventFilter( uint32_t id, TARGET_FILTER_TYPE type ){ |
|||
m_nDBID = id; |
|||
//m_pDBC = argusDBC::getInstance();
|
|||
m_bActive = false; |
|||
m_bFilterType = type; |
|||
//if( m_pDBC != NULL ) {
|
|||
//DBC_NODE_DATA *tData = NULL;
|
|||
//tData = m_pDBC->getNodeData( m_nDBID );
|
|||
//if( tData != NULL ) {
|
|||
// memcpy( &m_sNodeData , tData, sizeof(DBC_NODE_DATA));
|
|||
// free( tData );
|
|||
//} else {
|
|||
// memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA));
|
|||
// m_sNodeData.type = ARGUS_UNKNOWN;
|
|||
// m_sNodeData.node_id = id;
|
|||
//};
|
|||
//} else {
|
|||
//memset( &m_sNodeData , 0, sizeof(DBC_NODE_DATA));
|
|||
//m_sNodeData.type = ARGUS_UNKNOWN;
|
|||
//m_sNodeData.node_id = id;
|
|||
//};
|
|||
}; |
|||
|
|||
kernelEventFilter::~kernelEventFilter(){ |
|||
}; |
|||
@ -0,0 +1,33 @@ |
|||
#ifndef __KERNEL_EVENT_FILTER_HEADER__ |
|||
#define __KERNEL_EVENT_FILTER_HEADER__ |
|||
|
|||
#include "../../components/base/basicEvent.h" |
|||
#include "../../components/base/basicPosition.h" |
|||
#include "dataBinder.h" |
|||
|
|||
typedef enum E_TARGET_FILTER_TYPE{ |
|||
TF_UDEFINED_FILTER = 0, |
|||
TF_AUTHORISED_PEOPLE_FILTER = 1, |
|||
TF_LA_METRO_TRAIN_FILTER = 2 |
|||
}TARGET_FILTER_TYPE; |
|||
|
|||
class kernelEventFilter{ |
|||
protected: |
|||
uint32_t m_nDBID; |
|||
uint8_t m_bFilterType; |
|||
bool m_bActive; |
|||
public: |
|||
explicit kernelEventFilter( uint32_t id, TARGET_FILTER_TYPE type = TF_UDEFINED_FILTER ); |
|||
virtual ~kernelEventFilter(); |
|||
virtual bool validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ return true; }; |
|||
virtual bool initFilter(){ return true; }; |
|||
virtual bool stopFilter(){ return true; }; |
|||
uint32_t getID(){ return m_nDBID; }; |
|||
uint8_t getType(){ return m_bFilterType; }; |
|||
bool pause(); |
|||
bool resume(); |
|||
}; |
|||
|
|||
typedef vector<kernelEventFilter *> vectorKernelEventFilters; |
|||
|
|||
#endif |
|||
@ -0,0 +1,226 @@ |
|||
#include "kernelEventFilterAPF.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "APF", 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( "APF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "APF", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
kernelEventFilterAPF::kernelEventFilterAPF( uint32_t id ):kernelEventFilter( id, TF_AUTHORISED_PEOPLE_FILTER ), basicThread() { |
|||
m_iSocketFD = -1; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pPosition = new basicPosition(); |
|||
m_fDeltaX = 0.5f; |
|||
m_fDeltaY = 0.5f; |
|||
m_fDeltaZ = 1.0f; |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
memset( &m_Settings, 0, sizeof(DBC_APF_DATA)); |
|||
DBC_APF_DATA *tData = m_pDBC->getAPFData( m_nDBID ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_Settings, tData, sizeof(DBC_APF_DATA)); |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
|
|||
kernelEventFilterAPF::~kernelEventFilterAPF(){ |
|||
LOG("Stoping Filter!"); |
|||
stopFilter(); |
|||
}; |
|||
|
|||
bool kernelEventFilterAPF::initFilter(){ |
|||
#ifdef DEBUG
|
|||
LOG("Init Started"); |
|||
#endif
|
|||
struct sockaddr_in servaddr; |
|||
|
|||
// Creating socket file descriptor
|
|||
if(( m_iSocketFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ){ |
|||
LOG_ERROR("socket creation failed"); |
|||
return false; |
|||
}; |
|||
memset(&servaddr, 0, sizeof(servaddr)); |
|||
|
|||
// Filling server information
|
|||
servaddr.sin_family = AF_INET; // IPv4
|
|||
servaddr.sin_addr.s_addr = INADDR_ANY; |
|||
servaddr.sin_port = htons( m_Settings.port ); |
|||
|
|||
// Bind the socket with the server address
|
|||
if( bind(m_iSocketFD, (const struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ){ |
|||
LOG_ERROR( "bind failed" ); |
|||
return false; |
|||
}; |
|||
|
|||
#ifdef DEBUG
|
|||
LOG("UDP PORT LISTEN"); |
|||
#endif
|
|||
if( m_pPosition ) { |
|||
m_pPosition->setPositionDeg( m_Settings.lat, m_Settings.lon, m_Settings.alt, m_Settings.roll, m_Settings.pitch, m_Settings.yaw, 0.f ); |
|||
return init(); |
|||
}; |
|||
LOG_ERROR( "POSITION ERROR!" ); |
|||
stopFilter(); |
|||
return false; |
|||
}; |
|||
|
|||
bool kernelEventFilterAPF::stopFilter(){ |
|||
if( m_bActive ) { |
|||
m_bActive = false; |
|||
|
|||
int tSocketFD = -1; |
|||
struct sockaddr_in servaddr; |
|||
// Creating socket file descriptor
|
|||
if(( tSocketFD = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0 ){ |
|||
LOG_ERROR("socket creation failed"); |
|||
return false; |
|||
}; |
|||
memset(&servaddr, 0, sizeof(servaddr)); |
|||
|
|||
// Filling server information
|
|||
servaddr.sin_family = AF_INET; // IPv4
|
|||
servaddr.sin_addr.s_addr = INADDR_ANY; |
|||
servaddr.sin_port = htons( m_Settings.port ); |
|||
char *message="shutdown:"; |
|||
int slen=sizeof( servaddr ); |
|||
if( sendto( tSocketFD, message, strlen(message), 0 , (struct sockaddr *) &servaddr, slen) == -1 ){ |
|||
LOG_ERROR("Failure to Send Shutdown Command!"); |
|||
}; |
|||
}; |
|||
|
|||
waitThreadEnd( true ); |
|||
|
|||
if( m_iSocketFD > -1 ){ |
|||
shutdown( m_iSocketFD, 2 ); |
|||
}; |
|||
if( m_vBounds.size() ) { |
|||
for( V_BOUNDS::iterator idx = m_vBounds.begin(); idx < m_vBounds.end(); idx++ ) { |
|||
free( *idx ); |
|||
}; |
|||
m_vBounds.clear(); |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
bool kernelEventFilterAPF::validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ |
|||
if( m_bActive ) { |
|||
if( m_vBounds.size() > 0 ) { |
|||
for( V_BOUNDS::iterator idx = m_vBounds.begin(); idx < m_vBounds.end(); idx++ ) { |
|||
bool X,Y,Z; |
|||
#ifdef DEBUG
|
|||
char tBuf[100]; |
|||
// COMP: -41.34x-9.50x-6.18 <> -41.78x-8.50x-15.87
|
|||
sprintf( tBuf,"COMP: %0.2fx%0.2fx%0.2f <> %0.2fx%0.2fx%0.2f", ptr->system_target.x, ptr->system_target.y, ptr->system_target.z, (*idx)->position.x, (*idx)->position.y, (*idx)->position.z ); |
|||
LOG( tBuf ); |
|||
#endif
|
|||
X = ( ptr->system_target.x < (*idx)->position.x+m_fDeltaX ) && ( ptr->system_target.x > (*idx)->position.x-m_fDeltaX ); |
|||
Y = ( ptr->system_target.y < (*idx)->position.y+m_fDeltaY ) && ( ptr->system_target.y > (*idx)->position.y-m_fDeltaY ); |
|||
Z = ( ptr->system_target.z < (*idx)->position.z+m_fDeltaZ ) && ( ptr->system_target.z > (*idx)->position.z-m_fDeltaZ ); |
|||
if( X && Y && Z ) return false; |
|||
}; |
|||
}; |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
APF_BOUNDARY *kernelEventFilterAPF::getBoxByID( CSTR id ){ |
|||
if( m_vBounds.size() ) { |
|||
for( V_BOUNDS::iterator idx = m_vBounds.begin(); idx < m_vBounds.end(); idx++ ) { |
|||
if( strstr( (*idx)->idc, id )!= NULL ){ |
|||
return (*idx); |
|||
}; |
|||
}; |
|||
}; |
|||
return NULL; |
|||
}; |
|||
void kernelEventFilterAPF::m_fThreadProc( void ){ |
|||
struct sockaddr_in CA; |
|||
socklen_t caLen; |
|||
int dLen; |
|||
char inBuff[1024]; |
|||
|
|||
caLen = sizeof(CA); |
|||
memset(&CA, 0, caLen); |
|||
m_bActive = true; |
|||
m_bThreadStatus = TH_WORKING; |
|||
while (m_bThreadStatus < TH_ENDED) { |
|||
memset( inBuff, 0, 1024 ); |
|||
if( m_bActive ){ |
|||
dLen = recvfrom( m_iSocketFD, (char *)inBuff, 1024, MSG_WAITALL, ( struct sockaddr *) &CA, &caLen ); |
|||
} else { |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG( "Filter deactivated!"); |
|||
#endif
|
|||
continue; |
|||
}; |
|||
if( dLen < 0 ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
LOG_ERROR( "RECV error!"); |
|||
continue; |
|||
}; |
|||
//char tB[128];
|
|||
//LOG( inBuff );
|
|||
//sprintf( tB, "Received %d Bytes", dLen );
|
|||
//LOG( tB );
|
|||
if( strstr( inBuff, "display:" ) != NULL ) { |
|||
CSTR PACK = inBuff+8; |
|||
CArray *Parts; |
|||
if( m_pPosition == NULL ) continue; |
|||
Parts = explode( ',', PACK ); |
|||
if( Parts != NULL ) { |
|||
APF_BOUNDARY * tBOX; |
|||
tBOX = getBoxByID( (*Parts)[1] ); |
|||
if( tBOX == NULL ) { |
|||
tBOX = (APF_BOUNDARY *) malloc( sizeof(APF_BOUNDARY)); |
|||
memset( tBOX, 0, sizeof(APF_BOUNDARY) ); |
|||
strncpy( tBOX->idc, (*Parts)[1], 16 ); |
|||
m_vBounds.push_back( tBOX ); |
|||
}; |
|||
systemAnchor* tSystem = systemAnchor::getInstance(); |
|||
if( tSystem != NULL ) { |
|||
C3D_DECART tDecart; |
|||
//C3D_SPH_DEGREES
|
|||
C3D_SPH_RADIANS tSpherical; |
|||
tDecart.x = atof( (*Parts)[6] );//Y
|
|||
tDecart.y = atof( (*Parts)[5] );//X
|
|||
tDecart.z = atof( (*Parts)[7] );//Z
|
|||
decart2spherical( tDecart, tSpherical ); |
|||
tSystem->convertToSystem( m_pPosition, tSpherical, tBOX->position ); |
|||
m_pDBC->updateAFPBox( m_nDBID, (*Parts)[1], tDecart.x, tDecart.y, tDecart.z ); |
|||
} else { |
|||
LOG_ERROR("No SYSTEM ANCHOR!"); |
|||
} |
|||
delete( Parts ); |
|||
}; |
|||
}; |
|||
if( strstr( inBuff, "shutdown:" ) != NULL ){ |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG( "Shutdown Requested!"); |
|||
#endif
|
|||
continue; |
|||
}; |
|||
SLEEP( 2 ); |
|||
}; |
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,41 @@ |
|||
#ifndef __KERNEL_EVENT_FILTER_APF_HEADER__ |
|||
#define __KERNEL_EVENT_FILTER_APF_HEADER__ |
|||
|
|||
#include "kernelEventFilter.h" |
|||
#include "../../components/object/objectSystemAnchor.h" |
|||
#include "../../components/base/basicThread.h" |
|||
|
|||
#include "dataBinder.h" |
|||
|
|||
typedef struct S_APF_BOUNDARY{ |
|||
char idc[16]; |
|||
C3D_DECART position; |
|||
}APF_BOUNDARY; |
|||
|
|||
typedef vector<APF_BOUNDARY *> V_BOUNDS; |
|||
|
|||
class kernelEventFilterAPF: public kernelEventFilter, public basicThread{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
basicPosition * m_pPosition; |
|||
int m_iSocketFD; |
|||
V_BOUNDS m_vBounds; |
|||
DBC_APF_DATA m_Settings; |
|||
dataBinder * m_pDBC; |
|||
/* CUBE DEFENITION IN METERS */ |
|||
float m_fDeltaX; |
|||
float m_fDeltaY; |
|||
float m_fDeltaZ; |
|||
|
|||
APF_BOUNDARY * getBoxByID( CSTR id ); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelEventFilterAPF( uint32_t id ); |
|||
virtual ~kernelEventFilterAPF(); |
|||
virtual bool initFilter(); |
|||
virtual bool stopFilter(); |
|||
virtual bool validateTarget( uint32_t DevID, TARGET_DATA *ptr ); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,38 @@ |
|||
#include "kernelModule.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
kernelModule::kernelModule( uint32_t id, KERNEL_MODULE_TYPE type ): basicEventHandler(), basicObject(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
//m_pKernel = argusKernel::getInstance();
|
|||
m_eType = type; |
|||
m_nDBID = id; |
|||
m_bDetached = false; |
|||
m_bEnabled = false; |
|||
m_nDBAUXID = 0; |
|||
|
|||
// Clear Events flags
|
|||
if( m_pDBC ) { |
|||
DBC_MODULE_DATA *tData = NULL; |
|||
tData = m_pDBC->getModuleData( m_nDBID ); |
|||
if( tData ) { |
|||
m_nDBAUXID = tData->aux_id; |
|||
m_bEnabled = tData->enabled; |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
for( int i = 0; i < EVT_COUNT; i++ ) m_bEvtFlags[i] = false; |
|||
}; |
|||
|
|||
kernelModule::~kernelModule(){ |
|||
}; |
|||
|
|||
@ -0,0 +1,58 @@ |
|||
#ifndef __DFSL_KERNEL_MODULE_HEADER__ |
|||
#define __DFSL_KERNEL_MODULE_HEADER__ |
|||
|
|||
#include <vector> |
|||
|
|||
#include "../../components/base/basicObject.h" |
|||
#include "../../components/base/basicEngine.h" |
|||
#include "../../components/base/basicEventHandler.h" |
|||
#include "../../components/base/basicLogCollection.h" |
|||
#include "dataBinder.h" |
|||
|
|||
|
|||
typedef enum E_KERNEL_MODULE_TYPE{ |
|||
KERNEL_MODULE_UNKNOWN = 0, |
|||
//KERNEL_MODULE_ZLMEDIA = 1, |
|||
KERNEL_MODULE_DCBUSB = 1, |
|||
KERNEL_MODULE_KAFKA = 2, |
|||
KERNEL_MODULE_GPS = 3, |
|||
KERNEL_MODULE_NETWORK = 4, |
|||
KERNEL_MODULE_FLYHUNTER = 5, |
|||
KERNEL_MODULE_SSDP_ANONCE = 6, |
|||
KERNEL_MODULE_ONVIF_OBSERVER = 7, |
|||
KERNEL_MODULE_EMBED_VIDEO = 8, |
|||
KERNEL_MODULE_MODEM_MANAGER = 9 |
|||
}KERNEL_MODULE_TYPE; |
|||
|
|||
class kernelModule: public basicEventHandler, basicObject{ |
|||
protected: |
|||
basicLogCollection * m_pLog; |
|||
dataBinder * m_pDBC; |
|||
uint32_t m_nDBID; |
|||
uint32_t m_nDBAUXID; |
|||
bool m_bEnabled; |
|||
bool m_bDetached; |
|||
bool m_bEvtFlags[EVT_COUNT]; |
|||
KERNEL_MODULE_TYPE m_eType; |
|||
public: |
|||
explicit kernelModule( uint32_t id, KERNEL_MODULE_TYPE type = KERNEL_MODULE_UNKNOWN ); |
|||
virtual ~kernelModule(); |
|||
uint32_t getId() const { return m_nDBID; }; |
|||
uint32_t getAuxId() const { return m_nDBAUXID; }; |
|||
KERNEL_MODULE_TYPE getType() const { return m_eType; }; |
|||
bool isDetached() const { return m_bDetached; }; |
|||
bool isAttached() const { return !m_bDetached; }; |
|||
bool isEnabled() const { return m_bEnabled;}; |
|||
virtual bool reloadSettings(){ return false; }; |
|||
void setAttached( bool b=true ){ m_bDetached = !b; }; |
|||
void setDetached( bool b=true ){ m_bDetached = b; }; |
|||
virtual bool startService(){ return false; }; |
|||
virtual bool stopService( bool force = false ){ return true; }; |
|||
virtual bool validate(){ return false; }; |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ){}; |
|||
}; |
|||
|
|||
typedef std::vector<kernelModule*> vectorKernelModules; |
|||
|
|||
#endif |
|||
|
|||
2211
lib/App/common/kernelModuleEmbedVideo.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,319 @@ |
|||
#ifndef __KERNEL_MODULE_EMBED_VIDEO_HEADER__ |
|||
#define __KERNEL_MODULE_EMBED_VIDEO_HEADER__ |
|||
#include "kernelModule.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
//#include "../data/media/video/videoAVLIBDestination.h" |
|||
#include "../components/base/basicMediaSource.h" |
|||
#include "../components/base/basicMediaDestination.h" |
|||
|
|||
class kernelModuleEmbedVideo; |
|||
|
|||
#define FILESTREAMBUFFERSZ 1048576 |
|||
|
|||
#define EVE_ENABLE_VIDEO |
|||
|
|||
|
|||
|
|||
//#define USE_SCALING_IN |
|||
|
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
|
|||
//#define EVE_DONT_DELETE_SEGMENTS |
|||
|
|||
/* Video CODECS */ |
|||
#define VC_VPX 0 |
|||
#define VC_X264 1 |
|||
#define VC_MP4 2 |
|||
#define VC_MJPEG 3 |
|||
#define VC_FLV 4 |
|||
|
|||
/* Video FORMATS */ |
|||
#define VF_WEBM 0 |
|||
#define VF_MP4 1 |
|||
#define VF_MP3 2 |
|||
#define VF_AAC 3 |
|||
#define VF_OGG 4 |
|||
#define VF_MJPEG 5 |
|||
#define VF_FLV 6 |
|||
|
|||
/* Encoder PROFILES */ |
|||
#define VP_ULTRAFAST 0 |
|||
#define VP_VERYFAST 1 |
|||
#define VP_FAST 2 |
|||
#define VP_MEDIUM 3 |
|||
#define VP_SLOW 4 |
|||
#define VP_VERYSLOW 5 |
|||
#define VP_ULTRASLOW 6 |
|||
|
|||
#define VO_MJPEG 1 |
|||
#define VO_MPEG4 2 |
|||
#define VO_H264 3 |
|||
#define VO_H265 4 |
|||
#define VO_FLV 5 |
|||
|
|||
//#define VIDEO_OUTPUT VO_MJPEG |
|||
//#define VIDEO_OUTPUT VO_MPEG4 |
|||
#define VIDEO_OUTPUT VO_H264 |
|||
//#define VIDEO_OUTPUT VO_H265 |
|||
//#define VIDEO_OUTPUT VO_FLV |
|||
|
|||
//#define VIDEO_OUTPUT_WIDTH 640 //1920 |
|||
//#define VIDEO_OUTPUT_HEIGHT 480 //1080 |
|||
//#define VIDEO_OUTPUT_FPS 10 |
|||
//#define VIDEO_OUTPUT_GOP 15 |
|||
|
|||
#if( LIBAVCODEC_VERSION_MAJOR < 54 ) |
|||
#define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P |
|||
#else |
|||
#if VIDEO_OUTPUT == VO_MJPEG |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUVJ422P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mpeg" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "webm" |
|||
#elif VIDEO_OUTPUT == VO_MPEG4 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_H264 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_H265 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H265 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_FLV |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "flv" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "flv" |
|||
#endif |
|||
#endif |
|||
|
|||
#endif //EVE_ENABLE_VIDEO |
|||
|
|||
typedef struct S_buffer_data { |
|||
uint8_t * buf; |
|||
int size; |
|||
uint8_t * ptr; |
|||
size_t room; ///< size left in the buffer |
|||
} buffer_data; |
|||
|
|||
#define NR_COLORS 4 |
|||
#define AVIO_BUFFER_SIZE 4096 |
|||
#define BD_BUFFER_SIZE 1024 |
|||
|
|||
class streamHandler; |
|||
|
|||
typedef struct S_WEB_CLIENT_CTX{ |
|||
int m_iSocketFID; |
|||
int m_iEncoderPipe[2]; |
|||
bool bValid; |
|||
bool initDone; |
|||
bool headerIsSent; |
|||
uint32_t mediaStreamId; |
|||
streamHandler * m_pHandler; |
|||
kernelModuleEmbedVideo * ModulePtr; |
|||
}WEB_CLIENT_CTX; |
|||
|
|||
|
|||
typedef struct S_WEB_HANDLER{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
WEB_CLIENT_CTX * CTX; |
|||
}WEB_HANDLER; |
|||
|
|||
typedef vector<WEB_HANDLER*> vectorHANDLERS; |
|||
|
|||
|
|||
//typedef vector<STREAM_CTX*> vectorSTREAMS; |
|||
|
|||
typedef struct S_STREAM_CAP{ |
|||
uint32_t stream_id; |
|||
uint32_t buffer_size; |
|||
uint8_t picture_buffer; |
|||
}STREAM_CAP; |
|||
|
|||
typedef struct S_VIDEO_EVT{ |
|||
uint32_t dbid; |
|||
uint32_t frame; |
|||
}VIDEO_EVT; |
|||
|
|||
typedef vector<uchar> compressedFRAME; |
|||
typedef map<uint32_t, compressedFRAME> mapSTREAMCAPS; |
|||
typedef map<uint32_t, cv::Mat> mapSTREAMMAPS; |
|||
|
|||
#define PRE_ALARM_TIME_MILSECONDS 2000 // 2 sec |
|||
#define POST_ALARM_TIME_MILSECONDS 2000 // 2 sec |
|||
#define ENCODING_SEGMENT_MILSECONDS 50000 // 50 sec |
|||
#define ENCODING_SEGMENT_LIMIT_MILSECONDS 60000 // 1 minute |
|||
//#define ENCODING_SEGMENT_LIMIT_MILSECONDS 900000 // 15 minute |
|||
|
|||
#define EVE_OUTPUT_PICTURES 1 |
|||
#define EVE_OUTPUT_VIDEO 2 |
|||
#define EVE_OUTPUT_PIC_AND_VID 3 |
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
|
|||
typedef struct S_ENCODING_BUFFER{ |
|||
int linesize[2]; |
|||
int rows; |
|||
uint8_t * data[2]; |
|||
size_t size; |
|||
}ENCODING_BUFFER; |
|||
|
|||
typedef std::queue<ENCODING_BUFFER *> Q_ENCODING_BUFFER; |
|||
|
|||
#endif |
|||
class streamHandler: |
|||
public basicMediaDestination |
|||
#ifdef EVE_ENABLE_VIDEO |
|||
, public basicThread |
|||
#endif |
|||
{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
basicMediaSource * m_pSource; |
|||
MEDIA_SOURCE_DESC m_sSourceDesc; |
|||
char m_cSourceType; |
|||
DBC_MEDIA_STREAM_DATA m_sStreamData; |
|||
basicMutex m_mProtector; |
|||
kernelModuleEmbedVideo * m_pMaster; |
|||
uint8_t m_bEvtMarkerCounter; |
|||
uint8_t m_bCamMoveCounter; |
|||
dataBinder * m_pDBC; |
|||
MS_WORK_MODE m_eWM; |
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
basicMutex m_mFrameCounterProtector; |
|||
uint32_t m_nPreAlarmFrames; |
|||
uint32_t m_nPostAlarmFrames; |
|||
uint32_t m_nGlobalFrameCounter; |
|||
uint32_t m_nVideoRegisteredDBID; |
|||
uint32_t m_nSegAFrameCounter; |
|||
uint32_t m_nSegBFrameCounter; |
|||
uint32_t m_nSegAShiftFrames; |
|||
uint32_t m_nSegBShiftFrames; |
|||
uint32_t m_nSegASkippedFrames; |
|||
uint32_t m_nSegBSkippedFrames; |
|||
uint32_t m_nSegmentLimitFrames; |
|||
uint32_t m_nHardLimitFrames; |
|||
uint8_t m_bActiveEncoderStream; |
|||
bool m_bSegAActive; |
|||
bool m_bSegADelete; |
|||
bool m_bSegBActive; |
|||
bool m_bSegBDelete; |
|||
basicMutex m_mCurrentOperationProtector; |
|||
uint8_t m_bCOP; |
|||
char m_cSegNameA[128]; |
|||
char m_cSegMD5A[33]; |
|||
char m_cSegNameB[128]; |
|||
char m_cSegMD5B[33]; |
|||
// encoding video stuff |
|||
AVCodec * m_pVideoCodec; |
|||
AVCodecContext * m_pCodecCtx; |
|||
SwsContext * m_pConvertCtx; |
|||
AVFrame * m_pAVFrame; |
|||
uint8_t * m_pOutBuffer; |
|||
// File Context 2 units |
|||
AVOutputFormat * m_pFormat; |
|||
AVFormatContext * m_pFormatCtxA; |
|||
AVFormatContext * m_pFormatCtxB; |
|||
AVStream * m_pVideoStrA; |
|||
AVStream * m_pVideoStrB; |
|||
//common output options |
|||
AVDictionary * m_pFormatOpts; |
|||
|
|||
basicMutex m_mEncodingQueueProtector; |
|||
Q_ENCODING_BUFFER m_qEncodingQueue; |
|||
|
|||
bool openSegmentA( void ); |
|||
void closeSegmentA( void ); |
|||
bool openSegmentB( void ); |
|||
void closeSegmentB( void ); |
|||
void swapActiveStreams( void ); |
|||
void closeAll(); |
|||
bool initVideoOutput(); |
|||
protected: |
|||
void m_fThreadProc( void ); |
|||
#endif //EVE_ENABLE_VIDEO |
|||
|
|||
public: |
|||
explicit streamHandler( kernelModuleEmbedVideo *ptr, MS_WORK_MODE M = MS_MODE_DECODE_FRAMES ); |
|||
virtual ~streamHandler(); |
|||
bool create( dataBinder *ptr, uint32_t stremID ); |
|||
/* from Media Destination */ |
|||
virtual bool pushFrame( AVFrame *Frame, void* src = NULL); |
|||
//virtual void pushFrame( cv::Mat* Frame, void* src = NULL); |
|||
virtual bool pushFrame( cv::Mat &Frame, void* src = NULL); |
|||
bool triggerEvent( uint32_t &dbid, uint32_t &frame ); |
|||
bool triggerCamMove( void ); |
|||
bool validate( void ); |
|||
}; |
|||
|
|||
typedef map<uint32_t, streamHandler *> mapSTREAMHANDLERS; |
|||
|
|||
class kernelModuleEmbedVideo: public kernelModule, /*public basicMediaDestination,*/ public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
static void * webClientProc( void *ptr ); |
|||
int m_nSocketDescriptor; |
|||
basicMutex m_mHandlersProtector; |
|||
basicMutex m_mPictureProtector; |
|||
basicMutex m_mEncodedProtector; |
|||
vectorHANDLERS m_vHandlersPool; |
|||
DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData; |
|||
mapSTREAMCAPS m_mapCAPTURES; |
|||
mapSTREAMMAPS m_mapMATS; |
|||
mapSTREAMHANDLERS m_mapHANDLERS; |
|||
uint8_t * n_pNoSignalData; |
|||
uint32_t m_nNoSignalSize; |
|||
cv::Mat m_mLogoPic; |
|||
cv::Mat m_mLogoMask; |
|||
char m_pBaseSavePath[PATH_MAX]; |
|||
bool registerForMediaStream( uint32_t id, WEB_CLIENT_CTX *&CTX ); |
|||
bool saveStreamPicture( uint32_t id ); |
|||
bool saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ); |
|||
bool generateSavePicPath( CSTR MD5, CSTR Output ); |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelModuleEmbedVideo( uint32_t moduleID ); |
|||
~kernelModuleEmbedVideo(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
/* from Media Destination * / |
|||
virtual bool pushFrame( AVFrame *Frame, void* src = NULL); |
|||
//virtual void pushFrame( cv::Mat* Frame, void* src = NULL); |
|||
virtual bool pushFrame( cv::Mat &Frame, void* src = NULL); |
|||
/* Module Specific Functionality */ |
|||
int getWidh( void ); |
|||
int getHeight( void ); |
|||
bool registerStream( uint32_t streamID ); |
|||
bool unregisterStream( uint32_t streamID ); |
|||
|
|||
friend class streamHandler; |
|||
|
|||
}; |
|||
#endif |
|||
@ -0,0 +1,397 @@ |
|||
#include "kernelModuleFactory.h"
|
|||
#include "kernelModuleUSBRelay.h"
|
|||
#include "kernelModuleKafka.h"
|
|||
#include "kernelModuleFlyHunter.h"
|
|||
#include "kernelModuleSSDP.h"
|
|||
#include "kernelModuleOnvifObserver.h"
|
|||
#include "kernelModuleEmbedVideo.h"
|
|||
#include "kernelModuleModemManager.h"
|
|||
|
|||
#ifdef MEM_DEBUG
|
|||
#include "../alg/generic/heapDebug.h"
|
|||
#endif
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MFAC", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MFAC", this, _LOG_ERROR, X )
|
|||
|
|||
kernelModuleFactory * kernelModuleFactory::_instance = NULL; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
kernelModuleFactory* kernelModuleFactory::getInstance( uint32_t InstanceID ) { |
|||
if( NULL == _instance) { |
|||
_instance = new kernelModuleFactory( InstanceID ); |
|||
}; |
|||
return _instance; |
|||
}; |
|||
|
|||
kernelModuleFactory::kernelModuleFactory( uint32_t InstanceID ):basicThread(){ |
|||
m_nInstanceID = InstanceID; |
|||
m_bInitialValidatioonDone = false; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
init(); |
|||
}; |
|||
|
|||
kernelModuleFactory::~kernelModuleFactory(){ |
|||
waitThreadEnd( true ); |
|||
shutdownServices( true ); |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
void kernelModuleFactory::shutdownServices( bool force ){ |
|||
#ifdef DEBUG
|
|||
LOG("shutdownServices"); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() > 0 ){ |
|||
for( vectorKernelModules::iterator index = m_vKernelModules.begin(); index < m_vKernelModules.end(); index++ ){ |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
switch( (*index)->getType() ){ |
|||
//case KERNEL_MODULE_ZLMEDIA: sprintf( tB, "Stop Service of ZlMedia Module" ); break;
|
|||
case KERNEL_MODULE_DCBUSB: sprintf( tB, "Stop Service of DCUSB Module" ); break; |
|||
case KERNEL_MODULE_KAFKA: sprintf( tB, "Stop Service of KAFKA Module" ); break; |
|||
case KERNEL_MODULE_GPS: sprintf( tB, "Stop Service of GPS Module" ); break; |
|||
case KERNEL_MODULE_NETWORK: sprintf( tB, "Stop Service of Network Module" ); break; |
|||
case KERNEL_MODULE_FLYHUNTER: sprintf( tB, "Stop Service of FlyHunter Module" ); break; |
|||
case KERNEL_MODULE_SSDP_ANONCE: sprintf( tB, "Stop Service of SSDP Module" ); break; |
|||
case KERNEL_MODULE_ONVIF_OBSERVER: sprintf( tB, "Stop Service of OnVif Observer Module" ); break; |
|||
case KERNEL_MODULE_EMBED_VIDEO: sprintf( tB, "Stop Service of EmbedVideo Module" ); break; |
|||
case KERNEL_MODULE_MODEM_MANAGER: sprintf( tB, "Stop Service of Modem Manager Module" ); break; |
|||
default: sprintf( tB, "Stop Service of UNKNOWN[%d] Module", (*index)->getType() ); break; |
|||
}; |
|||
LOG( tB ); |
|||
#endif
|
|||
// (*index)->stopService( force );
|
|||
#ifdef DEBUG
|
|||
LOG("Done"); |
|||
#endif
|
|||
deleteModule( (*index) ); |
|||
#ifdef DEBUG
|
|||
LOG("Module is Deleted"); |
|||
#endif
|
|||
}; |
|||
m_vKernelModules.clear(); |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("Done shutdownServices"); |
|||
#endif
|
|||
}; |
|||
|
|||
bool kernelModuleFactory::loadModules(){ |
|||
DBC_INT_LIST *tList = NULL; |
|||
if( m_pDBC == NULL ) return false; |
|||
tList = m_pDBC->listModules(); |
|||
if( tList != NULL ) { |
|||
if( tList->size() ) { |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
sprintf( tB, "Have %d Modules to create!", tList->size() ); |
|||
LOG( tB ); |
|||
#endif
|
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createModule( *idx ); |
|||
tList->clear(); |
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("No Modules Defined"); |
|||
} |
|||
#endif
|
|||
delete( tList ); |
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("No Modules Defined"); |
|||
} |
|||
#endif
|
|||
return true; |
|||
}; |
|||
|
|||
kernelModule *kernelModuleFactory::createModule( int id ){ |
|||
kernelModule *tVal = NULL; |
|||
if( m_pDBC != NULL ){ |
|||
DBC_MODULE_DATA *tData = NULL; |
|||
|
|||
tData = m_pDBC->getModuleData( id ); |
|||
if( tData!= NULL ) { |
|||
switch( tData->type ) { |
|||
case KERNEL_MODULE_DCBUSB: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Dry Contact USB Module"); |
|||
#endif
|
|||
tVal = new kernelModuleUSBRelay( tData->module_id ); |
|||
|
|||
break; |
|||
case KERNEL_MODULE_KAFKA: |
|||
#ifdef DEBUG
|
|||
LOG("Creating KAFKA Module"); |
|||
#endif
|
|||
tVal = new kernelModuleKafka( tData->module_id ); |
|||
break; |
|||
case KERNEL_MODULE_FLYHUNTER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Fly Hunter Module"); |
|||
#endif
|
|||
tVal = new kernelModuleFlyHunter( tData->module_id ); |
|||
break; |
|||
case KERNEL_MODULE_SSDP_ANONCE: |
|||
#ifdef DEBUG
|
|||
LOG("Creating SSDP Announcer Module"); |
|||
#endif
|
|||
tVal = new kernelModuleSSDPAnnouncer( tData->module_id ); |
|||
break; |
|||
case KERNEL_MODULE_ONVIF_OBSERVER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating OnVif Observer Module"); |
|||
#endif
|
|||
if ( m_pDBC->isLocal() ) { |
|||
tVal = new kernelModuleOnvifObserver(tData->module_id); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("Module is Disabled Since Remote Database!"); |
|||
#endif
|
|||
}; |
|||
break; |
|||
case KERNEL_MODULE_EMBED_VIDEO: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Embed Video Module"); |
|||
#endif
|
|||
if ( m_pDBC->isLocal() ){ |
|||
tVal = new kernelModuleEmbedVideo( tData->module_id ); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("Module is Disabled Since Remote Database!"); |
|||
#endif
|
|||
}; |
|||
break; |
|||
case KERNEL_MODULE_MODEM_MANAGER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Modem Manager Module"); |
|||
#endif
|
|||
tVal = new kernelModuleModemManager( tData->module_id ); |
|||
break; |
|||
}; |
|||
free(tData); |
|||
} else { |
|||
LOG_ERROR("No Module Data Fetched!"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Database Object Assigned!"); |
|||
}; |
|||
if( tVal != NULL ){ |
|||
tVal->startService(); |
|||
m_mModulesProtector.lock(); |
|||
m_vKernelModules.push_back( tVal ); |
|||
m_mModulesProtector.unlock(); |
|||
}; |
|||
return tVal; |
|||
}; |
|||
|
|||
void kernelModuleFactory::deleteModule( kernelModule *M ){ |
|||
if( M ) { |
|||
M->stopService( true ); |
|||
switch( M->getType() ) { |
|||
case KERNEL_MODULE_DCBUSB: delete( (kernelModuleUSBRelay*) M ); break; |
|||
case KERNEL_MODULE_KAFKA: delete( (kernelModuleKafka*) M ); break; |
|||
case KERNEL_MODULE_FLYHUNTER: delete( (kernelModuleFlyHunter*) M ); break; |
|||
case KERNEL_MODULE_SSDP_ANONCE: delete( (kernelModuleSSDPAnnouncer*) M ); break; |
|||
case KERNEL_MODULE_ONVIF_OBSERVER: delete( (kernelModuleOnvifObserver*) M ); break; |
|||
case KERNEL_MODULE_EMBED_VIDEO: delete( (kernelModuleEmbedVideo*) M ); break; |
|||
case KERNEL_MODULE_MODEM_MANAGER: delete( (kernelModuleModemManager*) M ); break; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void kernelModuleFactory::deleteModule( int id ){ |
|||
if( m_vKernelModules.size() > id ) { |
|||
deleteModule( m_vKernelModules.at( id ) ); |
|||
m_vKernelModules.erase( m_vKernelModules.begin() + id ); |
|||
m_vKernelModules.shrink_to_fit(); |
|||
}; |
|||
}; |
|||
|
|||
uint32_t kernelModuleFactory::getModulesCount( KERNEL_MODULE_TYPE t ){ |
|||
uint32_t cnt = 0; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( int i=0; i < m_vKernelModules.size(); i++ ) { |
|||
if( m_vKernelModules.at(i)->getType() == t ) cnt++; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return cnt; |
|||
}; |
|||
|
|||
uint32_t kernelModuleFactory::fetchModules( KERNEL_MODULE_TYPE t, kernelModule**&RA ){ |
|||
uint32_t cnt = getModulesCount( t ); |
|||
RA = NULL; |
|||
if( cnt > 0 ) { |
|||
RA = ( kernelModule** ) calloc( cnt, sizeof( kernelModule* ) ); |
|||
if( RA!= NULL ) { |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
uint32_t idx = 0; |
|||
for( int i=0; i < m_vKernelModules.size(); i++ ) { |
|||
if( m_vKernelModules.at(i)->getType() == t ) { |
|||
RA[idx] = m_vKernelModules.at(i); |
|||
idx++; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
} else cnt = 0; |
|||
}; |
|||
return cnt; |
|||
}; |
|||
|
|||
kernelModule *kernelModuleFactory::getModule( uint32_t id ){ |
|||
kernelModule *RetVal = NULL; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ |
|||
if( (*idx)->getId() == id ) { |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return RetVal; |
|||
}; |
|||
|
|||
kernelModule *kernelModuleFactory::getModule( KERNEL_MODULE_TYPE t, uint32_t id ){ |
|||
kernelModule *RetVal = NULL; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ |
|||
if( id ){ |
|||
if( ( (*idx)->getType() == t ) && ( (*idx)->getId() == id ) ){ |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
} else { |
|||
if( (*idx)->getType() == t ){ |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool kernelModuleFactory::validate( void ){ |
|||
return ( m_bThreadStatus < TH_ENDED ); |
|||
}; |
|||
|
|||
void kernelModuleFactory::m_fThreadProc( void ){ |
|||
if( m_pDBC == NULL) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
} else { |
|||
DBC_INT_LIST *tList = NULL; |
|||
#ifdef MEM_DEBUG
|
|||
size_t memStart, memEnd, memDiff; |
|||
char MEM_MSG[256]; |
|||
#endif
|
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
#ifdef MEM_DEBUG
|
|||
memStart = getCurrentRSS(); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
DBC_INT_LIST tL; |
|||
for( int cm = 0; cm < m_vKernelModules.size(); cm++ ) tL.push_back( m_vKernelModules.at(cm)->getId() ); |
|||
tList = m_pDBC->listNewModules( &tL ); |
|||
tL.clear(); |
|||
} else { |
|||
tList = m_pDBC->listNewModules( NULL ); |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
if( tList != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("New Modules Exists!"); |
|||
#endif
|
|||
for( int index=0; index< tList->size(); index++) createModule(tList->at(index)); |
|||
tList->clear(); |
|||
delete( tList ); |
|||
}; |
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
//Get Full List
|
|||
//tList = NULL;
|
|||
tList = m_pDBC->listModules(); |
|||
if( tList != NULL ) { |
|||
int cm = 0; |
|||
while( cm < m_vKernelModules.size() ) { |
|||
//check if module removed
|
|||
bool tRemoved = true; |
|||
for( int lm = 0; lm < tList->size(); lm++ ) { |
|||
if( tList->at(lm) == m_vKernelModules.at( cm )->getId() ) { |
|||
tRemoved = false; |
|||
break; |
|||
}; |
|||
}; |
|||
if( !tRemoved ) { |
|||
// validate module
|
|||
m_vKernelModules.at( cm )->validate(); |
|||
cm++; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Delete Module!"); |
|||
#endif
|
|||
deleteModule( cm ); |
|||
}; |
|||
}; |
|||
tList->clear(); |
|||
delete( tList ); |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("All Modules Must be Deleted!"); |
|||
#endif
|
|||
while( m_vKernelModules.size() ) deleteModule( 0 ); |
|||
}; |
|||
} |
|||
#ifdef DEBUG_EXTRA
|
|||
else { |
|||
LOG("No Modules to Validate!"); |
|||
} |
|||
#endif
|
|||
; |
|||
m_mModulesProtector.unlock(); |
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
if( !m_bInitialValidatioonDone ) m_bInitialValidatioonDone = true; |
|||
for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
}; |
|||
}; |
|||
//--enable-gpl --enable-libx264 --enable-nonfree --extra-ldflags=-latomic --enable-omx --enable-omx-rpi
|
|||
//-rtsp_transport tcp
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,40 @@ |
|||
#ifndef __KERNEL_MODULE_FACTORY_HEADER__ |
|||
#define __KERNEL_MODULE_FACTORY_HEADER__ |
|||
|
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "kernelModule.h" |
|||
#include "dataBinder.h" |
|||
|
|||
|
|||
|
|||
class kernelModuleFactory: public basicThread{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
dataBinder * m_pDBC; |
|||
uint32_t m_nInstanceID; |
|||
vectorKernelModules m_vKernelModules; |
|||
basicMutex m_mModulesProtector; |
|||
bool m_bInitialValidatioonDone; |
|||
void deleteModule( kernelModule * ); |
|||
public: |
|||
static kernelModuleFactory * getInstance( uint32_t InstanceID = 0 ); |
|||
virtual ~kernelModuleFactory(); |
|||
kernelModule * createModule( int id ); |
|||
void deleteModule( int id ); |
|||
kernelModule * getModule( uint32_t id ); |
|||
kernelModule * getModule( KERNEL_MODULE_TYPE t, uint32_t id = 0 ); |
|||
uint32_t getModulesCount( KERNEL_MODULE_TYPE t ); |
|||
uint32_t fetchModules( KERNEL_MODULE_TYPE, kernelModule**&RA ); |
|||
bool loadModules( void ); |
|||
bool validate( void ); |
|||
void shutdownServices( bool force = false ); |
|||
bool isValidationDone( void ){ return m_bInitialValidatioonDone; }; |
|||
protected: |
|||
explicit kernelModuleFactory( uint32_t InstanceID ); |
|||
virtual void m_fThreadProc( void ); |
|||
private: |
|||
static kernelModuleFactory * _instance; |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,474 @@ |
|||
#include "kernelModuleFlyHunter.h"
|
|||
|
|||
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_FH", 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 );\ |
|||
kernelModule::m_pLog->Log( "MOD_FH", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_FH", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
kernelModuleFlyHunter::kernelModuleFlyHunter( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_FLYHUNTER ), basicThread(){ |
|||
memset( &m_sCurrentMission, 0, sizeof(FH_MISSION_DATA) ); |
|||
memset( &m_sCurrentlocation, 0 , sizeof(C3D_WGS84_LOC)); |
|||
m_pProtocol = NULL; |
|||
m_bEnabled = false; |
|||
m_bDroneStatus = FH_STATUS_NONE; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
}; |
|||
|
|||
kernelModuleFlyHunter::~kernelModuleFlyHunter(){ |
|||
m_bEnabled = false; |
|||
waitThreadEnd( true ); |
|||
if( m_pProtocol!= NULL ) delete( m_pProtocol ); |
|||
}; |
|||
|
|||
bool kernelModuleFlyHunter::startService(){ |
|||
LOG("Starting Service!"); |
|||
if( m_bEnabled ) return false; |
|||
DBC_FH_DATA *tData = m_pDBC->getFlyHunterData( m_nDBAUXID ); |
|||
if( tData == NULL ) return false; |
|||
m_sGCSlocation.lat = tData->lat; |
|||
m_sGCSlocation.lon = tData->lon; |
|||
m_sGCSlocation.alt = tData->alt; |
|||
|
|||
m_bWorkingMode = FH_WM_NONE; |
|||
#ifdef SIMULATE_FH
|
|||
m_bDroneStatus = FH_STATUS_INIT; |
|||
m_bEnabled = true; |
|||
m_fStepLat = 0.0f; |
|||
m_fStepLon = 0.0f; |
|||
m_fStepAlt = 0.0f; |
|||
return init(); |
|||
#else
|
|||
m_pProtocol = new protocolMAVLINK(); |
|||
if( m_pProtocol!= NULL ) { |
|||
m_bDroneStatus = FH_STATUS_INIT; |
|||
if( m_pProtocol->create() ) { |
|||
m_bEnabled = true; |
|||
return init(); |
|||
}; |
|||
}; |
|||
#endif
|
|||
return false; |
|||
}; |
|||
|
|||
bool kernelModuleFlyHunter::stopService( bool force ){ |
|||
return true; |
|||
}; |
|||
|
|||
void kernelModuleFlyHunter::m_fThreadProc(){ |
|||
m_bThreadStatus = TH_WORKING; |
|||
if( !m_bEnabled ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG("Module is Disabled!"); |
|||
#endif
|
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Module Started!"); |
|||
#endif
|
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
switch( m_bWorkingMode ) { |
|||
case FH_WM_CANCELING:{ |
|||
m_bWorkingMode = FH_WM_FTL; |
|||
#ifdef SIMULATE_FH
|
|||
m_nSymTO = SIMULATE_FH_FTL_TO; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_WM_MISSION_FLIGHT:{ |
|||
|
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){ |
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
|
|||
m_sCurrentlocation.lat = m_sCurrentlocation.lat + m_fStepLat; |
|||
m_sCurrentlocation.lon = m_sCurrentlocation.lon + m_fStepLon; |
|||
m_sCurrentlocation.alt = m_sCurrentlocation.alt + m_fStepAlt; |
|||
|
|||
} else { |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt = NULL; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
switch( m_sCurrentMission.type ) { |
|||
case FH_WM_OBSERVE: |
|||
LOG("OBSERVE Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_DEST_REACHED, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
break; |
|||
case FH_WM_JAMING: |
|||
LOG("JAMING Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_JAMING; |
|||
m_nJamingTO = m_nJamingTO; |
|||
break; |
|||
case FH_WM_INTERCEPT: |
|||
LOG("INTERCEPT Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_BEGIN, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_INTERCEPT; |
|||
#ifdef SIMULATE_FH
|
|||
m_nSymTO = SIMULATE_FH_INTERCEPT; |
|||
#endif
|
|||
break; |
|||
default: |
|||
LOG("No Mission Type SET!!"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_DEST_REACHED, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
}; |
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_INTERCEPT:{ |
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
//if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){
|
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
} else { |
|||
float R = RAND_MAX / rand(); |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt = NULL; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
#ifdef SIMULATE_FH
|
|||
if( R > 0.5 ) { |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_OK, NULL, NULL, evtData ); |
|||
} else { |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_NOK, NULL, NULL, evtData ); |
|||
}; |
|||
#endif
|
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_JAMING:{ |
|||
if( m_nJamingTO ) { |
|||
if( m_nJamingTO == 1 ) { |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_OFF, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( POSHOLD ); |
|||
#endif
|
|||
}; |
|||
m_nJamingTO--; |
|||
} else { |
|||
//If Accedently entering in this mode!
|
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( POSHOLD ); |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_HOOVERING:{ |
|||
// Just Hold Position FH_HOOVERING_INTERVAL seconds
|
|||
if( m_nHooveringTO ) { |
|||
if( m_nHooveringTO == 1 ) { |
|||
// No New Assigns -> Going Home
|
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( RTL ); |
|||
#else
|
|||
m_nSymTO = SIMULATE_FH_FTL_TO; |
|||
m_fStepLat = ( m_sGCSlocation.lat - m_sCurrentlocation.lat ) / m_nSymTO; |
|||
m_fStepLon = ( m_sGCSlocation.lon - m_sCurrentlocation.lon ) / m_nSymTO; |
|||
m_fStepAlt = ( m_sGCSlocation.alt - m_sCurrentlocation.alt ) / m_nSymTO; |
|||
#endif
|
|||
m_bWorkingMode = FH_WM_FTL; |
|||
|
|||
}; |
|||
m_nHooveringTO--; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_EMERGENCY_FTL: |
|||
case FH_WM_FTL:{ |
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){ |
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
|
|||
m_sCurrentlocation.lat = m_sCurrentlocation.lat + m_fStepLat; |
|||
m_sCurrentlocation.lon = m_sCurrentlocation.lon + m_fStepLon; |
|||
m_sCurrentlocation.alt = m_sCurrentlocation.alt + m_fStepAlt; |
|||
|
|||
} else { |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sGCSlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
// Turn Off Motors
|
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->broadcastArm( false ) ){ |
|||
// Stop Chakalaka!!
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
|
|||
switch( m_bDroneStatus ) { |
|||
case FH_STATUS_INIT:{ |
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->broadcastProtocolVersionReq() ){ |
|||
m_bDroneStatus = FH_STATUS_CONNECT; |
|||
} else SLEEP ( 1000 ); |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_STATUS_PREARM:{ |
|||
if( m_bWorkingMode > FH_WM_FTL ) { |
|||
#ifndef SIMULATE_FH
|
|||
// Turn On Motors
|
|||
if( m_pProtocol->broadcastArm( true ) ){ |
|||
//Run Chakalaka!!
|
|||
m_bDroneStatus = FH_STATUS_ARMED; |
|||
m_bWorkingMode = FH_WM_START_FLIGHT; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_ARMED; |
|||
m_bWorkingMode = FH_WM_START_FLIGHT; |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
case FH_STATUS_ARMED:{ |
|||
#ifndef SIMULATE_FH
|
|||
// Lift Up
|
|||
if( m_pProtocol->broadcastTakeoff( 10.0f ) ){ |
|||
m_bDroneStatus = FH_STATUS_FLYING; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_FLYING; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_STATUS_FLYING:{ |
|||
if( m_bWorkingMode == FH_WM_START_FLIGHT ){ |
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->setTargetPosition( m_sCurrentMission.location.lat, m_sCurrentMission.location.lon, m_sCurrentMission.location.alt, 0 ) ){ |
|||
m_bWorkingMode = FH_WM_MISSION_FLIGHT; |
|||
}; |
|||
#else
|
|||
m_bWorkingMode = FH_WM_MISSION_FLIGHT; |
|||
m_nSymTO = SIMULATE_FH_FLY; |
|||
|
|||
m_sCurrentlocation.lat = m_sGCSlocation.lat; |
|||
m_sCurrentlocation.lon = m_sGCSlocation.lon; |
|||
m_sCurrentlocation.alt = m_sGCSlocation.alt; |
|||
|
|||
m_fStepLat = ( m_sCurrentMission.location.lat - m_sGCSlocation.lat ) / m_nSymTO; |
|||
m_fStepLon = ( m_sCurrentMission.location.lon - m_sGCSlocation.lon ) / m_nSymTO; |
|||
m_fStepAlt = ( m_sCurrentMission.location.alt - m_sGCSlocation.alt ) / m_nSymTO; |
|||
#endif
|
|||
}; |
|||
//Update Position to other components
|
|||
if( m_nWayPointTO ) { |
|||
m_nWayPointTO --; |
|||
}; |
|||
if( m_nWayPointTO == 0 ){ |
|||
m_nWayPointTO = FH_WAYPOINT_UPDATE_INTERVAL; |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_WAYPOINT, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
};// Drone Status Switch
|
|||
#ifdef SIMULATE_FH
|
|||
SLEEP( 1000 ); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
void kernelModuleFlyHunter::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
if(!m_bEnabled) { |
|||
LOG("Module Disabled!"); |
|||
return; |
|||
} |
|||
if( Evt == NULL ) return; |
|||
switch( Evt->m_eClass ){ |
|||
case EVT_CLASS_EXTERNAL_CMD:{ |
|||
switch( Evt->m_eType ) { |
|||
case EVT_FH_MISSION_BEGIN:{ |
|||
if( |
|||
( ( m_bDroneStatus == FH_STATUS_PREARM ) && ( m_bWorkingMode == FH_WM_NONE ) ) || |
|||
( ( ( m_bDroneStatus == FH_STATUS_ARMED ) && ( ( m_bWorkingMode == FH_WM_HOOVERING ) || ( m_bWorkingMode == FH_WM_FTL ) ) ) ) |
|||
){ |
|||
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
DBC_EVT_RECORD * tEVT = m_pDBC->getEventByUUID( tData->targetUUID ); |
|||
if( tEVT ) { |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
evtData->location.lat = tEVT->lat; |
|||
evtData->location.lon = tEVT->lon; |
|||
evtData->location.alt = tEVT->alt; |
|||
sprintf( evtData->missionID, tData->evtUUID ); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_FLY_TO, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
memcpy( &m_sCurrentMission, evtData, sizeof(FH_MISSION_DATA) ); |
|||
m_sCurrentMission.type = FH_WM_INTERCEPT; |
|||
m_bWorkingMode = FH_WM_MISSION_BEGIN; |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
free( tEVT ); |
|||
} else { |
|||
// Not Found In Database
|
|||
}; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("BUSY!"); |
|||
char tB[128]; |
|||
sprintf( tB, "DS: %02d WM: %02d", m_bDroneStatus, m_bWorkingMode ); |
|||
LOG( tB ); |
|||
#endif
|
|||
if( Evt->m_pEvtData!= NULL ) { |
|||
FH_CTRL_DATA * tEData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
FH_CTRL_DATA * tNData = (FH_CTRL_DATA *) malloc(sizeof(FH_CTRL_DATA)); |
|||
if( tNData != NULL ) { |
|||
EVENT_CONTAINER * tEvt; |
|||
memcpy(tNData, tEData, sizeof(FH_CTRL_DATA)); |
|||
tEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_BUSY, NULL, NULL, tNData ); |
|||
if( tEvt!= NULL ) { |
|||
m_pEventHeap->broadcast( tEvt ); |
|||
} else { |
|||
free( tNData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_JAMING_BEGIN:{ // FH_CTRL_DATA
|
|||
if( m_bWorkingMode == FH_WM_MISSION_FLIGHT || m_bWorkingMode == FH_WM_HOOVERING || m_bWorkingMode == FH_WM_FTL ){ |
|||
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_bWorkingMode = FH_WM_JAMING; |
|||
m_sCurrentMission.type = FH_WM_JAMING; |
|||
m_nJamingTO = tData->param; |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
} else { |
|||
// No Jaming When No Mission is assigned
|
|||
if( Evt->m_pEvtData!= NULL ) { |
|||
FH_CTRL_DATA * tEData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
FH_CTRL_DATA * tNData = (FH_CTRL_DATA *) malloc(sizeof(FH_CTRL_DATA)); |
|||
if( tNData != NULL ) { |
|||
EVENT_CONTAINER * tEvt; |
|||
memcpy(tNData, tEData, sizeof(FH_CTRL_DATA)); |
|||
tEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_BUSY, NULL, NULL, tNData ); |
|||
if( tEvt!= NULL ) { |
|||
m_pEventHeap->broadcast( tEvt ); |
|||
} else { |
|||
free( tNData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_CANCEL_ACTION:{ |
|||
m_bWorkingMode = FH_WM_CANCELING; |
|||
break; |
|||
}; |
|||
}; // Case Class
|
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool kernelModuleFlyHunter::reloadSettings(){ |
|||
return true; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,73 @@ |
|||
#ifndef __KERNEL_MODULE_FLY_HUNTER_HEADER__ |
|||
#define __KERNEL_MODULE_FLY_HUNTER_HEADER__ |
|||
#include "kernelModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
|
|||
#include "../data/protocol/protocolMAVLINK.h" |
|||
|
|||
#define SIMULATE_FH |
|||
|
|||
#ifdef SIMULATE_FH |
|||
#define SIMULATE_FH_FLY 40 |
|||
#define SIMULATE_FH_INTERCEPT 30 |
|||
#define SIMULATE_FH_FTL_TO 40 |
|||
#endif |
|||
|
|||
typedef enum E_FH_STATUS{ |
|||
FH_STATUS_NONE = 0, |
|||
FH_STATUS_INIT = 1, |
|||
FH_STATUS_CONNECT = 2, |
|||
FH_STATUS_READ_DATA = 3, |
|||
FH_STATUS_ERROR = 4, |
|||
FH_STATUS_PREARM = 5, |
|||
FH_STATUS_ARMED = 6, |
|||
FH_STATUS_FLYING = 7 |
|||
}FH_STATUS; |
|||
|
|||
typedef enum E_FH_WM{ |
|||
FH_WM_NONE = 0, |
|||
FH_WM_CANCELING = 1, |
|||
FH_WM_HOOVERING = 2, |
|||
FH_WM_FTL = 3, |
|||
FH_WM_MISSION_BEGIN = 4, |
|||
FH_WM_START_FLIGHT = 5, |
|||
FH_WM_MISSION_FLIGHT = 6, |
|||
FH_WM_INTERCEPT = 7, |
|||
FH_WM_JAMING = 8, |
|||
FH_WM_OBSERVE = 9, |
|||
FH_WM_EMERGENCY_FTL = 10 |
|||
}FH_WM; |
|||
|
|||
#define FH_WAYPOINT_UPDATE_INTERVAL 15 |
|||
#define FH_HOOVERING_INTERVAL 25 |
|||
|
|||
class kernelModuleFlyHunter: public kernelModule, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
FH_MISSION_DATA m_sCurrentMission; |
|||
FH_WM m_bWorkingMode; |
|||
FH_STATUS m_bDroneStatus; |
|||
uint16_t m_nJamingTO; |
|||
uint16_t m_nWayPointTO; |
|||
uint16_t m_nHooveringTO; |
|||
#ifdef SIMULATE_FH |
|||
uint16_t m_nSymTO; |
|||
float m_fStepLat; |
|||
float m_fStepLon; |
|||
float m_fStepAlt; |
|||
#endif |
|||
C3D_WGS84_LOC m_sCurrentlocation; |
|||
C3D_WGS84_LOC m_sGCSlocation; |
|||
protocolMAVLINK * m_pProtocol; |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelModuleFlyHunter( uint32_t oduleID ); |
|||
~kernelModuleFlyHunter(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
}; |
|||
#endif |
|||
@ -0,0 +1,760 @@ |
|||
#include "kernelModuleKafka.h"
|
|||
//#include "mojoKernel.h"
|
|||
#include "../hardware/soc/general/3DLRF.h"
|
|||
#include "../data/json/json_tool.h"
|
|||
#include <strings.h>
|
|||
#include <json/value.h>
|
|||
#include <json/writer.h>
|
|||
#include <json/reader.h>
|
|||
|
|||
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_KAFKA", 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 );\ |
|||
kernelModule::m_pLog->Log( "MOD_KAFKA", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_KAFKA", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
kernelModuleKafka::kernelModuleKafka( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_KAFKA ){ |
|||
m_pProtocol = NULL; |
|||
m_bConsumerEnabled = false; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
partition = 0; //RdKafka::Topic::PARTITION_UA;
|
|||
//start_offset = RdKafka::Topic::OFFSET_END;// OFFSET_BEGINNING;
|
|||
start_offset = 0;//RdKafka::Topic::OFFSET_BEGINNING;
|
|||
//start_offset = RdKafka::Topic::OFFSET_STORED;
|
|||
|
|||
memset( m_sServerIP, 0 ,48 ); |
|||
CSTR TVAL = NULL;//m_pKernel->getServerIp();
|
|||
if ( TVAL ) { |
|||
strncpy( m_sServerIP, TVAL, 48 ); |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Get Argus Server IP!"); |
|||
strncpy( m_sServerIP, "192.168.0.127", 48 ); |
|||
}; |
|||
memset( m_sServerName, 0, 48 ); |
|||
TVAL = NULL;//m_pKernel->getServerName();
|
|||
if ( TVAL ) { |
|||
strncpy( m_sServerName, TVAL, 48 ); |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Get Argus Server Name!"); |
|||
strncpy( m_sServerName, "Argus Server", 48 ); |
|||
}; |
|||
|
|||
m_pEvtTemplates = (KAFKA_TEMPLATE***) calloc(EVT_CLASS_COUNT, sizeof(KAFKA_TEMPLATE**)); |
|||
if( m_pEvtTemplates!= NULL ) { |
|||
memset( m_pEvtTemplates, 0, EVT_CLASS_COUNT * sizeof(KAFKA_TEMPLATE**)); |
|||
} else LOG_ERROR("EVT Templates Memory Allocation Error!"); |
|||
/*
|
|||
Do it in Kernel!! |
|||
if ( m_pKernel!= NULL ) { |
|||
argusHardwareManager *tHWM = m_pKernel->getHardwareManager(); |
|||
if( tHWM != NULL ) { |
|||
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK ); |
|||
if( rIDS != NULL ) { |
|||
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){ |
|||
argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx ); |
|||
if( tRES != NULL ) { |
|||
m_pServerIP = tRES->getAddress(); |
|||
break; |
|||
} else { |
|||
LOG_ERROR("Cannot Get Resource!"); |
|||
}; |
|||
}; |
|||
delete( rIDS ); |
|||
} else { |
|||
LOG("No Networks Detected!"); |
|||
m_bEnabled = false; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No HW Manager"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Kernel"); |
|||
}; |
|||
*/ |
|||
}; |
|||
|
|||
kernelModuleKafka::~kernelModuleKafka(){ |
|||
|
|||
m_bEnabled = false; |
|||
|
|||
waitThreadEnd( true ); |
|||
|
|||
if( m_pProtocol!= NULL ) { |
|||
delete( m_pProtocol ); |
|||
}; |
|||
|
|||
if( m_pEvtTemplates!= NULL ) { |
|||
for(int i=0; i < EVT_CLASS_COUNT; i++ ) { |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
for( int j=0; j< EVT_COUNT; j++ ) { |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl ); |
|||
free( m_pEvtTemplates[i][j] ); |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates[i] ); |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates ); |
|||
}; |
|||
}; |
|||
/* Periodical Job Handler */ |
|||
void kernelModuleKafka::m_fThreadProc( void ){ |
|||
#ifdef SIMULATOR
|
|||
float sim_Az = 0.f; |
|||
float sim_El = 20.f; |
|||
float sim_Ran = 80.35f; |
|||
float tr_Az_step = 0.3f; |
|||
uint32_t src = 128; |
|||
#endif
|
|||
#ifdef DEBUG
|
|||
LOG("Pereodical Jobs Started"); |
|||
#endif
|
|||
m_bThreadStatus = TH_WORKING; |
|||
if( !m_bEnabled ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG("Module is Disabled!"); |
|||
#endif
|
|||
}; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
m_llTicks ++;//= getMilliseconds();
|
|||
if( m_llTicks % 20 == 0 ) { // each 2 seconds
|
|||
#ifdef SIMULATOR
|
|||
sim_Az += tr_Az_step; |
|||
for(int i=0; i < EVT_CLASS_COUNT; i++ ) { |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
for( int j=0; j< EVT_COUNT; j++ ) { |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
CSTR tpl; |
|||
CSTR ts; |
|||
CSTR uuid; |
|||
char LON[10]; |
|||
char LAT[10]; |
|||
char AZ[10]; |
|||
char EL[10]; |
|||
char RN[10]; |
|||
float lat = 32.906153575029926; |
|||
float lon = 35.09629379621815; |
|||
sprintf( AZ, "%.3f", sim_Az+(0.6/RAND_MAX)*rand()); |
|||
sprintf( EL, "%.3f", sim_El+(0.6/RAND_MAX)*rand()); |
|||
sprintf( RN, "%.3f", sim_Ran+(0.6/RAND_MAX)*rand()); |
|||
sprintf( LAT, "%.10f", lat+(0.00006/RAND_MAX)*rand() ); |
|||
sprintf( LON, "%.10f", lon+(0.00006/RAND_MAX)*rand() ); |
|||
uuid = getUniqID_UUID(); |
|||
ts = getTimeStamp(); |
|||
src = i; |
|||
tpl = buildTemplate( m_pEvtTemplates[i][j]->tpl, src, ts, uuid, AZ, RN, EL, LAT, LON ); |
|||
if( tpl ) { |
|||
m_pProtocol->issuePost( m_pEvtTemplates[i][j]->topic, tpl, strlen( tpl ) ); |
|||
free( tpl ); |
|||
}; |
|||
if( uuid ) free( uuid ); |
|||
if( ts ) free( ts ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
#endif
|
|||
}; |
|||
if( m_bConsumerEnabled ) { |
|||
for( uint8_t idx = 0; idx < EVT_COUNT; idx++ ) { |
|||
if( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx] != NULL ){ |
|||
char BUF[1024]; |
|||
int len; |
|||
if( m_pProtocol->receivePost( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx]->topic, partition, start_offset, BUF, len ) ){ |
|||
if( len > 0 ) { |
|||
start_offset++; |
|||
#ifdef DEBUG
|
|||
char ttt[64]; |
|||
LOG(" HAVE MESSAGE "); |
|||
sprintf( ttt, " MSG Len: %d", len ); |
|||
LOG( ttt ); |
|||
#endif
|
|||
if( len > 0 ){ |
|||
LOG ( BUF ); |
|||
try{ |
|||
Json::Value root; |
|||
#ifdef OLD_WAY_JSON
|
|||
Json::Reader reader; |
|||
if( !reader.parse( BUF, root ) ){ |
|||
LOG_ERROR( "Error parsing the string" ); |
|||
} else { |
|||
#else
|
|||
JSONCPP_STRING err; |
|||
Json::CharReaderBuilder builder; |
|||
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); |
|||
if (!reader->parse(BUF, BUF + len, &root, &err)) { |
|||
LOG_ERROR( "Error parsing the string" ); |
|||
LOG_ERROR( err.c_str() ); |
|||
} else { |
|||
#endif
|
|||
|
|||
if (root.size()) { |
|||
FH_CTRL_DATA * tData; |
|||
basicEventTypeID evtID = EVT_NOINIT; |
|||
Json::Value tVal; |
|||
tData =(FH_CTRL_DATA *)malloc( sizeof(FH_CTRL_DATA)); |
|||
if( tData ) { |
|||
memset( tData, 0, sizeof(FH_CTRL_DATA)); |
|||
tVal = root["id"]; |
|||
|
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG(tVal.asString().c_str()); |
|||
#endif
|
|||
sprintf( tData->cmdUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
tVal = root["action"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
if ( strcasecmp(tVal.asString().c_str(), "intercept_target") == 0) { |
|||
evtID = EVT_FH_MISSION_BEGIN; |
|||
}; |
|||
if ( strcasecmp(tVal.asString().c_str(), "jam_target") == 0) { |
|||
tData->param = atoi( tVal.asString().c_str()+10 ); |
|||
if( tData->param == 0 ) { |
|||
tData->param = FH_DEFAULT_JAMING_TIME; |
|||
}; |
|||
evtID = EVT_FH_JAMING_BEGIN; |
|||
}; |
|||
if ( strcasecmp(tVal.asString().c_str(), "cancel") == 0) { |
|||
evtID = EVT_FH_CANCEL_ACTION; |
|||
}; |
|||
}; |
|||
tVal = root["event_id"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
sprintf( tData->evtUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
tVal = root["target_id"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
sprintf( tData->targetUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
if( evtID ) { |
|||
EVENT_CONTAINER * tEVT; |
|||
tEVT = createBasicEvent( 0, EVT_CLASS_EXTERNAL_CMD, evtID, NULL, NULL, tData ); |
|||
if( tEVT ) { |
|||
m_pEventHeap->broadcast( tEVT ); |
|||
} else { |
|||
free( tData ); |
|||
}; |
|||
} else { |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
} catch( exception e ){ |
|||
LOG_ERROR("EXCEPTION"); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
SLEEP(100); |
|||
}; |
|||
}; |
|||
|
|||
bool kernelModuleKafka::startService(){ |
|||
if(!m_bEnabled) return false; |
|||
if( reloadSettings() ) { |
|||
if( m_pSettings!= NULL ){ |
|||
m_pProtocol = new protocolKAFKA( m_pSettings ); |
|||
if( m_pProtocol->init() ){ |
|||
return init(); |
|||
}; |
|||
}; |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
bool kernelModuleKafka::stopService( bool force ){ |
|||
waitThreadEnd( true ); |
|||
return true; |
|||
}; |
|||
|
|||
bool kernelModuleKafka::reloadSettings(){ |
|||
if( m_pDBC==NULL ) return false; |
|||
if(! m_bEnabled) return false; |
|||
m_pSettings = m_pDBC->getSettingsKAFKA( m_nDBAUXID ); |
|||
if( m_pSettings != NULL ) { |
|||
if( m_pEvtTemplates != NULL ) { |
|||
// Clear Templates
|
|||
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){ |
|||
for(int j = 0; j < EVT_COUNT; j++ ){ |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl ); |
|||
free( m_pEvtTemplates[i][j] ); |
|||
m_pEvtTemplates[i][j] = NULL; |
|||
}; |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates[i] ); |
|||
m_pEvtTemplates[i] = NULL; |
|||
}; |
|||
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){ |
|||
for(int j = 0; j < EVT_COUNT; j++ ){ |
|||
KAFKA_TEMPLATE * tT; |
|||
tT = m_pDBC->getKafkaTemplateForEvent( m_nDBAUXID, i, j ); |
|||
if( tT != NULL ) { |
|||
if( m_pEvtTemplates[i]== NULL ) { |
|||
m_pEvtTemplates[i]=(KAFKA_TEMPLATE**)calloc(EVT_COUNT,sizeof(KAFKA_TEMPLATE*)); |
|||
memset( m_pEvtTemplates[i], 0, EVT_COUNT * sizeof(KAFKA_TEMPLATE*)); |
|||
if( i == EVT_CLASS_EXTERNAL_CMD ) { |
|||
m_bConsumerEnabled = true; |
|||
}; |
|||
}; |
|||
m_pEvtTemplates[i][j] = tT; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
return true; |
|||
}; |
|||
return false; |
|||
}; |
|||
CSTR kernelModuleKafka::buildTemplate( |
|||
CSTR tpl, |
|||
uint32_t source_id, |
|||
CSTR ts, |
|||
CSTR uuid, |
|||
CSTR az, |
|||
CSTR range, |
|||
CSTR width, |
|||
CSTR el, |
|||
CSTR lat, |
|||
CSTR lon, |
|||
CSTR alt, |
|||
CSTR extID, |
|||
CSTR src_Name, |
|||
CSTR src_IP, |
|||
CSTR src_lat, |
|||
CSTR src_lon, |
|||
CSTR src_alt, |
|||
CSTR src_rot_x, |
|||
CSTR src_rot_y, |
|||
CSTR src_rot_z |
|||
){ |
|||
CSTR ct1, ct2; |
|||
char sid[64]; |
|||
if( tpl ) { |
|||
sprintf( sid, "%d", source_id ); |
|||
ct1 = strReplace( tpl, KAFKA_TPL_SUBST_ID, sid ); |
|||
if( ct1 ) { |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_TS, ts ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
if( uuid ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_UUID, uuid ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( az ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_AZ, az ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( range ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_RANGE, range ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( width ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_WIDTH, width ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( el ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EL, el ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( lat ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_LAT, lat ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( lon ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_LON, lon ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( alt ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_ALT, alt ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( extID ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EXEVTD, extID ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_Name ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_NAME, src_Name ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_IP ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_IP, src_IP ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_lat ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_LAT, src_lat ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_lon ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_LON, src_lon ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_alt ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ALT, src_alt ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_x ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_X, src_rot_x ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_y ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_Y, src_rot_y ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_z ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_Z, src_rot_z ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
//Finalaze Message by System Wide Data
|
|||
// UUID
|
|||
CSTR TVAL = getUniqID_UUID(); |
|||
if ( TVAL != NULL ) { |
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_MSG_UUID, TVAL ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Generate Message UUID!"); |
|||
}; |
|||
// Server IP
|
|||
|
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_IP, m_sServerIP ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
// Server Name
|
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_NAME, m_sServerName ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
return ct1; |
|||
}; |
|||
} |
|||
return NULL; |
|||
}; |
|||
|
|||
void kernelModuleKafka::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|||
if( Evt == NULL ) return; |
|||
if( !m_bEnabled ) return; |
|||
#ifdef DEBUG
|
|||
char tBuffer[256]; |
|||
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
if( m_pEvtTemplates[ Evt->m_eClass ]!= NULL ) { |
|||
// We have defined Channel for that class Events
|
|||
// Skip Event Handling by flags
|
|||
if( !m_bEvtFlags[ Evt->m_eType ] ){ |
|||
#ifdef DEBUG
|
|||
//LOG("Disabled By FLAG!");
|
|||
#endif
|
|||
//return;
|
|||
} |
|||
// Hadle Event
|
|||
CSTR tDATA = NULL; |
|||
if( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ] != NULL ) { |
|||
switch( Evt->m_eType ) { |
|||
case EVT_TARGET_2D_BLACK: |
|||
case EVT_TARGET_2D_WHITE:{ |
|||
TARGET_DATA * tTARGET = ( TARGET_DATA *) Evt->m_pEvtData; |
|||
if(tTARGET!=NULL){ |
|||
char AZ[10]; |
|||
char RA[10]; |
|||
char WID[10]; |
|||
|
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
|
|||
char SLAT[10]; |
|||
char SLON[10]; |
|||
char SALT[10]; |
|||
char SROT_X[10]; |
|||
char SROT_Y[10]; |
|||
char SROT_Z[10]; |
|||
char SNAME[64]; |
|||
char TS[64]; |
|||
|
|||
sprintf( AZ,"%0.3f", tTARGET->local_target.fi ); |
|||
sprintf( RA,"%0.3f", tTARGET->local_target.r ); |
|||
sprintf( WID,"%0.3f", tTARGET->area ); |
|||
sprintf( LAT,"%0.6f", tTARGET->global_target.lat ); |
|||
sprintf( LON,"%0.6f", tTARGET->global_target.lon ); |
|||
sprintf( ALT,"%0.6f", tTARGET->global_target.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
sprintf( SLAT,"%0.6f", tTARGET->source_position.lat ); |
|||
sprintf( SLON,"%0.6f", tTARGET->source_position.lon ); |
|||
sprintf( SALT,"%0.6f", tTARGET->source_position.alt ); |
|||
|
|||
sprintf( SROT_X,"%0.6f", tTARGET->source_orient.rot_x ); |
|||
sprintf( SROT_Y,"%0.6f", tTARGET->source_orient.rot_y ); |
|||
sprintf( SROT_Z,"%0.6f", tTARGET->source_orient.rot_z ); |
|||
CSTR tN = m_pDBC->getNodeName( Evt->m_nSourceNodeID ); |
|||
if ( tN ) { |
|||
strncpy( SNAME, tN, 64 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SNAME, "Noname-Laser-Detector", 64); |
|||
}; |
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
AZ, |
|||
RA, |
|||
WID, |
|||
NULL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
NULL, |
|||
SNAME, |
|||
m_sServerIP, |
|||
SLAT, |
|||
SLON, |
|||
SALT, |
|||
SROT_X, |
|||
SROT_Y, |
|||
SROT_Z |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_TARGET_3D_BLACK: |
|||
case EVT_TARGET_3D_WHITE:{ |
|||
TARGET_DATA * tTARGET = ( TARGET_DATA *) Evt->m_pEvtData; |
|||
if(tTARGET!=NULL){ |
|||
char AZ[10]; |
|||
char EL[10]; |
|||
char RA[10]; |
|||
char WID[10]; |
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
|
|||
char SLAT[10]; |
|||
char SLON[10]; |
|||
char SALT[10]; |
|||
char SROT_X[10]; |
|||
char SROT_Y[10]; |
|||
char SROT_Z[10]; |
|||
|
|||
char SIP[16]; |
|||
char SNAME[64]; |
|||
|
|||
char TS[64]; |
|||
sprintf( AZ,"%0.3f", tTARGET->local_target.fi ); |
|||
sprintf( EL,"%0.3f", tTARGET->local_target.tetta ); |
|||
sprintf( RA,"%0.3f", tTARGET->local_target.r ); |
|||
sprintf( WID,"%0.3f", tTARGET->area ); |
|||
sprintf( LAT,"%0.6f", tTARGET->global_target.lat ); |
|||
sprintf( LON,"%0.6f", tTARGET->global_target.lon ); |
|||
sprintf( ALT,"%0.6f", tTARGET->global_target.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
sprintf( SLAT,"%0.6f", tTARGET->source_position.lat ); |
|||
sprintf( SLON,"%0.6f", tTARGET->source_position.lon ); |
|||
sprintf( SALT,"%0.6f", tTARGET->source_position.alt ); |
|||
|
|||
sprintf( SROT_X,"%0.6f", tTARGET->source_orient.rot_x ); |
|||
sprintf( SROT_Y,"%0.6f", tTARGET->source_orient.rot_y ); |
|||
sprintf( SROT_Z,"%0.6f", tTARGET->source_orient.rot_z ); |
|||
CSTR tN = m_pDBC->getNodeName( Evt->m_nSourceNodeID ); |
|||
if ( tN ) { |
|||
strncpy( SNAME, tN, 64 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SNAME, "Noname-Laser-Detector", 64); |
|||
}; |
|||
|
|||
if ( 0 ) { |
|||
strncpy( SIP, tN, 16 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SIP, "192.168.1.24", 16); |
|||
}; |
|||
|
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
AZ, |
|||
RA, |
|||
WID, |
|||
EL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
NULL, |
|||
SNAME, |
|||
SIP, |
|||
SLAT, |
|||
SLON, |
|||
SALT, |
|||
SROT_X, |
|||
SROT_Y, |
|||
SROT_Z |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_JAMER_ON: |
|||
case EVT_FH_JAMER_OFF: |
|||
case EVT_FH_FLY_TO: |
|||
case EVT_FH_WAYPOINT: |
|||
case EVT_FH_INTERCEPT_OK: |
|||
case EVT_FH_INTERCEPT_NOK: |
|||
case EVT_FH_BUSY: |
|||
case EVT_FH_LANDED:{ |
|||
FH_MISSION_DATA * tPOINT=(FH_MISSION_DATA *) Evt->m_pEvtData; |
|||
if( tPOINT ) { |
|||
char TS[64]; |
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
sprintf( LAT,"%0.6f", tPOINT->location.lat ); |
|||
sprintf( LON,"%0.6f", tPOINT->location.lon ); |
|||
sprintf( ALT,"%0.6f", tPOINT->location.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
NULL, |
|||
NULL, |
|||
NULL, |
|||
NULL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
tPOINT->missionID |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
default:{ |
|||
break; |
|||
}; |
|||
}; |
|||
if( tDATA!= NULL ) { |
|||
#ifdef KAFKA_DUMMY_SEND
|
|||
LOG( tDATA ); |
|||
#else
|
|||
m_pProtocol->issuePost( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->topic, tDATA, strlen( tDATA ) ); |
|||
#endif
|
|||
} else { |
|||
LOG_ERROR("Cant Build Template!"); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,86 @@ |
|||
#ifndef __KERNEL_KAFKA_MODULE_HEADERS__ |
|||
#define __KERNEL_KAFKA_MODULE_HEADERS__ |
|||
|
|||
|
|||
#include "kernelModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
#include "../data/protocol/protocolKAFKA.h" |
|||
|
|||
//#define SIMULATOR |
|||
//#define KAFKA_DUMMY_SEND |
|||
|
|||
#define KAFKA_TPL_SUBST_ID "%%ID%%" |
|||
#define KAFKA_TPL_SUBST_UUID "%%UUID%%" |
|||
#define KAFKA_TPL_SUBST_TS "%%TIMESTAMP%%" |
|||
#define KAFKA_TPL_SUBST_AZ "%%AZIMUTH%%" |
|||
#define KAFKA_TPL_SUBST_RANGE "%%RANGE%%" |
|||
#define KAFKA_TPL_SUBST_EL "%%ELEVATION%%" |
|||
#define KAFKA_TPL_SUBST_WIDTH "%%WIDTH%%" |
|||
#define KAFKA_TPL_SUBST_LON "%%LON%%" |
|||
#define KAFKA_TPL_SUBST_LAT "%%LAT%%" |
|||
#define KAFKA_TPL_SUBST_ALT "%%ALT%%" |
|||
#define KAFKA_TPL_SUBST_EXEVTD "%%EXEVTID%%" |
|||
#define KAFKA_TPL_SUBST_SRC_LON "%%SRC_LON%%" |
|||
#define KAFKA_TPL_SUBST_SRC_LAT "%%SRC_LAT%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ALT "%%SRC_ALT%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_X "%%SRC_ROT_X%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_Y "%%SRC_ROT_Y%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_Z "%%SRC_ROT_Z%%" |
|||
#define KAFKA_TPL_SUBST_SRC_IP "%%SRC_IP%%" |
|||
#define KAFKA_TPL_SUBST_SRV_IP "%%SRV_IP%%" |
|||
#define KAFKA_TPL_SUBST_SRV_NAME "%%SRV_NAME%%" |
|||
#define KAFKA_TPL_SUBST_SRC_NAME "%%SRC_NAME%%" |
|||
#define KAFKA_TPL_SUBST_MSG_UUID "%%MUID%%" |
|||
|
|||
|
|||
#define FH_DEFAULT_JAMING_TIME 10 |
|||
|
|||
class kernelModuleKafka: public kernelModule, public basicThread { |
|||
private: |
|||
KAFKA_SETTINGS *m_pSettings; |
|||
protocolKAFKA *m_pProtocol; |
|||
bool m_bConsumerEnabled; |
|||
basicEventHeap *m_pEventHeap; |
|||
KAFKA_TEMPLATE ***m_pEvtTemplates; |
|||
|
|||
int32_t partition; |
|||
int64_t start_offset; |
|||
char m_sServerIP[48]; |
|||
char m_sServerName[48]; |
|||
unsigned long long m_llTicks; |
|||
CSTR buildTemplate( CSTR tpl, |
|||
uint32_t source_id, |
|||
CSTR ts, |
|||
CSTR uuid = NULL, |
|||
CSTR az = NULL, |
|||
CSTR range = NULL, |
|||
CSTR width = NULL, |
|||
CSTR el = NULL, |
|||
CSTR lat = NULL, |
|||
CSTR lon = NULL, |
|||
CSTR alt = NULL, |
|||
CSTR extID = NULL, |
|||
CSTR src_Name = NULL, |
|||
CSTR src_IP = NULL, |
|||
CSTR src_lat = NULL, |
|||
CSTR src_lon = NULL, |
|||
CSTR src_alt = NULL, |
|||
CSTR src_rot_x = NULL, |
|||
CSTR src_rot_y = NULL, |
|||
CSTR src_rot_z = NULL |
|||
); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelModuleKafka( uint32_t ModuleID ); |
|||
virtual ~kernelModuleKafka(); |
|||
|
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
}; |
|||
|
|||
|
|||
#endif |
|||
@ -0,0 +1,324 @@ |
|||
#include "kernelModuleModemManager.h"
|
|||
#include "../../components/base/basicFunctionality.h"
|
|||
|
|||
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_MODEM", 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 );\ |
|||
kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
kernelModuleModemManager::kernelModuleModemManager( uint32_t moduleID ): kernelModule( moduleID, KERNEL_MODULE_MODEM_MANAGER ), basicThread(){ |
|||
LOG("Creating!"); |
|||
if( checkCmdExists("mmcli") > 0 ){ |
|||
//Modem Manager Exists
|
|||
LOG("Manager OK!"); |
|||
}; |
|||
}; |
|||
|
|||
kernelModuleModemManager::~kernelModuleModemManager(){ |
|||
|
|||
}; |
|||
|
|||
bool kernelModuleModemManager::reloadSettings(){ |
|||
return true; |
|||
}; |
|||
|
|||
bool kernelModuleModemManager::startService(){ |
|||
return true; |
|||
}; |
|||
|
|||
bool kernelModuleModemManager::stopService( bool force ){ |
|||
return true; |
|||
}; |
|||
|
|||
void kernelModuleModemManager::m_fThreadProc( void ){ |
|||
|
|||
}; |
|||
|
|||
void kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
}; |
|||
|
|||
bool kernelModuleModemManager::validate(){ |
|||
DBC_MODEM_DATA *tDATA = getModemInfo( 0 ); |
|||
if ( tDATA ) { |
|||
free( tDATA ); |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
void parseModemsInSystem(){ |
|||
"mmcli --list-modems"; |
|||
|
|||
}; |
|||
|
|||
typedef enum E_CFG_TAG_ID{ |
|||
CFG_GENERAL = 0, |
|||
CFG_HARDWARE = 1, |
|||
CFG_SYSTEM, |
|||
CFG_STATUS, |
|||
CFG_MODES, |
|||
CFG_BANDS, |
|||
CFG_IP, |
|||
CFG_EPS, |
|||
CFG_3GPP, |
|||
CFG_SIM, |
|||
CFG_BEARER, |
|||
CFG_COUNT |
|||
}CFG_TAG_ID; |
|||
|
|||
const CSTR cfg_tags[]={ |
|||
"General", |
|||
"Hardware", |
|||
"System", |
|||
"Status", |
|||
"Modes", |
|||
"Bands", |
|||
"IP", |
|||
"3GPP EPS", |
|||
"3GPP", |
|||
"SIM", |
|||
"Bearer" |
|||
}; |
|||
|
|||
DBC_MODEM_DATA *kernelModuleModemManager::getModemInfo( uint32_t modem_id ){ |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
FILE * fd = NULL; |
|||
CFG_TAG_ID cMode = CFG_GENERAL; |
|||
DBC_MODEM_DATA * retVal = (DBC_MODEM_DATA *)malloc(sizeof(DBC_MODEM_DATA)); |
|||
|
|||
if ( retVal != NULL ) { |
|||
memset( retVal, 0 , sizeof(DBC_MODEM_DATA)); |
|||
sprintf( tB, "mmcli --modem=%d", modem_id ); |
|||
fd = popen( tB, "r"); |
|||
if (fd!= NULL ) { |
|||
retVal->modem_id = modem_id; |
|||
while ( !feof( fd )) { |
|||
fgets( (CSTR)tB, 1024, fd ); |
|||
trim( tB ); |
|||
if( strstr(tB, "error:" ) != NULL){ |
|||
free( retVal ); |
|||
retVal = NULL; |
|||
break; |
|||
}; |
|||
LOG(tB); |
|||
strncpy( expBuf, tB, 1024 ); |
|||
CArray *CA = explode( ':', expBuf ); |
|||
if( CA ){ |
|||
if( CA->size() ){ |
|||
for( int ii = CFG_GENERAL; ii < CFG_COUNT; ii++ ){ |
|||
if( strstr( CA->at(0), cfg_tags[ii] ) != NULL ){ |
|||
cMode = (CFG_TAG_ID) ii; |
|||
break; |
|||
}; |
|||
}; |
|||
switch( cMode ){ |
|||
case CFG_GENERAL:{ |
|||
//LOG("GEN");
|
|||
if ( strstr( CA->at(0), "device id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->dbus_dev_id, CA->at(1), 64 ); |
|||
retVal->dbus_dev_id[64] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_HARDWARE:{ |
|||
//LOG("HW");
|
|||
if ( strstr( tB, "manufacturer") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->hw_manufac, CA->at(1), 64); |
|||
retVal->hw_manufac[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "model") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_model, CA->at(1), 64); |
|||
retVal->hw_model[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "h/w revision") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_revision, CA->at(1), 64); |
|||
retVal->hw_revision[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "revision") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_version, CA->at(1), 32); |
|||
retVal->hw_revision[32] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "equipment id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_id, CA->at(1), 32); |
|||
retVal->hw_id[32] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_SYSTEM:{ |
|||
//LOG("SYS");
|
|||
if ( strstr( tB, "ports") != NULL ) { |
|||
trim(CA->at(1)); |
|||
CArray *CZ = explode( ':', CA->at(1) ); |
|||
if ( CZ ) { |
|||
int CP = 0; |
|||
for (int z=0; z< CZ->size(); z++) { |
|||
if ( strstr(CZ->at(z),"(at)")!= NULL ) { |
|||
if (CP == 0 ) { |
|||
retVal->at_uart_id = 1;//getUartIdByDevice();
|
|||
} else { |
|||
retVal->at_uart_id_aux = 2; |
|||
}; |
|||
CP++; |
|||
}; |
|||
if (CP == 2) break; |
|||
}; |
|||
delete( CZ ); |
|||
}; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_STATUS:{ |
|||
//LOG("STAT");
|
|||
if ( strstr( tB, "power state") != NULL ) { |
|||
if ( strstr(CA->at(1),"on") ) { |
|||
retVal->power[0] = 'E'; |
|||
retVal->power[1]=(char)0; |
|||
} else { |
|||
retVal->power[0] = 'D'; |
|||
retVal->power[1]=(char)0; |
|||
}; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "state") != NULL ) { |
|||
if ( strstr(CA->at(1),"registered") ) { |
|||
retVal->status[0]='R'; |
|||
retVal->status[1]=(char)0; |
|||
} else { |
|||
}; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "access tech") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->conmection_tech, CA->at(1), 5); |
|||
retVal->conmection_tech[5] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "signal quality") != NULL ) { |
|||
trim(CA->at(1)); |
|||
retVal->signal = atoi(CA->at(1)); |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_MODES:{ |
|||
//LOG("MOD");
|
|||
//if ( strstr( CA->at(0), "current") != NULL ) {
|
|||
// trim(CA->at(1));
|
|||
// strncpy( retVal->hw_manufac, CA->at(1), 64);
|
|||
// retVal->hw_manufac[64] = (char)0;
|
|||
// break;
|
|||
//};
|
|||
break; |
|||
}; |
|||
case CFG_IP:{ |
|||
//LOG("IP");
|
|||
break; |
|||
}; |
|||
case CFG_EPS:{ |
|||
//LOG("EPS");
|
|||
break; |
|||
}; |
|||
case CFG_3GPP:{ |
|||
// LOG("3GPP");
|
|||
if ( strstr( tB, "imei") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->imei, CA->at(1), 16); |
|||
retVal->imei[16] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "operator id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
retVal->operator_id = atoi(CA->at(1)); |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "registration") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->registration, CA->at(1), 64); |
|||
retVal->registration[64] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_SIM:{ |
|||
// LOG("SIM");
|
|||
break; |
|||
}; |
|||
case CFG_BEARER:{ |
|||
// LOG("BEAR");
|
|||
break; |
|||
}; |
|||
//default: LOG("UNK");
|
|||
}; |
|||
} else { |
|||
LOG("No CA Parts!"); |
|||
}; |
|||
delete( CA ); |
|||
} else { |
|||
LOG("No CA!"); |
|||
}; |
|||
}; |
|||
fclose(fd); |
|||
}; |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
if ( retVal ) { |
|||
char ttB[256]; |
|||
sprintf(ttB, "Modem ID: [%d]", retVal->modem_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW Manufac: [%s]", retVal->hw_manufac); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW Model: [%s]", retVal->hw_model); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW id: [%s]", retVal->hw_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Revision id: [%s]", retVal->hw_revision); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Revision Version: [%s]", retVal->hw_version); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem DBus id: [%s]", retVal->dbus_dev_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem IMEI: [%s]", retVal->imei); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Access Tech: [%s]", retVal->conmection_tech); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Operator: [%d]", retVal->operator_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Power: [%s]", retVal->power); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Registration: [%s]", retVal->registration); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Signal Power: [%d%%]", retVal->signal); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Status: [%s]", retVal->status); |
|||
LOG(ttB); |
|||
}; |
|||
#endif
|
|||
return retVal; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,24 @@ |
|||
#ifndef __KERNEL_MODULE_MODEM_MANAGER_HEADER__ |
|||
#define __KERNEL_MODULE_MODEM_MANAGER_HEADER__ |
|||
|
|||
#include "kernelModule.h" |
|||
#include "../../components/base/basicThread.h" |
|||
|
|||
class kernelModuleModemManager: public kernelModule, public basicThread { |
|||
private: |
|||
DBC_MODEM_DATA * getModemInfo( uint32_t modem_id ); |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelModuleModemManager( uint32_t moduleID ); |
|||
~kernelModuleModemManager(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,603 @@ |
|||
#include "kernelModuleOnvifObserver.h"
|
|||
#include "hardwareManager.h"
|
|||
#include "hardwareResourceNetworkProvider.h"
|
|||
|
|||
#define SEARCH_REQUEST_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"><e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header><e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
|
|||
#define SEARCH_REQUEST_STRING2323 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
|
|||
"<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \ |
|||
"<SOAP:Header>\n" \ |
|||
"<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \ |
|||
"<wsa:Action>\n" \ |
|||
"http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \ |
|||
"</wsa:Action>\n" \ |
|||
"<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \ |
|||
"</SOAP:Header>\n" \ |
|||
"<SOAP:Body>\n" \ |
|||
"<DISCOVERY:Probe>\n" \ |
|||
"<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \ |
|||
"</DISCOVERY:Probe>\n" \ |
|||
"</SOAP:Body>\n" \ |
|||
"</SOAP:Envelope>\r\n\r\n" |
|||
#define HTTP_OK "200 OK"
|
|||
|
|||
/******************************************************************
|
|||
** Action Defines * |
|||
*******************************************************************/ |
|||
#define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
|
|||
"HOST: %s:%u\r\n" \ |
|||
"SOAPACTION:\"%s#%s\"\r\n" \ |
|||
"CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\ |
|||
"Content-Length: %d \r\n\r\n" |
|||
|
|||
#define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
|
|||
"<s:Envelope xmlns:s=" \ |
|||
"\"http://schemas.xmlsoap.org/soap/envelope/\" " \ |
|||
"s:encodingStyle=" \ |
|||
"\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \ |
|||
"<s:Body>\r\n" \ |
|||
"<u:%s xmlns:u=\"%s\">\r\n%s" \ |
|||
"</u:%s>\r\n" \ |
|||
"</s:Body>\r\n" \ |
|||
"</s:Envelope>\r\n" |
|||
|
|||
#define PORT_MAPPING_LEASE_TIME "63072000" //two year
|
|||
|
|||
#define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
|
|||
"<NewExternalPort>%u</NewExternalPort>\r\n"\ |
|||
"<NewProtocol>%s</NewProtocol>\r\n" \ |
|||
"<NewInternalPort>%u</NewInternalPort>\r\n"\ |
|||
"<NewInternalClient>%s</NewInternalClient>\r\n" \ |
|||
"<NewEnabled>1</NewEnabled>\r\n" \ |
|||
"<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \ |
|||
"<NewLeaseDuration>" \ |
|||
PORT_MAPPING_LEASE_TIME \ |
|||
"</NewLeaseDuration>\r\n" |
|||
|
|||
|
|||
|
|||
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", 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 );\ |
|||
kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
kernelModuleOnvifObserver::kernelModuleOnvifObserver( uint32_t ModuleID ): kernelModule( ModuleID, KERNEL_MODULE_ONVIF_OBSERVER ), basicThread(){ |
|||
m_bEnabled = false; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
|
|||
m_bCurrentNIF = 0; |
|||
m_bProbeIsActive = false; |
|||
m_bDetached = false; |
|||
#ifdef __linux__
|
|||
m_bWSAOK = true; |
|||
#else
|
|||
m_bWSAOK = false; |
|||
WORD wVersionRequested; |
|||
WSADATA wsaData; |
|||
int err; |
|||
wVersionRequested = MAKEWORD(2, 2); |
|||
err = WSAStartup(wVersionRequested, &wsaData); |
|||
if (err != 0){ |
|||
LOG_ERROR("WSAStartup failed with error"); |
|||
} else m_bWSAOK = true; |
|||
#endif
|
|||
}; |
|||
|
|||
kernelModuleOnvifObserver::~kernelModuleOnvifObserver(){ |
|||
if( !m_bDetached ) stopService( true ); |
|||
}; |
|||
|
|||
bool kernelModuleOnvifObserver::startService(){ |
|||
LOG("Starting Service!"); |
|||
if( !m_bWSAOK ) return false; |
|||
m_bEnabled = reloadSettings(); |
|||
return init(); |
|||
}; |
|||
|
|||
bool kernelModuleOnvifObserver::stopService( bool force ){ |
|||
m_bEnabled = false; |
|||
if( !m_bDetached ) m_bDetached = uninit(); |
|||
if( m_bDetached ) { |
|||
//Clear Results
|
|||
m_mResultProtector.lock(); |
|||
if (m_vResultPool.size()){ // Clear structures
|
|||
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){ |
|||
free(*index); |
|||
}; |
|||
m_vResultPool.clear(); |
|||
}; |
|||
m_mResultProtector.unlock(); |
|||
}; |
|||
return m_bDetached; |
|||
}; |
|||
|
|||
/*
|
|||
#include <stdio.h>
|
|||
#include <stdint.h>
|
|||
#include <string.h>
|
|||
#include <sys/types.h>
|
|||
#include <sys/socket.h>
|
|||
#include <linux/in.h>
|
|||
#include <linux/if_ether.h>
|
|||
#include <net/if.h>
|
|||
#include <errno.h>
|
|||
// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
|
|||
static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){ |
|||
|
|||
#if MCAST_JOIN_GROUP
|
|||
struct group_req req; |
|||
req.gr_interface = 0; |
|||
if (grplen > sizeof(req.gr_group)) { |
|||
errno = EINVAL; |
|||
return -1; |
|||
} |
|||
memcpy(&req.gr_group, grp, grplen); |
|||
return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req))); |
|||
#else
|
|||
switch (grp->sa_family) { |
|||
case AF_INET: { |
|||
struct ip_mreq mreq; |
|||
struct ifreq ifreq; |
|||
memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr)); |
|||
mreq.imr_interface.s_addr = htonl(INADDR_ANY); |
|||
return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, |
|||
&mreq, sizeof(mreq))); |
|||
} |
|||
#ifdef IPV6
|
|||
#ifndef IPV6_JOIN_GROUP // APIv0 compatibility
|
|||
#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
|
|||
#endif
|
|||
case AF_INET6: { |
|||
struct ipv6_mreq mreq6; |
|||
memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr)); |
|||
mreq6.ipv6mr_interface = 0; |
|||
return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6))); |
|||
} |
|||
#endif
|
|||
default: |
|||
errno = EAFNOSUPPORT; |
|||
return -1; |
|||
} |
|||
#endif
|
|||
}; |
|||
|
|||
int main(int argc, char **argv){ |
|||
|
|||
int fd = socket(AF_INET, SOCK_DGRAM, 0); |
|||
struct sockaddr_in grp; |
|||
bzero(&grp, sizeof(grp)); |
|||
grp.sin_family = AF_INET; |
|||
grp.sin_addr.s_addr = inet_addr("224.0.0.1");; |
|||
if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp))) |
|||
perror("Join multicast group failed"); |
|||
} |
|||
|
|||
*/ |
|||
|
|||
|
|||
void kernelModuleOnvifObserver::m_fThreadProc(){ |
|||
int socketFD; |
|||
int RetVal; |
|||
struct sockaddr_in r_address; |
|||
bool bOptVal; |
|||
int bOptLen; |
|||
int iOptLen; |
|||
uint16_t bCounterTO = 600; // 3 second
|
|||
char rBuffer[MAX_BUFF_SIZE]; |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
LOG("Module Started!"); |
|||
#endif
|
|||
m_bDetached = false; |
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
if ( m_bEnabled ) { |
|||
if ( m_bProbeIsActive ) { |
|||
if( socketFD > -1 ){ |
|||
if( bCounterTO-- ){ |
|||
memset( rBuffer, 0, MAX_BUFF_SIZE ); |
|||
#ifdef DEBUG
|
|||
struct sockaddr src_addr; |
|||
socklen_t addrlen = sizeof( src_addr ); |
|||
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen ); |
|||
if ( RetVal > -1 ) { |
|||
sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr)); |
|||
LOG( tB ); |
|||
}; |
|||
#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
|
|||
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL ); |
|||
#endif
|
|||
if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) { |
|||
LOG_ERROR("Error acures while reading UDP package"); |
|||
close( socketFD ); |
|||
m_bProbeIsActive = false; |
|||
continue; // Error ocured but continue to next address
|
|||
}; |
|||
if( RetVal < 1 ){ |
|||
//LOG("SLEEP");
|
|||
SLEEP(DEFAULT_THREAD_SLEEP_TIME); |
|||
continue; // No Data - wait to next time
|
|||
}; |
|||
OBSERVER_RESULT *tResult = parseXML( rBuffer ); |
|||
if ( tResult ) { |
|||
m_mResultProtector.lock(); |
|||
m_vResultPool.push_back( tResult ); |
|||
m_mResultProtector.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished!"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished with unrecognized data!"); |
|||
#endif
|
|||
}; |
|||
continue; //To Fetch Another responces
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished By Timeout!"); |
|||
#endif
|
|||
}; |
|||
#ifdef __linux__
|
|||
close(socketFD); |
|||
#else
|
|||
closesocket(socketFD); |
|||
#endif
|
|||
}; |
|||
m_bProbeIsActive = false; |
|||
//Sleep 5 minutes if done all scans
|
|||
if ( m_bCurrentNIF == 0 ){ |
|||
for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
} else { |
|||
// start new probe;
|
|||
m_mNIFMUTEX.lock(); |
|||
if ( m_vNIFIPS.size() ) { |
|||
#ifdef DEBUG
|
|||
sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) ); |
|||
LOG( tB ); |
|||
#endif
|
|||
socketFD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
|||
if( socketFD > -1 ){ |
|||
CSTR send_buff = (CSTR)SEARCH_REQUEST_STRING; |
|||
r_address.sin_family = AF_INET; |
|||
r_address.sin_port = htons(HTTPMU_HOST_PORT); |
|||
r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF)); |
|||
bOptVal = true; |
|||
#ifdef DEBUG
|
|||
LOG("Set Broadcast Flag"); |
|||
#endif
|
|||
RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen ); |
|||
struct group_req req; |
|||
req.gr_interface = 0; |
|||
memcpy( &req.gr_group, &r_address, sizeof(r_address)); |
|||
#ifdef DEBUG
|
|||
LOG("Join Broadcast Group"); |
|||
#endif
|
|||
RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) ); |
|||
//The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
|
|||
|
|||
if ( RetVal > -1 ) { |
|||
LOG_ERROR("Setting Socked as Broadcasted Error!"); |
|||
}; |
|||
|
|||
//
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; // IPv4
|
|||
tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
|
|||
tServerAddr.sin_port = htons(rand( 20000, 40000)); |
|||
|
|||
// Bind the socket with the server address
|
|||
RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr)); |
|||
if ( RetVal > -1 ) { |
|||
LOG_ERROR("Bind Socked Error!"); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Sending Probe Request"); |
|||
#endif
|
|||
RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in)); |
|||
if ( RetVal > -1 ) { |
|||
#ifdef DEBUG
|
|||
sprintf( tB, "Sent %d Bytes of %d", RetVal, strlen(send_buff) ); |
|||
LOG( tB ); |
|||
#endif
|
|||
|
|||
#ifdef __linux__
|
|||
fcntl( socketFD, F_SETFL, fcntl( socketFD, F_GETFL, 0) | O_NONBLOCK ); |
|||
#else
|
|||
u_long val = 1; |
|||
ioctlsocket( socketFD, FIONBIO, &val );//none block
|
|||
#endif
|
|||
bCounterTO = 600; |
|||
m_bProbeIsActive = true; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
// Failure to send probe package
|
|||
LOG_ERROR("Error in sending Probe Request"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
close(socketFD); |
|||
#else
|
|||
closesocket(socketFD); |
|||
#endif
|
|||
}; |
|||
}; |
|||
m_bCurrentNIF++; |
|||
if ( m_bCurrentNIF == m_vNIFIPS.size() ) m_bCurrentNIF = 0; |
|||
}; |
|||
m_mNIFMUTEX.unlock(); |
|||
}; |
|||
} else { |
|||
//Sleep 3 Sec.
|
|||
for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
}; |
|||
m_bDetached = true; |
|||
}; |
|||
|
|||
void kernelModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
if(!m_bEnabled) { |
|||
#ifdef DEBUG
|
|||
LOG("Module Disabled!"); |
|||
#endif
|
|||
return; |
|||
} |
|||
if( Evt == NULL ) return; |
|||
|
|||
}; |
|||
|
|||
bool kernelModuleOnvifObserver::reloadSettings(){ |
|||
m_mNIFMUTEX.lock(); |
|||
if( m_vNIFIPS.size() ) { |
|||
for ( vectorCSTR::iterator idx=m_vNIFIPS.begin(); idx < m_vNIFIPS.end(); idx++ ) free(*idx); |
|||
m_vNIFIPS.clear(); |
|||
}; |
|||
m_mNIFMUTEX.unlock(); |
|||
|
|||
#ifdef DEBUG
|
|||
LOG("Check IPS"); |
|||
#endif
|
|||
hardwareManager *tHWM = hardwareManager::getInstance(); |
|||
if( tHWM != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 11"); |
|||
#endif
|
|||
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( HARDWARE_PROVIDER_NETWORK ); |
|||
if( rIDS != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 22"); |
|||
#endif
|
|||
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){ |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 33"); |
|||
#endif
|
|||
hardwareResourceNetwork *tRES = ( hardwareResourceNetwork *) tHWM->requestResource( HARDWARE_PROVIDER_NETWORK, *idx ); |
|||
if( tRES != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Have NIF Resource"); |
|||
#endif
|
|||
CSTR BC = tRES->getBroadcast(); |
|||
if( BC!= NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Have BC Address"); |
|||
LOG(BC); |
|||
#endif
|
|||
m_mNIFMUTEX.lock(); |
|||
m_vNIFIPS.push_back( BC ); |
|||
m_mNIFMUTEX.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("NIF defined"); |
|||
#endif
|
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("NO BC Address"); |
|||
} |
|||
#endif
|
|||
; |
|||
} else { |
|||
LOG_ERROR("Cannot Get Resource!"); |
|||
}; |
|||
}; |
|||
delete( rIDS ); |
|||
} else { |
|||
LOG("No Networks Detected!"); |
|||
m_bEnabled = false; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No HW Manager"); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Default Probe"); |
|||
LOG( HTTPMU_HOST_ADDRESS ); |
|||
#endif
|
|||
CSTR tBC = (CSTR) malloc(16); |
|||
if ( tBC ) { |
|||
sprintf(tBC, HTTPMU_HOST_ADDRESS ); |
|||
m_mNIFMUTEX.lock(); |
|||
m_vNIFIPS.push_back( tBC ); |
|||
m_mNIFMUTEX.unlock(); |
|||
} else { |
|||
LOG_ERROR("Malloc Error!"); |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
OBSERVER_RESULT *kernelModuleOnvifObserver::parseXML( CSTR data ){ |
|||
OBSERVER_RESULT *retVal = NULL; |
|||
if( data!=NULL ){ |
|||
XMLResults tParseResults; |
|||
XMLNode response = XMLNode::parseString( data, "root", &tParseResults ); |
|||
if( tParseResults.error ){ |
|||
char tBuffer[CTEXT]; |
|||
sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn ); |
|||
LOG_ERROR( tBuffer ); |
|||
} else { |
|||
if( response.isEmpty() ){ |
|||
LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element."); |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe XML parsed"); |
|||
#endif
|
|||
XMLNode Body = response.getChildNode( "Body", 0 ); |
|||
if(!Body.isEmpty()){ |
|||
LOG("Have Body elm"); |
|||
XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
|
|||
if(!ProbeMatches.isEmpty()) { |
|||
LOG("Have ProbeMathes elm"); |
|||
int matches = ProbeMatches.nChildNode(); |
|||
for(int index=0;index<matches;index++){ |
|||
XMLNode ProbeMatch = ProbeMatches.getChildNode("ProbeMatch", index); |
|||
retVal = (OBSERVER_RESULT *)malloc(sizeof(OBSERVER_RESULT)); |
|||
if( retVal != NULL ){ |
|||
memset( retVal, 0, sizeof(OBSERVER_RESULT)); |
|||
if(!ProbeMatch.isEmpty()) { |
|||
LOG("Have ProbeMatch elm"); |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("EndpointReference", 0); |
|||
if(!node.isEmpty()) { |
|||
LOG("Have ProbeMatch EndpointReference"); |
|||
XMLNode nod = node.getChildNode("Address", 0); |
|||
if(!nod.isEmpty()){ |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", nod.getText(0)); |
|||
CArray *tArr; |
|||
LOG("Before Explode"); |
|||
tArr = explode(':',tBuf); |
|||
LOG("After Explode"); |
|||
for(int j=0; j<tArr->size(); j++) { |
|||
if( strlen(tArr->at(j)) > 10 ) { |
|||
sprintf(retVal->RefID,"%s",tArr->at(j)); |
|||
break; |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
delete(tArr); |
|||
|
|||
}; |
|||
}; |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("Types", 0); |
|||
if( !node.isEmpty() ){ |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", node.getText(0)); |
|||
CArray *tArr; |
|||
tArr = explode(' ',tBuf); |
|||
sprintf(retVal->Type,"%s",tArr->at(0)); |
|||
tArr->clear(); |
|||
delete(tArr); |
|||
} |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("Scopes", 0); |
|||
char tBuf[CLOG]; |
|||
sprintf( tBuf,"%s", node.getText(0) ); |
|||
CArray *tArr = explode(' ',tBuf); |
|||
if( tArr->size() > 0 ) { |
|||
for( int index = 0; index < tArr->size(); index++){ |
|||
char *tPtr; |
|||
if( tPtr = strstr( tArr->at(index), "mac/" ) ){ |
|||
sprintf(retVal->MAC,"%s",tPtr+4); |
|||
}; |
|||
if( tPtr = strstr( tArr->at(index), "hardware/" ) ){ |
|||
sprintf(retVal->Hardware,"%s",tPtr+9); |
|||
}; |
|||
if( tPtr = strstr( tArr->at(index), "name/" ) ){ |
|||
sprintf(retVal->Name,"%s",tPtr+5); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "MAC/")) { |
|||
sprintf(retVal->MAC, "%s", tPtr + 4); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "HARDWARE/")) { |
|||
sprintf(retVal->Hardware, "%s", tPtr + 9); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "NAME/")) { |
|||
sprintf(retVal->Name, "%s", tPtr + 5); |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
}; |
|||
delete(tArr); |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("XAddrs", 0); |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", node.getText(0)); |
|||
CArray *tArr; |
|||
tArr = explode(' ',tBuf); |
|||
if( tArr->size() > 0 ) { |
|||
for(int index=0; index < tArr->size(); index++) { |
|||
if( strstr( tArr->at(index), "[" ) != NULL ){ |
|||
// IPv6
|
|||
} else{ |
|||
// IPv4
|
|||
sprintf(retVal->XAddrs,"%s",tArr->at(0)); |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
}; |
|||
delete(tArr); |
|||
} |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
return retVal; |
|||
}; |
|||
|
|||
|
|||
bool kernelModuleOnvifObserver::validate(){ |
|||
m_mResultProtector.lock(); |
|||
if( m_vResultPool.size() ){ // Clear structures
|
|||
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){ |
|||
#ifdef DEBUG
|
|||
char tBuffer[256]; |
|||
sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
|
|||
if( cid ) { |
|||
#ifdef DEBUG
|
|||
sprintf( tBuffer, "Camera is Listed as %d", cid ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
m_pDBC->updateIPCam( cid, (*index)->XAddrs );// DiscoverResults->at(index));
|
|||
} else { |
|||
// Uncknown camera - no checking
|
|||
#ifdef DEBUG
|
|||
LOG("Camera is Not Listed"); |
|||
#endif
|
|||
m_pDBC->addIPCam( (*index) ); |
|||
}; |
|||
free(*index); |
|||
} |
|||
m_vResultPool.clear(); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Clear Structs Done!"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("No Online IP Cameras in Network"); |
|||
#endif
|
|||
}; |
|||
m_mResultProtector.unlock(); |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,94 @@ |
|||
#ifndef __KERNEL_MODULE_ONVIF_OBSERVER_HEADER__ |
|||
#define __KERNEL_MODULE_ONVIF_OBSERVER_HEADER__ |
|||
|
|||
#include <sys/socket.h> |
|||
#include <netinet/in.h> |
|||
#include <arpa/inet.h> |
|||
#include <ifaddrs.h> |
|||
#include <fcntl.h> |
|||
|
|||
#include "kernelModule.h" |
|||
#include "../../data/protocol/xmlParser.h" |
|||
#include "../../components/base/basicThread.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../components/base/basicFunctionality.h" |
|||
|
|||
#pragma warning(disable: 4251) |
|||
|
|||
#define HTTPMU_HOST_ADDRESS "239.255.255.250" |
|||
#define HTTPMU_HOST_PORT 3702 |
|||
|
|||
|
|||
//#define DEBUG_ONVIF_PRINTOUT_MESSAGES |
|||
|
|||
#define DEFAULT_HTTP_PORT 80 |
|||
|
|||
typedef std::vector<OBSERVER_RESULT*> vectorOBSERVER_RESULT; |
|||
|
|||
class kernelModuleOnvifObserver; |
|||
|
|||
typedef struct S_PROBE_CTX{ |
|||
int AddressID; |
|||
char IpAddress[16]; |
|||
int Port; |
|||
int socketFD; |
|||
char buff[MAX_BUFF_SIZE + 1]; |
|||
CSTR send_buff; |
|||
CSTR recv_buff; |
|||
struct sockaddr_in r_address; |
|||
bool bOptVal; |
|||
int bOptLen; |
|||
int iOptLen; |
|||
int RetVal; |
|||
int index; |
|||
bool isFinished; |
|||
kernelModuleOnvifObserver * observer; |
|||
}PROBE_CTX; |
|||
|
|||
typedef struct S_OBSERVER_CTX{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
PROBE_CTX * context; |
|||
}OBSERVER_CTX; |
|||
|
|||
typedef std::vector<OBSERVER_CTX*> vectorOBSERVER_CTX; |
|||
|
|||
|
|||
class kernelModuleOnvifObserver: public kernelModule, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
//enumeratorInfo m_vLocalDevices; |
|||
//localIpAddresses m_vIpAddresses; |
|||
|
|||
vectorOBSERVER_RESULT m_vResultPool; |
|||
basicMutex m_mResultProtector; |
|||
basicMutex m_mNIFMUTEX; |
|||
vectorCSTR m_vNIFIPS; |
|||
bool m_bProbeIsActive; |
|||
bool m_bWSAOK; |
|||
uint8_t m_bCurrentNIF; |
|||
|
|||
//PROBE_CTX * init_PROBE_CTX( CSTR ADR, int ID ); |
|||
//bool loadAssignedSources(void); |
|||
//bool startProbe( CSTR IP, int ID ); |
|||
//static void * probeThreadProc(void *); |
|||
OBSERVER_RESULT * parseXML( CSTR data ); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
|
|||
public: |
|||
explicit kernelModuleOnvifObserver( uint32_t moduleID ); |
|||
~kernelModuleOnvifObserver(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
1041
lib/App/common/kernelModuleSSDP.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,211 @@ |
|||
#ifndef __KERNEL_MODULE_SSDP_ANNOUNCER_HEADER__ |
|||
#define __KERNEL_MODULE_SSDP_ANNOUNCER_HEADER__ |
|||
#include "kernelModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
|
|||
#include <ctype.h> |
|||
#include <err.h> |
|||
#include <errno.h> |
|||
#include <getopt.h> |
|||
#include <ifaddrs.h> |
|||
#include <netdb.h> |
|||
#include <paths.h> |
|||
#include <poll.h> |
|||
#include <stdio.h> |
|||
#include <signal.h> |
|||
#include <stdint.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include <time.h> |
|||
#include <unistd.h> |
|||
#include <arpa/inet.h> |
|||
#include <netinet/ip.h> |
|||
#include <netinet/udp.h> |
|||
#include <sys/param.h> /* MIN() */ |
|||
#include <sys/socket.h> |
|||
#include <queue.h> |
|||
#include <unistd.h> |
|||
#include <sys/types.h> |
|||
#include <sys/syscall.h> |
|||
#define gettid() syscall(SYS_gettid) |
|||
|
|||
#define SSDP_TAG_DEVICE_SERVER_STRING "SERVER_STRING" |
|||
#define SSDP_TAG_DEVICE_FRIENDLY_NAME "DEVICE_FRIENDLY_NAME" |
|||
#define SSDP_TAG_DEVICE_TYPE "DEVICE_TYPE" |
|||
#define SSDP_TAG_DEVICE_BASE_URL "BASE_URL" |
|||
#define SSDP_TAG_AUX_WEB_SERVICE "AUX_WEB_SERVICE" |
|||
#define SSDP_TAG_DEVICE_MANUFACTURER "MANUFACTURER" |
|||
#define SSDP_TAG_DEVICE_MANUFACTURER_URL "MANUFACTURER_URL" |
|||
#define SSDP_TAG_DEVICE_MODEL_NAME "MODEL_NAME" |
|||
#define SSDP_TAG_DEVICE_MODEL_NUMBER "MODEL_NUMBER" |
|||
#define SSDP_TAG_DEVICE_MODEL_DESCRIPTION "MODEL_DESCRIPTION" |
|||
#define SSDP_TAG_DEVICE_MODEL_URL "MODEL_URL" |
|||
#define SSDP_TAG_DEVICE_SERIAL "DEVICE_SERIAL_NUMBER" |
|||
#define SSDP_TAG_DEVICE_UUID "DEVICE_UUID" |
|||
#define SSDP_TAG_DEVICE_UPC "DEVICE_UPC" |
|||
#define SSDP_TAG_DEVICE_ICONS "ICONS" |
|||
#define SSDP_TAG_DEVICE_ICON_IMAGE_FORMAT "FORMAT" |
|||
#define SSDP_TAG_DEVICE_ICON_WIDTH "WIDTH" |
|||
#define SSDP_TAG_DEVICE_ICON_HEIGHT "HEIGHT" |
|||
#define SSDP_TAG_DEVICE_ICON_DEPTH "DEPTH" |
|||
#define SSDP_TAG_DEVICE_ICON_URL "URL" |
|||
#define SSDP_TAG_DEVICE_SERVICES "SERVICES" |
|||
#define SSDP_TAG_DEVICE_SERVICE_TYPE "TYPE" |
|||
#define SSDP_TAG_DEVICE_SERVICE_ID "ID" |
|||
#define SSDP_TAG_DEVICE_SERVICE_DESC_URL "DESCRIPTION_URL" |
|||
#define SSDP_TAG_DEVICE_SERVICE_CTRL_URL "CONTROL_URL" |
|||
#define SSDP_TAG_DEVICE_SERVICE_EVTS_URL "EVENTS_URL" |
|||
#define SSDP_TAG_DEVICE_PRESENTATION_URL "PRESENTATION_URL" |
|||
|
|||
|
|||
typedef struct S_SSDP_ICON_DATA{ |
|||
char format[6]; |
|||
int width; |
|||
int height; |
|||
int depth; |
|||
char url[128]; |
|||
}SSDP_ICON_DATA; |
|||
|
|||
typedef struct S_SSDP_SERVICE_DATA{ |
|||
char type[128]; |
|||
char id[64]; |
|||
char desc[128]; |
|||
char ctrl[128]; |
|||
char evt[128]; |
|||
}SSDP_SERVICE_DATA; |
|||
|
|||
typedef struct S_SSDP_ICON_STORAGE{ |
|||
SSDP_ICON_DATA * array; |
|||
int size; |
|||
}SSDP_ICON_STORAGE; |
|||
|
|||
typedef struct S_SSDP_SERVICE_STORAGE{ |
|||
SSDP_SERVICE_DATA * array; |
|||
int size; |
|||
}SSDP_SERVICE_STORAGE; |
|||
|
|||
/* Notify should be less than half the cache timeout */ |
|||
#define NOTIFY_INTERVAL 300 |
|||
#define REFRESH_INTERVAL 600 |
|||
#define CACHE_TIMEOUT 1800 |
|||
#define MAX_NUM_IFACES 100 |
|||
#define MAX_PKT_SIZE 2000 |
|||
#define SSDP_MAX_SUPPORTED_TYPES 10 |
|||
#define MC_SSDP_GROUP "239.255.255.250" |
|||
#define MC_SSDP_PORT 1900 |
|||
#define LOCATION_PORT (MC_SSDP_PORT + 1) |
|||
#define LOCATION_DESC "/description.xml" |
|||
#define PACKAGE_NAME "Argus" |
|||
#define PACKAGE_VERSION "1.0.5" |
|||
#define MODEL "Server" |
|||
#define MANUFACTURER "Toogler(ltd)" |
|||
|
|||
#define SSDP_ST_ALL "ssdp:all" |
|||
|
|||
#define SERVER_STRING "POSIX UPnP/1.0 " PACKAGE_NAME "/" PACKAGE_VERSION |
|||
|
|||
typedef enum E_SOC_HANDLER_TYPE{ |
|||
SOC_HANDLER_SSDP = 0, |
|||
SOC_HANDLER_WEB = 1 |
|||
}SOC_HANDLER_TYPE; |
|||
|
|||
struct ifsock { |
|||
LIST_ENTRY(ifsock) link; |
|||
int stale; |
|||
int mod; |
|||
/* |
|||
* Sockets for inbound and outbound |
|||
* |
|||
* - The inbound is the multicast socket, shared between all ifaces |
|||
* - The outbound is bound to the iface address and a random port |
|||
*/ |
|||
int in, out; |
|||
/* Interface address and netmask */ |
|||
struct sockaddr_in addr; |
|||
struct sockaddr_in mask; |
|||
SOC_HANDLER_TYPE type; |
|||
}; |
|||
|
|||
class kernelModuleSSDPAnnouncer: public kernelModule, public basicThread { |
|||
private: |
|||
int m_iSocketFID; |
|||
LIST_HEAD(, ifsock) m_lInterfaceLinks; |
|||
struct sockaddr_in * address; |
|||
struct sockaddr_in * netmask; |
|||
|
|||
SSDP_ICON_STORAGE m_sIcons; |
|||
SSDP_SERVICE_STORAGE m_sServices; |
|||
|
|||
/***/ |
|||
char m_sDeviceType[64]; |
|||
char m_sServerName[128]; |
|||
char m_sDeviceName[64]; |
|||
char m_sDeviceSerial[64]; |
|||
char m_sDevicePresentationURL[128]; |
|||
char m_sUniversalProductCode[42]; |
|||
char m_sUUID[42]; |
|||
char m_sHostName[64]; |
|||
char m_sManufacturer[64]; |
|||
char m_sBaseURL[128]; |
|||
char m_sManufacturerURL[128]; |
|||
char m_sModelName[64]; |
|||
char m_sModelNumber[64]; |
|||
char m_sModelSite[128]; |
|||
char m_sModelDescription[128]; |
|||
|
|||
|
|||
bool m_bUseWebService; |
|||
uint16_t m_nWebPort; |
|||
time_t m_sTimeOut; |
|||
time_t m_nRefreshTime; |
|||
time_t m_nNotifyTime; |
|||
char * supported_types[SSDP_MAX_SUPPORTED_TYPES]; |
|||
char m_pXMLTEMPLATE[4096]; |
|||
struct ifsock * find_outbound( struct sockaddr *sa ); |
|||
struct ifsock * find_iface( struct sockaddr *sa ); |
|||
|
|||
int multicast_init(void); |
|||
int multicast_join( int sd, struct sockaddr *sa ); |
|||
|
|||
//int register_socket(int in, int out, struct sockaddr *addr, struct sockaddr *mask, void (*cb)(int sd) ); |
|||
bool register_socket(int in, int out, struct sockaddr *addr, struct sockaddr *mask, SOC_HANDLER_TYPE type ); |
|||
void announce( int mod ); |
|||
|
|||
int open_socket(char *ifname, struct sockaddr *addr, int port); |
|||
int close_socket(void); |
|||
|
|||
int filter_addr(struct sockaddr *sa); |
|||
int filter_iface(char *ifname, char *iflist[], size_t num); |
|||
|
|||
void compose_addr(struct sockaddr_in *sin, char *group, int port); |
|||
void compose_response(char *type, char *host, char *buf, size_t len); |
|||
void compose_search(char *type, char *buf, size_t len); |
|||
void compose_notify(char *type, char *host, char *buf, size_t len); |
|||
void compose_xml( CSTR peerIP ); |
|||
|
|||
void uuidgen(void); |
|||
bool web_init( int PortID ); |
|||
bool ssdp_init(int inSo ); |
|||
|
|||
void send_search( struct ifsock *ifs, char *type ); |
|||
void send_message( struct ifsock *ifs, char *type, struct sockaddr *sa ); |
|||
void ssdp_recv(int sd); |
|||
void web_recv(int sd); |
|||
bool stream_peek(int sd, char *ifname, int size ); |
|||
void respond(int sd, char *ifname); |
|||
void handle_message(int sd); |
|||
void mark(void); |
|||
bool sweep(void); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit kernelModuleSSDPAnnouncer( uint32_t moduleID ); |
|||
~kernelModuleSSDPAnnouncer(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
#endif |
|||
@ -0,0 +1,317 @@ |
|||
#include <stdio.h>
|
|||
#include <wchar.h>
|
|||
#include <string.h>
|
|||
#include <stdlib.h>
|
|||
#include <ctype.h>
|
|||
#include <unistd.h>
|
|||
#include <hidapi/hidapi.h>
|
|||
#include "kernelModuleUSBRelay.h"
|
|||
|
|||
#define LOG( X ) kernelModule::m_pLog->Log( "MOD_USBDC", 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 );\ |
|||
kernelModule::m_pLog->Log( "MOD_USBDC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelModule::m_pLog->Log( "MOD_USBDC", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
//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; |
|||
} |
|||
|
|||
|
|||
kernelModuleUSBRelay::kernelModuleUSBRelay( uint32_t ModuleID ) : kernelModule( ModuleID, KERNEL_MODULE_DCBUSB ){ |
|||
|
|||
}; |
|||
|
|||
kernelModuleUSBRelay::~kernelModuleUSBRelay(){ |
|||
}; |
|||
|
|||
void kernelModuleUSBRelay::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|||
|
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,40 @@ |
|||
#ifndef __KERNEL_USB_RELAY_MODULE_HEADER__ |
|||
#define __KERNEL_USB_RELAY_MODULE_HEADER__ |
|||
|
|||
#include "kernelModule.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 kernelModuleUSBRelay: public kernelModule { |
|||
private: |
|||
relay_board m_sBoardDef; |
|||
uint32_t m_nNO_CONFIG; |
|||
uint32_t m_nCURRENT_STATE; |
|||
uint32_t m_aCHANNEL_CONFIGS[32]; |
|||
public: |
|||
explicit kernelModuleUSBRelay( uint32_t ModuleID ); |
|||
virtual ~kernelModuleUSBRelay(); |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ); |
|||
}; |
|||
#endif |
|||
@ -0,0 +1,96 @@ |
|||
#include "kernelPrototype.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", 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 );\ |
|||
kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
kernelPrototype *kernelPrototype::_instance = NULL; |
|||
kernelPrototype *kernelPrototype::getInstance(){ |
|||
return _instance; |
|||
}; |
|||
|
|||
kernelPrototype::kernelPrototype( config_setting_t *ptr ): m_mWMProtector(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( ptr, "KERNEL" ); |
|||
#ifdef USE_MYSQL
|
|||
m_pDBC = mysqlDBC::getInstance(); |
|||
#else
|
|||
m_pDBC = sqliteDBC::getInstance(); |
|||
#endif
|
|||
m_pHardwareManager = NULL; |
|||
m_pModuleFactory = NULL; |
|||
m_pNodeFactory = NULL; |
|||
m_bExitCause = EXIT_CODE_KERNEL_CLEAR; |
|||
m_bWM = WM_KERNEL_PROTOTYPE_INIT; |
|||
kernelPrototype::_instance = this; |
|||
}; |
|||
|
|||
kernelPrototype::~kernelPrototype(){ |
|||
}; |
|||
|
|||
void kernelPrototype::setWM( uint8_t mode ){ |
|||
m_mWMProtector.lock(); |
|||
m_bWM = mode; |
|||
m_mWMProtector.unlock(); |
|||
}; |
|||
|
|||
void kernelPrototype::setExitCause( uint8_t code ){ |
|||
m_mWMProtector.lock(); |
|||
m_bExitCause = code; |
|||
m_mWMProtector.unlock(); |
|||
}; |
|||
|
|||
uint8_t kernelPrototype::getWM( void ){ |
|||
m_mWMProtector.lock(); |
|||
uint8_t rV = m_bWM; |
|||
m_mWMProtector.unlock(); |
|||
return rV; |
|||
}; |
|||
|
|||
uint8_t kernelPrototype::getExitCause(){ |
|||
return m_bExitCause; |
|||
}; |
|||
|
|||
void kernelPrototype::WaitFinish( bool Force ){ |
|||
if( Force ){ |
|||
#ifdef DEBUG
|
|||
LOG( "Forced Exit" ); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG( "Start Waiting for Thread to End (usually at MAIN)." ); |
|||
#endif
|
|||
}; |
|||
waitThreadEnd( Force ); |
|||
}; |
|||
|
|||
kernelEventFilter *kernelPrototype::getFilter( uint32_t id ){ |
|||
kernelEventFilter *RetVal = NULL; |
|||
if( m_vTargetFilters.size() > 0 ) { |
|||
for( vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){ |
|||
if( (*idx)->getID() == id ) { |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,63 @@ |
|||
#ifndef __DFSL_KERNEL_PROTOTYPE_HEADER__ |
|||
#define __DFSL_KERNEL_PROTOTYPE_HEADER__ |
|||
|
|||
#include "../../components/base/basicThread.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../components/base/basicLogCollection.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "hardwareManager.h" |
|||
#include "kernelModuleFactory.h" |
|||
#include "deviceNodeFactory.h" |
|||
#include "kernelEventFilter.h" |
|||
|
|||
|
|||
#define WM_KERNEL_PROTOTYPE_INIT 0 |
|||
|
|||
|
|||
#define EXIT_CODE_KERNEL_CLEAR 0 |
|||
#define EXIT_CODE_RELOAD_SERVICES 1 |
|||
#define EXIT_CODE_RESTART_OS 2 |
|||
#define EXIT_CODE_FACTORY_RESET 3 |
|||
#define EXIT_CODE_DETECT_HARDWARE 4 |
|||
|
|||
|
|||
class kernelPrototype: public basicThread { |
|||
private: |
|||
/* Internal */ |
|||
basicMutex m_mWMProtector; |
|||
uint8_t m_bExitCause; |
|||
uint8_t m_bWM; |
|||
static kernelPrototype * _instance; |
|||
protected: |
|||
/* basic */ |
|||
basicLogCollection * m_pLog; |
|||
basicEventHeap * m_pEventHeap; |
|||
config_setting_t * m_pSettings; |
|||
/* Special */ |
|||
dataBinder * m_pDBC; |
|||
hardwareManager * m_pHardwareManager; |
|||
kernelModuleFactory * m_pModuleFactory; |
|||
deviceNodeFactory * m_pNodeFactory; |
|||
vectorKernelEventFilters m_vTargetFilters; |
|||
/* func */ |
|||
virtual void m_fThreadProc( void ){}; |
|||
//hiden constructor -> the object cannot be used directly! |
|||
explicit kernelPrototype( config_setting_t *ptr ); |
|||
void setWM( uint8_t mode ); |
|||
void setExitCause( uint8_t mode ); |
|||
public: |
|||
virtual ~kernelPrototype(); |
|||
virtual bool create(){ return false; }; |
|||
uint8_t getExitCause(); |
|||
static kernelPrototype * getInstance(); |
|||
uint8_t getWM( void ); |
|||
//uint32_t getInstanceID(); |
|||
//hardwareManager * getHardwareManager(){ return m_pHardwareManager; }; |
|||
//kernelModuleFactory * getModuleFactory(); |
|||
kernelEventFilter * getFilter( uint32_t id ); |
|||
void WaitFinish( bool Force = false ); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,476 @@ |
|||
//----------------------------------------------------------------------------
|
|||
// Dr.Frucht Systems Ltd.
|
|||
// Copyright © 2000-2022. All Rights Reserved.
|
|||
// Version 2.0 11/18/2022
|
|||
// Last modification: 11/18/2022
|
|||
// PROJECT:
|
|||
// SUBSYSTEM:
|
|||
// FILE: LRF_Server.cpp
|
|||
// AUTHOR: gagua
|
|||
// OVERVIEW
|
|||
// ~~~~~~~~
|
|||
// Header file of mojoBackend.cpp
|
|||
//----------------------------------------------------------------------------
|
|||
//
|
|||
|
|||
#include "mojoBackend.h"
|
|||
|
|||
#ifdef USE_MYSQL
|
|||
#include "../common/MySQL_dataBinder.h"
|
|||
#else
|
|||
#include "../common/SQLite_dataBinder.h"
|
|||
#endif
|
|||
|
|||
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 )
|
|||
|
|||
mojoKernel * Kernel = NULL; |
|||
basicLogCollection * m_pLog = NULL; |
|||
basicSettingsProvider * SettingsProvider = NULL; |
|||
config_setting_t * Settings = NULL; |
|||
|
|||
#ifdef USE_MYSQL
|
|||
mysqlDBC * DBC = NULL; |
|||
#else
|
|||
sqliteDBC * DBC = NULL; |
|||
#endif
|
|||
|
|||
|
|||
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[] ){ |
|||
|
|||
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 Mojo Module\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@"; |
|||
}; |
|||
|
|||
|
|||
// Demonizing or not
|
|||
if( WBG ){ |
|||
printf( "Dr Frucht Systems Mojo Module 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 ); |
|||
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());
|
|||
}; |
|||
|
|||
SettingsProvider = basicSettingsProvider::getInstance( DCF_NAME ); |
|||
Settings = SettingsProvider->getSubNode( NULL, "GENERAL" ); |
|||
|
|||
uint8_t ExitCode = 0; |
|||
bool SSDP_ENABLE = false; |
|||
config_setting_t * pSetting = NULL; |
|||
|
|||
if(!config_setting_lookup_bool( Settings, "SSDP_ENABLE", (int*) &SSDP_ENABLE )){ |
|||
pSetting = config_setting_add( Settings, "SSDP_ENABLE", CONFIG_TYPE_BOOL ); |
|||
SSDP_ENABLE = true; |
|||
config_setting_set_bool( pSetting, SSDP_ENABLE ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
LOG("Manufacturer not set - using default"); |
|||
}; |
|||
|
|||
SettingsProvider->validate(); |
|||
|
|||
#ifdef USE_MYSQL
|
|||
DBC = mysqlDBC::getInstance( Settings ); |
|||
#else
|
|||
DBC = sqliteDBC::getInstance( Settings ); |
|||
#endif
|
|||
if( DBC ) { |
|||
if(!DBC->connect()){ |
|||
delete( DBC ); |
|||
LOG_ERROR( "++++ DB ERROR ++++" ); |
|||
unlink( gsCFG_PID_FILE ); |
|||
LOG( "PID File Deleted" ); |
|||
delete( m_pLog ); |
|||
return -1; |
|||
}; |
|||
}; |
|||
|
|||
// Start Loop of Restarted Kernel
|
|||
do{ |
|||
ExitCode = 0; |
|||
Kernel = mojoKernel::getInstance( Settings );//HWManager );
|
|||
|
|||
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( ) ){ |
|||
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 ); |
|||
ExitCode = Kernel->getExitCause(); |
|||
signal( 9, old_kill_handler_9 ); |
|||
signal( 15, old_kill_handler_15 ); |
|||
}; |
|||
delete( Kernel ); |
|||
LOG( "++++ Server Ended ++++" ); |
|||
}; |
|||
|
|||
if( ExitCode == EXIT_CODE_FACTORY_RESET ){ |
|||
CSTR tNAME = DBC->getDataParam( 0 ); |
|||
CSTR tUSER = DBC->getDataParam( 1 ); |
|||
CSTR tGROUP = DBC->getDataParam( 2 ); |
|||
delete( DBC ); |
|||
if ( tNAME != NULL ) { |
|||
LOG("FACTORY RESET ISSUED!"); |
|||
if( !fileExist( "data/factory.db" ) ){ |
|||
LOG_ERROR( "++++ No Factory Backup ++++" ); |
|||
} else { |
|||
if ( fileExist( tNAME ) ) { |
|||
LOG("Replace Working DB by Factory Clean one!"); |
|||
unlink( tNAME ); |
|||
} else { |
|||
LOG("No Old DB! Just copy Factory Clean one!"); |
|||
}; |
|||
fileCopy( "data/factory.db", tNAME ); |
|||
}; |
|||
free( tNAME ); |
|||
} else { |
|||
LOG_ERROR( "++++ No DB File Assigned ++++" ); |
|||
}; |
|||
ExitCode = 0; |
|||
}; |
|||
|
|||
} while( ExitCode > 0 ); |
|||
|
|||
unlink( gsCFG_PID_FILE ); |
|||
LOG( "PID File Deleted" ); |
|||
delete( m_pLog ); |
|||
return 0; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,29 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// 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 __LA_MOJO_SERVER_HEADER__ |
|||
#define __LA_MOJO_SERVER_HEADER__ |
|||
|
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <signal.h> |
|||
|
|||
#include "../../components/base/basicSettings.h" |
|||
#include "../../components/base/basicLogCollection.h" |
|||
#include "../../components/base/basicMemoryOperation.h" |
|||
#include "../../components/object/objectFileLoggingService.h" |
|||
#include "mojoKernel.h" |
|||
|
|||
|
|||
#endif |
|||
@ -0,0 +1,264 @@ |
|||
#include "mojoDBConnector.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MDBC", 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( "MDBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MDBC", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
mojoDBC *mojoDBC::_instance = NULL; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
mojoDBC *mojoDBC::getInstance( config_setting_t * Settings ) { |
|||
// check if the instance has been created yet
|
|||
if( 0 == _instance ){ |
|||
// if not, then create it
|
|||
_instance = new mojoDBC( Settings ); |
|||
}; |
|||
// return the single instance
|
|||
return _instance; |
|||
}; |
|||
|
|||
|
|||
mojoDBC::mojoDBC( config_setting_t * Settings ){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DATABASE" ); |
|||
m_bIsConnected = false; |
|||
m_bIsServerLocal = true; |
|||
m_pDataStorage = NULL; |
|||
m_pDataMemory = NULL; |
|||
}; |
|||
|
|||
mojoDBC::~mojoDBC(){ |
|||
if ( m_pDataStorage ) delete( m_pDataStorage ); |
|||
if ( m_pDataMemory ) delete( m_pDataMemory ); |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
bool mojoDBC::connect( void ){ |
|||
if ( m_pSettings == NULL) return false; |
|||
bool bRecreateMemStructures = false; |
|||
config_setting_t * pSetting; |
|||
const char * tBuff; |
|||
//Disconnect if Connected
|
|||
m_bIsConnected = false; |
|||
char web_access_user[64]; |
|||
char web_access_group[64]; |
|||
|
|||
//Apply New Config
|
|||
#ifdef DEBUG
|
|||
LOG( "Reading DB Settings ... " ); |
|||
#endif
|
|||
if(!config_setting_lookup_string(m_pSettings, "DATA_FILE_NAME", (const char**)&tBuff )){ |
|||
pSetting = config_setting_add(m_pSettings, "DATA_FILE_NAME", CONFIG_TYPE_STRING); |
|||
sprintf( m_pDbFile, "data/mysqlitedb.db" ); |
|||
config_setting_set_string( pSetting, m_pDbFile ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
LOG("Data Storage not set - using default"); |
|||
} else { |
|||
sprintf( m_pDbFile, tBuff ); |
|||
}; |
|||
if(!config_setting_lookup_string(m_pSettings, "WEB_ACCESS_USER", (const char**)&tBuff )){ |
|||
pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_USER", CONFIG_TYPE_STRING); |
|||
sprintf( web_access_user, "www-data" ); |
|||
config_setting_set_string( pSetting, web_access_user ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
LOG("Web Access User not set - using default"); |
|||
} else { |
|||
sprintf( web_access_user, tBuff ); |
|||
}; |
|||
if(!config_setting_lookup_string(m_pSettings, "WEB_ACCESS_GROUP", (const char**)&tBuff )){ |
|||
pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_GROUP", CONFIG_TYPE_STRING); |
|||
sprintf( web_access_group, "www-data" ); |
|||
config_setting_set_string( pSetting, web_access_group ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
LOG("Web Access Group not set - using default"); |
|||
} else { |
|||
sprintf( web_access_group, tBuff ); |
|||
}; |
|||
if( !fileExist( DB_SHMEM_POINT )) { |
|||
bRecreateMemStructures = true; |
|||
mkdir( DB_SHMEM_POINT, 0775 );// S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
|||
chown( DB_SHMEM_POINT, web_access_user, web_access_group ); //To make Accessed from PHP
|
|||
chmod( DB_SHMEM_POINT, 0775 ); |
|||
}; |
|||
if (!config_setting_lookup_string(m_pSettings, "DATA_MEMORY_NAME", (const char **)&tBuff)) { |
|||
pSetting = config_setting_add(m_pSettings, "DATA_MEMORY_NAME", CONFIG_TYPE_STRING); |
|||
sprintf( m_pDbMemory, "mem_db.db" ); |
|||
config_setting_set_string( pSetting, m_pDbMemory ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
LOG("Memory Storage not set - using default"); |
|||
}; |
|||
sprintf( m_pDbMemory, "%s/%s", DB_SHMEM_POINT, tBuff ); |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
|
|||
// Kill Connection if any
|
|||
if ( m_pDataStorage ) delete( m_pDataStorage ); |
|||
if ( m_pDataMemory ) delete( m_pDataMemory ); |
|||
|
|||
#ifdef DEBUG
|
|||
LOG( m_pDbFile ); |
|||
#endif
|
|||
// Create New Connections
|
|||
m_pDataStorage = new SQLite_Connector(); |
|||
if ( m_pDataStorage ) { |
|||
if( m_pDataStorage->Connect( m_pDbFile, 0, true ) ){ |
|||
#ifdef DEBUG
|
|||
LOG("DB File Opened"); |
|||
#endif
|
|||
chown( m_pDbFile, web_access_user, web_access_group ); |
|||
chmod( m_pDbFile, 0775 ); |
|||
} else{ |
|||
LOG_ERROR("Cannot Connect to DB File"); |
|||
delete( m_pDataStorage ); |
|||
m_pDataStorage = NULL; |
|||
LOG("Storage Deleted!"); |
|||
return false; |
|||
}; |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG( m_pDbMemory ); |
|||
#endif
|
|||
if( !fileExist( m_pDbMemory )) { |
|||
bRecreateMemStructures = true; |
|||
}; |
|||
m_pDataMemory = new SQLite_Connector(); |
|||
if ( m_pDataMemory ) { |
|||
if( m_pDataMemory->Connect( m_pDbMemory, 0, true ) ){ |
|||
#ifdef DEBUG
|
|||
LOG("DB Memory Opened"); |
|||
#endif
|
|||
chown( m_pDbMemory, web_access_user, web_access_group ); |
|||
chmod( m_pDbMemory, 0775 ); |
|||
if ( bRecreateMemStructures ) initMemDB(); |
|||
} else{ |
|||
LOG_ERROR("Cannot Connect to DB Memory"); |
|||
delete( m_pDataStorage ); |
|||
delete( m_pDataMemory ); |
|||
m_pDataStorage = NULL; |
|||
m_pDataMemory = NULL; |
|||
return false; |
|||
}; |
|||
}; |
|||
m_bIsConnected = true; |
|||
return m_bIsConnected; |
|||
}; |
|||
|
|||
void mojoDBC::initMemDB( void ){ |
|||
|
|||
m_pDataMemory->Query("CREATE TABLE \"nodes_qcq\" ( \
|
|||
\"id\" INTEGER NOT NULL,\
|
|||
\"node_id\" INTEGER NOT NULL,\
|
|||
\"cmd\" INTEGER NOT NULL,\
|
|||
\"status\" INTEGER DEFAULT 0,\
|
|||
\"parameter\" TEXT,\
|
|||
PRIMARY KEY(\"id\" AUTOINCREMENT)\
|
|||
);"); |
|||
|
|||
m_pDataMemory->Query("CREATE TABLE \"servers\" (\
|
|||
\"id\" INTEGER NOT NULL,\
|
|||
\"online\" INTEGER DEFAULT 0,\
|
|||
\"ts\" INTEGER DEFAULT 0,\
|
|||
\"version_string\" TEXT,\
|
|||
\"identity\" TEXT,\
|
|||
\"pid\" INTEGER DEFAULT 0,\
|
|||
\"cpu_cores\" INTEGER DEFAULT 0.0,\
|
|||
\"stat_cpu1\" REAL DEFAULT 0.0,\
|
|||
\"stat_cpu5\" REAL DEFAULT 0.0,\
|
|||
\"stat_cpu15\" REAL DEFAULT 0.0,\
|
|||
\"stat_mem\" REAL DEFAULT 0.0,\
|
|||
\"stat_disk\" REAL DEFAULT 0.0,\
|
|||
\"val_mem_tottal\" INTEGER DEFAULT 0,\
|
|||
\"val_mem_current\" INTEGER DEFAULT 0,\
|
|||
\"val_disk_tottal\" INTEGER DEFAULT 0,\
|
|||
\"val_disk_current\" INTEGER DEFAULT 0,\
|
|||
\"temp0\" REAL DEFAULT 0.0,\
|
|||
PRIMARY KEY(\"id\" AUTOINCREMENT)\
|
|||
);"); |
|||
|
|||
}; |
|||
|
|||
|
|||
DBC_PUSHED_CMD *mojoDBC::getNodePushedCMD( uint32_t NodeID ){ |
|||
DBC_PUSHED_CMD * RetVal = NULL; |
|||
if ( m_bIsConnected ) { |
|||
char QS[MAX_PATH]; |
|||
AAssoc * result; |
|||
sprintf( QS, "select * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 ORDER BY `id` LIMIT 1", NodeID ); |
|||
result = m_pDataMemory->Query( QS ); |
|||
if ( result ) { |
|||
if( result->size() > 0 ) { |
|||
RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD)); |
|||
if( RetVal ) { |
|||
Assoc * cArr; |
|||
Assoc::iterator it; |
|||
|
|||
memset( RetVal, 0, sizeof(DBC_PUSHED_CMD)); |
|||
cArr = result->at(0); |
|||
it = cArr->find("id"); |
|||
if( it != cArr->end() ){ |
|||
RetVal->id = atoi( it->second.c_str() ); |
|||
}; |
|||
it = cArr->find("cmd"); |
|||
if( it != cArr->end() ){ |
|||
RetVal->CMD = atoi( it->second.c_str() ); |
|||
}; |
|||
it = cArr->find("parameter"); |
|||
if( it != cArr->end() ){ |
|||
strncpy( RetVal->PARAM, it->second.c_str(), 256 ); |
|||
RetVal->PARAM[255] = (char)0; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
m_pDataMemory->deleteResult( result ); |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool mojoDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){ |
|||
if ( m_bIsConnected ) { |
|||
char QS[MAX_PATH]; |
|||
sprintf( QS, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID ); |
|||
return m_pDataMemory->SilentQuery( QS ); |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
bool mojoDBC::cleanNodePushedCMD( void ){ |
|||
if ( m_bIsConnected ) { |
|||
return m_pDataMemory->SilentQuery( "DELETE FROM `nodes_qcq` WHERE `status` > 200" ); |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
|
|||
|
|||
/********************************************************************
|
|||
* * |
|||
* Slow DB Functions * |
|||
* * |
|||
********************************************************************/ |
|||
|
|||
DBC_NET_IF_DATA *mojoDBC::getNIF_Data( uint32_t ID ){ |
|||
|
|||
}; |
|||
uint32_t mojoDBC::getNIF_ID( CSTR key ){ |
|||
|
|||
}; |
|||
uint32_t mojoDBC::getNIF_IDbyDevice( CSTR device ){ |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,202 @@ |
|||
#ifndef __MOJO_DATABASE_CONNECTOR_HEADER__ |
|||
#define __MOJO_DATABASE_CONNECTOR_HEADER__ |
|||
|
|||
#include "../components/base/basicSettingsProvider.h" |
|||
#include "../data/sqlite/sqlite_class.h" |
|||
#include "../alg/generic/md5.h" |
|||
#include "../alg/lgs/mask.h" |
|||
#include "../../rgoose/rgooseTypes.h" |
|||
|
|||
#define DB_SHMEM_POINT "/dev/shm/argus" |
|||
|
|||
|
|||
class mojoDBC{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
config_setting_t * m_pSettings; |
|||
SQLite_Connector * m_pDataStorage; |
|||
SQLite_Connector * m_pDataMemory; |
|||
bool m_bIsConnected; |
|||
bool m_bIsServerLocal; |
|||
bool m_bRecreateMemStructures; |
|||
char m_pDbFile[CLOG]; |
|||
char m_pDbMemory[CLOG]; |
|||
char m_pDbUsername[CLOG]; |
|||
char m_pDbPassword[CLOG]; |
|||
char m_pDbDatabase[CLOG]; |
|||
void initMemDB( void ); |
|||
public: |
|||
static mojoDBC * getInstance( config_setting_t * Settings = NULL ); |
|||
virtual ~mojoDBC(); |
|||
/* Functionality */ |
|||
bool connect( void ); |
|||
bool isLocal( void ) const { return m_bIsServerLocal; }; |
|||
|
|||
//SET GLOBAL tmp_table_size = 1024 * 1024 * 1024 * 2; |
|||
//SET GLOBAL max_heap_table_size = 1024 * 1024 * 1024 * 2; |
|||
//SELECT @@max_heap_table_size; |
|||
//SHOW VARIABLES LIKE 'max_heap_table_size'; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
uint32_t addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id=0, uint16_t dig_r=0, float EL=.0f, float AZ=.0f, float RANGE=.0f, float AREA=.0f, float lat=.0f, float lon=.0f, float alt=.0f, uint32_t RefID=0, CSTR RefUUID=NULL ); |
|||
bool addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ); |
|||
|
|||
bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false ); |
|||
uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 ); |
|||
uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ); |
|||
bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ); |
|||
|
|||
//bool addIPCam( uint32_t SiteID, resultWoWo *tPtr ); |
|||
bool addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr ); |
|||
uint32_t addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ); |
|||
uint32_t addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ); |
|||
uint32_t addLocalUART( uint32_t NodeID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode=0, uint16_t port=0 ); |
|||
uint32_t addLocalNIF( CSTR device, CSTR mac, ARGUS_NIF_TYPE dtype, ARGUS_NIF_MODE dmode, uint32_t aux_id = 0 ); |
|||
uint32_t addLocalNetwork( uint32_t NIF_ID, ARGUS_NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ); |
|||
uint32_t addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp=false, CSTR BRANG=NULL, CSTR ERANG=NULL, CSTR MASK=NULL, CSTR LEASE_TIME=NULL ); |
|||
uint32_t addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSID, CSTR password, ARGUS_WIFI_ENCRIPTION encryption, uint32_t router_id=0 ); |
|||
bool addNotification( uint32_t MSG_ID, uint8_t DIS_LVL = 0, uint32_t OBJ_ID=0 ); |
|||
bool addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ); |
|||
|
|||
//bool addPictureEvent( uint32_t evtID, uint32_t pictureoID ); |
|||
uint32_t addResource( uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID = 0 ); |
|||
uint32_t addUploadFile( uint32_t NodeID, CSTR uid, CSTR fileName ); |
|||
|
|||
bool addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ); |
|||
uint32_t addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ); |
|||
|
|||
bool cleanResources( uint32_t ServerNodeID, bool all = false ); |
|||
bool cleanLRFMask( uint32_t maskID, bool deleteMask = false ); |
|||
bool cleanNodeEvents( uint32_t NodeID, bool all = false ); |
|||
bool cleanEvents2PictureBinding( uint32_t PicID ); |
|||
bool cleanEvents2VideoBinding( uint32_t PicID ); |
|||
bool cleanNodePushedCMD( void ); |
|||
|
|||
|
|||
void lazyEventArchiver( uint32_t DalayTime = 10 ); |
|||
DBC_INT_LIST * listCamMediaStreams( uint32_t CAMID ); |
|||
DBC_INT_LIST * listStreamCapPictures( uint32_t StreamID, uint32_t cnt ); |
|||
DBC_INT_LIST * listDetectionProfileIDs( uint32_t nodeID ); |
|||
DBC_INT_LIST * listDetectionProfiles( uint32_t nodeID ); |
|||
DBC_INT_LIST * listFilters( uint32_t ServerID ); |
|||
DBC_INT_LIST * listLRFMaskVertexes( uint32_t MaskID ); |
|||
DBC_INT_LIST * listLRFMaskVertexPoints( uint32_t VertexID ); |
|||
DBC_INT_LIST * listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listingType = LIST_ALL_RECORDS ); |
|||
DBC_INT_LIST * listMediaStreams( uint32_t SiteId, uint8_t listingType = LIST_ALL_RECORDS ); |
|||
DBC_INT_LIST * listModules( uint32_t ServerID ); |
|||
DBC_INT_LIST * listNetworks( uint32_t nif_id ); |
|||
DBC_INT_LIST * listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ); |
|||
|
|||
DBC_INT_LIST * listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST * old_ids ); |
|||
DBC_INT_LIST * listNodes( uint32_t SiteID, uint32_t ServerID, bool all = false ); |
|||
//DBC_INT_LIST * listSockets( uint32_t NodeID ); |
|||
DBC_INT_LIST * listResources( uint32_t NodeID = 0 ); |
|||
simplePolygone * loadLRFMaskVertex( uint32_t vid ); |
|||
|
|||
bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ); |
|||
DBC_APF_DATA * getAPFData( uint32_t APFID ); |
|||
DBC_CAM_DATA * getCamData( uint32_t CamID ); |
|||
uint32_t getCamId( CSTR UUID ); |
|||
|
|||
bool getConnectionStatus(void){return m_bIsConnected;}; |
|||
DBC_CAP_DATA * getCamCapPictureData( uint32_t PicID ); |
|||
DBC_EVT_RECORD * getEventByUUID( CSTR UUID ); |
|||
DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID ); |
|||
DBC_FH_DATA * getFlyHunterData( uint32_t ID ); |
|||
int getIPCamCount( uint32_t SiteID ); |
|||
KAFKA_TEMPLATE * getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ); |
|||
//bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ); |
|||
DBC_LRF_DATA * getLRFData( uint32_t ID ); |
|||
uint8_t getLRFDataStatus( uint32_t ID ); |
|||
PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ); |
|||
CSTR getLRFDraw( uint32_t DBID ); |
|||
uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 ); |
|||
DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_DATA * getMediaServerData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamData( uint32_t ID ); |
|||
DBC_MEDIA_SERVER_STREAM_DATA * getMediaServerStreamDataBySource( uint32_t ID ); |
|||
DBC_MODULE_DATA * getModuleData( uint32_t ID ); |
|||
CSTR getNodeName( uint32_t NodeID ); |
|||
uint32_t getNodeAuxParam( uint32_t NodeID ); |
|||
uint32_t getNodeAuxID( uint32_t NodeID ); |
|||
DBC_NETWORK_DATA * getNetworkData( uint32_t net_id ); |
|||
uint32_t getNetworkInfrastructureID( uint32_t nif_id ); |
|||
DBC_NET_IF_DATA * getNIF_Data( uint32_t ID ); |
|||
uint32_t getNIF_ID( CSTR key ); |
|||
uint32_t getNIF_IDbyDevice( CSTR device ); |
|||
DBC_NODE_DATA * getNodeData( uint32_t ID ); |
|||
|
|||
DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID ); |
|||
DBC_PUSHED_CMD * getActivePushedCMD( uint32_t NodeID ); |
|||
DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID ); |
|||
|
|||
//uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ); |
|||
DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ); |
|||
uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ); |
|||
uint32_t getServerID( CSTR identity ); |
|||
uint32_t getServerNode( uint32_t SID ); |
|||
KAFKA_SETTINGS * getSettingsKAFKA( uint32_t NodeID ); |
|||
DBC_SITE_DATA * getSiteData( uint32_t ID ); |
|||
//DBC_SOCKET_DATA * getSocketData( uint32_t ID ); |
|||
DBC_TARGET_FLITER_DATA * getTargetFilterData( uint32_t ID ); |
|||
DBC_UART_DATA * getUartData( uint32_t UartID ); |
|||
uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path ); |
|||
uint32_t getWiFi_ID( uint32_t nif_id ); |
|||
bool fillShadow2D( uint32_t ID, SHADOW & SH ); |
|||
|
|||
void deleteCamCapPicture( uint32_t PicID ); |
|||
void deleteNode( uint32_t NodeID ); |
|||
void deleteCamera( uint32_t CamID ); |
|||
void deleteConnections( uint32_t NodeID ); |
|||
void deleteNodeEvents( uint32_t NodeID ); |
|||
void deleteMediaStream( uint32_t MediaID ); |
|||
void deleteNIF( uint32_t NifID ); |
|||
void deleteNIS( uint32_t NisID ); |
|||
void deleteResource( uint32_t ResourceID ); |
|||
void deleteSensor( uint32_t SensorID ); |
|||
void deleteUART( uint32_t UARTID ); |
|||
|
|||
void finalizeVideoRecord( uint32_t videoID, uint32_t clen ); |
|||
|
|||
void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ); |
|||
void unregisterServer( uint32_t ServerID, uint32_t NodeID ); |
|||
|
|||
bool transferEvtToArchive( uint32_t SECONDS = ONE_DAY_HISTORY ); |
|||
|
|||
|
|||
|
|||
bool setNodeOnline( uint32_t NodeID, uint8_t status=ARGUS_NODE_STATUS_WORK ); |
|||
bool setNodeOffline( uint32_t NodeID ); |
|||
bool setOnlineStatus( bool Status ); |
|||
bool setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ); |
|||
bool setLRFDataStatus( uint32_t lrfID, uint8_t ST ); |
|||
bool setLRFAltSerial( uint32_t lrfID, CSTR Serial ); |
|||
bool setLRFAltVerison( uint32_t lrfID, CSTR version ); |
|||
bool setLRFMaskStatus( uint32_t maskID, bool status ); |
|||
bool setStreamValid( uint32_t streamID, bool status = true ); |
|||
//bool syncEventArchive( void ); ALTER TABLE table_name AUTO_INCREMENT = start_value; |
|||
bool update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ); |
|||
bool updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ); |
|||
bool updateCamRange( uint32_t camID, float range ); |
|||
bool updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ); |
|||
bool updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ); |
|||
bool updateLRFSerial( uint32_t lrfID, CSTR Serial ); |
|||
bool updateLRFVerison( uint32_t lrfID, CSTR version ); |
|||
bool updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP=0, uint32_t spikes=0 ); |
|||
bool updateMediaServerStream( uint32_t id, CSTR mrl=NULL, CSTR key = NULL ); |
|||
bool updateNetworkNode( bool OnlineStatus ); |
|||
bool updateNodePushedCMD( uint32_t CmdID, uint8_t status ); |
|||
bool updateResourceAUX( uint32_t ResID, uint32_t AUX ); |
|||
bool updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ); |
|||
private: |
|||
static mojoDBC * _instance; |
|||
explicit mojoDBC( config_setting_t * Settings ); |
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
#endif //__MOJO_DATABASE_CONNECTOR_HEADER__ |
|||
@ -0,0 +1,916 @@ |
|||
//----------------------------------------------------------------------------
|
|||
// Dr.Frucht Systems Ltd.
|
|||
// Copyright © 2000-2017. All Rights Reserved.
|
|||
// Version 2.0 7/20/2017
|
|||
// Last modification: 7/20/2017
|
|||
// PROJECT:
|
|||
// SUBSYSTEM:
|
|||
// FILE: mojoHardwareManager.cpp
|
|||
// AUTHOR: gagua
|
|||
// OVERVIEW
|
|||
// ~~~~~~~~
|
|||
// Header file of mojoHardwareManager.cpp
|
|||
//----------------------------------------------------------------------------
|
|||
//
|
|||
|
|||
#include "mojoHardwareManager.h"
|
|||
#include "../hardware/hid/hid_dc.h"
|
|||
|
|||
#include <sys/time.h>
|
|||
#include <sys/resource.h>
|
|||
#include <sys/types.h>
|
|||
#include <sys/ioctl.h>
|
|||
#include <hidapi/hidapi.h>
|
|||
#include <ifaddrs.h>
|
|||
#include <linux/serial.h>
|
|||
#include <linux/videodev2.h>
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MHWM", 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( "MHWM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MHWM", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
mojoHardwareManager *mojoHardwareManager::_instance = NULL; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
mojoHardwareManager *mojoHardwareManager::getInstance( config_setting_t * Settings ) { |
|||
// check if the instance has been created yet
|
|||
if( 0 == _instance ){ |
|||
// if not, then create it
|
|||
_instance = new mojoHardwareManager( Settings ); |
|||
}; |
|||
// return the single instance
|
|||
return _instance; |
|||
}; |
|||
|
|||
|
|||
// Constructor implementation
|
|||
mojoHardwareManager::mojoHardwareManager( config_setting_t *SNode ){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pSettingsProvider = basicSettingsProvider::getInstance(); |
|||
m_nMemoryLimitHeapSize = 0; |
|||
if( m_pSettingsProvider ) { |
|||
m_pSettings = m_pSettingsProvider->getSubNode( SNode, "HARDWARE_MANAGER" ); |
|||
if( m_pSettingsProvider->isCompromised() ) { |
|||
m_pSettingsProvider->validate(); |
|||
}; |
|||
} else { |
|||
m_pSettings = NULL; |
|||
}; |
|||
|
|||
m_pDBC = mojoDBC::getInstance(); |
|||
|
|||
char tB[128]; |
|||
struct rlimit rl={0}; |
|||
getrlimit( RLIMIT_STACK, &rl ); |
|||
sprintf( tB, "Stack Size: %d", rl.rlim_cur ); //RLIM_INFINITY
|
|||
LOG( tB ); |
|||
sprintf( tB, "MAX Stack Size: %d", rl.rlim_max ); |
|||
LOG( tB ); |
|||
m_bInitOK = false; |
|||
}; |
|||
|
|||
mojoHardwareManager::~mojoHardwareManager(){ |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
bool mojoHardwareManager::validate(){ |
|||
bool RetVal = true; |
|||
//Mem Validator
|
|||
if( m_nMemoryLimitHeapSize ) { |
|||
size_t memStat = getCurrentRSS(); |
|||
#ifdef DEBUG_EXTRA
|
|||
char MEM_MSG[128]; |
|||
sprintf( MEM_MSG, "MEM: %d TARG: %d", memStat, m_nMemoryLimitHeapSize ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
RetVal = ( memStat < m_nMemoryLimitHeapSize ); |
|||
if ( !RetVal ) { |
|||
LOG_ERROR("Memory Consumption too BIG!"); |
|||
}; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
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))
|
|||
|
|||
|
|||
|
|||
void mojoHardwareManager::getMAC( CSTR if_name, CSTR buf ){ |
|||
char tB[128]; |
|||
FILE * fd=NULL; |
|||
if ( buf ) { |
|||
sprintf(tB, "/sys/class/net/%s/address", if_name); |
|||
#ifdef DEBUG
|
|||
LOG( tB ); |
|||
#endif
|
|||
fd=fopen(tB,"r"); |
|||
if ( fd ) { |
|||
fread( buf, 1, INET6_ADDRSTRLEN, fd ); |
|||
fclose( fd ); |
|||
buf = trim( buf ); |
|||
} else { |
|||
memset( buf, 0, INET6_ADDRSTRLEN ); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG( buf ); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
void mojoHardwareManager::getGW( CSTR if_name, CSTR buf ){ |
|||
FILE * fd = popen( "route -n", "r" ); |
|||
char tB[1024]; |
|||
//char expBuf[1024];
|
|||
|
|||
memset( buf, 0, INET6_ADDRSTRLEN ); |
|||
|
|||
if ( fd ) { |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim((CSTR)tB); |
|||
if( strlen(tB) ) { |
|||
if( strstr( tB, if_name ) != NULL ){ |
|||
//strncpy( expBuf, tB, 1024 );
|
|||
CArray *CA = explode( ' ', tB ); |
|||
if ( CA ) { |
|||
//for (int i=0; i< CA->size(); i++ ) {
|
|||
// char tB[128];
|
|||
// trim( CA->at(i) );
|
|||
// sprintf( tB, "GW# %d: %s", i, CA->at(i) );
|
|||
// LOG( tB );
|
|||
//};
|
|||
trim( CA->at(1) ); |
|||
if( strstr(CA->at(1), "0.0.0.0") == NULL ) { |
|||
strncpy( buf, CA->at(1), INET6_ADDRSTRLEN ); |
|||
}; |
|||
delete(CA); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
if( strlen( buf ) == 0 ) strncpy( buf, "0.0.0.0", INET6_ADDRSTRLEN ); |
|||
}; |
|||
|
|||
void mojoHardwareManager::getTTyDesc( CSTR dev_name, CSTR buf ){ |
|||
FILE * fd = popen( "dmesg | grep tty", "r" ); |
|||
char tB[1024]; |
|||
//char expBuf[1024];
|
|||
|
|||
memset( buf, 0, DBC_RESOURCE_DESC_SIZE ); |
|||
|
|||
if ( fd ) { |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim((CSTR)tB); |
|||
if( strlen(tB) ) { |
|||
if( strstr( tB, dev_name ) != NULL ){ |
|||
//strncpy( expBuf, tB, 1024 );
|
|||
CArray *CA = explode( ':', tB ); |
|||
if ( CA ) { |
|||
//for (int i=0; i< CA->size(); i++ ) {
|
|||
// char tB[128];
|
|||
// trim( CA->at(i) );
|
|||
// sprintf( tB, "GW# %d: %s", i, CA->at(i) );
|
|||
// LOG( tB );
|
|||
//};
|
|||
trim( CA->at(1) ); |
|||
strncpy( buf, CA->at(1), DBC_RESOURCE_DESC_SIZE ); |
|||
buf[DBC_RESOURCE_DESC_SIZE-1]=(char)0; |
|||
delete(CA); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
if( strlen( buf ) == 0 ){ |
|||
strncpy( buf, "--Unknown--", DBC_RESOURCE_DESC_SIZE ); |
|||
buf[DBC_RESOURCE_DESC_SIZE-1]=(char)0; |
|||
}; |
|||
}; |
|||
|
|||
PARSE_RESULT_NET_INTERFACES *mojoHardwareManager::parse_neconfig( CSTR if_name ){ |
|||
PARSE_RESULT_NET_INTERFACES *tVal = NULL; |
|||
FILE *fd; |
|||
bool cConfig = false; |
|||
fd = fopen("/etc/network/interfaces","r"); |
|||
if ( fd ) { |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
tVal = (PARSE_RESULT_NET_INTERFACES *) malloc( sizeof(PARSE_RESULT_NET_INTERFACES)); |
|||
if ( tVal ) { |
|||
memset(tVal, 0 , sizeof(PARSE_RESULT_NET_INTERFACES)); |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim((CSTR)tB); |
|||
if( strlen(tB) ) { |
|||
strncpy( expBuf, tB, 1024 ); |
|||
CArray *CA = explode( ' ', expBuf ); |
|||
if( CA ) { |
|||
for( CArray::iterator idx = CA->begin(); idx < CA->end(); idx++ ) { |
|||
if((*idx)[0]=='#') break; |
|||
if(strstr((*idx), "auto")!= NULL ) if( strstr( tB, if_name )!= NULL ) tVal->enabled = true; |
|||
if(strstr((*idx), "allow-hotplug")!= NULL ) if( strstr( tB, if_name )!= NULL ) tVal->hot_plug = true; |
|||
if(strstr((*idx), "iface")!= NULL ) if( strstr( tB, if_name )!= NULL ){ |
|||
if (strstr( tB, "static") != NULL) tVal->if_static = true; |
|||
cConfig = true; |
|||
} else cConfig = false; |
|||
if(strstr((*idx), "address")!= NULL ) if( cConfig ){ |
|||
idx++; |
|||
if(strstr((*idx),"/")!= NULL ){ |
|||
int8_t sh = strstr((*idx),"/") - (*idx); |
|||
strncpy( tVal->address, (*idx), sh ); |
|||
tVal->address[sh]=(char)0; |
|||
int8_t bm = atoi( (*idx) + sh + 1 ); |
|||
union{ |
|||
uint32_t mm; |
|||
uint8_t nm[4]; |
|||
} nmu = {0}; |
|||
for ( sh = 0; sh < bm; sh++ ) nmu.mm |= (1 << sh); |
|||
sprintf(tVal->netmask, "%d.%d.%d.%d", nmu.nm[0], nmu.nm[1], nmu.nm[2], nmu.nm[3]); |
|||
} else { |
|||
strncpy( tVal->address, (*idx), INET6_ADDRSTRLEN ); |
|||
}; |
|||
}; |
|||
if(strstr((*idx), "netmask")!= NULL ) if( cConfig ){ |
|||
LOG("netMSK"); |
|||
idx++; |
|||
LOG(*idx); |
|||
strncpy(tVal->netmask, (*idx), INET6_ADDRSTRLEN); |
|||
}; |
|||
//if(strstr((*idx), "bridge_ports")!= NULL ) cMode = 6;
|
|||
//if(strstr((*idx), "bridge_stp")!= NULL ) cMode = 7;
|
|||
//if(strstr((*idx), "bridge_waitport")!= NULL ) cMode = 8;
|
|||
//if(strstr((*idx), "bridge_fd")!= NULL ) cMode = 9;
|
|||
}; |
|||
delete( CA ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
#ifdef DEBUG
|
|||
if ( tVal ) { |
|||
if( tVal->enabled ) LOG("NIF Enabled"); else LOG("NIF Disabled"); |
|||
if (tVal->hot_plug) LOG("NIF Hot Plugable"); else LOG("NIF not Hot Plugable"); |
|||
if (tVal->if_static) LOG("Address is static"); else LOG("Address is Dynamic"); |
|||
if(strlen(tVal->address))LOG(tVal->address); |
|||
if(strlen(tVal->netmask))LOG(tVal->netmask); |
|||
}; |
|||
#endif
|
|||
return tVal; |
|||
}; |
|||
|
|||
PARSE_RESULT_WIFI_SETTINGS *mojoHardwareManager::parse_wifi( CSTR if_name ){ |
|||
PARSE_RESULT_WIFI_SETTINGS *tVal = NULL; |
|||
FILE *fd; |
|||
bool cConfig = false; |
|||
|
|||
tVal = (PARSE_RESULT_WIFI_SETTINGS *) malloc( sizeof(PARSE_RESULT_WIFI_SETTINGS)); |
|||
if ( tVal ) { |
|||
memset(tVal, 0 , sizeof(PARSE_RESULT_WIFI_SETTINGS)); |
|||
fd = fopen("/etc/dnsmasq.conf","r"); |
|||
if ( fd ) { |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim((CSTR)tB); |
|||
if( strlen(tB) ) { |
|||
strncpy( expBuf, tB, 1024 ); |
|||
CArray *CA = explode( '=', expBuf ); |
|||
if( CA ) { |
|||
if( CA->size() ){ |
|||
if( CA->at(0)[0] == '#' ) continue; |
|||
if( strstr(CA->at(0), "interface")!= NULL ) { |
|||
if( strstr( tB, if_name)!= NULL ) { |
|||
cConfig = true; |
|||
tVal->dhcp_enabled = true; |
|||
}; |
|||
}; |
|||
if( cConfig ){ |
|||
if ( strstr(CA->at(0), "dhcp-range")!= NULL ) { |
|||
char tT[1024]; |
|||
strncpy( tT, CA->at(1), 1024 ); |
|||
CArray *CB = explode(',', tT ); |
|||
if( CB ){ |
|||
if( CB->size() > 3 ){ |
|||
strncpy( tVal->range_start, CB->at(0), INET6_ADDRSTRLEN); |
|||
strncpy( tVal->range_stop, CB->at(1), INET6_ADDRSTRLEN); |
|||
strncpy( tVal->netmask, CB->at(2), INET6_ADDRSTRLEN); |
|||
strncpy( tVal->lease_period, CB->at(3), INET6_ADDRSTRLEN); |
|||
}; |
|||
delete( CB ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
delete( CA ); |
|||
}; |
|||
}; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
//Check WiFi
|
|||
if( strstr(if_name,"w")!= NULL ) { |
|||
char tName[128]; |
|||
sprintf( tName, "iwconfig %s", if_name ); |
|||
fd = popen( tName, "r" ); |
|||
if ( fd ) { |
|||
char tB[1024]; |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd ); |
|||
trim( tB ); |
|||
if (strstr(tB, "Mode") != NULL) if (strstr(tB, "Master") != NULL) tVal->access_point = true; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
}; |
|||
if ( tVal->access_point ) { |
|||
fd = fopen("/etc/hostapd/hostapd.conf", "r"); |
|||
if ( fd ) { |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim( tB ); |
|||
if( strlen(tB) ) { |
|||
if( tB[0]=='#' ) continue; |
|||
strncpy(expBuf, tB, 1024); |
|||
CArray *CA = explode( '=', expBuf ); |
|||
if( CA ) { |
|||
if( CA->size() ){ |
|||
if (strstr(CA->at(0), "ssid") != NULL) if (strstr(CA->at(0), "ignore_broadcast_ssid") == NULL){ |
|||
strncpy( tVal->SSID, CA->at(1), 64 ); |
|||
} else tVal->hiden_ssid = (bool) atoi(CA->at(1)); |
|||
if (strstr(CA->at(0), "wpa_passphrase") != NULL) strncpy( tVal->password, CA->at(1), 64 ); |
|||
if (strstr(CA->at(0), "country_code") != NULL) strncpy(tVal->country_code, CA->at(1), 3); |
|||
if (strstr(CA->at(0), "channel") != NULL) tVal->channel = atoi(CA->at(1)); |
|||
}; |
|||
delete( CA ); |
|||
}; |
|||
}; |
|||
}; |
|||
fclose( fd ); |
|||
}; |
|||
} else { |
|||
fd = fopen("/etc/wpa_supplicant/wpa_supplicant.conf", "r"); |
|||
if ( fd ) { |
|||
|
|||
fclose( fd ); |
|||
}; |
|||
}; |
|||
fd = fopen("/etc/rc.local","r"); |
|||
if ( fd ) { |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
while (!feof(fd)) { |
|||
fgets((CSTR)tB, 1024, fd); |
|||
trim((CSTR)tB); |
|||
if( strlen(tB) ) { |
|||
strncpy( expBuf, tB, 1024 ); |
|||
CArray *CA = explode( ' ', expBuf ); |
|||
if( CA ) { |
|||
if ( CA->size() ) { |
|||
if (CA->at(0)[0] == '#') continue; |
|||
if( strstr(CA->at(0), "iptables-restore")!= NULL ) { |
|||
char zB[1024]; |
|||
FILE *afd = fopen( CA->at(2), "r" ); |
|||
if ( afd ) { |
|||
while( !feof( afd ) ){ |
|||
fgets((CSTR)zB, 1024, afd ); |
|||
if( strstr( zB, "POSTROUTING" )!= NULL ) if( strstr( zB, "MASQUERADE" )!= NULL ) if( strstr( zB, if_name )== NULL ){ |
|||
CArray *CB = explode( ' ', zB ); |
|||
if ( CB ) { |
|||
if ( CB->size() > 3 ) { |
|||
strncpy(tVal->router_outbond, CB->at(3), INET6_ADDRSTRLEN); |
|||
}; |
|||
delete( CB ); |
|||
}; |
|||
tVal->router_enabled = true; |
|||
}; |
|||
}; |
|||
fclose(afd); |
|||
} else LOG("Error Opening Firewall Rules!"); |
|||
}; |
|||
}; |
|||
delete( CA ); |
|||
}; |
|||
}; |
|||
}; |
|||
fclose(fd); |
|||
} else LOG_ERROR("Can not open rc.local!"); |
|||
}; |
|||
#ifdef DEBUG
|
|||
if ( tVal ) { |
|||
if (tVal->access_point) LOG("AP Mode"); else LOG("WiFi Mode"); |
|||
LOG(tVal->SSID); |
|||
if (tVal->hiden_ssid) LOG("SSID is hidden"); |
|||
LOG(tVal->password); |
|||
if (tVal->dhcp_enabled){ |
|||
LOG("DHCP Service"); |
|||
LOG(tVal->range_start); |
|||
LOG(tVal->range_stop); |
|||
LOG(tVal->lease_period); |
|||
} else LOG("DHCP Disabled"); |
|||
if (tVal->router_enabled){ |
|||
LOG("Routing Enabled"); |
|||
LOG( tVal->router_outbond ); |
|||
} else LOG("Routing Disabled"); |
|||
}; |
|||
#endif
|
|||
return tVal; |
|||
}; |
|||
|
|||
void mojoHardwareManager::enumerateNIFS( void ){ |
|||
struct ifaddrs * ifaddr = NULL; |
|||
char tBuffer[128]; |
|||
|
|||
//if( m_pKernel == NULL ) return;
|
|||
if( m_pDBC == NULL ) return; |
|||
|
|||
if( -1 == getifaddrs(&ifaddr)) { |
|||
LOG_ERROR("No NET INTERFACES?!"); |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Enumerating Network Interfaces"); |
|||
#endif
|
|||
struct ifaddrs * ifa; |
|||
|
|||
for( ifa = ifaddr; ifa; ifa = ifa->ifa_next ){ |
|||
char addr[INET6_ADDRSTRLEN]; |
|||
char mask[INET6_ADDRSTRLEN]; |
|||
char gw[INET6_ADDRSTRLEN]; |
|||
char bc[INET6_ADDRSTRLEN]; |
|||
char mac[INET6_ADDRSTRLEN]; |
|||
char device[INET6_ADDRSTRLEN]; |
|||
|
|||
uint32_t nif_id = 0; |
|||
uint32_t nif_aux_id = 0; |
|||
uint32_t router_id = 0; |
|||
ARGUS_NIF_TYPE nif_type = NIF_LOOPBACK; |
|||
ARGUS_NETWORK_TYPE net_type = NETWORK_IPV4; |
|||
ARGUS_RESOURCE_TYPE res_type = ARGUS_HARDWARE_NIF_LOOPBACK; |
|||
ARGUS_NIF_MODE nif_mode = ADDRESS_DISABLED; |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("NIF ***"); |
|||
#endif
|
|||
strncpy( device, ifa->ifa_name, INET6_ADDRSTRLEN ); |
|||
strncpy( mac,"--no-mac--", INET6_ADDRSTRLEN ); |
|||
// Filter Loopback if
|
|||
if( strstr( device, "lo" ) != NULL ){ |
|||
nif_type = NIF_LOOPBACK; |
|||
res_type = ARGUS_HARDWARE_NIF_LOOPBACK; |
|||
//Not Implemented
|
|||
continue; |
|||
}; |
|||
// Filter vpn TUN if
|
|||
if( strstr( device, "tun" ) != NULL ){ |
|||
nif_type = NIF_VPN_TUNEL; |
|||
res_type = ARGUS_HARDWARE_NIF_TUNEL; |
|||
//Not Implemented Yet
|
|||
continue; |
|||
}; |
|||
if( strstr( device, "eth" ) != NULL ){ |
|||
LOG(device); |
|||
nif_type = NIF_ETHERNET; |
|||
res_type = ARGUS_HARDWARE_NIF_ETHERNET; |
|||
}; |
|||
if( strstr( device, "wlan" ) != NULL ){ |
|||
LOG(device); |
|||
nif_type = NIF_WIFI; |
|||
res_type = ARGUS_HARDWARE_NIF_WIFI; |
|||
}; |
|||
if( strstr( device, "wwan" ) != NULL ){ |
|||
LOG(device); |
|||
nif_type = NIF_WAN; |
|||
res_type = ARGUS_HARDWARE_NIF_WAN; |
|||
}; |
|||
if( ifa->ifa_addr != NULL ){ |
|||
if (ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family != AF_INET6) { |
|||
LOG("CONT"); |
|||
continue; |
|||
} |
|||
} else { |
|||
LOG("ifa->ifa_addr is NULL"); |
|||
continue; |
|||
}; |
|||
LOG("GETMAC"); |
|||
getMAC( device, mac ); |
|||
getGW( device, gw ); |
|||
LOG( mac ); |
|||
LOG( gw ); |
|||
PARSE_RESULT_NET_INTERFACES * tt = NULL; |
|||
PARSE_RESULT_WIFI_SETTINGS * tw = NULL; |
|||
tt = parse_neconfig( device ); |
|||
tw = parse_wifi( device ); |
|||
if( tt ) { |
|||
if ( tt->enabled ) { |
|||
if( tt->if_static ){ |
|||
nif_mode = ADDRESS_STATIC; |
|||
} else { |
|||
nif_mode = ADDRESS_DYNAMIC; |
|||
}; |
|||
} else { |
|||
nif_mode = ADDRESS_DISABLED; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Error Parsing System NIF Settings!"); |
|||
continue; |
|||
}; |
|||
if ( tw ){ |
|||
if( nif_mode == ADDRESS_STATIC ) { |
|||
if (tw->dhcp_enabled) { |
|||
nif_mode = ADDRESS_STATIC_RAP; |
|||
}; |
|||
}; |
|||
if ( nif_type == NIF_WIFI ){ |
|||
nif_id = m_pDBC->addLocalNIF( device, mac, nif_type, nif_mode ); |
|||
if( nif_id == 0 ) continue; |
|||
ARGUS_WIFI_MODE w_mode; |
|||
if( !tt->enabled ) { |
|||
w_mode = WIFI_DISABLED; |
|||
} else { |
|||
if (tt->if_static) { |
|||
if( tw->access_point ) { |
|||
w_mode = WIFI_IS_AP; |
|||
uint32_t outbond_id = 0; |
|||
if( tw->router_enabled ){ |
|||
outbond_id = m_pDBC->getNIF_IDbyDevice( tw->router_outbond ); |
|||
}; |
|||
if( tw->dhcp_enabled ) { |
|||
router_id = m_pDBC->addLocalNetworkInfrastructure(nif_id, outbond_id, true, tw->range_start, tw->range_stop, tw->netmask, tw->lease_period ); |
|||
} else { |
|||
router_id = m_pDBC->addLocalNetworkInfrastructure(nif_id, outbond_id ); |
|||
}; |
|||
} else { |
|||
w_mode = WIFI_CONNECTED_TO_AP; |
|||
}; |
|||
}; |
|||
}; |
|||
nif_aux_id = m_pDBC->addLocalWiFi(nif_id, w_mode, tw->SSID, tw->password, ENCRIPTION_WPA_PSK, router_id ); |
|||
}; |
|||
if( nif_type == NIF_ETHERNET || nif_type == NIF_ETHERNET_VIRTUAL ){ |
|||
|
|||
}; |
|||
free(tt); |
|||
free(tw); |
|||
} else { |
|||
LOG_ERROR("Error Parsing System Router/AP Settings!"); |
|||
free(tt); |
|||
continue; |
|||
}; |
|||
nif_id = m_pDBC->addLocalNIF( device, mac, nif_type, nif_mode, nif_aux_id ); |
|||
if( nif_id == 0 ) continue; |
|||
|
|||
LOG("NIF added!"); |
|||
m_pDBC->addResource( 1, res_type, device, nif_id ); |
|||
if(ifa->ifa_addr->sa_family == AF_INET){ |
|||
net_type = NETWORK_IPV4; |
|||
// create IPv4 string
|
|||
struct sockaddr_in *in = (struct sockaddr_in*) ifa->ifa_addr; |
|||
inet_ntop(AF_INET, &in->sin_addr, addr, sizeof(addr)); |
|||
sprintf( mask, "%d.%d.%d.%d", |
|||
(uint8_t)ifa->ifa_netmask->sa_data[2], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[3], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[4], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[5] |
|||
); |
|||
sprintf( bc, "%d.%d.%d.%d", |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[2], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[3], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[4], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[5] |
|||
); |
|||
} else { // AF_INET6
|
|||
net_type = NETWORK_IPV6; |
|||
// create IPv6 string
|
|||
struct sockaddr_in6 *in6 = (struct sockaddr_in6*) ifa->ifa_addr; |
|||
inet_ntop(AF_INET6, &in6->sin6_addr, addr, sizeof(addr)); |
|||
sprintf( mask, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", |
|||
(uint8_t)ifa->ifa_netmask->sa_data[2], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[3], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[4], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[5], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[6], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[7], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[8], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[9], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[10], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[11], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[12], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[13], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[14], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[15], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[16], |
|||
(uint8_t)ifa->ifa_netmask->sa_data[17] |
|||
); |
|||
if( ifa->ifa_ifu.ifu_broadaddr != NULL ){ |
|||
sprintf( bc, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[2], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[3], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[4], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[5], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[6], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[7], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[8], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[9], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[10], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[11], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[12], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[13], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[14], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[15], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[16], |
|||
(uint8_t)ifa->ifa_ifu.ifu_broadaddr->sa_data[17] |
|||
); |
|||
} else { |
|||
sprintf( bc, "" ); |
|||
}; |
|||
}; |
|||
m_pDBC->addLocalNetwork( nif_id, net_type, addr, mask, gw, bc ); |
|||
#ifdef DEBUG
|
|||
sprintf( tBuffer, "Detected Network Interface: %s [%s]", ifa->ifa_name, addr ); |
|||
LOG(tBuffer); |
|||
#endif
|
|||
}; |
|||
freeifaddrs( ifaddr ); |
|||
}; |
|||
}; |
|||
|
|||
void mojoHardwareManager::enumerateHardware( void ){ |
|||
char tBuffer[CTEXT]; |
|||
DIR * dFD = NULL; |
|||
struct dirent * pDR = NULL; |
|||
|
|||
//ToDo: Check Ability to work without Kernel and DBC
|
|||
//if( m_pKernel == NULL ) return;
|
|||
if( m_pDBC == NULL ) return; |
|||
#ifdef DEBUG
|
|||
LOG("HW Enumeration Started!"); |
|||
#endif
|
|||
// Moved to a constructor!!
|
|||
//m_nServerNodeID = m_pKernel->getServerNodeId();
|
|||
//m_nServerID = m_pKernel->getServerId();
|
|||
//m_nSiteID = m_pKernel->getSiteId();
|
|||
/* Add Network Interfaces */ |
|||
|
|||
m_pDBC->cleanResources( 1, true ); |
|||
|
|||
enumerateNIFS(); |
|||
/* Check HID Devices */ |
|||
|
|||
struct hid_device_info * pDevs; |
|||
uint8_t DCBCount; |
|||
//Enumerate USB devices with the given IDs
|
|||
pDevs = hid_enumerate( 0x16c0, 0x05df ); |
|||
if( pDevs!=NULL ){ |
|||
struct hid_device_info * pCDev = pDevs; |
|||
//Count the number of returned devices
|
|||
for( DCBCount = 0; pCDev!=NULL; DCBCount++ ) pCDev = pCDev->next; |
|||
//Allocate a buffer for the relays
|
|||
if( DCBCount > 0 ){ |
|||
DC_BOARD tDCB; |
|||
//Fill the relay structs
|
|||
pCDev = pDevs; |
|||
for( int idx = 0; idx < DCBCount; idx++ ){ |
|||
//Save the path to this device
|
|||
memset( tDCB.path, 0, MAX_PATH_LEN ); |
|||
strncpy( tDCB.path, pCDev->path, MAX_PATH_LEN ); |
|||
// The product string is USBRelayx where x is number of relays read to the \0 in case there are more than 9
|
|||
tDCB.relay_count = atoi((const char *)&pCDev->product_string[8]); |
|||
//Open it to get more details
|
|||
hid_device * handle; |
|||
handle = hid_open_path( tDCB.path ); |
|||
if( handle ){ |
|||
unsigned char buf[9]; |
|||
//Get the features of the device
|
|||
buf[0] = 0x01; |
|||
if( hid_get_feature_report( handle, buf, sizeof(buf)) == -1 ){ |
|||
LOG_ERROR("hid_get_feature_report"); |
|||
pCDev = pCDev->next; |
|||
hid_close( handle ); |
|||
continue; |
|||
}; |
|||
//Set the serial number (0x0 for termination)
|
|||
memset( tDCB.serial, 0x0, (HID_DCR_SERIIAL_LENGTH+1) ); |
|||
memcpy( tDCB.serial, buf, HID_DCR_SERIIAL_LENGTH ); |
|||
//Byte 7 in the response contains the target_state of the relays
|
|||
tDCB.state = buf[7]; |
|||
hid_close( handle ); |
|||
#ifdef DEBUG
|
|||
//Output the device enumeration details if verbose is on
|
|||
LOG("HID DCB Found"); |
|||
sprintf(tBuffer, " Type: %04hx::%04hx", pCDev->vendor_id, pCDev->product_id); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Path: %s", pCDev->path ); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Serial_number: %ls", pCDev->serial_number ); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Manufacturer: %ls", pCDev->manufacturer_string); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Product: %ls", pCDev->product_string); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Release: %hx", pCDev->release_number); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Interface: %d", pCDev->interface_number); |
|||
LOG(tBuffer); |
|||
sprintf(tBuffer, " Number of Relays = %d", tDCB.relay_count); |
|||
LOG(tBuffer); |
|||
//If debug are on, output individual relay details
|
|||
for( int k = 0; k < tDCB.relay_count; k++ ){ |
|||
if( tDCB.state & 1 << k ){ |
|||
sprintf(tBuffer, " %s_%d=1", tDCB.serial, k + 1); |
|||
} else { |
|||
sprintf(tBuffer, " %s_%d=0", tDCB.serial, k + 1); |
|||
}; |
|||
LOG(tBuffer); |
|||
}; |
|||
#endif
|
|||
m_pDBC->addLocalDCB( 1, pCDev->path, tDCB.serial, tDCB.relay_count, tDCB.state ); |
|||
} else { |
|||
LOG_ERROR("unable to open HID device"); |
|||
}; |
|||
pCDev = pCDev->next; |
|||
}; |
|||
}; |
|||
hid_free_enumeration( pDevs ); |
|||
}; |
|||
|
|||
/* Add devices from DEV */ |
|||
dFD = opendir("/dev"); |
|||
if( dFD != NULL ) { |
|||
while( ( pDR = readdir( dFD ))!= NULL ){ |
|||
if( strcasestr( pDR->d_name, "video" ) == pDR->d_name ) { |
|||
createResourceVIDEO( pDR->d_name ); |
|||
continue; |
|||
}; |
|||
if( strcasestr( pDR->d_name, "ttyS" ) == pDR->d_name ){ |
|||
createResourceUART( pDR->d_name ); |
|||
continue; |
|||
}; |
|||
// RaspberyPI Hardware
|
|||
if( strcasestr( pDR->d_name, "ttyAMA" ) == pDR->d_name ){ |
|||
createResourceUART( pDR->d_name ); |
|||
continue; |
|||
}; |
|||
if( strcasestr( pDR->d_name, "ttyUSB" ) == pDR->d_name ){ |
|||
createResourceUART( pDR->d_name ); |
|||
continue; |
|||
}; |
|||
}; |
|||
closedir( dFD ); |
|||
}; |
|||
//m_bHardwareEnumerated = true;
|
|||
}; |
|||
|
|||
uint32_t mojoHardwareManager::createResourceUART( CSTR devName ){ |
|||
uint32_t RetVal = 0; |
|||
char tBuffer[256]; |
|||
/* Enumerate BuiltIn Serial */ |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tBuffer, "Serial Device: %s", devName ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
char dev_name[CTEXT]; |
|||
int fd = -1; |
|||
struct serial_struct ss; |
|||
sprintf( dev_name, "/dev/%s", devName ); |
|||
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 ); |
|||
} else { |
|||
|
|||
if ( 0 && ( -1 == xioctl(fd, TIOCGSERIAL, &ss) )){ |
|||
LOG_ERROR("TIOCGSERIAL"); |
|||
} else { |
|||
#ifdef DEBUG_EXTRA
|
|||
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 ); |
|||
#endif
|
|||
getTTyDesc( devName, tBuffer ); |
|||
uint32_t tID = m_pDBC->addLocalUART( 1, 1, 19200, 8, 'N', 1.0f, dev_name ); |
|||
if ( tID ) { |
|||
m_pDBC->addResource( 1, ARGUS_HARDWARE_UART, tBuffer, tID ); |
|||
}; |
|||
}; |
|||
close(fd); |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
uint32_t mojoHardwareManager::createResourceVIDEO( CSTR devName ){ |
|||
uint32_t RetVal = 0; |
|||
char tBuffer[256]; |
|||
/* Enumerate Video Capture */ |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tBuffer, "Video Source: %s", devName ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
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", devName ); |
|||
|
|||
if (-1 == stat( dev_name, &st )) { |
|||
sprintf( tBuffer, "Cannot identify '%s': %d, %s\\n", dev_name, errno, strerror(errno)); |
|||
LOG_ERROR( tBuffer ); |
|||
return 0; |
|||
}; |
|||
if (!S_ISCHR(st.st_mode)) { |
|||
sprintf( tBuffer, "%s is no devicen", dev_name); |
|||
LOG_ERROR( tBuffer ); |
|||
return 0; |
|||
}; |
|||
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 ); |
|||
} 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); |
|||
return 0; |
|||
}; |
|||
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf(tBuffer, "%s is no video capture device", dev_name); |
|||
LOG_ERROR( tBuffer ); |
|||
#endif
|
|||
close(fd); |
|||
return 0; |
|||
}; |
|||
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 { |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tBuffer, "Grabber[%dx%d]",fmt.fmt.pix.width,fmt.fmt.pix.height); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
uint64_t mid = m_pDBC->addLocalMediaSource( 1, dev_name, fmt.fmt.pix.width, fmt.fmt.pix.height ); |
|||
//m_pDBC->addNodeSocket( m_nServerNodeID, mid, ARGUS_NODE_SOCK_TYPE_ANALOG_VIDEO_GRABBER, ARGUS_NODE_SOCK_MODE_OUT, false, dev_name, tBuffer );
|
|||
RetVal = m_pDBC->addResource( 1, ARGUS_HARDWARE_ANALOG_VIDEO_IN, dev_name, mid ); |
|||
}; |
|||
close(fd); |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
uint32_t mojoHardwareManager::createResourceUDCB( CSTR devName ){ |
|||
uint32_t RetVal = 0; |
|||
char tBuffer[256]; |
|||
return RetVal; |
|||
}; |
|||
/*
|
|||
killWifi(){ |
|||
ifconfig wlan0 down |
|||
ifconfig wlan0 up |
|||
iw dev wlan0 station dump |
|||
} |
|||
*/ |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,163 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// 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 __MOJO_HARDWAREMANAGER_H_INCL__ |
|||
#define __MOJO_HARDWAREMANAGER_H_INCL__ |
|||
|
|||
#include <stdio.h> |
|||
#include <fcntl.h> |
|||
#include <unistd.h> |
|||
#include <errno.h> |
|||
#include <string.h> |
|||
#include <sys/mman.h> |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include <sys/resource.h> |
|||
#include <hidapi/hidapi.h> |
|||
#include <ifaddrs.h> |
|||
|
|||
#include "../../components/base/basicLogCollection.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../alg/lgs/detectorStructures.h" |
|||
#include "../../alg/generic/heapDebug.h" |
|||
#include "../../rgoose/rgooseTypes.h" |
|||
#include "mojoDBConnector.h" |
|||
|
|||
|
|||
#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" |
|||
|
|||
#define DBC_RESOURCE_DESC_SIZE 64 |
|||
|
|||
|
|||
typedef struct S_PARSE_RESULT_NET_INTERFACES{ |
|||
bool enabled; |
|||
bool if_static; |
|||
bool hot_plug; |
|||
char address[INET6_ADDRSTRLEN]; |
|||
char netmask[INET6_ADDRSTRLEN]; |
|||
char gateway[INET6_ADDRSTRLEN]; |
|||
}PARSE_RESULT_NET_INTERFACES; |
|||
|
|||
typedef struct S_PARSE_RESULT_WIFI_SETTINGS{ |
|||
char SSID[64]; |
|||
char password[64]; |
|||
ARGUS_WIFI_ENCRIPTION encryption; |
|||
bool access_point; |
|||
uint8_t channel; |
|||
char country_code[3]; |
|||
bool hiden_ssid; |
|||
/* Router Settings */ |
|||
bool router_enabled; |
|||
char router_outbond[INET6_ADDRSTRLEN]; |
|||
/* DHCP */ |
|||
bool dhcp_enabled; |
|||
char range_start[INET6_ADDRSTRLEN]; |
|||
char range_stop[INET6_ADDRSTRLEN]; |
|||
char netmask[INET6_ADDRSTRLEN]; |
|||
char lease_period[INET6_ADDRSTRLEN]; |
|||
}PARSE_RESULT_WIFI_SETTINGS; |
|||
|
|||
|
|||
/** |
|||
* Class to talk with Hardware via MemMap |
|||
* |
|||
* @author gagua |
|||
*/ |
|||
class mojoHardwareManager { |
|||
private: |
|||
/* General System Variables*/ |
|||
|
|||
basicLogCollection * m_pLog; |
|||
config_setting_t * m_pSettings; |
|||
basicSettingsProvider * m_pSettingsProvider; |
|||
uint32_t m_nMemoryLimitHeapSize; |
|||
mojoDBC * m_pDBC; |
|||
bool m_bInitOK; |
|||
|
|||
uint32_t createResourceUART( CSTR devName ); |
|||
uint32_t createResourceVIDEO( CSTR devName ); |
|||
uint32_t createResourceUDCB( CSTR devName ); |
|||
uint32_t createResourceNETWORK( CSTR devName ); |
|||
void enumerateNIFS( void ); |
|||
void getMAC( CSTR if_name, CSTR buf ); |
|||
void getGW( CSTR if_name, CSTR buf ); |
|||
void getTTyDesc( CSTR dev_name, CSTR buf ); |
|||
/* Linux System Parsers */ |
|||
PARSE_RESULT_NET_INTERFACES * parse_neconfig( CSTR if_name ); |
|||
PARSE_RESULT_WIFI_SETTINGS * parse_wifi( CSTR if_name ); |
|||
protected: |
|||
static mojoHardwareManager * _instance; |
|||
// Constructor |
|||
explicit mojoHardwareManager( config_setting_t *SNode ); |
|||
public: |
|||
static mojoHardwareManager * getInstance( config_setting_t *SNode = NULL ); |
|||
// Destructor |
|||
virtual ~mojoHardwareManager(); |
|||
void enumerateHardware( void ); |
|||
bool validate(); |
|||
}; |
|||
|
|||
#endif // __LRF_HARDWAREMANAGER_H_INCL__ |
|||
@ -0,0 +1,390 @@ |
|||
//----------------------------------------------------------------------------
|
|||
// Dr.Frucht Systems Ltd.
|
|||
// Copyright © 2000-2022. All Rights Reserved.
|
|||
// Version 1.0 11/19/2022
|
|||
// Last modification: 11/19/2022
|
|||
// PROJECT:
|
|||
// SUBSYSTEM:
|
|||
// FILE: mojoKernel.cpp
|
|||
// AUTHOR: gagua
|
|||
// OVERVIEW
|
|||
// ~~~~~~~~
|
|||
// LRF_Kernel.cpp
|
|||
//----------------------------------------------------------------------------
|
|||
//
|
|||
|
|||
#include "mojoKernel.h"
|
|||
#include "../data/json/json_tool.h"
|
|||
#include <strings.h>
|
|||
#include <json/value.h>
|
|||
#include <json/writer.h>
|
|||
#include <json/reader.h>
|
|||
|
|||
#include "../common/kernelEventFilterAPF.h"
|
|||
|
|||
|
|||
#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", 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 );\ |
|||
kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
mojoKernel *mojoKernel::_instance = NULL; |
|||
|
|||
mojoKernel *mojoKernel::getInstance( config_setting_t *ptr ){ |
|||
if ( _instance == NULL ) { |
|||
_instance = new mojoKernel( ptr ); |
|||
}; |
|||
return _instance; |
|||
}; |
|||
|
|||
mojoKernel::mojoKernel( config_setting_t *ptr ):kernelPrototype( ptr ){ |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
memset( &m_sSysInfo, 0, sizeof( DBC_SYS_LOAD_INFO )); |
|||
m_pShadow = NULL; |
|||
m_pSystemAnchor = NULL; |
|||
setWM( WM_NONE ); |
|||
}; |
|||
|
|||
|
|||
mojoKernel::~mojoKernel(){ |
|||
WaitFinish( true ); |
|||
#ifdef DEBUG
|
|||
LOG(" Deleting Node Factory..."); |
|||
#endif
|
|||
//if( m_pNodeFactory != NULL ) delete( m_pNodeFactory );
|
|||
#ifdef DEBUG
|
|||
LOG(" Deleting Module Factory..."); |
|||
#endif
|
|||
if( m_pModuleFactory != NULL ) delete( m_pModuleFactory ); |
|||
#ifdef DEBUG
|
|||
LOG(" Deleting Target Filters..."); |
|||
#endif
|
|||
unloadFilters(); |
|||
|
|||
if( EXIT_CODE_KERNEL_CLEAR == getExitCause() ) { |
|||
#ifdef DEBUG
|
|||
LOG("Unregister Server"); |
|||
#endif
|
|||
m_pDBC->unregisterServer(); |
|||
#ifdef DEBUG
|
|||
//LOG("Close DataBase Connection...");
|
|||
#endif
|
|||
//if( m_pDBC != NULL ) delete( m_pDBC );//Deleting in Backend
|
|||
//m_pDBC = NULL;
|
|||
} else { |
|||
if( EXIT_CODE_DETECT_HARDWARE == getExitCause() ) { |
|||
#ifdef DEBUG
|
|||
LOG("HW PNP Detection Requested..."); |
|||
#endif
|
|||
//m_pDBC->updateNodePushedCMD( tCMD->id, 30 );
|
|||
m_pHardwareManager->enumerateHardware(); |
|||
//m_pDBC->updateNodePushedCMD( tCMD->id, 60 );
|
|||
}; |
|||
#ifdef DEBUG
|
|||
//LOG("Close DataBase Connection...");
|
|||
#endif
|
|||
//if( m_pDBC != NULL ) delete( m_pDBC );
|
|||
//m_pDBC = NULL;
|
|||
}; |
|||
delete( m_pHardwareManager ); |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
bool mojoKernel::create(){ |
|||
if( m_pSettings != NULL ) { |
|||
config_setting_t * pSetting; |
|||
int tVal; |
|||
const char * tBuf; |
|||
char tBuffer[128]; |
|||
LOG("Getting Settings ..."); |
|||
if( !config_setting_lookup_string( m_pSettings, MOJO_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, MOJO_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, MOJO_KERNEL_TAG_SITE_ID, &tVal ) ){ |
|||
tVal = m_nInstanceID = 1; |
|||
pSetting = config_setting_add( m_pSettings, MOJO_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_nInstanceID = tVal; |
|||
sprintf( tBuffer, "App Instance ID Read From Settings: %d", m_nInstanceID ); |
|||
LOG( tBuffer ); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Failed Read Config Settings!"); |
|||
return false; |
|||
}; |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
|
|||
LOG("Register Server ... "); |
|||
m_pDBC->registerServer( m_nInstanceID, m_sIdentity, getpid(), &m_nServerID, &m_nServerNodeID ); |
|||
char tBuffer[128]; |
|||
sprintf( tBuffer,"Server Registered as [%d] nodeID[%d]",m_nServerID, m_nServerNodeID ); |
|||
LOG( tBuffer ); |
|||
|
|||
DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( m_nInstanceID ); |
|||
|
|||
if( tSiteData ) { |
|||
C3D_WGS84_LOC t; |
|||
t.lat = tSiteData->lat; |
|||
t.lon = tSiteData->lon; |
|||
t.alt = tSiteData->alt; |
|||
m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t, tSiteData->local_binding ); |
|||
free( tSiteData ); |
|||
} else { |
|||
LOG_ERROR("Error Loading Site DATA!"); |
|||
C3D_WGS84_LOC t; |
|||
t.lat = 0; |
|||
t.lon = 0; |
|||
t.alt = 0; |
|||
m_pSystemAnchor = systemAnchor::getInstance( false, &t, true ); |
|||
}; |
|||
|
|||
m_pHardwareManager = hardwareManager::getInstance(); |
|||
|
|||
loadFilters(); |
|||
|
|||
m_pModuleFactory = kernelModuleFactory::getInstance( m_nInstanceID ); |
|||
if( !m_pModuleFactory ) { |
|||
LOG_ERROR("Module Factory Failure!"); |
|||
return false; |
|||
}; |
|||
//Autoloading Modules
|
|||
//if( !m_pModuleFactory->loadModules() ){
|
|||
// LOG_ERROR("Modules Loading Failure!");
|
|||
// return false;
|
|||
//};
|
|||
m_pNodeFactory = deviceNodeFactory::getInstance(); |
|||
if( !m_pNodeFactory ){ |
|||
LOG_ERROR("Node Factory Failure!"); |
|||
return false; |
|||
}; |
|||
return init(); |
|||
}; |
|||
|
|||
void mojoKernel::m_fThreadProc( void ){ |
|||
time_t tTimeTSeconds = 0; |
|||
m_bThreadStatus = TH_WORKING; |
|||
while ( m_bThreadStatus < TH_ENDED ) { |
|||
m_tTimeTSeconds = time( NULL ); |
|||
//Each Second
|
|||
if( m_tTimeTSeconds != tTimeTSeconds ){ |
|||
tTimeTSeconds = m_tTimeTSeconds; |
|||
|
|||
m_pHardwareManager->updateSysInfo( &m_sSysInfo ); |
|||
|
|||
DBC_PUSHED_CMD * tCMD = m_pDBC->getNodePushedCMD( m_nServerNodeID ); //Kernel
|
|||
if( tCMD != NULL ) { |
|||
m_pDBC->updateNodePushedCMD( tCMD->id, DBC_CMD_STARTED ); |
|||
switch( tCMD->CMD ){ |
|||
case CMD_KRNL_RELOAD:{ |
|||
LOG("Reload Mojo Node!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
setExitCause( EXIT_CODE_RELOAD_SERVICES ); |
|||
break; |
|||
}; |
|||
case CMD_KRNL_RESTART:{ |
|||
LOG("Restart Mojo Node!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
setExitCause( EXIT_CODE_KERNEL_CLEAR ); |
|||
break; |
|||
}; |
|||
case CMD_KRNL_FACTORY_RESET:{ |
|||
LOG("Restart Mojo -> Factory Reset!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
setExitCause( EXIT_CODE_FACTORY_RESET ); |
|||
break; |
|||
}; |
|||
case CMD_NODES_RELOAD:{ |
|||
//if( m_pNodeFactory != NULL ) {
|
|||
// m_pNodeFactory->reloadNodes( m_nSiteID );
|
|||
//};
|
|||
break; |
|||
}; |
|||
case CMD_NODE_RELOAD:{ |
|||
uint32_t tNodeID = atoi( tCMD->PARAM ); |
|||
//if( m_pNodeFactory != NULL ) {
|
|||
// m_pNodeFactory->reloadNode( tNodeID );
|
|||
//};
|
|||
break; |
|||
}; |
|||
case CMD_KRNL_PNP:{ |
|||
if( m_pHardwareManager!= NULL ) { |
|||
LOG_ERROR( "Restart and Detect HardWare!" ); |
|||
// Must be shutdowned all service that uses hardware prior to detection!
|
|||
// m_pHardwareManager->enumerateHardware();
|
|||
m_bThreadStatus = TH_ENDED; |
|||
setExitCause( EXIT_CODE_DETECT_HARDWARE ); // Go -> Detect Hardware in BACKEND
|
|||
}; |
|||
break; |
|||
}; |
|||
case CMD_KRNL_SYNC_TIME:{ |
|||
uint32_t uts = atoi( tCMD->PARAM ); |
|||
if( uts ){ |
|||
time_t ts = (time_t)uts; |
|||
if( stime( &ts ) == 0 ){ |
|||
// Restert Server;
|
|||
m_bThreadStatus = TH_ENDED; |
|||
setExitCause( EXIT_CODE_KERNEL_CLEAR ); |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case CMD_KRNL_SYSTEM_TASK:{ |
|||
/*
|
|||
try{ |
|||
Json::Value root; |
|||
JSONCPP_STRING err; |
|||
Json::CharReaderBuilder builder; |
|||
|
|||
int len = strlen( tCMD->PARAM ); |
|||
|
|||
if ( len ) { |
|||
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); |
|||
if (!reader->parse( tCMD->PARAM, tCMD->PARAM + len, &root, &err)) { |
|||
LOG_ERROR( "Error parsing the string" ); |
|||
LOG_ERROR( err.c_str() ); |
|||
} else { |
|||
if (root.size()) { |
|||
Json::Value tVal; |
|||
|
|||
tVal = root["action"]; |
|||
if (!tVal.isNull()) { |
|||
LOG( tVal.asString().c_str() ); |
|||
//SYS_COMMAND_ENUMERATOR tENUM = SYS_CMD_NONE;
|
|||
CSTR pTemp = NULL; |
|||
SYS_COMMAND_ENUMERATOR eType = SYS_CMD_NONE; |
|||
for( int i = 0; i < 4; i++ ){ |
|||
pTemp = (CSTR) strstr( tVal.asString().c_str(), SYS_COMANDS_SCRIPTS[i] ); |
|||
if( pTemp ){ |
|||
eType = (SYS_COMMAND_ENUMERATOR)i; |
|||
break; |
|||
}; |
|||
}; |
|||
if( eType != SYS_CMD_NONE ){ |
|||
switch( eType ){ |
|||
case SYS_CMD_REBOOT: { |
|||
int rv = system("./scripts/linux/reboot_system.sh"); |
|||
if( rv == -1 ) { |
|||
LOG_ERROR("Error issuing System Command!"); |
|||
} else { |
|||
m_bThreadStatus = TH_ENDED; |
|||
m_bExitCause = 0; |
|||
}; |
|||
break; |
|||
}; |
|||
case SYS_CMD_SET_STATIC:{ |
|||
tVal = root["nif_id"]; |
|||
if (!tVal.isNull()) { |
|||
LOG( tVal.asString().c_str() ); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
} catch (exception e) { |
|||
m_pDBC->updateNodePushedCMD( tCMD->id, DBC_CMD_FINISHED_ERROR ); |
|||
LOG_ERROR("EXCEPTION"); |
|||
}; |
|||
*/ |
|||
break; |
|||
}; |
|||
}; |
|||
free( tCMD ); |
|||
}; |
|||
m_pDBC->cleanNodePushedCMD(); |
|||
|
|||
}; |
|||
SLEEP(SLEEP_KERNEL_INTERVAL); |
|||
}; |
|||
}; |
|||
|
|||
void mojoKernel::loadFilters(){ |
|||
if( m_pDBC == NULL ) return; |
|||
DBC_INT_LIST *tList = m_pDBC->listFilters( m_nServerID ); |
|||
if( tList != NULL ) { |
|||
if( tList->size() > 0 ) { |
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) { |
|||
DBC_TARGET_FLITER_DATA *tData = NULL; |
|||
tData = m_pDBC->getTargetFilterData( (*idx) ); |
|||
if( tData != NULL ) { |
|||
switch( tData->type ) { |
|||
case TF_AUTHORISED_PEOPLE_FILTER: { |
|||
kernelEventFilterAPF *tFilter = new kernelEventFilterAPF( tData->aux_id ); |
|||
if( tFilter != NULL ) { |
|||
if( tFilter->initFilter() ){ |
|||
m_vTargetFilters.push_back( (kernelEventFilter*) tFilter ); |
|||
} else { |
|||
delete( tFilter ); |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
tList->clear(); |
|||
}; |
|||
delete( tList ); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("No Target Filters Assigned!"); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
void mojoKernel::unloadFilters(){ |
|||
if( m_vTargetFilters.size() > 0 ) { |
|||
#ifdef DEBUG
|
|||
LOG("Have Filters to Unload"); |
|||
#endif
|
|||
for( vectorKernelEventFilters::iterator idx = m_vTargetFilters.begin(); idx < m_vTargetFilters.end(); idx++ ){ |
|||
switch( (*idx)->getType() ) { |
|||
case TF_AUTHORISED_PEOPLE_FILTER:{ |
|||
delete( (kernelEventFilterAPF*)(*idx) ); |
|||
break; |
|||
}; |
|||
default:{ |
|||
char tBuffer[64]; |
|||
sprintf( tBuffer, "Unknown Filter: %d", (*idx)->getType() ); |
|||
LOG( tBuffer ); |
|||
}; |
|||
}; |
|||
}; |
|||
m_vTargetFilters.clear(); |
|||
LOG("Unload Filters Done!"); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("No Filters to Unload!"); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,81 @@ |
|||
//---------------------------------------------------------------------------- |
|||
// Dr.Frucht Systems Ltd. |
|||
// Copyright © 2000-2022. All Rights Reserved. |
|||
// Version 1.0 11/19/2022 |
|||
// Last modification: 11/19/2022 |
|||
// PROJECT: |
|||
// SUBSYSTEM: |
|||
// FILE: mojoKernel.h |
|||
// AUTHOR: gagua |
|||
// OVERVIEW |
|||
// ~~~~~~~~ |
|||
// Header file of mojoKernel.cpp |
|||
//---------------------------------------------------------------------------- |
|||
// |
|||
|
|||
#ifndef __MOJO_KERNEL_H_INCL__ |
|||
#define __MOJO_KERNEL_H_INCL__ |
|||
|
|||
#define LA_METRO 1 |
|||
|
|||
#include "../../components/base/basicThread.h" |
|||
#include "../../components/base/basicSettingsProvider.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../components/object/objectSystemAnchor.h" |
|||
#include "../../alg/lgs/detectorStructures.h" |
|||
#include "../../alg/lgs/detector.h" |
|||
#include "../../alg/lgs/mask.h" |
|||
#include "../../alg/generic/md5.h" |
|||
|
|||
#include "../common/kernelPrototype.h" |
|||
|
|||
#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" |
|||
|
|||
#define MOJO_KERNEL_TAG_SITE_ID "SITE_ID" |
|||
#define MOJO_KERNEL_TAG_SERVER_IDENTITY "IDENTITY" |
|||
/** |
|||
* LRF_Kernel class - manages communication between client |
|||
* handlers and PRU cores bseide of Event management. |
|||
* |
|||
* |
|||
* @author gagua |
|||
*/ |
|||
class mojoKernel: public kernelPrototype{ |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
ShadowMask * m_pShadow; |
|||
time_t m_tTimeTSeconds; |
|||
DBC_SYS_LOAD_INFO m_sSysInfo; |
|||
char m_sIdentity[128]; |
|||
uint32_t m_nInstanceID; |
|||
uint32_t m_nServerID; |
|||
uint32_t m_nServerNodeID; |
|||
systemAnchor * m_pSystemAnchor; |
|||
|
|||
#ifdef LA_METRO |
|||
|
|||
#endif |
|||
void loadFilters(); |
|||
void unloadFilters(); |
|||
static mojoKernel * _instance; |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
// Constructor |
|||
explicit mojoKernel( config_setting_t *ptr ); |
|||
public: |
|||
static mojoKernel * getInstance( config_setting_t *ptr = NULL ); |
|||
// Destructor |
|||
virtual ~mojoKernel(); |
|||
virtual bool create(); |
|||
}; |
|||
|
|||
#endif // __MOJJO_KERNEL_H_INCL__ |
|||
@ -0,0 +1,28 @@ |
|||
#include "rgooseModule.h"
|
|||
|
|||
argusKernelModule::argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param ): basicEventHandler(), basicObject(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pDBC = mojoDBC::getInstance(); |
|||
m_pKernel = mojoKernel::getInstance(); |
|||
m_eType = param; |
|||
m_nDBID = id; |
|||
m_bDetached = false; |
|||
m_bEnabled = false; |
|||
m_nDBAUXID = 0; |
|||
|
|||
// Clear Events flags
|
|||
if( m_pDBC ) { |
|||
DBC_MODULE_DATA *tData = NULL; |
|||
tData = m_pDBC->getModuleData( m_nDBID ); |
|||
if( tData ) { |
|||
m_nDBAUXID = tData->aux_id; |
|||
m_bEnabled = tData->enabled; |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
for( int i = 0; i < EVT_COUNT; i++ ) m_bEvtFlags[i] = false; |
|||
}; |
|||
|
|||
argusKernelModule::~argusKernelModule(){ |
|||
}; |
|||
|
|||
@ -0,0 +1,57 @@ |
|||
#ifndef __ARGUS_MODULE_HEADER__ |
|||
#define __ARGUS_MODULE_HEADER__ |
|||
|
|||
#include "../components/base/basicObject.h" |
|||
#include "../components/base/basicEventHandler.h" |
|||
#include "../components/base/basicLogCollection.h" |
|||
#include "mojoKernel.h" |
|||
#include "mojoDBConnector.h" |
|||
|
|||
|
|||
typedef enum E_ARGUS_MODULE_TYPE{ |
|||
ARGUS_MODULE_UNKNOWN = 0, |
|||
ARGUS_MODULE_DCBUSB = 1, |
|||
ARGUS_MODULE_KAFKA = 2, |
|||
ARGUS_MODULE_GPS = 3, |
|||
ARGUS_MODULE_NETWORK = 4, |
|||
ARGUS_MODULE_FLYHUNTER = 5, |
|||
ARGUS_MODULE_SSDP_ANONCE = 6, |
|||
ARGUS_MODULE_ONVIF_OBSERVER = 7, |
|||
ARGUS_MODULE_EMBED_VIDEO = 8, |
|||
ARGUS_MODULE_MODEM_MANAGER = 9 |
|||
}ARGUS_MODULE_TYPE; |
|||
|
|||
class argusKernel; |
|||
|
|||
class argusKernelModule: public basicEventHandler, basicObject{ |
|||
protected: |
|||
basicLogCollection * m_pLog; |
|||
mojoDBC * m_pDBC; |
|||
uint32_t m_nDBID; |
|||
uint32_t m_nDBAUXID; |
|||
mojoKernel * m_pKernel; |
|||
bool m_bEnabled; |
|||
bool m_bDetached; |
|||
bool m_bEvtFlags[EVT_COUNT]; |
|||
public: |
|||
ARGUS_MODULE_TYPE m_eType; |
|||
explicit argusKernelModule( uint32_t id, ARGUS_MODULE_TYPE param = ARGUS_MODULE_UNKNOWN ); |
|||
virtual ~argusKernelModule(); |
|||
uint32_t getId() const { return m_nDBID; }; |
|||
uint32_t getAuxId() const { return m_nDBAUXID; }; |
|||
ARGUS_MODULE_TYPE getType() const { return m_eType; }; |
|||
bool isDetached() const { return m_bDetached; }; |
|||
bool isAttached() const { return !m_bDetached; }; |
|||
bool isEnabled() const { return m_bEnabled;}; |
|||
virtual bool reloadSettings(){ return false; }; |
|||
void setAttached( bool b=true ){ m_bDetached = !b; }; |
|||
void setDetached( bool b=true ){ m_bDetached = b; }; |
|||
virtual bool startService(){ return false; }; |
|||
virtual bool stopService( bool force = false ){ return true; }; |
|||
virtual bool validate(){ return false; }; |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ){}; |
|||
}; |
|||
|
|||
|
|||
#endif |
|||
|
|||
1464
lib/App/mojo/rgooseModuleEmbedVideo - Copy.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,225 @@ |
|||
#ifndef __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#define __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
//#include "../data/media/video/videoAVLIBDestination.h" |
|||
#include "../components/base/basicMediaDestination.h" |
|||
|
|||
class argusModuleEmbedVideo; |
|||
|
|||
#define FILESTREAMBUFFERSZ 1048576 |
|||
|
|||
/* Video CODECS */ |
|||
#define VC_VPX 0 |
|||
#define VC_X264 1 |
|||
#define VC_MP4 2 |
|||
#define VC_MJPEG 3 |
|||
#define VC_FLV 4 |
|||
|
|||
/* Video FORMATS */ |
|||
#define VF_WEBM 0 |
|||
#define VF_MP4 1 |
|||
#define VF_MP3 2 |
|||
#define VF_AAC 3 |
|||
#define VF_OGG 4 |
|||
#define VF_MJPEG 5 |
|||
#define VF_FLV 6 |
|||
|
|||
/* Encoder PROFILES */ |
|||
#define VP_ULTRAFAST 0 |
|||
#define VP_VERYFAST 1 |
|||
#define VP_FAST 2 |
|||
#define VP_MEDIUM 3 |
|||
#define VP_SLOW 4 |
|||
#define VP_VERYSLOW 5 |
|||
#define VP_ULTRASLOW 6 |
|||
|
|||
#define VIDEO_OUTPUT VO_MJPEG |
|||
//#define VIDEO_OUTPUT VO_MPEG4 |
|||
//#define VIDEO_OUTPUT VO_H264 |
|||
//#define VIDEO_OUTPUT VO_FLV |
|||
|
|||
#define VIDEO_OUTPUT_WIDTH 1920 |
|||
#define VIDEO_OUTPUT_HEIGHT 1080 |
|||
#define VIDEO_OUTPUT_FPS 10 |
|||
#define VIDEO_OUTPUT_GOP 30 |
|||
|
|||
#if( LIBAVCODEC_VERSION_MAJOR < 54 ) |
|||
//#define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG |
|||
//#define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P |
|||
#else |
|||
//#if( VIDEO_OUTPUT == VO_MJPEG ) |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUVJ422P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mjpeg" |
|||
/* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_MPEG4 ) |
|||
|
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_BITRATE 100000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
//* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_H264 ) |
|||
//* / |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 100000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "matroska" |
|||
#define VIDEO_OUTPUT_CONTAINER "mkv" |
|||
/* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_FLV ) |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "flv" |
|||
#endif |
|||
*/ |
|||
#endif |
|||
|
|||
typedef struct S_buffer_data { |
|||
uint8_t * buf; |
|||
int size; |
|||
uint8_t * ptr; |
|||
size_t room; ///< size left in the buffer |
|||
} buffer_data; |
|||
|
|||
#define NR_COLORS 4 |
|||
#define AVIO_BUFFER_SIZE 4096 |
|||
#define BD_BUFFER_SIZE 1024 |
|||
|
|||
typedef struct S_STREAM_CTX{ |
|||
argusModuleEmbedVideo * ModulePtr; |
|||
uint32_t mediaStreamId; |
|||
AVFormatContext * ofmt_ctx; |
|||
|
|||
|
|||
AVIOContext * avio_ctx; |
|||
uint8_t * avio_ctx_buffer; |
|||
size_t avio_ctx_buffer_size; |
|||
buffer_data * buffer; |
|||
|
|||
|
|||
/* VIDEO */ |
|||
AVStream * video_stream; |
|||
struct SwsContext * video_sws_ctx; |
|||
AVCodecContext * video_ctx; |
|||
AVCodec * video_codec; |
|||
AVFrame * video_frame; |
|||
|
|||
/* For Encoding */ |
|||
cv::Mat * InputMat; |
|||
AVFrame * outputFrame; |
|||
|
|||
int64_t ts; |
|||
uint32_t frame_idx; |
|||
int have_video; |
|||
bool bHeaderIsReady; |
|||
uint8_t * header; |
|||
uint32_t header_size; |
|||
#ifndef _NOAUDIO_ |
|||
/* AUDIO */ |
|||
AVStream * audio_stream; |
|||
AVCodecContext * audio_ctx; |
|||
AVCodec * audio_codec; |
|||
struct SwrContext * audio_swr_ctx; |
|||
AVFrame * audio_frame; |
|||
int have_audio; |
|||
uint32_t audio_buffer_size; |
|||
float * audio_buffer_left; |
|||
float * audio_buffer_right; |
|||
uint32_t max_audio_buffer_size; |
|||
int src_sample_rate; |
|||
int src_bit_rate; |
|||
int src_nr_channels; |
|||
int dst_nb_samples; |
|||
int audio_frame_bytes; |
|||
#endif |
|||
}STREAM_CTX; |
|||
|
|||
|
|||
typedef struct S_WEB_CLIENT_CTX{ |
|||
int m_iSocketFID; |
|||
int m_iEncoderPipe[2]; |
|||
AVPacket * pkt; |
|||
|
|||
bool bValid; |
|||
|
|||
bool initDone; |
|||
bool headerIsSent; |
|||
|
|||
argusModuleEmbedVideo * ModulePtr; |
|||
STREAM_CTX * STREAM; |
|||
}WEB_CLIENT_CTX; |
|||
|
|||
|
|||
typedef struct S_WEB_HANDLER{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
WEB_CLIENT_CTX * CTX; |
|||
}WEB_HANDLER; |
|||
|
|||
typedef vector<WEB_HANDLER*> vectorHANDLERS; |
|||
typedef vector<STREAM_CTX*> vectorSTREAMS; |
|||
|
|||
class argusModuleEmbedVideo: public argusKernelModule, public basicMediaDestination, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
static void * webClientProc( void *ptr ); |
|||
//static int write_packet( void *opaque, uint8_t *buf, int buf_size ); |
|||
int m_nSocketDescriptor; |
|||
basicMutex m_mHandlersProtector; |
|||
vectorHANDLERS m_vHandlersPool; |
|||
basicMutex m_mStreamsProtector; |
|||
vectorSTREAMS m_vRegisteredStreams; |
|||
bool registerForMediaStream( uint32_t id, WEB_CLIENT_CTX *&CTX ); |
|||
bool write_header( STREAM_CTX *CTX ); |
|||
bool createStream( uint32_t id ); |
|||
bool open_client_video( STREAM_CTX *&CTX, int w, int h, int fps, int br, int codec_idx, int format_idx ); |
|||
bool open_module_video( STREAM_CTX *&CTX, int w, int h, int fps, int br, int preset_idx, int codec_idx, int format_idx ); |
|||
static int write_module_packet( void *opaque, uint8_t *buf, int buf_size ); |
|||
static int write_client_packet( void *opaque, uint8_t *buf, int buf_size ); |
|||
void encode_module_video( STREAM_CTX *CTX, AVFrame *DATA ); |
|||
void encode_client_video( STREAM_CTX *CTX, AVPacket *pkt ); |
|||
void add_video_frame( STREAM_CTX *CTX ); |
|||
void destroy( WEB_CLIENT_CTX *&ptr ); |
|||
void cleanSTREAM_CTX( STREAM_CTX *&CTX ); |
|||
uint8_t * close_stream( STREAM_CTX *CTX, int* size ); |
|||
#ifndef _NOAUDIO_ |
|||
void encode_audio( STREAM_CTX *CTX, AVFrame *DATA ); |
|||
bool alloc_audio_frame( STREAM_CTX *CTX ); |
|||
int check_sample_fmt(const AVCodec *codec, enum AVSampleFormat sample_fmt ); |
|||
void add_audio_frame( STREAM_CTX *CTX, float* left, float* right, int size ); |
|||
bool open_audio( STREAM_CTX *&CTX, int sample_rate, int nr_channels, int bit_rate, int codec_idx ); |
|||
#endif |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleEmbedVideo( uint32_t moduleID ); |
|||
~argusModuleEmbedVideo(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
bool registerStream( MEDIA_SOURCE_DESC *ptr ); |
|||
bool unregisterStream( MEDIA_SOURCE_DESC *ptr ); |
|||
/* from Media Destination */ |
|||
virtual void pushFrame(AVFrame *Frame, void* src = NULL); |
|||
virtual void pushFrame(cv::Mat* Frame, void* src = NULL); |
|||
}; |
|||
#endif |
|||
2208
lib/App/mojo/rgooseModuleEmbedVideo.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,320 @@ |
|||
#ifndef __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#define __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
//#include "../data/media/video/videoAVLIBDestination.h" |
|||
#include "../components/base/basicMediaSource.h" |
|||
#include "../components/base/basicMediaDestination.h" |
|||
|
|||
class argusModuleEmbedVideo; |
|||
|
|||
#define FILESTREAMBUFFERSZ 1048576 |
|||
|
|||
#define EVE_ENABLE_VIDEO |
|||
|
|||
|
|||
|
|||
//#define USE_SCALING_IN |
|||
|
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
|
|||
//#define EVE_DONT_DELETE_SEGMENTS |
|||
|
|||
/* Video CODECS */ |
|||
#define VC_VPX 0 |
|||
#define VC_X264 1 |
|||
#define VC_MP4 2 |
|||
#define VC_MJPEG 3 |
|||
#define VC_FLV 4 |
|||
|
|||
/* Video FORMATS */ |
|||
#define VF_WEBM 0 |
|||
#define VF_MP4 1 |
|||
#define VF_MP3 2 |
|||
#define VF_AAC 3 |
|||
#define VF_OGG 4 |
|||
#define VF_MJPEG 5 |
|||
#define VF_FLV 6 |
|||
|
|||
/* Encoder PROFILES */ |
|||
#define VP_ULTRAFAST 0 |
|||
#define VP_VERYFAST 1 |
|||
#define VP_FAST 2 |
|||
#define VP_MEDIUM 3 |
|||
#define VP_SLOW 4 |
|||
#define VP_VERYSLOW 5 |
|||
#define VP_ULTRASLOW 6 |
|||
|
|||
#define VO_MJPEG 1 |
|||
#define VO_MPEG4 2 |
|||
#define VO_H264 3 |
|||
#define VO_H265 4 |
|||
#define VO_FLV 5 |
|||
|
|||
//#define VIDEO_OUTPUT VO_MJPEG |
|||
//#define VIDEO_OUTPUT VO_MPEG4 |
|||
#define VIDEO_OUTPUT VO_H264 |
|||
//#define VIDEO_OUTPUT VO_H265 |
|||
//#define VIDEO_OUTPUT VO_FLV |
|||
|
|||
//#define VIDEO_OUTPUT_WIDTH 640 //1920 |
|||
//#define VIDEO_OUTPUT_HEIGHT 480 //1080 |
|||
//#define VIDEO_OUTPUT_FPS 10 |
|||
//#define VIDEO_OUTPUT_GOP 15 |
|||
|
|||
#if( LIBAVCODEC_VERSION_MAJOR < 54 ) |
|||
#define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P |
|||
#else |
|||
#if VIDEO_OUTPUT == VO_MJPEG |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUVJ422P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mpeg" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "webm" |
|||
#elif VIDEO_OUTPUT == VO_MPEG4 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_H264 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_H265 |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H265 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
#elif VIDEO_OUTPUT == VO_FLV |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "flv" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "flv" |
|||
#endif |
|||
#endif |
|||
|
|||
#endif //EVE_ENABLE_VIDEO |
|||
|
|||
typedef struct S_buffer_data { |
|||
uint8_t * buf; |
|||
int size; |
|||
uint8_t * ptr; |
|||
size_t room; ///< size left in the buffer |
|||
} buffer_data; |
|||
|
|||
#define NR_COLORS 4 |
|||
#define AVIO_BUFFER_SIZE 4096 |
|||
#define BD_BUFFER_SIZE 1024 |
|||
|
|||
class streamHandler; |
|||
|
|||
typedef struct S_WEB_CLIENT_CTX{ |
|||
int m_iSocketFID; |
|||
int m_iEncoderPipe[2]; |
|||
bool bValid; |
|||
bool initDone; |
|||
bool headerIsSent; |
|||
uint32_t mediaStreamId; |
|||
streamHandler * m_pHandler; |
|||
argusModuleEmbedVideo * ModulePtr; |
|||
}WEB_CLIENT_CTX; |
|||
|
|||
|
|||
typedef struct S_WEB_HANDLER{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
WEB_CLIENT_CTX * CTX; |
|||
}WEB_HANDLER; |
|||
|
|||
typedef vector<WEB_HANDLER*> vectorHANDLERS; |
|||
|
|||
|
|||
//typedef vector<STREAM_CTX*> vectorSTREAMS; |
|||
|
|||
typedef struct S_STREAM_CAP{ |
|||
uint32_t stream_id; |
|||
uint32_t buffer_size; |
|||
uint8_t picture_buffer; |
|||
}STREAM_CAP; |
|||
|
|||
typedef struct S_VIDEO_EVT{ |
|||
uint32_t dbid; |
|||
uint32_t frame; |
|||
}VIDEO_EVT; |
|||
|
|||
typedef vector<uchar> compressedFRAME; |
|||
typedef map<uint32_t, compressedFRAME> mapSTREAMCAPS; |
|||
typedef map<uint32_t, cv::Mat> mapSTREAMMAPS; |
|||
|
|||
class argusModuleEmbedVideo; |
|||
|
|||
#define PRE_ALARM_TIME_MILSECONDS 2000 // 2 sec |
|||
#define POST_ALARM_TIME_MILSECONDS 2000 // 2 sec |
|||
#define ENCODING_SEGMENT_MILSECONDS 50000 // 50 sec |
|||
#define ENCODING_SEGMENT_LIMIT_MILSECONDS 60000 // 1 minute |
|||
//#define ENCODING_SEGMENT_LIMIT_MILSECONDS 900000 // 15 minute |
|||
|
|||
#define EVE_OUTPUT_PICTURES 1 |
|||
#define EVE_OUTPUT_VIDEO 2 |
|||
#define EVE_OUTPUT_PIC_AND_VID 3 |
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
|
|||
typedef struct S_ENCODING_BUFFER{ |
|||
int linesize[2]; |
|||
int rows; |
|||
uint8_t * data[2]; |
|||
size_t size; |
|||
}ENCODING_BUFFER; |
|||
|
|||
typedef std::queue<ENCODING_BUFFER *> Q_ENCODING_BUFFER; |
|||
|
|||
#endif |
|||
class streamHandler: |
|||
public basicMediaDestination |
|||
#ifdef EVE_ENABLE_VIDEO |
|||
, public basicThread |
|||
#endif |
|||
{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
basicMediaSource * m_pSource; |
|||
MEDIA_SOURCE_DESC m_sSourceDesc; |
|||
char m_cSourceType; |
|||
DBC_MEDIA_STREAM_DATA m_sStreamData; |
|||
basicMutex m_mProtector; |
|||
argusModuleEmbedVideo * m_pMaster; |
|||
uint8_t m_bEvtMarkerCounter; |
|||
uint8_t m_bCamMoveCounter; |
|||
MS_WORK_MODE m_eWM; |
|||
|
|||
#ifdef EVE_ENABLE_VIDEO |
|||
basicMutex m_mFrameCounterProtector; |
|||
uint32_t m_nPreAlarmFrames; |
|||
uint32_t m_nPostAlarmFrames; |
|||
uint32_t m_nGlobalFrameCounter; |
|||
uint32_t m_nVideoRegisteredDBID; |
|||
uint32_t m_nSegAFrameCounter; |
|||
uint32_t m_nSegBFrameCounter; |
|||
uint32_t m_nSegAShiftFrames; |
|||
uint32_t m_nSegBShiftFrames; |
|||
uint32_t m_nSegASkippedFrames; |
|||
uint32_t m_nSegBSkippedFrames; |
|||
uint32_t m_nSegmentLimitFrames; |
|||
uint32_t m_nHardLimitFrames; |
|||
uint8_t m_bActiveEncoderStream; |
|||
bool m_bSegAActive; |
|||
bool m_bSegADelete; |
|||
bool m_bSegBActive; |
|||
bool m_bSegBDelete; |
|||
basicMutex m_mCurrentOperationProtector; |
|||
uint8_t m_bCOP; |
|||
char m_cSegNameA[128]; |
|||
char m_cSegMD5A[33]; |
|||
char m_cSegNameB[128]; |
|||
char m_cSegMD5B[33]; |
|||
// encoding video stuff |
|||
AVCodec * m_pVideoCodec; |
|||
AVCodecContext * m_pCodecCtx; |
|||
SwsContext * m_pConvertCtx; |
|||
AVFrame * m_pAVFrame; |
|||
uint8_t * m_pOutBuffer; |
|||
// File Context 2 units |
|||
AVOutputFormat * m_pFormat; |
|||
AVFormatContext * m_pFormatCtxA; |
|||
AVFormatContext * m_pFormatCtxB; |
|||
AVStream * m_pVideoStrA; |
|||
AVStream * m_pVideoStrB; |
|||
//common output options |
|||
AVDictionary * m_pFormatOpts; |
|||
|
|||
basicMutex m_mEncodingQueueProtector; |
|||
Q_ENCODING_BUFFER m_qEncodingQueue; |
|||
|
|||
bool openSegmentA( void ); |
|||
void closeSegmentA( void ); |
|||
bool openSegmentB( void ); |
|||
void closeSegmentB( void ); |
|||
void swapActiveStreams( void ); |
|||
void closeAll(); |
|||
bool initVideoOutput(); |
|||
protected: |
|||
void m_fThreadProc( void ); |
|||
#endif //EVE_ENABLE_VIDEO |
|||
|
|||
public: |
|||
explicit streamHandler( argusModuleEmbedVideo *ptr, MS_WORK_MODE M = MS_MODE_DECODE_FRAMES ); |
|||
virtual ~streamHandler(); |
|||
bool create( uint32_t stremID ); |
|||
/* from Media Destination */ |
|||
virtual bool pushFrame( AVFrame *Frame, void* src = NULL); |
|||
//virtual void pushFrame( cv::Mat* Frame, void* src = NULL); |
|||
virtual bool pushFrame( cv::Mat &Frame, void* src = NULL); |
|||
bool triggerEvent( uint32_t &dbid, uint32_t &frame ); |
|||
bool triggerCamMove( void ); |
|||
bool validate( void ); |
|||
}; |
|||
|
|||
typedef map<uint32_t, streamHandler *> mapSTREAMHANDLERS; |
|||
|
|||
class argusModuleEmbedVideo: public argusKernelModule, /*public basicMediaDestination,*/ public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
static void * webClientProc( void *ptr ); |
|||
int m_nSocketDescriptor; |
|||
basicMutex m_mHandlersProtector; |
|||
basicMutex m_mPictureProtector; |
|||
basicMutex m_mEncodedProtector; |
|||
vectorHANDLERS m_vHandlersPool; |
|||
DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData; |
|||
mapSTREAMCAPS m_mapCAPTURES; |
|||
mapSTREAMMAPS m_mapMATS; |
|||
mapSTREAMHANDLERS m_mapHANDLERS; |
|||
uint8_t * n_pNoSignalData; |
|||
uint32_t m_nNoSignalSize; |
|||
cv::Mat m_mLogoPic; |
|||
cv::Mat m_mLogoMask; |
|||
char m_pBaseSavePath[PATH_MAX]; |
|||
bool registerForMediaStream( uint32_t id, WEB_CLIENT_CTX *&CTX ); |
|||
bool saveStreamPicture( uint32_t id ); |
|||
bool saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ); |
|||
bool generateSavePicPath( CSTR MD5, CSTR Output ); |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleEmbedVideo( uint32_t moduleID ); |
|||
~argusModuleEmbedVideo(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
/* from Media Destination * / |
|||
virtual bool pushFrame( AVFrame *Frame, void* src = NULL); |
|||
//virtual void pushFrame( cv::Mat* Frame, void* src = NULL); |
|||
virtual bool pushFrame( cv::Mat &Frame, void* src = NULL); |
|||
/* Module Specific Functionality */ |
|||
int getWidh( void ); |
|||
int getHeight( void ); |
|||
bool registerStream( uint32_t streamID ); |
|||
bool unregisterStream( uint32_t streamID ); |
|||
|
|||
friend class streamHandler; |
|||
|
|||
}; |
|||
#endif |
|||
@ -0,0 +1,386 @@ |
|||
#include "rgooseModuleFactory.h"
|
|||
#include "rgooseModuleUSBRelay.h"
|
|||
#include "rgooseModuleKafka.h"
|
|||
#include "rgooseModuleFlyHunter.h"
|
|||
#include "rgooseModuleSSDP.h"
|
|||
#include "rgooseModuleOnvifObserver.h"
|
|||
#include "rgooseModuleEmbedVideo.h"
|
|||
#include "rgooseModuleModemManager.h"
|
|||
|
|||
#ifdef MEM_DEBUG
|
|||
#include "../alg/generic/heapDebug.h"
|
|||
#endif
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MFAC", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MFAC", this, _LOG_ERROR, X )
|
|||
|
|||
argusModuleFactory * argusModuleFactory::_instance = NULL; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
argusModuleFactory* argusModuleFactory::getInstance( uint32_t ServerID ) { |
|||
if( NULL == _instance) { |
|||
if( ServerID ) { |
|||
_instance = new argusModuleFactory( ServerID ); |
|||
}; |
|||
}; |
|||
return _instance; |
|||
}; |
|||
|
|||
argusModuleFactory::argusModuleFactory( uint32_t ServerID ):basicThread(){ |
|||
m_nServerID = ServerID; |
|||
m_bInitialValidatioonDone = false; |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pDBC = mojoDBC::getInstance(); |
|||
init(); |
|||
}; |
|||
|
|||
argusModuleFactory::~argusModuleFactory(){ |
|||
waitThreadEnd( true ); |
|||
shutdownServices( true ); |
|||
_instance = NULL; |
|||
}; |
|||
|
|||
void argusModuleFactory::shutdownServices( bool force ){ |
|||
#ifdef DEBUG
|
|||
LOG("shutdownServices"); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() > 0 ){ |
|||
for( vectorKernelModules::iterator index = m_vKernelModules.begin(); index < m_vKernelModules.end(); index++ ){ |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
switch( (*index)->getType() ){ |
|||
case ARGUS_MODULE_DCBUSB: sprintf( tB, "Stop Service of DCUSB Module" ); break; |
|||
case ARGUS_MODULE_KAFKA: sprintf( tB, "Stop Service of KAFKA Module" ); break; |
|||
case ARGUS_MODULE_GPS: sprintf( tB, "Stop Service of GPS Module" ); break; |
|||
case ARGUS_MODULE_NETWORK: sprintf( tB, "Stop Service of Network Module" ); break; |
|||
case ARGUS_MODULE_FLYHUNTER: sprintf( tB, "Stop Service of FlyHunter Module" ); break; |
|||
case ARGUS_MODULE_SSDP_ANONCE: sprintf( tB, "Stop Service of SSDP Module" ); break; |
|||
case ARGUS_MODULE_ONVIF_OBSERVER: sprintf( tB, "Stop Service of OnVif Observer Module" ); break; |
|||
case ARGUS_MODULE_EMBED_VIDEO: sprintf( tB, "Stop Service of EmbedVideo Module" ); break; |
|||
case ARGUS_MODULE_MODEM_MANAGER: sprintf( tB, "Stop Service of Modem Manager Module" ); break; |
|||
default: sprintf( tB, "Stop Service of UNKNOWN[%d] Module", (*index)->getType() ); break; |
|||
}; |
|||
LOG( tB ); |
|||
#endif
|
|||
(*index)->stopService( force ); |
|||
#ifdef DEBUG
|
|||
LOG("Done"); |
|||
#endif
|
|||
deleteModule( (*index) ); |
|||
#ifdef DEBUG
|
|||
LOG("Module is Deleted"); |
|||
#endif
|
|||
}; |
|||
m_vKernelModules.clear(); |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("Done shutdownServices"); |
|||
#endif
|
|||
}; |
|||
|
|||
bool argusModuleFactory::loadModules( uint32_t ServerID ){ |
|||
DBC_INT_LIST *tList = NULL; |
|||
|
|||
if(m_pDBC == NULL) return false; |
|||
m_nServerID = ServerID; |
|||
tList = m_pDBC->listModules( m_nServerID ); |
|||
if( tList != NULL ) { |
|||
if( tList->size() ) { |
|||
for( DBC_INT_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) createModule( *idx ); |
|||
tList->clear(); |
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("No Modules Defined"); |
|||
} |
|||
#endif
|
|||
delete( tList ); |
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("No Modules Defined"); |
|||
} |
|||
#endif
|
|||
return true; |
|||
}; |
|||
|
|||
argusKernelModule *argusModuleFactory::createModule( int id ){ |
|||
argusKernelModule *tVal = NULL; |
|||
if( m_pDBC != NULL ){ |
|||
DBC_MODULE_DATA *tData = NULL; |
|||
|
|||
tData = m_pDBC->getModuleData( id ); |
|||
if( tData!= NULL ) { |
|||
switch( tData->type ) { |
|||
case ARGUS_MODULE_DCBUSB: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Dry Contact USB Module"); |
|||
#endif
|
|||
tVal = new argusModuleUSBRelay( tData->module_id ); |
|||
|
|||
break; |
|||
case ARGUS_MODULE_KAFKA: |
|||
#ifdef DEBUG
|
|||
LOG("Creating KAFKA Module"); |
|||
#endif
|
|||
tVal = new argusModuleKafka( tData->module_id ); |
|||
break; |
|||
case ARGUS_MODULE_FLYHUNTER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Fly Hunter Module"); |
|||
#endif
|
|||
tVal = new argusModuleFlyHunter( tData->module_id ); |
|||
break; |
|||
case ARGUS_MODULE_SSDP_ANONCE: |
|||
#ifdef DEBUG
|
|||
LOG("Creating SSDP Announcer Module"); |
|||
#endif
|
|||
tVal = new argusModuleSSDPAnnouncer( tData->module_id ); |
|||
break; |
|||
case ARGUS_MODULE_ONVIF_OBSERVER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating OnVif Observer Module"); |
|||
#endif
|
|||
if ( m_pDBC->isLocal() ) { |
|||
tVal = new argusModuleOnvifObserver(tData->module_id); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("Module is Disabled Since Remote Database!"); |
|||
#endif
|
|||
}; |
|||
break; |
|||
case ARGUS_MODULE_EMBED_VIDEO: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Embed Video Module"); |
|||
#endif
|
|||
if ( m_pDBC->isLocal() ){ |
|||
tVal = new argusModuleEmbedVideo( tData->module_id ); |
|||
#ifdef DEBUG
|
|||
} else { |
|||
LOG("Module is Disabled Since Remote Database!"); |
|||
#endif
|
|||
}; |
|||
break; |
|||
case ARGUS_MODULE_MODEM_MANAGER: |
|||
#ifdef DEBUG
|
|||
LOG("Creating Modem Manager Module"); |
|||
#endif
|
|||
tVal = new argusModuleModemManager( tData->module_id ); |
|||
break; |
|||
}; |
|||
free(tData); |
|||
} else { |
|||
LOG_ERROR("No Module Data Fetched!"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Database Object Assigned!"); |
|||
}; |
|||
if( tVal != NULL ){ |
|||
tVal->startService(); |
|||
m_mModulesProtector.lock(); |
|||
m_vKernelModules.push_back( tVal ); |
|||
m_mModulesProtector.unlock(); |
|||
}; |
|||
return tVal; |
|||
}; |
|||
|
|||
void argusModuleFactory::deleteModule( argusKernelModule *M ){ |
|||
if( M ) { |
|||
switch( M->getType() ) { |
|||
case ARGUS_MODULE_DCBUSB: delete( (argusModuleUSBRelay*) M ); break; |
|||
case ARGUS_MODULE_KAFKA: delete( (argusModuleKafka*) M ); break; |
|||
case ARGUS_MODULE_FLYHUNTER: delete( (argusModuleFlyHunter*) M ); break; |
|||
case ARGUS_MODULE_SSDP_ANONCE: delete( (argusModuleSSDPAnnouncer*) M ); break; |
|||
case ARGUS_MODULE_ONVIF_OBSERVER: delete( (argusModuleOnvifObserver*) M ); break; |
|||
case ARGUS_MODULE_EMBED_VIDEO: delete( (argusModuleEmbedVideo*) M ); break; |
|||
case ARGUS_MODULE_MODEM_MANAGER: delete( (argusModuleModemManager*) M ); break; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void argusModuleFactory::deleteModule( int id ){ |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() > id ) { |
|||
deleteModule( m_vKernelModules.at( id ) ); |
|||
m_vKernelModules.erase( m_vKernelModules.begin() + id ); |
|||
m_vKernelModules.shrink_to_fit(); |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
}; |
|||
|
|||
uint32_t argusModuleFactory::getModulesCount( ARGUS_MODULE_TYPE t ){ |
|||
uint32_t cnt = 0; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( int i=0; i < m_vKernelModules.size(); i++ ) { |
|||
if( m_vKernelModules.at(i)->getType() == t ) cnt++; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return cnt; |
|||
}; |
|||
|
|||
uint32_t argusModuleFactory::fetchModules( ARGUS_MODULE_TYPE t, argusKernelModule**&RA ){ |
|||
uint32_t cnt = getModulesCount( t ); |
|||
RA = NULL; |
|||
if( cnt > 0 ) { |
|||
RA = ( argusKernelModule** ) calloc( cnt, sizeof( argusKernelModule* ) ); |
|||
if( RA!= NULL ) { |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
uint32_t idx = 0; |
|||
for( int i=0; i < m_vKernelModules.size(); i++ ) { |
|||
if( m_vKernelModules.at(i)->getType() == t ) { |
|||
RA[idx] = m_vKernelModules.at(i); |
|||
idx++; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
} else cnt = 0; |
|||
}; |
|||
return cnt; |
|||
}; |
|||
|
|||
argusKernelModule *argusModuleFactory::getModule( uint32_t id ){ |
|||
argusKernelModule *RetVal = NULL; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ |
|||
if( (*idx)->getId() == id ) { |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return RetVal; |
|||
}; |
|||
|
|||
argusKernelModule *argusModuleFactory::getModule( ARGUS_MODULE_TYPE t, uint32_t id ){ |
|||
argusKernelModule *RetVal = NULL; |
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
for( vectorKernelModules::iterator idx = m_vKernelModules.begin(); idx < m_vKernelModules.end(); idx++ ){ |
|||
if( id ){ |
|||
if( ( (*idx)->getType() == t ) && ( (*idx)->getId() == id ) ){ |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
} else { |
|||
if( (*idx)->getType() == t ){ |
|||
RetVal = (*idx); |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool argusModuleFactory::validate( void ){ |
|||
return ( m_bThreadStatus < TH_ENDED ); |
|||
}; |
|||
|
|||
void argusModuleFactory::m_fThreadProc( void ){ |
|||
if( m_pDBC == NULL) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
} else { |
|||
DBC_INT_LIST *tList = NULL; |
|||
#ifdef MEM_DEBUG
|
|||
size_t memStart, memEnd, memDiff; |
|||
char MEM_MSG[256]; |
|||
#endif
|
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
#ifdef MEM_DEBUG
|
|||
memStart = getCurrentRSS(); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
DBC_INT_LIST tL; |
|||
for( int cm = 0; cm < m_vKernelModules.size(); cm++ ) tL.push_back( m_vKernelModules.at(cm)->getId() ); |
|||
tList = m_pDBC->listNewModules( m_nServerID, &tL ); |
|||
tL.clear(); |
|||
} else { |
|||
tList = m_pDBC->listNewModules( m_nServerID, NULL ); |
|||
}; |
|||
m_mModulesProtector.unlock(); |
|||
if( tList != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("New Modules Exists!"); |
|||
#endif
|
|||
for( int index=0; index< tList->size(); index++) createModule(tList->at(index)); |
|||
tList->clear(); |
|||
delete( tList ); |
|||
}; |
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF1: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
m_mModulesProtector.lock(); |
|||
if( m_vKernelModules.size() ) { |
|||
//Get Full List
|
|||
//tList = NULL;
|
|||
tList = m_pDBC->listModules( m_nServerID ); |
|||
if( tList != NULL ) { |
|||
int cm = 0; |
|||
while( cm < m_vKernelModules.size() ) { |
|||
//check if module removed
|
|||
bool tRemoved = true; |
|||
for( int lm = 0; lm < tList->size(); lm++ ) { |
|||
if( tList->at(lm) == m_vKernelModules.at( cm )->getId() ) { |
|||
tRemoved = false; |
|||
break; |
|||
}; |
|||
}; |
|||
if( !tRemoved ) { |
|||
// validate module
|
|||
m_vKernelModules.at( cm )->validate(); |
|||
cm++; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Delete Module!"); |
|||
#endif
|
|||
deleteModule( cm ); |
|||
}; |
|||
}; |
|||
tList->clear(); |
|||
delete( tList ); |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("All Modules Must be Deleted!"); |
|||
#endif
|
|||
while( m_vKernelModules.size() ) deleteModule( 0 ); |
|||
}; |
|||
} |
|||
#ifdef DEBUG_EXTRA
|
|||
else { |
|||
LOG("No Modules to Validate!"); |
|||
} |
|||
#endif
|
|||
; |
|||
m_mModulesProtector.unlock(); |
|||
#ifdef MEM_DEBUG
|
|||
memEnd = getCurrentRSS(); |
|||
memDiff = memEnd - memStart; |
|||
sprintf(MEM_MSG,"MEM START: %d MEM DIF2: %d", memStart, memDiff ); |
|||
LOG( MEM_MSG ); |
|||
#endif
|
|||
if( !m_bInitialValidatioonDone ) m_bInitialValidatioonDone = true; |
|||
for( int i = ( 5000 / DEFAULT_THREAD_SLEEP_TIME ); i && ( m_bThreadStatus < TH_ENDED ); i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
}; |
|||
}; |
|||
//--enable-gpl --enable-libx264 --enable-nonfree --extra-ldflags=-latomic --enable-omx --enable-omx-rpi
|
|||
//-rtsp_transport tcp
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,40 @@ |
|||
#ifndef __ARGUS_MODULE_FACTORY_HEADER__ |
|||
#define __ARGUS_MODULE_FACTORY_HEADER__ |
|||
|
|||
#include <vector> |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicMutex.h" |
|||
|
|||
typedef std::vector<argusKernelModule*> vectorKernelModules; |
|||
|
|||
class argusModuleFactory: public basicThread{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
mojoDBC * m_pDBC; |
|||
uint32_t m_nServerID; |
|||
vectorKernelModules m_vKernelModules; |
|||
basicMutex m_mModulesProtector; |
|||
bool m_bInitialValidatioonDone; |
|||
void deleteModule( argusKernelModule * ); |
|||
public: |
|||
static argusModuleFactory * getInstance( uint32_t ServerID = 0 ); |
|||
virtual ~argusModuleFactory(); |
|||
argusKernelModule * createModule( int id ); |
|||
void deleteModule( int id ); |
|||
argusKernelModule * getModule( uint32_t id ); |
|||
argusKernelModule * getModule( ARGUS_MODULE_TYPE t, uint32_t id = 0 ); |
|||
uint32_t getModulesCount( ARGUS_MODULE_TYPE t ); |
|||
uint32_t fetchModules( ARGUS_MODULE_TYPE, argusKernelModule**&RA ); |
|||
bool loadModules( uint32_t ServerID = 0 ); |
|||
bool validate( void ); |
|||
void shutdownServices( bool force = false ); |
|||
bool isValidationDone( void ){ return m_bInitialValidatioonDone; }; |
|||
protected: |
|||
explicit argusModuleFactory( uint32_t ServerID ); |
|||
virtual void m_fThreadProc( void ); |
|||
private: |
|||
static argusModuleFactory * _instance; |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,474 @@ |
|||
#include "rgooseModuleFlyHunter.h"
|
|||
|
|||
#define LOG( X ) argusKernelModule::m_pLog->Log( "MOD_FH", 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 );\ |
|||
argusKernelModule::m_pLog->Log( "MOD_FH", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "MOD_FH", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
argusModuleFlyHunter::argusModuleFlyHunter( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_FLYHUNTER ), basicThread(){ |
|||
memset( &m_sCurrentMission, 0, sizeof(FH_MISSION_DATA) ); |
|||
memset( &m_sCurrentlocation, 0 , sizeof(C3D_WGS84_LOC)); |
|||
m_pProtocol = NULL; |
|||
m_bEnabled = false; |
|||
m_bDroneStatus = FH_STATUS_NONE; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
}; |
|||
|
|||
argusModuleFlyHunter::~argusModuleFlyHunter(){ |
|||
m_bEnabled = false; |
|||
waitThreadEnd( true ); |
|||
if( m_pProtocol!= NULL ) delete( m_pProtocol ); |
|||
}; |
|||
|
|||
bool argusModuleFlyHunter::startService(){ |
|||
LOG("Starting Service!"); |
|||
if( m_bEnabled ) return false; |
|||
DBC_FH_DATA *tData = m_pDBC->getFlyHunterData( m_nDBAUXID ); |
|||
if( tData == NULL ) return false; |
|||
m_sGCSlocation.lat = tData->lat; |
|||
m_sGCSlocation.lon = tData->lon; |
|||
m_sGCSlocation.alt = tData->alt; |
|||
|
|||
m_bWorkingMode = FH_WM_NONE; |
|||
#ifdef SIMULATE_FH
|
|||
m_bDroneStatus = FH_STATUS_INIT; |
|||
m_bEnabled = true; |
|||
m_fStepLat = 0.0f; |
|||
m_fStepLon = 0.0f; |
|||
m_fStepAlt = 0.0f; |
|||
return init(); |
|||
#else
|
|||
m_pProtocol = new protocolMAVLINK(); |
|||
if( m_pProtocol!= NULL ) { |
|||
m_bDroneStatus = FH_STATUS_INIT; |
|||
if( m_pProtocol->create() ) { |
|||
m_bEnabled = true; |
|||
return init(); |
|||
}; |
|||
}; |
|||
#endif
|
|||
return false; |
|||
}; |
|||
|
|||
bool argusModuleFlyHunter::stopService( bool force ){ |
|||
return true; |
|||
}; |
|||
|
|||
void argusModuleFlyHunter::m_fThreadProc(){ |
|||
m_bThreadStatus = TH_WORKING; |
|||
if( !m_bEnabled ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG("Module is Disabled!"); |
|||
#endif
|
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Module Started!"); |
|||
#endif
|
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
switch( m_bWorkingMode ) { |
|||
case FH_WM_CANCELING:{ |
|||
m_bWorkingMode = FH_WM_FTL; |
|||
#ifdef SIMULATE_FH
|
|||
m_nSymTO = SIMULATE_FH_FTL_TO; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_WM_MISSION_FLIGHT:{ |
|||
|
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){ |
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
|
|||
m_sCurrentlocation.lat = m_sCurrentlocation.lat + m_fStepLat; |
|||
m_sCurrentlocation.lon = m_sCurrentlocation.lon + m_fStepLon; |
|||
m_sCurrentlocation.alt = m_sCurrentlocation.alt + m_fStepAlt; |
|||
|
|||
} else { |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt = NULL; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
switch( m_sCurrentMission.type ) { |
|||
case FH_WM_OBSERVE: |
|||
LOG("OBSERVE Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_DEST_REACHED, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
break; |
|||
case FH_WM_JAMING: |
|||
LOG("JAMING Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_JAMING; |
|||
m_nJamingTO = m_nJamingTO; |
|||
break; |
|||
case FH_WM_INTERCEPT: |
|||
LOG("INTERCEPT Mission"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_BEGIN, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_INTERCEPT; |
|||
#ifdef SIMULATE_FH
|
|||
m_nSymTO = SIMULATE_FH_INTERCEPT; |
|||
#endif
|
|||
break; |
|||
default: |
|||
LOG("No Mission Type SET!!"); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_DEST_REACHED, NULL, NULL, evtData ); |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
}; |
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_INTERCEPT:{ |
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
//if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){
|
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
} else { |
|||
float R = RAND_MAX / rand(); |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt = NULL; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
#ifdef SIMULATE_FH
|
|||
if( R > 0.5 ) { |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_OK, NULL, NULL, evtData ); |
|||
} else { |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_INTERCEPT_NOK, NULL, NULL, evtData ); |
|||
}; |
|||
#endif
|
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_JAMING:{ |
|||
if( m_nJamingTO ) { |
|||
if( m_nJamingTO == 1 ) { |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_OFF, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( POSHOLD ); |
|||
#endif
|
|||
}; |
|||
m_nJamingTO--; |
|||
} else { |
|||
//If Accedently entering in this mode!
|
|||
m_bWorkingMode = FH_WM_HOOVERING; |
|||
m_nHooveringTO = FH_HOOVERING_INTERVAL; |
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( POSHOLD ); |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_HOOVERING:{ |
|||
// Just Hold Position FH_HOOVERING_INTERVAL seconds
|
|||
if( m_nHooveringTO ) { |
|||
if( m_nHooveringTO == 1 ) { |
|||
// No New Assigns -> Going Home
|
|||
#ifndef SIMULATE_FH
|
|||
m_pProtocol->broadcastSetBaseMode( RTL ); |
|||
#else
|
|||
m_nSymTO = SIMULATE_FH_FTL_TO; |
|||
m_fStepLat = ( m_sGCSlocation.lat - m_sCurrentlocation.lat ) / m_nSymTO; |
|||
m_fStepLon = ( m_sGCSlocation.lon - m_sCurrentlocation.lon ) / m_nSymTO; |
|||
m_fStepAlt = ( m_sGCSlocation.alt - m_sCurrentlocation.alt ) / m_nSymTO; |
|||
#endif
|
|||
m_bWorkingMode = FH_WM_FTL; |
|||
|
|||
}; |
|||
m_nHooveringTO--; |
|||
}; |
|||
break; |
|||
}; |
|||
case FH_WM_EMERGENCY_FTL: |
|||
case FH_WM_FTL:{ |
|||
#ifndef SIMULATE_FH
|
|||
//IF landed
|
|||
// Must be Provided comparation
|
|||
if( m_sGCSlocation.lat == m_sCurrentlocation.lat && m_sGCSlocation.lon == m_sCurrentlocation.lon ){ |
|||
#else
|
|||
if( m_nSymTO ){ |
|||
m_nSymTO --; |
|||
|
|||
m_sCurrentlocation.lat = m_sCurrentlocation.lat + m_fStepLat; |
|||
m_sCurrentlocation.lon = m_sCurrentlocation.lon + m_fStepLon; |
|||
m_sCurrentlocation.alt = m_sCurrentlocation.alt + m_fStepAlt; |
|||
|
|||
} else { |
|||
#endif
|
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sGCSlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_LANDED, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
// Propogate Event
|
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
// Turn Off Motors
|
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->broadcastArm( false ) ){ |
|||
// Stop Chakalaka!!
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
m_bWorkingMode = FH_WM_NONE; |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
|
|||
switch( m_bDroneStatus ) { |
|||
case FH_STATUS_INIT:{ |
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->broadcastProtocolVersionReq() ){ |
|||
m_bDroneStatus = FH_STATUS_CONNECT; |
|||
} else SLEEP ( 1000 ); |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_PREARM; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_STATUS_PREARM:{ |
|||
if( m_bWorkingMode > FH_WM_FTL ) { |
|||
#ifndef SIMULATE_FH
|
|||
// Turn On Motors
|
|||
if( m_pProtocol->broadcastArm( true ) ){ |
|||
//Run Chakalaka!!
|
|||
m_bDroneStatus = FH_STATUS_ARMED; |
|||
m_bWorkingMode = FH_WM_START_FLIGHT; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_ARMED; |
|||
m_bWorkingMode = FH_WM_START_FLIGHT; |
|||
#endif
|
|||
}; |
|||
break; |
|||
}; |
|||
case FH_STATUS_ARMED:{ |
|||
#ifndef SIMULATE_FH
|
|||
// Lift Up
|
|||
if( m_pProtocol->broadcastTakeoff( 10.0f ) ){ |
|||
m_bDroneStatus = FH_STATUS_FLYING; |
|||
}; |
|||
#else
|
|||
m_bDroneStatus = FH_STATUS_FLYING; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case FH_STATUS_FLYING:{ |
|||
if( m_bWorkingMode == FH_WM_START_FLIGHT ){ |
|||
#ifndef SIMULATE_FH
|
|||
if( m_pProtocol->setTargetPosition( m_sCurrentMission.location.lat, m_sCurrentMission.location.lon, m_sCurrentMission.location.alt, 0 ) ){ |
|||
m_bWorkingMode = FH_WM_MISSION_FLIGHT; |
|||
}; |
|||
#else
|
|||
m_bWorkingMode = FH_WM_MISSION_FLIGHT; |
|||
m_nSymTO = SIMULATE_FH_FLY; |
|||
|
|||
m_sCurrentlocation.lat = m_sGCSlocation.lat; |
|||
m_sCurrentlocation.lon = m_sGCSlocation.lon; |
|||
m_sCurrentlocation.alt = m_sGCSlocation.alt; |
|||
|
|||
m_fStepLat = ( m_sCurrentMission.location.lat - m_sGCSlocation.lat ) / m_nSymTO; |
|||
m_fStepLon = ( m_sCurrentMission.location.lon - m_sGCSlocation.lon ) / m_nSymTO; |
|||
m_fStepAlt = ( m_sCurrentMission.location.alt - m_sGCSlocation.alt ) / m_nSymTO; |
|||
#endif
|
|||
}; |
|||
//Update Position to other components
|
|||
if( m_nWayPointTO ) { |
|||
m_nWayPointTO --; |
|||
}; |
|||
if( m_nWayPointTO == 0 ){ |
|||
m_nWayPointTO = FH_WAYPOINT_UPDATE_INTERVAL; |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
memcpy( &evtData->location, &m_sCurrentlocation, sizeof(C3D_WGS84_LOC)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_WAYPOINT, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
};// Drone Status Switch
|
|||
#ifdef SIMULATE_FH
|
|||
SLEEP( 1000 ); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
void argusModuleFlyHunter::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
if(!m_bEnabled) { |
|||
LOG("Module Disabled!"); |
|||
return; |
|||
} |
|||
if( Evt == NULL ) return; |
|||
switch( Evt->m_eClass ){ |
|||
case EVT_CLASS_EXTERNAL_CMD:{ |
|||
switch( Evt->m_eType ) { |
|||
case EVT_FH_MISSION_BEGIN:{ |
|||
if( |
|||
( ( m_bDroneStatus == FH_STATUS_PREARM ) && ( m_bWorkingMode == FH_WM_NONE ) ) || |
|||
( ( ( m_bDroneStatus == FH_STATUS_ARMED ) && ( ( m_bWorkingMode == FH_WM_HOOVERING ) || ( m_bWorkingMode == FH_WM_FTL ) ) ) ) |
|||
){ |
|||
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
DBC_EVT_RECORD * tEVT = m_pDBC->getEventByUUID( tData->targetUUID ); |
|||
if( tEVT ) { |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
evtData->location.lat = tEVT->lat; |
|||
evtData->location.lon = tEVT->lon; |
|||
evtData->location.alt = tEVT->alt; |
|||
sprintf( evtData->missionID, tData->evtUUID ); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_FLY_TO, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
memcpy( &m_sCurrentMission, evtData, sizeof(FH_MISSION_DATA) ); |
|||
m_sCurrentMission.type = FH_WM_INTERCEPT; |
|||
m_bWorkingMode = FH_WM_MISSION_BEGIN; |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
free( tEVT ); |
|||
} else { |
|||
// Not Found In Database
|
|||
}; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("BUSY!"); |
|||
char tB[128]; |
|||
sprintf( tB, "DS: %02d WM: %02d", m_bDroneStatus, m_bWorkingMode ); |
|||
LOG( tB ); |
|||
#endif
|
|||
if( Evt->m_pEvtData!= NULL ) { |
|||
FH_CTRL_DATA * tEData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
FH_CTRL_DATA * tNData = (FH_CTRL_DATA *) malloc(sizeof(FH_CTRL_DATA)); |
|||
if( tNData != NULL ) { |
|||
EVENT_CONTAINER * tEvt; |
|||
memcpy(tNData, tEData, sizeof(FH_CTRL_DATA)); |
|||
tEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_BUSY, NULL, NULL, tNData ); |
|||
if( tEvt!= NULL ) { |
|||
m_pEventHeap->broadcast( tEvt ); |
|||
} else { |
|||
free( tNData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_JAMING_BEGIN:{ // FH_CTRL_DATA
|
|||
if( m_bWorkingMode == FH_WM_MISSION_FLIGHT || m_bWorkingMode == FH_WM_HOOVERING || m_bWorkingMode == FH_WM_FTL ){ |
|||
FH_CTRL_DATA * tData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
EVENT_CONTAINER * newEvt; |
|||
FH_MISSION_DATA * evtData = (FH_MISSION_DATA *) malloc( sizeof(FH_MISSION_DATA)); |
|||
if( evtData ){ |
|||
memcpy( evtData, &m_sCurrentMission, sizeof(FH_MISSION_DATA)); |
|||
newEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_JAMER_ON, NULL, NULL, evtData ); |
|||
if( newEvt ) { |
|||
m_bWorkingMode = FH_WM_JAMING; |
|||
m_sCurrentMission.type = FH_WM_JAMING; |
|||
m_nJamingTO = tData->param; |
|||
m_pEventHeap->broadcast( newEvt ); |
|||
} else { |
|||
free( evtData ); |
|||
}; |
|||
}; |
|||
} else { |
|||
// No Jaming When No Mission is assigned
|
|||
if( Evt->m_pEvtData!= NULL ) { |
|||
FH_CTRL_DATA * tEData = (FH_CTRL_DATA *) Evt->m_pEvtData; |
|||
FH_CTRL_DATA * tNData = (FH_CTRL_DATA *) malloc(sizeof(FH_CTRL_DATA)); |
|||
if( tNData != NULL ) { |
|||
EVENT_CONTAINER * tEvt; |
|||
memcpy(tNData, tEData, sizeof(FH_CTRL_DATA)); |
|||
tEvt = createBasicEvent( getAuxId(), EVT_CLASS_FLY_HUNTER, EVT_FH_BUSY, NULL, NULL, tNData ); |
|||
if( tEvt!= NULL ) { |
|||
m_pEventHeap->broadcast( tEvt ); |
|||
} else { |
|||
free( tNData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_CANCEL_ACTION:{ |
|||
m_bWorkingMode = FH_WM_CANCELING; |
|||
break; |
|||
}; |
|||
}; // Case Class
|
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool argusModuleFlyHunter::reloadSettings(){ |
|||
return true; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,73 @@ |
|||
#ifndef __ARGUS_MODULE_FLY_HUNTER_HEADER__ |
|||
#define __ARGUS_MODULE_FLY_HUNTER_HEADER__ |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
|
|||
#include "../data/protocol/protocolMAVLINK.h" |
|||
|
|||
#define SIMULATE_FH |
|||
|
|||
#ifdef SIMULATE_FH |
|||
#define SIMULATE_FH_FLY 40 |
|||
#define SIMULATE_FH_INTERCEPT 30 |
|||
#define SIMULATE_FH_FTL_TO 40 |
|||
#endif |
|||
|
|||
typedef enum E_FH_STATUS{ |
|||
FH_STATUS_NONE = 0, |
|||
FH_STATUS_INIT = 1, |
|||
FH_STATUS_CONNECT = 2, |
|||
FH_STATUS_READ_DATA = 3, |
|||
FH_STATUS_ERROR = 4, |
|||
FH_STATUS_PREARM = 5, |
|||
FH_STATUS_ARMED = 6, |
|||
FH_STATUS_FLYING = 7 |
|||
}FH_STATUS; |
|||
|
|||
typedef enum E_FH_WM{ |
|||
FH_WM_NONE = 0, |
|||
FH_WM_CANCELING = 1, |
|||
FH_WM_HOOVERING = 2, |
|||
FH_WM_FTL = 3, |
|||
FH_WM_MISSION_BEGIN = 4, |
|||
FH_WM_START_FLIGHT = 5, |
|||
FH_WM_MISSION_FLIGHT = 6, |
|||
FH_WM_INTERCEPT = 7, |
|||
FH_WM_JAMING = 8, |
|||
FH_WM_OBSERVE = 9, |
|||
FH_WM_EMERGENCY_FTL = 10 |
|||
}FH_WM; |
|||
|
|||
#define FH_WAYPOINT_UPDATE_INTERVAL 15 |
|||
#define FH_HOOVERING_INTERVAL 25 |
|||
|
|||
class argusModuleFlyHunter: public argusKernelModule, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
FH_MISSION_DATA m_sCurrentMission; |
|||
FH_WM m_bWorkingMode; |
|||
FH_STATUS m_bDroneStatus; |
|||
uint16_t m_nJamingTO; |
|||
uint16_t m_nWayPointTO; |
|||
uint16_t m_nHooveringTO; |
|||
#ifdef SIMULATE_FH |
|||
uint16_t m_nSymTO; |
|||
float m_fStepLat; |
|||
float m_fStepLon; |
|||
float m_fStepAlt; |
|||
#endif |
|||
C3D_WGS84_LOC m_sCurrentlocation; |
|||
C3D_WGS84_LOC m_sGCSlocation; |
|||
protocolMAVLINK * m_pProtocol; |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleFlyHunter( uint32_t oduleID ); |
|||
~argusModuleFlyHunter(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
}; |
|||
#endif |
|||
@ -0,0 +1,760 @@ |
|||
#include "rgooseModuleKafka.h"
|
|||
#include "mojoKernel.h"
|
|||
#include "../hardware/soc/general/3DLRF.h"
|
|||
#include "../data/json/json_tool.h"
|
|||
#include <strings.h>
|
|||
#include <json/value.h>
|
|||
#include <json/writer.h>
|
|||
#include <json/reader.h>
|
|||
|
|||
#define LOG( X ) argusKernelModule::m_pLog->Log( "MOD_KAFKA", 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 );\ |
|||
argusKernelModule::m_pLog->Log( "MOD_KAFKA", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "MOD_KAFKA", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
argusModuleKafka::argusModuleKafka( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_KAFKA ){ |
|||
m_pProtocol = NULL; |
|||
m_bConsumerEnabled = false; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
partition = 0; //RdKafka::Topic::PARTITION_UA;
|
|||
//start_offset = RdKafka::Topic::OFFSET_END;// OFFSET_BEGINNING;
|
|||
start_offset = 0;//RdKafka::Topic::OFFSET_BEGINNING;
|
|||
//start_offset = RdKafka::Topic::OFFSET_STORED;
|
|||
|
|||
memset( m_sServerIP, 0 ,48 ); |
|||
CSTR TVAL = NULL;//m_pKernel->getServerIp();
|
|||
if ( TVAL ) { |
|||
strncpy( m_sServerIP, TVAL, 48 ); |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Get Argus Server IP!"); |
|||
strncpy( m_sServerIP, "192.168.0.127", 48 ); |
|||
}; |
|||
memset( m_sServerName, 0, 48 ); |
|||
TVAL = NULL;//m_pKernel->getServerName();
|
|||
if ( TVAL ) { |
|||
strncpy( m_sServerName, TVAL, 48 ); |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Get Argus Server Name!"); |
|||
strncpy( m_sServerName, "Argus Server", 48 ); |
|||
}; |
|||
|
|||
m_pEvtTemplates = (KAFKA_TEMPLATE***) calloc(EVT_CLASS_COUNT, sizeof(KAFKA_TEMPLATE**)); |
|||
if( m_pEvtTemplates!= NULL ) { |
|||
memset( m_pEvtTemplates, 0, EVT_CLASS_COUNT * sizeof(KAFKA_TEMPLATE**)); |
|||
} else LOG_ERROR("EVT Templates Memory Allocation Error!"); |
|||
/*
|
|||
Do it in Kernel!! |
|||
if ( m_pKernel!= NULL ) { |
|||
argusHardwareManager *tHWM = m_pKernel->getHardwareManager(); |
|||
if( tHWM != NULL ) { |
|||
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK ); |
|||
if( rIDS != NULL ) { |
|||
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){ |
|||
argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx ); |
|||
if( tRES != NULL ) { |
|||
m_pServerIP = tRES->getAddress(); |
|||
break; |
|||
} else { |
|||
LOG_ERROR("Cannot Get Resource!"); |
|||
}; |
|||
}; |
|||
delete( rIDS ); |
|||
} else { |
|||
LOG("No Networks Detected!"); |
|||
m_bEnabled = false; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No HW Manager"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No Kernel"); |
|||
}; |
|||
*/ |
|||
}; |
|||
|
|||
argusModuleKafka::~argusModuleKafka(){ |
|||
|
|||
m_bEnabled = false; |
|||
|
|||
waitThreadEnd( true ); |
|||
|
|||
if( m_pProtocol!= NULL ) { |
|||
delete( m_pProtocol ); |
|||
}; |
|||
|
|||
if( m_pEvtTemplates!= NULL ) { |
|||
for(int i=0; i < EVT_CLASS_COUNT; i++ ) { |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
for( int j=0; j< EVT_COUNT; j++ ) { |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl ); |
|||
free( m_pEvtTemplates[i][j] ); |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates[i] ); |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates ); |
|||
}; |
|||
}; |
|||
/* Periodical Job Handler */ |
|||
void argusModuleKafka::m_fThreadProc( void ){ |
|||
#ifdef SIMULATOR
|
|||
float sim_Az = 0.f; |
|||
float sim_El = 20.f; |
|||
float sim_Ran = 80.35f; |
|||
float tr_Az_step = 0.3f; |
|||
uint32_t src = 128; |
|||
#endif
|
|||
#ifdef DEBUG
|
|||
LOG("Pereodical Jobs Started"); |
|||
#endif
|
|||
m_bThreadStatus = TH_WORKING; |
|||
if( !m_bEnabled ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
#ifdef DEBUG
|
|||
LOG("Module is Disabled!"); |
|||
#endif
|
|||
}; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
m_llTicks ++;//= getMilliseconds();
|
|||
if( m_llTicks % 20 == 0 ) { // each 2 seconds
|
|||
#ifdef SIMULATOR
|
|||
sim_Az += tr_Az_step; |
|||
for(int i=0; i < EVT_CLASS_COUNT; i++ ) { |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
for( int j=0; j< EVT_COUNT; j++ ) { |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
CSTR tpl; |
|||
CSTR ts; |
|||
CSTR uuid; |
|||
char LON[10]; |
|||
char LAT[10]; |
|||
char AZ[10]; |
|||
char EL[10]; |
|||
char RN[10]; |
|||
float lat = 32.906153575029926; |
|||
float lon = 35.09629379621815; |
|||
sprintf( AZ, "%.3f", sim_Az+(0.6/RAND_MAX)*rand()); |
|||
sprintf( EL, "%.3f", sim_El+(0.6/RAND_MAX)*rand()); |
|||
sprintf( RN, "%.3f", sim_Ran+(0.6/RAND_MAX)*rand()); |
|||
sprintf( LAT, "%.10f", lat+(0.00006/RAND_MAX)*rand() ); |
|||
sprintf( LON, "%.10f", lon+(0.00006/RAND_MAX)*rand() ); |
|||
uuid = getUniqID_UUID(); |
|||
ts = getTimeStamp(); |
|||
src = i; |
|||
tpl = buildTemplate( m_pEvtTemplates[i][j]->tpl, src, ts, uuid, AZ, RN, EL, LAT, LON ); |
|||
if( tpl ) { |
|||
m_pProtocol->issuePost( m_pEvtTemplates[i][j]->topic, tpl, strlen( tpl ) ); |
|||
free( tpl ); |
|||
}; |
|||
if( uuid ) free( uuid ); |
|||
if( ts ) free( ts ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
#endif
|
|||
}; |
|||
if( m_bConsumerEnabled ) { |
|||
for( uint8_t idx = 0; idx < EVT_COUNT; idx++ ) { |
|||
if( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx] != NULL ){ |
|||
char BUF[1024]; |
|||
int len; |
|||
if( m_pProtocol->receivePost( m_pEvtTemplates[EVT_CLASS_EXTERNAL_CMD][idx]->topic, partition, start_offset, BUF, len ) ){ |
|||
if( len > 0 ) { |
|||
start_offset++; |
|||
#ifdef DEBUG
|
|||
char ttt[64]; |
|||
LOG(" HAVE MESSAGE "); |
|||
sprintf( ttt, " MSG Len: %d", len ); |
|||
LOG( ttt ); |
|||
#endif
|
|||
if( len > 0 ){ |
|||
LOG ( BUF ); |
|||
try{ |
|||
Json::Value root; |
|||
#ifdef OLD_WAY_JSON
|
|||
Json::Reader reader; |
|||
if( !reader.parse( BUF, root ) ){ |
|||
LOG_ERROR( "Error parsing the string" ); |
|||
} else { |
|||
#else
|
|||
JSONCPP_STRING err; |
|||
Json::CharReaderBuilder builder; |
|||
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); |
|||
if (!reader->parse(BUF, BUF + len, &root, &err)) { |
|||
LOG_ERROR( "Error parsing the string" ); |
|||
LOG_ERROR( err.c_str() ); |
|||
} else { |
|||
#endif
|
|||
|
|||
if (root.size()) { |
|||
FH_CTRL_DATA * tData; |
|||
basicEventTypeID evtID = EVT_NOINIT; |
|||
Json::Value tVal; |
|||
tData =(FH_CTRL_DATA *)malloc( sizeof(FH_CTRL_DATA)); |
|||
if( tData ) { |
|||
memset( tData, 0, sizeof(FH_CTRL_DATA)); |
|||
tVal = root["id"]; |
|||
|
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG(tVal.asString().c_str()); |
|||
#endif
|
|||
sprintf( tData->cmdUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
tVal = root["action"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
if ( strcasecmp(tVal.asString().c_str(), "intercept_target") == 0) { |
|||
evtID = EVT_FH_MISSION_BEGIN; |
|||
}; |
|||
if ( strcasecmp(tVal.asString().c_str(), "jam_target") == 0) { |
|||
tData->param = atoi( tVal.asString().c_str()+10 ); |
|||
if( tData->param == 0 ) { |
|||
tData->param = FH_DEFAULT_JAMING_TIME; |
|||
}; |
|||
evtID = EVT_FH_JAMING_BEGIN; |
|||
}; |
|||
if ( strcasecmp(tVal.asString().c_str(), "cancel") == 0) { |
|||
evtID = EVT_FH_CANCEL_ACTION; |
|||
}; |
|||
}; |
|||
tVal = root["event_id"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
sprintf( tData->evtUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
tVal = root["target_id"]; |
|||
if (!tVal.isNull()) { |
|||
#ifdef DEBUG
|
|||
LOG( tVal.asString().c_str() ); |
|||
#endif
|
|||
sprintf( tData->targetUUID, "%s", tVal.asString().c_str() ); |
|||
}; |
|||
if( evtID ) { |
|||
EVENT_CONTAINER * tEVT; |
|||
tEVT = createBasicEvent( 0, EVT_CLASS_EXTERNAL_CMD, evtID, NULL, NULL, tData ); |
|||
if( tEVT ) { |
|||
m_pEventHeap->broadcast( tEVT ); |
|||
} else { |
|||
free( tData ); |
|||
}; |
|||
} else { |
|||
free( tData ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
} catch( exception e ){ |
|||
LOG_ERROR("EXCEPTION"); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
SLEEP(100); |
|||
}; |
|||
}; |
|||
|
|||
bool argusModuleKafka::startService(){ |
|||
if(!m_bEnabled) return false; |
|||
if( reloadSettings() ) { |
|||
if( m_pSettings!= NULL ){ |
|||
m_pProtocol = new protocolKAFKA( m_pSettings ); |
|||
if( m_pProtocol->init() ){ |
|||
return init(); |
|||
}; |
|||
}; |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
bool argusModuleKafka::stopService( bool force ){ |
|||
waitThreadEnd( true ); |
|||
return true; |
|||
}; |
|||
|
|||
bool argusModuleKafka::reloadSettings(){ |
|||
if( m_pDBC==NULL ) return false; |
|||
if(! m_bEnabled) return false; |
|||
m_pSettings = m_pDBC->getSettingsKAFKA( m_nDBAUXID ); |
|||
if( m_pSettings != NULL ) { |
|||
if( m_pEvtTemplates != NULL ) { |
|||
// Clear Templates
|
|||
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){ |
|||
for(int j = 0; j < EVT_COUNT; j++ ){ |
|||
if( m_pEvtTemplates[i] != NULL ){ |
|||
if( m_pEvtTemplates[i][j] != NULL ){ |
|||
if( m_pEvtTemplates[i][j]->tpl ) free( m_pEvtTemplates[i][j]->tpl ); |
|||
free( m_pEvtTemplates[i][j] ); |
|||
m_pEvtTemplates[i][j] = NULL; |
|||
}; |
|||
}; |
|||
}; |
|||
free( m_pEvtTemplates[i] ); |
|||
m_pEvtTemplates[i] = NULL; |
|||
}; |
|||
for(int i = 0; i < EVT_CLASS_COUNT; i++ ){ |
|||
for(int j = 0; j < EVT_COUNT; j++ ){ |
|||
KAFKA_TEMPLATE * tT; |
|||
tT = m_pDBC->getKafkaTemplateForEvent( m_nDBAUXID, i, j ); |
|||
if( tT != NULL ) { |
|||
if( m_pEvtTemplates[i]== NULL ) { |
|||
m_pEvtTemplates[i]=(KAFKA_TEMPLATE**)calloc(EVT_COUNT,sizeof(KAFKA_TEMPLATE*)); |
|||
memset( m_pEvtTemplates[i], 0, EVT_COUNT * sizeof(KAFKA_TEMPLATE*)); |
|||
if( i == EVT_CLASS_EXTERNAL_CMD ) { |
|||
m_bConsumerEnabled = true; |
|||
}; |
|||
}; |
|||
m_pEvtTemplates[i][j] = tT; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
return true; |
|||
}; |
|||
return false; |
|||
}; |
|||
CSTR argusModuleKafka::buildTemplate( |
|||
CSTR tpl, |
|||
uint32_t source_id, |
|||
CSTR ts, |
|||
CSTR uuid, |
|||
CSTR az, |
|||
CSTR range, |
|||
CSTR width, |
|||
CSTR el, |
|||
CSTR lat, |
|||
CSTR lon, |
|||
CSTR alt, |
|||
CSTR extID, |
|||
CSTR src_Name, |
|||
CSTR src_IP, |
|||
CSTR src_lat, |
|||
CSTR src_lon, |
|||
CSTR src_alt, |
|||
CSTR src_rot_x, |
|||
CSTR src_rot_y, |
|||
CSTR src_rot_z |
|||
){ |
|||
CSTR ct1, ct2; |
|||
char sid[64]; |
|||
if( tpl ) { |
|||
sprintf( sid, "%d", source_id ); |
|||
ct1 = strReplace( tpl, KAFKA_TPL_SUBST_ID, sid ); |
|||
if( ct1 ) { |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_TS, ts ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
if( uuid ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_UUID, uuid ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( az ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_AZ, az ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( range ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_RANGE, range ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( width ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_WIDTH, width ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( el ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EL, el ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( lat ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_LAT, lat ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( lon ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_LON, lon ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( alt ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_ALT, alt ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( extID ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_EXEVTD, extID ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_Name ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_NAME, src_Name ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_IP ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_IP, src_IP ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_lat ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_LAT, src_lat ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_lon ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_LON, src_lon ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_alt ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ALT, src_alt ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_x ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_X, src_rot_x ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_y ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_Y, src_rot_y ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
if( src_rot_z ){ |
|||
ct2 = strReplace( ct1, KAFKA_TPL_SUBST_SRC_ROT_Z, src_rot_z ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
}; |
|||
//Finalaze Message by System Wide Data
|
|||
// UUID
|
|||
CSTR TVAL = getUniqID_UUID(); |
|||
if ( TVAL != NULL ) { |
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_MSG_UUID, TVAL ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
free( TVAL ); |
|||
} else { |
|||
LOG_ERROR("Error Generate Message UUID!"); |
|||
}; |
|||
// Server IP
|
|||
|
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_IP, m_sServerIP ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
// Server Name
|
|||
ct2 = strReplace(ct1, KAFKA_TPL_SUBST_SRV_NAME, m_sServerName ); |
|||
if( ct2 ) { |
|||
free( ct1 ); |
|||
ct1 = ct2; |
|||
}; |
|||
return ct1; |
|||
}; |
|||
} |
|||
return NULL; |
|||
}; |
|||
|
|||
void argusModuleKafka::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|||
if( Evt == NULL ) return; |
|||
if( !m_bEnabled ) return; |
|||
#ifdef DEBUG
|
|||
char tBuffer[256]; |
|||
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
if( m_pEvtTemplates[ Evt->m_eClass ]!= NULL ) { |
|||
// We have defined Channel for that class Events
|
|||
// Skip Event Handling by flags
|
|||
if( !m_bEvtFlags[ Evt->m_eType ] ){ |
|||
#ifdef DEBUG
|
|||
//LOG("Disabled By FLAG!");
|
|||
#endif
|
|||
//return;
|
|||
} |
|||
// Hadle Event
|
|||
CSTR tDATA = NULL; |
|||
if( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ] != NULL ) { |
|||
switch( Evt->m_eType ) { |
|||
case EVT_TARGET_2D_BLACK: |
|||
case EVT_TARGET_2D_WHITE:{ |
|||
TARGET_DATA * tTARGET = ( TARGET_DATA *) Evt->m_pEvtData; |
|||
if(tTARGET!=NULL){ |
|||
char AZ[10]; |
|||
char RA[10]; |
|||
char WID[10]; |
|||
|
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
|
|||
char SLAT[10]; |
|||
char SLON[10]; |
|||
char SALT[10]; |
|||
char SROT_X[10]; |
|||
char SROT_Y[10]; |
|||
char SROT_Z[10]; |
|||
char SNAME[64]; |
|||
char TS[64]; |
|||
|
|||
sprintf( AZ,"%0.3f", tTARGET->local_target.fi ); |
|||
sprintf( RA,"%0.3f", tTARGET->local_target.r ); |
|||
sprintf( WID,"%0.3f", tTARGET->area ); |
|||
sprintf( LAT,"%0.6f", tTARGET->global_target.lat ); |
|||
sprintf( LON,"%0.6f", tTARGET->global_target.lon ); |
|||
sprintf( ALT,"%0.6f", tTARGET->global_target.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
sprintf( SLAT,"%0.6f", tTARGET->source_position.lat ); |
|||
sprintf( SLON,"%0.6f", tTARGET->source_position.lon ); |
|||
sprintf( SALT,"%0.6f", tTARGET->source_position.alt ); |
|||
|
|||
sprintf( SROT_X,"%0.6f", tTARGET->source_orient.rot_x ); |
|||
sprintf( SROT_Y,"%0.6f", tTARGET->source_orient.rot_y ); |
|||
sprintf( SROT_Z,"%0.6f", tTARGET->source_orient.rot_z ); |
|||
CSTR tN = m_pDBC->getNodeName( Evt->m_nSourceNodeID ); |
|||
if ( tN ) { |
|||
strncpy( SNAME, tN, 64 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SNAME, "Noname-Laser-Detector", 64); |
|||
}; |
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
AZ, |
|||
RA, |
|||
WID, |
|||
NULL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
NULL, |
|||
SNAME, |
|||
m_sServerIP, |
|||
SLAT, |
|||
SLON, |
|||
SALT, |
|||
SROT_X, |
|||
SROT_Y, |
|||
SROT_Z |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_TARGET_3D_BLACK: |
|||
case EVT_TARGET_3D_WHITE:{ |
|||
TARGET_DATA * tTARGET = ( TARGET_DATA *) Evt->m_pEvtData; |
|||
if(tTARGET!=NULL){ |
|||
char AZ[10]; |
|||
char EL[10]; |
|||
char RA[10]; |
|||
char WID[10]; |
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
|
|||
char SLAT[10]; |
|||
char SLON[10]; |
|||
char SALT[10]; |
|||
char SROT_X[10]; |
|||
char SROT_Y[10]; |
|||
char SROT_Z[10]; |
|||
|
|||
char SIP[16]; |
|||
char SNAME[64]; |
|||
|
|||
char TS[64]; |
|||
sprintf( AZ,"%0.3f", tTARGET->local_target.fi ); |
|||
sprintf( EL,"%0.3f", tTARGET->local_target.tetta ); |
|||
sprintf( RA,"%0.3f", tTARGET->local_target.r ); |
|||
sprintf( WID,"%0.3f", tTARGET->area ); |
|||
sprintf( LAT,"%0.6f", tTARGET->global_target.lat ); |
|||
sprintf( LON,"%0.6f", tTARGET->global_target.lon ); |
|||
sprintf( ALT,"%0.6f", tTARGET->global_target.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
sprintf( SLAT,"%0.6f", tTARGET->source_position.lat ); |
|||
sprintf( SLON,"%0.6f", tTARGET->source_position.lon ); |
|||
sprintf( SALT,"%0.6f", tTARGET->source_position.alt ); |
|||
|
|||
sprintf( SROT_X,"%0.6f", tTARGET->source_orient.rot_x ); |
|||
sprintf( SROT_Y,"%0.6f", tTARGET->source_orient.rot_y ); |
|||
sprintf( SROT_Z,"%0.6f", tTARGET->source_orient.rot_z ); |
|||
CSTR tN = m_pDBC->getNodeName( Evt->m_nSourceNodeID ); |
|||
if ( tN ) { |
|||
strncpy( SNAME, tN, 64 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SNAME, "Noname-Laser-Detector", 64); |
|||
}; |
|||
|
|||
if ( 0 ) { |
|||
strncpy( SIP, tN, 16 ); |
|||
free( tN ); |
|||
} else { |
|||
strncpy(SIP, "192.168.1.24", 16); |
|||
}; |
|||
|
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
AZ, |
|||
RA, |
|||
WID, |
|||
EL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
NULL, |
|||
SNAME, |
|||
SIP, |
|||
SLAT, |
|||
SLON, |
|||
SALT, |
|||
SROT_X, |
|||
SROT_Y, |
|||
SROT_Z |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
case EVT_FH_JAMER_ON: |
|||
case EVT_FH_JAMER_OFF: |
|||
case EVT_FH_FLY_TO: |
|||
case EVT_FH_WAYPOINT: |
|||
case EVT_FH_INTERCEPT_OK: |
|||
case EVT_FH_INTERCEPT_NOK: |
|||
case EVT_FH_BUSY: |
|||
case EVT_FH_LANDED:{ |
|||
FH_MISSION_DATA * tPOINT=(FH_MISSION_DATA *) Evt->m_pEvtData; |
|||
if( tPOINT ) { |
|||
char TS[64]; |
|||
char LAT[10]; |
|||
char LON[10]; |
|||
char ALT[10]; |
|||
sprintf( LAT,"%0.6f", tPOINT->location.lat ); |
|||
sprintf( LON,"%0.6f", tPOINT->location.lon ); |
|||
sprintf( ALT,"%0.6f", tPOINT->location.alt ); |
|||
sprintf( TS, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", |
|||
( Evt->sTS.tm_year+1900), |
|||
(Evt->sTS.tm_mon+1), |
|||
Evt->sTS.tm_mday, |
|||
Evt->sTS.tm_hour, |
|||
Evt->sTS.tm_min, |
|||
Evt->sTS.tm_sec, |
|||
(Evt->m_UMSTS%1000) |
|||
); |
|||
tDATA = buildTemplate( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->tpl, |
|||
Evt->m_nSourceNodeID, |
|||
TS, |
|||
Evt->m_UUID, |
|||
NULL, |
|||
NULL, |
|||
NULL, |
|||
NULL, |
|||
LAT, |
|||
LON, |
|||
ALT, |
|||
tPOINT->missionID |
|||
); |
|||
}; |
|||
break; |
|||
}; |
|||
default:{ |
|||
break; |
|||
}; |
|||
}; |
|||
if( tDATA!= NULL ) { |
|||
#ifdef KAFKA_DUMMY_SEND
|
|||
LOG( tDATA ); |
|||
#else
|
|||
m_pProtocol->issuePost( m_pEvtTemplates[ Evt->m_eClass ][ Evt->m_eType ]->topic, tDATA, strlen( tDATA ) ); |
|||
#endif
|
|||
} else { |
|||
LOG_ERROR("Cant Build Template!"); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,86 @@ |
|||
#ifndef __RGOOSE_KAFKA_MODULE_HEADERS__ |
|||
#define __RGOOSE_KAFKA_MODULE_HEADERS__ |
|||
|
|||
|
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
#include "../data/protocol/protocolKAFKA.h" |
|||
|
|||
//#define SIMULATOR |
|||
//#define KAFKA_DUMMY_SEND |
|||
|
|||
#define KAFKA_TPL_SUBST_ID "%%ID%%" |
|||
#define KAFKA_TPL_SUBST_UUID "%%UUID%%" |
|||
#define KAFKA_TPL_SUBST_TS "%%TIMESTAMP%%" |
|||
#define KAFKA_TPL_SUBST_AZ "%%AZIMUTH%%" |
|||
#define KAFKA_TPL_SUBST_RANGE "%%RANGE%%" |
|||
#define KAFKA_TPL_SUBST_EL "%%ELEVATION%%" |
|||
#define KAFKA_TPL_SUBST_WIDTH "%%WIDTH%%" |
|||
#define KAFKA_TPL_SUBST_LON "%%LON%%" |
|||
#define KAFKA_TPL_SUBST_LAT "%%LAT%%" |
|||
#define KAFKA_TPL_SUBST_ALT "%%ALT%%" |
|||
#define KAFKA_TPL_SUBST_EXEVTD "%%EXEVTID%%" |
|||
#define KAFKA_TPL_SUBST_SRC_LON "%%SRC_LON%%" |
|||
#define KAFKA_TPL_SUBST_SRC_LAT "%%SRC_LAT%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ALT "%%SRC_ALT%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_X "%%SRC_ROT_X%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_Y "%%SRC_ROT_Y%%" |
|||
#define KAFKA_TPL_SUBST_SRC_ROT_Z "%%SRC_ROT_Z%%" |
|||
#define KAFKA_TPL_SUBST_SRC_IP "%%SRC_IP%%" |
|||
#define KAFKA_TPL_SUBST_SRV_IP "%%SRV_IP%%" |
|||
#define KAFKA_TPL_SUBST_SRV_NAME "%%SRV_NAME%%" |
|||
#define KAFKA_TPL_SUBST_SRC_NAME "%%SRC_NAME%%" |
|||
#define KAFKA_TPL_SUBST_MSG_UUID "%%MUID%%" |
|||
|
|||
|
|||
#define FH_DEFAULT_JAMING_TIME 10 |
|||
|
|||
class argusModuleKafka: public argusKernelModule, public basicThread { |
|||
private: |
|||
KAFKA_SETTINGS *m_pSettings; |
|||
protocolKAFKA *m_pProtocol; |
|||
bool m_bConsumerEnabled; |
|||
basicEventHeap *m_pEventHeap; |
|||
KAFKA_TEMPLATE ***m_pEvtTemplates; |
|||
|
|||
int32_t partition; |
|||
int64_t start_offset; |
|||
char m_sServerIP[48]; |
|||
char m_sServerName[48]; |
|||
unsigned long long m_llTicks; |
|||
CSTR buildTemplate( CSTR tpl, |
|||
uint32_t source_id, |
|||
CSTR ts, |
|||
CSTR uuid = NULL, |
|||
CSTR az = NULL, |
|||
CSTR range = NULL, |
|||
CSTR width = NULL, |
|||
CSTR el = NULL, |
|||
CSTR lat = NULL, |
|||
CSTR lon = NULL, |
|||
CSTR alt = NULL, |
|||
CSTR extID = NULL, |
|||
CSTR src_Name = NULL, |
|||
CSTR src_IP = NULL, |
|||
CSTR src_lat = NULL, |
|||
CSTR src_lon = NULL, |
|||
CSTR src_alt = NULL, |
|||
CSTR src_rot_x = NULL, |
|||
CSTR src_rot_y = NULL, |
|||
CSTR src_rot_z = NULL |
|||
); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleKafka( uint32_t ModuleID ); |
|||
virtual ~argusModuleKafka(); |
|||
|
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
}; |
|||
|
|||
|
|||
#endif |
|||
@ -0,0 +1,323 @@ |
|||
#include "rgooseModuleModemManager.h"
|
|||
|
|||
#define LOG( X ) argusKernelModule::m_pLog->Log( "MOD_MODEM", 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 );\ |
|||
argusKernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "MOD_MODEM", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
argusModuleModemManager::argusModuleModemManager( uint32_t moduleID ): argusKernelModule( moduleID, ARGUS_MODULE_MODEM_MANAGER ), basicThread(){ |
|||
LOG("Creating!"); |
|||
if( checkCmdExists("mmcli") > 0 ){ |
|||
//Modem Manager Exists
|
|||
LOG("Manager OK!"); |
|||
}; |
|||
}; |
|||
|
|||
argusModuleModemManager::~argusModuleModemManager(){ |
|||
|
|||
}; |
|||
|
|||
bool argusModuleModemManager::reloadSettings(){ |
|||
return true; |
|||
}; |
|||
|
|||
bool argusModuleModemManager::startService(){ |
|||
return true; |
|||
}; |
|||
|
|||
bool argusModuleModemManager::stopService( bool force ){ |
|||
return true; |
|||
}; |
|||
|
|||
void argusModuleModemManager::m_fThreadProc( void ){ |
|||
|
|||
}; |
|||
|
|||
void argusModuleModemManager::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
}; |
|||
|
|||
bool argusModuleModemManager::validate(){ |
|||
DBC_MODEM_DATA *tDATA = getModemInfo( 0 ); |
|||
if ( tDATA ) { |
|||
free( tDATA ); |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
void parseModemsInSystem(){ |
|||
"mmcli --list-modems"; |
|||
|
|||
}; |
|||
|
|||
typedef enum E_CFG_TAG_ID{ |
|||
CFG_GENERAL = 0, |
|||
CFG_HARDWARE = 1, |
|||
CFG_SYSTEM, |
|||
CFG_STATUS, |
|||
CFG_MODES, |
|||
CFG_BANDS, |
|||
CFG_IP, |
|||
CFG_EPS, |
|||
CFG_3GPP, |
|||
CFG_SIM, |
|||
CFG_BEARER, |
|||
CFG_COUNT |
|||
}CFG_TAG_ID; |
|||
|
|||
const CSTR cfg_tags[]={ |
|||
"General", |
|||
"Hardware", |
|||
"System", |
|||
"Status", |
|||
"Modes", |
|||
"Bands", |
|||
"IP", |
|||
"3GPP EPS", |
|||
"3GPP", |
|||
"SIM", |
|||
"Bearer" |
|||
}; |
|||
|
|||
DBC_MODEM_DATA *argusModuleModemManager::getModemInfo( uint32_t modem_id ){ |
|||
char tB[1024]; |
|||
char expBuf[1024]; |
|||
FILE * fd = NULL; |
|||
CFG_TAG_ID cMode = CFG_GENERAL; |
|||
DBC_MODEM_DATA * retVal = (DBC_MODEM_DATA *)malloc(sizeof(DBC_MODEM_DATA)); |
|||
|
|||
if ( retVal != NULL ) { |
|||
memset( retVal, 0 , sizeof(DBC_MODEM_DATA)); |
|||
sprintf( tB, "mmcli --modem=%d", modem_id ); |
|||
fd = popen( tB, "r"); |
|||
if (fd!= NULL ) { |
|||
retVal->modem_id = modem_id; |
|||
while ( !feof( fd )) { |
|||
fgets( (CSTR)tB, 1024, fd ); |
|||
trim( tB ); |
|||
if( strstr(tB, "error:" ) != NULL){ |
|||
free( retVal ); |
|||
retVal = NULL; |
|||
break; |
|||
}; |
|||
LOG(tB); |
|||
strncpy( expBuf, tB, 1024 ); |
|||
CArray *CA = explode( ':', expBuf ); |
|||
if( CA ){ |
|||
if( CA->size() ){ |
|||
for( int ii = CFG_GENERAL; ii < CFG_COUNT; ii++ ){ |
|||
if( strstr( CA->at(0), cfg_tags[ii] ) != NULL ){ |
|||
cMode = (CFG_TAG_ID) ii; |
|||
break; |
|||
}; |
|||
}; |
|||
switch( cMode ){ |
|||
case CFG_GENERAL:{ |
|||
//LOG("GEN");
|
|||
if ( strstr( CA->at(0), "device id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->dbus_dev_id, CA->at(1), 64 ); |
|||
retVal->dbus_dev_id[64] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_HARDWARE:{ |
|||
//LOG("HW");
|
|||
if ( strstr( tB, "manufacturer") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->hw_manufac, CA->at(1), 64); |
|||
retVal->hw_manufac[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "model") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_model, CA->at(1), 64); |
|||
retVal->hw_model[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "h/w revision") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_revision, CA->at(1), 64); |
|||
retVal->hw_revision[64] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "revision") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_version, CA->at(1), 32); |
|||
retVal->hw_revision[32] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "equipment id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->hw_id, CA->at(1), 32); |
|||
retVal->hw_id[32] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_SYSTEM:{ |
|||
//LOG("SYS");
|
|||
if ( strstr( tB, "ports") != NULL ) { |
|||
trim(CA->at(1)); |
|||
CArray *CZ = explode( ':', CA->at(1) ); |
|||
if ( CZ ) { |
|||
int CP = 0; |
|||
for (int z=0; z< CZ->size(); z++) { |
|||
if ( strstr(CZ->at(z),"(at)")!= NULL ) { |
|||
if (CP == 0 ) { |
|||
retVal->at_uart_id = 1;//getUartIdByDevice();
|
|||
} else { |
|||
retVal->at_uart_id_aux = 2; |
|||
}; |
|||
CP++; |
|||
}; |
|||
if (CP == 2) break; |
|||
}; |
|||
delete( CZ ); |
|||
}; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_STATUS:{ |
|||
//LOG("STAT");
|
|||
if ( strstr( tB, "power state") != NULL ) { |
|||
if ( strstr(CA->at(1),"on") ) { |
|||
retVal->power[0] = 'E'; |
|||
retVal->power[1]=(char)0; |
|||
} else { |
|||
retVal->power[0] = 'D'; |
|||
retVal->power[1]=(char)0; |
|||
}; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "state") != NULL ) { |
|||
if ( strstr(CA->at(1),"registered") ) { |
|||
retVal->status[0]='R'; |
|||
retVal->status[1]=(char)0; |
|||
} else { |
|||
}; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "access tech") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->conmection_tech, CA->at(1), 5); |
|||
retVal->conmection_tech[5] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "signal quality") != NULL ) { |
|||
trim(CA->at(1)); |
|||
retVal->signal = atoi(CA->at(1)); |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_MODES:{ |
|||
//LOG("MOD");
|
|||
//if ( strstr( CA->at(0), "current") != NULL ) {
|
|||
// trim(CA->at(1));
|
|||
// strncpy( retVal->hw_manufac, CA->at(1), 64);
|
|||
// retVal->hw_manufac[64] = (char)0;
|
|||
// break;
|
|||
//};
|
|||
break; |
|||
}; |
|||
case CFG_IP:{ |
|||
//LOG("IP");
|
|||
break; |
|||
}; |
|||
case CFG_EPS:{ |
|||
//LOG("EPS");
|
|||
break; |
|||
}; |
|||
case CFG_3GPP:{ |
|||
// LOG("3GPP");
|
|||
if ( strstr( tB, "imei") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy( retVal->imei, CA->at(1), 16); |
|||
retVal->imei[16] = (char)0; |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "operator id") != NULL ) { |
|||
trim(CA->at(1)); |
|||
retVal->operator_id = atoi(CA->at(1)); |
|||
break; |
|||
}; |
|||
if ( strstr( tB, "registration") != NULL ) { |
|||
trim(CA->at(1)); |
|||
strncpy(retVal->registration, CA->at(1), 64); |
|||
retVal->registration[64] = (char)0; |
|||
break; |
|||
}; |
|||
break; |
|||
}; |
|||
case CFG_SIM:{ |
|||
// LOG("SIM");
|
|||
break; |
|||
}; |
|||
case CFG_BEARER:{ |
|||
// LOG("BEAR");
|
|||
break; |
|||
}; |
|||
//default: LOG("UNK");
|
|||
}; |
|||
} else { |
|||
LOG("No CA Parts!"); |
|||
}; |
|||
delete( CA ); |
|||
} else { |
|||
LOG("No CA!"); |
|||
}; |
|||
}; |
|||
fclose(fd); |
|||
}; |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
if ( retVal ) { |
|||
char ttB[256]; |
|||
sprintf(ttB, "Modem ID: [%d]", retVal->modem_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW Manufac: [%s]", retVal->hw_manufac); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW Model: [%s]", retVal->hw_model); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem HW id: [%s]", retVal->hw_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Revision id: [%s]", retVal->hw_revision); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Revision Version: [%s]", retVal->hw_version); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem DBus id: [%s]", retVal->dbus_dev_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem IMEI: [%s]", retVal->imei); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Access Tech: [%s]", retVal->conmection_tech); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Operator: [%d]", retVal->operator_id); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Power: [%s]", retVal->power); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Registration: [%s]", retVal->registration); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Signal Power: [%d%%]", retVal->signal); |
|||
LOG(ttB); |
|||
sprintf(ttB, "Modem Status: [%s]", retVal->status); |
|||
LOG(ttB); |
|||
}; |
|||
#endif
|
|||
return retVal; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,24 @@ |
|||
#ifndef __ARGUS_MODULE_MODEM_MANAGER_HEADER__ |
|||
#define __ARGUS_MODULE_MODEM_MANAGER_HEADER__ |
|||
|
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
|
|||
class argusModuleModemManager: public argusKernelModule, public basicThread { |
|||
private: |
|||
DBC_MODEM_DATA * getModemInfo( uint32_t modem_id ); |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleModemManager( uint32_t moduleID ); |
|||
~argusModuleModemManager(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,602 @@ |
|||
#include "rgooseModuleOnvifObserver.h"
|
|||
#include "mojoKernel.h"
|
|||
//#include "rgooseHardwareResourceNetworkProvider.h"
|
|||
|
|||
#define SEARCH_REQUEST_STRING "<?xml version=\"1.0\" encoding=\"UTF-8\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"><e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header><e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
|
|||
#define SEARCH_REQUEST_STRING2323 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
|
|||
"<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \ |
|||
"<SOAP:Header>\n" \ |
|||
"<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \ |
|||
"<wsa:Action>\n" \ |
|||
"http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \ |
|||
"</wsa:Action>\n" \ |
|||
"<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \ |
|||
"</SOAP:Header>\n" \ |
|||
"<SOAP:Body>\n" \ |
|||
"<DISCOVERY:Probe>\n" \ |
|||
"<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \ |
|||
"</DISCOVERY:Probe>\n" \ |
|||
"</SOAP:Body>\n" \ |
|||
"</SOAP:Envelope>\r\n\r\n" |
|||
#define HTTP_OK "200 OK"
|
|||
|
|||
/******************************************************************
|
|||
** Action Defines * |
|||
*******************************************************************/ |
|||
#define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
|
|||
"HOST: %s:%u\r\n" \ |
|||
"SOAPACTION:\"%s#%s\"\r\n" \ |
|||
"CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\ |
|||
"Content-Length: %d \r\n\r\n" |
|||
|
|||
#define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
|
|||
"<s:Envelope xmlns:s=" \ |
|||
"\"http://schemas.xmlsoap.org/soap/envelope/\" " \ |
|||
"s:encodingStyle=" \ |
|||
"\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \ |
|||
"<s:Body>\r\n" \ |
|||
"<u:%s xmlns:u=\"%s\">\r\n%s" \ |
|||
"</u:%s>\r\n" \ |
|||
"</s:Body>\r\n" \ |
|||
"</s:Envelope>\r\n" |
|||
|
|||
#define PORT_MAPPING_LEASE_TIME "63072000" //two year
|
|||
|
|||
#define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
|
|||
"<NewExternalPort>%u</NewExternalPort>\r\n"\ |
|||
"<NewProtocol>%s</NewProtocol>\r\n" \ |
|||
"<NewInternalPort>%u</NewInternalPort>\r\n"\ |
|||
"<NewInternalClient>%s</NewInternalClient>\r\n" \ |
|||
"<NewEnabled>1</NewEnabled>\r\n" \ |
|||
"<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \ |
|||
"<NewLeaseDuration>" \ |
|||
PORT_MAPPING_LEASE_TIME \ |
|||
"</NewLeaseDuration>\r\n" |
|||
|
|||
|
|||
|
|||
#define LOG( X ) argusKernelModule::m_pLog->Log( "MOD_ONVIF", 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 );\ |
|||
argusKernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "MOD_ONVIF", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
argusModuleOnvifObserver::argusModuleOnvifObserver( uint32_t ModuleID ): argusKernelModule( ModuleID, ARGUS_MODULE_ONVIF_OBSERVER ), basicThread(){ |
|||
m_bEnabled = false; |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
|
|||
m_bCurrentNIF = 0; |
|||
m_bProbeIsActive = false; |
|||
m_bDetached = false; |
|||
#ifdef __linux__
|
|||
m_bWSAOK = true; |
|||
#else
|
|||
m_bWSAOK = false; |
|||
WORD wVersionRequested; |
|||
WSADATA wsaData; |
|||
int err; |
|||
wVersionRequested = MAKEWORD(2, 2); |
|||
err = WSAStartup(wVersionRequested, &wsaData); |
|||
if (err != 0){ |
|||
LOG_ERROR("WSAStartup failed with error"); |
|||
} else m_bWSAOK = true; |
|||
#endif
|
|||
}; |
|||
|
|||
argusModuleOnvifObserver::~argusModuleOnvifObserver(){ |
|||
if( !m_bDetached ) stopService( true ); |
|||
}; |
|||
|
|||
bool argusModuleOnvifObserver::startService(){ |
|||
LOG("Starting Service!"); |
|||
if( !m_bWSAOK ) return false; |
|||
m_bEnabled = reloadSettings(); |
|||
return init(); |
|||
}; |
|||
|
|||
bool argusModuleOnvifObserver::stopService( bool force ){ |
|||
m_bEnabled = false; |
|||
if( !m_bDetached ) m_bDetached = uninit(); |
|||
if( m_bDetached ) { |
|||
//Clear Results
|
|||
m_mResultProtector.lock(); |
|||
if (m_vResultPool.size()){ // Clear structures
|
|||
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){ |
|||
free(*index); |
|||
}; |
|||
m_vResultPool.clear(); |
|||
}; |
|||
m_mResultProtector.unlock(); |
|||
}; |
|||
return m_bDetached; |
|||
}; |
|||
|
|||
void argusModuleOnvifObserver::m_fThreadProc(){ |
|||
int socketFD; |
|||
int RetVal; |
|||
struct sockaddr_in r_address; |
|||
bool bOptVal; |
|||
int bOptLen; |
|||
int iOptLen; |
|||
uint16_t bCounterTO = 600; // 3 second
|
|||
char rBuffer[MAX_BUFF_SIZE]; |
|||
#ifdef DEBUG
|
|||
char tB[128]; |
|||
LOG("Module Started!"); |
|||
#endif
|
|||
m_bDetached = false; |
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
if ( m_bEnabled ) { |
|||
if ( m_bProbeIsActive ) { |
|||
if( socketFD > -1 ){ |
|||
if( bCounterTO-- ){ |
|||
memset( rBuffer, 0, MAX_BUFF_SIZE ); |
|||
#ifdef DEBUG_EXTRA
|
|||
struct sockaddr src_addr; |
|||
socklen_t addrlen = sizeof( src_addr ); |
|||
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen ); |
|||
if ( RetVal > -1 ) { |
|||
sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr)); |
|||
LOG( tB ); |
|||
}; |
|||
#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
|
|||
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL ); |
|||
#endif
|
|||
if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) { |
|||
LOG_ERROR("Error acures while reading UDP package"); |
|||
close( socketFD ); |
|||
m_bProbeIsActive = false; |
|||
continue; // Error ocured but continue to next address
|
|||
}; |
|||
if( RetVal < 1 ){ |
|||
//LOG("SLEEP");
|
|||
SLEEP(DEFAULT_THREAD_SLEEP_TIME); |
|||
continue; // No Data - wait to next time
|
|||
}; |
|||
OBSERVER_RESULT *tResult = parseXML( rBuffer ); |
|||
if ( tResult ) { |
|||
m_mResultProtector.lock(); |
|||
m_vResultPool.push_back( tResult ); |
|||
m_mResultProtector.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished!"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished with unrecognized data!"); |
|||
#endif
|
|||
}; |
|||
continue; //To Fetch Another responces
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe Finished By Timeout!"); |
|||
#endif
|
|||
}; |
|||
#ifdef __linux__
|
|||
close(socketFD); |
|||
#else
|
|||
closesocket(socketFD); |
|||
#endif
|
|||
}; |
|||
m_bProbeIsActive = false; |
|||
//Sleep 5 minutes if done all scans
|
|||
if ( m_bCurrentNIF == 0 ){ |
|||
for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
} else { |
|||
// start new probe;
|
|||
m_mNIFMUTEX.lock(); |
|||
if ( m_vNIFIPS.size() ) { |
|||
#ifdef DEBUG
|
|||
sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) ); |
|||
LOG( tB ); |
|||
#endif
|
|||
socketFD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); |
|||
if( socketFD > -1 ){ |
|||
CSTR send_buff = (CSTR)SEARCH_REQUEST_STRING; |
|||
r_address.sin_family = AF_INET; |
|||
r_address.sin_port = htons(HTTPMU_HOST_PORT); |
|||
r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF)); |
|||
bOptVal = true; |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Set Broadcast Flag"); |
|||
#endif
|
|||
RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen ); |
|||
struct group_req req; |
|||
req.gr_interface = 0; |
|||
memcpy( &req.gr_group, &r_address, sizeof(r_address)); |
|||
RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) ); |
|||
/*
|
|||
#include <stdio.h>
|
|||
#include <stdint.h>
|
|||
#include <string.h>
|
|||
#include <sys/types.h>
|
|||
#include <sys/socket.h>
|
|||
#include <linux/in.h>
|
|||
#include <linux/if_ether.h>
|
|||
#include <net/if.h>
|
|||
#include <errno.h>
|
|||
// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
|
|||
static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){ |
|||
|
|||
#if MCAST_JOIN_GROUP
|
|||
struct group_req req; |
|||
req.gr_interface = 0; |
|||
if (grplen > sizeof(req.gr_group)) { |
|||
errno = EINVAL; |
|||
return -1; |
|||
} |
|||
memcpy(&req.gr_group, grp, grplen); |
|||
return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req))); |
|||
#else
|
|||
switch (grp->sa_family) { |
|||
case AF_INET: { |
|||
struct ip_mreq mreq; |
|||
struct ifreq ifreq; |
|||
memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr)); |
|||
mreq.imr_interface.s_addr = htonl(INADDR_ANY); |
|||
return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, |
|||
&mreq, sizeof(mreq))); |
|||
} |
|||
#ifdef IPV6
|
|||
#ifndef IPV6_JOIN_GROUP // APIv0 compatibility
|
|||
#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
|
|||
#endif
|
|||
case AF_INET6: { |
|||
struct ipv6_mreq mreq6; |
|||
memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr)); |
|||
mreq6.ipv6mr_interface = 0; |
|||
return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6))); |
|||
} |
|||
#endif
|
|||
default: |
|||
errno = EAFNOSUPPORT; |
|||
return -1; |
|||
} |
|||
#endif
|
|||
}; |
|||
|
|||
int main(int argc, char **argv){ |
|||
|
|||
int fd = socket(AF_INET, SOCK_DGRAM, 0); |
|||
struct sockaddr_in grp; |
|||
bzero(&grp, sizeof(grp)); |
|||
grp.sin_family = AF_INET; |
|||
grp.sin_addr.s_addr = inet_addr("224.0.0.1");; |
|||
if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp))) |
|||
perror("Join multicast group failed"); |
|||
} |
|||
|
|||
*/ |
|||
|
|||
//The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
|
|||
|
|||
if ( RetVal > -1 ) { |
|||
LOG_ERROR("Setting Socked as Broadcasted Error!"); |
|||
}; |
|||
|
|||
//
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; // IPv4
|
|||
tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
|
|||
tServerAddr.sin_port = htons(rand( 20000, 40000)); |
|||
|
|||
// Bind the socket with the server address
|
|||
RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr)); |
|||
if ( RetVal > -1 ) { |
|||
LOG_ERROR("Bind Socked Error!"); |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Sending Probe Request"); |
|||
#endif
|
|||
RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in)); |
|||
if ( RetVal > -1 ) { |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tB, "Sent %d Bytes of %d", RetVal, strlen(send_buff) ); |
|||
LOG( tB ); |
|||
#endif
|
|||
|
|||
#ifdef __linux__
|
|||
fcntl( socketFD, F_SETFL, fcntl( socketFD, F_GETFL, 0) | O_NONBLOCK ); |
|||
#else
|
|||
u_long val = 1; |
|||
ioctlsocket( socketFD, FIONBIO, &val );//none block
|
|||
#endif
|
|||
bCounterTO = 600; |
|||
m_bProbeIsActive = true; |
|||
} else { |
|||
#ifdef DEBUG
|
|||
// Failure to send probe package
|
|||
LOG_ERROR("Error in sending Probe Request"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
close(socketFD); |
|||
#else
|
|||
closesocket(socketFD); |
|||
#endif
|
|||
}; |
|||
}; |
|||
m_bCurrentNIF++; |
|||
if ( m_bCurrentNIF == m_vNIFIPS.size() ) m_bCurrentNIF = 0; |
|||
}; |
|||
m_mNIFMUTEX.unlock(); |
|||
}; |
|||
} else { |
|||
//Sleep 3 Sec.
|
|||
for( int i=300; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|||
}; |
|||
}; |
|||
m_bDetached = true; |
|||
}; |
|||
|
|||
void argusModuleOnvifObserver::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
if(!m_bEnabled) { |
|||
#ifdef DEBUG
|
|||
LOG("Module Disabled!"); |
|||
#endif
|
|||
return; |
|||
} |
|||
if( Evt == NULL ) return; |
|||
|
|||
}; |
|||
|
|||
bool argusModuleOnvifObserver::reloadSettings(){ |
|||
m_mNIFMUTEX.lock(); |
|||
if( m_vNIFIPS.size() ) { |
|||
for ( vectorCSTR::iterator idx=m_vNIFIPS.begin(); idx < m_vNIFIPS.end(); idx++ ) free(*idx); |
|||
m_vNIFIPS.clear(); |
|||
}; |
|||
m_mNIFMUTEX.unlock(); |
|||
if( m_pKernel != NULL ){ |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS"); |
|||
#endif
|
|||
argusHardwareManager *tHWM = m_pKernel->getHardwareManager(); |
|||
if( tHWM != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 11"); |
|||
#endif
|
|||
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK ); |
|||
if( rIDS != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 22"); |
|||
#endif
|
|||
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){ |
|||
#ifdef DEBUG
|
|||
LOG("Check IPS 33"); |
|||
#endif
|
|||
argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx ); |
|||
if( tRES != NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Have NIF Resource"); |
|||
#endif
|
|||
CSTR BC = tRES->getBroadcast(); |
|||
if( BC!= NULL ) { |
|||
#ifdef DEBUG
|
|||
LOG("Have BC Address"); |
|||
LOG(BC); |
|||
#endif
|
|||
m_mNIFMUTEX.lock(); |
|||
m_vNIFIPS.push_back( BC ); |
|||
m_mNIFMUTEX.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("NIF defined"); |
|||
#endif
|
|||
} |
|||
#ifdef DEBUG
|
|||
else { |
|||
LOG("NO BC Address"); |
|||
} |
|||
#endif
|
|||
; |
|||
} else { |
|||
LOG_ERROR("Cannot Get Resource!"); |
|||
}; |
|||
}; |
|||
delete( rIDS ); |
|||
} else { |
|||
LOG("No Networks Detected!"); |
|||
m_bEnabled = false; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("No HW Manager"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Kernel Not Assigned!" ); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Default Probe"); |
|||
LOG( HTTPMU_HOST_ADDRESS ); |
|||
#endif
|
|||
CSTR tBC = (CSTR) malloc(16); |
|||
if ( tBC ) { |
|||
sprintf(tBC, HTTPMU_HOST_ADDRESS ); |
|||
m_mNIFMUTEX.lock(); |
|||
m_vNIFIPS.push_back( tBC ); |
|||
m_mNIFMUTEX.unlock(); |
|||
} else { |
|||
LOG_ERROR("Malloc Error!"); |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
OBSERVER_RESULT *argusModuleOnvifObserver::parseXML( CSTR data ){ |
|||
OBSERVER_RESULT *retVal = NULL; |
|||
if( data!=NULL ){ |
|||
XMLResults tParseResults; |
|||
XMLNode response = XMLNode::parseString( data, "root", &tParseResults ); |
|||
if( tParseResults.error ){ |
|||
char tBuffer[CTEXT]; |
|||
sprintf( tBuffer, "XML Parse Error %d at %d:%d", tParseResults.error, tParseResults.nLine, tParseResults.nColumn ); |
|||
LOG_ERROR( tBuffer ); |
|||
} else { |
|||
if( response.isEmpty() ){ |
|||
LOG_ERROR("The device descripe XML file is not a valid XML file. Cann't find root element."); |
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG("Probe XML parsed"); |
|||
#endif
|
|||
XMLNode Body = response.getChildNode( "Body", 0 ); |
|||
if(!Body.isEmpty()){ |
|||
LOG("Have Body elm"); |
|||
XMLNode ProbeMatches = Body.getChildNode("ProbeMatches", 0);//EndpointReference
|
|||
if(!ProbeMatches.isEmpty()) { |
|||
LOG("Have ProbeMathes elm"); |
|||
int matches = ProbeMatches.nChildNode(); |
|||
for(int index=0;index<matches;index++){ |
|||
XMLNode ProbeMatch = ProbeMatches.getChildNode("ProbeMatch", index); |
|||
retVal = (OBSERVER_RESULT *)malloc(sizeof(OBSERVER_RESULT)); |
|||
if( retVal != NULL ){ |
|||
memset( retVal, 0, sizeof(OBSERVER_RESULT)); |
|||
if(!ProbeMatch.isEmpty()) { |
|||
LOG("Have ProbeMatch elm"); |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("EndpointReference", 0); |
|||
if(!node.isEmpty()) { |
|||
LOG("Have ProbeMatch EndpointReference"); |
|||
XMLNode nod = node.getChildNode("Address", 0); |
|||
if(!nod.isEmpty()){ |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", nod.getText(0)); |
|||
CArray *tArr; |
|||
LOG("Before Explode"); |
|||
tArr = explode(':',tBuf); |
|||
LOG("After Explode"); |
|||
for(int j=0; j<tArr->size(); j++) { |
|||
if( strlen(tArr->at(j)) > 10 ) { |
|||
sprintf(retVal->RefID,"%s",tArr->at(j)); |
|||
break; |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
delete(tArr); |
|||
|
|||
}; |
|||
}; |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("Types", 0); |
|||
if( !node.isEmpty() ){ |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", node.getText(0)); |
|||
CArray *tArr; |
|||
tArr = explode(' ',tBuf); |
|||
sprintf(retVal->Type,"%s",tArr->at(0)); |
|||
tArr->clear(); |
|||
delete(tArr); |
|||
} |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("Scopes", 0); |
|||
char tBuf[CLOG]; |
|||
sprintf( tBuf,"%s", node.getText(0) ); |
|||
CArray *tArr = explode(' ',tBuf); |
|||
if( tArr->size() > 0 ) { |
|||
for( int index = 0; index < tArr->size(); index++){ |
|||
char *tPtr; |
|||
if( tPtr = strstr( tArr->at(index), "mac/" ) ){ |
|||
sprintf(retVal->MAC,"%s",tPtr+4); |
|||
}; |
|||
if( tPtr = strstr( tArr->at(index), "hardware/" ) ){ |
|||
sprintf(retVal->Hardware,"%s",tPtr+9); |
|||
}; |
|||
if( tPtr = strstr( tArr->at(index), "name/" ) ){ |
|||
sprintf(retVal->Name,"%s",tPtr+5); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "MAC/")) { |
|||
sprintf(retVal->MAC, "%s", tPtr + 4); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "HARDWARE/")) { |
|||
sprintf(retVal->Hardware, "%s", tPtr + 9); |
|||
}; |
|||
if (tPtr = strstr(tArr->at(index), "NAME/")) { |
|||
sprintf(retVal->Name, "%s", tPtr + 5); |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
}; |
|||
delete(tArr); |
|||
} |
|||
{ |
|||
XMLNode node = ProbeMatch.getChildNode("XAddrs", 0); |
|||
char tBuf[CLOG]; |
|||
sprintf(tBuf,"%s", node.getText(0)); |
|||
CArray *tArr; |
|||
tArr = explode(' ',tBuf); |
|||
if( tArr->size() > 0 ) { |
|||
for(int index=0; index < tArr->size(); index++) { |
|||
if( strstr( tArr->at(index), "[" ) != NULL ){ |
|||
// IPv6
|
|||
} else{ |
|||
// IPv4
|
|||
sprintf(retVal->XAddrs,"%s",tArr->at(0)); |
|||
}; |
|||
}; |
|||
tArr->clear(); |
|||
}; |
|||
delete(tArr); |
|||
} |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
return retVal; |
|||
}; |
|||
|
|||
|
|||
bool argusModuleOnvifObserver::validate(){ |
|||
m_mResultProtector.lock(); |
|||
if( m_vResultPool.size() ){ // Clear structures
|
|||
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){ |
|||
#ifdef DEBUG
|
|||
char tBuffer[256]; |
|||
sprintf( tBuffer, "Found Camwera [%s] %s", (*index)->XAddrs, (*index)->RefID ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
uint32_t cid = m_pDBC->getCamId( (*index)->RefID ); //isCameraListed( DiscoverResults->at(index)->RefID );
|
|||
if( cid ) { |
|||
#ifdef DEBUG
|
|||
sprintf( tBuffer, "Camera is Listed as %d", cid ); |
|||
LOG( tBuffer ); |
|||
#endif
|
|||
m_pDBC->updateIPCam( m_pKernel->getSiteId(), cid, (*index)->XAddrs );// DiscoverResults->at(index));
|
|||
} else { |
|||
// Uncknown camera - no checking
|
|||
#ifdef DEBUG
|
|||
LOG("Camera is Not Listed"); |
|||
#endif
|
|||
m_pDBC->addIPCam( m_pKernel->getSiteId(), (*index) ); |
|||
}; |
|||
free(*index); |
|||
} |
|||
m_vResultPool.clear(); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Clear Structs Done!"); |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("No Online IP Cameras in Network"); |
|||
#endif
|
|||
}; |
|||
m_mResultProtector.unlock(); |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,88 @@ |
|||
#ifndef __ARGUS_MODULE_ONVIF_OBSERVER_HEADER__ |
|||
#define __ARGUS_MODULE_ONVIF_OBSERVER_HEADER__ |
|||
|
|||
#include "../data/protocol/xmlParser.h" |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
|
|||
|
|||
#pragma warning(disable: 4251) |
|||
|
|||
#define HTTPMU_HOST_ADDRESS "239.255.255.250" |
|||
#define HTTPMU_HOST_PORT 3702 |
|||
|
|||
|
|||
//#define DEBUG_ONVIF_PRINTOUT_MESSAGES |
|||
|
|||
#define DEFAULT_HTTP_PORT 80 |
|||
|
|||
typedef std::vector<OBSERVER_RESULT*> vectorOBSERVER_RESULT; |
|||
|
|||
class argusModuleOnvifObserver; |
|||
|
|||
typedef struct S_PROBE_CTX{ |
|||
int AddressID; |
|||
char IpAddress[16]; |
|||
int Port; |
|||
int socketFD; |
|||
char buff[MAX_BUFF_SIZE + 1]; |
|||
CSTR send_buff; |
|||
CSTR recv_buff; |
|||
struct sockaddr_in r_address; |
|||
bool bOptVal; |
|||
int bOptLen; |
|||
int iOptLen; |
|||
int RetVal; |
|||
int index; |
|||
bool isFinished; |
|||
argusModuleOnvifObserver * observer; |
|||
}PROBE_CTX; |
|||
|
|||
typedef struct S_OBSERVER_CTX{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
PROBE_CTX * context; |
|||
}OBSERVER_CTX; |
|||
|
|||
typedef std::vector<OBSERVER_CTX*> vectorOBSERVER_CTX; |
|||
|
|||
|
|||
class argusModuleOnvifObserver: public argusKernelModule, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
//enumeratorInfo m_vLocalDevices; |
|||
//localIpAddresses m_vIpAddresses; |
|||
|
|||
vectorOBSERVER_RESULT m_vResultPool; |
|||
basicMutex m_mResultProtector; |
|||
basicMutex m_mNIFMUTEX; |
|||
vectorCSTR m_vNIFIPS; |
|||
bool m_bProbeIsActive; |
|||
bool m_bWSAOK; |
|||
uint8_t m_bCurrentNIF; |
|||
|
|||
//PROBE_CTX * init_PROBE_CTX( CSTR ADR, int ID ); |
|||
//bool loadAssignedSources(void); |
|||
//bool startProbe( CSTR IP, int ID ); |
|||
//static void * probeThreadProc(void *); |
|||
OBSERVER_RESULT * parseXML( CSTR data ); |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
|
|||
public: |
|||
explicit argusModuleOnvifObserver( uint32_t moduleID ); |
|||
~argusModuleOnvifObserver(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,46 @@ |
|||
#include "rgooseModuleSSDP.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MOD_SSDP", 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( "MOD_SSDP", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MOD_SSDP", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
argusModuleSSDPAnnouncer::argusModuleSSDPAnnouncer( uint32_t ModuleID ) : argusKernelModule( ModuleID, ARGUS_MODULE_SSDP_ANONCE ){ |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
}; |
|||
|
|||
argusModuleSSDPAnnouncer::~argusModuleSSDPAnnouncer(){ |
|||
}; |
|||
|
|||
void argusModuleSSDPAnnouncer::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|||
|
|||
}; |
|||
|
|||
void argusModuleSSDPAnnouncer::m_fThreadProc( void ){ |
|||
|
|||
}; |
|||
|
|||
bool argusModuleSSDPAnnouncer::reloadSettings(){ |
|||
return false; |
|||
}; |
|||
bool argusModuleSSDPAnnouncer::startService(){ |
|||
return false; |
|||
}; |
|||
bool argusModuleSSDPAnnouncer::stopService( bool force ){ |
|||
return true; |
|||
}; |
|||
bool argusModuleSSDPAnnouncer::validate(){ |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,23 @@ |
|||
#ifndef __ARGUS_MODULE_SSDP_ANNOUNCER_HEADER__ |
|||
#define __ARGUS_MODULE_SSDP_ANNOUNCER_HEADER__ |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
|
|||
|
|||
|
|||
class argusModuleSSDPAnnouncer: public argusKernelModule, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleSSDPAnnouncer( uint32_t moduleID ); |
|||
~argusModuleSSDPAnnouncer(); |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService( bool force = false ); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
}; |
|||
#endif |
|||
@ -0,0 +1,317 @@ |
|||
#include <stdio.h>
|
|||
#include <wchar.h>
|
|||
#include <string.h>
|
|||
#include <stdlib.h>
|
|||
#include <ctype.h>
|
|||
#include <unistd.h>
|
|||
#include <hidapi/hidapi.h>
|
|||
#include "rgooseModuleUSBRelay.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "MOD_USBDC", 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( "MOD_USBDC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "MOD_USBDC", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
|
|||
//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; |
|||
} |
|||
|
|||
|
|||
argusModuleUSBRelay::argusModuleUSBRelay( uint32_t ModuleID ) : argusKernelModule( ModuleID, ARGUS_MODULE_DCBUSB ){ |
|||
|
|||
}; |
|||
|
|||
argusModuleUSBRelay::~argusModuleUSBRelay(){ |
|||
}; |
|||
|
|||
void argusModuleUSBRelay::dispatchEvent( EVENT_CONTAINER *Evt ){ |
|||
|
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,40 @@ |
|||
#ifndef __ARGUS_USB_RELAY_MODULE_HEADER__ |
|||
#define __ARGUS_USB_RELAY_MODULE_HEADER__ |
|||
|
|||
#include "rgooseModule.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 argusModuleUSBRelay: public argusKernelModule { |
|||
private: |
|||
relay_board m_sBoardDef; |
|||
uint32_t m_nNO_CONFIG; |
|||
uint32_t m_nCURRENT_STATE; |
|||
uint32_t m_aCHANNEL_CONFIGS[32]; |
|||
public: |
|||
explicit argusModuleUSBRelay( uint32_t ModuleID ); |
|||
virtual ~argusModuleUSBRelay(); |
|||
virtual void dispatchEvent( EVENT_CONTAINER *Evt ); |
|||
}; |
|||
#endif |
|||
@ -1,95 +1,95 @@ |
|||
#include "heapDebug.h"
|
|||
|
|||
#if !defined( DEBUG ) && !defined( MEM_DEBUG_LOG )
|
|||
size_t getPeakRSS( ){ return 0; }; |
|||
size_t getCurrentRSS( ){ return 0; }; |
|||
#else
|
|||
/**
|
|||
* Returns the peak (maximum so far) resident set size (physical |
|||
* memory use) measured in bytes, or zero if the value cannot be |
|||
* determined on this OS. |
|||
*/ |
|||
size_t getPeakRSS( ) |
|||
{ |
|||
#if defined(_WIN32)
|
|||
/* Windows -------------------------------------------------- */ |
|||
PROCESS_MEMORY_COUNTERS info; |
|||
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); |
|||
return (size_t)info.PeakWorkingSetSize; |
|||
|
|||
#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
|
|||
/* AIX and Solaris ------------------------------------------ */ |
|||
struct psinfo psinfo; |
|||
int fd = -1; |
|||
if ( (fd = open( "/proc/self/psinfo", O_RDONLY )) == -1 ) |
|||
return (size_t)0L; /* Can't open? */ |
|||
if ( read( fd, &psinfo, sizeof(psinfo) ) != sizeof(psinfo) ) |
|||
{ |
|||
close( fd ); |
|||
return (size_t)0L; /* Can't read? */ |
|||
} |
|||
close( fd ); |
|||
return (size_t)(psinfo.pr_rssize * 1024L); |
|||
|
|||
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
|
|||
/* BSD, Linux, and OSX -------------------------------------- */ |
|||
struct rusage rusage; |
|||
getrusage( RUSAGE_SELF, &rusage ); |
|||
#if defined(__APPLE__) && defined(__MACH__)
|
|||
return (size_t)rusage.ru_maxrss; |
|||
#else
|
|||
return (size_t)(rusage.ru_maxrss * 1024L); |
|||
#endif
|
|||
|
|||
#else
|
|||
/* Unknown OS ----------------------------------------------- */ |
|||
return (size_t)0L; /* Unsupported. */ |
|||
#endif
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/**
|
|||
* Returns the current resident set size (physical memory use) measured |
|||
* in bytes, or zero if the value cannot be determined on this OS. |
|||
*/ |
|||
size_t getCurrentRSS( ) |
|||
{ |
|||
#if defined(_WIN32)
|
|||
/* Windows -------------------------------------------------- */ |
|||
PROCESS_MEMORY_COUNTERS info; |
|||
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); |
|||
return (size_t)info.WorkingSetSize; |
|||
|
|||
#elif defined(__APPLE__) && defined(__MACH__)
|
|||
/* OSX ------------------------------------------------------ */ |
|||
struct mach_task_basic_info info; |
|||
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; |
|||
if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO, |
|||
(task_info_t)&info, &infoCount ) != KERN_SUCCESS ) |
|||
return (size_t)0L; /* Can't access? */ |
|||
return (size_t)info.resident_size; |
|||
|
|||
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
|
|||
/* Linux ---------------------------------------------------- */ |
|||
long rss = 0L; |
|||
FILE* fp = NULL; |
|||
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL ) |
|||
return (size_t)0L; /* Can't open? */ |
|||
if ( fscanf( fp, "%*s%ld", &rss ) != 1 ) |
|||
{ |
|||
fclose( fp ); |
|||
return (size_t)0L; /* Can't read? */ |
|||
} |
|||
fclose( fp ); |
|||
return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE); |
|||
|
|||
#else
|
|||
/* AIX, BSD, Solaris, and Unknown OS ------------------------ */ |
|||
return (size_t)0L; /* Unsupported. */ |
|||
#endif
|
|||
} |
|||
|
|||
#include "heapDebug.h"
|
|||
|
|||
#if !defined( DEBUG ) && defined( SKIP_MEM_CHECK )
|
|||
size_t getPeakRSS( ){ return 0; }; |
|||
size_t getCurrentRSS( ){ return 0; }; |
|||
#else
|
|||
/**
|
|||
* Returns the peak (maximum so far) resident set size (physical |
|||
* memory use) measured in bytes, or zero if the value cannot be |
|||
* determined on this OS. |
|||
*/ |
|||
size_t getPeakRSS( ) |
|||
{ |
|||
#if defined(_WIN32)
|
|||
/* Windows -------------------------------------------------- */ |
|||
PROCESS_MEMORY_COUNTERS info; |
|||
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); |
|||
return (size_t)info.PeakWorkingSetSize; |
|||
|
|||
#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
|
|||
/* AIX and Solaris ------------------------------------------ */ |
|||
struct psinfo psinfo; |
|||
int fd = -1; |
|||
if ( (fd = open( "/proc/self/psinfo", O_RDONLY )) == -1 ) |
|||
return (size_t)0L; /* Can't open? */ |
|||
if ( read( fd, &psinfo, sizeof(psinfo) ) != sizeof(psinfo) ) |
|||
{ |
|||
close( fd ); |
|||
return (size_t)0L; /* Can't read? */ |
|||
} |
|||
close( fd ); |
|||
return (size_t)(psinfo.pr_rssize * 1024L); |
|||
|
|||
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
|
|||
/* BSD, Linux, and OSX -------------------------------------- */ |
|||
struct rusage rusage; |
|||
getrusage( RUSAGE_SELF, &rusage ); |
|||
#if defined(__APPLE__) && defined(__MACH__)
|
|||
return (size_t)rusage.ru_maxrss; |
|||
#else
|
|||
return (size_t)(rusage.ru_maxrss * 1024L); |
|||
#endif
|
|||
|
|||
#else
|
|||
/* Unknown OS ----------------------------------------------- */ |
|||
return (size_t)0L; /* Unsupported. */ |
|||
#endif
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/**
|
|||
* Returns the current resident set size (physical memory use) measured |
|||
* in bytes, or zero if the value cannot be determined on this OS. |
|||
*/ |
|||
size_t getCurrentRSS( ) |
|||
{ |
|||
#if defined(_WIN32)
|
|||
/* Windows -------------------------------------------------- */ |
|||
PROCESS_MEMORY_COUNTERS info; |
|||
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) ); |
|||
return (size_t)info.WorkingSetSize; |
|||
|
|||
#elif defined(__APPLE__) && defined(__MACH__)
|
|||
/* OSX ------------------------------------------------------ */ |
|||
struct mach_task_basic_info info; |
|||
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; |
|||
if ( task_info( mach_task_self( ), MACH_TASK_BASIC_INFO, |
|||
(task_info_t)&info, &infoCount ) != KERN_SUCCESS ) |
|||
return (size_t)0L; /* Can't access? */ |
|||
return (size_t)info.resident_size; |
|||
|
|||
#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
|
|||
/* Linux ---------------------------------------------------- */ |
|||
long rss = 0L; |
|||
FILE* fp = NULL; |
|||
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL ) |
|||
return (size_t)0L; /* Can't open? */ |
|||
if ( fscanf( fp, "%*s%ld", &rss ) != 1 ) |
|||
{ |
|||
fclose( fp ); |
|||
return (size_t)0L; /* Can't read? */ |
|||
} |
|||
fclose( fp ); |
|||
return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE); |
|||
|
|||
#else
|
|||
/* AIX, BSD, Solaris, and Unknown OS ------------------------ */ |
|||
return (size_t)0L; /* Unsupported. */ |
|||
#endif
|
|||
} |
|||
|
|||
#endif // DEBUG
|
|||
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue