You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __PROTOCOL_DEFENDER_HEADER__
  2. #define __PROTOCOL_DEFENDER_HEADER__
  3. #ifdef __linux__
  4. #include <features.h>
  5. #endif
  6. #include "protocolHTTP.h"
  7. #include <time.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/types.h>
  11. #include <sys/timeb.h>
  12. #include <string>
  13. #include "../../components/base/basicFunctionality.h"
  14. #include "../../components/base/basicLogCollection.h"
  15. #include "../../components/base/basicSettingsProvider.h"
  16. #include "xmlParser.h"
  17. #define PROTOCOL_TYPE_3D true
  18. #define PROTOCOL_TYPE_2D false
  19. #define SERVICE_URL_TEMPLATE_NOTIFY "/simple-event/notify"
  20. #define SERVICE_URL_TEMPLATE_STATUS "/sensors/lidar%dd/%s/status"
  21. #define SERVICE_URL_TEMPLATE_FAULT "/sensors/lidar%dd/%s/fault"
  22. #define SERVICE_URL_TEMPLATE_EVENT "/sensors/lidar%dd/%s/event"
  23. #define SERVICE_URL_TEMPLATE_CALLBACK "/sensors/lidar%dd/%s/httpcallback"
  24. #define SERVICE_URL_TEMPLATE_CLOCKSYNC "/sensors/lidar%dd/%s/clocksync"
  25. #define DFSL_HARDWARE_TYPE "DFSL_3D_LIDAR"
  26. #ifdef PRU_SLAVE
  27. #define DFSL_SOURCE_NAME "SLAVE_SENSOR"
  28. #else
  29. #define DFSL_SOURCE_NAME "MASTER_SENSOR"
  30. #endif
  31. typedef enum E_DEFENDER_CATEGORY{
  32. DC_STATUS = 0,
  33. DC_ALARM = 1,
  34. DC_ERROR = 2
  35. } defenderCategoryTypes;
  36. #define DFSL_DEVICE "DFSL Lidar Sensor"
  37. #define DFSL_DEFAULT_LOCATION "{\"point\": [ 32.878, 35.999 ], \"heading\": 128, \"area\": [] }"
  38. #define DFSL_SensorSourceDto "{ \"providerId\": \"%s\", \"sensorNodeId\" : \"%s\", \"sensorId\": \"%s\" }"
  39. #define DFSL_LidarTargetDto "{ \"id\": %d, \"AZ\": %d, \"EL\": %d, \"Range\": %d, \"Width\": %d }"
  40. #define DFSL_LocationDto "{\"point\": [ %s ],\"area\": [ %s ] }"
  41. #define DFSL_SE_ENVELOPE "{\"id\": %d,\"category\": \"%s\",\"severity\": \"%s\"," \
  42. "\"receivedTS\": \"%s\",\"lastChangeTS\": \"%s\"," \
  43. "\"startTime\": \"%s\",\"endTime\": \"%s\", \"location\": %s, " \
  44. "\"radius\": 0, \"data\": [ %s ]}"
  45. #define PACKAGE_SE_DATA_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s," \
  46. " \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"targets\": [%s] }"
  47. #define PACKAGE_SE_DATA_STATUS_ELEMENT "{\"description\": \"%s\", \"created\": \"%s\", \"source\": %s, " \
  48. " \"name\": \"%s\", \"type\": \"%s\", \"eventId\": \"%s\", \"payload\": [%s] }"
  49. #define OS_SCANNER_NAME_SIZE 128
  50. #define OS_CEP_ADDRESS_SIZE 16
  51. /**
  52. * TODO: Add class description
  53. *
  54. * @author gagua
  55. */
  56. class protocolRGoose : public protocolHTTP {
  57. private:
  58. basicLogCollection *m_pLog;
  59. config_setting_t *m_pSettings;
  60. int m_nScannerDimentions;
  61. CSTR m_pScannerName;
  62. CSTR m_pServerIP;
  63. int m_nServerPort;
  64. bool m_bCurrentStatus;
  65. CSTR buildURL( CSTR templ, int dim, CSTR devID );
  66. CSTR buildUniqID( void );
  67. bool buildClockSyncPackage( unsigned char *Buffer, int &BufferSize );
  68. bool buildCallBackPackage( unsigned char *Buffer, int &BufferSize, CSTR CallBackPath );
  69. bool buildStatusPackage( unsigned char *Buffer, int &BufferSize, bool Status );
  70. bool buildFaultPackage( unsigned char *Buffer, int &BufferSize, unsigned char Type, CSTR Description );
  71. bool buildEvent2DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle, int Range, int Width );
  72. bool buildEvent3DPackage( unsigned char *Buffer, int &BufferSize, CSTR msgUID, int targetID, int Angle1, int Angle2, int Range );
  73. CSTR assembleStatusData( bool StatusOK );
  74. CSTR assembleFaultData( uint8_t Code, CSTR Desc );
  75. CSTR assembleTargetData( int targetID, int Range, int Width, int Azimuth, int Elevation = 0 );
  76. size_t assembleDefenderJSON( CSTR Buffer, defenderCategoryTypes Type, uint8_t Severity, CSTR Location, CSTR Data );
  77. protected:
  78. virtual bool packetHandler( protocolPackage *Package );
  79. public:
  80. // Constructor
  81. explicit protocolRGoose( config_setting_t *Settings = NULL );
  82. //ToDo: change Serial to BaseClass of some kind of socket
  83. //protocolSafeShore( clientPort *SocketTransport, config_setting_t *Settings = NULL );
  84. // Destructor
  85. virtual ~protocolRGoose();
  86. virtual bool init(){ return true; };
  87. bool Alarm2D( int Angle, int Range, int Width, int ID=0 );
  88. bool Alarm3D( int Angle1, int Angle2, int Range, int ID=0 );
  89. bool VisibilityChanged( bool Worsened );
  90. bool StatusUpdate( void );
  91. void SetStatus( bool A ){ m_bCurrentStatus = A; };
  92. bool ErrorReporting( int lvl, CSTR Descr );
  93. bool StartTimeSynch( void );
  94. #ifdef __linux__
  95. //bool FinishTimeSynch( unsigned long long *tVals );
  96. #else
  97. //bool FinishTimeSynch( unsigned __int64 *tVals );
  98. #endif
  99. bool SetupCallBack( CSTR CallBackPath );
  100. void setProtocolType( bool DeviceIs3D );
  101. void setScannerName( CSTR Name );
  102. };
  103. #ifdef __linux__
  104. unsigned long long getSHTimeValue( void );
  105. #else
  106. unsigned __int64 getSHTimeValue( void );
  107. #endif
  108. #endif