Subversion Repositories Projects

Rev

Rev 397 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 397 Rev 399
Line 5... Line 5...
5
 */
5
 */
6
Handler::Handler(Communication * com) {
6
Handler::Handler(Communication * com) {
7
    this->com = com;
7
    this->com = com;
8
}
8
}
Line -... Line 9...
-
 
9
 
-
 
10
//-------------FlightCtrl commands--------------------
-
 
11
/**
-
 
12
 * read settings from FlightCtrl (settings index 0x00-0x05)
-
 
13
 */
-
 
14
void Handler::get_flightctrl_settings(int index) {
-
 
15
    char tx_data[2] = {index, 0};
-
 
16
    com->send_cmd('q', ADDRESS_FC, tx_data, 1, true);
-
 
17
}
-
 
18
 
-
 
19
/**
-
 
20
 * write settings to FlightCtrl
-
 
21
 */
-
 
22
void Handler::set_flightctrl_settings(char * tx_data) {
-
 
23
    com->send_cmd('s', ADDRESS_FC, tx_data, MaxParameter+2, true);
-
 
24
}
-
 
25
 
-
 
26
/**
-
 
27
 * test one or more motors
-
 
28
 */
-
 
29
void Handler::motor_test(sMotor motor) {
-
 
30
    char tx_data[12];
-
 
31
    for (int z = 0; z<12; z++)
-
 
32
    {
-
 
33
        tx_data[z] = motor.Speed[z];
-
 
34
    }
-
 
35
    com->send_cmd('t', ADDRESS_FC, tx_data, 12, false);
-
 
36
}
9
 
37
 
10
/**
38
/**
11
 * read mixer values from FlightCtrl
39
 * read mixer values from FlightCtrl
12
 */
40
 */
13
void Handler::read_mixer() {
41
void Handler::read_mixer() {
14
    char tx_data[1] = {0};
42
    char tx_data[1] = {0};
15
    //com->log("read motor mixer");
43
    //com->log("read motor mixer");
16
    com->send_cmd('n', ADDRESS_FC, tx_data, 1, true);
44
    com->send_cmd('n', ADDRESS_FC, tx_data, 1, true);
Line -... Line 45...
-
 
45
}
-
 
46
 
-
 
47
/**
-
 
48
 * write motor mixer values to FlightCtrl
-
 
49
 */
-
 
50
void Handler::write_mixer(char * tx_data, int length) {
-
 
51
    com->send_cmd('m', ADDRESS_FC, tx_data, length, true);
17
}
52
}
18
 
53
 
Line -... Line 54...
-
 
54
void Handler::get_motor_config() {
-
 
55
}
-
 
56
 
-
 
57
//-------------NaviCtrl commands--------------------
-
 
58
/**
-
 
59
 * set debug values for NaviCtrl
-
 
60
 */
-
 
61
void Handler::set_navictrl_debug(int speed) {
-
 
62
    char tx_data[1] = { speed };
-
 
63
    com->send_cmd('o', ADDRESS_NC, tx_data, 1, false);
-
 
64
}
-
 
65
 
-
 
66
/**
-
 
67
 * stop debug for NaviCtrl
-
 
68
 */
-
 
69
void Handler::stop_navictrl_debug() {
-
 
70
    set_navictrl_debug(0);
-
 
71
}
-
 
72
 
-
 
73
/**
-
 
74
 * send a waypoint to the NaviCtrl (the copter will fly to the position emidiately)
-
 
75
 */
-
 
76
void Handler::send_waypoint(Waypoint_t desired_pos) {
-
 
77
    com->send_cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
-
 
78
}
-
 
79
 
-
 
80
/**
-
 
81
 * add waypoint to waypoint list
-
 
82
 */
-
 
83
void Handler::add_waypoint(Waypoint_t wp) {
-
 
84
    com->send_cmd('w', ADDRESS_NC, (char *)&wp, sizeof(wp), false);
-
 
85
}
-
 
86
 
-
 
87
/**
-
 
88
 * clear waypoint list on MK
-
 
89
 */
-
 
90
void Handler::delete_waypoints() {
-
 
91
    Waypoint_t wp;
-
 
92
    wp.Position.Status = INVALID;
-
 
93
    send_waypoint(wp);
-
 
94
}
-
 
95
//-------------switch between Hardware--------------------
-
 
96
void Handler::switch_navictrl() {
-
 
97
    char tx_data[6] = { 0x1B, 0x1B, 0x55, 0xAA, 0x00, '\r'};
-
 
98
    com->send_cmd('#', ADDRESS_NC, tx_data, 6, false);
-
 
99
}
-
 
100
 
-
 
101
void Handler::switch_flightctrl() {
-
 
102
    char tx_data[1] = { 0 };
-
 
103
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
-
 
104
}
-
 
105
 
-
 
106
void Handler::switch_mk3mag() {
-
 
107
    char tx_data[1] = { 1 };
-
 
108
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
-
 
109
}
-
 
110
 
-
 
111
//-------------commands for MK3MAG-----------------
-
 
112
 
-
 
113
 
-
 
114
//-------------commands for all--------------------
-
 
115
 
-
 
116
/**
-
 
117
 * set debug values for all components
-
 
118
 */
-
 
119
void Handler::set_all_debug(int speed) {
-
 
120
    char tx_data[1] = { speed };
-
 
121
    com->send_cmd('d', ADDRESS_ALL, tx_data, 1, false);
-
 
122
}
-
 
123
 
-
 
124
/**
-
 
125
 * stop debug for all components
-
 
126
 */
-
 
127
void Handler::stop_all_debug() {
-
 
128
    set_all_debug(0);
-
 
129
}
-
 
130
 
-
 
131
/**
-
 
132
 * get all analog labels
-
 
133
 */
-
 
134
void Handler::get_analog() {
-
 
135
    char tx_data[1] = { 0 };
-
 
136
    com->send_cmd('a', ADDRESS_ALL, tx_data, 1, true);
-
 
137
}
-
 
138
 
-
 
139
/**
-
 
140
 * get values from LCD / show LCD
-
 
141
 */
-
 
142
void Handler::show_lcd() {
-
 
143
    char tx_data[1] = {0};
-
 
144
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
-
 
145
}
-
 
146
 
-
 
147
/**
-
 
148
 * got to next LCD Page
-
 
149
 */
-
 
150
void Handler::lcd_up() {
-
 
151
    char tx_data[2] = { 0, 0 };
-
 
152
    if (lcd_cur != lcd_max)
-
 
153
        tx_data[0] = lcd_cur+1;
-
 
154
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
-
 
155
}
-
 
156
 
-
 
157
/**
-
 
158
 * got to previous LCD Page
-
 
159
 */
-
 
160
void Handler::lcd_down() {
-
 
161
    char tx_data[2] = { 0, 0 };
-
 
162
    if (lcd_cur != 0)
-
 
163
        tx_data[0] = lcd_cur-1;
-
 
164
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
-
 
165
}
-
 
166
 
-
 
167
void Handler::get_version() {
-
 
168
    //TODO: Check if is this correct or do we need data from switch_...
-
 
169
    char tx_data[1] = { 0 };
-
 
170
    com->send_cmd('v', ADDRESS_ALL, tx_data, 0, true);
-
 
171
}
-
 
172
 
-
 
173
void Handler::get_ppm_channels() {
-
 
174
    char tx_data[1] = { 0 };
-
 
175
    com->send_cmd('p', ADDRESS_ALL, tx_data, 0, false);
-
 
176
}
-
 
177
 
19
void Handler::get_motor_config() {
178
/**
20
}
179
 * receive data
21
 
180
 */
22
void Handler::receive_data(sRxData RX) {
181
void Handler::receive_data(sRxData RX) {
23
    //extract hardware ID from received Data
182
    //extract hardware ID from received Data