/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input.cpp |
---|
0,0 → 1,60 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "Input.h" |
void Input::Init() |
{ |
} |
bool Input::Open(set_Input s_Input) |
{ |
s_Input = s_Input; |
return false; |
} |
bool Input::IsOpen() |
{ |
return false; |
} |
bool Input::Close() |
{ |
return false; |
} |
void Input::send_Data(QString t_Data, int ID) |
{ |
t_Data = t_Data; |
ID = ID; |
} |
void Input::send_RawData(char *t_Data) |
{ |
t_Data = t_Data; |
} |
void Input::stop_Resend(int ID) |
{ |
ID = ID; |
} |
eMode Input::Mode() |
{ |
return NONE; |
} |
/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input.h |
---|
0,0 → 1,65 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef INPUT_H |
#define INPUT_H |
#include <QObject> |
enum eMode {NONE, TCP, TTY}; |
struct set_Input |
{ |
QString Main; |
QString Sub; |
}; |
struct s_Resend |
{ |
bool ID; |
QString Data; |
}; |
static const int CLOSED = 0; |
static const int REFUSED = 1; |
static const int REMOTECLOSED = 2; |
static const int MAX_Confirm = 11; |
class Input : public QObject |
{ |
Q_OBJECT |
public: |
virtual void Init(); |
virtual bool Open(set_Input s_Input); |
virtual bool IsOpen(); |
virtual bool Close(); |
virtual void send_Data(QString t_Data, int ID = 0); |
virtual void send_RawData(char *t_Data); |
virtual void stop_Resend(int ID); |
virtual eMode Mode(); |
signals: |
virtual void sig_NewData(QString Data); |
// private: |
}; |
#endif // INPUT_H |
/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input_TCP.cpp |
---|
0,0 → 1,197 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "Input_TCP.h" |
void Input_TCP::Init() |
{ |
b_Open = false; |
Timer = new QTimer(); |
s_Buffer = ""; |
connect(Timer, SIGNAL(timeout()), this, SLOT(slot_Timer())); |
for (int z = 0; z < MAX_Confirm; z++) |
{ |
Confirm[z].ID = false; |
} |
} |
bool Input_TCP::Open(set_Input s_Input) |
{ |
TCP_Socket = new(QTcpSocket); |
TCP_Socket->connectToHost (s_Input.Main, s_Input.Sub.toInt()); |
connect(TCP_Socket, SIGNAL(connected()), this, SLOT(slot_TCP_Connected()) ); |
connect(TCP_Socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_TCP_Error(QAbstractSocket::SocketError))); |
return true; |
} |
bool Input_TCP::IsOpen() |
{ |
return b_Open; |
} |
bool Input_TCP::Close() |
{ |
TCP_Socket->disconnectFromHost(); |
disconnect(TCP_Socket, SIGNAL(connected()), 0, 0); |
disconnect(TCP_Socket, SIGNAL(readyRead()), 0, 0); |
disconnect(TCP_Socket, SIGNAL(disconnected()), 0, 0); |
b_Open = false; |
Timer->stop(); |
return true; |
} |
void Input_TCP::send_Data(QString t_Data, int ID) |
{ |
if ((ID > 0) && (ID < MAX_Confirm)) |
{ |
Timer->start(2500); |
Confirm[ID].ID = true; |
Confirm[ID].Data = t_Data; |
} |
if (b_Open) |
{ |
usleep(50000); |
if (t_Data[t_Data.length() - 1] != '\r') |
{ |
t_Data = t_Data + "\r"; |
} |
QByteArray Temp; |
Temp = QByteArray(QString(t_Data + "\n").toAscii()); |
TCP_Socket->write(Temp); |
TCP_Socket->flush(); |
// qDebug(t_Data.toLatin1().data()); |
} |
} |
void Input_TCP::send_RawData(char *t_Data) |
{ |
t_Data = t_Data; |
} |
void Input_TCP::stop_Resend(int ID) |
{ |
if ((ID > 0) && (ID < MAX_Confirm)) |
{ |
Confirm[ID].ID = false; |
Confirm[ID].Data = ""; |
} |
} |
void Input_TCP::slot_Timer() |
{ |
bool Active = false; |
for (int x = 0; x < MAX_Confirm; x++) |
{ |
if (Confirm[x].ID) |
{ |
Active = true; |
send_Data(Confirm[x].Data); |
} |
} |
if (Active == false) |
{ |
Timer->stop(); |
} |
} |
void Input_TCP::slot_TCP_Connected() |
{ |
b_Open = true; |
connect(TCP_Socket, SIGNAL(readyRead()), SLOT(slot_TCP_ReadLine())); |
connect(TCP_Socket, SIGNAL(disconnected()),TCP_Socket, SLOT(deleteLater())); |
connect(TCP_Socket, SIGNAL(disconnected()),this, SLOT(slot_TCP_Disconnect())); |
emit sig_Connected(); |
} |
void Input_TCP::slot_TCP_Disconnect() |
{ |
disconnect(TCP_Socket, SIGNAL(disconnected()), 0, 0); |
disconnect(TCP_Socket, SIGNAL(readyRead()), 0, 0); |
// emit sig_Disconnected(1); |
} |
void Input_TCP::slot_TCP_ReadLine() |
{ |
// QString t_Data = QString(TCP_Socket->readLine(TCP_Socket->bytesAvailable())).remove(QChar('\n')); |
QString t_Data = s_Buffer + QString(TCP_Socket->readAll()).remove(QChar('\n')); |
s_Buffer = ""; |
t_Data = t_Data.replace('\r', "\r\n"); |
QStringList l_Data; |
l_Data = t_Data.split('\n'); |
for (int z = 0; z < l_Data.count(); z++) |
{ |
if ((l_Data[z][l_Data[z].length() - 1] == '\r')) |
{ |
emit(sig_NewData(l_Data[z])); |
// qDebug(QString("DATA: _" + l_Data[z] + "_ < END").toLatin1().data()); |
} |
else |
{ |
s_Buffer = s_Buffer + l_Data[z]; |
} |
} |
} |
void Input_TCP::slot_TCP_Error(QAbstractSocket::SocketError Error) |
{ |
b_Open = false; |
disconnect(TCP_Socket, SIGNAL(disconnected()), 0, 0); |
disconnect(TCP_Socket, SIGNAL(error(QAbstractSocket::SocketError)), 0, 0); |
disconnect(TCP_Socket, SIGNAL(connected()), 0, 0); |
disconnect(TCP_Socket, SIGNAL(readyRead()), 0, 0); |
// qDebug("Error"); |
switch (Error) |
{ |
case QAbstractSocket::ConnectionRefusedError: |
emit sig_Disconnected(REFUSED); |
break; |
case QAbstractSocket::RemoteHostClosedError: |
emit sig_Disconnected(REMOTECLOSED); |
break; |
default: |
emit sig_Disconnected(CLOSED); |
break; |
} |
// emit sig_Disconnected(CLOSED); |
} |
eMode Input_TCP::Mode() |
{ |
return TCP; |
} |
/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input_TCP.h |
---|
0,0 → 1,67 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef INPUT_TCP_H |
#define INPUT_TCP_H |
#include <QObject> |
#include <QTcpServer> |
#include <QTcpSocket> |
#include <QTimer> |
#include <QStringList> |
#include "Input.h" |
class Input_TCP : public Input |
{ |
Q_OBJECT |
public: |
void Init(); |
bool Open(set_Input s_Input); |
bool IsOpen(); |
bool Close(); |
void send_Data(QString t_Data, int ID = 0); |
void send_RawData(char *t_Data); |
void stop_Resend(int ID); |
eMode Mode(); |
private: |
// TCP Server und Socket. |
QTcpServer *TCP_Server; |
QTcpSocket *TCP_Socket; |
QTimer *Timer; |
bool b_Open; |
s_Resend Confirm[MAX_Confirm]; |
QString s_Buffer; |
private slots: |
// void slot_newDataReceived(const QByteArray &dataReceived); |
void slot_TCP_Connected(); |
void slot_TCP_Disconnect(); |
void slot_TCP_ReadLine(); |
void slot_TCP_Error(QAbstractSocket::SocketError Error); |
void slot_Timer(); |
signals: |
void sig_NewData(QString); |
void sig_Disconnected(int); |
void sig_Connected(); |
}; |
#endif // INPUT_TCP_H |
/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input_TTY.cpp |
---|
0,0 → 1,160 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#include "Input_TTY.h" |
void Input_TTY::Init() |
{ |
Timer = new QTimer(); |
connect(Timer, SIGNAL(timeout()), this, SLOT(slot_Timer())); |
for (int z = 0; z < MAX_Confirm; z++) |
{ |
Confirm[z].ID = false; |
} |
} |
bool Input_TTY::Open(set_Input s_Input) |
{ |
o_TTY = new ManageSerialPort; |
o_TTY->setBaudRate(BAUD57600); //BaudRate |
o_TTY->setDataBits(DATA_8); //DataBits |
o_TTY->setParity(PAR_NONE); //Parity |
o_TTY->setStopBits(STOP_1); //StopBits |
o_TTY->setFlowControl(FLOW_OFF); //FlowControl |
o_TTY->setTimeout(0, 10); |
o_TTY->enableSending(); |
o_TTY->enableReceiving(); |
o_TTY->setPort(s_Input.Main); //Port |
o_TTY->open(); |
if (o_TTY->isOpen()) |
{ |
connect(o_TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_Receive(const QByteArray &))); |
o_TTY->receiveData(); |
// qDebug(QString("Open Input-TTY " + s_Input.Main).toLatin1().data()); |
return true; |
} |
return false; |
} |
bool Input_TTY::IsOpen() |
{ |
return o_TTY->isOpen(); |
} |
bool Input_TTY::Close() |
{ |
o_TTY->close(); |
disconnect(o_TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0); |
Timer->stop(); |
return o_TTY->isOpen(); |
} |
void Input_TTY::send_Data(QString t_Data, int ID) |
{ |
if ((ID > 0) && (ID < MAX_Confirm)) |
{ |
Timer->start(2500); |
Confirm[ID].ID = true; |
Confirm[ID].Data = t_Data; |
} |
if (o_TTY->isOpen()) |
{ |
if (t_Data[t_Data.length() - 1] != '\r') |
{ |
t_Data = t_Data + "\r"; |
} |
QByteArray Temp; |
Temp = QByteArray(t_Data.toAscii()); |
o_TTY->sendData(Temp); |
// qDebug(t_Data.toLatin1().data()); |
} |
} |
void Input_TTY::send_RawData(char *t_Data) |
{ |
t_Data = t_Data; |
} |
void Input_TTY::slot_Receive(const QByteArray &dataReceived) |
{ |
const char *RX; |
RX = dataReceived.data(); |
int a = 0; |
while (RX[a] != '\0') |
{ |
if (RX[a] == '\r') |
{ |
emit(sig_NewData(s_RX)); |
s_RX = QString(""); |
} |
else |
{ |
s_RX = s_RX + QString(RX[a]); |
} |
a++; |
} |
} |
void Input_TTY::stop_Resend(int ID) |
{ |
if ((ID > 0) && (ID < MAX_Confirm)) |
{ |
Confirm[ID].ID = false; |
Confirm[ID].Data = ""; |
} |
} |
void Input_TTY::slot_Timer() |
{ |
bool Active = false; |
for (int x = 0; x < MAX_Confirm; x++) |
{ |
if (Confirm[x].ID) |
{ |
Active = true; |
send_Data(Confirm[x].Data); |
} |
} |
if (Active == false) |
{ |
Timer->stop(); |
} |
} |
eMode Input_TTY::Mode() |
{ |
return TTY; |
} |
/QMK-Groundstation/tags/QMK-Tools v1.3.0/Global/Class_Input/Input_TTY.h |
---|
0,0 → 1,57 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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. * |
* * |
* 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., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
#ifndef INPUT_TTY_H |
#define INPUT_TTY_H |
#include <QObject> |
#include <QTimer> |
#include "Input.h" |
#include "../Class_SerialPort/ManageSerialPort.h" |
class Input_TTY : public Input |
{ |
Q_OBJECT |
public: |
void Init(); |
bool Open(set_Input s_Input); |
bool IsOpen(); |
bool Close(); |
void send_Data(QString t_Data, int ID = 0); |
void send_RawData(char *t_Data); |
void stop_Resend(int ID); |
eMode Mode(); |
private: |
ManageSerialPort *o_TTY; |
QString s_RX; |
QTimer *Timer; |
s_Resend Confirm[MAX_Confirm]; |
private slots: |
void slot_Receive(const QByteArray &dataReceived); |
void slot_Timer(); |
signals: |
void sig_NewData(QString Data); |
}; |
#endif // INPUT_TTY_H |