23#include <unordered_map>
28#include "modbus/ModbusTypes.h"
59 std::string type2str( MTRType t );
60 MTRType str2type(
const std::string& s );
61 size_t wsize( MTRType t );
64 const ModbusRTU::ModbusData regModelNumber = 0x01;
65 const ModbusRTU::ModbusData regSerialNumber = 0x09;
71 const ModbusRTU::ModbusData regUpdateConfiguration = 53;
72 const ModbusRTU::ModbusData regAddress = 55;
73 const ModbusRTU::ModbusData regBaudRate = 56;
74 const ModbusRTU::ModbusData regStopBit = 57;
75 const ModbusRTU::ModbusData regParity = 58;
76 const ModbusRTU::ModbusData regDataBits = 59;
103 bool setAddress(
uniset::ModbusClient* mb, ModbusRTU::ModbusAddr addr, ModbusRTU::ModbusAddr newAddr );
108 ComPort::Parity get_parity( ModbusRTU::ModbusData data );
109 ComPort::Speed get_speed( ModbusRTU::ModbusData data );
119 std::ostream& operator<<(std::ostream& os, MTRError& e );
122 const std::string& mtrconfile,
int verbose = 0 );
125 typedef std::list<ModbusRTU::ModbusData> DataList;
126 typedef std::unordered_map<ModbusRTU::ModbusData, DataList> DataMap;
127 const int attempts = 3;
128 static const ModbusRTU::ModbusData skip[] = {48, 49, 59};
130 bool send_param(
uniset::ModbusClient* mb, DataMap& dmap, ModbusRTU::ModbusAddr addr,
int verb );
131 bool read_param(
const std::string& str, std::string& str1, std::string& str2 );
132 DataMap read_confile(
const std::string& f );
133 void update_communication_params( ModbusRTU::ModbusAddr reg, ModbusRTU::ModbusData data,
136 static const size_t u2size = 2;
142 T1( uint16_t v ): val(v) {}
143 T1(
const ModbusRTU::ModbusData* data ): val(data[0]) {}
159 std::ostream& operator<<(std::ostream& os, T1& t );
165 T2( int16_t v ): val(v) {}
166 T2(
const ModbusRTU::ModbusData* data ): val(data[0]) {}
182 std::ostream& operator<<(std::ostream& os, T2& t );
198 memset(raw.v, 0,
sizeof(raw.v));
206 T3( uint16_t v1, uint16_t v2 )
212 T3(
const ModbusRTU::ModbusData* data,
size_t size )
243 std::ostream& operator<<(std::ostream& os, T3& t );
250 T4(): sval(
""), raw(0) {}
251 T4( uint16_t v1 ): raw(v1)
256 sval = std::string(c);
259 T4(
const ModbusRTU::ModbusData* data ):
263 memcpy(c, &(data[0]), 2);
265 sval = std::string(c);
284 std::ostream& operator<<(std::ostream& os, T4& t );
298 } __attribute__( ( packed ) ) u2;
305 memset(raw.v, 0,
sizeof(raw.v));
307 T5( uint16_t v1, uint16_t v2 )
311 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
317 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
320 T5(
const ModbusRTU::ModbusData* data,
size_t size ): val(0)
327 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
347 std::ostream& operator<<(std::ostream& os, T5& t );
368 memset(raw.v, 0,
sizeof(raw.v));
370 T6( uint16_t v1, uint16_t v2 )
374 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
380 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
383 T6(
const ModbusRTU::ModbusData* data,
size_t size )
390 val = raw.u2.val * pow( (
long)10, (
long)raw.u2.exp );
407 double val = { 0.0 };
410 std::ostream& operator<<(std::ostream& os, T6& t );
425 } __attribute__( ( packed ) ) u2;
432 memset(raw.v, 0,
sizeof(raw.v));
434 T7( uint16_t v1, uint16_t v2 )
438 val = raw.u2.val * pow( (
long)10, (
long) - 4 );
443 val = raw.u2.val * pow( (
long)10, (
long) - 4 );
446 T7(
const ModbusRTU::ModbusData* data,
size_t size )
453 val = raw.u2.val * pow( (
long)10, (
long) - 4 );
470 double val = { 0.0 };
473 std::ostream& operator<<(std::ostream& os, T7& t );
489 } __attribute__( ( packed ) ) u2;
495 memset(raw.v, 0,
sizeof(raw.v));
497 T8( uint16_t v1, uint16_t v2 )
503 T8(
const ModbusRTU::ModbusData* data,
size_t size )
513 inline uint16_t day()
517 inline uint16_t mon()
521 inline uint16_t hour()
525 inline uint16_t min()
545 std::ostream& operator<<(std::ostream& os, T8& t );
561 } __attribute__( ( packed ) ) u2;
567 memset(raw.v, 0,
sizeof(raw.v));
569 T9( uint16_t v1, uint16_t v2 )
575 T9(
const ModbusRTU::ModbusData* data,
size_t size )
585 inline uint16_t hour()
589 inline uint16_t min()
593 inline uint16_t sec()
597 inline uint16_t ssec()
617 std::ostream& operator<<(std::ostream& os, T9& t );
632 } __attribute__( ( packed ) ) u2;
638 memset(raw.v, 0,
sizeof(raw.v));
640 T10( uint16_t v1, uint16_t v2 )
646 T10(
const ModbusRTU::ModbusData* data,
size_t size )
656 inline uint16_t year()
660 inline uint16_t mon()
664 inline uint16_t day()
684 std::ostream& operator<<(std::ostream& os, T10& t );
691 T16( uint16_t v ): val(v)
693 fval = (float)(val) / 100.0;
695 T16(
const ModbusRTU::ModbusData* data ): val(data[0])
697 fval = (float)(val) / 100.0;
699 T16(
float f ): fval(f)
701 val = lroundf(fval * 100);
726 uint16_t val = { 0 };
727 float fval = { 0.0 };
729 std::ostream& operator<<(std::ostream& os, T16& t );
735 T17( int16_t v ): val(v)
737 fval = (float)(v) / 100.0;
739 T17( uint16_t v ): val(v)
741 fval = (float)( (int16_t)(v) ) / 100.0;
744 T17(
const ModbusRTU::ModbusData* data ): val(data[0])
746 fval = (float)(val) / 100.0;
748 T17(
float f ): fval(f)
750 val = lroundf(fval * 100);
777 std::ostream& operator<<(std::ostream& os, T17& t );
793 memset(raw.v, 0,
sizeof(raw.v));
795 F1( uint16_t v1, uint16_t v2 )
806 F1(
const ModbusRTU::ModbusData* data,
size_t size )
835 return lroundf(raw.val);
840 std::ostream& operator<<(std::ostream& os, F1& t );
851 ModbusRTU::ModbusData data[8];
853 for(
int i = 0; i < 8; i++ )
854 data[i] = ModbusRTU::SWAPSHORT(ret.data[i]);
856 memcpy(c, &data, 16);
858 sval = std::string(c);
876 std::ostream& operator<<(std::ostream& os, T_Str16& t );
888 ModbusRTU::ModbusData data[4];
890 for(
int i = 0; i < 4; i++ )
891 data[i] = ModbusRTU::SWAPSHORT(ret.data[i]);
895 sval = std::string(c);
913 std::ostream& operator<<(std::ostream& os, T_Str8& t );
static size_t wsize()
Definition MTR.h:819
static MTRType type()
Definition MTR.h:824
static MTRType type()
Definition MTR.h:677
static size_t wsize()
Definition MTR.h:672
static MTRType type()
Definition MTR.h:712
static size_t wsize()
Definition MTR.h:707
static size_t wsize()
Definition MTR.h:755
static MTRType type()
Definition MTR.h:760
static size_t wsize()
Definition MTR.h:147
static MTRType type()
Definition MTR.h:152
static size_t wsize()
Definition MTR.h:170
static MTRType type()
Definition MTR.h:175
static MTRType type()
Definition MTR.h:230
static size_t wsize()
Definition MTR.h:225
static MTRType type()
Definition MTR.h:276
static size_t wsize()
Definition MTR.h:271
static size_t wsize()
Definition MTR.h:334
static MTRType type()
Definition MTR.h:339
static MTRType type()
Definition MTR.h:402
static size_t wsize()
Definition MTR.h:397
static size_t wsize()
Definition MTR.h:460
static MTRType type()
Definition MTR.h:465
static size_t wsize()
Definition MTR.h:533
static MTRType type()
Definition MTR.h:538
static MTRType type()
Definition MTR.h:610
static size_t wsize()
Definition MTR.h:605
static size_t wsize()
Definition MTR.h:864
static MTRType type()
Definition MTR.h:869
static size_t wsize()
Definition MTR.h:901
static MTRType type()
Definition MTR.h:906
Definition ModbusClient.h:19
Definition Calibration.h:27