Commit 5dec0299 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(unet): minor fixes

parent 3b725a99
...@@ -512,7 +512,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept ...@@ -512,7 +512,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::checkConnection() bool UNetReceiver::checkConnection()
{ {
bool tout = false; bool tout = false;
...@@ -530,12 +530,21 @@ void UNetReceiver::checkConnection() ...@@ -530,12 +530,21 @@ void UNetReceiver::checkConnection()
if( w ) if( w )
{ {
if( tout ) try
{
if (tout)
slEvent(w, evTimeout); slEvent(w, evTimeout);
else else
slEvent(w, evOK); slEvent(w, evOK);
} }
catch( std::exception& ex )
{
unetcrit << myname << "(checkConnection): exception: " << ex.what() << endl;
}
}
} }
return !tout;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
...@@ -552,7 +561,10 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept ...@@ -552,7 +561,10 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
// взводим таймер опять.. // взводим таймер опять..
tm.again(); tm.again();
// собственно обработка события // смотрим есть ли связь..
bool recvOk = checkConnection();
// обновление данных в SM
try try
{ {
update(); update();
...@@ -562,16 +574,13 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept ...@@ -562,16 +574,13 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
unetcrit << myname << "(updateEvent): " << ex.what() << std::endl; unetcrit << myname << "(updateEvent): " << ex.what() << std::endl;
} }
// смотрим есть ли связь..
checkConnection();
if( sidRespond != DefaultObjectId ) if( sidRespond != DefaultObjectId )
{ {
try try
{ {
if( isInitOK() ) if( isInitOK() )
{ {
bool r = respondInvert ? !isRecvOK() : isRecvOK(); bool r = respondInvert ? !recvOk : recvOk;
shm->localSetValue(itRespond, sidRespond, ( r ? 1 : 0 ), shm->ID()); shm->localSetValue(itRespond, sidRespond, ( r ? 1 : 0 ), shm->ID());
} }
} }
......
...@@ -189,7 +189,7 @@ namespace uniset ...@@ -189,7 +189,7 @@ namespace uniset
void initIterators() noexcept; void initIterators() noexcept;
bool createConnection( bool throwEx = false ); bool createConnection( bool throwEx = false );
void checkConnection(); bool checkConnection();
size_t rnext( size_t num ); size_t rnext( size_t num );
private: private:
......
#include <cstdlib> #include <cstdlib>
#include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
...@@ -68,7 +67,7 @@ int main(int argc, char* argv[]) ...@@ -68,7 +67,7 @@ int main(int argc, char* argv[])
int verb = 0; int verb = 0;
std::string addr = ""; std::string addr = "";
int port = 0; int port = 0;
int usecpause = 2000000; int usecpause = 200000;
timeout_t tout = UniSetTimer::WaitUpTime; timeout_t tout = UniSetTimer::WaitUpTime;
bool broadcast = true; bool broadcast = true;
int procID = 1; int procID = 1;
...@@ -108,7 +107,7 @@ int main(int argc, char* argv[]) ...@@ -108,7 +107,7 @@ int main(int argc, char* argv[])
cout << "[-y|--prof] num - Print receive statistics every NUM packets (for -r only)" << endl; cout << "[-y|--prof] num - Print receive statistics every NUM packets (for -r only)" << endl;
cout << "[-a|--a-data] id1=val1,id2=val2,... - Analog data. Send: id1=id1,id2=id2,.. for analog sensors" << endl; cout << "[-a|--a-data] id1=val1,id2=val2,... - Analog data. Send: id1=id1,id2=id2,.. for analog sensors" << endl;
cout << "[-i|--d-data] id1=val1,id2=val2,... - Digital data. Send: id1=id1,id2=id2,.. for digital sensors" << endl; cout << "[-i|--d-data] id1=val1,id2=val2,... - Digital data. Send: id1=id1,id2=id2,.. for digital sensors" << endl;
cout << "[-u|--pack-num] num - first packet numbrt (default: 1)" << endl; cout << "[-u|--pack-num] num - first packet number (default: 1)" << endl;
cout << endl; cout << endl;
return 0; return 0;
...@@ -255,7 +254,7 @@ int main(int argc, char* argv[]) ...@@ -255,7 +254,7 @@ int main(int argc, char* argv[])
continue; continue;
} }
size_t ret = udp.receiveBytes(&pack, sizeof(pack) ); size_t ret = udp.receiveBytes(&pack, sizeof(pack));
if( ret < 0 ) if( ret < 0 )
{ {
...@@ -281,7 +280,9 @@ int main(int argc, char* argv[]) ...@@ -281,7 +280,9 @@ int main(int argc, char* argv[])
{ {
if( prev_num != (pack.header.num - 1) ) if( prev_num != (pack.header.num - 1) )
cerr << "WARNING! Incorrect sequence of packets! current=" << pack.header.num cerr << "WARNING! Incorrect sequence of packets! current=" << pack.header.num
<< " prev=" << prev_num << endl; << " prev=" << prev_num
<< " lost: " << std::labs(pack.header.num - prev_num)
<< endl;
prev_num = pack.header.num; prev_num = pack.header.num;
} }
......
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