Rev 449 |
Rev 451 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "QTSerialCommunication.h"
#include "../libMK/Parser.h"
#include "../Classes/ToolBox.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(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
*/
void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
if (is_connected()) {
Parser::create_frame(cmd, address, data, length);
if (resend) {
//FIXME: start timer...?
}
QByteArray temp(data);
serial->sendData(temp);
}
};
/**
* stop sending commands to Mikrokopter
* stop timer
*/
void QTSerialCommunication::stop_resend() {
};