Subversion Repositories NaviCtrl

Rev

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

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