Subversion Repositories FlightCtrl

Rev

Rev 1739 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1739 Rev 1749
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) Holger Buss, Ingo Busker
2
// + Copyright (c) Holger Buss, Ingo Busker
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
#include <stdarg.h>
7
#include <stdarg.h>
8
#include <string.h>
8
#include <string.h>
9
#include <avr/pgmspace.h>
9
#include <avr/pgmspace.h>
10
#include "main.h"
10
#include "main.h"
11
#include "uart.h"
11
#include "uart.h"
12
#include "libfc.h"
12
#include "libfc.h"
13
#include "eeprom.h"
13
#include "eeprom.h"
14
 
14
 
15
 
15
 
16
 
16
 
17
#define FC_ADDRESS 1
17
#define FC_ADDRESS 1
18
#define NC_ADDRESS 2
18
#define NC_ADDRESS 2
19
#define MK3MAG_ADDRESS 3
19
#define MK3MAG_ADDRESS 3
20
#define BL_CTRL_ADDRESS 5
20
#define BL_CTRL_ADDRESS 5
21
 
21
 
22
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
22
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
23
#define MAX_SENDE_BUFF     160
23
#define MAX_SENDE_BUFF     160
24
#define MAX_EMPFANGS_BUFF  160
24
#define MAX_EMPFANGS_BUFF  160
25
 
25
 
26
 
26
 
27
#define BLPARAM_REVISION 1
27
#define BLPARAM_REVISION 1
28
#define MASK_SET_PWM_SCALING            0x01
28
#define MASK_SET_PWM_SCALING            0x01
29
#define MASK_SET_CURRENT_LIMIT          0x02
29
#define MASK_SET_CURRENT_LIMIT          0x02
30
#define MASK_SET_TEMP_LIMIT                     0x04
30
#define MASK_SET_TEMP_LIMIT                     0x04
31
#define MASK_SET_CURRENT_SCALING        0x08
31
#define MASK_SET_CURRENT_SCALING        0x08
32
#define MASK_SET_BITCONFIG                      0x10
32
#define MASK_SET_BITCONFIG                      0x10
33
#define MASK_RESET_CAPCOUNTER           0x20
33
#define MASK_RESET_CAPCOUNTER           0x20
34
#define MASK_SET_DEFAULT_PARAMS         0x40
34
#define MASK_SET_DEFAULT_PARAMS         0x40
35
#define MASK_SET_SAVE_EEPROM            0x80
35
#define MASK_SET_SAVE_EEPROM            0x80
36
 
36
 
37
typedef struct
37
typedef struct
38
{
38
{
39
        unsigned char Revision;                 // revision of parameter structure
39
        unsigned char Revision;                 // revision of parameter structure
40
        unsigned char Address;                  // target address
40
        unsigned char Address;                  // target address
41
        unsigned char PwmScaling;               // maximum value of pwm setpoint
41
        unsigned char PwmScaling;               // maximum value of pwm setpoint
42
        unsigned char CurrentLimit;             // current limit in 1A steps
42
        unsigned char CurrentLimit;             // current limit in 1A steps
43
        unsigned char TemperatureLimit; // in °C
43
        unsigned char TemperatureLimit; // in °C
44
        unsigned char CurrentScaling;   // scaling factor for current measurement
44
        unsigned char CurrentScaling;   // scaling factor for current measurement
45
        unsigned char BitConfig;                // see defines above
45
        unsigned char BitConfig;                // see defines above
46
        unsigned char SetMask;                  // filter for active paramters
46
        unsigned char SetMask;                  // filter for active paramters
47
        unsigned char Checksum;                 // checksum for parameter sturcture
47
        unsigned char Checksum;                 // checksum for parameter sturcture
48
}  __attribute__((packed)) BLParameter_t;
48
}  __attribute__((packed)) BLParameter_t;
49
 
49
 
50
 
50
 
51
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
51
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
52
unsigned char DisplayLine = 0;
52
unsigned char DisplayLine = 0;
53
unsigned volatile char SioTmp = 0;
53
unsigned volatile char SioTmp = 0;
54
unsigned volatile char NeuerDatensatzEmpfangen = 0;
54
unsigned volatile char NeuerDatensatzEmpfangen = 0;
55
unsigned volatile char NeueKoordinateEmpfangen = 0;
55
unsigned volatile char NeueKoordinateEmpfangen = 0;
56
unsigned volatile char UebertragungAbgeschlossen = 1;
56
unsigned volatile char UebertragungAbgeschlossen = 1;
57
unsigned volatile char CntCrcError = 0;
57
unsigned volatile char CntCrcError = 0;
58
unsigned volatile char AnzahlEmpfangsBytes = 0;
58
unsigned volatile char AnzahlEmpfangsBytes = 0;
59
unsigned volatile char TxdBuffer[MAX_SENDE_BUFF];
59
unsigned volatile char TxdBuffer[MAX_SENDE_BUFF];
60
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
60
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
61
 
61
 
62
unsigned char *pRxData = 0;
62
unsigned char *pRxData = 0;
63
unsigned char RxDataLen = 0;
63
unsigned char RxDataLen = 0;
64
unsigned volatile char PC_DebugTimeout = 0;
64
unsigned volatile char PC_DebugTimeout = 0;
65
unsigned volatile char PC_MotortestActive = 0;
65
unsigned volatile char PC_MotortestActive = 0;
66
unsigned char DebugTextAnforderung = 255;
66
unsigned char DebugTextAnforderung = 255;
67
 
67
 
68
unsigned char PcZugriff = 100;
68
unsigned char PcZugriff = 100;
69
unsigned char MotorTest[16];
69
unsigned char MotorTest[16];
70
unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl
70
unsigned char MeineSlaveAdresse = 1; // Flight-Ctrl
71
unsigned char ConfirmFrame;
71
unsigned char ConfirmFrame;
72
struct str_DebugOut    DebugOut;
72
struct str_DebugOut    DebugOut;
73
struct str_ExternControl  ExternControl;
73
struct str_ExternControl  ExternControl;
74
struct str_VersionInfo VersionInfo;
74
struct str_VersionInfo VersionInfo;
75
struct str_WinkelOut WinkelOut;
75
struct str_WinkelOut WinkelOut;
76
struct str_Data3D Data3D;
76
struct str_Data3D Data3D;
77
 
77
 
78
int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D;
78
int Display_Timer, Debug_Timer,Kompass_Timer,Timer3D;
79
unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0;
79
unsigned int DebugDataIntervall = 0, Intervall3D = 0, Display_Interval = 0;
80
unsigned int AboTimeOut = 0;
80
unsigned int AboTimeOut = 0;
-
 
81
 
81
 
82
 
82
const unsigned char ANALOG_TEXT[32][16] PROGMEM =
83
const unsigned char ANALOG_TEXT[32][13] PROGMEM =
83
{
84
{
84
   //1234567890123456
85
   //1234567890123456
85
    "AngleNick       ", //0
86
    "AngleNick    ", //0
86
    "AngleRoll       ",
87
    "AngleRoll    ",
87
    "AccNick         ",
88
    "AccNick      ",
88
    "AccRoll         ",
89
    "AccRoll      ",
89
    "YawGyro         ",
90
    "YawGyro      ",
90
    "Height Value    ", //5
91
    "Height Value ", //5
91
    "AccZ            ",
92
    "AccZ         ",
92
    "Gas             ",
93
    "Gas          ",
93
    "Compass Value   ",
94
    "Compass Value",
94
    "Voltage [0.1V]  ",
95
    "Voltage[0.1V]",
95
    "Receiver Level  ", //10
96
    "ReceiverLevel", //10
96
    "Gyro Compass    ",
97
    "Gyro Compass ",
97
    "Motor 1         ",
98
    "Motor 1      ",
98
    "Motor 2         ",
99
    "Motor 2      ",
99
    "Motor 3         ",
100
    "Motor 3      ",
100
    "Motor 4         ", //15
101
    "Motor 4      ", //15
101
    "Motor 5         ",
102
    "Motor 5      ",
102
    "Motor 6         ",
103
    "Motor 6      ",
103
    "18              ",
104
    "18           ",
104
    "WoutCalcState   ",
105
    "WoutCalcState",
105
    "Servo           ", //20
106
    "Servo        ", //20
106
    "Hovergas        ",
107
    "Hovergas     ",
107
    "Current [0.1A]  ",
108
    "Current[0.1A]",
108
    "Capacity [mAh]  ",
109
    "Capacity[mAh]",
109
    "Motor 7         ",
110
    "Motor 7      ",
110
    "Motor 8         ", //25
111
    "Motor 8      ", //25
111
    "Motor 9         ",
112
    "Motor 9      ",
112
    "Motor 10        ",
113
    "Motor 10     ",
113
    "I2C-Error       ",
114
    "I2C-Error    ",
114
    "BL Limit        ",
115
    "BL Limit     ",
115
    "GPS_Nick        ", //30
116
    "GPS_Nick     ", //30
116
    "GPS_Roll        "
117
    "GPS_Roll     "
117
};
118
};
118
 
119
 
-
 
120
 
119
 
121
 
120
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121
//++ Sende-Part der Datenübertragung
123
//++ Sende-Part der Datenübertragung
122
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123
ISR(USART0_TX_vect)
125
ISR(USART0_TX_vect)
124
{
126
{
125
 static unsigned int ptr = 0;
127
 static unsigned int ptr = 0;
126
 unsigned char tmp_tx;
128
 unsigned char tmp_tx;
127
 if(!UebertragungAbgeschlossen)
129
 if(!UebertragungAbgeschlossen)
128
  {
130
  {
129
   ptr++;                    // die [0] wurde schon gesendet
131
   ptr++;                    // die [0] wurde schon gesendet
130
   tmp_tx = TxdBuffer[ptr];
132
   tmp_tx = TxdBuffer[ptr];
131
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
133
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
132
    {
134
    {
133
     ptr = 0;
135
     ptr = 0;
134
     UebertragungAbgeschlossen = 1;
136
     UebertragungAbgeschlossen = 1;
135
    }
137
    }
136
   UDR0 = tmp_tx;
138
   UDR0 = tmp_tx;
137
  }
139
  }
138
  else ptr = 0;
140
  else ptr = 0;
139
}
141
}
140
 
142
 
141
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
144
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
143
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
145
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
144
ISR(USART0_RX_vect)
146
ISR(USART0_RX_vect)
145
{
147
{
146
 static unsigned int crc;
148
 static unsigned int crc;
147
 static unsigned char crc1,crc2,buf_ptr;
149
 static unsigned char crc1,crc2,buf_ptr;
148
 static unsigned char UartState = 0;
150
 static unsigned char UartState = 0;
149
 unsigned char CrcOkay = 0;
151
 unsigned char CrcOkay = 0;
150
 
152
 
151
 SioTmp = UDR0;
153
 SioTmp = UDR0;
152
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
154
 if(buf_ptr >= MAX_SENDE_BUFF)    UartState = 0;
153
 if(SioTmp == '\r' && UartState == 2)
155
 if(SioTmp == '\r' && UartState == 2)
154
  {
156
  {
155
   UartState = 0;
157
   UartState = 0;
156
   crc -= RxdBuffer[buf_ptr-2];
158
   crc -= RxdBuffer[buf_ptr-2];
157
   crc -= RxdBuffer[buf_ptr-1];
159
   crc -= RxdBuffer[buf_ptr-1];
158
   crc %= 4096;
160
   crc %= 4096;
159
   crc1 = '=' + crc / 64;
161
   crc1 = '=' + crc / 64;
160
   crc2 = '=' + crc % 64;
162
   crc2 = '=' + crc % 64;
161
   CrcOkay = 0;
163
   CrcOkay = 0;
162
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
164
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
163
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
165
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
164
    {
166
    {
165
     NeuerDatensatzEmpfangen = 1;
167
     NeuerDatensatzEmpfangen = 1;
166
         AnzahlEmpfangsBytes = buf_ptr + 1;
168
         AnzahlEmpfangsBytes = buf_ptr + 1;
167
     RxdBuffer[buf_ptr] = '\r';
169
     RxdBuffer[buf_ptr] = '\r';
168
         if(RxdBuffer[2] == 'R')
170
         if(RxdBuffer[2] == 'R')
169
          {
171
          {
-
 
172
          #ifdef NODISPLAY                      //  main.h
-
 
173
 
-
 
174
#warning : "### no MKTool Display ###"
170
           LcdClear();
175
           LcdClear();
-
 
176
           #endif
171
           wdt_enable(WDTO_250MS); // Reset-Commando
177
           wdt_enable(WDTO_250MS); // Reset-Commando
172
           ServoActive = 0;
178
           ServoActive = 0;
173
 
179
 
174
          }
180
          }
175
        }
181
        }
176
  }
182
  }
177
  else
183
  else
178
  switch(UartState)
184
  switch(UartState)
179
  {
185
  {
180
   case 0:
186
   case 0:
181
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
187
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
182
                  buf_ptr = 0;
188
                  buf_ptr = 0;
183
                  RxdBuffer[buf_ptr++] = SioTmp;
189
                  RxdBuffer[buf_ptr++] = SioTmp;
184
                  crc = SioTmp;
190
                  crc = SioTmp;
185
          break;
191
          break;
186
   case 1: // Adresse auswerten
192
   case 1: // Adresse auswerten
187
                  UartState++;
193
                  UartState++;
188
                  RxdBuffer[buf_ptr++] = SioTmp;
194
                  RxdBuffer[buf_ptr++] = SioTmp;
189
                  crc += SioTmp;
195
                  crc += SioTmp;
190
                  break;
196
                  break;
191
   case 2: //  Eingangsdaten sammeln
197
   case 2: //  Eingangsdaten sammeln
192
                  RxdBuffer[buf_ptr] = SioTmp;
198
                  RxdBuffer[buf_ptr] = SioTmp;
193
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
199
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
194
                  else UartState = 0;
200
                  else UartState = 0;
195
                  crc += SioTmp;
201
                  crc += SioTmp;
196
                  break;
202
                  break;
197
   default:
203
   default:
198
          UartState = 0;
204
          UartState = 0;
199
          break;
205
          break;
200
  }
206
  }
201
}
207
}
202
 
208
 
203
 
209
 
204
// --------------------------------------------------------------------------
210
// --------------------------------------------------------------------------
205
void AddCRC(unsigned int wieviele)
211
void AddCRC(unsigned int wieviele)
206
{
212
{
207
 unsigned int tmpCRC = 0,i;
213
 unsigned int tmpCRC = 0,i;
208
 for(i = 0; i < wieviele;i++)
214
 for(i = 0; i < wieviele;i++)
209
  {
215
  {
210
   tmpCRC += TxdBuffer[i];
216
   tmpCRC += TxdBuffer[i];
211
  }
217
  }
212
   tmpCRC %= 4096;
218
   tmpCRC %= 4096;
213
   TxdBuffer[i++] = '=' + tmpCRC / 64;
219
   TxdBuffer[i++] = '=' + tmpCRC / 64;
214
   TxdBuffer[i++] = '=' + tmpCRC % 64;
220
   TxdBuffer[i++] = '=' + tmpCRC % 64;
215
   TxdBuffer[i++] = '\r';
221
   TxdBuffer[i++] = '\r';
216
  UebertragungAbgeschlossen = 0;
222
  UebertragungAbgeschlossen = 0;
217
  UDR0 = TxdBuffer[0];
223
  UDR0 = TxdBuffer[0];
218
}
224
}
219
 
225
 
220
 
226
 
221
 
227
 
222
// --------------------------------------------------------------------------
228
// --------------------------------------------------------------------------
223
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
229
void SendOutData(unsigned char cmd,unsigned char address, unsigned char BufferAnzahl, ...) //unsigned char *snd, unsigned char len)
224
{
230
{
225
 va_list ap;
231
 va_list ap;
226
 unsigned int pt = 0;
232
 unsigned int pt = 0;
227
 unsigned char a,b,c;
233
 unsigned char a,b,c;
228
 unsigned char ptr = 0;
234
 unsigned char ptr = 0;
229
 
235
 
230
 unsigned char *snd = 0;
236
 unsigned char *snd = 0;
231
 int len = 0;
237
 int len = 0;
232
 
238
 
233
 TxdBuffer[pt++] = '#';                         // Startzeichen
239
 TxdBuffer[pt++] = '#';                         // Startzeichen
234
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
240
 TxdBuffer[pt++] = 'a' + address;               // Adresse (a=0; b=1,...)
235
 TxdBuffer[pt++] = cmd;                         // Commando
241
 TxdBuffer[pt++] = cmd;                         // Commando
236
 
242
 
237
 va_start(ap, BufferAnzahl);
243
 va_start(ap, BufferAnzahl);
238
 if(BufferAnzahl)
244
 if(BufferAnzahl)
239
 {
245
 {
240
                snd = va_arg(ap, unsigned char*);
246
                snd = va_arg(ap, unsigned char*);
241
                len = va_arg(ap, int);
247
                len = va_arg(ap, int);
242
                ptr = 0;
248
                ptr = 0;
243
                BufferAnzahl--;
249
                BufferAnzahl--;
244
 }
250
 }
245
 while(len)
251
 while(len)
246
  {
252
  {
247
        if(len)
253
        if(len)
248
        {
254
        {
249
           a = snd[ptr++];
255
           a = snd[ptr++];
250
           len--;
256
           len--;
251
           if((!len) && BufferAnzahl)
257
           if((!len) && BufferAnzahl)
252
                {
258
                {
253
                        snd = va_arg(ap, unsigned char*);
259
                        snd = va_arg(ap, unsigned char*);
254
                        len = va_arg(ap, int);
260
                        len = va_arg(ap, int);
255
                        ptr = 0;
261
                        ptr = 0;
256
                        BufferAnzahl--;
262
                        BufferAnzahl--;
257
                }
263
                }
258
        }
264
        }
259
        else a = 0;
265
        else a = 0;
260
        if(len)
266
        if(len)
261
        {
267
        {
262
                b = snd[ptr++];
268
                b = snd[ptr++];
263
                len--;
269
                len--;
264
                if((!len) && BufferAnzahl)
270
                if((!len) && BufferAnzahl)
265
                {
271
                {
266
                        snd = va_arg(ap, unsigned char*);
272
                        snd = va_arg(ap, unsigned char*);
267
                        len = va_arg(ap, int);
273
                        len = va_arg(ap, int);
268
                        ptr = 0;
274
                        ptr = 0;
269
                        BufferAnzahl--;
275
                        BufferAnzahl--;
270
                }
276
                }
271
        }
277
        }
272
        else b = 0;
278
        else b = 0;
273
        if(len)
279
        if(len)
274
        {
280
        {
275
                c = snd[ptr++];
281
                c = snd[ptr++];
276
                len--;
282
                len--;
277
                if((!len) && BufferAnzahl)
283
                if((!len) && BufferAnzahl)
278
                {
284
                {
279
                        snd = va_arg(ap, unsigned char*);
285
                        snd = va_arg(ap, unsigned char*);
280
                        len = va_arg(ap, int);
286
                        len = va_arg(ap, int);
281
                        ptr = 0;
287
                        ptr = 0;
282
                        BufferAnzahl--;
288
                        BufferAnzahl--;
283
                }
289
                }
284
        }
290
        }
285
        else c = 0;
291
        else c = 0;
286
   TxdBuffer[pt++] = '=' + (a >> 2);
292
   TxdBuffer[pt++] = '=' + (a >> 2);
287
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
293
   TxdBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
288
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
294
   TxdBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
289
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
295
   TxdBuffer[pt++] = '=' + ( c & 0x3f);
290
  }
296
  }
291
 va_end(ap);
297
 va_end(ap);
292
 AddCRC(pt);
298
 AddCRC(pt);
293
}
299
}
294
 
300
 
295
// --------------------------------------------------------------------------
301
// --------------------------------------------------------------------------
296
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
302
void Decode64(void)  // die daten werden im rx buffer dekodiert, das geht nur, weil aus 4 byte immer 3 gemacht werden.
297
{
303
{
298
 unsigned char a,b,c,d;
304
 unsigned char a,b,c,d;
299
 unsigned char x,y,z;
305
 unsigned char x,y,z;
300
 unsigned char ptrIn = 3; // start at begin of data block
306
 unsigned char ptrIn = 3; // start at begin of data block
301
 unsigned char ptrOut = 3;
307
 unsigned char ptrOut = 3;
302
 unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers  ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab.
308
 unsigned char len = AnzahlEmpfangsBytes - 6; // von der Gesamtbytezahl eines Frames gehen 3 Bytes des Headers  ('#',Addr, Cmd) und 3 Bytes des Footers (CRC1, CRC2, '\r') ab.
303
 
309
 
304
 while(len)
310
 while(len)
305
  {
311
  {
306
   a = RxdBuffer[ptrIn++] - '=';
312
   a = RxdBuffer[ptrIn++] - '=';
307
   b = RxdBuffer[ptrIn++] - '=';
313
   b = RxdBuffer[ptrIn++] - '=';
308
   c = RxdBuffer[ptrIn++] - '=';
314
   c = RxdBuffer[ptrIn++] - '=';
309
   d = RxdBuffer[ptrIn++] - '=';
315
   d = RxdBuffer[ptrIn++] - '=';
310
 
316
 
311
   x = (a << 2) | (b >> 4);
317
   x = (a << 2) | (b >> 4);
312
   y = ((b & 0x0f) << 4) | (c >> 2);
318
   y = ((b & 0x0f) << 4) | (c >> 2);
313
   z = ((c & 0x03) << 6) | d;
319
   z = ((c & 0x03) << 6) | d;
314
 
320
 
315
   if(len--) RxdBuffer[ptrOut++] = x; else break;
321
   if(len--) RxdBuffer[ptrOut++] = x; else break;
316
   if(len--) RxdBuffer[ptrOut++] = y; else break;
322
   if(len--) RxdBuffer[ptrOut++] = y; else break;
317
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
323
   if(len--) RxdBuffer[ptrOut++] = z;   else break;
318
  }
324
  }
319
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
325
        pRxData = (unsigned char*)&RxdBuffer[3]; // decodierte Daten beginnen beim 4. Byte
320
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
326
        RxDataLen = ptrOut - 3;  // wie viele Bytes wurden dekodiert?
321
 
327
 
322
}
328
}
323
 
329
 
324
// --------------------------------------------------------------------------
330
// --------------------------------------------------------------------------
325
void BearbeiteRxDaten(void)
331
void BearbeiteRxDaten(void)
326
{
332
{
327
 if(!NeuerDatensatzEmpfangen) return;
333
 if(!NeuerDatensatzEmpfangen) return;
328
 
334
 
329
        unsigned char tempchar1, tempchar2;
335
        unsigned char tempchar1, tempchar2;
330
        Decode64(); // dekodiere datenblock im Empfangsbuffer
336
        Decode64(); // dekodiere datenblock im Empfangsbuffer
331
        switch(RxdBuffer[1]-'a') // check for Slave Address
337
        switch(RxdBuffer[1]-'a') // check for Slave Address
332
        {
338
        {
333
                case FC_ADDRESS: // FC special commands
339
                case FC_ADDRESS: // FC special commands
334
                switch(RxdBuffer[2])
340
                switch(RxdBuffer[2])
335
                {
341
                {
336
                        case 'K':// Kompasswert
342
                        case 'K':// Kompasswert
337
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
343
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
338
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
344
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
339
                                        break;
345
                                        break;
340
                        case 't':// Motortest
346
                        case 't':// Motortest
341
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
347
                                if(AnzahlEmpfangsBytes > 20) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
342
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
348
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
343
                                        PC_MotortestActive = 240;
349
                                        PC_MotortestActive = 240;
344
                                        //while(!UebertragungAbgeschlossen);
350
                                        //while(!UebertragungAbgeschlossen);
345
                                        //SendOutData('T', MeineSlaveAdresse, 0);
351
                                        //SendOutData('T', MeineSlaveAdresse, 0);
346
                                        PcZugriff = 255;
352
                                        PcZugriff = 255;
347
                                        break;
353
                                        break;
348
 
354
 
349
                        case 'n':// "Get Mixer
355
                        case 'n':// "Get Mixer
350
                                        while(!UebertragungAbgeschlossen);
356
                                        while(!UebertragungAbgeschlossen);
351
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
357
                    SendOutData('N', FC_ADDRESS, 1, (unsigned char *) &Mixer, sizeof(Mixer) - 1);
352
                                        Debug("Mixer lesen");
358
                                        Debug("Mixer lesen");
353
                                        break;
359
                                        break;
354
 
360
 
355
                        case 'm':// "Write Mixer
361
                        case 'm':// "Write Mixer
356
                    if(pRxData[0] == EEMIXER_REVISION)
362
                    if(pRxData[0] == EEMIXER_REVISION)
357
                                        {
363
                                        {
358
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
364
                       memcpy(&Mixer, (unsigned char *)pRxData, sizeof(Mixer) - 1);
359
                       MixerTable_WriteToEEProm();
365
                       MixerTable_WriteToEEProm();
360
                                           tempchar1 = 1;
366
                                           tempchar1 = 1;
361
                                           VersionInfo.HardwareError[1] &= ~DEFEKT_MIXER_ERR;
367
                                           VersionInfo.HardwareError[1] &= ~DEFEKT_MIXER_ERR;
362
                                        }
368
                                        }
363
                    else
369
                    else
364
                    {
370
                    {
365
                                                tempchar1 = 0;
371
                                                tempchar1 = 0;
366
                                        }
372
                                        }
367
                                        while(!UebertragungAbgeschlossen);
373
                                        while(!UebertragungAbgeschlossen);
368
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
374
                                        SendOutData('M', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
369
                                        break;
375
                                        break;
370
 
376
 
371
                        case 'p': // get PPM Channels
377
                        case 'p': // get PPM Channels
372
                                        GetPPMChannelAnforderung = 1;
378
                                        GetPPMChannelAnforderung = 1;
373
                                        PcZugriff = 255;
379
                                        PcZugriff = 255;
374
                                        break;
380
                                        break;
375
 
381
 
376
                        case 'q':// "Get"-Anforderung für Settings
382
                        case 'q':// "Get"-Anforderung für Settings
377
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
383
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
378
                                        if(pRxData[0] == 0xFF)
384
                                        if(pRxData[0] == 0xFF)
379
                                        {
385
                                        {
380
                                                pRxData[0] = GetActiveParamSet();
386
                                                pRxData[0] = GetActiveParamSet();
381
                                        }
387
                                        }
382
                                        // limit settings range
388
                                        // limit settings range
383
                                        if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5
389
                                        if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5
384
                                        else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5
390
                                        else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5
385
                                        // load requested parameter set
391
                                        // load requested parameter set
386
                                        ParamSet_ReadFromEEProm(pRxData[0]);
392
                                        ParamSet_ReadFromEEProm(pRxData[0]);
387
                                        tempchar1 = pRxData[0];
393
                                        tempchar1 = pRxData[0];
388
                                        while(!UebertragungAbgeschlossen);
394
                                        while(!UebertragungAbgeschlossen);
389
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
395
                                        SendOutData('Q', FC_ADDRESS, 2, &tempchar1, sizeof(tempchar1), (unsigned char *) &EE_Parameter, sizeof(EE_Parameter) - 1);
390
                                        Debug("Lese Setting %d", tempchar1);
396
                                        Debug("Lese Setting %d", tempchar1);
391
 
397
 
392
                                        break;
398
                                        break;
393
 
399
 
394
                        case 's': // Parametersatz speichern
400
                        case 's': // Parametersatz speichern
395
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION)) // check for setting to be in range
401
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] == EEPARAM_REVISION)) // check for setting to be in range
396
                                        {
402
                                        {
397
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
403
                                                memcpy(&EE_Parameter, (uint8_t*)&pRxData[1], sizeof(EE_Parameter) - 1);
398
                                                ParamSet_WriteToEEProm(pRxData[0]);
404
                                                ParamSet_WriteToEEProm(pRxData[0]);
399
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
405
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
400
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
406
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
401
                                                tempchar1 = GetActiveParamSet();
407
                                                tempchar1 = GetActiveParamSet();
402
                                        }
408
                                        }
403
                                        else
409
                                        else
404
                                        {
410
                                        {
405
                                                tempchar1 = 0; // mark in response an invlid setting
411
                                                tempchar1 = 0; // mark in response an invlid setting
406
                                        }
412
                                        }
407
                                        while(!UebertragungAbgeschlossen);
413
                                        while(!UebertragungAbgeschlossen);
408
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
414
                                        SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
409
                                        if(!MotorenEin) Piep(tempchar1,110);
415
                                        if(!MotorenEin) Piep(tempchar1,110);
410
                                        LipoDetection(0);
416
                                        LipoDetection(0);
411
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
417
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
412
                                        break;
418
                                        break;
413
                        case 'f': // auf anderen Parametersatz umschalten
419
                        case 'f': // auf anderen Parametersatz umschalten
414
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
420
                                if((1 <= pRxData[0]) && (pRxData[0] <= 5)) ParamSet_ReadFromEEProm(pRxData[0]);
415
                                        tempchar1 = GetActiveParamSet();
421
                                        tempchar1 = GetActiveParamSet();
416
                                        while(!UebertragungAbgeschlossen);
422
                                        while(!UebertragungAbgeschlossen);
417
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
423
                                        SendOutData('F', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1));
418
                                        if(!MotorenEin) Piep(tempchar1,110);
424
                                        if(!MotorenEin) Piep(tempchar1,110);
419
                                        LipoDetection(0);
425
                                        LipoDetection(0);
420
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
426
                                        LIBFC_ReceiverInit(EE_Parameter.Receiver);
421
                                        break;
427
                                        break;
422
                        case 'y':// serial Potis
428
                        case 'y':// serial Potis
423
                                        PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3];
429
                                        PPM_in[13] = (signed char) pRxData[0]; PPM_in[14] = (signed char) pRxData[1]; PPM_in[15] = (signed char) pRxData[2]; PPM_in[16] = (signed char) pRxData[3];
424
                                        PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7];
430
                                        PPM_in[17] = (signed char) pRxData[4]; PPM_in[18] = (signed char) pRxData[5]; PPM_in[19] = (signed char) pRxData[6]; PPM_in[20] = (signed char) pRxData[7];
425
                                        PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11];
431
                                        PPM_in[21] = (signed char) pRxData[8]; PPM_in[22] = (signed char) pRxData[9]; PPM_in[23] = (signed char) pRxData[10]; PPM_in[24] = (signed char) pRxData[11];
426
                                        break;
432
                                        break;
427
 
433
 
428
                        case 'u': // request BL parameter
434
                        case 'u': // request BL parameter
429
                                Debug("Reading BL %d", pRxData[0]);
435
                                Debug("Reading BL %d", pRxData[0]);
430
                                // try to read BL configuration
436
                                // try to read BL configuration
431
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
437
                                tempchar2 = I2C_ReadBLConfig(pRxData[0]);
432
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
438
                                if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
433
                                else tempchar1 = 0;
439
                                else tempchar1 = 0;
434
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
440
                                while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
435
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
441
                                SendOutData('U', FC_ADDRESS, 4, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2), &pRxData[0], 1, &BLConfig, sizeof(BLConfig_t));
436
                                break;
442
                                break;
437
 
443
 
438
                        case 'w': // write BL parameter
444
                        case 'w': // write BL parameter
439
                                Debug("Writing BL %d", pRxData[0]);
445
                                Debug("Writing BL %d", pRxData[0]);
440
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
446
                                if(RxDataLen >= 1+sizeof(BLConfig_t))
441
                                {
447
                                {
442
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
448
                                        memcpy(&BLConfig, (uint8_t*)(&pRxData[1]), sizeof(BLConfig_t));
443
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
449
                                        tempchar2 = I2C_WriteBLConfig(pRxData[0]);
444
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
450
                                        if(tempchar2 == BLCONFIG_SUCCESS) tempchar1 = 1;
445
                                        else tempchar1 = 0; // indicate error
451
                                        else tempchar1 = 0; // indicate error
446
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
452
                                        while(!UebertragungAbgeschlossen); // wait for previous frame to be sent
447
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
453
                                        SendOutData('W', FC_ADDRESS,2, &tempchar1, sizeof(tempchar1), &tempchar2, sizeof(tempchar2));
448
                                }
454
                                }
449
                                break;
455
                                break;
450
 
456
 
451
                } // case FC_ADDRESS:
457
                } // case FC_ADDRESS:
452
 
458
 
453
                default: // any Slave Address
459
                default: // any Slave Address
454
 
460
 
455
                switch(RxdBuffer[2])
461
                switch(RxdBuffer[2])
456
                {
462
                {
457
                        // 't' comand placed here only for compatibility to BL
463
                        // 't' comand placed here only for compatibility to BL
458
                        case 't':// Motortest
464
                        case 't':// Motortest
459
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
465
                                if(AnzahlEmpfangsBytes >= sizeof(MotorTest)) memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
460
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
466
                                else memcpy(&MotorTest[0], (unsigned char *)pRxData, 4);
461
                                        while(!UebertragungAbgeschlossen);
467
                                        while(!UebertragungAbgeschlossen);
462
                                        SendOutData('T', MeineSlaveAdresse, 0);
468
                                        SendOutData('T', MeineSlaveAdresse, 0);
463
                                        PC_MotortestActive = 250;
469
                                        PC_MotortestActive = 250;
464
                                        PcZugriff = 255;
470
                                        PcZugriff = 255;
465
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
471
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
466
                                        break;
472
                                        break;
467
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
473
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
468
                        case 'K':// Kompasswert
474
                        case 'K':// Kompasswert
469
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
475
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
470
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
476
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
471
                                        break;
477
                                        break;
472
                        case 'a':// Texte der Analogwerte
478
                        case 'a':// Texte der Analogwerte
473
                                        DebugTextAnforderung = pRxData[0];
479
                                        DebugTextAnforderung = pRxData[0];
474
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
480
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
475
                                        PcZugriff = 255;
481
                                        PcZugriff = 255;
476
                                        break;
482
                                        break;
477
                        case 'b':
483
                        case 'b':
478
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
484
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
479
                                        ConfirmFrame = ExternControl.Frame;
485
                                        ConfirmFrame = ExternControl.Frame;
480
                                        PcZugriff = 255;
486
                                        PcZugriff = 255;
481
                                        break;
487
                                        break;
482
                        case 'c': // Poll the 3D-Data
488
                        case 'c': // Poll the 3D-Data
483
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
489
                    if(!Intervall3D) { if(pRxData[0]) Timer3D = SetDelay(pRxData[0] * 10);}
484
                                        Intervall3D = pRxData[0] * 10;
490
                                        Intervall3D = pRxData[0] * 10;
485
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
491
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
486
                                        break;
492
                                        break;
487
                        case 'd': // Poll the debug data
493
                        case 'd': // Poll the debug data
488
                                        PcZugriff = 255;
494
                                        PcZugriff = 255;
489
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
495
                                        DebugDataIntervall = (unsigned int)pRxData[0] * 10;
490
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
496
                                        if(DebugDataIntervall > 0) DebugDataAnforderung = 1;
491
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
497
                                        AboTimeOut = SetDelay(ABO_TIMEOUT);
492
                                        break;
498
                                        break;
493
 
499
 
494
                        case 'h':// x-1 Displayzeilen
500
                        case 'h':// x-1 Displayzeilen
-
 
501
                       
-
 
502
                        #ifdef NODISPLAY                                                                                                                        // only include functions if DEBUG is defined in main.h
-
 
503
#warning : "### no MKTool Display ###"
-
 
504
 
495
                                PcZugriff = 255;
505
                                PcZugriff = 255;
496
                                if((pRxData[0] & 0x80) == 0x00) // old format
506
                                if((pRxData[0] & 0x80) == 0x00) // old format
497
                                        {
507
                                        {
498
                                                DisplayLine = 2;
508
                                                DisplayLine = 2;
499
                                                Display_Interval = 0;
509
                                                Display_Interval = 0;
500
                                        }
510
                                        }
501
                                        else // new format
511
                                        else // new format
502
                                        {
512
                                        {
503
                                                RemoteKeys |= ~pRxData[0];
513
                                                RemoteKeys |= ~pRxData[0];
504
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
514
                                                Display_Interval = (unsigned int)pRxData[1] * 10;
505
                                                DisplayLine = 4;
515
                                                DisplayLine = 4;
506
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
516
                                                AboTimeOut = SetDelay(ABO_TIMEOUT);
507
                                        }
517
                                        }
508
                                        DebugDisplayAnforderung = 1;
518
                                        DebugDisplayAnforderung = 1;
509
                                        break;
519
                                        break;
510
 
520
 
511
                        case 'l':// x-1 Displayzeilen
521
                        case 'l':// x-1 Displayzeilen
512
                                PcZugriff = 255;
522
                                PcZugriff = 255;
513
                                        MenuePunkt = pRxData[0];
523
                                        MenuePunkt = pRxData[0];
514
                                        DebugDisplayAnforderung1 = 1;
524
                                        DebugDisplayAnforderung1 = 1;
515
                                        break;
525
                                        break;
-
 
526
                                        #endif
516
                        case 'v': // Version-Anforderung und Ausbaustufe
527
                        case 'v': // Version-Anforderung und Ausbaustufe
517
                                        GetVersionAnforderung = 1;
528
                                        GetVersionAnforderung = 1;
518
                                        break;
529
                                        break;
519
 
530
 
520
                        case 'g'://
531
                        case 'g'://
521
                                        GetExternalControl = 1;
532
                                        GetExternalControl = 1;
522
                                        break;
533
                                        break;
523
 
534
 
524
                        default:
535
                        default:
525
                                //unsupported command received
536
                                //unsupported command received
526
                                break;
537
                                break;
527
                }
538
                }
528
                break; // default:
539
                break; // default:
529
        }
540
        }
530
        NeuerDatensatzEmpfangen = 0;
541
        NeuerDatensatzEmpfangen = 0;
531
        pRxData = 0;
542
        pRxData = 0;
532
        RxDataLen = 0;
543
        RxDataLen = 0;
533
}
544
}
534
 
545
 
535
//############################################################################
546
//############################################################################
536
//Routine für die Serielle Ausgabe
547
//Routine für die Serielle Ausgabe
537
void uart_putchar (char c)
548
void uart_putchar (char c)
538
//############################################################################
549
//############################################################################
539
{
550
{
540
        //Warten solange bis Zeichen gesendet wurde
551
        //Warten solange bis Zeichen gesendet wurde
541
        loop_until_bit_is_set(UCSR0A, UDRE0);
552
        loop_until_bit_is_set(UCSR0A, UDRE0);
542
        //Ausgabe des Zeichens
553
        //Ausgabe des Zeichens
543
        UDR0 = c;
554
        UDR0 = c;
544
}
555
}
545
 
556
 
546
 
557
 
547
//############################################################################
558
//############################################################################
548
//INstallation der Seriellen Schnittstelle
559
//INstallation der Seriellen Schnittstelle
549
void UART_Init (void)
560
void UART_Init (void)
550
//############################################################################
561
//############################################################################
551
{
562
{
552
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
563
        unsigned int ubrr = (unsigned int) ((unsigned long) F_CPU/(8 * USART0_BAUD) - 1);
553
 
564
 
554
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
565
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
555
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
566
        UCSR0B = (1 << TXEN0) | (1 << RXEN0);
556
    // UART Double Speed (U2X)
567
    // UART Double Speed (U2X)
557
        UCSR0A |= (1 << U2X0);
568
        UCSR0A |= (1 << U2X0);
558
        // RX-Interrupt Freigabe
569
        // RX-Interrupt Freigabe
559
        UCSR0B |= (1 << RXCIE0);
570
        UCSR0B |= (1 << RXCIE0);
560
        // TX-Interrupt Freigabe
571
        // TX-Interrupt Freigabe
561
        UCSR0B |= (1 << TXCIE0);
572
        UCSR0B |= (1 << TXCIE0);
562
        // USART0 Baud Rate Register
573
        // USART0 Baud Rate Register
563
        // set clock divider
574
        // set clock divider
564
        UBRR0H = (uint8_t)(ubrr >> 8);
575
        UBRR0H = (uint8_t)(ubrr >> 8);
565
        UBRR0L = (uint8_t)ubrr;
576
        UBRR0L = (uint8_t)ubrr;
566
 
577
 
567
        Debug_Timer = SetDelay(DebugDataIntervall);
578
        Debug_Timer = SetDelay(DebugDataIntervall);
568
        Kompass_Timer = SetDelay(220);
579
        Kompass_Timer = SetDelay(220);
569
 
580
 
570
        VersionInfo.SWMajor = VERSION_MAJOR;
581
        VersionInfo.SWMajor = VERSION_MAJOR;
571
        VersionInfo.SWMinor = VERSION_MINOR;
582
        VersionInfo.SWMinor = VERSION_MINOR;
572
        VersionInfo.SWPatch = VERSION_PATCH;
583
        VersionInfo.SWPatch = VERSION_PATCH;
573
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
584
        VersionInfo.ProtoMajor  = VERSION_SERIAL_MAJOR;
574
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
585
        VersionInfo.ProtoMinor  = VERSION_SERIAL_MINOR;
575
 
586
 
576
        pRxData = 0;
587
        pRxData = 0;
577
        RxDataLen = 0;
588
        RxDataLen = 0;
578
}
589
}
579
 
590
 
580
//---------------------------------------------------------------------------------------------
591
//---------------------------------------------------------------------------------------------
581
void DatenUebertragung(void)
592
void DatenUebertragung(void)
582
{
593
{
583
        if(!UebertragungAbgeschlossen) return;
594
        if(!UebertragungAbgeschlossen) return;
584
 
595
 
585
        if(CheckDelay(AboTimeOut))
596
        if(CheckDelay(AboTimeOut))
586
        {
597
        {
587
                Display_Interval = 0;
598
                Display_Interval = 0;
588
                DebugDataIntervall = 0;
599
                DebugDataIntervall = 0;
589
                Intervall3D = 0;
600
                Intervall3D = 0;
590
        }
601
        }
-
 
602
#ifdef NODISPLAY        //main.h
-
 
603
#warning : "### no MKTool Display ###"
591
 
604
 
592
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
605
        if(((Display_Interval>0 && CheckDelay(Display_Timer)) || DebugDisplayAnforderung) && UebertragungAbgeschlossen)
593
        {
606
        {
594
                if(DisplayLine > 3)// new format
607
                if(DisplayLine > 3)// new format
595
                {
608
                {
596
                        Menu();
609
                        Menu();
597
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
610
                        SendOutData('H', FC_ADDRESS, 1, (uint8_t *)DisplayBuff, 80);
598
                }
611
                }
599
                else // old format
612
                else // old format
600
                {
613
                {
601
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
614
                        LCD_printfxy(0,0,"!!! INCOMPATIBLE !!!");
602
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
615
                        SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (uint8_t *)DisplayBuff, 20);
603
                        if(DisplayLine++ > 3) DisplayLine = 0;
616
                        if(DisplayLine++ > 3) DisplayLine = 0;
604
                }
617
                }
605
                Display_Timer = SetDelay(Display_Interval);
618
                Display_Timer = SetDelay(Display_Interval);
606
                DebugDisplayAnforderung = 0;
619
                DebugDisplayAnforderung = 0;
607
        }
620
        }
608
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
621
        if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
609
        {
622
        {
610
                Menu();
623
                Menu();
611
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
624
                SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
612
                DebugDisplayAnforderung1 = 0;
625
                DebugDisplayAnforderung1 = 0;
613
        }
626
        }
-
 
627
        #endif
614
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
628
        if(GetVersionAnforderung && UebertragungAbgeschlossen)
615
        {
629
        {
616
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
630
                SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
617
                GetVersionAnforderung = 0;
631
                GetVersionAnforderung = 0;
618
                Debug_OK("Version gesendet");
632
                Debug_OK("Version gesendet");
619
        }
633
        }
620
 
634
 
621
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
635
        if(GetExternalControl && UebertragungAbgeschlossen)           // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
622
        {
636
        {
623
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
637
                SendOutData('G',MeineSlaveAdresse, 1, (unsigned char *) &ExternControl, sizeof(ExternControl));
624
                GetExternalControl = 0;
638
                GetExternalControl = 0;
625
        }
639
        }
626
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
640
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)
627
         {
641
         {
628
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
642
                  WinkelOut.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
629
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
643
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
630
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
644
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
631
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
645
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
632
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
646
          SendOutData('k', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
633
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
647
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
634
          Kompass_Timer = SetDelay(99);
648
          Kompass_Timer = SetDelay(99);
635
         }
649
         }
636
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
650
    if(((DebugDataIntervall>0 && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
637
         {
651
         {
638
                  CopyDebugValues();
652
                  CopyDebugValues();
639
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
653
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
640
          DebugDataAnforderung = 0;
654
          DebugDataAnforderung = 0;
641
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
655
          if(DebugDataIntervall>0) Debug_Timer = SetDelay(DebugDataIntervall);
642
         }
656
         }
643
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
657
    if(Intervall3D > 0 && CheckDelay(Timer3D) && UebertragungAbgeschlossen)
644
         {
658
         {
645
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
659
                  Data3D.Winkel[0] = (int) (IntegralNick / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
646
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
660
                  Data3D.Winkel[1] = (int) (IntegralRoll / (EE_Parameter.GyroAccFaktor * 4));  // etwa in 0.1 Grad
647
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
661
          Data3D.Winkel[2] = (int) ((10 * ErsatzKompass) / GIER_GRAD_FAKTOR);
648
                  Data3D.Centroid[0] = SummeNick >> 9;
662
                  Data3D.Centroid[0] = SummeNick >> 9;
649
                  Data3D.Centroid[1] = SummeRoll >> 9;
663
                  Data3D.Centroid[1] = SummeRoll >> 9;
650
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
664
                  Data3D.Centroid[2] = Mess_Integral_Gier >> 9;
651
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
665
          SendOutData('C', FC_ADDRESS, 1, (unsigned char *) &Data3D,sizeof(Data3D));
652
          Timer3D = SetDelay(Intervall3D);
666
          Timer3D = SetDelay(Intervall3D);
653
         }
667
         }
654
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
668
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
655
     {
669
     {
656
                unsigned char label[16]; // local sram buffer
670
                unsigned char label[16]; // local sram buffer
657
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
671
                memcpy_P(label, ANALOG_TEXT[DebugTextAnforderung], 16); // read lable from flash to sra
658
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
672
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),label, 16);
659
      DebugTextAnforderung = 255;
673
      DebugTextAnforderung = 255;
660
         }
674
         }
661
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
675
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
662
         {
676
         {
663
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
677
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
664
        ConfirmFrame = 0;
678
        ConfirmFrame = 0;
665
     }
679
     }
666
 
680
 
667
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
681
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
668
     {
682
     {
669
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
683
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
670
                 GetPPMChannelAnforderung = 0;
684
                 GetPPMChannelAnforderung = 0;
671
         }
685
         }
672
 
686
 
673
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
687
#ifdef DEBUG                                                                                                                    // only include functions if DEBUG is defined
674
     if(SendDebugOutput && UebertragungAbgeschlossen)
688
     if(SendDebugOutput && UebertragungAbgeschlossen)
675
     {
689
     {
676
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
690
                 SendOutData('0', FC_ADDRESS, 1, (unsigned char *) &tDebug, sizeof(tDebug));
677
                 SendDebugOutput = 0;
691
                 SendDebugOutput = 0;
678
         }
692
         }
679
#endif
693
#endif
680
 
694
 
681
}
695
}
682
 
696
 
683
 
697
 
684
 
698