/QMK-Groundstation/branches/libMK/com.pri |
---|
File deleted |
/QMK-Groundstation/branches/libMK/com/Kopter.h |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/QTCommunication.cpp |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/Communication.h |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/Parser.cpp |
---|
File deleted |
/QMK-Groundstation/branches/libMK/com/Handler.cpp |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/QTCommunication.h |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/Parser.h |
---|
File deleted |
/QMK-Groundstation/branches/libMK/com/Handler.h |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/com/Communication.cpp |
---|
File deleted |
\ No newline at end of file |
/QMK-Groundstation/branches/libMK/Classes/ToolBox.cpp |
---|
18,7 → 18,7 |
***************************************************************************/ |
#include "ToolBox.h" |
#include "../com/Parser.h" |
#include "../libMK/Parser.h" |
/** |
* specific data for QT |
30,7 → 30,7 |
#ifndef _WIN32_ |
usleep(Time); |
#else |
//FIXME: implement sleep for win_32 |
//TODO: implement sleep for win_32 |
//(or kick this function completely) |
// sleep(Time); |
#endif |
/QMK-Groundstation/branches/libMK/Classes/ToolBox.h |
---|
22,7 → 22,7 |
#include <QString> |
#include <QIcon> |
#include "../global.h" |
#include "../com/Kopter.h" |
#include "../libMK/Kopter.h" |
class ToolBox |
{ |
/QMK-Groundstation/branches/libMK/Classes/cConnection.h |
---|
26,7 → 26,7 |
#include "ToolBox.h" |
#include "../global.h" |
#include "../SerialPort/ManageSerialPort.h" |
#include "../com/Parser.h" |
#include "../libMK/Parser.h" |
#define C_TTY 1 |
#define C_IP 2 |
/QMK-Groundstation/branches/libMK/Classes/cKML_Server.cpp |
---|
46,7 → 46,7 |
delete TcpServer; |
} |
void cKML_Server::store_NaviString(sNaviString Navi) |
void cKML_Server::store_NaviString(sNaviData Navi) |
{ |
Route[NaviCount] = Navi; |
NaviCount++; |
/QMK-Groundstation/branches/libMK/Classes/cKML_Server.h |
---|
36,7 → 36,7 |
void start_Server(int Port, cSettings *Set); |
void stop_Server(); |
void store_NaviString(sNaviString Navi); |
void store_NaviString(sNaviData Navi); |
private: |
46,7 → 46,7 |
cSettings *Settings; |
QByteArray get_KML(); |
sNaviString Route[MaxNaviPos]; |
sNaviData Route[MaxNaviPos]; |
int NaviCount; |
private slots: |
/QMK-Groundstation/branches/libMK/Classes/cQMK_Server.cpp |
---|
57,7 → 57,7 |
TcpSocket->write(SendText); |
} |
void cQMK_Server::NewPosition(sNaviString Pos) |
void cQMK_Server::NewPosition(sNaviData Pos) |
{ |
if (1==1) |
{ |
/QMK-Groundstation/branches/libMK/Classes/cQMK_Server.h |
---|
34,7 → 34,7 |
cQMK_Server(); |
void Connect(QString IP, int Port, QString User, QString Pass); |
void Disconnect(); |
void NewPosition(sNaviString Pos); |
void NewPosition(sNaviData Pos); |
void send_RawData(QString Data); |
private: |
/QMK-Groundstation/branches/libMK/Classes/cSettings.h |
---|
20,7 → 20,7 |
#define CSETTINGS_H |
#include "../global.h" |
#include "../com/Kopter.h" |
#include "../libMK/Kopter.h" |
struct set_TTY |
{ |
/QMK-Groundstation/branches/libMK/Forms/dlg_MotorMixer.cpp |
---|
77,6 → 77,8 |
// Motordaten übernehmen. |
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); |
93,69 → 95,37 |
} |
set_MotorData(); |
*/ |
} |
// Motordaten aus GUI übernehmen |
void dlg_MotorMixer::get_MotorData() |
{ |
MixerName = le_NAME->text(); |
//FIXME: add Function in handler to send data |
char * mixerName = le_NAME->text().toAscii().data(); |
Motor[0][0] = sb_GAS_1->value(); |
Motor[1][0] = sb_GAS_2->value(); |
Motor[2][0] = sb_GAS_3->value(); |
Motor[3][0] = sb_GAS_4->value(); |
Motor[4][0] = sb_GAS_5->value(); |
Motor[5][0] = sb_GAS_6->value(); |
Motor[6][0] = sb_GAS_7->value(); |
Motor[7][0] = sb_GAS_8->value(); |
Motor[8][0] = sb_GAS_9->value(); |
Motor[9][0] = sb_GAS_10->value(); |
Motor[10][0] = sb_GAS_11->value(); |
Motor[11][0] = sb_GAS_12->value(); |
Motor[0][1] = sb_NICK_1->value(); |
Motor[1][1] = sb_NICK_2->value(); |
Motor[2][1] = sb_NICK_3->value(); |
Motor[3][1] = sb_NICK_4->value(); |
Motor[4][1] = sb_NICK_5->value(); |
Motor[5][1] = sb_NICK_6->value(); |
Motor[6][1] = sb_NICK_7->value(); |
Motor[7][1] = sb_NICK_8->value(); |
Motor[8][1] = sb_NICK_9->value(); |
Motor[9][1] = sb_NICK_10->value(); |
Motor[10][1] = sb_NICK_11->value(); |
Motor[11][1] = sb_NICK_12->value(); |
Motor[0][2] = sb_ROLL_1->value(); |
Motor[1][2] = sb_ROLL_2->value(); |
Motor[2][2] = sb_ROLL_3->value(); |
Motor[3][2] = sb_ROLL_4->value(); |
Motor[4][2] = sb_ROLL_5->value(); |
Motor[5][2] = sb_ROLL_6->value(); |
Motor[6][2] = sb_ROLL_7->value(); |
Motor[7][2] = sb_ROLL_8->value(); |
Motor[8][2] = sb_ROLL_9->value(); |
Motor[9][2] = sb_ROLL_10->value(); |
Motor[10][2] = sb_ROLL_11->value(); |
Motor[11][2] = sb_ROLL_12->value(); |
Motor[0][3] = sb_GIER_1->value(); |
Motor[1][3] = sb_GIER_2->value(); |
Motor[2][3] = sb_GIER_3->value(); |
Motor[3][3] = sb_GIER_4->value(); |
Motor[4][3] = sb_GIER_5->value(); |
Motor[5][3] = sb_GIER_6->value(); |
Motor[6][3] = sb_GIER_7->value(); |
Motor[7][3] = sb_GIER_8->value(); |
Motor[8][3] = sb_GIER_9->value(); |
Motor[9][3] = sb_GIER_10->value(); |
Motor[10][3] = sb_GIER_11->value(); |
Motor[11][3] = sb_GIER_12->value(); |
//TODO: use an array in Form |
int motor[16][4] = { |
sb_GAS_1->value(), sb_NICK_1->value(), sb_ROLL_1->value(), sb_GIER_1->value(), |
sb_GAS_2->value(), sb_NICK_2->value(), sb_ROLL_2->value(), sb_GIER_2->value(), |
sb_GAS_3->value(), sb_NICK_3->value(), sb_ROLL_3->value(), sb_GIER_3->value(), |
sb_GAS_4->value(), sb_NICK_4->value(), sb_ROLL_4->value(), sb_GIER_4->value(), |
sb_GAS_5->value(), sb_NICK_5->value(), sb_ROLL_5->value(), sb_GIER_5->value(), |
sb_GAS_6->value(), sb_NICK_6->value(), sb_ROLL_6->value(), sb_GIER_6->value(), |
sb_GAS_7->value(), sb_NICK_7->value(), sb_ROLL_7->value(), sb_GIER_7->value(), |
sb_GAS_8->value(), sb_NICK_8->value(), sb_ROLL_8->value(), sb_GIER_8->value(), |
sb_GAS_9->value(), sb_NICK_9->value(), sb_ROLL_9->value(), sb_GIER_9->value(), |
sb_GAS_10->value(), sb_NICK_10->value(), sb_ROLL_10->value(), sb_GIER_10->value(), |
sb_GAS_11->value(), sb_NICK_11->value(), sb_ROLL_11->value(), sb_GIER_11->value(), |
sb_GAS_12->value(), sb_NICK_12->value(), sb_ROLL_12->value(), sb_GIER_12->value() |
}; |
} |
// Motordaten anzeigen |
void dlg_MotorMixer::set_MotorData() |
{ |
//FIXME: create special struct for mixer - KopterData |
/* |
le_NAME->setText(MixerName); |
sb_GAS_1->setValue(Motor[0][0]); |
209,6 → 179,7 |
sb_GIER_10->setValue(Motor[9][3]); |
sb_GIER_11->setValue(Motor[10][3]); |
sb_GIER_12->setValue(Motor[11][3]); |
*/ |
} |
// Prüfen auf vollstaändigkeit |
253,7 → 224,7 |
} |
} |
//FIXME: put this in com/Handler.cpp |
//FIXME: put this in libMK/Handler.cpp |
/* |
int dlg_MotorMixer::get_MotorConfig() |
{ |
289,26 → 260,22 |
return Pos - 1; |
} |
*/ |
void dlg_MotorMixer::read_Mixer() |
{ |
//See Handler::read_mixer in com/Handler.cpp |
}*/ |
// read motor values |
void dlg_MotorMixer::slot_pb_READ() |
{ |
//send command to get mixer values |
handler->read_mixer(); |
handler->read_motor_mixer(); |
} |
//write motor values |
//FIXME: put this in com/Handler.cpp |
//FIXME: put this in libMK/Handler.cpp |
void dlg_MotorMixer::slot_pb_WRITE() |
{ |
/* int Length = handler->get_motor_config(); |
handler->write_mixer(TX_Data, Length);*/ |
char tx_data[150]; |
int length = handler->get_motor_config(tx_data); |
handler->write_motor_mixer(tx_data, length); |
} |
void dlg_MotorMixer::slot_pb_LOAD() |
320,10 → 287,13 |
QSettings Setting(Filename, QSettings::IniFormat); |
Setting.beginGroup("Info"); |
MixerName = Setting.value("Name", QString("--noname--")).toString(); |
MixerVersion = Setting.value("Version", 0).toInt(); |
//FIXME: Add mixer-struct in kopter.h for kopterdata |
// MixerName = Setting.value("Name", QString("--noname--")).toString(); |
// MixerVersion = Setting.value("Version", 0).toInt(); |
Setting.endGroup(); |
//FIXME: Add mixer-struct in kopter.h for kopterdata |
/* |
Setting.beginGroup("Gas"); |
for (int z = 0; z < MAXMOTOR; z++) |
{ |
351,11 → 321,11 |
Motor[z][3] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
} |
Setting.endGroup(); |
if (MixerVersion == VERSION_MIXER) |
{ |
set_MotorData(); |
} |
*/ |
} |
} |
375,6 → 345,8 |
QSettings Setting(Filename, QSettings::IniFormat); |
Setting.beginGroup("Info"); |
//FIXME: Add mixer-struct in kopter.h for kopterdata - doppelter Code!!! |
/* |
Setting.setValue("Name", MixerName); |
Setting.setValue("Version", VERSION_MIXER); |
Setting.endGroup(); |
406,5 → 378,6 |
Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][3]); |
} |
Setting.endGroup(); |
*/ |
} |
} |
/QMK-Groundstation/branches/libMK/Forms/dlg_MotorMixer.h |
---|
29,7 → 29,7 |
#include "../typedefs.h" |
//#include "../Classes/ToolBox.h" |
#include "../global.h" |
#include "../com/Handler.h" |
#include "../libMK/Handler.h" |
class dlg_MotorMixer : public QDialog, public Ui::dlg_MotorMixer_UI |
{ |
47,12 → 47,6 |
cSettings *o_Settings; |
char TX_Data[150]; |
int Motor[16][4]; //vgl. typedefs.h |
QString MixerName; |
int MixerVersion; |
void set_MotorData(); |
void get_MotorData(); |
/QMK-Groundstation/branches/libMK/Forms/mktool.cpp |
---|
197,11 → 197,14 |
void MKTool::init_Objects() |
{ |
//new KopterData object that contains all data from MK |
data = new KopterData(); |
//new QT-Communication object |
com = new QTCommunication(); |
//create handler that handles incomming data |
handler = new Handler(com); |
handler = new Handler(com, data); |
// QTimer-Instanzen |
Ticker = new QTimer(this); |
210,7 → 213,7 |
//o_Connection = new cConnection(); |
// Logger |
logger = new Logger(Settings, &Mode); |
logger = new Logger(Settings, data); |
// LCD-Dialog |
f_LCD = new dlg_LCD(this); |
417,7 → 420,8 |
//FIXME: put this in cpp/NaviCtrl.cpp? |
void MKTool::slot_pb_SendTarget() |
{ |
if ((Navi.Current.Longitude == 0) && (Navi.Current.Latitude == 0)) |
sNaviData navi = data->navi; |
if ((navi.Current.Longitude == 0) && (navi.Current.Latitude == 0)) |
{ |
QMessageBox msgB; |
QString msg; |
459,8 → 463,8 |
//...und sende ihn an die NaviCtrl |
int max_radius = 10000; |
if (ok_lat && ok_lon && |
abs((double)(Navi.Current.Longitude - desired_pos.Position.Longitude)) < max_radius && |
abs((double)(Navi.Current.Latitude - desired_pos.Position.Latitude)) < max_radius) |
abs((double)(navi.Current.Longitude - desired_pos.Position.Longitude)) < max_radius && |
abs((double)(navi.Current.Latitude - desired_pos.Position.Latitude)) < max_radius) |
{ |
handler->send_waypoint(desired_pos); |
} |
471,10 → 475,10 |
msg += tr("Bitte die Eingabe ueberpruefen!\n"); |
msg += tr("Die Werte muessen sich in der Naehe der aktuellen Koordinaten befinden\n"); |
msg += "(Lon: "; |
msg += QString::number(Navi.Current.Longitude); |
msg += QString::number(navi.Current.Longitude); |
msg += ", "; |
msg += "Lat: "; |
msg += QString::number(Navi.Current.Latitude); |
msg += QString::number(navi.Current.Latitude); |
msg += ")"; |
msgB.setText(msg); |
msgB.exec(); |
497,7 → 501,7 |
// Hardware Auswahl und umschalten |
void MKTool::slot_rb_Hardware() |
{ |
if ((rb_SelNC->isChecked() == false) && (Mode.ID != ADDRESS_NC)) |
if ((rb_SelNC->isChecked() == false) && (data->mode.ID != ADDRESS_NC)) |
{ |
lb_Status->setText(tr("Schalte um auf NaviCtrl.")); |
handler->switch_navictrl(); |
532,7 → 536,7 |
/////////////// |
void MKTool::slot_Ticker() |
{ |
//FIXME: Put this somewhere in Handler.cpp |
//FIXME: Put this somewhere in libMK/QTCommunication.cpp |
/* |
if (TickerDiv) |
TickerDiv = false; |
683,13 → 687,8 |
disconnect(f_Motortest, 0,0,0); |
for (int z = 0; z<12; z++) |
{ |
Motor.Speed[z] = 0; |
} |
handler->reset_motor(); |
slot_Motortest(Motor); |
Ticker->setInterval(2000); |
TickerEvent[4] = false; |
} |
703,7 → 702,7 |
void MKTool::slot_ac_MotorMixer() |
{ |
f_MotorMixer->set_Objects(handler, Settings); |
handler->read_mixer(); |
handler->read_motor_mixer(); |
if (f_MotorMixer->exec()==QDialog::Accepted) |
{ |
721,10 → 720,10 |
// LCD auf / ab |
connect(f_LCD->pb_LCDup, SIGNAL(clicked()), this, SLOT(slot_LCD_UP())); |
connect(f_LCD->pb_LCDdown, SIGNAL(clicked()), this, SLOT(slot_LCD_DOWN())); |
//FIXME: put this in com/Handler.cpp |
//FIXME: put this in libMK/Handler.cpp |
f_LCD->show(); |
handler->show_lcd(); |
//FIXME: replace ticker with something else |
//FIXME: replace ticker with something else??? |
Ticker->setInterval(500); |
TickerEvent[2] = true; |
} |
741,7 → 740,7 |
void MKTool::slot_MAP_SetWayPoints(QList<sWayPoint> l_WayPoints) |
{ |
//FIXME: Put this in com/Handler.cpp or com/NaviCtrl.cpp |
//FIXME: Put this in libMK/Handler.cpp or libMK/NaviCtrl.cpp |
double Longitude, Latitude; |
806,12 → 805,12 |
Old_Analog1 = Settings->Analog1; |
dlg_Config *f_Config = new dlg_Config(this); |
f_Config->set_Settings(Settings, Mode.ID); |
f_Config->set_Settings(Settings, data->mode.ID); |
if (f_Config->exec()==QDialog::Accepted) |
{ |
Settings = f_Config->get_Settings(); |
Settings->write_Settings_Analog(Mode.ID); |
Settings->write_Settings_Analog(data->mode.ID); |
// Plotter neu einrichten |
if (Old_Analog1.PlotView != Settings->Analog1.PlotView) |
994,8 → 993,9 |
else |
{ |
// Wenn MK3MAG dann andauernd Daten neu anfragen. |
if (Mode.ID == ADDRESS_MK3MAG) |
TickerEvent[3] = true; |
//FIXME: TickerEvent in Communication oder so |
/* if (Mode.ID == ADDRESS_MK3MAG) |
TickerEvent[3] = true;*/ |
if (ac_FastDebug->isChecked()) |
{ |
1257,17 → 1257,19 |
void MKTool::show_DebugData() |
{ |
if (logger->is_active()) |
logger->write(AnalogData); |
//FIXME: log analogdata in Communication |
/* if (logger->is_active()) |
logger->write(AnalogData);*/ |
if (ac_StartPlotter->isChecked()) |
{ |
aID[NextPlot] = NextPlot; |
//FIXME: get analogData from handler |
/* |
for (int a = 0; a < MaxAnalog; a++) |
{ |
aData[a][NextPlot] = AnalogData[a]; |
} |
}*/ |
NextPlot++; |
if ((tab_Main->currentWidget()->objectName() == QString("Tab_1"))) |
1274,6 → 1276,8 |
update_Plot(); |
} |
//FIXME: get analogdata from handler |
/* |
le_A_0->setText(QString("%1").arg(AnalogData[0])); |
le_A_1->setText(QString("%1").arg(AnalogData[1])); |
le_A_2->setText(QString("%1").arg(AnalogData[2])); |
1326,12 → 1330,13 |
Attitude->setAngle(Roll); |
Attitude->setGradient(double(double(Nick) / 100.0)); |
} |
*/ |
} |
void MKTool::new_NaviData(sRxData RX) |
{ |
// qDebug("Navi-Data"); |
sNaviData navi = data->navi; |
switch(RX.decode[N_NC_FLAGS]) |
{ |
case 0x01 : lb_Mode->setText(tr("Free")); break; |
1343,12 → 1348,12 |
case 0x40 : lb_Mode->setText(tr("Manual Control")); break; |
} |
Navi.Current.Longitude = Parser::dataToLong(RX.decode, N_CUR_LONGITUDE, true); |
Navi.Current.Latitude = Parser::dataToLong(RX.decode, N_CUR_LATITUDE, true); |
Navi.Current.Altitude = Parser::dataToLong(RX.decode, N_CUR_ALTITUDE, true); |
Navi.Target.Longitude = Parser::dataToLong(RX.decode, N_TAR_LONGITUDE, true); |
Navi.Target.Latitude = Parser::dataToLong(RX.decode, N_TAR_LATITUDE, true); |
Navi.Target.Altitude = Parser::dataToLong(RX.decode, N_TAR_ALTITUDE, true); |
navi.Current.Longitude = Parser::dataToLong(RX.decode, N_CUR_LONGITUDE, true); |
navi.Current.Latitude = Parser::dataToLong(RX.decode, N_CUR_LATITUDE, true); |
navi.Current.Altitude = Parser::dataToLong(RX.decode, N_CUR_ALTITUDE, true); |
navi.Target.Longitude = Parser::dataToLong(RX.decode, N_TAR_LONGITUDE, true); |
navi.Target.Latitude = Parser::dataToLong(RX.decode, N_TAR_LATITUDE, true); |
navi.Target.Altitude = Parser::dataToLong(RX.decode, N_TAR_ALTITUDE, true); |
le_CDistance->setText(QString("%1 cm").arg(Parser::dataToInt(RX.decode, N_HOME_DISTANCE))); |
le_CWPA->setText(QString("%1").arg(RX.decode[N_WP_INDEX])); |
1395,23 → 1400,23 |
Attitude->setAngle(Roll); |
Attitude->setGradient(double(0.0 - (double(Nick) / 100.0))); |
sNaviString NaviString; |
sNaviData naviData; |
naviData.Longitude = Parser::getFloat(navi.Current.Longitude,7); |
naviData.Latitude = Parser::getFloat(navi.Current.Latitude,7); |
naviData.Altitude = Parser::getFloat(navi.Current.Altitude,3); |
NaviString.Longitude = Parser::getFloat(Navi.Current.Longitude,7); |
NaviString.Latitude = Parser::getFloat(Navi.Current.Latitude,7); |
NaviString.Altitude = Parser::getFloat(Navi.Current.Altitude,3); |
le_CurLong->setText(QString::number(naviData.Longitude)); |
le_CurLat->setText(QString::number(naviData.Latitude)); |
le_CurLong->setText(QString::number(NaviString.Longitude)); |
le_CurLat->setText(QString::number(NaviString.Latitude)); |
KML_Server->store_NaviString(naviData); |
KML_Server->store_NaviString(NaviString); |
f_Map->add_Position(naviData.Longitude, naviData.Latitude); |
f_Map->add_Position(NaviString.Longitude, NaviString.Latitude); |
if ((QMK_Server->property("Connect")) == true) |
{ |
// qDebug("Send Data to Server..!!"); |
QMK_Server->NewPosition(NaviString); |
// qDebug("Send Data to Server..."); |
QMK_Server->NewPosition(naviData); |
} |
} |
1472,7 → 1477,7 |
// Verbindung zum Kopter herstellen / Trennen |
void MKTool::slot_OpenPort() |
{ |
//FIXME: Put this in com/QTCommunication.cpp |
//FIXME: Put this in libMK/QTCommunication.cpp |
/* |
if (o_Connection->isOpen()) |
{ |
1534,7 → 1539,7 |
MKTool::~MKTool() |
{ |
//FIXME: Put this in com/QTCommunication.cpp |
//FIXME: Put this in libMK/QTCommunication.cpp |
/* |
if (o_Connection->isOpen()) |
{ |
/QMK-Groundstation/branches/libMK/Forms/mktool.h |
---|
53,9 → 53,9 |
#include "../typedefs.h" |
//quadcopter lib stuff |
#include "../com/Handler.h" |
#include "../com/Communication.h" |
#include "../com/QTCommunication.h" |
#include "../libMK/Handler.h" |
#include "../libMK/Communication.h" |
#include "../libMK/QTCommunication.h" |
class QextSerialPort; |
70,6 → 70,7 |
private: |
// Object für Kopter-Verbindung |
//cConnection *o_Connection; |
KopterData * data; |
Handler *handler; |
108,9 → 109,6 |
// Analogwert-Beschreibungen |
QLabel *lb_Analog[MaxAnalog]; |
// Analogwerte |
int AnalogData[MaxAnalog]; |
// Plots für die Analogwerte |
QwtPlotCurve *Plot[MaxAnalog]; |
129,13 → 127,6 |
//Logger für CVS und andere |
Logger * logger; |
sMode Mode; |
sRxData RxData; |
sNaviData Navi; |
sMotor Motor; |
QString RXS; |
// Softwareupdate |
QProcess *Update; |
/QMK-Groundstation/branches/libMK/Logger/CSVLogger.cpp |
---|
20,12 → 20,12 |
#include "CSVLogger.h" |
CSVLogger::CSVLogger(cSettings * settings, sMode * mode) |
CSVLogger::CSVLogger(cSettings * settings, KopterData * data) |
{ |
// QFile-Instanz (Log-Datei) |
csvfile = new QFile(""); |
this->settings = settings; |
this->mode = mode; |
this->data = data; |
} |
CSVLogger::~CSVLogger() |
51,7 → 51,7 |
{ |
if (!csvfile->isOpen()) |
{ |
QString mode_name = QString(mode->Hardware.c_str()); |
QString mode_name = QString(data->mode.Hardware.c_str()); |
if (mode_name.size() == 0) |
{ |
/QMK-Groundstation/branches/libMK/Logger/CSVLogger.h |
---|
28,6 → 28,7 |
#include <QTime> |
#include "../global.h" |
#include "../Classes/cSettings.h" |
#include "../libMK/Kopter.h" |
#include "DefaultLogger.h" |
class CSVLogger : public DefaultLogger |
36,9 → 37,9 |
// Object für das Datenfile; |
QFile * csvfile; |
cSettings * settings; |
sMode * mode; |
KopterData * data; |
public: |
CSVLogger(cSettings * settings, sMode * mode); |
CSVLogger(cSettings * settings, KopterData * data); |
~CSVLogger(); |
//schreibe log |
/QMK-Groundstation/branches/libMK/Logger/Logger.cpp |
---|
20,9 → 20,9 |
#include "Logger.h" |
Logger::Logger(cSettings * settings, sMode * mode) |
Logger::Logger(cSettings * settings, KopterData * data) |
{ |
csv = new CSVLogger(settings, mode); |
csv = new CSVLogger(settings, data); |
logger << csv; |
active = false; |
} |
/QMK-Groundstation/branches/libMK/Logger/Logger.h |
---|
26,6 → 26,7 |
#include "DefaultLogger.h" |
#include "../global.h" |
#include "../Classes/cSettings.h" |
#include "../libMK/Handler.h" |
//Die verschiedenen header der einzelnen Logger |
//TODO: MySQLLogger, SQLiteLogger und/oder PostGreSQLLogger |
41,7 → 42,7 |
bool active; |
public: |
Logger(cSettings * settings, sMode * mode); |
Logger(cSettings * settings, KopterData * data); |
~Logger(); |
void start_Log(); |
/QMK-Groundstation/branches/libMK/eeepc.pro |
---|
1,5 → 1,5 |
include(QMapControl.pri) |
include(com.pri) |
include(libMK.pri) |
DEFINES += _TTY_POSIX_ _EEEPC_ |
/QMK-Groundstation/branches/libMK/global.h |
---|
26,7 → 26,7 |
#include <QBitArray> |
//copter settings from kopter module |
#include "com/Kopter.h" |
#include "libMK/Kopter.h" |
#include "Parameter_Positions.h" |
96,6 → 96,7 |
static const QRgb Def_Colors[] = {0x00FF0000, 0x0000FF00, 0x00FFFF00, 0x000000FF, 0x00FF00FF, 0x0000FFFF, 0x00FFFFFF, 0x00660000, 0x00006600, 0x00666600, 0x00000066, 0x00660066, 0x000066, 0x00666666, 0x00990000, 0x00009900, 0x00999900, 0x00000099, 0x00990099, 0x00009999, 0x00999999, 0x00CC0000, 0x0000CC00, 0x00CCCC00, 0x000000CC, 0x00CC00CC, 0x0000CCCC, 0x00CCCCCC, 0x0066FF99, 0x009966FF, 0x00FF9966, 0x0099FF66}; |
//plot informations - see cSettings-constructor. |
static const bool Def_Plot_Show[] = {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0}; |
static const bool Def_Log[] = {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0}; |
/QMK-Groundstation/branches/libMK/groundstation.kdevelop |
---|
3,7 → 3,7 |
<general> |
<author/> |
<email/> |
<version>own_lib_branch</version> |
<version>libMK_branch</version> |
<projectmanagement>KDevTrollProject</projectmanagement> |
<primarylanguage>C++</primarylanguage> |
<keywords> |
145,7 → 145,7 |
</kdevdebugger> |
<kdevtrollproject> |
<run> |
<mainprogram>/home/andreas/uni/Mikrokopter/QMK-Groundstation/branches/own_com_lib/build/bin/QMK-Groundstation</mainprogram> |
<mainprogram>/home/andreas/uni/Mikrokopter/QMK-Groundstation/branches/libMK/build/bin/QMK-Groundstation</mainprogram> |
<programargs/> |
<directoryradio>executable</directoryradio> |
<globaldebugarguments/> |
176,7 → 176,7 |
<enableFilenamesOnly>false</enableFilenamesOnly> |
<showVariablesInTree>true</showVariablesInTree> |
<showParseErrors>true</showParseErrors> |
<projectfile>/home/andreas/uni/Mikrokopter/QMK-Groundstation/branches/own_com_lib/eeepc.pro</projectfile> |
<projectfile>/home/andreas/uni/Mikrokopter/QMK-Groundstation/branches/libMK/eeepc.pro</projectfile> |
</qmake> |
</kdevtrollproject> |
<workspace> |
210,9 → 210,9 |
<LICENSE>GPL</LICENSE> |
<LICENSEFILE>COPYING</LICENSEFILE> |
<QMAKE/> |
<VERSION>own_lib_branch</VERSION> |
<VERSION>libMK_branch</VERSION> |
<YEAR>2009</YEAR> |
<dest>branches/own_com_lib</dest> |
<dest>branches/libMK</dest> |
</substmap> |
<cppsupportpart> |
<filetemplates> |
/QMK-Groundstation/branches/libMK/libMK/Communication.cpp |
---|
0,0 → 1,5 |
#include "Communication.h" |
bool Communication::is_connected() { |
return connected; |
} |
/QMK-Groundstation/branches/libMK/libMK/Communication.h |
---|
0,0 → 1,23 |
#ifndef COMMUNICATION_H |
#define COMMUNICATION_H |
#include <string> |
/** |
* communication interface for Mikrokopter (MK) USART connection |
*/ |
using namespace std; |
class Communication{ |
protected: |
bool connected; |
public: |
//connect to MK |
virtual void connect_MK(string) {}; |
//send command to MK |
virtual bool send_cmd(char, int, char[150],unsigned int, bool) { return false; }; |
virtual void stop_resend() {}; |
bool is_connected(); |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/Handler.cpp |
---|
0,0 → 1,470 |
#include<Handler.h> |
/** |
* Constructor that gets a communication instance |
*/ |
Handler::Handler(Communication * com, KopterData * data) { |
this->com = com; |
this->data = data; |
} |
//-------------FlightCtrl commands-------------------- |
/** |
* read settings from FlightCtrl (settings index 0x00-0x05) |
*/ |
void Handler::get_flightctrl_settings(int index) { |
char tx_data[2] = {index, 0}; |
com->send_cmd('q', ADDRESS_FC, tx_data, 1, true); |
} |
/** |
* write settings to FlightCtrl |
*/ |
void Handler::set_flightctrl_settings(char * tx_data) { |
com->send_cmd('s', ADDRESS_FC, tx_data, MaxParameter+2, true); |
} |
/** |
* test one or more motors |
*/ |
void Handler::motor_test(sMotor motor) { |
char tx_data[12]; |
for (int z = 0; z<12; z++) |
{ |
tx_data[z] = motor.Speed[z]; |
} |
com->send_cmd('t', ADDRESS_FC, tx_data, 12, false); |
} |
void Handler::reset_motor() { |
sMotor motor; |
for (int z = 0; z<12; z++) |
{ |
motor.Speed[z] = 0; |
} |
motor_test(motor); |
} |
/** |
* read mixer values from FlightCtrl |
*/ |
void Handler::read_motor_mixer() { |
char tx_data[1] = {0}; |
//com->log("read motor mixer"); |
com->send_cmd('n', ADDRESS_FC, tx_data, 1, true); |
} |
/** |
* write motor mixer values to FlightCtrl |
*/ |
void Handler::write_motor_mixer(char * tx_data, int length) { |
com->send_cmd('m', ADDRESS_FC, tx_data, length, true); |
} |
int Handler::get_motor_config(char * tx_data) { |
return -1; |
} |
//-------------NaviCtrl commands-------------------- |
/** |
* set debug values for NaviCtrl |
*/ |
void Handler::set_navictrl_debug(int speed) { |
char tx_data[1] = { speed }; |
com->send_cmd('o', ADDRESS_NC, tx_data, 1, false); |
} |
/** |
* stop debug for NaviCtrl |
*/ |
void Handler::stop_navictrl_debug() { |
set_navictrl_debug(0); |
} |
/** |
* send a waypoint to the NaviCtrl (the copter 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); |
} |
/** |
* add waypoint to waypoint list |
*/ |
void Handler::add_waypoint(Waypoint_t wp) { |
com->send_cmd('w', ADDRESS_NC, (char *)&wp, sizeof(wp), false); |
} |
/** |
* clear waypoint list on MK |
*/ |
void Handler::delete_waypoints() { |
Waypoint_t wp; |
wp.Position.Status = INVALID; |
send_waypoint(wp); |
} |
//-------------switch between Hardware-------------------- |
void Handler::switch_navictrl() { |
char tx_data[6] = { 0x1B, 0x1B, 0x55, 0xAA, 0x00, '\r'}; |
com->send_cmd('#', ADDRESS_NC, tx_data, 6, false); |
} |
void Handler::switch_flightctrl() { |
char tx_data[1] = { 0 }; |
com->send_cmd('u', ADDRESS_NC, tx_data, 1, false); |
} |
void Handler::switch_mk3mag() { |
char tx_data[1] = { 1 }; |
com->send_cmd('u', ADDRESS_NC, tx_data, 1, false); |
} |
//-------------commands for MK3MAG----------------- |
//-------------commands for all-------------------- |
/** |
* set debug values for all components |
*/ |
void Handler::set_all_debug(int speed) { |
char tx_data[1] = { speed }; |
com->send_cmd('d', ADDRESS_ALL, tx_data, 1, false); |
} |
/** |
* stop debug for all components |
*/ |
void Handler::stop_all_debug() { |
set_all_debug(0); |
} |
/** |
* get all analog labels |
*/ |
void Handler::get_analog() { |
char tx_data[1] = { 0 }; |
com->send_cmd('a', ADDRESS_ALL, tx_data, 1, true); |
} |
/** |
* get values from LCD / show LCD |
*/ |
void Handler::show_lcd() { |
char tx_data[1] = {0}; |
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true); |
} |
/** |
* got to next LCD Page |
*/ |
void Handler::lcd_up() { |
char tx_data[2] = { 0, 0 }; |
if (data->lcd_cur != data->lcd_max) |
tx_data[0] = data->lcd_cur+1; |
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true); |
} |
/** |
* got to previous LCD Page |
*/ |
void Handler::lcd_down() { |
char tx_data[2] = { 0, 0 }; |
if (data->lcd_cur != 0) |
tx_data[0] = data->lcd_cur-1; |
com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true); |
} |
void Handler::get_version() { |
//TODO: Check if is this correct or do we need data from switch_... |
char tx_data[1] = { 0 }; |
com->send_cmd('v', ADDRESS_ALL, tx_data, 0, true); |
} |
void Handler::get_ppm_channels() { |
char tx_data[1] = { 0 }; |
com->send_cmd('p', ADDRESS_ALL, tx_data, 0, false); |
} |
/** |
* receive data |
*/ |
void Handler::receive_data(sRxData RX) { |
//extract hardware ID from received Data |
int hardwareID = RX.input[1] - 'a'; |
switch(hardwareID) |
{ |
case ADDRESS_FC : |
switch(RX.input[2]) |
{ |
// Motor-Mixer |
case 'N' : |
if (Parser::decode64(RX)) |
{ |
com->stop_resend(); |
if (RX.decode[0] == VERSION_MIXER) |
{ |
//f_MotorMixer->set_MotorConfig(RX); |
} |
} |
break; |
// Motor-Mixer Schreib-Bestätigung |
case 'M' : |
if (Parser::decode64(RX)) |
{ |
com->stop_resend(); |
if (RX.decode[0] == 1) |
{ |
//lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben.")); |
} |
} |
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; |
// Settings lesen |
case 'Q' : // DONE 0.71g |
if (Parser::decode64(RX)) |
{ |
com->stop_resend(); |
if (RX.decode[1] == VERSION_SETTINGS) |
{ |
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);*/ |
} |
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);*/ |
} |
} |
break; |
// Settings written |
case 'S' : // DONE 0.71g |
com->stop_resend(); |
//TODO: QMessagebox("settings written successful") ? |
break; |
} |
case ADDRESS_NC : |
switch(RX.input[2]) |
{ |
// Navigationsdaten |
case 'O' : // NOT DONE 0.12h |
if (Parser::decode64(RX)) |
{ |
//new_NaviData(RX); |
} |
break; |
} |
// case ADDRESS_MK3MAG : |
default : |
switch(RX.input[2]) |
{ |
// LCD-Anzeige |
case 'L' : // DONE 0.71g |
if (Parser::decode64(RX)) |
{ |
com->stop_resend(); |
/*int LCD[150]; |
memcpy(LCD,RX.decode, sizeof(RX.decode)); |
f_LCD->show_Data(LCD); |
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(); |
int Position = RX.decode[0]; |
if (Position != 31) |
{ |
/* |
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);*/ |
} |
if (Position == 31) |
{ |
/* |
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();*/ |
} |
} |
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(); |
} |
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]; |
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) |
{ |
// AllowSend = false; |
QMessageBox::warning(this, QA_NAME, |
tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok); |
} |
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_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. |
// ToolBox::Wait(SLEEP); |
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); |
} |
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();*/ |
} |
break; |
} |
} |
} |
/QMK-Groundstation/branches/libMK/libMK/Handler.h |
---|
0,0 → 1,60 |
#ifndef HANDLER_H |
#define HANDLER_H |
#include <string> |
#include "Parser.h" |
#include "Communication.h" |
#include "Kopter.h" |
#include "../Parameter_Positions.h" |
#include "../typedefs.h" |
/** |
* The Handler handels commands that are send from/to the Mikrokopter |
* and parses them using the Parser-class. |
*/ |
class Handler { |
private: |
Communication * com; |
KopterData * data; |
sRxData rxData; |
public: |
Handler(Communication * com, KopterData * data); |
//FlightCtrl commands |
void get_flightctrl_settings(int index); |
void set_flightctrl_settings(char * tx_data); |
void motor_test(sMotor motor); |
void reset_motor(); |
void read_motor_mixer(); |
void write_motor_mixer(char * tx_data, int length); |
int get_motor_config(char * tx_data); |
//NaviCtrl commands |
void set_navictrl_debug(int speed); |
void stop_navictrl_debug(); |
void send_waypoint(Waypoint_t desired_pos); |
void add_waypoint(Waypoint_t wp); |
void delete_waypoints(); |
//switch between MK modules/components |
void switch_navictrl(); |
void switch_flightctrl(); |
void switch_mk3mag(); |
//commands for MK3MAG |
//commands for all modules/components |
void set_all_debug(int speed); |
void stop_all_debug(); |
void get_analog(); |
void show_lcd(); |
void lcd_up(); |
void lcd_down(); |
void get_version(); |
void get_ppm_channels(); |
void receive_data(sRxData rx); |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/Kopter.h |
---|
0,0 → 1,99 |
#ifndef COPTER_H |
#define COPTER_H |
#include <string> |
using namespace std; |
/** |
* This file contains informations and configurations from the Mikrokopter |
*/ |
// version information for the serial connection |
static const int VERSION_SERIAL_MAJOR = 10; |
static const int VERSION_SERIAL_MINOR = 0; |
// Basis-Adresses for different Hardware components |
static const int ADDRESS_ALL = 0; |
static const int ADDRESS_FC = 1; |
static const int ADDRESS_NC = 2; |
static const int ADDRESS_MK3MAG = 3; |
// settings ID |
static const int SETTINGS_ID = 2; |
static const string HardwareType[] = {"Default", "FlightCtrl", "NaviCtrl", "MK3Mag"}; |
static const int MaxTickerEvents = 5; |
static const int MaxAnalog = 32; |
static const int MaxPlot = 50000; |
static const int MaxNaviPos = 2000; |
struct sMotor |
{ |
int Speed[12]; |
}; |
struct MotorData |
{ |
int motor[16][4]; |
string mixerName; |
int mixerVersion; |
}; |
struct sMode |
{ |
int ID; |
int VERSION_MAJOR; |
int VERSION_MINOR; |
int VERSION_PATCH; |
int VERSION_SERIAL_MAJOR; |
int VERSION_SERIAL_MINOR; |
string Hardware; |
string Version; |
}; |
struct sGPS_Pos |
{ |
long Longitude; |
long Latitude; |
long Altitude; |
}; |
struct sNaviData |
{ |
sGPS_Pos Current; |
sGPS_Pos Target; |
sGPS_Pos Home; |
long Longitude; |
long Latitude; |
long Altitude; |
}; |
struct sWayPoint |
{ |
double Longitude; |
double Latitude; |
double Altitude; |
int Time; |
}; |
/** |
* The KopterData class represents the current state of the MikroKopter. |
* It containes all data that was sent from the Mikrokopter |
*/ |
class KopterData { |
public: |
sMode mode; |
sNaviData navi; |
sMotor motor; |
int analogData[MaxAnalog]; |
// current LCD page |
int lcd_cur; |
//max count of LCD pages |
int lcd_max; |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/Parser.cpp |
---|
0,0 → 1,203 |
#include <Parser.h> |
// Base64 Decoder |
// see Parser.h for details about sRxData |
bool Parser::decode64(sRxData &rx) |
{ |
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; |
//TODO: catch error to show that something went wrong during the decode process |
//throw "Nothing received"; |
} |
while(len != 0) { |
a = rx.input[ptrIn++] - '='; |
b = rx.input[ptrIn++] - '='; |
c = rx.input[ptrIn++] - '='; |
d = rx.input[ptrIn++] - '='; |
if(ptrIn > max - 2) break; |
x = (a << 2) | (b >> 4); |
y = ((b & 0x0f) << 4) | (c >> 2); |
z = ((c & 0x03) << 6) | d; |
if(len--) ptrOut[ptr++] = x; else break; |
if(len--) ptrOut[ptr++] = y; else break; |
if(len--) ptrOut[ptr++] = z; else break; |
} |
for (int a=0; a<ptr; a++) { |
if (length == false) { |
int b1, b2, b3; |
b1 = ptrOut[a++]; |
b2 = ptrOut[a]; |
b3 = (b2 << 8) | b1; |
if (b3 > 32767) |
b3 = b3 - 65536; |
rx.decode[decLen] = b3; |
decLen++; |
} else { |
rx.decode[decLen] = ptrOut[a]; |
decLen++; |
} |
rx.decLen = decLen; |
} |
return true; |
} |
// base64 encoder |
string Parser::encode64(char data[150],unsigned int length) |
{ |
unsigned int pt = 0; |
unsigned char a,b,c; |
unsigned char ptr = 0; |
char tx_buff[150]; |
while(length > 0) |
{ |
if(length) { a = data[ptr++]; length--;} else a = 0; |
if(length) { b = data[ptr++]; length--;} else b = 0; |
if(length) { c = data[ptr++]; length--;} else c = 0; |
tx_buff[pt++] = '=' + (a >> 2); |
tx_buff[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
tx_buff[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
tx_buff[pt++] = '=' + ( c & 0x3f); |
} |
tx_buff[pt] = 0; |
return string(tx_buff); |
} |
// Datensatz nach 8bit Integer |
int Parser::dataToChar(int *data , int start, bool is_signed) { |
int out = (data[start]); |
if ((out > 128) && (is_signed)) |
out = out - 256; |
return out; |
} |
// received char to 8 bit integer |
int Parser::charToData(int data) { |
if (data < 0) |
return data + 256; |
return data; |
} |
// convert data to 16bit Integer |
int Parser::dataToInt(int *Data , int Start, bool is_signed) |
{ |
int Out = (Data[Start+1]<<8) | (Data[Start+0]); |
if ((Out > 32767) && (is_signed)) |
Out = Out - 65536; |
return Out; |
} |
// 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]); |
if ((Out > 32767) && (is_signed)) |
Out = Out; |
return Out; |
} |
float Parser::getFloat(long value, int count) |
{ |
long num = pow(10, count); |
float temp = value; |
return temp / num; |
} |
string Parser::dataToString(int Data[150], int Start, int End) |
{ |
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) |
{ |
RX[1] = 0; |
} |
for(int i=0; i < length-2; i++) |
{ |
CRC+=RX[i]; |
} |
CRC = CRC % 4096; |
if(RX[length - 2] != ('=' + (CRC / 64))) |
{ |
return false; |
} |
if(RX[length - 1] != ('=' + CRC % 64)) |
{ |
return false; |
} |
return true; |
} |
// add CRC |
string Parser::add_CRC(string TX) |
{ |
int length = TX.size(); |
unsigned int tmpCRC = 0; |
char CRC[2]; |
for(int i = 0; i < length; i++) |
{ |
tmpCRC += TX[i]; |
} |
tmpCRC %= 4096; |
CRC[0] = '=' + tmpCRC / 64; |
CRC[1] = '=' + tmpCRC % 64; |
CRC[2] = '\0'; |
return string(TX) + string(CRC); |
} |
/QMK-Groundstation/branches/libMK/libMK/Parser.h |
---|
0,0 → 1,38 |
#ifndef PARSER_H |
#define PARSER_H |
#include <string> |
#include <cmath> |
/** |
* 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); |
static string add_CRC(string TX); |
static bool check_CRC(string RX); |
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 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); |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/QTCommunication.cpp |
---|
0,0 → 1,23 |
#include <QTCommunication.h> |
/** |
* connect to Mikrokopter |
*/ |
void QTCommunication::connect_MK(string addr) { |
}; |
/** |
* send command to Mikrokopter |
*/ |
bool QTCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) { |
return true; |
}; |
/** |
* stop sending commands to Mikrokopter |
* stop timer |
*/ |
void QTCommunication::stop_resend() { |
}; |
/QMK-Groundstation/branches/libMK/libMK/QTCommunication.h |
---|
0,0 → 1,21 |
#ifndef QT_COMMUNICATION_H |
#define QT_COMMUNICATION_H |
#include <Communication.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 QTCommunication : public Communication { |
public: |
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 |
---|
0,0 → 1,16 |
DEPENDPATH += libMK |
INCLUDEPATH += libMK |
MOC_DIR = tmp |
OBJECTS_DIR = obj |
# Input |
HEADERS += Communication.h \ |
Handler.h \ |
Kopter.h \ |
Parser.h \ |
QTCommunication.h |
SOURCES += Communication.cpp \ |
Handler.cpp \ |
Parser.cpp \ |
QTCommunication.cpp |
QT += network |