Subversion Repositories NaviCtrl

Rev

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

Rev Author Line No. Line
41 ingob 1
#ifndef _UART1_H
2
#define _UART1_H
3
 
4
#define UART_FLIGHTCTRL 0
5
#define UART_MK3MAG     1
6
#define UART_MKGPS      2
7
 
92 killagreg 8
#include "ubx.h"
495 killagreg 9
#include "waypoints.h"
41 ingob 10
 
256 killagreg 11
#define NC_ERROR0_SPI_RX                                0x01
12
#define NC_ERROR0_COMPASS_RX                    0x02
13
#define NC_ERROR0_FC_INCOMPATIBLE               0x04
14
#define NC_ERROR0_COMPASS_INCOMPATIBLE  0x08
15
#define NC_ERROR0_GPS_RX                                0x10
16
#define NC_ERROR0_COMPASS_VALUE                 0x20
156 killagreg 17
 
675 holgerb 18
#define DISABLE_FC_UART GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_SET);
19
#define  ENABLE_FC_UART GPIO_WriteBit(GPIO3, GPIO_Pin_7, Bit_RESET);
819 holgerb 20
extern u16 Uart1Baudrate;
675 holgerb 21
 
819 holgerb 22
#define MAX_BD_RATES 9
23
extern const u32 BAUDRATES[MAX_BD_RATES];
24
 
62 killagreg 25
typedef struct
92 killagreg 26
{
112 killagreg 27
        u8 SWMajor;
28
        u8 SWMinor;
29
        u8 ProtoMajor;
598 holgerb 30
        u8 LabelTextCRC;
112 killagreg 31
        u8 SWPatch;
454 holgerb 32
    u8 HardwareError[2];
33
    u8 HWMajor;
548 holgerb 34
    u8 BL_Firmware;  
454 holgerb 35
    u8 Flags;
161 killagreg 36
} __attribute__((packed)) UART_VersionInfo_t;
112 killagreg 37
 
38
extern UART_VersionInfo_t UART_VersionInfo;
39
 
454 holgerb 40
//VersionInfo.Flags
41
#define NC_VERSION_FLAG_MK3MAG_PRESENT      0x01
42
#define NC_VERSION_FLAG_GPS_PRESENT             0x02
43
 
112 killagreg 44
typedef struct
45
{
161 killagreg 46
        s16 AngleNick;  // in 0.1 deg
47
        s16 AngleRoll;   // in 0.1 deg
48
        s16 Heading;    // in 0.1 deg
358 holgerb 49
    u8 StickNick;
50
    u8 StickRoll;
51
    u8 StickYaw;
52
    u8 StickGas;
739 holgerb 53
        s16 Altimeter_5cm; // in 5cm -> devide by 20 to get meters & multiply with 5 to get cm
588 holgerb 54
        u8 reserve[2];
61 holgerb 55
} __attribute__((packed)) Data3D_t;
56
 
57
extern Data3D_t Data3D;
58
 
112 killagreg 59
 
60
extern const u8 ANALOG_LABEL[32][16];
61
 
338 holgerb 62
#define AMPEL_FC                0x01
63
#define AMPEL_BL                0x02
64
#define AMPEL_NC                0x04
65
#define AMPEL_COMPASS   0x08
66
 
41 ingob 67
typedef struct
68
{
338 holgerb 69
        u8 StatusGreen;
70
        u8 StatusRed;
41 ingob 71
        u16 Analog[32];    // Debugwerte
72
} __attribute__((packed)) DebugOut_t;
73
 
74
extern DebugOut_t DebugOut;
75
 
682 holgerb 76
/*
41 ingob 77
typedef struct
78
{
79
        u8      Digital[2];
80
        u8      RemoteButtons;
81
        s8      Nick;
82
        s8      Roll;
83
        s8      Yaw;
84
        u8      Gas;
85
        s8      Height;
86
        u8      free;
87
        u8      Frame;
88
        u8      Config;
89
} __attribute__((packed)) ExternControl_t;
682 holgerb 90
*/
41 ingob 91
 
824 holgerb 92
#define EC_VALID                                0x01 // only valid if this is 1
93
#define EC_GAS_ADD                              0x02 // if 1 -> use the GAS Value not as MAX
94
#define EC_ONLY_IF_MOTOR_OFF    0x10 // use these Stick Positions only if the motors are not running -> Claibrate etc.
95
#define EC_USE_SWITCH                   0x20 // if 1 -> use the Switches for further control
96
#define EC_IGNORE_RC_STICK              0x40 // direct control (do nor add to RC-Stick)
97
#define EC_IGNORE_RC_LOST               0x80 // if 1 -> for Flying without RC-Control 
682 holgerb 98
 
689 holgerb 99
// defines for ExternalControl.Switches -> control GPS Modes etc. if(Config & EC_USE_SWITCH)
100
#define EC2_PH                          0x01 // GPS-Mode: PH
101
#define EC2_CH                          0x02 // GPS-Mode: CH
102
#define EC2_CAREFREE            0x10 // 
103
#define EC2_ALTITUDE            0x20 // 
104
#define EC2_AUTOSTART           0x40 // 
105
#define EC2_AUTOLAND            0x80 // 
106
 
682 holgerb 107
typedef struct
108
{
689 holgerb 109
 signed char Nick;
110
 signed char Roll;
111
 signed char Gier;
112
 signed char Gas;
113
 unsigned char Frame; // will return a confirm frame with this value
682 holgerb 114
 unsigned char Config;
689 holgerb 115
 unsigned char Switches;
116
 unsigned char Free1; // these two don't need capacity in the ASCII data string
117
 unsigned char Free2;
682 holgerb 118
} __attribute__((packed)) ExternControl_t;
41 ingob 119
extern ExternControl_t ExternControl;
689 holgerb 120
extern u8 NewExternalControlFrame; // flag that sends the Frame to FC
41 ingob 121
 
689 holgerb 122
#define SERIAL_POTI_START 17
123
#define WP_EVENT_PPM_IN   29
124
#define PPM_IN_OFF        30
125
#define PPM_IN_MAX        31
126
#define PPM_IN_MID        32
41 ingob 127
typedef struct
128
{
689 holgerb 129
 signed char   Ch[12];
130
} __attribute__((packed)) SerialChannel_t;
131
extern SerialChannel_t SerialChannel;
132
extern u8 NewSerialChannelFrame; // flag that sends the Frame to FC
133
 
134
typedef struct
135
{
41 ingob 136
        s16 Nick;
137
        s16 Roll;
138
        s16 Compass;                                    // angle between north and head of the MK
161 killagreg 139
} __attribute__((packed)) Attitude_t;
41 ingob 140
 
494 killagreg 141
 
142
typedef struct
143
{
737 holgerb 144
        u16 Distance_dm;                                        // distance to target in dm
92 killagreg 145
        s16 Bearing;                                    // course to target in deg
161 killagreg 146
} __attribute__((packed)) GPS_PosDev_t;
41 ingob 147
 
294 holgerb 148
#define NAVIDATA_VERSION 5
89 killagreg 149
 
789 holgerb 150
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151
//+ old protocol
152
//+ start abbo communication with: 'O' + Interval [10ms] 
153
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154
typedef struct   // 84 Bytes    (note: this is the old protocol)
41 ingob 155
{
768 holgerb 156
        u8 Version;                                             // version of the data structure = 5 
491 killagreg 157
        GPS_Pos_t CurrentPosition;              // see gpspos.h for details
41 ingob 158
        GPS_Pos_t TargetPosition;
159
        GPS_PosDev_t TargetPositionDeviation;
160
        GPS_Pos_t HomePosition;
161
        GPS_PosDev_t HomePositionDeviation;
162
        u8  WaypointIndex;                              // index of current waypoints running from 0 to WaypointNumber-1
163
        u8  WaypointNumber;                             // number of stored waypoints
89 killagreg 164
        u8  SatsInUse;                                  // number of satellites used for position solution
739 holgerb 165
        s16 Altimeter_5cm;                              // hight according to air pressure
41 ingob 166
        s16 Variometer;                                 // climb(+) and sink(-) rate
167
        u16 FlyingTime;                                 // in seconds
168
        u8  UBat;                                               // Battery Voltage in 0.1 Volts
169
        u16 GroundSpeed;                                // speed over ground in cm/s (2D)
89 killagreg 170
        s16 Heading;                                    // current flight direction in ° as angle to north
171
        s16     CompassHeading;                         // current compass value in °
41 ingob 172
        s8  AngleNick;                                  // current Nick angle in 1°
173
        s8  AngleRoll;                                  // current Rick angle in 1°
174
        u8  RC_Quality;                                 // RC_Quality
789 holgerb 175
        u8  FCStatusFlags;                              // Flags from FC see main.c FC_STATUS_xxx
176
        u8  NCFlags;                                    // Flags from NC see main.h NC_FLAG_xxx
41 ingob 177
        u8  Errorcode;                                  // 0 --> okay
532 holgerb 178
        u8  WP_OperatingRadius;                 // current WP operation radius around the Home Position in m
89 killagreg 179
        s16 TopSpeed;                                   // velocity in vertical direction in cm/s
125 killagreg 180
        u8  TargetHoldTime;                             // time in s to stay at the given target, counts down to 0 if target has been reached
294 holgerb 181
        u8  FCStatusFlags2;                             // StatusFlags2 (since version 5 added)
161 killagreg 182
        s16 SetpointAltitude;                   // setpoint for altitude
789 holgerb 183
        u8  Gas;                                                // current gas (thrust)
206 killagreg 184
        u16 Current;                                    // actual current in 0.1A steps
185
        u16 UsedCapacity;                               // used capacity in mAh
768 holgerb 186
        u8 reserve1;                                    // to fit into 84 bytes (must be divisible by 3) 
187
        u8 reserve2;                                    // to fit into 84 bytes (must be divisible by 3)
41 ingob 188
} __attribute__((packed)) NaviData_t;
189
extern NaviData_t NaviData;
190
 
789 holgerb 191
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
192
//+ New protocol
193
//+ start abbo communication with: 'O' + Interval 1byte [10ms] + MaxBytesPerSecond (2Bytes)
194
//+ i.e. 'O'+10+1024
195
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
196
 
824 holgerb 197
typedef struct // Index:10 (15 Bytes need 27 ASCII-characters) -> 7+(x/3)*4
598 holgerb 198
{
789 holgerb 199
        u8 Index;                               // Index to identify this data set
200
        s32 ActualLongitude;    // 
201
        s32 ActualLatitude;             // 
202
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
203
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
204
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
205
        u8 CamCtrlChar;                 // Status from a connected CamCtrl unit: 'R' = REC  'c' = Ready  '!' = Error  ...etc
206
u8 reserve1;                     
598 holgerb 207
} __attribute__((packed)) NaviData_Tiny_t;
208
extern NaviData_Tiny_t NaviData_Tiny;
209
 
210
#define START_PAYLOAD_DATA  13  // 
211
 
789 holgerb 212
typedef struct  // Index:11 (24 Bytes need 39 ASCII-characters)
598 holgerb 213
{
789 holgerb 214
        u8 Index;                               // Index to identify this data set
215
        s32 ActualLongitude;    // 
216
        s32 ActualLatitude;             // 
217
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm 
218
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
219
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
220
        u8 OSDStatusFlags2;             // see main.h for definitions OSD_FLAG2_xxx
221
        u8  NCFlags;                    // Flags from NC
222
u8 ReserveFlags;
223
        u8  Errorcode;                  // 0 --> okay  see http://wiki.mikrokopter.de/ErrorCodes
224
        u8 SpeakHoTT;                   // voice output SPEAK_xxx (see spi_slave.h)
225
        u8 VarioCharacter;              // display as ascii character ('+' = 'climb' etc)
226
        u8 GPS_ModeCharacter;   // display as ascii character ('H' = 'Home' etc)
227
        u8 BL_MinOfMaxPWM;              // status byte of the BL-Ctrls
598 holgerb 228
} __attribute__((packed)) NaviData_Flags_t;
229
extern NaviData_Flags_t NaviData_Flags;
230
 
789 holgerb 231
typedef struct  // Index:12  (27 Bytes need 43 ASCII-characters)
598 holgerb 232
{
789 holgerb 233
        u8 Index;                               // Index to identify this data set
234
        s32 ActualLongitude;    // 
235
        s32 ActualLatitude;             // 
236
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
237
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
238
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
239
        s32 TargetLongitude;    // 
240
        s32 TargetLatitude;             // 
241
        s16 TargetAltitude;     // hight according to air pressure
242
        u8  RC_Quality;                 // RC_Quality
598 holgerb 243
} __attribute__((packed)) NaviData_Target_t;
244
extern NaviData_Target_t NaviData_Target;
245
 
789 holgerb 246
typedef struct  // Index:13  (30 Bytes need 47 ASCII-characters)
247
{                                          
248
        u8 Index;                               // Index to identify this data set
249
        s32 ActualLongitude;    // 
250
        s32 ActualLatitude;             // 
251
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
252
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
253
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
254
        s32 HomeLongitude;              // 
255
        s32 HomeLatitude;               // 
256
        s16 HomeAltitude;               // hight according to air pressure
257
        u16 WP_OperatingRadius; // current WP operation radius around the Home Position in m
598 holgerb 258
        u8 LipoCellCount;
789 holgerb 259
        u8 DescendRange;                // in [10m]
260
        u8 ManualFlyingRange;   // in [10m]
807 holgerb 261
        u8 OSDStatusFlags3;
622 holgerb 262
u8 reserve1;
598 holgerb 263
} __attribute__((packed)) NaviData_Home_t;
264
extern NaviData_Home_t NaviData_Home;
265
 
789 holgerb 266
typedef struct   // Index:14    (24 Bytes need 39 ASCII-characters)
600 holgerb 267
{
789 holgerb 268
        u8 Index;                               // Index to identify this data set
269
        s32 ActualLongitude;    // 
270
        s32 ActualLatitude;             // 
271
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
272
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
273
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
274
        u16 FlyingTime;                 // in seconds
275
        u16 DistanceToHome;             // [10cm] (100 = 10m)
276
        u8  HeadingToHome;              // in 2° (100 = 200°)
277
        u16 DistanceToTarget;   // [10cm] (100 = 10m)   
278
        u8  HeadingToTarget;    // in 2° (100 = 200°)
279
        s8  AngleNick;                  // current Nick angle in 1°
280
        s8  AngleRoll;                  // current Rick angle in 1°
281
        u8  SatsInUse;                  // number of satellites used for position solution
282
} __attribute__((packed)) NaviData_Deviation_t;
283
extern NaviData_Deviation_t NaviData_Deviation;
600 holgerb 284
 
789 holgerb 285
typedef struct // Index:15 (18 Bytes need 31 ASCII-characters)
621 holgerb 286
{
789 holgerb 287
        u8 Index;                               // Index to identify this data set
288
        s32 ActualLongitude;    // 
289
        s32 ActualLatitude;             // 
290
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
291
        u8  GroundSpeed;                // speed over ground in 10cm/s (2D) (255 = 91km/h)
292
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
293
        u8  WaypointIndex;              // index of current waypoints running from 0 to WaypointNumber-1
294
        u8  WaypointNumber;             // number of stored waypoints
295
        u8  TargetHoldTime;             // time in s to stay at the given target, counts down to 0 if target has been reached
296
        u8 WP_Eventchannel;             // the current value of the event channel
598 holgerb 297
u8 reserve;
298
} __attribute__((packed)) NaviData_WP_t;
299
extern NaviData_WP_t NaviData_WP;
300
 
789 holgerb 301
typedef struct // Index:16  (27 Bytes need 43 ASCII-characters)
598 holgerb 302
{
789 holgerb 303
        u8 Index;                               // Index to identify this data set
304
        s32 ActualLongitude;    // 
305
        s32 ActualLatitude;             // 
306
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
307
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
308
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
309
        u16 UBat;                               // Battery Voltage in 0.1 Volts
310
        u16 Current;                    // actual current in 0.1A steps
311
        u16 UsedCapacity;               // used capacity in mAh
312
        s8  Variometer;                 // climb(+) and sink(-) rate
313
        u8  Heading;                    // Current moving direction in 2° (100 = 200°)
314
        u8      CompassHeading;         // current compass value in 2°
315
        u8  Gas;                                // current gas (thrust)
316
        u16 ShutterCounter;             // counts every time a Out1 was activated
317
        s16 SetpointAltitude;   // setpoint for altitude
598 holgerb 318
} __attribute__((packed)) NaviData_Volatile_t;
319
extern NaviData_Volatile_t NaviData_Volatile;
320
 
321
 
789 holgerb 322
typedef struct  // Index:17  (21 Bytes need 35 ASCII-characters)
323
{
324
        u8 Index;                               // Index to identify this data set
325
        s32 ActualLongitude;    // 
326
        s32 ActualLatitude;             // 
327
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
328
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
329
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
330
        s32 Longitude;                  // Failsafe-Position
331
        s32 Latitude;                   // Failsafe-Position
332
} __attribute__((packed)) NaviData_FS_Pos_t;
333
extern NaviData_FS_Pos_t NaviData_Failsafe;
598 holgerb 334
 
789 holgerb 335
typedef struct // Index:18  (9 Bytes need 19 ASCII-characters)
336
{
337
        u8 Index;                               // Index to identify this data set
338
        s32 Longitude;                  // Trigger Position
339
        s32 Latitude;                   // Trigger Position
340
} __attribute__((packed)) NaviData_Out_t;
341
extern NaviData_Out_t NaviData_Out1Trigger;
598 holgerb 342
 
343
 
824 holgerb 344
typedef struct  // Index:19  (36 Bytes need 55 ASCII-characters) -> 7+(x/3)*4
345
{
346
        u8 Index;                               // Index to identify this data set
347
        s32 ActualLongitude;    // 
348
        s32 ActualLatitude;             // 
349
        s16 Altimeter_5cm;              // hight -> devide by 20 to get meters & multiply with 5 to get cm
350
        u8 GroundSpeed;                 // speed over ground in 10cm/s (2D) (255 = 91km/h)
351
        u8 OSDStatusFlags;              // see main.h for definitions OSD_FLAG_xxx
352
        u8 HoTT_DisplayText[21];
830 holgerb 353
        u8 HoTT_TextLevel;          // Level of the Message: 0 = Nothing special; 1 = OEM-Name ;  2 = Waypoint Data ; 3 = Simulation ; 4 = "Calibrate"  ; 5 = "Load&Safe" ; 6 = "Setting name"  ; 7-10 = Error
824 holgerb 354
u8 reserve;
355
} __attribute__((packed)) NaviData_HoTT_Text_t;
356
extern NaviData_HoTT_Text_t NaviData_HoTT_Text;
357
 
41 ingob 358
extern UART_TypeDef *DebugUART;
92 killagreg 359
extern volatile u8 SerialLinkOkay;
349 ingob 360
extern Buffer_t UART1_tx_buffer;
380 holgerb 361
extern Buffer_t UART1_rx_buffer;
773 holgerb 362
extern u16 UART1_BaudrateFallbackTimeout;
41 ingob 363
 
364
void UART1_Init(void);
365
void UART1_Transmit(void);
366
void UART1_TransmitTxData(void);
367
void UART1_ProcessRxData(void);
368
 
110 killagreg 369
s16  UART1_Putchar(char c);
370
void UART1_PutString(u8 *s);
150 killagreg 371
extern u8 text[]; // globally used text buffer
110 killagreg 372
extern u8 UART1_Request_SendFollowMe;
360 holgerb 373
extern u8 LastTransmittedFCStatusFlags2;
519 holgerb 374
extern u8 UART1_Request_ReadPoint;
495 killagreg 375
extern WPL_Store_t WPL_Store;
598 holgerb 376
extern u8 CalculateDebugLableCrc(void);
626 holgerb 377
extern u8 NaviData_Flags_SpeakHoTT_Processed;
532 holgerb 378
 
772 ingob 379
extern void UART1_Configure(u32 baudrate);
819 holgerb 380
extern void GetBaudrateFromSdCard(u32 oldBd);
772 ingob 381
 
532 holgerb 382
typedef struct
383
{
384
        u8 User[128];
385
        u8 eMail[128];
386
        u8 Feature[128];
387
        u8 Expire[11];
388
        u8 License[16];
763 holgerb 389
} __attribute__((packed)) LicenseS_t;
529 holgerb 390
extern u8 *LicensePtr;
495 killagreg 391
 
460 holgerb 392
extern u32 NMEA_Interval;// in ms
529 holgerb 393
#define LICENSE_SIZE            480
394
#define LICENSE_SIZE_TEXT       411
460 holgerb 395
 
41 ingob 396
#endif //_UART1_H