Subversion Repositories NaviCtrl

Rev

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

Rev 576 Rev 586
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include <stdio.h>
56
#include <stdio.h>
57
#include <stdlib.h>
57
#include <stdlib.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 "spi_slave.h"
80
#include "ftphelper.h"
80
#include "ftphelper.h"
81
#include "led.h"
81
#include "led.h"
82
#include "fat16.h"
82
#include "fat16.h"
83
#include "eeprom.h"
83
#include "eeprom.h"
84
 
84
 
85
#define LIC_CMD_READ_LICENSE     1
85
#define LIC_CMD_READ_LICENSE     1
86
#define LIC_CMD_WRITE_LICENSE    2
86
#define LIC_CMD_WRITE_LICENSE    2
87
#define LIC_CMD_ERASE_LICENSE    3
87
#define LIC_CMD_ERASE_LICENSE    3
88
 
88
 
89
 
89
 
90
#define FALSE   0
90
#define FALSE   0
91
#define TRUE    1
91
#define TRUE    1
92
 
92
 
93
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
93
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
94
u32 UART1_AboTimeOut = 0;
94
u32 UART1_AboTimeOut = 0;
95
 
95
 
96
u8 UART1_Request_VersionInfo    = FALSE;
96
u8 UART1_Request_VersionInfo    = FALSE;
97
u8 UART1_Request_ExternalControl= FALSE;
97
u8 UART1_Request_ExternalControl= FALSE;
98
u8 UART1_Request_Display                = FALSE;
98
u8 UART1_Request_Display                = FALSE;
99
u8 UART1_Request_Display1               = FALSE;
99
u8 UART1_Request_Display1               = FALSE;
100
u8 UART1_Request_DebugData              = FALSE;
100
u8 UART1_Request_DebugData              = FALSE;
101
u8 UART1_Request_DebugLabel             = 255;
101
u8 UART1_Request_DebugLabel             = 255;
102
u8 UART1_Request_NaviData               = FALSE;
102
u8 UART1_Request_NaviData               = FALSE;
103
u8 UART1_Request_ErrorMessage   = FALSE;
103
u8 UART1_Request_ErrorMessage   = FALSE;
104
u8 UART1_Request_WritePoint             = 0xFF;
104
u8 UART1_Request_WritePoint             = 0xFF;
105
u8 UART1_Request_ReadPoint              = 0;
105
u8 UART1_Request_ReadPoint              = 0;
106
u8 UART1_Request_Data3D             = FALSE;
106
u8 UART1_Request_Data3D             = FALSE;
107
u8 UART1_Request_MotorData          = FALSE;
107
u8 UART1_Request_MotorData          = FALSE;
108
u8 UART1_Request_Echo               = FALSE;
108
u8 UART1_Request_Echo               = FALSE;
109
u8 UART1_Request_ParameterId    = 0;
109
u8 UART1_Request_ParameterId    = 0;
110
u8 UART1_Request_WPLStore               = FALSE;
110
u8 UART1_Request_WPLStore               = FALSE;
111
u8 UART1_Request_Parameter              = FALSE;
111
u8 UART1_Request_Parameter              = FALSE;
112
u8 UART1_Request_SystemTime             = FALSE;
112
u8 UART1_Request_SystemTime             = FALSE;
113
u8 UART1_DisplayKeys                    = 0;
113
u8 UART1_DisplayKeys                    = 0;
114
u8 UART1_DisplayLine                    = 0;
114
u8 UART1_DisplayLine                    = 0;
115
u8 UART1_ConfirmFrame                   = 0;
115
u8 UART1_ConfirmFrame                   = 0;
116
u8 UART1_Request_FTP                    = FALSE;
116
u8 UART1_Request_FTP                    = FALSE;
117
u8 UART1_Request_LicenseString  = FALSE;
117
u8 UART1_Request_LicenseString  = FALSE;
118
u8 LastTransmittedFCStatusFlags2 = 0;
118
u8 LastTransmittedFCStatusFlags2 = 0;
119
u8 UART1_ExternalControlConfirmFrame = FALSE;
119
u8 UART1_ExternalControlConfirmFrame = FALSE;
120
u8 Send_NMEA_RMC = FALSE;
120
u8 Send_NMEA_RMC = FALSE;
121
 
121
 
122
UART_TypeDef *DebugUART = UART1;
122
UART_TypeDef *DebugUART = UART1;
123
 
123
 
124
#ifdef FOLLOW_ME
124
#ifdef FOLLOW_ME
125
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
125
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
126
u32 UART1_FollowMe_Timer        = 0;
126
u32 UART1_FollowMe_Timer        = 0;
127
Point_t FollowMe;
127
Point_t FollowMe;
128
#endif
128
#endif
129
 
129
 
130
// the primary rx fifo
130
// the primary rx fifo
131
#define UART1_RX_FIFO_LEN 1024
131
#define UART1_RX_FIFO_LEN 1024
132
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
132
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
133
fifo_t UART1_rx_fifo;
133
fifo_t UART1_rx_fifo;
134
 
134
 
135
// the rx buffer
135
// the rx buffer
136
#define UART1_RX_BUFFER_LEN 1024
136
#define UART1_RX_BUFFER_LEN 1024
137
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
137
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
138
Buffer_t UART1_rx_buffer;
138
Buffer_t UART1_rx_buffer;
139
 
139
 
140
// the tx buffer
140
// the tx buffer
141
#define UART1_TX_BUFFER_LEN 1024
141
#define UART1_TX_BUFFER_LEN 1024
142
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
142
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
143
Buffer_t UART1_tx_buffer;
143
Buffer_t UART1_tx_buffer;
144
 
144
 
145
volatile u8 SerialLinkOkay = 0;
145
volatile u8 SerialLinkOkay = 0;
146
 
146
 
147
u8 text[200];
147
u8 text[200];
148
u8 *LicensePtr = UART1_tbuffer;
148
u8 *LicensePtr = UART1_tbuffer;
149
 
149
 
150
const u8 ANALOG_LABEL[32][16] =
150
const u8 ANALOG_LABEL[32][16] =
151
{
151
{
152
   //1234567890123456
152
   //1234567890123456
153
        "AngleNick       ", //0
153
        "AngleNick       ", //0
154
        "AngleRoll       ",
154
        "AngleRoll       ",
155
        "AccNick         ",
155
        "AccNick         ",
156
        "AccRoll         ",
156
        "AccRoll         ",
157
        "Altitude [0.1m] ",
157
        "Altitude [0.1m] ",
158
        "FC-Flags        ", //5
158
        "FC-Flags        ", //5
159
        "NC-Flags        ",
159
        "NC-Flags        ",
160
        "Voltage  [0.1V] ",
160
        "Voltage  [0.1V] ",
161
        "Current  [0.1A] ",
161
        "Current  [0.1A] ",
162
        "GPS Data        ",
162
        "GPS Data        ",
163
        "CompassHeading  ", //10
163
        "CompassHeading  ", //10
164
        "GyroHeading     ",
164
        "GyroHeading     ",
165
        "SPI Error       ", // achtung: muss auf 12 bleiben
165
        "SPI Error       ", // achtung: muss auf 12 bleiben
166
        "SPI Okay        ",
166
        "SPI Okay        ",
167
        "I2C Error       ",
167
        "I2C Error       ",
168
        "I2C Okay        ", //15
168
        "I2C Okay        ", //15
169
        "16              ",
169
        "16              ",
170
        "17              ",
170
        "17              ",
171
        "18              ",
171
        "18              ",
172
        "19              ", // SD-Card-time
172
        "19              ", // SD-Card-time
173
        "EarthMagnet [%] ", //20
173
        "EarthMagnet [%] ", //20
174
        "Ground Speed    ", //  "Z_Speed         ",
174
        "Ground Speed    ", //  "Z_Speed         ",
175
        "N_Speed         ",
175
        "N_Speed         ",
176
        "E_Speed         ",
176
        "E_Speed         ",
177
        "Magnet X        ",
177
        "Magnet X        ",
178
        "Magnet Y        ", //25
178
        "Magnet Y        ", //25
179
        "Magnet Z        ",
179
        "Magnet Z        ",
180
        "Distance N      ",
180
        "Distance N      ",
181
        "Distance E      ",
181
        "Distance E      ",
182
        "-GPS_Nick       ",
182
        "-GPS_Nick       ",
183
        "-GPS_Roll       ", //30
183
        "-GPS_Roll       ", //30
184
        "Used_Sats       "
184
        "Used_Sats       "
185
};
185
};
186
 
186
 
187
typedef struct
187
typedef struct
188
{
188
{
189
        u8 Index;
189
        u8 Index;
190
        u8 Status;
190
        u8 Status;
191
} __attribute__((packed)) WPL_Answer_t;
191
} __attribute__((packed)) WPL_Answer_t;
192
WPL_Answer_t WPL_Answer;
192
WPL_Answer_t WPL_Answer;
193
 
193
 
194
DebugOut_t DebugOut;
194
DebugOut_t DebugOut;
195
ExternControl_t ExternControl;
195
ExternControl_t ExternControl;
196
UART_VersionInfo_t UART_VersionInfo;
196
UART_VersionInfo_t UART_VersionInfo;
197
NaviData_t NaviData;
197
NaviData_t NaviData;
198
Data3D_t Data3D;
198
Data3D_t Data3D;
199
 
199
 
200
u16 Echo; // 2 bytes recieved will be sent back as echo
200
u16 Echo; // 2 bytes recieved will be sent back as echo
201
 
201
 
202
u32 UART1_DebugData_Timer = 0;
202
u32 UART1_DebugData_Timer = 0;
203
u32 UART1_DebugData_Interval = 0;       // in ms
203
u32 UART1_DebugData_Interval = 0;       // in ms
204
u32 UART1_NaviData_Timer = 0;
204
u32 UART1_NaviData_Timer = 0;
205
u32 UART1_NaviData_Interval = 0;        // in ms
205
u32 UART1_NaviData_Interval = 0;        // in ms
206
u32 UART1_Data3D_Timer = 0;
206
u32 UART1_Data3D_Timer = 0;
207
u32 UART1_Data3D_Interval = 0;          // in ms
207
u32 UART1_Data3D_Interval = 0;          // in ms
208
u32 UART1_MotorData_Timer = 0;
208
u32 UART1_MotorData_Timer = 0;
209
u32 UART1_MotorData_Interval = 0;               // in ms
209
u32 UART1_MotorData_Interval = 0;               // in ms
210
u32 UART1_Display_Timer = 0;
210
u32 UART1_Display_Timer = 0;
211
u32 UART1_Display_Interval = 0;         // in ms
211
u32 UART1_Display_Interval = 0;         // in ms
212
u32 NMEA_Timer = 0;
212
u32 NMEA_Timer = 0;
213
u32 NMEA_Interval = 0;// in ms
213
u32 NMEA_Interval = 0;// in ms
214
 
214
 
215
/********************************************************/
215
/********************************************************/
216
/*            Initialization the UART1                  */
216
/*            Initialization the UART1                  */
217
/********************************************************/
217
/********************************************************/
218
void UART1_Init (void)
218
void UART1_Init (void)
219
{
219
{
220
        GPIO_InitTypeDef GPIO_InitStructure;
220
        GPIO_InitTypeDef GPIO_InitStructure;
221
        UART_InitTypeDef UART_InitStructure;
221
        UART_InitTypeDef UART_InitStructure;
222
 
222
 
223
        // initialize txd buffer
223
        // initialize txd buffer
224
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
224
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
225
 
225
 
226
        // initialize rxd buffer
226
        // initialize rxd buffer
227
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
227
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
228
 
228
 
229
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
229
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
230
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
230
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
231
 
231
 
232
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
232
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
233
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
233
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
234
 
234
 
235
        /*Configure UART1_Rx pin GPIO3.2*/
235
        /*Configure UART1_Rx pin GPIO3.2*/
236
        GPIO_StructInit(&GPIO_InitStructure);
236
        GPIO_StructInit(&GPIO_InitStructure);
237
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
237
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
238
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
238
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
239
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
239
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
240
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
240
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
241
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
241
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
242
        GPIO_Init(GPIO3, &GPIO_InitStructure);
242
        GPIO_Init(GPIO3, &GPIO_InitStructure);
243
 
243
 
244
        /*Configure UART1_Tx pin GPIO3.3*/
244
        /*Configure UART1_Tx pin GPIO3.3*/
245
        GPIO_StructInit(&GPIO_InitStructure);
245
        GPIO_StructInit(&GPIO_InitStructure);
246
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
246
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
247
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
247
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
248
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
248
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
249
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
249
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
250
        GPIO_Init(GPIO3, &GPIO_InitStructure);
250
        GPIO_Init(GPIO3, &GPIO_InitStructure);
251
 
251
 
252
        /* UART1 configured as follow:
252
        /* UART1 configured as follow:
253
        - Word Length = 8 Bits
253
        - Word Length = 8 Bits
254
        - One Stop Bit
254
        - One Stop Bit
255
        - No parity
255
        - No parity
256
        - BaudRate = 57600 baud
256
        - BaudRate = 57600 baud
257
        - Hardware flow control Disabled
257
        - Hardware flow control Disabled
258
        - Receive and transmit enabled
258
        - Receive and transmit enabled
259
        - Receive and transmit FIFOs are Disabled
259
        - Receive and transmit FIFOs are Disabled
260
        */
260
        */
261
        UART_StructInit(&UART_InitStructure);
261
        UART_StructInit(&UART_InitStructure);
262
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
262
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
263
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
263
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
264
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
264
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
265
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
265
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
266
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
266
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
267
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
267
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
268
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
268
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
269
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
269
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
270
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
270
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
271
 
271
 
272
        UART_DeInit(UART1); // reset uart 1     to default
272
        UART_DeInit(UART1); // reset uart 1     to default
273
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
273
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
274
        // enable uart 1 interrupts selective
274
        // enable uart 1 interrupts selective
275
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
275
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
276
        UART_Cmd(UART1, ENABLE); // enable uart 1
276
        UART_Cmd(UART1, ENABLE); // enable uart 1
277
        // configure the uart 1 interupt line
277
        // configure the uart 1 interupt line
278
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
278
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
279
        // enable the uart 1 IRQ
279
        // enable the uart 1 IRQ
280
        VIC_ITCmd(UART1_ITLine, ENABLE);
280
        VIC_ITCmd(UART1_ITLine, ENABLE);
281
 
281
 
282
        // initialize the debug timer
282
        // initialize the debug timer
283
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
283
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
284
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
284
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
285
        NMEA_Timer = SetDelay(14000);
285
        NMEA_Timer = SetDelay(14000);
286
 
286
 
287
        // Fill Version Info Structure
287
        // Fill Version Info Structure
288
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
288
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
289
        UART_VersionInfo.SWMinor = VERSION_MINOR;
289
        UART_VersionInfo.SWMinor = VERSION_MINOR;
290
        UART_VersionInfo.SWPatch = VERSION_PATCH;
290
        UART_VersionInfo.SWPatch = VERSION_PATCH;
291
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
291
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
292
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
292
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
293
    UART_VersionInfo.BL_Firmware = 255;
293
    UART_VersionInfo.BL_Firmware = 255;
294
        UART_VersionInfo.Flags = 0;
294
        UART_VersionInfo.Flags = 0;
295
        UART_VersionInfo.Reserved1 = 0;
295
        UART_VersionInfo.Reserved1 = 0;
296
        NaviData.Version = NAVIDATA_VERSION;
296
        NaviData.Version = NAVIDATA_VERSION;
297
 
297
 
298
        UART1_PutString("\r\n UART1 init...ok");
298
        UART1_PutString("\r\n UART1 init...ok");
299
}
299
}
300
 
300
 
301
 
301
 
302
/****************************************************************/
302
/****************************************************************/
303
/*               USART1 receiver ISR                            */
303
/*               USART1 receiver ISR                            */
304
/****************************************************************/
304
/****************************************************************/
305
void UART1_IRQHandler(void)
305
void UART1_IRQHandler(void)
306
{
306
{
307
        static u8 abortState = 0;
307
        static u8 abortState = 0;
308
        u8 c;
308
        u8 c;
309
 
309
 
310
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
310
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
311
        {
311
        {
312
                // clear the pending bits!
312
                // clear the pending bits!
313
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
313
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
314
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
314
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
315
                // if debug UART is not UART1
315
                // if debug UART is not UART1
316
                if (DebugUART != UART1)
316
                if (DebugUART != UART1)
317
                {       // forward received data to the debug UART tx buffer
317
                {       // forward received data to the debug UART tx buffer
318
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
318
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
319
                        {
319
                        {
320
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
320
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
321
                                c = UART_ReceiveData(UART1);
321
                                c = UART_ReceiveData(UART1);
322
 
322
 
323
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
323
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
324
                                switch (abortState)
324
                                switch (abortState)
325
                                {
325
                                {
326
                                        case 0:
326
                                        case 0:
327
                                                if (c == 27) abortState++;
327
                                                if (c == 27) abortState++;
328
                                                break;
328
                                                break;
329
                                        case 1:
329
                                        case 1:
330
                                                if (c == 27) abortState++;
330
                                                if (c == 27) abortState++;
331
                                                else abortState = 0;
331
                                                else abortState = 0;
332
                                        break;
332
                                        break;
333
                                        case 2:
333
                                        case 2:
334
                                                if (c == 0x55) abortState++;
334
                                                if (c == 0x55) abortState++;
335
                                                else abortState = 0;
335
                                                else abortState = 0;
336
                                                break;
336
                                                break;
337
                                        case 3:
337
                                        case 3:
338
                                                if (c == 0xAA) abortState++;
338
                                                if (c == 0xAA) abortState++;
339
                                                else abortState = 0;
339
                                                else abortState = 0;
340
                                                break;
340
                                                break;
341
                                        case 4:
341
                                        case 4:
342
                                                if (c == 0x00)
342
                                                if (c == 0x00)
343
                                                {
343
                                                {
344
                                                        if(DebugUART == UART0)
344
                                                        if(DebugUART == UART0)
345
                                                        {
345
                                                        {
346
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
346
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
347
                                                                TIMER2_Init(); // enbable servo outputs
347
                                                                TIMER2_Init(); // enbable servo outputs
348
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
348
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
349
                                                        }
349
                                                        }
350
                                                        DebugUART = UART1;
350
                                                        DebugUART = UART1;
351
                                                }
351
                                                }
352
                                                abortState = 0;
352
                                                abortState = 0;
353
                                                break;
353
                                                break;
354
                                } // end switch abort state
354
                                } // end switch abort state
355
                                // if the Debug uart is not UART1, redirect input to the Debug UART
355
                                // if the Debug uart is not UART1, redirect input to the Debug UART
356
                                if (DebugUART != UART1)
356
                                if (DebugUART != UART1)
357
                                {
357
                                {
358
                                        // wait for space in the tx buffer of the DebugUART
358
                                        // wait for space in the tx buffer of the DebugUART
359
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
359
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
360
                                        // move byte to the tx fifo of the debug uart
360
                                        // move byte to the tx fifo of the debug uart
361
                                        UART_SendData(DebugUART, c);
361
                                        UART_SendData(DebugUART, c);
362
                                }
362
                                }
363
                        }
363
                        }
364
                }
364
                }
365
                else  // DebugUART == UART1 (normal operation)
365
                else  // DebugUART == UART1 (normal operation)
366
                {
366
                {
367
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
367
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
368
                        { // some byes in the hardware fifo
368
                        { // some byes in the hardware fifo
369
                            // get byte from hardware fifo
369
                            // get byte from hardware fifo
370
                        c = UART_ReceiveData(UART1);
370
                        c = UART_ReceiveData(UART1);
371
                                // put into the software fifo
371
                                // put into the software fifo
372
                                if(!fifo_put(&UART1_rx_fifo, c))
372
                                if(!fifo_put(&UART1_rx_fifo, c))
373
                                {       // fifo overflow
373
                                {       // fifo overflow
374
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
374
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
375
                                }
375
                                }
376
                        } // EOF while some byes in the hardware fifo
376
                        } // EOF while some byes in the hardware fifo
377
                } // eof DebugUart = UART1
377
                } // eof DebugUart = UART1
378
        }
378
        }
379
 
379
 
380
 
380
 
381
 
381
 
382
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
382
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
383
}
383
}
384
 
384
 
385
/**************************************************************/
385
/**************************************************************/
386
/* Process incomming data from debug uart                     */
386
/* Process incomming data from debug uart                     */
387
/**************************************************************/
387
/**************************************************************/
388
void UART1_ProcessRxData(void)
388
void UART1_ProcessRxData(void)
389
{
389
{
390
        // return on forwarding uart  or unlocked rx buffer
390
        // return on forwarding uart  or unlocked rx buffer
391
        u8 c;
391
        u8 c;
392
        if(DebugUART != UART1) return;
392
        if(DebugUART != UART1) return;
393
        // if rx buffer is not locked
393
        // if rx buffer is not locked
394
        if(UART1_rx_buffer.Locked == FALSE)
394
        if(UART1_rx_buffer.Locked == FALSE)
395
        {
395
        {
396
                //collect data from primary rx fifo
396
                //collect data from primary rx fifo
397
                while(fifo_get(&UART1_rx_fifo, &c))
397
                while(fifo_get(&UART1_rx_fifo, &c))
398
                {
398
                {
399
                        // break if complete frame is collected
399
                        // break if complete frame is collected
400
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
400
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
401
                }
401
                }
402
        }
402
        }
403
        if(UART1_rx_buffer.Locked == FALSE) return;
403
        if(UART1_rx_buffer.Locked == FALSE) return;
404
 
404
 
405
        Point_t * pPoint = NULL;
405
        Point_t * pPoint = NULL;
406
        SerialMsg_t SerialMsg;
406
        SerialMsg_t SerialMsg;
407
 
407
 
408
        // analyze header first
408
        // analyze header first
409
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
409
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
410
        if( SerialMsg.Address == FC_ADDRESS )
410
        if( SerialMsg.Address == FC_ADDRESS )
411
        {
411
        {
412
                switch(SerialMsg.CmdID)
412
                switch(SerialMsg.CmdID)
413
                {
413
                {
414
//                      case 'v': // version
414
//                      case 'v': // version
415
                        case 'b': // extern control
415
                        case 'b': // extern control
416
                                          UART1_ExternalControlConfirmFrame = 1;
416
                                          UART1_ExternalControlConfirmFrame = 1;
417
                        case 'y': // serial poti values
417
                        case 'y': // serial poti values
418
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
418
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
419
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
419
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
420
                                return; //end process rx data
420
                                return; //end process rx data
421
                        break;
421
                        break;
422
                }
422
                }
423
        }
423
        }
424
 
424
 
425
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
425
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
426
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
426
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
427
        switch(SerialMsg.Address) // check for Slave Address
427
        switch(SerialMsg.Address) // check for Slave Address
428
        {
428
        {
429
                case NC_ADDRESS:  // own Slave Address
429
                case NC_ADDRESS:  // own Slave Address
430
                switch(SerialMsg.CmdID)
430
                switch(SerialMsg.CmdID)
431
                {
431
                {
432
                        case 't': // request for the GPS time
432
                        case 't': // request for the GPS time
433
                                UART1_Request_SystemTime  = TRUE;
433
                                UART1_Request_SystemTime  = TRUE;
434
                                break;
434
                                break;
435
 
435
 
436
                        case 'm': // request for the license string
436
                        case 'm': // request for the license string
437
                                UART1_Request_LicenseString = SerialMsg.pData[0];
437
                                UART1_Request_LicenseString = SerialMsg.pData[0];
438
                                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20))
438
                                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20))
439
                                 {
439
                                 {
440
                                  memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy ftp parameter
440
                                  memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy ftp parameter
441
                                 }
441
                                 }
442
                                break;
442
                                break;
443
                        case 'f': // ftp command
443
                        case 'f': // ftp command
444
                                UART1_Request_FTP = SerialMsg.pData[0];
444
                                UART1_Request_FTP = SerialMsg.pData[0];
445
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
445
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
446
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
446
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
447
                        break;
447
                        break;
448
 
448
 
449
                        case 'z': // connection checker
449
                        case 'z': // connection checker
450
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
450
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
451
                                UART1_Request_Echo = TRUE;
451
                                UART1_Request_Echo = TRUE;
452
                                break;
452
                                break;
453
 
453
 
454
                        case 'e': // request for the text of the error status
454
                        case 'e': // request for the text of the error status
455
                                UART1_Request_ErrorMessage = TRUE;
455
                                UART1_Request_ErrorMessage = TRUE;
456
                                break;
456
                                break;
457
 
457
 
458
                        case 's'://  new target position
458
                        case 's'://  new target position
459
                                pPoint = (Point_t*)SerialMsg.pData;
459
                                pPoint = (Point_t*)SerialMsg.pData;
460
                                if(pPoint->Position.Status == NEWDATA)
460
                                if(pPoint->Position.Status == NEWDATA)
461
                                {
461
                                {
462
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
462
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
463
                                        //pPoint->Index = 1; // must be one after empty list
463
                                        //pPoint->Index = 1; // must be one after empty list
464
                                        PointList_SetAt(pPoint);
464
                                        PointList_SetAt(pPoint);
465
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
465
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
466
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
466
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
467
                                        BeepTime = 50;
467
                                        BeepTime = 50;
468
                                }
468
                                }
469
                                else
469
                                else
470
                                if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN))
470
                                if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN))
471
                                {
471
                                {
-
 
472
                                if(pPoint->Event_Flag & SIMULATION_MOTOR_ON)
-
 
473
                                 {
472
                                if(pPoint->Event_Flag & SIMULATION_MOTOR_ON) GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position
474
                                  GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position
-
 
475
                                  CompassDirectionAtMotorStart = SimulatedDirection*10;
-
 
476
                                 }
473
                                if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON))
477
                                if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON))
474
                                 {
478
                                 {
475
                                  SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin
479
                                  SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin
476
                                  SpeakHoTT = SPEAK_STARTING;
480
                                  SpeakHoTT = SPEAK_STARTING;
477
                                 }
481
                                 }
478
                                else
482
                                else
479
                                if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON))
483
                                if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON))
480
                                 {
484
                                 {
481
                                  SimulationFlags = pPoint->Event_Flag;
485
                                  SimulationFlags = pPoint->Event_Flag;
482
                                  SpeakHoTT = SPEAK_MK_OFF;
486
                                  SpeakHoTT = SPEAK_MK_OFF;
483
                                  BeepTime = 50;
487
                                  BeepTime = 50;
484
                                 }
488
                                 }
485
                                 else
489
                                 else
486
                                  SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START);
490
                                  SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START);
487
                                }
491
                                }
488
                                break;
492
                                break;
489
                        case 'u': // redirect debug uart
493
                        case 'u': // redirect debug uart
490
                                switch(SerialMsg.pData[0])
494
                                switch(SerialMsg.pData[0])
491
                                {
495
                                {
492
                                        case UART_FLIGHTCTRL:
496
                                        case UART_FLIGHTCTRL:
493
                                                UART2_Init();                           // initialize UART2 to FC pins
497
                                                UART2_Init();                           // initialize UART2 to FC pins
494
                                                fifo_purge(&UART1_rx_fifo);
498
                                                fifo_purge(&UART1_rx_fifo);
495
                                                TIMER2_Deinit();                        // reduce irq load
499
                                                TIMER2_Deinit();                        // reduce irq load
496
                                                DebugUART = UART2;
500
                                                DebugUART = UART2;
497
                                                break;
501
                                                break;
498
                                        case UART_MK3MAG:
502
                                        case UART_MK3MAG:
499
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
503
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
500
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
504
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
501
                                                GPSData.Status = INVALID;
505
                                                GPSData.Status = INVALID;
502
                                                fifo_purge(&UART1_rx_fifo);
506
                                                fifo_purge(&UART1_rx_fifo);
503
                                                DebugUART = UART0;
507
                                                DebugUART = UART0;
504
                                                break;
508
                                                break;
505
                                        case UART_MKGPS:
509
                                        case UART_MKGPS:
506
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
510
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
507
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
511
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
508
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
512
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
509
                                                GPSData.Status = INVALID;
513
                                                GPSData.Status = INVALID;
510
                                                fifo_purge(&UART1_rx_fifo);
514
                                                fifo_purge(&UART1_rx_fifo);
511
                                                DebugUART = UART0;
515
                                                DebugUART = UART0;
512
                                                break;
516
                                                break;
513
                                        default:
517
                                        default:
514
                                                break;
518
                                                break;
515
                                }
519
                                }
516
                                break;
520
                                break;
517
 
521
 
518
                        case 'w'://  Set point in list at index
522
                        case 'w'://  Set point in list at index
519
                                {
523
                                {
520
                                        pPoint = (Point_t*)SerialMsg.pData;
524
                                        pPoint = (Point_t*)SerialMsg.pData;
521
 
525
 
522
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
526
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
523
                                        {
527
                                        {
524
                                                PointList_Clear();
528
                                                PointList_Clear();
525
                                                GPS_pWaypoint = PointList_WPBegin();
529
                                                GPS_pWaypoint = PointList_WPBegin();
526
                                                UART1_Request_WritePoint = 0; // return new point count
530
                                                UART1_Request_WritePoint = 0; // return new point count
527
                                                NewWaypointsReceived = 1;
531
                                                NewWaypointsReceived = 1;
528
                                        }
532
                                        }
529
                                        else
533
                                        else
530
                                        {  // update WP in list at index
534
                                        {  // update WP in list at index
531
                                                if(pPoint->Index > MaxNumberOfWaypoints)
535
                                                if(pPoint->Index > MaxNumberOfWaypoints)
532
                                                {
536
                                                {
533
                                                        UART1_Request_WritePoint = 254;
537
                                                        UART1_Request_WritePoint = 254;
534
                                                        pPoint->Index = MaxNumberOfWaypoints;
538
                                                        pPoint->Index = MaxNumberOfWaypoints;
535
                                                }
539
                                                }
536
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
540
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
537
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
541
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
538
                                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
542
                                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
539
                                                if(UART1_Request_WritePoint == pPoint->Index)
543
                                                if(UART1_Request_WritePoint == pPoint->Index)
540
                                                {
544
                                                {
541
                                                        BeepTime = 500;
545
                                                        BeepTime = 500;
542
                                                    if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1;            // Speak once as soon as the Points are active
546
                                                    if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1;            // Speak once as soon as the Points are active
543
                                                }
547
                                                }
544
                                        }
548
                                        }
545
                                }
549
                                }
546
                                break;
550
                                break;
547
 
551
 
548
                        case 'x'://  Read Waypoint from List
552
                        case 'x'://  Read Waypoint from List
549
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
553
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
550
                                break;
554
                                break;
551
 
555
 
552
                        case 'i':// Store WP List to file
556
                        case 'i':// Store WP List to file
553
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
557
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
554
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
558
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
555
                                WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer
559
                                WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer
556
                                WPL_Answer.Status = PointList_WriteToFile(&WPL_Store);
560
                                WPL_Answer.Status = PointList_WriteToFile(&WPL_Store);
557
                                UART1_Request_WPLStore = TRUE;
561
                                UART1_Request_WPLStore = TRUE;
558
                                break;
562
                                break;
559
 
563
 
560
 
564
 
561
                        case 'j':// Set/Get NC-Parameter
565
                        case 'j':// Set/Get NC-Parameter
562
                                switch(SerialMsg.pData[0])
566
                                switch(SerialMsg.pData[0])
563
                                {
567
                                {
564
                                        case 0: // get
568
                                        case 0: // get
565
                                        break;
569
                                        break;
566
 
570
 
567
                                        case 1: // set
571
                                        case 1: // set
568
                                        {
572
                                        {
569
                                                s16 value;
573
                                                s16 value;
570
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
574
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
571
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
575
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
572
                                        }
576
                                        }
573
                                        break;
577
                                        break;
574
                                       
578
                                       
575
                                        default:
579
                                        default:
576
                                        break;
580
                                        break;
577
                                }
581
                                }
578
                                UART1_Request_ParameterId = SerialMsg.pData[1];
582
                                UART1_Request_ParameterId = SerialMsg.pData[1];
579
                                UART1_Request_Parameter = TRUE;
583
                                UART1_Request_Parameter = TRUE;
580
                                break;
584
                                break;
581
                        default:
585
                        default:
582
                                // unsupported command recieved
586
                                // unsupported command recieved
583
                                break;
587
                                break;
584
                } // case NC_ADDRESS
588
                } // case NC_ADDRESS
585
                // "break;" is missing here to fall thru to the common commands
589
                // "break;" is missing here to fall thru to the common commands
586
 
590
 
587
                default:  // and any other Slave Address
591
                default:  // and any other Slave Address
588
 
592
 
589
                switch(SerialMsg.CmdID) // check CmdID
593
                switch(SerialMsg.CmdID) // check CmdID
590
                {
594
                {
591
                        case 'a':// request for the labels of the analog debug outputs
595
                        case 'a':// request for the labels of the analog debug outputs
592
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
596
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
593
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
597
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
594
                                break;
598
                                break;
595
                        /*
599
                        /*
596
                        case 'b': // submit extern control
600
                        case 'b': // submit extern control
597
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
601
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
598
                                UART1_ConfirmFrame = ExternControl.Frame;
602
                                UART1_ConfirmFrame = ExternControl.Frame;
599
                                break;
603
                                break;
600
                        */
604
                        */
601
                        case 'd': // request for debug data;
605
                        case 'd': // request for debug data;
602
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
606
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
603
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
607
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
604
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
608
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
605
                                break;
609
                                break;
606
 
610
 
607
                        case 'c': // request for 3D data;
611
                        case 'c': // request for 3D data;
608
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
612
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
609
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
613
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
610
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
614
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
611
                                break;
615
                                break;
612
 
616
 
613
                        case 'k': // request for Motor data;
617
                        case 'k': // request for Motor data;
614
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
618
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
615
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
619
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
616
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
620
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
617
                                break;
621
                                break;
618
 
622
 
619
                        case 'h':// reqest for display line
623
                        case 'h':// reqest for display line
620
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
624
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
621
                                {
625
                                {
622
                                        UART1_DisplayLine = 2;
626
                                        UART1_DisplayLine = 2;
623
                                        UART1_Display_Interval = 0;
627
                                        UART1_Display_Interval = 0;
624
                                }
628
                                }
625
                                else
629
                                else
626
                                {
630
                                {
627
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
631
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
628
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
632
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
629
                                        UART1_DisplayLine = 4;
633
                                        UART1_DisplayLine = 4;
630
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
634
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
631
                                }
635
                                }
632
                                UART1_Request_Display = TRUE;
636
                                UART1_Request_Display = TRUE;
633
                                break;
637
                                break;
634
 
638
 
635
                        case 'l':// reqest for display columns
639
                        case 'l':// reqest for display columns
636
                                MenuItem = SerialMsg.pData[0];
640
                                MenuItem = SerialMsg.pData[0];
637
                                UART1_Request_Display1 = TRUE;
641
                                UART1_Request_Display1 = TRUE;
638
                                break;
642
                                break;
639
 
643
 
640
                        case 'o': // request for navigation information
644
                        case 'o': // request for navigation information
641
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
645
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
642
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
646
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
643
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
647
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
644
                                break;
648
                                break;
645
 
649
 
646
                        case 'v': // request for version info
650
                        case 'v': // request for version info
647
                                if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1;
651
                                if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1;
648
                                else UART1_Request_VersionInfo = 2;
652
                                else UART1_Request_VersionInfo = 2;
649
                                break;
653
                                break;
650
                        default:
654
                        default:
651
                                // unsupported command recieved
655
                                // unsupported command recieved
652
                                break;
656
                                break;
653
                }
657
                }
654
                break; // default:
658
                break; // default:
655
        }
659
        }
656
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
660
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
657
}
661
}
658
 
662
 
659
 
663
 
660
/*****************************************************/
664
/*****************************************************/
661
/*                   Send a character                */
665
/*                   Send a character                */
662
/*****************************************************/
666
/*****************************************************/
663
s16 UART1_Putchar(char c)
667
s16 UART1_Putchar(char c)
664
{
668
{
665
        u32 timeout = 10000;
669
        u32 timeout = 10000;
666
        if (c == '\n') UART1_Putchar('\r');
670
        if (c == '\n') UART1_Putchar('\r');
667
        // wait until txd fifo is not full
671
        // wait until txd fifo is not full
668
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
672
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
669
        // transmit byte
673
        // transmit byte
670
        UART_SendData(UART1, c);
674
        UART_SendData(UART1, c);
671
        #ifdef FOLLOW_ME
675
        #ifdef FOLLOW_ME
672
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
676
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
673
        #endif
677
        #endif
674
        return (0);
678
        return (0);
675
}
679
}
676
 
680
 
677
/*****************************************************/
681
/*****************************************************/
678
/*       Send a string to the debug uart              */
682
/*       Send a string to the debug uart              */
679
/*****************************************************/
683
/*****************************************************/
680
void UART1_PutString(u8 *s)
684
void UART1_PutString(u8 *s)
681
{
685
{
682
        if(s == NULL) return;
686
        if(s == NULL) return;
683
        while (*s != '\0' && DebugUART == UART1)
687
        while (*s != '\0' && DebugUART == UART1)
684
        {
688
        {
685
                UART1_Putchar(*s);
689
                UART1_Putchar(*s);
686
                s ++;
690
                s ++;
687
        }
691
        }
688
}
692
}
689
 
693
 
690
 
694
 
691
/**************************************************************/
695
/**************************************************************/
692
/*         Transmit tx buffer via debug uart                  */
696
/*         Transmit tx buffer via debug uart                  */
693
/**************************************************************/
697
/**************************************************************/
694
void UART1_Transmit(void)
698
void UART1_Transmit(void)
695
{
699
{
696
        u8 tmp_tx;
700
        u8 tmp_tx;
697
        if(DebugUART != UART1) return;
701
        if(DebugUART != UART1) return;
698
        // if something has to be send and the txd fifo is not full
702
        // if something has to be send and the txd fifo is not full
699
        if(UART1_tx_buffer.Locked == TRUE)
703
        if(UART1_tx_buffer.Locked == TRUE)
700
        {
704
        {
701
                // while there is some space in the tx fifo
705
                // while there is some space in the tx fifo
702
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
706
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
703
                {
707
                {
704
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
708
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
705
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
709
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
706
                        #ifdef FOLLOW_ME
710
                        #ifdef FOLLOW_ME
707
                        if(TransmitAlsoToFC)
711
                        if(TransmitAlsoToFC)
708
                        {
712
                        {
709
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
713
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
710
                        }
714
                        }
711
                        #endif
715
                        #endif
712
                        // if terminating character or end of txd buffer reached
716
                        // if terminating character or end of txd buffer reached
713
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
717
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
714
                        {
718
                        {
715
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
719
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
716
                                #ifdef FOLLOW_ME
720
                                #ifdef FOLLOW_ME
717
                                TransmitAlsoToFC = 0;
721
                                TransmitAlsoToFC = 0;
718
                                #endif
722
                                #endif
719
                                break; // end while loop
723
                                break; // end while loop
720
                        }
724
                        }
721
                }
725
                }
722
        }
726
        }
723
}
727
}
724
 
728
 
725
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
729
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
726
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
730
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
727
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
731
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
728
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
732
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
729
 
733
 
730
void CreateNmeaGGA(void)
734
void CreateNmeaGGA(void)
731
{
735
{
732
        u8 array[200], i = 0, crc = 0, x;
736
        u8 array[200], i = 0, crc = 0, x;
733
        s32 tmp1, tmp2;
737
        s32 tmp1, tmp2;
734
 
738
 
735
        i += sprintf(array, "$GPGGA,");
739
        i += sprintf(array, "$GPGGA,");
736
        // +++++++++++++++++++++++++++++++++++++++++++
740
        // +++++++++++++++++++++++++++++++++++++++++++
737
        if(SystemTime.Valid)
741
        if(SystemTime.Valid)
738
        {
742
        {
739
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
743
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
740
        }
744
        }
741
        else
745
        else
742
        {
746
        {
743
                i += sprintf(&array[i], ",");
747
                i += sprintf(&array[i], ",");
744
        }
748
        }
745
        // +++++++++++++++++++++++++++++++++++++++++++
749
        // +++++++++++++++++++++++++++++++++++++++++++
746
        if(GPSData.Flags & FLAG_GPSFIXOK)
750
        if(GPSData.Flags & FLAG_GPSFIXOK)
747
        {
751
        {
748
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
752
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
749
                i += sprintf(&array[i],"%02d",(s16)tmp1);
753
                i += sprintf(&array[i],"%02d",(s16)tmp1);
750
 
754
 
751
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
755
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
752
                tmp1 *= 6; // in Minuten
756
                tmp1 *= 6; // in Minuten
753
                tmp2 = tmp1 / 1000000L;
757
                tmp2 = tmp1 / 1000000L;
754
                i += sprintf(&array[i],"%02d", (u16)tmp2);
758
                i += sprintf(&array[i],"%02d", (u16)tmp2);
755
                tmp2 = tmp1 % 1000000L;
759
                tmp2 = tmp1 % 1000000L;
756
                tmp2 /= 100; // zwei Stellen zu viel
760
                tmp2 /= 100; // zwei Stellen zu viel
757
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
761
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
758
 
762
 
759
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
763
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
760
                else i += sprintf(&array[i],"S,");
764
                else i += sprintf(&array[i],"S,");
761
                // +++++++++++++++++++++++++++++++++++++++++++
765
                // +++++++++++++++++++++++++++++++++++++++++++
762
 
766
 
763
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
767
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
764
                i += sprintf(&array[i],"%03d", (u16)tmp1);
768
                i += sprintf(&array[i],"%03d", (u16)tmp1);
765
 
769
 
766
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
770
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
767
                tmp1 *= 6; // in Minuten
771
                tmp1 *= 6; // in Minuten
768
                tmp2 = tmp1 / 1000000L;
772
                tmp2 = tmp1 / 1000000L;
769
                i += sprintf(&array[i],"%02d", (u16)tmp2);
773
                i += sprintf(&array[i],"%02d", (u16)tmp2);
770
                tmp2 = tmp1 % 1000000L;
774
                tmp2 = tmp1 % 1000000L;
771
                tmp2 /= 100; // zwei Stellen zu viel
775
                tmp2 /= 100; // zwei Stellen zu viel
772
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
776
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
773
 
777
 
774
 
778
 
775
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
779
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
776
                else i += sprintf(&array[i],"W,");
780
                else i += sprintf(&array[i],"W,");
777
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
781
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
778
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
782
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
779
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
783
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
780
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
784
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
781
                tmp1 = NaviData.Altimeter / 2; // in dm
785
                tmp1 = NaviData.Altimeter / 2; // in dm
782
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
786
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
783
                i += sprintf(&array[i],",,,*");
787
                i += sprintf(&array[i],",,,*");
784
        }
788
        }
785
        else
789
        else
786
        {
790
        {
787
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
791
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
788
        }
792
        }
789
        for(x = 1; x < i-1; x++)
793
        for(x = 1; x < i-1; x++)
790
        {
794
        {
791
                crc ^= array[x];
795
                crc ^= array[x];
792
        }
796
        }
793
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
797
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
794
        AddSerialData(&UART1_tx_buffer,array,i);
798
        AddSerialData(&UART1_tx_buffer,array,i);
795
 
799
 
796
        // +++++++++++++++++++++++++++++++++++++++++++
800
        // +++++++++++++++++++++++++++++++++++++++++++
797
}
801
}
798
 
802
 
799
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
803
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
800
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
804
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
801
 
805
 
802
void CreateNmeaRMC(void)
806
void CreateNmeaRMC(void)
803
{
807
{
804
        u8 array[200], i = 0, crc = 0, x;
808
        u8 array[200], i = 0, crc = 0, x;
805
        s16 tmp_int;
809
        s16 tmp_int;
806
        s32 tmp1, tmp2;
810
        s32 tmp1, tmp2;
807
        // +++++++++++++++++++++++++++++++++++++++++++
811
        // +++++++++++++++++++++++++++++++++++++++++++
808
        i += sprintf(array, "$GPRMC,");
812
        i += sprintf(array, "$GPRMC,");
809
        // +++++++++++++++++++++++++++++++++++++++++++
813
        // +++++++++++++++++++++++++++++++++++++++++++
810
        if(SystemTime.Valid)
814
        if(SystemTime.Valid)
811
        {
815
        {
812
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
816
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
813
        }
817
        }
814
        else
818
        else
815
        {
819
        {
816
                i += sprintf(&array[i], ",");
820
                i += sprintf(&array[i], ",");
817
        }
821
        }
818
        if(GPSData.Flags & FLAG_GPSFIXOK)
822
        if(GPSData.Flags & FLAG_GPSFIXOK)
819
        {
823
        {
820
                // +++++++++++++++++++++++++++++++++++++++++++
824
                // +++++++++++++++++++++++++++++++++++++++++++
821
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
825
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
822
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
826
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
823
 
827
 
824
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
828
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
825
                tmp1 *= 6; // in Minuten
829
                tmp1 *= 6; // in Minuten
826
                tmp2 = tmp1 / 1000000L;
830
                tmp2 = tmp1 / 1000000L;
827
                i += sprintf(&array[i],"%02d", (s16)tmp2);
831
                i += sprintf(&array[i],"%02d", (s16)tmp2);
828
                tmp2 = tmp1 % 1000000L;
832
                tmp2 = tmp1 % 1000000L;
829
                tmp2 /= 100; // zwei Stellen zu viel
833
                tmp2 /= 100; // zwei Stellen zu viel
830
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
834
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
831
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
835
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
832
                else i += sprintf(&array[i],"S,");
836
                else i += sprintf(&array[i],"S,");
833
                // +++++++++++++++++++++++++++++++++++++++++++
837
                // +++++++++++++++++++++++++++++++++++++++++++
834
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
838
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
835
                i += sprintf(&array[i],"%03d", (s16)tmp1);
839
                i += sprintf(&array[i],"%03d", (s16)tmp1);
836
 
840
 
837
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
841
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
838
                tmp1 *= 6; // in Minuten
842
                tmp1 *= 6; // in Minuten
839
                tmp2 = tmp1 / 1000000L;
843
                tmp2 = tmp1 / 1000000L;
840
                i += sprintf(&array[i],"%02d", (s16)tmp2);
844
                i += sprintf(&array[i],"%02d", (s16)tmp2);
841
                tmp2 = tmp1 % 1000000L;
845
                tmp2 = tmp1 % 1000000L;
842
                tmp2 /= 100; // zwei Stellen zu viel
846
                tmp2 /= 100; // zwei Stellen zu viel
843
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
847
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
844
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
848
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
845
                else i += sprintf(&array[i],"W,");
849
                else i += sprintf(&array[i],"W,");
846
                // +++++++++++++++++++++++++++++++++++++++++++
850
                // +++++++++++++++++++++++++++++++++++++++++++
847
                tmp_int = GPSData.Speed_Ground; // in cm/sek
851
                tmp_int = GPSData.Speed_Ground; // in cm/sek
848
                tmp_int *= 90;
852
                tmp_int *= 90;
849
                tmp_int /= 463;
853
                tmp_int /= 463;
850
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
854
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
851
                // +++++++++++++++++++++++++++++++++++++++++++
855
                // +++++++++++++++++++++++++++++++++++++++++++
852
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
856
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
853
                // +++++++++++++++++++++++++++++++++++++++++++
857
                // +++++++++++++++++++++++++++++++++++++++++++
854
                if(SystemTime.Valid)
858
                if(SystemTime.Valid)
855
                {
859
                {
856
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
860
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
857
                }
861
                }
858
                else
862
                else
859
                {
863
                {
860
                        i += sprintf(&array[i], ",");
864
                        i += sprintf(&array[i], ",");
861
                }
865
                }
862
                // +++++++++++++++++++++++++++++++++++++++++++
866
                // +++++++++++++++++++++++++++++++++++++++++++
863
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
867
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
864
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
868
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
865
                // +++++++++++++++++++++++++++++++++++++++++++
869
                // +++++++++++++++++++++++++++++++++++++++++++
866
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*");
870
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*");
867
                else i += sprintf(&array[i], "A*");
871
                else i += sprintf(&array[i], "A*");
868
        }
872
        }
869
        else // kein Satfix
873
        else // kein Satfix
870
        {
874
        {
871
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
875
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
872
        }
876
        }
873
        // +++++++++++++++++++++++++++++++++++++++++++
877
        // +++++++++++++++++++++++++++++++++++++++++++
874
        //  CRC
878
        //  CRC
875
        // +++++++++++++++++++++++++++++++++++++++++++
879
        // +++++++++++++++++++++++++++++++++++++++++++
876
        for(x=1; x<i-1; x++)
880
        for(x=1; x<i-1; x++)
877
        {
881
        {
878
                crc ^= array[x];
882
                crc ^= array[x];
879
        }
883
        }
880
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
884
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
881
        // +++++++++++++++++++++++++++++++++++++++++++
885
        // +++++++++++++++++++++++++++++++++++++++++++
882
        AddSerialData(&UART1_tx_buffer,array,i);
886
        AddSerialData(&UART1_tx_buffer,array,i);
883
        // +++++++++++++++++++++++++++++++++++++++++++
887
        // +++++++++++++++++++++++++++++++++++++++++++
884
/*
888
/*
885
 
889
 
886
 
890
 
887
 
891
 
888
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
892
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
889
                GPSData.NumOfSats =                     UbxSol.numSV;
893
                GPSData.NumOfSats =                     UbxSol.numSV;
890
                GPSData.SatFix =                                UbxSol.GPSfix;
894
                GPSData.SatFix =                                UbxSol.GPSfix;
891
                GPSData.Position_Accuracy =             UbxSol.PAcc;
895
                GPSData.Position_Accuracy =             UbxSol.PAcc;
892
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
896
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
893
                SetGPSTime(&SystemTime); // update system time
897
                SetGPSTime(&SystemTime); // update system time
894
                // NAV POSLLH
898
                // NAV POSLLH
895
                GPSData.Position.Status =               INVALID;
899
                GPSData.Position.Status =               INVALID;
896
                GPSData.Position.Longitude =    UbxPosLlh.LON;
900
                GPSData.Position.Longitude =    UbxPosLlh.LON;
897
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
901
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
898
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
902
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
899
                GPSData.Position.Status =               NEWDATA;
903
                GPSData.Position.Status =               NEWDATA;
900
                // NAV VELNED
904
                // NAV VELNED
901
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
905
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
902
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
906
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
903
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
907
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
904
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
908
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
905
                GPSData.Heading =                               UbxVelNed.Heading;
909
                GPSData.Heading =                               UbxVelNed.Heading;
906
                SystemTime.Year = 0;
910
                SystemTime.Year = 0;
907
                SystemTime.Month = 0;
911
                SystemTime.Month = 0;
908
                SystemTime.Day = 0;
912
                SystemTime.Day = 0;
909
                SystemTime.Hour = 0;
913
                SystemTime.Hour = 0;
910
                SystemTime.Min = 0;
914
                SystemTime.Min = 0;
911
                SystemTime.Sec = 0;
915
                SystemTime.Sec = 0;
912
                SystemTime.mSec = 0;
916
                SystemTime.mSec = 0;
913
                SystemTime.Valid = 0;
917
                SystemTime.Valid = 0;
914
 
918
 
915
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
919
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
916
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
920
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
917
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
921
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
918
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
922
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
919
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
923
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
920
 
924
 
921
 
925
 
922
 
926
 
923
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
927
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
924
                        i1 *= 100;
928
                        i1 *= 100;
925
                        i1 += i2 / 100000;
929
                        i1 += i2 / 100000;
926
                        i2  = i2 % 100000;
930
                        i2  = i2 % 100000;
927
                        i2 /= 10;
931
                        i2 /= 10;
928
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
932
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
929
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
933
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
930
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
934
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
931
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
935
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
932
                        break;
936
                        break;
933
                case 1:
937
                case 1:
934
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
938
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
935
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
939
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
936
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
940
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
937
                        //-----------------------------
941
                        //-----------------------------
938
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
942
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
939
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
943
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
940
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
944
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
941
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
945
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
942
 
946
 
943
*/
947
*/
944
}
948
}
945
 
949
 
946
 
950
 
947
/**************************************************************/
951
/**************************************************************/
948
/* Send the answers to incomming commands at the debug uart   */
952
/* Send the answers to incomming commands at the debug uart   */
949
/**************************************************************/
953
/**************************************************************/
950
void UART1_TransmitTxData(void)
954
void UART1_TransmitTxData(void)
951
{
955
{
952
static u8 motorindex1 = 255, motorindex2 = 0;
956
static u8 motorindex1 = 255, motorindex2 = 0;
953
        if(DebugUART != UART1) return;
957
        if(DebugUART != UART1) return;
954
 
958
 
955
        if(CheckDelay(UART1_AboTimeOut))
959
        if(CheckDelay(UART1_AboTimeOut))
956
        {
960
        {
957
                UART1_DebugData_Interval = 0;
961
                UART1_DebugData_Interval = 0;
958
                UART1_NaviData_Interval = 0;
962
                UART1_NaviData_Interval = 0;
959
                UART1_Data3D_Interval = 0;
963
                UART1_Data3D_Interval = 0;
960
                UART1_Display_Interval = 0;
964
                UART1_Display_Interval = 0;
961
                UART1_MotorData_Interval = 0;
965
                UART1_MotorData_Interval = 0;
962
        }
966
        }
963
 
967
 
964
        UART1_Transmit(); // output pending bytes in tx buffer
968
        UART1_Transmit(); // output pending bytes in tx buffer
965
        if((UART1_tx_buffer.Locked == TRUE)) return;
969
        if((UART1_tx_buffer.Locked == TRUE)) return;
966
 
970
 
967
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
971
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
968
        {
972
        {
969
                s16 ParamValue;
973
                s16 ParamValue;
970
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
974
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
971
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
975
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
972
                UART1_Request_Parameter = FALSE;
976
                UART1_Request_Parameter = FALSE;
973
        }
977
        }
974
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
978
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
975
        {
979
        {
976
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
980
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
977
                Echo = 0; // reset echo value
981
                Echo = 0; // reset echo value
978
                UART1_Request_Echo = FALSE;
982
                UART1_Request_Echo = FALSE;
979
        }
983
        }
980
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
984
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
981
        {
985
        {
982
                u8 errorcode = FTP_ERROR_NONE;
986
                u8 errorcode = FTP_ERROR_NONE;
983
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
987
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
984
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
988
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
985
 
989
 
986
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
990
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
987
                else
991
                else
988
                {
992
                {
989
                        u8 cmd = FTP_CMD_ERROR;
993
                        u8 cmd = FTP_CMD_ERROR;
990
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
994
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
991
                }
995
                }
992
 
996
 
993
                UART1_Request_FTP = FALSE;
997
                UART1_Request_FTP = FALSE;
994
        }
998
        }
995
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
999
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
996
        {
1000
        {
997
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
1001
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
998
                UART1_Request_WritePoint = 0xFF;
1002
                UART1_Request_WritePoint = 0xFF;
999
        }
1003
        }
1000
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
1004
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
1001
        {
1005
        {
1002
                u8 PointCount = PointList_GetCount();
1006
                u8 PointCount = PointList_GetCount();
1003
                if (UART1_Request_ReadPoint <= PointCount)
1007
                if (UART1_Request_ReadPoint <= PointCount)
1004
                {
1008
                {
1005
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
1009
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
1006
                }
1010
                }
1007
                else
1011
                else
1008
                {
1012
                {
1009
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
1013
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
1010
                }
1014
                }
1011
                UART1_Request_ReadPoint = 0;
1015
                UART1_Request_ReadPoint = 0;
1012
        }
1016
        }
1013
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1017
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1014
        {
1018
        {
1015
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
1019
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
1016
                UART1_Request_DebugLabel = 0xFF;
1020
                UART1_Request_DebugLabel = 0xFF;
1017
        }
1021
        }
1018
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1022
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1019
        {
1023
        {
1020
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
1024
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
1021
                UART1_ExternalControlConfirmFrame = 0;
1025
                UART1_ExternalControlConfirmFrame = 0;
1022
        }
1026
        }
1023
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
1027
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
1024
        {
1028
        {
1025
                NaviData.Errorcode = ErrorCode;
1029
                NaviData.Errorcode = ErrorCode;
1026
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
1030
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
1027
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1031
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1028
                UART1_Request_NaviData = FALSE;
1032
                UART1_Request_NaviData = FALSE;
1029
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1033
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1030
        }
1034
        }
1031
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1035
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1032
        {
1036
        {
1033
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1037
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1034
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1038
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1035
                UART1_Request_DebugData = FALSE;
1039
                UART1_Request_DebugData = FALSE;
1036
        }
1040
        }
1037
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1041
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1038
        {
1042
        {
1039
                Data3D.StickNick = FC.StickNick;
1043
                Data3D.StickNick = FC.StickNick;
1040
                Data3D.StickRoll = FC.StickRoll;
1044
                Data3D.StickRoll = FC.StickRoll;
1041
        Data3D.StickYaw = FC.StickYaw;
1045
        Data3D.StickYaw = FC.StickYaw;
1042
        Data3D.StickGas = FC.StickGas;
1046
        Data3D.StickGas = FC.StickGas;
1043
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1047
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1044
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1048
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1045
                UART1_Request_Data3D = FALSE;
1049
                UART1_Request_Data3D = FALSE;
1046
        }
1050
        }
1047
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1051
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1048
        {
1052
        {
1049
                do
1053
                do
1050
                {
1054
                {
1051
                 motorindex1++;
1055
                 motorindex1++;
1052
                 motorindex1%=12;
1056
                 motorindex1%=12;
1053
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1057
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1054
                 if(motorindex1 == motorindex2) break;
1058
                 if(motorindex1 == motorindex2) break;
1055
                }
1059
                }
1056
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1060
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1057
 
1061
 
1058
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1062
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1059
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1063
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1060
                UART1_Request_MotorData = FALSE;
1064
                UART1_Request_MotorData = FALSE;
1061
        }
1065
        }
1062
        else if(UART1_Request_WPLStore)
1066
        else if(UART1_Request_WPLStore)
1063
        {
1067
        {
1064
                /*
1068
                /*
1065
                s8 txt[50];
1069
                s8 txt[50];
1066
                sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n",  WPL_Store.OverwriteFile,  WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status);
1070
                sprintf(txt, "\r\nWPL Overwride = %d, Type = %d, Index = %d, Status = %d\r\n",  WPL_Store.OverwriteFile,  WPL_Store.Type, WPL_Answer.Index, WPL_Answer.Status);
1067
                UART1_PutString(txt);
1071
                UART1_PutString(txt);
1068
                */
1072
                */
1069
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1073
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1070
                UART1_Request_WPLStore = FALSE;                
1074
                UART1_Request_WPLStore = FALSE;                
1071
        }
1075
        }
1072
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1076
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1073
        {
1077
        {
1074
                CreateNmeaGGA();
1078
                CreateNmeaGGA();
1075
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1079
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1076
                NMEA_Timer = SetDelay(NMEA_Interval);
1080
                NMEA_Timer = SetDelay(NMEA_Interval);
1077
        }
1081
        }
1078
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1082
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1079
        {
1083
        {
1080
          CreateNmeaRMC();
1084
          CreateNmeaRMC();
1081
          Send_NMEA_RMC = FALSE;
1085
          Send_NMEA_RMC = FALSE;
1082
        }
1086
        }
1083
 
1087
 
1084
        /*
1088
        /*
1085
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1089
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1086
        {
1090
        {
1087
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1091
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1088
                UART1_ConfirmFrame = 0;
1092
                UART1_ConfirmFrame = 0;
1089
        }
1093
        }
1090
        */
1094
        */
1091
        /*
1095
        /*
1092
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1096
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1093
        {
1097
        {
1094
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1098
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1095
                UART1_Request_ExternalControl = FALSE;
1099
                UART1_Request_ExternalControl = FALSE;
1096
        }
1100
        }
1097
        */
1101
        */
1098
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1102
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1099
        {
1103
        {
1100
                if(UART1_DisplayLine > 3)
1104
                if(UART1_DisplayLine > 3)
1101
                {
1105
                {
1102
                        Menu_Update(UART1_DisplayKeys);
1106
                        Menu_Update(UART1_DisplayKeys);
1103
                        UART1_DisplayKeys = 0;
1107
                        UART1_DisplayKeys = 0;
1104
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1108
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1105
                }
1109
                }
1106
                else
1110
                else
1107
                {
1111
                {
1108
                        UART1_DisplayLine = 2;
1112
                        UART1_DisplayLine = 2;
1109
                        sprintf(text,"!!! incompatible !!!");
1113
                        sprintf(text,"!!! incompatible !!!");
1110
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1114
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1111
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1115
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1112
                }
1116
                }
1113
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1117
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1114
                UART1_Request_Display = FALSE;
1118
                UART1_Request_Display = FALSE;
1115
        }
1119
        }
1116
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1120
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1117
        {
1121
        {
1118
                Menu_Update(0);
1122
                Menu_Update(0);
1119
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1123
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1120
                UART1_Request_Display1 = FALSE;
1124
                UART1_Request_Display1 = FALSE;
1121
        }
1125
        }
1122
        else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions
1126
        else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions
1123
        {
1127
        {
1124
                UART_VersionInfo_t version_tmp;
1128
                UART_VersionInfo_t version_tmp;
1125
                version_tmp.SWMajor = FC_Version.Major;
1129
                version_tmp.SWMajor = FC_Version.Major;
1126
                version_tmp.SWMinor = FC_Version.Minor;
1130
                version_tmp.SWMinor = FC_Version.Minor;
1127
                version_tmp.SWPatch = FC_Version.Patch;
1131
                version_tmp.SWPatch = FC_Version.Patch;
1128
                version_tmp.HWMajor = FC_Version.Hardware;
1132
                version_tmp.HWMajor = FC_Version.Hardware;
1129
                version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version 
1133
                version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version 
1130
                version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version 
1134
                version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version 
1131
                version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor;
1135
                version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor;
1132
                version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware;
1136
                version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware;
1133
                version_tmp.Flags = 0;
1137
                version_tmp.Flags = 0;
1134
                version_tmp.Reserved1 = 0;
1138
                version_tmp.Reserved1 = 0;
1135
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp));
1139
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp));
1136
                UART1_Request_VersionInfo = FALSE;
1140
                UART1_Request_VersionInfo = FALSE;
1137
        }
1141
        }
1138
        else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions
1142
        else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions
1139
        {
1143
        {
1140
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1144
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1141
                UART1_Request_VersionInfo = FALSE;
1145
                UART1_Request_VersionInfo = FALSE;
1142
        }
1146
        }
1143
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1147
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1144
        {
1148
        {
1145
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1149
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1146
                UART1_Request_SystemTime = FALSE;
1150
                UART1_Request_SystemTime = FALSE;
1147
        }
1151
        }
1148
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1152
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1149
        {
1153
        {
1150
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1154
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1151
                UART1_Request_ErrorMessage = FALSE;
1155
                UART1_Request_ErrorMessage = FALSE;
1152
        }
1156
        }
1153
        else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE))
1157
        else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE))
1154
        {
1158
        {
1155
                u8 result = 1, cmd = 0;
1159
                u8 result = 1, cmd = 0;
1156
                if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE)  
1160
                if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE)  
1157
                {
1161
                {
1158
                  result = LIC_CMD_READ_LICENSE;
1162
                  result = LIC_CMD_READ_LICENSE;
1159
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE);
1163
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE);
1160
                }
1164
                }
1161
                else
1165
                else
1162
                if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1166
                if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1163
                 {
1167
                 {
1164
                  result = LIC_CMD_ERASE_LICENSE;
1168
                  result = LIC_CMD_ERASE_LICENSE;
1165
                  DeleteLicenseInEEPROM();
1169
                  DeleteLicenseInEEPROM();
1166
                  CheckLicense(GET_LICENSE);
1170
                  CheckLicense(GET_LICENSE);
1167
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1);
1171
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1);
1168
                 }
1172
                 }
1169
                else
1173
                else
1170
                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1174
                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1171
                {
1175
                {
1172
                  cmd = LIC_CMD_WRITE_LICENSE;
1176
                  cmd = LIC_CMD_WRITE_LICENSE;
1173
                  if(CheckLicense(CHECK_ONLY))  //new license is okay
1177
                  if(CheckLicense(CHECK_ONLY))  //new license is okay
1174
                  {
1178
                  {
1175
                   WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL);
1179
                   WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL);
1176
                   result = 1;
1180
                   result = 1;
1177
                  }
1181
                  }
1178
                  else //new license is NOT okay
1182
                  else //new license is NOT okay
1179
                  {
1183
                  {
1180
                   ClearLicenseText();
1184
                   ClearLicenseText();
1181
                   result = 0;
1185
                   result = 0;
1182
                   CheckLicense(GET_LICENSE);  // fetch a license if available
1186
                   CheckLicense(GET_LICENSE);  // fetch a license if available
1183
                  }
1187
                  }
1184
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 );
1188
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 );
1185
                }
1189
                }
1186
                UART1_Request_LicenseString = 0;
1190
                UART1_Request_LicenseString = 0;
1187
        }
1191
        }
1188
#ifdef FOLLOW_ME
1192
#ifdef FOLLOW_ME
1189
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1193
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1190
        {
1194
        {
1191
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1195
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1192
                {
1196
                {
1193
                        TransmitAlsoToFC = 1;
1197
                        TransmitAlsoToFC = 1;
1194
                        // update FollowMe content
1198
                        // update FollowMe content
1195
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1199
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1196
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1200
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1197
                        FollowMe.Position.Status = NEWDATA;
1201
                        FollowMe.Position.Status = NEWDATA;
1198
                        FollowMe.Position.Altitude = 1;
1202
                        FollowMe.Position.Altitude = 1;
1199
                        // 0  -> no Orientation
1203
                        // 0  -> no Orientation
1200
                        // 1-360 -> CompassCourse Setpoint
1204
                        // 1-360 -> CompassCourse Setpoint
1201
                        // -1 -> points to  WP1 -> itself
1205
                        // -1 -> points to  WP1 -> itself
1202
                FollowMe.Heading = -1;
1206
                FollowMe.Heading = -1;
1203
                        FollowMe.ToleranceRadius = 1;
1207
                        FollowMe.ToleranceRadius = 1;
1204
                        FollowMe.HoldTime = 60;
1208
                        FollowMe.HoldTime = 60;
1205
                        FollowMe.Event_Flag = 1;
1209
                        FollowMe.Event_Flag = 1;
1206
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1210
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1207
                        FollowMe.Type = POINT_TYPE_WP;
1211
                        FollowMe.Type = POINT_TYPE_WP;
1208
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1212
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1209
                        FollowMe.AltitudeRate = 0;                        // do not change height
1213
                        FollowMe.AltitudeRate = 0;                        // do not change height
1210
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1214
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1211
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1215
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1212
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1216
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1213
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1217
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1214
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1218
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1215
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1219
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1216
                        FollowMe.reserve[0] = 0;                // reserve
1220
                        FollowMe.reserve[0] = 0;                // reserve
1217
                        FollowMe.reserve[1] = 0;                // reserve
1221
                        FollowMe.reserve[1] = 0;                // reserve
1218
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1222
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1219
                }
1223
                }
1220
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1224
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1221
        }
1225
        }
1222
#endif
1226
#endif
1223
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1227
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1224
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1228
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1225
        {
1229
        {
1226
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1230
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1227
                SendDebugOutput = 0;
1231
                SendDebugOutput = 0;
1228
        }
1232
        }
1229
#endif
1233
#endif
1230
        UART1_Transmit(); // output pending bytes in tx buffer
1234
        UART1_Transmit(); // output pending bytes in tx buffer
1231
}
1235
}
1232
 
1236
 
1233
 
1237