Commit 618e6fba authored by Pavel Vainerman's avatar Pavel Vainerman

make style, fix docs

parent 1a629d75
...@@ -11,112 +11,112 @@ ...@@ -11,112 +11,112 @@
/*! Ничего не делающая реализация MBSlave для тестирования */ /*! Ничего не делающая реализация MBSlave для тестирования */
class MBSlave class MBSlave
{ {
public: public:
MBSlave( const std::unordered_set<uniset::ModbusRTU::ModbusAddr>& vaddr, const std::string& dev, const std::string& speed, bool use485 = false ); MBSlave( const std::unordered_set<uniset::ModbusRTU::ModbusAddr>& vaddr, const std::string& dev, const std::string& speed, bool use485 = false );
~MBSlave(); ~MBSlave();
inline void setVerbose( bool state ) inline void setVerbose( bool state )
{ {
verbose = state; verbose = state;
} }
inline void setReply( long val ) inline void setReply( long val )
{ {
replyVal = val; replyVal = val;
} }
inline void setReply2( long val ) inline void setReply2( long val )
{ {
replyVal2 = val; replyVal2 = val;
} }
inline void setReply3( long val ) inline void setReply3( long val )
{ {
replyVal3 = val; replyVal3 = val;
} }
void execute(); /*!< основной цикл работы */ void execute(); /*!< основной цикл работы */
void setLog( std::shared_ptr<DebugStream> dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
protected: protected:
// действия при завершении работы // действия при завершении работы
void sigterm( int signo ); void sigterm( int signo );
/*! обработка 0x01 */ /*! обработка 0x01 */
uniset::ModbusRTU::mbErrCode readCoilStatus( uniset::ModbusRTU::ReadCoilMessage& query, uniset::ModbusRTU::mbErrCode readCoilStatus( uniset::ModbusRTU::ReadCoilMessage& query,
uniset::ModbusRTU::ReadCoilRetMessage& reply ); uniset::ModbusRTU::ReadCoilRetMessage& reply );
/*! обработка 0x02 */ /*! обработка 0x02 */
uniset::ModbusRTU::mbErrCode readInputStatus( uniset::ModbusRTU::ReadInputStatusMessage& query, uniset::ModbusRTU::mbErrCode readInputStatus( uniset::ModbusRTU::ReadInputStatusMessage& query,
uniset::ModbusRTU::ReadInputStatusRetMessage& reply ); uniset::ModbusRTU::ReadInputStatusRetMessage& reply );
/*! обработка 0x03 */ /*! обработка 0x03 */
uniset::ModbusRTU::mbErrCode readOutputRegisters( uniset::ModbusRTU::ReadOutputMessage& query, uniset::ModbusRTU::mbErrCode readOutputRegisters( uniset::ModbusRTU::ReadOutputMessage& query,
uniset::ModbusRTU::ReadOutputRetMessage& reply ); uniset::ModbusRTU::ReadOutputRetMessage& reply );
/*! обработка 0x04 */ /*! обработка 0x04 */
uniset::ModbusRTU::mbErrCode readInputRegisters( uniset::ModbusRTU::ReadInputMessage& query, uniset::ModbusRTU::mbErrCode readInputRegisters( uniset::ModbusRTU::ReadInputMessage& query,
uniset::ModbusRTU::ReadInputRetMessage& reply ); uniset::ModbusRTU::ReadInputRetMessage& reply );
/*! обработка 0x05 */ /*! обработка 0x05 */
uniset::ModbusRTU::mbErrCode forceSingleCoil( uniset::ModbusRTU::ForceSingleCoilMessage& query, uniset::ModbusRTU::mbErrCode forceSingleCoil( uniset::ModbusRTU::ForceSingleCoilMessage& query,
uniset::ModbusRTU::ForceSingleCoilRetMessage& reply ); uniset::ModbusRTU::ForceSingleCoilRetMessage& reply );
/*! обработка 0x0F */ /*! обработка 0x0F */
uniset::ModbusRTU::mbErrCode forceMultipleCoils( uniset::ModbusRTU::ForceCoilsMessage& query, uniset::ModbusRTU::mbErrCode forceMultipleCoils( uniset::ModbusRTU::ForceCoilsMessage& query,
uniset::ModbusRTU::ForceCoilsRetMessage& reply ); uniset::ModbusRTU::ForceCoilsRetMessage& reply );
/*! обработка 0x10 */ /*! обработка 0x10 */
uniset::ModbusRTU::mbErrCode writeOutputRegisters( uniset::ModbusRTU::WriteOutputMessage& query, uniset::ModbusRTU::mbErrCode writeOutputRegisters( uniset::ModbusRTU::WriteOutputMessage& query,
uniset::ModbusRTU::WriteOutputRetMessage& reply ); uniset::ModbusRTU::WriteOutputRetMessage& reply );
/*! обработка 0x06 */ /*! обработка 0x06 */
uniset::ModbusRTU::mbErrCode writeOutputSingleRegister( uniset::ModbusRTU::WriteSingleOutputMessage& query, uniset::ModbusRTU::mbErrCode writeOutputSingleRegister( uniset::ModbusRTU::WriteSingleOutputMessage& query,
uniset::ModbusRTU::WriteSingleOutputRetMessage& reply ); uniset::ModbusRTU::WriteSingleOutputRetMessage& reply );
/*! обработка запросов на чтение ошибок */ /*! обработка запросов на чтение ошибок */
uniset::ModbusRTU::mbErrCode journalCommand( uniset::ModbusRTU::JournalCommandMessage& query, uniset::ModbusRTU::mbErrCode journalCommand( uniset::ModbusRTU::JournalCommandMessage& query,
uniset::ModbusRTU::JournalCommandRetMessage& reply ); uniset::ModbusRTU::JournalCommandRetMessage& reply );
/*! обработка запроса на установку времени */ /*! обработка запроса на установку времени */
uniset::ModbusRTU::mbErrCode setDateTime( uniset::ModbusRTU::SetDateTimeMessage& query, uniset::ModbusRTU::mbErrCode setDateTime( uniset::ModbusRTU::SetDateTimeMessage& query,
uniset::ModbusRTU::SetDateTimeRetMessage& reply ); uniset::ModbusRTU::SetDateTimeRetMessage& reply );
/*! обработка запроса удалённого сервиса */ /*! обработка запроса удалённого сервиса */
uniset::ModbusRTU::mbErrCode remoteService( uniset::ModbusRTU::RemoteServiceMessage& query, uniset::ModbusRTU::mbErrCode remoteService( uniset::ModbusRTU::RemoteServiceMessage& query,
uniset::ModbusRTU::RemoteServiceRetMessage& reply ); uniset::ModbusRTU::RemoteServiceRetMessage& reply );
uniset::ModbusRTU::mbErrCode fileTransfer( uniset::ModbusRTU::FileTransferMessage& query, uniset::ModbusRTU::mbErrCode fileTransfer( uniset::ModbusRTU::FileTransferMessage& query,
uniset::ModbusRTU::FileTransferRetMessage& reply ); uniset::ModbusRTU::FileTransferRetMessage& reply );
uniset::ModbusRTU::mbErrCode diagnostics( uniset::ModbusRTU::DiagnosticMessage& query, uniset::ModbusRTU::mbErrCode diagnostics( uniset::ModbusRTU::DiagnosticMessage& query,
uniset::ModbusRTU::DiagnosticRetMessage& reply ); uniset::ModbusRTU::DiagnosticRetMessage& reply );
uniset::ModbusRTU::mbErrCode read4314( uniset::ModbusRTU::MEIMessageRDI& query, uniset::ModbusRTU::mbErrCode read4314( uniset::ModbusRTU::MEIMessageRDI& query,
uniset::ModbusRTU::MEIMessageRetRDI& reply ); uniset::ModbusRTU::MEIMessageRetRDI& reply );
/*! интерфейс ModbusRTUSlave для обмена по RS */ /*! интерфейс ModbusRTUSlave для обмена по RS */
uniset::ModbusRTUSlaveSlot* rscomm; uniset::ModbusRTUSlaveSlot* rscomm;
std::unordered_set<uniset::ModbusRTU::ModbusAddr> vaddr; /*!< адреса на которые отвечаем */ std::unordered_set<uniset::ModbusRTU::ModbusAddr> vaddr; /*!< адреса на которые отвечаем */
bool verbose; bool verbose;
#if 0 #if 0
typedef std::unordered_map<uniset::ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap; typedef std::unordered_map<uniset::ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap;
ExchangeErrorMap errmap; /*!< статистика обмена */ ExchangeErrorMap errmap; /*!< статистика обмена */
uniset::ModbusRTU::mbErrCode prev; uniset::ModbusRTU::mbErrCode prev;
// можно было бы сделать unsigned, но аналоговые датчики у нас имеют // можно было бы сделать unsigned, но аналоговые датчики у нас имеют
// тип long. А это число передаётся в графику в виде аналогового датчика // тип long. А это число передаётся в графику в виде аналогового датчика
long askCount; /*!< количество принятых запросов */ long askCount; /*!< количество принятых запросов */
typedef std::unordered_map<int, std::string> FileList; typedef std::unordered_map<int, std::string> FileList;
FileList flist; FileList flist;
#endif #endif
long replyVal; long replyVal;
long replyVal2; long replyVal2;
long replyVal3; long replyVal3;
private: private:
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -9,111 +9,111 @@ ...@@ -9,111 +9,111 @@
/*! Ничего не делающая реализация MBTCPServer для тестирования */ /*! Ничего не делающая реализация MBTCPServer для тестирования */
class MBTCPServer class MBTCPServer
{ {
public: public:
MBTCPServer( const std::unordered_set<uniset::ModbusRTU::ModbusAddr>& myaddr, const std::string& inetaddr, int port = 502, bool verbose = false ); MBTCPServer( const std::unordered_set<uniset::ModbusRTU::ModbusAddr>& myaddr, const std::string& inetaddr, int port = 502, bool verbose = false );
~MBTCPServer(); ~MBTCPServer();
inline void setVerbose( bool state ) inline void setVerbose( bool state )
{ {
verbose = state; verbose = state;
} }
inline void setReply( long val ) inline void setReply( long val )
{ {
replyVal = val; replyVal = val;
} }
inline uniset::timeout_t setAfterSendPause( uniset::timeout_t msec ) inline uniset::timeout_t setAfterSendPause( uniset::timeout_t msec )
{ {
return sslot->setAfterSendPause(msec); return sslot->setAfterSendPause(msec);
} }
void execute(); /*!< основной цикл работы */ void execute(); /*!< основной цикл работы */
void setLog( std::shared_ptr<DebugStream>& dlog ); void setLog( std::shared_ptr<DebugStream>& dlog );
void setMaxSessions( size_t max ); void setMaxSessions( size_t max );
protected: protected:
// действия при завершении работы // действия при завершении работы
void sigterm( int signo ); void sigterm( int signo );
/*! обработка 0x01 */ /*! обработка 0x01 */
uniset::ModbusRTU::mbErrCode readCoilStatus( uniset::ModbusRTU::ReadCoilMessage& query, uniset::ModbusRTU::mbErrCode readCoilStatus( uniset::ModbusRTU::ReadCoilMessage& query,
uniset::ModbusRTU::ReadCoilRetMessage& reply ); uniset::ModbusRTU::ReadCoilRetMessage& reply );
/*! обработка 0x02 */ /*! обработка 0x02 */
uniset::ModbusRTU::mbErrCode readInputStatus( uniset::ModbusRTU::ReadInputStatusMessage& query, uniset::ModbusRTU::mbErrCode readInputStatus( uniset::ModbusRTU::ReadInputStatusMessage& query,
uniset::ModbusRTU::ReadInputStatusRetMessage& reply ); uniset::ModbusRTU::ReadInputStatusRetMessage& reply );
/*! обработка 0x03 */ /*! обработка 0x03 */
uniset::ModbusRTU::mbErrCode readOutputRegisters( uniset::ModbusRTU::ReadOutputMessage& query, uniset::ModbusRTU::mbErrCode readOutputRegisters( uniset::ModbusRTU::ReadOutputMessage& query,
uniset::ModbusRTU::ReadOutputRetMessage& reply ); uniset::ModbusRTU::ReadOutputRetMessage& reply );
/*! обработка 0x04 */ /*! обработка 0x04 */
uniset::ModbusRTU::mbErrCode readInputRegisters( uniset::ModbusRTU::ReadInputMessage& query, uniset::ModbusRTU::mbErrCode readInputRegisters( uniset::ModbusRTU::ReadInputMessage& query,
uniset::ModbusRTU::ReadInputRetMessage& reply ); uniset::ModbusRTU::ReadInputRetMessage& reply );
/*! обработка 0x05 */ /*! обработка 0x05 */
uniset::ModbusRTU::mbErrCode forceSingleCoil( uniset::ModbusRTU::ForceSingleCoilMessage& query, uniset::ModbusRTU::mbErrCode forceSingleCoil( uniset::ModbusRTU::ForceSingleCoilMessage& query,
uniset::ModbusRTU::ForceSingleCoilRetMessage& reply ); uniset::ModbusRTU::ForceSingleCoilRetMessage& reply );
/*! обработка 0x0F */ /*! обработка 0x0F */
uniset::ModbusRTU::mbErrCode forceMultipleCoils( uniset::ModbusRTU::ForceCoilsMessage& query, uniset::ModbusRTU::mbErrCode forceMultipleCoils( uniset::ModbusRTU::ForceCoilsMessage& query,
uniset::ModbusRTU::ForceCoilsRetMessage& reply ); uniset::ModbusRTU::ForceCoilsRetMessage& reply );
/*! обработка 0x10 */ /*! обработка 0x10 */
uniset::ModbusRTU::mbErrCode writeOutputRegisters( uniset::ModbusRTU::WriteOutputMessage& query, uniset::ModbusRTU::mbErrCode writeOutputRegisters( uniset::ModbusRTU::WriteOutputMessage& query,
uniset::ModbusRTU::WriteOutputRetMessage& reply ); uniset::ModbusRTU::WriteOutputRetMessage& reply );
/*! обработка 0x06 */ /*! обработка 0x06 */
uniset::ModbusRTU::mbErrCode writeOutputSingleRegister( uniset::ModbusRTU::WriteSingleOutputMessage& query, uniset::ModbusRTU::mbErrCode writeOutputSingleRegister( uniset::ModbusRTU::WriteSingleOutputMessage& query,
uniset::ModbusRTU::WriteSingleOutputRetMessage& reply ); uniset::ModbusRTU::WriteSingleOutputRetMessage& reply );
uniset::ModbusRTU::mbErrCode diagnostics( uniset::ModbusRTU::DiagnosticMessage& query, uniset::ModbusRTU::mbErrCode diagnostics( uniset::ModbusRTU::DiagnosticMessage& query,
uniset::ModbusRTU::DiagnosticRetMessage& reply ); uniset::ModbusRTU::DiagnosticRetMessage& reply );
uniset::ModbusRTU::mbErrCode read4314( uniset::ModbusRTU::MEIMessageRDI& query, uniset::ModbusRTU::mbErrCode read4314( uniset::ModbusRTU::MEIMessageRDI& query,
uniset::ModbusRTU::MEIMessageRetRDI& reply ); uniset::ModbusRTU::MEIMessageRetRDI& reply );
/*! обработка запросов на чтение ошибок */ /*! обработка запросов на чтение ошибок */
uniset::ModbusRTU::mbErrCode journalCommand( uniset::ModbusRTU::JournalCommandMessage& query, uniset::ModbusRTU::mbErrCode journalCommand( uniset::ModbusRTU::JournalCommandMessage& query,
uniset::ModbusRTU::JournalCommandRetMessage& reply ); uniset::ModbusRTU::JournalCommandRetMessage& reply );
/*! обработка запроса на установку времени */ /*! обработка запроса на установку времени */
uniset::ModbusRTU::mbErrCode setDateTime( uniset::ModbusRTU::SetDateTimeMessage& query, uniset::ModbusRTU::mbErrCode setDateTime( uniset::ModbusRTU::SetDateTimeMessage& query,
uniset::ModbusRTU::SetDateTimeRetMessage& reply ); uniset::ModbusRTU::SetDateTimeRetMessage& reply );
/*! обработка запроса удалённого сервиса */ /*! обработка запроса удалённого сервиса */
uniset::ModbusRTU::mbErrCode remoteService( uniset::ModbusRTU::RemoteServiceMessage& query, uniset::ModbusRTU::mbErrCode remoteService( uniset::ModbusRTU::RemoteServiceMessage& query,
uniset::ModbusRTU::RemoteServiceRetMessage& reply ); uniset::ModbusRTU::RemoteServiceRetMessage& reply );
uniset::ModbusRTU::mbErrCode fileTransfer( uniset::ModbusRTU::FileTransferMessage& query, uniset::ModbusRTU::mbErrCode fileTransfer( uniset::ModbusRTU::FileTransferMessage& query,
uniset::ModbusRTU::FileTransferRetMessage& reply ); uniset::ModbusRTU::FileTransferRetMessage& reply );
/*! интерфейс ModbusSlave для обмена по RS */ /*! интерфейс ModbusSlave для обмена по RS */
uniset::ModbusTCPServerSlot* sslot; uniset::ModbusTCPServerSlot* sslot;
std::unordered_set<uniset::ModbusRTU::ModbusAddr> vaddr; /*!< адреса данного узла */ std::unordered_set<uniset::ModbusRTU::ModbusAddr> vaddr; /*!< адреса данного узла */
bool verbose = { false }; bool verbose = { false };
long replyVal = { -1 }; long replyVal = { -1 };
#if 0 #if 0
typedef std::unordered_map<uniset::ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap; typedef std::unordered_map<uniset::ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap;
ExchangeErrorMap errmap; /*!< статистика обмена */ ExchangeErrorMap errmap; /*!< статистика обмена */
uniset::ModbusRTU::mbErrCode prev; uniset::ModbusRTU::mbErrCode prev;
// можно было бы сделать unsigned, но аналоговые датчики у нас имеют // можно было бы сделать unsigned, но аналоговые датчики у нас имеют
// тип long. А это число передаётся в графику в виде аналогового датчика // тип long. А это число передаётся в графику в виде аналогового датчика
long askCount; /*!< количество принятых запросов */ long askCount; /*!< количество принятых запросов */
typedef std::unordered_map<int, std::string> FileList; typedef std::unordered_map<int, std::string> FileList;
FileList flist; FileList flist;
#endif #endif
private: private:
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -10,147 +10,147 @@ using namespace std; ...@@ -10,147 +10,147 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static struct option longopts[] = static struct option longopts[] =
{ {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "device", required_argument, 0, 'd' }, { "device", required_argument, 0, 'd' },
{ "verbose", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'v' },
{ "myaddr", required_argument, 0, 'a' }, { "myaddr", required_argument, 0, 'a' },
{ "speed", required_argument, 0, 's' }, { "speed", required_argument, 0, 's' },
{ "use485F", no_argument, 0, 'y' }, { "use485F", no_argument, 0, 'y' },
{ "const-reply", required_argument, 0, 'c' }, { "const-reply", required_argument, 0, 'c' },
{ NULL, 0, 0, 0 } { NULL, 0, 0, 0 }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("-h|--help - this message\n"); printf("-h|--help - this message\n");
printf("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-d|--device] dev - use device dev. Default: /dev/ttyS0\n"); printf("[-d|--device] dev - use device dev. Default: /dev/ttyS0\n");
printf("[-a|--myaddr] addr - Modbus address for master. Default: 0x01.\n"); printf("[-a|--myaddr] addr - Modbus address for master. Default: 0x01.\n");
printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n"); printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
printf("[-y|--use485F] - use RS485 Fastwel.\n"); printf("[-y|--use485F] - use RS485 Fastwel.\n");
printf("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-c|--const-reply] val1 [val2 val3] - Reply val for all queries\n"); printf("[-c|--const-reply] val1 [val2 val3] - Reply val for all queries\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static char* checkArg( int ind, int argc, char* argv[] ); static char* checkArg( int ind, int argc, char* argv[] );
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
string dev("/dev/ttyS0"); string dev("/dev/ttyS0");
string speed("38400"); string speed("38400");
ModbusRTU::ModbusAddr myaddr = 0x01; ModbusRTU::ModbusAddr myaddr = 0x01;
auto dlog = make_shared<DebugStream>(); auto dlog = make_shared<DebugStream>();
int use485 = 0; int use485 = 0;
int replyVal = -1; int replyVal = -1;
int replyVal2 = -1; int replyVal2 = -1;
int replyVal3 = -1; int replyVal3 = -1;
try try
{ {
while(1) while(1)
{ {
opt = getopt_long(argc, argv, "hva:d:s:yc:", longopts, &optindex); opt = getopt_long(argc, argv, "hva:d:s:yc:", longopts, &optindex);
if( opt == -1 ) if( opt == -1 )
break; break;
switch (opt) switch (opt)
{ {
case 'h': case 'h':
print_help(); print_help();
return 0; return 0;
case 'd': case 'd':
dev = string(optarg); dev = string(optarg);
break; break;
case 's': case 's':
speed = string(optarg); speed = string(optarg);
break; break;
case 'a': case 'a':
myaddr = ModbusRTU::str2mbAddr(optarg); myaddr = ModbusRTU::str2mbAddr(optarg);
break; break;
case 'v': case 'v':
verb = 1; verb = 1;
break; break;
case 'y': case 'y':
use485 = 1; use485 = 1;
break; break;
case 'c': case 'c':
replyVal = uni_atoi(optarg); replyVal = uni_atoi(optarg);
if( checkArg(optind, argc, argv) ) if( checkArg(optind, argc, argv) )
replyVal2 = uni_atoi(argv[optind]); replyVal2 = uni_atoi(argv[optind]);
if( checkArg(optind + 1, argc, argv) ) if( checkArg(optind + 1, argc, argv) )
replyVal3 = uni_atoi(argv[optind + 1]); replyVal3 = uni_atoi(argv[optind + 1]);
break; break;
case '?': case '?':
default: default:
printf("? argumnet\n"); printf("? argumnet\n");
return 0; return 0;
} }
} }
if( verb ) if( verb )
{ {
cout << "(init): dev=" << dev << " speed=" << speed cout << "(init): dev=" << dev << " speed=" << speed
<< " myaddr=" << ModbusRTU::addr2str(myaddr) << " myaddr=" << ModbusRTU::addr2str(myaddr)
<< endl; << endl;
dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
} }
/*! \todo Доделать возможность задавать много адресов для ответа */ /*! \todo Доделать возможность задавать много адресов для ответа */
std::unordered_set<ModbusRTU::ModbusAddr> vaddr; std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
vaddr.emplace(myaddr); vaddr.emplace(myaddr);
MBSlave mbs(vaddr, dev, speed, use485); MBSlave mbs(vaddr, dev, speed, use485);
mbs.setLog(dlog); mbs.setLog(dlog);
mbs.setVerbose(verb); mbs.setVerbose(verb);
if( replyVal != -1 ) if( replyVal != -1 )
mbs.setReply(replyVal); mbs.setReply(replyVal);
if( replyVal2 != -1 ) if( replyVal2 != -1 )
mbs.setReply2(replyVal2); mbs.setReply2(replyVal2);
if( replyVal3 != -1 ) if( replyVal3 != -1 )
mbs.setReply3(replyVal3); mbs.setReply3(replyVal3);
mbs.execute(); mbs.execute();
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
cerr << "(mbtester): " << ex << endl; cerr << "(mbtester): " << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(mbslave): " << ex.what() << endl; cerr << "(mbslave): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(mbslave): catch(...)" << endl; cerr << "(mbslave): catch(...)" << endl;
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
char* checkArg( int i, int argc, char* argv[] ) char* checkArg( int i, int argc, char* argv[] )
{ {
if( i < argc && (argv[i])[0] != '-' ) if( i < argc && (argv[i])[0] != '-' )
return argv[i]; return argv[i];
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -10,150 +10,150 @@ using namespace std; ...@@ -10,150 +10,150 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static struct option longopts[] = static struct option longopts[] =
{ {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "device", required_argument, 0, 'd' }, { "device", required_argument, 0, 'd' },
{ "verbose", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'v' },
{ "myaddr", required_argument, 0, 'a' }, { "myaddr", required_argument, 0, 'a' },
{ "speed", required_argument, 0, 's' }, { "speed", required_argument, 0, 's' },
{ "f485", no_argument, 0, 'g' }, { "f485", no_argument, 0, 'g' },
{ NULL, 0, 0, 0 } { NULL, 0, 0, 0 }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("-h|--help - this message\n"); printf("-h|--help - this message\n");
printf("[-t|--timeout] msec - Timeout. Default: 2000.\n"); printf("[-t|--timeout] msec - Timeout. Default: 2000.\n");
printf("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-d|--device] dev - use device dev. Default: /dev/ttyS0\n"); printf("[-d|--device] dev - use device dev. Default: /dev/ttyS0\n");
printf("[-a|--myaddr] addr1,addr2,... - Modbus address for this slave. Default: 0x01.\n"); printf("[-a|--myaddr] addr1,addr2,... - Modbus address for this slave. Default: 0x01.\n");
printf(" myaddr=0 - Reply to all RTU-addresses (broadcast).\n"); printf(" myaddr=0 - Reply to all RTU-addresses (broadcast).\n");
printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n"); printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
printf("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-g|--f485] - Use 485 Fastwel\n"); printf("[-g|--f485] - Use 485 Fastwel\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
int f485 = 0; int f485 = 0;
string dev("/dev/ttyS0"); string dev("/dev/ttyS0");
string speed("38400"); string speed("38400");
std::string myaddr("0x01"); std::string myaddr("0x01");
int tout = 2000; int tout = 2000;
DebugStream dlog; DebugStream dlog;
try try
{ {
while(1) while(1)
{ {
opt = getopt_long(argc, argv, "hva:d:s:c:", longopts, &optindex); opt = getopt_long(argc, argv, "hva:d:s:c:", longopts, &optindex);
if( opt == -1 ) if( opt == -1 )
break; break;
switch (opt) switch (opt)
{ {
case 'h': case 'h':
print_help(); print_help();
return 0; return 0;
case 'd': case 'd':
dev = string(optarg); dev = string(optarg);
break; break;
case 's': case 's':
speed = string(optarg); speed = string(optarg);
break; break;
case 't': case 't':
tout = uni_atoi(optarg); tout = uni_atoi(optarg);
break; break;
case 'a': case 'a':
myaddr = string(optarg); myaddr = string(optarg);
break; break;
case 'v': case 'v':
verb = 1; verb = 1;
break; break;
case 'g': case 'g':
f485 = 1; f485 = 1;
break; break;
case '?': case '?':
default: default:
printf("? argumnet\n"); printf("? argumnet\n");
return 0; return 0;
} }
} }
auto avec = uniset::explode_str(myaddr, ','); auto avec = uniset::explode_str(myaddr, ',');
std::unordered_set<ModbusRTU::ModbusAddr> vaddr; std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
for( const auto& a : avec ) for( const auto& a : avec )
vaddr.emplace( ModbusRTU::str2mbAddr(a) ); vaddr.emplace( ModbusRTU::str2mbAddr(a) );
if( verb ) if( verb )
{ {
cout << "(init): dev=" << dev << " speed=" << speed cout << "(init): dev=" << dev << " speed=" << speed
<< " myaddr=" << ModbusServer::vaddr2str(vaddr) << " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< " timeout=" << tout << " msec " << " timeout=" << tout << " msec "
<< endl; << endl;
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
} }
if( f485 ) if( f485 )
{ {
#ifndef DISABLE_COMPORT_485F #ifndef DISABLE_COMPORT_485F
ComPort485F* cp; ComPort485F* cp;
if( dev == "/dev/ttyS2" ) if( dev == "/dev/ttyS2" )
cp = new ComPort485F(dev, 5); cp = new ComPort485F(dev, 5);
else if( dev == "/dev/ttyS3" ) else if( dev == "/dev/ttyS3" )
cp = new ComPort485F(dev, 6); cp = new ComPort485F(dev, 6);
else else
{ {
cerr << "dev must be /dev/ttyS2 or /dev/tytS3" << endl; cerr << "dev must be /dev/ttyS2 or /dev/tytS3" << endl;
return 1; return 1;
} }
MBSlave mbs(cp, vaddr, speed); MBSlave mbs(cp, vaddr, speed);
mbs.setLog(dlog); mbs.setLog(dlog);
mbs.setVerbose(verb); mbs.setVerbose(verb);
mbs.execute(); mbs.execute();
#else #else
cerr << "DISABLE_COMPORT_485F" << endl; cerr << "DISABLE_COMPORT_485F" << endl;
return 1; return 1;
#endif // #ifndef DISABLE_COMPORT_485F #endif // #ifndef DISABLE_COMPORT_485F
} }
else else
{ {
MBSlave mbs(vaddr, dev, speed); MBSlave mbs(vaddr, dev, speed);
mbs.setLog(dlog); mbs.setLog(dlog);
mbs.setVerbose(verb); mbs.setVerbose(verb);
mbs.execute(); mbs.execute();
} }
} }
catch( const ModbusRTU::mbException& ex ) catch( const ModbusRTU::mbException& ex )
{ {
cerr << "(mbtester): " << ex << endl; cerr << "(mbtester): " << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(mbslave): " << ex.what() << endl; cerr << "(mbslave): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(mbslave): catch(...)" << endl; cerr << "(mbslave): catch(...)" << endl;
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -9,134 +9,134 @@ using namespace std; ...@@ -9,134 +9,134 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static struct option longopts[] = static struct option longopts[] =
{ {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "iaddr", required_argument, 0, 'i' }, { "iaddr", required_argument, 0, 'i' },
{ "verbose", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'v' },
{ "myaddr", required_argument, 0, 'a' }, { "myaddr", required_argument, 0, 'a' },
{ "port", required_argument, 0, 'p' }, { "port", required_argument, 0, 'p' },
{ "const-reply", required_argument, 0, 'c' }, { "const-reply", required_argument, 0, 'c' },
{ "after-send-pause", required_argument, 0, 's' }, { "after-send-pause", required_argument, 0, 's' },
{ "max-sessions", required_argument, 0, 'm' }, { "max-sessions", required_argument, 0, 'm' },
{ NULL, 0, 0, 0 } { NULL, 0, 0, 0 }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("Example: uniset-mbtcpserver-echo -i localhost -p 2049 -v \n"); printf("Example: uniset-mbtcpserver-echo -i localhost -p 2049 -v \n");
printf("-h|--help - this message\n"); printf("-h|--help - this message\n");
printf("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-i|--iaddr] ip - Server listen ip. Default 127.0.0.1\n"); printf("[-i|--iaddr] ip - Server listen ip. Default 127.0.0.1\n");
printf("[-a|--myaddr] addr1,addr2,... - Modbus address for master. Default: 0x01.\n"); printf("[-a|--myaddr] addr1,addr2,... - Modbus address for master. Default: 0x01.\n");
printf(" myaddr=0 - Reply to all RTU-addresses (broadcast).\n"); printf(" myaddr=0 - Reply to all RTU-addresses (broadcast).\n");
printf("[-p|--port] port - Server port. Default: 502.\n"); printf("[-p|--port] port - Server port. Default: 502.\n");
printf("[-c|--const-reply] val - Reply 'val' for all queries\n"); printf("[-c|--const-reply] val - Reply 'val' for all queries\n");
printf("[-s|--after-send-pause] msec - Pause after send request. Default: 0\n"); printf("[-s|--after-send-pause] msec - Pause after send request. Default: 0\n");
printf("[-m|--max-sessions] num - Set the maximum number of sessions. Default: 10\n"); printf("[-m|--max-sessions] num - Set the maximum number of sessions. Default: 10\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
int port = 502; int port = 502;
string iaddr("127.0.0.1"); string iaddr("127.0.0.1");
string myaddr("0x01"); string myaddr("0x01");
auto dlog = make_shared<DebugStream>(); auto dlog = make_shared<DebugStream>();
int replyVal = -1; int replyVal = -1;
timeout_t afterpause = 0; timeout_t afterpause = 0;
size_t maxSessions = 10; size_t maxSessions = 10;
try try
{ {
while(1) while(1)
{ {
opt = getopt_long(argc, argv, "hva:p:i:c:s:m:", longopts, &optindex); opt = getopt_long(argc, argv, "hva:p:i:c:s:m:", longopts, &optindex);
if( opt == -1 ) if( opt == -1 )
break; break;
switch (opt) switch (opt)
{ {
case 'h': case 'h':
print_help(); print_help();
return 0; return 0;
case 'i': case 'i':
iaddr = string(optarg); iaddr = string(optarg);
break; break;
case 'p': case 'p':
port = uni_atoi(optarg); port = uni_atoi(optarg);
break; break;
case 'a': case 'a':
myaddr = string(optarg); myaddr = string(optarg);
break; break;
case 'v': case 'v':
verb = 1; verb = 1;
break; break;
case 'c': case 'c':
replyVal = uni_atoi(optarg); replyVal = uni_atoi(optarg);
break; break;
case 's': case 's':
afterpause = uni_atoi(optarg); afterpause = uni_atoi(optarg);
break; break;
case 'm': case 'm':
maxSessions = uni_atoi(optarg); maxSessions = uni_atoi(optarg);
break; break;
case '?': case '?':
default: default:
printf("? argumnet\n"); printf("? argumnet\n");
return 0; return 0;
} }
} }
auto avec = uniset::explode_str(myaddr, ','); auto avec = uniset::explode_str(myaddr, ',');
std::unordered_set<ModbusRTU::ModbusAddr> vaddr; std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
for( const auto& a : avec ) for( const auto& a : avec )
vaddr.emplace( ModbusRTU::str2mbAddr(a) ); vaddr.emplace( ModbusRTU::str2mbAddr(a) );
if( verb ) if( verb )
{ {
cout << "(init): iaddr: " << iaddr << ":" << port cout << "(init): iaddr: " << iaddr << ":" << port
<< " myaddr=" << ModbusServer::vaddr2str(vaddr) << " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< endl; << endl;
dlog->addLevel( Debug::ANY ); dlog->addLevel( Debug::ANY );
} }
MBTCPServer mbs(vaddr, iaddr, port, verb); MBTCPServer mbs(vaddr, iaddr, port, verb);
mbs.setLog(dlog); mbs.setLog(dlog);
mbs.setVerbose(verb); mbs.setVerbose(verb);
mbs.setAfterSendPause(afterpause); mbs.setAfterSendPause(afterpause);
mbs.setMaxSessions(maxSessions); mbs.setMaxSessions(maxSessions);
if( replyVal != -1 ) if( replyVal != -1 )
mbs.setReply(replyVal); mbs.setReply(replyVal);
mbs.execute(); mbs.execute();
} }
catch( const ModbusRTU::mbException& ex ) catch( const ModbusRTU::mbException& ex )
{ {
cerr << "(mbtcpserver): " << ex << endl; cerr << "(mbtcpserver): " << ex << endl;
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
cerr << "(mbtcpserver): " << e.what() << endl; cerr << "(mbtcpserver): " << e.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(mbtcpserver): catch(...)" << endl; cerr << "(mbtcpserver): catch(...)" << endl;
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -8,28 +8,28 @@ using namespace std; ...@@ -8,28 +8,28 @@ using namespace std;
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
NullController::NullController( ObjectId id, const string& ioconfile, NullController::NullController( ObjectId id, const string& ioconfile,
const std::string& s_filterField, const std::string& s_filterField,
const std::string& s_filterValue, const std::string& s_filterValue,
const std::string& c_filterField, const std::string& c_filterField,
const std::string& c_filterValue, const std::string& c_filterValue,
bool _dumpingToDB ): bool _dumpingToDB ):
IONotifyController(id), IONotifyController(id),
dumpingToDB(_dumpingToDB) dumpingToDB(_dumpingToDB)
{ {
restorer = NULL; restorer = NULL;
auto ioconf = make_shared<IOConfig_XML>(ioconfile, uniset_conf()); auto ioconf = make_shared<IOConfig_XML>(ioconfile, uniset_conf());
ioconf->setItemFilter(s_filterField, s_filterValue); ioconf->setItemFilter(s_filterField, s_filterValue);
ioconf->setConsumerFilter(c_filterField, c_filterValue); ioconf->setConsumerFilter(c_filterField, c_filterValue);
restorer = std::static_pointer_cast<IOConfig>(ioconf); restorer = std::static_pointer_cast<IOConfig>(ioconf);
/* /*
// askd->setReadItem( sigc::mem_fun(this,&NullController::readSItem) ); // askd->setReadItem( sigc::mem_fun(this,&NullController::readSItem) );
askd->setNCReadItem( sigc::mem_fun(this,&NullController::readSItem) ); askd->setNCReadItem( sigc::mem_fun(this,&NullController::readSItem) );
askd->setReadThresholdItem( sigc::mem_fun(this,&NullController::readTItem) ); askd->setReadThresholdItem( sigc::mem_fun(this,&NullController::readTItem) );
askd->setReadConsumerItem( sigc::mem_fun(this,&NullController::readCItem) ); askd->setReadConsumerItem( sigc::mem_fun(this,&NullController::readCItem) );
*/ */
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
...@@ -39,8 +39,8 @@ NullController::~NullController() ...@@ -39,8 +39,8 @@ NullController::~NullController()
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void NullController::dumpToDB() void NullController::dumpToDB()
{ {
if( dumpingToDB ) if( dumpingToDB )
IONotifyController::dumpToDB(); IONotifyController::dumpToDB();
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/* /*
......
...@@ -6,28 +6,28 @@ ...@@ -6,28 +6,28 @@
#include "IONotifyController.h" #include "IONotifyController.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class NullController: class NullController:
public uniset::IONotifyController public uniset::IONotifyController
{ {
public: public:
NullController(uniset::ObjectId id, const std::string& ioconfile, NullController(uniset::ObjectId id, const std::string& ioconfile,
const std::string& s_filterField = "", const std::string& s_filterField = "",
const std::string& s_filterValue = "", const std::string& s_filterValue = "",
const std::string& c_filterField = "", const std::string& c_filterField = "",
const std::string& c_filterValue = "", const std::string& c_filterValue = "",
bool _dumpingToDB = false ); bool _dumpingToDB = false );
virtual ~NullController(); virtual ~NullController();
protected: protected:
virtual void dumpToDB(); virtual void dumpToDB();
// bool readSItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec, NCRestorer::SInfo& inf ); // bool readSItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec, NCRestorer::SInfo& inf );
// bool readTItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec); // bool readTItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec);
// bool readCItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec); // bool readCItem( UniXML& xml, UniXML::iterator& it, xmlNode* sec);
private: private:
bool dumpingToDB; bool dumpingToDB;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
...@@ -9,86 +9,86 @@ using namespace std; ...@@ -9,86 +9,86 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void short_usage() static void short_usage()
{ {
cout << "Usage: uniset-nullController" cout << "Usage: uniset-nullController"
<< "--confile configure.xml. По умолчанию: configure.xml." << endl << "--confile configure.xml. По умолчанию: configure.xml." << endl
<< " --name ObjectId [--confile configure.xml] [--askfile filename] \n" << " --name ObjectId [--confile configure.xml] [--askfile filename] \n"
<< " --s-filter-field name - поле для фильтрования списка датчиков\n" << " --s-filter-field name - поле для фильтрования списка датчиков\n"
<< " --s-filter-value value - значение для поля фильтрования списка датчиков \n" << " --s-filter-value value - значение для поля фильтрования списка датчиков \n"
<< " --c-filter-field name - поле для фильтрования списка заказчиков по каждому датчику\n" << " --c-filter-field name - поле для фильтрования списка заказчиков по каждому датчику\n"
<< " --c-filter-value value - значение для поля фильтрования списка заказчиков по каждому датчику\n" << " --c-filter-value value - значение для поля фильтрования списка заказчиков по каждому датчику\n"
<< " --dbDumping [0,1] - создавать ли dump-файл \n"; << " --dbDumping [0,1] - создавать ли dump-файл \n";
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
try try
{ {
if( argc <= 1 ) if( argc <= 1 )
{ {
cerr << "\nНе указаны необходимые параметры\n\n"; cerr << "\nНе указаны необходимые параметры\n\n";
short_usage(); short_usage();
return 0; return 0;
} }
if( !strcmp(argv[1], "--help") ) if( !strcmp(argv[1], "--help") )
{ {
short_usage(); short_usage();
return 0; return 0;
} }
auto conf = uniset_init(argc, argv, "configure.xml"); auto conf = uniset_init(argc, argv, "configure.xml");
// определяем ID объекта // определяем ID объекта
string name = conf->getArgParam("--name"); string name = conf->getArgParam("--name");
if( name.empty()) if( name.empty())
{ {
cerr << "(nullController): не задан ObjectId!!! (--name)\n"; cerr << "(nullController): не задан ObjectId!!! (--name)\n";
return 0; return 0;
} }
ObjectId ID = conf->oind->getIdByName(conf->getControllersSection() + "/" + name); ObjectId ID = conf->oind->getIdByName(conf->getControllersSection() + "/" + name);
if( ID == uniset::DefaultObjectId ) if( ID == uniset::DefaultObjectId )
{ {
cerr << "(nullController): идентификатор '" << name cerr << "(nullController): идентификатор '" << name
<< "' не найден в конф. файле!" << "' не найден в конф. файле!"
<< " в секции " << conf->getControllersSection() << endl; << " в секции " << conf->getControllersSection() << endl;
return 0; return 0;
} }
// определяем ask-файл // определяем ask-файл
string askfile = conf->getArgParam("--askfile"); string askfile = conf->getArgParam("--askfile");
if( askfile.empty()) if( askfile.empty())
askfile = conf->getConfFileName(); askfile = conf->getConfFileName();
// определяем фильтр // определяем фильтр
string s_field = conf->getArgParam("--s-filter-field"); string s_field = conf->getArgParam("--s-filter-field");
string s_fvalue = conf->getArgParam("--s-filter-value"); string s_fvalue = conf->getArgParam("--s-filter-value");
string c_field = conf->getArgParam("--c-filter-field"); string c_field = conf->getArgParam("--c-filter-field");
string c_fvalue = conf->getArgParam("--c-filter-value"); string c_fvalue = conf->getArgParam("--c-filter-value");
// надо ли писать изменения в БД // надо ли писать изменения в БД
bool dbDumping = conf->getArgInt("--dbDumping"); bool dbDumping = conf->getArgInt("--dbDumping");
auto nc = make_shared<NullController>(ID, askfile, s_field, s_fvalue, c_field, c_fvalue, dbDumping); auto nc = make_shared<NullController>(ID, askfile, s_field, s_fvalue, c_field, c_fvalue, dbDumping);
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(nc); act->add(nc);
act->run(false); act->run(false);
return 0; return 0;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(nullController::main): " << ex.what() << endl; cerr << "(nullController::main): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(nullController::main): catch ..." << endl; cerr << "(nullController::main): catch ..." << endl;
} }
return 1; return 1;
} }
...@@ -9,57 +9,57 @@ using namespace std; ...@@ -9,57 +9,57 @@ using namespace std;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int main( int argc, const char** argv ) int main( int argc, const char** argv )
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
try try
{ {
if( argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h") ) ) if( argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h") ) )
{ {
cout << "Usage: uniset-smonit [ args ] --sid id1@node1,Sensor2@node2,id2,sensorname3,... " << endl cout << "Usage: uniset-smonit [ args ] --sid id1@node1,Sensor2@node2,id2,sensorname3,... " << endl
<< "Args: " << endl << "Args: " << endl
<< " --confile confilename - Default: configure.xml" << endl << " --confile confilename - Default: configure.xml" << endl
<< " --name XXX - name for smonit. Default: TestProc" << endl; << " --name XXX - name for smonit. Default: TestProc" << endl;
// << " --script scriptname \n" // << " --script scriptname \n"
return 0; return 0;
} }
auto conf = uniset_init(argc, argv, "configure.xml"); auto conf = uniset_init(argc, argv, "configure.xml");
ObjectId ID(DefaultObjectId); ObjectId ID(DefaultObjectId);
string name = conf->getArgParam("--name", "TestProc"); string name = conf->getArgParam("--name", "TestProc");
ID = conf->getObjectID(name); ID = conf->getObjectID(name);
if( ID == uniset::DefaultObjectId ) if( ID == uniset::DefaultObjectId )
{ {
cerr << "(main): идентификатор '" << name cerr << "(main): идентификатор '" << name
<< "' не найден в конф. файле!" << "' не найден в конф. файле!"
<< " в секции " << conf->getObjectsSection() << endl; << " в секции " << conf->getObjectsSection() << endl;
return 0; return 0;
} }
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
auto smon = make_shared<SMonitor>(ID); auto smon = make_shared<SMonitor>(ID);
act->add(smon); act->add(smon);
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
act->run(false); act->run(false);
return 0; return 0;
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cout << "(main):" << ex << endl; cout << "(main):" << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cout << "(main): exception: " << ex.what() << endl; cout << "(main): exception: " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cout << "(main): Unknown exception!!" << endl; cout << "(main): Unknown exception!!" << endl;
} }
return 1; return 1;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
...@@ -8,49 +8,49 @@ using namespace std; ...@@ -8,49 +8,49 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void short_usage() static void short_usage()
{ {
cout << "Usage: uniset-sviewer-text [--fullname] [--polltime msec] [--confile uniset-confile]\n"; cout << "Usage: uniset-sviewer-text [--fullname] [--polltime msec] [--confile uniset-confile]\n";
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
try try
{ {
if( argc > 1 && !strcmp(argv[1], "--help") ) if( argc > 1 && !strcmp(argv[1], "--help") )
{ {
short_usage(); short_usage();
return 0; return 0;
} }
auto conf = uniset_init(argc, argv, "configure.xml"); auto conf = uniset_init(argc, argv, "configure.xml");
bool fullname = false; bool fullname = false;
if( findArgParam("--fullname", conf->getArgc(), conf->getArgv()) != -1 ) if( findArgParam("--fullname", conf->getArgc(), conf->getArgv()) != -1 )
fullname = true; fullname = true;
SViewer sv(conf->getControllersSection(), !fullname); SViewer sv(conf->getControllersSection(), !fullname);
timeout_t timeMS = conf->getArgInt("--polltime"); timeout_t timeMS = conf->getArgInt("--polltime");
if( timeMS ) if( timeMS )
{ {
cout << "(main): просматриваем с периодом " << timeMS << "[мсек]" << endl; cout << "(main): просматриваем с периодом " << timeMS << "[мсек]" << endl;
sv.monitor(timeMS); sv.monitor(timeMS);
} }
else else
sv.view(); sv.view();
return 0; return 0;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(main): Поймали исключение " << ex.what() << endl; cerr << "(main): Поймали исключение " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(main): Неизвестное исключение!!!!" << endl; cerr << "(main): Неизвестное исключение!!!!" << endl;
} }
return 1; return 1;
} }
...@@ -11,100 +11,100 @@ using namespace std; ...@@ -11,100 +11,100 @@ using namespace std;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
static struct option longopts[] = static struct option longopts[] =
{ {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "iaddr", required_argument, 0, 'i' }, { "iaddr", required_argument, 0, 'i' },
{ "port", required_argument, 0, 'p' }, { "port", required_argument, 0, 'p' },
{ "verbose", no_argument, 0, 'v' }, { "verbose", no_argument, 0, 'v' },
{ NULL, 0, 0, 0 } { NULL, 0, 0, 0 }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("-h - this message\n"); printf("-h - this message\n");
printf("-v - Print all messages to stdout\n"); printf("-v - Print all messages to stdout\n");
printf("-i addr - LogServer ip or hostname. Default: localhost.\n"); printf("-i addr - LogServer ip or hostname. Default: localhost.\n");
printf("-p port - LogServer port. Default: 3333.\n"); printf("-p port - LogServer port. Default: 3333.\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char* argv[], char* envp[] ) int main( int argc, char* argv[], char* envp[] )
{ {
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
int verb = 0; int verb = 0;
string addr("localhost"); string addr("localhost");
int port = 3333; int port = 3333;
try try
{ {
while(1) while(1)
{ {
opt = getopt_long(argc, argv, "hvi:p:", longopts, &optindex); opt = getopt_long(argc, argv, "hvi:p:", longopts, &optindex);
if( opt == -1 ) if( opt == -1 )
break; break;
switch (opt) switch (opt)
{ {
case 'h': case 'h':
print_help(); print_help();
return 0; return 0;
case 'i': case 'i':
addr = string(optarg); addr = string(optarg);
break; break;
case 'p': case 'p':
port = atoi(optarg); port = atoi(optarg);
break; break;
case 'v': case 'v':
verb = 1; verb = 1;
break; break;
case '?': case '?':
default: default:
printf("? argumnet\n"); printf("? argumnet\n");
return 0; return 0;
} }
} }
if( verb ) if( verb )
cout << "(init): listen " << addr << ":" << port << endl; cout << "(init): listen " << addr << ":" << port << endl;
auto log = make_shared<DebugStream>(); auto log = make_shared<DebugStream>();
LogServer ls(log); LogServer ls(log);
ls.async_run(addr, port); ls.async_run(addr, port);
char buf[10000]; char buf[10000];
while( true ) while( true )
{ {
ssize_t r = read(fileno(stdin), buf, sizeof(buf) - 1); ssize_t r = read(fileno(stdin), buf, sizeof(buf) - 1);
if( r > 0 ) if( r > 0 )
{ {
buf[r] = '\0'; buf[r] = '\0';
log->any() << buf; log->any() << buf;
} }
} }
} }
catch( const SystemError& err ) catch( const SystemError& err )
{ {
cerr << "(log-stdin): " << err << endl; cerr << "(log-stdin): " << err << endl;
return 1; return 1;
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cerr << "(log-stdin): " << ex << endl; cerr << "(log-stdin): " << ex << endl;
return 1; return 1;
} }
catch(...) catch(...)
{ {
cerr << "(log-stdin): catch(...)" << endl; cerr << "(log-stdin): catch(...)" << endl;
return 1; return 1;
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -16,106 +16,106 @@ using namespace std; ...@@ -16,106 +16,106 @@ using namespace std;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("\n"); printf("\n");
printf("Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..\n"); printf("Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..\n");
printf("\n"); printf("\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char* argv[], char* envp[] ) int main( int argc, char* argv[], char* envp[] )
{ {
if( argc < 4 ) if( argc < 4 )
{ {
print_help(); print_help();
return 1; return 1;
} }
string addr(argv[1]); string addr(argv[1]);
int port = atoi(argv[2]); int port = atoi(argv[2]);
int pid; int pid;
int cp[2]; /* Child to parent pipe */ int cp[2]; /* Child to parent pipe */
if( pipe(cp) < 0) if( pipe(cp) < 0)
{ {
perror("Can't make pipe"); perror("Can't make pipe");
exit(1); exit(1);
} }
try try
{ {
switch( pid = fork() ) switch( pid = fork() )
{ {
case -1: case -1:
{ {
perror("Can't fork"); perror("Can't fork");
exit(1); exit(1);
} }
case 0: case 0:
{ {
/* Child. */ /* Child. */
close(cp[0]); close(cp[0]);
close( fileno(stdout) ); close( fileno(stdout) );
dup2(cp[1], fileno(stdout)); dup2(cp[1], fileno(stdout));
close( fileno(stderr) ); close( fileno(stderr) );
dup2(fileno(stdout), fileno(stderr)); dup2(fileno(stdout), fileno(stderr));
execvpe(argv[3], argv + 3, envp); execvpe(argv[3], argv + 3, envp);
perror("No exec"); perror("No exec");
kill(getppid(), SIGQUIT); kill(getppid(), SIGQUIT);
exit(1); exit(1);
} }
break; break;
default: default:
{ {
/* Parent. */ /* Parent. */
close(cp[1]); close(cp[1]);
auto zlog = make_shared<DebugStream>(); auto zlog = make_shared<DebugStream>();
zlog->addLevel(Debug::ANY); zlog->addLevel(Debug::ANY);
LogServer ls(zlog); LogServer ls(zlog);
cout << "wrap: server " << addr << ":" << port << endl; cout << "wrap: server " << addr << ":" << port << endl;
ls.async_run( addr, port ); ls.async_run( addr, port );
char buf[5000]; char buf[5000];
while( true ) while( true )
{ {
ssize_t r = read(cp[0], &buf, sizeof(buf) - 1 ); ssize_t r = read(cp[0], &buf, sizeof(buf) - 1 );
if( r > 0 ) if( r > 0 )
{ {
buf[r] = '\0'; buf[r] = '\0';
zlog->any() << buf; zlog->any() << buf;
} }
} }
exit(0); exit(0);
} }
break; break;
} }
} }
catch( const SystemError& err ) catch( const SystemError& err )
{ {
cerr << "(logserver-wrap): " << err << endl; cerr << "(logserver-wrap): " << err << endl;
return 1; return 1;
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cerr << "(logserver-wrap): " << ex << endl; cerr << "(logserver-wrap): " << ex << endl;
return 1; return 1;
} }
catch(...) catch(...)
{ {
cerr << "(logserver-wrap): catch(...)" << endl; cerr << "(logserver-wrap): catch(...)" << endl;
return 1; return 1;
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -7,16 +7,16 @@ using namespace std; ...@@ -7,16 +7,16 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
if( argc < 2 || (argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) ) // -V560 if( argc < 2 || (argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) ) // -V560
{ {
cout << "Usage: lo2gval [ info,warn,crit,level1...level9,init,repository,system,exception | any ]" << endl; cout << "Usage: lo2gval [ info,warn,crit,level1...level9,init,repository,system,exception | any ]" << endl;
return 0; return 0;
} }
const string s(argv[1]); const string s(argv[1]);
cout << (int)Debug::value(s) << endl; cout << (int)Debug::value(s) << endl;
return 0; return 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -8,42 +8,42 @@ using namespace std; ...@@ -8,42 +8,42 @@ using namespace std;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int main( int argc, const char** argv ) int main( int argc, const char** argv )
{ {
try try
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
xmlNode* cnode = conf->getNode("Skel"); xmlNode* cnode = conf->getNode("Skel");
if( cnode == NULL ) if( cnode == NULL )
{ {
cerr << "(Skel): not found <Skel> in conffile" << endl; cerr << "(Skel): not found <Skel> in conffile" << endl;
return 1; return 1;
} }
auto o = make_shared<Skel>("Skel", cnode); auto o = make_shared<Skel>("Skel", cnode);
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(o); act->add(o);
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulogany << "\n\n\n"; ulogany << "\n\n\n";
ulogany << "(Skel::main): -------------- Skel START -------------------------\n\n"; ulogany << "(Skel::main): -------------- Skel START -------------------------\n\n";
dlogany << "\n\n\n"; dlogany << "\n\n\n";
dlogany << "(Skel::main): -------------- Skel START -------------------------\n\n"; dlogany << "(Skel::main): -------------- Skel START -------------------------\n\n";
act->run(false); act->run(false);
return 0; return 0;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(Skel::main): " << ex.what() << endl; cerr << "(Skel::main): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(Skel::main): catch(...)" << endl; cerr << "(Skel::main): catch(...)" << endl;
} }
return 1; return 1;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -5,7 +5,7 @@ using namespace std; ...@@ -5,7 +5,7 @@ using namespace std;
using namespace uniset; using namespace uniset;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Skel::Skel( uniset::ObjectId id, xmlNode* confnode ): Skel::Skel( uniset::ObjectId id, xmlNode* confnode ):
Skel_SK( id, confnode ) Skel_SK( id, confnode )
{ {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -15,8 +15,8 @@ Skel::~Skel() ...@@ -15,8 +15,8 @@ Skel::~Skel()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
Skel::Skel() Skel::Skel()
{ {
cerr << "(Skel): init failed!!!!!!!!!!!!!!!" << endl; cerr << "(Skel): init failed!!!!!!!!!!!!!!!" << endl;
throw Exception(); throw Exception();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Skel::step() void Skel::step()
......
...@@ -5,21 +5,21 @@ ...@@ -5,21 +5,21 @@
#include "Skel_SK.h" #include "Skel_SK.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class Skel: class Skel:
public Skel_SK public Skel_SK
{ {
public: public:
Skel( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("Skel") ); Skel( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("Skel") );
virtual ~Skel(); virtual ~Skel();
protected: protected:
Skel(); Skel();
virtual void step() override; virtual void step() override;
virtual void sensorInfo( const uniset::SensorMessage* sm ) override; virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
virtual void timerInfo( const uniset::TimerMessage* tm ) override; virtual void timerInfo( const uniset::TimerMessage* tm ) override;
virtual void askSensors( UniversalIO::UIOCommand cmd ) override; virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
private: private:
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // Skel_H_ #endif // Skel_H_
......
...@@ -5,29 +5,29 @@ using namespace std; ...@@ -5,29 +5,29 @@ using namespace std;
using namespace uniset; using namespace uniset;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TestGen::TestGen( uniset::ObjectId id, xmlNode* confnode ): TestGen::TestGen( uniset::ObjectId id, xmlNode* confnode ):
TestGen_SK( id, confnode ) TestGen_SK( id, confnode )
{ {
vmonit(int_var); vmonit(int_var);
vmonit(bool_var); vmonit(bool_var);
const long* i = valptr(input2_s); const long* i = valptr(input2_s);
long* k = outptr(output1_c); long* k = outptr(output1_c);
if( !k ) if( !k )
cerr << "output1_c NOT FOUND!!!" << endl; cerr << "output1_c NOT FOUND!!!" << endl;
ObjectId d = idval(in_input2_s); ObjectId d = idval(in_input2_s);
ObjectId d2 = idval(&in_input2_s); ObjectId d2 = idval(&in_input2_s);
ObjectId d3 = idval(i); ObjectId d3 = idval(i);
ObjectId d4 = idval(&out_output1_c); ObjectId d4 = idval(&out_output1_c);
if( !i ) if( !i )
cerr << "input2_s NOT FOUND!!!" << endl; cerr << "input2_s NOT FOUND!!!" << endl;
else else
cerr << "input2_s=" << (*i) << " d=" << d << " d2=" << d2 << " d3=" << d3 << " input2_s=" << input2_s << endl; cerr << "input2_s=" << (*i) << " d=" << d << " d2=" << d2 << " d3=" << d3 << " input2_s=" << input2_s << endl;
vmonit(t_val); vmonit(t_val);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TestGen::~TestGen() TestGen::~TestGen()
...@@ -36,61 +36,61 @@ TestGen::~TestGen() ...@@ -36,61 +36,61 @@ TestGen::~TestGen()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TestGen::TestGen() TestGen::TestGen()
{ {
cerr << ": init failed!!!!!!!!!!!!!!!" << endl; cerr << ": init failed!!!!!!!!!!!!!!!" << endl;
throw Exception(); throw Exception();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGen::step() void TestGen::step()
{ {
#if 0 #if 0
cout << "strval: " << strval(input2_s) << endl; cout << "strval: " << strval(input2_s) << endl;
cout << "str: " << str(input2_s) << endl; cout << "str: " << str(input2_s) << endl;
cout << "===========" << endl; cout << "===========" << endl;
cout << dumpIO() << endl; cout << dumpIO() << endl;
myinfo << str(input2_s) << endl; myinfo << str(input2_s) << endl;
ulog()->info() << "ulog: " << str(input2_s) << endl; ulog()->info() << "ulog: " << str(input2_s) << endl;
int_var++; int_var++;
bool_var ^= true; bool_var ^= true;
cout << vmon << endl; cout << vmon << endl;
#endif #endif
// cout << vmon.pretty_str() << endl; // cout << vmon.pretty_str() << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGen::sensorInfo( const SensorMessage* sm ) void TestGen::sensorInfo( const SensorMessage* sm )
{ {
if( sm->id == input1_s ) if( sm->id == input1_s )
out_output1_c = in_input1_s; // sm->state out_output1_c = in_input1_s; // sm->state
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGen::timerInfo( const TimerMessage* tm ) void TestGen::timerInfo( const TimerMessage* tm )
{ {
if( tm->id == 1 ) if( tm->id == 1 )
{ {
askTimer(1, 0); askTimer(1, 0);
askTimer(2, 3000); askTimer(2, 3000);
} }
else if( tm->id == 2 ) else if( tm->id == 2 )
{ {
askTimer(1, 2000); askTimer(1, 2000);
askTimer(2, 0); askTimer(2, 0);
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
void TestGen::httpGetUserData( Poco::JSON::Object::Ptr& jdata ) void TestGen::httpGetUserData( Poco::JSON::Object::Ptr& jdata )
{ {
jdata->set("myMode", "RUNNING"); jdata->set("myMode", "RUNNING");
jdata->set("myVar", 42); jdata->set("myVar", 42);
jdata->set("myFloatVar", 42.42); jdata->set("myFloatVar", 42.42);
jdata->set("myMessage", "This is text fot test httpGetUserData"); jdata->set("myMessage", "This is text fot test httpGetUserData");
} }
#endif #endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGen::sysCommand( const uniset::SystemMessage* sm ) void TestGen::sysCommand( const uniset::SystemMessage* sm )
{ {
if( sm->command == SystemMessage::StartUp ) if( sm->command == SystemMessage::StartUp )
askTimer(1, 2000); askTimer(1, 2000);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -5,26 +5,26 @@ ...@@ -5,26 +5,26 @@
#include "TestGen_SK.h" #include "TestGen_SK.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class TestGen: class TestGen:
public TestGen_SK public TestGen_SK
{ {
public: public:
TestGen( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("TestGen") ); TestGen( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("TestGen") );
virtual ~TestGen(); virtual ~TestGen();
protected: protected:
TestGen(); TestGen();
virtual void step() override; virtual void step() override;
virtual void sensorInfo( const uniset::SensorMessage* sm ) override; virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
virtual void timerInfo( const uniset::TimerMessage* tm ) override; virtual void timerInfo( const uniset::TimerMessage* tm ) override;
virtual void sysCommand( const uniset::SystemMessage* sm ) override; virtual void sysCommand( const uniset::SystemMessage* sm ) override;
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) override; virtual void httpGetUserData( Poco::JSON::Object::Ptr& jdata ) override;
#endif #endif
private: private:
bool bool_var = { false }; bool bool_var = { false };
int int_var = {0}; int int_var = {0};
uniset::timeout_t t_val = { 0 }; uniset::timeout_t t_val = { 0 };
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // TestGen_H_ #endif // TestGen_H_
......
...@@ -5,7 +5,7 @@ using namespace std; ...@@ -5,7 +5,7 @@ using namespace std;
using namespace uniset; using namespace uniset;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TestGenAlone::TestGenAlone( uniset::ObjectId id, xmlNode* confnode ): TestGenAlone::TestGenAlone( uniset::ObjectId id, xmlNode* confnode ):
TestGenAlone_SK( id, confnode ) TestGenAlone_SK( id, confnode )
{ {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -15,13 +15,13 @@ TestGenAlone::~TestGenAlone() ...@@ -15,13 +15,13 @@ TestGenAlone::~TestGenAlone()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGenAlone::step() void TestGenAlone::step()
{ {
cout << strval(in_input2_s) << endl; cout << strval(in_input2_s) << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGenAlone::sensorInfo( const SensorMessage* sm ) void TestGenAlone::sensorInfo( const SensorMessage* sm )
{ {
if( sm->id == input1_s ) if( sm->id == input1_s )
out_output1_c = in_input1_s; // sm->state out_output1_c = in_input1_s; // sm->state
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGenAlone::timerInfo( const TimerMessage* tm ) void TestGenAlone::timerInfo( const TimerMessage* tm )
......
...@@ -5,19 +5,19 @@ ...@@ -5,19 +5,19 @@
#include "TestGenAlone_SK.h" #include "TestGenAlone_SK.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class TestGenAlone: class TestGenAlone:
public TestGenAlone_SK public TestGenAlone_SK
{ {
public: public:
TestGenAlone( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("TestGenAlone") ); TestGenAlone( uniset::ObjectId id, xmlNode* confnode = uniset::uniset_conf()->getNode("TestGenAlone") );
virtual ~TestGenAlone(); virtual ~TestGenAlone();
protected: protected:
virtual void step() override; virtual void step() override;
void sensorInfo( const uniset::SensorMessage* sm ) override; void sensorInfo( const uniset::SensorMessage* sm ) override;
void timerInfo( const uniset::TimerMessage* tm ) override; void timerInfo( const uniset::TimerMessage* tm ) override;
private: private:
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // TestGenAlone_H_ #endif // TestGenAlone_H_
......
...@@ -32,9 +32,10 @@ AC_ENABLE_SHARED(yes) ...@@ -32,9 +32,10 @@ AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no) AC_ENABLE_STATIC(no)
AM_PROG_LIBTOOL AM_PROG_LIBTOOL
ASTYLE_OPT="-A1 -T -C -S -N -L -w -Y -M -f -p --mode=c --lineend=linux --align-reference=type --align-pointer=type --suffix=none --style=ansi" ASTYLE_OPT="-A1 -T -C -S -L -w -N -Y -M -f -p --mode=c --lineend=linux --align-reference=type --align-pointer=type --suffix=none --style=ansi --convert-tabs -s4"
AC_SUBST(ASTYLE_OPT) AC_SUBST(ASTYLE_OPT)
# Checks for libraries. # Checks for libraries.
PKG_CHECK_MODULES(XML, libxml-2.0) PKG_CHECK_MODULES(XML, libxml-2.0)
PKG_CHECK_MODULES(OMNI, omniORB4) PKG_CHECK_MODULES(OMNI, omniORB4)
......
/*! \page ConfigurationPage Конфигурирование системы /*! \page ConfigurationPage Конфигурирование системы
- \ref ConfigurationPage_secCommon - \ref ConfigurationPage_secCommon
- \ref ConfigurationPage_secOmniORB - \ref ConfigurationPage_secOmniORB
\section ConfigurationPage_secCommon Общее описание \section ConfigurationPage_secCommon Общее описание
Для конфигурирования системы используется файл (обычно "configure.xml").
Конфигурация является глобальным объектом. Для получения доступа к ней используется функция auto conf = uniset_conf();
До начала работы, обычно в функции main(), конфигурация должна быть инициализирована при помощи функции uniset_init().
При этом третий параметр, указывающий название конфигурационного файла, является не обязательным.
По умолчанию обрабатывается аргумент командной строки --confile filename.
Для конфигурирования системы используется файл (обычно "configure.xml").
Конфигурация является глобальным объектом. Для получения доступа к ней используется функция auto conf = uniset_conf();
До начала работы, обычно в функции main(), конфигурация должна быть инициализирована при помощи функции uniset_init().
При этом третий параметр, указывающий название конфигурационного файла, является не обязательным.
По умолчанию обрабатывается аргумент командной строки --confile filename.
\code \code
... ...
#include <Configuration.h> #include <Configuration.h>
...@@ -20,41 +20,39 @@ int main(int argc, char **argv) ...@@ -20,41 +20,39 @@ int main(int argc, char **argv)
{ {
try try
{ {
uniset_init(argc, argv, "configure.xml"); uniset_init(argc, argv, "configure.xml");
... ...
... ...
}
} catch(Exception& ex )
catch(Exception& ex )
{ {
cerr << "(main): Поймали исключение " << ex << endl; cerr << "(main): Поймали исключение " << ex << endl;
} }
catch(...) catch(...)
{ {
cerr << "Неизвестное исключение!!!!"<< endl; cerr << "Неизвестное исключение!!!!"<< endl;
} }
...
... }
}
\endcode \endcode
\section ConfigurationPage_secOmniORB Конфигурирование OmniORB \section ConfigurationPage_secOmniORB Конфигурирование OmniORB
Для возможности задать напрямую параметры для omniORB заложена специальная секция <omniORB>. Для возможности задать напрямую параметры для omniORB заложена специальная секция <omniORB>.
В данную секцию можно записывать любые параметры поддерживаемые библиотекой omniORB. В данную секцию можно записывать любые параметры поддерживаемые библиотекой omniORB.
Формат и название параметров см. документацию по omniORB. Формат и название параметров см. документацию по omniORB.
Пример: Пример:
\code \code
<omniORB> <omniORB>
<option name="endPoint" arg="giop:tcp:host1:"/> <option name="endPoint" arg="giop:tcp:host1:"/>
<option name="endPoint" arg="giop:tcp:host2:" error_if_not_available="1"/> <option name="endPoint" arg="giop:tcp:host2:" error_if_not_available="1"/>
</omniORB> </omniORB>
\endcode \endcode
Для параметра 'endPoint' встроена дополнительная проверка доступности указанной адреса. Для параметра 'endPoint' встроена дополнительная проверка доступности указанного адреса.
\warning По умолчанию \b недоступность \b игнорируется, если не указан параметр \a error_if_not_available="1" \warning По умолчанию \b недоступность \b игнорируется, если не указан параметр \a error_if_not_available="1"
Помимо этого можно задать параметр \a ignore_checking="1", чтобы не происходило проверки доступности endPoint. Помимо этого можно задать параметр \a ignore_checking="1", чтобы не происходило проверки доступности endPoint.
*/ */
\ No newline at end of file
/*! \page DebugPage Описание использования функций отладки /*! \page DebugPage Описание использования функций отладки
Класс для вывода отладочных сообщений называется DebugStream. Класс для вывода отладочных сообщений называется DebugStream.
Сообщения могут выводится на экран и в файл, отбираться по Сообщения могут выводится на экран и в файл, отбираться по
определённым критериям и до определённого уровня. определённым критериям и до определённого уровня.
- \ref subUsing - \ref subUsing
- \ref subConf - \ref subConf
\subsection subUsing Использование \subsection subUsing Использование
Для использования нужно создать свой объект класса DebugStream или Для использования нужно создать свой объект класса DebugStream или
использовать глобальный объект UniSetTypes::unideb. использовать глобальный объект UniSetTypes::unideb.
Для переключения вывода отладки в файл, используйте функцию logFile(char const *f); Для переключения вывода отладки в файл, используйте функцию logFile(char const *f);
Описание всех имеющихся функций находится в файле DebugStream.h
на английском языке.
Функция unideb[...] по умолчанию выводит в строку дату и время. Описание всех имеющихся функций находится в файле DebugStream.h
Функция unideb(...) просто выводит строку (в конец предыдущему потоку). на английском языке.
\par Пример использования:
\code
#include "Debug.h"
#include "Configuration.h"
using namespace UniSetTypes;
...
unideb << "Этот текст будет выведен на экран в любом случае";
unideb.addLevel(Debug::CRIT); // показывать CRIT
unideb[Debug::CRIT] << "Этот текст будет выведен при разрешении выводить сообщения уровня CRIT";
unideb.delLevel(Debug::CRIT); // больше не показывать CRIT
// Отладочное сообщение будет выводиться при установленном уровне INFO или CRIT"
unideb[Debug::type(Debug::INFO | Debug::CRIT)] << "Отладочное сообщение";
// Вывод многострочного сообщения Функция unideb[...] по умолчанию выводит в строку дату и время.
unideb[Debug::INFO] << " вывод с датой и временем "; Функция unideb(...) просто выводит строку (в конец предыдущему потоку).
unideb(Debug::INFO) << " продолжение вывода без даты и времени " << endl;
\par Пример использования:
\endcode \code
#include "Debug.h"
#include "Configuration.h"
using namespace UniSetTypes;
...
unideb << "Этот текст будет выведен на экран в любом случае";
unideb.addLevel(Debug::CRIT); // показывать CRIT
unideb[Debug::CRIT] << "Этот текст будет выведен при разрешении выводить сообщения уровня CRIT";
unideb.delLevel(Debug::CRIT); // больше не показывать CRIT
// Отладочное сообщение будет выводиться при установленном уровне INFO или CRIT"
unideb[Debug::type(Debug::INFO | Debug::CRIT)] << "Отладочное сообщение";
Если вы хотите использовать отладочный вывод из критичного к времени // Вывод многострочного сообщения
кода, используйте следующую конструкцию: unideb[Debug::INFO] << " вывод с датой и временем ";
unideb(Debug::INFO) << " продолжение вывода без даты и времени " << endl;
\code
if (unideb.debugging(Debug::INFO)) { \endcode
unideb << "...debug output..." << endl;
}
\endcode
\subsection subConf Конфигурирование логов Если вы хотите использовать отладочный вывод из критичного к времени
Конфигурирование логов можно производить, при помощи файла конфигурации или через командную строку. кода, используйте следующую конструкцию:
Например UniSetTypes::unideb настраивается в конфигурационном файле следующим образом:
\code \code
<UniSetDebug name="unideb" levels="crit,warn" file=""/> if (unideb.debugging(Debug::INFO)) {
\endcode unideb << "...debug output..." << endl;
}
При запуске программ используйте ключ "--help" для получения подробной информации \endcode
о настройке логов из командной строки
\subsection subConf Конфигурирование логов
Конфигурирование логов можно производить, при помощи файла конфигурации или через командную строку.
Например UniSetTypes::unideb настраивается в конфигурационном файле следующим образом:
\code
<UniSetDebug name="unideb" levels="crit,warn" file=""/>
\endcode
При запуске программ используйте ключ "--help" для получения подробной информации
о настройке логов из командной строки
*/ */
\ No newline at end of file
/*! /*!
\page MutexHowToPage Как пользоваться uniset_mutex и uniset_mutex_lock \page MutexHowToPage Как пользоваться uniset_mutex и uniset_mutex_lock
\par \par
"мьютекс"(mutex) - получено от англ. Mutual Exclusive. (нечто вроде "взаимоисключение") "мьютекс"(mutex) - получено от англ. Mutual Exclusive. (нечто вроде "взаимоисключение")
\par \par
Основными операциями для мьютексов, помимо создания и уничтожения, являются операции lock и unlock. Основными операциями для мьютексов, помимо создания и уничтожения, являются операции lock и unlock.
Логически работа с мьютексом могла бы выглядеть так (псевдокод) Логически работа с мьютексом могла бы выглядеть так (псевдокод)
\code \code
Mutex mutex; Mutex mutex;
... ...
mutex.lock(); mutex.lock();
DoSomething(); DoSomething();
mutex.unlock(); mutex.unlock();
\endcode \endcode
Но в общем случае это ни к чему хорошему не приведет, т.к. если в \c DoSomething() возникнет исключение, то
\c mutex.unlock() уже не выполнится. Конечно можно использовать \c try...catch, но желательно, чтобы
код работал независимо от ситуации. Для этого введен класс \b uniset_mutex_lock. При его использовании получается
следующий код (один из вариантов использования):
\code
using namespase UniSetTypes;
...
uniset_mutex mutex;
...
{
uniset_mutex_lock lock(mutex); // вызов mutex.lock() как часть кода конструктора
DoSomething();
} // <-- Заканчивается зона видимости lock-а и происходит вызов mutex.unlock() как часть кода деструктора
\endcode
В этом случае, даже если в \c DoSomethig() будет сгенерировано исключение ресурс будет освобожден
при вызове деструктора. Вот и все решение...
\par
Главное не забывайте ставить скобочки...
\par
Желательно не использовать \c mutex.lock() и \c uniset_mutex.unlock() в чистом виде, а только совместно с
\b uniset_mutex_lock. Кроме особых случаев (см. \ref secWarning).
\par
Следует помнить, что мьютексы \b фактически никаких ресурсов не захватывают, это только флаг означающий,
что ресурс занят. Поэтому работать с ними надо внимательно и не забывать блокировать ресурс там где это надо.
\par
Описания классов см. UniSetTypes::uniset_mutex и UniSetTypes::uniset_mutex_lock
\section secWarning Особые случаи Но в общем случае это ни к чему хорошему не приведет, т.к. если в \c DoSomething() возникнет исключение, то
Если в \c DoSomethig() будет вызвана \c exit(0), \c abort() или что-нибудь подобное, \c mutex.unlock() уже не выполнится. Конечно можно использовать \c try...catch, но желательно, чтобы
то unlock не произойдет. В таком случае следовало бы напрямую вызывать \c unlock() до вызова сигнала, но эти случаи редкие и если код работал независимо от ситуации. Для этого введен класс \b uniset_mutex_lock. При его использовании получается
возникнет необходимость, то можно будет вместо \a protected сделать их \a public. следующий код (один из вариантов использования):
\code
\note Описание составлено на основе описания мьютексов из книги А.Цимбала "Технология CORBA для профессионалов". using namespase UniSetTypes;
...
uniset_mutex mutex;
...
{
uniset_mutex_lock lock(mutex); // вызов mutex.lock() как часть кода конструктора
DoSomething();
} // <-- Заканчивается зона видимости lock-а и происходит вызов mutex.unlock() как часть кода деструктора
\endcode
В этом случае, даже если в \c DoSomethig() будет сгенерировано исключение ресурс будет освобожден
при вызове деструктора. Вот и все решение...
\par
Главное не забывайте ставить скобочки...
\par
Желательно не использовать \c mutex.lock() и \c uniset_mutex.unlock() в чистом виде, а только совместно с
\b uniset_mutex_lock. Кроме особых случаев (см. \ref secWarning).
\par
Следует помнить, что мьютексы \b фактически никаких ресурсов не захватывают, это только флаг означающий,
что ресурс занят. Поэтому работать с ними надо внимательно и не забывать блокировать ресурс там где это надо.
\par
Описания классов см. UniSetTypes::uniset_mutex и UniSetTypes::uniset_mutex_lock
\section secWarning Особые случаи
Если в \c DoSomethig() будет вызвана \c exit(0), \c abort() или что-нибудь подобное,
то unlock не произойдет. В таком случае следовало бы напрямую вызывать \c unlock() до вызова сигнала, но эти случаи редкие и если
возникнет необходимость, то можно будет вместо \a protected сделать их \a public.
\note Описание составлено на основе описания мьютексов из книги А.Цимбала "Технология CORBA для профессионалов".
*/ */
\ No newline at end of file
/* OBSOLETE DOC!!! /* OBSOLETE DOC!!!
\page ObjectRepositoryPage Репозиторий объектов \page ObjectRepositoryPage Репозиторий объектов
Репозиторий объектов предназначен для хранения и получения ссылок на объекты, с целью дальнейшего Репозиторий объектов предназначен для хранения и получения ссылок на объекты, с целью дальнейшего
использования функций предоставленных этими объектами. Объекты регистрирующиеся в репозитории могут быть удаленными... использования функций предоставленных этими объектами. Объекты регистрирующиеся в репозитории могут быть удаленными...
- \ref subRegCommon - \ref subRegCommon
- \ref subReg - \ref subReg
- \ref subResolve - \ref subResolve
\section subRegCommon Вводная \section subRegCommon Вводная
При наследовании от UniSetObject (и его потомков) регистрация в репозитории происходит автоматически. При наследовании от UniSetObject (и его потомков) регистрация в репозитории происходит автоматически.
Поэтому регистрироваться отдельно нет необходимости. Поэтому регистрироваться отдельно нет необходимости.
\section subReg Регистрация \section subReg Регистрация
Для регистрации существует следующие функции. Для регистрации существует следующие функции.
По текстовому имени По текстовому имени
- void ObjectRepository::registration(const ObjectName name, const ObjectPtr oRef, const string section) - void ObjectRepository::registration(const ObjectName name, const ObjectPtr oRef, const string section)
- void ObjectRepository::registration(const ObjectName fullName, const ObjectPtr oRef) - void ObjectRepository::registration(const ObjectName fullName, const ObjectPtr oRef)
По идентификатору По идентификатору
- void UniversalInterface::registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef)throw(ORepFailed); - void UniversalInterface::registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef)throw(ORepFailed);
- void UniversalInterface::registered(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node, const UniSetTypes::ObjectPtr oRef)throw(ORepFailed); - void UniversalInterface::registered(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node, const UniSetTypes::ObjectPtr oRef)throw(ORepFailed);
Пример: Пример:
\code \code
#include "ObjectRepository.h" #include "ObjectRepository.h"
... ...
CORBA::Object_ptr oref; CORBA::Object_ptr oref;
... ...
ObjectRepository orep; ObjectRepository orep;
try try
{ {
orep.registration("myObject", oref, "Root/Processes"); orep.registration("myObject", oref, "Root/Processes");
} }
cacth(ORepFailed) cacth(ORepFailed)
{ {
cerr << "Не удалось зарегистрировать объект " << endl; cerr << "Не удалось зарегистрировать объект " << endl;
} }
\endcode \endcode
Или при помощи UniverslaInterface Или при помощи UniverslaInterface
\code \code
class MyObject: class MyObject:
public UniSetObject public UniSetObject
{ {
public: public:
MyObject( UniSetTypes::ObjectId id ); MyObject( UniSetTypes::ObjectId id );
... ...
protected:
void my_start()
{
try
{
ui.registration(myid, myRef);
}
catch(Exception ex)
{
cout << ex << endl;
}
}
}
\endcode
\section subResolve Получение ссылки на объект
Для получения ссылки лучше всего пользоваться protected:
- UniSetTypes::ObjectPtr UniversalInterface::resolve( UniSetTypes::ObjectId id ) void my_start()
- UniSetTypes::ObjectPtr UniversalInterface::resolve( UniSetTypes::ObjectId id, UniSetTypes::ObjectId nodeName, int timeoutMS=UniversalIO::defaultTimeOut) {
throw(ResolveNameError, TimeOut); try
{
ui.registration(myid, myRef);
}
catch(Exception ex)
{
cout << ex << endl;
}
}
}
\endcode
т.к. UniversalInterface::resolve() пытается получиться ссылку, в том числе через резервный каналы связи. \section subResolve Получение ссылки на объект
Пример: Для получения ссылки лучше всего пользоваться
\code - UniSetTypes::ObjectPtr UniversalInterface::resolve( UniSetTypes::ObjectId id )
... - UniSetTypes::ObjectPtr UniversalInterface::resolve( UniSetTypes::ObjectId id, UniSetTypes::ObjectId nodeName, int timeoutMS=UniversalIO::defaultTimeOut)
throw(ResolveNameError, TimeOut);
try
{
CORBA::Object_ptr oref=0;
IOController_i_var ioc = IOController_i::_narrow( ui.resolve(id, node) );
...
}
catch(Exception ex)
{
cout << ex << endl;
}
\endcode т.к. UniversalInterface::resolve() пытается получиться ссылку, в том числе через резервный каналы связи.
Пример:
\code
...
try
{
CORBA::Object_ptr oref=0;
IOController_i_var ioc = IOController_i::_narrow( ui.resolve(id, node) );
...
}
catch(Exception ex)
{
cout << ex << endl;
}
\endcode
*/ */
\ No newline at end of file
// эти разделы сформируются автоматически из описаний сделанных в соответствующих h-файлах
/*!
\page ServicesPage Сервисы
- \ref secDBServer
\section secDBServer Сервер БД
\sa \ref page_DBServer_MySQL
*/
\ No newline at end of file
/* OBSOLETE DOC!!! /* OBSOLETE DOC!!!
\page UniversalInterfacePage Универсальный интерфейс \page UniversalInterfacePage Универсальный интерфейс
Этот интерфейс позволяет получать доступ к объекту по идентификатору(или имени), заказывать датчики, и т.п. Этот интерфейс позволяет получать доступ к объекту по идентификатору(или имени), заказывать датчики, и т.п.
Для работы с удаленными объектами необходимо указывать идентификатор узла, на котором Для работы с удаленными объектами необходимо указывать идентификатор узла, на котором
находится этот объект(если он не задан, идет обращение к локальному). находится этот объект(если он не задан, идет обращение к локальному).
- \ref secIOControl - \ref secIOControl
- \ref subAsk - \ref subAsk
- \ref subGet - \ref subGet
- \ref subSet - \ref subSet
- \ref secTimers - \ref secTimers
- \ref secORep - \ref secORep
\sa UniversalInterface \sa UniversalInterface
\section secIOControl Функции работы с вводом/выводом \section secIOControl Функции работы с вводом/выводом
\subsection subAsk Заказ датчиков \subsection subAsk Заказ датчиков
Заказ датчиков осуществляется при помощи функций:
Заказ датчиков осуществляется при помощи функций: для дискретных датчиков
- \ref void UniversalInterface::askState(...)
для дискретных датчиков
- \ref void UniversalInterface::askState(...)
для аналоговых датчиков для аналоговых датчиков
- \ref void UniversalInterface::askValue(...) - \ref void UniversalInterface::askValue(...)
\subsection subGet Получение информации о текущем состоянии датчика \subsection subGet Получение информации о текущем состоянии датчика
Информацию о состоянии датчика можно получить при помощи функций: Информацию о состоянии датчика можно получить при помощи функций:
для дискретных датчиков для дискретных датчиков
- \ref void UniversalInterface::getState(...) - \ref void UniversalInterface::getState(...)
для аналоговых датчиков для аналоговых датчиков
- \ref void UniversalInterface::getValue(...) - \ref void UniversalInterface::getValue(...)
\subsection subSet Управление выходными сигналом \subsection subSet Управление выходными сигналом
для дискретных датчиков для дискретных датчиков
- \ref void UniversalInterface::setState(...) - \ref void UniversalInterface::setState(...)
для аналоговых датчиков для аналоговых датчиков
- \ref void UniversalInterface::setValue(...) - \ref void UniversalInterface::setValue(...)
\section secORep Функции работы с репозиторием объектов \section secORep Функции работы с репозиторием объектов
- \ref void UniversalInterface::registered(...) - \ref void UniversalInterface::registered(...)
- \ref void UniversalInterface::unregister(...) - \ref void UniversalInterface::unregister(...)
- \ref void UniversalInterface::resolve(...) - \ref void UniversalInterface::resolve(...)
- \ref ObjectId UniversalInterface::getIdByName(...) - \ref ObjectId UniversalInterface::getIdByName(...)
- \ref const char* UniversalInterface::getNameById(...) - \ref const char* UniversalInterface::getNameById(...)
\section secTimers Заказ таймеров \section secTimers Заказ таймеров
- \ref void UniversalInterface::askTimer(...) - \ref void UniversalInterface::askTimer(...)
*/ */
/*! /*!
\page DependsPage Зависимости между датчиками \page DependsPage Зависимости между датчиками
Существует два механизма реализующих зависимость между датчиками: Существует два механизма реализующих зависимость между датчиками:
- \ref pgDep_secIOControl - \ref pgDep_secIOControl
- \ref pgDep_secIOBase - \ref pgDep_secIOBase
\section pgDep_secIOControl Зависимость на уровне IOController (SharedMemmory) \section pgDep_secIOControl Зависимость на уровне IOController (SharedMemmory)
Механизм зависимостей реализован в классе IOController. Механизм зависимостей реализован в классе IOController.
Пример записи "зависимости" в configure.xml: Пример записи "зависимости" в configure.xml:
\code \code
<item textname="...." iotype="..." .../> <item textname="...." iotype="..." .../>
<consumers> <consumers>
<consumers> <consumers>
<depends> <depends>
<depend name="Sensor1" filter="val" /> <depend name="Sensor1" filter="val" />
<depend name="Sensor2" filter2="val1" /> <depend name="Sensor2" filter2="val1" />
</depends> </depends>
</item> </item>
\endcode \endcode
При считывании конф. файла можно задавать фильтры. При считывании конф. файла можно задавать фильтры.
ПОКА РЕАЛИЗОВАНА ЗАВИСИМОСТЬ ТОЛЬКО ОТ ОДНОГО ДАТЧИКА! ПОКА РЕАЛИЗОВАНА ЗАВИСИМОСТЬ ТОЛЬКО ОТ ОДНОГО ДАТЧИКА!
т.е. <depend> может быть только один. т.е. <depend> может быть только один.
\section pgDep_secIOBase Зависимость на уровне IOBase \section pgDep_secIOBase Зависимость на уровне IOBase
Механизм зависимостей между датчиками на уровне IOBase, Механизм зависимостей между датчиками на уровне IOBase,
работает на уровне процессов обмена использующих IOBase. работает на уровне процессов обмена использующих IOBase.
В ним относятся IOControl, ModbusMaster (RTU,TCP) и т.п. В ним относятся IOControl, ModbusMaster (RTU,TCP) и т.п.
Плюсом данного механизма является, то, что он обеспечивает Плюсом данного механизма является, то, что он обеспечивает
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
Следует иметь ввиду, что этот механизм не действует при сохранении значений, например при помощи uniset-admin, Следует иметь ввиду, что этот механизм не действует при сохранении значений, например при помощи uniset-admin,
в отличие от механизма \ref pgDep_secIOControl в отличие от механизма \ref pgDep_secIOControl
Пример записи "зависимости" в configure.xml: Пример записи "зависимости" в configure.xml:
\code \code
<item textname="...." iotype="..." ... depend="OtherSensor_AS" depend_value="2" /> <item textname="...." iotype="..." ... depend="OtherSensor_AS" depend_value="2" />
\endcode \endcode
В данном случае подразумевается, что разрешающим датчиком является OtherSensor_AS=2. В данном случае подразумевается, что разрешающим датчиком является OtherSensor_AS=2.
......
/*! \page page_Uniset Краткое описание библиотеки libuniset /*! \page page_Uniset Краткое описание библиотеки libuniset
- \ref pg_UniSet_Common - \ref pg_UniSet_Common
- \ref pg_Uniset_Processes - \ref pg_Uniset_Processes
- \ref pg_UniSet_Network - \ref pg_UniSet_Network
- \ref pg_UniSet_Utilities - \ref pg_UniSet_Utilities
\section pg_UniSet_Common Общее описание libuniset \section pg_UniSet_Common Общее описание libuniset
......
/*! /*!
\mainpage \mainpage
\image html uniset.png \image html uniset.png
\section MainSection Оглавление \section MainSection Оглавление
- \ref page_Concept - \ref page_Concept
- \ref page_Uniset - \ref page_Uniset
- \ref UniSetLibStylePage - \ref UniSetLibStylePage
*/ */
/*! /*!
\page ToDoPage Необходимо доделать \page ToDoPage Необходимо доделать
-# утилиты мониторинга работы системы -# утилиты мониторинга работы системы
-# настройку "политик" для ORB сделать из конф. файла -# настройку "политик" для ORB сделать из конф. файла
-# по максимуму переход на xml -# по максимуму переход на xml
-# дополнить описание IOController-ов разделом про XML-файл заказчиков(создание,работа) -# дополнить описание IOController-ов разделом про XML-файл заказчиков(создание,работа)
-# сделать описание принципов и деталей межобъектного взаимодействия -# сделать описание принципов и деталей межобъектного взаимодействия
(об ограничениях на размер сообщений, очередь сообщений, приоритеты и т.п.) (об ограничениях на размер сообщений, очередь сообщений, приоритеты и т.п.)
-# попытаться сделать работу с сервисами более универсальной -# попытаться сделать работу с сервисами более универсальной
(что то типа "UniSetTypes::ObjectId conf->getService(const string name)" ) (что то типа "UniSetTypes::ObjectId conf->getService(const string name)" )
-# откорректировать и дописать "общее описание" библиотеки -# откорректировать и дописать "общее описание" библиотеки
-# сделать тип в UniSetObject::getType string-ом -# сделать тип в UniSetObject::getType string-ом
(для универсальности и простоты будущих расширений) (для универсальности и простоты будущих расширений)
-# переписать тестовые примеры, под текущую ситуацию. -# переписать тестовые примеры, под текущую ситуацию.
-# в будущем попытаться отказаться от ObjectId и перейти на строки (это надо ещё обдумать) -# в будущем попытаться отказаться от ObjectId и перейти на строки (это надо ещё обдумать)
-# в InfoServer-е по routeList-у сообщения пересылаются, только если они локальные. -# в InfoServer-е по routeList-у сообщения пересылаются, только если они локальные.
Надо переделать механизм, чтобы можно было отделять тех кому пересылать все сообщения, Надо переделать механизм, чтобы можно было отделять тех кому пересылать все сообщения,
от тех кому пересылать только локальные.... от тех кому пересылать только локальные....
-# Для IOController-ов разработать спец. интерфейс для работы с датчиками (сохранение, получение состояния и т.п.) -# Для IOController-ов разработать спец. интерфейс для работы с датчиками (сохранение, получение состояния и т.п.)
Для того, чтобы можно было использовать разные способы хранения (БД, STL-контейнеры, файлы и т.п.). Т.к. сейчас Для того, чтобы можно было использовать разные способы хранения (БД, STL-контейнеры, файлы и т.п.). Т.к. сейчас
жёсткая реализация на STL-контейнерах. жёсткая реализация на STL-контейнерах.
-# дописать Mutex как надо (или перейти на omni_mutex-ы) . Сделать RWMutex и RMutex. -# дописать Mutex как надо (или перейти на omni_mutex-ы) . Сделать RWMutex и RMutex.
-# стартовые скрипты для локальной отладки (откорректировать старые) -# стартовые скрипты для локальной отладки (откорректировать старые)
-# управление очередью сообщений, очистка по фильтру и т.п. (может перейти на несколько очередей по приоритетам) -# управление очередью сообщений, очистка по фильтру и т.п. (может перейти на несколько очередей по приоритетам)
-# У NotifyController-а две функции с название calibrate (надо переименовать) -# У NotifyController-а две функции с название calibrate (надо переименовать)
-# Сделать свойство tick у процессов обмена по Modbus, чтобы можно было с разной периодичностью опрашивать разные регистры -# Сделать свойство tick у процессов обмена по Modbus, чтобы можно было с разной периодичностью опрашивать разные регистры
*/ */
...@@ -11,59 +11,59 @@ using namespace uniset::extensions; ...@@ -11,59 +11,59 @@ using namespace uniset::extensions;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int main( int argc, const char** argv ) int main( int argc, const char** argv )
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) ) if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) )
{ {
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl; cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << endl; cout << endl;
BackendOpenTSDB::help_print(argc, argv); BackendOpenTSDB::help_print(argc, argv);
return 0; return 0;
} }
try try
{ {
auto conf = uniset_init( argc, argv ); auto conf = uniset_init( argc, argv );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
if( !sID.empty() ) if( !sID.empty() )
shmID = conf->getControllerID(sID); shmID = conf->getControllerID(sID);
else else
shmID = getSharedMemoryID(); shmID = getSharedMemoryID();
if( shmID == DefaultObjectId ) if( shmID == DefaultObjectId )
{ {
cerr << sID << "? SharedMemoryID not found in " << conf->getControllersSection() << " section" << endl; cerr << sID << "? SharedMemoryID not found in " << conf->getControllersSection() << " section" << endl;
return 1; return 1;
} }
auto db = BackendOpenTSDB::init_opendtsdb(argc, argv, shmID); auto db = BackendOpenTSDB::init_opendtsdb(argc, argv, shmID);
if( !db ) if( !db )
{ {
cerr << "(opendtsdb): init failed..." << endl; cerr << "(opendtsdb): init failed..." << endl;
return 1; return 1;
} }
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(db); act->add(db);
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
act->run(false); act->run(false);
return 0; return 0;
} }
catch( uniset::Exception& ex ) catch( uniset::Exception& ex )
{ {
cerr << "(opendtsdb): " << ex << std::endl; cerr << "(opendtsdb): " << ex << std::endl;
} }
catch(...) catch(...)
{ {
cerr << "(opendtsdb): catch ..." << std::endl; cerr << "(opendtsdb): catch ..." << std::endl;
} }
return 1; return 1;
} }
...@@ -26,196 +26,196 @@ using namespace uniset; ...@@ -26,196 +26,196 @@ using namespace uniset;
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
MySQLInterface::MySQLInterface(): MySQLInterface::MySQLInterface():
lastQ(""), lastQ(""),
connected(false) connected(false)
{ {
mysql = new MYSQL(); mysql = new MYSQL();
mysql_init(mysql); mysql_init(mysql);
// mysql_options(mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name"); // mysql_options(mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
mysql_options(mysql, MYSQL_OPT_COMPRESS, 0); mysql_options(mysql, MYSQL_OPT_COMPRESS, 0);
} }
MySQLInterface::~MySQLInterface() MySQLInterface::~MySQLInterface()
{ {
try try
{ {
close(); close();
} }
catch( ... ) // пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора catch( ... ) // пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{ {
cerr << "MySQLInterface::~MySQLInterface(): an error occured while closing connection!" << endl; cerr << "MySQLInterface::~MySQLInterface(): an error occured while closing connection!" << endl;
} }
delete mysql; delete mysql;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::nconnect(const string& host, const string& user, const string& pswd, const string& dbname, unsigned int port ) bool MySQLInterface::nconnect(const string& host, const string& user, const string& pswd, const string& dbname, unsigned int port )
{ {
if( !mysql_real_connect(mysql, host.c_str(), user.c_str(), pswd.c_str(), dbname.c_str(), port, NULL, 0) ) if( !mysql_real_connect(mysql, host.c_str(), user.c_str(), pswd.c_str(), dbname.c_str(), port, NULL, 0) )
{ {
cout << error() << endl; cout << error() << endl;
mysql_close(mysql); mysql_close(mysql);
connected = false; connected = false;
return false; return false;
} }
connected = true; connected = true;
return true; return true;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::close() bool MySQLInterface::close()
{ {
mysql_close(mysql); mysql_close(mysql);
return true; return true;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::insert( const string& q ) bool MySQLInterface::insert( const string& q )
{ {
if( !mysql ) if( !mysql )
return false; return false;
if( mysql_query(mysql, q.c_str()) ) if( mysql_query(mysql, q.c_str()) )
return false; return false;
return true; return true;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
DBResult MySQLInterface::query( const std::string& q ) DBResult MySQLInterface::query( const std::string& q )
{ {
if( !mysql ) if( !mysql )
return DBResult(); return DBResult();
if( mysql_query(mysql, q.c_str()) ) if( mysql_query(mysql, q.c_str()) )
{ {
cerr << error() << endl; cerr << error() << endl;
return DBResult(); return DBResult();
} }
lastQ = q; lastQ = q;
MYSQL_RES* res = mysql_store_result(mysql); // _use_result - некорректно работает с _num_rows MYSQL_RES* res = mysql_store_result(mysql); // _use_result - некорректно работает с _num_rows
if( !res || mysql_num_rows(res) == 0 ) if( !res || mysql_num_rows(res) == 0 )
return DBResult(); return DBResult();
return makeResult(res, true); return makeResult(res, true);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::query_ok( const string& q ) bool MySQLInterface::query_ok( const string& q )
{ {
if( !mysql ) if( !mysql )
return false; return false;
if( mysql_query(mysql, q.c_str()) ) if( mysql_query(mysql, q.c_str()) )
return false; return false;
lastQ = q; lastQ = q;
MYSQL_RES* res = mysql_store_result(mysql); // _use_result - некорректно работает с _num_rows MYSQL_RES* res = mysql_store_result(mysql); // _use_result - некорректно работает с _num_rows
if( !res || mysql_num_rows(res) == 0 ) if( !res || mysql_num_rows(res) == 0 )
{ {
if( res ) if( res )
mysql_free_result(res); mysql_free_result(res);
return false; return false;
} }
mysql_free_result(res); mysql_free_result(res);
return true; return true;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
const string MySQLInterface::error() const string MySQLInterface::error()
{ {
return mysql_error(mysql); return mysql_error(mysql);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
const string MySQLInterface::lastQuery() const string MySQLInterface::lastQuery()
{ {
return lastQ; return lastQ;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
double MySQLInterface::insert_id() double MySQLInterface::insert_id()
{ {
if( !mysql ) if( !mysql )
return 0; return 0;
return mysql_insert_id(mysql); return mysql_insert_id(mysql);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
const char* MySQLInterface::gethostinfo() const const char* MySQLInterface::gethostinfo() const
{ {
return mysql_get_host_info(mysql); return mysql_get_host_info(mysql);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::ping() const bool MySQLInterface::ping() const
{ {
if( !mysql || !connected ) if( !mysql || !connected )
return false; return false;
// внимание mysql_ping возвращает 0 // внимание mysql_ping возвращает 0
// если всё хорошо.... (поэтому мы инвертируем) // если всё хорошо.... (поэтому мы инвертируем)
return !mysql_ping(mysql); return !mysql_ping(mysql);
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
bool MySQLInterface::isConnection() const bool MySQLInterface::isConnection() const
{ {
return ping(); //!mysql; return ping(); //!mysql;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
string MySQLInterface::addslashes( const string& str ) string MySQLInterface::addslashes( const string& str )
{ {
ostringstream tmp; ostringstream tmp;
for( unsigned int i = 0; i < str.size(); i++ ) for( unsigned int i = 0; i < str.size(); i++ )
{ {
// if( !strcmp(str[i],'\'') ) // if( !strcmp(str[i],'\'') )
if( str[i] == '\'' ) if( str[i] == '\'' )
tmp << "\\"; tmp << "\\";
tmp << str[i]; tmp << str[i];
} }
return tmp.str(); return tmp.str();
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
DBResult MySQLInterface::makeResult( MYSQL_RES* myres, bool finalize ) DBResult MySQLInterface::makeResult( MYSQL_RES* myres, bool finalize )
{ {
DBResult result; DBResult result;
if( !myres ) if( !myres )
{ {
if( finalize ) if( finalize )
mysql_free_result(myres); mysql_free_result(myres);
return result; return result;
} }
MYSQL_ROW mysql_row; MYSQL_ROW mysql_row;
unsigned int nfields = mysql_num_fields(myres); unsigned int nfields = mysql_num_fields(myres);
while( (mysql_row = mysql_fetch_row(myres)) ) while( (mysql_row = mysql_fetch_row(myres)) )
{ {
DBResult::COL c; DBResult::COL c;
for( unsigned int i = 0; i < nfields; i++ ) for( unsigned int i = 0; i < nfields; i++ )
{ {
MYSQL_FIELD* field_info = mysql_fetch_field_direct(myres, i); MYSQL_FIELD* field_info = mysql_fetch_field_direct(myres, i);
result.setColName( i, std::string(field_info->name) ); result.setColName( i, std::string(field_info->name) );
c.emplace_back( (mysql_row[i] != 0 ? string(mysql_row[i]) : "") ); c.emplace_back( (mysql_row[i] != 0 ? string(mysql_row[i]) : "") );
} }
result.row().emplace_back(c); result.row().emplace_back(c);
} }
if( finalize ) if( finalize )
mysql_free_result(myres); mysql_free_result(myres);
return result; return result;
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
extern "C" std::shared_ptr<DBInterface> create_mysqlinterface() extern "C" std::shared_ptr<DBInterface> create_mysqlinterface()
{ {
return std::shared_ptr<DBInterface>(new MySQLInterface(), DBInterfaceDeleter()); return std::shared_ptr<DBInterface>(new MySQLInterface(), DBInterfaceDeleter());
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
...@@ -32,57 +32,57 @@ ...@@ -32,57 +32,57 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// no thread safety // no thread safety
class MySQLInterface: class MySQLInterface:
public DBNetInterface public DBNetInterface
{ {
public: public:
MySQLInterface(); MySQLInterface();
~MySQLInterface(); ~MySQLInterface();
// DBResult listFields( const std::string& table, const std::string& wild ); // DBResult listFields( const std::string& table, const std::string& wild );
virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd, virtual bool nconnect( const std::string& host, const std::string& user, const std::string& pswd,
const std::string& dbname, unsigned int port = 0 ) override; const std::string& dbname, unsigned int port = 0 ) override;
virtual bool close() override; virtual bool close() override;
bool query_ok( const std::string& q ); bool query_ok( const std::string& q );
// \param finalize - освободить буфер после запроса // \param finalize - освободить буфер после запроса
virtual DBResult query( const std::string& q ) override; virtual DBResult query( const std::string& q ) override;
virtual const std::string lastQuery() override; virtual const std::string lastQuery() override;
virtual bool insert( const std::string& q ) override; virtual bool insert( const std::string& q ) override;
std::string addslashes(const std::string& str); std::string addslashes(const std::string& str);
/*! /*!
проверка связи с БД. проверка связи с БД.
в случае отсутствия попытка восстановить... в случае отсутствия попытка восстановить...
*/ */
virtual bool ping() const override; virtual bool ping() const override;
/*! связь с БД установлена (была) */ /*! связь с БД установлена (была) */
virtual bool isConnection() const override; virtual bool isConnection() const override;
virtual double insert_id() override; virtual double insert_id() override;
virtual const std::string error() override; virtual const std::string error() override;
// ******************* // *******************
const char* gethostinfo() const; const char* gethostinfo() const;
protected: protected:
private: private:
DBResult makeResult( MYSQL_RES* r, bool finalize = true ); DBResult makeResult( MYSQL_RES* r, bool finalize = true );
MYSQL* mysql; MYSQL* mysql;
std::string lastQ; std::string lastQ;
bool connected; bool connected;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
#endif #endif
...@@ -8,33 +8,33 @@ using namespace std; ...@@ -8,33 +8,33 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
try try
{ {
if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) ) if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) )
{ {
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
DBServer_MySQL::help_print(argc, argv); DBServer_MySQL::help_print(argc, argv);
return 0; return 0;
} }
auto conf = uniset_init(argc, argv, "configure.xml"); auto conf = uniset_init(argc, argv, "configure.xml");
auto db = DBServer_MySQL::init_dbserver(argc, argv); auto db = DBServer_MySQL::init_dbserver(argc, argv);
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(db); act->add(db);
act->run(false); act->run(false);
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(DBServer::main): " << ex.what() << endl; cerr << "(DBServer::main): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(DBServer::main): catch ..." << endl; cerr << "(DBServer::main): catch ..." << endl;
} }
return 0; return 0;
} }
...@@ -8,67 +8,67 @@ using namespace std; ...@@ -8,67 +8,67 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
std::string dbname("test-db"); std::string dbname("test-db");
std::string host("localhost"); std::string host("localhost");
std::string table("main_history"); std::string table("main_history");
if( argc > 1 ) if( argc > 1 )
dbname = string(argv[1]); dbname = string(argv[1]);
if( argc > 2 ) if( argc > 2 )
host = string(argv[2]); host = string(argv[2]);
if( argc > 3 ) if( argc > 3 )
table = string(argv[3]); table = string(argv[3]);
try try
{ {
MySQLInterface db; MySQLInterface db;
if( !db.nconnect(host, "dbadmin", "dbadmin", dbname) ) if( !db.nconnect(host, "dbadmin", "dbadmin", dbname) )
{ {
cerr << "db connect error: " << db.error() << endl; cerr << "db connect error: " << db.error() << endl;
return 1; return 1;
} }
stringstream q; stringstream q;
q << "SELECT * from " << table; q << "SELECT * from " << table;
DBResult r = db.query(q.str()); DBResult r = db.query(q.str());
if( !r ) if( !r )
{ {
cerr << "db connect error: " << db.error() << endl; cerr << "db connect error: " << db.error() << endl;
return 1; return 1;
} }
for( DBResult::iterator it = r.begin(); it != r.end(); it++ ) for( DBResult::iterator it = r.begin(); it != r.end(); it++ )
{ {
cout << "ROW: "; cout << "ROW: ";
// DBResult::COL col(*it); // DBResult::COL col(*it);
// for( DBResult::COL::iterator cit = col.begin(); cit != col.end(); cit++ ) // for( DBResult::COL::iterator cit = col.begin(); cit != col.end(); cit++ )
// cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | "; // cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | ";
// cout << endl; // cout << endl;
for( DBResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ ) for( DBResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ )
cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | "; cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
// cout << "ID: " << r.as_string(it, "id") << endl; // cout << "ID: " << r.as_string(it, "id") << endl;
cout << "ID: " << it.as_string("id") << endl; cout << "ID: " << it.as_string("id") << endl;
} }
db.close(); db.close();
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cerr << "(test): " << ex << endl; cerr << "(test): " << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
cerr << "(test): " << ex.what() << endl; cerr << "(test): " << ex.what() << endl;
} }
return 0; return 0;
} }
...@@ -28,55 +28,55 @@ ...@@ -28,55 +28,55 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// No thread safety! // No thread safety!
class PostgreSQLInterface: class PostgreSQLInterface:
public DBNetInterface public DBNetInterface
{ {
public: public:
PostgreSQLInterface(); PostgreSQLInterface();
~PostgreSQLInterface(); ~PostgreSQLInterface();
virtual bool nconnect( const std::string& host, const std::string& user, virtual bool nconnect( const std::string& host, const std::string& user,
const std::string& pswd, const std::string& dbname, const std::string& pswd, const std::string& dbname,
unsigned int port = 5432) override; unsigned int port = 5432) override;
virtual bool close() override; virtual bool close() override;
virtual bool isConnection() const override; virtual bool isConnection() const override;
virtual bool ping() const override; virtual bool ping() const override;
virtual DBResult query( const std::string& q ) override; virtual DBResult query( const std::string& q ) override;
virtual void cancel_query() override; virtual void cancel_query() override;
virtual const std::string lastQuery() override; virtual const std::string lastQuery() override;
virtual bool insert( const std::string& q ) override; virtual bool insert( const std::string& q ) override;
bool insertAndSaveRowid( const std::string& q ); bool insertAndSaveRowid( const std::string& q );
virtual double insert_id() override; virtual double insert_id() override;
void save_inserted_id( const pqxx::result& res ); void save_inserted_id( const pqxx::result& res );
typedef std::list<std::string> Record; typedef std::list<std::string> Record;
typedef std::vector<Record> Data; typedef std::vector<Record> Data;
// fast insert: Use COPY..from SDTIN.. // fast insert: Use COPY..from SDTIN..
bool copy( const std::string& tblname, const std::vector<std::string>& cols, const Data& data ); bool copy( const std::string& tblname, const std::vector<std::string>& cols, const Data& data );
virtual const std::string error() override; virtual const std::string error() override;
bool reconnect(const std::string& host, const std::string& user, bool reconnect(const std::string& host, const std::string& user,
const std::string& pswd, const std::string& dbname, const std::string& pswd, const std::string& dbname,
unsigned int port = 5432); unsigned int port = 5432);
protected: protected:
private: private:
DBResult makeResult( const pqxx::result& res ); DBResult makeResult( const pqxx::result& res );
std::unique_ptr<pqxx::connection> db; std::unique_ptr<pqxx::connection> db;
std::string lastQ; std::string lastQ;
std::string lastE; std::string lastE;
double last_inserted_id; double last_inserted_id;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#endif #endif
......
...@@ -8,36 +8,36 @@ using namespace std; ...@@ -8,36 +8,36 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
// std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
try try
{ {
if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) ) if( argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) )
{ {
cout << "--confile filename - configuration file. Default: configure.xml" << endl; cout << "--confile filename - configuration file. Default: configure.xml" << endl;
DBServer_PostgreSQL::help_print(argc, argv); DBServer_PostgreSQL::help_print(argc, argv);
return 0; return 0;
} }
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
auto dbs = DBServer_PostgreSQL::init_dbserver(argc, argv); auto dbs = DBServer_PostgreSQL::init_dbserver(argc, argv);
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->add(dbs); act->add(dbs);
act->run(false); act->run(false);
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cerr << "(DBServer_PosgreSQL::main): " << ex << endl; cerr << "(DBServer_PosgreSQL::main): " << ex << endl;
} }
catch( std::exception& ex ) catch( std::exception& ex )
{ {
cerr << "(DBServer_PosgreSQL::main): " << ex.what() << endl; cerr << "(DBServer_PosgreSQL::main): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(DBServer_PosgreSQL::main): catch ..." << endl; cerr << "(DBServer_PosgreSQL::main): catch ..." << endl;
} }
return 0; return 0;
} }
...@@ -8,111 +8,111 @@ using namespace std; ...@@ -8,111 +8,111 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
std::string dbname("test-db"); std::string dbname("test-db");
if( argc > 1 ) if( argc > 1 )
dbname = string(argv[1]); dbname = string(argv[1]);
size_t ver = 1; size_t ver = 1;
if( argc > 2 ) if( argc > 2 )
ver = atoi(argv[2]); ver = atoi(argv[2]);
size_t num = 10000; size_t num = 10000;
if( argc > 3 ) if( argc > 3 )
num = atoi(argv[3]); num = atoi(argv[3]);
try try
{ {
PostgreSQLInterface db; PostgreSQLInterface db;
cout << "connect to '" << dbname << "'..." << endl; cout << "connect to '" << dbname << "'..." << endl;
if( !db.nconnect("localhost", "dbadmin", "dbadmin", dbname) ) if( !db.nconnect("localhost", "dbadmin", "dbadmin", dbname) )
{ {
cerr << "[FAILED] connect error: " << db.error() << endl; cerr << "[FAILED] connect error: " << db.error() << endl;
db.close(); db.close();
return 1; return 1;
} }
cout << "connect to '" << dbname << "' [OK]" << endl; cout << "connect to '" << dbname << "' [OK]" << endl;
stringstream q; stringstream q;
if( ver == 1 ) if( ver == 1 )
{ {
for( size_t i = 0; i < num; i++ ) for( size_t i = 0; i < num; i++ )
{ {
q << "INSERT INTO main_history(date,time,time_usec,sensor_id,value,node)" q << "INSERT INTO main_history(date,time,time_usec,sensor_id,value,node)"
<< " VALUES(now(),now(),0,7,1,3000);"; << " VALUES(now(),now(),0,7,1,3000);";
} }
} }
else if( ver == 2 ) else if( ver == 2 )
{ {
q << "INSERT INTO main_history(date,time,time_usec,sensor_id,value,node) VALUES"; q << "INSERT INTO main_history(date,time,time_usec,sensor_id,value,node) VALUES";
for( size_t i = 0; i < num; i++ ) for( size_t i = 0; i < num; i++ )
{ {
q << "(now(),now(),0,7,1,3000),"; q << "(now(),now(),0,7,1,3000),";
} }
q << "(now(),now(),0,7,1,3000);"; q << "(now(),now(),0,7,1,3000);";
} }
std::chrono::time_point<std::chrono::system_clock> start, end; std::chrono::time_point<std::chrono::system_clock> start, end;
if( ver == 3 ) if( ver == 3 )
{ {
std::vector<std::string> cols = { "date", "time", "time_usec", "sensor_id", "value", "node" }; std::vector<std::string> cols = { "date", "time", "time_usec", "sensor_id", "value", "node" };
PostgreSQLInterface::Data data; PostgreSQLInterface::Data data;
for( size_t i = 0; i < num; i++ ) for( size_t i = 0; i < num; i++ )
{ {
PostgreSQLInterface::Record d = { "now()", "now()", "0", "7", "1", "3000" }; PostgreSQLInterface::Record d = { "now()", "now()", "0", "7", "1", "3000" };
data.push_back(std::move(d)); data.push_back(std::move(d));
} }
start = std::chrono::system_clock::now(); start = std::chrono::system_clock::now();
if( !db.copy("main_history", cols, data) ) if( !db.copy("main_history", cols, data) )
{ {
cerr << "query error: " << db.error() << endl; cerr << "query error: " << db.error() << endl;
db.close(); db.close();
return 1; return 1;
} }
} }
else else
{ {
start = std::chrono::system_clock::now(); start = std::chrono::system_clock::now();
if( !db.insert( std::move(q.str())) ) if( !db.insert( std::move(q.str())) )
{ {
cerr << "query error: " << db.error() << endl; cerr << "query error: " << db.error() << endl;
db.close(); db.close();
return 1; return 1;
} }
} }
end = std::chrono::system_clock::now(); end = std::chrono::system_clock::now();
int elapsed_seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); int elapsed_seconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cerr << "INSERT " << num << " records elasped time: " << elapsed_seconds << " ms\n"; std::cerr << "INSERT " << num << " records elasped time: " << elapsed_seconds << " ms\n";
db.close(); db.close();
} }
catch( const uniset::Exception& ex ) catch( const uniset::Exception& ex )
{ {
cerr << "(test): " << ex << endl; cerr << "(test): " << ex << endl;
} }
catch( std::exception& ex ) catch( std::exception& ex )
{ {
cerr << "(test): " << ex.what() << endl; cerr << "(test): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
cerr << "(test): catch ..." << endl; cerr << "(test): catch ..." << endl;
} }
return 0; return 0;
} }
...@@ -31,115 +31,115 @@ ...@@ -31,115 +31,115 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/*! \page SQLiteIntarface Интерфейс к SQLite /*! \page SQLiteIntarface Интерфейс к SQLite
Пример использования: Пример использования:
\code \code
try try
{ {
SQLiteInterface db; SQLiteInterface db;
if( !db.connect("test.db") ) if( !db.connect("test.db") )
{ {
cerr << "db connect error: " << db.error() << endl; cerr << "db connect error: " << db.error() << endl;
return 1; return 1;
} }
stringstream q; stringstream q;
q << "SELECT * from main_history"; q << "SELECT * from main_history";
DBResult r = db.query(q.str()); DBResult r = db.query(q.str());
if( !r ) if( !r )
{ {
cerr << "db connect error: " << db.error() << endl; cerr << "db connect error: " << db.error() << endl;
return 1; return 1;
} }
for( DBResult::iterator it=r.begin(); it!=r.end(); it++ ) for( DBResult::iterator it=r.begin(); it!=r.end(); it++ )
{ {
cout << "ROW: "; cout << "ROW: ";
DBResult::COL col(*it); DBResult::COL col(*it);
for( DBResult::COL::iterator cit = it->begin(); cit!=it->end(); cit++ ) for( DBResult::COL::iterator cit = it->begin(); cit!=it->end(); cit++ )
cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | "; cout << DBResult::as_string(cit) << "(" << DBResult::as_double(cit) << ") | ";
cout << endl; cout << endl;
} }
db.close(); db.close();
} }
catch(Exception& ex) catch(Exception& ex)
{ {
cerr << "(test): " << ex << endl; cerr << "(test): " << ex << endl;
} }
catch(...) catch(...)
{ {
cerr << "(test): catch ..." << endl; cerr << "(test): catch ..." << endl;
} }
\endcode \endcode
*/ */
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Памятка: // Памятка:
// Включение режима для журнала - "вести в памяти" (чтобы поберечь CompactFlash) // Включение режима для журнала - "вести в памяти" (чтобы поберечь CompactFlash)
// PRAGMA journal_mode = MEMORY // PRAGMA journal_mode = MEMORY
// При этом конечно есть риск потерять данные при выключении.. // При этом конечно есть риск потерять данные при выключении..
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class SQLiteInterface: class SQLiteInterface:
public DBInterface public DBInterface
{ {
public: public:
SQLiteInterface(); SQLiteInterface();
~SQLiteInterface(); ~SQLiteInterface();
virtual bool connect( const std::string& param ) override; virtual bool connect( const std::string& param ) override;
bool connect(const std::string& dbfile, bool create, int extra_sqlite_flags = 0 ); bool connect(const std::string& dbfile, bool create, int extra_sqlite_flags = 0 );
virtual bool close() override; virtual bool close() override;
virtual bool isConnection() const override; virtual bool isConnection() const override;
virtual bool ping() const override; virtual bool ping() const override;
void setOperationTimeout( timeout_t msec ); void setOperationTimeout( timeout_t msec );
inline timeout_t getOperationTimeout() inline timeout_t getOperationTimeout()
{ {
return opTimeout; return opTimeout;
} }
inline void setOperationCheckPause( timeout_t msec ) inline void setOperationCheckPause( timeout_t msec )
{ {
opCheckPause = msec; opCheckPause = msec;
} }
inline timeout_t getOperationCheckPause() inline timeout_t getOperationCheckPause()
{ {
return opCheckPause; return opCheckPause;
} }
virtual DBResult query( const std::string& q ) override; virtual DBResult query( const std::string& q ) override;
virtual const std::string lastQuery() override; virtual const std::string lastQuery() override;
bool lastQueryOK() const; bool lastQueryOK() const;
virtual bool insert( const std::string& q ) override; virtual bool insert( const std::string& q ) override;
virtual double insert_id() override; virtual double insert_id() override;
virtual const std::string error() override; virtual const std::string error() override;
protected: protected:
bool wait( sqlite3_stmt* stmt, int result ); bool wait( sqlite3_stmt* stmt, int result );
static bool checkResult( int rc ); static bool checkResult( int rc );
private: private:
DBResult makeResult( sqlite3_stmt* s, bool finalize = true ); DBResult makeResult( sqlite3_stmt* s, bool finalize = true );
sqlite3* db; sqlite3* db;
// sqlite3_stmt* curStmt; // sqlite3_stmt* curStmt;
std::string lastQ; std::string lastQ;
std::string lastE; std::string lastE;
bool queryok; // успешность текущего запроса bool queryok; // успешность текущего запроса
bool connected; bool connected;
timeout_t opTimeout; timeout_t opTimeout;
timeout_t opCheckPause; timeout_t opCheckPause;
}; };
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#endif #endif
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment