Commit 44054773 authored by Pavel Vainerman's avatar Pavel Vainerman

(IOControl): Исправление SEGFAULT при загрузке конфигурации.

Заодно встроил отдельный поток для опроса внутрь IOControl
parent 56880695
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <deque> #include <deque>
#include <string> #include <string>
#include "UniXML.h" #include "UniXML.h"
#include "ThreadCreator.h"
#include "PassiveTimer.h" #include "PassiveTimer.h"
#include "Trigger.h" #include "Trigger.h"
#include "IONotifyController.h" #include "IONotifyController.h"
...@@ -197,12 +198,12 @@ namespace uniset ...@@ -197,12 +198,12 @@ namespace uniset
delete (*this)[i]; delete (*this)[i];
} }
inline ComediInterface* getCard(int ncard) const inline ComediInterface* getCard( size_t ncard ) const
{ {
if( ncard >= 0 && ncard < (int)size() ) if( ncard < size() )
return (*this)[ncard]; return (*this)[ncard];
return NULL; return nullptr;
} }
}; };
...@@ -284,7 +285,8 @@ namespace uniset ...@@ -284,7 +285,8 @@ namespace uniset
bool enable_testmode; /*!< флаг для режима тестирования tmConfigEnable */ bool enable_testmode; /*!< флаг для режима тестирования tmConfigEnable */
bool disable_testmode; /*!< флаг для режима тестирования tmConfigDisable */ bool disable_testmode; /*!< флаг для режима тестирования tmConfigDisable */
friend std::ostream& operator<<(std::ostream& os, IOInfo& inf ); friend std::ostream& operator<<(std::ostream& os, const IOInfo& inf );
friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<IOInfo>& inf );
}; };
struct IOPriority struct IOPriority
...@@ -306,15 +308,14 @@ namespace uniset ...@@ -306,15 +308,14 @@ namespace uniset
tmOnlyOutputs = 5 /*!< включены только выходы */ tmOnlyOutputs = 5 /*!< включены только выходы */
}; };
void execute();
protected: protected:
void iopoll(); /*!< опрос карт в/в */ void iopoll(); /*!< опрос карт в/в */
void ioread( IOInfo* it ); void ioread( std::shared_ptr<IOInfo>& it );
void check_testlamp(); void check_testlamp();
void check_testmode(); void check_testmode();
void blink(); void blink();
void iothread();
// действия при завершении работы // действия при завершении работы
virtual void sysCommand( const uniset::SystemMessage* sm ) override; virtual void sysCommand( const uniset::SystemMessage* sm ) override;
...@@ -323,6 +324,7 @@ namespace uniset ...@@ -323,6 +324,7 @@ namespace uniset
virtual void timerInfo( const uniset::TimerMessage* tm ) override; virtual void timerInfo( const uniset::TimerMessage* tm ) override;
virtual void sigterm( int signo ) override; virtual void sigterm( int signo ) override;
virtual bool activateObject() override; virtual bool activateObject() override;
virtual bool deactivateObject() override;
// начальная инициализация выходов // начальная инициализация выходов
void initOutputs(); void initOutputs();
...@@ -344,14 +346,14 @@ namespace uniset ...@@ -344,14 +346,14 @@ namespace uniset
CardList cards; /*!< список карт - массив созданных ComediInterface */ CardList cards; /*!< список карт - массив созданных ComediInterface */
bool noCards = { false }; bool noCards = { false };
typedef std::vector<IOInfo> IOMap; typedef std::vector< std::shared_ptr<IOInfo> > IOMap;
IOMap iomap; /*!< список входов/выходов */ IOMap iomap; /*!< список входов/выходов */
typedef std::deque<IOPriority> PIOMap; typedef std::deque<IOPriority> PIOMap;
PIOMap pmap; /*!< список приоритетных входов/выходов */ PIOMap pmap; /*!< список приоритетных входов/выходов */
unsigned int maxItem = { 0 }; /*!< количество элементов (используется на момент инициализации) */ size_t maxItem = { 0 }; /*!< количество элементов (используется на момент инициализации) */
unsigned int maxHalf = { 0 }; size_t maxHalf = { 0 };
int filtersize = { 0 }; int filtersize = { 0 };
float filterT = { 0.0 }; float filterT = { 0.0 };
...@@ -362,10 +364,10 @@ namespace uniset ...@@ -362,10 +364,10 @@ namespace uniset
uniset::ObjectId myid = { uniset::DefaultObjectId }; uniset::ObjectId myid = { uniset::DefaultObjectId };
std::string prefix; std::string prefix;
typedef std::list<IOInfo*> BlinkList; typedef std::list<std::shared_ptr<IOInfo>> BlinkList;
void addBlink( IOInfo* it, BlinkList& lst ); void addBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
void delBlink( IOInfo* it, BlinkList& lst ); void delBlink( std::shared_ptr<IOInfo>& it, BlinkList& lst );
void blink( BlinkList& lst, bool& bstate ); void blink( BlinkList& lst, bool& bstate );
// обычное мигание // обычное мигание
...@@ -417,6 +419,8 @@ namespace uniset ...@@ -417,6 +419,8 @@ namespace uniset
std::string logserv_host = {""}; std::string logserv_host = {""};
int logserv_port = {0}; int logserv_port = {0};
std::shared_ptr< ThreadCreator<IOControl> > ioThread;
private: private:
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
...@@ -61,7 +61,6 @@ int main(int argc, const char** argv) ...@@ -61,7 +61,6 @@ int main(int argc, const char** argv)
return 1; return 1;
} }
auto ic = IOControl::init_iocontrol(argc, argv, shmID); auto ic = IOControl::init_iocontrol(argc, argv, shmID);
if( !ic ) if( !ic )
...@@ -80,18 +79,16 @@ int main(int argc, const char** argv) ...@@ -80,18 +79,16 @@ int main(int argc, const char** argv)
ulogany << "(main): -------------- IOControl START -------------------------\n\n"; ulogany << "(main): -------------- IOControl START -------------------------\n\n";
dlogany << "\n\n\n"; dlogany << "\n\n\n";
dlogany << "(main): -------------- IOControl START -------------------------\n\n"; dlogany << "(main): -------------- IOControl START -------------------------\n\n";
act->run(true); act->run(false);
msleep(500);
ic->execute();
return 0; return 0;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
dcrit << "(iocontrol): " << ex.what() << endl; cerr << "(iocontrol): " << ex.what() << endl;
} }
catch(...) catch(...)
{ {
dcrit << "(iocontrol): catch(...)" << endl; cerr << "(iocontrol): catch(...)" << endl;
} }
return 1; return 1;
......
...@@ -15,5 +15,5 @@ uniset2-start.sh -f ./uniset2-iocontrol --smemory-id SharedMemory \ ...@@ -15,5 +15,5 @@ uniset2-start.sh -f ./uniset2-iocontrol --smemory-id SharedMemory \
--io-test-lamp Input1_S \ --io-test-lamp Input1_S \
--io-heartbeat-id AI_AS \ --io-heartbeat-id AI_AS \
--io-sm-ready-test-sid Input1_S \ --io-sm-ready-test-sid Input1_S \
--ulog-add-levels any --dlog-add-levels any --ulog-add-levels any --dlog-add-levels any --io-log-add-levels any
...@@ -97,10 +97,7 @@ int main( int argc, const char** argv ) ...@@ -97,10 +97,7 @@ int main( int argc, const char** argv )
if( !ic ) if( !ic )
return 1; return 1;
ThreadCreator<IOControl>* io_thr = new ThreadCreator<IOControl>(ic.get(), &IOControl::execute);
act->add(ic); act->add(ic);
lst_iothr.push_back( io_thr );
} }
} }
......
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