Subversion Repositories Projects

Rev

Rev 451 | Rev 500 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
449 Brean 1
#include "QTSerialCommunication.h"
2
#include "../libMK/Parser.h"
450 Brean 3
#include "../Classes/ToolBox.h"
392 Brean 4
 
397 Brean 5
/**
449 Brean 6
 * initiate connection and stuff
7
 */
8
QTSerialCommunication::QTSerialCommunication() {
451 Brean 9
    connection_lost();
449 Brean 10
    serial = new ManageSerialPort();
11
    serial->setBaudRate(BAUD57600);   //BaudRate
12
    serial->setDataBits(DATA_8);      //DataBits
13
    serial->setParity(PAR_NONE);      //Parity
14
    serial->setStopBits(STOP_1);      //StopBits
15
    serial->setFlowControl(FLOW_OFF); //FlowControl
16
 
17
    serial->setTimeout(0, 10);
18
    serial->enableSending();
19
    serial->enableReceiving();
20
}
21
 
22
/**
397 Brean 23
 * connect to Mikrokopter
24
 */
450 Brean 25
void QTSerialCommunication::connect_MK(char * addr) {
26
    serial->setPort(addr);
27
    serial->open();
28
    int timeout = 5;
29
    while (timeout > 0) {
30
        ToolBox::wait(200);
31
        timeout--;
32
        if (serial->isOpen()) {
33
            serial->receiveData();
34
            connection_established();
35
            //break while loop
36
            return;
37
        }
38
    }
39
    //TODO: Error message, because communication could not established
392 Brean 40
};
41
 
397 Brean 42
/**
451 Brean 43
 * received new data from MK
44
 */
45
 
46
 
47
/**
397 Brean 48
 * send command to Mikrokopter
49
 */
450 Brean 50
void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
449 Brean 51
    if (is_connected()) {
450 Brean 52
        Parser::create_frame(cmd, address, data, length);
53
        if (resend) {
451 Brean 54
            //resend evrey 2 seconds
55
            resendTimer.start(2000);
56
            resendData = data;
450 Brean 57
        }
58
        QByteArray temp(data);
59
        serial->sendData(temp);
451 Brean 60
    } else {
61
        //FIXME: Error message: not connected
449 Brean 62
    }
396 Brean 63
};
64
 
399 Brean 65
/**
66
 * stop sending commands to Mikrokopter
67
 * stop timer
68
 */
449 Brean 69
void QTSerialCommunication::stop_resend() {
396 Brean 70
 
451 Brean 71
};
72
 
73
/**
74
 * resend timer timout
75
 */
76
void QTSerialCommunication::slot_resend_timer() {
462 Brean 77
}
78
 
79
void QTSerialCommunication::received_data(char * data) {
451 Brean 80
}