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.

97 lines
3.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "protocolZLMEDIA.h"
  2. #include "../json/json_tool.h"
  3. #include <json/value.h>
  4. #include <json/writer.h>
  5. #include <json/reader.h>
  6. #define LOG( X ) basicLogCollection::getInstance()->Log( "ZLMEDIA", this, X )
  7. #define LOG_ERROR( X ) basicLogCollection::getInstance()->Log( "ZLMEDIA", this, _LOG_ERROR, X )
  8. protocolZLMEDIA::protocolZLMEDIA( config_setting_t *Settings ): protocolHTTP( basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_CONNECTION") ){
  9. m_pLog = basicLogCollection::getInstance();
  10. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_CONNECTION");
  11. /*
  12. if( m_pSettings != NULL ){
  13. config_setting_t *pSetting;
  14. if (!config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char**)&m_pScannerName)){
  15. strncpy( m_pScannerName, "LRF_2D_001", 64 );
  16. LOG( m_pScannerName );
  17. pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
  18. config_setting_set_string(pSetting, m_pScannerName);
  19. basicSettingsProvider::getInstance()->compromise();
  20. };
  21. if (!config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions )){
  22. m_nScannerDimentions = 2;
  23. pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
  24. config_setting_set_int(pSetting, m_nScannerDimentions);
  25. basicSettingsProvider::getInstance()->compromise();
  26. };
  27. if (!config_setting_lookup_string(m_pSettings, "LCU_IP_ADDRESS", (const char**)&m_pServerIP)){
  28. strncpy( m_pServerIP, "192.168.200.204", 16 );
  29. LOG( m_pServerIP );
  30. pSetting = config_setting_add(m_pSettings, "LCU_IP_ADDRESS", CONFIG_TYPE_STRING);
  31. config_setting_set_string(pSetting, m_pServerIP);
  32. basicSettingsProvider::getInstance()->compromise();
  33. };
  34. if (!config_setting_lookup_int(m_pSettings, "LCU_IP_PORT", &m_nServerPort)){
  35. m_nServerPort = 80;
  36. pSetting = config_setting_add(m_pSettings, "LCU_IP_PORT", CONFIG_TYPE_INT);
  37. config_setting_set_int(pSetting, m_nServerPort);
  38. basicSettingsProvider::getInstance()->compromise();
  39. };
  40. basicSettingsProvider::getInstance()->validate();
  41. }; //*/
  42. };
  43. protocolZLMEDIA::~protocolZLMEDIA(){
  44. };
  45. bool protocolZLMEDIA::packetHandler( protocolPackage *Package ){
  46. if( Package == NULL )return false;
  47. if( Package->m_nSize == 0 ) return false;
  48. if( Package->m_pData == NULL ) return false;
  49. if( Package->m_nCode != 200 ) return false;
  50. try{
  51. Json::Value root;
  52. Json::Reader reader;
  53. if( !reader.parse( (char *)Package->m_pData, root ) ){
  54. LOG_ERROR( "Error parsing the string" );
  55. return false;
  56. };
  57. for( Json::Value::const_iterator outer = root.begin() ; outer != root.end() ; outer++ ){
  58. for( Json::Value::const_iterator inner = (*outer).begin() ; inner!= (*outer).end() ; inner++ ){
  59. char tBuffer[256];
  60. sprintf( tBuffer,"Data: %s: %s ", inner.key().asString().c_str(), (*inner).asString().c_str() );
  61. LOG( tBuffer );
  62. };
  63. };
  64. } catch (exception e ){
  65. return false;
  66. };
  67. return true;
  68. };
  69. // Issue New Online Check but return current value
  70. bool protocolZLMEDIA::isOnline(){
  71. if( !m_bSessionOnGo ) {
  72. char URL[256];
  73. uint8_t timeout = 100; // 1 sec.
  74. m_bSessionOnGo = true;
  75. if( m_bUseSSL ) {
  76. sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, m_pAccessPoint, m_pSecret );
  77. } else {
  78. };
  79. issuePost(CSTR URL, char *Buffer, int &BufferSize )
  80. while( m_bSessionOnGo && timeout-- ) SLEEP(10);
  81. };
  82. return m_bServerIsPresent;
  83. };
  84. #undef LOG
  85. #undef LOG_ERROR