Commit 8dd92d64 authored by Pavel Vainerman's avatar Pavel Vainerman

(UNetUDP): fix init error for digital sensors, init default value

parent 8e396a36
...@@ -82,6 +82,7 @@ namespace uniset ...@@ -82,6 +82,7 @@ namespace uniset
packs_anum[0] = 0; packs_anum[0] = 0;
packs_dnum[0] = 0; packs_dnum[0] = 0;
auto& mypack(mypacks[0][0]); auto& mypack(mypacks[0][0]);
// выставляем поля, которые не меняются // выставляем поля, которые не меняются
{ {
uniset_rwmutex_wrlock l(mypack.mut); uniset_rwmutex_wrlock l(mypack.mut);
...@@ -412,6 +413,7 @@ namespace uniset ...@@ -412,6 +413,7 @@ namespace uniset
return false; return false;
} }
int priority = it.getPIntProp(prop_prefix + "_sendfactor", 0); int priority = it.getPIntProp(prop_prefix + "_sendfactor", 0);
auto& pk = mypacks[priority]; auto& pk = mypacks[priority];
...@@ -419,6 +421,7 @@ namespace uniset ...@@ -419,6 +421,7 @@ namespace uniset
UItem p; UItem p;
p.iotype = uniset::getIOType(it.getProp("iotype")); p.iotype = uniset::getIOType(it.getProp("iotype"));
p.pack_sendfactor = priority; p.pack_sendfactor = priority;
long defval = it.getIntProp("default");
if( !it.getProp("undefined_value").empty() ) if( !it.getProp("undefined_value").empty() )
p.undefined_value = it.getIntProp("undefined_value"); p.undefined_value = it.getIntProp("undefined_value");
...@@ -438,11 +441,12 @@ namespace uniset ...@@ -438,11 +441,12 @@ namespace uniset
if( pk.size() <= dnum ) if( pk.size() <= dnum )
pk.resize(dnum + 1); pk.resize(dnum + 1);
auto& mypack(pk[dnum]); auto& mypack = pk[dnum];
uniset_rwmutex_wrlock l(mypack.mut); {
uniset_rwmutex_wrlock l(mypack.mut);
p.pack_ind = mypack.msg.addDData(sid, 0); p.pack_ind = mypack.msg.addDData(sid, defval);
} // unlock mutex....
if( p.pack_ind >= maxDData ) if( p.pack_ind >= maxDData )
{ {
...@@ -451,21 +455,21 @@ namespace uniset ...@@ -451,21 +455,21 @@ namespace uniset
if( dnum >= pk.size() ) if( dnum >= pk.size() )
pk.resize(dnum + 1); pk.resize(dnum + 1);
auto& mypack2( pk[dnum] ); auto& mypack2 = pk[dnum];
uniset_rwmutex_wrlock l2(mypack2.mut); uniset_rwmutex_wrlock l2(mypack2.mut);
p.pack_ind = mypack2.msg.addDData(sid, 0); p.pack_ind = mypack2.msg.addDData(sid, defval);
mypack2.msg.nodeID = uniset_conf()->getLocalNode(); mypack2.msg.nodeID = uniset_conf()->getLocalNode();
mypack2.msg.procID = shm->ID(); mypack2.msg.procID = shm->ID();
} }
p.pack_num = dnum; p.pack_num = dnum;
packs_anum[priority] = dnum; packs_dnum[priority] = dnum;
if ( p.pack_ind >= UniSetUDP::MaxDCount ) if ( p.pack_ind >= UniSetUDP::MaxDCount )
{ {
unetcrit << myname unetcrit << myname
<< "(readItem): OVERFLOW! MAX UDP DIGITAL DATA LIMIT! max=" << "(readItem): OVERFLOW! MAX UDP DIGITAL DATA LIMIT! max="
<< UniSetUDP::MaxDCount << endl; << UniSetUDP::MaxDCount << endl << flush;
std::terminate(); std::terminate();
return false; return false;
...@@ -478,20 +482,22 @@ namespace uniset ...@@ -478,20 +482,22 @@ namespace uniset
if( pk.size() <= anum ) if( pk.size() <= anum )
pk.resize(anum + 1); pk.resize(anum + 1);
auto& mypack(pk[anum]); auto& mypack = pk[anum];
uniset_rwmutex_wrlock l(mypack.mut);
p.pack_ind = mypack.msg.addAData(sid, 0); {
uniset_rwmutex_wrlock l(mypack.mut);
p.pack_ind = mypack.msg.addAData(sid, defval);
}
if( p.pack_ind >= maxAData ) if( p.pack_ind >= maxAData )
{ {
anum++; anum++;
if( anum >= pk.size() ) if( anum >= pk.size() )
pk.resize(anum + 1); pk.resize(anum + 1);
auto& mypack2(pk[anum]); auto& mypack2 = pk[anum];
uniset_rwmutex_wrlock l2(mypack2.mut); uniset_rwmutex_wrlock l2(mypack2.mut);
p.pack_ind = mypack2.msg.addAData(sid, 0); p.pack_ind = mypack2.msg.addAData(sid, defval);
mypack2.msg.nodeID = uniset_conf()->getLocalNode(); mypack2.msg.nodeID = uniset_conf()->getLocalNode();
mypack2.msg.procID = shm->ID(); mypack2.msg.procID = shm->ID();
} }
...@@ -503,7 +509,7 @@ namespace uniset ...@@ -503,7 +509,7 @@ namespace uniset
{ {
unetcrit << myname unetcrit << myname
<< "(readItem): OVERFLOW! MAX UDP ANALOG DATA LIMIT! max=" << "(readItem): OVERFLOW! MAX UDP ANALOG DATA LIMIT! max="
<< UniSetUDP::MaxACount << endl; << UniSetUDP::MaxACount << endl << flush;
std::terminate(); std::terminate();
return false; return false;
......
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