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

📄 yatemodem.h

📁 C++ modem驱动代码
💻 H
📖 第 1 页 / 共 2 页
字号:
     */    inline bool demodulate(const DataBlock& data)	{ return m_modem.demodulate(data); }    /**     * Create a buffer containing the modulated representation of a list of parameters     * @param dest Destination buffer     * @param params The list containing the values to be modulated     * @return False on failure (an 'error' parameter will be set in params)     */    inline bool modulate(DataBlock& dest, NamedList& params) {	    DataBlock data;	    if (!createMsg(params,data))		return false;	    m_modem.modulate(dest,data);	    return true;	}    /**     * Create a buffer containing the modulated representation of another one     * @param dest Destination buffer     * @param src Source buffer     */    inline void modulate(DataBlock& dest, const DataBlock& src)	{ m_modem.modulate(dest,src); }    /**     * Push a bit of data into this UART. Once a data byte is accumulated, push it back to itself     * @param value The bit to be processed     * @return False to stop feeding data     */    bool recvBit(bool value);    /**     * Push a data byte into this UART     * @param data The byte to be processed     * @return False to stop feeding data     */    virtual bool recvByte(unsigned char data)	{ return false; }    /**     * Notification from modem that the FSK start was detected     * @return False to stop the modem     */    virtual bool fskStarted()	{ return true; }    /**     * Keeps the names associated with UART errors     */    static TokenDict s_errors[];protected:    /**     * Process an accumulated byte in Idle state     * @param data The byte to process     * @return Negative to stop, positive to change state to BitStart, 0 to continue     */    virtual int idleRecvByte(unsigned char data)	{ return false; }    /**     * Create a buffer containing the byte representation of a message to be sent     * @param params The list containing message parameters     * @param data Destination message data buffer     * @return False on failure     */    virtual bool createMsg(NamedList& params, DataBlock& data)	{ return false; }    /**     * Set the error state of this UART     * @param e The error     * @return False     */    bool error(Error e);private:     // Change this UART's state    void changeState(State newState);    FSKModem m_modem;                    // The modem used by this UART    State m_state;                       // The state of this UART    Error m_error;                       // The error type if state is error    int m_parity;                        // Used parity: 0=none, -1=odd, 1=even    bool m_expectedParity;               // The expected value of the parity bit if used    BitAccumulator m_accumulator;        // The data bits accumulator};/** * This class is used by an UART to accumulate messages with known length * @short A fixed length byte accumulator used by an UART */class YMODEM_API UARTBuffer{public:    /**     * Constructor     * @param client The client of this buffer     */    inline UARTBuffer(UART* client)	: m_client(client)	{ reset(); }    /**     * Get the accumulated data     * @return The accumulated data     */    inline const DataBlock& buffer() const	{ return m_buffer; }    /**     * Get the free space length in the buffer     * @return The free space length     */    inline unsigned int free() const	{ return m_free; }    /**     * Reset the buffer     * @param len The new length of the buffer. Set to 0 to left the length unchanged     */    inline void reset(unsigned int len = 0) {	    m_buffer.clear();	    m_crtIdx = m_free = 0;	    if (len) {		m_buffer.assign(0,len);		m_free = len;	    }	}    /**     * Accumulate data     * @param value The value to append to the buffer     * @return False on buffer overflow     */    inline bool accumulate(unsigned char value) {	    if (m_free) {		((unsigned char*)m_buffer.data())[m_crtIdx++] = value;		m_free--;		return true;	    }	    Debug(m_client,DebugNote,"Buffer overflow");	    return false;	}private:    UART* m_client;                      // The client    unsigned int m_crtIdx;               // Current index n buffer    unsigned int m_free;                 // Free buffer length    DataBlock m_buffer;                  // The buffer};/** * This class implements a modem/UART pair used to demodulate/decode analog signal as defined *  in ETSI EN 300 659-1, ETSI EN 300 659-2, ETSI EN 300 659-3 * @short An analog signal processor as defined by ETSI */class YMODEM_API ETSIModem : public UART{public:    /**     * The state of this ETSI decoder     */    enum State {	StateError,                      // Error encountered: need reset	WaitFSKStart,                    // Waiting for data start pattern	WaitMark,                        // Waiting for mark pattern	WaitMsg,                         // Wait a message	WaitMsgLen,                      // Received message: wait length	WaitParam,                       // Wait a parameter	WaitParamLen,                    // Received parameter: wait length	WaitData,                        // Received parameter length: wait data	WaitChksum,                      // Wait checksum    };    /**     * Message type defined in ETSI EN 659-3 5.2     */    enum MsgType {	MsgCallSetup = 0x80,             // Call setup	MsgMWI       = 0x82,             // Message waiting indicator	MsgCharge    = 0x86,             // Advise of charge	MsgSMS       = 0x89,             // Short message service    };    /**     * Message parameters defined in ETSI EN 659-3 5.3     */    enum MsgParam {	DateTime         = 0x01,         // 8		Date and Time	CallerId         = 0x02,         // max. 20	Calling Line Identity	CalledId         = 0x03,         // max. 20	Called Line Identity	CallerIdReason   = 0x04,         // 1		Reason for Absence of Calling Line Identity	CallerName       = 0x07,         // max. 50	Calling Party Name	CallerNameReason = 0x08,         // 1		Reason for absence of Calling Party Name	VisualIndicator  = 0x0B,         // 1		Visual Indicator	MessageId        = 0x0D,         // 3		Message Identification	LastMsgCLI       = 0x0E,         // max. 20	Last Message CLI	CompDateTime     = 0x0F,         // 8 or 10	Complementary Date and Time	CompCallerId     = 0x10,         // max. 20	Complementary Calling Line Identity	CallType         = 0x11,         // 1		Call type	FirstCalledId    = 0x12,         // max. 20	First Called Line Identity	MWICount         = 0x13,         // 1		Number of Messages	FwdCallType      = 0x15,         // 1		Type of Forwarded call	CallerType       = 0x16,         // 1		Type of Calling user	RedirNumber      = 0x1A,         // max. 20	Redirecting Number	Charge           = 0x20,         // 14		Charge	AdditionalCharge = 0x21,         // 14		Additional Charge	Duration         = 0x23,         // 6		Duration of the Call	NetworkID        = 0x30,         // max. 20	Network Provider Identity	CarrierId        = 0x31,         // max. 20	Carrier Identity	SelectFunction   = 0x40,         // 2-21        Selection of Terminal Function	Display          = 0x50,         // max. 253	Display Information	ServiceInfo      = 0x55,         // 1		Service Information	Extension        = 0xE0,         // 10		Extension for network operator use	Unknown    };    /**     * Constructor     * @param params Decoder parameters     * @param name The name of this debug enabler     */    ETSIModem(const NamedList& params, const char* name = 0);    /**     * Destructor     */    virtual ~ETSIModem();    /**     * Reset this decoder (modem and UART)     */    virtual void reset();    /**     * Push a data byte into this decoder. Reset this UART and call decode after validated a received message     * @param data The byte to be processed     * @return False to stop feeding data     */    virtual bool recvByte(unsigned char data);    /**     * Keeps the text associated with message type enumeration     */    static TokenDict s_msg[];    /**     * Keeps the text associated with parameter type enumeration     */    static TokenDict s_msgParams[];protected:    /**     * Process an accumulated byte in Idle state     * @param data The byte to process     * @return Negative to stop, positive to change state to BitStart, 0 to continue     */    virtual int idleRecvByte(unsigned char data);    /**     * Process a list of received message parameters     * @param msg The message type as enumeration     * @param params Message parameters     * @return False to stop processing data     */    virtual bool recvParams(MsgType msg, const NamedList& params)	{ return false; }    /**     * Process (decode) a valid received buffer. Call recvParams() after decoding the message     * @param msg The message type as enumeration     * @param buffer The accumulated data bytes     * @return False to stop processing data     */    virtual bool decode(MsgType msg, const DataBlock& buffer);    /**     * Create a buffer containing the byte representation of a message to be sent     * @param params The list containing message parameters.     *  The name of the list must be a valid (known) message     * @param data Destination message data buffer     * @return False on failure (an 'error' parameter will be set in params)     */    virtual bool createMsg(NamedList& params, DataBlock& data);private:    // Change decoder's state    void changeState(State newState);    UARTBuffer m_buffer;                 // The buffer used to accumulate messages    State m_state;                       // Decoder state    unsigned char m_waitSeizureCount;    // Expected number of channel seizure bytes in a row    unsigned char m_crtSeizureCount;     // Current number of channel seizure bytes in a row    unsigned char m_crtMsg;              // Current message id    unsigned char m_crtParamLen;         // Current receiving parameter length    unsigned int m_chksum;               // Current calculated checksum};}#endif /* __YATEMODEM_H *//* vi: set ts=8 sw=4 sts=4 noet: */

⌨️ 快捷键说明

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