Subversion Repositories FlightCtrl

Rev

Rev 1378 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1378 Rev 1550
Line 5... Line 5...
5
//struct str_ToNaviCtrl_Version   ToNaviCtrl_Version;
5
//struct str_ToNaviCtrl_Version   ToNaviCtrl_Version;
6
//struct str_FromNaviCtrl_Version   FromNaviCtrl_Version;
6
//struct str_FromNaviCtrl_Version   FromNaviCtrl_Version;
7
struct str_ToNaviCtrl   ToNaviCtrl;
7
struct str_ToNaviCtrl   ToNaviCtrl;
8
struct str_FromNaviCtrl   FromNaviCtrl;
8
struct str_FromNaviCtrl   FromNaviCtrl;
9
struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
9
struct str_FromNaviCtrl_Value FromNaviCtrl_Value;
10
struct str_SPI_VersionInfo SPI_VersionInfo;
10
struct str_SPI_VersionInfo NC_Version;
-
 
11
struct str_GPSInfo GPSInfo;
Line 11... Line 12...
11
 
12
 
12
unsigned char              SPI_BufferIndex;
13
unsigned char              SPI_BufferIndex;
Line 13... Line 14...
13
unsigned char              SPI_RxBufferIndex;
14
unsigned char              SPI_RxBufferIndex;
14
 
15
 
Line 15... Line 16...
15
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
16
volatile unsigned char     SPI_Buffer[sizeof(FromNaviCtrl)];
16
unsigned char *SPI_TX_Buffer;
17
unsigned char *SPI_TX_Buffer;
Line 17... Line 18...
17
 
18
 
18
unsigned char SPITransferCompleted, SPI_ChkSum;
19
unsigned char SPITransferCompleted, SPI_ChkSum;
Line 19... Line 20...
19
unsigned char SPI_RxDataValid,NaviDataOkay = 0;
20
unsigned char SPI_RxDataValid,NaviDataOkay = 0;
Line 20... Line 21...
20
 
21
 
Line 38... Line 39...
38
  //SPDR = 0x00;  // dummy write
39
  //SPDR = 0x00;  // dummy write
Line 39... Line 40...
39
 
40
 
40
  ToNaviCtrl.Sync1 = 0xAA;
41
  ToNaviCtrl.Sync1 = 0xAA;
Line 41... Line 42...
41
  ToNaviCtrl.Sync2 = 0x83;
42
  ToNaviCtrl.Sync2 = 0x83;
42
 
43
 
43
  ToNaviCtrl.Command = SPI_CMD_USER;
44
  ToNaviCtrl.Command = SPI_FCCMD_USER;
44
  ToNaviCtrl.IntegralNick = 0;
45
  ToNaviCtrl.IntegralNick = 0;
45
  ToNaviCtrl.IntegralRoll = 0;
46
  ToNaviCtrl.IntegralRoll = 0;
Line 46... Line -...
46
  FromNaviCtrl_Value.SerialDataOkay = 0;
-
 
47
  SPI_RxDataValid = 0;
-
 
48
 
-
 
49
  SPI_VersionInfo.Major = VERSION_MAJOR;
-
 
50
  SPI_VersionInfo.Minor = VERSION_MINOR;
47
  FromNaviCtrl_Value.SerialDataOkay = 0;
Line 51... Line 48...
51
  SPI_VersionInfo.Patch = VERSION_PATCH;
48
  SPI_RxDataValid = 0;
52
  SPI_VersionInfo.Compatible = NC_SPI_COMPATIBLE;
49
 
53
}
50
}
Line 167... Line 164...
167
  NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0;
164
  NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0;
168
//  ToNaviCtrl.User8 = Parameter_UserParam8;
165
//  ToNaviCtrl.User8 = Parameter_UserParam8;
169
//  ToNaviCtrl.CalState = WinkelOut.CalcState;
166
//  ToNaviCtrl.CalState = WinkelOut.CalcState;
170
   switch(ToNaviCtrl.Command)  //
167
   switch(ToNaviCtrl.Command)  //
171
   {
168
   {
172
         case SPI_CMD_USER:
169
         case SPI_FCCMD_USER:
173
                                ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1;
170
                                ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1;
174
                                ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2;
171
                                ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2;
175
                                ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3;
172
                                ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3;
176
                                ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4;
173
                                ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4;
177
                                ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5;
174
                                ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5;
178
                                ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6;
175
                                ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6;
179
                                ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7;
176
                                ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7;
180
                                ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8;
177
                                ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8;
181
                                ToNaviCtrl.Param.Byte[8] = (unsigned char) MikroKopterFlags;
178
                                ToNaviCtrl.Param.Byte[8] = (unsigned char) FCFlags;
182
                MikroKopterFlags &= ~(FLAG_CALIBRATE | FLAG_START);
179
                FCFlags &= ~(FCFLAG_CALIBRATE | FCFLAG_START);
183
                    ToNaviCtrl.Param.Byte[9] = (unsigned char) UBat;
-
 
184
                    ToNaviCtrl.Param.Byte[10] =(unsigned char) BattLowVoltageWarning;
-
 
185
                    ToNaviCtrl.Param.Byte[11] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
180
                    ToNaviCtrl.Param.Byte[9] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
186
        break;
181
        break;
Line -... Line 182...
-
 
182
 
-
 
183
     case SPI_FCCMD_ACCU:
-
 
184
                        ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A
-
 
185
                        ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh
-
 
186
                        ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V
-
 
187
                        ToNaviCtrl.Param.Byte[5] = (unsigned char) BattLowVoltageWarning; //0.1V
-
 
188
        break;
187
 
189
 
188
         case SPI_CMD_PARAMETER1:
190
         case SPI_FCCMD_PARAMETER1:
189
                                ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl;     // Parameters for the Naviboard
191
                                ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl;     // Parameters for the Naviboard
190
                                ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain;
192
                                ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain;
191
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP;
193
                                ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP;
192
                                ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI;
194
                                ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI;
Line 198... Line 200...
198
                ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection;
200
                ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection;
199
                ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation;
201
                ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation;
200
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation;
202
                                ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation;
201
            break;
203
            break;
Line 202... Line 204...
202
 
204
 
203
         case SPI_CMD_STICK:
205
         case SPI_FCCMD_STICK:
204
              cli();
206
              cli();
205
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
207
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]];  if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
206
                                ToNaviCtrl.Param.Byte[0] = (char) tmp;
208
                                ToNaviCtrl.Param.Byte[0] = (char) tmp;
207
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
209
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
208
                                ToNaviCtrl.Param.Byte[1] = (char) tmp;
210
                                ToNaviCtrl.Param.Byte[1] = (char) tmp;
209
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
211
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
210
                                ToNaviCtrl.Param.Byte[2] = (char) tmp;
212
                                ToNaviCtrl.Param.Byte[2] = (char) tmp;
211
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
213
                tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127;
212
              sei();
214
              sei();
213
                                ToNaviCtrl.Param.Byte[3] = (char) tmp;
215
                                ToNaviCtrl.Param.Byte[3] = (char) tmp;
214
                                ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti1;
216
                                ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0];
215
                                ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti2;
217
                                ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1];
216
                                ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti3;
218
                                ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2];
217
                    ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti4;
219
                    ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3];
218
                    ToNaviCtrl.Param.Byte[8] = (unsigned char) SenderOkay;
220
                                ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4];
219
                    ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderRSSI;
221
                                ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5];
-
 
222
                                ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6];
220
                                ToNaviCtrl.Param.Byte[10] = DebugOut.Analog[7] / 4; //GasMischanteil
223
                                ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7];
221
                        break;
224
                        break;
222
                case SPI_CMD_MISC:
225
                case SPI_FCCMD_MISC:
223
                        if(WinkelOut.CalcState > 5)
226
                        if(WinkelOut.CalcState > 5)
224
                        {
227
                        {
225
                                WinkelOut.CalcState = 0;
228
                                WinkelOut.CalcState = 0;
226
                                ToNaviCtrl.Param.Byte[0] = 5;
229
                                ToNaviCtrl.Param.Byte[0] = 5;
Line 230... Line 233...
230
                        ToNaviCtrl.Param.Int[1] = DebugOut.Analog[5];// = HoehenWert/5;
233
                        ToNaviCtrl.Param.Int[1] = DebugOut.Analog[5];// = HoehenWert/5;
231
                        ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5);
234
                        ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5);
232
                        ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit;
235
                        ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit;
233
                        ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit;
236
                        ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit;
234
                        ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit;
237
                        ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit;
-
 
238
            ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay;
-
 
239
            ToNaviCtrl.Param.Byte[10] = (unsigned char) SenderRSSI;
-
 
240
                        ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil
235
                        break;
241
                        break;
236
 
-
 
237
                case SPI_CMD_VERSION:
242
                case SPI_FCCMD_VERSION:
238
                        ToNaviCtrl.Param.Byte[0] = SPI_VersionInfo.Major;
243
                        ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR;
239
                        ToNaviCtrl.Param.Byte[1] = SPI_VersionInfo.Minor;
244
                        ToNaviCtrl.Param.Byte[1] = VERSION_MINOR;
240
                        ToNaviCtrl.Param.Byte[2] = SPI_VersionInfo.Patch;
245
                        ToNaviCtrl.Param.Byte[2] = VERSION_PATCH;
241
                        ToNaviCtrl.Param.Byte[3] = SPI_VersionInfo.Compatible;
246
                        ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE;
242
                        ToNaviCtrl.Param.Byte[4] = PlatinenVersion;
247
                        ToNaviCtrl.Param.Byte[4] = PlatinenVersion;
243
                break;
248
                break;
Line 244... Line 249...
244
 
249
 
245
            case SPI_CMD_SERVOS:
250
            case SPI_FCCMD_SERVOS:
246
                ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh;     // Parameters for the Servo Control
251
                ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh;     // Parameters for the Servo Control
247
                        ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert;
252
                        ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert;
248
                        ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl;
253
                        ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl;
249
                        ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp;
254
                        ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp;
Line 269... Line 274...
269
 
274
 
Line 270... Line 275...
270
    if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime;
275
    if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime;
271
 
276
 
272
          switch (FromNaviCtrl.Command)
277
          switch (FromNaviCtrl.Command)
273
          {
278
          {
274
            case SPI_KALMAN:
279
            case SPI_NCCMD_KALMAN:
275
                        FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0];
280
                        FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0];
276
                        FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1];
281
                        FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1];
277
                        FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2];
282
                        FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2];
278
                        FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3];
283
                        FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3];
Line -... Line 284...
-
 
284
                        FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4];
-
 
285
                        break;
-
 
286
 
-
 
287
                case SPI_NCCMD_VERSION:
-
 
288
                        NC_Version.Major = FromNaviCtrl.Param.Byte[0];
-
 
289
                        NC_Version.Minor = FromNaviCtrl.Param.Byte[1];
-
 
290
                        NC_Version.Patch = FromNaviCtrl.Param.Byte[2];
-
 
291
                        NC_Version.Compatible = FromNaviCtrl.Param.Byte[3];
-
 
292
                        NC_Version.Hardware = FromNaviCtrl.Param.Byte[4];
-
 
293
                        break;
-
 
294
 
-
 
295
                case SPI_NCCMD_GPSINFO:
-
 
296
                        GPSInfo.Flags = FromNaviCtrl.Param.Byte[0];
-
 
297
                        GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1];
-
 
298
                        GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2];
-
 
299
                        GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2];
279
                        FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4];
300
                        GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3];
280
                        break;
301
                        break;
281
 
302
 
282
                default:
303
                default:
283
                  break;
304
                        break;
284
          }
305
          }
285
  }
306
  }