Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
674 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
#include "Input_TTY.h"
20
 
21
void Input_TTY::Init()
22
{
23
    Timer = new QTimer();
24
    connect(Timer, SIGNAL(timeout()), this, SLOT(slot_Timer()));
25
 
26
    for (int z = 0; z < MAX_Confirm; z++)
27
    {
28
        Confirm[z].ID = false;
29
    }
30
}
31
 
32
bool Input_TTY::Open(set_Input s_Input)
33
{
34
    o_TTY = new ManageSerialPort;
35
 
36
    o_TTY->setBaudRate(BAUD57600);   //BaudRate
37
    o_TTY->setDataBits(DATA_8);      //DataBits
38
    o_TTY->setParity(PAR_NONE);      //Parity
39
    o_TTY->setStopBits(STOP_1);      //StopBits
40
    o_TTY->setFlowControl(FLOW_OFF); //FlowControl
41
 
42
    o_TTY->setTimeout(0, 10);
43
    o_TTY->enableSending();
44
    o_TTY->enableReceiving();
45
 
46
    o_TTY->setPort(s_Input.Main); //Port
47
    o_TTY->open();
48
 
49
    if (o_TTY->isOpen())
50
    {
51
        connect(o_TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_Receive(const QByteArray &)));
52
 
53
        o_TTY->receiveData();
54
//        qDebug(QString("Open Input-TTY " + s_Input.Main).toLatin1().data());
55
 
56
        return true;
57
    }
58
    return false;
59
}
60
 
61
bool Input_TTY::IsOpen()
62
{
63
    return o_TTY->isOpen();
64
}
65
 
66
bool Input_TTY::Close()
67
{
68
    o_TTY->close();
69
 
70
    disconnect(o_TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0);
71
 
72
    Timer->stop();
73
 
74
    return o_TTY->isOpen();
75
}
76
 
77
void Input_TTY::send_Data(QString t_Data, int ID)
78
{
79
    if ((ID > 0) && (ID < MAX_Confirm))
80
    {
81
        Timer->start(2500);
82
        Confirm[ID].ID = true;
83
        Confirm[ID].Data = t_Data;
84
    }
85
 
86
    if (o_TTY->isOpen())
87
    {
88
        if (t_Data[t_Data.length() - 1] != '\r')
89
        {
90
            t_Data = t_Data + "\r";
91
        }
92
 
93
        QByteArray Temp;
94
 
95
        Temp = QByteArray(t_Data.toAscii());
96
 
97
        o_TTY->sendData(Temp);
98
 
99
//        qDebug(t_Data.toLatin1().data());
100
    }
101
}
102
 
103
void Input_TTY::send_RawData(char *t_Data)
104
{
105
    t_Data = t_Data;
106
}
107
 
108
void Input_TTY::slot_Receive(const QByteArray &dataReceived)
109
{
110
    const char *RX;
111
    RX = dataReceived.data();
112
    int a = 0;
113
 
114
    while (RX[a] != '\0')
115
    {
116
        if (RX[a] == '\r')
117
        {
118
            emit(sig_NewData(s_RX));
119
            s_RX = QString("");
120
        }
121
        else
122
        {
123
            s_RX = s_RX + QString(RX[a]);
124
        }
125
        a++;
126
    }
127
}
128
 
129
void Input_TTY::stop_Resend(int ID)
130
{
131
    if ((ID > 0) && (ID < MAX_Confirm))
132
    {
133
        Confirm[ID].ID = false;
134
        Confirm[ID].Data = "";
135
    }
136
}
137
 
138
void Input_TTY::slot_Timer()
139
{
140
    bool Active = false;
141
 
142
    for (int x = 0; x < MAX_Confirm; x++)
143
    {
144
        if (Confirm[x].ID)
145
        {
146
            Active = true;
147
            send_Data(Confirm[x].Data);
148
        }
149
    }
150
 
151
    if (Active == false)
152
    {
153
        Timer->stop();
154
    }
155
}
156
 
157
eMode Input_TTY::Mode()
158
{
159
    return TTY;
160
}