Commit d27a9114 authored by Pavel Vainerman's avatar Pavel Vainerman

(mtr-read): Добавил утилиту чтения регистров с устройств MTR (DEIF)

parent 9e1146c5
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 1.0 Version: 1.0
Release: alt56 Release: alt57
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la ...@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la
%changelog %changelog
* Sun Nov 27 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt57
- add uniset-mtr-read utility
* Sat Nov 26 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt56 * Sat Nov 26 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt56
- (modbus): fixed bug (again) in ModbusSlave::readInputStatus(0x02) - (modbus): fixed bug (again) in ModbusSlave::readInputStatus(0x02)
......
...@@ -13,7 +13,7 @@ static void print_help() ...@@ -13,7 +13,7 @@ static void print_help()
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, const char **argv ) int main( int argc, const char **argv )
{ {
unsigned short v1 = 0; unsigned short v1 = 0;
unsigned short v2 = 0; unsigned short v2 = 0;
const char* type=""; const char* type="";
...@@ -22,11 +22,11 @@ int main( int argc, const char **argv ) ...@@ -22,11 +22,11 @@ int main( int argc, const char **argv )
{ {
print_help(); print_help();
return 1; return 1;
} }
type = argv[1]; type = argv[1];
v1 = UniSetTypes::uni_atoi(argv[2]); v1 = UniSetTypes::uni_atoi(argv[2]);
if( argc>=4 ) if( argc>=4 )
{ {
v1 = UniSetTypes::uni_atoi(argv[3]); v1 = UniSetTypes::uni_atoi(argv[3]);
...@@ -52,50 +52,64 @@ int main( int argc, const char **argv ) ...@@ -52,50 +52,64 @@ int main( int argc, const char **argv )
{ {
T3 t(v1,v2); T3 t(v1,v2);
cout << "(T3): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T3): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t << endl; << " --> " << (long)t << endl;
} }
else if( !strcmp(type,"T4") ) else if( !strcmp(type,"T4") )
{ {
T4 t(v1); T4 t(v1);
cout << "(T4): v1=" << t.raw cout << "(T4): v1=" << t.raw
<< " --> " << t << endl; << " --> " << t.sval << endl;
} }
else if( !strcmp(type,"T5") ) else if( !strcmp(type,"T5") )
{ {
T5 t(v1,v2); T5 t(v1,v2);
cout << "(T5): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T5): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t << endl; << " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
} }
else if( !strcmp(type,"T6") ) else if( !strcmp(type,"T6") )
{ {
T6 t(v1,v2); T6 t(v1,v2);
cout << "(T6): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T6): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t << endl; << " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
} }
else if( !strcmp(type,"T7") ) else if( !strcmp(type,"T7") )
{ {
T7 t(v1,v2); T7 t(v1,v2);
cout << "(T7): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T7): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
// << " --> " << T7.val << " * 10^-4" // << " --> " << T7.val << " * 10^-4"
<< " ===> " << t << endl; << " ===> " << t.val
<< " [" << ( t.raw.u2.ic == 0xFF ? "CAP" : "IND" ) << "|"
<< ( t.raw.u2.ie == 0xFF ? "EXP" : "IMP" ) << "]"
<< endl;
} }
else if( !strcmp(type,"T8") ) else if( !strcmp(type,"T8") )
{ {
T8 t(v1,v2); T8 t(v1,v2);
cout << "(T8): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T8): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << t << endl; << " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< " " << setw(2) << t.day() << "/" << setw(2) << t.mon()
<< endl;
} }
else if( !strcmp(type,"T9") ) else if( !strcmp(type,"T9") )
{ {
T9 t(v1,v2); T9 t(v1,v2);
cout << "(T9): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T9): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << t << endl; << " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< ":" << setw(2) << t.sec() << "." << setw(2) << t.ssec()
<< endl;
} }
else if( !strcmp(type,"T10") ) else if( !strcmp(type,"T10") )
{ {
T10 t(v1,v2); T10 t(v1,v2);
cout << "(T10): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1] cout << "(T10): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << t << endl; << " ===> " << setfill('0') << dec
<< setw(4) << t.year() << "/" << setw(2) << t.mon()
<< "/" << setw(2) << t.day()
<< endl;
} }
else if( !strcmp(type,"F1") ) else if( !strcmp(type,"F1") )
{ {
...@@ -103,7 +117,7 @@ int main( int argc, const char **argv ) ...@@ -103,7 +117,7 @@ int main( int argc, const char **argv )
cout << "(F1): v1=" << f.raw.v[0] << " v2=" << f.raw.v[1] cout << "(F1): v1=" << f.raw.v[0] << " v2=" << f.raw.v[1]
<< " ===> " << f.raw.val << endl; << " ===> " << f.raw.val << endl;
} }
else else
{ {
cout << " Unknown type: " << type << endl; cout << " Unknown type: " << type << endl;
return 1; return 1;
......
// --------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include "UniSetTypes.h"
#include "MTR.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace MTR;
// --------------------------------------------------------------------------
static void print_help()
{
printf("Usage: mtrconv TYPE[T1...T12,T16,T17] hex1 hex2\n");
}
// --------------------------------------------------------------------------
int main( int argc, const char **argv )
{
unsigned short v1 = 0;
unsigned short v2 = 0;
const char* type="";
if( argc<2 )
{
print_help();
return 1;
}
type = argv[1];
v1 = UniSetTypes::uni_atoi(argv[2]);
if( argc>=4 )
{
v1 = UniSetTypes::uni_atoi(argv[3]);
v2 = UniSetTypes::uni_atoi(argv[2]);
}
if( !strcmp(type,"T1") )
cout << "(T1): v1=" << v1 << " --> (unsigned) " << v1 << endl;
else if( !strcmp(type,"T2") )
cout << "(T2): v1=" << v1 << " --> (signed) " << (signed short)v1 << endl;
else if( !strcmp(type,"T16") )
{
T16 t(v1);
cout << "(T16): v1=" << t.val << " float=" << t.fval << endl;
}
else if( !strcmp(type,"T17") )
{
T17 t(v1);
cout << "(T17): v1=" << t.val << " float=" << t.fval << endl;
}
else if( !strcmp(type,"T3") )
{
T3 t(v1,v2);
cout << "(T3): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << (long)t << endl;
}
else if( !strcmp(type,"T4") )
{
T4 t(v1);
cout << "(T4): v1=" << t.raw
<< " --> " << t.sval << endl;
}
else if( !strcmp(type,"T5") )
{
T5 t(v1,v2);
cout << "(T5): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
}
else if( !strcmp(type,"T6") )
{
T6 t(v1,v2);
cout << "(T6): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
}
else if( !strcmp(type,"T7") )
{
T7 t(v1,v2);
cout << "(T7): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
// << " --> " << T7.val << " * 10^-4"
<< " ===> " << t.val
<< " [" << ( t.raw.u2.ic == 0xFF ? "CAP" : "IND" ) << "|"
<< ( t.raw.u2.ie == 0xFF ? "EXP" : "IMP" ) << "]"
<< endl;
}
else if( !strcmp(type,"T8") )
{
T8 t(v1,v2);
cout << "(T8): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< " " << setw(2) << t.day() << "/" << setw(2) << t.mon()
<< endl;
}
else if( !strcmp(type,"T9") )
{
T9 t(v1,v2);
cout << "(T9): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< ":" << setw(2) << t.sec() << "." << setw(2) << t.ssec()
<< endl;
}
else if( !strcmp(type,"T10") )
{
T10 t(v1,v2);
cout << "(T10): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << setfill('0') << dec
<< setw(4) << t.year() << "/" << setw(2) << t.mon()
<< "/" << setw(2) << t.day()
<< endl;
}
else if( !strcmp(type,"F1") )
{
F1 f(v1,v2);
cout << "(F1): v1=" << f.raw.v[0] << " v2=" << f.raw.v[1]
<< " ===> " << f.raw.val << endl;
}
else
{
cout << " Unknown type: " << type << endl;
return 1;
}
return 0;
}
// --------------------------------------------------------------------------
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