Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 393 → Rev 396

/QMK-Groundstation/branches/own_com_lib/com/Communication.h
8,11 → 8,12
 
using namespace std;
 
class Communication {
class Communication{
public:
//connect to MK
virtual void connectMK(string) {};
//send command to MK
virtual bool sendCmd(char, int, char[150],unsigned int, bool) {};
virtual bool sendCmd(char, int, char[150],unsigned int, bool) { return false; };
virtual void stopReSend() {};
};
#endif
/QMK-Groundstation/branches/own_com_lib/com/Handler.cpp
11,10 → 11,14
* read mixer values from FlightCtrl
*/
void Handler::read_mixer() {
TX_Data[0] = 0;
com->send_cmd('n', ADDRESS_FC, TX_Data, 1, true);
char tx_data[1] = {0};
//com->log("read motor mixer");
com->sendCmd('n', ADDRESS_FC, tx_data, 1, true);
}
 
void Handler::get_motor_config() {
}
 
void Handler::receive_data(sRxData RX) {
//extract hardware ID from received Data
int hardwareID = RX.input[1] - 'a';
31,7 → 35,7
 
if (RX.decode[0] == VERSION_MIXER)
{
f_MotorMixer->set_MotorConfig(RX);
//f_MotorMixer->set_MotorConfig(RX);
}
}
break;
43,7 → 47,7
 
if (RX.decode[0] == 1)
{
lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
//lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
}
}
break;
52,7 → 56,7
case 'P' : // DONE 0.71g
if (Parser::decode64(RX))
{
f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true));
/*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));
59,7 → 63,7
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));
f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/
}
break;
// Settings lesen
66,22 → 70,22
case 'Q' : // DONE 0.71g
if (Parser::decode64(RX))
{
o_Connection->stop_ReSend();
com->stopReSend();
 
if (RX.decode[1] == VERSION_SETTINGS)
{
int Settings_ID = RX.decode[0];
for (int a = 0; a < MaxParameter; a++)
/*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);
f_Settings->pb_Write->setEnabled(true);*/
}
else
{
f_Settings->pb_Read->setDisabled(true);
/*f_Settings->pb_Read->setDisabled(true);
f_Settings->pb_Write->setDisabled(true);
 
QString name = QString("Versionen inkompatibel.\n") +
91,13 → 95,14
QString(RX.decode[1]) +
QString("\nParameterbearbeitung nicht moeglich.");
QMessageBox::warning(this, QA_NAME,
name, QMessageBox::Ok);
name, QMessageBox::Ok);*/
}
}
break;
// Settings geschrieben
// Settings written
case 'S' : // DONE 0.71g
o_Connection->stop_ReSend();
com->stopReSend();
//TODO: QMessagebox("settings written successful") ?
break;
}
 
108,7 → 113,7
case 'O' : // NOT DONE 0.12h
if (Parser::decode64(RX))
{
new_NaviData(RX);
//new_NaviData(RX);
}
break;
}
121,9 → 126,9
case 'L' : // DONE 0.71g
if (Parser::decode64(RX))
{
o_Connection->stop_ReSend();
com->stopReSend();
 
int LCD[150];
/*int LCD[150];
memcpy(LCD,RX.decode, sizeof(RX.decode));
 
f_LCD->show_Data(LCD);
130,6 → 135,7
 
LCD_Page = RX.decode[0];
LCD_MAX_Page = RX.decode[1];
*/
}
break;
// Analoglabels
136,11 → 142,12
case 'A' : // DONE 0.71g
if (Parser::decode64(RX))
{
o_Connection->stop_ReSend();
com->stopReSend();
 
int Position = RX.decode[0];
if (Position != 31)
{
/*
Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed();
if (Settings->Analog1.Label[Position] == "")
{
148,10 → 155,11
}
Position ++;
TX_Data[0] = Position;
o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);
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]);
158,7 → 166,7
}
Settings->Analog1.Version = QString(Mode.Version);
Settings->write_Settings_AnalogLabels(HardwareID);
config_Plot();
config_Plot();*/
}
}
break;
168,9 → 176,9
{
for (int i = 0; i < MaxAnalog; i++)
{
AnalogData[i] = Parser::dataToInt(RX.decode, (i * 2) + 2);
//AnalogData[i] = Parser::dataToInt(RX.decode, (i * 2) + 2);
}
show_DebugData();
//show_DebugData();
}
break;
// Version
177,8 → 185,8
case 'V' : // DONE 0.71h
if (Parser::decode64(RX))
{
o_Connection->stop_ReSend();
 
com->stopReSend();
/*
Mode.ID = HardwareID;
Mode.VERSION_MAJOR = RX.decode[0];
Mode.VERSION_MINOR = RX.decode[1];
283,7 → 291,7
{
lb_Analog[a]->setText(Settings->Analog1.Label[a]);
}
config_Plot();
config_Plot();*/
}
break;
}
/QMK-Groundstation/branches/own_com_lib/com/Handler.h
1,8 → 1,10
#ifndef HANDLER_H
#define HANDLER_H
#include <string>
#include <Parser.h>
#include <Communication.h>
#include "Parser.h"
#include "Communication.h"
#include "Kopter.h"
#include "../Parameter_Positions.h"
 
/**
* The Handler handels commands that are send from/to the Mikrokopter
12,10 → 14,14
class Handler {
private:
Communication * com;
 
//buffer to send data
//char tx_data[150];
public:
Handler(Communication * com);
void read_mixer();
void receive_data(sRxData rx);
void get_motor_config();
};
 
#endif
/QMK-Groundstation/branches/own_com_lib/com/Parser.cpp
2,7 → 2,7
 
// Base64 Decoder
// see Parser.h for details about sRxData
void Parser::decode64(sRxData &rx)
bool Parser::decode64(sRxData &rx)
{
int length = rx.str.size();
unsigned char a,b,c,d;
15,8 → 15,10
int len = length;
int decLen = 0;
 
if (rx.Input[ptrIn] == 0) {
throw "Nothing received";
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) {
37,7 → 39,7
}
 
for (int a=0; a<ptr; a++) {
if (Long == false) {
if (length == false) {
int b1, b2, b3;
 
b1 = ptrOut[a++];
48,14 → 50,15
if (b3 > 32767)
b3 = b3 - 65536;
 
RX.decode[DecLen] = b3;
DecLen++;
rx.decode[decLen] = b3;
decLen++;
} else {
RX.decode[DecLen] = ptrOut[a];
DecLen++;
rx.decode[decLen] = ptrOut[a];
decLen++;
}
RX.DecLen = DecLen;
rx.decLen = decLen;
}
return true;
}
 
// base64 encoder
67,11 → 70,11
 
char tx_buff[150];
 
while(Length > 0)
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;
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));
125,11 → 128,11
 
float Parser::getFloat(long value, int count)
{
long num = math.pow(10, count);
long num = pow(10, count);
 
float temp = value;
 
return value / num;
return temp / num;
}
 
string Parser::dataToString(int Data[150], int Start, int End)
145,10 → 148,11
}
 
// check CRC
bool Parser::check_CRC(char * RX, int length)
bool Parser::check_CRC(string RXstr)
{
int length = RXstr.size();
int CRC = 0;
char *RX;
char *RX = (char *)RXstr.c_str();
 
if (RX[1] == 127)
{
176,8 → 180,9
}
 
// add CRC
string Parser::add_CRC(char * TX, int length)
string Parser::add_CRC(string TX)
{
int length = TX.size();
unsigned int tmpCRC = 0;
 
char CRC[2];
/QMK-Groundstation/branches/own_com_lib/com/Parser.h
1,6 → 1,7
#ifndef PARSER_H
#define PARSER_H
#include <string>
#include <cmath>
 
/**
* The Parser gets values from the Mikrokopter-USART interface
7,6 → 8,8
* and parses them into a sRxData-Struct
*/
 
using namespace std;
 
struct sRxData
{
char *input;
20,8 → 23,8
static bool decode64(sRxData &rx);
static string encode64(char data[150],unsigned int length);
 
static string add_CRC(char * TX, int length);
static string check_CRC(char * RX, int length);
static string add_CRC(string TX);
static bool check_CRC(string RX);
 
static float getFloat(long value, int count);
 
/QMK-Groundstation/branches/own_com_lib/com/QTCommunication.cpp
6,4 → 6,8
 
bool QTCommunication::sendCmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
};
 
void QTCommunication::stopReSend() {
};
/QMK-Groundstation/branches/own_com_lib/com/QTCommunication.h
10,9 → 10,12
* ( philippe.vianney.liaud gmail.com )
*/
 
using namespace std;
 
class QTCommunication : public Communication {
public:
void connectMK(string addr);
bool sendCmd(char cmd, int address, char data[150], unsigned int length, bool resend);
void stopReSend();
};
#endif