Rev 449 | Rev 451 | 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() { |
||
9 | serial = new ManageSerialPort(); |
||
10 | serial->setBaudRate(BAUD57600); //BaudRate |
||
11 | serial->setDataBits(DATA_8); //DataBits |
||
12 | serial->setParity(PAR_NONE); //Parity |
||
13 | serial->setStopBits(STOP_1); //StopBits |
||
14 | serial->setFlowControl(FLOW_OFF); //FlowControl |
||
15 | |||
16 | serial->setTimeout(0, 10); |
||
17 | serial->enableSending(); |
||
18 | serial->enableReceiving(); |
||
19 | } |
||
20 | |||
21 | /** |
||
397 | Brean | 22 | * connect to Mikrokopter |
23 | */ |
||
450 | Brean | 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 | } |
||
37 | } |
||
38 | //TODO: Error message, because communication could not established |
||
392 | Brean | 39 | }; |
40 | |||
397 | Brean | 41 | /** |
42 | * send command to Mikrokopter |
||
43 | */ |
||
450 | Brean | 44 | void QTSerialCommunication::send_cmd(char cmd, int address, char data[150], unsigned int length, bool resend) { |
449 | Brean | 45 | if (is_connected()) { |
450 | Brean | 46 | Parser::create_frame(cmd, address, data, length); |
47 | if (resend) { |
||
48 | //FIXME: start timer...? |
||
49 | } |
||
50 | QByteArray temp(data); |
||
51 | serial->sendData(temp); |
||
449 | Brean | 52 | } |
396 | Brean | 53 | }; |
54 | |||
399 | Brean | 55 | /** |
56 | * stop sending commands to Mikrokopter |
||
57 | * stop timer |
||
58 | */ |
||
449 | Brean | 59 | void QTSerialCommunication::stop_resend() { |
396 | Brean | 60 | |
392 | Brean | 61 | }; |