?? yatemodem.h
字號:
/* * yatemodem.h * This file is part of the YATE Project http://YATE.null.ro * * Yet Another Modem * * Yet Another Telephony Engine - a fully featured software PBX and IVR * Copyright (C) 2004-2006 Null Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */#ifndef __YATEMODEM_H#define __YATEMODEM_H#include <yateclass.h>#ifdef _WINDOWS#ifdef LIBYMODEM_EXPORTS#define YMODEM_API __declspec(dllexport)#else#ifndef LIBYMODEM_STATIC#define YMODEM_API __declspec(dllimport)#endif#endif#endif /* _WINDOWS */#ifndef YMODEM_API#define YMODEM_API#endif/** * Holds all Telephony Engine related classes. */namespace TelEngine {class BitAccumulator; // 1-byte length bit accumulatorclass FSKModem; // Frequency Shift Keying modulator/demodulatorclass UART; // UART receiver/transmitterclass UARTBuffer; // A byte accumulator used by an UARTclass ETSIModem; // An analog signal processor as defined by ETSI// Internal forward declarationsclass BitBuffer; // Used to accumulate all bits to be printed to outputclass FSKFilter; // The internal signal filter/** * This class encapsulates an 8 bits length buffer used to accumulate bits * @short A 1-byte length bit accumulator */class YMODEM_API BitAccumulator{public: /** * Constructor * @param dataBits The buffer size. Values interval 1..8 */ inline BitAccumulator(unsigned char dataBits) : m_crtByte(0), m_crtPos(0), m_dataBits(dataBits), m_oddParity(false) {} /** * Get the buffer size * @return The buffer size */ inline unsigned char dataBits() const { return m_dataBits; } /** * Set the buffer size. Reset the accumulator * @param value The new buffer size. Values interval 1..8 */ inline void dataBits(unsigned char value) { m_dataBits = value; reset(); } /** * Reset the accumulator. Returns the old data * @param oddParity Optional pointer to get the parity of old data * @return The old data */ inline unsigned char reset(bool* oddParity = 0) { unsigned char tmp = m_crtByte; m_crtByte = m_crtPos = 0; if (oddParity) *oddParity = m_oddParity; m_oddParity = false; return tmp; } /** * Accumulate a bit. Reset accumulator when full * @param bit The bit value to accumulate * @param oddParity Optional pointer to get the data parity when full * @return The accumulated byte or a value greater then 255 if incomplete */ inline unsigned int accumulate(bool bit, bool* oddParity = 0) { if (bit) { m_crtByte |= (1 << m_crtPos); m_oddParity = !m_oddParity; } m_crtPos++; if (m_crtPos != m_dataBits) return 0xffff; return reset(oddParity); }private: unsigned char m_crtByte; // Current partial byte unsigned char m_crtPos; // Current free bit position unsigned char m_dataBits; // The length of a data byte (interval: 1..8) bool m_oddParity; // The parity of the current byte value (true: odd)};/** * This is a modulator/demodulator class attached to an UART. Used to demodulate bits * from frequency modulated signal and send them to an UART * @short A Frequency Shift Keying modem */class YMODEM_API FSKModem{public: /** * Modem type enumeration */ enum Type { ETSI = 0, // ETSI caller id signal: MARK:1200 SPACE:2200 BAUDRATE:1200 // SAMPLERATE:8000 SAMPLES/BIT:7 STOPBITS:1 PARITY:NONE TypeCount = 1 // NOTE: Don't change these values: they are used as array indexes }; /** * Constructor * @param params Modem parameters (including modemtype) * @param uart The UART attached to this modem */ FSKModem(const NamedList& params, UART* uart); /** * Destructor */ ~FSKModem(); /** * Check if this modem is terminated. Need reset if so. * The modem can terminate processing on UART's request * @return True if this modem is terminated */ inline bool terminated() const { return m_terminated; } /** * Get the type of this modem * @return The modem type */ inline int type() const { return m_type; } /** * Reset modem to its initial state */ void reset(); /** * Data processor. Demodulate received data. Feed the UART with received bits * @param data The data to process * @return False to stop feedding data (terminated) */ bool demodulate(const DataBlock& data); /** * Create a buffer containing the modulated representation of a message. * A data pattern (depending on modem's type) will be added before the message. * A mark pattern (2ms long) will be added after the message. * Reset the modem before each request to modulate * @param dest Destination buffer * @param data Message data (each byte will be enclosed in start/stop/parity bits) */ void modulate(DataBlock& dest, const DataBlock& data); /** * Append a raw buffer to a data block * @param dest Destination buffer * @param buf Buffer to append to destination * @param len the number of bytes to append starting with buf */ static inline void addRaw(DataBlock& dest, void* buf, unsigned int len) { DataBlock tmp(buf,len,false); dest += tmp; tmp.clear(false); } /** * Keep the modem type names. Useful to configure the modem */ static TokenDict s_typeName[];private: int m_type; // Modem type bool m_terminated; // Terminated flag (need reset if true) FSKFilter* m_filter; // Internal filter used to demodulate received data UART* m_uart; // The UART using this modem's services DataBlock m_buffer; // Partial input buffer when used to demodulate or modulate data BitBuffer* m_bits; // Bit buffer used when debugging};/** * Accumulate data bits received from a modem * @short An UART receiver/transmitter */class YMODEM_API UART : public DebugEnabler{public: /** * UART state enumeration */ enum State { Idle, // Not started BitStart, // Waiting for start bit (SPACE) BitData, // Accumulate data bits BitParity, // Waiting for parity bit(s) BitStop, // Waiting for stop bit (MARK) UARTError, // Error }; /** * UART error enumeration */ enum Error { EFraming, // Frame error: invalid stop bit(s) EParity, // Parity error EChksum, // Message checksum error EInvalidData, // Invalid (inconsistent) data EUnknown, // Unknown error EStopped, // Aborted by descendants ENone }; /** * Constructor * @param state The initial state of this UART * @param params The UART's parameters * @param name The name of this debug enabler */ UART(State state, const NamedList& params, const char* name = 0); /** * Destructor */ virtual ~UART() {} /** * Get the current state of this UART * @return The current state of this UART as enumeration */ inline State state() const { return m_state; } /** * Get the current error state of this UART, if any * @return The current error state of this UART as enumeration */ inline Error error() const { return m_error; } /** * Get the type of this UART's modem * @return The type of this UART's modem */ inline int modemType() const { return m_modem.type(); } /** * Get the data bit accumulator used by this UART * @return The data bit accumulator used by this UART */ inline const BitAccumulator& accumulator() const { return m_accumulator; } /** * Reset this UART * @param newState The state to reset to */ virtual void reset(State newState = Idle); /** * Send data to the enclosed modem to be demodulated * @param data The data to process * @return False to stop processing
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -