Commit ca49444d authored by Pavel Vainerman's avatar Pavel Vainerman

MBTCPMaster: добавил работу с MTR (перенёс из RTUExchange)

parent c4b4043b
...@@ -284,7 +284,7 @@ void MBTCPMaster::poll() ...@@ -284,7 +284,7 @@ void MBTCPMaster::poll()
{ {
try try
{ {
if( d->dtype==MBTCPMaster::dtRTU ) if( d->dtype==MBTCPMaster::dtRTU || d->dtype==MBTCPMaster::dtMTR )
{ {
pollRTU(d,it); pollRTU(d,it);
} }
...@@ -606,6 +606,8 @@ void MBTCPMaster::updateSM() ...@@ -606,6 +606,8 @@ void MBTCPMaster::updateSM()
{ {
if( d->dtype == dtRTU ) if( d->dtype == dtRTU )
updateRTU(it); updateRTU(it);
else if( d->dtype == dtMTR )
updateMTR(it);
} }
catch(IOController_i::NameNotFound &ex) catch(IOController_i::NameNotFound &ex)
{ {
...@@ -1179,6 +1181,13 @@ bool MBTCPMaster::initRegInfo( RegInfo* r, UniXML_iterator& it, MBTCPMaster::RT ...@@ -1179,6 +1181,13 @@ bool MBTCPMaster::initRegInfo( RegInfo* r, UniXML_iterator& it, MBTCPMaster::RT
<< "' for " << it.getProp("name") << endl; << "' for " << it.getProp("name") << endl;
return false; return false;
} }
else if( dev->dtype == MBTCPMaster::dtMTR )
{
// only for MTR
if( !initMTRitem(it,r) )
return false;
}
if( mbregFromID ) if( mbregFromID )
{ {
...@@ -1232,6 +1241,9 @@ MBTCPMaster::DeviceType MBTCPMaster::getDeviceType( const std::string dtype ) ...@@ -1232,6 +1241,9 @@ MBTCPMaster::DeviceType MBTCPMaster::getDeviceType( const std::string dtype )
if( dtype.empty() ) if( dtype.empty() )
return dtUnknown; return dtUnknown;
if( dtype == "mtr" || dtype == "MTR" )
return dtMTR;
if( dtype == "rtu" || dtype == "RTU" ) if( dtype == "rtu" || dtype == "RTU" )
return dtRTU; return dtRTU;
...@@ -1301,6 +1313,16 @@ bool MBTCPMaster::initItem( UniXML_iterator& it ) ...@@ -1301,6 +1313,16 @@ bool MBTCPMaster::initItem( UniXML_iterator& it )
RegInfo* ri = addReg(dev->regmap,mbreg,it,dev); RegInfo* ri = addReg(dev->regmap,mbreg,it,dev);
if( dev->dtype == dtMTR )
{
p.rnum = MTR::wsize(ri->mtrType);
if( p.rnum <= 0 )
{
dlog[Debug::CRIT] << myname << "(initItem): unknown word size for " << it.getProp("name") << endl;
return false;
}
}
if( !ri ) if( !ri )
return false; return false;
...@@ -1359,7 +1381,21 @@ bool MBTCPMaster::initItem( UniXML_iterator& it ) ...@@ -1359,7 +1381,21 @@ bool MBTCPMaster::initItem( UniXML_iterator& it )
return true; return true;
} }
// ------------------------------------------------------------------------------------------
bool MBTCPMaster::initMTRitem( UniXML_iterator& it, RegInfo* p )
{
p->mtrType = MTR::str2type(it.getProp("mtrtype"));
if( p->mtrType == MTR::mtUnknown )
{
dlog[Debug::CRIT] << myname << "(readMTRItem): Unknown mtrtype '"
<< it.getProp("mtrtype")
<< "' for " << it.getProp("name") << endl;
return false;
}
return true;
}
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void MBTCPMaster::initIterators() void MBTCPMaster::initIterators()
{ {
...@@ -1425,6 +1461,10 @@ std::ostream& operator<<( std::ostream& os, const MBTCPMaster::DeviceType& dt ) ...@@ -1425,6 +1461,10 @@ std::ostream& operator<<( std::ostream& os, const MBTCPMaster::DeviceType& dt )
os << "RTU"; os << "RTU";
break; break;
case MBTCPMaster::dtMTR:
os << "MTR";
break;
default: default:
os << "Unknown device type (" << (int)dt << ")"; os << "Unknown device type (" << (int)dt << ")";
break; break;
...@@ -1554,6 +1594,7 @@ std::ostream& operator<<( std::ostream& os, MBTCPMaster::RegInfo& r ) ...@@ -1554,6 +1594,7 @@ std::ostream& operator<<( std::ostream& os, MBTCPMaster::RegInfo& r )
<< " q_num=" << r.q_num << " q_num=" << r.q_num
<< " q_count=" << r.q_count << " q_count=" << r.q_count
<< " value=" << ModbusRTU::dat2str(r.mbval) << "(" << (int)r.mbval << ")" << " value=" << ModbusRTU::dat2str(r.mbval) << "(" << (int)r.mbval << ")"
<< " mtrType=" << MTR::type2str(r.mtrType)
<< endl; << endl;
for( MBTCPMaster::PList::iterator it=r.slst.begin(); it!=r.slst.end(); ++it ) for( MBTCPMaster::PList::iterator it=r.slst.begin(); it!=r.slst.end(); ++it )
...@@ -1862,6 +1903,200 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1862,6 +1903,200 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only )
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::updateMTR( RegMap::iterator& rit )
{
RegInfo* r(rit->second);
using namespace ModbusRTU;
bool save = isWriteFunction( r->mbfunc );
{
for( PList::iterator it=r->slst.begin(); it!=r->slst.end(); ++it )
{
try
{
if( r->mtrType == MTR::mtT1 )
{
if( save )
r->mbval = IOBase::processingAsAO( &(*it), shm, force_out );
else
{
MTR::T1 t(r->mbval);
IOBase::processingAsAI( &(*it), t.val, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT2 )
{
if( save )
{
MTR::T2 t(IOBase::processingAsAO( &(*it), shm, force_out ));
r->mbval = t.val;
}
else
{
MTR::T2 t(r->mbval);
IOBase::processingAsAI( &(*it), t.val, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT3 )
{
RegMap::iterator i(rit);
if( save )
{
MTR::T3 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T3::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
else
{
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[MTR::T3::wsize()];
for( int k=0; k<MTR::T3::wsize(); k++, i++ )
data[k] = i->second->mbval;
MTR::T3 t(data,MTR::T3::wsize());
delete[] data;
IOBase::processingAsAI( &(*it), (long)t, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT4 )
{
if( save )
cerr << myname << "(updateMTR): write (T4) reg(" << dat2str(r->mbreg) << ") to MTR NOT YET!!!" << endl;
else
{
MTR::T4 t(r->mbval);
IOBase::processingAsAI( &(*it), uni_atoi(t.sval), shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT5 )
{
RegMap::iterator i(rit);
if( save )
{
MTR::T5 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T5::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
else
{
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[MTR::T5::wsize()];
for( int k=0; k<MTR::T5::wsize(); k++, i++ )
data[k] = i->second->mbval;
MTR::T5 t(data,MTR::T5::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT6 )
{
RegMap::iterator i(rit);
if( save )
{
MTR::T6 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T6::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
else
{
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[MTR::T6::wsize()];
for( int k=0; k<MTR::T6::wsize(); k++, i++ )
data[k] = i->second->mbval;
MTR::T6 t(data,MTR::T6::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtT7 )
{
RegMap::iterator i(rit);
if( save )
{
MTR::T7 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T7::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
else
{
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[MTR::T7::wsize()];
for( int k=0; k<MTR::T7::wsize(); k++, i++ )
data[k] = i->second->mbval;
MTR::T7 t(data,MTR::T7::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
}
continue;
}
if( r->mtrType == MTR::mtF1 )
{
RegMap::iterator i(rit);
if( save )
{
float f = IOBase::processingFasAO( &(*it), shm, force_out );
MTR::F1 f1(f);
for( int k=0; k<MTR::F1::wsize(); k++, i++ )
i->second->mbval = f1.raw.v[k];
}
else
{
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[MTR::F1::wsize()];
for( int k=0; k<MTR::F1::wsize(); k++, i++ )
data[k] = i->second->mbval;
MTR::F1 t(data,MTR::F1::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)t, shm, force );
}
continue;
}
}
catch(IOController_i::NameNotFound &ex)
{
dlog[Debug::LEVEL3] << myname << "(updateMTR):(NameNotFound) " << ex.err << endl;
}
catch(IOController_i::IOBadParam& ex )
{
dlog[Debug::LEVEL3] << myname << "(updateMTR):(IOBadParam) " << ex.err << endl;
}
catch(IONotifyController_i::BadRange )
{
dlog[Debug::LEVEL3] << myname << "(updateMTR): (BadRange)..." << endl;
}
catch( Exception& ex )
{
dlog[Debug::LEVEL3] << myname << "(updateMTR): " << ex << endl;
}
catch(CORBA::SystemException& ex)
{
dlog[Debug::LEVEL3] << myname << "(updateMTR): CORBA::SystemException: "
<< ex.NP_minorString() << endl;
}
catch(...)
{
dlog[Debug::LEVEL3] << myname << "(updateMTR): catch ..." << endl;
}
}
}
}
// -----------------------------------------------------------------------------
void MBTCPMaster::execute() void MBTCPMaster::execute()
{ {
no_extimer = true; no_extimer = true;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "SharedMemory.h" #include "SharedMemory.h"
#include "IOBase.h" #include "IOBase.h"
#include "VTypes.h" #include "VTypes.h"
#include "MTR.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! /*!
\page page_ModbusTCP Реализация ModbusTCP master \page page_ModbusTCP Реализация ModbusTCP master
...@@ -180,7 +181,8 @@ class MBTCPMaster: ...@@ -180,7 +181,8 @@ class MBTCPMaster:
enum DeviceType enum DeviceType
{ {
dtUnknown, /*!< неизвестный */ dtUnknown, /*!< неизвестный */
dtRTU /*!< RTU (default) */ dtRTU, /*!< RTU (default) */
dtMTR /*!< MTR (DEIF) */
}; };
static DeviceType getDeviceType( const std::string dtype ); static DeviceType getDeviceType( const std::string dtype );
...@@ -216,7 +218,7 @@ class MBTCPMaster: ...@@ -216,7 +218,7 @@ class MBTCPMaster:
{ {
RegInfo(): RegInfo():
mbval(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown), mbval(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown),
dev(0),offset(0), dev(0),offset(0),mtrType(MTR::mtUnknown),
q_num(0),q_count(1),mb_init(false),sm_init(false), q_num(0),q_count(1),mb_init(false),sm_init(false),
mb_init_mbreg(0) mb_init_mbreg(0)
{} {}
...@@ -230,9 +232,12 @@ class MBTCPMaster: ...@@ -230,9 +232,12 @@ class MBTCPMaster:
int offset; int offset;
// only for MTR
MTR::MTRType mtrType; /*!< тип регистра (согласно спецификации на MTR) */
// optimization // optimization
int q_num; /*! number in query */ int q_num; /*!< number in query */
int q_count; /*! count registers for query */ int q_count; /*!< count registers for query */
RegMap::iterator rit; RegMap::iterator rit;
bool mb_init; /*!< init before use */ bool mb_init; /*!< init before use */
...@@ -309,6 +314,7 @@ class MBTCPMaster: ...@@ -309,6 +314,7 @@ class MBTCPMaster:
void updateSM(); void updateSM();
void updateRTU(RegMap::iterator& it); void updateRTU(RegMap::iterator& it);
void updateMTR(RegMap::iterator& it);
void updateRSProperty( RSProperty* p, bool write_only=false ); void updateRSProperty( RSProperty* p, bool write_only=false );
virtual void processingMessage( UniSetTypes::VoidMessage *msg ); virtual void processingMessage( UniSetTypes::VoidMessage *msg );
...@@ -337,6 +343,7 @@ class MBTCPMaster: ...@@ -337,6 +343,7 @@ class MBTCPMaster:
RTUDevice* dev, RegInfo* rcopy=0 ); RTUDevice* dev, RegInfo* rcopy=0 );
RSProperty* addProp( PList& plist, RSProperty& p ); RSProperty* addProp( PList& plist, RSProperty& p );
bool initMTRitem( UniXML_iterator& it, RegInfo* p );
bool initRSProperty( RSProperty& p, UniXML_iterator& it ); bool initRSProperty( RSProperty& p, UniXML_iterator& it );
bool initRegInfo( RegInfo* r, UniXML_iterator& it, RTUDevice* dev ); bool initRegInfo( RegInfo* r, UniXML_iterator& it, RTUDevice* dev );
bool initRTUDevice( RTUDevice* d, UniXML_iterator& it ); bool initRTUDevice( RTUDevice* d, UniXML_iterator& it );
......
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