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.

2880 lines
103 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
5 years ago
​
5 years ago
​
5 years ago
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
5 years ago
​
5 years ago
​
5 years ago
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseDBConnector.h"
  2. #define LOG( X ) m_pLog->Log( "ADBC", this, X )
  3. #ifdef DEBUG
  4. #define LOG_ERROR( X ) {\
  5. char _tBfrErrMSG2w34[256];\
  6. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  7. m_pLog->Log( "ADBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "ADBC", this, _LOG_ERROR, X );
  11. #endif
  12. argusDBC *argusDBC::_instance = NULL;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. argusDBC* argusDBC::getInstance( config_setting_t * Settings ) {
  17. // check if the instance has been created yet
  18. if( 0 == _instance ){
  19. // if not, then create it
  20. _instance = new argusDBC( Settings );
  21. };
  22. // return the single instance
  23. return _instance;
  24. };
  25. argusDBC::argusDBC( config_setting_t * Settings ){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
  28. m_bIsConnected = false;
  29. m_nSiteID = 0;
  30. m_pDatabase = NULL;
  31. };
  32. argusDBC::~argusDBC(){
  33. m_bIsConnected = false;
  34. if( m_pDatabase != NULL ) delete( m_pDatabase );
  35. m_pDatabase = NULL;
  36. _instance = NULL;
  37. };
  38. bool argusDBC::connect( void ){
  39. config_setting_t * tSetting;
  40. m_bIsConnected = false;
  41. if( m_pSettings!= NULL ) {
  42. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  43. if( tSetting == NULL ){
  44. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  45. config_setting_set_string( tSetting, "localhost" );
  46. basicSettingsProvider::getInstance()->compromise();
  47. LOG("No DB Host Setting! Using default!");
  48. };
  49. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  50. tSetting = config_setting_get_member( m_pSettings, "DATABASE_NAME" );
  51. if( tSetting == NULL ){
  52. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  53. config_setting_set_string( tSetting, "dfsl_gunter" );
  54. basicSettingsProvider::getInstance()->compromise();
  55. LOG("No DB Database Setting! Using default!");
  56. };
  57. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  58. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  59. if( tSetting == NULL ){
  60. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  61. config_setting_set_string( tSetting, "dbroot" );
  62. basicSettingsProvider::getInstance()->compromise();
  63. LOG("No DB User Setting! Using default!");
  64. };
  65. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  66. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  67. if( tSetting == NULL ){
  68. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  69. config_setting_set_string( tSetting, "123567" );
  70. basicSettingsProvider::getInstance()->compromise();
  71. LOG("No DB Password Setting! Using default!");
  72. };
  73. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  74. basicSettingsProvider::getInstance()->validate();
  75. m_pDatabase = new MySQL_Connector();
  76. if( m_pDatabase == NULL )return false;
  77. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  78. } else {
  79. LOG_ERROR("No Settings Provided!");
  80. };
  81. return m_bIsConnected;
  82. };
  83. bool argusDBC::cleanResources( uint32_t SiteID, uint32_t ServerNodeID, bool all ){
  84. if(m_bIsConnected) {
  85. char tQBuf[MAX_PATH_LEN];
  86. if( all ) {
  87. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `site_id`=%d AND `node_id`=%d", SiteID, ServerNodeID );
  88. } else {
  89. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `site_id`=%d AND `node_id`=%d AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", SiteID, ServerNodeID );
  90. };
  91. #ifdef DEBUG
  92. LOG(tQBuf);
  93. #endif
  94. m_pDatabase->SilentQuery( tQBuf );
  95. return true;
  96. };
  97. return false;
  98. };
  99. bool argusDBC::updateIPCam( uint32_t SiteID, CSTR uuid, CSTR Addr ){
  100. if(m_bIsConnected) {
  101. char tQBuf[MAX_PATH_LEN];
  102. char tIpBuf[CTEXT];
  103. char *tPos;
  104. char *tPos2;
  105. #ifdef DEBUG
  106. LOG("Cam Update");
  107. #endif
  108. tPos = strstr(Addr,"//");
  109. if( tPos != NULL ) {
  110. tPos2 = strstr( tPos + 2,"/");
  111. if( tPos2 != NULL ) {
  112. int len;
  113. len = tPos2 - tPos - 2;
  114. strncpy(tIpBuf,tPos + 2,len);
  115. tIpBuf[len] = (char)0;
  116. } else {
  117. LOG_ERROR("Pos 2 - err");
  118. tIpBuf[0] = (char)0;
  119. };
  120. } else {
  121. LOG_ERROR("Pos 0 - err");
  122. tIpBuf[0] = (char)0;
  123. };
  124. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s' AND `site_id`=%d",
  125. Addr,
  126. tIpBuf,
  127. uuid,
  128. SiteID
  129. );
  130. #ifdef DEBUG
  131. LOG(tQBuf);
  132. #endif
  133. m_pDatabase->SilentQuery( tQBuf );
  134. return true;
  135. };
  136. return false;
  137. };
  138. bool argusDBC::updateIPCam( uint32_t SiteID, uint32_t CamID, CSTR Addr ){
  139. if(m_bIsConnected) {
  140. char tQBuf[MAX_PATH_LEN];
  141. char tIpBuf[CTEXT];
  142. char *tPos;
  143. char *tPos2;
  144. #ifdef DEBUG
  145. LOG("Cam Update");
  146. #endif
  147. tPos = strstr(Addr,"//");
  148. if( tPos != NULL ) {
  149. tPos2 = strstr( tPos + 2,"/");
  150. if( tPos2 != NULL ) {
  151. int len;
  152. len = tPos2 - tPos - 2;
  153. strncpy(tIpBuf,tPos + 2,len);
  154. tIpBuf[len] = (char)0;
  155. } else {
  156. LOG_ERROR("Pos 2 - err");
  157. tIpBuf[0] = (char)0;
  158. };
  159. } else {
  160. LOG_ERROR("Pos 0 - err");
  161. tIpBuf[0] = (char)0;
  162. };
  163. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE id=%d AND `site_id`=%d",
  164. Addr,
  165. tIpBuf,
  166. CamID,
  167. SiteID
  168. );
  169. #ifdef DEBUG
  170. LOG(tQBuf);
  171. #endif
  172. m_pDatabase->SilentQuery( tQBuf );
  173. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  174. #ifdef DEBUG
  175. LOG(tQBuf);
  176. #endif
  177. m_pDatabase->SilentQuery( tQBuf );
  178. return true;
  179. };
  180. return false;
  181. };
  182. bool argusDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  183. if(m_bIsConnected) {
  184. char tQBuf[1024];
  185. char tIpBuf[32];
  186. char tProto[32];
  187. char tPath[CTEXT];
  188. char *tPos;
  189. char *tPos2;
  190. #ifdef DEBUG
  191. LOG("Add New Camera Record");
  192. #endif
  193. memcpy( tProto, tPtr->XAddrs, 5 );
  194. tProto[5] = (char)0;
  195. if( tProto[4] == ':') tProto[4] = (char)0;
  196. memset( tPath, 0, CTEXT );
  197. tPos = strstr(tPtr->XAddrs,"//");
  198. if( tPos != NULL ) {
  199. tPos2 = strstr( tPos + 2,"/");
  200. if( tPos2 != NULL ) {
  201. int len,len2,len3;
  202. len = tPos2 - tPos - 2;
  203. strncpy( tIpBuf, tPos + 2, len);
  204. tIpBuf[len] = (char)0;
  205. strncpy( tPath, tPos + 2 + len, CTEXT );
  206. } else {
  207. LOG_ERROR("Pos 2 - err");
  208. tIpBuf[0] = (char)0;
  209. };
  210. } else {
  211. LOG_ERROR("Pos 0 - err");
  212. tIpBuf[0] = (char)0;
  213. };
  214. sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'",
  215. tPtr->RefID,
  216. //tPtr->XAddrs,
  217. tPath,
  218. tIpBuf,
  219. SiteID,
  220. tPtr->MAC,
  221. tPtr->Hardware,
  222. tPtr->Name,
  223. tProto,
  224. //tPtr->XAddrs,
  225. tIpBuf
  226. );
  227. #ifdef DEBUG
  228. LOG(tQBuf);
  229. #endif
  230. m_pDatabase->SilentQuery( tQBuf );
  231. return true;
  232. };
  233. return false;
  234. };
  235. bool argusDBC::addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr ){
  236. if(m_bIsConnected) {
  237. char tQBuf[1024];
  238. char tIpBuf[32];
  239. char tProto[32];
  240. char tPath[CTEXT];
  241. char *tPos;
  242. char *tPos2;
  243. #ifdef DEBUG
  244. LOG("Add New Camera Record");
  245. #endif
  246. memcpy( tProto, tPtr->XAddrs, 5 );
  247. tProto[5] = (char)0;
  248. if( tProto[4] == ':') tProto[4] = (char)0;
  249. memset( tPath, 0, CTEXT );
  250. tPos = strstr(tPtr->XAddrs,"//");
  251. if( tPos != NULL ) {
  252. tPos2 = strstr( tPos + 2,"/");
  253. if( tPos2 != NULL ) {
  254. int len,len2,len3;
  255. len = tPos2 - tPos - 2;
  256. strncpy( tIpBuf, tPos + 2, len);
  257. tIpBuf[len] = (char)0;
  258. strncpy( tPath, tPos + 2 + len, CTEXT );
  259. } else {
  260. LOG_ERROR("Pos 2 - err");
  261. tIpBuf[0] = (char)0;
  262. };
  263. } else {
  264. LOG_ERROR("Pos 0 - err");
  265. tIpBuf[0] = (char)0;
  266. };
  267. sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'",
  268. tPtr->RefID,
  269. //tPtr->XAddrs,
  270. tPath,
  271. tIpBuf,
  272. SiteID,
  273. tPtr->MAC,
  274. tPtr->Hardware,
  275. tPtr->Name,
  276. tProto,
  277. //tPtr->XAddrs,
  278. tIpBuf
  279. );
  280. #ifdef DEBUG
  281. LOG(tQBuf);
  282. #endif
  283. m_pDatabase->SilentQuery( tQBuf );
  284. return true;
  285. };
  286. return false;
  287. };
  288. bool argusDBC::transferEvtToArchive( uint32_t SECONDS ){
  289. if(m_bIsConnected) {
  290. if( SECONDS > 0 ) {
  291. char tQBuf[CTEXT];
  292. sprintf(tQBuf,"INSERT INTO events_archive ( SELECT * FROM events_cloud ec WHERE ec.ts < ( UNIX_TIMESTAMP(NOW()) - %d ) ); DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - %d );", SECONDS, SECONDS );
  293. m_pDatabase->SilentQuery( tQBuf );
  294. return true;
  295. };
  296. };
  297. return false;
  298. }
  299. bool argusDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  300. if(m_bIsConnected){
  301. char tQBuf[CTEXT];
  302. AAssoc *result;
  303. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  304. result = m_pDatabase->Query( tQBuf );
  305. if( result!= NULL ) {
  306. DBC_EVT_DATA *tPtr;
  307. Assoc *cArr;
  308. for(int i=0;i<result->size();i++) {
  309. cArr = result->at(i);
  310. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  311. if( tPtr!= NULL ) {
  312. Assoc::iterator it;
  313. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  314. it = cArr->find("id");
  315. if( it != cArr->end() ){
  316. tPtr->id = atoi( it->second.c_str() );
  317. };
  318. it = cArr->find("node_id");
  319. if( it != cArr->end() ){
  320. tPtr->node_id = atoi( it->second.c_str() );
  321. };
  322. it = cArr->find("uuid");
  323. if( it != cArr->end() ){
  324. strncpy( tPtr->uuid, it->second.c_str(),64 );
  325. };
  326. it = cArr->find("ts");
  327. if( it != cArr->end() ){
  328. tPtr->ts_s = atoi( it->second.c_str() );
  329. };
  330. it = cArr->find("ts_ms");
  331. if( it != cArr->end() ){
  332. tPtr->ts_ms = atoi( it->second.c_str() );
  333. };
  334. it = cArr->find("evt_type");
  335. if( it != cArr->end() ){
  336. tPtr->type = atoi( it->second.c_str() );
  337. };
  338. it = cArr->find("range_digital");
  339. if( it != cArr->end() ){
  340. tPtr->range_digital = atoi( it->second.c_str() );
  341. };
  342. it = cArr->find("azimuth");
  343. if( it != cArr->end() ){
  344. tPtr->az = atof( it->second.c_str() );
  345. };
  346. it = cArr->find("elevation");
  347. if( it != cArr->end() ){
  348. tPtr->el = atof( it->second.c_str() );
  349. };
  350. it = cArr->find("range");
  351. if( it != cArr->end() ){
  352. tPtr->ra = atof( it->second.c_str() );
  353. };
  354. it = cArr->find("area");
  355. if( it != cArr->end() ){
  356. tPtr->area = atof( it->second.c_str() );
  357. };
  358. it = cArr->find("lat");
  359. if( it != cArr->end() ){
  360. tPtr->lat = atof( it->second.c_str() );
  361. };
  362. it = cArr->find("lon");
  363. if( it != cArr->end() ){
  364. tPtr->lon = atof( it->second.c_str() );
  365. };
  366. it = cArr->find("alt");
  367. if( it != cArr->end() ){
  368. tPtr->alt = atof( it->second.c_str() );
  369. };
  370. it = cArr->find("ref_uuid");
  371. if( it != cArr->end() ){
  372. strncpy( tPtr->uuid, it->second.c_str(),64 );
  373. };
  374. char tBuf[CLOG];
  375. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  376. LOG(tBuf);
  377. VR.push_back(tPtr);
  378. };
  379. };
  380. };
  381. deleteResult( result );
  382. if( m_pDatabase->isConnected()) return true;
  383. };
  384. return false;
  385. };
  386. bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  387. if(m_bIsConnected){
  388. char tQBuf[CTEXT];
  389. AAssoc *result;
  390. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  391. #ifdef DEBUG
  392. LOG(tQBuf);
  393. #endif
  394. result = m_pDatabase->Query( tQBuf );
  395. if( result!= NULL ) {
  396. DBC_CAM_DATA *tVal;
  397. Assoc *cArr;
  398. for(int i=0;i<result->size();i++) {
  399. LOG("Cam_Record!");
  400. cArr = result->at(i);
  401. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  402. if( tVal!= NULL ) {
  403. Assoc::iterator it;
  404. memset(tVal,0,sizeof(DBC_CAM_DATA));
  405. it = cArr->find("id");
  406. if( it != cArr->end() ){
  407. tVal->id = atoi( it->second.c_str() );
  408. };
  409. it = cArr->find("site_id");
  410. if( it != cArr->end() ){
  411. tVal->site_id = atoi( it->second.c_str() );
  412. };
  413. it = cArr->find("node_id");
  414. if( it != cArr->end() ){
  415. tVal->node_id = atoi( it->second.c_str() );
  416. };
  417. it = cArr->find("online");
  418. if( it != cArr->end() ){
  419. tVal->online = (bool) atoi( it->second.c_str() );
  420. };
  421. it = cArr->find("type");
  422. if( it != cArr->end() ){
  423. tVal->type = atoi( it->second.c_str() );
  424. };
  425. it = cArr->find("name");
  426. if( it != cArr->end() ){
  427. strncpy( tVal->name, it->second.c_str(), 64 );
  428. };
  429. it = cArr->find("hardware");
  430. if( it != cArr->end() ){
  431. strncpy( tVal->hardware, it->second.c_str(), 32 );
  432. };
  433. it = cArr->find("status");
  434. if( it != cArr->end() ){
  435. tVal->status = atoi( it->second.c_str() );
  436. };
  437. it = cArr->find("session");
  438. if( it != cArr->end() ){
  439. strncpy( tVal->session, it->second.c_str(), 32 );
  440. };
  441. it = cArr->find("protocol");
  442. if( it != cArr->end() ){
  443. tVal->protocol = atoi( it->second.c_str() );
  444. };
  445. it = cArr->find("protocol_aux");
  446. if( it != cArr->end() ){
  447. strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
  448. };
  449. it = cArr->find("lat");
  450. if( it != cArr->end() ){
  451. tVal->lat = atof( it->second.c_str() );
  452. };
  453. it = cArr->find("lon");
  454. if( it != cArr->end() ){
  455. tVal->lon = atof( it->second.c_str() );
  456. };
  457. it = cArr->find("alt");
  458. if( it != cArr->end() ){
  459. tVal->alt = atof( it->second.c_str() );
  460. };
  461. it = cArr->find("picth");
  462. if( it != cArr->end() ){
  463. tVal->pitch = atof( it->second.c_str() );
  464. };
  465. it = cArr->find("roll");
  466. if( it != cArr->end() ){
  467. tVal->roll = atof( it->second.c_str() );
  468. };
  469. it = cArr->find("yaw");
  470. if( it != cArr->end() ){
  471. tVal->yaw = atof( it->second.c_str() );
  472. };
  473. it = cArr->find("imager_type");
  474. if( it != cArr->end() ){
  475. tVal->imager_type = atoi( it->second.c_str() );
  476. };
  477. it = cArr->find("min_f");
  478. if( it != cArr->end() ){
  479. tVal->min_f = atof( it->second.c_str() );
  480. };
  481. it = cArr->find("max_f");
  482. if( it != cArr->end() ){
  483. tVal->max_f = atof( it->second.c_str() );
  484. };
  485. it = cArr->find("access_login");
  486. if( it != cArr->end() ){
  487. strncpy( tVal->username, it->second.c_str(), 16 );
  488. };
  489. it = cArr->find("access_pass");
  490. if( it != cArr->end() ){
  491. strncpy( tVal->password, it->second.c_str(), 16 );
  492. };
  493. it = cArr->find("uuid");
  494. if( it != cArr->end() ){
  495. strncpy( tVal->uuid, it->second.c_str(), CLOG );
  496. };
  497. it = cArr->find("mac");
  498. if( it != cArr->end() ){
  499. strncpy( tVal->mac, it->second.c_str(), 16 );
  500. };
  501. it = cArr->find("ip");
  502. if( it != cArr->end() ){
  503. strncpy( tVal->ip, it->second.c_str(), 16 );
  504. };
  505. it = cArr->find("port");
  506. if( it != cArr->end() ){
  507. tVal->port = atoi( it->second.c_str() );
  508. };
  509. it = cArr->find("onvif_access");
  510. if( it != cArr->end() ){
  511. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  512. };
  513. it = cArr->find("onvif_ctrl");
  514. if( it != cArr->end() ){
  515. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  516. };
  517. it = cArr->find("ptz_token");
  518. if( it != cArr->end() ){
  519. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  520. };
  521. VR.push_back(tVal);
  522. };
  523. //??
  524. //delete(cArr);
  525. };
  526. };
  527. deleteResult( result );
  528. #ifdef DEBUG
  529. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  530. LOG(tQBuf);
  531. #endif
  532. if( m_pDatabase->isConnected()) return true;
  533. };
  534. return false;
  535. };
  536. DBC_INT_LIST *argusDBC::listNodes( uint32_t SiteID ){
  537. DBC_INT_LIST * tVal = NULL;
  538. if(m_bIsConnected){
  539. char tQBuf[CTEXT];
  540. AAssoc *result;
  541. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0", SiteID );
  542. #ifdef DEBUG
  543. //LOG(tQBuf);
  544. #endif
  545. result = m_pDatabase->Query( tQBuf );
  546. if( result!= NULL ) {
  547. if( result->size() > 0 ) {
  548. Assoc *cArr;
  549. tVal = new DBC_INT_LIST();
  550. if( tVal != NULL ) {
  551. Assoc::iterator it;
  552. for(int i=0;i<result->size();i++) {
  553. cArr = result->at(i);
  554. it = cArr->find("id");
  555. if( it != cArr->end() ){
  556. tVal->push_back( atoi( it->second.c_str() ));
  557. };
  558. };
  559. };
  560. };
  561. };
  562. deleteResult( result );
  563. };
  564. return tVal;
  565. };
  566. DBC_INT_LIST *argusDBC::listNewNodes( uint32_t SiteID, DBC_INT_LIST *old_ids ){
  567. DBC_INT_LIST * tVal = NULL;
  568. char tParam[CTEXT];
  569. //memset( tParam, 0, CTEXT );
  570. sprintf(tParam,"0");
  571. if( old_ids != NULL ) {
  572. char tBuffer[CTEXT];
  573. for(int i = 0; i< old_ids->size(); i++ ) {
  574. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  575. strncpy( tParam, tBuffer, CTEXT );
  576. };
  577. };
  578. if( m_bIsConnected ){
  579. char tQBuf[CTEXT];
  580. AAssoc *result;
  581. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam );
  582. #ifdef DEBUG
  583. //LOG(tQBuf);
  584. #endif
  585. result = m_pDatabase->Query( tQBuf );
  586. if( result!= NULL ) {
  587. if( result->size() > 0 ) {
  588. Assoc *cArr;
  589. tVal = new DBC_INT_LIST();
  590. if( tVal != NULL ) {
  591. Assoc::iterator it;
  592. for(int i=0;i<result->size();i++) {
  593. cArr = result->at(i);
  594. it = cArr->find("id");
  595. if( it != cArr->end() ){
  596. tVal->push_back( atoi( it->second.c_str() ));
  597. };
  598. };
  599. };
  600. };
  601. };
  602. deleteResult( result );
  603. };
  604. return tVal;
  605. };
  606. DBC_INT_LIST *argusDBC::listCamMediaStreams( uint32_t CAMID ){
  607. DBC_INT_LIST * tVal = NULL;
  608. if(m_bIsConnected){
  609. char tQBuf[CTEXT];
  610. AAssoc *result;
  611. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  612. #ifdef DEBUG
  613. LOG(tQBuf);
  614. #endif
  615. result = m_pDatabase->Query( tQBuf );
  616. if( result!= NULL ) {
  617. if( result->size() > 0 ) {
  618. Assoc *cArr;
  619. tVal = new DBC_INT_LIST();
  620. if( tVal != NULL ) {
  621. Assoc::iterator it;
  622. for(int i=0;i<result->size();i++) {
  623. cArr = result->at(i);
  624. it = cArr->find("id");
  625. if( it != cArr->end() ){
  626. tVal->push_back( atoi( it->second.c_str() ));
  627. };
  628. };
  629. };
  630. };
  631. };
  632. deleteResult( result );
  633. };
  634. return tVal;
  635. };
  636. DBC_NODE_DATA *argusDBC::getNodeData( uint32_t ID ){
  637. DBC_NODE_DATA * tVal = NULL;
  638. if(m_bIsConnected){
  639. char tQBuf[CTEXT];
  640. AAssoc *result;
  641. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  642. #ifdef DEBUG
  643. LOG(tQBuf);
  644. #endif
  645. result = m_pDatabase->Query( tQBuf );
  646. if( result!= NULL ) {
  647. if( result->size() > 0 ) {
  648. Assoc *cArr;
  649. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  650. if( tVal != NULL ) {
  651. Assoc::iterator it;
  652. cArr = result->at(0);
  653. it = cArr->find("id");
  654. if( it != cArr->end() ){
  655. tVal->node_id = atoi( it->second.c_str() );
  656. };
  657. it = cArr->find("type");
  658. if( it != cArr->end() ){
  659. tVal->type = (ARGUS_NODE_TYPE) atoi( it->second.c_str() );
  660. };
  661. it = cArr->find("aux_id");
  662. if( it != cArr->end() ){
  663. tVal->aux_id = atoi( it->second.c_str() );
  664. };
  665. it = cArr->find("name");
  666. if( it != cArr->end() ){
  667. sprintf( tVal->name, it->second.c_str() );
  668. };
  669. it = cArr->find("ts_s");
  670. if( it != cArr->end() ){
  671. tVal->tss = atoi( it->second.c_str() );
  672. };
  673. it = cArr->find("ts_ms");
  674. if( it != cArr->end() ){
  675. tVal->tsm = atoi( it->second.c_str() );
  676. };
  677. it = cArr->find("online");
  678. if( it != cArr->end() ){
  679. tVal->online = (bool)atoi( it->second.c_str() );
  680. };
  681. };
  682. };
  683. };
  684. deleteResult( result );
  685. };
  686. return tVal;
  687. };
  688. DBC_APF_DATA *argusDBC::getAPFData( uint32_t APFID ){
  689. DBC_APF_DATA * tVal = NULL;
  690. if(m_bIsConnected){
  691. char tQBuf[CTEXT];
  692. AAssoc *result;
  693. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  694. #ifdef DEBUG
  695. LOG(tQBuf);
  696. #endif
  697. result = m_pDatabase->Query( tQBuf );
  698. if( result!= NULL ) {
  699. if( result->size() > 0 ) {
  700. Assoc *cArr;
  701. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  702. if( tVal != NULL ) {
  703. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  704. Assoc::iterator it;
  705. cArr = result->at(0);
  706. it = cArr->find("mode");
  707. if( it != cArr->end() ){
  708. sprintf( tVal->mode, it->second.c_str() );
  709. };
  710. it = cArr->find("port");
  711. if( it != cArr->end() ){
  712. tVal->port = atoi( it->second.c_str() );
  713. };
  714. it = cArr->find("lat");
  715. if( it != cArr->end() ){
  716. tVal->lat = atof( it->second.c_str() );
  717. };
  718. it = cArr->find("lon");
  719. if( it != cArr->end() ){
  720. tVal->lon = atof( it->second.c_str() );
  721. };
  722. it = cArr->find("alt");
  723. if( it != cArr->end() ){
  724. tVal->alt = atof( it->second.c_str() );
  725. };
  726. it = cArr->find("roll");
  727. if( it != cArr->end() ){
  728. tVal->roll = atof( it->second.c_str() );
  729. };
  730. it = cArr->find("pitch");
  731. if( it != cArr->end() ){
  732. tVal->pitch = atof( it->second.c_str() );
  733. };
  734. it = cArr->find("yaw");
  735. if( it != cArr->end() ){
  736. tVal->yaw = atof( it->second.c_str() );
  737. };
  738. it = cArr->find("dx");
  739. if( it != cArr->end() ){
  740. tVal->dx = atof( it->second.c_str() );
  741. };
  742. it = cArr->find("dy");
  743. if( it != cArr->end() ){
  744. tVal->dy = atof( it->second.c_str() );
  745. };
  746. it = cArr->find("dz");
  747. if( it != cArr->end() ){
  748. tVal->dz = atof( it->second.c_str() );
  749. };
  750. };
  751. };
  752. };
  753. deleteResult( result );
  754. };
  755. return tVal;
  756. };
  757. DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
  758. DBC_FH_DATA * tVal = NULL;
  759. if(m_bIsConnected){
  760. char tQBuf[CTEXT];
  761. AAssoc *result;
  762. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  763. #ifdef DEBUG
  764. LOG(tQBuf);
  765. #endif
  766. result = m_pDatabase->Query( tQBuf );
  767. if( result!= NULL ) {
  768. if( result->size() > 0 ) {
  769. Assoc *cArr;
  770. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  771. if( tVal != NULL ) {
  772. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  773. Assoc::iterator it;
  774. cArr = result->at(0);
  775. it = cArr->find("name");
  776. if( it != cArr->end() ){
  777. sprintf( tVal->name, it->second.c_str() );
  778. };
  779. it = cArr->find("lat");
  780. if( it != cArr->end() ){
  781. tVal->lat = atof( it->second.c_str() );
  782. };
  783. it = cArr->find("lon");
  784. if( it != cArr->end() ){
  785. tVal->lon = atof( it->second.c_str() );
  786. };
  787. it = cArr->find("alt");
  788. if( it != cArr->end() ){
  789. tVal->alt = atof( it->second.c_str() );
  790. };
  791. it = cArr->find("dc_module_id");
  792. if( it != cArr->end() ){
  793. tVal->dc_id = atoi( it->second.c_str() );
  794. };
  795. it = cArr->find("uart_id");
  796. if( it != cArr->end() ){
  797. tVal->uart_id = atoi( it->second.c_str() );
  798. };
  799. };
  800. };
  801. };
  802. deleteResult( result );
  803. };
  804. return tVal;
  805. };
  806. DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
  807. DBC_SITE_DATA * tVal = NULL;
  808. if(m_bIsConnected){
  809. char tQBuf[CTEXT];
  810. AAssoc *result;
  811. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  812. #ifdef DEBUG
  813. LOG(tQBuf);
  814. #endif
  815. result = m_pDatabase->Query( tQBuf );
  816. if( result!= NULL ) {
  817. if( result->size() > 0 ) {
  818. Assoc *cArr;
  819. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  820. if( tVal != NULL ) {
  821. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  822. Assoc::iterator it;
  823. cArr = result->at(0);
  824. it = cArr->find("account_id");
  825. if( it != cArr->end() ){
  826. tVal->account_id = atoi( it->second.c_str() );
  827. };
  828. it = cArr->find("name");
  829. if( it != cArr->end() ){
  830. sprintf( tVal->name, it->second.c_str() );
  831. };
  832. it = cArr->find("server_ident");
  833. if( it != cArr->end() ){
  834. sprintf( tVal->ident, it->second.c_str() );
  835. };
  836. it = cArr->find("anchor_lat");
  837. if( it != cArr->end() ){
  838. tVal->lat = atof( it->second.c_str() );
  839. };
  840. it = cArr->find("anchor_lon");
  841. if( it != cArr->end() ){
  842. tVal->lon = atof( it->second.c_str() );
  843. };
  844. it = cArr->find("anchor_alt");
  845. if( it != cArr->end() ){
  846. tVal->alt = atof( it->second.c_str() );
  847. };
  848. it = cArr->find("hemisphere");
  849. if( it != cArr->end() ){
  850. tVal->SH = ( it->second.c_str()[0] == 'S' );
  851. };
  852. it = cArr->find("map_id");
  853. if( it != cArr->end() ){
  854. tVal->map_id = atoi( it->second.c_str() );
  855. };
  856. };
  857. };
  858. };
  859. deleteResult( result );
  860. };
  861. return tVal;
  862. };
  863. DBC_TARGET_FLITER_DATA *argusDBC::getTargetFilterData( uint32_t ID ){
  864. DBC_TARGET_FLITER_DATA * tVal = NULL;
  865. if(m_bIsConnected){
  866. char tQBuf[CTEXT];
  867. AAssoc *result;
  868. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  869. #ifdef DEBUG
  870. LOG(tQBuf);
  871. #endif
  872. result = m_pDatabase->Query( tQBuf );
  873. if( result!= NULL ) {
  874. if( result->size() > 0 ) {
  875. Assoc *cArr;
  876. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  877. if( tVal != NULL ) {
  878. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  879. Assoc::iterator it;
  880. tVal->id = ID;
  881. cArr = result->at(0);
  882. it = cArr->find("type");
  883. if( it != cArr->end() ){
  884. tVal->type = atoi( it->second.c_str() );
  885. };
  886. it = cArr->find("aux_id");
  887. if( it != cArr->end() ){
  888. tVal->aux_id = atoi( it->second.c_str() );
  889. };
  890. };
  891. };
  892. };
  893. deleteResult( result );
  894. };
  895. return tVal;
  896. };
  897. DBC_LRF_DATA *argusDBC::getLRFData( uint32_t ID ){
  898. DBC_LRF_DATA * tVal = NULL;
  899. if(m_bIsConnected){
  900. char tQBuf[CTEXT];
  901. AAssoc *result;
  902. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  903. #ifdef DEBUG
  904. LOG(tQBuf);
  905. #endif
  906. result = m_pDatabase->Query( tQBuf );
  907. if( result!= NULL ) {
  908. if( result->size() > 0 ) {
  909. Assoc *cArr;
  910. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  911. if( tVal != NULL ) {
  912. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  913. Assoc::iterator it;
  914. tVal->id = ID;
  915. cArr = result->at(0);
  916. it = cArr->find("data_status");
  917. if( it != cArr->end() ){
  918. tVal->data_status = atoi( it->second.c_str() );
  919. };
  920. it = cArr->find("serial");
  921. if( it != cArr->end() ){
  922. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  923. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  924. };
  925. it = cArr->find("version");
  926. if( it != cArr->end() ){
  927. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  928. tVal->version[sizeof(tVal->version)-1]=(char)0;
  929. };
  930. it = cArr->find("lat");
  931. if( it != cArr->end() ){
  932. tVal->lat = atof( it->second.c_str() );
  933. };
  934. it = cArr->find("lon");
  935. if( it != cArr->end() ){
  936. tVal->lon = atof( it->second.c_str() );
  937. };
  938. it = cArr->find("alt");
  939. if( it != cArr->end() ){
  940. tVal->alt = atof( it->second.c_str() );
  941. };
  942. it = cArr->find("pitch");
  943. if( it != cArr->end() ){
  944. tVal->pitch = atof( it->second.c_str() );
  945. };
  946. it = cArr->find("yaw");
  947. if( it != cArr->end() ){
  948. tVal->yaw = atof( it->second.c_str() );
  949. };
  950. it = cArr->find("roll");
  951. if( it != cArr->end() ){
  952. tVal->roll = atof( it->second.c_str() );
  953. };
  954. it = cArr->find("uart_id");
  955. if( it != cArr->end() ){
  956. tVal->uart_id = atoi( it->second.c_str() );
  957. };
  958. it = cArr->find("device_id");
  959. if( it != cArr->end() ){
  960. tVal->device_id = atoi( it->second.c_str() );
  961. };
  962. it = cArr->find("ip_address");
  963. if( it != cArr->end() ){
  964. sprintf( tVal->master_host, it->second.c_str() );
  965. };
  966. it = cArr->find("aux_ip_address");
  967. if( it != cArr->end() ){
  968. sprintf( tVal->slave_host, it->second.c_str() );
  969. };
  970. it = cArr->find("port");
  971. if( it != cArr->end() ){
  972. tVal->master_port = atoi( it->second.c_str() );
  973. };
  974. it = cArr->find("aux_port");
  975. if( it != cArr->end() ){
  976. tVal->slave_port = atoi( it->second.c_str() );
  977. };
  978. it = cArr->find("auto_draw");
  979. if( it != cArr->end() ){
  980. tVal->auto_draw = atoi( it->second.c_str() );
  981. };
  982. it = cArr->find("filter_id");
  983. if( it != cArr->end() ){
  984. tVal->filter_id = atoi( it->second.c_str() );
  985. };
  986. //it = cArr->find("enabled_lrf");
  987. //if( it != cArr->end() ){
  988. // tVal->enabled_lrf = atoi( it->second.c_str() );
  989. //};
  990. it = cArr->find("max_range");
  991. if( it != cArr->end() ){
  992. tVal->max_range = atof( it->second.c_str() );
  993. };
  994. it = cArr->find("base_shift");
  995. if( it != cArr->end() ){
  996. tVal->base_shift = atoi( it->second.c_str() );
  997. };
  998. it = cArr->find("mirror_shift");
  999. if( it != cArr->end() ){
  1000. tVal->mirror_shift = atoi( it->second.c_str() );
  1001. };
  1002. it = cArr->find("detection_profile_id");
  1003. if( it != cArr->end() ){
  1004. tVal->detection_profile_id = atoi( it->second.c_str() );
  1005. };
  1006. it = cArr->find("width_table_id");
  1007. if( it != cArr->end() ){
  1008. tVal->width_table_id = atoi( it->second.c_str() );
  1009. };
  1010. it = cArr->find("zoom_table_id");
  1011. if( it != cArr->end() ){
  1012. tVal->zoom_table_id = atoi( it->second.c_str() );
  1013. };
  1014. it = cArr->find("embd_cam");
  1015. if( it != cArr->end() ){
  1016. tVal->embd_cam = atoi( it->second.c_str() );
  1017. };
  1018. it = cArr->find("embd_cam_auto");
  1019. if( it != cArr->end() ){
  1020. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1021. };
  1022. it = cArr->find("embd_dc");
  1023. if( it != cArr->end() ){
  1024. tVal->embd_dc = atoi( it->second.c_str() );
  1025. };
  1026. it = cArr->find("autoreset");
  1027. if( it != cArr->end() ){
  1028. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1029. };
  1030. };
  1031. };
  1032. };
  1033. deleteResult( result );
  1034. };
  1035. return tVal;
  1036. };
  1037. uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
  1038. uint8_t RetVal = 0;
  1039. if(m_bIsConnected){
  1040. char tQBuf[CTEXT];
  1041. AAssoc *result;
  1042. sprintf(tQBuf, "SELECT * FROM `lrf_sensors` WHERE `id`=%d", ID );
  1043. #ifdef DEBUG
  1044. LOG(tQBuf);
  1045. #endif
  1046. result = m_pDatabase->Query( tQBuf );
  1047. if( result!= NULL ) {
  1048. if( result->size() > 0 ) {
  1049. Assoc *cArr;
  1050. Assoc::iterator it;
  1051. cArr = result->at(0);
  1052. it = cArr->find("data_status");
  1053. if( it != cArr->end() ){
  1054. RetVal = atoi( it->second.c_str() );
  1055. };
  1056. };
  1057. };
  1058. deleteResult( result );
  1059. };
  1060. return RetVal;
  1061. };
  1062. uint8_t argusDBC::getLRFPushedCMD( uint32_t ID ){
  1063. uint8_t RetVal = 0;
  1064. if(m_bIsConnected){
  1065. char tQBuf[CTEXT];
  1066. AAssoc *result;
  1067. sprintf(tQBuf, "SELECT `pushed_cmd` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1068. #ifdef DEBUG
  1069. //LOG(tQBuf);
  1070. #endif
  1071. result = m_pDatabase->Query( tQBuf );
  1072. if( result!= NULL ) {
  1073. if( result->size() > 0 ) {
  1074. Assoc *cArr;
  1075. Assoc::iterator it;
  1076. cArr = result->at(0);
  1077. it = cArr->find("pushed_cmd");
  1078. if( it != cArr->end() ){
  1079. RetVal = atoi( it->second.c_str() );
  1080. };
  1081. };
  1082. };
  1083. deleteResult( result );
  1084. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0 WHERE `id`=%d", ID );
  1085. m_pDatabase->SilentQuery( tQBuf );
  1086. };
  1087. return RetVal;
  1088. };
  1089. DBC_INT_LIST *argusDBC::listModules( uint32_t ServerID ){
  1090. DBC_INT_LIST * tVal = NULL;
  1091. if(m_bIsConnected){
  1092. char tQBuf[CTEXT];
  1093. AAssoc *result;
  1094. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1095. #ifdef DEBUG
  1096. LOG(tQBuf);
  1097. #endif
  1098. result = m_pDatabase->Query( tQBuf );
  1099. if( result!= NULL ) {
  1100. if( result->size() > 0 ) {
  1101. Assoc *cArr;
  1102. tVal = new DBC_INT_LIST();
  1103. if( tVal != NULL ) {
  1104. Assoc::iterator it;
  1105. for(int i=0;i<result->size();i++) {
  1106. cArr = result->at(i);
  1107. it = cArr->find("id");
  1108. if( it != cArr->end() ){
  1109. tVal->push_back( atoi( it->second.c_str() ));
  1110. };
  1111. };
  1112. };
  1113. };
  1114. };
  1115. deleteResult( result );
  1116. };
  1117. return tVal;
  1118. };
  1119. DBC_INT_LIST *argusDBC::listFilters( uint32_t SiteID, uint32_t ServerID ){
  1120. DBC_INT_LIST * tVal = NULL;
  1121. if(m_bIsConnected){
  1122. char tQBuf[CTEXT];
  1123. AAssoc *result;
  1124. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1125. #ifdef DEBUG
  1126. LOG(tQBuf);
  1127. #endif
  1128. result = m_pDatabase->Query( tQBuf );
  1129. if( result!= NULL ) {
  1130. if( result->size() > 0 ) {
  1131. Assoc *cArr;
  1132. tVal = new DBC_INT_LIST();
  1133. if( tVal != NULL ) {
  1134. Assoc::iterator it;
  1135. for(int i=0;i<result->size();i++) {
  1136. cArr = result->at(i);
  1137. it = cArr->find("id");
  1138. if( it != cArr->end() ){
  1139. tVal->push_back( atoi( it->second.c_str() ));
  1140. };
  1141. };
  1142. };
  1143. };
  1144. };
  1145. deleteResult( result );
  1146. };
  1147. return tVal;
  1148. };
  1149. DBC_INT_LIST *argusDBC::listMediaStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  1150. DBC_INT_LIST * tVal = NULL;
  1151. if(m_bIsConnected){
  1152. char tQBuf[CTEXT];
  1153. AAssoc *result;
  1154. switch( listMode ){
  1155. case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=1 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
  1156. case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
  1157. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  1158. };
  1159. #ifdef DEBUG
  1160. //LOG(tQBuf);
  1161. #endif
  1162. result = m_pDatabase->Query( tQBuf );
  1163. if( result!= NULL ) {
  1164. if( result->size() > 0 ) {
  1165. Assoc *cArr;
  1166. tVal = new DBC_INT_LIST();
  1167. if( tVal != NULL ) {
  1168. Assoc::iterator it;
  1169. for(int i=0;i<result->size();i++) {
  1170. cArr = result->at(i);
  1171. it = cArr->find("id");
  1172. if( it != cArr->end() ){
  1173. tVal->push_back( atoi( it->second.c_str() ));
  1174. };
  1175. };
  1176. };
  1177. };
  1178. };
  1179. deleteResult( result );
  1180. };
  1181. return tVal;
  1182. };
  1183. DBC_INT_LIST *argusDBC::listDetectionProfileIDs( uint32_t nodeID ){
  1184. DBC_INT_LIST * tVal = NULL;
  1185. if(m_bIsConnected){
  1186. char tQBuf[CTEXT];
  1187. AAssoc *result;
  1188. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1189. #ifdef DEBUG
  1190. LOG(tQBuf);
  1191. #endif
  1192. result = m_pDatabase->Query( tQBuf );
  1193. if( result!= NULL ) {
  1194. if( result->size() > 0 ) {
  1195. Assoc *cArr;
  1196. tVal = new DBC_INT_LIST();
  1197. if( tVal != NULL ) {
  1198. Assoc::iterator it;
  1199. for(int i=0;i<result->size();i++) {
  1200. cArr = result->at(i);
  1201. it = cArr->find("profile_id");
  1202. if( it != cArr->end() ){
  1203. tVal->push_back( atoi( it->second.c_str() ));
  1204. };
  1205. };
  1206. };
  1207. };
  1208. };
  1209. deleteResult( result );
  1210. };
  1211. return tVal;
  1212. };
  1213. DBC_INT_LIST *argusDBC::listDetectionProfiles( uint32_t nodeID ){
  1214. DBC_INT_LIST * tVal = NULL;
  1215. if(m_bIsConnected){
  1216. char tQBuf[CTEXT];
  1217. AAssoc *result;
  1218. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  1219. #ifdef DEBUG
  1220. LOG(tQBuf);
  1221. #endif
  1222. result = m_pDatabase->Query( tQBuf );
  1223. if( result!= NULL ) {
  1224. if( result->size() > 0 ) {
  1225. Assoc *cArr;
  1226. tVal = new DBC_INT_LIST();
  1227. if( tVal != NULL ) {
  1228. Assoc::iterator it;
  1229. for(int i=0;i<result->size();i++) {
  1230. cArr = result->at(i);
  1231. it = cArr->find("id");
  1232. if( it != cArr->end() ){
  1233. tVal->push_back( atoi( it->second.c_str() ));
  1234. };
  1235. };
  1236. };
  1237. };
  1238. };
  1239. deleteResult( result );
  1240. };
  1241. return tVal;
  1242. };
  1243. /*
  1244. DBC_INT_LIST *argusDBC::listSockets( uint32_t NodeID ){
  1245. DBC_INT_LIST * tVal = NULL;
  1246. if(m_bIsConnected){
  1247. char tQBuf[CTEXT];
  1248. AAssoc *result;
  1249. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  1250. #ifdef DEBUG
  1251. LOG(tQBuf);
  1252. #endif
  1253. result = m_pDatabase->Query( tQBuf );
  1254. if( result!= NULL ) {
  1255. if( result->size() > 0 ) {
  1256. Assoc *cArr;
  1257. tVal = new DBC_INT_LIST();
  1258. if( tVal != NULL ) {
  1259. Assoc::iterator it;
  1260. for(int i=0;i<result->size();i++) {
  1261. cArr = result->at(i);
  1262. it = cArr->find("id");
  1263. if( it != cArr->end() ){
  1264. tVal->push_back( atoi( it->second.c_str() ));
  1265. };
  1266. };
  1267. };
  1268. };
  1269. };
  1270. deleteResult( result );
  1271. };
  1272. return tVal;
  1273. };
  1274. */
  1275. DBC_INT_LIST *argusDBC::listResources( uint32_t NodeID ){
  1276. DBC_INT_LIST * tVal = NULL;
  1277. if(m_bIsConnected){
  1278. char tQBuf[CTEXT];
  1279. AAssoc *result;
  1280. if( NodeID ) {
  1281. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1", NodeID );
  1282. } else {
  1283. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `site_id`=%d AND `active`=1", m_nSiteID );
  1284. };
  1285. #ifdef DEBUG
  1286. LOG(tQBuf);
  1287. #endif
  1288. result = m_pDatabase->Query( tQBuf );
  1289. if( result!= NULL ) {
  1290. if( result->size() > 0 ) {
  1291. Assoc *cArr;
  1292. tVal = new DBC_INT_LIST();
  1293. if( tVal != NULL ) {
  1294. Assoc::iterator it;
  1295. for(int i=0;i<result->size();i++) {
  1296. cArr = result->at(i);
  1297. it = cArr->find("id");
  1298. if( it != cArr->end() ){
  1299. tVal->push_back( atoi( it->second.c_str() ));
  1300. };
  1301. };
  1302. };
  1303. };
  1304. };
  1305. deleteResult( result );
  1306. };
  1307. return tVal;
  1308. };
  1309. DBC_INT_LIST *argusDBC::listNewModules( uint32_t ServerID, DBC_INT_LIST * old_ids ){
  1310. DBC_INT_LIST * tVal = NULL;
  1311. char tParam[CTEXT];
  1312. //memset( tParam, 0, CTEXT );
  1313. sprintf(tParam,"0");
  1314. if( old_ids != NULL ) {
  1315. char tBuffer[CTEXT];
  1316. for(int i = 0; i< old_ids->size(); i++ ) {
  1317. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  1318. strncpy( tParam, tBuffer, CTEXT );
  1319. };
  1320. };
  1321. if(m_bIsConnected){
  1322. char tQBuf[CTEXT];
  1323. AAssoc *result;
  1324. sprintf(tQBuf, "SELECT id FROM server_modules WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", ServerID, tParam );
  1325. #ifdef DEBUG
  1326. LOG(tQBuf);
  1327. #endif
  1328. result = m_pDatabase->Query( tQBuf );
  1329. if( result!= NULL ) {
  1330. if( result->size() > 0 ) {
  1331. Assoc *cArr;
  1332. tVal = new DBC_INT_LIST();
  1333. if( tVal != NULL ) {
  1334. Assoc::iterator it;
  1335. for(int i=0;i<result->size();i++) {
  1336. cArr = result->at(i);
  1337. it = cArr->find("id");
  1338. if( it != cArr->end() ){
  1339. tVal->push_back( atoi( it->second.c_str() ));
  1340. };
  1341. };
  1342. };
  1343. };
  1344. };
  1345. deleteResult( result );
  1346. };
  1347. return tVal;
  1348. };
  1349. uint32_t argusDBC::getCamId( CSTR UUID ){
  1350. uint32_t RetVal = 0;
  1351. if(m_bIsConnected){
  1352. char tQBuf[CTEXT];
  1353. AAssoc *result;
  1354. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  1355. #ifdef DEBUG
  1356. LOG(tQBuf);
  1357. #endif
  1358. result = m_pDatabase->Query( tQBuf );
  1359. if( result!= NULL ) {
  1360. if( result->size() > 0 ) {
  1361. Assoc *cArr;
  1362. Assoc::iterator it;
  1363. cArr = result->at(0);
  1364. it = cArr->find("id");
  1365. if( it != cArr->end() ){
  1366. RetVal = atoi( it->second.c_str() );
  1367. };
  1368. };
  1369. };
  1370. deleteResult( result );
  1371. };
  1372. return RetVal;
  1373. };
  1374. DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
  1375. DBC_CAM_DATA *tVal = NULL;
  1376. if(m_bIsConnected){
  1377. char tQBuf[CTEXT];
  1378. AAssoc *result;
  1379. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  1380. #ifdef DEBUG
  1381. LOG(tQBuf);
  1382. #endif
  1383. result = m_pDatabase->Query( tQBuf );
  1384. if( result!= NULL ) {
  1385. if( result->size() > 0 ) {
  1386. Assoc *cArr;
  1387. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  1388. if( tVal != NULL ) {
  1389. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  1390. tVal->id = ID;
  1391. Assoc::iterator it;
  1392. cArr = result->at(0);
  1393. it = cArr->find("site_id");
  1394. if( it != cArr->end() ){
  1395. tVal->site_id = atoi( it->second.c_str() );
  1396. };
  1397. it = cArr->find("node_id");
  1398. if( it != cArr->end() ){
  1399. tVal->node_id = atoi( it->second.c_str() );
  1400. };
  1401. it = cArr->find("online");
  1402. if( it != cArr->end() ){
  1403. tVal->online = (bool) atoi( it->second.c_str() );
  1404. };
  1405. it = cArr->find("type");
  1406. if( it != cArr->end() ){
  1407. tVal->type = atoi( it->second.c_str() );
  1408. };
  1409. it = cArr->find("name");
  1410. if( it != cArr->end() ){
  1411. strncpy( tVal->name, it->second.c_str(), 64 );
  1412. };
  1413. it = cArr->find("hardware");
  1414. if( it != cArr->end() ){
  1415. strncpy( tVal->hardware, it->second.c_str(), 32 );
  1416. };
  1417. it = cArr->find("status");
  1418. if( it != cArr->end() ){
  1419. tVal->status = atoi( it->second.c_str() );
  1420. };
  1421. it = cArr->find("session");
  1422. if( it != cArr->end() ){
  1423. strncpy( tVal->session, it->second.c_str(), 32 );
  1424. };
  1425. it = cArr->find("protocol");
  1426. if( it != cArr->end() ){
  1427. tVal->protocol = atoi( it->second.c_str() );
  1428. };
  1429. it = cArr->find("protocol_aux");
  1430. if( it != cArr->end() ){
  1431. strncpy( tVal->protocol_aux, it->second.c_str(), 64 );
  1432. };
  1433. it = cArr->find("uart_id");
  1434. if( it != cArr->end() ){
  1435. tVal->uart_id = atoi( it->second.c_str() );
  1436. };
  1437. it = cArr->find("lat");
  1438. if( it != cArr->end() ){
  1439. tVal->lat = atof( it->second.c_str() );
  1440. };
  1441. it = cArr->find("lon");
  1442. if( it != cArr->end() ){
  1443. tVal->lon = atof( it->second.c_str() );
  1444. };
  1445. it = cArr->find("alt");
  1446. if( it != cArr->end() ){
  1447. tVal->alt = atof( it->second.c_str() );
  1448. };
  1449. it = cArr->find("picth");
  1450. if( it != cArr->end() ){
  1451. tVal->pitch = atof( it->second.c_str() );
  1452. };
  1453. it = cArr->find("roll");
  1454. if( it != cArr->end() ){
  1455. tVal->roll = atof( it->second.c_str() );
  1456. };
  1457. it = cArr->find("yaw");
  1458. if( it != cArr->end() ){
  1459. tVal->yaw = atof( it->second.c_str() );
  1460. };
  1461. it = cArr->find("imager_type");
  1462. if( it != cArr->end() ){
  1463. tVal->imager_type = atoi( it->second.c_str() );
  1464. };
  1465. it = cArr->find("min_f");
  1466. if( it != cArr->end() ){
  1467. tVal->min_f = atof( it->second.c_str() );
  1468. };
  1469. it = cArr->find("max_f");
  1470. if( it != cArr->end() ){
  1471. tVal->max_f = atof( it->second.c_str() );
  1472. };
  1473. it = cArr->find("pan_model");
  1474. if( it != cArr->end() ){
  1475. tVal->pan_model = atoi( it->second.c_str() );
  1476. };
  1477. it = cArr->find("pan_angles");
  1478. if( it != cArr->end() ){
  1479. tVal->pan_angles = atoi( it->second.c_str() );
  1480. };
  1481. it = cArr->find("tilt_model");
  1482. if( it != cArr->end() ){
  1483. tVal->tilt_model = atoi( it->second.c_str() );
  1484. };
  1485. it = cArr->find("tilt_angles");
  1486. if( it != cArr->end() ){
  1487. tVal->tilt_angles = atoi( it->second.c_str() );
  1488. };
  1489. it = cArr->find("max_range");
  1490. if( it != cArr->end() ){
  1491. tVal->max_range = atof( it->second.c_str() );
  1492. };
  1493. it = cArr->find("access_login");
  1494. if( it != cArr->end() ){
  1495. strncpy( tVal->username, it->second.c_str(), 16 );
  1496. };
  1497. it = cArr->find("access_pass");
  1498. if( it != cArr->end() ){
  1499. strncpy( tVal->password, it->second.c_str(), 16 );
  1500. };
  1501. it = cArr->find("uuid");
  1502. if( it != cArr->end() ){
  1503. strncpy( tVal->uuid, it->second.c_str(), 64 );
  1504. };
  1505. it = cArr->find("mac");
  1506. if( it != cArr->end() ){
  1507. strncpy( tVal->mac, it->second.c_str(), 16 );
  1508. };
  1509. it = cArr->find("ip");
  1510. if( it != cArr->end() ){
  1511. strncpy( tVal->ip, it->second.c_str(), 16 );
  1512. };
  1513. it = cArr->find("port");
  1514. if( it != cArr->end() ){
  1515. tVal->port = atoi( it->second.c_str() );
  1516. };
  1517. it = cArr->find("onvif_access");
  1518. if( it != cArr->end() ){
  1519. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  1520. };
  1521. it = cArr->find("onvif_ctrl");
  1522. if( it != cArr->end() ){
  1523. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  1524. };
  1525. it = cArr->find("ptz_token");
  1526. if( it != cArr->end() ){
  1527. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  1528. };
  1529. };
  1530. };
  1531. };
  1532. deleteResult( result );
  1533. };
  1534. return tVal;
  1535. };
  1536. DBC_MODULE_DATA *argusDBC::getModuleData( uint32_t ID ){
  1537. DBC_MODULE_DATA *tVal = NULL;
  1538. if(m_bIsConnected){
  1539. char tQBuf[CTEXT];
  1540. AAssoc *result;
  1541. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  1542. #ifdef DEBUG
  1543. LOG(tQBuf);
  1544. #endif
  1545. result = m_pDatabase->Query( tQBuf );
  1546. if( result!= NULL ) {
  1547. if( result->size() > 0 ) {
  1548. Assoc *cArr;
  1549. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  1550. if( tVal != NULL ) {
  1551. Assoc::iterator it;
  1552. cArr = result->at(0);
  1553. it = cArr->find("id");
  1554. if( it != cArr->end() ){
  1555. tVal->module_id = atoi( it->second.c_str() );
  1556. };
  1557. it = cArr->find("aux_id");
  1558. if( it != cArr->end() ){
  1559. tVal->aux_id = atoi( it->second.c_str() );
  1560. };
  1561. it = cArr->find("type");
  1562. if( it != cArr->end() ){
  1563. tVal->type = atoi( it->second.c_str() );
  1564. };
  1565. it = cArr->find("enabled");
  1566. if( it != cArr->end() ){
  1567. tVal->enabled = (bool)atoi( it->second.c_str() );
  1568. };
  1569. };
  1570. };
  1571. };
  1572. deleteResult( result );
  1573. };
  1574. return tVal;
  1575. };
  1576. /*
  1577. DBC_SOCKET_DATA *argusDBC::getSocketData( uint32_t ID ){
  1578. DBC_SOCKET_DATA *tVal = NULL;
  1579. if(m_bIsConnected){
  1580. char tQBuf[CTEXT];
  1581. AAssoc *result;
  1582. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  1583. #ifdef DEBUG
  1584. //LOG(tQBuf);
  1585. #endif
  1586. result = m_pDatabase->Query( tQBuf );
  1587. if( result!= NULL ) {
  1588. if( result->size() > 0 ) {
  1589. Assoc *cArr;
  1590. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  1591. if( tVal != NULL ) {
  1592. Assoc::iterator it;
  1593. cArr = result->at(0);
  1594. it = cArr->find("id");
  1595. if( it != cArr->end() ){
  1596. tVal->socket_id = atoi( it->second.c_str() );
  1597. };
  1598. it = cArr->find("aux_id");
  1599. if( it != cArr->end() ){
  1600. tVal->aux_id = atoi( it->second.c_str() );
  1601. };
  1602. it = cArr->find("type");
  1603. if( it != cArr->end() ){
  1604. tVal->type = atoi( it->second.c_str() );
  1605. };
  1606. it = cArr->find("binded");
  1607. if( it != cArr->end() ){
  1608. tVal->binded = (bool)atoi( it->second.c_str() );
  1609. };
  1610. };
  1611. };
  1612. };
  1613. deleteResult( result );
  1614. };
  1615. return tVal;
  1616. };
  1617. */
  1618. DBC_MEDIA_STREAM_DATA *argusDBC::getMediaStreamData( uint32_t ID ){
  1619. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  1620. if(m_bIsConnected){
  1621. char tQBuf[CTEXT];
  1622. AAssoc *result;
  1623. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  1624. #ifdef DEBUG
  1625. //LOG(tQBuf);
  1626. #endif
  1627. result = m_pDatabase->Query( tQBuf );
  1628. if( result!= NULL ) {
  1629. if( result->size() > 0 ) {
  1630. Assoc *cArr;
  1631. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  1632. if( tVal != NULL ) {
  1633. Assoc::iterator it;
  1634. cArr = result->at(0);
  1635. tVal->id = ID;
  1636. it = cArr->find("source_id");
  1637. if( it != cArr->end() ){
  1638. tVal->source_id = atoi( it->second.c_str() );
  1639. };
  1640. it = cArr->find("site_id");
  1641. if( it != cArr->end() ){
  1642. tVal->site_id = atoi( it->second.c_str() );
  1643. };
  1644. it = cArr->find("source_type");
  1645. if( it != cArr->end() ){
  1646. sprintf( tVal->source_type, it->second.c_str() );
  1647. };
  1648. it = cArr->find("valid");
  1649. if( it != cArr->end() ){
  1650. tVal->valid = (bool) atoi( it->second.c_str() );
  1651. };
  1652. it = cArr->find("token");
  1653. if( it != cArr->end() ){
  1654. sprintf( tVal->token, it->second.c_str() );
  1655. };
  1656. it = cArr->find("mrl_proto");
  1657. if( it != cArr->end() ){
  1658. sprintf( tVal->mrl_proto, it->second.c_str() );
  1659. };
  1660. it = cArr->find("mrl_port");
  1661. if( it != cArr->end() ){
  1662. tVal->mrl_port = atoi( it->second.c_str() );
  1663. };
  1664. it = cArr->find("mrl");
  1665. if( it != cArr->end() ){
  1666. sprintf( tVal->mrl, it->second.c_str() );
  1667. };
  1668. };
  1669. };
  1670. };
  1671. deleteResult( result );
  1672. };
  1673. return tVal;
  1674. };
  1675. DBC_MEDIA_SERVER_DATA *argusDBC::getMediaServerData( uint32_t ID ){
  1676. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  1677. if(m_bIsConnected){
  1678. char tQBuf[CTEXT];
  1679. AAssoc *result;
  1680. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  1681. #ifdef DEBUG
  1682. LOG(tQBuf);
  1683. #endif
  1684. result = m_pDatabase->Query( tQBuf );
  1685. if( result!= NULL ) {
  1686. if( result->size() > 0 ) {
  1687. Assoc *cArr;
  1688. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  1689. if( tVal != NULL ) {
  1690. Assoc::iterator it;
  1691. cArr = result->at(0);
  1692. tVal->id = ID;
  1693. it = cArr->find("secret_key");
  1694. if( it != cArr->end() ){
  1695. sprintf( tVal->key, it->second.c_str() );
  1696. };
  1697. it = cArr->find("ip");
  1698. if( it != cArr->end() ){
  1699. sprintf( tVal->ip, it->second.c_str() );
  1700. };
  1701. it = cArr->find("REST_port");
  1702. if( it != cArr->end() ){
  1703. tVal->port = atoi( it->second.c_str() );
  1704. };
  1705. it = cArr->find("virtual_host");
  1706. if( it != cArr->end() ){
  1707. sprintf( tVal->host, it->second.c_str() );
  1708. };
  1709. it = cArr->find("recording");
  1710. if( it != cArr->end() ){
  1711. tVal->recording = (bool)atoi( it->second.c_str() );
  1712. };
  1713. it = cArr->find("local");
  1714. if( it != cArr->end() ){
  1715. tVal->local = (bool)atoi( it->second.c_str() );
  1716. };
  1717. it = cArr->find("docRoot");
  1718. if( it != cArr->end() ){
  1719. sprintf( tVal->docRoot, it->second.c_str() );
  1720. };
  1721. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  1722. };
  1723. };
  1724. };
  1725. deleteResult( result );
  1726. };
  1727. return tVal;
  1728. };
  1729. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  1730. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  1731. if(m_bIsConnected){
  1732. char tQBuf[MAX_PATH_LEN];
  1733. AAssoc *result;
  1734. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  1735. #ifdef DEBUG
  1736. //LOG(tQBuf);
  1737. #endif
  1738. result = m_pDatabase->Query( tQBuf );
  1739. if( result!= NULL ) {
  1740. if( result->size() > 0 ) {
  1741. Assoc *cArr;
  1742. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  1743. if( tVal != NULL ) {
  1744. Assoc::iterator it;
  1745. cArr = result->at(0);
  1746. tVal->id = ID;
  1747. it = cArr->find("media_stream_id");
  1748. if( it != cArr->end() ){
  1749. tVal->media_stream_id = atoi( it->second.c_str() );
  1750. };
  1751. it = cArr->find("online");
  1752. if( it != cArr->end() ){
  1753. tVal->online = atoi( it->second.c_str() );
  1754. };
  1755. it = cArr->find("key");
  1756. if( it != cArr->end() ){
  1757. sprintf( tVal->key, it->second.c_str() );
  1758. };
  1759. it = cArr->find("mrl");
  1760. if( it != cArr->end() ){
  1761. sprintf( tVal->mrl, it->second.c_str() );
  1762. };
  1763. };
  1764. };
  1765. };
  1766. deleteResult( result );
  1767. };
  1768. return tVal;
  1769. };
  1770. DBC_MEDIA_SERVER_STREAM_DATA *argusDBC::getMediaServerStreamData( uint32_t ID ){
  1771. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  1772. if(m_bIsConnected){
  1773. char tQBuf[MAX_PATH_LEN];
  1774. AAssoc *result;
  1775. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  1776. #ifdef DEBUG
  1777. //LOG(tQBuf);
  1778. #endif
  1779. result = m_pDatabase->Query( tQBuf );
  1780. if( result!= NULL ) {
  1781. if( result->size() > 0 ) {
  1782. Assoc *cArr;
  1783. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  1784. if( tVal != NULL ) {
  1785. Assoc::iterator it;
  1786. cArr = result->at(0);
  1787. tVal->id = ID;
  1788. it = cArr->find("media_stream_id");
  1789. if( it != cArr->end() ){
  1790. tVal->media_stream_id = atoi( it->second.c_str() );
  1791. };
  1792. it = cArr->find("online");
  1793. if( it != cArr->end() ){
  1794. tVal->online = atoi( it->second.c_str() );
  1795. };
  1796. it = cArr->find("key");
  1797. if( it != cArr->end() ){
  1798. sprintf( tVal->key, it->second.c_str() );
  1799. };
  1800. it = cArr->find("mrl");
  1801. if( it != cArr->end() ){
  1802. sprintf( tVal->mrl, it->second.c_str() );
  1803. };
  1804. };
  1805. };
  1806. };
  1807. deleteResult( result );
  1808. };
  1809. return tVal;
  1810. };
  1811. void argusDBC::registerServer(uint32_t SiteID, CSTR identity ){
  1812. if(m_bIsConnected){
  1813. m_nSiteID = SiteID;
  1814. char tQBuf[CTEXT];
  1815. sprintf(tQBuf,"INSERT INTO servers SET `site_id`=%d, `identity`='%s', `online`=1 ON DUPLICATE KEY UPDATE `online`=1", SiteID, identity );
  1816. #ifdef DEBUG
  1817. //LOG(tQBuf);
  1818. #endif
  1819. m_pDatabase->SilentQuery( tQBuf );
  1820. // Clenup Nodes and services ...
  1821. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `site_id`=%d ", SiteID );
  1822. #ifdef DEBUG
  1823. //LOG(tQBuf);
  1824. #endif
  1825. m_pDatabase->SilentQuery( tQBuf );
  1826. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  1827. #ifdef DEBUG
  1828. //LOG(tQBuf);
  1829. #endif
  1830. m_pDatabase->SilentQuery( tQBuf );
  1831. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  1832. #ifdef DEBUG
  1833. //LOG(tQBuf);
  1834. #endif
  1835. m_pDatabase->SilentQuery( tQBuf );
  1836. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  1837. #ifdef DEBUG
  1838. //LOG(tQBuf);
  1839. #endif
  1840. m_pDatabase->SilentQuery( tQBuf );
  1841. uint32_t sid = getServerID( identity );
  1842. if( sid ) {
  1843. sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, sid );
  1844. #ifdef DEBUG
  1845. //LOG(tQBuf);
  1846. #endif
  1847. m_pDatabase->SilentQuery( tQBuf );
  1848. cleanResources( m_nSiteID, sid );
  1849. };
  1850. };
  1851. };
  1852. void argusDBC::unregisterServer(uint32_t ServerID, uint32_t NodeID ){
  1853. if(m_bIsConnected){
  1854. char tQBuf[CTEXT];
  1855. sprintf(tQBuf,"UPDATE servers SET `online`=0 WHERE `id` = %d", ServerID );
  1856. #ifdef DEBUG
  1857. //LOG(tQBuf);
  1858. #endif
  1859. m_pDatabase->SilentQuery( tQBuf );
  1860. setNodeOffline( NodeID );
  1861. };
  1862. };
  1863. bool argusDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  1864. if(m_bIsConnected){
  1865. char tQBuf[CTEXT];
  1866. if( NodeID ) {
  1867. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id` = %d", status, NodeID );
  1868. #ifdef DEBUG
  1869. //LOG(tQBuf);
  1870. #endif
  1871. m_pDatabase->SilentQuery( tQBuf );
  1872. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id` = %d", NodeID );
  1873. #ifdef DEBUG
  1874. //LOG(tQBuf);
  1875. #endif
  1876. m_pDatabase->SilentQuery( tQBuf );
  1877. return true;
  1878. };
  1879. };
  1880. return false;
  1881. };
  1882. bool argusDBC::setNodeOffline( uint32_t NodeID ){
  1883. if(m_bIsConnected){
  1884. char tQBuf[CTEXT];
  1885. if( NodeID ) {
  1886. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  1887. #ifdef DEBUG
  1888. //LOG(tQBuf);
  1889. #endif
  1890. m_pDatabase->SilentQuery( tQBuf );
  1891. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  1892. #ifdef DEBUG
  1893. //LOG(tQBuf);
  1894. #endif
  1895. m_pDatabase->SilentQuery( tQBuf );
  1896. return true;
  1897. };
  1898. };
  1899. return false;
  1900. };
  1901. DBC_RESOURCE_DATA *argusDBC::getResourceData( uint32_t ResourceID ){
  1902. DBC_RESOURCE_DATA *tVal = NULL;
  1903. if( m_bIsConnected ){
  1904. char tQBuf[CTEXT];
  1905. AAssoc *result;
  1906. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  1907. #ifdef DEBUG
  1908. //LOG(tQBuf);
  1909. #endif
  1910. result = m_pDatabase->Query( tQBuf );
  1911. if( result!= NULL ) {
  1912. if( result->size() > 0 ) {
  1913. Assoc *cArr;
  1914. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  1915. if( tVal != NULL ) {
  1916. Assoc::iterator it;
  1917. cArr = result->at(0);
  1918. tVal->id = ResourceID;
  1919. it = cArr->find("node_id");
  1920. if( it != cArr->end() ){
  1921. tVal->node_id = atoi( it->second.c_str() );
  1922. };
  1923. it = cArr->find("type");
  1924. if( it != cArr->end() ){
  1925. tVal->type = atoi( it->second.c_str() );
  1926. };
  1927. it = cArr->find("aux_id");
  1928. if( it != cArr->end() ){
  1929. tVal->aux_id = atoi( it->second.c_str() );
  1930. };
  1931. it = cArr->find("device");
  1932. if( it != cArr->end() ){
  1933. strncpy( tVal->device, it->second.c_str(), 64 );
  1934. tVal->device[63] = (char)0;
  1935. };
  1936. };
  1937. };
  1938. };
  1939. deleteResult( result );
  1940. };
  1941. return tVal;
  1942. };
  1943. uint32_t argusDBC::getResourceID( uint32_t SiteID, uint32_t NodeID, uint8_t type, uint32_t auxID ){
  1944. uint32_t RetVal = 0;
  1945. if(m_bIsConnected){
  1946. char tQBuf[CTEXT];
  1947. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `site_id`=%d AND `node_id`=%d AND `type`=%d AND `aux_id`=%d", SiteID, NodeID, type, auxID );
  1948. AAssoc *result;
  1949. result = m_pDatabase->Query( tQBuf );
  1950. if( result!= NULL ) {
  1951. if( result->size() > 0 ) {
  1952. Assoc * cArr;
  1953. Assoc::iterator it;
  1954. cArr = result->at(0);
  1955. it = cArr->find("id");
  1956. if( it != cArr->end() ){
  1957. RetVal = atoi( it->second.c_str() );
  1958. };
  1959. };
  1960. };
  1961. deleteResult( result );
  1962. };
  1963. return RetVal;
  1964. };
  1965. uint32_t argusDBC::getServerID( CSTR identity ){
  1966. uint32_t RetVal = 0;
  1967. if(m_bIsConnected){
  1968. char tQBuf[CTEXT];
  1969. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  1970. #ifdef DEBUG
  1971. LOG(tQBuf);
  1972. #endif
  1973. AAssoc *result;
  1974. result = m_pDatabase->Query( tQBuf );
  1975. if( result!= NULL ) {
  1976. if( result->size() > 0 ) {
  1977. Assoc * cArr;
  1978. Assoc::iterator it;
  1979. cArr = result->at(0);
  1980. it = cArr->find("id");
  1981. if( it != cArr->end() ){
  1982. RetVal = atoi( it->second.c_str() );
  1983. };
  1984. };
  1985. };
  1986. deleteResult( result );
  1987. };
  1988. return RetVal;
  1989. };
  1990. uint32_t argusDBC::getServerNode( uint32_t SID ){
  1991. uint32_t RetVal = 0;
  1992. if(m_bIsConnected){
  1993. char tQBuf[CTEXT];
  1994. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  1995. #ifdef DEBUG
  1996. LOG(tQBuf);
  1997. #endif
  1998. AAssoc *result;
  1999. result = m_pDatabase->Query( tQBuf );
  2000. if( result!= NULL ) {
  2001. if( result->size() > 0 ) {
  2002. Assoc * cArr;
  2003. Assoc::iterator it;
  2004. cArr = result->at(0);
  2005. it = cArr->find("id");
  2006. if( it != cArr->end() ){
  2007. RetVal = atoi( it->second.c_str() );
  2008. };
  2009. };
  2010. };
  2011. deleteResult( result );
  2012. };
  2013. return RetVal;
  2014. };
  2015. uint32_t argusDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  2016. uint32_t RetVal = 0;
  2017. if(m_bIsConnected){
  2018. char tQBuf[1024];
  2019. char tM5[33];
  2020. CSTR tMD5 = MD5String( path );
  2021. if( tMD5 != NULL ) {
  2022. memcpy( tM5, tMD5, 33 );
  2023. tM5[32]=(char)0;
  2024. free( tMD5 );
  2025. sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1, img_width=%d, img_height=%d",
  2026. SiteID, tM5, width, height, path, width, height );
  2027. #ifdef DEBUG
  2028. //LOG(tQBuf);
  2029. #endif
  2030. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2031. };
  2032. };
  2033. return RetVal;
  2034. };
  2035. /*
  2036. uint32_t argusDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  2037. uint32_t retVal = 0;
  2038. if(m_bIsConnected){
  2039. char tQBuf[2048];
  2040. char tM5[33];
  2041. CSTR tMD5 = MD5String( path );
  2042. if( tMD5 != NULL ) {
  2043. memcpy( tM5, tMD5, 33 );
  2044. free( tMD5 );
  2045. if( multidrop ) {
  2046. sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=1, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
  2047. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2048. } else {
  2049. sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=0, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
  2050. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  2051. };
  2052. #ifdef DEBUG
  2053. LOG(tQBuf);
  2054. #endif
  2055. //m_pDatabase->SilentQuery( tQBuf );
  2056. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2057. };
  2058. };
  2059. return retVal;
  2060. };
  2061. */
  2062. bool argusDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  2063. if(m_bIsConnected){
  2064. char tQBuf[2048];
  2065. sprintf(tQBuf,"INSERT INTO `notifications` SET `site_id`=%d, `ts`=NOW(), `lvl`=%d, `type`=%d, `obj_id`=%d ON DUPLICATE KEY UPDATE `status`='A', `ts`=NOW()", m_nSiteID, DIS_LVL, MSG_ID, OBJ_ID );
  2066. #ifdef DEBUG
  2067. LOG(tQBuf);
  2068. #endif
  2069. m_pDatabase->SilentQuery( tQBuf );
  2070. return true;
  2071. };
  2072. return false;
  2073. };
  2074. uint32_t argusDBC::addResource( uint32_t SiteID, uint32_t NodeID, uint8_t type, CSTR devName, uint32_t auxID ){
  2075. uint32_t RetVal = 0;
  2076. if( m_bIsConnected ){
  2077. char tQBuf[2048];
  2078. CSTR tMD5 = MD5String( devName );
  2079. if( tMD5 ) {
  2080. sprintf( tQBuf, "INSERT INTO `resources` SET `site_id`=%d, `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s' ON DUPLICATE KEY UPDATE `active`=1", SiteID, NodeID, type, tMD5, auxID, devName );
  2081. free( tMD5 );
  2082. #ifdef DEBUG
  2083. //LOG(tQBuf);
  2084. #endif
  2085. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2086. if( RetVal == 0 ) {
  2087. RetVal = getResourceID( SiteID, NodeID, type, auxID );
  2088. };
  2089. };
  2090. };
  2091. return RetVal;
  2092. };
  2093. /*
  2094. uint32_t argusDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  2095. uint32_t retVal = 0;
  2096. if(m_bIsConnected){
  2097. char tQBuf[2048];
  2098. char tM5[33];
  2099. CSTR tMD5 = MD5String( path );
  2100. if( tMD5 != NULL ) {
  2101. memcpy( tM5, tMD5, 33 );
  2102. free( tMD5 );
  2103. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  2104. #ifdef DEBUG
  2105. LOG(tQBuf);
  2106. #endif
  2107. AAssoc *result;
  2108. result = m_pDatabase->Query( tQBuf );
  2109. if( result!= NULL ) {
  2110. if( result->size() > 0 ) {
  2111. Assoc * cArr;
  2112. Assoc::iterator it;
  2113. cArr = result->at(0);
  2114. it = cArr->find("id");
  2115. if( it != cArr->end() ){
  2116. retVal = atoi( it->second.c_str() );
  2117. };
  2118. };
  2119. };
  2120. deleteResult( result );
  2121. };
  2122. };
  2123. return retVal;
  2124. };
  2125. */
  2126. CSTR argusDBC::getNodeIP4( uint32_t NodeID ){
  2127. return getResourceDevice( NodeID, ARGUS_HARDWARE_NETWORK_IPV4 );
  2128. };
  2129. CSTR argusDBC::getNodeIP6( uint32_t NodeID ){
  2130. return getResourceDevice( NodeID, ARGUS_HARDWARE_NETWORK_IPV6 );
  2131. };
  2132. CSTR argusDBC::getResourceDevice( uint32_t NodeID, uint32_t Type ){
  2133. if(m_bIsConnected){
  2134. char tQBuf[CTEXT];
  2135. sprintf( tQBuf, "SELECT `device` FROM `resources` WHERE `node_id`=%d AND `type`=%d LIMIT 1", NodeID, Type );
  2136. #ifdef DEBUG
  2137. LOG(tQBuf);
  2138. #endif
  2139. AAssoc *result;
  2140. result = m_pDatabase->Query( tQBuf );
  2141. if( result!= NULL ) {
  2142. if( result->size() > 0 ) {
  2143. Assoc * cArr;
  2144. Assoc::iterator it;
  2145. cArr = result->at(0);
  2146. it = cArr->find("path");
  2147. if( it != cArr->end() ){
  2148. strncpy( tQBuf, it->second.c_str(), CTEXT );
  2149. };
  2150. };
  2151. };
  2152. deleteResult( result );
  2153. return strdup(tQBuf);
  2154. };
  2155. return NULL;
  2156. };
  2157. /*
  2158. CSTR argusDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  2159. if(m_bIsConnected){
  2160. char tQBuf[CTEXT];
  2161. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  2162. NodeID, Type );
  2163. #ifdef DEBUG
  2164. LOG(tQBuf);
  2165. #endif
  2166. AAssoc *result;
  2167. result = m_pDatabase->Query( tQBuf );
  2168. if( result!= NULL ) {
  2169. if( result->size() > 0 ) {
  2170. Assoc * cArr;
  2171. Assoc::iterator it;
  2172. cArr = result->at(0);
  2173. it = cArr->find("name");
  2174. if( it != cArr->end() ){
  2175. strncpy( tQBuf, it->second.c_str(), CTEXT );
  2176. };
  2177. };
  2178. };
  2179. deleteResult( result );
  2180. return strdup(tQBuf);
  2181. };
  2182. return NULL;
  2183. };
  2184. */
  2185. KAFKA_SETTINGS *argusDBC::getSettingsKAFKA( uint32_t ModuleID ){
  2186. KAFKA_SETTINGS *tVal = NULL;
  2187. if( m_bIsConnected ) {
  2188. char tQBuf[CTEXT];
  2189. AAssoc *result;
  2190. sprintf( tQBuf, "SELECT brocker_address, brocker_port FROM modules_kafka WHERE module_id = %d", ModuleID );
  2191. #ifdef DEBUG
  2192. LOG(tQBuf);
  2193. #endif
  2194. result = m_pDatabase->Query( tQBuf );
  2195. if( result!= NULL ) {
  2196. if( result->size() > 0 ) {
  2197. Assoc *cArr;
  2198. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  2199. if( tVal != NULL ) {
  2200. Assoc::iterator it;
  2201. cArr = result->at(0);
  2202. it = cArr->find("brocker_address");
  2203. if( it != cArr->end() ){
  2204. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  2205. };
  2206. it = cArr->find("brocker_port");
  2207. if( it != cArr->end() ){
  2208. tVal->brocker_port = atoi( it->second.c_str() );
  2209. };
  2210. };
  2211. };
  2212. };
  2213. deleteResult( result );
  2214. };
  2215. return tVal;
  2216. };
  2217. KAFKA_TEMPLATE *argusDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  2218. KAFKA_TEMPLATE *tVal = NULL;
  2219. if( m_bIsConnected ) {
  2220. char tQBuf[CTEXT];
  2221. AAssoc *result;
  2222. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  2223. #ifdef DEBUG
  2224. LOG(tQBuf);
  2225. #endif
  2226. result = m_pDatabase->Query( tQBuf );
  2227. if( result!= NULL ) {
  2228. if( result->size() > 0 ) {
  2229. Assoc *cArr;
  2230. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  2231. if( tVal != NULL ) {
  2232. Assoc::iterator it;
  2233. cArr = result->at(0);
  2234. it = cArr->find("topic");
  2235. if( it != cArr->end() ){
  2236. memset( tVal->topic, 0, 128 );
  2237. strncpy( tVal->topic , it->second.c_str(), 127 );
  2238. };
  2239. it = cArr->find("template");
  2240. if( it != cArr->end() ){
  2241. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  2242. if( tVal->tpl!= NULL) {
  2243. memset( tVal->tpl, 0, it->second.length() + 1 );
  2244. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  2245. };
  2246. };
  2247. };
  2248. };
  2249. };
  2250. deleteResult( result );
  2251. };
  2252. return tVal;
  2253. };
  2254. DBC_UART_DATA *argusDBC::getUartData( uint32_t UartID ){
  2255. DBC_UART_DATA *tVal = NULL;
  2256. if( m_bIsConnected ) {
  2257. char tQBuf[MAX_PATH_LEN];
  2258. AAssoc *result;
  2259. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  2260. #ifdef DEBUG
  2261. //LOG(tQBuf);
  2262. #endif
  2263. result = m_pDatabase->Query( tQBuf );
  2264. if( result!= NULL ) {
  2265. if( result->size() > 0 ) {
  2266. Assoc *cArr;
  2267. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  2268. if( tVal != NULL ) {
  2269. Assoc::iterator it;
  2270. cArr = result->at(0);
  2271. it = cArr->find("type");
  2272. if( it != cArr->end() ){
  2273. tVal->type = atoi( it->second.c_str() );
  2274. };
  2275. it = cArr->find("speed");
  2276. if( it != cArr->end() ){
  2277. tVal->speed = atoi( it->second.c_str() );
  2278. };
  2279. it = cArr->find("mode");
  2280. if( it != cArr->end() ){
  2281. tVal->mode = atoi( it->second.c_str() );
  2282. };
  2283. it = cArr->find("port");
  2284. if( it != cArr->end() ){
  2285. tVal->port = atoi( it->second.c_str() );
  2286. };
  2287. it = cArr->find("path");
  2288. if( it != cArr->end() ){
  2289. strncpy( tVal->path, it->second.c_str(), 128 );
  2290. };
  2291. };
  2292. };
  2293. };
  2294. deleteResult( result );
  2295. };
  2296. return tVal;
  2297. };
  2298. uint32_t argusDBC::getUartID( uint32_t RessourceID ){
  2299. uint32_t RetVal = 0;
  2300. if(m_bIsConnected){
  2301. char tQBuf[CTEXT];
  2302. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `resource_id`=%d", RessourceID );
  2303. AAssoc *result;
  2304. result = m_pDatabase->Query( tQBuf );
  2305. if( result!= NULL ) {
  2306. if( result->size() > 0 ) {
  2307. Assoc * cArr;
  2308. Assoc::iterator it;
  2309. cArr = result->at(0);
  2310. it = cArr->find("id");
  2311. if( it != cArr->end() ){
  2312. RetVal = atoi( it->second.c_str() );
  2313. };
  2314. };
  2315. };
  2316. deleteResult( result );
  2317. };
  2318. return RetVal;
  2319. };
  2320. bool argusDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  2321. if( m_bIsConnected ) {
  2322. char tQBuf[MAX_PATH_LEN];
  2323. #ifdef DEBUG
  2324. LOG("Stream Update");
  2325. #endif
  2326. if( key == NULL ) {
  2327. if( mrl == NULL ) {
  2328. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  2329. } else {
  2330. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  2331. };
  2332. } else {
  2333. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  2334. key,
  2335. mrl,
  2336. id
  2337. );
  2338. };
  2339. #ifdef DEBUG
  2340. LOG(tQBuf);
  2341. #endif
  2342. m_pDatabase->SilentQuery( tQBuf );
  2343. return true;
  2344. };
  2345. return false;
  2346. };
  2347. bool argusDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  2348. if( m_bIsConnected ) {
  2349. char tQBuf[MAX_PATH_LEN];
  2350. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  2351. #ifdef DEBUG
  2352. LOG(tQBuf);
  2353. #endif
  2354. m_pDatabase->SilentQuery( tQBuf );
  2355. return true;
  2356. };
  2357. return false;
  2358. };
  2359. uint32_t argusDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  2360. uint32_t RetVal = 0;
  2361. if( m_bIsConnected ) {
  2362. char tQBuf[MAX_PATH_LEN];
  2363. sprintf( tQBuf, "INSERT INTO modules_dcr SET site_id=%d, status=%d, channels=%d, serial_id='%s' ON DUPLICATE KEY UPDATE status=%d, channels=%d",
  2364. SiteID,
  2365. status,
  2366. CNT,
  2367. SERIAL,
  2368. status,
  2369. CNT
  2370. );
  2371. #ifdef DEBUG
  2372. //LOG(tQBuf);
  2373. #endif
  2374. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  2375. if( cid == 0 ) {
  2376. AAssoc *result;
  2377. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  2378. SiteID,
  2379. SERIAL
  2380. );
  2381. #ifdef DEBUG
  2382. //LOG(tQBuf);
  2383. #endif
  2384. result = m_pDatabase->Query( tQBuf );
  2385. if( result!= NULL ) {
  2386. if( result->size() > 0 ) {
  2387. Assoc * cArr;
  2388. Assoc::iterator it;
  2389. cArr = result->at(0);
  2390. it = cArr->find("id");
  2391. if( it != cArr->end() ){
  2392. cid = atoi( it->second.c_str() );
  2393. };
  2394. };
  2395. deleteResult( result );
  2396. };
  2397. };
  2398. if( cid!= 0 ) {
  2399. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  2400. if( status & ( 1 << idx ) ){
  2401. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  2402. (uint32_t) cid,
  2403. idx
  2404. );
  2405. } else {
  2406. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  2407. (uint32_t) cid,
  2408. idx
  2409. );
  2410. }
  2411. #ifdef DEBUG
  2412. //LOG(tQBuf);
  2413. #endif
  2414. m_pDatabase->SilentQuery( tQBuf );
  2415. };
  2416. };
  2417. };
  2418. return RetVal;
  2419. };
  2420. uint32_t argusDBC::addLocalUART( uint32_t ResID, uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  2421. uint32_t RetVal = 0;
  2422. if( m_bIsConnected ) {
  2423. char tQBuf[MAX_PATH_LEN];
  2424. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `resource_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  2425. ResID,
  2426. utype,
  2427. speed,
  2428. bit,
  2429. parity,
  2430. stop_bit,
  2431. mode,
  2432. port,
  2433. PATH
  2434. );
  2435. #ifdef DEBUG
  2436. //LOG(tQBuf);
  2437. #endif
  2438. RetVal = m_pDatabase->QueryID( tQBuf );
  2439. if( RetVal == 0 ) {
  2440. RetVal = getUartID( ResID );
  2441. };
  2442. };
  2443. return RetVal;
  2444. };
  2445. bool argusDBC::addDraw( uint32_t DBID, uint16_t SIZE, CSTR ID ){
  2446. if( m_bIsConnected ) {
  2447. char tQBuf[MAX_PATH_LEN];
  2448. sprintf( tQBuf,"INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'",
  2449. DBID,
  2450. ID,
  2451. SIZE,
  2452. ID,
  2453. SIZE
  2454. );
  2455. #ifdef DEBUG
  2456. //LOG(tQBuf);
  2457. #endif
  2458. m_pDatabase->SilentQuery( tQBuf );
  2459. return true;
  2460. };
  2461. return false;
  2462. };
  2463. uint32_t argusDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint16_t dig_r, float AZ, float EL, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  2464. uint32_t RetVal = 0;
  2465. if( m_bIsConnected ) {
  2466. char tQBuf[MAX_PATH_LEN];
  2467. if( RefUUID == NULL ) {
  2468. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f",
  2469. SRC,
  2470. UUID,
  2471. tss,
  2472. tsms,
  2473. evt_type,
  2474. dig_r,
  2475. AZ,
  2476. EL,
  2477. RANGE,
  2478. AREA,
  2479. lat,
  2480. lon,
  2481. alt
  2482. );
  2483. } else {
  2484. sprintf( tQBuf,"INSERT INTO events_cloud SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'",
  2485. SRC,
  2486. UUID,
  2487. tss,
  2488. tsms,
  2489. evt_type,
  2490. dig_r,
  2491. AZ,
  2492. EL,
  2493. RANGE,
  2494. AREA,
  2495. lat,
  2496. lon,
  2497. alt,
  2498. RefUUID
  2499. );
  2500. };
  2501. #ifdef DEBUG
  2502. // LOG(tQBuf);
  2503. #endif
  2504. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2505. };
  2506. return RetVal;
  2507. };
  2508. bool argusDBC::addVideoEvent( uint32_t evtID, uint32_t videoID ){
  2509. if( m_bIsConnected ) {
  2510. char tQBuf[MAX_PATH_LEN];
  2511. sprintf( tQBuf, "INSERT INTO `events_video_records` SET `evt_id`=%d, `video_id`=%d", evtID, videoID );
  2512. m_pDatabase->SilentQuery( tQBuf );
  2513. return true;
  2514. };
  2515. return true;
  2516. };
  2517. uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID ){
  2518. uint32_t tID = 0;
  2519. if( m_bIsConnected ) {
  2520. char tQBuf[MAX_PATH_LEN];
  2521. sprintf( tQBuf, "INSERT INTO `video_records` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `part_id`=%d ", streamID, md5, partID );
  2522. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  2523. }
  2524. return tID;
  2525. };
  2526. DBC_KRNL_CMD *argusDBC::getActiveCommand( uint32_t SiteID ){
  2527. DBC_KRNL_CMD *tPtr = NULL;
  2528. if( m_bIsConnected ) {
  2529. char tQBuf[MAX_PATH_LEN];
  2530. AAssoc *result;
  2531. sprintf( tQBuf, "SELECT * FROM `cmd_queue` WHERE `status`=0 AND `site_id`=%d", SiteID );
  2532. result = m_pDatabase->Query( tQBuf );
  2533. if( result != NULL ) {
  2534. if( result->size() > 0 ) {
  2535. Assoc *cArr;
  2536. tPtr = (DBC_KRNL_CMD*)malloc(sizeof(DBC_KRNL_CMD));
  2537. if( tPtr!= NULL ) {
  2538. Assoc::iterator it;
  2539. memset(tPtr,0,sizeof(DBC_KRNL_CMD));
  2540. cArr = result->at(0);
  2541. it = cArr->find("id");
  2542. if( it != cArr->end() ){
  2543. tPtr->id = atoi( it->second.c_str() );
  2544. };
  2545. it = cArr->find("cmd");
  2546. if( it != cArr->end() ){
  2547. tPtr->cmd = atoi( it->second.c_str() );
  2548. };
  2549. it = cArr->find("param");
  2550. if( it != cArr->end() ){
  2551. strncpy( tPtr->param, it->second.c_str(), 255 );
  2552. };
  2553. it = cArr->find("aux_param");
  2554. if( it != cArr->end() ){
  2555. strncpy( tPtr->aux_param, it->second.c_str(), 255 );
  2556. };
  2557. };
  2558. };
  2559. };
  2560. deleteResult( result );
  2561. };
  2562. return tPtr;
  2563. };
  2564. bool argusDBC::updateCommand( uint32_t CMD_ID, uint8_t STATUS ){
  2565. if( m_bIsConnected ) {
  2566. char tQBuf[MAX_PATH_LEN];
  2567. sprintf( tQBuf, "UPDATE `cmd_queue` SET `status`=%d WHERE id=%d", STATUS, CMD_ID );
  2568. m_pDatabase->SilentQuery( tQBuf );
  2569. return true;
  2570. };
  2571. return false;
  2572. };
  2573. bool argusDBC::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, uint32_t spikes ){
  2574. if( m_bIsConnected ) {
  2575. char tQBuf[MAX_PATH_LEN];
  2576. if( master ) {
  2577. sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'1'",
  2578. nOrder,
  2579. nOffset,
  2580. nDelta,
  2581. nFlip,
  2582. nWidth,
  2583. bSST,
  2584. nSun,
  2585. GP,
  2586. spikes,
  2587. lrfID,
  2588. profileID );
  2589. } else {
  2590. sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'0'",
  2591. nOrder,
  2592. nOffset,
  2593. nDelta,
  2594. nFlip,
  2595. nWidth,
  2596. bSST,
  2597. nSun,
  2598. GP,
  2599. spikes,
  2600. lrfID,
  2601. profileID );
  2602. };
  2603. #ifdef DEBUG
  2604. LOG(tQBuf);
  2605. #endif
  2606. m_pDatabase->SilentQuery( tQBuf );
  2607. return true;
  2608. };
  2609. return false;
  2610. };
  2611. bool argusDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  2612. if( m_bIsConnected ) {
  2613. char tQBuf[MAX_PATH_LEN];
  2614. CSTR tES = m_pDatabase->escapeString( Serial );
  2615. if( tES ) {
  2616. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  2617. free( tES );
  2618. #ifdef DEBUG
  2619. LOG(tQBuf);
  2620. #endif
  2621. m_pDatabase->SilentQuery( tQBuf );
  2622. return true;
  2623. };
  2624. };
  2625. return false;
  2626. };
  2627. bool argusDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  2628. if( m_bIsConnected ) {
  2629. char tQBuf[MAX_PATH_LEN];
  2630. CSTR tES = m_pDatabase->escapeString( version );
  2631. if( tES ) {
  2632. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  2633. free( tES );
  2634. #ifdef DEBUG
  2635. LOG(tQBuf);
  2636. #endif
  2637. m_pDatabase->SilentQuery( tQBuf );
  2638. return true;
  2639. };
  2640. };
  2641. return false;
  2642. };
  2643. bool argusDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  2644. if( m_bIsConnected ) {
  2645. char tQBuf[MAX_PATH_LEN];
  2646. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  2647. #ifdef DEBUG
  2648. LOG(tQBuf);
  2649. #endif
  2650. m_pDatabase->SilentQuery( tQBuf );
  2651. return true;
  2652. };
  2653. return false;
  2654. };
  2655. bool argusDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  2656. if( m_bIsConnected ) {
  2657. char tQBuf[MAX_PATH_LEN];
  2658. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  2659. #ifdef DEBUG
  2660. LOG(tQBuf);
  2661. #endif
  2662. m_pDatabase->SilentQuery( tQBuf );
  2663. return true;
  2664. };
  2665. return false;
  2666. };
  2667. bool argusDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  2668. if( m_bIsConnected ) {
  2669. char tQBuf[MAX_PATH_LEN];
  2670. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  2671. #ifdef DEBUG
  2672. LOG(tQBuf);
  2673. #endif
  2674. m_pDatabase->SilentQuery( tQBuf );
  2675. return true;
  2676. };
  2677. return false;
  2678. };
  2679. bool argusDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  2680. if( m_bIsConnected ) {
  2681. char tQBuf[MAX_PATH_LEN];
  2682. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  2683. #ifdef DEBUG
  2684. LOG(tQBuf);
  2685. #endif
  2686. m_pDatabase->SilentQuery( tQBuf );
  2687. return true;
  2688. };
  2689. return false;
  2690. };
  2691. bool argusDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  2692. if( m_bIsConnected ) {
  2693. char tQBuf[MAX_PATH_LEN];
  2694. sprintf( tQBuf, "INSERT INTO `target_filter_apf_boxes` SET `filter_id`=%d, `tag`='%s', `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f ON DUPLICATE KEY UPDATE `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f",
  2695. filterID,
  2696. Tag,
  2697. x,y,z,
  2698. x,y,z
  2699. );
  2700. #ifdef DEBUG
  2701. //LOG(tQBuf);
  2702. #endif
  2703. m_pDatabase->SilentQuery( tQBuf );
  2704. return true;
  2705. };
  2706. return false;
  2707. };
  2708. DBC_EVT_DATA *argusDBC::getEventByUUID( CSTR UUID ){
  2709. DBC_EVT_DATA *tPtr = NULL;
  2710. if( m_bIsConnected ) {
  2711. char tQBuf[MAX_PATH_LEN];
  2712. AAssoc *result;
  2713. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  2714. #ifdef DEBUG
  2715. //LOG(tQBuf);
  2716. #endif
  2717. result = m_pDatabase->Query( tQBuf );
  2718. if( result!= NULL ) {
  2719. if( result->size() > 0 ) {
  2720. Assoc *cArr;
  2721. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  2722. if( tPtr!= NULL ) {
  2723. Assoc::iterator it;
  2724. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  2725. cArr = result->at(0);
  2726. it = cArr->find("id");
  2727. if( it != cArr->end() ){
  2728. tPtr->id = atoi( it->second.c_str() );
  2729. };
  2730. it = cArr->find("node_id");
  2731. if( it != cArr->end() ){
  2732. tPtr->node_id = atoi( it->second.c_str() );
  2733. };
  2734. it = cArr->find("uuid");
  2735. if( it != cArr->end() ){
  2736. strncpy( tPtr->uuid, it->second.c_str(),64 );
  2737. };
  2738. it = cArr->find("ts");
  2739. if( it != cArr->end() ){
  2740. tPtr->ts_s = atoi( it->second.c_str() );
  2741. };
  2742. it = cArr->find("ts_ms");
  2743. if( it != cArr->end() ){
  2744. tPtr->ts_ms = atoi( it->second.c_str() );
  2745. };
  2746. it = cArr->find("evt_type");
  2747. if( it != cArr->end() ){
  2748. tPtr->type = atoi( it->second.c_str() );
  2749. };
  2750. it = cArr->find("range_digital");
  2751. if( it != cArr->end() ){
  2752. tPtr->range_digital = atoi( it->second.c_str() );
  2753. };
  2754. it = cArr->find("azimuth");
  2755. if( it != cArr->end() ){
  2756. tPtr->az = atof( it->second.c_str() );
  2757. };
  2758. it = cArr->find("elevation");
  2759. if( it != cArr->end() ){
  2760. tPtr->el = atof( it->second.c_str() );
  2761. };
  2762. it = cArr->find("range");
  2763. if( it != cArr->end() ){
  2764. tPtr->ra = atof( it->second.c_str() );
  2765. };
  2766. it = cArr->find("area");
  2767. if( it != cArr->end() ){
  2768. tPtr->area = atof( it->second.c_str() );
  2769. };
  2770. it = cArr->find("lat");
  2771. if( it != cArr->end() ){
  2772. tPtr->lat = atof( it->second.c_str() );
  2773. };
  2774. it = cArr->find("lon");
  2775. if( it != cArr->end() ){
  2776. tPtr->lon = atof( it->second.c_str() );
  2777. };
  2778. it = cArr->find("alt");
  2779. if( it != cArr->end() ){
  2780. tPtr->alt = atof( it->second.c_str() );
  2781. };
  2782. it = cArr->find("ref_id");
  2783. if( it != cArr->end() ){
  2784. tPtr->ref_id = atoi( it->second.c_str() );
  2785. };
  2786. it = cArr->find("ref_uuid");
  2787. if( it != cArr->end() ){
  2788. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  2789. };
  2790. };
  2791. };
  2792. };
  2793. deleteResult( result );
  2794. };
  2795. return tPtr;
  2796. };
  2797. #undef LOG
  2798. #undef LOG_ERROR