Subversion Repositories NaviCtrl

Rev

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

Rev 496 Rev 497
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
 
83
 
84
 
84
 
85
#define FALSE   0
85
#define FALSE   0
86
#define TRUE    1
86
#define TRUE    1
87
 
87
 
88
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
88
#define ABO_TIMEOUT 8000 // disable abo after 8 seconds
89
u32 UART1_AboTimeOut = 0;
89
u32 UART1_AboTimeOut = 0;
90
 
90
 
91
u8 UART1_Request_VersionInfo    = FALSE;
91
u8 UART1_Request_VersionInfo    = FALSE;
92
u8 UART1_Request_ExternalControl= FALSE;
92
u8 UART1_Request_ExternalControl= FALSE;
93
u8 UART1_Request_Display                = FALSE;
93
u8 UART1_Request_Display                = FALSE;
94
u8 UART1_Request_Display1               = FALSE;
94
u8 UART1_Request_Display1               = FALSE;
95
u8 UART1_Request_DebugData              = FALSE;
95
u8 UART1_Request_DebugData              = FALSE;
96
u8 UART1_Request_DebugLabel             = 255;
96
u8 UART1_Request_DebugLabel             = 255;
97
u8 UART1_Request_NaviData               = FALSE;
97
u8 UART1_Request_NaviData               = FALSE;
98
u8 UART1_Request_ErrorMessage   = FALSE;
98
u8 UART1_Request_ErrorMessage   = FALSE;
99
u8 UART1_Request_WritePoint             = 0xFF;
99
u8 UART1_Request_WritePoint             = 0xFF;
100
u8 UART1_Request_ReadPoint              = 0;
100
u8 UART1_Request_ReadPoint              = 0;
101
u8 UART1_Request_Data3D             = FALSE;
101
u8 UART1_Request_Data3D             = FALSE;
102
u8 UART1_Request_MotorData          = FALSE;
102
u8 UART1_Request_MotorData          = FALSE;
103
u8 UART1_Request_Echo               = FALSE;
103
u8 UART1_Request_Echo               = FALSE;
104
u8 UART1_Request_ParameterId    = 0;
104
u8 UART1_Request_ParameterId    = 0;
105
u8 UART1_Request_WPLStore               = FALSE;
105
u8 UART1_Request_WPLStore               = FALSE;
106
u8 UART1_Request_Parameter              = FALSE;
106
u8 UART1_Request_Parameter              = FALSE;
107
u8 UART1_Request_SystemTime             = FALSE;
107
u8 UART1_Request_SystemTime             = FALSE;
108
u8 UART1_DisplayKeys                    = 0;
108
u8 UART1_DisplayKeys                    = 0;
109
u8 UART1_DisplayLine                    = 0;
109
u8 UART1_DisplayLine                    = 0;
110
u8 UART1_ConfirmFrame                   = 0;
110
u8 UART1_ConfirmFrame                   = 0;
111
u8 UART1_Request_FTP                    = FALSE;
111
u8 UART1_Request_FTP                    = FALSE;
112
u8 LastTransmittedFCStatusFlags2 = 0;
112
u8 LastTransmittedFCStatusFlags2 = 0;
113
u8 UART1_ExternalControlConfirmFrame = FALSE;
113
u8 UART1_ExternalControlConfirmFrame = FALSE;
114
u8 Send_NMEA_RMC = FALSE;
114
u8 Send_NMEA_RMC = FALSE;
115
 
115
 
116
UART_TypeDef *DebugUART = UART1;
116
UART_TypeDef *DebugUART = UART1;
117
 
117
 
118
#ifdef FOLLOW_ME
118
#ifdef FOLLOW_ME
119
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
119
#define FOLLOW_ME_INTERVAL 200 // 5 Hz
120
u32 UART1_FollowMe_Timer        = 0;
120
u32 UART1_FollowMe_Timer        = 0;
121
Point_t FollowMe;
121
Point_t FollowMe;
122
#endif
122
#endif
123
 
123
 
124
// the primary rx fifo
124
// the primary rx fifo
125
#define UART1_RX_FIFO_LEN 1024
125
#define UART1_RX_FIFO_LEN 1024
126
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
126
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
127
fifo_t UART1_rx_fifo;
127
fifo_t UART1_rx_fifo;
128
 
128
 
129
// the rx buffer
129
// the rx buffer
130
#define UART1_RX_BUFFER_LEN  1024
130
#define UART1_RX_BUFFER_LEN  1024
131
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
131
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
132
Buffer_t UART1_rx_buffer;
132
Buffer_t UART1_rx_buffer;
133
 
133
 
134
// the tx buffer
134
// the tx buffer
135
#define UART1_TX_BUFFER_LEN  1024
135
#define UART1_TX_BUFFER_LEN  1024
136
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
136
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
137
Buffer_t UART1_tx_buffer;
137
Buffer_t UART1_tx_buffer;
138
 
138
 
139
volatile u8 SerialLinkOkay = 0;
139
volatile u8 SerialLinkOkay = 0;
140
 
140
 
141
u8 text[200];
141
u8 text[200];
142
 
142
 
143
const u8 ANALOG_LABEL[32][16] =
143
const u8 ANALOG_LABEL[32][16] =
144
{
144
{
145
   //1234567890123456
145
   //1234567890123456
146
        "AngleNick       ", //0
146
        "AngleNick       ", //0
147
        "AngleRoll       ",
147
        "AngleRoll       ",
148
        "AccNick         ",
148
        "AccNick         ",
149
        "AccRoll         ",
149
        "AccRoll         ",
150
        "OperatingRadius ",
150
        "OperatingRadius ",
151
        "FC-Flags        ", //5
151
        "FC-Flags        ", //5
152
        "NC-Flags        ",
152
        "NC-Flags        ",
153
        "Voltage  [0,1V] ",
153
        "Voltage  [0,1V] ",
154
        "Current  [0,1A] ",
154
        "Current  [0,1A] ",
155
        "GPS Data        ",
155
        "GPS Data        ",
156
        "CompassHeading  ", //10
156
        "CompassHeading  ", //10
157
        "GyroHeading     ",
157
        "GyroHeading     ",
158
        "SPI Error       ", // achtung: muss auf 12 bleiben
158
        "SPI Error       ", // achtung: muss auf 12 bleiben
159
        "SPI Okay        ",
159
        "SPI Okay        ",
160
        "I2C Error       ",
160
        "I2C Error       ",
161
        "I2C Okay        ", //15
161
        "I2C Okay        ", //15
162
        "16              ",
162
        "16              ",
163
        "17              ",
163
        "17              ",
164
        "18              ",
164
        "18              ",
165
        "19              ", // SD-Card-time
165
        "19              ", // SD-Card-time
166
        "EarthMagnet [%] ", //20
166
        "EarthMagnet [%] ", //20
167
        "Ground Speed    ", //  "Z_Speed         ",
167
        "Ground Speed    ", //  "Z_Speed         ",
168
        "N_Speed         ",
168
        "N_Speed         ",
169
        "E_Speed         ",
169
        "E_Speed         ",
170
        "Magnet X        ",
170
        "Magnet X        ",
171
        "Magnet Y        ", //25
171
        "Magnet Y        ", //25
172
        "Magnet Z        ",
172
        "Magnet Z        ",
173
        "Distance N      ",
173
        "Distance N      ",
174
        "Distance E      ",
174
        "Distance E      ",
175
        "GPS_Nick        ",
175
        "GPS_Nick        ",
176
        "GPS_Roll        ", //30
176
        "GPS_Roll        ", //30
177
        "Used_Sats       "
177
        "Used_Sats       "
178
};
178
};
179
 
179
 
180
typedef struct
180
typedef struct
181
{
181
{
182
        u8 Index;
182
        u8 Index;
183
        u8 Status;
183
        u8 Status;
184
} __attribute__((packed)) WPL_Answer_t;
184
} __attribute__((packed)) WPL_Answer_t;
185
WPL_Answer_t WPL_Answer;
185
WPL_Answer_t WPL_Answer;
186
 
186
 
187
DebugOut_t DebugOut;
187
DebugOut_t DebugOut;
188
ExternControl_t ExternControl;
188
ExternControl_t ExternControl;
189
UART_VersionInfo_t UART_VersionInfo;
189
UART_VersionInfo_t UART_VersionInfo;
190
NaviData_t NaviData;
190
NaviData_t NaviData;
191
Data3D_t Data3D;
191
Data3D_t Data3D;
192
 
192
 
193
u16 Echo; // 2 bytes recieved will be sent back as echo
193
u16 Echo; // 2 bytes recieved will be sent back as echo
194
 
194
 
195
u32 UART1_DebugData_Timer = 0;
195
u32 UART1_DebugData_Timer = 0;
196
u32 UART1_DebugData_Interval = 0;       // in ms
196
u32 UART1_DebugData_Interval = 0;       // in ms
197
u32 UART1_NaviData_Timer = 0;
197
u32 UART1_NaviData_Timer = 0;
198
u32 UART1_NaviData_Interval = 0;        // in ms
198
u32 UART1_NaviData_Interval = 0;        // in ms
199
u32 UART1_Data3D_Timer = 0;
199
u32 UART1_Data3D_Timer = 0;
200
u32 UART1_Data3D_Interval = 0;          // in ms
200
u32 UART1_Data3D_Interval = 0;          // in ms
201
u32 UART1_MotorData_Timer = 0;
201
u32 UART1_MotorData_Timer = 0;
202
u32 UART1_MotorData_Interval = 0;               // in ms
202
u32 UART1_MotorData_Interval = 0;               // in ms
203
u32 UART1_Display_Timer = 0;
203
u32 UART1_Display_Timer = 0;
204
u32 UART1_Display_Interval = 0;         // in ms
204
u32 UART1_Display_Interval = 0;         // in ms
205
u32 NMEA_Timer = 0;
205
u32 NMEA_Timer = 0;
206
u32 NMEA_Interval = 500;// in ms
206
u32 NMEA_Interval = 500;// in ms
207
 
207
 
208
/********************************************************/
208
/********************************************************/
209
/*            Initialization the UART1                  */
209
/*            Initialization the UART1                  */
210
/********************************************************/
210
/********************************************************/
211
void UART1_Init (void)
211
void UART1_Init (void)
212
{
212
{
213
        GPIO_InitTypeDef GPIO_InitStructure;
213
        GPIO_InitTypeDef GPIO_InitStructure;
214
        UART_InitTypeDef UART_InitStructure;
214
        UART_InitTypeDef UART_InitStructure;
215
 
215
 
216
        // initialize txd buffer
216
        // initialize txd buffer
217
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
217
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
218
 
218
 
219
        // initialize rxd buffer
219
        // initialize rxd buffer
220
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
220
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
221
 
221
 
222
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
222
        // initialize the rx fifo, block UART IRQ geting a byte from fifo
223
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
223
        fifo_init(&UART1_rx_fifo, UART1_rxfifobuffer, UART1_RX_FIFO_LEN, NO_ITLine, UART1_ITLine);
224
 
224
 
225
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
225
        SCU_APBPeriphClockConfig(__UART1, ENABLE);  // Enable the UART1 Clock
226
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
226
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
227
 
227
 
228
        /*Configure UART1_Rx pin GPIO3.2*/
228
        /*Configure UART1_Rx pin GPIO3.2*/
229
        GPIO_StructInit(&GPIO_InitStructure);
229
        GPIO_StructInit(&GPIO_InitStructure);
230
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
230
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
231
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
231
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_2;
232
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
232
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
233
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
233
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
234
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
234
        GPIO_InitStructure.GPIO_Alternate =     GPIO_InputAlt1; // UART1_RxD
235
        GPIO_Init(GPIO3, &GPIO_InitStructure);
235
        GPIO_Init(GPIO3, &GPIO_InitStructure);
236
 
236
 
237
        /*Configure UART1_Tx pin GPIO3.3*/
237
        /*Configure UART1_Tx pin GPIO3.3*/
238
        GPIO_StructInit(&GPIO_InitStructure);
238
        GPIO_StructInit(&GPIO_InitStructure);
239
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
239
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
240
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
240
        GPIO_InitStructure.GPIO_Pin =                   GPIO_Pin_3;
241
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
241
        GPIO_InitStructure.GPIO_Type =                  GPIO_Type_PushPull;
242
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
242
        GPIO_InitStructure.GPIO_Alternate =     GPIO_OutputAlt2; // UART1_TX
243
        GPIO_Init(GPIO3, &GPIO_InitStructure);
243
        GPIO_Init(GPIO3, &GPIO_InitStructure);
244
 
244
 
245
        /* UART1 configured as follow:
245
        /* UART1 configured as follow:
246
        - Word Length = 8 Bits
246
        - Word Length = 8 Bits
247
        - One Stop Bit
247
        - One Stop Bit
248
        - No parity
248
        - No parity
249
        - BaudRate = 57600 baud
249
        - BaudRate = 57600 baud
250
        - Hardware flow control Disabled
250
        - Hardware flow control Disabled
251
        - Receive and transmit enabled
251
        - Receive and transmit enabled
252
        - Receive and transmit FIFOs are Disabled
252
        - Receive and transmit FIFOs are Disabled
253
        */
253
        */
254
        UART_StructInit(&UART_InitStructure);
254
        UART_StructInit(&UART_InitStructure);
255
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
255
        UART_InitStructure.UART_WordLength =                    UART_WordLength_8D;
256
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
256
        UART_InitStructure.UART_StopBits =                              UART_StopBits_1;
257
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
257
        UART_InitStructure.UART_Parity =                                UART_Parity_No ;
258
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
258
        UART_InitStructure.UART_BaudRate =                              UART1_BAUD_RATE;
259
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
259
        UART_InitStructure. UART_HardwareFlowControl =  UART_HardwareFlowControl_None;
260
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
260
        UART_InitStructure.UART_Mode =                                  UART_Mode_Tx_Rx;
261
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
261
        UART_InitStructure.UART_FIFO =                                  UART_FIFO_Enable;
262
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
262
        UART_InitStructure.UART_TxFIFOLevel =                   UART_FIFOLevel_1_2;
263
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
263
        UART_InitStructure.UART_RxFIFOLevel =                   UART_FIFOLevel_1_2;      // FIFO size 16 bytes, FIFO level 8 bytes
264
 
264
 
265
        UART_DeInit(UART1); // reset uart 1     to default
265
        UART_DeInit(UART1); // reset uart 1     to default
266
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
266
        UART_Init(UART1, &UART_InitStructure); // initialize uart 1
267
        // enable uart 1 interrupts selective
267
        // enable uart 1 interrupts selective
268
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
268
        UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
269
        UART_Cmd(UART1, ENABLE); // enable uart 1
269
        UART_Cmd(UART1, ENABLE); // enable uart 1
270
        // configure the uart 1 interupt line
270
        // configure the uart 1 interupt line
271
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
271
        VIC_Config(UART1_ITLine, VIC_IRQ, PRIORITY_UART1);
272
        // enable the uart 1 IRQ
272
        // enable the uart 1 IRQ
273
        VIC_ITCmd(UART1_ITLine, ENABLE);
273
        VIC_ITCmd(UART1_ITLine, ENABLE);
274
 
274
 
275
        // initialize the debug timer
275
        // initialize the debug timer
276
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
276
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
277
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
277
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
278
        NMEA_Timer = SetDelay(14000);
278
        NMEA_Timer = SetDelay(14000);
279
 
279
 
280
        // Fill Version Info Structure
280
        // Fill Version Info Structure
281
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
281
        UART_VersionInfo.SWMajor = VERSION_MAJOR;
282
        UART_VersionInfo.SWMinor = VERSION_MINOR;
282
        UART_VersionInfo.SWMinor = VERSION_MINOR;
283
        UART_VersionInfo.SWPatch = VERSION_PATCH;
283
        UART_VersionInfo.SWPatch = VERSION_PATCH;
284
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
284
        UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
285
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
285
        UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
286
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
286
    UART_VersionInfo.HWMajor = Version_HW & 0x7F;
287
    UART_VersionInfo.reserved2 = 0;
287
    UART_VersionInfo.reserved2 = 0;
288
        UART_VersionInfo.Flags = 0;
288
        UART_VersionInfo.Flags = 0;
289
        NaviData.Version = NAVIDATA_VERSION;
289
        NaviData.Version = NAVIDATA_VERSION;
290
 
290
 
291
        UART1_PutString("\r\n UART1 init...ok");
291
        UART1_PutString("\r\n UART1 init...ok");
292
}
292
}
293
 
293
 
294
 
294
 
295
/****************************************************************/
295
/****************************************************************/
296
/*               USART1 receiver ISR                            */
296
/*               USART1 receiver ISR                            */
297
/****************************************************************/
297
/****************************************************************/
298
void UART1_IRQHandler(void)
298
void UART1_IRQHandler(void)
299
{
299
{
300
        static u8 abortState = 0;
300
        static u8 abortState = 0;
301
        u8 c;
301
        u8 c;
302
 
302
 
303
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
303
        if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) )
304
        {
304
        {
305
                // clear the pending bits!
305
                // clear the pending bits!
306
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
306
                UART_ClearITPendingBit(UART1, UART_IT_Receive);
307
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
307
                UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut);
308
                // if debug UART is not UART1
308
                // if debug UART is not UART1
309
                if (DebugUART != UART1)
309
                if (DebugUART != UART1)
310
                {       // forward received data to the debug UART tx buffer
310
                {       // forward received data to the debug UART tx buffer
311
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
311
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
312
                        {
312
                        {
313
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
313
                                // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART
314
                                c = UART_ReceiveData(UART1);
314
                                c = UART_ReceiveData(UART1);
315
 
315
 
316
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
316
                                // check for abort condition (ESC ESC 0x55 0xAA 0x00)
317
                                switch (abortState)
317
                                switch (abortState)
318
                                {
318
                                {
319
                                        case 0:
319
                                        case 0:
320
                                                if (c == 27) abortState++;
320
                                                if (c == 27) abortState++;
321
                                                break;
321
                                                break;
322
                                        case 1:
322
                                        case 1:
323
                                                if (c == 27) abortState++;
323
                                                if (c == 27) abortState++;
324
                                                else abortState = 0;
324
                                                else abortState = 0;
325
                                        break;
325
                                        break;
326
                                        case 2:
326
                                        case 2:
327
                                                if (c == 0x55) abortState++;
327
                                                if (c == 0x55) abortState++;
328
                                                else abortState = 0;
328
                                                else abortState = 0;
329
                                                break;
329
                                                break;
330
                                        case 3:
330
                                        case 3:
331
                                                if (c == 0xAA) abortState++;
331
                                                if (c == 0xAA) abortState++;
332
                                                else abortState = 0;
332
                                                else abortState = 0;
333
                                                break;
333
                                                break;
334
                                        case 4:
334
                                        case 4:
335
                                                if (c == 0x00)
335
                                                if (c == 0x00)
336
                                                {
336
                                                {
337
                                                        if(DebugUART == UART0)
337
                                                        if(DebugUART == UART0)
338
                                                        {
338
                                                        {
339
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
339
                                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
340
                                                                TIMER2_Init(); // enbable servo outputs
340
                                                                TIMER2_Init(); // enbable servo outputs
341
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
341
                                                                fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
342
                                                        }
342
                                                        }
343
                                                        DebugUART = UART1;
343
                                                        DebugUART = UART1;
344
                                                }
344
                                                }
345
                                                abortState = 0;
345
                                                abortState = 0;
346
                                                break;
346
                                                break;
347
                                } // end switch abort state
347
                                } // end switch abort state
348
                                // if the Debug uart is not UART1, redirect input to the Debug UART
348
                                // if the Debug uart is not UART1, redirect input to the Debug UART
349
                                if (DebugUART != UART1)
349
                                if (DebugUART != UART1)
350
                                {
350
                                {
351
                                        // wait for space in the tx buffer of the DebugUART
351
                                        // wait for space in the tx buffer of the DebugUART
352
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
352
                                        while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {};
353
                                        // move byte to the tx fifo of the debug uart
353
                                        // move byte to the tx fifo of the debug uart
354
                                        UART_SendData(DebugUART, c);
354
                                        UART_SendData(DebugUART, c);
355
                                }
355
                                }
356
                        }
356
                        }
357
                }
357
                }
358
                else  // DebugUART == UART1 (normal operation)
358
                else  // DebugUART == UART1 (normal operation)
359
                {
359
                {
360
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
360
                        while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
361
                        { // some byes in the hardware fifo
361
                        { // some byes in the hardware fifo
362
                            // get byte from hardware fifo
362
                            // get byte from hardware fifo
363
                        c = UART_ReceiveData(UART1);
363
                        c = UART_ReceiveData(UART1);
364
                                // put into the software fifo
364
                                // put into the software fifo
365
                                if(!fifo_put(&UART1_rx_fifo, c))
365
                                if(!fifo_put(&UART1_rx_fifo, c))
366
                                {       // fifo overflow
366
                                {       // fifo overflow
367
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
367
                                        //fifo_purge(&UART1_rx_fifo); // flush the whole buffer
368
                                }
368
                                }
369
                        } // EOF while some byes in the hardware fifo
369
                        } // EOF while some byes in the hardware fifo
370
                } // eof DebugUart = UART1
370
                } // eof DebugUart = UART1
371
        }
371
        }
372
 
372
 
373
 
373
 
374
 
374
 
375
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
375
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
376
}
376
}
377
 
377
 
378
/**************************************************************/
378
/**************************************************************/
379
/* Process incomming data from debug uart                     */
379
/* Process incomming data from debug uart                     */
380
/**************************************************************/
380
/**************************************************************/
381
void UART1_ProcessRxData(void)
381
void UART1_ProcessRxData(void)
382
{
382
{
383
        // return on forwarding uart  or unlocked rx buffer
383
        // return on forwarding uart  or unlocked rx buffer
384
        u8 c;
384
        u8 c;
385
        if(DebugUART != UART1) return;
385
        if(DebugUART != UART1) return;
386
        // if rx buffer is not locked
386
        // if rx buffer is not locked
387
        if(UART1_rx_buffer.Locked == FALSE)
387
        if(UART1_rx_buffer.Locked == FALSE)
388
        {
388
        {
389
                //collect data from primary rx fifo
389
                //collect data from primary rx fifo
390
                while(fifo_get(&UART1_rx_fifo, &c))
390
                while(fifo_get(&UART1_rx_fifo, &c))
391
                {
391
                {
392
                        // break if complete frame is collected
392
                        // break if complete frame is collected
393
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
393
                        if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
394
                }
394
                }
395
        }
395
        }
396
        if(UART1_rx_buffer.Locked == FALSE) return;
396
        if(UART1_rx_buffer.Locked == FALSE) return;
397
 
397
 
398
        Point_t * pPoint = NULL;
398
        Point_t * pPoint = NULL;
399
        SerialMsg_t SerialMsg;
399
        SerialMsg_t SerialMsg;
400
 
400
 
401
        // analyze header first
401
        // analyze header first
402
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
402
        MKProtocol_DecodeSerialFrameHeader(&UART1_rx_buffer, &SerialMsg);
403
        if( SerialMsg.Address == FC_ADDRESS )
403
        if( SerialMsg.Address == FC_ADDRESS )
404
        {
404
        {
405
                switch(SerialMsg.CmdID)
405
                switch(SerialMsg.CmdID)
406
                {
406
                {
407
//                      case 'v': // version
407
//                      case 'v': // version
408
                        case 'b': // extern control
408
                        case 'b': // extern control
409
                                          UART1_ExternalControlConfirmFrame = 1;
409
                                          UART1_ExternalControlConfirmFrame = 1;
410
                        case 'y': // serial poti values
410
                        case 'y': // serial poti values
411
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
411
                                Buffer_Copy(&UART1_rx_buffer, &UART2_tx_buffer); //forward to FC
412
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
412
                                Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
413
                                return; //end process rx data
413
                                return; //end process rx data
414
                        break;
414
                        break;
415
                }
415
                }
416
        }
416
        }
417
 
417
 
418
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
418
        MKProtocol_DecodeSerialFrameData(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
419
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
419
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
420
        switch(SerialMsg.Address) // check for Slave Address
420
        switch(SerialMsg.Address) // check for Slave Address
421
        {
421
        {
422
                case NC_ADDRESS:  // own Slave Address
422
                case NC_ADDRESS:  // own Slave Address
423
                switch(SerialMsg.CmdID)
423
                switch(SerialMsg.CmdID)
424
                {
424
                {
425
                        case 't': // request for the GPS time
425
                        case 't': // request for the GPS time
426
                                UART1_Request_SystemTime  = TRUE;
426
                                UART1_Request_SystemTime  = TRUE;
427
                                break;
427
                                break;
428
 
428
 
429
                        case 'f': // ftp command
429
                        case 'f': // ftp command
430
                                UART1_Request_FTP = SerialMsg.pData[0];
430
                                UART1_Request_FTP = SerialMsg.pData[0];
431
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
431
                                //if (UART1_Request_FTP == FTP_CMD_SET_CWD || UART1_Request_FTP == FTP_CMD_GET_FILE)
432
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
432
                                memcpy(&FTP_data, &SerialMsg.pData[1], sizeof(FTP_data)); // copy ftp parameter
433
                        break;
433
                        break;
434
 
434
 
435
                        case 'z': // connection checker
435
                        case 'z': // connection checker
436
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
436
                                memcpy(&Echo, SerialMsg.pData, sizeof(Echo)); // copy echo pattern
437
                                UART1_Request_Echo = TRUE;
437
                                UART1_Request_Echo = TRUE;
438
                                break;
438
                                break;
439
 
439
 
440
                        case 'e': // request for the text of the error status
440
                        case 'e': // request for the text of the error status
441
                                UART1_Request_ErrorMessage = TRUE;
441
                                UART1_Request_ErrorMessage = TRUE;
442
                                break;
442
                                break;
443
 
443
 
444
                        case 's'://  new target position
444
                        case 's'://  new target position
445
                                pPoint = (Point_t*)SerialMsg.pData;
445
                                pPoint = (Point_t*)SerialMsg.pData;
446
                                if(pPoint->Position.Status == NEWDATA)
446
                                if(pPoint->Position.Status == NEWDATA)
447
                                {
447
                                {
448
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
448
                                        //if(!(FC.StatusFlags & FC_STATUS_FLY)) PointList_Clear(); // flush the list
449
                                        //pPoint->Index = 1; // must be one after empty list
449
                                        //pPoint->Index = 1; // must be one after empty list
450
                                        PointList_SetAt(pPoint);
450
                                        PointList_SetAt(pPoint);
451
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
451
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
452
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
452
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
453
                                        if(GPS_pWaypoint != NULL) // if new WP exist
453
                                        if(GPS_pWaypoint != NULL) // if new WP exist
454
                                        {   // update WP hold time stamp immediately!
454
                                        {   // update WP hold time stamp immediately!
455
                                                EnableNewWpHeading();
455
                                                EnableNewWpHeading();
456
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
456
/*                                              if(GPS_pWaypoint->Heading > 0 && GPS_pWaypoint->Heading <= 360)
457
                                                {
457
                                                {
458
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
458
                                                 CAM_Orientation.Azimuth = GPS_pWaypoint->Heading;
459
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
459
                                                 CAM_Orientation.UpdateMask |= CAM_UPDATE_AZIMUTH;
460
                                                }
460
                                                }
461
*/
461
*/
462
                                        }
462
                                        }
463
                                        BeepTime = 50;
463
                                        BeepTime = 50;
464
                                }
464
                                }
465
                                break;
465
                                break;
466
 
466
 
467
                        case 'u': // redirect debug uart
467
                        case 'u': // redirect debug uart
468
                                switch(SerialMsg.pData[0])
468
                                switch(SerialMsg.pData[0])
469
                                {
469
                                {
470
                                        case UART_FLIGHTCTRL:
470
                                        case UART_FLIGHTCTRL:
471
                                                UART2_Init();                           // initialize UART2 to FC pins
471
                                                UART2_Init();                           // initialize UART2 to FC pins
472
                                                fifo_purge(&UART1_rx_fifo);
472
                                                fifo_purge(&UART1_rx_fifo);
473
                                                TIMER2_Deinit();                        // reduce irq load
473
                                                TIMER2_Deinit();                        // reduce irq load
474
                                                DebugUART = UART2;
474
                                                DebugUART = UART2;
475
                                                break;
475
                                                break;
476
                                        case UART_MK3MAG:
476
                                        case UART_MK3MAG:
477
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
477
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
478
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
478
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
479
                                                GPSData.Status = INVALID;
479
                                                GPSData.Status = INVALID;
480
                                                fifo_purge(&UART1_rx_fifo);
480
                                                fifo_purge(&UART1_rx_fifo);
481
                                                DebugUART = UART0;
481
                                                DebugUART = UART0;
482
                                                break;
482
                                                break;
483
                                        case UART_MKGPS:
483
                                        case UART_MKGPS:
484
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
484
                                                if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) break; // not if the motors are running
485
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
485
                                                TIMER2_Deinit();                        // disable servo outputs to reduce irq load
486
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
486
                                                UART0_Connect_to_MKGPS(UART0_BAUD_RATE);        // connect UART0 to MKGPS pins
487
                                                GPSData.Status = INVALID;
487
                                                GPSData.Status = INVALID;
488
                                                fifo_purge(&UART1_rx_fifo);
488
                                                fifo_purge(&UART1_rx_fifo);
489
                                                DebugUART = UART0;
489
                                                DebugUART = UART0;
490
                                                break;
490
                                                break;
491
                                        default:
491
                                        default:
492
                                                break;
492
                                                break;
493
                                }
493
                                }
494
                                break;
494
                                break;
495
 
495
 
496
                        case 'w'://  Set point in list at index
496
                        case 'w'://  Set point in list at index
497
                                {
497
                                {
498
                                        pPoint = (Point_t*)SerialMsg.pData;
498
                                        pPoint = (Point_t*)SerialMsg.pData;
499
 
499
 
500
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
500
                                        if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
501
                                        {
501
                                        {
502
                                                PointList_Clear();
502
                                                PointList_Clear();
503
                                                GPS_pWaypoint = PointList_WPBegin();
503
                                                GPS_pWaypoint = PointList_WPBegin();
504
                                                UART1_Request_WritePoint = 0; // return new point count
504
                                                UART1_Request_WritePoint = 0; // return new point count
505
                                        }
505
                                        }
506
                                        else
506
                                        else
507
                                        {  // update WP in list at index
507
                                        {  // update WP in list at index
508
                                                if(pPoint->Index > MaxNumberOfWaypoints)
508
                                                if(pPoint->Index > MaxNumberOfWaypoints)
509
                                                {
509
                                                {
510
                                                        UART1_Request_WritePoint = 254;
510
                                                        UART1_Request_WritePoint = 254;
511
                                                        pPoint->Index = MaxNumberOfWaypoints;
511
                                                        pPoint->Index = MaxNumberOfWaypoints;
512
                                                }
512
                                                }
513
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
513
                                                else UART1_Request_WritePoint = PointList_SetAt(pPoint);
514
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
514
                                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
515
                                                if(UART1_Request_WritePoint == pPoint->Index)
515
                                                if(UART1_Request_WritePoint == pPoint->Index)
516
                                                {
516
                                                {
517
                                                        BeepTime = 500;
517
                                                        BeepTime = 500;
518
                                                }
518
                                                }
519
                                        }
519
                                        }
520
                                }
520
                                }
521
                                break;
521
                                break;
522
 
522
 
523
                        case 'x'://  Read Waypoint from List
523
                        case 'x'://  Read Waypoint from List
524
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
524
                                UART1_Request_ReadPoint = SerialMsg.pData[0];
525
                                break;
525
                                break;
526
 
526
 
527
                        case 'i':// Store WP List to file
527
                        case 'i':// Store WP List to file
528
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
528
                                memcpy((u8*)&WPL_Store, SerialMsg.pData, sizeof(WPL_Store_t));
529
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
529
                                WPL_Store.Name[11] = 0; // make sure the name string is terminated
530
                                WPL_Answer.Index = WPL_Store.Index; // echo Index
530
                                WPL_Answer.Index = WPL_Store.Index; // echo Index in cmd answer
531
                                WPL_Answer.Status = PointList_SaveToFile(&WPL_Store);
531
                                WPL_Answer.Status = PointList_SaveToFile(&WPL_Store);
532
                                UART1_Request_WPLStore = TRUE;
532
                                UART1_Request_WPLStore = TRUE;
533
                                break;
533
                                break;
534
 
534
 
535
 
535
 
536
                        case 'j':// Set/Get NC-Parameter
536
                        case 'j':// Set/Get NC-Parameter
537
                                switch(SerialMsg.pData[0])
537
                                switch(SerialMsg.pData[0])
538
                                {
538
                                {
539
                                        case 0: // get
539
                                        case 0: // get
540
                                        break;
540
                                        break;
541
 
541
 
542
                                        case 1: // set
542
                                        case 1: // set
543
                                        {
543
                                        {
544
                                                s16 value;
544
                                                s16 value;
545
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
545
                                                value = SerialMsg.pData[2] + (s16)SerialMsg.pData[3] * 0x0100;
546
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
546
                                                NCParams_SetValue(SerialMsg.pData[1], &value);
547
                                        }
547
                                        }
548
                                        break;
548
                                        break;
549
                                       
549
                                       
550
                                        default:
550
                                        default:
551
                                        break;
551
                                        break;
552
                                }
552
                                }
553
                                UART1_Request_ParameterId = SerialMsg.pData[1];
553
                                UART1_Request_ParameterId = SerialMsg.pData[1];
554
                                UART1_Request_Parameter = TRUE;
554
                                UART1_Request_Parameter = TRUE;
555
                                break;
555
                                break;
556
                        default:
556
                        default:
557
                                // unsupported command recieved
557
                                // unsupported command recieved
558
                                break;
558
                                break;
559
                } // case NC_ADDRESS
559
                } // case NC_ADDRESS
560
                // "break;" is missing here to fall thru to the common commands
560
                // "break;" is missing here to fall thru to the common commands
561
 
561
 
562
                default:  // and any other Slave Address
562
                default:  // and any other Slave Address
563
 
563
 
564
                switch(SerialMsg.CmdID) // check CmdID
564
                switch(SerialMsg.CmdID) // check CmdID
565
                {
565
                {
566
                        case 'a':// request for the labels of the analog debug outputs
566
                        case 'a':// request for the labels of the analog debug outputs
567
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
567
                                UART1_Request_DebugLabel = SerialMsg.pData[0];
568
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
568
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
569
                                break;
569
                                break;
570
                        /*
570
                        /*
571
                        case 'b': // submit extern control
571
                        case 'b': // submit extern control
572
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
572
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
573
                                UART1_ConfirmFrame = ExternControl.Frame;
573
                                UART1_ConfirmFrame = ExternControl.Frame;
574
                                break;
574
                                break;
575
                        */
575
                        */
576
                        case 'd': // request for debug data;
576
                        case 'd': // request for debug data;
577
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
577
                                UART1_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
578
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
578
                                if(UART1_DebugData_Interval > 0) UART1_Request_DebugData = TRUE;
579
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
579
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
580
                                break;
580
                                break;
581
 
581
 
582
                        case 'c': // request for 3D data;
582
                        case 'c': // request for 3D data;
583
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
583
                                UART1_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
584
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
584
                                if(UART1_Data3D_Interval > 0) UART1_Request_Data3D = TRUE;
585
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
585
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
586
                                break;
586
                                break;
587
 
587
 
588
                        case 'k': // request for Motor data;
588
                        case 'k': // request for Motor data;
589
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
589
                                UART1_MotorData_Interval = (u32) SerialMsg.pData[0] * 10;
590
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
590
                                if(UART1_MotorData_Interval > 0) UART1_Request_MotorData = TRUE;
591
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
591
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
592
                                break;
592
                                break;
593
 
593
 
594
                        case 'h':// reqest for display line
594
                        case 'h':// reqest for display line
595
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
595
                                if((SerialMsg.pData[0]& 0x80) == 0x00)// old format
596
                                {
596
                                {
597
                                        UART1_DisplayLine = 2;
597
                                        UART1_DisplayLine = 2;
598
                                        UART1_Display_Interval = 0;
598
                                        UART1_Display_Interval = 0;
599
                                }
599
                                }
600
                                else
600
                                else
601
                                {
601
                                {
602
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
602
                                        UART1_DisplayKeys |= ~SerialMsg.pData[0];
603
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
603
                                        UART1_Display_Interval = (u32) SerialMsg.pData[1] * 10;
604
                                        UART1_DisplayLine = 4;
604
                                        UART1_DisplayLine = 4;
605
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
605
                                        UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
606
                                }
606
                                }
607
                                UART1_Request_Display = TRUE;
607
                                UART1_Request_Display = TRUE;
608
                                break;
608
                                break;
609
 
609
 
610
                        case 'l':// reqest for display columns
610
                        case 'l':// reqest for display columns
611
                                MenuItem = SerialMsg.pData[0];
611
                                MenuItem = SerialMsg.pData[0];
612
                                UART1_Request_Display1 = TRUE;
612
                                UART1_Request_Display1 = TRUE;
613
                                break;
613
                                break;
614
 
614
 
615
                        case 'o': // request for navigation information
615
                        case 'o': // request for navigation information
616
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
616
                                UART1_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
617
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
617
                                if(UART1_NaviData_Interval > 0) UART1_Request_NaviData = TRUE;
618
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
618
                                UART1_AboTimeOut = SetDelay(ABO_TIMEOUT);
619
                                break;
619
                                break;
620
 
620
 
621
                        case 'v': // request for version info
621
                        case 'v': // request for version info
622
                                UART1_Request_VersionInfo = TRUE;
622
                                UART1_Request_VersionInfo = TRUE;
623
                                break;
623
                                break;
624
                        default:
624
                        default:
625
                                // unsupported command recieved
625
                                // unsupported command recieved
626
                                break;
626
                                break;
627
                }
627
                }
628
                break; // default:
628
                break; // default:
629
        }
629
        }
630
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
630
        Buffer_Clear(&UART1_rx_buffer); // free rc buffer for next frame
631
}
631
}
632
 
632
 
633
 
633
 
634
/*****************************************************/
634
/*****************************************************/
635
/*                   Send a character                */
635
/*                   Send a character                */
636
/*****************************************************/
636
/*****************************************************/
637
s16 UART1_Putchar(char c)
637
s16 UART1_Putchar(char c)
638
{
638
{
639
        u32 timeout = 10000;
639
        u32 timeout = 10000;
640
        if (c == '\n') UART1_Putchar('\r');
640
        if (c == '\n') UART1_Putchar('\r');
641
        // wait until txd fifo is not full
641
        // wait until txd fifo is not full
642
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
642
        while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET) if(--timeout == 0) return(0);
643
        // transmit byte
643
        // transmit byte
644
        UART_SendData(UART1, c);
644
        UART_SendData(UART1, c);
645
        #ifdef FOLLOW_ME
645
        #ifdef FOLLOW_ME
646
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
646
        if(TransmitAlsoToFC) UART_SendData(UART2, c);
647
        #endif
647
        #endif
648
        return (0);
648
        return (0);
649
}
649
}
650
 
650
 
651
/*****************************************************/
651
/*****************************************************/
652
/*       Send a string to the debug uart              */
652
/*       Send a string to the debug uart              */
653
/*****************************************************/
653
/*****************************************************/
654
void UART1_PutString(u8 *s)
654
void UART1_PutString(u8 *s)
655
{
655
{
656
        if(s == NULL) return;
656
        if(s == NULL) return;
657
        while (*s != '\0' && DebugUART == UART1)
657
        while (*s != '\0' && DebugUART == UART1)
658
        {
658
        {
659
                UART1_Putchar(*s);
659
                UART1_Putchar(*s);
660
                s ++;
660
                s ++;
661
        }
661
        }
662
}
662
}
663
 
663
 
664
 
664
 
665
/**************************************************************/
665
/**************************************************************/
666
/*         Transmit tx buffer via debug uart                  */
666
/*         Transmit tx buffer via debug uart                  */
667
/**************************************************************/
667
/**************************************************************/
668
void UART1_Transmit(void)
668
void UART1_Transmit(void)
669
{
669
{
670
        u8 tmp_tx;
670
        u8 tmp_tx;
671
        if(DebugUART != UART1) return;
671
        if(DebugUART != UART1) return;
672
        // if something has to be send and the txd fifo is not full
672
        // if something has to be send and the txd fifo is not full
673
        if(UART1_tx_buffer.Locked == TRUE)
673
        if(UART1_tx_buffer.Locked == TRUE)
674
        {
674
        {
675
                // while there is some space in the tx fifo
675
                // while there is some space in the tx fifo
676
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
676
                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != SET)
677
                {
677
                {
678
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
678
                        tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
679
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
679
                        UART_SendData(UART1, tmp_tx); // put character to txd fifo
680
                        #ifdef FOLLOW_ME
680
                        #ifdef FOLLOW_ME
681
                        if(TransmitAlsoToFC)
681
                        if(TransmitAlsoToFC)
682
                        {
682
                        {
683
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
683
                                UART_SendData(UART2, tmp_tx); // put character to txd fifo
684
                        }
684
                        }
685
                        #endif
685
                        #endif
686
                        // if terminating character or end of txd buffer reached
686
                        // if terminating character or end of txd buffer reached
687
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
687
                        if((tmp_tx == '\0') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
688
                        {
688
                        {
689
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
689
                                Buffer_Clear(&UART1_tx_buffer); // clear txd buffer
690
                                #ifdef FOLLOW_ME
690
                                #ifdef FOLLOW_ME
691
                                TransmitAlsoToFC = 0;
691
                                TransmitAlsoToFC = 0;
692
                                #endif
692
                                #endif
693
                                break; // end while loop
693
                                break; // end while loop
694
                        }
694
                        }
695
                }
695
                }
696
        }
696
        }
697
}
697
}
698
 
698
 
699
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
699
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
700
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
700
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
701
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
701
//$GPGGA,092120.20,,,,,0,00,99.99,,,,,,*6C
702
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
702
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
703
void CreateNmeaGGA(void)
703
void CreateNmeaGGA(void)
704
{
704
{
705
        u8 array[200], i = 0, crc = 0, x;
705
        u8 array[200], i = 0, crc = 0, x;
706
        s32 tmp1, tmp2;
706
        s32 tmp1, tmp2;
707
 
707
 
708
        i += sprintf(array, "$GPGGA,");
708
        i += sprintf(array, "$GPGGA,");
709
        // +++++++++++++++++++++++++++++++++++++++++++
709
        // +++++++++++++++++++++++++++++++++++++++++++
710
        if(SystemTime.Valid)
710
        if(SystemTime.Valid)
711
        {
711
        {
712
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
712
                i += sprintf(&array[i], "%02d%02d%02d.%02d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec/10);
713
        }
713
        }
714
        else
714
        else
715
        {
715
        {
716
                i += sprintf(&array[i], ",");
716
                i += sprintf(&array[i], ",");
717
        }
717
        }
718
        // +++++++++++++++++++++++++++++++++++++++++++
718
        // +++++++++++++++++++++++++++++++++++++++++++
719
        if(GPSData.Flags & FLAG_GPSFIXOK)
719
        if(GPSData.Flags & FLAG_GPSFIXOK)
720
        {
720
        {
721
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
721
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
722
                i += sprintf(&array[i],"%02d",(s16)tmp1);
722
                i += sprintf(&array[i],"%02d",(s16)tmp1);
723
 
723
 
724
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
724
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
725
                tmp1 *= 6; // in Minuten
725
                tmp1 *= 6; // in Minuten
726
                tmp2 = tmp1 / 1000000L;
726
                tmp2 = tmp1 / 1000000L;
727
                i += sprintf(&array[i],"%02d", (s16)tmp2);
727
                i += sprintf(&array[i],"%02d", (s16)tmp2);
728
                tmp2 = tmp1 % 1000000L;
728
                tmp2 = tmp1 % 1000000L;
729
                tmp2 /= 10; // eine Stelle zu viel
729
                tmp2 /= 10; // eine Stelle zu viel
730
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
730
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
731
 
731
 
732
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
732
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
733
                else i += sprintf(&array[i],"S,");
733
                else i += sprintf(&array[i],"S,");
734
                // +++++++++++++++++++++++++++++++++++++++++++
734
                // +++++++++++++++++++++++++++++++++++++++++++
735
 
735
 
736
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
736
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
737
                i += sprintf(&array[i],"%03d", (s16)tmp1);
737
                i += sprintf(&array[i],"%03d", (s16)tmp1);
738
 
738
 
739
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
739
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
740
                tmp1 *= 6; // in Minuten
740
                tmp1 *= 6; // in Minuten
741
                tmp2 = tmp1 / 1000000L;
741
                tmp2 = tmp1 / 1000000L;
742
                i += sprintf(&array[i],"%02d", (s16)tmp2);
742
                i += sprintf(&array[i],"%02d", (s16)tmp2);
743
                tmp2 = tmp1 % 1000000L;
743
                tmp2 = tmp1 % 1000000L;
744
                tmp2 /= 10; // eine Stelle zu viel
744
                tmp2 /= 10; // eine Stelle zu viel
745
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
745
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
746
 
746
 
747
 
747
 
748
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
748
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
749
                else i += sprintf(&array[i],"W,");
749
                else i += sprintf(&array[i],"W,");
750
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
750
                i += sprintf(&array[i],"%d,",GPSData.SatFix);
751
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
751
                i += sprintf(&array[i],"%d,",GPSData.NumOfSats);
752
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
752
                i += sprintf(&array[i],"%d.%d,",(s16)(GPSData.Position_Accuracy/100),abs(GPSData.Position_Accuracy%100));
753
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
753
                //  i += sprintf(&array[i],"%d.%d,M,",GPSData.Position.Altitude/1000,abs(GPSData.Position.Altitude%1000)/100);
754
                tmp1 = NaviData.Altimeter / 2; // in dm
754
                tmp1 = NaviData.Altimeter / 2; // in dm
755
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
755
                i += sprintf(&array[i],"%d.%d,M,",(s16)tmp1 / 10,abs((s16)tmp1 % 10));
756
                i += sprintf(&array[i],",,,*");
756
                i += sprintf(&array[i],",,,*");
757
        }
757
        }
758
        else
758
        else
759
        {
759
        {
760
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
760
                i += sprintf(&array[i], ",,,,%d,00,99.99,,,,,,*",GPSData.NumOfSats);
761
        }
761
        }
762
        for(x = 1; x < i-1; x++)
762
        for(x = 1; x < i-1; x++)
763
        {
763
        {
764
                crc ^= array[x];
764
                crc ^= array[x];
765
        }
765
        }
766
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
766
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
767
        AddSerialData(&UART1_tx_buffer,array,i);
767
        AddSerialData(&UART1_tx_buffer,array,i);
768
 
768
 
769
        // +++++++++++++++++++++++++++++++++++++++++++
769
        // +++++++++++++++++++++++++++++++++++++++++++
770
}
770
}
771
 
771
 
772
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
772
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
773
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
773
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
774
 
774
 
775
void CreateNmeaRMC(void)
775
void CreateNmeaRMC(void)
776
{
776
{
777
        u8 array[200], i = 0, crc = 0, x;
777
        u8 array[200], i = 0, crc = 0, x;
778
        s16 tmp_int;
778
        s16 tmp_int;
779
        s32 tmp1, tmp2;
779
        s32 tmp1, tmp2;
780
        // +++++++++++++++++++++++++++++++++++++++++++
780
        // +++++++++++++++++++++++++++++++++++++++++++
781
        i += sprintf(array, "$GPRMC,");
781
        i += sprintf(array, "$GPRMC,");
782
        // +++++++++++++++++++++++++++++++++++++++++++
782
        // +++++++++++++++++++++++++++++++++++++++++++
783
        if(SystemTime.Valid)
783
        if(SystemTime.Valid)
784
        {
784
        {
785
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
785
                i += sprintf(&array[i], "%02d%02d%02d.%03d,", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
786
        }
786
        }
787
        else
787
        else
788
        {
788
        {
789
                i += sprintf(&array[i], ",");
789
                i += sprintf(&array[i], ",");
790
        }
790
        }
791
        if(GPSData.Flags & FLAG_GPSFIXOK)
791
        if(GPSData.Flags & FLAG_GPSFIXOK)
792
        {
792
        {
793
                // +++++++++++++++++++++++++++++++++++++++++++
793
                // +++++++++++++++++++++++++++++++++++++++++++
794
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
794
                tmp1 = abs(GPSData.Position.Latitude)/10000000L;
795
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
795
                i += sprintf(&array[i],"A,%02d", (s16)tmp1); // Status: A = Okay  V = Warnung
796
 
796
 
797
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
797
                tmp1 = abs(GPSData.Position.Latitude)%10000000L;
798
                tmp1 *= 6; // in Minuten
798
                tmp1 *= 6; // in Minuten
799
                tmp2 = tmp1 / 1000000L;
799
                tmp2 = tmp1 / 1000000L;
800
                i += sprintf(&array[i],"%02d", (s16)tmp2);
800
                i += sprintf(&array[i],"%02d", (s16)tmp2);
801
                tmp2 = tmp1 % 1000000L;
801
                tmp2 = tmp1 % 1000000L;
802
                tmp2 /= 10; // eine Stelle zu viel
802
                tmp2 /= 10; // eine Stelle zu viel
803
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
803
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
804
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
804
                if(GPSData.Position.Latitude >= 0) i += sprintf(&array[i],"N,");
805
                else i += sprintf(&array[i],"S,");
805
                else i += sprintf(&array[i],"S,");
806
                // +++++++++++++++++++++++++++++++++++++++++++
806
                // +++++++++++++++++++++++++++++++++++++++++++
807
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
807
                tmp1 = abs(GPSData.Position.Longitude)/10000000L;
808
                i += sprintf(&array[i],"%03d", (s16)tmp1);
808
                i += sprintf(&array[i],"%03d", (s16)tmp1);
809
 
809
 
810
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
810
                tmp1 = abs(GPSData.Position.Longitude)%10000000L;
811
                tmp1 *= 6; // in Minuten
811
                tmp1 *= 6; // in Minuten
812
                tmp2 = tmp1 / 1000000L;
812
                tmp2 = tmp1 / 1000000L;
813
                i += sprintf(&array[i],"%02d", (s16)tmp2);
813
                i += sprintf(&array[i],"%02d", (s16)tmp2);
814
                tmp2 = tmp1 % 1000000L;
814
                tmp2 = tmp1 % 1000000L;
815
                tmp2 /= 10; // eine Stelle zu viel
815
                tmp2 /= 10; // eine Stelle zu viel
816
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
816
                i += sprintf(&array[i],".%05d,", (s16)tmp2);
817
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
817
                if(GPSData.Position.Longitude >= 0) i += sprintf(&array[i],"E,");
818
                else i += sprintf(&array[i],"W,");
818
                else i += sprintf(&array[i],"W,");
819
                // +++++++++++++++++++++++++++++++++++++++++++
819
                // +++++++++++++++++++++++++++++++++++++++++++
820
                tmp_int = GPSData.Speed_Ground; // in cm/sek
820
                tmp_int = GPSData.Speed_Ground; // in cm/sek
821
                tmp_int *= 90;
821
                tmp_int *= 90;
822
                tmp_int /= 463;
822
                tmp_int /= 463;
823
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
823
                i += sprintf(&array[i],"%02d.%d,",tmp_int/10,tmp_int%10); // in Knoten
824
                // +++++++++++++++++++++++++++++++++++++++++++
824
                // +++++++++++++++++++++++++++++++++++++++++++
825
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
825
                i += sprintf(&array[i],"%03d.%d,",GyroCompassCorrected/10,GyroCompassCorrected%10);
826
                // +++++++++++++++++++++++++++++++++++++++++++
826
                // +++++++++++++++++++++++++++++++++++++++++++
827
                if(SystemTime.Valid)
827
                if(SystemTime.Valid)
828
                {
828
                {
829
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
829
                        i += sprintf(&array[i], "%02d%02d%02d,",SystemTime.Day,SystemTime.Month,SystemTime.Year);
830
                }
830
                }
831
                else
831
                else
832
                {
832
                {
833
                        i += sprintf(&array[i], ",");
833
                        i += sprintf(&array[i], ",");
834
                }
834
                }
835
                // +++++++++++++++++++++++++++++++++++++++++++
835
                // +++++++++++++++++++++++++++++++++++++++++++
836
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
836
                i += sprintf(&array[i],"%d.%1d,", abs(GeoMagDec)/10,abs(GeoMagDec)%10);
837
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
837
                if(GeoMagDec < 0) i += sprintf(&array[i], "W,"); else i += sprintf(&array[i], "E,");
838
                // +++++++++++++++++++++++++++++++++++++++++++
838
                // +++++++++++++++++++++++++++++++++++++++++++
839
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D,");
839
                if(GPSData.Flags & FLAG_DIFFSOLN) i += sprintf(&array[i], "D,");
840
                else i += sprintf(&array[i], "A,");
840
                else i += sprintf(&array[i], "A,");
841
        }
841
        }
842
        else // kein Satfix
842
        else // kein Satfix
843
        {
843
        {
844
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
844
                i += sprintf(&array[i], "V,,,,,,,,,,N*");
845
        }
845
        }
846
        // +++++++++++++++++++++++++++++++++++++++++++
846
        // +++++++++++++++++++++++++++++++++++++++++++
847
        //  CRC
847
        //  CRC
848
        // +++++++++++++++++++++++++++++++++++++++++++
848
        // +++++++++++++++++++++++++++++++++++++++++++
849
        for(x=1; x<i-1; x++)
849
        for(x=1; x<i-1; x++)
850
        {
850
        {
851
                crc ^= array[x];
851
                crc ^= array[x];
852
        }
852
        }
853
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
853
        i += sprintf(&array[i], "%02x%c%c",crc,0x0d,0x0a);
854
        // +++++++++++++++++++++++++++++++++++++++++++
854
        // +++++++++++++++++++++++++++++++++++++++++++
855
        AddSerialData(&UART1_tx_buffer,array,i);
855
        AddSerialData(&UART1_tx_buffer,array,i);
856
        // +++++++++++++++++++++++++++++++++++++++++++
856
        // +++++++++++++++++++++++++++++++++++++++++++
857
/*
857
/*
858
 
858
 
859
 
859
 
860
 
860
 
861
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
861
                GPSData.Flags =         (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits
862
                GPSData.NumOfSats =                     UbxSol.numSV;
862
                GPSData.NumOfSats =                     UbxSol.numSV;
863
                GPSData.SatFix =                                UbxSol.GPSfix;
863
                GPSData.SatFix =                                UbxSol.GPSfix;
864
                GPSData.Position_Accuracy =             UbxSol.PAcc;
864
                GPSData.Position_Accuracy =             UbxSol.PAcc;
865
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
865
                GPSData.Speed_Accuracy =                UbxSol.SAcc;
866
                SetGPSTime(&SystemTime); // update system time
866
                SetGPSTime(&SystemTime); // update system time
867
                // NAV POSLLH
867
                // NAV POSLLH
868
                GPSData.Position.Status =               INVALID;
868
                GPSData.Position.Status =               INVALID;
869
                GPSData.Position.Longitude =    UbxPosLlh.LON;
869
                GPSData.Position.Longitude =    UbxPosLlh.LON;
870
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
870
                GPSData.Position.Latitude =     UbxPosLlh.LAT;
871
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
871
                GPSData.Position.Altitude =     UbxPosLlh.HMSL;
872
                GPSData.Position.Status =               NEWDATA;
872
                GPSData.Position.Status =               NEWDATA;
873
                // NAV VELNED
873
                // NAV VELNED
874
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
874
                GPSData.Speed_East =                    UbxVelNed.VEL_E;
875
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
875
                GPSData.Speed_North =                   UbxVelNed.VEL_N;
876
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
876
                GPSData.Speed_Top       =                       -UbxVelNed.VEL_D;
877
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
877
                GPSData.Speed_Ground =                  UbxVelNed.GSpeed;
878
                GPSData.Heading =                               UbxVelNed.Heading;
878
                GPSData.Heading =                               UbxVelNed.Heading;
879
                SystemTime.Year = 0;
879
                SystemTime.Year = 0;
880
                SystemTime.Month = 0;
880
                SystemTime.Month = 0;
881
                SystemTime.Day = 0;
881
                SystemTime.Day = 0;
882
                SystemTime.Hour = 0;
882
                SystemTime.Hour = 0;
883
                SystemTime.Min = 0;
883
                SystemTime.Min = 0;
884
                SystemTime.Sec = 0;
884
                SystemTime.Sec = 0;
885
                SystemTime.mSec = 0;
885
                SystemTime.mSec = 0;
886
                SystemTime.Valid = 0;
886
                SystemTime.Valid = 0;
887
 
887
 
888
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
888
                FromFlightCtrl.GyroHeading / 10;//NaviData.HomePositionDeviation.Bearing / 2;
889
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
889
                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
890
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
890
                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
891
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
891
                        i1 = abs(GPSData.Position.Latitude)/10000000L;
892
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
892
                        i2 = abs(GPSData.Position.Latitude)%10000000L;
893
 
893
 
894
 
894
 
895
 
895
 
896
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
896
                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
897
                        i1 *= 100;
897
                        i1 *= 100;
898
                        i1 += i2 / 100000;
898
                        i1 += i2 / 100000;
899
                        i2  = i2 % 100000;
899
                        i2  = i2 % 100000;
900
                        i2 /= 10;
900
                        i2 /= 10;
901
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
901
                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
902
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
902
                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
903
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
903
                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
904
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
904
                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
905
                        break;
905
                        break;
906
                case 1:
906
                case 1:
907
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
907
                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
908
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
908
                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
909
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
909
                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
910
                        //-----------------------------
910
                        //-----------------------------
911
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
911
                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
912
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
912
                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
913
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
913
                        i1 = abs(GPSData.Position.Longitude)/10000000L;
914
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
914
                        i2 = abs(GPSData.Position.Longitude)%10000000L;
915
 
915
 
916
*/
916
*/
917
}
917
}
918
 
918
 
919
 
919
 
920
/**************************************************************/
920
/**************************************************************/
921
/* Send the answers to incomming commands at the debug uart   */
921
/* Send the answers to incomming commands at the debug uart   */
922
/**************************************************************/
922
/**************************************************************/
923
void UART1_TransmitTxData(void)
923
void UART1_TransmitTxData(void)
924
{
924
{
925
static u8 motorindex1 = 255, motorindex2 = 0;
925
static u8 motorindex1 = 255, motorindex2 = 0;
926
        if(DebugUART != UART1) return;
926
        if(DebugUART != UART1) return;
927
 
927
 
928
        if(CheckDelay(UART1_AboTimeOut))
928
        if(CheckDelay(UART1_AboTimeOut))
929
        {
929
        {
930
                UART1_DebugData_Interval = 0;
930
                UART1_DebugData_Interval = 0;
931
                UART1_NaviData_Interval = 0;
931
                UART1_NaviData_Interval = 0;
932
                UART1_Data3D_Interval = 0;
932
                UART1_Data3D_Interval = 0;
933
                UART1_Display_Interval = 0;
933
                UART1_Display_Interval = 0;
934
                UART1_MotorData_Interval = 0;
934
                UART1_MotorData_Interval = 0;
935
        }
935
        }
936
 
936
 
937
        UART1_Transmit(); // output pending bytes in tx buffer
937
        UART1_Transmit(); // output pending bytes in tx buffer
938
        if((UART1_tx_buffer.Locked == TRUE)) return;
938
        if((UART1_tx_buffer.Locked == TRUE)) return;
939
 
939
 
940
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
940
        if(UART1_Request_Parameter && (UART1_tx_buffer.Locked == FALSE))
941
        {
941
        {
942
                s16 ParamValue;
942
                s16 ParamValue;
943
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
943
                NCParams_GetValue(UART1_Request_ParameterId, &ParamValue);
944
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
944
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'J', NC_ADDRESS, 2, &UART1_Request_ParameterId, sizeof(UART1_Request_ParameterId), &ParamValue, sizeof(ParamValue)); // answer the param request
945
                UART1_Request_Parameter = FALSE;
945
                UART1_Request_Parameter = FALSE;
946
        }
946
        }
947
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
947
        else if(UART1_Request_Echo && (UART1_tx_buffer.Locked == FALSE))
948
        {
948
        {
949
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
949
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request
950
                Echo = 0; // reset echo value
950
                Echo = 0; // reset echo value
951
                UART1_Request_Echo = FALSE;
951
                UART1_Request_Echo = FALSE;
952
        }
952
        }
953
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
953
        else if(UART1_Request_FTP && (UART1_tx_buffer.Locked == FALSE))
954
        {
954
        {
955
                u8 errorcode = FTP_ERROR_NONE;
955
                u8 errorcode = FTP_ERROR_NONE;
956
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
956
        if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) errorcode = FTP_ERROR_MOTOR_RUN;
957
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
957
                else if (!Partition.IsValid) errorcode = FTP_ERROR_NO_SDCARD;
958
 
958
 
959
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
959
                if (!errorcode) CheckFTPCommand(UART1_Request_FTP);
960
                else
960
                else
961
                {
961
                {
962
                        u8 cmd = FTP_CMD_ERROR;
962
                        u8 cmd = FTP_CMD_ERROR;
963
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
963
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'F', NC_ADDRESS, 2, &cmd, 1, &errorcode, 1);
964
                }
964
                }
965
 
965
 
966
                UART1_Request_FTP = FALSE;
966
                UART1_Request_FTP = FALSE;
967
        }
967
        }
968
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
968
        else if((UART1_Request_WritePoint!= 0xFF) && (UART1_tx_buffer.Locked == FALSE))
969
        {
969
        {
970
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
970
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &UART1_Request_WritePoint, sizeof(UART1_Request_WritePoint));
971
                UART1_Request_WritePoint = 0xFF;
971
                UART1_Request_WritePoint = 0xFF;
972
        }
972
        }
973
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
973
        else if((UART1_Request_ReadPoint) && (UART1_tx_buffer.Locked == FALSE))
974
        {
974
        {
975
                u8 PointCount = PointList_GetCount();
975
                u8 PointCount = PointList_GetCount();
976
                if (UART1_Request_ReadPoint <= PointCount)
976
                if (UART1_Request_ReadPoint <= PointCount)
977
                {
977
                {
978
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
978
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &PointCount, 1, &UART1_Request_ReadPoint, 1, PointList_GetAt(UART1_Request_ReadPoint), sizeof(Point_t));
979
                }
979
                }
980
                else
980
                else
981
                {
981
                {
982
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
982
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &PointCount, sizeof(PointCount));
983
                }
983
                }
984
                UART1_Request_ReadPoint = 0;
984
                UART1_Request_ReadPoint = 0;
985
        }
985
        }
986
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
986
        else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
987
        {
987
        {
988
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
988
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
989
                UART1_Request_DebugLabel = 0xFF;
989
                UART1_Request_DebugLabel = 0xFF;
990
        }
990
        }
991
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
991
        else if(UART1_ExternalControlConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
992
        {
992
        {
993
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
993
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1,(u8 *)&UART1_ExternalControlConfirmFrame, sizeof(UART1_ExternalControlConfirmFrame));
994
                UART1_ExternalControlConfirmFrame = 0;
994
                UART1_ExternalControlConfirmFrame = 0;
995
        }
995
        }
996
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
996
        else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
997
        {
997
        {
998
                NaviData.Errorcode = ErrorCode;
998
                NaviData.Errorcode = ErrorCode;
999
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
999
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS, 1 , (u8 *)&NaviData, sizeof(NaviData));
1000
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1000
                UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval);
1001
                UART1_Request_NaviData = FALSE;
1001
                UART1_Request_NaviData = FALSE;
1002
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1002
                LastTransmittedFCStatusFlags2 = NaviData.FCStatusFlags2;
1003
        }
1003
        }
1004
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1004
        else if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
1005
        {
1005
        {
1006
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1006
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
1007
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1007
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
1008
                UART1_Request_DebugData = FALSE;
1008
                UART1_Request_DebugData = FALSE;
1009
        }
1009
        }
1010
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1010
        else if((( (UART1_Data3D_Interval > 0) && CheckDelay(UART1_Data3D_Timer) ) || UART1_Request_Data3D) && (UART1_tx_buffer.Locked == FALSE))
1011
        {
1011
        {
1012
                Data3D.StickNick = FC.StickNick;
1012
                Data3D.StickNick = FC.StickNick;
1013
                Data3D.StickRoll = FC.StickRoll;
1013
                Data3D.StickRoll = FC.StickRoll;
1014
        Data3D.StickYaw = FC.StickYaw;
1014
        Data3D.StickYaw = FC.StickYaw;
1015
        Data3D.StickGas = FC.StickGas;
1015
        Data3D.StickGas = FC.StickGas;
1016
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1016
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
1017
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1017
                UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
1018
                UART1_Request_Data3D = FALSE;
1018
                UART1_Request_Data3D = FALSE;
1019
        }
1019
        }
1020
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1020
        else if((((UART1_MotorData_Interval > 0) && CheckDelay(UART1_MotorData_Timer) ) || UART1_Request_MotorData) && (UART1_tx_buffer.Locked == FALSE))
1021
        {
1021
        {
1022
                do
1022
                do
1023
                {
1023
                {
1024
                 motorindex1++;
1024
                 motorindex1++;
1025
                 motorindex1%=12;
1025
                 motorindex1%=12;
1026
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1026
         if(!motorindex1) {motorindex2++;  motorindex2 %= 12;};
1027
                 if(motorindex1 == motorindex2) break;
1027
                 if(motorindex1 == motorindex2) break;
1028
                }
1028
                }
1029
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1029
                while((Motor[motorindex1].State & 0x80) != 0x80); // skip unused Motors
1030
 
1030
 
1031
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1031
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'K', NC_ADDRESS, 2, &motorindex1, sizeof(motorindex1),(u8 *)&Motor[motorindex1], sizeof(Motor_t));
1032
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1032
            UART1_MotorData_Timer = SetDelay(UART1_MotorData_Interval);
1033
                UART1_Request_MotorData = FALSE;
1033
                UART1_Request_MotorData = FALSE;
1034
        }
1034
        }
1035
        else if(UART1_Request_WPLStore)
1035
        else if(UART1_Request_WPLStore)
1036
        {
1036
        {
1037
                /*
1037
                /*
1038
                s8 txt[50];
1038
                s8 txt[50];
1039
                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);
1039
                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);
1040
                UART1_PutString(txt);
1040
                UART1_PutString(txt);
1041
                */
1041
                */
1042
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1042
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'I', NC_ADDRESS, 1,(u8 *)&(WPL_Answer), sizeof(WPL_Answer_t));
1043
                UART1_Request_WPLStore = FALSE;                
1043
                UART1_Request_WPLStore = FALSE;                
1044
        }
1044
        }
1045
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1045
        else if((((NMEA_Interval > 0) && CheckDelay(NMEA_Timer))) && (UART1_tx_buffer.Locked == FALSE))
1046
        {
1046
        {
1047
                CreateNmeaGGA();
1047
                CreateNmeaGGA();
1048
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1048
                Send_NMEA_RMC = TRUE;   // das muss noch da hinter
1049
                NMEA_Timer = SetDelay(NMEA_Interval);
1049
                NMEA_Timer = SetDelay(NMEA_Interval);
1050
        }
1050
        }
1051
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1051
        else if(Send_NMEA_RMC == TRUE && (UART1_tx_buffer.Locked == FALSE))
1052
        {
1052
        {
1053
          CreateNmeaRMC();
1053
          CreateNmeaRMC();
1054
          Send_NMEA_RMC = FALSE;
1054
          Send_NMEA_RMC = FALSE;
1055
        }
1055
        }
1056
 
1056
 
1057
        /*
1057
        /*
1058
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1058
        else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
1059
        {
1059
        {
1060
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1060
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
1061
                UART1_ConfirmFrame = 0;
1061
                UART1_ConfirmFrame = 0;
1062
        }
1062
        }
1063
        */
1063
        */
1064
        /*
1064
        /*
1065
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1065
        else if(UART1_Request_ExternalControl && (UART1_tx_buffer.Locked == FALSE))
1066
        {
1066
        {
1067
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1067
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
1068
                UART1_Request_ExternalControl = FALSE;
1068
                UART1_Request_ExternalControl = FALSE;
1069
        }
1069
        }
1070
        */
1070
        */
1071
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1071
        else if( (( (UART1_Display_Interval > 0) && CheckDelay(UART1_Display_Timer)) || UART1_Request_Display) && (UART1_tx_buffer.Locked == FALSE))
1072
        {
1072
        {
1073
                if(UART1_DisplayLine > 3)
1073
                if(UART1_DisplayLine > 3)
1074
                {
1074
                {
1075
                        Menu_Update(UART1_DisplayKeys);
1075
                        Menu_Update(UART1_DisplayKeys);
1076
                        UART1_DisplayKeys = 0;
1076
                        UART1_DisplayKeys = 0;
1077
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1077
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
1078
                }
1078
                }
1079
                else
1079
                else
1080
                {
1080
                {
1081
                        UART1_DisplayLine = 2;
1081
                        UART1_DisplayLine = 2;
1082
                        sprintf(text,"!!! incompatible !!!");
1082
                        sprintf(text,"!!! incompatible !!!");
1083
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1083
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&text, 20);
1084
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1084
                        if(UART1_DisplayLine++ > 3) UART1_DisplayLine = 0;
1085
                }
1085
                }
1086
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1086
                UART1_Display_Timer = SetDelay(UART1_Display_Interval);
1087
                UART1_Request_Display = FALSE;
1087
                UART1_Request_Display = FALSE;
1088
        }
1088
        }
1089
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1089
        else if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
1090
        {
1090
        {
1091
                Menu_Update(0);
1091
                Menu_Update(0);
1092
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1092
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
1093
                UART1_Request_Display1 = FALSE;
1093
                UART1_Request_Display1 = FALSE;
1094
        }
1094
        }
1095
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
1095
        else if(UART1_Request_VersionInfo && (UART1_tx_buffer.Locked == FALSE))
1096
        {
1096
        {
1097
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1097
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
1098
                UART1_Request_VersionInfo = FALSE;
1098
                UART1_Request_VersionInfo = FALSE;
1099
        }
1099
        }
1100
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1100
        else if(UART1_Request_SystemTime && (UART1_tx_buffer.Locked == FALSE))
1101
        {
1101
        {
1102
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1102
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'T', NC_ADDRESS,1, (u8 *)&SystemTime, sizeof(SystemTime));
1103
                UART1_Request_SystemTime = FALSE;
1103
                UART1_Request_SystemTime = FALSE;
1104
        }
1104
        }
1105
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1105
        else if(UART1_Request_ErrorMessage && (UART1_tx_buffer.Locked == FALSE))
1106
        {
1106
        {
1107
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1107
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
1108
                UART1_Request_ErrorMessage = FALSE;
1108
                UART1_Request_ErrorMessage = FALSE;
1109
        }
1109
        }
1110
#ifdef FOLLOW_ME
1110
#ifdef FOLLOW_ME
1111
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1111
        else if(CheckDelay(UART1_FollowMe_Timer) && (UART1_tx_buffer.Locked == FALSE))
1112
        {
1112
        {
1113
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1113
                if((GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.NumOfSats >= 4))
1114
                {
1114
                {
1115
                        TransmitAlsoToFC = 1;
1115
                        TransmitAlsoToFC = 1;
1116
                        // update FollowMe content
1116
                        // update FollowMe content
1117
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1117
                        FollowMe.Position.Longitude     = GPSData.Position.Longitude;
1118
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1118
                        FollowMe.Position.Latitude      = GPSData.Position.Latitude;
1119
                        FollowMe.Position.Status = NEWDATA;
1119
                        FollowMe.Position.Status = NEWDATA;
1120
                        FollowMe.Position.Altitude = 1;
1120
                        FollowMe.Position.Altitude = 1;
1121
                        // 0  -> no Orientation
1121
                        // 0  -> no Orientation
1122
                        // 1-360 -> CompassCourse Setpoint
1122
                        // 1-360 -> CompassCourse Setpoint
1123
                        // -1 -> points to  WP1 -> itself
1123
                        // -1 -> points to  WP1 -> itself
1124
                FollowMe.Heading = -1;
1124
                FollowMe.Heading = -1;
1125
                        FollowMe.ToleranceRadius = 1;
1125
                        FollowMe.ToleranceRadius = 1;
1126
                        FollowMe.HoldTime = 60;
1126
                        FollowMe.HoldTime = 60;
1127
                        FollowMe.Event_Flag = 1;
1127
                        FollowMe.Event_Flag = 1;
1128
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1128
                        FollowMe.Index = 1; // 0 = Delete List, 1 place at first entry in the list
1129
                        FollowMe.Type = POINT_TYPE_WP;
1129
                        FollowMe.Type = POINT_TYPE_WP;
1130
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1130
                        FollowMe.WP_EventChannelValue = 100;  // set servo value
1131
                        FollowMe.AltitudeRate = 0;                        // do not change height
1131
                        FollowMe.AltitudeRate = 0;                        // do not change height
1132
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1132
                        FollowMe.Speed = 0;                             // rate to change the Position (0 = max)
1133
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1133
                        FollowMe.CamAngle = 255;                // Camera servo angle in degree (255 -> POI-Automatic)
1134
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1134
                        FollowMe.Name[0] = 'F';             // Name of that point (ASCII)
1135
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1135
                        FollowMe.Name[1] = 'O';             // Name of that point (ASCII)
1136
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1136
                        FollowMe.Name[2] = 'L';             // Name of that point (ASCII)
1137
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1137
                        FollowMe.Name[3] = 'L';             // Name of that point (ASCII)
1138
                        FollowMe.reserve[0] = 0;                // reserve
1138
                        FollowMe.reserve[0] = 0;                // reserve
1139
                        FollowMe.reserve[1] = 0;                // reserve
1139
                        FollowMe.reserve[1] = 0;                // reserve
1140
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1140
                        MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
1141
                }
1141
                }
1142
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1142
                UART1_FollowMe_Timer = SetDelay(FOLLOW_ME_INTERVAL); // set new update time
1143
        }
1143
        }
1144
#endif
1144
#endif
1145
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1145
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
1146
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1146
        else if(SendDebugOutput && (UART1_tx_buffer.Locked == FALSE))
1147
        {
1147
        {
1148
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1148
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'0', NC_ADDRESS, 1, (u8 *) &tDebug, sizeof(tDebug));
1149
                SendDebugOutput = 0;
1149
                SendDebugOutput = 0;
1150
        }
1150
        }
1151
#endif
1151
#endif
1152
        UART1_Transmit(); // output pending bytes in tx buffer
1152
        UART1_Transmit(); // output pending bytes in tx buffer
1153
}
1153
}
1154
 
1154
 
1155
 
1155