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" |
|
Line 3... | Line 4... | ||
3 | 4 | ||
4 | /** |
5 | /** |
5 | * initiate connection and stuff |
6 | * initiate connection and stuff |
6 | */ |
7 | */ |
Line 18... | Line 19... | ||
18 | } |
19 | } |
Line 19... | Line 20... | ||
19 | 20 | ||
20 | /** |
21 | /** |
21 | * connect to Mikrokopter |
22 | * connect to Mikrokopter |
22 | */ |
23 | */ |
- | 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; |
|
23 | void QTSerialCommunication::connect_MK(string addr) { |
36 | } |
- | 37 | } |
|
24 | 38 | //TODO: Error message, because communication could not established |
|
Line 25... | Line 39... | ||
25 | }; |
39 | }; |
26 | 40 | ||
27 | /** |
41 | /** |
28 | * send command to Mikrokopter |
42 | * send command to Mikrokopter |
29 | */ |
43 | */ |
- | 44 | void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) { |
|
- | 45 | if (is_connected()) { |
|
- | 46 | Parser::create_frame(cmd, address, data, length); |
|
- | 47 | if (resend) { |
|
30 | bool QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) { |
48 | //FIXME: start timer...? |
- | 49 | } |
|
31 | if (is_connected()) { |
50 | QByteArray temp(data); |
32 | //a valid command starts |
- | |
33 | } |
51 | serial->sendData(temp); |
Line 34... | Line 52... | ||
34 | return true; |
52 | } |
35 | }; |
53 | }; |
36 | 54 |