Subversion Repositories FlightCtrl

Rev

Rev 2560 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
304 ingob 1
// ######################## SPI - FlightCtrl ###################
2
#include "main.h"
1622 killagreg 3
#include "eeprom.h"
2496 holgerb 4
#include "uart.h"
304 ingob 5
 
823 ingob 6
//struct str_ToNaviCtrl_Version   ToNaviCtrl_Version;
7
//struct str_FromNaviCtrl_Version   FromNaviCtrl_Version;
8
struct str_ToNaviCtrl   ToNaviCtrl;
9
struct str_FromNaviCtrl   FromNaviCtrl;
978 hbuss 10
struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
1448 killagreg 11
struct str_SPI_VersionInfo NC_Version;
1451 killagreg 12
struct str_GPSInfo GPSInfo;
708 ingob 13
 
2008 holgerb 14
unsigned char SPI_BufferIndex;
15
unsigned char SPI_RxBufferIndex;
1668 holgerb 16
signed char FromNC_Rotate_C = 32, FromNC_Rotate_S = 0;
2485 holgerb 17
signed char FromNC_WP_EventChannel_New = 0;
606 ingob 18
 
882 hbuss 19
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
823 ingob 20
unsigned char *SPI_TX_Buffer;
708 ingob 21
 
617 ingob 22
unsigned char SPITransferCompleted, SPI_ChkSum;
1690 holgerb 23
unsigned char SPI_RxDataValid,NaviDataOkay = 250;
720 ingob 24
 
2499 holgerb 25
unsigned char SPI_CommandSequence[] = { SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_SLOW,SPI_FCCMD_BL_ACCU,
26
                                                                                SPI_FCCMD_STICK, SPI_FCCMD_MISC, SPI_FCCMD_BL_ACCU,
27
                                        SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_BL_ACCU,
2341 holgerb 28
                                                                                SPI_FCCMD_STICK, SPI_FCCMD_PARAMETER2, SPI_FCCMD_BL_ACCU
2183 holgerb 29
                                                                                };
823 ingob 30
unsigned char SPI_CommandCounter = 0;
1703 holgerb 31
unsigned char NC_ErrorCode = 0;
1920 holgerb 32
unsigned char NC_GPS_ModeCharacter = ' ';
1972 holgerb 33
unsigned char EarthMagneticField = 0;
34
unsigned char EarthMagneticInclination = 0, EarthMagneticInclinationTheoretic = 0;
2009 holgerb 35
unsigned char NC_To_FC_Flags = 0;
2501 holgerb 36
unsigned char NCForcesNewDirection = 0; // allows Yawing without CareFree (Yawing at Coming Home)
2447 holgerb 37
//unsigned char NC_To_FC_MaxAltitude = 0; // this is a Parameter on the SD-card
1840 holgerb 38
signed int POI_KameraNick = 0; // in 0,1°
1852 killagreg 39
vector16_t MagVec = {0,0,0};
823 ingob 40
 
597 ingob 41
#ifdef USE_SPI_COMMUNICATION
691 ingob 42
 
304 ingob 43
//------------------------------------------------------
44
void SPI_MasterInit(void)
45
{
1051 killagreg 46
  DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK);    // Set MOSI and SCK output, all others input
304 ingob 47
  SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT);
1051 killagreg 48
 
49
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE);   // Enable SPI, Master, set clock rate fck/64
723 hbuss 50
  SPSR = 0;//(1<<SPI2X);
1051 killagreg 51
 
52
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);
606 ingob 53
  SPITransferCompleted = 1;
1051 killagreg 54
 
708 ingob 55
  //SPDR = 0x00;  // dummy write
1051 killagreg 56
 
823 ingob 57
  ToNaviCtrl.Sync1 = 0xAA;
58
  ToNaviCtrl.Sync2 = 0x83;
1051 killagreg 59
 
1448 killagreg 60
  ToNaviCtrl.Command = SPI_FCCMD_USER;
823 ingob 61
  ToNaviCtrl.IntegralNick = 0;
62
  ToNaviCtrl.IntegralRoll = 0;
1215 hbuss 63
  FromNaviCtrl_Value.SerialDataOkay = 0;
1051 killagreg 64
  SPI_RxDataValid = 0;
65
 
304 ingob 66
}
67
 
68
//------------------------------------------------------
2386 holgerb 69
unsigned char SPI_StartTransmitPacket(void)
304 ingob 70
{
2386 holgerb 71
   if(!SPITransferCompleted) return(0);
304 ingob 72
   SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
823 ingob 73
   SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl;
1051 killagreg 74
 
823 ingob 75
   ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
76
   if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
1051 killagreg 77
 
606 ingob 78
   SPITransferCompleted = 0;
2560 holgerb 79
   UpdateSPI_Buffer();                       // update buffer
304 ingob 80
   SPI_BufferIndex = 1;
823 ingob 81
   ToNaviCtrl.Chksum = ToNaviCtrl.Sync1;
1051 killagreg 82
   SPDR = ToNaviCtrl.Sync1;                  // Start transmission
2386 holgerb 83
   return(1);
304 ingob 84
}
85
 
86
//------------------------------------------------------
2496 holgerb 87
//SIaNAL(SIG_SPI)
304 ingob 88
void SPI_TransmitByte(void)
89
{
708 ingob 90
   static unsigned char SPI_RXState = 0;
1051 killagreg 91
   unsigned char rxdata;
708 ingob 92
   static unsigned char rxchksum;
1051 killagreg 93
 
691 ingob 94
   if (SPITransferCompleted) return;
304 ingob 95
   if (!(SPSR & (1 << SPIF))) return;
2386 holgerb 96
  BytegapSPI = SPI_BYTEGAP;
1051 killagreg 97
//   _delay_us(30);
606 ingob 98
  SLAVE_SELECT_PORT |=  (1 << SPI_SLAVE_SELECT);   // DeselectSlave
1051 killagreg 99
 
708 ingob 100
  rxdata = SPDR;
101
  switch ( SPI_RXState)
102
  {
1051 killagreg 103
  case 0:
104
                        SPI_RxBufferIndex = 0;
105
                        rxchksum = rxdata;
106
                        if (rxdata == 0x81 )  { SPI_RXState  = 1;  }   // 1. Syncbyte ok
107
 
708 ingob 108
           break;
109
 
1051 killagreg 110
   case 1:
111
                    if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState  = 2;  }   // 2. Syncbyte ok
112
                 else SPI_RXState  = 0;
113
           break;
114
 
708 ingob 115
   case 2:
116
                   SPI_Buffer[SPI_RxBufferIndex++]= rxdata;             // get data
117
           //DebugOut.Analog[19]++;
1051 killagreg 118
           if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl))
119
                   {
708 ingob 120
                if (rxdata == rxchksum)
121
                        {
823 ingob 122
                  unsigned char *ptr = (unsigned char *)&FromNaviCtrl;
708 ingob 123
                          memcpy(ptr, (unsigned char *) SPI_Buffer,  sizeof(SPI_Buffer));
1051 killagreg 124
                          SPI_RxDataValid = 1;
125
                        }
1856 killagreg 126
                        else
1855 holgerb 127
                         {
128
                          SPI_RxDataValid = 0;
1856 killagreg 129
                         }
1051 killagreg 130
                        SPI_RXState  = 0;
708 ingob 131
                   }
1051 killagreg 132
                  else rxchksum += rxdata;
133
        break;
134
 
135
  }
136
 
137
   if (SPI_BufferIndex < sizeof(ToNaviCtrl))
138
     {
606 ingob 139
           SLAVE_SELECT_PORT &=  ~(1 << SPI_SLAVE_SELECT);  // SelectSlave
2341 holgerb 140
           asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop");
708 ingob 141
           SPDR = SPI_TX_Buffer[SPI_BufferIndex];
823 ingob 142
           ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex];
2341 holgerb 143
         }
1051 killagreg 144
         else SPITransferCompleted = 1;
145
 
304 ingob 146
         SPI_BufferIndex++;
147
}
148
 
691 ingob 149
 
304 ingob 150
//------------------------------------------------------
151
void UpdateSPI_Buffer(void)
152
{
2496 holgerb 153
//  signed int tmp;
2499 holgerb 154
  static unsigned char motorindex, oldcommand = SPI_NCCMD_VERSION, slow_command = 0;
2373 holgerb 155
  ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad
156
  ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); // etwa in 0.1 Grad
1171 hbuss 157
  ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR;
1664 holgerb 158
  ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier;
1171 hbuss 159
  ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4;
160
  ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4;
819 hbuss 161
  NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0;
823 ingob 162
//  ToNaviCtrl.User8 = Parameter_UserParam8;
163
//  ToNaviCtrl.CalState = WinkelOut.CalcState;
1051 killagreg 164
   switch(ToNaviCtrl.Command)  //
823 ingob 165
   {
1448 killagreg 166
         case SPI_FCCMD_USER:
823 ingob 167
                                ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1;
168
                                ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2;
169
                                ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3;
170
                                ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4;
171
                                ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5;
172
                                ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6;
173
                                ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7;
921 hbuss 174
                                ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8;
1765 killagreg 175
                                ToNaviCtrl.Param.Byte[8] = FC_StatusFlags;
2518 holgerb 176
                                ToNaviCtrl.Param.Byte[9] = FC_StatusFlags2;
2309 holgerb 177
//if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) ToNaviCtrl.Param.Byte[8] &= ~FC_STATUS_FLY;
1765 killagreg 178
                FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START);
2518 holgerb 179
                        ToNaviCtrl.Param.Int[5] = UBat; // 10 & 11
2348 holgerb 180
                                if(!(PORTC & (1<<PORTC2))) FC_StatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;       // Out1 (J16)
921 hbuss 181
        break;
2341 holgerb 182
     case SPI_FCCMD_BL_ACCU:
1508 killagreg 183
                        ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A
2527 holgerb 184
                                ToNaviCtrl.Param.Byte[2] = motorindex | Out1ChangedFlag; // 0x80 this Flag marks a changed Out1
2443 holgerb 185
                                ToNaviCtrl.Param.Byte[3] = Capacity.MinOfMaxPWM;
2386 holgerb 186
                                ToNaviCtrl.Param.Byte[4] = GetChannelValue(EE_Parameter.NaviGpsModeChannel);  // GPS-Mode control 
187
                                ToNaviCtrl.Param.Byte[5] = VarioCharacter;
2443 holgerb 188
                                ToNaviCtrl.Param.Byte[6] = Motor[motorindex].NotReadyCnt;
2386 holgerb 189
                                ToNaviCtrl.Param.Byte[7] = Motor[motorindex].Version;
2037 holgerb 190
                                ToNaviCtrl.Param.Byte[8] = Motor[motorindex].MaxPWM;
191
                                ToNaviCtrl.Param.Byte[9] = Motor[motorindex].State;
1948 holgerb 192
                                ToNaviCtrl.Param.Byte[10] = Motor[motorindex].Temperature;
2346 holgerb 193
                                ToNaviCtrl.Param.Byte[11] = Motor[motorindex].Current;
2404 holgerb 194
                                if(Mixer.Motor[++motorindex][0] <= 0) // next motor is not used ?
195
                                  while(Mixer.Motor[motorindex][0] <= 0 && motorindex) motorindex = (motorindex + 1) % 13;
2527 holgerb 196
                                Out1ChangedFlag = 0;
1508 killagreg 197
        break;
2477 holgerb 198
         case SPI_FCCMD_SLOW:
199
               switch(slow_command)
200
           {
201
                         case 0:
2499 holgerb 202
                                ToNaviCtrl.Command = SPI_FCCMD_VERSION;
203
                                ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR;
204
                                ToNaviCtrl.Param.Byte[1] = VERSION_MINOR;
205
                                ToNaviCtrl.Param.Byte[2] = VERSION_PATCH;
206
                                ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE;
207
                                ToNaviCtrl.Param.Byte[4] = PlatinenVersion;
208
                                ToNaviCtrl.Param.Byte[5] = EE_Parameter.LandingSpeed;
209
                                ToNaviCtrl.Param.Byte[6] = EE_Parameter.ComingHomeAltitude;
210
                                ToNaviCtrl.Param.Byte[7] = EE_Parameter.AutoPhotoAtitudes;
211
                                ToNaviCtrl.Param.Byte[8] = VersionInfo.BL_Firmware;
2518 holgerb 212
                    ToNaviCtrl.Param.Byte[9] = ActiveParamSet;
2499 holgerb 213
                                ToNaviCtrl.Param.Int[5] = FlugMinutenGesamt; // 10 & 11
214
                                slow_command++;  
215
                         break;
216
                         case 1:
217
                                ToNaviCtrl.Command = SPI_FCCMD_PARAMETER1;
2341 holgerb 218
                                ToNaviCtrl.Param.Byte[0] = (unsigned char) BattLowVoltageWarning; //0.1V
219
                                ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain;           // Parameters for the Naviboard
1051 killagreg 220
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP;
221
                                ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI;
222
                                ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD;
2344 holgerb 223
                                ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsA;
1051 killagreg 224
                                ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat;
225
                ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold;
2447 holgerb 226
                ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviMaxFlyingRange;
993 hbuss 227
                ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection;
1936 holgerb 228
                ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviAccCompensation;
1064 hbuss 229
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation;
2499 holgerb 230
                                slow_command++;
2477 holgerb 231
                         break;
2499 holgerb 232
                         case 2:
233
                                ToNaviCtrl.Command = SPI_FCCMD_SLOW2;
234
                                ToNaviCtrl.Param.Int[0] = BoatNeutralNick; // 0 & 1
235
                                ToNaviCtrl.Param.Int[1] = BoatNeutralRoll; // 2 & 3
236
                                ToNaviCtrl.Param.Int[2] = BoatNeutralGier; // 4 & 5
237
                                ToNaviCtrl.Param.Byte[6] = EE_Parameter.CamOrientation;
238
                                ToNaviCtrl.Param.Byte[7] = EE_Parameter.CompassOffset;
239
                                ToNaviCtrl.Param.Byte[8] = Parameter_GlobalConfig;
240
                                ToNaviCtrl.Param.Byte[9] = Parameter_ExtraConfig;
241
                                ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle;
242
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.GlobalConfig3;
243
                                slow_command++;  
244
                         break;
245
                         case 3:
246
                                ToNaviCtrl.Command = SPI_FCCMD_SLOW3;
247
                                ToNaviCtrl.Param.Byte[0] = Parameter_ServoNickControl;
248
                                ToNaviCtrl.Param.Byte[1] = Parameter_ServoRollControl;
249
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviDescendRange; // in 10m
250
                                ToNaviCtrl.Param.Byte[3] = Parameter_MaximumAltitude;
2501 holgerb 251
                                ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoCompInvert;
2518 holgerb 252
                                ToNaviCtrl.Param.Byte[5] = LipoCells;
253
                                ToNaviCtrl.Param.Int[3] = ShutterCounter; // 6 & 7
2541 holgerb 254
                                ToNaviCtrl.Param.Byte[8] = LowVoltageLandingActive;
2560 holgerb 255
                                ToNaviCtrl.Param.Byte[9] = EE_Parameter.FailSafeTime;
2499 holgerb 256
ToNaviCtrl.Param.Byte[10] = 0;
257
ToNaviCtrl.Param.Byte[11] = 0;
258
                                slow_command++;  
259
                 break;
2477 holgerb 260
                         default:
2499 holgerb 261
                                ToNaviCtrl.Command = SPI_FCCMD_NEUTRAL;
2477 holgerb 262
                                ToNaviCtrl.Param.Int[0] = AdNeutralNick; // 0 & 1
263
                                ToNaviCtrl.Param.Int[1] = AdNeutralRoll; // 2 & 3
264
                                ToNaviCtrl.Param.Int[2] = AdNeutralGier; // 4 & 5
265
                                ToNaviCtrl.Param.Byte[6] = EE_Parameter.Driftkomp;
2499 holgerb 266
                                ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviPH_LoginTime;
267
                                ToNaviCtrl.Param.Byte[8] = EE_Parameter.Receiver;
268
                                ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviGpsPLimit;
269
                                ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviGpsILimit;
270
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviGpsDLimit;
271
                                slow_command = 0;
2477 holgerb 272
                         break;
273
                        }      
823 ingob 274
            break;
2183 holgerb 275
         case SPI_FCCMD_PARAMETER2:
2440 holgerb 276
                                ToNaviCtrl.Param.Byte[0] = EE_Parameter.AutoPhotoDistance;     // Distance between Photo releases
2190 holgerb 277
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2263 holgerb 278
                                // create the ToNC_SpeakHoTT
279
                                if(EE_Parameter.Receiver != RECEIVER_HOTT)
280
                                 {
281
                                  if(JetiBeep != 'B') JetiBeep = pgm_read_byte(&JETI_CODE[HoTT_Waring()]);
282
                                  else HoTT_Waring();
283
                                 }
2190 holgerb 284
                                ToNaviCtrl.Param.Byte[1] = ToNC_SpeakHoTT;
285
#else
286
                                ToNaviCtrl.Param.Byte[1] = 0;
287
#endif
2499 holgerb 288
                                ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh    // 2 & 3
2408 holgerb 289
                                ToNaviCtrl.Param.Byte[4] = LowVoltageHomeActive;
2418 holgerb 290
                                ToNaviCtrl.Param.Byte[5] = ToNC_Load_WP_List;
2438 holgerb 291
                                ToNaviCtrl.Param.Byte[6] = ToNC_Load_SingePoint;
292
                                ToNaviCtrl.Param.Byte[7] = ToNC_Store_SingePoint;
2418 holgerb 293
                                ToNC_Load_WP_List = 0;
2438 holgerb 294
                                ToNC_Load_SingePoint = 0;
295
                                ToNC_Store_SingePoint = 0;
2477 holgerb 296
                                if(Parameter_KompassWirkung) ToNaviCtrl.Param.sInt[4] = KompassSollWert; // Pos. 8 & 9
297
                                else ToNaviCtrl.Param.sInt[4] = ErsatzKompassInGrad; // answer with the compass value if the Compass effect is zero
2499 holgerb 298
                                ToNaviCtrl.Param.Byte[10] = FC_StatusFlags3;
2440 holgerb 299
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.SingleWpSpeed;
2183 holgerb 300
            break;
1448 killagreg 301
         case SPI_FCCMD_STICK:
2496 holgerb 302
/*
1320 hbuss 303
              cli();
871 hbuss 304
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 305
                                ToNaviCtrl.Param.Byte[0] = (char) tmp;
871 hbuss 306
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 307
                                ToNaviCtrl.Param.Byte[1] = (char) tmp;
871 hbuss 308
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
846 hbuss 309
                                ToNaviCtrl.Param.Byte[2] = (char) tmp;
871 hbuss 310
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
1320 hbuss 311
              sei();
846 hbuss 312
                                ToNaviCtrl.Param.Byte[3] = (char) tmp;
2496 holgerb 313
*/
314
                                ToNaviCtrl.Param.Byte[0] = ChannelGas;
315
                                ToNaviCtrl.Param.Byte[1] = ChannelYaw;
316
                                ToNaviCtrl.Param.Byte[2] = ChannelRoll;
317
                                ToNaviCtrl.Param.Byte[3] = ChannelNick;
1377 hbuss 318
                                ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0];
319
                                ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1];
320
                                ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2];
321
                    ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3];
322
                                ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4];
323
                                ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5];
324
                                ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6];
325
                                ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7];
1241 killagreg 326
                        break;
1448 killagreg 327
                case SPI_FCCMD_MISC:
2418 holgerb 328
                        if(WinkelOut.CalcState >= 5)
1241 killagreg 329
                        {
330
                                WinkelOut.CalcState = 0;
331
                                ToNaviCtrl.Param.Byte[0] = 5;
332
                        }
333
                        else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState;
2499 holgerb 334
                        ToNaviCtrl.Param.Byte[1] = HoverGas / 4;
335
                        ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); //2 & 3
336
                        ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5);  //4 & 5
337
                        ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[0];
338
                        ToNaviCtrl.Param.Byte[7] = VersionInfo.HardwareError[1];
339
                        VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; //                         VersionInfo.HardwareError[0] = 0;
340
                        VersionInfo.HardwareError[1] &= FC_ERROR1_MIXER;
341
                        ToNaviCtrl.Param.Byte[8] = DebugOut.Analog[28]; // I2C-Error counter
1377 hbuss 342
            ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay;
2370 holgerb 343
                        ToNaviCtrl.Param.Byte[10] = NC_Wait_for_LED;
1377 hbuss 344
                        ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil
1241 killagreg 345
                        break;
346
        }
2010 holgerb 347
 
1215 hbuss 348
  if(SPI_RxDataValid)
1051 killagreg 349
  {
2148 holgerb 350
        if(FromNaviCtrl.Command != oldcommand) NaviDataOkay = 250;
351
        oldcommand = FromNaviCtrl.Command;
1852 killagreg 352
        CalculateCompassTimer = 1;
353
        if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV))
354
        {
355
                GPS_Nick = FromNaviCtrl.GPS_Nick;
356
                GPS_Roll = FromNaviCtrl.GPS_Roll;
357
        }
1690 holgerb 358
 
1852 killagreg 359
        // update compass readings
1936 holgerb 360
//      MagVec.x = FromNaviCtrl.MagVecX;
361
//      MagVec.y = FromNaviCtrl.MagVecY;
362
//      MagVec.z = FromNaviCtrl.MagVecZ;
1852 killagreg 363
 
1690 holgerb 364
        if(FromNaviCtrl.CompassValue <= 360)   KompassValue = FromNaviCtrl.CompassValue;
1051 killagreg 365
 
2029 holgerb 366
    if(FromNaviCtrl.BeepTime > beeptime && !DisableRcOffBeeping) beeptime = FromNaviCtrl.BeepTime;
823 ingob 367
          switch (FromNaviCtrl.Command)
368
          {
1448 killagreg 369
            case SPI_NCCMD_KALMAN:
1231 killagreg 370
                        FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0];
371
                        FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1];
372
                        FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2];
1944 holgerb 373
                        KompassFusion = FromNaviCtrl.Param.sByte[3];
2501 holgerb 374
                        if(FromNaviCtrl.Param.Byte[4] & 0x01) NCForcesNewDirection = 1;
1664 holgerb 375
                        FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5];
376
                        FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6];
1945 holgerb 377
                        GPS_Aid_StickMultiplikator = FromNaviCtrl.Param.Byte[7];
2497 holgerb 378
                        if(FromNaviCtrl.Param.sInt[4] >= 0)
1840 holgerb 379
                         {
2497 holgerb 380
                          NC_CompassSetpoint = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben
1856 killagreg 381
                         }
1862 holgerb 382
                        POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel
1231 killagreg 383
                        break;
1448 killagreg 384
                case SPI_NCCMD_VERSION:
385
                        NC_Version.Major = FromNaviCtrl.Param.Byte[0];
386
                        NC_Version.Minor = FromNaviCtrl.Param.Byte[1];
387
                        NC_Version.Patch = FromNaviCtrl.Param.Byte[2];
388
                        NC_Version.Compatible = FromNaviCtrl.Param.Byte[3];
389
                        NC_Version.Hardware = FromNaviCtrl.Param.Byte[4];
1702 holgerb 390
                        DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5];
391
                        DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08));
1920 holgerb 392
                        NC_ErrorCode = FromNaviCtrl.Param.Byte[7];
393
                        NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8];
1944 holgerb 394
                        FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[9];
2009 holgerb 395
                        NC_To_FC_Flags = FromNaviCtrl.Param.Byte[10];
2447 holgerb 396
//NC_To_FC_MaxAltitude = FromNaviCtrl.Param.Byte[11];
1856 killagreg 397
                        break;
1451 killagreg 398
                case SPI_NCCMD_GPSINFO:
399
                        GPSInfo.Flags = FromNaviCtrl.Param.Byte[0];
400
                        GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1];
401
                        GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2];
1690 holgerb 402
                        GPSInfo.Speed = FromNaviCtrl.Param.Byte[3];
1852 killagreg 403
                        GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2];
1472 killagreg 404
                        GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3];
2540 holgerb 405
                    if(!FromNC_WP_EventChannel_New) FromNC_WP_EventChannel_New = (unsigned char) FromNaviCtrl.Param.Byte[8] + 127;  // zwischenspeichern, damit keiner verpasst wird
2340 holgerb 406
                        PPM_in[WP_EVENT_PPM_IN] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value (FromNC_WP_EventChannel)
2488 holgerb 407
                        FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9];
1857 holgerb 408
                FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10;  // in cm
1451 killagreg 409
                        break;
1972 holgerb 410
                case SPI_MISC:
411
                        EarthMagneticField = FromNaviCtrl.Param.Byte[0];
412
                        EarthMagneticInclination = FromNaviCtrl.Param.Byte[1];
413
                        EarthMagneticInclinationTheoretic = FromNaviCtrl.Param.Byte[2];
2090 holgerb 414
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2179 holgerb 415
                        if(FromNaviCtrl.Param.Byte[3])
2120 holgerb 416
            if(!SpeakHoTT || (SpeakHoTT >= SPEAK_GPS_HOLD && SpeakHoTT <= SPEAK_GPS_OFF)) SpeakHoTT = FromNaviCtrl.Param.Byte[3];
2426 holgerb 417
                        NaviData_TargetDistance = FromNaviCtrl.Param.Int[3];
418
#endif
2179 holgerb 419
                        NaviData_WaypointIndex = FromNaviCtrl.Param.Byte[4];
420
                        NaviData_WaypointNumber = FromNaviCtrl.Param.Byte[5];
421
                        NaviData_TargetHoldTime = FromNaviCtrl.Param.Byte[8];
2420 holgerb 422
                        NaviData_MaxWpListIndex = FromNaviCtrl.Param.Byte[9];
2437 holgerb 423
                        CompassCorrected = FromNaviCtrl.Param.sInt[5]; // Bytes 10 & 11
2090 holgerb 424
                        break;    
1972 holgerb 425
 
1940 holgerb 426
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
427
                case SPI_NCCMD_HOTT_DATA:
2377 holgerb 428
                        //if(EE_Parameter.Receiver == RECEIVER_HOTT) 
429
                        NC_Fills_HoTT_Telemety();
1940 holgerb 430
                        break;
431
#endif
432
 
1855 holgerb 433
// 0 = 0,1
434
// 1 = 2,3
435
// 2 = 4,5
436
// 3 = 6,7
437
// 4 = 8,9
438
// 5 = 10,11
823 ingob 439
                default:
1451 killagreg 440
                        break;
823 ingob 441
          }
720 ingob 442
  }
443
  else
444
  {
819 hbuss 445
//    KompassValue = 0;
446
//    KompassRichtung = 0;
720 ingob 447
        GPS_Nick = 0;
448
    GPS_Roll = 0;
449
  }
304 ingob 450
}
451
 
597 ingob 452
#endif
304 ingob 453
 
454