Commit 4404d4a2 authored by Pavel Vainerman's avatar Pavel Vainerman

(UNet): added "undefined_value" property

parent e6210567
......@@ -103,7 +103,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
nodes = conf->findNode(xml->getFirstNode(), nconfname);
}
unetinfo << myname << "(init): init from <" << nconfname << ">" << endl;
unetinfo << myname << "(init): init from <" << nconfname << ">" << endl;
if( !nodes )
throw uniset::SystemError("(UNetExchange): Not found confnode <" + nconfname + ">");
......
......@@ -152,8 +152,27 @@ namespace uniset
for( auto && it : items )
{
UItem& i = it.second;
long value = shm->localGetValue(i.ioit, i.id);
updateItem(i, value);
try
{
long value = shm->localGetValue(i.ioit, i.id);
updateItem(i, value);
}
catch( IOController_i::Undefined& ex )
{
unetwarn << myname << "(updateFromSM): sid=" << i.id
<< " undefined state..." << endl;
if( i.undefined_value != not_specified_value )
updateItem( i, i.undefined_value );
}
catch( std::exception& ex )
{
unetwarn << myname << "(updateFromSM): " << ex.what() << endl;
if( i.undefined_value != not_specified_value )
updateItem( i, i.undefined_value );
}
}
}
// -----------------------------------------------------------------------------
......@@ -293,7 +312,6 @@ namespace uniset
if( packetnum == 0 )
packetnum = 1;
if( !udp || !udp->poll( UniSetTimer::millisecToPoco(writeTimeout), Poco::Net::Socket::SELECT_WRITE) )
return;
......@@ -399,6 +417,9 @@ namespace uniset
p.iotype = uniset::getIOType(it.getProp("iotype"));
p.pack_sendfactor = priority;
if( !it.getProp("undefined_value").empty() )
p.undefined_value = it.getIntProp("undefined_value");
if( p.iotype == UniversalIO::UnknownIOType )
{
unetcrit << myname << "(readItem): Unknown iotype for sid=" << sid << endl;
......
......@@ -20,6 +20,7 @@
#include <ostream>
#include <string>
#include <vector>
#include <limits>
#include <unordered_map>
#include "UniSetObject.h"
#include "Trigger.h"
......@@ -76,6 +77,8 @@ namespace uniset
typedef size_t sendfactor_t;
static const long not_specified_value = { std::numeric_limits<long>::max() };
struct UItem
{
UItem():
......@@ -91,6 +94,7 @@ namespace uniset
size_t pack_num;
size_t pack_ind;
sendfactor_t pack_sendfactor = { 0 };
long undefined_value = { not_specified_value };
friend std::ostream& operator<<( std::ostream& os, UItem& p );
};
......
......@@ -468,3 +468,41 @@ TEST_CASE("[UNetUDP]: switching channels", "[unetudp][chswitch]")
REQUIRE( ui->getValue(node1_numchannel_as) == 1 );
}
// -----------------------------------------------------------------------------
TEST_CASE("[UNetUDP]: check undefined value", "[unetudp][sender]")
{
InitTest();
UniSetUDP::UDPMessage pack = receive();
ui->setValue(2, 110);
REQUIRE( ui->getValue(2) == 110 );
msleep(600);
pack = receive();
REQUIRE( pack.num != 0 );
REQUIRE( pack.asize() == 4 );
REQUIRE( pack.dsize() == 2 );
REQUIRE( pack.a_dat[0].val == 110 );
IOController_i::SensorInfo si;
si.id = 2;
si.node = uniset_conf()->getLocalNode();
ui->setUndefinedState(si, true, 6000 /* TestProc */ );
msleep(600);
pack = receive();
REQUIRE( pack.num != 0 );
REQUIRE( pack.asize() == 4 );
REQUIRE( pack.dsize() == 2 );
REQUIRE( pack.a_dat[0].val == 65635 );
ui->setUndefinedState(si, false, 6000 /* TestProc */ );
msleep(600);
pack = receive();
REQUIRE( pack.num != 0 );
REQUIRE( pack.asize() == 4 );
REQUIRE( pack.dsize() == 2 );
REQUIRE( pack.a_dat[0].val == 110 );
}
// -----------------------------------------------------------------------------
......@@ -43,7 +43,7 @@
<item id="100" iotype="DI" name="TestMode_S" textname="Test sensor"/>
<item id="1" iotype="DI" name="Node1_Not_Respond_S" textname="Node1 not respond"/>
<item id="2" iotype="AI" name="AI1_S" textname="AI sensor 1" unet="1" default="1"/>
<item id="2" iotype="AI" name="AI1_S" textname="AI sensor 1" unet="1" default="1" undefined_value="65635"/>
<item id="3" iotype="AI" name="AI2_S" textname="AI sensor 2" unet="1" default="2"/>
<item id="4" iotype="AI" name="AI3_S" textname="AI sensor 3" unet="1" default="3"/>
<item id="5" iotype="AI" name="AI4_S" textname="AI sensor 4" unet="1" default="4"/>
......
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