Commit 214d41a4 authored by Pavel Vainerman's avatar Pavel Vainerman

Добавил новые типы данные (vtype): F2r, I2r, U2r с обратным(reverse)

порядком слов.
parent 0723dd05
......@@ -8,7 +8,7 @@
Name: libuniset
Version: 1.7
Release: alt9
Release: alt10
Summary: UniSet - library for building distributed industrial control systems
......@@ -335,6 +335,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Tue Apr 01 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt10
- add new vtype: F2r, I2r, U2r (reverse data order)
* Wed Mar 19 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt9
- add thresholds processing for ModbusMaster (TCP and RTU)
- minor fixes
......
......@@ -733,6 +733,11 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
VTypes::F2 f(data,VTypes::F2::wsize());
IOBase::processingFasAI( p, (float)f, shm, true );
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f(data,VTypes::F2r::wsize());
IOBase::processingFasAI( p, (float)f, shm, true );
}
else if( p->vType == VTypes::vtF4 )
{
VTypes::F4 f(data,VTypes::F4::wsize());
......@@ -743,11 +748,21 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
VTypes::I2 i2(data,VTypes::I2::wsize());
IOBase::processingAsAI( p, (int)i2, shm, true );
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(data,VTypes::I2::wsize());
IOBase::processingAsAI( p, (int)i2, shm, true );
}
else if( p->vType == VTypes::vtU2 )
{
VTypes::U2 u2(data,VTypes::U2::wsize());
IOBase::processingAsAI( p, (unsigned int)u2, shm, true );
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(data,VTypes::U2::wsize());
IOBase::processingAsAI( p, (unsigned int)u2, shm, true );
}
return true;
}
......@@ -1265,7 +1280,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
return;
}
else if( p->vType == VTypes::vtF2 )
else if( p->vType == VTypes::vtF2 || p->vType == VTypes::vtF2r )
{
RegMap::iterator i(p->reg->rit);
if( save )
......@@ -1273,9 +1288,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK )
{
float f = IOBase::processingFasAO( p, shm, force_out );
VTypes::F2 f2(f);
for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
if( p->vType == VTypes::vtF2 )
{
VTypes::F2 f2(f);
for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f2(f);
for( int k=0; k<VTypes::F2r::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
}
r->sm_initOK = true;
}
......@@ -1285,11 +1309,22 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[VTypes::F2::wsize()];
for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
data[k] = i->second->mbval;
VTypes::F2 f(data,VTypes::F2::wsize());
float f=0;
if( p->vType == VTypes::vtF2 )
{
VTypes::F2 f1(data,VTypes::F2::wsize());
f = (float)f1;
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f1(data,VTypes::F2r::wsize());
f = (float)f1;
}
delete[] data;
IOBase::processingFasAI( p, (float)f, shm, force );
IOBase::processingFasAI( p, f, shm, force );
}
}
else if( p->vType == VTypes::vtF4 )
......@@ -1317,7 +1352,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
IOBase::processingFasAI( p, (float)f, shm, force );
}
}
else if( p->vType == VTypes::vtI2 )
else if( p->vType == VTypes::vtI2 || p->vType == VTypes::vtI2r )
{
RegMap::iterator i(p->reg->rit);
if( save )
......@@ -1325,10 +1360,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK )
{
long v = IOBase::processingAsAO( p, shm, force_out );
VTypes::I2 i2(v);
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
i->second->mbval = i2.raw.v[k];
if( p->vType == VTypes::vtI2 )
{
VTypes::I2 i2(v);
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
i->second->mbval = i2.raw.v[k];
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(v);
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
i->second->mbval = i2.raw.v[k];
}
r->sm_initOK = true;
}
}
......@@ -1338,13 +1381,23 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
data[k] = i->second->mbval;
VTypes::I2 i2(data,VTypes::I2::wsize());
int v = 0;
if( p->vType == VTypes::vtI2 )
{
VTypes::I2 i2(data,VTypes::I2::wsize());
v = (int)i2;
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(data,VTypes::I2::wsize());
v = (int)i2;
}
delete[] data;
IOBase::processingAsAI( p, (int)i2, shm, force );
IOBase::processingAsAI( p, v, shm, force );
}
}
else if( p->vType == VTypes::vtU2 )
else if( p->vType == VTypes::vtU2 || p->vType == VTypes::vtU2r )
{
RegMap::iterator i(p->reg->rit);
if( save )
......@@ -1352,9 +1405,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK )
{
long v = IOBase::processingAsAO( p, shm, force_out );
VTypes::U2 u2(v);
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
i->second->mbval = u2.raw.v[k];
if( p->vType == VTypes::vtU2 )
{
VTypes::U2 u2(v);
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
i->second->mbval = u2.raw.v[k];
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(v);
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
i->second->mbval = u2.raw.v[k];
}
r->sm_initOK = true;
}
......@@ -1365,16 +1427,26 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
data[k] = i->second->mbval;
VTypes::U2 u2(data,VTypes::U2::wsize());
unsigned int v = 0;
if( p->vType == VTypes::vtU2 )
{
VTypes::U2 u2(data,VTypes::U2::wsize());
v = (unsigned int)u2;
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(data,VTypes::U2::wsize());
v = (unsigned int)u2;
}
delete[] data;
IOBase::processingAsAI( p, (unsigned int)u2, shm, force );
IOBase::processingAsAI( p, v, shm, force );
}
}
return;
}
catch(IOController_i::NameNotFound &ex)
catch(IOController_i::NameNotFound& ex)
{
dlog[Debug::LEVEL3] << myname << "(updateRSProperty):(NameNotFound) " << ex.err << endl;
}
......
......@@ -9,11 +9,11 @@ using namespace VTypes;
// --------------------------------------------------------------------------
static void print_help()
{
printf("Usage: vtconv TYPE[F2|F4|I2|U2] hex1 hex2 [hex3 hex4]\n");
printf("Usage: vtconv TYPE[F2|F2r|F4|I2|U2|I2r|U2r] hex1 hex2 [hex3 hex4]\n");
}
// --------------------------------------------------------------------------
int main( int argc, const char **argv )
{
{
/*
VTypes::F2 f2;
f2.raw.val = 2.345;
......@@ -89,6 +89,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F2r") )
{
VTypes::F2r f(v,sizeof(v));
cout << "(F2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F4") )
{
VTypes::F4 f(v,sizeof(v));
......@@ -105,6 +112,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl;
}
else if( !strcmp(type,"I2r") )
{
VTypes::I2r i(v,sizeof(v));
cout << "(I2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl;
}
else if( !strcmp(type,"U2") )
{
VTypes::U2 i(v,sizeof(v));
......@@ -112,6 +126,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl;
}
else if( !strcmp(type,"U2r") )
{
VTypes::U2r i(v,sizeof(v));
cout << "(U2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl;
}
else
{
cout << " Unknown type: " << type << endl;
......
......@@ -1287,7 +1287,7 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
{
val = IOBase::processingAsAO(p,shm,force);
}
if( p->vtype == VTypes::vtF2 )
else if( p->vtype == VTypes::vtF2 )
{
float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2 f2(f);
......@@ -1297,6 +1297,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtF2r )
{
float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2r f2(f);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtF4 )
{
float f = IOBase::processingFasAO(p,shm,force);
......@@ -1317,6 +1327,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtI2r )
{
long v = IOBase::processingAsAO(p,shm,force);
VTypes::I2r i2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtU2 )
{
unsigned long v = IOBase::processingAsAO(p,shm,force);
......@@ -1327,6 +1347,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtU2r )
{
unsigned long v = IOBase::processingAsAO(p,shm,force);
VTypes::U2r u2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum];
}
else
val = IOBase::processingAsAO(p,shm,force);
}
......
......@@ -16,12 +16,15 @@ namespace VTypes
{
vtUnknown,
vtF2, /*!< двойное слово float(4 байта). В виде строки задаётся как \b "F2". */
vtF2r, /*!< двойное слово float(4 байта). С перевёрнутой (reverse) последовательностью слов. \b "F2r". */
vtF4, /*!< 8-х байтовое слово (double). В виде строки задаётся как \b "F4". */
vtByte, /*!< байт. В виде строки задаётся как \b "byte". */
vtUnsigned, /*!< беззнаковое целое (2 байта). В виде строки задаётся как \b "unsigned". */
vtSigned, /*!< знаковое целое (2 байта). В виде строки задаётся как \b "signed". */
vtI2, /*!< целое (4 байта). В виде строки задаётся как \b "I2".*/
vtU2 /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/
vtI2r, /*!< целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "I2r".*/
vtU2, /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/
vtU2r /*!< беззнаковое целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "U2r".*/
};
std::ostream& operator<<( std::ostream& os, const VType& vt );
......@@ -67,6 +70,24 @@ namespace VTypes
F2mem raw;
};
// --------------------------------------------------------------------------
class F2r:
public F2
{
public:
// ------------------------------------------
// конструкторы на разные случаи...
F2r(){}
F2r( float f ):F2(f){}
F2r( const ModbusRTU::ModbusData* data, int size ):F2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~F2r(){}
};
// --------------------------------------------------------------------------
class F4
{
public:
......@@ -239,6 +260,21 @@ namespace VTypes
I2mem raw;
};
// --------------------------------------------------------------------------
class I2r:
public I2
{
public:
I2r(){}
I2r( int v ):I2(v){}
I2r( const ModbusRTU::ModbusData* data, int size ):I2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~I2r(){}
};
// --------------------------------------------------------------------------
class U2
{
public:
......@@ -274,6 +310,21 @@ namespace VTypes
U2mem raw;
};
// --------------------------------------------------------------------------
class U2r:
public U2
{
public:
U2r(){}
U2r( int v ):U2(v){}
U2r( const ModbusRTU::ModbusData* data, int size ):U2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~U2r(){}
};
// --------------------------------------------------------------------------
} // end of namespace VTypes
// --------------------------------------------------------------------------
......
......@@ -18,6 +18,8 @@ VType str2type( const std::string& s )
return vtByte;
if( s == "F2" || s == "f2" )
return vtF2;
if( s == "F2r" || s == "f2r" )
return vtF2r;
if( s == "F4" || s == "f4" )
return vtF4;
if( s == "Unsigned" || s == "unsigned" )
......@@ -26,8 +28,12 @@ VType str2type( const std::string& s )
return vtSigned;
if( s == "I2" || s == "i2" )
return vtI2;
if( s == "I2r" || s == "i2r" )
return vtI2r;
if( s == "U2" || s == "u2" )
return vtU2;
if( s == "U2r" || s == "u2r" )
return vtU2r;
return vtUnknown;
}
......@@ -38,6 +44,8 @@ string type2str( VType t )
return "Byte";
if( t == vtF2 )
return "F2";
if( t == vtF2r )
return "F2r";
if( t == vtF4 )
return "F4";
if( t == vtUnsigned )
......@@ -46,8 +54,12 @@ string type2str( VType t )
return "Signed";
if( t == vtI2 )
return "I2";
if( t == vtI2r )
return "I2r";
if( t == vtU2 )
return "U2";
if( t == vtU2r )
return "U2r";
return "vtUnknown";
}
......@@ -56,7 +68,7 @@ int wsize( VType t )
{
if( t == vtByte )
return Byte::wsize();
if( t == vtF2 )
if( t == vtF2 || t == vtF2r )
return F2::wsize();
if( t == vtF4 )
return F4::wsize();
......@@ -64,9 +76,9 @@ int wsize( VType t )
return Unsigned::wsize();
if( t == vtSigned )
return Signed::wsize();
if( t == vtI2 )
if( t == vtI2 || t == vtI2r )
return I2::wsize();
if( t == vtU2 )
if( t == vtU2 || t == vtU2r )
return U2::wsize();
return 1;
......
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