Subversion Repositories Code-Repo

Rev

Rev 353 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef SERIALHELPER_H
#define SERIALHELPER_H

#include "GlobalDefines.h"
#include <QtSerialPort>

#define SERIAL_NEWLINE_CHAR "\n"
#define SERIAL_BUFFER_SIZE      32

class SerialHelper : public QObject
{
        Q_OBJECT
    public:
        SerialHelper(QObject *parent = 0);
        ~SerialHelper();

        bool connected;

    public slots:
        // Inbound from SerialController
        void Serial_QueryParameters(void);
        void Serial_Connect(QString port, QString speed, QString dataBits,
                            QString stopBits, QString parity, QString flowControl);
        void Serial_Disconnect(void);
        void Serial_TransmitString(QString string);
        void Serial_TransmitByteArray(QByteArray buffer);

        // Local processing of received data
        void Serial_ProcessIncomingData(void);
        void Serial_ProcessError(QSerialPort::SerialPortError error);

    signals:
        // Outbound to SerialController
        void Serial_UpdateParameters(QStringList ports, QStringList speeds, QStringList dataBits,
                                     QStringList stopBits, QStringList parity, QStringList flowControl);
        void Serial_ReceivedByte(char byte);
        void Serial_Connected(void);
        void Serial_Disconnected(void);
        void UpdateStatus(QString string);

    private:
        QSerialPort *serialPort;
        QStringList speeds;
        QStringList dataBits;
        QStringList stopBits;
        QStringList parity;
        QStringList flowControl;

        char bufferIn[SERIAL_BUFFER_SIZE];
        int bufferInIndex;
        bool bufferInOverflow;
        QString currString;
};

#endif // SERIALHELPER_H