Commit 89118bca authored by Pavel Vainerman's avatar Pavel Vainerman

minor fixes in Modbus

parent 4e1bea37
......@@ -25,4 +25,8 @@
----------
smonit: processing "precision"
admin: processing "precision"
\ No newline at end of file
admin: processing "precision"
Встроить в SM возможность заказать переодичность уведомления по аналоговым
(или любым) датчикам.
\ No newline at end of file
......@@ -57,9 +57,8 @@ namespace ModbusRTU
};
const unsigned char MBErrMask = 0x80;
// ---------------------------------------------------------------------
static unsigned short SWAPSHORT(unsigned short x) { return ((((x)>>8)&0xff)|(((x)<<8)&0xff00)); }
unsigned short SWAPSHORT(unsigned short x);
// ---------------------------------------------------------------------
/*! ޣ */
ModbusCRC checkCRC( ModbusByte* start, int len );
......@@ -514,15 +513,17 @@ namespace ModbusRTU
void clear();
/*! */
inline bool isFull()
inline bool isFull()
{
return ( count*sizeof(ModbusData) >= MAXLENPACKET );
}
void swapData();
/*! ( ) */
int szData();
/*! */
/*! */
ModbusMessage transport_msg();
// modbus
......
......@@ -11,7 +11,7 @@
using namespace ModbusRTU;
using namespace std;
// -------------------------------------------------------------------------
#define SWAPSHORT(x) ((((x)>>8)&0xff)|(((x)<<8)&0xff00))
//#define SWAPSHORT(x) ((((x)>>8)&0xff)|(((x)<<8)&0xff00))
// -------------------------------------------------------------------------
#define USE_CRC_TAB 1 // ޣ
// -------------------------------------------------------------------------
......
......@@ -13,6 +13,13 @@ using namespace std;
// -------------------------------------------------------------------------
#define USE_CRC_TAB 1 // ޣ
// -------------------------------------------------------------------------
unsigned short ModbusRTU::SWAPSHORT( unsigned short x )
{
return ((((x)>>8)&0xff)|(((x)<<8)&0xff00));
}
// -------------------------------------------------------------------------
// Lav: , .
#ifdef USE_CRC_TAB
......@@ -1099,12 +1106,18 @@ void ReadInputRetMessage::init( ModbusMessage& m )
memcpy(&data,&(m.data[1]),bcnt);
//
for( unsigned int i=0; i<cnt; i++ )
data[i] = SWAPSHORT(data[i]);
swapData();
memcpy(&crc,&(m.data[bcnt+1]),szCRC);
}
// -------------------------------------------------------------------------
void ReadInputRetMessage::swapData()
{
//
for( unsigned int i=0; i<count; i++ )
data[i] = SWAPSHORT(data[i]);
}
// -------------------------------------------------------------------------
int ReadInputRetMessage::getDataLen( ModbusMessage& m )
{
if( m.len < 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