⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbprotocol.h

📁 an example of programming philips pegoda reader
💻 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 USBProtocol.h
*
* Projekt: MF EV X00 Firmware
*
* $Workfile:: USBProtocol.h                                       $ 
* $Modtime:: 10.07.01 8:00                                              $ 
* $Author:: Hb                                                          $
* $Revision:: 11                                                        $
*
*/
#ifndef USBPROTOCOL_H
#define USBPROTOCOL_H

#ifdef __cplusplus
extern "C" {
#endif

//----------------------------------------------------------------------------
// INCLUDES
//----------------------------------------------------------------------------
#include <ProtocolBase.h>

class USB;

/// USB communication protocol
/*!
* \ingroup hostrdcom
* USB supports a very high level protocol, which makes additional data integrity
* checks unnecessary.
*
* This is the reason why the implemented protocol does not contain any check bytes.
* Only a sequence number is provided, in order to ensure the correct association
* between send and receive packet. The sequence number is value between 0 and 255 
* and is generated by the host. The reader simply returns the number in the receive
* frame. If send and receive sequence number does not match, a serious communication
* error occured.
*
* Send frame: 
*
* <ul>
*  <li> seq        sequence number
*  <li> cmd        command identifier
*  <li> len0       least significant byte of the number of data bytes
*  <li> len1       most significant byte of the number of data bytes
*  <li> data0      first data byte
*  <li> :
*  <li> dataN      last data byte
* </ul>
*
* Receive frame:
*
* <ul>
*  <li> seq        sequence number
*  <li> status     status byte of the command
*  <li> len0       least significant byte of the number of data bytes
*  <li> len1       most significant byte of the number of data bytes
*  <li> data0      first data byte
*  <li> :
*  <li> dataN      last data byte
* </ul>
*/
class DLLEXP_IMP USBProtocol 
: public ProtocolBase
{
public:
    
    /// Construction, destruction
    //@{
    USBProtocol(USB& pRI);
    virtual ~USBProtocol();
    //@}

    /// Reset protocol to default values
    /*!
    * \param none
    * \return
    *
    */
    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
    USBProtocol() {};

    // Copy constructor
    USBProtocol(const USBProtocol& usb_protocol) {};

    // Assignment operator
    USBProtocol& operator= (const USBProtocol& usb_protocol)
                 { return *this;};

    /// Overloaded member function from ProtocolBase
    /*!
    * \param CmdObject (<EM>IN</EM>)
    *                  Command object, where the transmit/receive data is handled
    * \param RxTimeout (<EM>IN</EM>) default 0\n
    *                  If a value larger than 0 is provided, this parameter overrides 
    *                  the globally set Rx-Timeout
    *                  periode. 
    * \param TxTimeout (<EM>IN</EM>) default 0\n
    *                  If a value larger than 0 is provided, this parameter overrides 
    *                  the globally set Tx-Timeout
    *                  periode. 
    * \return
    */
    virtual short DoCommunicationWork(CommandObject& CmdObject, 
                                      unsigned long RxTimeout,
                                      unsigned long TxTimeout);

    /// Creates send frame 
    /*!
    * \param CmdObj (<EM>IN</EM>) 
    *               Command Object
    * \return <ul>
    *          <li> COM_SUCCESS
    *          <li> COM_NEW_FAILED
    *         </ul>
    *
    * Puts data to right position within sendframe,
    * calculates and encloses checksum
    */
    short CreateSendFrame(CommandObject& CmdObj);

    /// Send frame to reader
    /*!
    * \param TxTimeout (<EM>IN</EM>)
    *                  send timeout periode in [ms]
    *                  If the value is larger than 0, this parameter
    *                  overrides the global timeout periode.
    * \return <ul>
    *          <li>
    *         </ul>
    *
    */
    short SendData(unsigned long TxTimeout);

    /// Receive frame from reader
    /*!
    * \param RxTimeout (<EM>IN</EM>)
    *                  timeout periode in [ms]
    *                  If the value is larger than 0, this parameter
    *                  overrides the global timeout periode.
    * \return <ul>
    *          <li> COM_USB_LEN_ERR
    *          <li> COM_USB_TX_RX_SEQ_ERR
    *         </ul>
    */
    short RecvData(unsigned long RxTimeout);
      

    // Default values for RS232Protocol3964 after startup
    enum USB_PROTOCOL           { POS_SEQNR         = 0,
                                  POS_CMD           = 1,
                                  POS_STATUS        = 1,
                                  POS_LEN           = 2,
                                  POS_DATA          = 4,
                                  HEADER            = 4,
                                  MAXDATA           = 32737
                                };

    // corresponding reader interface
    USB*        m_pUSB;

    // Tx sequence number
    volatile unsigned char m_ucTxSeq;
    // Sendbuffer
    unsigned char* m_ucpSendBuffer;
    // stores the length of SendBuffer
    unsigned long m_ulSendBufferLength;
    // ReceiveBuffer
    unsigned char* m_ucpReceiveBuffer;

//----------------------------------------------------------------------------
};

#ifdef __cplusplus
}
#endif

#endif // USBPROTOCOL_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -