Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 158 → Rev 159

/QMK-Groundstation/trunk/Forms/mktool.cpp
29,6 → 29,7
#include "mktool.h"
#include "dlg_Config.h"
#include "dlg_Motortest.h"
#include "dlg_Preferences.h"
#include "../global.h"
#include "../ToolBox.h"
 
51,7 → 52,7
 
init_Plot();
 
Ticker->start(500);
Ticker->start(2000);
}
 
void MKTool::init_GUI()
116,6 → 117,8
 
// QFile-Instanz (Log-Datei)
CSVFile = new QFile("");
 
AllowSend = true;
}
 
void MKTool::init_Connections()
129,8 → 132,13
connect(pb_Read, SIGNAL(clicked()), this, SLOT(slot_GetParameter()));
connect(pb_Write, SIGNAL(clicked()), this, SLOT(slot_SetParameter()));
 
connect(pb_LCDup, SIGNAL(clicked()), this, SLOT(slot_LCD_UP()));
connect(pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN()));
 
// Actions
connect(ac_Config, SIGNAL(triggered()), this, SLOT(slot_ac_Config()));
connect(ac_Preferences, SIGNAL(triggered()), this, SLOT(slot_ac_Preferences()));
 
connect(ac_Motortest, SIGNAL(triggered()), this, SLOT(slot_ac_Motortest()));
connect(ac_StartPlotter, SIGNAL(triggered()), this, SLOT(slot_ac_StartPlotter()));
connect(ac_MehrDaten, SIGNAL(triggered()), this, SLOT(slot_ac_MehrDaten()));
295,11 → 303,6
else
TickerDiv = true;
 
if (ac_MehrDaten->isChecked())
{
send_Data('f', TX_Data, 0);
}
 
for (int a = 0; a < MaxTickerEvents; a++)
{
if (TickerEvent[a] == true)
313,12 → 316,15
serialPort->sendData(Temp);
}
break;
 
case 1 :
TX_Data[0] = 255;
TX_Data[1] = 255;
send_Data('h', TX_Data, 2, false);
TX_Data[0] = 0;
send_Data('p', ADDRESS_FC, TX_Data, 0, false);
break;
case 2 :
TX_Data[0] = LCD_Page;
TX_Data[1] = 0;
send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
break;
}
}
}
347,7 → 353,7
TX_Data[1] = Motor2;
TX_Data[2] = Motor3;
TX_Data[3] = Motor4;
send_Data('t', TX_Data, 4, false);
send_Data('t', ADDRESS_FC, TX_Data, 4, false);
}
 
void MKTool::slot_ac_Config()
392,6 → 398,16
}
}
 
void MKTool::slot_ac_Preferences()
{
dlg_Preferences *f_Preferences = new dlg_Preferences(this);
 
if (f_Preferences->exec()==QDialog::Accepted)
{
 
}
}
 
void MKTool::slot_ac_StartPlotter()
{
if (ac_StartPlotter->isChecked())
446,16 → 462,16
}
}
 
void MKTool::slot_ac_MehrDaten()
void MKTool::slot_ac_MehrDaten() // DONE 0.71g
{
if (ac_MehrDaten->isChecked())
{
Ticker->setInterval(100);
}
TX_Data[0] = 10;
send_Data('d', ADDRESS_ALL, TX_Data, 1, false); }
else
{
Ticker->setInterval(500);
}
TX_Data[0] = 50;
send_Data('d', ADDRESS_ALL, TX_Data, 1, false); }
}
 
void MKTool::slot_ac_About()
463,12 → 479,13
QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
}
 
void MKTool::slot_ac_GetLabels()
void MKTool::slot_ac_GetLabels() // DONE 0.71g
{
TX_Data[0] = 0;
send_Data('a', TX_Data, 1, false);
send_Data('a', ADDRESS_ALL, TX_Data, 1, false);
}
 
 
// Daten-Plotter
/////////////////
void MKTool::update_Plot()
822,7 → 839,7
return Combo->currentText().toInt();
}
 
void MKTool::store_ParameterSet(int Set)
void MKTool::store_ParameterSet(int Set) // DONE 0.71g
{
char *Name = le_SetName->text().toLatin1().data();
 
963,7 → 980,7
ParameterSet[Set][P_NAV_RADIUS] = get_Value(cb_13_3);
}
 
void MKTool::slot_SaveParameter()
void MKTool::slot_SaveParameter() // DONE 0.71g
{
int Set = sb_Set->value() + 5;
 
1086,7 → 1103,7
}
}
 
void MKTool::slot_LoadParameter()
void MKTool::slot_LoadParameter() // DONE 0.71g
{
QString Filename = QFileDialog::getOpenFileName(this, "Mikrokopter Parameter laden", Settings->DIR.Parameter, "Mikrokopter Parameter(*.mkp);;Alle Dateien (*)");
 
1218,7 → 1235,7
}
}
 
void MKTool::show_ParameterSet(int Set)
void MKTool::show_ParameterSet(int Set) // DONE 0.71g
{
char Name[12];
for (int a = 0; a < 12; a++)
1391,44 → 1408,90
 
}
 
void MKTool::slot_TabChanged(int Tab)
void MKTool::slot_TabChanged(int Tab) // DONE 0.71g
{
Tab = Tab;
 
if ((tab_Main->currentWidget()->objectName() == QString("Tab_2")) && (tab_Par->currentIndex() == 1))
{
TX_Data[0] = 0;
send_Data('p', ADDRESS_FC, TX_Data, 0, true);
 
Ticker->setInterval(500);
TickerEvent[1] = true;
// Poll->start(500);
}
else
{
Ticker->setInterval(2000);
TickerEvent[1] = false;
// Poll->stop();
}
 
if ((tab_Main->currentWidget()->objectName() == QString("Tab_4")))
{
TX_Data[0] = 0;
TX_Data[1] = 0;
send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
 
Ticker->setInterval(500);
TickerEvent[2] = true;
}
else
{
Ticker->setInterval(2000);
TickerEvent[2] = false;
}
 
}
 
void MKTool::slot_GetParameter()
void MKTool::slot_LCD_UP() // DONE 0.71g
{
if (LCD_Page == LCD_MAX_Page)
TX_Data[0] = 0;
else
TX_Data[0] = LCD_Page + 1;
 
TX_Data[1] = 0;
send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
}
 
void MKTool::slot_LCD_DOWN() // DONE 0.71g
{
if (LCD_Page == 0)
TX_Data[0] = LCD_MAX_Page;
else
TX_Data[0] = LCD_Page - 1;
 
TX_Data[1] = 0;
send_Data('l', ADDRESS_ALL, TX_Data, 1, true);
}
 
void MKTool::slot_GetParameter() // DONE 0.71g
{
TX_Data[0] = sb_Set->value();
TX_Data[1] = 0;
send_Data('q', TX_Data, 1);
send_Data('q', ADDRESS_FC, TX_Data, 1);
}
 
void MKTool::slot_SetParameter()
void MKTool::slot_SetParameter() // DONE 0.71g
{
store_ParameterSet(sb_Set->value());
 
for (int a = 0; a < 150; a++)
TX_Data[0] = sb_Set->value();
TX_Data[1] = VERSION_SETTINGS;
 
for (int a = 0; a < MaxParameter; a++)
{
TX_Data[a] = ParameterSet[sb_Set->value()][a];
TX_Data[a + 2] = ParameterSet[sb_Set->value()][a];
}
 
store_ParameterSet(sb_Set->value());
 
char Set = 'k' + sb_Set->value();
send_Data(Set, TX_Data, MaxParameter, false);
send_Data('s', ADDRESS_FC, TX_Data, MaxParameter + 2, false);
}
 
 
// Save GUI-Settings
////////////////////
void MKTool::write_Settings()
{
QBitArray TabViews(6);
1453,6 → 1516,7
Setting.endGroup();
}
 
 
// Debug-Daten anzeigen und Aufzeichnen
///////////////////////////////////////
void MKTool::write_CSV()
1470,11 → 1534,11
Out << "\n";
}
 
void MKTool::slot_RecordCSV()
void MKTool::slot_RecordCSV() // DONE 0.71g
{
if (!CSVFile->isOpen())
{
QString Filename = Settings->DIR.Logging + QDate::currentDate().toString(("yyyy-MM-dd")) + " -- " + QTime::currentTime().toString("hh-mm") + ".csv";
QString Filename = Settings->DIR.Logging + Mode.Hardware + " - " + QDate::currentDate().toString(("yyyy-MM-dd")) + " -- " + QTime::currentTime().toString("hh-mm") + ".csv";
 
CSVFile = new QFile(Filename);
if (!CSVFile->exists())
1574,11 → 1638,12
le_A_31->setText(QString("%1").arg(AnalogData[31]));
}
 
 
// Seriel-Port Bereich, Befehle senden und Daten empfangen
//////////////////////////////////////////////////////////
 
// Neues Datenpacket empfangen -> Verarbeiten
void MKTool::new_RXData(sRxData RX)
void MKTool::new_RXData(sRxData RX) // DONE 0.71g
{
 
if (LastSend.length() > 2)
1587,53 → 1652,46
 
switch(RX.Input[2])
{
case '0' :
case 'L' : // DONE 0.71g
if (ToolBox::Decode64(RX, true))
{
le_LCD0->setText(ToolBox::DataToString(RX.Decode));
int LCD[150];
memcpy(LCD,RX.Decode, sizeof(RX.Decode));
 
LCD_Page = RX.Decode[0];
LCD_MAX_Page = RX.Decode[1];
 
le_LCD0->setText(ToolBox::Data2QString(LCD,2,22));
le_LCD1->setText(ToolBox::Data2QString(LCD,22,42));
le_LCD2->setText(ToolBox::Data2QString(LCD,42,62));
le_LCD3->setText(ToolBox::Data2QString(LCD,62,82));
 
TickerEvent[0] = false;
}
break;
case '1' :
case 'P' : // DONE 0.71g
if (ToolBox::Decode64(RX, true))
{
le_LCD1->setText(ToolBox::DataToString(RX.Decode));
pb_K1->setValue(ToolBox::Data2Int(RX.Decode, 0,true));
pb_K2->setValue(ToolBox::Data2Int(RX.Decode, 2,true));
pb_K3->setValue(ToolBox::Data2Int(RX.Decode, 4,true));
pb_K4->setValue(ToolBox::Data2Int(RX.Decode, 6,true));
pb_K5->setValue(ToolBox::Data2Int(RX.Decode, 8,true));
pb_K6->setValue(ToolBox::Data2Int(RX.Decode, 10,true));
pb_K7->setValue(ToolBox::Data2Int(RX.Decode, 12,true));
pb_K8->setValue(ToolBox::Data2Int(RX.Decode, 14,true));
}
break;
case '2' :
case 'A' : // DONE 0.71g
if (ToolBox::Decode64(RX, true))
{
le_LCD2->setText(ToolBox::DataToString(RX.Decode));
}
break;
case '3' :
if (ToolBox::Decode64(RX, true))
{
le_LCD3->setText(ToolBox::DataToString(RX.Decode));
}
break;
case '4' :
if (ToolBox::Decode64(RX, false))
{
pb_K1->setValue(RX.Decode[1]);
pb_K2->setValue(RX.Decode[2]);
pb_K3->setValue(RX.Decode[3]);
pb_K4->setValue(RX.Decode[4]);
pb_K5->setValue(RX.Decode[5]);
pb_K6->setValue(RX.Decode[6]);
pb_K7->setValue(RX.Decode[7]);
pb_K8->setValue(RX.Decode[8]);
}
break;
case 'A' :
if (ToolBox::Decode64(RX, true))
{
int Position = RX.Input[1] - 48;
int Position = RX.Decode[0];
if (Position < 32)
{
Settings->Analog[Position].Name = ToolBox::DataToString(RX.Decode);
Settings->Analog[Position].Name = ToolBox::Data2QString(RX.Decode,1,17).trimmed();
Position ++;
TX_Data[0] = Position;
send_Data('a', TX_Data, 1, false);
send_Data('a', ADDRESS_ALL, TX_Data, 1, false);
}
if (Position == 32)
{
1646,7 → 1704,7
}
}
break;
case 'D' :
case 'D' : // DONE 0.71g
if (ToolBox::Decode64(RX, true))
{
for (int i = 0; i < MaxAnalog; i++)
1656,44 → 1714,68
show_DebugData();
}
break;
case 'L' :
case 'M' :
case 'N' :
case 'O' :
case 'P' :
case 'Q' : // DONE 0.71g
TickerEvent[0] = false;
 
ToolBox::Decode64(RX, true);
memcpy(ParameterSet[sb_Set->value()],RX.Decode, sizeof(RX.Decode));
show_ParameterSet(sb_Set->value());
 
if (RX.Decode[1] == VERSION_SETTINGS)
{
int Settings_ID = RX.Decode[0];
for (int a = 0; a < MaxParameter; a++)
{
ParameterSet[Settings_ID][a] = RX.Decode[a + 2];
}
// memcpy(ParameterSet[Settings_ID],RX.Decode, sizeof(RX.Decode));
show_ParameterSet(Settings_ID);
}
else
{
pb_Read->setDisabled(true);
pb_Write->setDisabled(true);
 
QMessageBox::warning(this, QA_NAME,
"Versionen inkompatibel. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
}
 
break;
case 'V' :
case 'S' : // DONE 0.71g
TickerEvent[0] = false;
qDebug("Settings set...!!!");
break;
case 'V' : // DONE 0.71g
TickerEvent[0] = false;
 
ToolBox::Decode64(RX, true);
 
Mode.ID = RX.Input[1];
Mode.ID = RX.Input[1] - 'a';
Mode.VERSION_MAJOR = RX.Decode[0];
Mode.VERSION_MINOR = RX.Decode[1];
Mode.VERSION_PATCH = RX.Decode[4];
Mode.VERSION_SERIAL_MAJOR = RX.Decode[2];
Mode.VERSION_SERIAL_MINOR = RX.Decode[3];
 
Mode.Hardware = HardwareType[Mode.ID];
Mode.Version = QString("%1").arg(RX.Decode[0]) + "." + QString("%1").arg(RX.Decode[1]) + QString(RX.Decode[4] + 'a');
Mode.Compatible = RX.Decode[2];
 
setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + Mode.Hardware + " " + Mode.Version);
 
if (Mode.ID == 1)
if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
{
if (RX.Decode[2] != FC_VERSION)
{
pb_Read->setDisabled(true);
pb_Write->setDisabled(true);
AllowSend = false;
QMessageBox::warning(this, QA_NAME,
"Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,", QMessageBox::Ok);
}
 
QMessageBox::warning(this, QA_NAME,
QA_NAME + " und Flight-Control inkompatibel.\nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
}
else
TX_Data[0] = 50;
send_Data('d', ADDRESS_ALL, TX_Data, 1, false);
 
if (Mode.ID == ADDRESS_FC)
{
{
TX_Data[0] = 1;
TX_Data[0] = 0xff;
TX_Data[1] = 0;
send_Data('q', TX_Data, 1);
send_Data('q', ADDRESS_FC, TX_Data, 1);
}
}
else
1701,8 → 1783,8
pb_Read->setDisabled(true);
pb_Write->setDisabled(true);
 
QMessageBox::warning(this, QA_NAME,
"Keine Verbindung zur FlightCtrl. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
// QMessageBox::warning(this, QA_NAME,
// "Keine Verbindung zur FlightCtrl. \nParameterbearbeitung nicht moeglich.", QMessageBox::Ok);
}
break;
}
1709,7 → 1791,7
}
 
// Neue Daten an der Schnittstelle
void MKTool::slot_newDataReceived(const QByteArray &dataReceived)
void MKTool::slot_newDataReceived(const QByteArray &dataReceived) // DONE 0.71g
{
const char *RXt;
RXt = dataReceived.data();
1764,9 → 1846,8
TX_Data[1] = 0;
TX_Data[2] = 0;
TX_Data[3] = 0;
send_Data('t', TX_Data, 4, false);
send_Data('t', ADDRESS_FC, TX_Data, 4, false);
 
// timer->stop();
serialPort->close();
pb_Open->setText("Verbinden");
ac_ConnectTTY->setText("Verbinden");
1792,7 → 1873,8
{
serialPort->receiveData();
 
send_Data('v', TX_Data, 0, true);
send_Data('v', ADDRESS_ALL, TX_Data, 0, true);
 
pb_Open->setText("Trennen");
ac_ConnectTTY->setText("Trennen");
pb_Open->setIcon(Icons[8]);
1802,13 → 1884,13
}
 
// Daten senden
void MKTool::send_Data(char CMD, char Data[150],unsigned int Length, bool Resend)
void MKTool::send_Data(char CMD, int Address, char Data[150],unsigned int Length, bool Resend) // DONE 0.71g
{
if (serialPort->isOpen())
if (serialPort->isOpen() && AllowSend)
{
QString TX_Data = ToolBox::Encode64(Data, Length);
 
TX_Data = QString("#0") + QString(CMD) + TX_Data;
TX_Data = QString("#") + (QString('a' + Address)) + QString(CMD) + TX_Data;
 
// qDebug(TX_Data.toLatin1().data());
 
1816,7 → 1898,6
 
// qDebug(TX_Data.toLatin1().data());
 
 
if (Resend)
{
LastSend = TX_Data;