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; |
}; |
|
/** |