Subversion Repositories Projects

Rev

Rev 451 | Rev 500 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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