Subversion Repositories NaviCtrl

Rev

Rev 357 | Rev 360 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 357 Rev 358
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
42
// +     clearly linked as origin
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE.
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <stdio.h>
57
#include <stdio.h>
58
#include <stdarg.h>
58
#include <stdarg.h>
59
#include <string.h>
59
#include <string.h>
60
 
60
 
61
#include "91x_lib.h"
61
#include "91x_lib.h"
62
#include "main.h"
62
#include "main.h"
63
#include "config.h"
63
#include "config.h"
64
#include "menu.h"
64
#include "menu.h"
65
#include "GPS.h"
65
#include "GPS.h"
66
#include "i2c.h"
66
#include "i2c.h"
67
#include "uart0.h"
67
#include "uart0.h"
68
#include "uart1.h"
68
#include "uart1.h"
69
#include "uart2.h"
69
#include "uart2.h"
70
#include "timer1.h"
70
#include "timer1.h"
71
#include "timer2.h"
71
#include "timer2.h"
72
#include "analog.h"
72
#include "analog.h"
73
#include "compass.h"
73
#include "compass.h"
74
#include "waypoints.h"
74
#include "waypoints.h"
75
#include "mkprotocol.h"
75
#include "mkprotocol.h"
76
#include "params.h"
76
#include "params.h"
77
#include "fifo.h"
77
#include "fifo.h"
78
#include "debug.h"
78
#include "debug.h"
-
 
79
#include "spi_slave.h"
79
#include "ftphelper.h"
80
#include "ftphelper.h"
80
 
81
 
81
#define FALSE   0
82
#define FALSE   0
82
#define TRUE    1
83
#define TRUE    1
83
 
84
 
84
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
85
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
85
u32 UART1_AboTimeOut = 0;
86
u32 UART1_AboTimeOut = 0;
86
 
87
 
87
u8 UART1_Request_VersionInfo    = FALSE;
88
u8 UART1_Request_VersionInfo    = FALSE;
88
u8 UART1_Request_ExternalControl= FALSE;
89
u8 UART1_Request_ExternalControl= FALSE;
89
u8 UART1_Request_Display                = FALSE;
90
u8 UART1_Request_Display                = FALSE;
90
u8 UART1_Request_Display1               = FALSE;
91
u8 UART1_Request_Display1               = FALSE;
91
u8 UART1_Request_DebugData              = FALSE;
92
u8 UART1_Request_DebugData              = FALSE;
92
u8 UART1_Request_DebugLabel             = 255;
93
u8 UART1_Request_DebugLabel             = 255;
93
u8 UART1_Request_NaviData               = FALSE;
94
u8 UART1_Request_NaviData               = FALSE;
94
u8 UART1_Request_ErrorMessage   = FALSE;
95
u8 UART1_Request_ErrorMessage   = FALSE;
95
u8 UART1_Request_WritePoint             = 0xFF;
96
u8 UART1_Request_WritePoint             = 0xFF;
96
u8 UART1_Request_ReadPoint              = 0;
97
u8 UART1_Request_ReadPoint              = 0;
97
u8 UART1_Request_Data3D             = FALSE;
98
u8 UART1_Request_Data3D             = FALSE;
-
 
99
u8 UART1_Request_MotorData          = FALSE;
98
u8 UART1_Request_Echo               = FALSE;
100
u8 UART1_Request_Echo               = FALSE;
99
u8 UART1_Request_ParameterId    = 0;
101
u8 UART1_Request_ParameterId    = 0;
100
u8 UART1_Request_Parameter              = FALSE;
102
u8 UART1_Request_Parameter              = FALSE;
101
u8 UART1_DisplayKeys                    = 0;
103
u8 UART1_DisplayKeys                    = 0;
102
u8 UART1_DisplayLine                    = 0;
104
u8 UART1_DisplayLine                    = 0;
103
u8 UART1_ConfirmFrame                   = 0;
105
u8 UART1_ConfirmFrame                   = 0;
104
u8 UART1_Request_FTP                    = FALSE;
106
u8 UART1_Request_FTP                    = FALSE;
105
 
107
 
106
 
108
 
107
UART_TypeDef *DebugUART = UART1;
109
UART_TypeDef *DebugUART = UART1;
108
 
110
 
109
#ifdef FOLLOW_ME
111
#ifdef FOLLOW_ME
110
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
112
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
111
u32 UART1_FollowMe_Timer        = 0;
113
u32 UART1_FollowMe_Timer        = 0;
112
Point_t FollowMe;
114
Point_t FollowMe;
113
#endif
115
#endif
114
 
116
 
115
// the primary rx fifo
117
// the primary rx fifo
116
#define UART1_RX_FIFO_LEN 512
118
#define UART1_RX_FIFO_LEN 512
117
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
119
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
118
fifo_t UART1_rx_fifo;
120
fifo_t UART1_rx_fifo;
119
 
121
 
120
// the rx buffer
122
// the rx buffer
121
#define UART1_RX_BUFFER_LEN  150
123
#define UART1_RX_BUFFER_LEN  150
122
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
124
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
123
Buffer_t UART1_rx_buffer;
125
Buffer_t UART1_rx_buffer;
124
 
126
 
125
// the tx buffer
127
// the tx buffer
126
#define UART1_TX_BUFFER_LEN  1024
128
#define UART1_TX_BUFFER_LEN  1024
127
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
129
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
128
Buffer_t UART1_tx_buffer;
130
Buffer_t UART1_tx_buffer;
129
 
131
 
130
volatile u8 SerialLinkOkay = 0;
132
volatile u8 SerialLinkOkay = 0;
131
 
133
 
132
u8 text[200];
134
u8 text[200];
133
 
135
 
134
const u8 ANALOG_LABEL[32][16] =
136
const u8 ANALOG_LABEL[32][16] =
135
{
137
{
136
   //1234567890123456
138
   //1234567890123456
137
        "AngleNick       ", //0
139
        "AngleNick       ", //0
138
        "AngleRoll       ",
140
        "AngleRoll       ",
139
        "AccNick         ",
141
        "AccNick         ",
140
        "AccRoll         ",
142
        "AccRoll         ",
141
        "OperatingRadius ",
143
        "OperatingRadius ",
142
        "FC-Flags        ", //5
144
        "FC-Flags        ", //5
143
        "NC-Flags        ",
145
        "NC-Flags        ",
144
        "NickServo       ",
146
        "NickServo       ",
145
        "RollServo       ",
147
        "RollServo       ",
146
        "GPS Data        ",
148
        "GPS Data        ",
147
        "CompassHeading  ", //10
149
        "CompassHeading  ", //10
148
        "GyroHeading     ",
150
        "GyroHeading     ",
149
        "SPI Error       ",
151
        "SPI Error       ",
150
        "SPI Okay        ",
152
        "SPI Okay        ",
151
        "I2C Error       ",
153
        "I2C Error       ",
152
        "I2C Okay        ", //15
154
        "I2C Okay        ", //15
153
        "16              ",
155
        "16              ",
154
        "17              ",
156
        "17              ",
155
        "18              ",
157
        "18              ",
156
        "19              ", // SD-Card-time 
158
        "19              ", // SD-Card-time 
157
        "EarthMagnet [%] ", //20
159
        "EarthMagnet [%] ", //20
158
        "Z_Speed         ",
160
        "Z_Speed         ",
159
        "N_Speed         ",
161
        "N_Speed         ",
160
        "E_Speed         ",
162
        "E_Speed         ",
161
        "Magnet X        ",
163
        "Magnet X        ",
162
        "Magnet Y        ", //25
164
        "Magnet Y        ", //25
163
        "Magnet Z        ",
165
        "Magnet Z        ",
164
        "Distance N      ",
166
        "Distance N      ",
165
        "Distance E      ",
167
        "Distance E      ",
166
        "GPS_Nick        ",
168
        "GPS_Nick        ",
167
        "GPS_Roll        ", //30
169
        "GPS_Roll        ", //30
168
        "Used_Sats       "
170
        "Used_Sats       "
169
};
171
};
170
 
172
 
171
DebugOut_t DebugOut;
173
DebugOut_t DebugOut;
172
ExternControl_t ExternControl;
174
ExternControl_t ExternControl;
173
UART_VersionInfo_t UART_VersionInfo;
175
UART_VersionInfo_t UART_VersionInfo;
174
NaviData_t NaviData;
176
NaviData_t NaviData;
175
Data3D_t Data3D;
177
Data3D_t Data3D;
176
u16 Echo; // 2 bytes recieved will be sent back as echo
178
u16 Echo; // 2 bytes recieved will be sent back as echo
177
 
179
 
178
u32 UART1_DebugData_Timer = 0;
180
u32 UART1_DebugData_Timer = 0;
179
u32 UART1_DebugData_Interval = 0;       // in ms
181
u32 UART1_DebugData_Interval = 0;       // in ms
180
u32 UART1_NaviData_Timer = 0;
182
u32 UART1_NaviData_Timer = 0;
181
u32 UART1_NaviData_Interval = 0;        // in ms
183
u32 UART1_NaviData_Interval = 0;        // in ms
182
u32 UART1_Data3D_Timer = 0;
184
u32 UART1_Data3D_Timer = 0;
183
u32 UART1_Data3D_Interval = 0;          // in ms
185
u32 UART1_Data3D_Interval = 0;          // in ms
-
 
186
u32 UART1_MotorData_Timer = 0;
-
 
187
u32 UART1_MotorData_Interval = 0;               // in ms
184
u32 UART1_Display_Timer = 0;
188
u32 UART1_Display_Timer = 0;
185
u32 UART1_Display_Interval = 0;         // in ms
189
u32 UART1_Display_Interval = 0;         // in ms
186
 
190
 
187
/********************************************************/
191
/********************************************************/
188
/*            Initialization the UART1                  */
192
/*            Initialization the UART1                  */
189
/********************************************************/
193
/********************************************************/
190
void UART1_Init (void)
194
void UART1_Init (void)
191
{
195
{
192
        GPIO_InitTypeDef GPIO_InitStructure;
196
        GPIO_InitTypeDef GPIO_InitStructure;
193
        UART_InitTypeDef UART_InitStructure;
197
        UART_InitTypeDef UART_InitStructure;
194
 
198
 
195
        // initialize txd buffer
199
        // initialize txd buffer
196
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
200
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
197
 
201
 
198
        // initialize rxd buffer
202
        // initialize rxd buffer
199
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
203
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
200
 
204
 
201
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
205
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
202
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
206
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
203
 
207
 
204
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
208
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
205
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
209
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
206
 
210
 
207
        /*Configure UART1_Rx pin GPIO3.2*/
211
        /*Configure UART1_Rx pin GPIO3.2*/
208
        GPIO_StructInit(&GPIO_InitStructure);
212
        GPIO_StructInit(&GPIO_InitStructure);
209
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
213
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
210
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
214
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
211
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
215
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
212
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
216
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
213
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
217
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
214
        GPIO_Init(GPIO3, &GPIO_InitStructure);
218
        GPIO_Init(GPIO3, &GPIO_InitStructure);
215
 
219
 
216
        /*Configure UART1_Tx pin GPIO3.3*/
220
        /*Configure UART1_Tx pin GPIO3.3*/
217
        GPIO_StructInit(&GPIO_InitStructure);
221
        GPIO_StructInit(&GPIO_InitStructure);
218
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
222
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
219
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
223
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
220
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
224
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
221
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
225
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
222
        GPIO_Init(GPIO3, &GPIO_InitStructure);
226
        GPIO_Init(GPIO3, &GPIO_InitStructure);
223
 
227
 
224
        /* UART1 configured as follow:
228
        /* UART1 configured as follow:
225
        - Word Length = 8 Bits
229
        - Word Length = 8 Bits
226
        - One Stop Bit
230
        - One Stop Bit
227
        - No parity
231
        - No parity
228
        - BaudRate = 57600 baud
232
        - BaudRate = 57600 baud
229
        - Hardware flow control Disabled
233
        - Hardware flow control Disabled
230
        - Receive and transmit enabled
234
        - Receive and transmit enabled
231
        - Receive and transmit FIFOs are Disabled
235
        - Receive and transmit FIFOs are Disabled
232
        */
236
        */
233
        UART_StructInit(&UART_InitStructure);
237
        UART_StructInit(&UART_InitStructure);
234
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
238
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
235
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
239
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
236
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
240
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
237
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
241
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
238
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
242
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
239
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
243
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
240
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
244
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
241
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
245
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
242
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;
246
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;
243
 
247
 
244
        UART_DeInit(UART1); // reset uart 1     to default
248
        UART_DeInit(UART1); // reset uart 1     to default
245
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
249
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
246
        // enable uart 1 interrupts selective
250
        // enable uart 1 interrupts selective
247
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
251
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
248
        UART_Cmd(UART1, ENABLE); // enable uart 1
252
        UART_Cmd(UART1, ENABLE); // enable uart 1
249
        // configure the uart 1 interupt line
253
        // configure the uart 1 interupt line
250
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
254
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
251
        // enable the uart 1 IRQ
255
        // enable the uart 1 IRQ
252
        VIC_ITCmd(UART1_ITLine, ENABLE);
256
        VIC_ITCmd(UART1_ITLine, ENABLE);
253
 
257
 
254
        // initialize the debug timer
258
        // initialize the debug timer
255
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
259
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
256
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
260
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
257
 
261
 
258
        // Fill Version Info Structure
262
        // Fill Version Info Structure
259
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
263
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
260
        UART_VersionInfo.SWMinor = VERSION_MINOR;
264
        UART_VersionInfo.SWMinor = VERSION_MINOR;
261
        UART_VersionInfo.SWPatch = VERSION_PATCH;
265
        UART_VersionInfo.SWPatch = VERSION_PATCH;
262
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
266
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
263
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
267
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
264
 
268
 
265
        NaviData.Version = NAVIDATA_VERSION;
269
        NaviData.Version = NAVIDATA_VERSION;
266
 
270
 
267
        UART1_PutString("\r\n UART1 init...ok");
271
        UART1_PutString("\r\n UART1 init...ok");
268
}
272
}
269
 
273
 
270
 
274
 
271
/****************************************************************/
275
/****************************************************************/
272
/*               USART1 receiver ISR                            */
276
/*               USART1 receiver ISR                            */
273
/****************************************************************/
277
/****************************************************************/
274
void UART1_IRQHandler(void)
278
void UART1_IRQHandler(void)
275
{
279
{
276
        static u8 abortState = 0;
280
        static u8 abortState = 0;
277
        u8 c;
281
        u8 c;
278
 
282
 
279
        IENABLE;
283
        IENABLE;
280
 
284
 
281
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
285
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
282
        {
286
        {
283
                // clear the pending bits!
287
                // clear the pending bits!
284
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
288
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
285
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
289
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
286
                // if debug UART is not UART1
290
                // if debug UART is not UART1
287
                if (DebugUART != UART1)
291
                if (DebugUART != UART1)
288
                {       // forward received data to the debug UART tx buffer
292
                {       // forward received data to the debug UART tx buffer
289
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
293
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
290
                        {
294
                        {
291
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
295
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
292
                                c = UART_ReceiveData(UART1);
296
                                c = UART_ReceiveData(UART1);
293
 
297
 
294
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
298
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
295
                                switch (abortState)
299
                                switch (abortState)
296
                                {
300
                                {
297
                                        case 0:
301
                                        case 0:
298
                                                if (c == 27) abortState++;
302
                                                if (c == 27) abortState++;
299
                                                break;
303
                                                break;
300
                                        case 1:
304
                                        case 1:
301
                                                if (c == 27) abortState++;
305
                                                if (c == 27) abortState++;
302
                                                else abortState = 0;
306
                                                else abortState = 0;
303
                                        break;
307
                                        break;
304
                                        case 2:
308
                                        case 2:
305
                                                if (c == 0x55) abortState++;
309
                                                if (c == 0x55) abortState++;
306
                                                else abortState = 0;
310
                                                else abortState = 0;
307
                                                break;
311
                                                break;
308
                                        case 3:
312
                                        case 3:
309
                                                if (c == 0xAA) abortState++;
313
                                                if (c == 0xAA) abortState++;
310
                                                else abortState = 0;
314
                                                else abortState = 0;
311
                                                break;
315
                                                break;
312
                                        case 4:
316
                                        case 4:
313
                                                if (c == 0x00)
317
                                                if (c == 0x00)
314
                                                {
318
                                                {
315
                                                        if(DebugUART == UART0)
319
                                                        if(DebugUART == UART0)
316
                                                        {
320
                                                        {
317
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
321
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
318
                                                                TIMER2_Init(); // enbable servo outputs
322
                                                                TIMER2_Init(); // enbable servo outputs
319
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
323
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
320
                                                        }
324
                                                        }
321
                                                        DebugUART = UART1;
325
                                                        DebugUART = UART1;
322
                                                }
326
                                                }
323
                                                abortState = 0;
327
                                                abortState = 0;
324
                                                break;
328
                                                break;
325
                                } // end switch abort state
329
                                } // end switch abort state
326
                                // if the Debug uart is not UART1, redirect input to the Debug UART
330
                                // if the Debug uart is not UART1, redirect input to the Debug UART
327
                                if (DebugUART != UART1)
331
                                if (DebugUART != UART1)
328
                                {
332
                                {
329
                                        // wait for space in the tx buffer of the DebugUART
333
                                        // wait for space in the tx buffer of the DebugUART
330
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
334
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
331
                                        // move byte to the tx fifo of the debug uart
335
                                        // move byte to the tx fifo of the debug uart
332
                                        UART_SendData(DebugUART, c);
336
                                        UART_SendData(DebugUART, c);
333
                                }
337
                                }
334
                        }
338
                        }
335
                }
339
                }
336
                else  // DebugUART == UART1 (normal operation)
340
                else  // DebugUART == UART1 (normal operation)
337
                {
341
                {
338
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
342
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
339
                        { // some byes in the hardware fifo
343
                        { // some byes in the hardware fifo
340
                            // get byte from hardware fifo
344
                            // get byte from hardware fifo
341
                        c = UART_ReceiveData(UART1);
345
                        c = UART_ReceiveData(UART1);
342
                                // put into the software fifo
346
                                // put into the software fifo
343
                                if(!fifo_put(&UART1_rx_fifo, c))
347
                                if(!fifo_put(&UART1_rx_fifo, c))
344
                                {       // fifo overflow
348
                                {       // fifo overflow
345
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
349
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
346
                                }
350
                                }
347
                        } // EOF while some byes in the hardware fifo
351
                        } // EOF while some byes in the hardware fifo
348
                } // eof DebugUart = UART1
352
                } // eof DebugUart = UART1
349
        }
353
        }
350
 
354
 
351
        IDISABLE;
355
        IDISABLE;
352
}
356
}
353
 
357
 
354
/**************************************************************/
358
/**************************************************************/
355
/* Process incomming data from debug uart                     */
359
/* Process incomming data from debug uart                     */
356
/**************************************************************/
360
/**************************************************************/
357
void UART1_ProcessRxData(void)
361
void UART1_ProcessRxData(void)
358
{
362
{
359
        // return on forwarding uart  or unlocked rx buffer
363
        // return on forwarding uart  or unlocked rx buffer
360
        if(DebugUART != UART1) return;
364
        if(DebugUART != UART1) return;
361
 
365
 
362
        u8 c;
366
        u8 c;
363
        // if rx buffer is not locked
367
        // if rx buffer is not locked
364
        if(UART1_rx_buffer.Locked == FALSE)
368
        if(UART1_rx_buffer.Locked == FALSE)
365
        {
369
        {
366
                //collect data from primary rx fifo
370
                //collect data from primary rx fifo
367
                while(fifo_get(&UART1_rx_fifo, &c))
371
                while(fifo_get(&UART1_rx_fifo, &c))
368
                {
372
                {
369
                        // break if complete frame is collected
373
                        // break if complete frame is collected
370
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
374
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
371
                }
375
                }
372
        }
376
        }
373
        if(UART1_rx_buffer.Locked == FALSE) return;
377
        if(UART1_rx_buffer.Locked == FALSE) return;
374
 
378
 
375
        Point_t * pPoint = NULL;
379
        Point_t * pPoint = NULL;
376
        SerialMsg_t SerialMsg;
380
        SerialMsg_t SerialMsg;
377
 
381
 
378
        // analyze header first
382
        // analyze header first
379
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
383
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
380
        if( SerialMsg.Address == FC_ADDRESS )
384
        if( SerialMsg.Address == FC_ADDRESS )
381
        {
385
        {
382
                switch(SerialMsg.CmdID)
386
                switch(SerialMsg.CmdID)
383
                {
387
                {
384
//                      case 'v': // version
388
//                      case 'v': // version
385
                        case 'y': // serial poti values
389
                        case 'y': // serial poti values
386
                        case 'b': // extern control
390
                        case 'b': // extern control
387
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
391
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
388
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
392
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
389
                                return; //end process rx data
393
                                return; //end process rx data
390
                        break;
394
                        break;
391
                }
395
                }
392
        }
396
        }
393
 
397
 
394
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
398
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
395
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
399
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
396
        switch(SerialMsg.Address) // check for Slave Address
400
        switch(SerialMsg.Address) // check for Slave Address
397
        {
401
        {
398
                case NC_ADDRESS:  // own Slave Address
402
                case NC_ADDRESS:  // own Slave Address
399
                switch(SerialMsg.CmdID)
403
                switch(SerialMsg.CmdID)
400
                {
404
                {
401
                       
405
                       
402
                        case 'f': // ftp command
406
                        case 'f': // ftp command
403
                                UART1_Request_FTP = SerialMsg.pData[0];
407
                                UART1_Request_FTP = SerialMsg.pData[0];
404
 
408
 
405
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) 
409
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) 
406
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
410
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
407
                        break;
411
                        break;
408
 
412
 
409
                        case 'z': // connection checker
413
                        case 'z': // connection checker
410
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
414
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
411
                                UART1_Request_Echo = TRUE;
415
                                UART1_Request_Echo = TRUE;
412
                                break;
416
                                break;
413
 
417
 
414
                        case 'e': // request for the text of the error status
418
                        case 'e': // request for the text of the error status
415
                                UART1_Request_ErrorMessage = TRUE;
419
                                UART1_Request_ErrorMessage = TRUE;
416
                                break;
420
                                break;
417
 
421
 
418
                        case 's'://  new target position
422
                        case 's'://  new target position
419
                                pPoint = (Point_t*)SerialMsg.pData;
423
                                pPoint = (Point_t*)SerialMsg.pData;
420
                                if(pPoint->Position.Status == NEWDATA)
424
                                if(pPoint->Position.Status == NEWDATA)
421
                                {
425
                                {
422
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
426
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
423
                                        //pPoint->Index = 1; // must be one after empty list
427
                                        //pPoint->Index = 1; // must be one after empty list
424
                                        PointList_SetAt(pPoint);
428
                                        PointList_SetAt(pPoint);
425
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
429
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
426
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
430
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
427
                                        if(GPS_pWaypoint != NULL) // if new WP exist
431
                                        if(GPS_pWaypoint != NULL) // if new WP exist
428
                                        {   // update WP hold time stamp immediately!
432
                                        {   // update WP hold time stamp immediately!
429
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
433
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
430
                                                {
434
                                                {
431
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
435
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
432
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
436
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
433
                                                }
437
                                                }
434
*/
438
*/
435
                                        }
439
                                        }
436
                                        BeepTime = 50;
440
                                        BeepTime = 50;
437
                                }
441
                                }
438
                                break;
442
                                break;
439
 
443
 
440
                        case 'u': // redirect debug uart
444
                        case 'u': // redirect debug uart
441
                                switch(SerialMsg.pData[0])
445
                                switch(SerialMsg.pData[0])
442
                                {
446
                                {
443
                                        case UART_FLIGHTCTRL:
447
                                        case UART_FLIGHTCTRL:
444
                                                UART2_Init();                           // initialize UART2 to FC pins
448
                                                UART2_Init();                           // initialize UART2 to FC pins
445
                                                fifo_purge(&UART1_rx_fifo);
449
                                                fifo_purge(&UART1_rx_fifo);
446
                                                TIMER2_Deinit();                        // reduce irq load
450
                                                TIMER2_Deinit();                        // reduce irq load
447
                                                DebugUART = UART2;
451
                                                DebugUART = UART2;
448
                                                break;
452
                                                break;
449
                                        case UART_MK3MAG:
453
                                        case UART_MK3MAG:
450
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
454
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
451
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
455
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
452
                                                GPSData.Status = INVALID;
456
                                                GPSData.Status = INVALID;
453
                                                fifo_purge(&UART1_rx_fifo);
457
                                                fifo_purge(&UART1_rx_fifo);
454
                                                DebugUART = UART0;
458
                                                DebugUART = UART0;
455
                                                break;
459
                                                break;
456
                                        case UART_MKGPS:
460
                                        case UART_MKGPS:
457
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
461
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
458
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
462
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
459
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
463
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
460
                                                GPSData.Status = INVALID;
464
                                                GPSData.Status = INVALID;
461
                                                fifo_purge(&UART1_rx_fifo);
465
                                                fifo_purge(&UART1_rx_fifo);
462
                                                DebugUART = UART0;
466
                                                DebugUART = UART0;
463
                                                break;
467
                                                break;
464
                                        default:
468
                                        default:
465
                                                break;
469
                                                break;
466
                                }
470
                                }
467
                                break;
471
                                break;
468
 
472
 
469
                        case 'w'://  Set point in list at index
473
                        case 'w'://  Set point in list at index
470
                                {
474
                                {
471
                                        pPoint = (Point_t*)SerialMsg.pData;
475
                                        pPoint = (Point_t*)SerialMsg.pData;
472
 
476
 
473
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
477
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
474
                                        {
478
                                        {
475
                                                PointList_Clear();
479
                                                PointList_Clear();
476
                                                GPS_pWaypoint = PointList_WPBegin();
480
                                                GPS_pWaypoint = PointList_WPBegin();
477
                                                UART1_Request_WritePoint = 0; // return new point count
481
                                                UART1_Request_WritePoint = 0; // return new point count
478
                                        }
482
                                        }
479
                                        else
483
                                        else
480
                                        {  // update WP in list at index
484
                                        {  // update WP in list at index
481
                                                if(pPoint->Index > MaxNumberOfWaypoints)
485
                                                if(pPoint->Index > MaxNumberOfWaypoints)
482
                                                 {
486
                                                 {
483
                                                  UART1_Request_WritePoint = 254;
487
                                                  UART1_Request_WritePoint = 254;
484
                                                  pPoint->Index = MaxNumberOfWaypoints;
488
                                                  pPoint->Index = MaxNumberOfWaypoints;
485
                                                 }
489
                                                 }
486
                                                 else
490
                                                 else
487
                                                 UART1_Request_WritePoint = PointList_SetAt(pPoint);
491
                                                 UART1_Request_WritePoint = PointList_SetAt(pPoint);
488
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
492
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
489
                                                if(UART1_Request_WritePoint == pPoint->Index)
493
                                                if(UART1_Request_WritePoint == pPoint->Index)
490
                                                {
494
                                                {
491
                                                        BeepTime = 500;
495
                                                        BeepTime = 500;
492
                                                }
496
                                                }
493
                                        }
497
                                        }
494
                                }
498
                                }
495
                                break;
499
                                break;
496
 
500
 
497
                        case 'x'://  Read Waypoint from List
501
                        case 'x'://  Read Waypoint from List
498
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
502
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
499
                                break;
503
                                break;
500
 
504
 
501
                        case 'j':// Set/Get NC-Parameter
505
                        case 'j':// Set/Get NC-Parameter
502
                                switch(SerialMsg.pData[0])
506
                                switch(SerialMsg.pData[0])
503
                                {
507
                                {
504
                                        case 0: // get
508
                                        case 0: // get
505
                                        break;
509
                                        break;
506
 
510
 
507
                                        case 1: // set
511
                                        case 1: // set
508
                                        {
512
                                        {
509
                                                s16 value;
513
                                                s16 value;
510
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
514
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
511
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
515
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
512
                                        }
516
                                        }
513
                                        break;
517
                                        break;
514
 
518
 
515
                                        default:
519
                                        default:
516
                                        break;
520
                                        break;
517
                                }
521
                                }
518
                                UART1_Request_ParameterId = SerialMsg.pData[1];
522
                                UART1_Request_ParameterId = SerialMsg.pData[1];
519
                                UART1_Request_Parameter = TRUE;
523
                                UART1_Request_Parameter = TRUE;
520
                                break;
524
                                break;
521
                        default:
525
                        default:
522
                                // unsupported command recieved
526
                                // unsupported command recieved
523
                                break;
527
                                break;
524
                } // case NC_ADDRESS
528
                } // case NC_ADDRESS
525
                // "break;" is missing here to fall thru to the common commands
529
                // "break;" is missing here to fall thru to the common commands
526
 
530
 
527
                default:  // and any other Slave Address
531
                default:  // and any other Slave Address
528
 
532
 
529
                switch(SerialMsg.CmdID) // check CmdID
533
                switch(SerialMsg.CmdID) // check CmdID
530
                {
534
                {
531
                        case 'a':// request for the labels of the analog debug outputs
535
                        case 'a':// request for the labels of the analog debug outputs
532
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
536
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
533
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
537
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
534
                                break;
538
                                break;
535
                        /*
539
                        /*
536
                        case 'b': // submit extern control
540
                        case 'b': // submit extern control
537
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
541
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
538
                                UART1_ConfirmFrame = ExternControl.Frame;
542
                                UART1_ConfirmFrame = ExternControl.Frame;
539
                                break;
543
                                break;
540
                        */
544
                        */
541
                        case 'd': // request for debug data;
545
                        case 'd': // request for debug data;
542
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
546
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
543
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
547
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
544
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
548
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
545
                                break;
549
                                break;
546
 
550
 
547
                        case 'c': // request for 3D data;
551
                        case 'c': // request for 3D data;
548
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
552
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
549
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
553
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
550
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
554
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
551
                                break;
555
                                break;
-
 
556
 
-
 
557
                        case 'k': // request for Motor data;
-
 
558
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
-
 
559
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
-
 
560
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
-
 
561
                                break;
552
 
562
 
553
                        case 'h':// reqest for display line
563
                        case 'h':// reqest for display line
554
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
564
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
555
                                {
565
                                {
556
                                        UART1_DisplayLine = 2;
566
                                        UART1_DisplayLine = 2;
557
                                        UART1_Display_Interval = 0;
567
                                        UART1_Display_Interval = 0;
558
                                }
568
                                }
559
                                else
569
                                else
560
                                {
570
                                {
561
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
571
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
562
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
572
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
563
                                        UART1_DisplayLine = 4;
573
                                        UART1_DisplayLine = 4;
564
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
574
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
565
                                }
575
                                }
566
                                UART1_Request_Display = TRUE;
576
                                UART1_Request_Display = TRUE;
567
                                break;
577
                                break;
568
 
578
 
569
                        case 'l':// reqest for display columns
579
                        case 'l':// reqest for display columns
570
                                MenuItem = SerialMsg.pData[0];
580
                                MenuItem = SerialMsg.pData[0];
571
                                UART1_Request_Display1 = TRUE;
581
                                UART1_Request_Display1 = TRUE;
572
                                break;
582
                                break;
573
 
583
 
574
                        case 'o': // request for navigation information
584
                        case 'o': // request for navigation information
575
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
585
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
576
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
586
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
577
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
587
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
578
                                break;
588
                                break;
579
 
589
 
580
                        case 'v': // request for version info
590
                        case 'v': // request for version info
581
                                UART1_Request_VersionInfo = TRUE;
591
                                UART1_Request_VersionInfo = TRUE;
582
                                break;
592
                                break;
583
                        default:
593
                        default:
584
                                // unsupported command recieved
594
                                // unsupported command recieved
585
                                break;
595
                                break;
586
                }
596
                }
587
                break; // default:
597
                break; // default:
588
        }
598
        }
589
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
599
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
590
}
600
}
591
 
601
 
592
 
602
 
593
/*****************************************************/
603
/*****************************************************/
594
/*                   Send a character                */
604
/*                   Send a character                */
595
/*****************************************************/
605
/*****************************************************/
596
s16 UART1_Putchar(char c)
606
s16 UART1_Putchar(char c)
597
{
607
{
598
        if (c == '\n') UART1_Putchar('\r');
608
        if (c == '\n') UART1_Putchar('\r');
599
        // wait until txd fifo is not full
609
        // wait until txd fifo is not full
600
        while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET);
610
        while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET);
601
        // transmit byte
611
        // transmit byte
602
        UART_SendData(UART1, c);
612
        UART_SendData(UART1, c);
603
        #ifdef FOLLOW_ME
613
        #ifdef FOLLOW_ME
604
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
614
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
605
        #endif
615
        #endif
606
        return (0);
616
        return (0);
607
}
617
}
608
 
618
 
609
/*****************************************************/
619
/*****************************************************/
610
/*       Send a string to the debug uart              */
620
/*       Send a string to the debug uart              */
611
/*****************************************************/
621
/*****************************************************/
612
void UART1_PutString(u8 *s)
622
void UART1_PutString(u8 *s)
613
{
623
{
614
        if(s == NULL) return;
624
        if(s == NULL) return;
615
        while (*s != '\0' && DebugUART == UART1)
625
        while (*s != '\0' && DebugUART == UART1)
616
        {
626
        {
617
                UART1_Putchar(*s);
627
                UART1_Putchar(*s);
618
                s ++;
628
                s ++;
619
        }
629
        }
620
}
630
}
621
 
631
 
622
 
632
 
623
/**************************************************************/
633
/**************************************************************/
624
/*         Transmit tx buffer via debug uart                  */
634
/*         Transmit tx buffer via debug uart                  */
625
/**************************************************************/
635
/**************************************************************/
626
void UART1_Transmit(void)
636
void UART1_Transmit(void)
627
{
637
{
628
        u8 tmp_tx;
638
        u8 tmp_tx;
629
        if(DebugUART != UART1) return;
639
        if(DebugUART != UART1) return;
630
        // if something has to be send and the txd fifo is not full
640
        // if something has to be send and the txd fifo is not full
631
        if(UART1_tx_buffer.Locked == TRUE)
641
        if(UART1_tx_buffer.Locked == TRUE)
632
        {
642
        {
633
                // while there is some space in the tx fifo
643
                // while there is some space in the tx fifo
634
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
644
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
635
                {
645
                {
636
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
646
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
637
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
647
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
638
                        #ifdef FOLLOW_ME
648
                        #ifdef FOLLOW_ME
639
                        if(TransmitAlsoToFC)
649
                        if(TransmitAlsoToFC)
640
                        {
650
                        {
641
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
651
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
642
                        }
652
                        }
643
                        #endif
653
                        #endif
644
                        // if terminating character or end of txd buffer reached
654
                        // if terminating character or end of txd buffer reached
645
                        if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
655
                        if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
646
                        {
656
                        {
647
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
657
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
648
                                #ifdef FOLLOW_ME
658
                                #ifdef FOLLOW_ME
649
                                TransmitAlsoToFC = 0;
659
                                TransmitAlsoToFC = 0;
650
                                #endif
660
                                #endif
651
                                break; // end while loop
661
                                break; // end while loop
652
                        }
662
                        }
653
                }
663
                }
654
        }
664
        }
655
}
665
}
656
 
666
 
657
/**************************************************************/
667
/**************************************************************/
658
/* Send the answers to incomming commands at the debug uart   */
668
/* Send the answers to incomming commands at the debug uart   */
659
/**************************************************************/
669
/**************************************************************/
660
void UART1_TransmitTxData(void)
670
void UART1_TransmitTxData(void)
661
{
671
{
-
 
672
static u8 motorindex1 = 255, motorindex2 = 0;
662
        if(DebugUART != UART1) return;
673
        if(DebugUART != UART1) return;
663
 
674
 
664
        if(CheckDelay(UART1_AboTimeOut))
675
        if(CheckDelay(UART1_AboTimeOut))
665
        {
676
        {
666
                UART1_DebugData_Interval = 0;
677
                UART1_DebugData_Interval = 0;
667
                UART1_NaviData_Interval = 0;
678
                UART1_NaviData_Interval = 0;
668
                UART1_Data3D_Interval = 0;
679
                UART1_Data3D_Interval = 0;
669
                UART1_Display_Interval = 0;
680
                UART1_Display_Interval = 0;
670
        }
681
        }
671
 
682
 
672
        UART1_Transmit(); // output pending bytes in tx buffer
683
        UART1_Transmit(); // output pending bytes in tx buffer
673
        if((UART1_tx_buffer.Locked == TRUE)) return;
684
        if((UART1_tx_buffer.Locked == TRUE)) return;
674
 
685
 
675
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
686
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
676
        {
687
        {
677
                s16 ParamValue;
688
                s16 ParamValue;
678
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
689
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
679
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
690
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
680
                UART1_Request_Parameter = FALSE;
691
                UART1_Request_Parameter = FALSE;
681
        }
692
        }
682
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
693
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
683
        {
694
        {
684
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
695
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
685
                Echo = 0; // reset echo value
696
                Echo = 0; // reset echo value
686
                UART1_Request_Echo = FALSE;
697
                UART1_Request_Echo = FALSE;
687
        }
698
        }
688
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
699
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
689
        {
700
        {
690
                CheckFTPCommand(UART1_Request_FTP);
701
                CheckFTPCommand(UART1_Request_FTP);
691
                UART1_Request_FTP = FALSE;
702
                UART1_Request_FTP = FALSE;
692
        }
703
        }
693
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
704
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
694
        {
705
        {
695
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
706
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
696
                UART1_Request_WritePoint = 0xFF;
707
                UART1_Request_WritePoint = 0xFF;
697
        }
708
        }
698
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
709
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
699
        {
710
        {
700
                u8 PointCount = PointList_GetCount();
711
                u8 PointCount = PointList_GetCount();
701
                if (UART1_Request_ReadPoint <= PointCount)
712
                if (UART1_Request_ReadPoint <= PointCount)
702
                {
713
                {
703
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
714
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
704
                }
715
                }
705
                else
716
                else
706
                {
717
                {
707
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
718
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
708
                }
719
                }
709
                UART1_Request_ReadPoint = 0;
720
                UART1_Request_ReadPoint = 0;
710
        }
721
        }
711
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
722
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
712
        {
723
        {
713
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
724
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
714
                UART1_Request_DebugLabel = 0xFF;
725
                UART1_Request_DebugLabel = 0xFF;
715
        }
726
        }
716
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
727
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
717
        {
728
        {
718
                NaviData.Errorcode = ErrorCode;
729
                NaviData.Errorcode = ErrorCode;
719
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
730
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
720
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
731
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
721
                UART1_Request_NaviData = FALSE;
732
                UART1_Request_NaviData = FALSE;
722
        }
733
        }
723
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
734
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
724
        {
735
        {
725
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
736
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
726
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
737
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
727
                UART1_Request_DebugData = FALSE;
738
                UART1_Request_DebugData = FALSE;
728
        }
739
        }
729
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
740
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
730
        {
741
        {
-
 
742
                Data3D.StickNick = FC.StickNick;
-
 
743
                Data3D.StickRoll = FC.StickRoll;
-
 
744
        Data3D.StickYaw = FC.StickYaw;
-
 
745
        Data3D.StickGas = FC.StickGas;
731
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
746
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
732
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
747
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
733
                UART1_Request_Data3D = FALSE;
748
                UART1_Request_Data3D = FALSE;
734
        }
749
        }
-
 
750
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
-
 
751
        {
-
 
752
                do
-
 
753
                {
-
 
754
                 motorindex1++;
-
 
755
                 motorindex1%=12;
-
 
756
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
-
 
757
                 if(motorindex1 == motorindex2) break;
-
 
758
                }
-
 
759
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
-
 
760
 
-
 
761
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
-
 
762
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
-
 
763
                UART1_Request_MotorData = FALSE;
-
 
764
        }
735
        /*
765
        /*
736
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
766
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
737
        {
767
        {
738
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
768
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
739
                UART1_ConfirmFrame = 0;
769
                UART1_ConfirmFrame = 0;
740
        }
770
        }
741
        */
771
        */
742
        /*
772
        /*
743
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
773
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
744
        {
774
        {
745
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
775
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
746
                UART1_Request_ExternalControl = FALSE;
776
                UART1_Request_ExternalControl = FALSE;
747
        }
777
        }
748
        */
778
        */
749
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
779
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
750
        {
780
        {
751
                if(UART1_DisplayLine > 3)
781
                if(UART1_DisplayLine > 3)
752
                {
782
                {
753
                        Menu_Update(UART1_DisplayKeys);
783
                        Menu_Update(UART1_DisplayKeys);
754
                        UART1_DisplayKeys = 0;
784
                        UART1_DisplayKeys = 0;
755
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
785
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
756
                }
786
                }
757
                else
787
                else
758
                {
788
                {
759
                        UART1_DisplayLine = 2;
789
                        UART1_DisplayLine = 2;
760
                        sprintf(text,"!!! incompatible !!!");
790
                        sprintf(text,"!!! incompatible !!!");
761
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
791
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
762
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
792
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
763
                }
793
                }
764
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
794
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
765
                UART1_Request_Display = FALSE;
795
                UART1_Request_Display = FALSE;
766
        }
796
        }
767
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
797
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
768
        {
798
        {
769
                Menu_Update(0);
799
                Menu_Update(0);
770
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
800
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
771
                UART1_Request_Display1 = FALSE;
801
                UART1_Request_Display1 = FALSE;
772
        }
802
        }
773
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
803
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
774
        {
804
        {
775
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
805
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
776
                UART1_Request_VersionInfo = FALSE;
806
                UART1_Request_VersionInfo = FALSE;
777
        }
807
        }
778
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
808
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
779
        {
809
        {
780
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
810
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
781
                UART1_Request_ErrorMessage = FALSE;
811
                UART1_Request_ErrorMessage = FALSE;
782
        }
812
        }
783
#ifdef FOLLOW_ME
813
#ifdef FOLLOW_ME
784
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
814
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
785
        {
815
        {
786
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
816
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
787
                {
817
                {
788
                        TransmitAlsoToFC = 1;
818
                        TransmitAlsoToFC = 1;
789
                        // update FollowMe content
819
                        // update FollowMe content
790
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
820
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
791
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
821
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
792
                        FollowMe.Position.Status = NEWDATA;
822
                        FollowMe.Position.Status = NEWDATA;
793
                        FollowMe.Position.Altitude = 1;
823
                        FollowMe.Position.Altitude = 1;
794
                        // 0  -> no Orientation
824
                        // 0  -> no Orientation
795
                        // 1-360 -> CompassCourse Setpoint
825
                        // 1-360 -> CompassCourse Setpoint
796
                        // -1 -> points to  WP1 -> itself
826
                        // -1 -> points to  WP1 -> itself
797
                FollowMe.Heading = -1;
827
                FollowMe.Heading = -1;
798
                        FollowMe.ToleranceRadius = 1;
828
                        FollowMe.ToleranceRadius = 1;
799
                        FollowMe.HoldTime = 60;
829
                        FollowMe.HoldTime = 60;
800
                        FollowMe.Event_Flag = 1;
830
                        FollowMe.Event_Flag = 1;
801
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
831
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
802
                        FollowMe.Type = POINT_TYPE_WP;
832
                        FollowMe.Type = POINT_TYPE_WP;
803
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
833
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
804
                        FollowMe.AltitudeRate = 0;                        // do not change height
834
                        FollowMe.AltitudeRate = 0;                        // do not change height
805
                        FollowMe.reserve[0] = 0;                // reserve
835
                        FollowMe.reserve[0] = 0;                // reserve
806
                        FollowMe.reserve[1] = 0;                // reserve
836
                        FollowMe.reserve[1] = 0;                // reserve
807
                        FollowMe.reserve[2] = 0;                // reserve
837
                        FollowMe.reserve[2] = 0;                // reserve
808
                        FollowMe.reserve[3] = 0;                // reserve
838
                        FollowMe.reserve[3] = 0;                // reserve
809
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
839
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
810
                }
840
                }
811
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
841
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
812
        }
842
        }
813
#endif
843
#endif
814
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
844
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
815
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
845
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
816
        {
846
        {
817
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
847
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
818
                SendDebugOutput = 0;
848
                SendDebugOutput = 0;
819
        }
849
        }
820
#endif
850
#endif
821
        UART1_Transmit(); // output pending bytes in tx buffer
851
        UART1_Transmit(); // output pending bytes in tx buffer
822
}
852
}
823
 
853
 
824
 
854