Subversion Repositories Projects

Rev

Rev 451 | Rev 500 | 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() {
    connection_lost();
    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
};

/**
 * received new data from MK
 */



/**
 * 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) {
            //resend evrey 2 seconds
            resendTimer.start(2000);
            resendData = data;
        }
        QByteArray temp(data);
        serial->sendData(temp);
    } else {
        //FIXME: Error message: not connected
    }
};

/**
 * stop sending commands to Mikrokopter
 * stop timer
 */

void QTSerialCommunication::stop_resend() {
   
};

/**
 * resend timer timout
 */

void QTSerialCommunication::slot_resend_timer() {
}

void QTSerialCommunication::received_data(char * data) {
}