Subversion Repositories NaviCtrl

Rev

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

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