Subversion Repositories NaviCtrl

Rev

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

Rev 349 Rev 351
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 "ftphelper.h"
79
#include "ftphelper.h"
80
 
80
 
81
#define FALSE   0
81
#define FALSE   0
82
#define TRUE    1
82
#define TRUE    1
83
 
83
 
84
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
84
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
85
u32 UART1_AboTimeOut = 0;
85
u32 UART1_AboTimeOut = 0;
86
 
86
 
87
u8 UART1_Request_VersionInfo    = FALSE;
87
u8 UART1_Request_VersionInfo    = FALSE;
88
u8 UART1_Request_ExternalControl= FALSE;
88
u8 UART1_Request_ExternalControl= FALSE;
89
u8 UART1_Request_Display                = FALSE;
89
u8 UART1_Request_Display                = FALSE;
90
u8 UART1_Request_Display1               = FALSE;
90
u8 UART1_Request_Display1               = FALSE;
91
u8 UART1_Request_DebugData              = FALSE;
91
u8 UART1_Request_DebugData              = FALSE;
92
u8 UART1_Request_DebugLabel             = 255;
92
u8 UART1_Request_DebugLabel             = 255;
93
u8 UART1_Request_NaviData               = FALSE;
93
u8 UART1_Request_NaviData               = FALSE;
94
u8 UART1_Request_ErrorMessage   = FALSE;
94
u8 UART1_Request_ErrorMessage   = FALSE;
95
u8 UART1_Request_WritePoint             = 0xFF;
95
u8 UART1_Request_WritePoint             = 0xFF;
96
u8 UART1_Request_ReadPoint              = 0;
96
u8 UART1_Request_ReadPoint              = 0;
97
u8 UART1_Request_Data3D             = FALSE;
97
u8 UART1_Request_Data3D             = FALSE;
98
u8 UART1_Request_Echo               = FALSE;
98
u8 UART1_Request_Echo               = FALSE;
99
u8 UART1_Request_ParameterId    = 0;
99
u8 UART1_Request_ParameterId    = 0;
100
u8 UART1_Request_Parameter              = FALSE;
100
u8 UART1_Request_Parameter              = FALSE;
101
u8 UART1_DisplayKeys                    = 0;
101
u8 UART1_DisplayKeys                    = 0;
102
u8 UART1_DisplayLine                    = 0;
102
u8 UART1_DisplayLine                    = 0;
103
u8 UART1_ConfirmFrame                   = 0;
103
u8 UART1_ConfirmFrame                   = 0;
104
u8 UART1_Request_FTP                    = FALSE;
104
u8 UART1_Request_FTP                    = FALSE;
105
 
105
 
106
 
106
 
107
UART_TypeDef *DebugUART = UART1;
107
UART_TypeDef *DebugUART = UART1;
108
 
108
 
109
#ifdef FOLLOW_ME
109
#ifdef FOLLOW_ME
110
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
110
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
111
u32 UART1_FollowMe_Timer        = 0;
111
u32 UART1_FollowMe_Timer        = 0;
112
Point_t FollowMe;
112
Point_t FollowMe;
113
#endif
113
#endif
114
 
114
 
115
// the primary rx fifo
115
// the primary rx fifo
116
#define UART1_RX_FIFO_LEN 512
116
#define UART1_RX_FIFO_LEN 512
117
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
117
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
118
fifo_t UART1_rx_fifo;
118
fifo_t UART1_rx_fifo;
119
 
119
 
120
// the rx buffer
120
// the rx buffer
121
#define UART1_RX_BUFFER_LEN  150
121
#define UART1_RX_BUFFER_LEN  150
122
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
122
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
123
Buffer_t UART1_rx_buffer;
123
Buffer_t UART1_rx_buffer;
124
 
124
 
125
// the tx buffer
125
// the tx buffer
126
#define UART1_TX_BUFFER_LEN  1024
126
#define UART1_TX_BUFFER_LEN  1024
127
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
127
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
128
Buffer_t UART1_tx_buffer;
128
Buffer_t UART1_tx_buffer;
129
 
129
 
130
volatile u8 SerialLinkOkay = 0;
130
volatile u8 SerialLinkOkay = 0;
131
 
131
 
132
u8 text[200];
132
u8 text[200];
133
 
133
 
134
const u8 ANALOG_LABEL[32][16] =
134
const u8 ANALOG_LABEL[32][16] =
135
{
135
{
136
   //1234567890123456
136
   //1234567890123456
137
        "AngleNick       ", //0
137
        "AngleNick       ", //0
138
        "AngleRoll       ",
138
        "AngleRoll       ",
139
        "AccNick         ",
139
        "AccNick         ",
140
        "AccRoll         ",
140
        "AccRoll         ",
141
        "OperatingRadius ",
141
        "OperatingRadius ",
142
        "FC-Flags        ", //5
142
        "FC-Flags        ", //5
143
        "NC-Flags        ",
143
        "NC-Flags        ",
144
        "NickServo       ",
144
        "NickServo       ",
145
        "RollServo       ",
145
        "RollServo       ",
146
        "GPS Data        ",
146
        "GPS Data        ",
147
        "CompassHeading  ", //10
147
        "CompassHeading  ", //10
148
        "GyroHeading     ",
148
        "GyroHeading     ",
149
        "SPI Error       ",
149
        "SPI Error       ",
150
        "SPI Okay        ",
150
        "SPI Okay        ",
151
        "I2C Error       ",
151
        "I2C Error       ",
152
        "I2C Okay        ", //15
152
        "I2C Okay        ", //15
153
        "16              ",
153
        "16              ",
154
        "17              ",
154
        "17              ",
155
        "18              ",
155
        "18              ",
156
        "19 SD-Card-time ",
156
        "19 SD-Card-time ",
157
        "EarthMagnet [%] ", //20
157
        "EarthMagnet [%] ", //20
158
        "Z_Speed         ",
158
        "Z_Speed         ",
159
        "N_Speed         ",
159
        "N_Speed         ",
160
        "E_Speed         ",
160
        "E_Speed         ",
161
        "Magnet X        ",
161
        "Magnet X        ",
162
        "Magnet Y        ", //25
162
        "Magnet Y        ", //25
163
        "Magnet Z        ",
163
        "Magnet Z        ",
164
        "Distance N      ",
164
        "Distance N      ",
165
        "Distance E      ",
165
        "Distance E      ",
166
        "GPS_Nick        ",
166
        "GPS_Nick        ",
167
        "GPS_Roll        ", //30
167
        "GPS_Roll        ", //30
168
        "Used_Sats       "
168
        "Used_Sats       "
169
};
169
};
170
 
170
 
171
DebugOut_t DebugOut;
171
DebugOut_t DebugOut;
172
ExternControl_t ExternControl;
172
ExternControl_t ExternControl;
173
UART_VersionInfo_t UART_VersionInfo;
173
UART_VersionInfo_t UART_VersionInfo;
174
NaviData_t NaviData;
174
NaviData_t NaviData;
175
Data3D_t Data3D;
175
Data3D_t Data3D;
176
u16 Echo; // 2 bytes recieved will be sent back as echo
176
u16 Echo; // 2 bytes recieved will be sent back as echo
177
 
177
 
178
u32 UART1_DebugData_Timer = 0;
178
u32 UART1_DebugData_Timer = 0;
179
u32 UART1_DebugData_Interval = 0;       // in ms
179
u32 UART1_DebugData_Interval = 0;       // in ms
180
u32 UART1_NaviData_Timer = 0;
180
u32 UART1_NaviData_Timer = 0;
181
u32 UART1_NaviData_Interval = 0;        // in ms
181
u32 UART1_NaviData_Interval = 0;        // in ms
182
u32 UART1_Data3D_Timer = 0;
182
u32 UART1_Data3D_Timer = 0;
183
u32 UART1_Data3D_Interval = 0;          // in ms
183
u32 UART1_Data3D_Interval = 0;          // in ms
184
u32 UART1_Display_Timer = 0;
184
u32 UART1_Display_Timer = 0;
185
u32 UART1_Display_Interval = 0;         // in ms
185
u32 UART1_Display_Interval = 0;         // in ms
186
 
186
 
187
/********************************************************/
187
/********************************************************/
188
/*            Initialization the UART1                  */
188
/*            Initialization the UART1                  */
189
/********************************************************/
189
/********************************************************/
190
void UART1_Init (void)
190
void UART1_Init (void)
191
{
191
{
192
        GPIO_InitTypeDef GPIO_InitStructure;
192
        GPIO_InitTypeDef GPIO_InitStructure;
193
        UART_InitTypeDef UART_InitStructure;
193
        UART_InitTypeDef UART_InitStructure;
194
 
194
 
195
        // initialize txd buffer
195
        // initialize txd buffer
196
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
196
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
197
 
197
 
198
        // initialize rxd buffer
198
        // initialize rxd buffer
199
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
199
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
200
 
200
 
201
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
201
        // 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);
202
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
203
 
203
 
204
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
204
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
205
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
205
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
206
 
206
 
207
        /*Configure UART1_Rx pin GPIO3.2*/
207
        /*Configure UART1_Rx pin GPIO3.2*/
208
        GPIO_StructInit(&GPIO_InitStructure);
208
        GPIO_StructInit(&GPIO_InitStructure);
209
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
209
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
210
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
210
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
211
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
211
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
212
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
212
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
213
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
213
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
214
        GPIO_Init(GPIO3, &GPIO_InitStructure);
214
        GPIO_Init(GPIO3, &GPIO_InitStructure);
215
 
215
 
216
        /*Configure UART1_Tx pin GPIO3.3*/
216
        /*Configure UART1_Tx pin GPIO3.3*/
217
        GPIO_StructInit(&GPIO_InitStructure);
217
        GPIO_StructInit(&GPIO_InitStructure);
218
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
218
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
219
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
219
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
220
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
220
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
221
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
221
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
222
        GPIO_Init(GPIO3, &GPIO_InitStructure);
222
        GPIO_Init(GPIO3, &GPIO_InitStructure);
223
 
223
 
224
        /* UART1 configured as follow:
224
        /* UART1 configured as follow:
225
        - Word Length = 8 Bits
225
        - Word Length = 8 Bits
226
        - One Stop Bit
226
        - One Stop Bit
227
        - No parity
227
        - No parity
228
        - BaudRate = 57600 baud
228
        - BaudRate = 57600 baud
229
        - Hardware flow control Disabled
229
        - Hardware flow control Disabled
230
        - Receive and transmit enabled
230
        - Receive and transmit enabled
231
        - Receive and transmit FIFOs are Disabled
231
        - Receive and transmit FIFOs are Disabled
232
        */
232
        */
233
        UART_StructInit(&UART_InitStructure);
233
        UART_StructInit(&UART_InitStructure);
234
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
234
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
235
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
235
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
236
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
236
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
237
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
237
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
238
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
238
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
239
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
239
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
240
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
240
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
241
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
241
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
242
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;
242
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;
243
 
243
 
244
        UART_DeInit(UART1); // reset uart 1     to default
244
        UART_DeInit(UART1); // reset uart 1     to default
245
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
245
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
246
        // enable uart 1 interrupts selective
246
        // enable uart 1 interrupts selective
247
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
247
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
248
        UART_Cmd(UART1, ENABLE); // enable uart 1
248
        UART_Cmd(UART1, ENABLE); // enable uart 1
249
        // configure the uart 1 interupt line
249
        // configure the uart 1 interupt line
250
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
250
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
251
        // enable the uart 1 IRQ
251
        // enable the uart 1 IRQ
252
        VIC_ITCmd(UART1_ITLine, ENABLE);
252
        VIC_ITCmd(UART1_ITLine, ENABLE);
253
 
253
 
254
        // initialize the debug timer
254
        // initialize the debug timer
255
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
255
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
256
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
256
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
257
 
257
 
258
        // Fill Version Info Structure
258
        // Fill Version Info Structure
259
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
259
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
260
        UART_VersionInfo.SWMinor = VERSION_MINOR;
260
        UART_VersionInfo.SWMinor = VERSION_MINOR;
261
        UART_VersionInfo.SWPatch = VERSION_PATCH;
261
        UART_VersionInfo.SWPatch = VERSION_PATCH;
262
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
262
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
263
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
263
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
264
 
264
 
265
        NaviData.Version = NAVIDATA_VERSION;
265
        NaviData.Version = NAVIDATA_VERSION;
266
 
266
 
267
        UART1_PutString("\r\n UART1 init...ok");
267
        UART1_PutString("\r\n UART1 init...ok");
268
}
268
}
269
 
269
 
270
 
270
 
271
/****************************************************************/
271
/****************************************************************/
272
/*               USART1 receiver ISR                            */
272
/*               USART1 receiver ISR                            */
273
/****************************************************************/
273
/****************************************************************/
274
void UART1_IRQHandler(void)
274
void UART1_IRQHandler(void)
275
{
275
{
276
        static u8 abortState = 0;
276
        static u8 abortState = 0;
277
        u8 c;
277
        u8 c;
278
 
278
 
279
        IENABLE;
279
        IENABLE;
280
 
280
 
281
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
281
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
282
        {
282
        {
283
                // clear the pending bits!
283
                // clear the pending bits!
284
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
284
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
285
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
285
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
286
                // if debug UART is not UART1
286
                // if debug UART is not UART1
287
                if (DebugUART != UART1)
287
                if (DebugUART != UART1)
288
                {       // forward received data to the debug UART tx buffer
288
                {       // forward received data to the debug UART tx buffer
289
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
289
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
290
                        {
290
                        {
291
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
291
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
292
                                c = UART_ReceiveData(UART1);
292
                                c = UART_ReceiveData(UART1);
293
 
293
 
294
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
294
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
295
                                switch (abortState)
295
                                switch (abortState)
296
                                {
296
                                {
297
                                        case 0:
297
                                        case 0:
298
                                                if (c == 27) abortState++;
298
                                                if (c == 27) abortState++;
299
                                                break;
299
                                                break;
300
                                        case 1:
300
                                        case 1:
301
                                                if (c == 27) abortState++;
301
                                                if (c == 27) abortState++;
302
                                                else abortState = 0;
302
                                                else abortState = 0;
303
                                        break;
303
                                        break;
304
                                        case 2:
304
                                        case 2:
305
                                                if (c == 0x55) abortState++;
305
                                                if (c == 0x55) abortState++;
306
                                                else abortState = 0;
306
                                                else abortState = 0;
307
                                                break;
307
                                                break;
308
                                        case 3:
308
                                        case 3:
309
                                                if (c == 0xAA) abortState++;
309
                                                if (c == 0xAA) abortState++;
310
                                                else abortState = 0;
310
                                                else abortState = 0;
311
                                                break;
311
                                                break;
312
                                        case 4:
312
                                        case 4:
313
                                                if (c == 0x00)
313
                                                if (c == 0x00)
314
                                                {
314
                                                {
315
                                                        if(DebugUART == UART0)
315
                                                        if(DebugUART == UART0)
316
                                                        {
316
                                                        {
317
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
317
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
318
                                                                TIMER2_Init(); // enbable servo outputs
318
                                                                TIMER2_Init(); // enbable servo outputs
319
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
319
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
320
                                                        }
320
                                                        }
321
                                                        DebugUART = UART1;
321
                                                        DebugUART = UART1;
322
                                                }
322
                                                }
323
                                                abortState = 0;
323
                                                abortState = 0;
324
                                                break;
324
                                                break;
325
                                } // end switch abort state
325
                                } // end switch abort state
326
                                // if the Debug uart is not UART1, redirect input to the Debug UART
326
                                // if the Debug uart is not UART1, redirect input to the Debug UART
327
                                if (DebugUART != UART1)
327
                                if (DebugUART != UART1)
328
                                {
328
                                {
329
                                        // wait for space in the tx buffer of the DebugUART
329
                                        // wait for space in the tx buffer of the DebugUART
330
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
330
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
331
                                        // move byte to the tx fifo of the debug uart
331
                                        // move byte to the tx fifo of the debug uart
332
                                        UART_SendData(DebugUART, c);
332
                                        UART_SendData(DebugUART, c);
333
                                }
333
                                }
334
                        }
334
                        }
335
                }
335
                }
336
                else  // DebugUART == UART1 (normal operation)
336
                else  // DebugUART == UART1 (normal operation)
337
                {
337
                {
338
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
338
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
339
                        { // some byes in the hardware fifo
339
                        { // some byes in the hardware fifo
340
                            // get byte from hardware fifo
340
                            // get byte from hardware fifo
341
                        c = UART_ReceiveData(UART1);
341
                        c = UART_ReceiveData(UART1);
342
                                // put into the software fifo
342
                                // put into the software fifo
343
                                if(!fifo_put(&UART1_rx_fifo, c))
343
                                if(!fifo_put(&UART1_rx_fifo, c))
344
                                {       // fifo overflow
344
                                {       // fifo overflow
345
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
345
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
346
                                }
346
                                }
347
                        } // EOF while some byes in the hardware fifo
347
                        } // EOF while some byes in the hardware fifo
348
                } // eof DebugUart = UART1
348
                } // eof DebugUart = UART1
349
        }
349
        }
350
 
350
 
351
        IDISABLE;
351
        IDISABLE;
352
}
352
}
353
 
353
 
354
/**************************************************************/
354
/**************************************************************/
355
/* Process incomming data from debug uart                     */
355
/* Process incomming data from debug uart                     */
356
/**************************************************************/
356
/**************************************************************/
357
void UART1_ProcessRxData(void)
357
void UART1_ProcessRxData(void)
358
{
358
{
359
        // return on forwarding uart  or unlocked rx buffer
359
        // return on forwarding uart  or unlocked rx buffer
360
        if(DebugUART != UART1) return;
360
        if(DebugUART != UART1) return;
361
 
361
 
362
        u8 c;
362
        u8 c;
363
        // if rx buffer is not locked
363
        // if rx buffer is not locked
364
        if(UART1_rx_buffer.Locked == FALSE)
364
        if(UART1_rx_buffer.Locked == FALSE)
365
        {
365
        {
366
                //collect data from primary rx fifo
366
                //collect data from primary rx fifo
367
                while(fifo_get(&UART1_rx_fifo, &c))
367
                while(fifo_get(&UART1_rx_fifo, &c))
368
                {
368
                {
369
                        // break if complete frame is collected
369
                        // break if complete frame is collected
370
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
370
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
371
                }
371
                }
372
        }
372
        }
373
        if(UART1_rx_buffer.Locked == FALSE) return;
373
        if(UART1_rx_buffer.Locked == FALSE) return;
374
 
374
 
375
        Point_t * pPoint = NULL;
375
        Point_t * pPoint = NULL;
376
        SerialMsg_t SerialMsg;
376
        SerialMsg_t SerialMsg;
377
 
377
 
378
        // analyze header first
378
        // analyze header first
379
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
379
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
380
        if( SerialMsg.Address == FC_ADDRESS )
380
        if( SerialMsg.Address == FC_ADDRESS )
381
        {
381
        {
382
                switch(SerialMsg.CmdID)
382
                switch(SerialMsg.CmdID)
383
                {
383
                {
384
//                      case 'v': // version
384
//                      case 'v': // version
385
                        case 'y': // serial poti values
385
                        case 'y': // serial poti values
386
                        case 'b': // extern control
386
                        case 'b': // extern control
387
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
387
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
388
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
388
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
389
                                return; //end process rx data
389
                                return; //end process rx data
390
                        break;
390
                        break;
391
                }
391
                }
392
        }
392
        }
393
 
393
 
394
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
394
        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"
395
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
396
        switch(SerialMsg.Address) // check for Slave Address
396
        switch(SerialMsg.Address) // check for Slave Address
397
        {
397
        {
398
                case NC_ADDRESS:  // own Slave Address
398
                case NC_ADDRESS:  // own Slave Address
399
                switch(SerialMsg.CmdID)
399
                switch(SerialMsg.CmdID)
400
                {
400
                {
401
                       
401
                       
402
                        case 'f': // ftp command
402
                        case 'f': // ftp command
403
                                UART1_Request_FTP = SerialMsg.pData[0];
403
                                UART1_Request_FTP = SerialMsg.pData[0];
404
 
404
 
405
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE) 
405
                                //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
406
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
407
                        break;
407
                        break;
408
 
408
 
409
                        case 'z': // connection checker
409
                        case 'z': // connection checker
410
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
410
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
411
                                UART1_Request_Echo = TRUE;
411
                                UART1_Request_Echo = TRUE;
412
                                break;
412
                                break;
413
 
413
 
414
                        case 'e': // request for the text of the error status
414
                        case 'e': // request for the text of the error status
415
                                UART1_Request_ErrorMessage = TRUE;
415
                                UART1_Request_ErrorMessage = TRUE;
416
                                break;
416
                                break;
417
 
417
 
418
                        case 's'://  new target position
418
                        case 's'://  new target position
419
                                pPoint = (Point_t*)SerialMsg.pData;
419
                                pPoint = (Point_t*)SerialMsg.pData;
420
                                if(pPoint->Position.Status == NEWDATA)
420
                                if(pPoint->Position.Status == NEWDATA)
421
                                {
421
                                {
422
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
422
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
423
                                        //pPoint->Index = 1; // must be one after empty list
423
                                        //pPoint->Index = 1; // must be one after empty list
424
                                        PointList_SetAt(pPoint);
424
                                        PointList_SetAt(pPoint);
425
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
425
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
426
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
426
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
427
                                        if(GPS_pWaypoint != NULL) // if new WP exist
427
                                        if(GPS_pWaypoint != NULL) // if new WP exist
428
                                        {   // update WP hold time stamp immediately!
428
                                        {   // update WP hold time stamp immediately!
429
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
429
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
430
                                                {
430
                                                {
431
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
431
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
432
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
432
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
433
                                                }
433
                                                }
434
*/
434
*/
435
                                        }
435
                                        }
436
                                        BeepTime = 50;
436
                                        BeepTime = 50;
437
                                }
437
                                }
438
                                break;
438
                                break;
439
 
439
 
440
                        case 'u': // redirect debug uart
440
                        case 'u': // redirect debug uart
441
                                switch(SerialMsg.pData[0])
441
                                switch(SerialMsg.pData[0])
442
                                {
442
                                {
443
                                        case UART_FLIGHTCTRL:
443
                                        case UART_FLIGHTCTRL:
444
                                                UART2_Init();                           // initialize UART2 to FC pins
444
                                                UART2_Init();                           // initialize UART2 to FC pins
445
                                                fifo_purge(&UART1_rx_fifo);
445
                                                fifo_purge(&UART1_rx_fifo);
446
                                                TIMER2_Deinit();                        // reduce irq load
446
                                                TIMER2_Deinit();                        // reduce irq load
447
                                                DebugUART = UART2;
447
                                                DebugUART = UART2;
448
                                                break;
448
                                                break;
449
                                        case UART_MK3MAG:
449
                                        case UART_MK3MAG:
450
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
450
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
451
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
451
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
452
                                                GPSData.Status = INVALID;
452
                                                GPSData.Status = INVALID;
453
                                                fifo_purge(&UART1_rx_fifo);
453
                                                fifo_purge(&UART1_rx_fifo);
454
                                                DebugUART = UART0;
454
                                                DebugUART = UART0;
455
                                                break;
455
                                                break;
456
                                        case UART_MKGPS:
456
                                        case UART_MKGPS:
457
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
457
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
458
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
458
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
459
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
459
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
460
                                                GPSData.Status = INVALID;
460
                                                GPSData.Status = INVALID;
461
                                                fifo_purge(&UART1_rx_fifo);
461
                                                fifo_purge(&UART1_rx_fifo);
462
                                                DebugUART = UART0;
462
                                                DebugUART = UART0;
463
                                                break;
463
                                                break;
464
                                        default:
464
                                        default:
465
                                                break;
465
                                                break;
466
                                }
466
                                }
467
                                break;
467
                                break;
468
 
468
 
469
                        case 'w'://  Set point in list at index
469
                        case 'w'://  Set point in list at index
470
                                {
470
                                {
471
                                        pPoint = (Point_t*)SerialMsg.pData;
471
                                        pPoint = (Point_t*)SerialMsg.pData;
472
 
472
 
473
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
473
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
474
                                        {
474
                                        {
475
                                                PointList_Clear();
475
                                                PointList_Clear();
476
                                                GPS_pWaypoint = PointList_WPBegin();
476
                                                GPS_pWaypoint = PointList_WPBegin();
477
                                                UART1_Request_WritePoint = 0; // return new point count
477
                                                UART1_Request_WritePoint = 0; // return new point count
478
                                        }
478
                                        }
479
                                        else
479
                                        else
480
                                        {  // update WP in list at index
480
                                        {  // update WP in list at index
-
 
481
                                                if(pPoint->Index > MaxNumberOfWaypoints)
-
 
482
                                                 {
-
 
483
                                                  UART1_Request_WritePoint = 254;
-
 
484
                                                  pPoint->Index = MaxNumberOfWaypoints;
-
 
485
                                                 }
-
 
486
                                                 else
481
                                                UART1_Request_WritePoint = PointList_SetAt(pPoint);
487
                                                 UART1_Request_WritePoint = PointList_SetAt(pPoint);
482
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
488
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
483
                                                if(UART1_Request_WritePoint == pPoint->Index)
489
                                                if(UART1_Request_WritePoint == pPoint->Index)
484
                                                {
490
                                                {
485
                                                        BeepTime = 500;
491
                                                        BeepTime = 500;
486
                                                }
492
                                                }
487
                                        }
493
                                        }
488
                                }
494
                                }
489
                                break;
495
                                break;
490
 
496
 
491
                        case 'x'://  Read Waypoint from List
497
                        case 'x'://  Read Waypoint from List
492
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
498
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
493
                                break;
499
                                break;
494
 
500
 
495
                        case 'j':// Set/Get NC-Parameter
501
                        case 'j':// Set/Get NC-Parameter
496
                                switch(SerialMsg.pData[0])
502
                                switch(SerialMsg.pData[0])
497
                                {
503
                                {
498
                                        case 0: // get
504
                                        case 0: // get
499
                                        break;
505
                                        break;
500
 
506
 
501
                                        case 1: // set
507
                                        case 1: // set
502
                                        {
508
                                        {
503
                                                s16 value;
509
                                                s16 value;
504
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
510
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
505
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
511
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
506
                                        }
512
                                        }
507
                                        break;
513
                                        break;
508
 
514
 
509
                                        default:
515
                                        default:
510
                                        break;
516
                                        break;
511
                                }
517
                                }
512
                                UART1_Request_ParameterId = SerialMsg.pData[1];
518
                                UART1_Request_ParameterId = SerialMsg.pData[1];
513
                                UART1_Request_Parameter = TRUE;
519
                                UART1_Request_Parameter = TRUE;
514
                                break;
520
                                break;
515
                        default:
521
                        default:
516
                                // unsupported command recieved
522
                                // unsupported command recieved
517
                                break;
523
                                break;
518
                } // case NC_ADDRESS
524
                } // case NC_ADDRESS
519
                // "break;" is missing here to fall thru to the common commands
525
                // "break;" is missing here to fall thru to the common commands
520
 
526
 
521
                default:  // and any other Slave Address
527
                default:  // and any other Slave Address
522
 
528
 
523
                switch(SerialMsg.CmdID) // check CmdID
529
                switch(SerialMsg.CmdID) // check CmdID
524
                {
530
                {
525
                        case 'a':// request for the labels of the analog debug outputs
531
                        case 'a':// request for the labels of the analog debug outputs
526
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
532
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
527
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
533
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
528
                                break;
534
                                break;
529
                        /*
535
                        /*
530
                        case 'b': // submit extern control
536
                        case 'b': // submit extern control
531
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
537
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
532
                                UART1_ConfirmFrame = ExternControl.Frame;
538
                                UART1_ConfirmFrame = ExternControl.Frame;
533
                                break;
539
                                break;
534
                        */
540
                        */
535
                        case 'd': // request for debug data;
541
                        case 'd': // request for debug data;
536
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
542
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
537
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
543
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
538
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
544
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
539
                                break;
545
                                break;
540
 
546
 
541
                        case 'c': // request for 3D data;
547
                        case 'c': // request for 3D data;
542
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
548
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
543
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
549
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
544
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
550
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
545
                                break;
551
                                break;
546
 
552
 
547
                        case 'h':// reqest for display line
553
                        case 'h':// reqest for display line
548
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
554
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
549
                                {
555
                                {
550
                                        UART1_DisplayLine = 2;
556
                                        UART1_DisplayLine = 2;
551
                                        UART1_Display_Interval = 0;
557
                                        UART1_Display_Interval = 0;
552
                                }
558
                                }
553
                                else
559
                                else
554
                                {
560
                                {
555
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
561
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
556
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
562
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
557
                                        UART1_DisplayLine = 4;
563
                                        UART1_DisplayLine = 4;
558
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
564
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
559
                                }
565
                                }
560
                                UART1_Request_Display = TRUE;
566
                                UART1_Request_Display = TRUE;
561
                                break;
567
                                break;
562
 
568
 
563
                        case 'l':// reqest for display columns
569
                        case 'l':// reqest for display columns
564
                                MenuItem = SerialMsg.pData[0];
570
                                MenuItem = SerialMsg.pData[0];
565
                                UART1_Request_Display1 = TRUE;
571
                                UART1_Request_Display1 = TRUE;
566
                                break;
572
                                break;
567
 
573
 
568
                        case 'o': // request for navigation information
574
                        case 'o': // request for navigation information
569
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
575
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
570
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
576
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
571
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
577
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
572
                                break;
578
                                break;
573
 
579
 
574
                        case 'v': // request for version info
580
                        case 'v': // request for version info
575
                                UART1_Request_VersionInfo = TRUE;
581
                                UART1_Request_VersionInfo = TRUE;
576
                                break;
582
                                break;
577
                        default:
583
                        default:
578
                                // unsupported command recieved
584
                                // unsupported command recieved
579
                                break;
585
                                break;
580
                }
586
                }
581
                break; // default:
587
                break; // default:
582
        }
588
        }
583
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
589
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
584
}
590
}
585
 
591
 
586
 
592
 
587
/*****************************************************/
593
/*****************************************************/
588
/*                   Send a character                */
594
/*                   Send a character                */
589
/*****************************************************/
595
/*****************************************************/
590
s16 UART1_Putchar(char c)
596
s16 UART1_Putchar(char c)
591
{
597
{
592
        if (c == '\n') UART1_Putchar('\r');
598
        if (c == '\n') UART1_Putchar('\r');
593
        // wait until txd fifo is not full
599
        // wait until txd fifo is not full
594
        while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET);
600
        while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET);
595
        // transmit byte
601
        // transmit byte
596
        UART_SendData(UART1, c);
602
        UART_SendData(UART1, c);
597
        #ifdef FOLLOW_ME
603
        #ifdef FOLLOW_ME
598
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
604
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
599
        #endif
605
        #endif
600
        return (0);
606
        return (0);
601
}
607
}
602
 
608
 
603
/*****************************************************/
609
/*****************************************************/
604
/*       Send a string to the debug uart              */
610
/*       Send a string to the debug uart              */
605
/*****************************************************/
611
/*****************************************************/
606
void UART1_PutString(u8 *s)
612
void UART1_PutString(u8 *s)
607
{
613
{
608
        if(s == NULL) return;
614
        if(s == NULL) return;
609
        while (*s != '\0' && DebugUART == UART1)
615
        while (*s != '\0' && DebugUART == UART1)
610
        {
616
        {
611
                UART1_Putchar(*s);
617
                UART1_Putchar(*s);
612
                s ++;
618
                s ++;
613
        }
619
        }
614
}
620
}
615
 
621
 
616
 
622
 
617
/**************************************************************/
623
/**************************************************************/
618
/*         Transmit tx buffer via debug uart                  */
624
/*         Transmit tx buffer via debug uart                  */
619
/**************************************************************/
625
/**************************************************************/
620
void UART1_Transmit(void)
626
void UART1_Transmit(void)
621
{
627
{
622
        u8 tmp_tx;
628
        u8 tmp_tx;
623
        if(DebugUART != UART1) return;
629
        if(DebugUART != UART1) return;
624
        // if something has to be send and the txd fifo is not full
630
        // if something has to be send and the txd fifo is not full
625
        if(UART1_tx_buffer.Locked == TRUE)
631
        if(UART1_tx_buffer.Locked == TRUE)
626
        {
632
        {
627
                // while there is some space in the tx fifo
633
                // while there is some space in the tx fifo
628
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
634
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
629
                {
635
                {
630
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
636
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
631
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
637
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
632
                        #ifdef FOLLOW_ME
638
                        #ifdef FOLLOW_ME
633
                        if(TransmitAlsoToFC)
639
                        if(TransmitAlsoToFC)
634
                        {
640
                        {
635
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
641
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
636
                        }
642
                        }
637
                        #endif
643
                        #endif
638
                        // if terminating character or end of txd buffer reached
644
                        // if terminating character or end of txd buffer reached
639
                        if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
645
                        if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
640
                        {
646
                        {
641
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
647
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
642
                                #ifdef FOLLOW_ME
648
                                #ifdef FOLLOW_ME
643
                                TransmitAlsoToFC = 0;
649
                                TransmitAlsoToFC = 0;
644
                                #endif
650
                                #endif
645
                                break; // end while loop
651
                                break; // end while loop
646
                        }
652
                        }
647
                }
653
                }
648
        }
654
        }
649
}
655
}
650
 
656
 
651
/**************************************************************/
657
/**************************************************************/
652
/* Send the answers to incomming commands at the debug uart   */
658
/* Send the answers to incomming commands at the debug uart   */
653
/**************************************************************/
659
/**************************************************************/
654
void UART1_TransmitTxData(void)
660
void UART1_TransmitTxData(void)
655
{
661
{
656
        if(DebugUART != UART1) return;
662
        if(DebugUART != UART1) return;
657
 
663
 
658
        if(CheckDelay(UART1_AboTimeOut))
664
        if(CheckDelay(UART1_AboTimeOut))
659
        {
665
        {
660
                UART1_DebugData_Interval = 0;
666
                UART1_DebugData_Interval = 0;
661
                UART1_NaviData_Interval = 0;
667
                UART1_NaviData_Interval = 0;
662
                UART1_Data3D_Interval = 0;
668
                UART1_Data3D_Interval = 0;
663
                UART1_Display_Interval = 0;
669
                UART1_Display_Interval = 0;
664
        }
670
        }
665
 
671
 
666
        UART1_Transmit(); // output pending bytes in tx buffer
672
        UART1_Transmit(); // output pending bytes in tx buffer
667
        if((UART1_tx_buffer.Locked == TRUE)) return;
673
        if((UART1_tx_buffer.Locked == TRUE)) return;
668
 
674
 
669
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
675
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
670
        {
676
        {
671
                s16 ParamValue;
677
                s16 ParamValue;
672
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
678
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
673
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
679
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
674
                UART1_Request_Parameter = FALSE;
680
                UART1_Request_Parameter = FALSE;
675
        }
681
        }
676
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
682
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
677
        {
683
        {
678
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
684
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
679
                Echo = 0; // reset echo value
685
                Echo = 0; // reset echo value
680
                UART1_Request_Echo = FALSE;
686
                UART1_Request_Echo = FALSE;
681
        }
687
        }
682
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
688
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
683
        {
689
        {
684
                CheckFTPCommand(UART1_Request_FTP);
690
                CheckFTPCommand(UART1_Request_FTP);
685
                UART1_Request_FTP = FALSE;
691
                UART1_Request_FTP = FALSE;
686
        }
692
        }
687
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
693
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
688
        {
694
        {
689
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
695
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
690
                UART1_Request_WritePoint = 0xFF;
696
                UART1_Request_WritePoint = 0xFF;
691
        }
697
        }
692
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
698
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
693
        {
699
        {
694
                u8 PointCount = PointList_GetCount();
700
                u8 PointCount = PointList_GetCount();
695
                if (UART1_Request_ReadPoint <= PointCount)
701
                if (UART1_Request_ReadPoint <= PointCount)
696
                {
702
                {
697
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
703
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
698
                }
704
                }
699
                else
705
                else
700
                {
706
                {
701
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
707
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
702
                }
708
                }
703
                UART1_Request_ReadPoint = 0;
709
                UART1_Request_ReadPoint = 0;
704
        }
710
        }
705
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
711
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
706
        {
712
        {
707
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
713
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
708
                UART1_Request_DebugLabel = 0xFF;
714
                UART1_Request_DebugLabel = 0xFF;
709
        }
715
        }
710
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
716
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
711
        {
717
        {
712
                NaviData.Errorcode = ErrorCode;
718
                NaviData.Errorcode = ErrorCode;
713
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
719
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
714
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
720
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
715
                UART1_Request_NaviData = FALSE;
721
                UART1_Request_NaviData = FALSE;
716
        }
722
        }
717
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
723
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
718
        {
724
        {
719
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
725
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
720
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
726
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
721
                UART1_Request_DebugData = FALSE;
727
                UART1_Request_DebugData = FALSE;
722
        }
728
        }
723
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
729
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
724
        {
730
        {
725
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
731
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
726
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
732
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
727
                UART1_Request_Data3D = FALSE;
733
                UART1_Request_Data3D = FALSE;
728
        }
734
        }
729
        /*
735
        /*
730
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
736
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
731
        {
737
        {
732
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
738
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
733
                UART1_ConfirmFrame = 0;
739
                UART1_ConfirmFrame = 0;
734
        }
740
        }
735
        */
741
        */
736
        /*
742
        /*
737
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
743
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
738
        {
744
        {
739
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
745
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
740
                UART1_Request_ExternalControl = FALSE;
746
                UART1_Request_ExternalControl = FALSE;
741
        }
747
        }
742
        */
748
        */
743
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
749
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
744
        {
750
        {
745
                if(UART1_DisplayLine > 3)
751
                if(UART1_DisplayLine > 3)
746
                {
752
                {
747
                        Menu_Update(UART1_DisplayKeys);
753
                        Menu_Update(UART1_DisplayKeys);
748
                        UART1_DisplayKeys = 0;
754
                        UART1_DisplayKeys = 0;
749
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
755
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
750
                }
756
                }
751
                else
757
                else
752
                {
758
                {
753
                        UART1_DisplayLine = 2;
759
                        UART1_DisplayLine = 2;
754
                        sprintf(text,"!!! incompatible !!!");
760
                        sprintf(text,"!!! incompatible !!!");
755
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
761
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
756
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
762
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
757
                }
763
                }
758
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
764
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
759
                UART1_Request_Display = FALSE;
765
                UART1_Request_Display = FALSE;
760
        }
766
        }
761
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
767
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
762
        {
768
        {
763
                Menu_Update(0);
769
                Menu_Update(0);
764
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
770
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
765
                UART1_Request_Display1 = FALSE;
771
                UART1_Request_Display1 = FALSE;
766
        }
772
        }
767
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
773
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
768
        {
774
        {
769
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
775
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
770
                UART1_Request_VersionInfo = FALSE;
776
                UART1_Request_VersionInfo = FALSE;
771
        }
777
        }
772
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
778
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
773
        {
779
        {
774
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
780
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
775
                UART1_Request_ErrorMessage = FALSE;
781
                UART1_Request_ErrorMessage = FALSE;
776
        }
782
        }
777
#ifdef FOLLOW_ME
783
#ifdef FOLLOW_ME
778
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
784
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
779
        {
785
        {
780
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
786
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
781
                {
787
                {
782
                        TransmitAlsoToFC = 1;
788
                        TransmitAlsoToFC = 1;
783
                        // update FollowMe content
789
                        // update FollowMe content
784
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
790
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
785
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
791
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
786
                        FollowMe.Position.Status = NEWDATA;
792
                        FollowMe.Position.Status = NEWDATA;
787
                        FollowMe.Position.Altitude = 1;
793
                        FollowMe.Position.Altitude = 1;
788
                        // 0  -> no Orientation
794
                        // 0  -> no Orientation
789
                        // 1-360 -> CompassCourse Setpoint
795
                        // 1-360 -> CompassCourse Setpoint
790
                        // -1 -> points to  WP1 -> itself
796
                        // -1 -> points to  WP1 -> itself
791
                FollowMe.Heading = -1;
797
                FollowMe.Heading = -1;
792
                        FollowMe.ToleranceRadius = 1;
798
                        FollowMe.ToleranceRadius = 1;
793
                        FollowMe.HoldTime = 60;
799
                        FollowMe.HoldTime = 60;
794
                        FollowMe.Event_Flag = 1;
800
                        FollowMe.Event_Flag = 1;
795
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
801
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
796
                        FollowMe.Type = POINT_TYPE_WP;
802
                        FollowMe.Type = POINT_TYPE_WP;
797
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
803
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
798
                        FollowMe.AltitudeRate = 0;                        // do not change height
804
                        FollowMe.AltitudeRate = 0;                        // do not change height
799
                        FollowMe.reserve[0] = 0;                // reserve
805
                        FollowMe.reserve[0] = 0;                // reserve
800
                        FollowMe.reserve[1] = 0;                // reserve
806
                        FollowMe.reserve[1] = 0;                // reserve
801
                        FollowMe.reserve[2] = 0;                // reserve
807
                        FollowMe.reserve[2] = 0;                // reserve
802
                        FollowMe.reserve[3] = 0;                // reserve
808
                        FollowMe.reserve[3] = 0;                // reserve
803
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
809
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
804
                }
810
                }
805
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
811
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
806
        }
812
        }
807
#endif
813
#endif
808
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
814
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
809
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
815
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
810
        {
816
        {
811
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
817
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
812
                SendDebugOutput = 0;
818
                SendDebugOutput = 0;
813
        }
819
        }
814
#endif
820
#endif
815
        UART1_Transmit(); // output pending bytes in tx buffer
821
        UART1_Transmit(); // output pending bytes in tx buffer
816
}
822
}
817
 
823
 
818
 
824