Removed svn keywords from comments.
[quicksms.git] / serial / serialport.h
blob10bd0df5405c34594e5ce609a859c4f8bbae175d
1 /***************************************************************************//**
2 * Project Name : quicksms
4 * \file serialport.h this file contains ISerialPort class declaration.
5 * \package quicksms
6 ******************************************************************************/
7 #ifndef SERIALPORT_H
8 #define SERIALPORT_H
10 #include "../pch.h"
11 #include "serialdefs.h"
13 /*****************************************************************************//**
14 * \namespace serial
15 * \brief this namespace groups objects for manipulating data over serial ports.
16 ********************************************************************************/
18 namespace serial{
21 /***************************************************************************//**
22 * \class CSerialPort
23 * \brief this class represents a serial port in objective manner.
25 * This class helps with manipulating data over serial ports
26 * It allows to select baudrate, parity and flow control
28 *******************************************************************************/
30 class ISerialPort
32 public:
33 /*********************************************************************//**
34 * \brief this CSerialPort constructor opens a port with name passed as
35 * parameter.
37 * \param[in] name name of file descriptor representing port to open.
38 ***********************************************************************/
39 ISerialPort(QString &name);
42 /*********************************************************************//**
43 * \brief constructor which allows to more precisely set port
44 * parameters.
46 * \param[in] pName port name
47 * \param[in] pBaudrate port baud rate
48 * \param[in] pFlow useful when needed specific flow control
49 * \param[in] pParity port parity control
51 * This constructor allows for more spohisticated port opening.
52 * It is possible to select correct port speed, parity and
53 * flow control instead of just choosing device name.
55 ***********************************************************************/
56 ISerialPort(const QString &pName,const serial::Baudrate &pBaudrate,const serial::Parity &pParity,
57 const serial::FlowControl &pFlow,const bool pOpen,const ReadCallback pReadCallback);
60 ~ISerialPort();
64 /********************************************************************//**
65 * \brief this function opens a port
66 * \param[in] pName port filename
67 * \return returns port state
68 * \retval
70 * If already open return value is Status::FILE_ALREADY_OPEN
71 * and if invalid file path is passed return value is
72 * Status::FILE_NOT_FOUND
74 ************************************************************************/
75 virtual bool open(const QString &pName) = 0;
78 /********************************************************************//**
79 * \brief this function opens a port
80 * \return returns port state
81 * \retval
83 * If already open return value is Status::FILE_ALREADY_OPEN
84 * and if invalid file path is passed return value is
85 * Status::FILE_NOT_FOUND
87 ************************************************************************/
88 virtual bool open() = 0;
91 /*********************************************************************//**
92 * \brief reopens an already open port.
94 * It is a convienience function, which allows to reopen port e.g
95 * when an I/O error occured. It will use last settings (port name parity
96 * speed and flow control).
97 ************************************************************************/
98 bool reopen();
101 /*********************************************************************//**
102 * \brief closes a port.
103 * \param[in] pForce set to true if you want to terminate pending tasks.
105 * closes a port. If you forget to close, it will be done in destructor.
106 ************************************************************************/
107 virtual bool close( bool pForce = 0) =0;
110 /*********************************************************************//**
111 * \brief opens or closes port, depending on pState value.
112 * \param[in] pState set true to open, close to close :-)
115 ************************************************************************/
116 virtual bool setOpened(const bool &pState) =0;
118 /*********************************************************************//**
119 * \brief opens or closes port, depending on pState value.
120 * \param[in] pState set true to open, close to close :-)
123 ************************************************************************/
124 virtual bool isOpened(const bool &pState);
127 /*********************************************************************//**
128 * \brief sets port blocking mode.
129 * \param[in] pState
131 * if port is in blocking mode, then the readBuffer() call will block
132 * thread until there is data to be read.
133 ************************************************************************/
134 virtual bool setBlocking(const bool &pState) =0;
137 /*********************************************************************//**
138 * \brief sets port blocking mode.
139 * \param[in] pState
141 * if port is in blocking mode, then the readBuffer() call will block
142 * thread until there is data to be read.
143 ************************************************************************/
144 virtual bool isBlocking(const bool &pState);
147 /*********************************************************************//**
148 * \brief set port baud rate.
149 * \param[in] pBaudrate port baudrate
150 * \todo value checks!
152 ************************************************************************/
153 virtual bool setBaudrate(const serial::Baudrate &pBaudrate) =0;
156 /*********************************************************************//**
157 * \brief get port baud rate.
158 * \param[out] pBaudrate port baudrate
159 * \todo value checks!
161 ************************************************************************/
162 bool getBaudrate(serial::Baudrate &pBaudrate);
165 /*********************************************************************//**
166 * \brief sets flow control
167 * \param[in] pFlow new flow control
170 ************************************************************************/
171 virtual bool setFlowControl(const serial::FlowControl &pFlow) =0;
174 /*********************************************************************//**
175 * \brief sets flow control
176 * \param[in] pFlow new flow control
179 ************************************************************************/
180 bool getFlowControl(const serial::FlowControl &pFlow);
183 /*********************************************************************//**
184 * \brief sets port parity checking mode.
185 * \param[in] pParity port parity.
188 ************************************************************************/
189 virtual bool setParity(const serial::Parity &pParity) =0;
191 /*********************************************************************//**
192 * \brief sets port parity checking mode.
193 * \param[in] pParity port parity.
196 ************************************************************************/
197 bool getParity(const serial::Parity &pParity);
200 /*********************************************************************//**
201 * \brief sets port filename.
202 * \param[in] pName port name /path
204 * if path is non-empty and existant, then this method setsmName = pName.
205 ************************************************************************/
206 virtual bool setFilename(const QString &pName) =0;
209 /*********************************************************************//**
210 * \brief sets port filename.
211 * \param[in] pName port name /path
213 * if path is non-empty and existant, then mName = pName.
214 ************************************************************************/
215 bool getFilename(const QString &pName);
218 /*********************************************************************//**
219 * \brief sets port filename.
220 * \param[out] pStatus target Status field.
222 * Use it to retrieve information about port operating status.
223 ************************************************************************/
224 bool getStatus(serial::Status &status);
227 /*********************************************************************//**
228 * \brief sets read callback function.
229 * \param[in] pCallback pointer to callback function
231 * Usable when you want to execute function as soon as data arrives.
232 * If pointer is valid, it sets mReadCallback to pCallback
233 ************************************************************************/
234 bool setReadCallback( const serial::ReadCallback &pCallback);
237 /*********************************************************************//**
238 * \brief writes data from buffer to port.
239 * \param[in] pBuffer location in memory where source data resides.
240 * \param[in] pSize number of bytes to be written.
242 * writeBuffer writes equal pSize bytes from pBuffer to port.
243 ************************************************************************/
244 virtual int writeBuffer(void *pBuffer, unsigned int pSize) =0;
247 /*********************************************************************//**
248 * \brief reads data from port to buffer
249 * \param[out] pBuffer location in memory where source data resides.
250 * \param[in] pSize number of bytes to be read.
251 * \param[in] pTimeout read timeout.
252 * \return number of bytes that actually have been retrieved.
254 * readBuffer reads MAXIMUM pSize bytes from port and writes it into
255 * buffer pointed by pBuffer. If timeout > 0 the function will wait
256 * if there aren't any bytes to be read.
257 ************************************************************************/
258 virtual int readBuffer(void *pBuffer, unsigned int pSize = 0, unsigned int pTimeout = 0) =0;
262 /*********************************************************************//**
263 * \brief writes string to port.
264 * \param[in] pStr source string.
266 * This is a convenience function handling string to byte-array conversion
267 ************************************************************************/
268 virtual int sendString(const QString &pStr) =0;
271 /*********************************************************************//**
272 * \brief writes QByteArray to port.
273 * \param[in] pArr source array.
275 * This is a convenience function handling Qt byte arrays.
276 ************************************************************************/
277 virtual int sendByteArray(const QByteArray &pArr) =0;
280 /*********************************************************************//**
281 * \brief reads string from port.
282 * \param[in] pStr source string.
283 * \param[in] pSize (optional) max bytes to be read.
285 * This is a convenience function handling string to byte-array conversion
286 ************************************************************************/
287 virtual int recieveString(QString &pStr, const unsigned int &pSize = 0) =0;
289 const inline bool isOpened();
291 private:
294 int mBaudrate; ///< current baudrate setting
296 bool mOpened; ///< is port opened?
297 bool mIoError; ///< when I/O error occurs this is set to true.
298 bool mBlocking; ///< if port is in blocking mode this is set to true.
299 bool mIsOpened; ///< indicates whether port is in open state.
300 bool mBusy; ///< informs whether are there any operations in progress
302 QString mName; ///< port name is saved here
304 serial::Parity mParity; ///< current parity setting
305 serial::FlowControl mFlow;///< actual flowcontrol setting
306 serial::Status mStatus; ///< port status
307 serial::ReadCallback mReadCallback; ///< pointer to function which will be executed
308 ///< everytime when there is data in buffer.
309 int mSignalHandler(int signal);
310 }; // ISerialPort
311 }; //serial
313 #endif //SERIALPORT_H