/QMK-Groundstation/branches/libMK/Forms/mktool.cpp |
---|
60,7 → 60,7 |
setWindowTitle(QA_NAME + " v" + QA_VERSION); |
// Tab mit Debug-Elementen verbergen |
tab_Main->removeTab(6); |
//tab_Main->removeTab(6); |
// Develop - Nicht gebrauchte sachen abschalten. |
pb_SettingsReset->hide(); |
202,7 → 202,7 |
data = new KopterData(); |
//new QT-Communication object |
com = new QTSerialCommunication(); |
com = new QTSerialCommunication(handler); |
//create handler that handles incomming data |
handler = new Handler(com, data); |
249,10 → 249,10 |
// connect(o_Connection, SIGNAL(newData(sRxData)), this, SLOT(slot_newData(sRxData))); |
// connect(o_Connection, SIGNAL(showTerminal(int, QString)), this, SLOT(slot_showTerminal(int, QString))); |
// Serielle Verbundung öffnen / schließen |
connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_OpenPort())); |
// click on button to open/close serial connection |
connect(ac_ConnectTTY, SIGNAL(triggered()), this, SLOT(slot_serial_connect())); |
// TCP-Connection for other QMK-Groundstations |
// clock on button for the TCP-Connection to other QMK-Groundstations |
connect(ac_QMKServer, SIGNAL(triggered()), this, SLOT(slot_QMKS_Connect())); |
// Buttons Settings lesen / schreiben |
568,8 → 568,6 |
/////////////// |
/*void MKTool::slot_Ticker() |
{ |
if (TickerDiv) |
TickerDiv = false; |
else |
1480,10 → 1478,23 |
} |
} |
// Verbindung zum Kopter herstellen / Trennen |
void MKTool::slot_OpenPort() |
// connect to MK |
void MKTool::slot_serial_connect() |
{ |
//FIXME: Put this in libMK/QTCommunication.cpp |
//connect to Mikrokopter |
com->connect_MK(le_Port->text().toAscii().data()); |
//TODO: check, if connection really is established |
ac_ConnectTTY->setText(tr("Kopter Trennen")); |
le_Port->setEnabled(false); |
//send command to get version of MK |
handler->get_version(); |
//TODO: Ticker->start(2000); |
//TODO: disconnect |
//FIXME: Put this in libMK/QTCommunication.cpp |
/* |
if (o_Connection->isOpen()) |
{ |
/QMK-Groundstation/branches/libMK/Forms/mktool.h |
---|
214,7 → 214,8 |
// Seriell-Port Slots |
// void slot_newData(sRxData RX); |
void slot_OpenPort(); |
//connect to serial port |
void slot_serial_connect(); |
void slot_TabChanged(int Tab); |
/QMK-Groundstation/branches/libMK/eeepc.pro |
---|
8,3 → 8,7 |
INCLUDEPATH += $(HOME)/include /usr/include/qwt-qt4 |
include(global.pri) |
HEADERS += libMK/FlightLog.h |
SOURCES += libMK/FlightLog.cpp |
/QMK-Groundstation/branches/libMK/libMK/Colors.h |
---|
0,0 → 1,55 |
/* |
* Colors.h |
* |
* show some colors in a terminal |
*/ |
#ifndef COLORS_H_ |
#define COLORS_H_ |
// colors |
#define COLOR_ESC "\033" |
#define COLOR_NORMAL COLOR_ESC"[m" |
#define COLOR_BIG COLOR_ESC"[1;1m" //big |
#define COLOR_LIGHT COLOR_ESC"[1;2m" //italic? |
#define COLOR_UNDERLINE COLOR_ESC"[1;4m" //underscored |
#define COLOR_BG_BLACK COLOR_ESC"[1;7m" //background black, foreground white(?) |
#define COLOR_BG_WHITE COLOR_ESC"[1;8m" //background white, foreground white(?) |
#define COLOR_SCORED COLOR_ESC"[1;4m" //scored |
// font colors |
#define COLOR_FG_DARKGREY COLOR_ESC"[1;30m" |
#define COLOR_FG_DARKRED COLOR_ESC"[1;31m" |
#define COLOR_FG_DARKGREEN COLOR_ESC"[1;32m" |
#define COLOR_FG_DARKYELLOW COLOR_ESC"[1;33m" |
#define COLOR_FG_DARKBLUE COLOR_ESC"[1;34m" |
#define COLOR_FG_DARKVIOLET COLOR_ESC"[1;35m" |
#define COLOR_FG_LIGHTBLUE COLOR_ESC"[1;36m" |
#define COLOR_FG_WHITE COLOR_ESC"[1;37m" |
#define COLOR_FG_BLACK COLOR_ESC"[1;38m" |
#define COLOR_FG_MIDGREY COLOR_ESC"[1;90m" |
#define COLOR_FG_LIGHTRED COLOR_ESC"[1;91m" |
#define COLOR_FG_LIGHTGREEN COLOR_ESC"[1;92m" |
#define COLOR_FG_LIGHTYELLOW COLOR_ESC"[1;93m" |
#define COLOR_FG_LIGHTVIOLET COLOR_ESC"[1;95m" |
// background colors |
#define COLOR_BG_DARKGREY COLOR_ESC"[1;40m" |
#define COLOR_BG_DARKRED COLOR_ESC"[1;41m" |
#define COLOR_BG_DARKGREEN COLOR_ESC"[1;42m" |
#define COLOR_BG_DARKYELLOW COLOR_ESC"[1;43m" |
#define COLOR_BG_DARKBLUE COLOR_ESC"[1;44m" |
#define COLOR_BG_DARKVIOLET COLOR_ESC"[1;45m" |
#define COLOR_BG_DARKBLUE2 COLOR_ESC"[1;46m" |
#define COLOR_BG_LIGHTGREY COLOR_ESC"[1;47m" |
#define COLOR_BG_MIDGREY COLOR_ESC"[1;100m" |
#define COLOR_BG_LIGHTRED COLOR_ESC"[1;101m" |
#define COLOR_BG_LIGHTGREEN COLOR_ESC"[1;102m" |
#define COLOR_BG_LIGHTYELLOW COLOR_ESC"[1;103m" |
#define COLOR_BG_LIGHTBLUE COLOR_ESC"[1;104m" |
#define COLOR_BG_LIGHTVIOLET COLOR_ESC"[1;105m" |
#define COLOR_BG_LIGHTBLUE2 COLOR_ESC"[1;106m" |
#endif |
/QMK-Groundstation/branches/libMK/libMK/Communication.cpp |
---|
10,4 → 10,4 |
void Communication::connection_lost() { |
connected = false; |
} |
} |
/QMK-Groundstation/branches/libMK/libMK/FlightLog.cpp |
---|
0,0 → 1,46 |
#include "FlightLog.h" |
//TODO: real logging with |
// * more log levels (arent info, warning and error enough?) |
// * logging in file |
// * the current timestamp |
// * normal difference between log and error messages |
// * and so on |
#include <iostream> |
#include "Colors.h" |
#include <string> |
//#include <ctime> |
#include <sys/time.h> |
void print_data(char * data, std::string type, char * color) { |
char buffer [100]; |
timeval timestamp; |
gettimeofday(×tamp, 0); |
sprintf(buffer, "%i.%03i", timestamp.tv_sec, (timestamp.tv_usec+500)/1000); |
/* |
time_t rawtime; |
struct tm * timeinfo; |
time ( &rawtime ); |
timeinfo = localtime ( &rawtime ); |
strftime(buffer, 100, "%x %X", timeinfo); |
*/ |
#ifdef USE_COLOR |
std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl; |
#else |
std::cout << buffer << " " << type << ": " << data << std::endl; |
#endif |
} |
void FlightLog::info(char * data) { |
print_data(data, "INFO", INFO_COLOR); |
} |
void FlightLog::warning(char * data) { |
print_data(data, "WARNING", WARNING_COLOR); |
} |
void FlightLog::error(char * data) { |
print_data(data, "ERROR", ERROR_COLOR); |
} |
/QMK-Groundstation/branches/libMK/libMK/FlightLog.h |
---|
0,0 → 1,27 |
#ifndef FLIGHTLOG_H |
#define FLIGHTLOG_H |
#include "Kopter.h" |
#include "../typedefs.h" |
#include <string> |
#define USE_COLOR |
#define ERROR_COLOR COLOR_FG_DARKRED |
#define WARNING_COLOR COLOR_BG_LIGHTYELLOW |
#define INFO_COLOR COLOR_NORMAL |
/** |
* The FlightLog saves a human-readable log, so that we can see, what happened. |
*/ |
class FlightLog { |
private: |
//TODO: use a struct that contains timestamp and encoded data? |
static char * log_str; |
public: |
static void info(char * dat); |
static void warning(char * dat); |
static void error(char * dat); |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/Handler.cpp |
---|
1,5 → 1,5 |
#include "Handler.h" |
#include <iostream> |
#include "FlightLog.h" |
/** |
* Constructor that gets a communication instance |
190,8 → 190,20 |
/** |
* receive data |
*/ |
//Parser::decode64(data); |
void Handler::receive_data(int hardwareID, int cmd, char * data) { |
void Handler::receive_data(char * incomming, int length) { |
if (incomming[0] != '#') |
FlightLog::error("this frame is not correct"); |
FlightLog::info(incomming); |
return; |
int hardwareID = incomming[1] - 'a'; |
//The cmd is also known as ID-Byte (or ID for short) in the wiki-dokumentation |
char cmd = incomming[2]; |
//decode data |
unsigned char data[150]; |
Parser::decode64(incomming, length, data, 3); |
switch(hardwareID) |
{ |
case ADDRESS_FC : |
203,6 → 215,7 |
//{ |
com->stop_resend(); |
//decoded data |
FlightLog::info("received motortest values from FlightCtrl"); |
if (data[0] == VERSION_MIXER) |
{ |
//f_MotorMixer->set_MotorConfig(RX); |
215,12 → 228,16 |
if (data[0] == 1) |
{ |
FlightLog::info("motor values written to FlightCtrl."); |
//lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben.")); |
} else { |
FlightLog::warning("could not write motor values to FlightCtrl!"); |
} |
break; |
// Stick-Belegung der Fernsteuerung |
case 'P' : // DONE 0.71g |
FlightLog::info("received stick-settings from FlightCtrl:"); |
/*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)); |
233,7 → 250,7 |
// Settings lesen |
case 'Q' : // DONE 0.71g |
com->stop_resend(); |
FlightLog::info("received settings from FlightCtrl"); |
if (data[1] == VERSION_SETTINGS) |
{ |
int Settings_ID = data[0]; |
247,6 → 264,7 |
} |
else |
{ |
FlightLog::error("wrong FlightCtrl version"); |
/*f_Settings->pb_Read->setDisabled(true); |
f_Settings->pb_Write->setDisabled(true); |
263,6 → 281,7 |
// Settings written |
case 'S' : // DONE 0.71g |
com->stop_resend(); |
FlightLog::info("settings written successfully to FlightCtrl"); |
//TODO: QMessagebox("settings written successful") ? |
break; |
} |
273,6 → 292,7 |
// Navigationsdaten |
case 'O' : // NOT DONE 0.12h |
//new_NaviData(RX); |
FlightLog::info("received navigation data from NaviCtrl"); |
break; |
} |
// case ADDRESS_MK3MAG : |
283,7 → 303,7 |
// LCD-Anzeige |
case 'L' : // DONE 0.71g |
com->stop_resend(); |
FlightLog::info("received LCD page."); |
/*int LCD[150]; |
memcpy(LCD,RX.decode, sizeof(RX.decode)); |
296,7 → 316,7 |
// Analoglabels |
case 'A' : // DONE 0.71g |
com->stop_resend(); |
FlightLog::info("received analog labels"); |
//check position |
if (data[0] != 31) { |
/* |
321,8 → 341,11 |
break; |
// Debug-Daten |
case 'D' : // DONE 0.71g |
FlightLog::info("received debug data:"); |
for (int i = 0; i < MaxAnalog; i++) { |
std::cout << Parser::dataToInt(data, (i * 2) + 2) << std::endl; |
/* |
Parser::dataToInt((char *)data, (i * 2) + 2, false); |
*/ |
} |
//show_DebugData(); |
break; |
329,6 → 352,7 |
// Version |
case 'V' : // DONE 0.71h |
com->stop_resend(); |
FlightLog::info("received version"); |
/* |
Mode.ID = HardwareID; |
Mode.VERSION_MAJOR = RX.decode[0]; |
/QMK-Groundstation/branches/libMK/libMK/Handler.h |
---|
53,7 → 53,7 |
void get_version(); |
void get_ppm_channels(); |
void receive_data(int hardwareID, int cmd, char * data); |
void receive_data(char * incomming, int length); |
}; |
#endif |
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.cpp |
---|
1,11 → 1,14 |
#include "QTSerialCommunication.h" |
#include "../libMK/Parser.h" |
#include "../Classes/ToolBox.h" |
#include <iostream> |
/** |
* initiate connection and stuff |
*/ |
QTSerialCommunication::QTSerialCommunication() { |
QTSerialCommunication::QTSerialCommunication(Handler * handler) { |
this->handler = handler; |
connection_lost(); |
serial = new ManageSerialPort(); |
serial->setBaudRate(BAUD57600); //BaudRate |
31,6 → 34,7 |
timeout--; |
if (serial->isOpen()) { |
serial->receiveData(); |
connect(serial, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_received_data(const QByteArray &))); |
connection_established(); |
//break while loop |
return; |
51,10 → 55,12 |
if (is_connected()) { |
Parser::create_frame(cmd, address, data, length); |
if (resend) { |
//resend evrey 2 seconds |
//resend every 2 seconds |
resendTimer.start(2000); |
resendData = data; |
} |
//TODO: save outgoing data for debug purpose |
std::cout << "send: " << data << std::endl; |
QByteArray temp(data); |
serial->sendData(temp); |
} else { |
67,7 → 73,7 |
* stop timer |
*/ |
void QTSerialCommunication::stop_resend() { |
resendTimer.stop(); |
}; |
/** |
76,5 → 82,23 |
void QTSerialCommunication::slot_resend_timer() { |
} |
void QTSerialCommunication::received_data(char * data) { |
/** |
* get incomming data from QT-Serial-Manager |
* and just give it to the handler. |
*/ |
void QTSerialCommunication::slot_received_data(const QByteArray & data) { |
received_data((char *)data.data(), data.length()); |
} |
/** |
* handel received data |
*/ |
void QTSerialCommunication::received_data(char * data, int length) { |
//Debug: print oud debug data |
//TODO: save data in a file for debug purposes |
std::cout << "receive: " << data << std::endl; |
//handle incomming data |
//FIXME: HIER! Hardware-Id = Mode.id |
handler->receive_data(data, length); |
} |
/QMK-Groundstation/branches/libMK/libMK/QTSerialCommunication.h |
---|
3,6 → 3,7 |
#include <QObject> |
#include <QTimer> |
#include "Communication.h" |
#include "Handler.h" |
#include "../SerialPort/ManageSerialPort.h" |
/** |
17,6 → 18,7 |
Q_OBJECT |
private: |
Handler * handler; |
//timer to resend data if necessary |
QTimer resendTimer; |
//data that will be resended if the timer |
27,10 → 29,11 |
ManageSerialPort * serial; |
private slots: |
void slot_resend_timer(); |
void slot_received_data(const QByteArray & data); |
public: |
QTSerialCommunication(); |
QTSerialCommunication(Handler * handler); |
void connect_MK(char * addr); |
void received_data(char * data); |
void received_data(char * data, int length); |
void send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend); |
void stop_resend(); |
}; |