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.

145 lines
4.8 KiB

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