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

minor fixes in Modbus

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