Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 262 → Rev 263

/QMK-Groundstation/trunk/Classes/cConnection.cpp
20,11 → 20,42
 
cConnection::cConnection()
{
i_Type = 0;
 
TTY = new ManageSerialPort();
 
TTY->setBaudRate(BAUD57600); //BaudRate
TTY->setDataBits(DATA_8); //DataBits
TTY->setParity(PAR_NONE); //Parity
TTY->setStopBits(STOP_1); //StopBits
TTY->setFlowControl(FLOW_OFF); //FlowControl
 
TTY->setTimeout(0, 10);
TTY->enableSending();
TTY->enableReceiving();
 
b_isOpen = false;
}
 
void cConnection::new_Data(QString Data)
{
while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#'))
{
RxData.String.remove(0,1);
}
 
if (ToolBox::check_CRC(RxData.String))
{
RxData.Input = RxData.String.toLatin1().data();
emit(newData(RxData));
}
else
{
emit(showTerminal(2, RxData.String));
}
 
}
 
void cConnection::slot_newDataReceived(const QByteArray &dataReceived)
{
const char *RXt;
35,21 → 66,7
{
if (RXt[a] == '\r')
{
while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#'))
{
RxData.String.remove(0,1);
}
 
if (ToolBox::check_CRC(RxData.String))
{
RxData.Input = RxData.String.toLatin1().data();
emit(newData(RxData));
// emit(showTerminal(1, RxData.String));
}
else
{
emit(showTerminal(2, RxData.String));
}
new_Data(QString(""));
RxData.String = QString("");
}
else
67,44 → 84,107
 
bool cConnection::Close()
{
TTY->close();
switch(i_Type)
{
case C_TTY :
{
TTY->close();
 
disconnect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0);
disconnect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0);
 
b_isOpen = false;
b_isOpen = false;
}
break;
case C_IP :
{
TcpSocket->disconnectFromHost();
disconnect(TcpSocket, SIGNAL(connected()), 0, 0);
disconnect(TcpSocket, SIGNAL(readyRead()), 0, 0);
disconnect(TcpSocket, SIGNAL(disconnected()), 0, 0);
 
b_isOpen = false;
}
break;
}
 
return b_isOpen;
}
 
bool cConnection::Open(QString Address)
bool cConnection::Open(int Typ, QString Address)
{
TTY->setPort(Address); //Port
switch(Typ)
{
case C_TTY :
{
TTY->setPort(Address); //Port
TTY->open();
 
TTY->setBaudRate(BAUD57600); //BaudRate
TTY->setDataBits(DATA_8); //DataBits
TTY->setParity(PAR_NONE); //Parity
TTY->setStopBits(STOP_1); //StopBits
TTY->setFlowControl(FLOW_OFF); //FlowControl
ToolBox::Wait(1000);
 
TTY->setTimeout(0, 10);
TTY->enableSending();
TTY->enableReceiving();
if (TTY->isOpen())
{
connect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &)));
 
TTY->open();
ToolBox::Wait(1000);
qDebug("Try Open");
if (TTY->isOpen())
{
qDebug("Opend");
connect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &)));
TTY->receiveData();
b_isOpen = true;
i_Type = C_TTY;
}
}
break;
case C_IP :
{
QStringList Host = Address.split(":");
 
TTY->receiveData();
b_isOpen = true;
TcpSocket = new(QTcpSocket);
TcpSocket->connectToHost (Host[1], Host[2].toInt());
 
connect(TcpSocket, SIGNAL(connected()), this, SLOT(slot_IP_Connected()) );
// connect(TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_Error(QAbstractSocket::SocketError)));
b_isOpen = true;
i_Type = C_IP;
}
break;
}
 
return b_isOpen;
}
 
void cConnection::slot_IP_Connected()
{
connect(TcpSocket, SIGNAL(readyRead()), SLOT(slot_IP_ReadLine()));
connect(TcpSocket, SIGNAL(disconnected()),TcpSocket, SLOT(deleteLater()));
connect(TcpSocket, SIGNAL(disconnected()),this, SLOT(slot_IP_Disconnect()));
 
// emit sig_Connected();
}
 
void cConnection::slot_IP_Disconnect()
{
disconnect(TcpSocket, SIGNAL(disconnected()), 0, 0);
disconnect(TcpSocket, SIGNAL(readyRead()), 0, 0);
// emit sig_Disconnected(1);
}
 
void cConnection::slot_IP_ReadLine()
{
QString Input = QString(TcpSocket->readLine(TcpSocket->bytesAvailable())).remove(QChar(' '));
 
int Len = Input.length();
 
for (int z = 0; z < Len; z++)
{
if (Input[z] == '\r')
{
new_Data(QString(""));
RxData.String = QString("");
}
else
{
RxData.String = RxData.String + Input[z];
}
}
}
 
bool cConnection::send_Cmd(char CMD, int Address, char Data[150],unsigned int Length, bool Resend)
{
if (b_isOpen)
134,7 → 214,19
}
}
 
TTY->sendData(Temp);
switch(i_Type)
{
case C_TTY :
{
TTY->sendData(Temp);
}
break;
case C_IP :
{
TcpSocket->write(Temp);
}
break;
}
 
emit(showTerminal(3, TX_Data));
}
/QMK-Groundstation/trunk/Classes/cConnection.h
20,10 → 20,15
#define CCONNECTION_H
 
#include <QObject>
#include <QTcpSocket>
 
#include "ToolBox.h"
#include "../global.h"
#include "../SerialPort/ManageSerialPort.h"
 
#define C_TTY 1
#define C_IP 2
 
class cConnection : public QObject
{
Q_OBJECT
31,17 → 36,25
public:
cConnection();
bool isOpen();
bool Open(QString Address);
bool Open(int Typ, QString Address);
bool Close();
bool send_Cmd(char CMD, int Address, char Data[150],unsigned int Length, bool Resend = true);
 
private:
ManageSerialPort *TTY;
QTcpSocket *TcpSocket;
bool b_isOpen;
int i_Type;
sRxData RxData;
 
void new_Data(QString Data);
 
private slots:
void slot_newDataReceived(const QByteArray &dataReceived);
void slot_IP_Connected();
void slot_IP_Disconnect();
void slot_IP_ReadLine();
// void slot_Error(QAbstractSocket::SocketError Error);
 
signals:
void newData(sRxData RxData);
/QMK-Groundstation/trunk/Forms/mktool.cpp
1629,7 → 1629,7
 
Conn->Close();
 
ac_ConnectTTY->setText("Seriell Verbinden");
ac_ConnectTTY->setText("Kopter Verbinden");
le_Port->setEnabled(true);
 
Ticker->stop();
1636,9 → 1636,19
}
else
{
if (Conn->Open(le_Port->text()))
int i_Type;
if (le_Port->text().contains(QString("IP:")))
{
ac_ConnectTTY->setText("Seriell Trennen");
i_Type = C_IP;
}
else
{
i_Type = C_TTY;
}
 
if (Conn->Open(i_Type, le_Port->text()))
{
ac_ConnectTTY->setText("Kopter Trennen");
le_Port->setEnabled(false);
 
Conn->send_Cmd('v', ADDRESS_ALL, TX_Data, 0, true);
/QMK-Groundstation/trunk/Forms/mktool.ui
1729,13 → 1729,7
</spacer>
</item>
</layout>
<zorder>label_8</zorder>
<zorder>label_9</zorder>
<zorder>le_TarLong</zorder>
<zorder>le_TarLat</zorder>
<zorder>pb_FlyTo</zorder>
<zorder>verticalSpacer_2</zorder>
<zorder>te_KML</zorder>
</widget>
</item>
<item row="0" column="1" >
1864,13 → 1858,23
</rect>
</property>
</widget>
<widget class="QComboBox" name="cb_device" >
<property name="geometry" >
<rect>
<x>350</x>
<y>140</y>
<width>114</width>
<height>26</height>
</rect>
</property>
<property name="editable" >
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
<zorder>line_2</zorder>
<zorder>lb_Status</zorder>
<zorder>tab_Main</zorder>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
1878,7 → 1882,7
<x>0</x>
<y>0</y>
<width>699</width>
<height>25</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="menuProgramm" >
2092,7 → 2096,7
<normalon>:/Actions/Images/Actions/Seriell-OK.png</normalon>:/Actions/Images/Actions/Seriell-NO.png</iconset>
</property>
<property name="text" >
<string>Seriell Verbinden</string>
<string>Kopter Verbinden</string>
</property>
</action>
<action name="ac_RecordCSV" >
/QMK-Groundstation/trunk/global.h
56,7 → 56,7
static const int SLEEP = 500000;
 
static const QString QA_NAME = "QMK-Groundstation";
static const QString QA_VERSION_NR = "0.7.1f";
static const QString QA_VERSION_NR = "0.7.2b";
 
#ifdef _BETA_
static const QString QA_VERSION = QA_VERSION_NR + " (BETA)";
66,7 → 66,7
static const QString QA_HWVERSION = "FlightCtrl v0.71h & NaviCtrl v0.12i";
#endif
 
static const QString QA_DATE = "03.02.2009";
static const QString QA_DATE = "18.02.2009";
static const QString QA_YEAR = "2008-2009";
static const QString QA_AUTHOR = "Manuel Schrape";
static const QString QA_EMAIL = "manuel.schrape@gmx.de";