Subversion Repositories FlightCtrl

Rev

Rev 854 | Rev 884 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 854 Rev 855
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
 
7
 
8
#include "main.h"
8
#include "main.h"
9
#include "uart.h"
9
#include "uart.h"
10
 
10
 
11
unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0;
11
unsigned char DebugGetAnforderung = 0,DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0;
12
unsigned volatile char SioTmp = 0;
12
unsigned volatile char SioTmp = 0;
13
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
13
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
14
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
14
unsigned volatile char RxdBuffer[MAX_EMPFANGS_BUFF];
15
unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF];
15
unsigned volatile char NMEABuffer[MAX_EMPFANGS_BUFF];
16
unsigned volatile char NeuerDatensatzEmpfangen = 0;
16
unsigned volatile char NeuerDatensatzEmpfangen = 0;
17
unsigned volatile char NeueKoordinateEmpfangen = 0;
17
unsigned volatile char NeueKoordinateEmpfangen = 0;
18
unsigned volatile char UebertragungAbgeschlossen = 1;
18
unsigned volatile char UebertragungAbgeschlossen = 1;
19
unsigned volatile char CntCrcError = 0;
19
unsigned volatile char CntCrcError = 0;
20
unsigned volatile char AnzahlEmpfangsBytes = 0;
20
unsigned volatile char AnzahlEmpfangsBytes = 0;
21
unsigned volatile char PC_DebugTimeout = 0;
21
unsigned volatile char PC_DebugTimeout = 0;
22
unsigned char RemotePollDisplayLine = 0;
22
unsigned char RemotePollDisplayLine = 0;
23
unsigned char NurKanalAnforderung = 0;
23
unsigned char NurKanalAnforderung = 0;
24
unsigned char DebugTextAnforderung = 255;
24
unsigned char DebugTextAnforderung = 255;
25
unsigned char PcZugriff = 100;
25
unsigned char PcZugriff = 100;
26
unsigned char MotorTest[4] = {0,0,0,0};
26
unsigned char MotorTest[4] = {0,0,0,0};
27
unsigned char DubWiseKeys[4] = {0,0,0,0};
27
unsigned char DubWiseKeys[4] = {0,0,0,0};
28
unsigned char MeineSlaveAdresse;
28
unsigned char MeineSlaveAdresse;
29
unsigned char ConfirmFrame;
29
unsigned char ConfirmFrame;
30
struct str_DebugOut    DebugOut;
30
struct str_DebugOut    DebugOut;
31
struct str_ExternControl  ExternControl;
31
struct str_ExternControl  ExternControl;
32
struct str_VersionInfo VersionInfo;
32
struct str_VersionInfo VersionInfo;
33
struct str_WinkelOut WinkelOut;
33
struct str_WinkelOut WinkelOut;
34
 
34
 
35
int Debug_Timer,Kompass_Timer;
35
int Debug_Timer,Kompass_Timer;
36
 
36
 
37
const unsigned char ANALOG_TEXT[32][16] =
37
const unsigned char ANALOG_TEXT[32][16] =
38
{
38
{
39
   //1234567890123456 
39
   //1234567890123456 
40
    "IntegralNick    ", //0
40
    "IntegralNick    ", //0
41
    "IntegralRoll    ",
41
    "IntegralRoll    ",
42
    "AccNick         ",
42
    "AccNick         ",
43
    "AccRoll         ",
43
    "AccRoll         ",
44
    "GyroGier        ",
44
    "GyroGier        ",
45
    "HoehenWert      ", //5
45
    "HoehenWert      ", //5
46
    "AccZ            ",
46
    "AccZ            ",
47
    "Gas             ",
47
    "Gas             ",
48
    "KompassValue    ",
48
    "KompassValue    ",
49
    "Spannung        ",
49
    "Spannung        ",
50
    "Empfang         ", //10
50
    "Empfang         ", //10
51
    "Ersatzkompass   ",
51
    "Ersatzkompass   ",
52
    "Motor_Vorne     ",
52
    "Motor_Vorne     ",
53
    "Motor_Hinten    ",
53
    "Motor_Hinten    ",
54
    "Motor_Links     ",
54
    "Motor_Links     ",
55
    "Motor_Rechts    ", //15
55
    "Motor_Rechts    ", //15
56
    "Acc_Z           ",
56
    "Acc_Z           ",
57
    "Distance        ",
57
    "Distance        ",
58
    "OsdBar          ",
58
    "OsdBar          ",
59
    "MK3Mag CalState ",
59
    "MK3Mag CalState ",
60
    "Servo           ", //20
60
    "Servo           ", //20
61
    "Nick            ",
61
    "Nick            ",
62
    "Roll            ",
62
    "Roll            ",
63
    "                ",
63
    "                ",
64
    "                ",
64
    "                ",
65
    "                ", //25
65
    "                ", //25
66
    "                ",
66
    "                ",
67
    "                ",
67
    "                ",
68
    "                ",
68
    "                ",
69
    "                ",
69
    "                ",
70
    "GPS_Nick        ", //30
70
    "GPS_Nick        ", //30
71
    "GPS_Roll        "
71
    "GPS_Roll        "
72
};
72
};
73
 
73
 
74
 
74
 
75
 
75
 
76
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
//++ Sende-Part der Datenübertragung
77
//++ Sende-Part der Datenübertragung
78
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
78
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
79
SIGNAL(INT_VEC_TX)
79
SIGNAL(INT_VEC_TX)
80
{
80
{
81
 static unsigned int ptr = 0;
81
 static unsigned int ptr = 0;
82
 unsigned char tmp_tx;
82
 unsigned char tmp_tx;
83
 if(!UebertragungAbgeschlossen)  
83
 if(!UebertragungAbgeschlossen)  
84
  {
84
  {
85
   ptr++;                    // die [0] wurde schon gesendet
85
   ptr++;                    // die [0] wurde schon gesendet
86
   tmp_tx = SendeBuffer[ptr];  
86
   tmp_tx = SendeBuffer[ptr];  
87
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
87
   if((tmp_tx == '\r') || (ptr == MAX_SENDE_BUFF))
88
    {
88
    {
89
     ptr = 0;
89
     ptr = 0;
90
     UebertragungAbgeschlossen = 1;
90
     UebertragungAbgeschlossen = 1;
91
    }
91
    }
92
   UDR = tmp_tx;
92
   UDR = tmp_tx;
93
  }
93
  }
94
  else ptr = 0;
94
  else ptr = 0;
95
}
95
}
96
 
96
 
97
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
97
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
98
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
98
//++ Empfangs-Part der Datenübertragung, incl. CRC-Auswertung
99
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100
SIGNAL(INT_VEC_RX)
100
SIGNAL(INT_VEC_RX)
101
{
101
{
102
 static unsigned int crc;
102
 static unsigned int crc;
103
 static unsigned char crc1,crc2,buf_ptr;
103
 static unsigned char crc1,crc2,buf_ptr;
104
 static unsigned char UartState = 0;
104
 static unsigned char UartState = 0;
105
 unsigned char CrcOkay = 0;
105
 unsigned char CrcOkay = 0;
106
 
106
 
107
 SioTmp = UDR;
107
 SioTmp = UDR;
108
 if(buf_ptr >= MAX_EMPFANGS_BUFF)    UartState = 0;
108
 if(buf_ptr >= MAX_EMPFANGS_BUFF)    UartState = 0;
109
 if(SioTmp == '\r' && UartState == 2)
109
 if(SioTmp == '\r' && UartState == 2)
110
  {
110
  {
111
   UartState = 0;
111
   UartState = 0;
112
   crc -= RxdBuffer[buf_ptr-2];
112
   crc -= RxdBuffer[buf_ptr-2];
113
   crc -= RxdBuffer[buf_ptr-1];
113
   crc -= RxdBuffer[buf_ptr-1];
114
   crc %= 4096;
114
   crc %= 4096;
115
   crc1 = '=' + crc / 64;
115
   crc1 = '=' + crc / 64;
116
   crc2 = '=' + crc % 64;
116
   crc2 = '=' + crc % 64;
117
   CrcOkay = 0;
117
   CrcOkay = 0;
118
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
118
   if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) CrcOkay = 1; else { CrcOkay = 0; CntCrcError++;};
119
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
119
   if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet
120
    {
120
    {
121
     NeuerDatensatzEmpfangen = 1;
121
     NeuerDatensatzEmpfangen = 1;
122
         AnzahlEmpfangsBytes = buf_ptr;
122
         AnzahlEmpfangsBytes = buf_ptr;
123
     RxdBuffer[buf_ptr] = '\r';
123
     RxdBuffer[buf_ptr] = '\r';
124
         if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando
124
         if(RxdBuffer[2] == 'R') wdt_enable(WDTO_250MS); // Reset-Commando
125
        }                                
125
        }                                
126
  }
126
  }
127
  else
127
  else
128
  switch(UartState)
128
  switch(UartState)
129
  {
129
  {
130
   case 0:
130
   case 0:
131
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
131
          if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1;  // Startzeichen und Daten schon verarbeitet
132
                  buf_ptr = 0;
132
                  buf_ptr = 0;
133
                  RxdBuffer[buf_ptr++] = SioTmp;
133
                  RxdBuffer[buf_ptr++] = SioTmp;
134
                  crc = SioTmp;
134
                  crc = SioTmp;
135
          break;
135
          break;
136
   case 1: // Adresse auswerten
136
   case 1: // Adresse auswerten
137
                  UartState++;
137
                  UartState++;
138
                  RxdBuffer[buf_ptr++] = SioTmp;
138
                  RxdBuffer[buf_ptr++] = SioTmp;
139
                  crc += SioTmp;
139
                  crc += SioTmp;
140
                  break;
140
                  break;
141
   case 2: //  Eingangsdaten sammeln
141
   case 2: //  Eingangsdaten sammeln
142
                  RxdBuffer[buf_ptr] = SioTmp;
142
                  RxdBuffer[buf_ptr] = SioTmp;
143
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
143
                  if(buf_ptr < MAX_EMPFANGS_BUFF) buf_ptr++;
144
                  else UartState = 0;
144
                  else UartState = 0;
145
                  crc += SioTmp;
145
                  crc += SioTmp;
146
                  break;
146
                  break;
147
   default:
147
   default:
148
          UartState = 0;
148
          UartState = 0;
149
          break;
149
          break;
150
  }
150
  }
151
}
151
}
152
 
152
 
153
 
153
 
154
// --------------------------------------------------------------------------
154
// --------------------------------------------------------------------------
155
void AddCRC(unsigned int wieviele)
155
void AddCRC(unsigned int wieviele)
156
{
156
{
157
 unsigned int tmpCRC = 0,i;
157
 unsigned int tmpCRC = 0,i;
158
 for(i = 0; i < wieviele;i++)
158
 for(i = 0; i < wieviele;i++)
159
  {
159
  {
160
   tmpCRC += SendeBuffer[i];
160
   tmpCRC += SendeBuffer[i];
161
  }
161
  }
162
   tmpCRC %= 4096;
162
   tmpCRC %= 4096;
163
   SendeBuffer[i++] = '=' + tmpCRC / 64;
163
   SendeBuffer[i++] = '=' + tmpCRC / 64;
164
   SendeBuffer[i++] = '=' + tmpCRC % 64;
164
   SendeBuffer[i++] = '=' + tmpCRC % 64;
165
   SendeBuffer[i++] = '\r';
165
   SendeBuffer[i++] = '\r';
166
  UebertragungAbgeschlossen = 0;
166
  UebertragungAbgeschlossen = 0;
167
  UDR = SendeBuffer[0];
167
  UDR = SendeBuffer[0];
168
}
168
}
169
 
169
 
170
 
170
 
171
 
171
 
172
// --------------------------------------------------------------------------
172
// --------------------------------------------------------------------------
173
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
173
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
174
{
174
{
175
 unsigned int pt = 0;
175
 unsigned int pt = 0;
176
 unsigned char a,b,c;
176
 unsigned char a,b,c;
177
 unsigned char ptr = 0;
177
 unsigned char ptr = 0;
178
 
178
 
179
 SendeBuffer[pt++] = '#';               // Startzeichen
179
 SendeBuffer[pt++] = '#';               // Startzeichen
180
 SendeBuffer[pt++] = modul;             // Adresse (a=0; b=1,...)
180
 SendeBuffer[pt++] = modul;             // Adresse (a=0; b=1,...)
181
 SendeBuffer[pt++] = cmd;                       // Commando
181
 SendeBuffer[pt++] = cmd;                       // Commando
182
 
182
 
183
 while(len)
183
 while(len)
184
  {
184
  {
185
   if(len) { a = snd[ptr++]; len--;} else a = 0;
185
   if(len) { a = snd[ptr++]; len--;} else a = 0;
186
   if(len) { b = snd[ptr++]; len--;} else b = 0;
186
   if(len) { b = snd[ptr++]; len--;} else b = 0;
187
   if(len) { c = snd[ptr++]; len--;} else c = 0;
187
   if(len) { c = snd[ptr++]; len--;} else c = 0;
188
   SendeBuffer[pt++] = '=' + (a >> 2);
188
   SendeBuffer[pt++] = '=' + (a >> 2);
189
   SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
189
   SendeBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
190
   SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
190
   SendeBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
191
   SendeBuffer[pt++] = '=' + ( c & 0x3f);
191
   SendeBuffer[pt++] = '=' + ( c & 0x3f);
192
  }
192
  }
193
 AddCRC(pt);
193
 AddCRC(pt);
194
}
194
}
195
 
195
 
196
 
196
 
197
// --------------------------------------------------------------------------
197
// --------------------------------------------------------------------------
198
void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max)  // Wohin mit den Daten; Wie lang; Wo im RxdBuffer
198
void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max)  // Wohin mit den Daten; Wie lang; Wo im RxdBuffer
199
{
199
{
200
 unsigned char a,b,c,d;
200
 unsigned char a,b,c,d;
201
 unsigned char ptr = 0;
201
 unsigned char ptr = 0;
202
 unsigned char x,y,z;
202
 unsigned char x,y,z;
203
 while(len)
203
 while(len)
204
  {
204
  {
205
   a = RxdBuffer[ptrIn++] - '=';
205
   a = RxdBuffer[ptrIn++] - '=';
206
   b = RxdBuffer[ptrIn++] - '=';
206
   b = RxdBuffer[ptrIn++] - '=';
207
   c = RxdBuffer[ptrIn++] - '=';
207
   c = RxdBuffer[ptrIn++] - '=';
208
   d = RxdBuffer[ptrIn++] - '=';
208
   d = RxdBuffer[ptrIn++] - '=';
209
   if(ptrIn > max - 2) break;     // nicht mehr Daten verarbeiten, als empfangen wurden
209
   if(ptrIn > max - 2) break;     // nicht mehr Daten verarbeiten, als empfangen wurden
210
 
210
 
211
   x = (a << 2) | (b >> 4);
211
   x = (a << 2) | (b >> 4);
212
   y = ((b & 0x0f) << 4) | (c >> 2);
212
   y = ((b & 0x0f) << 4) | (c >> 2);
213
   z = ((c & 0x03) << 6) | d;
213
   z = ((c & 0x03) << 6) | d;
214
 
214
 
215
   if(len--) ptrOut[ptr++] = x; else break;
215
   if(len--) ptrOut[ptr++] = x; else break;
216
   if(len--) ptrOut[ptr++] = y; else break;
216
   if(len--) ptrOut[ptr++] = y; else break;
217
   if(len--) ptrOut[ptr++] = z; else break;
217
   if(len--) ptrOut[ptr++] = z; else break;
218
  }
218
  }
219
 
219
 
220
}
220
}
221
 
221
 
222
// --------------------------------------------------------------------------
222
// --------------------------------------------------------------------------
223
void BearbeiteRxDaten(void)
223
void BearbeiteRxDaten(void)
224
{
224
{
225
 if(!NeuerDatensatzEmpfangen) return;
225
 if(!NeuerDatensatzEmpfangen) return;
226
 
226
 
227
 unsigned int tmp_int_arr1[1];
227
 unsigned int tmp_int_arr1[1];
228
// unsigned int tmp_int_arr2[2];
228
// unsigned int tmp_int_arr2[2];
229
// unsigned int tmp_int_arr3[3];
229
// unsigned int tmp_int_arr3[3];
230
 unsigned char tmp_char_arr2[2];
230
 unsigned char tmp_char_arr2[2];
231
// unsigned char tmp_char_arr3[3];
231
// unsigned char tmp_char_arr3[3];
232
// unsigned char tmp_char_arr4[4];
232
// unsigned char tmp_char_arr4[4];
233
 //if(!MotorenEin) 
233
 //if(!MotorenEin) 
234
  switch(RxdBuffer[2])
234
  switch(RxdBuffer[2])
235
  {
235
  {
236
   case 'K':// Kompasswert
236
   case 'K':// Kompasswert
237
            Decode64((unsigned char *) &tmp_int_arr1[0],sizeof(tmp_int_arr1),3,AnzahlEmpfangsBytes);
237
            Decode64((unsigned char *) &tmp_int_arr1[0],sizeof(tmp_int_arr1),3,AnzahlEmpfangsBytes);
238
            KompassValue = tmp_int_arr1[0];
238
            KompassValue = tmp_int_arr1[0];
239
            KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
239
            KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
240
                        break;
240
                        break;
241
   case 'a':// Texte der Analogwerte
241
   case 'a':// Texte der Analogwerte
242
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
242
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
243
            DebugTextAnforderung = tmp_char_arr2[0];
243
            DebugTextAnforderung = tmp_char_arr2[0];
244
            PcZugriff = 255;
244
            PcZugriff = 255;
245
                        break;
245
                        break;
246
   case 'b':
246
   case 'b':
247
                        Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes);
247
                        Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes);
248
                        RemoteTasten |= ExternControl.RemoteTasten;
248
                        RemoteTasten |= ExternControl.RemoteTasten;
249
            ConfirmFrame = ExternControl.Frame;
249
            ConfirmFrame = ExternControl.Frame;
250
            break;
250
            break;
251
   case 'c':
251
   case 'c':
252
                        Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes);
252
                        Decode64((unsigned char *) &ExternControl,sizeof(ExternControl),3,AnzahlEmpfangsBytes);
253
                        RemoteTasten |= ExternControl.RemoteTasten;
253
                        RemoteTasten |= ExternControl.RemoteTasten;
254
            ConfirmFrame = ExternControl.Frame;
254
            ConfirmFrame = ExternControl.Frame;
255
            DebugDataAnforderung = 1;
255
            DebugDataAnforderung = 1;
256
            PcZugriff = 255;
256
            PcZugriff = 255;
257
            break;
257
            break;
258
   case 'h':// x-1 Displayzeilen
258
   case 'h':// x-1 Displayzeilen
259
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
259
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
260
            RemoteTasten |= tmp_char_arr2[0];
260
            RemoteTasten |= tmp_char_arr2[0];
261
                        if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten
261
                        if(tmp_char_arr2[1] == 255) NurKanalAnforderung = 1; else NurKanalAnforderung = 0; // keine Displaydaten
262
                        DebugDisplayAnforderung = 1;
262
                        DebugDisplayAnforderung = 1;
263
                        break;
263
                        break;
264
   case 't':// Motortest
264
   case 't':// Motortest
265
            Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes);
265
            Decode64((unsigned char *) &MotorTest[0],sizeof(MotorTest),3,AnzahlEmpfangsBytes);
266
            PcZugriff = 255;
266
            PcZugriff = 255;
267
                        break;
267
                        break;
268
   case 'k':// Keys von DubWise
268
   case 'k':// Keys von DubWise
269
            Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes);
269
            Decode64((unsigned char *) &DubWiseKeys[0],sizeof(DubWiseKeys),3,AnzahlEmpfangsBytes);
270
                        ConfirmFrame = DubWiseKeys[3];
270
                        ConfirmFrame = DubWiseKeys[3];
271
            PcZugriff = 255;
271
            PcZugriff = 255;
272
                        break;
272
                        break;
273
   case 'v': // Version-Anforderung     und Ausbaustufe
273
   case 'v': // Version-Anforderung     und Ausbaustufe
274
            GetVersionAnforderung = 1;
274
            GetVersionAnforderung = 1;
275
            break;                                                               
275
            break;                                                               
276
   case 'g':// "Get"-Anforderung für Debug-Daten 
276
   case 'g':// "Get"-Anforderung für Debug-Daten 
277
            // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
277
            // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
278
            DebugGetAnforderung = 1;
278
            DebugGetAnforderung = 1;
279
            break;
279
            break;
280
   case 'q':// "Get"-Anforderung für Settings
280
   case 'q':// "Get"-Anforderung für Settings
281
            // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
281
            // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
282
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
282
            Decode64((unsigned char *) &tmp_char_arr2[0],sizeof(tmp_char_arr2),3,AnzahlEmpfangsBytes);
283
            while(!UebertragungAbgeschlossen);
283
            while(!UebertragungAbgeschlossen);
284
            if(tmp_char_arr2[0] != 0xff)
284
            if(tmp_char_arr2[0] != 0xff)
285
             {
285
             {
286
                          if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5;
286
                          if(tmp_char_arr2[0] > 5) tmp_char_arr2[0] = 5;
287
                  ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);                   
287
                  ReadParameterSet(tmp_char_arr2[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);                   
288
                  SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE);
288
                  SendOutData('L' + tmp_char_arr2[0] -1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE);
289
             }
289
             }
290
             else
290
             else
291
                  SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE);
291
                  SendOutData('L' + GetActiveParamSetNumber()-1,MeineSlaveAdresse,(unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE);
292
             
292
             
293
            break;
293
            break;
294
       
294
       
295
   case 'l':
295
   case 'l':
296
   case 'm':
296
   case 'm':
297
   case 'n':
297
   case 'n':
298
   case 'o':
298
   case 'o':
299
   case 'p': // Parametersatz speichern
299
   case 'p': // Parametersatz speichern
300
            Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes);
300
            Decode64((unsigned char *) &EE_Parameter.Kanalbelegung[0],STRUCT_PARAM_LAENGE,3,AnzahlEmpfangsBytes);
301
                        WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
301
                        WriteParameterSet(RxdBuffer[2] - 'l' + 1, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
302
            eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1);  // aktiven Datensatz merken
302
            eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1);  // aktiven Datensatz merken
303
            Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
303
            Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
304
            Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
304
            Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
305
            Piep(GetActiveParamSetNumber());
305
            Piep(GetActiveParamSetNumber());
306
         break;
306
         break;
307
               
307
               
308
         
308
         
309
  }
309
  }
310
// DebugOut.AnzahlZyklen =  Debug_Timer_Intervall;
310
// DebugOut.AnzahlZyklen =  Debug_Timer_Intervall;
311
 NeuerDatensatzEmpfangen = 0;
311
 NeuerDatensatzEmpfangen = 0;
312
}
312
}
313
 
313
 
314
//############################################################################
314
//############################################################################
315
//Routine für die Serielle Ausgabe
315
//Routine für die Serielle Ausgabe
316
int uart_putchar (char c)
316
int uart_putchar (char c)
317
//############################################################################
317
//############################################################################
318
{
318
{
319
        if (c == '\n')
319
        if (c == '\n')
320
                uart_putchar('\r');
320
                uart_putchar('\r');
321
        //Warten solange bis Zeichen gesendet wurde
321
        //Warten solange bis Zeichen gesendet wurde
322
        loop_until_bit_is_set(USR, UDRE);
322
        loop_until_bit_is_set(USR, UDRE);
323
        //Ausgabe des Zeichens
323
        //Ausgabe des Zeichens
324
        UDR = c;
324
        UDR = c;
325
       
325
       
326
        return (0);
326
        return (0);
327
}
327
}
328
 
328
 
329
// --------------------------------------------------------------------------
329
// --------------------------------------------------------------------------
330
void WriteProgramData(unsigned int pos, unsigned char wert)
330
void WriteProgramData(unsigned int pos, unsigned char wert)
331
{
331
{
332
  //if (ProgramLocation == IN_RAM) Buffer[pos] = wert;
332
  //if (ProgramLocation == IN_RAM) Buffer[pos] = wert;
333
  // else eeprom_write_byte(&EE_Buffer[pos], wert);
333
  // else eeprom_write_byte(&EE_Buffer[pos], wert);
334
  // Buffer[pos] = wert;
334
  // Buffer[pos] = wert;
335
}
335
}
336
 
336
 
337
//############################################################################
337
//############################################################################
338
//INstallation der Seriellen Schnittstelle
338
//INstallation der Seriellen Schnittstelle
339
void UART_Init (void)
339
void UART_Init (void)
340
//############################################################################
340
//############################################################################
341
{
341
{
342
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
342
        //Enable TXEN im Register UCR TX-Data Enable & RX Enable
343
 
343
 
344
        UCR=(1 << TXEN) | (1 << RXEN);
344
        UCR=(1 << TXEN) | (1 << RXEN);
345
    // UART Double Speed (U2X)
345
    // UART Double Speed (U2X)
346
        USR   |= (1<<U2X);          
346
        USR   |= (1<<U2X);          
347
        // RX-Interrupt Freigabe
347
        // RX-Interrupt Freigabe
348
        UCSRB |= (1<<RXCIE);          
348
        UCSRB |= (1<<RXCIE);          
349
        // TX-Interrupt Freigabe
349
        // TX-Interrupt Freigabe
350
        UCSRB |= (1<<TXCIE);          
350
        UCSRB |= (1<<TXCIE);          
351
 
351
 
352
        //Teiler wird gesetzt 
352
        //Teiler wird gesetzt 
353
        UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1);
353
        UBRR=(SYSCLK / (BAUD_RATE * 8L) - 1);
354
        //UBRR = 33;
354
        //UBRR = 33;
355
        //öffnet einen Kanal für printf (STDOUT)
355
        //öffnet einen Kanal für printf (STDOUT)
356
        //fdevopen (uart_putchar, 0);
356
        //fdevopen (uart_putchar, 0);
357
        //sbi(PORTD,4);
357
        //sbi(PORTD,4);
358
  Debug_Timer = SetDelay(200);  
358
  Debug_Timer = SetDelay(200);  
359
  Kompass_Timer = SetDelay(220);  
359
  Kompass_Timer = SetDelay(220);  
360
}
360
}
361
 
361
 
362
//---------------------------------------------------------------------------------------------
362
//---------------------------------------------------------------------------------------------
363
void DatenUebertragung(void)  
363
void DatenUebertragung(void)  
364
{
364
{
365
 if(!UebertragungAbgeschlossen) return;
365
 if(!UebertragungAbgeschlossen) return;
366
 
366
 
367
   if(DebugGetAnforderung && UebertragungAbgeschlossen)               // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
367
   if(DebugGetAnforderung && UebertragungAbgeschlossen)               // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
368
   {
368
   {
369
      SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl));
369
      SendOutData('G',MeineSlaveAdresse,(unsigned char *) &ExternControl,sizeof(ExternControl));
370
          DebugGetAnforderung = 0;
370
          DebugGetAnforderung = 0;
371
   }
371
   }
372
 
372
 
373
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)        
373
    if((CheckDelay(Kompass_Timer)) && UebertragungAbgeschlossen)        
374
         {
374
         {
375
                  WinkelOut.Winkel[0] = (int) (IntegralNick / 108);  // etwa in 0,1 Grad
375
                  WinkelOut.Winkel[0] = (int) (IntegralNick / 108);  // etwa in 0,1 Grad
376
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / 108);  // etwa in 0,1 Grad
376
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / 108);  // etwa in 0,1 Grad
377
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
377
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
378
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
378
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
379
          SendOutData('w',MeineSlaveAdresse,(unsigned char *) &WinkelOut,sizeof(WinkelOut));
379
          SendOutData('w',MeineSlaveAdresse,(unsigned char *) &WinkelOut,sizeof(WinkelOut));
380
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 0;
380
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
381
          Kompass_Timer = SetDelay(99);  
381
          Kompass_Timer = SetDelay(99);  
382
         }
382
         }
383
 
383
 
384
    if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen)  
384
    if((CheckDelay(Debug_Timer) || DebugDataAnforderung) && UebertragungAbgeschlossen)  
385
         {
385
         {
386
          SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut));
386
          SendOutData('D',MeineSlaveAdresse,(unsigned char *) &DebugOut,sizeof(DebugOut));
387
          DebugDataAnforderung = 0;
387
          DebugDataAnforderung = 0;
388
          Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL);  
388
          Debug_Timer = SetDelay(MIN_DEBUG_INTERVALL);  
389
         }
389
         }
390
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
390
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
391
     {
391
     {
392
      SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16);
392
      SendOutData('A',DebugTextAnforderung + '0',(unsigned char *) ANALOG_TEXT[DebugTextAnforderung],16);
393
      DebugTextAnforderung = 255;
393
      DebugTextAnforderung = 255;
394
         }
394
         }
395
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz ohne CRC bestätigen 
395
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz ohne CRC bestätigen 
396
         {
396
         {
397
      SendeBuffer[0] = '#';
397
      SendeBuffer[0] = '#';
398
      SendeBuffer[1] = ConfirmFrame;
398
      SendeBuffer[1] = ConfirmFrame;
399
      SendeBuffer[2] = '\r';
399
      SendeBuffer[2] = '\r';
400
      UebertragungAbgeschlossen = 0;
400
      UebertragungAbgeschlossen = 0;
401
      ConfirmFrame = 0;
401
      ConfirmFrame = 0;
402
      UDR = SendeBuffer[0];
402
      UDR = SendeBuffer[0];
403
     }
403
     }
404
     if(DebugDisplayAnforderung && UebertragungAbgeschlossen)
404
     if(DebugDisplayAnforderung && UebertragungAbgeschlossen)
405
         {
405
         {
406
      Menu();
406
      Menu();
407
          DebugDisplayAnforderung = 0;
407
          DebugDisplayAnforderung = 0;
408
      if(++RemotePollDisplayLine == 4 || NurKanalAnforderung)
408
      if(++RemotePollDisplayLine == 4 || NurKanalAnforderung)
409
      {
409
      {
410
       SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in));   // DisplayZeile übertragen
410
       SendOutData('4',0,(unsigned char *)&PPM_in,sizeof(PPM_in));   // DisplayZeile übertragen
411
       RemotePollDisplayLine = -1;
411
       RemotePollDisplayLine = -1;
412
      }
412
      }
413
      else  SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20);   // DisplayZeile übertragen
413
      else  SendOutData('0' + RemotePollDisplayLine,0,(unsigned char *)&DisplayBuff[20 * RemotePollDisplayLine],20);   // DisplayZeile übertragen
414
         }
414
         }
415
    if(GetVersionAnforderung && UebertragungAbgeschlossen)
415
    if(GetVersionAnforderung && UebertragungAbgeschlossen)
416
     {
416
     {
417
      SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo));
417
      SendOutData('V',MeineSlaveAdresse,(unsigned char *) &VersionInfo,sizeof(VersionInfo));
418
          GetVersionAnforderung = 0;
418
          GetVersionAnforderung = 0;
419
     }
419
     }
420
 
420
 
421
}
421
}
422
 
422
 
423
 
423