Commit 316d7772 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(modbus): make style

parent 08cccaf0
...@@ -21,146 +21,146 @@ ...@@ -21,146 +21,146 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace ModbusRTU; using namespace ModbusRTU;
using namespace uniset; using namespace uniset;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
static ComPort::Speed checkSpeed[] = static ComPort::Speed checkSpeed[] =
{ {
ComPort::ComSpeed9600, ComPort::ComSpeed9600,
ComPort::ComSpeed19200, ComPort::ComSpeed19200,
ComPort::ComSpeed38400, ComPort::ComSpeed38400,
ComPort::ComSpeed57600, ComPort::ComSpeed57600,
ComPort::ComSpeed4800, ComPort::ComSpeed4800,
ComPort::ComSpeed115200, ComPort::ComSpeed115200,
ComPort::ComSpeed0 ComPort::ComSpeed0
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusAddr ModbusHelpers::autodetectSlave( ModbusClient* m, ModbusAddr ModbusHelpers::autodetectSlave( ModbusClient* m,
ModbusAddr beg, ModbusAddr end, ModbusAddr beg, ModbusAddr end,
ModbusData reg, ModbusData reg,
SlaveFunctionCode fn ) SlaveFunctionCode fn )
{ {
if( beg > end ) if( beg > end )
{ {
ModbusAddr tmp = beg; ModbusAddr tmp = beg;
beg = end; beg = end;
end = tmp; end = tmp;
} }
for( ModbusAddr a = beg; a <= end; a++ ) for( ModbusAddr a = beg; a <= end; a++ )
{ {
try try
{ {
if( fn == fnReadInputRegisters ) if( fn == fnReadInputRegisters )
{ {
m->read04(a, reg, 1); m->read04(a, reg, 1);
} }
else if( fn == fnReadInputStatus ) else if( fn == fnReadInputStatus )
{ {
m->read02(a, reg, 1); m->read02(a, reg, 1);
} }
else if( fn == fnReadCoilStatus ) else if( fn == fnReadCoilStatus )
{ {
m->read01(a, reg, 1); m->read01(a, reg, 1);
} }
else if( fn == fnReadOutputRegisters ) else if( fn == fnReadOutputRegisters )
{ {
m->read03(a, reg, 1); m->read03(a, reg, 1);
} }
else else
throw mbException(erOperationFailed); throw mbException(erOperationFailed);
return a; return a;
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
if( ex.err < erInternalErrorCode ) if( ex.err < erInternalErrorCode )
return a; // узел ответил ошибкой (но связь то есть) return a; // узел ответил ошибкой (но связь то есть)
} }
catch(...) {} catch(...) {}
if( (beg == 0xff) || (end == 0xff) ) if( (beg == 0xff) || (end == 0xff) )
break; break;
} }
throw TimeOut(); throw TimeOut();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusAddr ModbusHelpers::autodetectSlave( std::string dev, ComPort::Speed s, int tout, ModbusAddr ModbusHelpers::autodetectSlave( std::string dev, ComPort::Speed s, int tout,
ModbusAddr beg, ModbusAddr end, ModbusAddr beg, ModbusAddr end,
ModbusData reg, ModbusData reg,
SlaveFunctionCode fn ) SlaveFunctionCode fn )
{ {
ModbusRTUMaster mb(dev); ModbusRTUMaster mb(dev);
mb.setSpeed(s); mb.setSpeed(s);
mb.setTimeout(tout); mb.setTimeout(tout);
return autodetectSlave( &mb, beg, end, reg, fn ); return autodetectSlave( &mb, beg, end, reg, fn );
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ComPort::Speed ModbusHelpers::autodetectSpeed( ModbusRTUMaster* m, ModbusAddr slave, ComPort::Speed ModbusHelpers::autodetectSpeed( ModbusRTUMaster* m, ModbusAddr slave,
ModbusData reg, SlaveFunctionCode fn ) ModbusData reg, SlaveFunctionCode fn )
{ {
ComPort::Speed cur = m->getSpeed(); ComPort::Speed cur = m->getSpeed();
ComPort::Speed s = ComPort::ComSpeed0; ComPort::Speed s = ComPort::ComSpeed0;
for( unsigned int i = 0; checkSpeed[i] != ComPort::ComSpeed0; i++ ) for( unsigned int i = 0; checkSpeed[i] != ComPort::ComSpeed0; i++ )
{ {
try try
{ {
m->setSpeed( checkSpeed[i] ); m->setSpeed( checkSpeed[i] );
if( fn == fnReadInputRegisters ) if( fn == fnReadInputRegisters )
{ {
m->read04(slave, reg, 1); m->read04(slave, reg, 1);
} }
else if( fn == fnReadInputStatus ) else if( fn == fnReadInputStatus )
{ {
m->read02(slave, reg, 1); m->read02(slave, reg, 1);
} }
else if( fn == fnReadCoilStatus ) else if( fn == fnReadCoilStatus )
{ {
m->read01(slave, reg, 1); m->read01(slave, reg, 1);
} }
else if( fn == fnReadOutputRegisters ) else if( fn == fnReadOutputRegisters )
{ {
m->read03(slave, reg, 1); m->read03(slave, reg, 1);
} }
else else
throw mbException(erOperationFailed); throw mbException(erOperationFailed);
s = checkSpeed[i]; s = checkSpeed[i];
break; break;
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
if( ex.err < erInternalErrorCode ) if( ex.err < erInternalErrorCode )
{ {
s = checkSpeed[i]; s = checkSpeed[i];
break; // узел ответил ошибкой (но связь то есть) break; // узел ответил ошибкой (но связь то есть)
} }
} }
catch(...) {} catch(...) {}
} }
m->setSpeed(cur); m->setSpeed(cur);
if( s != ComPort::ComSpeed0 ) if( s != ComPort::ComSpeed0 )
return s; return s;
throw TimeOut(); throw TimeOut();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ComPort::Speed ModbusHelpers::autodetectSpeed( std::string dev, ModbusRTU::ModbusAddr slave, int tout, ComPort::Speed ModbusHelpers::autodetectSpeed( std::string dev, ModbusRTU::ModbusAddr slave, int tout,
ModbusData reg, SlaveFunctionCode fn ) ModbusData reg, SlaveFunctionCode fn )
{ {
ModbusRTUMaster mb(dev); ModbusRTUMaster mb(dev);
mb.setTimeout(tout); mb.setTimeout(tout);
return autodetectSpeed( &mb, slave, reg, fn ); return autodetectSpeed( &mb, slave, reg, fn );
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -18,92 +18,92 @@ ...@@ -18,92 +18,92 @@
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace uniset namespace uniset
{ {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
using namespace ModbusRTU; using namespace ModbusRTU;
using namespace std; using namespace std;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusServerSlot::ModbusServerSlot() ModbusServerSlot::ModbusServerSlot()
{ {
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusServerSlot::~ModbusServerSlot() ModbusServerSlot::~ModbusServerSlot()
{ {
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectReadCoil( ReadCoilSlot sl ) void ModbusServerSlot::connectReadCoil( ReadCoilSlot sl )
{ {
slReadCoil = sl; slReadCoil = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectReadInputStatus( ReadInputStatusSlot sl ) void ModbusServerSlot::connectReadInputStatus( ReadInputStatusSlot sl )
{ {
slReadInputStatus = sl; slReadInputStatus = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectReadOutput( ReadOutputSlot sl ) void ModbusServerSlot::connectReadOutput( ReadOutputSlot sl )
{ {
slReadOutputs = sl; slReadOutputs = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectReadInput( ReadInputSlot sl ) void ModbusServerSlot::connectReadInput( ReadInputSlot sl )
{ {
slReadInputs = sl; slReadInputs = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectForceCoils( ForceCoilsSlot sl ) void ModbusServerSlot::connectForceCoils( ForceCoilsSlot sl )
{ {
slForceCoils = sl; slForceCoils = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectWriteOutput( WriteOutputSlot sl ) void ModbusServerSlot::connectWriteOutput( WriteOutputSlot sl )
{ {
slWriteOutputs = sl; slWriteOutputs = sl;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void ModbusServerSlot::connectWriteSingleOutput( WriteSingleOutputSlot sl ) void ModbusServerSlot::connectWriteSingleOutput( WriteSingleOutputSlot sl )
{ {
slWriteSingleOutputs = sl; slWriteSingleOutputs = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectDiagnostics( DiagnosticsSlot sl ) void ModbusServerSlot::connectDiagnostics( DiagnosticsSlot sl )
{ {
slDiagnostics = sl; slDiagnostics = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectMEIRDI( MEIRDISlot sl ) void ModbusServerSlot::connectMEIRDI( MEIRDISlot sl )
{ {
slMEIRDI = sl; slMEIRDI = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectForceSingleCoil( ForceSingleCoilSlot sl ) void ModbusServerSlot::connectForceSingleCoil( ForceSingleCoilSlot sl )
{ {
slForceSingleCoil = sl; slForceSingleCoil = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectJournalCommand( JournalCommandSlot sl ) void ModbusServerSlot::connectJournalCommand( JournalCommandSlot sl )
{ {
slJournalCommand = sl; slJournalCommand = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectSetDateTime( SetDateTimeSlot sl ) void ModbusServerSlot::connectSetDateTime( SetDateTimeSlot sl )
{ {
slSetDateTime = sl; slSetDateTime = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectRemoteService( RemoteServiceSlot sl ) void ModbusServerSlot::connectRemoteService( RemoteServiceSlot sl )
{ {
slRemoteService = sl; slRemoteService = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void ModbusServerSlot::connectFileTransfer( FileTransferSlot sl ) void ModbusServerSlot::connectFileTransfer( FileTransferSlot sl )
{ {
slFileTransfer = sl; slFileTransfer = sl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
} // end of namespace uniset } // end of namespace uniset
This source diff could not be displayed because it is too large. You can view the blob instead.
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