Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 448 → Rev 449

/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