Subversion Repositories NaviCtrl

Rev

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

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