Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 449 → Rev 450

/QMK-Groundstation/branches/libMK/Classes/ToolBox.cpp
49,10 → 49,9
}*/
 
// Datensatz nach QString
QString ToolBox::dataToQString(char data[MAX_DATA_SIZE], int start, int end)
QString ToolBox::dataToQString(char * data, int start, int end)
{
return QString(data);
//return QString(Parser::dataToString(data, start, end));
return QString(Parser::dataToString(data, start, end).c_str());
}
 
// Alle Icons
/QMK-Groundstation/branches/libMK/Forms/dlg_MotorMixer.cpp
77,12 → 77,12
 
// Motordaten ├╝bernehmen.
//FIXME: put this in libMK/Handler.cpp and fill motor values in KopterData
/*
void dlg_MotorMixer::set_MotorConfig(sRxData RX)
 
void dlg_MotorMixer::set_MotorConfig(char * data)
{
int Pos = 0;
 
MixerName = ToolBox::dataToQString(RX.decode, 1, 12);
MixerName = ToolBox::dataToQString(data, 1, 12);
 
Pos = 13;
 
90,7 → 90,7
{
for (int y = 0; y < 4; y++)
{
Motor[z][y] = Parser::dataToChar(RX.decode,Pos);
Motor[z][y] = Parser::dataToChar(data,Pos);
Pos++;
}
}
97,7 → 97,6
 
set_MotorData();
}
*/
 
// Motordaten aus GUI ├╝bernehmen
void dlg_MotorMixer::get_MotorData()
/QMK-Groundstation/branches/libMK/libMK/Kopter.h
23,6 → 23,15
// settings ID
#define SETTINGS_ID 2
 
//TODO: use enum?
/*
enum HardwareType {
Default,
FlightCtrl,
NaviCtrl,
MK3Mag
};
*/
static const char * HardwareType[] = {"Default", "FlightCtrl", "NaviCtrl", "MK3Mag"};
 
static const int MaxTickerEvents = 5;
/QMK-Groundstation/branches/libMK/libMK/Parser.cpp
10,29 → 10,28
* 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;
//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;
}
//allociate memory for the data we want to send
char * send_data = (char *)malloc(buf_len);
*/
Parser::encode64(data, length);
char send_data[150];
send_data[0]='#';
send_data[1]=(char)address+'a';
send_data[2]=cmd;
for (int i = 0; i < length; i++)
send_data[i+3] = data[i];
add_CRC(send_data, length+3);
data = send_data;
}
}
 
 
130,7 → 129,7
}
 
// Datensatz nach 8bit Integer
int Parser::dataToChar(int *data , int start, bool is_signed) {
int Parser::dataToChar(char *data , int start, bool is_signed) {
int out = (data[start]);
 
if ((out > 128) && (is_signed))
151,7 → 150,7
/**
* convert data to 16bit Integer
*/
int Parser::dataToInt(int *Data , int Start, bool is_signed)
int Parser::dataToInt(char *Data , int Start, bool is_signed)
{
int Out = (Data[Start+1]<<8) | (Data[Start+0]);
 
165,7 → 164,7
/**
* convert data to 32bit Long
*/
long Parser::dataToLong(int *Data , int Start, bool is_signed)
long Parser::dataToLong(char *Data , int Start, bool is_signed)
{
long Out = (Data[Start+3]<<24) | (Data[Start+2]<<16) | (Data[Start+1]<<8) | (Data[Start+0]);
 
175,6 → 174,14
return Out;
}
 
std::string Parser::dataToString(char * data, int start, int end)
{
char tmp[MAX_DATA_SIZE];
for (int i = start; i < end; i++)
tmp[i-start] = data[i];
return std::string(tmp);
}
 
float Parser::getFloat(long value, int count)
{
long num = pow(10, count);
230,8 → 237,8
 
tmpCRC %= 4096;
 
tx[length-2] = '=' + tmpCRC / 64;
tx[length-1] = '=' + tmpCRC % 64;
tx[length] = '\0';
tx[length] = '=' + tmpCRC / 64;
tx[length+1] = '=' + tmpCRC % 64;
tx[length+2] = '\0';
}
 
/QMK-Groundstation/branches/libMK/libMK/Parser.h
1,6 → 1,8
#ifndef PARSER_H
#define PARSER_H
#include "Kopter.h"
#include <cmath>
#include <string>
 
/**
* The Parser gets values from the Mikrokopter-USART interface
16,7 → 18,7
*/
class Parser {
public:
void create_frame(char cmd, int address, char * data, unsigned int length);
static void create_frame(char cmd, int address, char * data, unsigned int length);
 
static int decode64(char * data, int len, unsigned char *ptrOut, int offset);
static void encode64(char data[150],unsigned int length);
26,9 → 28,10
 
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 int dataToInt(char *data , int start, bool is_signed = true);
static long dataToLong(char *data , int start, bool is_signed = true);
static int dataToChar(char *data , int start, bool is_signed = true);
static std::string dataToString(char * data, int start, int end);
static int charToData(int data);
};
 
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.cpp
1,5 → 1,6
#include "QTSerialCommunication.h"
#include "../libMK/Parser.h"
#include "../Classes/ToolBox.h"
 
/**
* initiate connection and stuff
20,18 → 21,35
/**
* connect to Mikrokopter
*/
void QTSerialCommunication::connect_MK(string addr) {
void QTSerialCommunication::connect_MK(char * addr) {
serial->setPort(addr);
serial->open();
int timeout = 5;
while (timeout > 0) {
ToolBox::wait(200);
timeout--;
if (serial->isOpen()) {
serial->receiveData();
connection_established();
//break while loop
return;
}
}
//TODO: Error message, because communication could not established
};
 
/**
* send command to Mikrokopter
*/
bool QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
if (is_connected()) {
//a valid command starts
Parser::create_frame(cmd, address, data, length);
if (resend) {
//FIXME: start timer...?
}
QByteArray temp(data);
serial->sendData(temp);
}
return true;
};
 
/**
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.h
18,8 → 18,8
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 connect_MK(char * addr);
void send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend);
void stop_resend();
};
#endif