Subversion Repositories Projects

Rev

Rev 449 | Rev 451 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 449 Rev 450
Line 1... Line 1...
1
#include "QTSerialCommunication.h"
1
#include "QTSerialCommunication.h"
2
#include "../libMK/Parser.h"
2
#include "../libMK/Parser.h"
-
 
3
#include "../Classes/ToolBox.h"
3
 
4
 
4
/**
5
/**
5
 * initiate connection and stuff
6
 * initiate connection and stuff
6
 */
7
 */
7
QTSerialCommunication::QTSerialCommunication() {
8
QTSerialCommunication::QTSerialCommunication() {
Line 18... Line 19...
18
}
19
}
19
 
20
 
20
/**
21
/**
21
 * connect to Mikrokopter
22
 * connect to Mikrokopter
22
 */
23
 */
23
void QTSerialCommunication::connect_MK(string addr) {
24
void QTSerialCommunication::connect_MK(char * addr) {
-
 
25
    serial->setPort(addr);
-
 
26
    serial->open();
-
 
27
    int timeout = 5;
-
 
28
    while (timeout > 0) {
-
 
29
        ToolBox::wait(200);
-
 
30
        timeout--;
-
 
31
        if (serial->isOpen()) {
-
 
32
            serial->receiveData();
-
 
33
            connection_established();
-
 
34
            //break while loop
-
 
35
            return;
-
 
36
        }
24
   
37
    }
-
 
38
    //TODO: Error message, because communication could not established
25
};
39
};
26
 
40
 
27
/**
41
/**
28
 * send command to Mikrokopter
42
 * send command to Mikrokopter
29
 */
43
 */
30
bool QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
44
void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) {
31
    if (is_connected()) {
45
    if (is_connected()) {
-
 
46
        Parser::create_frame(cmd, address, data, length);
-
 
47
        if (resend) {
-
 
48
            //FIXME: start timer...?
-
 
49
        }
32
        //a valid command starts
50
        QByteArray temp(data);
-
 
51
        serial->sendData(temp);
33
    }
52
    }
34
    return true;
-
 
35
};
53
};
36
 
54
 
37
/**
55
/**
38
 * stop sending commands to Mikrokopter
56
 * stop sending commands to Mikrokopter
39
 * stop timer
57
 * stop timer