?? rs232blockframingprotocol.h
字號:
/*
* Copyright (c), Philips Semiconductors Gratkorn / Austria
*
* (C)PHILIPS Electronics N.V.2000
* All rights are reserved. Reproduction in whole or in part is
* prohibited without the written consent of the copyright owner.
* Philips reserves the right to make changes without notice at any time.
* Philips makes no warranty, expressed, implied or statutory, including but
* not limited to any implied warranty of merchantability or fitness for any
*particular purpose, or that the use will not infringe any third party patent,
* copyright or trademark. Philips must not be liable for any loss or damage
* arising from its use.
*/
/*! \file RS232BlockFramingProtocol.h
*
* Projekt: MF EV X00 Firmware
*
* $Workfile:: RS232BlockFramingProtocol.h $
* $Modtime:: 9.07.01 7:59 $
* $Author:: Hb $
* $Revision:: 2 $
*
*/
#ifndef RS232PROTOCOL3964_H
#define RS232PROTOCOL3964_H
#ifdef __cplusplus
extern "C" {
#endif
//----------------------------------------------------------------------------
// INCLUDES
//----------------------------------------------------------------------------
#include <ProtocolBase.h>
class RS232;
/// RS232 communication protocol
/*!
* \ingroup hostrdcom
* This class implements a protocol, which should be very easy to implement and
* ensures a quite save communication.
*
* The data, which should be transfered, is framed by a SOF-character, sequence
* number and two trailing CRC check bytes.
*
* The data integrity is ensured by the sequence number and the two bytes CRC.
* <ul>
* <li> SOF-character 0xA5 character to signal the start of frame
* <li> seqnr 1 byte sequence number, which is increased with every
* frame sent. The received sequence number from the reader
* has to match the sequence number sent.
* <li> cmd 1 command byte
* <li> datalen 2 length bytes with LSB first
* <li> data[0 .. datalen] data bytes
* <li> crc 16 bit CRC code LSB first
* </ul>
*
* The CRC check bytes are calculated from the whole data stream beginning with SOF
* and ending with the last data byte.
*/
class DLLEXP_IMP RS232BlockFramingProtocol
: public ProtocolBase
{
//----------------------------------------------------------------------------
// Member Functions
//----------------------------------------------------------------------------
public:
//------------------------------------------------------------------------
/// Construction with corresponding interface
RS232BlockFramingProtocol(RS232& pRI);
virtual ~RS232BlockFramingProtocol();
/// overloaded member function from <em>ProtocolBase</em>
virtual short ResetProtocol(void);
//! BUG: Wrong Operator Delete Called for Exported Class
/*!
* \name BUG: Q122675
*
* When allocating and deleting an object of a class that is exported from a DLL,
* you may find that the new operator in the EXE is called to allocate the memory but
* the delete operator in the DLL is called to delete the memory. Therefore, there is
* a new/delete mismatching problem, which may cause run-time errors.
*/
//@{
void* operator new( size_t tSize );
void operator delete( void* p );
//@}
private:
/// Default constructor - should never be called
RS232BlockFramingProtocol() {};
/// Copy constructor - should never be called
RS232BlockFramingProtocol(const RS232BlockFramingProtocol& rs232_protocol_3964) {};
/// Assignment operator - should never be called
RS232BlockFramingProtocol& operator= (const RS232BlockFramingProtocol& rs232_protocol_3964)
{return *this;};
/// overloaded member function from <em>ProtocolBase</em>
virtual short DoCommunicationWork(CommandObject& CmdObject,
unsigned long RxTimeout,
unsigned long TxTimeout);
/// Creates sendframe
/*
* \param CmdObj
* \return
*
* Puts data to right position within sendframe,
* calculates and encloses checksum
*/
short CreateSendFrame(CommandObject& CmdObj);
/// Send frame blockwise to reader
/*
* \param RxTimeout
* \param TxTimeout
* \return
*
*/
short SendData(unsigned long RxTimeout,
unsigned long TxTimeout);
/// Receive frame blockwise from reader
/*
* \param RxTimeout
* \param TxTimeout
* \return
*
*/
short RecvData(unsigned long RxTimeout,
unsigned long TxTimeout);
/// Checksum Calculation
/*!
* \param Buffer databuffer
* \param Len number of bytes
* \return CRC16 16 bit CRC code
*/
unsigned short CalcCRC(unsigned char* Buffer, unsigned short Len);
/// framing constants
enum RS_232_BLOCK_FRAMING { POS_SOF = 0,
POS_SEQNR = 1,
POS_CMD = 2,
POS_STATUS = 2,
POS_LEN = 3,
POS_DATA = 5,
HEADER = 5,
MAXDATA = 32768,
SOF_CHAR = 0xA5
};
/// CheckSum constants
enum CHECK_SUM { CRC_POLYNOM_LSB = 0x8408,
CRC_PRESET = 0xFFFF,
};
/// corresponding reader interface
RS232* m_pRs232;
/// Tx sequence number
unsigned char m_ucTxSeq;
/// Sendbuffer (block command)
unsigned char* m_ucpSendBuffer;
/// stores the length of SendBuffer
unsigned long m_ulSendBufferLength;
/// ReceiveBuffer (block response)
unsigned char* m_ucpReceiveBuffer;
//----------------------------------------------------------------------------
};
#ifdef __cplusplus
}
#endif
#endif // RS232PROTOCOL3964_H
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -