Rev 623 | Rev 626 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 623 | Rev 625 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | 56 | ||
57 | #include <string.h> |
57 | #include <string.h> |
58 | #include <math.h> |
58 | #include <math.h> |
59 | #include <stdlib.h> |
59 | #include <stdlib.h> |
60 | #include "91x_lib.h" |
60 | #include "91x_lib.h" |
61 | #include "led.h" |
61 | #include "led.h" |
62 | #include "gps.h" |
62 | #include "gps.h" |
63 | #include "uart1.h" |
63 | #include "uart1.h" |
64 | #include "spi_slave.h" |
64 | #include "spi_slave.h" |
65 | #include "compass.h" |
65 | #include "compass.h" |
66 | #include "timer1.h" |
66 | #include "timer1.h" |
67 | #include "timer2.h" |
67 | #include "timer2.h" |
68 | #include "config.h" |
68 | #include "config.h" |
69 | #include "main.h" |
69 | #include "main.h" |
70 | #include "params.h" |
70 | #include "params.h" |
71 | #include "settings.h" |
71 | #include "settings.h" |
72 | 72 | ||
73 | #define SPI_RXSYNCBYTE1 0xAA |
73 | #define SPI_RXSYNCBYTE1 0xAA |
74 | #define SPI_RXSYNCBYTE2 0x83 |
74 | #define SPI_RXSYNCBYTE2 0x83 |
75 | #define SPI_TXSYNCBYTE1 0x81 |
75 | #define SPI_TXSYNCBYTE1 0x81 |
76 | #define SPI_TXSYNCBYTE2 0x55 |
76 | #define SPI_TXSYNCBYTE2 0x55 |
77 | 77 | ||
78 | //communication packets |
78 | //communication packets |
79 | FromFlightCtrl_t FromFlightCtrl; |
79 | FromFlightCtrl_t FromFlightCtrl; |
80 | ToFlightCtrl_t ToFlightCtrl; |
80 | ToFlightCtrl_t ToFlightCtrl; |
81 | #define SPI0_TIMEOUT 2500 //ms |
81 | #define SPI0_TIMEOUT 2500 //ms |
82 | volatile u32 SPI0_Timeout = 0; |
82 | volatile u32 SPI0_Timeout = 0; |
83 | u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0; |
83 | u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0; |
84 | u8 SpeakHoTT = 0; |
84 | u8 SpeakHoTT = 0; |
85 | u32 LoggingGasFilter = 0, LoggingGasCnt = 0; |
85 | u32 LoggingGasFilter = 0, LoggingGasCnt = 0; |
86 | u8 Out1TriggerUpdateBlocked = 0; |
86 | u8 Out1TriggerUpdateBlocked = 0; |
87 | u8 Out1TriggerUpdateNewData = 0; |
87 | u8 Out1TriggerUpdateNewData = 0; |
88 | 88 | ||
89 | // tx packet buffer |
89 | // tx packet buffer |
90 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
90 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
91 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
91 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
92 | volatile u8 SPI_TxBufferIndex = 0; |
92 | volatile u8 SPI_TxBufferIndex = 0; |
93 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
93 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
94 | 94 | ||
95 | // rx packet buffer |
95 | // rx packet buffer |
96 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
96 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
97 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
97 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
98 | volatile u8 SPI_RxBufferIndex = 0; |
98 | volatile u8 SPI_RxBufferIndex = 0; |
99 | volatile u8 SPI_RxBuffer_Request = 0; |
99 | volatile u8 SPI_RxBuffer_Request = 0; |
100 | #define SPI_COMMAND_INDEX 0 |
100 | #define SPI_COMMAND_INDEX 0 |
101 | 101 | ||
102 | s32 Kalman_K = 32; |
102 | s32 Kalman_K = 32; |
103 | s32 Kalman_MaxDrift = 5 * 16; |
103 | s32 Kalman_MaxDrift = 5 * 16; |
104 | s32 Kalman_MaxFusion = 64; |
104 | s32 Kalman_MaxFusion = 64; |
105 | s32 Kalman_Kompass = 32; |
105 | s32 Kalman_Kompass = 32; |
106 | s32 ToFcGpsZ = 0; |
106 | s32 ToFcGpsZ = 0; |
107 | u8 CompassCalState = 0; |
107 | u8 CompassCalState = 0; |
108 | 108 | ||
109 | u8 SPI_CommandSequence[] = { SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO ,SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO, SPI_NCCMD_KALMAN, SPI_MISC, SPI_NCCMD_KALMAN, SPI_NCCMD_VERSION }; |
109 | u8 SPI_CommandSequence[] = { SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO ,SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO, SPI_NCCMD_KALMAN, SPI_MISC, SPI_NCCMD_KALMAN, SPI_NCCMD_VERSION }; |
110 | u8 SPI_CommandCounter = 0; |
110 | u8 SPI_CommandCounter = 0; |
111 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
111 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
112 | s32 HeadFreeStartAngle = 0; // in 0,1° |
112 | s32 HeadFreeStartAngle = 0; // in 0,1° |
113 | s32 CompassDirectionAtMotorStart = 0; // in 0,1° |
113 | s32 CompassDirectionAtMotorStart = 0; // in 0,1° |
114 | s16 FC_WP_EventChannel = 0, LogFC_WP_EventChannel = 0, FC_WP_EventChannel_Processed = 0; // gibt einen Schaltkanal an die FC weiter, wenn der Wegpunkt erreicht wurde |
114 | s16 FC_WP_EventChannel = 0, LogFC_WP_EventChannel = 0, FC_WP_EventChannel_Processed = 0; // gibt einen Schaltkanal an die FC weiter, wenn der Wegpunkt erreicht wurde |
115 | u32 ToFC_AltitudeRate = 0; |
115 | u32 ToFC_AltitudeRate = 0; |
116 | s32 ToFC_AltitudeSetpoint = 0; |
116 | s32 ToFC_AltitudeSetpoint = 0; |
117 | u8 FromFC_VarioCharacter = ' '; |
117 | u8 FromFC_VarioCharacter = ' '; |
118 | s16 GPS_Aid_StickMultiplikator = 0; |
118 | s16 GPS_Aid_StickMultiplikator = 0; |
119 | u8 NC_GPS_ModeCharacter = ' '; |
119 | u8 NC_GPS_ModeCharacter = ' '; |
120 | u8 FCCalibActive = 0; |
120 | u8 FCCalibActive = 0; |
121 | u8 FC_is_Calibrated = 0; |
121 | u8 FC_is_Calibrated = 0; |
122 | Motor_t Motor[MAX_MOTORS]; |
122 | Motor_t Motor[MAX_MOTORS]; |
123 | u8 Motor_Version[MAX_MOTORS]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
123 | u8 Motor_Version[MAX_MOTORS]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
124 | u8 NC_To_FC_Flags = 0; |
124 | u8 NC_To_FC_Flags = 0; |
125 | u8 BL_MinOfMaxPWM = 255; // indication if all BL-controllers run on full power |
125 | u8 BL_MinOfMaxPWM = 255; // indication if all BL-controllers run on full power |
126 | u8 Logging_BL_MinOfMaxPWM = 255; |
126 | u8 Logging_BL_MinOfMaxPWM = 255; |
127 | u8 ErrorCheck_BL_MinOfMaxPWM = 255; |
127 | u8 ErrorCheck_BL_MinOfMaxPWM = 255; |
128 | u32 FC_I2C_ErrorConter; |
128 | u32 FC_I2C_ErrorConter; |
129 | SPI_Version_t FC_Version; |
129 | SPI_Version_t FC_Version; |
130 | s16 POI_KameraNick = 0; |
130 | s16 POI_KameraNick = 0; |
131 | u8 NC_Wait_for_LED = 0; |
131 | u8 NC_Wait_for_LED = 0; |
132 | s16 GyroCompassCorrected = 0; // corrected with the magnetic declination |
132 | s16 GyroCompassCorrected = 0; // corrected with the magnetic declination |
133 | s16 CompassSetpointCorrected = 0; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
133 | s16 CompassSetpointCorrected = 0; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
134 | s16 CompassSetpoint = 0; // in 0,1° |
134 | s16 CompassSetpoint = 0; // in 0,1° |
135 | s16 SimulatedDirection = 0; // only for flight simulation |
135 | s16 SimulatedDirection = 0; // only for flight simulation |
136 | u8 AmountOfMotors = 0; |
136 | u8 AmountOfMotors = 0; |
137 | u16 FlugMinutenGesamt; |
137 | u16 FlugMinutenGesamt; |
138 | u8 HoverGas = 0; |
138 | u8 HoverGas = 0; |
- | 139 | u8 LowVoltageLandingActive = 0; |
|
139 | //-------------------------------------------------------------- |
140 | //-------------------------------------------------------------- |
140 | void SSP0_IRQHandler(void) |
141 | void SSP0_IRQHandler(void) |
141 | { |
142 | { |
142 | static u8 rxchksum = 0; |
143 | static u8 rxchksum = 0; |
143 | u8 rxdata; |
144 | u8 rxdata; |
144 | 145 | ||
145 | #define SPI_SYNC1 0 |
146 | #define SPI_SYNC1 0 |
146 | #define SPI_SYNC2 1 |
147 | #define SPI_SYNC2 1 |
147 | #define SPI_DATA 2 |
148 | #define SPI_DATA 2 |
148 | static u8 SPI_State = SPI_SYNC1; |
149 | static u8 SPI_State = SPI_SYNC1; |
149 | //IENABLE; |
150 | //IENABLE; |
150 | 151 | ||
151 | // clear pending bits |
152 | // clear pending bits |
152 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
153 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
153 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
154 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
154 | 155 | ||
155 | // while RxFIFO not empty |
156 | // while RxFIFO not empty |
156 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
157 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
157 | { |
158 | { |
158 | rxdata = SSP0->DR; // catch the received byte |
159 | rxdata = SSP0->DR; // catch the received byte |
159 | // Fill TxFIFO while its not full or end of packet is reached |
160 | // Fill TxFIFO while its not full or end of packet is reached |
160 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
161 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
161 | { |
162 | { |
162 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
163 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
163 | { |
164 | { |
164 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
165 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
165 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
166 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
166 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
167 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
167 | SPI_TxBufferIndex++; // pointer to next byte |
168 | SPI_TxBufferIndex++; // pointer to next byte |
168 | } |
169 | } |
169 | else // end of packet is reached reset and copy data to tx buffer |
170 | else // end of packet is reached reset and copy data to tx buffer |
170 | { |
171 | { |
171 | SPI_TxBufferIndex = 0; // reset buffer index |
172 | SPI_TxBufferIndex = 0; // reset buffer index |
172 | ToFlightCtrl.Chksum = 0; // initialize checksum |
173 | ToFlightCtrl.Chksum = 0; // initialize checksum |
173 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
174 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
174 | BeepTime = 0; // reset local beeptime |
175 | BeepTime = 0; // reset local beeptime |
175 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
176 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
176 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
177 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
177 | } |
178 | } |
178 | } |
179 | } |
179 | switch (SPI_State) |
180 | switch (SPI_State) |
180 | { |
181 | { |
181 | case SPI_SYNC1: |
182 | case SPI_SYNC1: |
182 | SPI_RxBufferIndex = 0; // reset buffer index |
183 | SPI_RxBufferIndex = 0; // reset buffer index |
183 | rxchksum = rxdata; // init checksum |
184 | rxchksum = rxdata; // init checksum |
184 | if (rxdata == SPI_RXSYNCBYTE1) |
185 | if (rxdata == SPI_RXSYNCBYTE1) |
185 | { // 1st syncbyte ok |
186 | { // 1st syncbyte ok |
186 | SPI_State = SPI_SYNC2; // step to sync2 |
187 | SPI_State = SPI_SYNC2; // step to sync2 |
187 | } |
188 | } |
188 | break; |
189 | break; |
189 | case SPI_SYNC2: |
190 | case SPI_SYNC2: |
190 | if (rxdata == SPI_RXSYNCBYTE2) |
191 | if (rxdata == SPI_RXSYNCBYTE2) |
191 | { // 2nd Syncbyte ok |
192 | { // 2nd Syncbyte ok |
192 | rxchksum += rxdata; |
193 | rxchksum += rxdata; |
193 | SPI_State = SPI_DATA; |
194 | SPI_State = SPI_DATA; |
194 | } // 2nd Syncbyte does not match |
195 | } // 2nd Syncbyte does not match |
195 | else |
196 | else |
196 | { |
197 | { |
197 | SPI_State = SPI_SYNC1; //jump back to sync1 |
198 | SPI_State = SPI_SYNC1; //jump back to sync1 |
198 | } |
199 | } |
199 | break; |
200 | break; |
200 | case SPI_DATA: |
201 | case SPI_DATA: |
201 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
202 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
202 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
203 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
203 | { |
204 | { |
204 | if (rxdata == rxchksum) // verify checksum byte |
205 | if (rxdata == rxchksum) // verify checksum byte |
205 | { |
206 | { |
206 | // copy SPI_RxBuffer -> FromFlightCtrl |
207 | // copy SPI_RxBuffer -> FromFlightCtrl |
207 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
208 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
208 | { |
209 | { |
209 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
210 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
210 | SPI_RxBuffer_Request = 1; |
211 | SPI_RxBuffer_Request = 1; |
211 | } |
212 | } |
212 | // reset timeout counter on good packet |
213 | // reset timeout counter on good packet |
213 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
214 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
214 | DebugOut.Analog[13]++; |
215 | DebugOut.Analog[13]++; |
215 | } |
216 | } |
216 | else // bad checksum byte |
217 | else // bad checksum byte |
217 | { |
218 | { |
218 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
219 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
219 | } |
220 | } |
220 | SPI_State = SPI_SYNC1; // reset state |
221 | SPI_State = SPI_SYNC1; // reset state |
221 | } |
222 | } |
222 | else // end of packet not reached |
223 | else // end of packet not reached |
223 | { |
224 | { |
224 | rxchksum += rxdata; // update checksum |
225 | rxchksum += rxdata; // update checksum |
225 | } |
226 | } |
226 | break; |
227 | break; |
227 | default: |
228 | default: |
228 | SPI_State = SPI_SYNC1; |
229 | SPI_State = SPI_SYNC1; |
229 | break; |
230 | break; |
230 | } |
231 | } |
231 | } |
232 | } |
232 | 233 | ||
233 | // IDISABLE; |
234 | // IDISABLE; |
234 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
235 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
235 | } |
236 | } |
236 | 237 | ||
237 | //-------------------------------------------------------------- |
238 | //-------------------------------------------------------------- |
238 | void SPI0_Init(void) |
239 | void SPI0_Init(void) |
239 | { |
240 | { |
240 | GPIO_InitTypeDef GPIO_InitStructure; |
241 | GPIO_InitTypeDef GPIO_InitStructure; |
241 | SSP_InitTypeDef SSP_InitStructure; |
242 | SSP_InitTypeDef SSP_InitStructure; |
242 | 243 | ||
243 | UART1_PutString("\r\n SPI init..."); |
244 | UART1_PutString("\r\n SPI init..."); |
244 | 245 | ||
245 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
246 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
246 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
247 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
247 | 248 | ||
248 | GPIO_DeInit(GPIO2); |
249 | GPIO_DeInit(GPIO2); |
249 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
250 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
250 | GPIO_StructInit(&GPIO_InitStructure); |
251 | GPIO_StructInit(&GPIO_InitStructure); |
251 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
252 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
252 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
253 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
253 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
254 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
254 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
255 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
255 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
256 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
256 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
257 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
257 | 258 | ||
258 | // SSP0_MISO pin GPIO2.6 |
259 | // SSP0_MISO pin GPIO2.6 |
259 | GPIO_StructInit(&GPIO_InitStructure); |
260 | GPIO_StructInit(&GPIO_InitStructure); |
260 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
261 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
261 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
262 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
262 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
263 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
263 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
264 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
264 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
265 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
265 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
266 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
266 | 267 | ||
267 | SSP_DeInit(SSP0); |
268 | SSP_DeInit(SSP0); |
268 | SSP_StructInit(&SSP_InitStructure); |
269 | SSP_StructInit(&SSP_InitStructure); |
269 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
270 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
270 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
271 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
271 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
272 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
272 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
273 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
273 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
274 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
274 | SSP_InitStructure.SSP_ClockRate = 0; |
275 | SSP_InitStructure.SSP_ClockRate = 0; |
275 | 276 | ||
276 | SSP_Init(SSP0, &SSP_InitStructure); |
277 | SSP_Init(SSP0, &SSP_InitStructure); |
277 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
278 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
278 | SSP_Cmd(SSP0, ENABLE); |
279 | SSP_Cmd(SSP0, ENABLE); |
279 | // initialize the syncbytes in the tx buffer |
280 | // initialize the syncbytes in the tx buffer |
280 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
281 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
281 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
282 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
282 | // set the pointer to the checksum byte in the tx buffer |
283 | // set the pointer to the checksum byte in the tx buffer |
283 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
284 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
284 | 285 | ||
285 | ToFlightCtrl.GPSStick.Nick = 0; |
286 | ToFlightCtrl.GPSStick.Nick = 0; |
286 | ToFlightCtrl.GPSStick.Roll = 0; |
287 | ToFlightCtrl.GPSStick.Roll = 0; |
287 | // ToFlightCtrl.GPSStick.Yaw = 0; |
288 | // ToFlightCtrl.GPSStick.Yaw = 0; |
288 | 289 | ||
289 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
290 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
290 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
291 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
291 | 292 | ||
292 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
293 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
293 | 294 | ||
294 | UART1_PutString("ok"); |
295 | UART1_PutString("ok"); |
295 | } |
296 | } |
296 | 297 | ||
297 | 298 | ||
298 | //------------------------------------------------------ |
299 | //------------------------------------------------------ |
299 | void SPI0_UpdateBuffer(void) |
300 | void SPI0_UpdateBuffer(void) |
300 | { |
301 | { |
301 | static u32 timeout = 0; |
302 | static u32 timeout = 0; |
302 | static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0; |
303 | static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0; |
303 | static s16 last_wp_event = 0; |
304 | static s16 last_wp_event = 0; |
304 | u8 index; |
305 | u8 index; |
305 | s16 tmp; |
306 | s16 tmp; |
306 | s32 i1,i2; |
307 | s32 i1,i2; |
307 | /* |
308 | /* |
308 | union |
309 | union |
309 | { |
310 | { |
310 | unsigned char Byte[4]; |
311 | unsigned char Byte[4]; |
311 | unsigned int Int[2]; |
312 | unsigned int Int[2]; |
312 | unsigned long Long; |
313 | unsigned long Long; |
313 | } Temp; |
314 | } Temp; |
314 | */ |
315 | */ |
315 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
316 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
316 | if(SPI_RxBuffer_Request) |
317 | if(SPI_RxBuffer_Request) |
317 | { |
318 | { |
318 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
319 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
319 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
320 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
320 | ToFlightCtrl.CompassHeading = Compass_Heading; |
321 | ToFlightCtrl.CompassHeading = Compass_Heading; |
321 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
322 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
322 | GyroCompassCorrected = (3600 + FromFlightCtrl.GyroHeading + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
323 | GyroCompassCorrected = (3600 + FromFlightCtrl.GyroHeading + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
323 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
324 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
324 | ToFlightCtrl.MagVecX = MagVector.X; |
325 | ToFlightCtrl.MagVecX = MagVector.X; |
325 | ToFlightCtrl.MagVecY = MagVector.Y; |
326 | ToFlightCtrl.MagVecY = MagVector.Y; |
326 | ToFlightCtrl.MagVecZ = MagVector.Z; |
327 | ToFlightCtrl.MagVecZ = MagVector.Z; |
327 | // ToFlightCtrl.NCStatus = 0; |
328 | // ToFlightCtrl.NCStatus = 0; |
328 | // cycle spi commands |
329 | // cycle spi commands |
329 | if(ErrorCode != last_error_code && enable_injecting) |
330 | if(ErrorCode != last_error_code && enable_injecting) |
330 | { |
331 | { |
331 | ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
332 | ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
332 | last_error_code = ErrorCode; |
333 | last_error_code = ErrorCode; |
333 | enable_injecting = 0; |
334 | enable_injecting = 0; |
334 | } |
335 | } |
335 | else |
336 | else |
336 | if(FC_WP_EventChannel != last_wp_event && enable_injecting) |
337 | if(FC_WP_EventChannel != last_wp_event && enable_injecting) |
337 | { |
338 | { |
338 | ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
339 | ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
339 | last_wp_event = FC_WP_EventChannel; |
340 | last_wp_event = FC_WP_EventChannel; |
340 | enable_injecting = 0; |
341 | enable_injecting = 0; |
341 | } |
342 | } |
342 | else |
343 | else |
343 | { |
344 | { |
344 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
345 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
345 | // restart command cycle at the end |
346 | // restart command cycle at the end |
346 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
347 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
347 | if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1; |
348 | if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1; |
348 | } |
349 | } |
349 | 350 | ||
350 | #define FLAG_GPS_AID 0x01 |
351 | #define FLAG_GPS_AID 0x01 |
351 | switch (ToFlightCtrl.Command) |
352 | switch (ToFlightCtrl.Command) |
352 | { |
353 | { |
353 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
354 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
354 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
355 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
355 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
356 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
356 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
357 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
357 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
358 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
358 | ToFlightCtrl.Param.Byte[4] = 0; // siehe bitcodiert unten |
359 | ToFlightCtrl.Param.Byte[4] = 0; // siehe bitcodiert unten |
359 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
360 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
360 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
361 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
361 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
362 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
362 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
363 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
363 | { |
364 | { |
364 | // if(CAM_Orientation.Azimuth != -1) ToFlightCtrl.Param.sInt[4] = (CAM_Orientation.Azimuth + (3*360) - (FC.FromFC_CompassOffset / 10 + GeoMagDec/10 + Parameter.OrientationAngle * 15)) % 360; // the FC uses the uncorrected comnpass value |
365 | // if(CAM_Orientation.Azimuth != -1) ToFlightCtrl.Param.sInt[4] = (CAM_Orientation.Azimuth + (3*360) - (FC.FromFC_CompassOffset / 10 + GeoMagDec/10 + Parameter.OrientationAngle * 15)) % 360; // the FC uses the uncorrected comnpass value |
365 | if(CAM_Orientation.Azimuth != -1) ToFlightCtrl.Param.sInt[4] = (CAM_Orientation.Azimuth + (3*360) - (FC.FromFC_CompassOffset / 10 + GeoMagDec/10 + Parameter.CamOrientation * 15)) % 360; // the FC uses the uncorrected comnpass value |
366 | if(CAM_Orientation.Azimuth != -1) ToFlightCtrl.Param.sInt[4] = (CAM_Orientation.Azimuth + (3*360) - (FC.FromFC_CompassOffset / 10 + GeoMagDec/10 + Parameter.CamOrientation * 15)) % 360; // the FC uses the uncorrected comnpass value |
366 | else CAM_Orientation.Azimuth = -1; |
367 | else CAM_Orientation.Azimuth = -1; |
367 | if(CAM_Orientation.UpdateMask & FORCE_AZIMUTH_ROTATION) ToFlightCtrl.Param.sByte[4] = 0x01; // allows Yawing without CareFree (Yawing at Coming Home) |
368 | if(CAM_Orientation.UpdateMask & FORCE_AZIMUTH_ROTATION) ToFlightCtrl.Param.sByte[4] = 0x01; // allows Yawing without CareFree (Yawing at Coming Home) |
368 | CAM_Orientation.UpdateMask &= ~(CAM_UPDATE_AZIMUTH | FORCE_AZIMUTH_ROTATION); |
369 | CAM_Orientation.UpdateMask &= ~(CAM_UPDATE_AZIMUTH | FORCE_AZIMUTH_ROTATION); |
369 | } |
370 | } |
370 | else |
371 | else |
371 | { |
372 | { |
372 | ToFlightCtrl.Param.sInt[4] = -1; |
373 | ToFlightCtrl.Param.sInt[4] = -1; |
373 | } |
374 | } |
374 | 375 | ||
375 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
376 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
376 | { |
377 | { |
377 | POI_KameraNick = tmp; |
378 | POI_KameraNick = tmp; |
378 | } |
379 | } |
379 | else |
380 | else |
380 | { |
381 | { |
381 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
382 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
382 | POI_KameraNick = CAM_Orientation.Elevation; |
383 | POI_KameraNick = CAM_Orientation.Elevation; |
383 | //else ToFlightCtrl.Param.sInt[5] = 0; |
384 | //else ToFlightCtrl.Param.sInt[5] = 0; |
384 | } |
385 | } |
385 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
386 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
386 | break; |
387 | break; |
387 | 388 | ||
388 | case SPI_NCCMD_VERSION: |
389 | case SPI_NCCMD_VERSION: |
389 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
390 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
390 | //+ higher than the maximum allowed altitude |
391 | //+ higher than the maximum allowed altitude |
391 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
392 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
392 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
393 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
393 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
394 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
394 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
395 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
395 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
396 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
396 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
397 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
397 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
398 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
398 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
399 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
399 | ToFlightCtrl.Param.Byte[7] = ErrorCode; // muss in SPI_NCCMD_VERSION bleiben! (siehe oben) |
400 | ToFlightCtrl.Param.Byte[7] = ErrorCode; // muss in SPI_NCCMD_VERSION bleiben! (siehe oben) |
400 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
401 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
401 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
402 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
402 | ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags; |
403 | ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags; |
403 | //[11] |
404 | //[11] |
404 | // if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work |
405 | // if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work |
405 | // else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
406 | // else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
406 | break; |
407 | break; |
407 | case SPI_MISC: |
408 | case SPI_MISC: |
408 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
409 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
409 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
410 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
410 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
411 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
411 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
412 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
412 | ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1 |
413 | ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1 |
413 | ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints |
414 | ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints |
414 | ToFlightCtrl.Param.Int[3] = NaviData.TargetPositionDeviation.Distance / 10; |
415 | ToFlightCtrl.Param.Int[3] = NaviData.TargetPositionDeviation.Distance / 10; |
415 | ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached |
416 | ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached |
416 | ToFlightCtrl.Param.Byte[9] = ToFC_MaxWpListIndex; |
417 | ToFlightCtrl.Param.Byte[9] = ToFC_MaxWpListIndex; |
417 | ToFlightCtrl.Param.sInt[5] = GyroCompassCorrected / 10; // Bytes 10 & 11 |
418 | ToFlightCtrl.Param.sInt[5] = GyroCompassCorrected / 10; // Bytes 10 & 11 |
418 | 419 | ||
419 | SpeakHoTT = 0; |
420 | SpeakHoTT = 0; |
420 | break; |
421 | break; |
421 | 422 | ||
422 | case SPI_NCCMD_GPSINFO: |
423 | case SPI_NCCMD_GPSINFO: |
423 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
424 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
424 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
425 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
425 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
426 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
426 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
427 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
427 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
428 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
428 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
429 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
429 | if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254; // Muss in SPI_NCCMD_GPSINFO bleiben! (siehe oben) |
430 | if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254; // Muss in SPI_NCCMD_GPSINFO bleiben! (siehe oben) |
430 | if(FC_WP_EventChannel) |
431 | if(FC_WP_EventChannel) |
431 | { |
432 | { |
432 | LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged |
433 | LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged |
433 | NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; // to make sure that it will be logged |
434 | NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; // to make sure that it will be logged |
434 | Out1TriggerUpdateBlocked = 3; // makes sure that the right trigger-pos is sent in command 18 |
435 | Out1TriggerUpdateBlocked = 3; // makes sure that the right trigger-pos is sent in command 18 |
435 | NaviData_Out1Trigger.Longitude = NaviData.CurrentPosition.Longitude; |
436 | NaviData_Out1Trigger.Longitude = NaviData.CurrentPosition.Longitude; |
436 | NaviData_Out1Trigger.Latitude = NaviData.CurrentPosition.Latitude; |
437 | NaviData_Out1Trigger.Latitude = NaviData.CurrentPosition.Latitude; |
437 | } |
438 | } |
438 | FC_WP_EventChannel_Processed = 1; |
439 | FC_WP_EventChannel_Processed = 1; |
439 | //DebugOut.Analog[] = FC_WP_EventChannel; |
440 | //DebugOut.Analog[] = FC_WP_EventChannel; |
440 | // ++++++++++++++++++++++++++++++++++ |
441 | // ++++++++++++++++++++++++++++++++++ |
441 | // Waypoint event +++++++++++++++++++ |
442 | // Waypoint event +++++++++++++++++++ |
442 | // ++++++++++++++++++++++++++++++++++ |
443 | // ++++++++++++++++++++++++++++++++++ |
443 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_ONCE, &tmp)) |
444 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_ONCE, &tmp)) |
444 | { |
445 | { |
445 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
446 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
446 | NCParams_ClearValue(NCPARAMS_WP_EVENT_ONCE); |
447 | NCParams_ClearValue(NCPARAMS_WP_EVENT_ONCE); |
447 | NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
448 | NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
448 | } |
449 | } |
449 | else |
450 | else |
450 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_FOREVER, &tmp)) |
451 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_FOREVER, &tmp)) |
451 | { |
452 | { |
452 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
453 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
453 | if(tmp == 0) NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
454 | if(tmp == 0) NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
454 | } |
455 | } |
455 | else ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
456 | else ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
456 | // FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
457 | // FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
457 | // ++++++++++++++++++++++++++++++++++ |
458 | // ++++++++++++++++++++++++++++++++++ |
458 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
459 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
459 | { |
460 | { |
460 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
461 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
461 | } |
462 | } |
462 | else |
463 | else |
463 | { |
464 | { |
464 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
465 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
465 | } |
466 | } |
466 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
467 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
467 | { |
468 | { |
468 | ToFlightCtrl.Param.sInt[5] = tmp; |
469 | ToFlightCtrl.Param.sInt[5] = tmp; |
469 | } |
470 | } |
470 | else |
471 | else |
471 | { |
472 | { |
472 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
473 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
473 | } |
474 | } |
474 | //DebugOut.Analog[] = ToFlightCtrl.Param.Byte[8]; |
475 | //DebugOut.Analog[] = ToFlightCtrl.Param.Byte[8]; |
475 | break; |
476 | break; |
476 | case SPI_NCCMD_HOTT_INFO: |
477 | case SPI_NCCMD_HOTT_INFO: |
477 | if(NewWPL_Name) hott_index = 100; |
478 | if(NewWPL_Name) hott_index = 100; |
478 | switch(hott_index++) |
479 | switch(hott_index++) |
479 | { |
480 | { |
480 | case 0: |
481 | case 0: |
481 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
482 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
482 | //53.28 5788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
483 | //53.28 5788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
483 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
484 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
484 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
485 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
485 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
486 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
486 | //----------------------------- |
487 | //----------------------------- |
487 | ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
488 | ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
488 | i1 = GPSData.Speed_Ground; // in cm/sec |
489 | i1 = GPSData.Speed_Ground; // in cm/sec |
489 | i1 *= 36; |
490 | i1 *= 36; |
490 | i1 /= 1000; |
491 | i1 /= 1000; |
491 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
492 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
492 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
493 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
493 | //----------------------------- |
494 | //----------------------------- |
494 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
495 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
495 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
496 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
496 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
497 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
497 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
498 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
498 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
499 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
499 | i1 *= 100; |
500 | i1 *= 100; |
500 | // Minuten |
501 | // Minuten |
501 | i2 *= 6; |
502 | i2 *= 6; |
502 | i2 /= 10; |
503 | i2 /= 10; |
503 | i1 += i2 / 100000; |
504 | i1 += i2 / 100000; |
504 | i2 = i2 % 100000; |
505 | i2 = i2 % 100000; |
505 | i2 /= 10; |
506 | i2 /= 10; |
506 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
507 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
507 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
508 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
508 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
509 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
509 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
510 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
510 | break; |
511 | break; |
511 | case 1: |
512 | case 1: |
512 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
513 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
513 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
514 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
514 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
515 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
515 | //----------------------------- |
516 | //----------------------------- |
516 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
517 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
517 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
518 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
518 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
519 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
519 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
520 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
520 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
521 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
521 | i1 *= 100; |
522 | i1 *= 100; |
522 | // Minuten |
523 | // Minuten |
523 | i2 *= 6; |
524 | i2 *= 6; |
524 | i2 /= 10; |
525 | i2 /= 10; |
525 | i1 += i2 / 100000; |
526 | i1 += i2 / 100000; |
526 | i2 = i2 % 100000; |
527 | i2 = i2 % 100000; |
527 | i2 /= 10; |
528 | i2 /= 10; |
528 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
529 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
529 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
530 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
530 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
531 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
531 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
532 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
532 | //----------------------------- |
533 | //----------------------------- |
533 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
534 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
534 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
535 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
535 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
536 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
536 | break; |
537 | break; |
537 | case 2: |
538 | case 2: |
538 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
539 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
539 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
540 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
540 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
541 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
541 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
542 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
542 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
543 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
543 | break; |
544 | break; |
544 | case 3: |
545 | case 3: |
545 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1; |
546 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1; |
546 | ToFlightCtrl.Param.Byte[0] = 0; // index |
547 | ToFlightCtrl.Param.Byte[0] = 0; // index |
547 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
548 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
548 | //JetiExData[14].Value = 53 * 0x10000 + 23467; |
549 | //JetiExData[14].Value = 53 * 0x10000 + 23467; |
549 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40; |
550 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40; |
550 | else ToFlightCtrl.Param.Byte[5] = 0x00; |
551 | else ToFlightCtrl.Param.Byte[5] = 0x00; |
551 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L; |
552 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L; |
552 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
553 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
553 | i2 *= 6; |
554 | i2 *= 6; |
554 | i2 /= 1000; |
555 | i2 /= 1000; |
555 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
556 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
556 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
557 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
557 | break; |
558 | break; |
558 | case 4: |
559 | case 4: |
559 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2; |
560 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2; |
560 | ToFlightCtrl.Param.Byte[0] = 0; // index |
561 | ToFlightCtrl.Param.Byte[0] = 0; // index |
561 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
562 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
562 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60; |
563 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60; |
563 | else ToFlightCtrl.Param.Byte[5] = 0x20; |
564 | else ToFlightCtrl.Param.Byte[5] = 0x20; |
564 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L; |
565 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L; |
565 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
566 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
566 | i2 *= 6; |
567 | i2 *= 6; |
567 | i2 /= 1000; |
568 | i2 /= 1000; |
568 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
569 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
569 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
570 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
570 | hott_index = 0; |
571 | hott_index = 0; |
571 | break; |
572 | break; |
572 | 573 | ||
573 | case 100: |
574 | case 100: |
574 | ToFlightCtrl.Param.Byte[11] = HOTT_WPL_NAME; |
575 | ToFlightCtrl.Param.Byte[11] = HOTT_WPL_NAME; |
575 | ToFlightCtrl.Param.Byte[0] = 0; // index |
576 | ToFlightCtrl.Param.Byte[0] = 0; // index |
576 | ToFlightCtrl.Param.Byte[2] = WPL_Store.Name[0]; |
577 | ToFlightCtrl.Param.Byte[2] = WPL_Store.Name[0]; |
577 | ToFlightCtrl.Param.Byte[3] = WPL_Store.Name[1]; |
578 | ToFlightCtrl.Param.Byte[3] = WPL_Store.Name[1]; |
578 | ToFlightCtrl.Param.Byte[4] = WPL_Store.Name[2]; |
579 | ToFlightCtrl.Param.Byte[4] = WPL_Store.Name[2]; |
579 | ToFlightCtrl.Param.Byte[5] = WPL_Store.Name[3]; |
580 | ToFlightCtrl.Param.Byte[5] = WPL_Store.Name[3]; |
580 | ToFlightCtrl.Param.Byte[6] = WPL_Store.Name[4]; |
581 | ToFlightCtrl.Param.Byte[6] = WPL_Store.Name[4]; |
581 | ToFlightCtrl.Param.Byte[7] = WPL_Store.Name[5]; |
582 | ToFlightCtrl.Param.Byte[7] = WPL_Store.Name[5]; |
582 | ToFlightCtrl.Param.Byte[8] = WPL_Store.Name[6]; |
583 | ToFlightCtrl.Param.Byte[8] = WPL_Store.Name[6]; |
583 | ToFlightCtrl.Param.Byte[9] = WPL_Store.Name[7]; |
584 | ToFlightCtrl.Param.Byte[9] = WPL_Store.Name[7]; |
584 | ToFlightCtrl.Param.Byte[10]= WPL_Store.Name[8]; |
585 | ToFlightCtrl.Param.Byte[10]= WPL_Store.Name[8]; |
585 | ToFlightCtrl.Param.Byte[1] = 9; // how many |
586 | ToFlightCtrl.Param.Byte[1] = 9; // how many |
586 | NewWPL_Name = 0; |
587 | NewWPL_Name = 0; |
587 | hott_index = 0; |
588 | hott_index = 0; |
588 | break; |
589 | break; |
589 | default: |
590 | default: |
590 | ToFlightCtrl.Param.Byte[0] = 255; |
591 | ToFlightCtrl.Param.Byte[0] = 255; |
591 | hott_index = 0; |
592 | hott_index = 0; |
592 | break; |
593 | break; |
593 | } |
594 | } |
594 | break; |
595 | break; |
595 | default: |
596 | default: |
596 | break; |
597 | break; |
597 | // 0 = 0,1 |
598 | // 0 = 0,1 |
598 | // 1 = 2,3 |
599 | // 1 = 2,3 |
599 | // 2 = 4,5 |
600 | // 2 = 4,5 |
600 | // 3 = 6,7 |
601 | // 3 = 6,7 |
601 | // 4 = 8,9 |
602 | // 4 = 8,9 |
602 | // 5 = 10,11 |
603 | // 5 = 10,11 |
603 | } |
604 | } |
604 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
605 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
605 | switch(FromFlightCtrl.Command) |
606 | switch(FromFlightCtrl.Command) |
606 | { |
607 | { |
607 | case SPI_FCCMD_USER: |
608 | case SPI_FCCMD_USER: |
608 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
609 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
609 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
610 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
610 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
611 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
611 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
612 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
612 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
613 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
613 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
614 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
614 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
615 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
615 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
616 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
616 | FC.RealStatusFlags = FromFlightCtrl.Param.Byte[8]; |
617 | FC.RealStatusFlags = FromFlightCtrl.Param.Byte[8]; |
617 | if(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN) SimulationFlags = 0; // stop the simulation if the motors would really start |
618 | if(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN) SimulationFlags = 0; // stop the simulation if the motors would really start |
618 | 619 | ||
619 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
620 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
620 | { |
621 | { |
621 | if(ClearFCStatusFlags) |
622 | if(ClearFCStatusFlags) |
622 | { |
623 | { |
623 | FC.StatusFlags = 0; |
624 | FC.StatusFlags = 0; |
624 | ClearFCStatusFlags = 0; |
625 | ClearFCStatusFlags = 0; |
625 | } |
626 | } |
626 | } |
627 | } |
627 | FC.StatusFlags |= FC.RealStatusFlags; |
628 | FC.StatusFlags |= FC.RealStatusFlags; |
628 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
629 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
629 | { |
630 | { |
630 | HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
631 | HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
631 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
632 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
632 | Compass_Init(); |
633 | Compass_Init(); |
633 | FCCalibActive = 10; |
634 | FCCalibActive = 10; |
634 | FC_is_Calibrated = 0; |
635 | FC_is_Calibrated = 0; |
635 | } |
636 | } |
636 | else |
637 | else |
637 | { |
638 | { |
638 | if(FCCalibActive) |
639 | if(FCCalibActive) |
639 | { |
640 | { |
640 | if(--FCCalibActive == 0) |
641 | if(--FCCalibActive == 0) |
641 | { |
642 | { |
642 | FC_is_Calibrated = 1; |
643 | FC_is_Calibrated = 1; |
643 | Compass_Check(); |
644 | Compass_Check(); |
644 | } |
645 | } |
645 | } |
646 | } |
646 | } |
647 | } |
647 | if(FC.StatusFlags & FC_STATUS_START) |
648 | if(FC.StatusFlags & FC_STATUS_START) |
648 | { |
649 | { |
649 | if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
650 | if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
650 | else HeadFreeStartAngle = GyroCompassCorrected; |
651 | else HeadFreeStartAngle = GyroCompassCorrected; |
651 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
652 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
652 | } |
653 | } |
653 | 654 | ||
654 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
655 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
655 | { |
656 | { |
656 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
657 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
657 | { |
658 | { |
658 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
659 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
659 | { |
660 | { |
660 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
661 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
661 | } |
662 | } |
662 | else // Ansonsten die aktuelle Richtung übernehmen |
663 | else // Ansonsten die aktuelle Richtung übernehmen |
663 | HeadFreeStartAngle = GyroCompassCorrected; // in 0.1° |
664 | HeadFreeStartAngle = GyroCompassCorrected; // in 0.1° |
664 | } |
665 | } |
665 | } |
666 | } |
666 | NaviData.FCStatusFlags = FC.StatusFlags; |
667 | NaviData.FCStatusFlags = FC.StatusFlags; |
667 | if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY; |
668 | if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY; |
668 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[9]; |
669 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[9]; |
669 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
670 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
670 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
671 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
671 | else |
672 | else |
672 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
673 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
673 | 674 | ||
674 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
675 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
675 | else |
676 | else |
676 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
677 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
677 | //DebugOut.Analog[] = (NaviData.FCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE); |
678 | //DebugOut.Analog[] = (NaviData.FCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE); |
678 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
679 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
679 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
680 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
680 | FC.BAT_Voltage = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
681 | FC.BAT_Voltage = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
681 | DebugOut.Analog[7] = FC.BAT_Voltage; |
682 | DebugOut.Analog[7] = FC.BAT_Voltage; |
682 | DebugOut.Analog[5] = FC.StatusFlags; |
683 | DebugOut.Analog[5] = FC.StatusFlags; |
683 | NaviData.UBat = (u8) FC.BAT_Voltage; // Achtung: die (u8) NaviData.UBat kann überlaufen -> das KopterTool müsste dann 25,5V drauf rechnen |
684 | NaviData.UBat = (u8) FC.BAT_Voltage; // Achtung: die (u8) NaviData.UBat kann überlaufen -> das KopterTool müsste dann 25,5V drauf rechnen |
684 | break; |
685 | break; |
685 | case SPI_FCCMD_BL_ACCU: |
686 | case SPI_FCCMD_BL_ACCU: |
686 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
687 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
687 | DebugOut.Analog[8] = FC.BAT_Current; |
688 | DebugOut.Analog[8] = FC.BAT_Current; |
688 | if(AmountOfMotors < FromFlightCtrl.Param.Byte[2]+1) AmountOfMotors = FromFlightCtrl.Param.Byte[2]+1; |
689 | if(AmountOfMotors < FromFlightCtrl.Param.Byte[2]+1) AmountOfMotors = FromFlightCtrl.Param.Byte[2]+1; |
689 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[3]; |
690 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[3]; |
690 | if(BL_MinOfMaxPWM < Logging_BL_MinOfMaxPWM) Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until logged |
691 | if(BL_MinOfMaxPWM < Logging_BL_MinOfMaxPWM) Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until logged |
691 | if(BL_MinOfMaxPWM < ErrorCheck_BL_MinOfMaxPWM) ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until Error processed |
692 | if(BL_MinOfMaxPWM < ErrorCheck_BL_MinOfMaxPWM) ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until Error processed |
692 | Parameter.NaviGpsModeControl = FromFlightCtrl.Param.Byte[4]; |
693 | Parameter.NaviGpsModeControl = FromFlightCtrl.Param.Byte[4]; |
693 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[5]; |
694 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[5]; |
694 | //0x40 |
695 | //0x40 |
695 | //0x20 |
696 | //0x20 |
696 | //0x10 |
697 | //0x10 |
697 | if(FromFlightCtrl.Param.Byte[2] & 0x80) // this Flag marks a changed Out1 |
698 | if(FromFlightCtrl.Param.Byte[2] & 0x80) // this Flag marks a changed Out1 |
698 | { |
699 | { |
699 | Out1TriggerUpdateNewData = 1; |
700 | Out1TriggerUpdateNewData = 1; |
700 | if(!Out1TriggerUpdateBlocked) |
701 | if(!Out1TriggerUpdateBlocked) |
701 | { |
702 | { |
702 | NaviData_Out1Trigger.Longitude = NaviData.CurrentPosition.Longitude; |
703 | NaviData_Out1Trigger.Longitude = NaviData.CurrentPosition.Longitude; |
703 | NaviData_Out1Trigger.Latitude = NaviData.CurrentPosition.Latitude; |
704 | NaviData_Out1Trigger.Latitude = NaviData.CurrentPosition.Latitude; |
704 | } |
705 | } |
705 | Out1TriggerUpdateBlocked = 0; |
706 | Out1TriggerUpdateBlocked = 0; |
706 | } |
707 | } |
707 | if(Out1TriggerUpdateBlocked) Out1TriggerUpdateBlocked--; |
708 | if(Out1TriggerUpdateBlocked) Out1TriggerUpdateBlocked--; |
708 | index = FromFlightCtrl.Param.Byte[2] & 0x0f; //MAX_MOTORS |
709 | index = FromFlightCtrl.Param.Byte[2] & 0x0f; //MAX_MOTORS |
709 | Motor[index].NotReadyCnt = FromFlightCtrl.Param.Byte[6]; |
710 | Motor[index].NotReadyCnt = FromFlightCtrl.Param.Byte[6]; |
710 | Motor_Version[index] = FromFlightCtrl.Param.Byte[7]; |
711 | Motor_Version[index] = FromFlightCtrl.Param.Byte[7]; |
711 | Motor[index].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
712 | Motor[index].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
712 | Motor[index].State = FromFlightCtrl.Param.Byte[9]; |
713 | Motor[index].State = FromFlightCtrl.Param.Byte[9]; |
713 | Motor[index].Temperature = FromFlightCtrl.Param.Byte[10]; |
714 | Motor[index].Temperature = FromFlightCtrl.Param.Byte[10]; |
714 | Motor[index].Current = FromFlightCtrl.Param.Byte[11]; |
715 | Motor[index].Current = FromFlightCtrl.Param.Byte[11]; |
715 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
716 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
716 | { |
717 | { |
717 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
718 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
718 | } |
719 | } |
719 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.Current = FC.BAT_Current; |
720 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.Current = FC.BAT_Current; |
720 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
721 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
721 | break; |
722 | break; |
722 | case SPI_FCCMD_PARAMETER1: |
723 | case SPI_FCCMD_PARAMETER1: |
723 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[0]; |
724 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[0]; |
724 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
725 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
725 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
726 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
726 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
727 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
727 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
728 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
728 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
729 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
729 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
730 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
730 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
731 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
731 | // CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
732 | // CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
732 | Parameter.NaviMaxFlyingRange = FromFlightCtrl.Param.Byte[8]; |
733 | Parameter.NaviMaxFlyingRange = FromFlightCtrl.Param.Byte[8]; |
733 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
734 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
734 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
735 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
735 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
736 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
736 | break; |
737 | break; |
737 | case SPI_FCCMD_PARAMETER2: |
738 | case SPI_FCCMD_PARAMETER2: |
738 | CHK_POTI_MM(FC.AutoPhotoDistance,FromFlightCtrl.Param.Byte[0],0,255); |
739 | CHK_POTI_MM(FC.AutoPhotoDistance,FromFlightCtrl.Param.Byte[0],0,255); |
739 | if(FromFlightCtrl.Param.Byte[1]) |
740 | if(FromFlightCtrl.Param.Byte[1]) |
740 | { |
741 | { |
741 | FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared in the SD-Logging |
742 | FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared in the SD-Logging |
742 | NaviData_Flags.SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared after the Uart-Trasmitting |
743 | NaviData_Flags.SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared after the Uart-Trasmitting |
743 | } |
744 | } |
744 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
745 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
745 | Parameter.FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4]; |
746 | Parameter.FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4]; |
746 | if(FromFlightCtrl.Param.Byte[5]) FromFC_LoadWP_List = FromFlightCtrl.Param.Byte[5]; |
747 | if(FromFlightCtrl.Param.Byte[5]) FromFC_LoadWP_List = FromFlightCtrl.Param.Byte[5]; |
747 | if(FromFlightCtrl.Param.Byte[6]) FromFC_Load_SinglePoint = FromFlightCtrl.Param.Byte[6]; |
748 | if(FromFlightCtrl.Param.Byte[6]) FromFC_Load_SinglePoint = FromFlightCtrl.Param.Byte[6]; |
748 | if(FromFlightCtrl.Param.Byte[7]) FromFC_Save_SinglePoint = FromFlightCtrl.Param.Byte[7]; |
749 | if(FromFlightCtrl.Param.Byte[7]) FromFC_Save_SinglePoint = FromFlightCtrl.Param.Byte[7]; |
749 | CompassSetpoint = FromFlightCtrl.Param.sInt[4] * 10; // 8 & 9 |
750 | CompassSetpoint = FromFlightCtrl.Param.sInt[4] * 10; // 8 & 9 |
750 | CompassSetpointCorrected = (3600 + CompassSetpoint + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
751 | CompassSetpointCorrected = (3600 + CompassSetpoint + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
751 | FC.StatusFlags3 = FromFlightCtrl.Param.Byte[10]; |
752 | FC.StatusFlags3 = FromFlightCtrl.Param.Byte[10]; |
752 | Parameter.SingleWpSpeed = FromFlightCtrl.Param.Byte[11]; |
753 | Parameter.SingleWpSpeed = FromFlightCtrl.Param.Byte[11]; |
753 | break; |
754 | break; |
754 | case SPI_FCCMD_STICK: |
755 | case SPI_FCCMD_STICK: |
755 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
756 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
756 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
757 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
757 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
758 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
758 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
759 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
759 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
760 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
760 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
761 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
761 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
762 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
762 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
763 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
763 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
764 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
764 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
765 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
765 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
766 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
766 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
767 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
767 | CHK_POTI_MM(WaypointAcceleration,WaypointAccelerationSetting,0,255); // that could be a Poti-Value |
768 | CHK_POTI_MM(WaypointAcceleration,WaypointAccelerationSetting,0,255); // that could be a Poti-Value |
768 | break; |
769 | break; |
769 | 770 | ||
770 | case SPI_FCCMD_MISC: |
771 | case SPI_FCCMD_MISC: |
771 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
772 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
772 | { // put only new CompassCalState into queue to send via I2C |
773 | { // put only new CompassCalState into queue to send via I2C |
773 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
774 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
774 | { |
775 | { |
775 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
776 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
776 | Compass_SetCalState(CompassCalState); |
777 | Compass_SetCalState(CompassCalState); |
777 | } |
778 | } |
778 | // else CompassCalState = 0; |
779 | // else CompassCalState = 0; |
779 | } |
780 | } |
780 | HoverGas = FromFlightCtrl.Param.Byte[1]; |
781 | HoverGas = FromFlightCtrl.Param.Byte[1]; |
781 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
782 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
782 | FC.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
783 | FC.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
783 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
784 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
784 | FC.Error[0] |= FromFlightCtrl.Param.Byte[6]; |
785 | FC.Error[0] |= FromFlightCtrl.Param.Byte[6]; |
785 | FC.Error[1] |= FromFlightCtrl.Param.Byte[7]; |
786 | FC.Error[1] |= FromFlightCtrl.Param.Byte[7]; |
786 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
787 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
787 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
788 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
788 | if(FC.Error[0] || FC.Error[1] /* || FC.Error[2] || FC.Error[3] || FC.Error[4]*/) DebugOut.StatusRed |= AMPEL_FC; |
789 | if(FC.Error[0] || FC.Error[1] /* || FC.Error[2] || FC.Error[3] || FC.Error[4]*/) DebugOut.StatusRed |= AMPEL_FC; |
789 | else DebugOut.StatusRed &= ~AMPEL_FC; |
790 | else DebugOut.StatusRed &= ~AMPEL_FC; |
790 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[8]; |
791 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[8]; |
791 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
792 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
792 | if(FC.RC_Quality > 160) NaviData.RC_Quality = 200; else NaviData.RC_Quality = FC.RC_Quality; |
793 | if(FC.RC_Quality > 160) NaviData.RC_Quality = 200; else NaviData.RC_Quality = FC.RC_Quality; |
793 | NC_Wait_for_LED = FromFlightCtrl.Param.Byte[10]; |
794 | NC_Wait_for_LED = FromFlightCtrl.Param.Byte[10]; |
794 | //DebugOut.Analog[] = NC_Wait_for_LED; |
795 | //DebugOut.Analog[] = NC_Wait_for_LED; |
795 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
796 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
796 | if(LoggingGasCnt == 0) LoggingGasFilter = 0; |
797 | if(LoggingGasCnt == 0) LoggingGasFilter = 0; |
797 | LoggingGasFilter += (u32) FromFlightCtrl.Param.Byte[11]; |
798 | LoggingGasFilter += (u32) FromFlightCtrl.Param.Byte[11]; |
798 | LoggingGasCnt++; |
799 | LoggingGasCnt++; |
799 | break; |
800 | break; |
800 | 801 | ||
801 | case SPI_FCCMD_VERSION: // slow! |
802 | case SPI_FCCMD_VERSION: // slow! |
802 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
803 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
803 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
804 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
804 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
805 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
805 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
806 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
806 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
807 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
807 | Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[5]; |
808 | Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[5]; |
808 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[6]; |
809 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[6]; |
809 | CHK_POTI_MM(Parameter.AutoPhotoAltitudes,FromFlightCtrl.Param.Byte[7],0,255); |
810 | CHK_POTI_MM(Parameter.AutoPhotoAltitudes,FromFlightCtrl.Param.Byte[7],0,255); |
810 | UART_VersionInfo.BL_Firmware = FromFlightCtrl.Param.Byte[8]; |
811 | UART_VersionInfo.BL_Firmware = FromFlightCtrl.Param.Byte[8]; |
811 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
812 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
812 | FlugMinutenGesamt = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
813 | FlugMinutenGesamt = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
813 | break; |
814 | break; |
814 | case SPI_FCCMD_NEUTRAL: // slow! |
815 | case SPI_FCCMD_NEUTRAL: // slow! |
815 | FC.AdNeutralNick = FromFlightCtrl.Param.Int[0]; |
816 | FC.AdNeutralNick = FromFlightCtrl.Param.Int[0]; |
816 | FC.AdNeutralRoll = FromFlightCtrl.Param.Int[1]; |
817 | FC.AdNeutralRoll = FromFlightCtrl.Param.Int[1]; |
817 | FC.AdNeutralYaw = FromFlightCtrl.Param.Int[2]; |
818 | FC.AdNeutralYaw = FromFlightCtrl.Param.Int[2]; |
818 | Parameter.Driftkomp = FromFlightCtrl.Param.Byte[6]; |
819 | Parameter.Driftkomp = FromFlightCtrl.Param.Byte[6]; |
819 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[7]; |
820 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[7]; |
820 | Parameter.ReceiverType = FromFlightCtrl.Param.Byte[8]; |
821 | Parameter.ReceiverType = FromFlightCtrl.Param.Byte[8]; |
821 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[9],0,255); |
822 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[9],0,255); |
822 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[10],0,255); |
823 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[10],0,255); |
823 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[11],0,255); |
824 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[11],0,255); |
824 | break; |
825 | break; |
825 | case SPI_FCCMD_SLOW2: // slow! |
826 | case SPI_FCCMD_SLOW2: // slow! |
826 | FC.BoatNeutralNick = FromFlightCtrl.Param.Int[0]; // 0 & 1 |
827 | FC.BoatNeutralNick = FromFlightCtrl.Param.Int[0]; // 0 & 1 |
827 | FC.BoatNeutralRoll = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
828 | FC.BoatNeutralRoll = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
828 | FC.BoatNeutralYaw = FromFlightCtrl.Param.Int[2]; // 4 & 5 |
829 | FC.BoatNeutralYaw = FromFlightCtrl.Param.Int[2]; // 4 & 5 |
829 | Parameter.CamOrientation = FromFlightCtrl.Param.Byte[6]; |
830 | Parameter.CamOrientation = FromFlightCtrl.Param.Byte[6]; |
830 | if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188) |
831 | if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188) |
831 | { |
832 | { |
832 | FC.FromFC_DisableDeclination = 1; |
833 | FC.FromFC_DisableDeclination = 1; |
833 | FC.FromFC_CompassOffset = 10 * (s8) (FromFlightCtrl.Param.Byte[7] - 128); |
834 | FC.FromFC_CompassOffset = 10 * (s8) (FromFlightCtrl.Param.Byte[7] - 128); |
834 | GeoMagDec = 0; |
835 | GeoMagDec = 0; |
835 | } |
836 | } |
836 | else |
837 | else |
837 | { |
838 | { |
838 | FC.FromFC_DisableDeclination = 0; |
839 | FC.FromFC_DisableDeclination = 0; |
839 | FC.FromFC_CompassOffset = 10 * FromFlightCtrl.Param.sByte[7]; |
840 | FC.FromFC_CompassOffset = 10 * FromFlightCtrl.Param.sByte[7]; |
840 | } |
841 | } |
841 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
842 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
842 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
843 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
843 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
844 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
844 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
845 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
845 | break; |
846 | break; |
846 | case SPI_FCCMD_SLOW3: // slow! |
847 | case SPI_FCCMD_SLOW3: // slow! |
847 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[0]; |
848 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[0]; |
848 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[1]; |
849 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[1]; |
849 | Parameter.DescendRange = FromFlightCtrl.Param.Byte[2]; |
850 | Parameter.DescendRange = FromFlightCtrl.Param.Byte[2]; |
850 | Parameter.MaximumAltitude = FromFlightCtrl.Param.Byte[3]; |
851 | Parameter.MaximumAltitude = FromFlightCtrl.Param.Byte[3]; |
851 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[4]; |
852 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[4]; |
852 | Parameter.HomeYawMode = ((ServoParams.CompInvert & 0x18) >> 3); |
853 | Parameter.HomeYawMode = ((ServoParams.CompInvert & 0x18) >> 3); |
853 | NaviData_Home.LipoCellCount = FromFlightCtrl.Param.Byte[5]; |
854 | NaviData_Home.LipoCellCount = FromFlightCtrl.Param.Byte[5]; |
854 | NaviData_Volatile.ShutterCounter = FromFlightCtrl.Param.Int[3]; // 6 & 7 |
855 | NaviData_Volatile.ShutterCounter = FromFlightCtrl.Param.Int[3]; // 6 & 7 |
- | 856 | LowVoltageLandingActive = FromFlightCtrl.Param.Byte[8]; |
|
855 | // DebugOut.Analog[] = NaviData_Volatile.ShutterCounter; |
857 | // DebugOut.Analog[] = NaviData_Volatile.ShutterCounter; |
856 | // 8 |
858 | // 8 |
857 | // 9 |
859 | // 9 |
858 | // 10 |
860 | // 10 |
859 | // 11 |
861 | // 11 |
860 | break; |
862 | break; |
861 | 863 | ||
862 | default: |
864 | default: |
863 | break; |
865 | break; |
864 | } |
866 | } |
865 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
867 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
866 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
868 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
867 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
869 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
868 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
870 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
869 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
871 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
870 | // every time we got new data from the FC via SPI call the navigation routine |
872 | // every time we got new data from the FC via SPI call the navigation routine |
871 | // and update GPSStick that are returned to FC |
873 | // and update GPSStick that are returned to FC |
872 | SPI_RxBuffer_Request = 0; |
874 | SPI_RxBuffer_Request = 0; |
873 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
875 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
874 | ClearFCStatusFlags = 1; |
876 | ClearFCStatusFlags = 1; |
875 | if(counter) |
877 | if(counter) |
876 | { |
878 | { |
877 | counter--; // count down to enable servo |
879 | counter--; // count down to enable servo |
878 | if(!counter) TIMER2_Init(); // enable Servo Output |
880 | if(!counter) TIMER2_Init(); // enable Servo Output |
879 | } |
881 | } |
880 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
882 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
881 | 883 | ||
882 | } // EOF if(SPI_RxBuffer_Request) |
884 | } // EOF if(SPI_RxBuffer_Request) |
883 | else // no new SPI data |
885 | else // no new SPI data |
884 | { |
886 | { |
885 | if(CheckDelay(timeout) && (counter == 0)) |
887 | if(CheckDelay(timeout) && (counter == 0)) |
886 | { |
888 | { |
887 | TIMER2_Deinit(); // disable Servo Output |
889 | TIMER2_Deinit(); // disable Servo Output |
888 | counter = 50; // reset counter for enabling Servo Output |
890 | counter = 50; // reset counter for enabling Servo Output |
889 | } |
891 | } |
890 | } |
892 | } |
891 | } |
893 | } |
892 | 894 | ||
893 | //------------------------------------------------------ |
895 | //------------------------------------------------------ |
894 | void SPI0_GetFlightCtrlVersion(void) |
896 | void SPI0_GetFlightCtrlVersion(void) |
895 | { |
897 | { |
896 | u32 timeout; |
898 | u32 timeout; |
897 | u8 repeat; |
899 | u8 repeat; |
898 | u8 msg[64]; |
900 | u8 msg[64]; |
899 | 901 | ||
900 | UART1_PutString("\r\n Looking for FlightControl"); |
902 | UART1_PutString("\r\n Looking for FlightControl"); |
901 | FC_Version.Major = 0xFF; |
903 | FC_Version.Major = 0xFF; |
902 | FC_Version.Minor = 0xFF; |
904 | FC_Version.Minor = 0xFF; |
903 | FC_Version.Patch = 0xFF; |
905 | FC_Version.Patch = 0xFF; |
904 | FC_Version.Compatible = 0xFF; |
906 | FC_Version.Compatible = 0xFF; |
905 | 907 | ||
906 | // polling FC version info |
908 | // polling FC version info |
907 | repeat = 0; |
909 | repeat = 0; |
908 | do |
910 | do |
909 | { |
911 | { |
910 | timeout = SetDelay(250); |
912 | timeout = SetDelay(250); |
911 | do |
913 | do |
912 | { |
914 | { |
913 | SPI0_UpdateBuffer(); |
915 | SPI0_UpdateBuffer(); |
914 | if (FC_Version.Major != 0xFF) break; |
916 | if (FC_Version.Major != 0xFF) break; |
915 | }while (!CheckDelay(timeout)); |
917 | }while (!CheckDelay(timeout)); |
916 | UART1_PutString("."); |
918 | UART1_PutString("."); |
917 | repeat++; |
919 | repeat++; |
918 | FCCalibActive = 1; |
920 | FCCalibActive = 1; |
919 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
921 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
920 | // if we got it |
922 | // if we got it |
921 | if (FC_Version.Major != 0xFF) |
923 | if (FC_Version.Major != 0xFF) |
922 | { |
924 | { |
923 | sprintf(msg, " FC V%d.%02d%c HW:%d.%d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10); |
925 | sprintf(msg, " FC V%d.%02d%c HW:%d.%d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10); |
924 | UART1_PutString(msg); |
926 | UART1_PutString(msg); |
925 | } |
927 | } |
926 | else UART1_PutString("\n\r not found!"); |
928 | else UART1_PutString("\n\r not found!"); |
927 | } |
929 | } |
928 | 930 | ||
929 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
931 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
930 | // + extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
932 | // + extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
931 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
933 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
932 | u16 BL3_Current(u8 who) // in 0,1A |
934 | u16 BL3_Current(u8 who) // in 0,1A |
933 | { |
935 | { |
934 | if(Motor[who].Current <= 200) return((u16) Motor[who].Current); |
936 | if(Motor[who].Current <= 200) return((u16) Motor[who].Current); |
935 | else |
937 | else |
936 | { |
938 | { |
937 | if(Motor_Version[who] & MOTOR_STATE_BL30) return(200 + 10 * (u16) (Motor[who].Current - 200)); |
939 | if(Motor_Version[who] & MOTOR_STATE_BL30) return(200 + 10 * (u16) (Motor[who].Current - 200)); |
938 | else return((u16) Motor[who].Current); |
940 | else return((u16) Motor[who].Current); |
939 | } |
941 | } |
940 | } |
942 | } |
941 | 943 | ||
942 | 944 |