Commit de1ea9fc authored by Pavel Vainerman's avatar Pavel Vainerman

(IOControl): добавил вывод getInfo(), добавил тест "testlamp".

parent bf9ffd30
......@@ -22,9 +22,10 @@
using namespace uniset;
using namespace std;
// -----------------------------------------------------------------------------
ComediInterface::ComediInterface( const std::string& dev ):
ComediInterface::ComediInterface( const std::string& dev, const std::string& cname ):
card(0),
dname(dev)
dname(dev),
name(cname)
{
card = comedi_open(dev.c_str());
......
......@@ -28,7 +28,7 @@ namespace uniset
class ComediInterface
{
public:
explicit ComediInterface( const std::string& dev );
explicit ComediInterface( const std::string& dev, const std::string& cname );
virtual ~ComediInterface();
virtual int getAnalogChannel( int subdev, int channel, int range = 0, int aref = AREF_GROUND ) const
......@@ -74,11 +74,17 @@ namespace uniset
return dname;
}
inline const std::string cardname() const
{
return name;
}
protected:
ComediInterface():card(nullptr){}
comedi_t* card; /*!< интерфейс для работы с картами в/в */
std::string dname;
std::string name;
private:
};
......
......@@ -15,6 +15,7 @@
*/
// -------------------------------------------------------------------------
#include <sstream>
#include <iomanip>
#include "ORepHelpers.h"
#include "UniSetTypes.h"
#include "Extensions.h"
......@@ -141,7 +142,7 @@ namespace uniset
else
{
noCards = false;
cards[i] = new ComediInterface(iodev);
cards[i] = new ComediInterface(iodev,"");
iolog3 << myname << "(init): ADD card" << i << " dev=" << iodev << endl;
}
......@@ -181,14 +182,21 @@ namespace uniset
ioinfo << myname << "(init): result numcards=" << cards.size() << endl;
polltime = conf->getArgPInt("--" + prefix + "-polltime", it.getProp("polltime"), polltime);
vmonit(polltime);
force = conf->getArgInt("--" + prefix + "-force", it.getProp("force"));
force_out = conf->getArgInt("--" + prefix + "-force-out", it.getProp("force_out"));
vmonit(force);
vmonit(force_out);
filtersize = conf->getArgPInt("--" + prefix + "-filtersize", it.getProp("filtersize"), 1);
filterT = atof(conf->getArgParam("--" + prefix + "-filterT", it.getProp("filterT")).c_str());
vmonit(filtersize);
vmonit(filterT);
string testlamp = conf->getArgParam("--" + prefix + "-test-lamp", it.getProp("testlamp_s"));
if( !testlamp.empty() )
......@@ -206,6 +214,8 @@ namespace uniset
ioinfo << myname << "(init): testLamp_S='" << testlamp << "'" << endl;
}
vmonit(testLamp_s);
string tmode = conf->getArgParam("--" + prefix + "-test-mode", it.getProp("testmode_as"));
if( !tmode.empty() )
......@@ -223,12 +233,17 @@ namespace uniset
ioinfo << myname << "(init): testMode_as='" << testmode << "'" << endl;
}
vmonit(testMode_as);
shm = make_shared<SMInterface>(icID, ui, myid, ic);
// определяем фильтр
s_field = conf->getArgParam("--" + prefix + "-s-filter-field");
s_fvalue = conf->getArgParam("--" + prefix + "-s-filter-value");
vmonit(s_field);
vmonit(s_fvalue);
ioinfo << myname << "(init): read s_field='" << s_field
<< "' s_fvalue='" << s_fvalue << "'" << endl;
......@@ -250,6 +265,8 @@ namespace uniset
else
smReadyTimeout = sm_tout;
vmonit(smReadyTimeout);
string sm_ready_sid = conf->getArgParam("--" + prefix + "-sm-ready-test-sid", it.getProp("sm_ready_test_sid"));
sidTestSMReady = conf->getSensorID(sm_ready_sid);
......@@ -263,6 +280,7 @@ namespace uniset
else
ioinfo << myname << "(init): sm-ready-test-sid: " << sm_ready_sid << endl;
vmonit(sidTestSMReady);
// -----------------------
string heart = conf->getArgParam("--" + prefix + "-heartbeat-id", it.getProp("heartbeat_id"));
......@@ -291,10 +309,15 @@ namespace uniset
activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 25000);
vmonit(activateTimeout);
if( !shm->isLocalwork() ) // ic
ic->addReadItem( sigc::mem_fun(this, &IOControl::readItem) );
ioThread = make_shared< ThreadCreator<IOControl> >(this, &IOControl::iothread);
vmonit(maxCardNum);
vmonit(sidHeartBeat);
}
// --------------------------------------------------------------------------------
......@@ -1145,9 +1168,6 @@ namespace uniset
if( isTestLamp )
blink_state = true; // первый такт всегда зажигаем...
// cout << myname << "(check_test_lamp): ************* test lamp "
// << isTestLamp << " *************" << endl;
// проходим по списку и формируем список мигающих выходов...
for( auto& it : iomap )
{
......@@ -1269,6 +1289,50 @@ namespace uniset
cout << LogServer::help_print("prefix-logserver") << endl;
}
// -----------------------------------------------------------------------------
SimpleInfo*IOControl::getInfo( const char* userparam )
{
uniset::SimpleInfo_var i = UniSetObject::getInfo(userparam);
ostringstream inf;
inf << i->info << endl;
inf << "LogServer: " << logserv_host << ":" << logserv_port << endl;
if( logserv )
inf << logserv->getShortInfo() << endl;
else
inf << "No logserver running." << endl;
inf << endl;
inf << "iomap: " << iomap.size()
<< " isTestLamp=" << isTestLamp
<< " blink1=" << ptBlink.getInterval()
<< " blink2=" << ptBlink2.getInterval()
<< " blink3=" << ptBlink3.getInterval()
<< endl;
inf << endl;
for( size_t i=0; i<cards.size(); i++ )
{
auto c = cards[i];
if( c )
{
inf << "card[" << setw(2) << i << "]:"
<< " " << setw(10) << c->cardname()
<< " dev=" << c->devname()
<< endl;
}
}
inf << endl;
inf << vmon.pretty_str() << endl;
i->info = inf.str().c_str();
return i._retn();
}
// -----------------------------------------------------------------------------
void IOControl::sysCommand( const SystemMessage* sm )
{
switch( sm->command )
......@@ -1703,7 +1767,7 @@ namespace uniset
try
{
cards[cardnum] = new ComediInterface(iodev);
cards[cardnum] = new ComediInterface(iodev,cname);
noCards = false;
}
catch( const uniset::Exception& ex )
......
......@@ -41,9 +41,13 @@
#include "DebugStream.h"
#include "LogAgregator.h"
// -------------------------------------------------------------------------
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
// -------------------------------------------------------------------------
namespace uniset
{
// -----------------------------------------------------------------------------
// ---------------------------------------------------------------------
/*!
\page page_IOControl (IOControl) Реализация процесса ввода/вывода
......@@ -237,6 +241,8 @@ namespace uniset
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
/*! Информация о входе/выходе */
struct IOInfo:
public IOBase
......@@ -421,6 +427,8 @@ namespace uniset
std::shared_ptr< ThreadCreator<IOControl> > ioThread;
VMonitor vmon;
private:
};
// --------------------------------------------------------------------------
......
......@@ -87,7 +87,8 @@ namespace uniset
chInputs(maxChannelNum),
chOutputs(maxChannelNum)
{
name="FakeCard";
dname="/dev/fakecomedi";
}
// -----------------------------------------------------------------------------
FakeComediInterface::~FakeComediInterface()
......
......@@ -27,7 +27,7 @@
<settings>
<SharedMemory name="SharedMemory" shmID="SharedMemory"/>
<IOControl1 name="IOControl"/>
<IOControl1 name="IOControl" testlamp_s="TestLamp_S"/>
</settings>
<ObjectsMap idfromfile="1">
<!--
......@@ -60,6 +60,8 @@
<item id="1010" io="1" iotype="AI" name="AI_T_AS" textname="AI for threshold" card="1" subdev="1" channel="10"/>
<item id="1011" io="1" iotype="DI" name="T1_S" textname="Threshold 1" threshold_aid="AI_T_AS" lowlimit="30" hilimit="40"/>
<item id="1012" io="1" iotype="DI" name="TestLamp_S" textname="TestLamp_S" card="1" subdev="1" channel="12"/>
<item id="1013" io="1" iotype="AO" name="Lamp_C" textname="TLamp_C" lamp="1" card="1" subdev="1" channel="13"/>
<item id="10000" iotype="DI" name="TestMode_S" textname="Тестовый датчик"/>
......
......@@ -38,7 +38,7 @@ int main( int argc, const char* argv[] )
return returnCode;
auto conf = uniset_init(argc, argv);
dlog()->logFile("./smtest.log");
// dlog()->logFile("./smtest.log");
bool apart = findArgParam("--apart", argc, argv) != -1;
......
......@@ -13,4 +13,4 @@ cd -
--smemory-id SharedMemory \
--io-s-filter-field io \
--io-s-filter-value 1
# --io-log-add-levels any
#--io-log-add-levels any
......@@ -73,22 +73,16 @@ TEST_CASE("IOControl: DO", "[iocontrol][do]")
REQUIRE( ioc->fcard->chOutputs[1] == 1 ); // invert
}
// -----------------------------------------------------------------------------
TEST_CASE("IOControl: AO (lamp)", "[iocontrol][lamp]")
static size_t pulseCount( FakeComediInterface* card, size_t ch )
{
InitTest();
auto card = ioc->fcard;
ui->setValue(1004, uniset::lmpBLINK);
// считаем количество импульсов "0 -> 1 -> 0"
size_t npulse = 0;
bool prev = false;
for( size_t i=0; i < 20 && npulse < 3; i ++ )
{
if( card->chOutputs[4] == 1 && !prev )
if( card->chOutputs[ch] == 1 && !prev )
prev = true;
else if( card->chOutputs[4] == 0 && prev )
else if( card->chOutputs[ch] == 0 && prev )
{
prev = false;
npulse++;
......@@ -98,6 +92,19 @@ TEST_CASE("IOControl: AO (lamp)", "[iocontrol][lamp]")
msleep( polltime / 2 );
}
return npulse;
}
// -----------------------------------------------------------------------------
TEST_CASE("IOControl: AO (lamp)", "[iocontrol][lamp]")
{
InitTest();
auto card = ioc->fcard;
ui->setValue(1004, uniset::lmpBLINK);
// считаем количество импульсов "0 -> 1 -> 0"
size_t npulse = pulseCount(card, 4);
REQUIRE( npulse >= 2 );
}
// -----------------------------------------------------------------------------
......@@ -158,3 +165,37 @@ TEST_CASE("IOControl: threshold", "[iocontrol][threshold]")
REQUIRE( ui->getValue(1011) == 0 ); // < lowlimit (30)
}
// -----------------------------------------------------------------------------
TEST_CASE("IOControl: test lamp", "[iocontrol][testlamp]")
{
InitTest();
auto card = ioc->fcard;
// отключаем тест ламп
card->chInputs[12] = 0;
msleep(polltime+10);
REQUIRE( ui->getValue(1012) == 0 );
REQUIRE( ui->getValue(1013) == 0 );
REQUIRE( card->chOutputs[13] == 0 );
// включаем тест ламп
card->chInputs[12] = 1;
msleep(polltime+10);
REQUIRE( ui->getValue(1012) == 1 );
// должны ловить мигание лампочки..
size_t npulse = pulseCount(card, 13);
REQUIRE( npulse >= 2 );
// отключаем тест ламп
card->chInputs[12] = 0;
msleep(polltime+10);
REQUIRE( ui->getValue(1012) == 0 );
REQUIRE( ui->getValue(1013) == 0 );
REQUIRE( card->chOutputs[13] == 0 );
npulse = pulseCount(card, 13);
REQUIRE( npulse == 0 );
}
// -----------------------------------------------------------------------------
......@@ -901,7 +901,7 @@ namespace uniset
<< " date: " << uniset::dateToString()
<< " time: " << uniset::timeToString()
<< "\n===============================================================================\n"
<< " pid=" << setw(10) << Poco::Process::id()
<< "pid=" << setw(10) << Poco::Process::id()
<< " tid=" << setw(10);
if( threadcreate )
......
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