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.
99 lines
3.9 KiB
99 lines
3.9 KiB
#include "protocolZLMEDIA.h"
|
|
#include "../json/json_tool.h"
|
|
#include <json/value.h>
|
|
#include <json/writer.h>
|
|
#include <json/reader.h>
|
|
|
|
#define LOG( X ) basicLogCollection::getInstance()->Log( "ZLMEDIA", this, X )
|
|
#define LOG_ERROR( X ) basicLogCollection::getInstance()->Log( "ZLMEDIA", this, _LOG_ERROR, X )
|
|
|
|
protocolZLMEDIA::protocolZLMEDIA( config_setting_t *Settings ): protocolHTTP( basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_CONNECTION") ){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "ZLMEDIA_CONNECTION");
|
|
/*
|
|
if( m_pSettings != NULL ){
|
|
|
|
config_setting_t *pSetting;
|
|
|
|
if (!config_setting_lookup_string(m_pSettings, "SCANNER_NAME", (const char**)&m_pScannerName)){
|
|
strncpy( m_pScannerName, "LRF_2D_001", 64 );
|
|
LOG( m_pScannerName );
|
|
pSetting = config_setting_add(m_pSettings, "SCANNER_NAME", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pScannerName);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_int(m_pSettings, "SCANNER_DIMENTIONS", &m_nScannerDimentions )){
|
|
m_nScannerDimentions = 2;
|
|
pSetting = config_setting_add(m_pSettings, "SCANNER_DIMENTIONS", CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nScannerDimentions);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_string(m_pSettings, "LCU_IP_ADDRESS", (const char**)&m_pServerIP)){
|
|
strncpy( m_pServerIP, "192.168.200.204", 16 );
|
|
LOG( m_pServerIP );
|
|
pSetting = config_setting_add(m_pSettings, "LCU_IP_ADDRESS", CONFIG_TYPE_STRING);
|
|
config_setting_set_string(pSetting, m_pServerIP);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
if (!config_setting_lookup_int(m_pSettings, "LCU_IP_PORT", &m_nServerPort)){
|
|
m_nServerPort = 80;
|
|
pSetting = config_setting_add(m_pSettings, "LCU_IP_PORT", CONFIG_TYPE_INT);
|
|
config_setting_set_int(pSetting, m_nServerPort);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
|
|
basicSettingsProvider::getInstance()->validate();
|
|
|
|
}; //*/
|
|
};
|
|
|
|
protocolZLMEDIA::~protocolZLMEDIA(){
|
|
};
|
|
|
|
bool protocolZLMEDIA::packetHandler( protocolPackage *Package ){
|
|
if( Package == NULL )return false;
|
|
if( Package->m_nSize == 0 ) return false;
|
|
if( Package->m_pData == NULL ) return false;
|
|
if( Package->m_nCode != 200 ) return false;
|
|
try{
|
|
Json::Value root;
|
|
Json::Reader reader;
|
|
if( !reader.parse( (char *)Package->m_pData, root ) ){
|
|
LOG_ERROR( "Error parsing the string" );
|
|
return false;
|
|
};
|
|
for( Json::Value::const_iterator outer = root.begin() ; outer != root.end() ; outer++ ){
|
|
for( Json::Value::const_iterator inner = (*outer).begin() ; inner!= (*outer).end() ; inner++ ){
|
|
char tBuffer[256];
|
|
sprintf( tBuffer,"Data: %s: %s ", inner.key().asString().c_str(), (*inner).asString().c_str() );
|
|
LOG( tBuffer );
|
|
};
|
|
};
|
|
} catch (exception e ){
|
|
return false;
|
|
};
|
|
return true;
|
|
};
|
|
// Issue New Online Check but return current value
|
|
bool protocolZLMEDIA::isOnline(){
|
|
if( !m_bSessionOnGo ) {
|
|
char URL[256];
|
|
uint8_t timeout = 100; // 1 sec.
|
|
m_bSessionOnGo = true;
|
|
if( m_bUseSSL ) {
|
|
sprintf(URL,"https://%s:%d/%s?secret=%s", m_pIP, m_nPort, m_pAccessPoint, m_pSecret );
|
|
} else {
|
|
sprintf(URL,"http://%s:%d/%s?secret=%s", m_pIP, m_nPort, m_pAccessPoint, m_pSecret );
|
|
};
|
|
//ToDo: Check if OK to send nothing for checking Onlines
|
|
int len = 0;
|
|
issuePost( URL, NULL, len );
|
|
while( m_bSessionOnGo && timeout-- ) SLEEP(10);
|
|
};
|
|
return m_bServerIsPresent;
|
|
};
|
|
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|