Rev 517 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 517 | Rev 518 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // + see the File "License.txt" for further Informations |
5 | // + see the File "License.txt" for further Informations |
- | 6 | // + |
|
- | 7 | // + GPS read out: |
|
- | 8 | // + modified Version of the Pitschu Brushless Ufo - (c) Peter Schulten, Mülheim, Germany |
|
- | 9 | // + only for non-profit use |
|
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 7... | Line 11... | ||
7 | 11 | ||
8 | #include "main.h" |
12 | #include "main.h" |
Line 32... | Line 36... | ||
32 | int Debug_Timer; |
36 | int Debug_Timer; |
Line 33... | Line 37... | ||
33 | 37 | ||
34 | const unsigned char ANALOG_TEXT[32][16] = |
38 | const unsigned char ANALOG_TEXT[32][16] = |
35 | { |
39 | { |
36 | //1234567890123456 |
40 | //1234567890123456 |
37 | "IntegralNick ", //0 |
41 | "IntegralNick____", //00 |
38 | "IntegralRoll ", |
42 | "IntegralRoll____", //01 |
39 | "AccNick ", |
43 | "AccNick_________", //02 |
40 | "AccRoll ", |
44 | "AccRoll_________", //03 |
41 | "GyroGier ", |
45 | "UserParam1______", //04 |
42 | "HoehenWert ", //5 |
46 | "UserParam2______", //05 |
43 | "AccZ ", |
47 | "Soll_Pos_North__", //06 |
44 | "Gas ", |
48 | "Soll_Pos_East___", //07 |
45 | "KompassValue ", |
49 | "KompassValue____", //08 |
46 | "Spannung ", |
50 | "UBat____________", //09 |
47 | "Empfang ", //10 |
51 | "SenderOkay______", //10 |
48 | "Analog11 ", |
52 | "GPSFix__________", //11 |
49 | "Motor_Vorne ", |
53 | "Gesamtstrom_____", //12 |
50 | "Motor_Hinten ", |
54 | "Geschwindigkeit_", //13 |
51 | "Motor_Links ", |
55 | "Pos.north_______", //14 |
52 | "Motor_Rechts ", //15 |
56 | "Pos.east________", //15 |
53 | "Acc_Z ", |
57 | "Poti3___________", //16 |
54 | "MittelAccNick ", |
58 | "Höhe_GPS________", //17 |
55 | "MittelAccRoll ", |
59 | "Home_North______", //18 |
56 | "IntegralErrNick ", |
60 | "Home_East_______", //19 |
57 | "IntegralErrRoll ", //20 |
61 | "Posabw_North____", //20 |
58 | "MittelIntNick ", |
62 | "Posabw_East_____", //21 |
59 | "MittelIntRoll ", |
63 | "P_Einfluss_North", //22 |
60 | "NeutralNick ", |
64 | "P_Einfluss_East_", //23 |
61 | "RollOffset ", |
65 | "D_Einfluss_North", //24 |
62 | "IntRoll*Faktor ", //25 |
66 | "D_Einfluss_East_", //25 |
63 | "Analog26 ", |
67 | "NORTH_MITTEL____", //26 |
64 | "DirektAusglRoll ", |
68 | "EAST_MITTEL_____", //27 |
65 | "MesswertRoll ", |
69 | "GPS_Nick________", //28 |
66 | "AusgleichRoll ", |
70 | "GPS_Roll________", //29 |
67 | "I-LageRoll ", //30 |
71 | "StickNick_______", //30 |
68 | "StickRoll " |
72 | "StickRoll_______" //31 |
Line -... | Line 73... | ||
- | 73 | }; |
|
- | 74 | ||
- | 75 | ||
- | 76 | char newData_navPosUtm = 0; // Flag, wenn neue PosUtm-Daten vorliegen (211007Kr) |
|
- | 77 | ||
- | 78 | static uint8_t gpsState; |
|
- | 79 | #define GPS_EMPTY 0 |
|
- | 80 | #define GPS_SYNC1 1 |
|
- | 81 | #define GPS_SYNC2 2 |
|
- | 82 | #define GPS_CLASS 3 |
|
- | 83 | #define GPS_LEN1 4 |
|
- | 84 | #define GPS_LEN2 5 |
|
- | 85 | #define GPS_FILLING 6 |
|
- | 86 | #define GPS_CKA 7 |
|
- | 87 | #define GPS_CKB 8 |
|
- | 88 | ||
- | 89 | gpsInfo_t actualPos; // measured position (last gps record) |
|
- | 90 | ||
- | 91 | #define SYNC_CHAR1 0xb5 |
|
- | 92 | #define SYNC_CHAR2 0x62 |
|
- | 93 | ||
- | 94 | #define CLASS_NAV 0x01 |
|
- | 95 | #define MSGID_STATUS 0x03 |
|
- | 96 | //#define MSGID_POSLLH 0x02 //(231107Kr) |
|
- | 97 | #define MSGID_POSUTM 0x08 |
|
- | 98 | #define MSGID_VELNED 0x12 |
|
- | 99 | ||
- | 100 | ||
- | 101 | ||
- | 102 | typedef struct { |
|
- | 103 | unsigned long ITOW; // time of week |
|
- | 104 | uint8_t GPSfix; // GPSfix Type, range 0..6 |
|
- | 105 | uint8_t Flags; // Navigation Status Flags |
|
- | 106 | uint8_t DiffS; // Differential Status |
|
- | 107 | uint8_t res; // reserved |
|
- | 108 | unsigned long TTFF; // Time to first fix (millisecond time tag) |
|
- | 109 | unsigned long MSSS; // Milliseconds since Startup / Reset |
|
- | 110 | uint8_t packetStatus; |
|
- | 111 | } NAV_STATUS_t; |
|
- | 112 | ||
- | 113 | /* |
|
- | 114 | typedef struct { //(231107Kr) |
|
- | 115 | unsigned long ITOW; // time of week |
|
- | 116 | long LON; // longitude in 1e-07 deg |
|
- | 117 | long LAT; // lattitude |
|
- | 118 | long HEIGHT; // height in mm |
|
- | 119 | long HMSL; // height above mean sea level im mm |
|
- | 120 | unsigned long Hacc; // horizontal accuracy in mm |
|
- | 121 | unsigned long Vacc; // vertical accuracy in mm |
|
- | 122 | uint8_t packetStatus; |
|
- | 123 | } NAV_POSLLH_t; |
|
- | 124 | */ |
|
- | 125 | ||
- | 126 | typedef struct { |
|
- | 127 | unsigned long ITOW; // time of week |
|
- | 128 | long EAST; // cm UTM Easting |
|
- | 129 | long NORTH; // cm UTM Nording |
|
- | 130 | long ALT; // cm altitude |
|
- | 131 | uint8_t ZONE; // UTM zone number |
|
- | 132 | uint8_t HEM; // Hemisphere Indicator (0=North, 1=South) |
|
- | 133 | uint8_t packetStatus; |
|
- | 134 | } NAV_POSUTM_t; |
|
- | 135 | ||
- | 136 | ||
- | 137 | typedef struct { |
|
- | 138 | unsigned long ITOW; // ms GPS Millisecond Time of Week |
|
- | 139 | long VEL_N; // cm/s NED north velocity |
|
- | 140 | long VEL_E; // cm/s NED east velocity |
|
- | 141 | long VEL_D; // cm/s NED down velocity |
|
- | 142 | unsigned long Speed; // cm/s Speed (3-D) |
|
- | 143 | unsigned long GSpeed; // cm/s Ground Speed (2-D) |
|
- | 144 | long Heading; // deg (1e-05) Heading 2-D |
|
- | 145 | unsigned long SAcc; // cm/s Speed Accuracy Estimate |
|
- | 146 | unsigned long CAcc; // deg Course / Heading Accuracy Estimate |
|
- | 147 | uint8_t packetStatus; |
|
- | 148 | } NAV_VELNED_t; |
|
- | 149 | ||
- | 150 | ||
- | 151 | ||
- | 152 | NAV_STATUS_t navStatus; |
|
- | 153 | //NAV_POSLLH_t navPosLlh; //(231107Kr) |
|
- | 154 | NAV_POSUTM_t navPosUtm; |
|
- | 155 | NAV_VELNED_t navVelNed; |
|
- | 156 | ||
- | 157 | volatile char *ubxP, *ubxEp, *ubxSp; // pointers to packet currently transfered |
|
- | 158 | volatile uint8_t CK_A, CK_B; // UBX checksum bytes |
|
- | 159 | volatile unsigned short msgLen; |
|
- | 160 | volatile uint8_t msgID; |
|
- | 161 | volatile uint8_t ignorePacket; // true when previous packet was not processed |
|
- | 162 | ||
- | 163 | ||
- | 164 | #ifdef GPS_DEBUG // if set then the GPS data is transfered to display |
|
- | 165 | extern volatile uint8_t v24state; |
|
- | 166 | char buf[200]; |
|
Line 69... | Line 167... | ||
69 | }; |
167 | char *bp; |
70 | 168 | char *ep; |
|
71 | 169 | #endif |
|
72 | 170 | ||
Line 89... | Line 187... | ||
89 | UDR = tmp_tx; |
187 | UDR = tmp_tx; |
90 | } |
188 | } |
91 | else ptr = 0; |
189 | else ptr = 0; |
92 | } |
190 | } |
Line -... | Line 191... | ||
- | 191 | ||
- | 192 | void GPSscanData (void) |
|
- | 193 | { |
|
- | 194 | ||
- | 195 | ||
- | 196 | ||
- | 197 | ||
- | 198 | if (navStatus.packetStatus == 1) // valid packet |
|
- | 199 | { |
|
- | 200 | actualPos.GPSFix = navStatus.GPSfix; |
|
- | 201 | actualPos.newData = navStatus.packetStatus; |
|
- | 202 | navStatus.packetStatus = 0; |
|
- | 203 | } |
|
- | 204 | ||
- | 205 | /* |
|
- | 206 | if (navPosLlh.packetStatus == 1) // valid packet |
|
- | 207 | { |
|
- | 208 | actualPos.longi = navPosLlh.LON; //(231107Kr) |
|
- | 209 | actualPos.lati = navPosLlh.LAT; //(231107Kr) |
|
- | 210 | actualPos.height = navPosLlh.HEIGHT; //(231107Kr) |
|
- | 211 | navPosLlh.packetStatus = 0; |
|
- | 212 | } |
|
- | 213 | */ |
|
- | 214 | ||
- | 215 | if (navPosUtm.packetStatus == 1) // valid packet |
|
- | 216 | { |
|
- | 217 | actualPos.northing = navPosUtm.NORTH; |
|
- | 218 | actualPos.easting = navPosUtm.EAST; |
|
- | 219 | actualPos.altitude = navPosUtm.ALT; |
|
- | 220 | navPosUtm.packetStatus = 0; |
|
- | 221 | newData_navPosUtm = 1; // (211007Kr) |
|
- | 222 | ROT_ON; // Rot blinkt in der Frequenz mit der neue UTM-Daten des GPS Empfänger ankommen und brauchbar sind //(211107Kr) |
|
- | 223 | } |
|
- | 224 | ||
- | 225 | ||
- | 226 | if (navVelNed.packetStatus == 1) // valid packet |
|
- | 227 | { |
|
- | 228 | actualPos.velNorth = navVelNed.VEL_N; |
|
- | 229 | actualPos.velEast = navVelNed.VEL_E; |
|
- | 230 | actualPos.velDown = navVelNed.VEL_D; |
|
- | 231 | actualPos.GSpeed = navVelNed.GSpeed; //Geschwindigkeit [cm/s] über Grund (151007Kr) |
|
- | 232 | navVelNed.packetStatus = 0; |
|
- | 233 | } |
|
- | 234 | ||
- | 235 | } |
|
93 | 236 | ||
94 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
237 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
95 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
238 | //++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung |
96 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
239 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
97 | SIGNAL(INT_VEC_RX) |
240 | SIGNAL(INT_VEC_RX) |
Line 100... | Line 243... | ||
100 | static unsigned char crc1,crc2,buf_ptr; |
243 | static unsigned char crc1,crc2,buf_ptr; |
101 | static unsigned char UartState = 0; |
244 | static unsigned char UartState = 0; |
102 | unsigned char CrcOkay = 0; |
245 | unsigned char CrcOkay = 0; |
Line 103... | Line 246... | ||
103 | 246 | ||
- | 247 | SioTmp = UDR; |
|
- | 248 | ||
- | 249 | uint8_t c; |
|
- | 250 | uint8_t re; |
|
- | 251 | ||
- | 252 | re = (UCSR0A & (_B1(FE0) | _B1(DOR0))); // any error occured ? |
|
- | 253 | c = SioTmp; |
|
- | 254 | ||
- | 255 | #ifdef GPS_DEBUG |
|
- | 256 | *bp++ = c; |
|
- | 257 | if (bp >= (buf+200)) bp = buf; |
|
- | 258 | if (v24state == 0) |
|
- | 259 | { |
|
- | 260 | v24state = 1; |
|
- | 261 | UDR0 = *ep++; |
|
- | 262 | if (ep >= buf+200) |
|
- | 263 | ep = buf; |
|
- | 264 | UCSR0B |= _B1(UDRIE0); //enable further irqs |
|
- | 265 | } |
|
- | 266 | #endif |
|
- | 267 | ||
- | 268 | if (re == 0) |
|
- | 269 | { |
|
- | 270 | switch (gpsState) |
|
- | 271 | { |
|
- | 272 | case GPS_EMPTY: |
|
- | 273 | if (c == SYNC_CHAR1) |
|
- | 274 | gpsState = GPS_SYNC1; |
|
- | 275 | break; |
|
- | 276 | case GPS_SYNC1: |
|
- | 277 | if (c == SYNC_CHAR2) |
|
- | 278 | gpsState = GPS_SYNC2; |
|
- | 279 | else if (c != SYNC_CHAR1) |
|
- | 280 | gpsState = GPS_EMPTY; |
|
- | 281 | break; |
|
- | 282 | case GPS_SYNC2: |
|
- | 283 | if (c == CLASS_NAV) |
|
- | 284 | gpsState = GPS_CLASS; |
|
- | 285 | else |
|
- | 286 | gpsState = GPS_EMPTY; |
|
- | 287 | break; |
|
- | 288 | case GPS_CLASS: // msg ID seen: init packed receive |
|
- | 289 | msgID = c; |
|
- | 290 | CK_A = CLASS_NAV + c; |
|
- | 291 | CK_B = CLASS_NAV + CK_A; |
|
- | 292 | gpsState = GPS_LEN1; |
|
- | 293 | ||
- | 294 | switch (msgID) |
|
- | 295 | { |
|
- | 296 | case MSGID_STATUS: |
|
- | 297 | ubxP = (char*)&navStatus; |
|
- | 298 | ubxEp = (char*)(&navStatus + sizeof(NAV_STATUS_t)); |
|
- | 299 | ubxSp = (char*)&navStatus.packetStatus; |
|
- | 300 | ignorePacket = navStatus.packetStatus; |
|
- | 301 | break; |
|
- | 302 | /* |
|
- | 303 | case MSGID_POSLLH: //(231107Kr) |
|
- | 304 | ubxP = (char*)&navPosLlh; |
|
- | 305 | ubxEp = (char*)(&navPosLlh + sizeof(NAV_POSLLH_t)); |
|
- | 306 | ubxSp = (char*)&navPosLlh.packetStatus; |
|
- | 307 | ignorePacket = navPosLlh.packetStatus; |
|
- | 308 | break; |
|
- | 309 | */ |
|
- | 310 | case MSGID_POSUTM: |
|
- | 311 | ubxP = (char*)&navPosUtm; |
|
- | 312 | ubxEp = (char*)(&navPosUtm + sizeof(NAV_POSUTM_t)); |
|
- | 313 | ubxSp = (char*)&navPosUtm.packetStatus; |
|
- | 314 | ignorePacket = navPosUtm.packetStatus; |
|
- | 315 | break; |
|
- | 316 | case MSGID_VELNED: |
|
- | 317 | ubxP = (char*)&navVelNed; |
|
- | 318 | ubxEp = (char*)(&navVelNed + sizeof(NAV_VELNED_t)); |
|
- | 319 | ubxSp = (char*)&navVelNed.packetStatus; |
|
- | 320 | ignorePacket = navVelNed.packetStatus; |
|
- | 321 | break; |
|
- | 322 | ||
- | 323 | ||
- | 324 | default: |
|
- | 325 | ignorePacket = 1; |
|
- | 326 | ubxSp = (char*)0; |
|
- | 327 | } |
|
- | 328 | break; |
|
- | 329 | case GPS_LEN1: // first len byte |
|
- | 330 | msgLen = c; |
|
- | 331 | CK_A += c; |
|
- | 332 | CK_B += CK_A; |
|
- | 333 | gpsState = GPS_LEN2; |
|
- | 334 | break; |
|
- | 335 | case GPS_LEN2: // second len byte |
|
- | 336 | msgLen = msgLen + (c * 256); |
|
- | 337 | CK_A += c; |
|
- | 338 | CK_B += CK_A; |
|
- | 339 | gpsState = GPS_FILLING; // next data will be stored in packet struct |
|
- | 340 | break; |
|
- | 341 | case GPS_FILLING: |
|
- | 342 | CK_A += c; |
|
- | 343 | CK_B += CK_A; |
|
- | 344 | ||
- | 345 | if ( !ignorePacket && ubxP < ubxEp) |
|
- | 346 | *ubxP++ = c; |
|
- | 347 | ||
- | 348 | if (--msgLen == 0) |
|
- | 349 | gpsState = GPS_CKA; |
|
- | 350 | ||
- | 351 | break; |
|
- | 352 | case GPS_CKA: |
|
- | 353 | if (c == CK_A) |
|
- | 354 | gpsState = GPS_CKB; |
|
- | 355 | else |
|
- | 356 | gpsState = GPS_EMPTY; |
|
- | 357 | break; |
|
- | 358 | case GPS_CKB: |
|
- | 359 | if (c == CK_B && ubxSp) // No error -> packet received successfully |
|
- | 360 | *ubxSp = 1; // set packetStatus in struct |
|
- | 361 | gpsState = GPS_EMPTY; // ready for next packet |
|
- | 362 | break; |
|
- | 363 | default: |
|
- | 364 | gpsState = GPS_EMPTY; // ready for next packet |
|
- | 365 | } |
|
- | 366 | } |
|
- | 367 | else // discard any data if error occured |
|
- | 368 | { |
|
- | 369 | gpsState = GPS_EMPTY; |
|
- | 370 | } |
|
- | 371 | GPSscanData (); |
|
- | 372 | ||
- | 373 | ||
- | 374 | ||
- | 375 | ||
- | 376 | ||
- | 377 | ||
104 | SioTmp = UDR; |
378 | |
105 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
379 | if(buf_ptr >= MAX_EMPFANGS_BUFF) UartState = 0; |
106 | if(SioTmp == '\r' && UartState == 2) |
380 | if(SioTmp == '\r' && UartState == 2) |
107 | { |
381 | { |
108 | UartState = 0; |
382 | UartState = 0; |
Line 163... | Line 437... | ||
163 | UebertragungAbgeschlossen = 0; |
437 | UebertragungAbgeschlossen = 0; |
164 | UDR = SendeBuffer[0]; |
438 | UDR = SendeBuffer[0]; |
165 | } |
439 | } |
Line 166... | Line -... | ||
166 | - | ||
167 | 440 | ||
168 | 441 | ||
169 | // -------------------------------------------------------------------------- |
442 | // -------------------------------------------------------------------------- |
170 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
443 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
171 | { |
444 | { |
Line 340... | Line 613... | ||
340 | //UBRR = 33; |
613 | //UBRR = 33; |
341 | //öffnet einen Kanal für printf (STDOUT) |
614 | //öffnet einen Kanal für printf (STDOUT) |
342 | //fdevopen (uart_putchar, 0); |
615 | //fdevopen (uart_putchar, 0); |
343 | //sbi(PORTD,4); |
616 | //sbi(PORTD,4); |
344 | Debug_Timer = SetDelay(200); |
617 | Debug_Timer = SetDelay(200); |
- | 618 | ||
- | 619 | gpsState = GPS_EMPTY; |
|
345 | } |
620 | } |
Line 346... | Line 621... | ||
346 | 621 | ||
347 | //--------------------------------------------------------------------------------------------- |
622 | //--------------------------------------------------------------------------------------------- |
348 | void DatenUebertragung(void) |
623 | void DatenUebertragung(void) |