Commit e751a8d7 authored by Vitaly Lipatov's avatar Vitaly Lipatov

fix warnings and tabs

parent 1a422150
......@@ -91,7 +91,6 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
string stype = conf->getArgParam(t1.str(),it.getProp(t2.str()));
if( !stype.empty() )
{
// ComediInterface::SubdevType st = (ComediInterface::SubdevType)UniSetTypes::uni_atoi(stype.c_str());
ComediInterface::SubdevType st = ComediInterface::str2type(stype.c_str());
if( !stype.empty() && st == ComediInterface::Unknown )
{
......
......@@ -19,9 +19,9 @@ UniSetObject_LT(objId),
mbslot(0),
shm(0),
initPause(0),
askCount(0),
test_id(DefaultObjectId),
askcount_id(DefaultObjectId),
askCount(0),
activated(false),
activateTimeout(500),
pingOK(true),
......@@ -51,7 +51,7 @@ prefix(prefix)
force = uni_atoi(conf->getArgParam("--" + prefix + "-force",it.getProp("force")));
int recv_timeout = atoi(conf->getArgParam("--" + prefix + "-recv-timeout",it.getProp("recv_timeout")).c_str());
// int recv_timeout = atoi(conf->getArgParam("--" + prefix + "-recv-timeout",it.getProp("recv_timeout")).c_str());
string saddr = conf->getArgParam("--" + prefix + "-my-addr",it.getProp("addr"));
......
......@@ -157,8 +157,8 @@ class LT_Object
short curTick;
//
bool operator < ( const TimerInfo& ti ) const
{
bool operator < ( const TimerInfo& ti ) const
{
return curTimeMS > ti.curTimeMS;
}
......
......@@ -66,10 +66,10 @@ namespace UniSetTypes
friend class uniset_mutex_lock;
uniset_mutex (const uniset_mutex& r);
const uniset_mutex &operator=(const uniset_mutex& r);
omni_condition* cnd;
std::string nm;
omni_semaphore sem;
omni_mutex mtx;
omni_condition* cnd;
mutex_atomic_t locked;
};
......
......@@ -30,13 +30,6 @@
#include <sys/time.h>
//#include "Exceptions.h"
//----------------------------------------------------------------------------------------
// CLK_TCK
#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#endif
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
/*! \class UniSetTimer
......
......@@ -95,7 +95,7 @@ class UniSetObject:
virtual void processingMessage(UniSetTypes::VoidMessage *msg);
/*! */
bool receiveMessage(UniSetTypes::VoidMessage& msg);
bool receiveMessage(UniSetTypes::VoidMessage& vm);
/*! */
unsigned int countMessages();
......@@ -219,7 +219,7 @@ class UniSetObject:
bool reg;
bool active;
bool threadcreate;
UniSetTimer* tmr;
UniSetTimer* tmr;
UniSetTypes::ObjectId myid;
CORBA::Object_var oref;
ThreadCreator<UniSetObject>* thr;
......
......@@ -4,6 +4,7 @@
#define ModbusServer_H_
// -------------------------------------------------------------------------
#include <string>
#include "Debug.h"
#include "Mutex.h"
#include "Configuration.h"
......
......@@ -97,8 +97,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( res!=erNoError )
return res;
if( !tcp->isPending(ost::Socket::pendingOutput,timeout) )
return erTimeOut;
if( !tcp->isPending(ost::Socket::pendingOutput,timeout) )
return erTimeOut;
if( timeout != TIMEOUT_INF )
{
......@@ -124,7 +124,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
dlog(Debug::INFO) << endl;
}
if( ret < sizeof(rmh) )
if( ret < (int)sizeof(rmh) )
return erHardwareError;
rmh.swapdata();
......
......@@ -150,7 +150,7 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH
while( !qrecv.empty() )
qrecv.pop();
int len = getNextData((unsigned char*)(&mhead),sizeof(mhead));
unsigned int len = getNextData((unsigned char*)(&mhead),sizeof(mhead));
if( len < sizeof(mhead) )
return erInvalidFormat;
......
......@@ -369,7 +369,7 @@ DataBits::operator ModbusByte()
ModbusByte DataBits::mbyte()
{
ModbusByte ubyte = 0;
for( int i=0; i<b.size(); i++ )
for( unsigned int i=0; i<b.size(); i++ )
{
if( b[i] )
ubyte |= 1<<i;
......@@ -380,7 +380,7 @@ ModbusByte DataBits::mbyte()
// -------------------------------------------------------------------------
const DataBits& DataBits::operator=( const ModbusByte& r )
{
for( int i=0; i<b.size(); i++ )
for( unsigned int i=0; i<b.size(); i++ )
b[i] = r&(1<<i);
return (*this);
......@@ -389,7 +389,7 @@ const DataBits& DataBits::operator=( const ModbusByte& r )
std::ostream& ModbusRTU::operator<<(std::ostream& os, DataBits& d )
{
os << "[";
for( int i=d.b.size()-1; i>=0; i-- )
for( int i = (int)d.b.size()-1; i>=0; i-- )
os << d.b[i];
os << "]";
......@@ -425,7 +425,7 @@ DataBits16::operator ModbusData()
ModbusData DataBits16::mdata()
{
ModbusData udata = 0;
for( int i=0; i<b.size(); i++ )
for( unsigned int i=0; i<b.size(); i++ )
{
if( b[i] )
udata |= 1<<i;
......@@ -436,7 +436,7 @@ ModbusData DataBits16::mdata()
// -------------------------------------------------------------------------
const DataBits16& DataBits16::operator=( const ModbusData& r )
{
for( int i=0; i<b.size(); i++ )
for( unsigned int i=0; i<b.size(); i++ )
b[i] = r&(1<<i);
return (*this);
......@@ -445,7 +445,7 @@ const DataBits16& DataBits16::operator=( const ModbusData& r )
std::ostream& ModbusRTU::operator<<(std::ostream& os, DataBits16& d )
{
os << "[";
for( int i=d.b.size()-1; i>=0; i-- )
for( int i=(int)d.b.size()-1; i>=0; i-- )
os << d.b[i];
os << "]";
......@@ -876,7 +876,7 @@ void ReadOutputRetMessage::init( ModbusMessage& m )
func = m.func;
// bcnt = m.data[0];
int cnt = m.data[0] / sizeof(ModbusData);
unsigned int cnt = m.data[0] / sizeof(ModbusData);
if( cnt > MAXLENPACKET/sizeof(ModbusData) )
{
// cerr << "(ReadOutputRetMessage): BAD bcnt="
......@@ -889,7 +889,7 @@ void ReadOutputRetMessage::init( ModbusMessage& m )
memcpy(&data,&(m.data[1]),bcnt);
//
for( int i=0; i<cnt; i++ )
for( unsigned int i=0; i<cnt; i++ )
data[i] = SWAPSHORT(data[i]);
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
......@@ -1092,7 +1092,7 @@ void ReadInputRetMessage::init( ModbusMessage& m )
func = m.func;
// bcnt = m.data[0];
int cnt = m.data[0] / sizeof(ModbusData);
unsigned int cnt = m.data[0] / sizeof(ModbusData);
if( cnt > MAXLENPACKET/sizeof(ModbusData) )
throw mbException(erPacketTooLong);
......@@ -1101,10 +1101,10 @@ void ReadInputRetMessage::init( ModbusMessage& m )
memcpy(&data,&(m.data[1]),bcnt);
//
for( int i=0; i<cnt; i++ )
for( unsigned int i=0; i<cnt; i++ )
data[i] = SWAPSHORT(data[i]);
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
}
// -------------------------------------------------------------------------
int ReadInputRetMessage::getDataLen( ModbusMessage& m )
......@@ -2910,7 +2910,7 @@ std::ostream& ModbusRTU::operator<<(std::ostream& os, FileTransferRetMessage* m
std::ostream& ModbusTCP::operator<<(std::ostream& os, MBAPHeader& m )
{
// m.swapdata();
for( int i=0; i<sizeof(m); i++ )
for( unsigned int i=0; i<sizeof(m); i++ )
os << ((unsigned char*)(&m))[i];
// m.swapdata();
return os;
......
......@@ -896,6 +896,8 @@ UniSetTypes::Message::Priority IOController::getMessagePriority(UniSetTypes::Key
return (UniSetTypes::Message::Priority)it->second.priority;
}
break;
default:
break;
}
return UniSetTypes::Message::Medium; // ??
......
......@@ -203,7 +203,6 @@ void IONotifyController::askState( const IOController_i::SensorInfo& si,
// , ...
DIOStateList::iterator li = mydioEnd();
bool st = localGetState(li,si);
// lock ???
if( li==mydioEnd() )
......@@ -288,7 +287,6 @@ void IONotifyController::askValue(const IOController_i::SensorInfo& si,
// , ...
AIOStateList::iterator li = myaioEnd();
long val = localGetValue(li,si);
if( li->second.type != UniversalIO::AnalogInput )
{
ostringstream err;
......
......@@ -107,7 +107,7 @@ void TimerService::askTimer( const TimerService_i::Timer& ti, const UniSetTypes:
{
li->curTick = ti.ticks;
li->tmr.setTiming(ti.timeMS);
li->not_ping = false;
li->not_ping = false;
li->lifetmr.reset();
unideb[Debug::INFO] << myname << ": (id="<< ti.timerid << ") "
<< ti.timeMS << " [] " << ui.getNameById(ci.id)
......@@ -212,7 +212,7 @@ void TimerService::work()
if( !AskLifeTimeSEC )
{
unideb[Debug::WARN] << myname << ": "<< ui.getNameById(li->cinf.id,li->cinf.node) << endl;
li = tlst.erase(li);
li = tlst.erase(li);
if( tlst.empty() )
isSleep = true;
continue;
......@@ -225,7 +225,7 @@ void TimerService::work()
else if( li->lifetmr.checkTime() )
{
unideb[Debug::WARN] << myname << ": "<< ui.getNameById(li->cinf.id,li->cinf.node) << endl;
li = tlst.erase(li);
li = tlst.erase(li);
if( tlst.empty() )
isSleep = true;
continue;
......@@ -237,7 +237,7 @@ void TimerService::work()
//
if( !li->curTick )
{
li = tlst.erase(li);
li = tlst.erase(li);
if( tlst.empty() )
isSleep = true;
continue;
......
......@@ -103,7 +103,7 @@ int PassiveSysTimer::wait(int timeMS)
if( sigaction(SIGALRM, &action, 0) == -1)
{
cerr << "PassiveSysTimer: error sigaction" << endl;
return 0;
return false;
}
......@@ -112,7 +112,7 @@ int PassiveSysTimer::wait(int timeMS)
terminated = 0;
int sec;
int msec;
int msec;
if (timeMS == WaitUpTime)
{
......@@ -126,19 +126,19 @@ int PassiveSysTimer::wait(int timeMS)
}
mtimer.it_value.tv_sec = sec;
mtimer.it_value.tv_usec = msec;
mtimer.it_value.tv_usec = msec;
mtimer.it_interval.tv_sec = 0;
mtimer.it_interval.tv_usec = 0;
setitimer( ITIMER_REAL, &mtimer, (struct itimerval *)0 );
setitimer( ITIMER_REAL, &mtimer, (struct itimerval *)0 );
PassiveTimer::setTiming(timeMS); // PassiveTimer-
sigset_t mask, oldmask;
sigemptyset(&mask);
sigemptyset(&mask);
//
sigaddset( &mask, SIGALRM );
sigprocmask( SIG_BLOCK, &mask, &oldmask );
sigaddset( &mask, SIGALRM );
sigprocmask( SIG_BLOCK, &mask, &oldmask );
if (timeMS == WaitUpTime)
{
while (!terminated)
......@@ -148,10 +148,10 @@ int PassiveSysTimer::wait(int timeMS)
sigsuspend( &oldmask );
terminated = 1;
sigprocmask( SIG_UNBLOCK, &mask, NULL );
sigprocmask( SIG_UNBLOCK, &mask, NULL );
// cout << "PassiveSysTimer: time ok"<< endl;
return 1;
return true;
}
// ------------------------------------------------------------------------------------------
......
......@@ -29,15 +29,22 @@
#include <unistd.h>
#include "PassiveTimer.h"
//----------------------------------------------------------------------------------------
// CLK_TCK
#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#endif
//----------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
PassiveTimer::PassiveTimer( ):
timeAct(0),
timeSS(0),
timeStart(0)
timeStart(0),
clock_ticks(sysconf(_SC_CLK_TCK))
{
clock_ticks = sysconf(_SC_CLK_TCK);
setTiming(-1);
setTiming(WaitUpTime);
}
//------------------------------------------------------------------------------
......@@ -45,65 +52,71 @@ timeStart(0)
PassiveTimer::PassiveTimer( int timeMS ):
timeAct(0),
timeSS(0),
timeStart(0)
timeStart(0),
clock_ticks(sysconf(_SC_CLK_TCK))
{
// printf("const =%d\n",timeMS);
clock_ticks = sysconf(_SC_CLK_TCK);
setTiming( timeMS );
}
//------------------------------------------------------------------------------
/*! \note timeMS<0, */
bool PassiveTimer::checkTime()
{
// printf("times=%d, act=%d\n",times(0),timeAct);
// printf("%d\n",timeSS); msleep(10);
if( timeSS<0 ) // == WaitUpTime;
return false;
if( timeSS == WaitUpTime);
return false;
if( times(0) >= timeAct )
if( times() >= timeAct )
return true;
return false;
}
//------------------------------------------------------------------------------
//
void PassiveTimer::setTiming( int timeMS )
timeout_t PassiveTimer::setTiming( timeout_t timeMS )
{
if( timeMS<0 )
if( timeMS == WaitUpTime )
{
// getCurrent()
// ӣ-
timeSS=WaitUpTime;
timeStart=times(0);
// PassiveTimer::reset();
timeSS = WaitUpTime;
}
else
{
timeSS=timeMS/10; //
if (timeMS%10)
timeSS++; //
PassiveTimer::reset();
}
PassiveTimer::reset();
return getInterval();
}
//------------------------------------------------------------------------------
//
void PassiveTimer::reset(void)
{
timeStart=times(0);
timeStart = times();
if( timeSS == WaitUpTime)
return;
timeAct = (timeSS*clock_ticks)/100 + timeStart;
}
//------------------------------------------------------------------------------
//
int PassiveTimer::getCurrent()
timeout_t PassiveTimer::getCurrent()
{
return (times(0)-timeStart)*1000/clock_ticks;
return (times()-timeStart)*1000/clock_ticks;
}
//------------------------------------------------------------------------------
void PassiveTimer::terminate()
{
timeAct = 0;
}
//------------------------------------------------------------------------------
clock_t PassiveTimer::times()
{
// Linux NULL
struct tms tm;
return ::times(&tm);
}
......@@ -129,7 +129,7 @@ Configuration::Configuration( int argc, const char** argv, const string xmlfile
_argc(argc),
_argv(argv),
NSName("NameService"),
repeatCount(2),repeatTimeout(100),
repeatCount(2),repeatTimeout(100),
localTimerService(UniSetTypes::DefaultObjectId),
localDBServer(UniSetTypes::DefaultObjectId),
localInfoServer(UniSetTypes::DefaultObjectId),
......
......@@ -88,14 +88,14 @@ int LT_Object::checkTimers( UniSetObject* obj )
//
if( !li->curTick )
{
li = tlst.erase(li);
li = tlst.erase(li);
if( tlst.empty() )
sleepTime = UniSetTimer::WaitUpTime;
continue;
}
else if(li->curTick>0 )
li->curTick--;
li->reset();
resort = true;
}
......
......@@ -35,8 +35,8 @@ using namespace UniSetTypes;
// -----------------------------------------------------------------------------
static mutex_atomic_t mutex_atomic_read( mutex_atomic_t* m ){ return (*m); }
static mutex_atomic_t mutex_atomic_set( mutex_atomic_t* m, int val ){ return (*m) = val; }
static void mutex_atomic_inc( mutex_atomic_t* m ){ (*m)++; }
static void mutex_atomic_dec( mutex_atomic_t* m ){ (*m)--; }
//static void mutex_atomic_inc( mutex_atomic_t* m ){ (*m)++; }
//static void mutex_atomic_dec( mutex_atomic_t* m ){ (*m)--; }
// -----------------------------------------------------------------------------
#ifndef HAVE_LINUX_LIBC_HEADERS_INCLUDE_LINUX_FUTEX_H
uniset_mutex::uniset_mutex():
......
......@@ -178,7 +178,7 @@ void SMonitor::sensorInfo( SensorMessage *si )
cmd << " " << si->sm_tv_sec << " " << si->sm_tv_usec;
int ret = system(cmd.str().c_str());
(void)system(cmd.str().c_str());
// if( WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
// {
// cout << "finish..." << endl;
......
......@@ -154,9 +154,10 @@ int TableStorage::addRow(char* key, char* value)
if((tbl->status==2)||(tbl->status==3)) st=2;
else st=4;
if(j==0)
if(j==0) {
if(st==2) st=4;
else st=2;
}
tbl->status=st;
strcpy(tbl->key,key);
......
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