Rev 449 | Rev 451 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 449 | Rev 450 | ||
---|---|---|---|
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() { |
8 | serial = new ManageSerialPort(); |
9 | serial = new ManageSerialPort(); |
9 | serial->setBaudRate(BAUD57600); //BaudRate |
10 | serial->setBaudRate(BAUD57600); //BaudRate |
10 | serial->setDataBits(DATA_8); //DataBits |
11 | serial->setDataBits(DATA_8); //DataBits |
11 | serial->setParity(PAR_NONE); //Parity |
12 | serial->setParity(PAR_NONE); //Parity |
12 | serial->setStopBits(STOP_1); //StopBits |
13 | serial->setStopBits(STOP_1); //StopBits |
13 | serial->setFlowControl(FLOW_OFF); //FlowControl |
14 | serial->setFlowControl(FLOW_OFF); //FlowControl |
14 | 15 | ||
15 | serial->setTimeout(0, 10); |
16 | serial->setTimeout(0, 10); |
16 | serial->enableSending(); |
17 | serial->enableSending(); |
17 | serial->enableReceiving(); |
18 | serial->enableReceiving(); |
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 |
40 | */ |
58 | */ |
41 | void QTSerialCommunication::stop_resend() { |
59 | void QTSerialCommunication::stop_resend() { |
42 | 60 | ||
43 | }; |
61 | }; |