Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 392 → Rev 393

/QMK-Groundstation/branches/own_com_lib/Forms/dlg_Config.cpp
119,9 → 119,3
 
return Settings;
}
 
dlg_Config::~dlg_Config()
{
}
 
 
/QMK-Groundstation/branches/own_com_lib/Forms/dlg_Config.h
30,8 → 30,6
public:
dlg_Config(QWidget *parent = 0);
 
~dlg_Config();
 
void set_Settings(cSettings *Set, int ID = 0);
cSettings *get_Settings();
 
/QMK-Groundstation/branches/own_com_lib/Forms/mktool.cpp
1459,282 → 1459,8
// Neues Datenpacket empfangen -> Verarbeiten
void MKTool::slot_newData(sRxData RX) // DONE 0.71g
{
if (LastSend.length() > 2)
{
}
int HardwareID = RX.input[1] - 'a';
//handler->receiveData(RX)
 
switch(HardwareID)
{
case ADDRESS_FC :
switch(RX.input[2])
{
// Motor-Mixer
case 'N' :
if (Parser::decode64(RX))
{
o_Connection->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))
{
o_Connection->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))
{
o_Connection->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 geschrieben
case 'S' : // DONE 0.71g
o_Connection->stop_ReSend();
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))
{
o_Connection->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))
{
o_Connection->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))
{
o_Connection->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;
}
}
 
// TODO: Roh-Daten senden zum QMK-Server dazu Sendebuffer bauen.
if ((QMK_Server->property("Connect")) == true)
{
1741,7 → 1467,7
// QMK_Server->send_RawData(RX.String);
}
 
slot_showTerminal(1, QString(RX.str));
slot_showTerminal(1, QString(RX.str.c_str()));
}
 
void MKTool::slot_showTerminal(int Typ, QString Text)
/QMK-Groundstation/branches/own_com_lib/Forms/mktool.h
133,7 → 133,6
sMotor Motor;
 
QString RXS;
QString LastSend;
 
// Softwareupdate
QProcess *Update;
/QMK-Groundstation/branches/own_com_lib/com/Handler.cpp
13,4 → 13,279
void Handler::read_mixer() {
TX_Data[0] = 0;
com->send_cmd('n', ADDRESS_FC, TX_Data, 1, true);
}
 
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->stopReSend();
 
if (RX.decode[0] == VERSION_MIXER)
{
f_MotorMixer->set_MotorConfig(RX);
}
}
break;
// Motor-Mixer Schreib-Best├Ątigung
case 'M' :
if (Parser::decode64(RX))
{
com->stopReSend();
 
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))
{
o_Connection->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 geschrieben
case 'S' : // DONE 0.71g
o_Connection->stop_ReSend();
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))
{
o_Connection->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))
{
o_Connection->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))
{
o_Connection->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/own_com_lib/com/Handler.h
15,6 → 15,7
public:
Handler(Communication * com);
void read_mixer();
void receive_data(sRxData rx);
};
 
#endif
/QMK-Groundstation/branches/own_com_lib/com/Parser.cpp
2,8 → 2,9
 
// Base64 Decoder
// see Parser.h for details about sRxData
void Parser::decode64(sRxData &rx, unsigned int length)
void Parser::decode64(sRxData &rx)
{
int length = rx.str.size();
unsigned char a,b,c,d;
unsigned char ptr = 0;
unsigned char x,y,z;
19,10 → 20,10
}
 
while(len != 0) {
a = RX.input[ptrIn++] - '=';
b = RX.input[ptrIn++] - '=';
c = RX.input[ptrIn++] - '=';
d = RX.input[ptrIn++] - '=';
a = rx.input[ptrIn++] - '=';
b = rx.input[ptrIn++] - '=';
c = rx.input[ptrIn++] - '=';
d = rx.input[ptrIn++] - '=';
 
if(ptrIn > max - 2) break;
 
/QMK-Groundstation/branches/own_com_lib/com/Parser.h
17,11 → 17,11
 
class Parser {
public:
bool decode64(sRxData &rx, unsigned int length);
string encode64(char data[150],unsigned int length);
static bool decode64(sRxData &rx);
static string encode64(char data[150],unsigned int length);
 
string add_CRC(char * TX, int length);
string check_CRC(char * RX, int length);
static string add_CRC(char * TX, int length);
static string check_CRC(char * RX, int length);
 
static float getFloat(long value, int count);