Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 442 → Rev 449

/QMK-Groundstation/branches/libMK/Classes/ToolBox.cpp
49,9 → 49,10
}*/
 
// Datensatz nach QString
QString ToolBox::dataToQString(int Data[150], int Start, int End)
QString ToolBox::dataToQString(char data[MAX_DATA_SIZE], int start, int end)
{
return QString(Parser::dataToString(Data, Start, End).c_str());
return QString(data);
//return QString(Parser::dataToString(data, start, end));
}
 
// Alle Icons
/QMK-Groundstation/branches/libMK/Classes/ToolBox.h
27,7 → 27,7
class ToolBox
{
public :
static QString dataToQString(int Data[150], int Start = 0, int End = 150);
static QString dataToQString(char data[MAX_DATA_SIZE], int Start = 0, int End = 150);
static QIcon Icon(int ID);
//static QString get_Float(long Wert, int Count);
static void wait(int Time);
/QMK-Groundstation/branches/libMK/Classes/cConnection.cpp
44,7 → 44,7
{
//Data = Data;
 
while ((RxData.str.size() > 1) && (RxData.str.substr(1,1) == string("#")))
/* while ((RxData.str.size() > 1) && (RxData.str.substr(1,1) == string("#")))
{
RxData.str = RxData.str.substr(1, RxData.str.size());
}
58,11 → 58,12
{
emit(showTerminal(2, QString(RxData.str.c_str())));
}
 
*/
}
 
void cConnection::slot_newDataReceived(const QByteArray &dataReceived)
{
/*
const char *RXt;
RXt = dataReceived.data();
int a = 0;
80,6 → 81,7
}
a++;
}
*/
}
 
bool cConnection::isOpen()
181,26 → 183,25
if (Input[z] == '\r')
{
new_Data(QString(""));
RxData.str = string("");
//RxData.str = string("");
}
else
{
RxData.str = RxData.str + Input[z].toAscii();
//RxData.str = RxData.str + Input[z].toAscii();
}
}
}
 
bool cConnection::send_Cmd(char CMD, int Address, char Data[150],unsigned int Length, bool Resend)
bool cConnection::send_Cmd(char CMD, int Address, char Data[MAX_DATA_SIZE],unsigned int Length, bool Resend)
{
if (b_isOpen)
if (b_isOpen) //is_connected()
{
QByteArray Temp;
string TX_Data;
 
/*
if (CMD != '#')
{
TX_Data = Parser::encode64(Data, Length);
 
string TX_Data;
char addr = 'a' + Address;
TX_Data = string("#") + (string(&addr)) + string(&CMD) + TX_Data;
TX_Data = Parser::add_CRC(TX_Data) + '\r';
212,6 → 213,7
o_Timer->start(2000);
s_ReSend = Temp;
}
emit(showTerminal(3, QString(TX_Data.c_str())));
}
else
{
220,7 → 222,7
Temp[a] = Data[a];
}
}
 
*/
switch(i_Type)
{
case C_TTY :
234,8 → 236,6
}
break;
}
 
emit(showTerminal(3, QString(TX_Data.c_str())));
}
return true;
}
/QMK-Groundstation/branches/libMK/Classes/cConnection.h
40,7 → 40,7
bool isOpen();
bool Open(int Typ, QString Address);
bool Close();
bool send_Cmd(char CMD, int Address, char Data[150],unsigned int Length, bool Resend = true);
bool send_Cmd(char CMD, int Address, char Data[MAX_DATA_SIZE],unsigned int Length, bool Resend = true);
void stop_ReSend();
 
private:
52,7 → 52,7
 
bool b_isOpen;
int i_Type;
sRxData RxData;
// sRxData RxData;
 
void new_Data(QString Data);
 
66,7 → 66,7
// void slot_Error(QAbstractSocket::SocketError Error);
 
signals:
void newData(sRxData RxData);
// void newData(sRxData RxData);
void showTerminal(int Typ, QString Text);
};
 
/QMK-Groundstation/branches/libMK/Classes/cSettings.cpp
82,7 → 82,7
// Config der Analogwert-Anzeige (Plotter / CVS)
void cSettings::write_Settings_Analog(int ID)
{
QString Hardware = QString(HardwareType[ID].c_str());
QString Hardware = QString(HardwareType[ID]);
 
QSettings Setting("KeyOz-Net", "QMK-Groundstation");
 
97,7 → 97,7
QBitArray Def_View;
Def_View.fill(true,MaxAnalog);
 
QString Hardware = QString(HardwareType[ID].c_str());
QString Hardware = QString(HardwareType[ID]);
 
QSettings Setting("KeyOz-Net", "QMK-Groundstation");
 
110,7 → 110,7
// Labels der Analogwerte.
void cSettings::write_Settings_AnalogLabels(int ID)
{
QString Hardware = QString(HardwareType[ID].c_str());
QString Hardware = QString(HardwareType[ID]);
 
QSettings Setting("KeyOz-Net", "QMK-Groundstation-Labels");
 
125,7 → 125,7
 
void cSettings::read_Settings_AnalogLabels(int ID)
{
QString Hardware = QString(HardwareType[ID].c_str());
QString Hardware = QString(HardwareType[ID]);
 
QSettings Setting("KeyOz-Net", "QMK-Groundstation-Labels");
 
/QMK-Groundstation/branches/libMK/Forms/dlg_Config.cpp
94,7 → 94,7
{
Settings = Set;
 
lb_Hardware->setText(QString(HardwareType[ID].c_str()));
lb_Hardware->setText(QString(HardwareType[ID]));
 
for (int a = 0; a < MaxAnalog; a++)
{
/QMK-Groundstation/branches/libMK/Forms/dlg_LCD.cpp
23,10 → 23,10
setupUi(this);
}
 
void dlg_LCD::show_Data(int *Data)
void dlg_LCD::show_Data(char *data)
{
le_LCD0->setText(ToolBox::dataToQString(Data,2,22));
le_LCD1->setText(ToolBox::dataToQString(Data,22,42));
le_LCD2->setText(ToolBox::dataToQString(Data,42,62));
le_LCD3->setText(ToolBox::dataToQString(Data,62,82));
le_LCD0->setText(ToolBox::dataToQString(data,2,22));
le_LCD1->setText(ToolBox::dataToQString(data,22,42));
le_LCD2->setText(ToolBox::dataToQString(data,42,62));
le_LCD3->setText(ToolBox::dataToQString(data,62,82));
}
/QMK-Groundstation/branches/libMK/Forms/dlg_LCD.h
30,7 → 30,7
 
public:
dlg_LCD(QWidget *parent = 0);
void show_Data(int *Data);
void show_Data(char * data);
};
 
#endif // DLG_LCD_H
/QMK-Groundstation/branches/libMK/Forms/dlg_MotorMixer.cpp
76,10 → 76,10
}
 
// Motordaten übernehmen.
//FIXME: put this in libMK/Handler.cpp and fill motor values in KopterData
/*
void dlg_MotorMixer::set_MotorConfig(sRxData RX)
{
//FIXME: put this in libMK/Handler.cpp and fill motor values in KopterData
/*
int Pos = 0;
 
MixerName = ToolBox::dataToQString(RX.decode, 1, 12);
96,8 → 96,8
}
 
set_MotorData();
}
*/
}
 
// Motordaten aus GUI übernehmen
void dlg_MotorMixer::get_MotorData()
104,8 → 104,7
{
sMotorData motorData;
 
char * mixerName = le_NAME->text().toAscii().data();
motorData.mixer_name = string(mixerName);
motorData.mixer_name = le_NAME->text().toAscii().data();
 
int gas[MAX_MOTORS] = {
sb_GAS_1->value(), sb_GAS_2->value(), sb_GAS_3->value(), sb_GAS_4->value(),
140,7 → 139,7
void dlg_MotorMixer::set_MotorData()
{
sMotorData motorData = handler->data->motor;
le_NAME->setText(motorData.mixer_name.c_str());
le_NAME->setText(motorData.mixer_name);
 
sb_GAS_1->setValue(motorData.mixer_gas[0]);
sb_GAS_2->setValue(motorData.mixer_gas[1]);
361,7 → 360,7
QSettings Setting(Filename, QSettings::IniFormat);
 
Setting.beginGroup("Info");
Setting.setValue("Name", data->motor.mixer_name.c_str());
Setting.setValue("Name", data->motor.mixer_name);
Setting.setValue("Version", data->motor.mixer_version);
Setting.endGroup();
 
/QMK-Groundstation/branches/libMK/Forms/dlg_MotorMixer.h
36,7 → 36,7
public:
dlg_MotorMixer(QWidget *parent = 0);
void set_Objects(Handler *handler, cSettings *t_Settings);
void set_MotorConfig(sRxData RX);
// void set_MotorConfig(sRxData RX);
void read_Mixer();
 
private:
/QMK-Groundstation/branches/libMK/Forms/mktool.cpp
61,6 → 61,7
 
// Tab mit Debug-Elementen verbergen
tab_Main->removeTab(6);
 
// Develop - Nicht gebrauchte sachen abschalten.
pb_SettingsReset->hide();
pb_Flash->hide();
201,7 → 202,7
data = new KopterData();
 
//new QT-Communication object
com = new QTCommunication();
com = new QTSerialCommunication();
 
//create handler that handles incomming data
handler = new Handler(com, data);
419,13 → 420,13
 
void MKTool::slot_Test()
{
sRxData RX;
// sRxData RX;
 
RX.str = IN->text().toLatin1().data();
// RX.str = IN->text().toLatin1().data();
 
RX.input = (char *)RX.str.c_str();
// RX.input = (char *)RX.str.c_str();
 
slot_newData(RX);
// slot_newData(RX);
}
 
// KML-Datei nach Wegpunkt parsen
770,8 → 771,6
 
void MKTool::slot_MAP_SetWayPoints(QList<sWayPoint> l_WayPoints)
{
//FIXME: Put this in libMK/Handler.cpp or libMK/NaviCtrl.cpp
 
double Longitude, Latitude;
 
// delete waypoint-list
1337,6 → 1336,8
}
}
 
//FIXME: HERE!
/*
void MKTool::new_NaviData(sRxData RX)
{
// qDebug("Navi-Data");
1423,12 → 1424,13
QMK_Server->NewPosition(naviData);
}
}
 
*/
// Kopter-Kommunikations-Bereich, Befehle senden und Daten empfangen
////////////////////////////////////////////////////////////////////
 
// Neues Datenpacket empfangen -> Verarbeiten
void MKTool::slot_newData(sRxData RX) // DONE 0.71g
//FIXME: HERE!
/*void MKTool::slot_newData(sRxData RX) // DONE 0.71g
{
//handler->receiveData(RX)
 
1440,7 → 1442,7
 
slot_showTerminal(1, QString(RX.str.c_str()));
}
 
*/
void MKTool::slot_showTerminal(int Typ, QString Text)
{
switch(Typ)
/QMK-Groundstation/branches/libMK/Forms/mktool.h
54,7 → 54,7
//quadcopter lib stuff
#include "../libMK/Handler.h"
#include "../libMK/Communication.h"
#include "../libMK/QTCommunication.h"
#include "../libMK/QTSerialCommunication.h"
 
class QextSerialPort;
 
150,7 → 150,7
void update_Plot();
void config_Plot();
 
void new_NaviData(sRxData RX);
// void new_NaviData(sRxData RX);
void parse_TargetKML();
 
// show and save debug/log
213,7 → 213,7
void slot_UpdateShell();
 
// Seriell-Port Slots
void slot_newData(sRxData RX);
// void slot_newData(sRxData RX);
void slot_OpenPort();
 
void slot_TabChanged(int Tab);
/QMK-Groundstation/branches/libMK/Forms/wdg_Settings.cpp
706,7 → 706,7
{
store_ParameterSet(sb_Set->value());
 
char *TX_Data = new char[150];
char *TX_Data = new char[MAX_DATA_SIZE];
 
TX_Data[0] = sb_Set->value();
TX_Data[1] = VERSION_SETTINGS;
/QMK-Groundstation/branches/libMK/Logger/CSVLogger.cpp
51,7 → 51,7
{
if (!csvfile->isOpen())
{
QString mode_name = QString(data->mode.hardware.c_str());
QString mode_name = QString(data->mode.hardware);
 
if (mode_name.size() == 0)
{
/QMK-Groundstation/branches/libMK/eeepc.pro
8,3 → 8,7
INCLUDEPATH += $(HOME)/include /usr/include/qwt-qt4
 
include(global.pri)
HEADERS += testing/LibMKTest.h
 
SOURCES += testing/LibMKTest.cpp
 
/QMK-Groundstation/branches/libMK/libMK/QTCommunication.cpp
File deleted
\ No newline at end of file
/QMK-Groundstation/branches/libMK/libMK/Communication.cpp
File deleted
\ No newline at end of file
/QMK-Groundstation/branches/libMK/libMK/QTCommunication.h
File deleted
\ No newline at end of file
/QMK-Groundstation/branches/libMK/libMK/Communication.h
File deleted
\ No newline at end of file
/QMK-Groundstation/branches/libMK/libMK/Handler.cpp
82,7 → 82,7
}
 
/**
* send a waypoint to the NaviCtrl (the copter will fly to the position emidiately)
* send a waypoint to the NaviCtrl (the MikroKopter will fly to the position emidiately)
*/
void Handler::send_waypoint(Waypoint_t desired_pos) {
com->send_cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
189,281 → 189,252
/**
* receive data
*/
void Handler::receive_data(sRxData RX) {
//extract hardware ID from received Data
int hardwareID = RX.input[1] - 'a';
//Parser::decode64(data);
void Handler::receive_data(int hardwareID, int cmd, char * data) {
switch(hardwareID)
{
case ADDRESS_FC :
switch(RX.input[2])
switch(cmd)
{
// Motor-Mixer
case 'N' :
if (Parser::decode64(RX))
{
//if (Parser::decode64(RX))
//{
com->stop_resend();
 
if (RX.decode[0] == VERSION_MIXER)
//decoded data
if (data[0] == VERSION_MIXER)
{
//f_MotorMixer->set_MotorConfig(RX);
}
}
break;
//}
break;
// Motor-Mixer Schreib-Bestätigung
case 'M' :
if (Parser::decode64(RX))
com->stop_resend();
 
if (data[0] == 1)
{
com->stop_resend();
 
if (RX.decode[0] == 1)
{
//lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
}
//lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
}
break;
break;
 
// Stick-Belegung der Fernsteuerung
case 'P' : // DONE 0.71g
if (Parser::decode64(RX))
{
/*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true));
f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode, 4,true));
f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode, 6,true));
f_Settings->pb_K4->setValue(Parser::dataToInt(RX.decode, 8,true));
f_Settings->pb_K5->setValue(Parser::dataToInt(RX.decode, 10 ,true));
f_Settings->pb_K6->setValue(Parser::dataToInt(RX.decode, 12,true));
f_Settings->pb_K7->setValue(Parser::dataToInt(RX.decode, 14,true));
f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/
}
break;
/*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true));
f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode, 4,true));
f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode, 6,true));
f_Settings->pb_K4->setValue(Parser::dataToInt(RX.decode, 8,true));
f_Settings->pb_K5->setValue(Parser::dataToInt(RX.decode, 10 ,true));
f_Settings->pb_K6->setValue(Parser::dataToInt(RX.decode, 12,true));
f_Settings->pb_K7->setValue(Parser::dataToInt(RX.decode, 14,true));
f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/
break;
// Settings lesen
case 'Q' : // DONE 0.71g
if (Parser::decode64(RX))
com->stop_resend();
 
if (data[1] == VERSION_SETTINGS)
{
com->stop_resend();
 
if (RX.decode[1] == VERSION_SETTINGS)
int Settings_ID = data[0];
/*for (int a = 0; a < MaxParameter; a++)
{
int Settings_ID = RX.decode[0];
/*for (int a = 0; a < MaxParameter; a++)
{
FCSettings[a] = RX.decode[a + 2];
}
f_Settings->show_FCSettings(Settings_ID, FCSettings);
f_Settings->pb_Read->setEnabled(true);
f_Settings->pb_Write->setEnabled(true);*/
FCSettings[a] = RX.decode[a + 2];
}
else
{
/*f_Settings->pb_Read->setDisabled(true);
f_Settings->pb_Write->setDisabled(true);
f_Settings->show_FCSettings(Settings_ID, FCSettings);
f_Settings->pb_Read->setEnabled(true);
f_Settings->pb_Write->setEnabled(true);*/
}
else
{
/*f_Settings->pb_Read->setDisabled(true);
f_Settings->pb_Write->setDisabled(true);
 
QString name = QString("Versionen inkompatibel.\n") +
QString("Version von GroundStation benoetigt: ") +
QString(VERSION_SETTINGS) +
QString("\nVersion auf der FlightCtrl: ") +
QString(RX.decode[1]) +
QString("\nParameterbearbeitung nicht moeglich.");
QMessageBox::warning(this, QA_NAME,
name, QMessageBox::Ok);*/
}
QString name = QString("Versionen inkompatibel.\n") +
QString("Version von GroundStation benoetigt: ") +
QString(VERSION_SETTINGS) +
QString("\nVersion auf der FlightCtrl: ") +
QString(RX.decode[1]) +
QString("\nParameterbearbeitung nicht moeglich.");
QMessageBox::warning(this, QA_NAME,
name, QMessageBox::Ok);*/
}
break;
break;
// Settings written
case 'S' : // DONE 0.71g
com->stop_resend();
//TODO: QMessagebox("settings written successful") ?
break;
break;
}
 
case ADDRESS_NC :
switch(RX.input[2])
switch(cmd)
{
// Navigationsdaten
case 'O' : // NOT DONE 0.12h
if (Parser::decode64(RX))
{
//new_NaviData(RX);
}
break;
//new_NaviData(RX);
break;
}
// case ADDRESS_MK3MAG :
 
default :
switch(RX.input[2])
switch(cmd)
{
// LCD-Anzeige
case 'L' : // DONE 0.71g
if (Parser::decode64(RX))
{
com->stop_resend();
com->stop_resend();
 
/*int LCD[150];
memcpy(LCD,RX.decode, sizeof(RX.decode));
/*int LCD[150];
memcpy(LCD,RX.decode, sizeof(RX.decode));
 
f_LCD->show_Data(LCD);
f_LCD->show_Data(LCD);
 
LCD_Page = RX.decode[0];
LCD_MAX_Page = RX.decode[1];
*/
}
break;
LCD_Page = RX.decode[0];
LCD_MAX_Page = RX.decode[1];
*/
break;
// Analoglabels
case 'A' : // DONE 0.71g
if (Parser::decode64(RX))
{
com->stop_resend();
com->stop_resend();
 
int Position = RX.decode[0];
if (Position != 31)
//check position
if (data[0] != 31) {
/*
Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed();
if (Settings->Analog1.Label[Position] == "")
{
/*
Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed();
if (Settings->Analog1.Label[Position] == "")
{
Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position);
}
Position ++;
TX_Data[0] = Position;
o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);*/
Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position);
}
if (Position == 31)
Position ++;
TX_Data[0] = Position;
o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);*/
} else {
/*
for (int a = 0; a < MaxAnalog; a++)
{
/*
for (int a = 0; a < MaxAnalog; a++)
{
lb_Analog[a]->setText(Settings->Analog1.Label[a]);
}
Settings->Analog1.Version = QString(Mode.Version);
Settings->write_Settings_AnalogLabels(HardwareID);
config_Plot();*/
lb_Analog[a]->setText(Settings->Analog1.Label[a]);
}
Settings->Analog1.Version = QString(Mode.Version);
Settings->write_Settings_AnalogLabels(HardwareID);
config_Plot();*/
}
break;
break;
// Debug-Daten
case 'D' : // DONE 0.71g
if (Parser::decode64(RX))
{
for (int i = 0; i < MaxAnalog; i++)
{
//AnalogData[i] = Parser::dataToInt(RX.decode, (i * 2) + 2);
}
//show_DebugData();
for (int i = 0; i < MaxAnalog; i++) {
//AnalogData[i] = Parser::dataToInt(RX.decode, (i * 2) + 2);
}
break;
//show_DebugData();
break;
// Version
case 'V' : // DONE 0.71h
if (Parser::decode64(RX))
{
com->stop_resend();
/*
Mode.ID = HardwareID;
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];
com->stop_resend();
/*
Mode.ID = HardwareID;
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];
//TODO: Funktion im Handler get_version() oder sowas
QString version = QString("%1").arg(RX.decode[0]) + "." +
QString("%1").arg(RX.decode[1]) +
QString(RX.decode[4] + 'a');
Mode.Version = version.toLatin1().data;
setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " +
Mode.Hardware + " " +
Mode.Version);
Mode.Hardware = HardwareType[Mode.ID];
//TODO: Funktion im Handler get_version() oder sowas
QString version = QString("%1").arg(RX.decode[0]) + "." +
QString("%1").arg(RX.decode[1]) +
QString(RX.decode[4] + 'a');
Mode.Version = version.toLatin1().data;
setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " +
Mode.Hardware + " " +
Mode.Version);
 
if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
{
if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
{
// AllowSend = false;
QMessageBox::warning(this, QA_NAME,
tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok);
}
QMessageBox::warning(this, QA_NAME,
tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok);
}
 
if (ac_NoDebug->isChecked())
if (ac_NoDebug->isChecked())
{
TX_Data[0] = 0;
}
else
if (ac_FastDebug->isChecked())
{
TX_Data[0] = Settings->Data.Debug_Fast / 10;
}
else
{
TX_Data[0] = Settings->Data.Debug_Slow / 10;
}
 
o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
 
// Wenn MK3MAG dann andauernd Daten neu anfragen.
if (Mode.ID == ADDRESS_MK3MAG)
{
TickerEvent[3] = true;
rb_SelMag->setChecked(true);
}
 
// Wenn NaviCtrl dann hier.
if (Mode.ID == ADDRESS_NC)
{
rb_SelNC->setChecked(true);
 
if (ac_NoNavi->isChecked())
{
TX_Data[0] = 0;
}
else
if (ac_FastDebug->isChecked())
if (ac_FastNavi->isChecked())
{
TX_Data[0] = Settings->Data.Debug_Fast / 10;
TX_Data[0] = Settings->Data.Navi_Fast / 10;
}
else
{
TX_Data[0] = Settings->Data.Debug_Slow / 10;
TX_Data[0] = Settings->Data.Navi_Slow / 10;
}
 
o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
}
 
// Wenn MK3MAG dann andauernd Daten neu anfragen.
if (Mode.ID == ADDRESS_MK3MAG)
{
TickerEvent[3] = true;
rb_SelMag->setChecked(true);
}
 
// Wenn NaviCtrl dann hier.
if (Mode.ID == ADDRESS_NC)
// Wenn FlightCtrl dann Settings abfragen.
if (Mode.ID == ADDRESS_FC)
{
rb_SelFC->setChecked(true);
{
rb_SelNC->setChecked(true);
TX_Data[0] = 0xff;
TX_Data[1] = 0;
 
if (ac_NoNavi->isChecked())
{
TX_Data[0] = 0;
}
else
if (ac_FastNavi->isChecked())
{
TX_Data[0] = Settings->Data.Navi_Fast / 10;
}
else
{
TX_Data[0] = Settings->Data.Navi_Slow / 10;
}
 
o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
}
 
 
// Wenn FlightCtrl dann Settings abfragen.
if (Mode.ID == ADDRESS_FC)
{
rb_SelFC->setChecked(true);
{
TX_Data[0] = 0xff;
TX_Data[1] = 0;
 
// DEP: Raus wenn Resend implementiert.
// DEP: Raus wenn Resend implementiert.
// ToolBox::Wait(SLEEP);
o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
qDebug("FC - Get Settings");
}
o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
qDebug("FC - Get Settings");
}
// Wenn nicht Lesen und Schreiben der Settings deaktivieren.
else
{
f_Settings->pb_Read->setDisabled(true);
f_Settings->pb_Write->setDisabled(true);
}
}
// Wenn nicht Lesen und Schreiben der Settings deaktivieren.
else
{
f_Settings->pb_Read->setDisabled(true);
f_Settings->pb_Write->setDisabled(true);
}
 
Settings->read_Settings_Analog(HardwareID);
Settings->read_Settings_AnalogLabels(HardwareID);
Settings->read_Settings_Analog(HardwareID);
Settings->read_Settings_AnalogLabels(HardwareID);
 
if (Settings->Analog1.Version != QString(Mode.Version))
{
lb_Status->setText(tr("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."));
slot_ac_GetLabels();
}
else
for (int a = 0; a < MaxAnalog; a++)
{
lb_Analog[a]->setText(Settings->Analog1.Label[a]);
}
config_Plot();*/
if (Settings->Analog1.Version != QString(Mode.Version))
{
lb_Status->setText(tr("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."));
slot_ac_GetLabels();
}
break;
else
for (int a = 0; a < MaxAnalog; a++)
{
lb_Analog[a]->setText(Settings->Analog1.Label[a]);
}
config_Plot();*/
break;
}
}
}
/QMK-Groundstation/branches/libMK/libMK/Handler.h
1,6 → 1,5
#ifndef HANDLER_H
#define HANDLER_H
#include <string>
#include "Parser.h"
#include "Communication.h"
#include "Kopter.h"
16,10 → 15,11
private:
Communication * com;
 
sRxData rxData;
public:
KopterData * data;
 
Handler(Communication * com, KopterData * data);
 
//FlightCtrl commands
void get_flightctrl_settings(int index);
void set_flightctrl_settings(char * tx_data);
53,7 → 53,7
void get_version();
void get_ppm_channels();
 
void receive_data(sRxData rx);
void receive_data(int hardwareID, int cmd, char * data);
};
 
#endif
/QMK-Groundstation/branches/libMK/libMK/Kopter.h
1,13 → 1,12
#ifndef COPTER_H
#define COPTER_H
#include <string>
 
using namespace std;
 
/**
* This file contains informations and configurations from the Mikrokopter
*/
 
#define MAX_DATA_SIZE 150
 
// version information for the serial connection
#define VERSION_SERIAL_MAJOR 10
#define VERSION_SERIAL_MINOR 0
24,7 → 23,7
// settings ID
#define SETTINGS_ID 2
 
static const string HardwareType[] = {"Default", "FlightCtrl", "NaviCtrl", "MK3Mag"};
static const char * HardwareType[] = {"Default", "FlightCtrl", "NaviCtrl", "MK3Mag"};
 
static const int MaxTickerEvents = 5;
 
40,7 → 39,7
int mixer_roll[MAX_MOTORS];
int mixer_yaw[MAX_MOTORS];
int desired_speed[MAX_MOTORS];
string mixer_name;
char * mixer_name;
int mixer_version;
};
 
52,8 → 51,8
int version_patch;
int version_serial_major;
int version_serial_minor;
string hardware;
string version;
char * hardware;
char * version;
};
 
struct sGPS_Pos
/QMK-Groundstation/branches/libMK/libMK/Parser.cpp
1,34 → 1,73
#include <Parser.h>
 
// Base64 Decoder
// see Parser.h for details about sRxData
bool Parser::decode64(sRxData &rx)
/**
* create a frame that can be send to the MK using the
* connection class.
* see http://www.mikrokopter.com/ucwiki/en/SerialProtocol
* how the protocol is encoded and
* see http://www.mikrokopter.com/ucwiki/en/SerialCommands
* to look at the possible commands that are already coded
* in data
*/
void Parser::create_frame(char cmd, int address, char * data, unsigned int length) {
//if # is cmd we do not touch anything, because
// the command is already encoded in data
if (cmd != '#') {
/*
//calculate buffer length
//(4 Bytes for 1-byte '#', 1-byte address, and 2-byte crc)
//(the rest for the data length - see encode how this is calculated)
int buff_len = 4+(length/3 + (length%3==0?0:1) )*4;
 
//allociate memory for the data we want to send
char * send_data = (char *)malloc(buf_len);
*/
char send_data[150];
send_data[0]='#';
send_data[1]=(char)address;
send_data[2]=cmd;
for (int i = 0; i < length; i++)
send_data[i+3] = data[i];
//TODO: abgleich mit MKCommunication::send_command
Parser::encode64(send_data, length);
address = 'a' + address;
}
}
 
 
/**
* Base64 Decoder
* see Parser.h for details about sRxData
* data = data that will be decoded
* len = length of data
* ptrOut = pointer to decoded data
* offset = offset in data
*/
int Parser::decode64(char * data, int len, unsigned char *ptrOut, int offset)
{
int length = rx.str.size();
unsigned char a,b,c,d;
unsigned char ptr = 0;
unsigned char x,y,z;
int ptrOut[150];
 
int ptrIn = 3;
int max = length;
int len = length;
int decLen = 0;
 
if (rx.input[ptrIn] == 0) {
return false;
/*
//FIXME: dies wieder einklammern!
if (data[ptrIn] == 0) {
return -1;
//TODO: catch error to show that something went wrong during the decode process
//throw "Nothing received";
}
*/
//decode data
while(len) {
a = data[offset++] - '=';
b = data[offset++] - '=';
c = data[offset++] - '=';
d = data[offset++] - '=';
 
while(len != 0) {
a = rx.input[ptrIn++] - '=';
b = rx.input[ptrIn++] - '=';
c = rx.input[ptrIn++] - '=';
d = rx.input[ptrIn++] - '=';
//if(offset > max - 2) break;
 
if(ptrIn > max - 2) break;
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
37,9 → 76,13
if(len--) ptrOut[ptr++] = y; else break;
if(len--) ptrOut[ptr++] = z; else break;
}
 
//decoded data
unsigned char * decData;
for (int a=0; a<ptr; a++) {
if (length == false) {
if (len) {
decData[decLen] = ptrOut[a];
decLen++;
} else {
int b1, b2, b3;
 
b1 = ptrOut[a++];
50,19 → 93,18
if (b3 > 32767)
b3 = b3 - 65536;
 
rx.decode[decLen] = b3;
decData[decLen] = b3;
decLen++;
} else {
rx.decode[decLen] = ptrOut[a];
decLen++;
}
rx.decLen = decLen;
}
return true;
ptrOut = decData;
return decLen;
}
 
// base64 encoder
string Parser::encode64(char data[150],unsigned int length)
/**
* base64 encoder
*/
void Parser::encode64(char data[150],unsigned int length)
{
unsigned int pt = 0;
unsigned char a,b,c;
83,7 → 125,8
}
tx_buff[pt] = 0;
 
return string(tx_buff);
//move pointer of tx_buff to data
data = tx_buff;
}
 
// Datensatz nach 8bit Integer
96,7 → 139,9
return out;
}
 
// received char to 8 bit integer
/**
* received char to 8 bit integer
*/
int Parser::charToData(int data) {
if (data < 0)
return data + 256;
103,7 → 148,9
return data;
}
 
// convert data to 16bit Integer
/**
* convert data to 16bit Integer
*/
int Parser::dataToInt(int *Data , int Start, bool is_signed)
{
int Out = (Data[Start+1]<<8) | (Data[Start+0]);
115,7 → 162,9
 
}
 
// convert data to 32bit Long
/**
* convert data to 32bit Long
*/
long Parser::dataToLong(int *Data , int Start, bool is_signed)
{
long Out = (Data[Start+3]<<24) | (Data[Start+2]<<16) | (Data[Start+1]<<8) | (Data[Start+0]);
135,43 → 184,31
return temp / num;
}
 
string Parser::dataToString(int Data[150], int Start, int End)
/**
* check CRC
*/
bool Parser::check_CRC(char * rx, int length)
{
char String[150];
for (int a = Start; a < End; a++)
{
String[a - Start] = Data[a];
}
String[End - Start] = '\0';
 
return string(String);
}
 
// check CRC
bool Parser::check_CRC(string RXstr)
{
int length = RXstr.size();
int CRC = 0;
char *RX = (char *)RXstr.c_str();
 
if (RX[1] == 127)
if (rx[1] == 127)
{
RX[1] = 0;
rx[1] = 0;
}
 
for(int i=0; i < length-2; i++)
{
CRC+=RX[i];
CRC+=rx[i];
}
 
CRC = CRC % 4096;
 
if(RX[length - 2] != ('=' + (CRC / 64)))
if(rx[length - 2] != ('=' + (CRC / 64)))
{
return false;
}
 
if(RX[length - 1] != ('=' + CRC % 64))
if(rx[length - 1] != ('=' + CRC % 64))
{
return false;
}
179,25 → 216,22
return true;
}
 
// add CRC
string Parser::add_CRC(string TX)
/**
* create CRC and add it to tx
*/
void Parser::add_CRC(char * tx, int length)
{
int length = TX.size();
unsigned int tmpCRC = 0;
 
char CRC[2];
 
for(int i = 0; i < length; i++)
{
tmpCRC += TX[i];
tmpCRC += tx[i];
}
 
tmpCRC %= 4096;
 
CRC[0] = '=' + tmpCRC / 64;
CRC[1] = '=' + tmpCRC % 64;
CRC[2] = '\0';
 
return string(TX) + string(CRC);
tx[length-2] = '=' + tmpCRC / 64;
tx[length-1] = '=' + tmpCRC % 64;
tx[length] = '\0';
}
 
/QMK-Groundstation/branches/libMK/libMK/Parser.h
1,6 → 1,5
#ifndef PARSER_H
#define PARSER_H
#include <string>
#include <cmath>
 
/**
7,31 → 6,29
* The Parser gets values from the Mikrokopter-USART interface
* and parses them into a sRxData-Struct
*/
 
using namespace std;
 
/*
struct sRxData
{
char *input;
string str;
int decode[150];
int decLen;
};
 
*/
class Parser {
public:
static bool decode64(sRxData &rx);
static string encode64(char data[150],unsigned int length);
void create_frame(char cmd, int address, char * data, unsigned int length);
 
static string add_CRC(string TX);
static bool check_CRC(string RX);
static int decode64(char * data, int len, unsigned char *ptrOut, int offset);
static void encode64(char data[150],unsigned int length);
 
static void add_CRC(char * tx, int length);
static bool check_CRC(char * rx, int length);
 
static float getFloat(long value, int count);
 
static int dataToInt(int *Data , int Start, bool is_signed = true);
static long dataToLong(int *Data , int Start, bool is_signed = true);
static int dataToInt(int *data , int start, bool is_signed = true);
static long dataToLong(int *data , int start, bool is_signed = true);
static int dataToChar(int *data , int start, bool is_signed = true);
static string dataToString(int Data[150], int Start = 0, int End = 150);
static int charToData(int data);
};
 
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.cpp
0,0 → 1,43
#include "QTSerialCommunication.h"
#include "../libMK/Parser.h"
 
/**
* initiate connection and stuff
*/
QTSerialCommunication::QTSerialCommunication() {
serial = new ManageSerialPort();
serial->setBaudRate(BAUD57600); //BaudRate
serial->setDataBits(DATA_8); //DataBits
serial->setParity(PAR_NONE); //Parity
serial->setStopBits(STOP_1); //StopBits
serial->setFlowControl(FLOW_OFF); //FlowControl
 
serial->setTimeout(0, 10);
serial->enableSending();
serial->enableReceiving();
}
 
/**
* connect to Mikrokopter
*/
void QTSerialCommunication::connect_MK(string addr) {
};
 
/**
* send command to Mikrokopter
*/
bool QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
if (is_connected()) {
//a valid command starts
}
return true;
};
 
/**
* stop sending commands to Mikrokopter
* stop timer
*/
void QTSerialCommunication::stop_resend() {
};
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.h
0,0 → 1,25
#ifndef QT_SERIAL_COMMUNICATION_H
#define QT_SERIAL_COMMUNICATION_H
#include "Communication.h"
#include "../SerialPort/ManageSerialPort.h"
 
/**
* QT specific communication class
* based on the communication interface
* using the SerialPort implementation
* by VIANNEY-LIAUD Philippe
* ( philippe.vianney.liaud gmail.com )
*/
 
using namespace std;
 
class QTSerialCommunication : public Communication {
private:
ManageSerialPort * serial;
public:
QTSerialCommunication();
void connect_MK(string addr);
bool send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend);
void stop_resend();
};
#endif
/QMK-Groundstation/branches/libMK/libMK.pri
8,9 → 8,9
Handler.h \
Kopter.h \
Parser.h \
QTCommunication.h
QTSerialCommunication.h
SOURCES += Communication.cpp \
Handler.cpp \
Parser.cpp \
QTCommunication.cpp
QTSerialCommunication.cpp
QT += network
/QMK-Groundstation/branches/libMK/typedefs.h
5,6 → 5,8
#define NEWDATA 0x01
#define PROCESSED 0x02
 
#include <stdint.h>
 
typedef struct
{
int32_t Longitude; // in 1E-7 deg