Subversion Repositories FlightCtrl

Rev

Rev 1435 | Rev 1441 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1435 Rev 1438
Line 6... Line 6...
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
#include <stdarg.h>
7
#include <stdarg.h>
8
#include <string.h>
8
#include <string.h>
9
#include "main.h"
9
#include "main.h"
10
#include "uart.h"
10
#include "uart.h"
-
 
11
#include "libfc.h"
Line 11... Line 12...
11
 
12
 
12
 
13
 
13
#define FC_ADDRESS 1
14
#define FC_ADDRESS 1
Line 17... Line 18...
17
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
18
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
Line 18... Line 19...
18
 
19
 
19
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
20
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
20
unsigned char DisplayLine = 0;
21
unsigned char DisplayLine = 0;
21
unsigned volatile char SioTmp = 0;
-
 
22
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
-
 
23
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
22
unsigned volatile char SioTmp = 0;
24
unsigned volatile char NeuerDatensatzEmpfangen = 0;
23
unsigned volatile char NeuerDatensatzEmpfangen = 0;
25
unsigned volatile char NeueKoordinateEmpfangen = 0;
24
unsigned volatile char NeueKoordinateEmpfangen = 0;
26
unsigned volatile char UebertragungAbgeschlossen = 1;
25
unsigned volatile char UebertragungAbgeschlossen = 1;
27
unsigned volatile char CntCrcError = 0;
26
unsigned volatile char CntCrcError = 0;
Line 93... Line 92...
93
 static unsigned int ptr = 0;
92
 static unsigned int ptr = 0;
94
 unsigned char tmp_tx;
93
 unsigned char tmp_tx;
95
 if(!UebertragungAbgeschlossen)
94
 if(!UebertragungAbgeschlossen)
96
  {
95
  {
97
   ptr++;                    // die [0] wurde schon gesendet
96
   ptr++;                    // die [0] wurde schon gesendet
98
   tmp_tx = SendeBuffer[ptr];
97
   tmp_tx = TxdBuffer[ptr];
99
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
98
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
100
    {
99
    {
101
     ptr = 0;
100
     ptr = 0;
102
     UebertragungAbgeschlossen = 1;
101
     UebertragungAbgeschlossen = 1;
103
    }
102
    }
Line 115... Line 114...
115
 static unsigned char crc1,crc2,buf_ptr;
114
 static unsigned char crc1,crc2,buf_ptr;
116
 static unsigned char UartState = 0;
115
 static unsigned char UartState = 0;
117
 unsigned char CrcOkay = 0;
116
 unsigned char CrcOkay = 0;
Line 118... Line 117...
118
 
117
 
119
 SioTmp = UDR;
118
 SioTmp = UDR;
120
 if(buf_ptr >= MAX_EMPFANGS_BUFF)    UartState = 0;
119
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
121
 if(SioTmp == '\r' && UartState == 2)
120
 if(SioTmp == '\r' && UartState == 2)
122
  {
121
  {
123
   UartState = 0;
122
   UartState = 0;
124
   crc -= RxdBuffer[buf_ptr-2];
123
   crc -= RxdBuffer[buf_ptr-2];
Line 156... Line 155...
156
                  RxdBuffer[buf_ptr++] = SioTmp;
155
                  RxdBuffer[buf_ptr++] = SioTmp;
157
                  crc += SioTmp;
156
                  crc += SioTmp;
158
                  break;
157
                  break;
159
   case 2: //  Eingangsdaten sammeln
158
   case 2: //  Eingangsdaten sammeln
160
                  RxdBuffer[buf_ptr] = SioTmp;
159
                  RxdBuffer[buf_ptr] = SioTmp;
161
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
160
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;  
162
                  else UartState = 0;
161
                  else UartState = 0;
163
                  crc += SioTmp;
162
                  crc += SioTmp;
164
                  break;
163
                  break;
165
   default:
164
   default:
166
          UartState = 0;
165
          UartState = 0;
Line 173... Line 172...
173
void AddCRC(unsigned int wieviele)
172
void AddCRC(unsigned int wieviele)
174
{
173
{
175
 unsigned int tmpCRC = 0,i;
174
 unsigned int tmpCRC = 0,i;
176
 for(i = 0; i < wieviele;i++)
175
 for(i = 0; i < wieviele;i++)
177
  {
176
  {
178
   tmpCRC += SendeBuffer[i];
177
   tmpCRC += TxdBuffer[i];
179
  }
178
  }
180
   tmpCRC %= 4096;
179
   tmpCRC %= 4096;
181
   SendeBuffer[i++] = '=' + tmpCRC / 64;
180
   TxdBuffer[i++] = '=' + tmpCRC / 64;
182
   SendeBuffer[i++] = '=' + tmpCRC % 64;
181
   TxdBuffer[i++] = '=' + tmpCRC % 64;
183
   SendeBuffer[i++] = '\r';
182
   TxdBuffer[i++] = '\r';
184
  UebertragungAbgeschlossen = 0;
183
  UebertragungAbgeschlossen = 0;
185
  UDR = SendeBuffer[0];
184
  UDR = TxdBuffer[0];
186
}
185
}
Line 187... Line 186...
187
 
186
 
Line 196... Line 195...
196
 unsigned char ptr = 0;
195
 unsigned char ptr = 0;
Line 197... Line 196...
197
 
196
 
198
 unsigned char *snd = 0;
197
 unsigned char *snd = 0;
Line 199... Line 198...
199
 int len = 0;
198
 int len = 0;
200
 
199
 
201
 SendeBuffer[pt++] = '#';                               // Startzeichen
200
 TxdBuffer[pt++] = '#';                         // Startzeichen
Line 202... Line 201...
202
 SendeBuffer[pt++] = 'a' + address;             // Adresse (a=0; b=1,...)
201
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
203
 SendeBuffer[pt++] = cmd;                               // Commando
202
 TxdBuffer[pt++] = cmd;                         // Commando
204
 
203
 
205
 va_start(ap, BufferAnzahl);
204
 va_start(ap, BufferAnzahl);
Line 249... Line 248...
249
                        ptr = 0;
248
                        ptr = 0;
250
                        BufferAnzahl--;
249
                        BufferAnzahl--;
251
                }
250
                }
252
        }
251
        }
253
        else c = 0;
252
        else c = 0;
254
   SendeBuffer[pt++] = '=' + (a >> 2);
253
   TxdBuffer[pt++] = '=' + (a >> 2);
255
   SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
254
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
256
   SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
255
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
257
   SendeBuffer[pt++] = '=' + ( c & 0x3f);
256
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
258
  }
257
  }
259
 va_end(ap);
258
 va_end(ap);
260
 AddCRC(pt);
259
 AddCRC(pt);
261
}
260
}
Line 262... Line -...
262
 
-
 
263
 
261
 
264
// --------------------------------------------------------------------------
262
// --------------------------------------------------------------------------
265
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
263
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
266
{
264
{
267
 unsigned char a,b,c,d;
265
 unsigned char a,b,c,d;
Line 424... Line 422...
424
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
422
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
425
                                        Intervall3D = pRxData[0] * 10;
423
                                        Intervall3D = pRxData[0] * 10;
426
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
424
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
427
                                        break;
425
                                        break;
428
                        case 'd': // Poll the debug data
426
                        case 'd': // Poll the debug data
-
 
427
                                        PcZugriff = 255;
429
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
428
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
430
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
429
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
431
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
430
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
432
                                        break;
431
                                        break;
Line 481... Line 480...
481
        UDR = c;
480
        UDR = c;
Line 482... Line 481...
482
 
481
 
483
        return (0);
482
        return (0);
Line 484... Line -...
484
}
-
 
485
 
-
 
486
// --------------------------------------------------------------------------
-
 
487
void WriteProgramData(unsigned int pos, unsigned char wert)
-
 
488
{
-
 
489
  //if (ProgramLocation == IN_RAM) Buffer[pos] = wert;
-
 
490
  // else eeprom_write_byte(&EE_Buffer[pos], wert);
-
 
Line 491... Line 483...
491
  // Buffer[pos] = wert;
483
}
492
}
484
 
493
 
485
 
494
//############################################################################
486
//############################################################################