Subversion Repositories NaviCtrl

Rev

Rev 807 | Rev 819 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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