Subversion Repositories NaviCtrl

Rev

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

Rev 689 Rev 694
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 "crc16.h"
83
#include "crc16.h"
84
#include "eeprom.h"
84
#include "eeprom.h"
85
 
85
 
86
#define LIC_CMD_READ_LICENSE     1
86
#define LIC_CMD_READ_LICENSE     1
87
#define LIC_CMD_WRITE_LICENSE    2
87
#define LIC_CMD_WRITE_LICENSE    2
88
#define LIC_CMD_ERASE_LICENSE    3
88
#define LIC_CMD_ERASE_LICENSE    3
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
NaviData_Volatile_t NaviData_Volatile;
96
NaviData_Volatile_t NaviData_Volatile;
97
NaviData_WP_t NaviData_WP;
97
NaviData_WP_t NaviData_WP;
98
NaviData_Deviation_t NaviData_Deviation;
98
NaviData_Deviation_t NaviData_Deviation;
99
NaviData_Home_t NaviData_Home;
99
NaviData_Home_t NaviData_Home;
100
NaviData_Target_t NaviData_Target;
100
NaviData_Target_t NaviData_Target;
101
NaviData_Flags_t NaviData_Flags;
101
NaviData_Flags_t NaviData_Flags;
102
NaviData_Tiny_t NaviData_Tiny;
102
NaviData_Tiny_t NaviData_Tiny;
103
NaviData_Pos_t NaviData_Failsafe;
103
NaviData_Pos_t NaviData_Failsafe;
104
NaviData_Out_t NaviData_Out1Trigger;
104
NaviData_Out_t NaviData_Out1Trigger;
105
NaviData_t NaviData;
105
NaviData_t NaviData;
106
 
106
 
107
u8 UART1_Request_VersionInfo    = FALSE;
107
u8 UART1_Request_VersionInfo    = FALSE;
108
u8 UART1_Request_ExternalControl= FALSE;
108
u8 UART1_Request_ExternalControl= FALSE;
109
u8 UART1_Request_Display                = FALSE;
109
u8 UART1_Request_Display                = FALSE;
110
u8 UART1_Request_Display1               = FALSE;
110
u8 UART1_Request_Display1               = FALSE;
111
u8 UART1_Request_DebugData              = FALSE;
111
u8 UART1_Request_DebugData              = FALSE;
112
u8 UART1_Request_DebugLabel             = 255;
112
u8 UART1_Request_DebugLabel             = 255;
113
u8 UART1_Request_NaviData               = FALSE;
113
u8 UART1_Request_NaviData               = FALSE;
114
u8 UART1_Request_ErrorMessage   = FALSE;
114
u8 UART1_Request_ErrorMessage   = FALSE;
115
u8 UART1_Request_WritePoint             = 0xFF;
115
u8 UART1_Request_WritePoint             = 0xFF;
116
u8 UART1_Request_ReadPoint              = 0;
116
u8 UART1_Request_ReadPoint              = 0;
117
u8 UART1_Request_Data3D             = FALSE;
117
u8 UART1_Request_Data3D             = FALSE;
118
u8 UART1_Request_MotorData          = FALSE;
118
u8 UART1_Request_MotorData          = FALSE;
119
u8 UART1_Request_Echo               = FALSE;
119
u8 UART1_Request_Echo               = FALSE;
120
u8 UART1_Request_ParameterId    = 0;
120
u8 UART1_Request_ParameterId    = 0;
121
u8 UART1_Request_WPLStore               = FALSE;
121
u8 UART1_Request_WPLStore               = FALSE;
122
u8 UART1_Request_Parameter              = FALSE;
122
u8 UART1_Request_Parameter              = FALSE;
123
u8 UART1_Request_SystemTime             = FALSE;
123
u8 UART1_Request_SystemTime             = FALSE;
124
u8 UART1_DisplayKeys                    = 0;
124
u8 UART1_DisplayKeys                    = 0;
125
u8 UART1_DisplayLine                    = 0;
125
u8 UART1_DisplayLine                    = 0;
126
u8 UART1_ConfirmFrame                   = 0;
126
u8 UART1_ConfirmFrame                   = 0;
127
u8 UART1_Request_FTP                    = FALSE;
127
u8 UART1_Request_FTP                    = FALSE;
128
u8 UART1_Request_LicenseString  = FALSE;
128
u8 UART1_Request_LicenseString  = FALSE;
129
u8 UART1_Request_PPM_Channels   = FALSE;
129
u8 UART1_Request_PPM_Channels   = FALSE;
130
u8 LastTransmittedFCStatusFlags2 = 0;
130
u8 LastTransmittedFCStatusFlags2 = 0;
131
u8 UART1_ExternalControlConfirmFrame = FALSE;
131
u8 UART1_ExternalControlConfirmFrame = FALSE;
132
u8 Send_NMEA_RMC = FALSE;
132
u8 Send_NMEA_RMC = FALSE;
133
u8 NaviData_Flags_SpeakHoTT_Processed = 0;
133
u8 NaviData_Flags_SpeakHoTT_Processed = 0;
134
u8 NewExternalControlFrame = 0; // flag that sends the Frame to FC
134
u8 NewExternalControlFrame = 0; // flag that sends the Frame to FC
135
 
135
 
136
SerialChannel_t SerialChannel;
136
SerialChannel_t SerialChannel;
137
u8 NewSerialChannelFrame = 0; // flag that sends the Frame to FC
137
u8 NewSerialChannelFrame = 0; // flag that sends the Frame to FC
138
 
138
 
139
UART_TypeDef *DebugUART = UART1;
139
UART_TypeDef *DebugUART = UART1;
140
 
140
 
141
#ifdef FOLLOW_ME
141
#ifdef FOLLOW_ME
142
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
142
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
143
u32 UART1_FollowMe_Timer        = 0;
143
u32 UART1_FollowMe_Timer        = 0;
144
Point_t FollowMe;
144
Point_t FollowMe;
145
#endif
145
#endif
146
 
146
 
147
// the primary rx fifo
147
// the primary rx fifo
148
#define UART1_RX_FIFO_LEN 1500
148
#define UART1_RX_FIFO_LEN 1500
149
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
149
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
150
fifo_t UART1_rx_fifo;
150
fifo_t UART1_rx_fifo;
151
 
151
 
152
// the rx buffer
152
// the rx buffer
153
#define UART1_RX_BUFFER_LEN 1500
153
#define UART1_RX_BUFFER_LEN 1500
154
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
154
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
155
Buffer_t UART1_rx_buffer;
155
Buffer_t UART1_rx_buffer;
156
 
156
 
157
// the tx buffer
157
// the tx buffer
158
//#define UART1_TX_BUFFER_LEN 1024
158
//#define UART1_TX_BUFFER_LEN 1024
159
#define UART1_TX_BUFFER_LEN 1500
159
#define UART1_TX_BUFFER_LEN 1500
160
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
160
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
161
Buffer_t UART1_tx_buffer;
161
Buffer_t UART1_tx_buffer;
162
 
162
 
163
volatile u8 SerialLinkOkay = 0;
163
volatile u8 SerialLinkOkay = 0;
164
 
164
 
165
u8 text[200];
165
u8 text[200];
166
u8 *LicensePtr = UART1_tbuffer;
166
u8 *LicensePtr = UART1_tbuffer;
167
 
167
 
168
const u8 ANALOG_LABEL[32][16] =
168
const u8 ANALOG_LABEL[32][16] =
169
{
169
{
170
   //1234567890123456
170
   //1234567890123456
171
        "AngleNick       ", //0
171
        "AngleNick       ", //0
172
        "AngleRoll       ",
172
        "AngleRoll       ",
173
        "AccNick         ",
173
        "AccNick         ",
174
        "AccRoll         ",
174
        "AccRoll         ",
175
        "Altitude [0.1m] ",
175
        "Altitude [0.1m] ",
176
        "FC-Flags        ", //5
176
        "FC-Flags        ", //5
177
        "NC-Flags        ",
177
        "NC-Flags        ",
178
        "Voltage  [0.1V] ",
178
        "Voltage  [0.1V] ",
179
        "Current  [0.1A] ",
179
        "Current  [0.1A] ",
180
        "GPS Data        ",
180
        "GPS Data        ",
181
        "CompassHeading  ", //10
181
        "CompassHeading  ", //10
182
        "GyroHeading     ",
182
        "GyroHeading     ",
183
        "SPI Error       ", // achtung: muss auf 12 bleiben
183
        "SPI Error       ", // achtung: muss auf 12 bleiben
184
        "GPS CRC Error   ",
184
        "GPS CRC Error   ",
185
        "I2C Error       ",
185
        "I2C Error       ",
186
        "I2C Okay        ", //15
186
        "I2C Okay        ", //15
187
        "16              ",
187
        "16              ",
188
        "17              ",
188
        "17              ",
189
        "18              ",
189
        "18              ",
190
        "19              ", // SD-Card-time
190
        "19              ", // SD-Card-time
191
        "EarthMagnet [%] ", //20
191
        "EarthMagnet [%] ", //20
192
        "Ground Speed    ", //  "Z_Speed         ",
192
        "Ground Speed    ", //  "Z_Speed         ",
193
        "N_Speed         ",
193
        "N_Speed         ",
194
        "E_Speed         ",
194
        "E_Speed         ",
195
        "Magnet X        ",
195
        "Magnet X        ",
196
        "Magnet Y        ", //25
196
        "Magnet Y        ", //25
197
        "Magnet Z        ",
197
        "Magnet Z        ",
198
        "Distance N      ",
198
        "Distance N      ",
199
        "Distance E      ",
199
        "Distance E      ",
200
        "-GPS_Nick       ",
200
        "-GPS_Nick       ",
201
        "-GPS_Roll       ", //30
201
        "-GPS_Roll       ", //30
202
        "Used_Sats       "
202
        "Used_Sats       "
203
};
203
};
204
 
204
 
205
typedef struct
205
typedef struct
206
{
206
{
207
        u8 Index;
207
        u8 Index;
208
        u8 Status;
208
        u8 Status;
209
} __attribute__((packed)) WPL_Answer_t;
209
} __attribute__((packed)) WPL_Answer_t;
210
WPL_Answer_t WPL_Answer;
210
WPL_Answer_t WPL_Answer;
211
 
211
 
212
DebugOut_t DebugOut;
212
DebugOut_t DebugOut;
213
ExternControl_t ExternControl;
213
ExternControl_t ExternControl;
214
UART_VersionInfo_t UART_VersionInfo;
214
UART_VersionInfo_t UART_VersionInfo;
215
NaviData_t NaviData;
215
NaviData_t NaviData;
216
Data3D_t Data3D;
216
Data3D_t Data3D;
217
 
217
 
218
u16 Echo; // 2 bytes recieved will be sent back as echo
218
u16 Echo; // 2 bytes recieved will be sent back as echo
219
 
219
 
220
u32 UART1_DebugData_Timer = 0;
220
u32 UART1_DebugData_Timer = 0;
221
u32 UART1_DebugData_Interval = 0;       // in ms
221
u32 UART1_DebugData_Interval = 0;       // in ms
222
u32 UART1_NaviData_Timer = 0;
222
u32 UART1_NaviData_Timer = 0;
223
u32 UART1_NaviData_Interval = 0;        // in ms
223
u32 UART1_NaviData_Interval = 0;        // in ms
224
u16 UART1_NaviData_MaxBytes = 0;                // newer protocol?
224
u16 UART1_NaviData_MaxBytes = 0;                // newer protocol?
225
u32 UART1_Data3D_Timer = 0;
225
u32 UART1_Data3D_Timer = 0;
226
u32 UART1_Data3D_Interval = 0;          // in ms
226
u32 UART1_Data3D_Interval = 0;          // in ms
227
u32 UART1_MotorData_Timer = 0;
227
u32 UART1_MotorData_Timer = 0;
228
u32 UART1_MotorData_Interval = 0;               // in ms
228
u32 UART1_MotorData_Interval = 0;               // in ms
229
u32 UART1_Display_Timer = 0;
229
u32 UART1_Display_Timer = 0;
230
u32 UART1_Display_Interval = 0;         // in ms
230
u32 UART1_Display_Interval = 0;         // in ms
231
u32 NMEA_Timer = 0;
231
u32 NMEA_Timer = 0;
232
u32 NMEA_Interval = 0;// in ms
232
u32 NMEA_Interval = 0;// in ms
233
 
233
 
234
u8 CalculateDebugLableCrc(void)
234
u8 CalculateDebugLableCrc(void)
235
{
235
{
236
        u16 i;
236
        u16 i;
237
        u8 crc = 0;
237
        u8 crc = 0;
238
        for(i=0;i<sizeof(ANALOG_LABEL);i++) crc += ANALOG_LABEL[0][i];
238
        for(i=0;i<sizeof(ANALOG_LABEL);i++) crc += ANALOG_LABEL[0][i];
239
        return(crc);
239
        return(crc);
240
}
240
}
241
 
241
 
242
/********************************************************/
242
/********************************************************/
243
/*            Initialization the UART1                  */
243
/*            Initialization the UART1                  */
244
/********************************************************/
244
/********************************************************/
245
void UART1_Init (void)
245
void UART1_Init (void)
246
{
246
{
247
        GPIO_InitTypeDef GPIO_InitStructure;
247
        GPIO_InitTypeDef GPIO_InitStructure;
248
        UART_InitTypeDef UART_InitStructure;
248
        UART_InitTypeDef UART_InitStructure;
249
 
249
 
250
        // initialize txd buffer
250
        // initialize txd buffer
251
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
251
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
252
 
252
 
253
        // initialize rxd buffer
253
        // initialize rxd buffer
254
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
254
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
255
 
255
 
256
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
256
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
257
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
257
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
258
 
258
 
259
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
259
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
260
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
260
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
261
 
261
 
262
        /*Configure UART1_Rx pin GPIO3.2*/
262
        /*Configure UART1_Rx pin GPIO3.2*/
263
        GPIO_StructInit(&GPIO_InitStructure);
263
        GPIO_StructInit(&GPIO_InitStructure);
264
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
264
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
265
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
265
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
266
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
266
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
267
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
267
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
268
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
268
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
269
        GPIO_Init(GPIO3, &GPIO_InitStructure);
269
        GPIO_Init(GPIO3, &GPIO_InitStructure);
270
 
270
 
271
        /*Configure UART1_Tx pin GPIO3.3*/
271
        /*Configure UART1_Tx pin GPIO3.3*/
272
        GPIO_StructInit(&GPIO_InitStructure);
272
        GPIO_StructInit(&GPIO_InitStructure);
273
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
273
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
274
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
274
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
275
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
275
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
276
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
276
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
277
        GPIO_Init(GPIO3, &GPIO_InitStructure);
277
        GPIO_Init(GPIO3, &GPIO_InitStructure);
278
 
278
 
279
// Control of PORT3.7 (FC-UART)
279
// Control of PORT3.7 (FC-UART)
280
        GPIO_StructInit(&GPIO_InitStructure);
280
        GPIO_StructInit(&GPIO_InitStructure);
281
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
281
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
282
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_7;
282
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_7;
283
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
283
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
284
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt1;
284
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt1;
285
        GPIO_Init(GPIO3, &GPIO_InitStructure);
285
        GPIO_Init(GPIO3, &GPIO_InitStructure);
286
DISABLE_FC_UART;
286
DISABLE_FC_UART;
287
 
287
 
288
        /* UART1 configured as follow:
288
        /* UART1 configured as follow:
289
        - Word Length = 8 Bits
289
        - Word Length = 8 Bits
290
        - One Stop Bit
290
        - One Stop Bit
291
        - No parity
291
        - No parity
292
        - BaudRate = 57600 baud
292
        - BaudRate = 57600 baud
293
        - Hardware flow control Disabled
293
        - Hardware flow control Disabled
294
        - Receive and transmit enabled
294
        - Receive and transmit enabled
295
        - Receive and transmit FIFOs are Disabled
295
        - Receive and transmit FIFOs are Disabled
296
        */
296
        */
297
        UART_StructInit(&UART_InitStructure);
297
        UART_StructInit(&UART_InitStructure);
298
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
298
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
299
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
299
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
300
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
300
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
301
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
301
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
302
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
302
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
303
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
303
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
304
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
304
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
305
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
305
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
306
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
306
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
307
 
307
 
308
        UART_DeInit(UART1); // reset uart 1     to default
308
        UART_DeInit(UART1); // reset uart 1     to default
309
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
309
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
310
        // enable uart 1 interrupts selective
310
        // enable uart 1 interrupts selective
311
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
311
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
312
        UART_Cmd(UART1, ENABLE); // enable uart 1
312
        UART_Cmd(UART1, ENABLE); // enable uart 1
313
        // configure the uart 1 interupt line
313
        // configure the uart 1 interupt line
314
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
314
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
315
        // enable the uart 1 IRQ
315
        // enable the uart 1 IRQ
316
        VIC_ITCmd(UART1_ITLine, ENABLE);
316
        VIC_ITCmd(UART1_ITLine, ENABLE);
317
 
317
 
318
        // initialize the debug timer
318
        // initialize the debug timer
319
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
319
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
320
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
320
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
321
        NMEA_Timer = SetDelay(14000);
321
        NMEA_Timer = SetDelay(14000);
322
 
322
 
323
        // Fill Version Info Structure
323
        // Fill Version Info Structure
324
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
324
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
325
        UART_VersionInfo.SWMinor = VERSION_MINOR;
325
        UART_VersionInfo.SWMinor = VERSION_MINOR;
326
        UART_VersionInfo.SWPatch = VERSION_PATCH;
326
        UART_VersionInfo.SWPatch = VERSION_PATCH;
327
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
327
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
328
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
328
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
329
    UART_VersionInfo.BL_Firmware = 255;
329
    UART_VersionInfo.BL_Firmware = 255;
330
        UART_VersionInfo.Flags = 0;
330
        UART_VersionInfo.Flags = 0;
331
        UART_VersionInfo.LabelTextCRC = CalculateDebugLableCrc();
331
        UART_VersionInfo.LabelTextCRC = CalculateDebugLableCrc();
332
        NaviData.Version = NAVIDATA_VERSION;
332
        NaviData.Version = NAVIDATA_VERSION;
333
 
333
 
334
        PPM_In[PPM_IN_MAX] = +127;
334
        PPM_In[PPM_IN_MAX] = +127;
335
        PPM_In[PPM_IN_OFF] = -127;
335
        PPM_In[PPM_IN_OFF] = -127;
336
        PPM_In[PPM_IN_MID] = 0;
336
        PPM_In[PPM_IN_MID] = 0;
337
 
337
 
338
        UART1_PutString("\r\n UART1 init...ok");
338
        UART1_PutString("\r\n UART1 init...ok");
339
}
339
}
340
 
340
 
341
 
341
 
342
/****************************************************************/
342
/****************************************************************/
343
/*               USART1 receiver ISR                            */
343
/*               USART1 receiver ISR                            */
344
/****************************************************************/
344
/****************************************************************/
345
void UART1_IRQHandler(void)
345
void UART1_IRQHandler(void)
346
{
346
{
347
        static u8 abortState = 0;
347
        static u8 abortState = 0;
348
        u8 c;
348
        u8 c;
349
 
349
 
350
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
350
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
351
        {
351
        {
352
                // clear the pending bits!
352
                // clear the pending bits!
353
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
353
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
354
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
354
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
355
                // if debug UART is not UART1
355
                // if debug UART is not UART1
356
                if (DebugUART != UART1)
356
                if (DebugUART != UART1)
357
                {       // forward received data to the debug UART tx buffer
357
                {       // forward received data to the debug UART tx buffer
358
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
358
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
359
                        {
359
                        {
360
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
360
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
361
                                c = UART_ReceiveData(UART1);
361
                                c = UART_ReceiveData(UART1);
362
 
362
 
363
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
363
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
364
                                switch (abortState)
364
                                switch (abortState)
365
                                {
365
                                {
366
                                        case 0:
366
                                        case 0:
367
                                                if (c == 27) abortState++;
367
                                                if (c == 27) abortState++;
368
                                                break;
368
                                                break;
369
                                        case 1:
369
                                        case 1:
370
                                                if (c == 27) abortState++;
370
                                                if (c == 27) abortState++;
371
                                                else abortState = 0;
371
                                                else abortState = 0;
372
                                        break;
372
                                        break;
373
                                        case 2:
373
                                        case 2:
374
                                                if (c == 0x55) abortState++;
374
                                                if (c == 0x55) abortState++;
375
                                                else abortState = 0;
375
                                                else abortState = 0;
376
                                                break;
376
                                                break;
377
                                        case 3:
377
                                        case 3:
378
                                                if (c == 0xAA) abortState++;
378
                                                if (c == 0xAA) abortState++;
379
                                                else abortState = 0;
379
                                                else abortState = 0;
380
                                                break;
380
                                                break;
381
                                        case 4:
381
                                        case 4:
382
                                                if (c == 0x00)
382
                                                if (c == 0x00)
383
                                                {
383
                                                {
384
                                                        if(DebugUART == UART0)
384
                                                        if(DebugUART == UART0)
385
                                                        {
385
                                                        {
386
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
386
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
387
                                                                TIMER2_Init(); // enbable servo outputs
387
                                                                TIMER2_Init(); // enbable servo outputs
388
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
388
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
389
                                                        }
389
                                                        }
390
                                                        DebugUART = UART1;
390
                                                        DebugUART = UART1;
391
DISABLE_FC_UART;
391
DISABLE_FC_UART;
392
                                                }
392
                                                }
393
                                                abortState = 0;
393
                                                abortState = 0;
394
                                                break;
394
                                                break;
395
                                } // end switch abort state
395
                                } // end switch abort state
396
                                // if the Debug uart is not UART1, redirect input to the Debug UART
396
                                // if the Debug uart is not UART1, redirect input to the Debug UART
397
                                if (DebugUART != UART1)
397
                                if (DebugUART != UART1)
398
                                {
398
                                {
399
                                        // wait for space in the tx buffer of the DebugUART
399
                                        // wait for space in the tx buffer of the DebugUART
400
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
400
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
401
                                        // move byte to the tx fifo of the debug uart
401
                                        // move byte to the tx fifo of the debug uart
402
                                        UART_SendData(DebugUART, c);
402
                                        UART_SendData(DebugUART, c);
403
                                }
403
                                }
404
                        }
404
                        }
405
                }
405
                }
406
                else  // DebugUART == UART1 (normal operation)
406
                else  // DebugUART == UART1 (normal operation)
407
                {
407
                {
408
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
408
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
409
                        { // some byes in the hardware fifo
409
                        { // some byes in the hardware fifo
410
                            // get byte from hardware fifo
410
                            // get byte from hardware fifo
411
                        c = UART_ReceiveData(UART1);
411
                        c = UART_ReceiveData(UART1);
412
                                // put into the software fifo
412
                                // put into the software fifo
413
                                if(!fifo_put(&UART1_rx_fifo, c))
413
                                if(!fifo_put(&UART1_rx_fifo, c))
414
                                {       // fifo overflow
414
                                {       // fifo overflow
415
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
415
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
416
                                }
416
                                }
417
                        } // EOF while some byes in the hardware fifo
417
                        } // EOF while some byes in the hardware fifo
418
                } // eof DebugUart = UART1
418
                } // eof DebugUart = UART1
419
        }
419
        }
420
 
420
 
421
 
421
 
422
 
422
 
423
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
423
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
424
}
424
}
425
 
425
 
426
/**************************************************************/
426
/**************************************************************/
427
/* Process incomming data from debug uart                     */
427
/* Process incomming data from debug uart                     */
428
/**************************************************************/
428
/**************************************************************/
429
void UART1_ProcessRxData(void)
429
void UART1_ProcessRxData(void)
430
{
430
{
431
        // return on forwarding uart  or unlocked rx buffer
431
        // return on forwarding uart  or unlocked rx buffer
432
        u8 c;
432
        u8 c;
433
        if(DebugUART != UART1) return;
433
        if(DebugUART != UART1) return;
434
        // if rx buffer is not locked
434
        // if rx buffer is not locked
435
        if(UART1_rx_buffer.Locked == FALSE)
435
        if(UART1_rx_buffer.Locked == FALSE)
436
        {
436
        {
437
                //collect data from primary rx fifo
437
                //collect data from primary rx fifo
438
                while(fifo_get(&UART1_rx_fifo, &c))
438
                while(fifo_get(&UART1_rx_fifo, &c))
439
                {
439
                {
440
                        // break if complete frame is collected
440
                        // break if complete frame is collected
441
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
441
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
442
                }
442
                }
443
        }
443
        }
444
        if(UART1_rx_buffer.Locked == FALSE) return;
444
        if(UART1_rx_buffer.Locked == FALSE) return;
445
 
445
 
446
        Point_t * pPoint = NULL;
446
        Point_t * pPoint = NULL;
447
        SerialMsg_t SerialMsg;
447
        SerialMsg_t SerialMsg;
448
 
448
 
449
        // analyze header first
449
        // analyze header first
450
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
450
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
451
/*
451
/*
452
        if( SerialMsg.Address == FC_ADDRESS )
452
        if( SerialMsg.Address == FC_ADDRESS )
453
        {
453
        {
454
                switch(SerialMsg.CmdID)
454
                switch(SerialMsg.CmdID)
455
                {
455
                {
456
//                      case 'b': // extern control
456
//                      case 'b': // extern control
457
//                                        UART1_ExternalControlConfirmFrame = 1;
457
//                                        UART1_ExternalControlConfirmFrame = 1;
458
//                      case 'y': // serial poti values
458
//                      case 'y': // serial poti values
459
//                              Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
459
//                              Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
460
//                              Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
460
//                              Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
461
//                              return; //end process rx data
461
//                              return; //end process rx data
462
                        break;
462
                        break;
463
                }
463
                }
464
        }
464
        }
465
*/
465
*/
466
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
466
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
467
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
467
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
468
        switch(SerialMsg.Address) // check for Slave Address
468
        switch(SerialMsg.Address) // check for Slave Address
469
        {
469
        {
470
                case NC_ADDRESS:  // own Slave Address
470
                case NC_ADDRESS:  // own Slave Address
471
                switch(SerialMsg.CmdID)
471
                switch(SerialMsg.CmdID)
472
                {
472
                {
473
                        case 't': // request for the GPS time
473
                        case 't': // request for the GPS time
474
                                UART1_Request_SystemTime  = TRUE;
474
                                UART1_Request_SystemTime  = TRUE;
475
                                break;
475
                                break;
476
 
476
 
477
                        case 'm': // request for the license string
477
                        case 'm': // request for the license string
478
                                UART1_Request_LicenseString = SerialMsg.pData[0];
478
                                UART1_Request_LicenseString = SerialMsg.pData[0];
479
                                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20))
479
                                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && (UART_VersionInfo.HWMajor >= 20))
480
                                 {
480
                                 {
481
                                  memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy ftp parameter
481
                                  memcpy(LicensePtr, &SerialMsg.pData[1],LICENSE_SIZE_TEXT); // copy ftp parameter
482
                                 }
482
                                 }
483
                                break;
483
                                break;
484
                        case 'f': // ftp command
484
                        case 'f': // ftp command
485
                                UART1_Request_FTP = SerialMsg.pData[0];
485
                                UART1_Request_FTP = SerialMsg.pData[0];
486
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
486
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
487
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
487
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
488
                        break;
488
                        break;
489
 
489
 
490
                        case 'z': // connection checker
490
                        case 'z': // connection checker
491
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
491
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
492
                                UART1_Request_Echo = TRUE;
492
                                UART1_Request_Echo = TRUE;
493
                                break;
493
                                break;
494
 
494
 
495
                        case 'e': // request for the text of the error status
495
                        case 'e': // request for the text of the error status
496
                                UART1_Request_ErrorMessage = TRUE;
496
                                UART1_Request_ErrorMessage = TRUE;
497
                                break;
497
                                break;
498
 
498
 
499
                        case 's'://  new target position
499
                        case 's'://  new target position
500
                                pPoint = (Point_t*)SerialMsg.pData;
500
                                pPoint = (Point_t*)SerialMsg.pData;
501
                                if(pPoint->Position.Status == NEWDATA)
501
                                if(pPoint->Position.Status == NEWDATA)
502
                                {
502
                                {
503
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
503
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
504
                                        //pPoint->Index = 1; // must be one after empty list
504
                                        //pPoint->Index = 1; // must be one after empty list
505
                                        PointList_SetAt(pPoint);
505
                                        PointList_SetAt(pPoint);
506
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
506
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
507
//                                      GPS_pWaypoint = PointList_WPBegin(); // updates POI index
507
//                                      GPS_pWaypoint = PointList_WPBegin(); // updates POI index
508
 
508
 
509
 
509
 
510
if(CurrentlyFlyingWaypoints)
510
if(CurrentlyFlyingWaypoints)
511
 {
511
 {
512
  GPS_pWaypoint = PointList_WPBegin();  
512
  GPS_pWaypoint = PointList_WPBegin();  
513
  NewWaypointsReceived = 0;                     // Only an update 
513
  NewWaypointsReceived = 0;                     // Only an update 
514
 }
514
 }
515
                                        BeepTime = 50;
515
                                        BeepTime = 50;
516
                                }
516
                                }
517
                                else
517
                                else
518
                                if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN))
518
                                if((pPoint->Position.Status == SIMULATION) && !(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN))
519
                                {
519
                                {
520
                                if(pPoint->Event_Flag & SIMULATION_MOTOR_ON)
520
                                if(pPoint->Event_Flag & SIMULATION_MOTOR_ON)
521
                                 {
521
                                 {
522
                                  GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position
522
                                  GPSPos_Copy(&(pPoint->Position), &SimulationPosition); // update hold position
523
                                  CompassDirectionAtMotorStart = SimulatedDirection*10;
523
                                  CompassDirectionAtMotorStart = SimulatedDirection*10;
524
                                 }
524
                                 }
525
                                if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON))
525
                                if(!(SimulationFlags & SIMULATION_MOTOR_ON) && (pPoint->Event_Flag & SIMULATION_MOTOR_ON))
526
                                 {
526
                                 {
527
                                  SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin
527
                                  SimulationFlags = pPoint->Event_Flag | SIMULATION_MOTOR_START; // dann steht da noch nicht "SIMULATION_MOTOR_ON" drin
528
                                  SpeakHoTT = SPEAK_STARTING;
528
                                  SpeakHoTT = SPEAK_STARTING;
529
                                 }
529
                                 }
530
                                else
530
                                else
531
                                if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON))
531
                                if(!(pPoint->Event_Flag & SIMULATION_MOTOR_ON) && (SimulationFlags & SIMULATION_MOTOR_ON))
532
                                 {
532
                                 {
533
                                  SimulationFlags = pPoint->Event_Flag;
533
                                  SimulationFlags = pPoint->Event_Flag;
534
                                  SpeakHoTT = SPEAK_MK_OFF;
534
                                  SpeakHoTT = SPEAK_MK_OFF;
535
                                  BeepTime = 50;
535
                                  BeepTime = 50;
536
                                 }
536
                                 }
537
                                 else
537
                                 else
538
                                  SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START);
538
                                  SimulationFlags = pPoint->Event_Flag | (SimulationFlags & SIMULATION_MOTOR_START);
539
                                }
539
                                }
540
                                break;
540
                                break;
541
                        case 'u': // redirect debug uart
541
                        case 'u': // redirect debug uart
542
                                switch(SerialMsg.pData[0])
542
                                switch(SerialMsg.pData[0])
543
                                {
543
                                {
544
                                        case UART_FLIGHTCTRL:
544
                                        case UART_FLIGHTCTRL:
545
ENABLE_FC_UART;
545
ENABLE_FC_UART;
546
                                                UART2_Init();                           // initialize UART2 to FC pins
546
                                                UART2_Init();                           // initialize UART2 to FC pins
547
                                                fifo_purge(&UART1_rx_fifo);
547
                                                fifo_purge(&UART1_rx_fifo);
548
                                                TIMER2_Deinit();                        // reduce irq load
548
                                                TIMER2_Deinit();                        // reduce irq load
549
                                                DebugUART = UART2;
549
                                                DebugUART = UART2;
550
                                                break;
550
                                                break;
551
                                        case UART_MK3MAG:
551
                                        case UART_MK3MAG:
552
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
552
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
553
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
553
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
554
                                                GPSData.Status = INVALID;
554
                                                GPSData.Status = INVALID;
555
                                                fifo_purge(&UART1_rx_fifo);
555
                                                fifo_purge(&UART1_rx_fifo);
556
                                                DebugUART = UART0;
556
                                                DebugUART = UART0;
557
                                                break;
557
                                                break;
558
                                        case UART_MKGPS:
558
                                        case UART_MKGPS:
559
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
559
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
560
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
560
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
561
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
561
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
562
                                                GPSData.Status = INVALID;
562
                                                GPSData.Status = INVALID;
563
                                                fifo_purge(&UART1_rx_fifo);
563
                                                fifo_purge(&UART1_rx_fifo);
564
                                                DebugUART = UART0;
564
                                                DebugUART = UART0;
565
                                                break;
565
                                                break;
566
                                        default:
566
                                        default:
567
                                                break;
567
                                                break;
568
                                }
568
                                }
569
                                break;
569
                                break;
570
 
570
 
571
                        case 'w'://  Set point in list at index
571
                        case 'w'://  Set point in list at index
572
                                {
572
                                {
573
                                        pPoint = (Point_t*)SerialMsg.pData;
573
                                        pPoint = (Point_t*)SerialMsg.pData;
574
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
574
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
575
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
575
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
576
                                        {
576
                                        {
577
                                                PointList_Clear();
577
                                                PointList_Clear();
578
                                                GPS_pWaypoint = PointList_WPBegin();
578
                                                GPS_pWaypoint = PointList_WPBegin();
579
                                                UART1_Request_WritePoint = 0; // return new point count
579
                                                UART1_Request_WritePoint = 0; // return new point count
580
                                                NewWaypointsReceived = 1;
580
                                                NewWaypointsReceived = 1;
581
                                        }
581
                                        }
582
                                        else
582
                                        else
583
                                        {  // update WP in list at index
583
                                        {  // update WP in list at index
584
                                                if(pPoint->Index > MaxNumberOfWaypoints)
584
                                                if(pPoint->Index > MaxNumberOfWaypoints)
585
                                                {
585
                                                {
586
                                                        UART1_Request_WritePoint = 254;
586
                                                        UART1_Request_WritePoint = 254;
587
                                                        pPoint->Index = MaxNumberOfWaypoints;
587
                                                        pPoint->Index = MaxNumberOfWaypoints;
588
                                                }
588
                                                }
589
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
589
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
590
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
590
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
591
                                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
591
                                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
592
                                                if(UART1_Request_WritePoint == pPoint->Index)
592
                                                if(UART1_Request_WritePoint == pPoint->Index)
593
                                                {
593
                                                {
594
                                                        BeepTime = 500;
594
                                                        BeepTime = 500;
595
                                                    if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1;            // Speak once as soon as the Points are active
595
                                                    if(UART1_Request_WritePoint == 1) SpeakNextWaypoint = 1;            // Speak once as soon as the Points are active
596
                                                }
596
                                                }
597
                                        }
597
                                        }
598
                                }
598
                                }
599
                                break;
599
                                break;
600
 
600
 
601
                        case 'x'://  Read Waypoint from List
601
                        case 'x'://  Read Waypoint from List
602
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
602
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
603
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
603
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
604
                                break;
604
                                break;
605
 
605
 
606
                        case 'i':// Store WP List to file
606
                        case 'i':// Store WP List to file
607
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
607
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
608
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
608
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
609
                                WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer
609
                                WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer
610
                                WPL_Answer.Status = PointList_WriteToFile(&WPL_Store);
610
                                WPL_Answer.Status = PointList_WriteToFile(&WPL_Store);
611
                                UART1_Request_WPLStore = TRUE;
611
                                UART1_Request_WPLStore = TRUE;
612
                                break;
612
                                break;
613
 
613
 
614
                        case 'j':// Set/Get NC-Parameter
614
                        case 'j':// Set/Get NC-Parameter
615
                                switch(SerialMsg.pData[0])
615
                                switch(SerialMsg.pData[0])
616
                                {
616
                                {
617
                                        case 0: // get
617
                                        case 0: // get
618
                                        break;
618
                                        break;
619
 
619
 
620
                                        case 1: // set
620
                                        case 1: // set
621
                                        {
621
                                        {
622
                                                s16 value;
622
                                                s16 value;
623
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
623
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
624
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
624
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
625
                                        }
625
                                        }
626
                                        break;
626
                                        break;
627
                                       
627
                                       
628
                                        default:
628
                                        default:
629
                                        break;
629
                                        break;
630
                                }
630
                                }
631
                                UART1_Request_ParameterId = SerialMsg.pData[1];
631
                                UART1_Request_ParameterId = SerialMsg.pData[1];
632
                                UART1_Request_Parameter = TRUE;
632
                                UART1_Request_Parameter = TRUE;
633
                                break;
633
                                break;
634
                        default:
634
                        default:
635
                                // unsupported command recieved
635
                                // unsupported command recieved
636
                                break;
636
                                break;
637
                } // case NC_ADDRESS
637
                } // case NC_ADDRESS
638
                // "break;" is missing here to fall thru to the common commands
638
                // "break;" is missing here to fall thru to the common commands
639
 
639
 
640
                default:  // and any other Slave Address
640
                default:  // and any other Slave Address
641
 
641
 
642
                switch(SerialMsg.CmdID) // check CmdID
642
                switch(SerialMsg.CmdID) // check CmdID
643
                {
643
                {
644
                        case 'a':// request for the labels of the analog debug outputs
644
                        case 'a':// request for the labels of the analog debug outputs
645
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
645
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
646
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
646
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
647
                                break;
647
                                break;
648
                       
648
                       
649
                        case 'b': // submit extern control
649
                        case 'b': // submit extern control
650
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
650
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
651
                                UART1_ConfirmFrame = ExternControl.Frame;
651
                                UART1_ConfirmFrame = ExternControl.Frame;
652
                                NewExternalControlFrame = 1;
652
                                NewExternalControlFrame = 1;
653
                                break;
653
                                break;
654
 
654
 
655
                        case 'y': // serial Channels
655
                        case 'y': // serial Channels
656
                                memcpy(&SerialChannel, SerialMsg.pData, sizeof(SerialChannel));
656
                                memcpy(&SerialChannel, SerialMsg.pData, sizeof(SerialChannel));
657
                                memcpy((u8 *) &(PPM_In[SERIAL_POTI_START]), (u8 *) &SerialChannel, 12); // copy the 12 Bytes Serial Channels into the PPM_In array
657
                                memcpy((u8 *) &(PPM_In[SERIAL_POTI_START]), (u8 *) &SerialChannel, 12); // copy the 12 Bytes Serial Channels into the PPM_In array
658
                                NewSerialChannelFrame = 1;
658
                                NewSerialChannelFrame = 1;
659
                                break;
659
                                break;
660
 
660
 
661
                        case 'g':// request for the externalControl
661
                        case 'g':// request for the externalControl
662
                                UART1_Request_ExternalControl = TRUE;
662
                                UART1_Request_ExternalControl = TRUE;
663
                                break;
663
                                break;
664
 
664
 
665
                        case 'p':// request for the PPM_In
665
                        case 'p':// request for the PPM_In
666
                                UART1_Request_PPM_Channels = TRUE;
666
                                UART1_Request_PPM_Channels = TRUE;
667
                                break;
667
                                break;
668
                       
668
                       
669
                        case 'd': // request for debug data;
669
                        case 'd': // request for debug data;
670
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
670
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
671
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
671
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
672
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
672
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
673
                                break;
673
                                break;
674
 
674
 
675
                        case 'c': // request for 3D data;
675
                        case 'c': // request for 3D data;
676
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
676
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
677
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
677
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
678
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
678
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
679
                                break;
679
                                break;
680
 
680
 
681
                        case 'k': // request for Motor data;
681
                        case 'k': // request for Motor data;
682
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
682
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
683
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
683
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
684
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
684
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
685
                                break;
685
                                break;
686
 
686
 
687
                        case 'h':// reqest for display line
687
                        case 'h':// reqest for display line
688
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
688
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
689
                                {
689
                                {
690
                                        UART1_DisplayLine = 2;
690
                                        UART1_DisplayLine = 2;
691
                                        UART1_Display_Interval = 0;
691
                                        UART1_Display_Interval = 0;
692
                                        UART1_Request_Display = TRUE;
692
                                        UART1_Request_Display = TRUE;
693
                                }
693
                                }
694
                                else
694
                                else
695
                                {
695
                                {
696
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
696
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
697
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
697
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
698
                                        UART1_DisplayLine = 4;
698
                                        UART1_DisplayLine = 4;
699
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
699
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
700
                                        if(UART1_Display_Interval) UART1_Request_Display = TRUE;
700
                                        if(UART1_Display_Interval) UART1_Request_Display = TRUE;
701
                                }
701
                                }
702
                                break;
702
                                break;
703
 
703
 
704
                        case 'l':// reqest for display columns
704
                        case 'l':// reqest for display columns
705
                                MenuItem = SerialMsg.pData[0];
705
                                MenuItem = SerialMsg.pData[0];
706
                                UART1_Request_Display1 = TRUE;
706
                                UART1_Request_Display1 = TRUE;
707
                                break;
707
                                break;
708
 
708
 
709
                        case 'o': // request for navigation information
709
                        case 'o': // request for navigation information
710
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
710
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
711
                                if(SerialMsg.DataLen > 2) UART1_NaviData_MaxBytes = SerialMsg.pData[1] * 256 + SerialMsg.pData[2];
711
                                if(SerialMsg.DataLen > 2) UART1_NaviData_MaxBytes = SerialMsg.pData[1] * 256 + SerialMsg.pData[2];
712
                                else UART1_NaviData_MaxBytes = 0;
712
                                else UART1_NaviData_MaxBytes = 0;
713
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
713
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
714
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
714
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
-
 
715
                                if(UART1_NaviData_Interval < 100) UART1_NaviData_Interval = 100;
715
                                break;
716
                                break;
716
 
717
 
717
                        case 'v': // request for version info
718
                        case 'v': // request for version info
718
                                if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1;
719
                                if(SerialMsg.DataLen > 0 && SerialMsg.pData[0] == 1) UART1_Request_VersionInfo = 1;
719
                                else UART1_Request_VersionInfo = 2;
720
                                else UART1_Request_VersionInfo = 2;
720
                                break;
721
                                break;
721
                        default:
722
                        default:
722
                                // unsupported command recieved
723
                                // unsupported command recieved
723
                                break;
724
                                break;
724
                }
725
                }
725
                break; // default:
726
                break; // default:
726
        }
727
        }
727
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
728
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
728
}
729
}
729
 
730
 
730
 
731
 
731
/*****************************************************/
732
/*****************************************************/
732
/*                   Send a character                */
733
/*                   Send a character                */
733
/*****************************************************/
734
/*****************************************************/
734
s16 UART1_Putchar(char c)
735
s16 UART1_Putchar(char c)
735
{
736
{
736
        u32 timeout = 10000;
737
        u32 timeout = 10000;
737
        if (c == '\n') UART1_Putchar('\r');
738
        if (c == '\n') UART1_Putchar('\r');
738
        // wait until txd fifo is not full
739
        // wait until txd fifo is not full
739
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
740
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
740
        // transmit byte
741
        // transmit byte
741
        UART_SendData(UART1, c);
742
        UART_SendData(UART1, c);
742
        #ifdef FOLLOW_ME
743
        #ifdef FOLLOW_ME
743
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
744
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
744
        #endif
745
        #endif
745
        return (0);
746
        return (0);
746
}
747
}
747
 
748
 
748
/*****************************************************/
749
/*****************************************************/
749
/*       Send a string to the debug uart              */
750
/*       Send a string to the debug uart              */
750
/*****************************************************/
751
/*****************************************************/
751
void UART1_PutString(u8 *s)
752
void UART1_PutString(u8 *s)
752
{
753
{
753
        if(s == NULL) return;
754
        if(s == NULL) return;
754
        while (*s != '\0' && DebugUART == UART1)
755
        while (*s != '\0' && DebugUART == UART1)
755
        {
756
        {
756
                UART1_Putchar(*s);
757
                UART1_Putchar(*s);
757
                s ++;
758
                s ++;
758
        }
759
        }
759
}
760
}
760
 
761
 
761
 
762
 
762
/**************************************************************/
763
/**************************************************************/
763
/*         Transmit tx buffer via debug uart                  */
764
/*         Transmit tx buffer via debug uart                  */
764
/**************************************************************/
765
/**************************************************************/
765
void UART1_Transmit(void)
766
void UART1_Transmit(void)
766
{
767
{
767
        u8 tmp_tx;
768
        u8 tmp_tx;
768
        if(DebugUART != UART1) return;
769
        if(DebugUART != UART1) return;
769
        // if something has to be send and the txd fifo is not full
770
        // if something has to be send and the txd fifo is not full
770
        if(UART1_tx_buffer.Locked == TRUE)
771
        if(UART1_tx_buffer.Locked == TRUE)
771
        {
772
        {
772
                // while there is some space in the tx fifo
773
                // while there is some space in the tx fifo
773
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
774
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
774
                {
775
                {
775
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
776
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
776
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
777
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
777
                        #ifdef FOLLOW_ME
778
                        #ifdef FOLLOW_ME
778
                        if(TransmitAlsoToFC)
779
                        if(TransmitAlsoToFC)
779
                        {
780
                        {
780
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
781
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
781
                        }
782
                        }
782
                        #endif
783
                        #endif
783
                        // if terminating character or end of txd buffer reached
784
                        // if terminating character or end of txd buffer reached
784
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
785
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
785
                        {
786
                        {
786
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
787
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
787
                                #ifdef FOLLOW_ME
788
                                #ifdef FOLLOW_ME
788
                                TransmitAlsoToFC = 0;
789
                                TransmitAlsoToFC = 0;
789
                                #endif
790
                                #endif
790
                                break; // end while loop
791
                                break; // end while loop
791
                        }
792
                        }
792
                }
793
                }
793
        }
794
        }
794
}
795
}
795
 
796
 
796
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
797
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
797
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
798
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
798
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
799
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
799
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
800
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
800
 
801
 
801
void CreateNmeaGGA(void)
802
void CreateNmeaGGA(void)
802
{
803
{
803
        u8 array[200], i = 0, crc = 0, x;
804
        u8 array[200], i = 0, crc = 0, x;
804
        s32 tmp1, tmp2;
805
        s32 tmp1, tmp2;
805
 
806
 
806
        i += sprintf(array, "$GPGGA,");
807
        i += sprintf(array, "$GPGGA,");
807
        // +++++++++++++++++++++++++++++++++++++++++++
808
        // +++++++++++++++++++++++++++++++++++++++++++
808
        if(SystemTime.Valid)
809
        if(SystemTime.Valid)
809
        {
810
        {
810
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
811
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
811
        }
812
        }
812
        else
813
        else
813
        {
814
        {
814
                i += sprintf(&array[i], ",");
815
                i += sprintf(&array[i], ",");
815
        }
816
        }
816
        // +++++++++++++++++++++++++++++++++++++++++++
817
        // +++++++++++++++++++++++++++++++++++++++++++
817
        if(GPSData.Flags & FLAG_GPSFIXOK)
818
        if(GPSData.Flags & FLAG_GPSFIXOK)
818
        {
819
        {
819
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
820
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
820
                i += sprintf(&array[i],"%02d",(s16)tmp1);
821
                i += sprintf(&array[i],"%02d",(s16)tmp1);
821
 
822
 
822
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
823
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
823
                tmp1 *= 6; // in Minuten
824
                tmp1 *= 6; // in Minuten
824
                tmp2 = tmp1 / 1000000L;
825
                tmp2 = tmp1 / 1000000L;
825
                i += sprintf(&array[i],"%02d", (u16)tmp2);
826
                i += sprintf(&array[i],"%02d", (u16)tmp2);
826
                tmp2 = tmp1 % 1000000L;
827
                tmp2 = tmp1 % 1000000L;
827
                tmp2 /= 100; // zwei Stellen zu viel
828
                tmp2 /= 100; // zwei Stellen zu viel
828
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
829
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
829
 
830
 
830
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
831
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
831
                else i += sprintf(&array[i],"S,");
832
                else i += sprintf(&array[i],"S,");
832
                // +++++++++++++++++++++++++++++++++++++++++++
833
                // +++++++++++++++++++++++++++++++++++++++++++
833
 
834
 
834
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
835
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
835
                i += sprintf(&array[i],"%03d", (u16)tmp1);
836
                i += sprintf(&array[i],"%03d", (u16)tmp1);
836
 
837
 
837
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
838
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
838
                tmp1 *= 6; // in Minuten
839
                tmp1 *= 6; // in Minuten
839
                tmp2 = tmp1 / 1000000L;
840
                tmp2 = tmp1 / 1000000L;
840
                i += sprintf(&array[i],"%02d", (u16)tmp2);
841
                i += sprintf(&array[i],"%02d", (u16)tmp2);
841
                tmp2 = tmp1 % 1000000L;
842
                tmp2 = tmp1 % 1000000L;
842
                tmp2 /= 100; // zwei Stellen zu viel
843
                tmp2 /= 100; // zwei Stellen zu viel
843
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
844
                i += sprintf(&array[i],".%04d,", (u16)tmp2);
844
 
845
 
845
 
846
 
846
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
847
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
847
                else i += sprintf(&array[i],"W,");
848
                else i += sprintf(&array[i],"W,");
848
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
849
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
849
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
850
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
850
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
851
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
851
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
852
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
852
                tmp1 = NaviData.Altimeter / 2; // in dm
853
                tmp1 = NaviData.Altimeter / 2; // in dm
853
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
854
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
854
                i += sprintf(&array[i],",,,*");
855
                i += sprintf(&array[i],",,,*");
855
        }
856
        }
856
        else
857
        else
857
        {
858
        {
858
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
859
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
859
        }
860
        }
860
        for(x = 1; x < i-1; x++)
861
        for(x = 1; x < i-1; x++)
861
        {
862
        {
862
                crc ^= array[x];
863
                crc ^= array[x];
863
        }
864
        }
864
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
865
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
865
        AddSerialData(&UART1_tx_buffer,array,i);
866
        AddSerialData(&UART1_tx_buffer,array,i);
866
 
867
 
867
        // +++++++++++++++++++++++++++++++++++++++++++
868
        // +++++++++++++++++++++++++++++++++++++++++++
868
}
869
}
869
 
870
 
870
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
871
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
871
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
872
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
872
 
873
 
873
void CreateNmeaRMC(void)
874
void CreateNmeaRMC(void)
874
{
875
{
875
        u8 array[200], i = 0, crc = 0, x;
876
        u8 array[200], i = 0, crc = 0, x;
876
        s16 tmp_int;
877
        s16 tmp_int;
877
        s32 tmp1, tmp2;
878
        s32 tmp1, tmp2;
878
        // +++++++++++++++++++++++++++++++++++++++++++
879
        // +++++++++++++++++++++++++++++++++++++++++++
879
        i += sprintf(array, "$GPRMC,");
880
        i += sprintf(array, "$GPRMC,");
880
        // +++++++++++++++++++++++++++++++++++++++++++
881
        // +++++++++++++++++++++++++++++++++++++++++++
881
        if(SystemTime.Valid)
882
        if(SystemTime.Valid)
882
        {
883
        {
883
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
884
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
884
        }
885
        }
885
        else
886
        else
886
        {
887
        {
887
                i += sprintf(&array[i], ",");
888
                i += sprintf(&array[i], ",");
888
        }
889
        }
889
        if(GPSData.Flags & FLAG_GPSFIXOK)
890
        if(GPSData.Flags & FLAG_GPSFIXOK)
890
        {
891
        {
891
                // +++++++++++++++++++++++++++++++++++++++++++
892
                // +++++++++++++++++++++++++++++++++++++++++++
892
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
893
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
893
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
894
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
894
 
895
 
895
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
896
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
896
                tmp1 *= 6; // in Minuten
897
                tmp1 *= 6; // in Minuten
897
                tmp2 = tmp1 / 1000000L;
898
                tmp2 = tmp1 / 1000000L;
898
                i += sprintf(&array[i],"%02d", (s16)tmp2);
899
                i += sprintf(&array[i],"%02d", (s16)tmp2);
899
                tmp2 = tmp1 % 1000000L;
900
                tmp2 = tmp1 % 1000000L;
900
                tmp2 /= 100; // zwei Stellen zu viel
901
                tmp2 /= 100; // zwei Stellen zu viel
901
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
902
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
902
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
903
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
903
                else i += sprintf(&array[i],"S,");
904
                else i += sprintf(&array[i],"S,");
904
                // +++++++++++++++++++++++++++++++++++++++++++
905
                // +++++++++++++++++++++++++++++++++++++++++++
905
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
906
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
906
                i += sprintf(&array[i],"%03d", (s16)tmp1);
907
                i += sprintf(&array[i],"%03d", (s16)tmp1);
907
 
908
 
908
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
909
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
909
                tmp1 *= 6; // in Minuten
910
                tmp1 *= 6; // in Minuten
910
                tmp2 = tmp1 / 1000000L;
911
                tmp2 = tmp1 / 1000000L;
911
                i += sprintf(&array[i],"%02d", (s16)tmp2);
912
                i += sprintf(&array[i],"%02d", (s16)tmp2);
912
                tmp2 = tmp1 % 1000000L;
913
                tmp2 = tmp1 % 1000000L;
913
                tmp2 /= 100; // zwei Stellen zu viel
914
                tmp2 /= 100; // zwei Stellen zu viel
914
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
915
                i += sprintf(&array[i],".%04d,", (s16)tmp2);
915
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
916
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
916
                else i += sprintf(&array[i],"W,");
917
                else i += sprintf(&array[i],"W,");
917
                // +++++++++++++++++++++++++++++++++++++++++++
918
                // +++++++++++++++++++++++++++++++++++++++++++
918
                tmp_int = GPSData.Speed_Ground; // in cm/sek
919
                tmp_int = GPSData.Speed_Ground; // in cm/sek
919
                tmp_int *= 90;
920
                tmp_int *= 90;
920
                tmp_int /= 463;
921
                tmp_int /= 463;
921
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
922
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
922
                // +++++++++++++++++++++++++++++++++++++++++++
923
                // +++++++++++++++++++++++++++++++++++++++++++
923
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
924
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
924
                // +++++++++++++++++++++++++++++++++++++++++++
925
                // +++++++++++++++++++++++++++++++++++++++++++
925
                if(SystemTime.Valid)
926
                if(SystemTime.Valid)
926
                {
927
                {
927
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
928
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
928
                }
929
                }
929
                else
930
                else
930
                {
931
                {
931
                        i += sprintf(&array[i], ",");
932
                        i += sprintf(&array[i], ",");
932
                }
933
                }
933
                // +++++++++++++++++++++++++++++++++++++++++++
934
                // +++++++++++++++++++++++++++++++++++++++++++
934
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
935
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
935
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
936
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
936
                // +++++++++++++++++++++++++++++++++++++++++++
937
                // +++++++++++++++++++++++++++++++++++++++++++
937
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*");
938
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D*");
938
                else i += sprintf(&array[i], "A*");
939
                else i += sprintf(&array[i], "A*");
939
        }
940
        }
940
        else // kein Satfix
941
        else // kein Satfix
941
        {
942
        {
942
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
943
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
943
        }
944
        }
944
        // +++++++++++++++++++++++++++++++++++++++++++
945
        // +++++++++++++++++++++++++++++++++++++++++++
945
        //  CRC
946
        //  CRC
946
        // +++++++++++++++++++++++++++++++++++++++++++
947
        // +++++++++++++++++++++++++++++++++++++++++++
947
        for(x=1; x<i-1; x++)
948
        for(x=1; x<i-1; x++)
948
        {
949
        {
949
                crc ^= array[x];
950
                crc ^= array[x];
950
        }
951
        }
951
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
952
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
952
        // +++++++++++++++++++++++++++++++++++++++++++
953
        // +++++++++++++++++++++++++++++++++++++++++++
953
        AddSerialData(&UART1_tx_buffer,array,i);
954
        AddSerialData(&UART1_tx_buffer,array,i);
954
        // +++++++++++++++++++++++++++++++++++++++++++
955
        // +++++++++++++++++++++++++++++++++++++++++++
955
/*
956
/*
956
 
957
 
957
 
958
 
958
 
959
 
959
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
960
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
960
                GPSData.NumOfSats =                     UbxSol.numSV;
961
                GPSData.NumOfSats =                     UbxSol.numSV;
961
                GPSData.SatFix =                                UbxSol.GPSfix;
962
                GPSData.SatFix =                                UbxSol.GPSfix;
962
                GPSData.Position_Accuracy =             UbxSol.PAcc;
963
                GPSData.Position_Accuracy =             UbxSol.PAcc;
963
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
964
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
964
                SetGPSTime(&SystemTime); // update system time
965
                SetGPSTime(&SystemTime); // update system time
965
                // NAV POSLLH
966
                // NAV POSLLH
966
                GPSData.Position.Status =               INVALID;
967
                GPSData.Position.Status =               INVALID;
967
                GPSData.Position.Longitude =    UbxPosLlh.LON;
968
                GPSData.Position.Longitude =    UbxPosLlh.LON;
968
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
969
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
969
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
970
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
970
                GPSData.Position.Status =               NEWDATA;
971
                GPSData.Position.Status =               NEWDATA;
971
                // NAV VELNED
972
                // NAV VELNED
972
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
973
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
973
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
974
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
974
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
975
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
975
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
976
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
976
                GPSData.Heading =                               UbxVelNed.Heading;
977
                GPSData.Heading =                               UbxVelNed.Heading;
977
                SystemTime.Year = 0;
978
                SystemTime.Year = 0;
978
                SystemTime.Month = 0;
979
                SystemTime.Month = 0;
979
                SystemTime.Day = 0;
980
                SystemTime.Day = 0;
980
                SystemTime.Hour = 0;
981
                SystemTime.Hour = 0;
981
                SystemTime.Min = 0;
982
                SystemTime.Min = 0;
982
                SystemTime.Sec = 0;
983
                SystemTime.Sec = 0;
983
                SystemTime.mSec = 0;
984
                SystemTime.mSec = 0;
984
                SystemTime.Valid = 0;
985
                SystemTime.Valid = 0;
985
 
986
 
986
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
987
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
987
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
988
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
988
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
989
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
989
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
990
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
990
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
991
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
991
 
992
 
992
 
993
 
993
 
994
 
994
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
995
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
995
                        i1 *= 100;
996
                        i1 *= 100;
996
                        i1 += i2 / 100000;
997
                        i1 += i2 / 100000;
997
                        i2  = i2 % 100000;
998
                        i2  = i2 % 100000;
998
                        i2 /= 10;
999
                        i2 /= 10;
999
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
1000
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
1000
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
1001
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
1001
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
1002
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
1002
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
1003
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
1003
                        break;
1004
                        break;
1004
                case 1:
1005
                case 1:
1005
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
1006
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
1006
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
1007
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
1007
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
1008
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
1008
                        //-----------------------------
1009
                        //-----------------------------
1009
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
1010
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
1010
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
1011
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
1011
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
1012
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
1012
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
1013
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
1013
 
1014
 
1014
*/
1015
*/
1015
}
1016
}
1016
 
1017
 
1017
u16 SendTriggerPos(void)
1018
u16 SendTriggerPos(void)
1018
{
1019
{
1019
 u16 sent = 0;                                 
1020
 u16 sent = 0;                                 
1020
 NaviData_Out1Trigger.Index = 18;
1021
 NaviData_Out1Trigger.Index = 18;
1021
 sent = MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Out1Trigger, sizeof(NaviData_Out1Trigger)) + 1;
1022
 sent = MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Out1Trigger, sizeof(NaviData_Out1Trigger)) + 1;
1022
 Out1TriggerUpdateNewData = 0;
1023
 Out1TriggerUpdateNewData = 0;
1023
// BeepTime = 50; // beep
1024
// BeepTime = 50; // beep
1024
 return(sent);
1025
 return(sent);
1025
}
1026
}
1026
 
1027
 
1027
 
1028
 
1028
u16 TransmitNavigationData(u16 MaxBytesPerSecond, u8 clear) // returns the minumum pause time in ms
1029
u16 TransmitNavigationData(u16 MaxBytesPerSecond, u8 clear) // returns the minumum pause time in ms
1029
{
1030
{
1030
static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6, count_fs = 7;
1031
static u8 state = 0, count_flags = 2, count_target = 3, count_home = 4, count_wp = 5 , count_tiny = 6, count_fs = 7;
1031
static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0, CRC_Fs = 0;
1032
static u16 CRC_Home = 0, CRC_Target = 0, CRC_Flags = 0, CRC_Wp = 0, CRC_Fs = 0;
1032
u16 pause, sent = 0, crc_home, crc_target, crc_flags, crc_wp, crc_fs;
1033
u16 pause, sent = 0, crc_home, crc_target, crc_flags, crc_wp, crc_fs;
1033
 
1034
 
1034
 if(clear)
1035
 if(clear)
1035
 {
1036
 {
1036
        state = 0;
1037
        state = 0;
1037
        CRC_Home++;
1038
        CRC_Home++;
1038
        CRC_Target++;
1039
        CRC_Target++;
1039
        CRC_Flags++;
1040
        CRC_Flags++;
1040
        CRC_Wp++;
1041
        CRC_Wp++;
1041
        CRC_Fs++;
1042
        CRC_Fs++;
1042
        if(ErrorCode) NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT;
1043
        if(ErrorCode) NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT;
1043
        else NaviData_Flags.SpeakHoTT = SPEAK_CONNECTED;
1044
        else NaviData_Flags.SpeakHoTT = SPEAK_CONNECTED;
1044
        NaviData_Flags_SpeakHoTT_Processed = 0; // don't overwrite in SPI.C
1045
        NaviData_Flags_SpeakHoTT_Processed = 0; // don't overwrite in SPI.C
1045
        return(1);
1046
        return(1);
1046
 }
1047
 }
1047
while(!sent)
1048
while(!sent)
1048
 {
1049
 {
1049
//      if(Out1TriggerUpdateNewData && MaxBytesPerSecond > 200)   // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available
1050
//      if(Out1TriggerUpdateNewData && MaxBytesPerSecond > 200)   // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available
1050
//     sent += SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung
1051
//     sent += SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung
1051
 
1052
 
1052
                switch(state++)
1053
                switch(state++)
1053
                {
1054
                {
1054
                 case 0:
1055
                 case 0:
1055
                 case 6:
1056
                 case 6:
1056
                 case 5:
1057
                 case 5:
1057
// belegt 35 ASCII-Zeichen
1058
// belegt 35 ASCII-Zeichen
1058
                                NaviData_Flags.Index = 11;
1059
                                NaviData_Flags.Index = 11;
1059
                                NaviData_Flags.ActualLongitude = NaviData.CurrentPosition.Longitude;
1060
                                NaviData_Flags.ActualLongitude = NaviData.CurrentPosition.Longitude;
1060
                                NaviData_Flags.ActualLatitude = NaviData.CurrentPosition.Latitude;
1061
                                NaviData_Flags.ActualLatitude = NaviData.CurrentPosition.Latitude;
1061
                                NaviData_Flags.Altimeter = NaviData.Altimeter;
1062
                                NaviData_Flags.Altimeter = NaviData.Altimeter;
1062
                                NaviData_Flags.GroundSpeed = NaviData.GroundSpeed / 10;
1063
                                NaviData_Flags.GroundSpeed = NaviData.GroundSpeed / 10;
1063
                                NaviData_Flags.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1064
                                NaviData_Flags.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1064
                                NaviData_Flags.OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2);
1065
                                NaviData_Flags.OSDStatusFlags2 = (FC.StatusFlags & ~OSD_FLAG_MASK1) | (FC.StatusFlags2 & ~OSD_FLAG_MASK2);
1065
                                NaviData_Flags.NCFlags = NaviData.NCFlags;
1066
                                NaviData_Flags.NCFlags = NaviData.NCFlags;
1066
                                NaviData_Flags.Errorcode = ErrorCode;
1067
                                NaviData_Flags.Errorcode = ErrorCode;
1067
                                NaviData_Flags.ReserveFlags = 0;
1068
                                NaviData_Flags.ReserveFlags = 0;
1068
                                //NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; -> in SPI.c
1069
                                //NaviData_Flags.SpeakHoTT = FC.FromFC_SpeakHoTT; -> in SPI.c
1069
                                NaviData_Flags.VarioCharacter = FromFC_VarioCharacter;
1070
                                NaviData_Flags.VarioCharacter = FromFC_VarioCharacter;
1070
                                NaviData_Flags.GPS_ModeCharacter = NC_GPS_ModeCharacter;
1071
                                NaviData_Flags.GPS_ModeCharacter = NC_GPS_ModeCharacter;
1071
                                NaviData_Flags.BL_MinOfMaxPWM = BL_MinOfMaxPWM;
1072
                                NaviData_Flags.BL_MinOfMaxPWM = BL_MinOfMaxPWM;
1072
                                crc_flags = CRC16((unsigned char*)(&NaviData_Flags.OSDStatusFlags2), sizeof(NaviData_Flags) - START_PAYLOAD_DATA); // update crc for the license structure
1073
                                crc_flags = CRC16((unsigned char*)(&NaviData_Flags.OSDStatusFlags2), sizeof(NaviData_Flags) - START_PAYLOAD_DATA); // update crc for the license structure
1073
                                if((crc_flags != CRC_Flags) || (--count_flags == 0))
1074
                                if((crc_flags != CRC_Flags) || (--count_flags == 0))
1074
                                {
1075
                                {
1075
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Flags, sizeof(NaviData_Flags)) + 1;
1076
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Flags, sizeof(NaviData_Flags)) + 1;
1076
                                 CRC_Flags = crc_flags;
1077
                                 CRC_Flags = crc_flags;
1077
                                 count_flags = 11*2;
1078
                                 count_flags = 11*2;
1078
                                }
1079
                                }
1079
                                NaviData_Flags_SpeakHoTT_Processed = 1; // allow update in SPI now
1080
                                NaviData_Flags_SpeakHoTT_Processed = 1; // allow update in SPI now
1080
                                break;
1081
                                break;
1081
                 case 1:
1082
                 case 1:
1082
                 case 7:
1083
                 case 7:
1083
// belegt 43 ASCII-Zeichen
1084
// belegt 43 ASCII-Zeichen
1084
                                NaviData_Target.Index = 12;
1085
                                NaviData_Target.Index = 12;
1085
                                NaviData_Target.ActualLongitude = NaviData.CurrentPosition.Longitude;
1086
                                NaviData_Target.ActualLongitude = NaviData.CurrentPosition.Longitude;
1086
                                NaviData_Target.ActualLatitude = NaviData.CurrentPosition.Latitude;
1087
                                NaviData_Target.ActualLatitude = NaviData.CurrentPosition.Latitude;
1087
                                NaviData_Target.Altimeter = NaviData.Altimeter;
1088
                                NaviData_Target.Altimeter = NaviData.Altimeter;
1088
                                NaviData_Target.GroundSpeed = NaviData.GroundSpeed / 10;
1089
                                NaviData_Target.GroundSpeed = NaviData.GroundSpeed / 10;
1089
                                NaviData_Target.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1090
                                NaviData_Target.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1090
                                NaviData_Target.TargetLongitude = NaviData.TargetPosition.Longitude;
1091
                                NaviData_Target.TargetLongitude = NaviData.TargetPosition.Longitude;
1091
                                NaviData_Target.TargetLatitude = NaviData.TargetPosition.Latitude;
1092
                                NaviData_Target.TargetLatitude = NaviData.TargetPosition.Latitude;
1092
                                NaviData_Target.TargetAltitude = NaviData.TargetPosition.Altitude;
1093
                                NaviData_Target.TargetAltitude = NaviData.TargetPosition.Altitude;
1093
                                NaviData_Target.RC_Quality = NaviData.RC_Quality;
1094
                                NaviData_Target.RC_Quality = NaviData.RC_Quality;
1094
                                crc_target = CRC16((unsigned char*)(&NaviData_Target.TargetLongitude), sizeof(NaviData_Target) - START_PAYLOAD_DATA); // update crc for the license structure
1095
                                crc_target = CRC16((unsigned char*)(&NaviData_Target.TargetLongitude), sizeof(NaviData_Target) - START_PAYLOAD_DATA); // update crc for the license structure
1095
                            if((crc_target != CRC_Target) || (--count_target == 0))
1096
                            if((crc_target != CRC_Target) || (--count_target == 0))
1096
                                {
1097
                                {
1097
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Target, sizeof(NaviData_Target)) + 1;
1098
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Target, sizeof(NaviData_Target)) + 1;
1098
                                 CRC_Target = crc_target;
1099
                                 CRC_Target = crc_target;
1099
                                 count_target = 10*2;
1100
                                 count_target = 10*2;
1100
                                }
1101
                                }
1101
                                break;
1102
                                break;
1102
                 case 2:
1103
                 case 2:
1103
                 case 8:
1104
                 case 8:
1104
// belegt 31 ASCII-Zeichen
1105
// belegt 31 ASCII-Zeichen
1105
                                NaviData_WP.Index = 15;
1106
                                NaviData_WP.Index = 15;
1106
                                NaviData_WP.ActualLongitude = NaviData.CurrentPosition.Longitude;
1107
                                NaviData_WP.ActualLongitude = NaviData.CurrentPosition.Longitude;
1107
                                NaviData_WP.ActualLatitude = NaviData.CurrentPosition.Latitude;
1108
                                NaviData_WP.ActualLatitude = NaviData.CurrentPosition.Latitude;
1108
                                NaviData_WP.Altimeter = NaviData.Altimeter;
1109
                                NaviData_WP.Altimeter = NaviData.Altimeter;
1109
                                NaviData_WP.GroundSpeed = NaviData.GroundSpeed / 10;
1110
                                NaviData_WP.GroundSpeed = NaviData.GroundSpeed / 10;
1110
                                NaviData_WP.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1111
                                NaviData_WP.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1111
                                NaviData_WP.WaypointIndex = NaviData.WaypointIndex;
1112
                                NaviData_WP.WaypointIndex = NaviData.WaypointIndex;
1112
                                NaviData_WP.WaypointNumber = NaviData.WaypointNumber;
1113
                                NaviData_WP.WaypointNumber = NaviData.WaypointNumber;
1113
                                NaviData_WP.TargetHoldTime = NaviData.TargetHoldTime;
1114
                                NaviData_WP.TargetHoldTime = NaviData.TargetHoldTime;
1114
                                // NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; -> happends already in SPI.c
1115
                                // NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; -> happends already in SPI.c
1115
                                crc_wp = CRC16((unsigned char*)(&NaviData_WP.WaypointIndex), sizeof(NaviData_WP) - START_PAYLOAD_DATA); // update crc for the license structure
1116
                                crc_wp = CRC16((unsigned char*)(&NaviData_WP.WaypointIndex), sizeof(NaviData_WP) - START_PAYLOAD_DATA); // update crc for the license structure
1116
                                if((crc_wp != CRC_Wp) || (--count_wp == 0))
1117
                                if((crc_wp != CRC_Wp) || (--count_wp == 0))
1117
                                {
1118
                                {
1118
                         sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_WP, sizeof(NaviData_WP)) + 1;
1119
                         sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_WP, sizeof(NaviData_WP)) + 1;
1119
                                 CRC_Wp = crc_wp;
1120
                                 CRC_Wp = crc_wp;
1120
                                 count_wp = 12*2;
1121
                                 count_wp = 12*2;
1121
                                }
1122
                                }
1122
                                break;
1123
                                break;
1123
                 case 3:
1124
                 case 3:
1124
                 case 9:
1125
                 case 9:
1125
// 35 ASCII-Zeichen
1126
// 35 ASCII-Zeichen
1126
                                NaviData_Failsafe.Index = 17;
1127
                                NaviData_Failsafe.Index = 17;
1127
                                NaviData_Failsafe.ActualLongitude = NaviData.CurrentPosition.Longitude;
1128
                                NaviData_Failsafe.ActualLongitude = NaviData.CurrentPosition.Longitude;
1128
                                NaviData_Failsafe.ActualLatitude = NaviData.CurrentPosition.Latitude;
1129
                                NaviData_Failsafe.ActualLatitude = NaviData.CurrentPosition.Latitude;
1129
                                NaviData_Failsafe.Altimeter = NaviData.Altimeter;
1130
                                NaviData_Failsafe.Altimeter = NaviData.Altimeter;
1130
                                NaviData_Failsafe.GroundSpeed = NaviData.GroundSpeed / 10;
1131
                                NaviData_Failsafe.GroundSpeed = NaviData.GroundSpeed / 10;
1131
                                NaviData_Failsafe.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1132
                                NaviData_Failsafe.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1132
                                NaviData_Failsafe.Longitude = GPS_FailsafePosition.Longitude;
1133
                                NaviData_Failsafe.Longitude = GPS_FailsafePosition.Longitude;
1133
                                NaviData_Failsafe.Latitude = GPS_FailsafePosition.Latitude;
1134
                                NaviData_Failsafe.Latitude = GPS_FailsafePosition.Latitude;
1134
                                crc_fs = CRC16((unsigned char*)(&NaviData_Failsafe.Longitude), sizeof(NaviData_Pos_t) - START_PAYLOAD_DATA); // update crc for the license structure
1135
                                crc_fs = CRC16((unsigned char*)(&NaviData_Failsafe.Longitude), sizeof(NaviData_Pos_t) - START_PAYLOAD_DATA); // update crc for the license structure
1135
                                if((crc_fs != CRC_Fs) || (--count_fs == 0))
1136
                                if((crc_fs != CRC_Fs) || (--count_fs == 0))
1136
                                {
1137
                                {
1137
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Failsafe, sizeof(NaviData_Failsafe)) + 1;
1138
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Failsafe, sizeof(NaviData_Failsafe)) + 1;
1138
                                 CRC_Fs = crc_fs;
1139
                                 CRC_Fs = crc_fs;
1139
                                 count_fs = 20*2;
1140
                                 count_fs = 20*2;
1140
                                }
1141
                                }
1141
                                break;
1142
                                break;
1142
                 case 4:
1143
                 case 4:
1143
                 case 10:
1144
                 case 10:
1144
// belegt 43 ASCII-Zeichen
1145
// belegt 43 ASCII-Zeichen
1145
                                NaviData_Home.Index = 13;
1146
                                NaviData_Home.Index = 13;
1146
                                NaviData_Home.ActualLongitude = NaviData.CurrentPosition.Longitude;
1147
                                NaviData_Home.ActualLongitude = NaviData.CurrentPosition.Longitude;
1147
                                NaviData_Home.ActualLatitude = NaviData.CurrentPosition.Latitude;
1148
                                NaviData_Home.ActualLatitude = NaviData.CurrentPosition.Latitude;
1148
                                NaviData_Home.Altimeter = NaviData.Altimeter;
1149
                                NaviData_Home.Altimeter = NaviData.Altimeter;
1149
                                NaviData_Home.GroundSpeed = NaviData.GroundSpeed / 10;
1150
                                NaviData_Home.GroundSpeed = NaviData.GroundSpeed / 10;
1150
                                NaviData_Home.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1151
                                NaviData_Home.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1151
                                NaviData_Home.HomeLongitude = NaviData.HomePosition.Longitude;
1152
                                NaviData_Home.HomeLongitude = NaviData.HomePosition.Longitude;
1152
                                NaviData_Home.HomeLatitude = NaviData.HomePosition.Latitude;
1153
                                NaviData_Home.HomeLatitude = NaviData.HomePosition.Latitude;
1153
                                NaviData_Home.HomeAltitude = NaviData.HomePosition.Altitude;
1154
                                NaviData_Home.HomeAltitude = NaviData.HomePosition.Altitude;
1154
                                NaviData_Home.WP_OperatingRadius = MaxWP_Radius_in_m;
1155
                                NaviData_Home.WP_OperatingRadius = MaxWP_Radius_in_m;
1155
                                crc_home = CRC16((unsigned char*)(&NaviData_Home.HomeLongitude), sizeof(NaviData_Home_t) - START_PAYLOAD_DATA); // update crc for the license structure
1156
                                crc_home = CRC16((unsigned char*)(&NaviData_Home.HomeLongitude), sizeof(NaviData_Home_t) - START_PAYLOAD_DATA); // update crc for the license structure
1156
                                if((crc_home != CRC_Home) || (--count_home == 0))
1157
                                if((crc_home != CRC_Home) || (--count_home == 0))
1157
                                {
1158
                                {
1158
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Home, sizeof(NaviData_Home)) + 1;
1159
                                 sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Home, sizeof(NaviData_Home)) + 1;
1159
                                 CRC_Home = crc_home;
1160
                                 CRC_Home = crc_home;
1160
                                 count_home = 25;
1161
                                 count_home = 25;
1161
                                }
1162
                                }
1162
                                break;
1163
                                break;
1163
                 case 11:
1164
                 case 11:
1164
// belegt 39 ASCII-Zeichen
1165
// belegt 39 ASCII-Zeichen
1165
                                NaviData_Deviation.Index = 14;
1166
                                NaviData_Deviation.Index = 14;
1166
                                NaviData_Deviation.ActualLongitude = NaviData.CurrentPosition.Longitude;
1167
                                NaviData_Deviation.ActualLongitude = NaviData.CurrentPosition.Longitude;
1167
                                NaviData_Deviation.ActualLatitude = NaviData.CurrentPosition.Latitude;
1168
                                NaviData_Deviation.ActualLatitude = NaviData.CurrentPosition.Latitude;
1168
                                NaviData_Deviation.Altimeter = NaviData.Altimeter;
1169
                                NaviData_Deviation.Altimeter = NaviData.Altimeter;
1169
                                NaviData_Deviation.GroundSpeed = NaviData.GroundSpeed / 10;
1170
                                NaviData_Deviation.GroundSpeed = NaviData.GroundSpeed / 10;
1170
                                NaviData_Deviation.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1171
                                NaviData_Deviation.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1171
                                NaviData_Deviation.FlyingTime = NaviData.FlyingTime;
1172
                                NaviData_Deviation.FlyingTime = NaviData.FlyingTime;
1172
                                NaviData_Deviation.DistanceToHome = NaviData.HomePositionDeviation.Distance;
1173
                                NaviData_Deviation.DistanceToHome = NaviData.HomePositionDeviation.Distance;
1173
                                NaviData_Deviation.HeadingToHome = NaviData.HomePositionDeviation.Bearing/2;
1174
                                NaviData_Deviation.HeadingToHome = NaviData.HomePositionDeviation.Bearing/2;
1174
                                NaviData_Deviation.DistanceToTarget = NaviData.TargetPositionDeviation.Distance;
1175
                                NaviData_Deviation.DistanceToTarget = NaviData.TargetPositionDeviation.Distance;
1175
                                NaviData_Deviation.HeadingToTarget = NaviData.TargetPositionDeviation.Bearing/2;
1176
                                NaviData_Deviation.HeadingToTarget = NaviData.TargetPositionDeviation.Bearing/2;
1176
                                NaviData_Deviation.AngleNick = NaviData.AngleNick;
1177
                                NaviData_Deviation.AngleNick = NaviData.AngleNick;
1177
                                NaviData_Deviation.AngleRoll = NaviData.AngleRoll;
1178
                                NaviData_Deviation.AngleRoll = NaviData.AngleRoll;
1178
                                NaviData_Deviation.SatsInUse = NaviData.SatsInUse;
1179
                                NaviData_Deviation.SatsInUse = NaviData.SatsInUse;
1179
                            sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Deviation, sizeof(NaviData_Deviation)) + 1;
1180
                            sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Deviation, sizeof(NaviData_Deviation)) + 1;
1180
                                break;
1181
                                break;
1181
                 case 12:
1182
                 case 12:
1182
// belegt 43 ASCII-Zeichen
1183
// belegt 43 ASCII-Zeichen
1183
                                NaviData_Volatile.Index = 16;
1184
                                NaviData_Volatile.Index = 16;
1184
                                NaviData_Volatile.ActualLongitude = NaviData.CurrentPosition.Longitude;
1185
                                NaviData_Volatile.ActualLongitude = NaviData.CurrentPosition.Longitude;
1185
                                NaviData_Volatile.ActualLatitude = NaviData.CurrentPosition.Latitude;
1186
                                NaviData_Volatile.ActualLatitude = NaviData.CurrentPosition.Latitude;
1186
                                NaviData_Volatile.Altimeter = NaviData.Altimeter;
1187
                                NaviData_Volatile.Altimeter = NaviData.Altimeter;
1187
                                NaviData_Volatile.GroundSpeed = NaviData.GroundSpeed / 10;
1188
                                NaviData_Volatile.GroundSpeed = NaviData.GroundSpeed / 10;
1188
                                NaviData_Volatile.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1189
                                NaviData_Volatile.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1189
                                NaviData_Volatile.UBat = FC.BAT_Voltage;
1190
                                NaviData_Volatile.UBat = FC.BAT_Voltage;
1190
                                NaviData_Volatile.Current = NaviData.Current;
1191
                                NaviData_Volatile.Current = NaviData.Current;
1191
                                NaviData_Volatile.UsedCapacity = NaviData.UsedCapacity;
1192
                                NaviData_Volatile.UsedCapacity = NaviData.UsedCapacity;
1192
                                NaviData_Volatile.Variometer = NaviData.Variometer;
1193
                                NaviData_Volatile.Variometer = NaviData.Variometer;
1193
                                NaviData_Volatile.Heading = NaviData.Heading / 2;
1194
                                NaviData_Volatile.Heading = NaviData.Heading / 2;
1194
                                NaviData_Volatile.CompassHeading = NaviData.CompassHeading / 2;
1195
                                NaviData_Volatile.CompassHeading = NaviData.CompassHeading / 2;
1195
                                NaviData_Volatile.Gas = NaviData.Gas;
1196
                                NaviData_Volatile.Gas = NaviData.Gas;
1196
                                NaviData_Volatile.SetpointAltitude = NaviData.SetpointAltitude;
1197
                                NaviData_Volatile.SetpointAltitude = NaviData.SetpointAltitude;
1197
                                sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Volatile, sizeof(NaviData_Volatile)) + 1;
1198
                                sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Volatile, sizeof(NaviData_Volatile)) + 1;
1198
                        break;
1199
                        break;
1199
                 case 13:
1200
                 case 13:
1200
// belegt 27 ASCII-Zeichen
1201
// belegt 27 ASCII-Zeichen
1201
                                NaviData_Tiny.Index = 10;
1202
                                NaviData_Tiny.Index = 10;
1202
                                NaviData_Tiny.ActualLongitude = NaviData.CurrentPosition.Longitude;
1203
                                NaviData_Tiny.ActualLongitude = NaviData.CurrentPosition.Longitude;
1203
                                NaviData_Tiny.ActualLatitude = NaviData.CurrentPosition.Latitude;
1204
                                NaviData_Tiny.ActualLatitude = NaviData.CurrentPosition.Latitude;
1204
                                NaviData_Tiny.Altimeter = NaviData.Altimeter;
1205
                                NaviData_Tiny.Altimeter = NaviData.Altimeter;
1205
                                NaviData_Tiny.GroundSpeed = NaviData.GroundSpeed / 10;
1206
                                NaviData_Tiny.GroundSpeed = NaviData.GroundSpeed / 10;
1206
                                NaviData_Tiny.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1207
                                NaviData_Tiny.OSDStatusFlags = (FC.StatusFlags & OSD_FLAG_MASK1) | (FC.StatusFlags2 & OSD_FLAG_MASK2);
1207
                                if(--count_tiny == 0)
1208
                                if(--count_tiny == 0)
1208
                                 {
1209
                                 {
1209
                                        sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Tiny, sizeof(NaviData_Tiny)) + 1;
1210
                                        sent += MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData_Tiny, sizeof(NaviData_Tiny)) + 1;
1210
                                        count_tiny = 200; // just to make sure that it comes sometimes
1211
                                        count_tiny = 200; // just to make sure that it comes sometimes
1211
                                 }
1212
                                 }
1212
                        break;
1213
                        break;
1213
                 default: state = 0;
1214
                 default: state = 0;
1214
                                break;
1215
                                break;
1215
                }
1216
                }
1216
 }
1217
 }
1217
        pause = (sent * 1000) / MaxBytesPerSecond;
1218
        pause = (sent * 1000) / MaxBytesPerSecond;
1218
 
1219
 
1219
        UART1_Request_NaviData = FALSE;
1220
        UART1_Request_NaviData = FALSE;
1220
        LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1221
        LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1221
return(pause);
1222
return(pause);
1222
// Clear at timeout: 
1223
// Clear at timeout: 
1223
// NaviData_WP.WP_Eventchannel
1224
// NaviData_WP.WP_Eventchannel
1224
}
1225
}
1225
 
1226
 
1226
/**************************************************************/
1227
/**************************************************************/
1227
/* Send the answers to incomming commands at the debug uart   */
1228
/* Send the answers to incomming commands at the debug uart   */
1228
/**************************************************************/
1229
/**************************************************************/
1229
void UART1_TransmitTxData(void)
1230
void UART1_TransmitTxData(void)
1230
{
1231
{
1231
static u8 motorindex1 = 255, motorindex2 = 0;
1232
static u8 motorindex1 = 255, motorindex2 = 0;
1232
        if(DebugUART != UART1) return;
1233
        if(DebugUART != UART1) return;
1233
 
1234
 
1234
        if(CheckDelay(UART1_AboTimeOut))
1235
        if(CheckDelay(UART1_AboTimeOut))
1235
        {
1236
        {
1236
                UART1_DebugData_Interval = 0;
1237
                UART1_DebugData_Interval = 0;
1237
                UART1_NaviData_Interval = 0;
1238
                UART1_NaviData_Interval = 0;
1238
                UART1_NaviData_MaxBytes = 0;
1239
                UART1_NaviData_MaxBytes = 0;
1239
                UART1_Data3D_Interval = 0;
1240
                UART1_Data3D_Interval = 0;
1240
                UART1_Display_Interval = 0;
1241
                UART1_Display_Interval = 0;
1241
                UART1_MotorData_Interval = 0;
1242
                UART1_MotorData_Interval = 0;
1242
                UART1_NaviData_Timer = SetDelay(500);
1243
                UART1_NaviData_Timer = SetDelay(500);
1243
                UART1_AboTimeOut = SetDelay(100);
1244
                UART1_AboTimeOut = SetDelay(100);
1244
                TransmitNavigationData(0,1); // clear the CRC values
1245
                TransmitNavigationData(0,1); // clear the CRC values
1245
        }
1246
        }
1246
//if(UART1_NaviData_MaxBytes > 150) UART1_NaviData_MaxBytes = 150;
1247
//if(UART1_NaviData_MaxBytes > 150) UART1_NaviData_MaxBytes = 150;
1247
//UART1_NaviData_MaxBytes = 150;
1248
//UART1_NaviData_MaxBytes = 150;
1248
/*
1249
/*
1249
#define CHK_MIN_INTERVAL(a,b) {if(a && a < b) a = b;}
1250
#define CHK_MIN_INTERVAL(a,b) {if(a && a < b) a = b;}
1250
UART1_NaviData_Interval = 500;
1251
UART1_NaviData_Interval = 500;
1251
CHK_MIN_INTERVAL(UART1_DebugData_Interval,500);
1252
CHK_MIN_INTERVAL(UART1_DebugData_Interval,500);
1252
CHK_MIN_INTERVAL(UART1_NaviData_Interval,1000);
1253
CHK_MIN_INTERVAL(UART1_NaviData_Interval,1000);
1253
CHK_MIN_INTERVAL(UART1_Data3D_Interval,255);
1254
CHK_MIN_INTERVAL(UART1_Data3D_Interval,255);
1254
CHK_MIN_INTERVAL(UART1_Display_Interval,1500);
1255
CHK_MIN_INTERVAL(UART1_Display_Interval,1500);
1255
CHK_MIN_INTERVAL(UART1_MotorData_Interval,750);
1256
CHK_MIN_INTERVAL(UART1_MotorData_Interval,750);
1256
*/
1257
*/
1257
        UART1_Transmit(); // output pending bytes in tx buffer
1258
        UART1_Transmit(); // output pending bytes in tx buffer
1258
        if((UART1_tx_buffer.Locked == TRUE)) return;
1259
        if((UART1_tx_buffer.Locked == TRUE)) return;
1259
 
1260
 
1260
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
1261
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
1261
        {
1262
        {
1262
                s16 ParamValue;
1263
                s16 ParamValue;
1263
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
1264
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
1264
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
1265
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
1265
                UART1_Request_Parameter = FALSE;
1266
                UART1_Request_Parameter = FALSE;
1266
        }
1267
        }
1267
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
1268
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
1268
        {
1269
        {
1269
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
1270
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
1270
                Echo = 0; // reset echo value
1271
                Echo = 0; // reset echo value
1271
                UART1_Request_Echo = FALSE;
1272
                UART1_Request_Echo = FALSE;
1272
        }
1273
        }
1273
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
1274
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
1274
        {
1275
        {
1275
                u8 errorcode = FTP_ERROR_NONE;
1276
                u8 errorcode = FTP_ERROR_NONE;
1276
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
1277
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
1277
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
1278
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
1278
 
1279
 
1279
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
1280
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
1280
                else
1281
                else
1281
                {
1282
                {
1282
                        u8 cmd = FTP_CMD_ERROR;
1283
                        u8 cmd = FTP_CMD_ERROR;
1283
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
1284
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
1284
                }
1285
                }
1285
 
1286
 
1286
                UART1_Request_FTP = FALSE;
1287
                UART1_Request_FTP = FALSE;
1287
        }
1288
        }
1288
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1289
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1289
        {
1290
        {
1290
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
1291
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
1291
                UART1_Request_WritePoint = 0xFF;
1292
                UART1_Request_WritePoint = 0xFF;
1292
        }
1293
        }
1293
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
1294
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
1294
        {
1295
        {
1295
                u8 PointCount = PointList_GetCount();
1296
                u8 PointCount = PointList_GetCount();
1296
                if (UART1_Request_ReadPoint <= PointCount)
1297
                if (UART1_Request_ReadPoint <= PointCount)
1297
                {
1298
                {
1298
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
1299
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
1299
                }
1300
                }
1300
                else
1301
                else
1301
                {
1302
                {
1302
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
1303
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
1303
                }
1304
                }
1304
                UART1_Request_ReadPoint = 0;
1305
                UART1_Request_ReadPoint = 0;
1305
        }
1306
        }
1306
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1307
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
1307
        {
1308
        {
1308
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
1309
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
1309
                UART1_Request_DebugLabel = 0xFF;
1310
                UART1_Request_DebugLabel = 0xFF;
1310
        }
1311
        }
1311
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1312
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1312
        {
1313
        {
1313
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
1314
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
1314
                UART1_ExternalControlConfirmFrame = 0;
1315
                UART1_ExternalControlConfirmFrame = 0;
1315
        }
1316
        }
1316
        else
1317
        else
1317
        if((UART1_NaviData_Interval > 0) && Out1TriggerUpdateNewData && UART1_NaviData_MaxBytes > 200)    // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available
1318
        if((UART1_NaviData_Interval > 0) && Out1TriggerUpdateNewData && UART1_NaviData_MaxBytes > 200)    // (only if the data link can transmit more than 200Bytes per secons) -> it wouldn't fit into the data-flow if there are too few bytes available
1318
         {
1319
         {
1319
          //sent += 
1320
          //sent += 
1320
          SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung
1321
          SendTriggerPos(); // dann passen die 35 Bytes noch ohne Verzögerung
1321
         }
1322
         }
1322
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
1323
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
1323
        {
1324
        {
1324
          u16 time = 0;
1325
          u16 time = 0;
1325
//UART1_NaviData_MaxBytes = 250;
1326
//UART1_NaviData_MaxBytes = 250;
1326
      if(UART1_NaviData_MaxBytes == 0) // Transmit the big NC Data frame
1327
      if(UART1_NaviData_MaxBytes == 0) // Transmit the big NC Data frame
1327
           {
1328
           {
1328
                NaviData.Errorcode = ErrorCode;
1329
                NaviData.Errorcode = ErrorCode;
1329
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
1330
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
1330
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1331
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1331
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1332
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1332
           }
1333
           }
1333
           else
1334
           else
1334
           if(CheckDelay(UART1_NaviData_Timer))
1335
           if(CheckDelay(UART1_NaviData_Timer))
1335
           {
1336
           {
1336
// Wert =  50 -> Sekunden laufen in 2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 3-4s)
1337
// Wert =  50 -> Sekunden laufen in 2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 3-4s)
1337
// Wert = 100 -> Sekunden laufen in 1-2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 2s)
1338
// Wert = 100 -> Sekunden laufen in 1-2 s-Abstand (im Wegpunkteflug mit aktivem Countdown in 2s)
1338
// Wert = 150 -> Sekunden laufen flüssig (im Wegpunkteflug mit aktivem Countdown und gleichzeitig Target verschieben manchmal in 2s)
1339
// Wert = 150 -> Sekunden laufen flüssig (im Wegpunkteflug mit aktivem Countdown und gleichzeitig Target verschieben manchmal in 2s)
1339
// Wert = 200 -> Sekunden laufen flüssig
1340
// Wert = 200 -> Sekunden laufen flüssig
1340
// Wert >= 250 -> optimal 
1341
// Wert >= 250 -> optimal 
1341
//UART1_NaviData_MaxBytes = 45;
1342
//UART1_NaviData_MaxBytes = 45;
1342
            time = TransmitNavigationData(UART1_NaviData_MaxBytes,0);
1343
            time = TransmitNavigationData(UART1_NaviData_MaxBytes,0);
1343
                if(UART1_NaviData_Interval > time) time = UART1_NaviData_Interval;
1344
                if(UART1_NaviData_Interval > time) time = UART1_NaviData_Interval;
1344
                UART1_NaviData_Timer = SetDelay(time);
1345
                UART1_NaviData_Timer = SetDelay(time);
1345
           }
1346
           }
1346
        UART1_Request_NaviData = FALSE;
1347
        UART1_Request_NaviData = FALSE;
1347
        }
1348
        }
1348
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1349
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1349
        {
1350
        {
1350
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1351
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1351
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1352
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1352
                UART1_Request_DebugData = FALSE;
1353
                UART1_Request_DebugData = FALSE;
1353
        }
1354
        }
1354
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1355
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1355
        {
1356
        {
1356
                Data3D.StickNick = FC.StickNick;
1357
                Data3D.StickNick = FC.StickNick;
1357
                Data3D.StickRoll = FC.StickRoll;
1358
                Data3D.StickRoll = FC.StickRoll;
1358
        Data3D.StickYaw = FC.StickYaw;
1359
        Data3D.StickYaw = FC.StickYaw;
1359
        Data3D.StickGas = FC.StickGas;
1360
        Data3D.StickGas = FC.StickGas;
1360
                Data3D.AngleNick = FromFlightCtrl.AngleNick;            // in 0.1 deg
1361
                Data3D.AngleNick = FromFlightCtrl.AngleNick;            // in 0.1 deg
1361
                Data3D.AngleRoll = FromFlightCtrl.AngleRoll;            // in 0.1 deg
1362
                Data3D.AngleRoll = FromFlightCtrl.AngleRoll;            // in 0.1 deg
1362
                Data3D.Heading   = FromFlightCtrl.GyroHeading;          // in 0.1 deg
1363
                Data3D.Heading   = FromFlightCtrl.GyroHeading;          // in 0.1 deg
1363
                Data3D.Altimeter = FC.Altimeter;                                        // in 5cm -> 20 = 1m
1364
                Data3D.Altimeter = FC.Altimeter;                                        // in 5cm -> 20 = 1m
1364
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1365
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1365
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1366
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1366
                UART1_Request_Data3D = FALSE;
1367
                UART1_Request_Data3D = FALSE;
1367
        }
1368
        }
1368
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1369
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1369
        {
1370
        {
1370
                do
1371
                do
1371
                {
1372
                {
1372
                 motorindex1++;
1373
                 motorindex1++;
1373
                 motorindex1%=12;
1374
                 motorindex1%=12;
1374
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1375
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1375
                 if(motorindex1 == motorindex2) break;
1376
                 if(motorindex1 == motorindex2) break;
1376
                }
1377
                }
1377
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1378
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1378
 
1379
 
1379
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1380
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1380
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1381
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1381
                UART1_Request_MotorData = FALSE;
1382
                UART1_Request_MotorData = FALSE;
1382
        }
1383
        }
1383
        else if(UART1_Request_WPLStore)
1384
        else if(UART1_Request_WPLStore)
1384
        {
1385
        {
1385
                /*
1386
                /*
1386
                s8 txt[50];
1387
                s8 txt[50];
1387
                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);
1388
                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);
1388
                UART1_PutString(txt);
1389
                UART1_PutString(txt);
1389
                */
1390
                */
1390
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1391
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1391
                UART1_Request_WPLStore = FALSE;                
1392
                UART1_Request_WPLStore = FALSE;                
1392
        }
1393
        }
1393
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1394
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1394
        {
1395
        {
1395
                CreateNmeaGGA();
1396
                CreateNmeaGGA();
1396
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1397
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1397
                NMEA_Timer = SetDelay(NMEA_Interval);
1398
                NMEA_Timer = SetDelay(NMEA_Interval);
1398
        }
1399
        }
1399
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1400
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1400
        {
1401
        {
1401
          CreateNmeaRMC();
1402
          CreateNmeaRMC();
1402
          Send_NMEA_RMC = FALSE;
1403
          Send_NMEA_RMC = FALSE;
1403
        }
1404
        }
1404
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1405
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1405
        {
1406
        {
1406
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1407
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1407
                UART1_ConfirmFrame = 0;
1408
                UART1_ConfirmFrame = 0;
1408
        }
1409
        }
1409
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1410
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1410
        {
1411
        {
1411
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1412
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1412
                UART1_Request_ExternalControl = FALSE;
1413
                UART1_Request_ExternalControl = FALSE;
1413
        }
1414
        }
1414
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1415
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1415
        {
1416
        {
1416
                if(UART1_DisplayLine > 3)
1417
                if(UART1_DisplayLine > 3)
1417
                {
1418
                {
1418
                        Menu_Update(UART1_DisplayKeys);
1419
                        Menu_Update(UART1_DisplayKeys);
1419
                        UART1_DisplayKeys = 0;
1420
                        UART1_DisplayKeys = 0;
1420
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1421
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1421
                }
1422
                }
1422
                else
1423
                else
1423
                {
1424
                {
1424
                        UART1_DisplayLine = 2;
1425
                        UART1_DisplayLine = 2;
1425
                        sprintf(text,"!!! incompatible !!!");
1426
                        sprintf(text,"!!! incompatible !!!");
1426
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1427
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1427
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1428
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1428
                }
1429
                }
1429
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1430
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1430
                UART1_Request_Display = FALSE;
1431
                UART1_Request_Display = FALSE;
1431
        }
1432
        }
1432
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1433
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1433
        {
1434
        {
1434
                Menu_Update(0);
1435
                Menu_Update(0);
1435
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1436
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1436
                UART1_Request_Display1 = FALSE;
1437
                UART1_Request_Display1 = FALSE;
1437
        }
1438
        }
1438
        else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions
1439
        else if(UART1_Request_VersionInfo == 1 && (UART1_tx_buffer.Locked == FALSE)) // get FC-Versions
1439
        {
1440
        {
1440
                UART_VersionInfo_t version_tmp;
1441
                UART_VersionInfo_t version_tmp;
1441
                version_tmp.SWMajor = FC_Version.Major;
1442
                version_tmp.SWMajor = FC_Version.Major;
1442
                version_tmp.SWMinor = FC_Version.Minor;
1443
                version_tmp.SWMinor = FC_Version.Minor;
1443
                version_tmp.SWPatch = FC_Version.Patch;
1444
                version_tmp.SWPatch = FC_Version.Patch;
1444
                version_tmp.HWMajor = FC_Version.Hardware;
1445
                version_tmp.HWMajor = FC_Version.Hardware;
1445
                version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version 
1446
                version_tmp.HardwareError[0] = 0xff; // tells the KopterTool that it is the FC-version 
1446
                version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version 
1447
                version_tmp.HardwareError[1] = 0xff; // tells the KopterTool that it is the FC-version 
1447
                version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor;
1448
                version_tmp.ProtoMajor = UART_VersionInfo.ProtoMajor;
1448
                version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware;
1449
                version_tmp.BL_Firmware = UART_VersionInfo.BL_Firmware;
1449
                version_tmp.Flags = 0;
1450
                version_tmp.Flags = 0;
1450
                version_tmp.LabelTextCRC = 0;//UART_VersionInfo.DebugTextCRC;
1451
                version_tmp.LabelTextCRC = 0;//UART_VersionInfo.DebugTextCRC;
1451
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp));
1452
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&version_tmp, sizeof(version_tmp));
1452
                UART1_Request_VersionInfo = FALSE;
1453
                UART1_Request_VersionInfo = FALSE;
1453
        }
1454
        }
1454
        else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions
1455
        else if(UART1_Request_VersionInfo == 2 && (UART1_tx_buffer.Locked == FALSE)) // get NC-Versions
1455
        {
1456
        {
1456
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1457
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1457
                UART1_Request_VersionInfo = FALSE;
1458
                UART1_Request_VersionInfo = FALSE;
1458
        }
1459
        }
1459
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1460
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1460
        {
1461
        {
1461
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1462
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1462
                UART1_Request_SystemTime = FALSE;
1463
                UART1_Request_SystemTime = FALSE;
1463
        }
1464
        }
1464
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1465
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1465
        {
1466
        {
1466
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1467
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1467
                UART1_Request_ErrorMessage = FALSE;
1468
                UART1_Request_ErrorMessage = FALSE;
1468
        }
1469
        }
1469
        else if(UART1_Request_PPM_Channels && (UART1_tx_buffer.Locked == FALSE))
1470
        else if(UART1_Request_PPM_Channels && (UART1_tx_buffer.Locked == FALSE))
1470
        {
1471
        {
-
 
1472
                s16 ppm_tmp[MAX_RC_IN], i;
-
 
1473
                for(i=0; i<MAX_RC_IN;i++) ppm_tmp[i] = PPM_In[i]; // because the serial Data expects s16
1471
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'P', NC_ADDRESS, 1, (u8 *)&PPM_In, sizeof(PPM_In));
1474
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'P', NC_ADDRESS, 1, (u8 *)&ppm_tmp, sizeof(ppm_tmp));
1472
                UART1_Request_PPM_Channels = FALSE;
1475
                UART1_Request_PPM_Channels = FALSE;
1473
        }
1476
        }
1474
        else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE))
1477
        else if(UART1_Request_LicenseString && (UART1_tx_buffer.Locked == FALSE))
1475
        {
1478
        {
1476
                u8 result = 1, cmd = 0;
1479
                u8 result = 1, cmd = 0;
1477
                if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE)  
1480
                if(UART1_Request_LicenseString == LIC_CMD_READ_LICENSE)  
1478
                {
1481
                {
1479
                  result = LIC_CMD_READ_LICENSE;
1482
                  result = LIC_CMD_READ_LICENSE;
1480
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE);
1483
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &result, 1, LicensePtr, LICENSE_SIZE);
1481
                }
1484
                }
1482
                else
1485
                else
1483
                if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1486
                if((UART1_Request_LicenseString == LIC_CMD_ERASE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1484
                 {
1487
                 {
1485
                  result = LIC_CMD_ERASE_LICENSE;
1488
                  result = LIC_CMD_ERASE_LICENSE;
1486
                  DeleteLicenseInEEPROM();
1489
                  DeleteLicenseInEEPROM();
1487
                  CheckLicense(GET_LICENSE);
1490
                  CheckLicense(GET_LICENSE);
1488
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1);
1491
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 1, &result, 1);
1489
                 }
1492
                 }
1490
                else
1493
                else
1491
                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1494
                if((UART1_Request_LicenseString == LIC_CMD_WRITE_LICENSE) && !(FC.StatusFlags & FC_STATUS_MOTOR_RUN) && (UART_VersionInfo.HWMajor >= 20))
1492
                {
1495
                {
1493
                  cmd = LIC_CMD_WRITE_LICENSE;
1496
                  cmd = LIC_CMD_WRITE_LICENSE;
1494
                  if(CheckLicense(CHECK_ONLY))  //new license is okay
1497
                  if(CheckLicense(CHECK_ONLY))  //new license is okay
1495
                  {
1498
                  {
1496
                   WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL);
1499
                   WriteLicenseToEEPROM(EEPROM_LICENSE_DATA_KOMPATIBEL);
1497
                   result = 1;
1500
                   result = 1;
1498
                  }
1501
                  }
1499
                  else //new license is NOT okay
1502
                  else //new license is NOT okay
1500
                  {
1503
                  {
1501
                   ClearLicenseText();
1504
                   ClearLicenseText();
1502
                   result = 0;
1505
                   result = 0;
1503
                   CheckLicense(GET_LICENSE);  // fetch a license if available
1506
                   CheckLicense(GET_LICENSE);  // fetch a license if available
1504
                  }
1507
                  }
1505
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 );
1508
                  MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'M', NC_ADDRESS, 2, &cmd, 1,&result, 1 );
1506
                }
1509
                }
1507
                UART1_Request_LicenseString = 0;
1510
                UART1_Request_LicenseString = 0;
1508
        }
1511
        }
1509
#ifdef FOLLOW_ME
1512
#ifdef FOLLOW_ME
1510
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1513
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1511
        {
1514
        {
1512
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1515
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1513
                {
1516
                {
1514
                        TransmitAlsoToFC = 1;
1517
                        TransmitAlsoToFC = 1;
1515
                        // update FollowMe content
1518
                        // update FollowMe content
1516
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1519
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1517
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1520
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1518
                        FollowMe.Position.Status = NEWDATA;
1521
                        FollowMe.Position.Status = NEWDATA;
1519
                        FollowMe.Position.Altitude = 1;
1522
                        FollowMe.Position.Altitude = 1;
1520
                        // 0  -> no Orientation
1523
                        // 0  -> no Orientation
1521
                        // 1-360 -> CompassCourse Setpoint
1524
                        // 1-360 -> CompassCourse Setpoint
1522
                        // -1 -> points to  WP1 -> itself
1525
                        // -1 -> points to  WP1 -> itself
1523
                FollowMe.Heading = -1;
1526
                FollowMe.Heading = -1;
1524
                        FollowMe.ToleranceRadius = 1;
1527
                        FollowMe.ToleranceRadius = 1;
1525
                        FollowMe.HoldTime = 60;
1528
                        FollowMe.HoldTime = 60;
1526
                        FollowMe.Event_Flag = 1;
1529
                        FollowMe.Event_Flag = 1;
1527
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1530
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1528
                        FollowMe.Type = POINT_TYPE_WP;
1531
                        FollowMe.Type = POINT_TYPE_WP;
1529
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1532
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1530
                        FollowMe.AltitudeRate = 0;                        // do not change height
1533
                        FollowMe.AltitudeRate = 0;                        // do not change height
1531
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1534
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1532
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1535
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1533
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1536
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1534
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1537
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1535
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1538
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1536
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1539
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1537
                        FollowMe.reserve[0] = 0;                // reserve
1540
                        FollowMe.reserve[0] = 0;                // reserve
1538
                        FollowMe.reserve[1] = 0;                // reserve
1541
                        FollowMe.reserve[1] = 0;                // reserve
1539
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1542
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1540
                }
1543
                }
1541
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1544
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1542
        }
1545
        }
1543
#endif
1546
#endif
1544
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1547
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1545
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1548
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1546
        {
1549
        {
1547
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1550
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1548
                SendDebugOutput = 0;
1551
                SendDebugOutput = 0;
1549
        }
1552
        }
1550
#endif
1553
#endif
1551
        UART1_Transmit(); // output pending bytes in tx buffer
1554
        UART1_Transmit(); // output pending bytes in tx buffer
1552
}
1555
}
1553
 
1556
 
1554
 
1557