Rev 598 | Rev 611 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 598 | Rev 605 | ||
---|---|---|---|
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 | 86 | ||
87 | // tx packet buffer |
87 | // tx packet buffer |
88 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
88 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
89 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
89 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
90 | volatile u8 SPI_TxBufferIndex = 0; |
90 | volatile u8 SPI_TxBufferIndex = 0; |
91 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
91 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
92 | 92 | ||
93 | // rx packet buffer |
93 | // rx packet buffer |
94 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
94 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
95 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
95 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
96 | volatile u8 SPI_RxBufferIndex = 0; |
96 | volatile u8 SPI_RxBufferIndex = 0; |
97 | volatile u8 SPI_RxBuffer_Request = 0; |
97 | volatile u8 SPI_RxBuffer_Request = 0; |
98 | #define SPI_COMMAND_INDEX 0 |
98 | #define SPI_COMMAND_INDEX 0 |
99 | 99 | ||
100 | s32 Kalman_K = 32; |
100 | s32 Kalman_K = 32; |
101 | s32 Kalman_MaxDrift = 5 * 16; |
101 | s32 Kalman_MaxDrift = 5 * 16; |
102 | s32 Kalman_MaxFusion = 64; |
102 | s32 Kalman_MaxFusion = 64; |
103 | s32 Kalman_Kompass = 32; |
103 | s32 Kalman_Kompass = 32; |
104 | s32 ToFcGpsZ = 0; |
104 | s32 ToFcGpsZ = 0; |
105 | u8 CompassCalState = 0; |
105 | u8 CompassCalState = 0; |
106 | 106 | ||
107 | 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 }; |
107 | 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 }; |
108 | u8 SPI_CommandCounter = 0; |
108 | u8 SPI_CommandCounter = 0; |
109 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
109 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
110 | s32 HeadFreeStartAngle = 0; // in 0,1° |
110 | s32 HeadFreeStartAngle = 0; // in 0,1° |
111 | s32 CompassDirectionAtMotorStart = 0; // in 0,1° |
111 | s32 CompassDirectionAtMotorStart = 0; // in 0,1° |
112 | 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 |
112 | 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 |
113 | u32 ToFC_AltitudeRate = 0; |
113 | u32 ToFC_AltitudeRate = 0; |
114 | s32 ToFC_AltitudeSetpoint = 0; |
114 | s32 ToFC_AltitudeSetpoint = 0; |
115 | u8 FromFC_VarioCharacter = ' '; |
115 | u8 FromFC_VarioCharacter = ' '; |
116 | s16 GPS_Aid_StickMultiplikator = 0; |
116 | s16 GPS_Aid_StickMultiplikator = 0; |
117 | u8 NC_GPS_ModeCharacter = ' '; |
117 | u8 NC_GPS_ModeCharacter = ' '; |
118 | u8 FCCalibActive = 0; |
118 | u8 FCCalibActive = 0; |
119 | u8 FC_is_Calibrated = 0; |
119 | u8 FC_is_Calibrated = 0; |
120 | Motor_t Motor[12]; |
120 | Motor_t Motor[MAX_MOTORS]; |
121 | u8 Motor_Version[12]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
121 | u8 Motor_Version[MAX_MOTORS]; // das kann nicht in die struct, weil der PC die Struktur bekommt |
122 | u8 NC_To_FC_Flags = 0; |
122 | u8 NC_To_FC_Flags = 0; |
123 | u8 BL_MinOfMaxPWM = 255; // indication if all BL-controllers run on full power |
123 | u8 BL_MinOfMaxPWM = 255; // indication if all BL-controllers run on full power |
124 | u8 Logging_BL_MinOfMaxPWM = 255; |
124 | u8 Logging_BL_MinOfMaxPWM = 255; |
125 | u8 ErrorCheck_BL_MinOfMaxPWM = 255; |
125 | u8 ErrorCheck_BL_MinOfMaxPWM = 255; |
126 | u32 FC_I2C_ErrorConter; |
126 | u32 FC_I2C_ErrorConter; |
127 | SPI_Version_t FC_Version; |
127 | SPI_Version_t FC_Version; |
128 | s16 POI_KameraNick = 0; |
128 | s16 POI_KameraNick = 0; |
129 | u8 NC_Wait_for_LED = 0; |
129 | u8 NC_Wait_for_LED = 0; |
130 | s16 GyroCompassCorrected = 0; // corrected with the magnetic declination |
130 | s16 GyroCompassCorrected = 0; // corrected with the magnetic declination |
131 | s16 CompassSetpointCorrected = 0; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
131 | s16 CompassSetpointCorrected = 0; // The compass setpoint that the FC tries to keep - corrected with the magnetic declination |
132 | s16 CompassSetpoint = 0; // in 0,1° |
132 | s16 CompassSetpoint = 0; // in 0,1° |
133 | s16 SimulatedDirection = 0; // only for flight simulation |
133 | s16 SimulatedDirection = 0; // only for flight simulation |
134 | u8 AmountOfMotors = 0; |
134 | u8 AmountOfMotors = 0; |
135 | u16 FlugMinutenGesamt; |
135 | u16 FlugMinutenGesamt; |
136 | u8 HoverGas = 0; |
136 | u8 HoverGas = 0; |
137 | //-------------------------------------------------------------- |
137 | //-------------------------------------------------------------- |
138 | void SSP0_IRQHandler(void) |
138 | void SSP0_IRQHandler(void) |
139 | { |
139 | { |
140 | static u8 rxchksum = 0; |
140 | static u8 rxchksum = 0; |
141 | u8 rxdata; |
141 | u8 rxdata; |
142 | 142 | ||
143 | #define SPI_SYNC1 0 |
143 | #define SPI_SYNC1 0 |
144 | #define SPI_SYNC2 1 |
144 | #define SPI_SYNC2 1 |
145 | #define SPI_DATA 2 |
145 | #define SPI_DATA 2 |
146 | static u8 SPI_State = SPI_SYNC1; |
146 | static u8 SPI_State = SPI_SYNC1; |
147 | //IENABLE; |
147 | //IENABLE; |
148 | 148 | ||
149 | // clear pending bits |
149 | // clear pending bits |
150 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
150 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
151 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
151 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
152 | 152 | ||
153 | // while RxFIFO not empty |
153 | // while RxFIFO not empty |
154 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
154 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
155 | { |
155 | { |
156 | rxdata = SSP0->DR; // catch the received byte |
156 | rxdata = SSP0->DR; // catch the received byte |
157 | // Fill TxFIFO while its not full or end of packet is reached |
157 | // Fill TxFIFO while its not full or end of packet is reached |
158 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
158 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
159 | { |
159 | { |
160 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
160 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
161 | { |
161 | { |
162 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
162 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
163 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
163 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
164 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
164 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
165 | SPI_TxBufferIndex++; // pointer to next byte |
165 | SPI_TxBufferIndex++; // pointer to next byte |
166 | } |
166 | } |
167 | else // end of packet is reached reset and copy data to tx buffer |
167 | else // end of packet is reached reset and copy data to tx buffer |
168 | { |
168 | { |
169 | SPI_TxBufferIndex = 0; // reset buffer index |
169 | SPI_TxBufferIndex = 0; // reset buffer index |
170 | ToFlightCtrl.Chksum = 0; // initialize checksum |
170 | ToFlightCtrl.Chksum = 0; // initialize checksum |
171 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
171 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
172 | BeepTime = 0; // reset local beeptime |
172 | BeepTime = 0; // reset local beeptime |
173 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
173 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
174 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
174 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
175 | } |
175 | } |
176 | } |
176 | } |
177 | switch (SPI_State) |
177 | switch (SPI_State) |
178 | { |
178 | { |
179 | case SPI_SYNC1: |
179 | case SPI_SYNC1: |
180 | SPI_RxBufferIndex = 0; // reset buffer index |
180 | SPI_RxBufferIndex = 0; // reset buffer index |
181 | rxchksum = rxdata; // init checksum |
181 | rxchksum = rxdata; // init checksum |
182 | if (rxdata == SPI_RXSYNCBYTE1) |
182 | if (rxdata == SPI_RXSYNCBYTE1) |
183 | { // 1st syncbyte ok |
183 | { // 1st syncbyte ok |
184 | SPI_State = SPI_SYNC2; // step to sync2 |
184 | SPI_State = SPI_SYNC2; // step to sync2 |
185 | } |
185 | } |
186 | break; |
186 | break; |
187 | case SPI_SYNC2: |
187 | case SPI_SYNC2: |
188 | if (rxdata == SPI_RXSYNCBYTE2) |
188 | if (rxdata == SPI_RXSYNCBYTE2) |
189 | { // 2nd Syncbyte ok |
189 | { // 2nd Syncbyte ok |
190 | rxchksum += rxdata; |
190 | rxchksum += rxdata; |
191 | SPI_State = SPI_DATA; |
191 | SPI_State = SPI_DATA; |
192 | } // 2nd Syncbyte does not match |
192 | } // 2nd Syncbyte does not match |
193 | else |
193 | else |
194 | { |
194 | { |
195 | SPI_State = SPI_SYNC1; //jump back to sync1 |
195 | SPI_State = SPI_SYNC1; //jump back to sync1 |
196 | } |
196 | } |
197 | break; |
197 | break; |
198 | case SPI_DATA: |
198 | case SPI_DATA: |
199 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
199 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
200 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
200 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
201 | { |
201 | { |
202 | if (rxdata == rxchksum) // verify checksum byte |
202 | if (rxdata == rxchksum) // verify checksum byte |
203 | { |
203 | { |
204 | // copy SPI_RxBuffer -> FromFlightCtrl |
204 | // copy SPI_RxBuffer -> FromFlightCtrl |
205 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
205 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
206 | { |
206 | { |
207 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
207 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
208 | SPI_RxBuffer_Request = 1; |
208 | SPI_RxBuffer_Request = 1; |
209 | } |
209 | } |
210 | // reset timeout counter on good packet |
210 | // reset timeout counter on good packet |
211 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
211 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
212 | DebugOut.Analog[13]++; |
212 | DebugOut.Analog[13]++; |
213 | } |
213 | } |
214 | else // bad checksum byte |
214 | else // bad checksum byte |
215 | { |
215 | { |
216 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
216 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
217 | } |
217 | } |
218 | SPI_State = SPI_SYNC1; // reset state |
218 | SPI_State = SPI_SYNC1; // reset state |
219 | } |
219 | } |
220 | else // end of packet not reached |
220 | else // end of packet not reached |
221 | { |
221 | { |
222 | rxchksum += rxdata; // update checksum |
222 | rxchksum += rxdata; // update checksum |
223 | } |
223 | } |
224 | break; |
224 | break; |
225 | default: |
225 | default: |
226 | SPI_State = SPI_SYNC1; |
226 | SPI_State = SPI_SYNC1; |
227 | break; |
227 | break; |
228 | } |
228 | } |
229 | } |
229 | } |
230 | 230 | ||
231 | // IDISABLE; |
231 | // IDISABLE; |
232 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
232 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
233 | } |
233 | } |
234 | 234 | ||
235 | //-------------------------------------------------------------- |
235 | //-------------------------------------------------------------- |
236 | void SPI0_Init(void) |
236 | void SPI0_Init(void) |
237 | { |
237 | { |
238 | GPIO_InitTypeDef GPIO_InitStructure; |
238 | GPIO_InitTypeDef GPIO_InitStructure; |
239 | SSP_InitTypeDef SSP_InitStructure; |
239 | SSP_InitTypeDef SSP_InitStructure; |
240 | 240 | ||
241 | UART1_PutString("\r\n SPI init..."); |
241 | UART1_PutString("\r\n SPI init..."); |
242 | 242 | ||
243 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
243 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
244 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
244 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
245 | 245 | ||
246 | GPIO_DeInit(GPIO2); |
246 | GPIO_DeInit(GPIO2); |
247 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
247 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
248 | GPIO_StructInit(&GPIO_InitStructure); |
248 | GPIO_StructInit(&GPIO_InitStructure); |
249 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
249 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
250 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
250 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
251 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
251 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
252 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
252 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
253 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
253 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
254 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
254 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
255 | 255 | ||
256 | // SSP0_MISO pin GPIO2.6 |
256 | // SSP0_MISO pin GPIO2.6 |
257 | GPIO_StructInit(&GPIO_InitStructure); |
257 | GPIO_StructInit(&GPIO_InitStructure); |
258 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
258 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
259 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
259 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
260 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
260 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
261 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
261 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
262 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
262 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
263 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
263 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
264 | 264 | ||
265 | SSP_DeInit(SSP0); |
265 | SSP_DeInit(SSP0); |
266 | SSP_StructInit(&SSP_InitStructure); |
266 | SSP_StructInit(&SSP_InitStructure); |
267 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
267 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
268 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
268 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
269 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
269 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
270 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
270 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
271 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
271 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
272 | SSP_InitStructure.SSP_ClockRate = 0; |
272 | SSP_InitStructure.SSP_ClockRate = 0; |
273 | 273 | ||
274 | SSP_Init(SSP0, &SSP_InitStructure); |
274 | SSP_Init(SSP0, &SSP_InitStructure); |
275 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
275 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
276 | SSP_Cmd(SSP0, ENABLE); |
276 | SSP_Cmd(SSP0, ENABLE); |
277 | // initialize the syncbytes in the tx buffer |
277 | // initialize the syncbytes in the tx buffer |
278 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
278 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
279 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
279 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
280 | // set the pointer to the checksum byte in the tx buffer |
280 | // set the pointer to the checksum byte in the tx buffer |
281 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
281 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
282 | 282 | ||
283 | ToFlightCtrl.GPSStick.Nick = 0; |
283 | ToFlightCtrl.GPSStick.Nick = 0; |
284 | ToFlightCtrl.GPSStick.Roll = 0; |
284 | ToFlightCtrl.GPSStick.Roll = 0; |
285 | // ToFlightCtrl.GPSStick.Yaw = 0; |
285 | // ToFlightCtrl.GPSStick.Yaw = 0; |
286 | 286 | ||
287 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
287 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
288 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
288 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
289 | 289 | ||
290 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
290 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
291 | 291 | ||
292 | UART1_PutString("ok"); |
292 | UART1_PutString("ok"); |
293 | } |
293 | } |
294 | 294 | ||
295 | 295 | ||
296 | //------------------------------------------------------ |
296 | //------------------------------------------------------ |
297 | void SPI0_UpdateBuffer(void) |
297 | void SPI0_UpdateBuffer(void) |
298 | { |
298 | { |
299 | static u32 timeout = 0; |
299 | static u32 timeout = 0; |
300 | static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0; |
300 | static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0; |
301 | static s16 last_wp_event = 0; |
301 | static s16 last_wp_event = 0; |
- | 302 | u8 index; |
|
302 | s16 tmp; |
303 | s16 tmp; |
303 | s32 i1,i2; |
304 | s32 i1,i2; |
304 | /* |
305 | /* |
305 | union |
306 | union |
306 | { |
307 | { |
307 | unsigned char Byte[4]; |
308 | unsigned char Byte[4]; |
308 | unsigned int Int[2]; |
309 | unsigned int Int[2]; |
309 | unsigned long Long; |
310 | unsigned long Long; |
310 | } Temp; |
311 | } Temp; |
311 | */ |
312 | */ |
312 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
313 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
313 | if(SPI_RxBuffer_Request) |
314 | if(SPI_RxBuffer_Request) |
314 | { |
315 | { |
315 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
316 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
316 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
317 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
317 | ToFlightCtrl.CompassHeading = Compass_Heading; |
318 | ToFlightCtrl.CompassHeading = Compass_Heading; |
318 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
319 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
319 | GyroCompassCorrected = (3600 + FromFlightCtrl.GyroHeading + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
320 | GyroCompassCorrected = (3600 + FromFlightCtrl.GyroHeading + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
320 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
321 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
321 | ToFlightCtrl.MagVecX = MagVector.X; |
322 | ToFlightCtrl.MagVecX = MagVector.X; |
322 | ToFlightCtrl.MagVecY = MagVector.Y; |
323 | ToFlightCtrl.MagVecY = MagVector.Y; |
323 | ToFlightCtrl.MagVecZ = MagVector.Z; |
324 | ToFlightCtrl.MagVecZ = MagVector.Z; |
324 | // ToFlightCtrl.NCStatus = 0; |
325 | // ToFlightCtrl.NCStatus = 0; |
325 | // cycle spi commands |
326 | // cycle spi commands |
326 | if(ErrorCode != last_error_code && enable_injecting) |
327 | if(ErrorCode != last_error_code && enable_injecting) |
327 | { |
328 | { |
328 | ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
329 | ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
329 | last_error_code = ErrorCode; |
330 | last_error_code = ErrorCode; |
330 | enable_injecting = 0; |
331 | enable_injecting = 0; |
331 | } |
332 | } |
332 | else |
333 | else |
333 | if(FC_WP_EventChannel != last_wp_event && enable_injecting) |
334 | if(FC_WP_EventChannel != last_wp_event && enable_injecting) |
334 | { |
335 | { |
335 | ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
336 | ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
336 | last_wp_event = FC_WP_EventChannel; |
337 | last_wp_event = FC_WP_EventChannel; |
337 | enable_injecting = 0; |
338 | enable_injecting = 0; |
338 | } |
339 | } |
339 | else |
340 | else |
340 | { |
341 | { |
341 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
342 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
342 | // restart command cycle at the end |
343 | // restart command cycle at the end |
343 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
344 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
344 | if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1; |
345 | if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1; |
345 | } |
346 | } |
346 | 347 | ||
347 | #define FLAG_GPS_AID 0x01 |
348 | #define FLAG_GPS_AID 0x01 |
348 | switch (ToFlightCtrl.Command) |
349 | switch (ToFlightCtrl.Command) |
349 | { |
350 | { |
350 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
351 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
351 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
352 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
352 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
353 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
353 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
354 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
354 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
355 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
355 | ToFlightCtrl.Param.Byte[4] = 0; // siehe bitcodiert unten |
356 | ToFlightCtrl.Param.Byte[4] = 0; // siehe bitcodiert unten |
356 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
357 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
357 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
358 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
358 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
359 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
359 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
360 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
360 | { |
361 | { |
361 | // 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 |
362 | // 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 |
362 | 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 |
363 | 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 |
363 | else CAM_Orientation.Azimuth = -1; |
364 | else CAM_Orientation.Azimuth = -1; |
364 | if(CAM_Orientation.UpdateMask & FORCE_AZIMUTH_ROTATION) ToFlightCtrl.Param.sByte[4] = 0x01; // allows Yawing without CareFree (Yawing at Coming Home) |
365 | if(CAM_Orientation.UpdateMask & FORCE_AZIMUTH_ROTATION) ToFlightCtrl.Param.sByte[4] = 0x01; // allows Yawing without CareFree (Yawing at Coming Home) |
365 | CAM_Orientation.UpdateMask &= ~(CAM_UPDATE_AZIMUTH | FORCE_AZIMUTH_ROTATION); |
366 | CAM_Orientation.UpdateMask &= ~(CAM_UPDATE_AZIMUTH | FORCE_AZIMUTH_ROTATION); |
366 | } |
367 | } |
367 | else |
368 | else |
368 | { |
369 | { |
369 | ToFlightCtrl.Param.sInt[4] = -1; |
370 | ToFlightCtrl.Param.sInt[4] = -1; |
370 | } |
371 | } |
371 | 372 | ||
372 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
373 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
373 | { |
374 | { |
374 | POI_KameraNick = tmp; |
375 | POI_KameraNick = tmp; |
375 | } |
376 | } |
376 | else |
377 | else |
377 | { |
378 | { |
378 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
379 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
379 | POI_KameraNick = CAM_Orientation.Elevation; |
380 | POI_KameraNick = CAM_Orientation.Elevation; |
380 | //else ToFlightCtrl.Param.sInt[5] = 0; |
381 | //else ToFlightCtrl.Param.sInt[5] = 0; |
381 | } |
382 | } |
382 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
383 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
383 | break; |
384 | break; |
384 | 385 | ||
385 | case SPI_NCCMD_VERSION: |
386 | case SPI_NCCMD_VERSION: |
386 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
387 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
387 | //+ higher than the maximum allowed altitude |
388 | //+ higher than the maximum allowed altitude |
388 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
389 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
389 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
390 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
390 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
391 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
391 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
392 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
392 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
393 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
393 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
394 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
394 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
395 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
395 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
396 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
396 | ToFlightCtrl.Param.Byte[7] = ErrorCode; // muss in SPI_NCCMD_VERSION bleiben! (siehe oben) |
397 | ToFlightCtrl.Param.Byte[7] = ErrorCode; // muss in SPI_NCCMD_VERSION bleiben! (siehe oben) |
397 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
398 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
398 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
399 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
399 | ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags; |
400 | ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags; |
400 | //[11] |
401 | //[11] |
401 | // if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work |
402 | // if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work |
402 | // else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
403 | // else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
403 | break; |
404 | break; |
404 | case SPI_MISC: |
405 | case SPI_MISC: |
405 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
406 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
406 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
407 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
407 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
408 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
408 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
409 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
409 | ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1 |
410 | ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1 |
410 | ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints |
411 | ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints |
411 | ToFlightCtrl.Param.Int[3] = NaviData.TargetPositionDeviation.Distance / 10; |
412 | ToFlightCtrl.Param.Int[3] = NaviData.TargetPositionDeviation.Distance / 10; |
412 | ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached |
413 | ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached |
413 | ToFlightCtrl.Param.Byte[9] = ToFC_MaxWpListIndex; |
414 | ToFlightCtrl.Param.Byte[9] = ToFC_MaxWpListIndex; |
414 | ToFlightCtrl.Param.sInt[5] = GyroCompassCorrected / 10; // Bytes 10 & 11 |
415 | ToFlightCtrl.Param.sInt[5] = GyroCompassCorrected / 10; // Bytes 10 & 11 |
415 | 416 | ||
416 | SpeakHoTT = 0; |
417 | SpeakHoTT = 0; |
417 | break; |
418 | break; |
418 | 419 | ||
419 | case SPI_NCCMD_GPSINFO: |
420 | case SPI_NCCMD_GPSINFO: |
420 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
421 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
421 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
422 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
422 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
423 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
423 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
424 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
424 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
425 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
425 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
426 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
426 | if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254; // Muss in SPI_NCCMD_GPSINFO bleiben! (siehe oben) |
427 | if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254; // Muss in SPI_NCCMD_GPSINFO bleiben! (siehe oben) |
427 | if(FC_WP_EventChannel) |
428 | if(FC_WP_EventChannel) |
428 | { |
429 | { |
429 | LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged |
430 | LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged |
430 | NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; // to make sure that it will be logged |
431 | NaviData_WP.WP_Eventchannel = FC_WP_EventChannel; // to make sure that it will be logged |
431 | } |
432 | } |
432 | FC_WP_EventChannel_Processed = 1; |
433 | FC_WP_EventChannel_Processed = 1; |
433 | // ++++++++++++++++++++++++++++++++++ |
434 | // ++++++++++++++++++++++++++++++++++ |
434 | // Waypoint event +++++++++++++++++++ |
435 | // Waypoint event +++++++++++++++++++ |
435 | // ++++++++++++++++++++++++++++++++++ |
436 | // ++++++++++++++++++++++++++++++++++ |
436 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_ONCE, &tmp)) |
437 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_ONCE, &tmp)) |
437 | { |
438 | { |
438 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
439 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
439 | NCParams_ClearValue(NCPARAMS_WP_EVENT_ONCE); |
440 | NCParams_ClearValue(NCPARAMS_WP_EVENT_ONCE); |
440 | NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
441 | NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
441 | } |
442 | } |
442 | else |
443 | else |
443 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_FOREVER, &tmp)) |
444 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_WP_EVENT_FOREVER, &tmp)) |
444 | { |
445 | { |
445 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
446 | ToFlightCtrl.Param.Byte[8] = (s8)(tmp - 127); |
446 | if(tmp == 0) NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
447 | if(tmp == 0) NCParams_ClearValue(NCPARAMS_WP_EVENT_FOREVER); |
447 | } |
448 | } |
448 | else ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
449 | else ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
449 | // FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
450 | // FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
450 | // ++++++++++++++++++++++++++++++++++ |
451 | // ++++++++++++++++++++++++++++++++++ |
451 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
452 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
452 | { |
453 | { |
453 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
454 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
454 | } |
455 | } |
455 | else |
456 | else |
456 | { |
457 | { |
457 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
458 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
458 | } |
459 | } |
459 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
460 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
460 | { |
461 | { |
461 | ToFlightCtrl.Param.sInt[5] = tmp; |
462 | ToFlightCtrl.Param.sInt[5] = tmp; |
462 | } |
463 | } |
463 | else |
464 | else |
464 | { |
465 | { |
465 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
466 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
466 | } |
467 | } |
467 | //DebugOut.Analog[] = ToFlightCtrl.Param.Byte[8]; |
468 | //DebugOut.Analog[] = ToFlightCtrl.Param.Byte[8]; |
468 | break; |
469 | break; |
469 | case SPI_NCCMD_HOTT_INFO: |
470 | case SPI_NCCMD_HOTT_INFO: |
470 | if(NewWPL_Name) hott_index = 100; |
471 | if(NewWPL_Name) hott_index = 100; |
471 | switch(hott_index++) |
472 | switch(hott_index++) |
472 | { |
473 | { |
473 | case 0: |
474 | case 0: |
474 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
475 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
475 | //53.28 5788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
476 | //53.28 5788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
476 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
477 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
477 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
478 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
478 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
479 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
479 | //----------------------------- |
480 | //----------------------------- |
480 | ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
481 | ToFlightCtrl.Param.Byte[2] = GyroCompassCorrected / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
481 | i1 = GPSData.Speed_Ground; // in cm/sec |
482 | i1 = GPSData.Speed_Ground; // in cm/sec |
482 | i1 *= 36; |
483 | i1 *= 36; |
483 | i1 /= 1000; |
484 | i1 /= 1000; |
484 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
485 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
485 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
486 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
486 | //----------------------------- |
487 | //----------------------------- |
487 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
488 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
488 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
489 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
489 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
490 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
490 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
491 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
491 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
492 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
492 | i1 *= 100; |
493 | i1 *= 100; |
493 | // Minuten |
494 | // Minuten |
494 | i2 *= 6; |
495 | i2 *= 6; |
495 | i2 /= 10; |
496 | i2 /= 10; |
496 | i1 += i2 / 100000; |
497 | i1 += i2 / 100000; |
497 | i2 = i2 % 100000; |
498 | i2 = i2 % 100000; |
498 | i2 /= 10; |
499 | i2 /= 10; |
499 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
500 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
500 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
501 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
501 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
502 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
502 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
503 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
503 | break; |
504 | break; |
504 | case 1: |
505 | case 1: |
505 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
506 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
506 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
507 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
507 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
508 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
508 | //----------------------------- |
509 | //----------------------------- |
509 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
510 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
510 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
511 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
511 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
512 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
512 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
513 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
513 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
514 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
514 | i1 *= 100; |
515 | i1 *= 100; |
515 | // Minuten |
516 | // Minuten |
516 | i2 *= 6; |
517 | i2 *= 6; |
517 | i2 /= 10; |
518 | i2 /= 10; |
518 | i1 += i2 / 100000; |
519 | i1 += i2 / 100000; |
519 | i2 = i2 % 100000; |
520 | i2 = i2 % 100000; |
520 | i2 /= 10; |
521 | i2 /= 10; |
521 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
522 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
522 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
523 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
523 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
524 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
524 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
525 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
525 | //----------------------------- |
526 | //----------------------------- |
526 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
527 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
527 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
528 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
528 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
529 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
529 | break; |
530 | break; |
530 | case 2: |
531 | case 2: |
531 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
532 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
532 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
533 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
533 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
534 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
534 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
535 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
535 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
536 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
536 | break; |
537 | break; |
537 | case 3: |
538 | case 3: |
538 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1; |
539 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID1; |
539 | ToFlightCtrl.Param.Byte[0] = 0; // index |
540 | ToFlightCtrl.Param.Byte[0] = 0; // index |
540 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
541 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
541 | //JetiExData[14].Value = 53 * 0x10000 + 23467; |
542 | //JetiExData[14].Value = 53 * 0x10000 + 23467; |
542 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40; |
543 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x40; |
543 | else ToFlightCtrl.Param.Byte[5] = 0x00; |
544 | else ToFlightCtrl.Param.Byte[5] = 0x00; |
544 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L; |
545 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Latitude)/10000000L; |
545 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
546 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
546 | i2 *= 6; |
547 | i2 *= 6; |
547 | i2 /= 1000; |
548 | i2 /= 1000; |
548 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
549 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
549 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
550 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
550 | break; |
551 | break; |
551 | case 4: |
552 | case 4: |
552 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2; |
553 | ToFlightCtrl.Param.Byte[11] = JETI_GPS_PACKET_ID2; |
553 | ToFlightCtrl.Param.Byte[0] = 0; // index |
554 | ToFlightCtrl.Param.Byte[0] = 0; // index |
554 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
555 | ToFlightCtrl.Param.Byte[1] = 4; // how many |
555 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60; |
556 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 0x60; |
556 | else ToFlightCtrl.Param.Byte[5] = 0x20; |
557 | else ToFlightCtrl.Param.Byte[5] = 0x20; |
557 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L; |
558 | ToFlightCtrl.Param.Byte[4] = abs(GPSData.Position.Longitude)/10000000L; |
558 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
559 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
559 | i2 *= 6; |
560 | i2 *= 6; |
560 | i2 /= 1000; |
561 | i2 /= 1000; |
561 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
562 | ToFlightCtrl.Param.Byte[3] = i2 / 256; |
562 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
563 | ToFlightCtrl.Param.Byte[2] = i2 % 256; |
563 | hott_index = 0; |
564 | hott_index = 0; |
564 | break; |
565 | break; |
565 | 566 | ||
566 | case 100: |
567 | case 100: |
567 | ToFlightCtrl.Param.Byte[11] = HOTT_WPL_NAME; |
568 | ToFlightCtrl.Param.Byte[11] = HOTT_WPL_NAME; |
568 | ToFlightCtrl.Param.Byte[0] = 0; // index |
569 | ToFlightCtrl.Param.Byte[0] = 0; // index |
569 | ToFlightCtrl.Param.Byte[2] = WPL_Store.Name[0]; |
570 | ToFlightCtrl.Param.Byte[2] = WPL_Store.Name[0]; |
570 | ToFlightCtrl.Param.Byte[3] = WPL_Store.Name[1]; |
571 | ToFlightCtrl.Param.Byte[3] = WPL_Store.Name[1]; |
571 | ToFlightCtrl.Param.Byte[4] = WPL_Store.Name[2]; |
572 | ToFlightCtrl.Param.Byte[4] = WPL_Store.Name[2]; |
572 | ToFlightCtrl.Param.Byte[5] = WPL_Store.Name[3]; |
573 | ToFlightCtrl.Param.Byte[5] = WPL_Store.Name[3]; |
573 | ToFlightCtrl.Param.Byte[6] = WPL_Store.Name[4]; |
574 | ToFlightCtrl.Param.Byte[6] = WPL_Store.Name[4]; |
574 | ToFlightCtrl.Param.Byte[7] = WPL_Store.Name[5]; |
575 | ToFlightCtrl.Param.Byte[7] = WPL_Store.Name[5]; |
575 | ToFlightCtrl.Param.Byte[8] = WPL_Store.Name[6]; |
576 | ToFlightCtrl.Param.Byte[8] = WPL_Store.Name[6]; |
576 | ToFlightCtrl.Param.Byte[9] = WPL_Store.Name[7]; |
577 | ToFlightCtrl.Param.Byte[9] = WPL_Store.Name[7]; |
577 | ToFlightCtrl.Param.Byte[10]= WPL_Store.Name[8]; |
578 | ToFlightCtrl.Param.Byte[10]= WPL_Store.Name[8]; |
578 | ToFlightCtrl.Param.Byte[1] = 9; // how many |
579 | ToFlightCtrl.Param.Byte[1] = 9; // how many |
579 | NewWPL_Name = 0; |
580 | NewWPL_Name = 0; |
580 | hott_index = 0; |
581 | hott_index = 0; |
581 | break; |
582 | break; |
582 | default: |
583 | default: |
583 | ToFlightCtrl.Param.Byte[0] = 255; |
584 | ToFlightCtrl.Param.Byte[0] = 255; |
584 | hott_index = 0; |
585 | hott_index = 0; |
585 | break; |
586 | break; |
586 | } |
587 | } |
587 | break; |
588 | break; |
588 | default: |
589 | default: |
589 | break; |
590 | break; |
590 | // 0 = 0,1 |
591 | // 0 = 0,1 |
591 | // 1 = 2,3 |
592 | // 1 = 2,3 |
592 | // 2 = 4,5 |
593 | // 2 = 4,5 |
593 | // 3 = 6,7 |
594 | // 3 = 6,7 |
594 | // 4 = 8,9 |
595 | // 4 = 8,9 |
595 | // 5 = 10,11 |
596 | // 5 = 10,11 |
596 | } |
597 | } |
597 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
598 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
598 | switch(FromFlightCtrl.Command) |
599 | switch(FromFlightCtrl.Command) |
599 | { |
600 | { |
600 | case SPI_FCCMD_USER: |
601 | case SPI_FCCMD_USER: |
601 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
602 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
602 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
603 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
603 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
604 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
604 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
605 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
605 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
606 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
606 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
607 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
607 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
608 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
608 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
609 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
609 | FC.RealStatusFlags = FromFlightCtrl.Param.Byte[8]; |
610 | FC.RealStatusFlags = FromFlightCtrl.Param.Byte[8]; |
610 | if(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN) SimulationFlags = 0; // stop the simulation if the motors would really start |
611 | if(FC.RealStatusFlags & FC_STATUS_MOTOR_RUN) SimulationFlags = 0; // stop the simulation if the motors would really start |
611 | 612 | ||
612 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
613 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
613 | { |
614 | { |
614 | if(ClearFCStatusFlags) |
615 | if(ClearFCStatusFlags) |
615 | { |
616 | { |
616 | FC.StatusFlags = 0; |
617 | FC.StatusFlags = 0; |
617 | ClearFCStatusFlags = 0; |
618 | ClearFCStatusFlags = 0; |
618 | } |
619 | } |
619 | } |
620 | } |
620 | FC.StatusFlags |= FC.RealStatusFlags; |
621 | FC.StatusFlags |= FC.RealStatusFlags; |
621 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
622 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
622 | { |
623 | { |
623 | HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
624 | HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
624 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
625 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
625 | Compass_Init(); |
626 | Compass_Init(); |
626 | FCCalibActive = 10; |
627 | FCCalibActive = 10; |
627 | FC_is_Calibrated = 0; |
628 | FC_is_Calibrated = 0; |
628 | } |
629 | } |
629 | else |
630 | else |
630 | { |
631 | { |
631 | if(FCCalibActive) |
632 | if(FCCalibActive) |
632 | { |
633 | { |
633 | if(--FCCalibActive == 0) |
634 | if(--FCCalibActive == 0) |
634 | { |
635 | { |
635 | FC_is_Calibrated = 1; |
636 | FC_is_Calibrated = 1; |
636 | Compass_Check(); |
637 | Compass_Check(); |
637 | } |
638 | } |
638 | } |
639 | } |
639 | } |
640 | } |
640 | if(FC.StatusFlags & FC_STATUS_START) |
641 | if(FC.StatusFlags & FC_STATUS_START) |
641 | { |
642 | { |
642 | if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
643 | if(Compass_Heading != -1) HeadFreeStartAngle = (3600 + Compass_Heading * 10 + GeoMagDec) % 3600; |
643 | else HeadFreeStartAngle = GyroCompassCorrected; |
644 | else HeadFreeStartAngle = GyroCompassCorrected; |
644 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
645 | CompassDirectionAtMotorStart = HeadFreeStartAngle; |
645 | } |
646 | } |
646 | 647 | ||
647 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
648 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
648 | { |
649 | { |
649 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
650 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
650 | { |
651 | { |
651 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
652 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
652 | { |
653 | { |
653 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
654 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
654 | } |
655 | } |
655 | else // Ansonsten die aktuelle Richtung übernehmen |
656 | else // Ansonsten die aktuelle Richtung übernehmen |
656 | HeadFreeStartAngle = GyroCompassCorrected; // in 0.1° |
657 | HeadFreeStartAngle = GyroCompassCorrected; // in 0.1° |
657 | } |
658 | } |
658 | } |
659 | } |
659 | NaviData.FCStatusFlags = FC.StatusFlags; |
660 | NaviData.FCStatusFlags = FC.StatusFlags; |
660 | if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY; |
661 | if(FC.StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) NaviData.FCStatusFlags &= ~FC_STATUS_FLY; |
661 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[9]; |
662 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[9]; |
662 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
663 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
663 | 664 | ||
664 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
665 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
665 | else |
666 | else |
666 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
667 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
667 | 668 | ||
668 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
669 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
669 | else |
670 | else |
670 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
671 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
671 | 672 | ||
672 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
673 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
673 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
674 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
674 | FC.BAT_Voltage = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
675 | FC.BAT_Voltage = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
675 | DebugOut.Analog[7] = FC.BAT_Voltage; |
676 | DebugOut.Analog[7] = FC.BAT_Voltage; |
676 | DebugOut.Analog[5] = FC.StatusFlags; |
677 | DebugOut.Analog[5] = FC.StatusFlags; |
677 | NaviData.UBat = (u8) FC.BAT_Voltage; // Achtung: die (u8) NaviData.UBat kann überlaufen -> das KopterTool müsste dann 25,5V drauf rechnen |
678 | NaviData.UBat = (u8) FC.BAT_Voltage; // Achtung: die (u8) NaviData.UBat kann überlaufen -> das KopterTool müsste dann 25,5V drauf rechnen |
678 | break; |
679 | break; |
679 | case SPI_FCCMD_BL_ACCU: |
680 | case SPI_FCCMD_BL_ACCU: |
680 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
681 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
681 | DebugOut.Analog[8] = FC.BAT_Current; |
682 | DebugOut.Analog[8] = FC.BAT_Current; |
682 | if(AmountOfMotors < FromFlightCtrl.Param.Byte[2]+1) AmountOfMotors = FromFlightCtrl.Param.Byte[2]+1; |
683 | if(AmountOfMotors < FromFlightCtrl.Param.Byte[2]+1) AmountOfMotors = FromFlightCtrl.Param.Byte[2]+1; |
683 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[3]; |
684 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[3]; |
684 | if(BL_MinOfMaxPWM < Logging_BL_MinOfMaxPWM) Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until logged |
685 | if(BL_MinOfMaxPWM < Logging_BL_MinOfMaxPWM) Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until logged |
685 | if(BL_MinOfMaxPWM < ErrorCheck_BL_MinOfMaxPWM) ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until Error processed |
686 | if(BL_MinOfMaxPWM < ErrorCheck_BL_MinOfMaxPWM) ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM; // hold the value until Error processed |
686 | Parameter.NaviGpsModeControl = FromFlightCtrl.Param.Byte[4]; |
687 | Parameter.NaviGpsModeControl = FromFlightCtrl.Param.Byte[4]; |
687 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[5]; |
688 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[5]; |
- | 689 | index = FromFlightCtrl.Param.Byte[2] % MAX_MOTORS; |
|
688 | Motor[FromFlightCtrl.Param.Byte[2]].NotReadyCnt = FromFlightCtrl.Param.Byte[6]; |
690 | Motor[index].NotReadyCnt = FromFlightCtrl.Param.Byte[6]; |
689 | Motor_Version[FromFlightCtrl.Param.Byte[2]] = FromFlightCtrl.Param.Byte[7]; |
691 | Motor_Version[index] = FromFlightCtrl.Param.Byte[7]; |
690 | Motor[FromFlightCtrl.Param.Byte[2]].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
692 | Motor[index].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
691 | Motor[FromFlightCtrl.Param.Byte[2]].State = FromFlightCtrl.Param.Byte[9]; |
693 | Motor[index].State = FromFlightCtrl.Param.Byte[9]; |
692 | Motor[FromFlightCtrl.Param.Byte[2]].Temperature = FromFlightCtrl.Param.Byte[10]; |
694 | Motor[index].Temperature = FromFlightCtrl.Param.Byte[10]; |
693 | Motor[FromFlightCtrl.Param.Byte[2]].Current = FromFlightCtrl.Param.Byte[11]; |
695 | Motor[index].Current = FromFlightCtrl.Param.Byte[11]; |
694 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
696 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
695 | { |
697 | { |
696 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
698 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
697 | } |
699 | } |
698 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.Current = FC.BAT_Current; |
700 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.Current = FC.BAT_Current; |
699 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
701 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
700 | break; |
702 | break; |
701 | case SPI_FCCMD_PARAMETER1: |
703 | case SPI_FCCMD_PARAMETER1: |
702 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[0]; |
704 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[0]; |
703 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
705 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
704 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
706 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
705 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
707 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
706 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
708 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
707 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
709 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
708 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
710 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
709 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
711 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
710 | // CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
712 | // CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
711 | Parameter.NaviMaxFlyingRange = FromFlightCtrl.Param.Byte[8]; |
713 | Parameter.NaviMaxFlyingRange = FromFlightCtrl.Param.Byte[8]; |
712 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
714 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
713 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
715 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
714 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
716 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
715 | break; |
717 | break; |
716 | case SPI_FCCMD_PARAMETER2: |
718 | case SPI_FCCMD_PARAMETER2: |
717 | CHK_POTI_MM(Parameter.AutoPhotoDistance,FromFlightCtrl.Param.Byte[0],0,255); |
719 | CHK_POTI_MM(FC.AutoPhotoDistance,FromFlightCtrl.Param.Byte[0],0,255); |
718 | if(FromFlightCtrl.Param.Byte[1]) FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared in the SD-Logging |
720 | if(FromFlightCtrl.Param.Byte[1]) FC.FromFC_SpeakHoTT = FromFlightCtrl.Param.Byte[1]; // will be cleared in the SD-Logging |
719 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
721 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
720 | Parameter.FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4]; |
722 | Parameter.FromFC_LowVoltageHomeActive = FromFlightCtrl.Param.Byte[4]; |
721 | if(FromFlightCtrl.Param.Byte[5]) FromFC_LoadWP_List = FromFlightCtrl.Param.Byte[5]; |
723 | if(FromFlightCtrl.Param.Byte[5]) FromFC_LoadWP_List = FromFlightCtrl.Param.Byte[5]; |
722 | if(FromFlightCtrl.Param.Byte[6]) FromFC_Load_SinglePoint = FromFlightCtrl.Param.Byte[6]; |
724 | if(FromFlightCtrl.Param.Byte[6]) FromFC_Load_SinglePoint = FromFlightCtrl.Param.Byte[6]; |
723 | if(FromFlightCtrl.Param.Byte[7]) FromFC_Save_SinglePoint = FromFlightCtrl.Param.Byte[7]; |
725 | if(FromFlightCtrl.Param.Byte[7]) FromFC_Save_SinglePoint = FromFlightCtrl.Param.Byte[7]; |
724 | CompassSetpoint = FromFlightCtrl.Param.sInt[4] * 10; // 8 & 9 |
726 | CompassSetpoint = FromFlightCtrl.Param.sInt[4] * 10; // 8 & 9 |
725 | CompassSetpointCorrected = (3600 + CompassSetpoint + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
727 | CompassSetpointCorrected = (3600 + CompassSetpoint + FC.FromFC_CompassOffset + GeoMagDec) % 3600; |
726 | FC.StatusFlags3 = FromFlightCtrl.Param.Byte[10]; |
728 | FC.StatusFlags3 = FromFlightCtrl.Param.Byte[10]; |
727 | Parameter.SingleWpSpeed = FromFlightCtrl.Param.Byte[11]; |
729 | Parameter.SingleWpSpeed = FromFlightCtrl.Param.Byte[11]; |
728 | break; |
730 | break; |
729 | case SPI_FCCMD_STICK: |
731 | case SPI_FCCMD_STICK: |
730 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
732 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
731 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
733 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
732 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
734 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
733 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
735 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
734 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
736 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
735 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
737 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
736 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
738 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
737 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
739 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
738 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
740 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
739 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
741 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
740 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
742 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
741 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
743 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
742 | CHK_POTI_MM(WaypointAcceleration,WaypointAccelerationSetting,0,255); // that could be a Poti-Value |
744 | CHK_POTI_MM(WaypointAcceleration,WaypointAccelerationSetting,0,255); // that could be a Poti-Value |
743 | break; |
745 | break; |
744 | 746 | ||
745 | case SPI_FCCMD_MISC: |
747 | case SPI_FCCMD_MISC: |
746 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
748 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
747 | { // put only new CompassCalState into queue to send via I2C |
749 | { // put only new CompassCalState into queue to send via I2C |
748 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
750 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
749 | { |
751 | { |
750 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
752 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
751 | Compass_SetCalState(CompassCalState); |
753 | Compass_SetCalState(CompassCalState); |
752 | } |
754 | } |
753 | // else CompassCalState = 0; |
755 | // else CompassCalState = 0; |
754 | } |
756 | } |
755 | HoverGas = FromFlightCtrl.Param.Byte[1]; |
757 | HoverGas = FromFlightCtrl.Param.Byte[1]; |
756 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
758 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
757 | FC.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
759 | FC.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
758 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
760 | if(!(SimulationFlags & SIMULATION_ACTIVE)) NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
759 | FC.Error[0] |= FromFlightCtrl.Param.Byte[6]; |
761 | FC.Error[0] |= FromFlightCtrl.Param.Byte[6]; |
760 | FC.Error[1] |= FromFlightCtrl.Param.Byte[7]; |
762 | FC.Error[1] |= FromFlightCtrl.Param.Byte[7]; |
761 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
763 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
762 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
764 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
763 | if(FC.Error[0] || FC.Error[1] /* || FC.Error[2] || FC.Error[3] || FC.Error[4]*/) DebugOut.StatusRed |= AMPEL_FC; |
765 | if(FC.Error[0] || FC.Error[1] /* || FC.Error[2] || FC.Error[3] || FC.Error[4]*/) DebugOut.StatusRed |= AMPEL_FC; |
764 | else DebugOut.StatusRed &= ~AMPEL_FC; |
766 | else DebugOut.StatusRed &= ~AMPEL_FC; |
765 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[8]; |
767 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[8]; |
766 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
768 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
767 | if(FC.RC_Quality > 160) NaviData.RC_Quality = 200; else NaviData.RC_Quality = FC.RC_Quality; |
769 | if(FC.RC_Quality > 160) NaviData.RC_Quality = 200; else NaviData.RC_Quality = FC.RC_Quality; |
768 | NC_Wait_for_LED = FromFlightCtrl.Param.Byte[10]; |
770 | NC_Wait_for_LED = FromFlightCtrl.Param.Byte[10]; |
769 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
771 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
770 | if(LoggingGasCnt == 0) LoggingGasFilter = 0; |
772 | if(LoggingGasCnt == 0) LoggingGasFilter = 0; |
771 | LoggingGasFilter += (u32) FromFlightCtrl.Param.Byte[11]; |
773 | LoggingGasFilter += (u32) FromFlightCtrl.Param.Byte[11]; |
772 | LoggingGasCnt++; |
774 | LoggingGasCnt++; |
773 | break; |
775 | break; |
774 | 776 | ||
775 | case SPI_FCCMD_VERSION: // slow! |
777 | case SPI_FCCMD_VERSION: // slow! |
776 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
778 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
777 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
779 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
778 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
780 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
779 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
781 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
780 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
782 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
781 | Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[5]; |
783 | Parameter.FromFC_LandingSpeed = FromFlightCtrl.Param.Byte[5]; |
782 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[6]; |
784 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[6]; |
783 | CHK_POTI_MM(Parameter.AutoPhotoAltitudes,FromFlightCtrl.Param.Byte[7],0,255); |
785 | CHK_POTI_MM(Parameter.AutoPhotoAltitudes,FromFlightCtrl.Param.Byte[7],0,255); |
784 | UART_VersionInfo.BL_Firmware = FromFlightCtrl.Param.Byte[8]; |
786 | UART_VersionInfo.BL_Firmware = FromFlightCtrl.Param.Byte[8]; |
785 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
787 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
786 | FlugMinutenGesamt = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
788 | FlugMinutenGesamt = FromFlightCtrl.Param.Int[5]; // 10 & 11 |
787 | break; |
789 | break; |
788 | case SPI_FCCMD_NEUTRAL: // slow! |
790 | case SPI_FCCMD_NEUTRAL: // slow! |
789 | FC.AdNeutralNick = FromFlightCtrl.Param.Int[0]; |
791 | FC.AdNeutralNick = FromFlightCtrl.Param.Int[0]; |
790 | FC.AdNeutralRoll = FromFlightCtrl.Param.Int[1]; |
792 | FC.AdNeutralRoll = FromFlightCtrl.Param.Int[1]; |
791 | FC.AdNeutralYaw = FromFlightCtrl.Param.Int[2]; |
793 | FC.AdNeutralYaw = FromFlightCtrl.Param.Int[2]; |
792 | Parameter.Driftkomp = FromFlightCtrl.Param.Byte[6]; |
794 | Parameter.Driftkomp = FromFlightCtrl.Param.Byte[6]; |
793 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[7]; |
795 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[7]; |
794 | Parameter.ReceiverType = FromFlightCtrl.Param.Byte[8]; |
796 | Parameter.ReceiverType = FromFlightCtrl.Param.Byte[8]; |
795 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[9],0,255); |
797 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[9],0,255); |
796 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[10],0,255); |
798 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[10],0,255); |
797 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[11],0,255); |
799 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[11],0,255); |
798 | break; |
800 | break; |
799 | case SPI_FCCMD_SLOW2: // slow! |
801 | case SPI_FCCMD_SLOW2: // slow! |
800 | FC.BoatNeutralNick = FromFlightCtrl.Param.Int[0]; // 0 & 1 |
802 | FC.BoatNeutralNick = FromFlightCtrl.Param.Int[0]; // 0 & 1 |
801 | FC.BoatNeutralRoll = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
803 | FC.BoatNeutralRoll = FromFlightCtrl.Param.Int[1]; // 2 & 3 |
802 | FC.BoatNeutralYaw = FromFlightCtrl.Param.Int[2]; // 4 & 5 |
804 | FC.BoatNeutralYaw = FromFlightCtrl.Param.Int[2]; // 4 & 5 |
803 | Parameter.CamOrientation = FromFlightCtrl.Param.Byte[6]; |
805 | Parameter.CamOrientation = FromFlightCtrl.Param.Byte[6]; |
804 | if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188) |
806 | if(FromFlightCtrl.Param.Byte[7] >= 68 && FromFlightCtrl.Param.Byte[7] <= 188) |
805 | { |
807 | { |
806 | FC.FromFC_DisableDeclination = 1; |
808 | FC.FromFC_DisableDeclination = 1; |
807 | FC.FromFC_CompassOffset = 10 * (s8) (FromFlightCtrl.Param.Byte[7] - 128); |
809 | FC.FromFC_CompassOffset = 10 * (s8) (FromFlightCtrl.Param.Byte[7] - 128); |
808 | GeoMagDec = 0; |
810 | GeoMagDec = 0; |
809 | } |
811 | } |
810 | else |
812 | else |
811 | { |
813 | { |
812 | FC.FromFC_DisableDeclination = 0; |
814 | FC.FromFC_DisableDeclination = 0; |
813 | FC.FromFC_CompassOffset = 10 * FromFlightCtrl.Param.sByte[7]; |
815 | FC.FromFC_CompassOffset = 10 * FromFlightCtrl.Param.sByte[7]; |
814 | } |
816 | } |
815 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
817 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
816 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
818 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
817 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
819 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
818 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
820 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
819 | break; |
821 | break; |
820 | case SPI_FCCMD_SLOW3: // slow! |
822 | case SPI_FCCMD_SLOW3: // slow! |
821 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[0]; |
823 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[0]; |
822 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[1]; |
824 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[1]; |
823 | Parameter.DescendRange = FromFlightCtrl.Param.Byte[2]; |
825 | Parameter.DescendRange = FromFlightCtrl.Param.Byte[2]; |
824 | Parameter.MaximumAltitude = FromFlightCtrl.Param.Byte[3]; |
826 | Parameter.MaximumAltitude = FromFlightCtrl.Param.Byte[3]; |
825 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[4]; |
827 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[4]; |
826 | Parameter.HomeYawMode = ((ServoParams.CompInvert & 0x18) >> 3); |
828 | Parameter.HomeYawMode = ((ServoParams.CompInvert & 0x18) >> 3); |
827 | NaviData_Home.LipoCellCount = FromFlightCtrl.Param.Byte[5]; |
829 | NaviData_Home.LipoCellCount = FromFlightCtrl.Param.Byte[5]; |
828 | NaviData_Volatile.ShutterCounter = FromFlightCtrl.Param.Int[3]; // 6 & 7 |
830 | NaviData_Volatile.ShutterCounter = FromFlightCtrl.Param.Int[3]; // 6 & 7 |
829 | // 8 |
831 | // 8 |
830 | // 9 |
832 | // 9 |
831 | // 10 |
833 | // 10 |
832 | // 11 |
834 | // 11 |
833 | break; |
835 | break; |
834 | 836 | ||
835 | default: |
837 | default: |
836 | break; |
838 | break; |
837 | } |
839 | } |
838 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
840 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
839 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
841 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
840 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
842 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
841 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
843 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
842 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
844 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
843 | // every time we got new data from the FC via SPI call the navigation routine |
845 | // every time we got new data from the FC via SPI call the navigation routine |
844 | // and update GPSStick that are returned to FC |
846 | // and update GPSStick that are returned to FC |
845 | SPI_RxBuffer_Request = 0; |
847 | SPI_RxBuffer_Request = 0; |
846 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
848 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
847 | ClearFCStatusFlags = 1; |
849 | ClearFCStatusFlags = 1; |
848 | if(counter) |
850 | if(counter) |
849 | { |
851 | { |
850 | counter--; // count down to enable servo |
852 | counter--; // count down to enable servo |
851 | if(!counter) TIMER2_Init(); // enable Servo Output |
853 | if(!counter) TIMER2_Init(); // enable Servo Output |
852 | } |
854 | } |
853 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
855 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
854 | 856 | ||
855 | } // EOF if(SPI_RxBuffer_Request) |
857 | } // EOF if(SPI_RxBuffer_Request) |
856 | else // no new SPI data |
858 | else // no new SPI data |
857 | { |
859 | { |
858 | if(CheckDelay(timeout) && (counter == 0)) |
860 | if(CheckDelay(timeout) && (counter == 0)) |
859 | { |
861 | { |
860 | TIMER2_Deinit(); // disable Servo Output |
862 | TIMER2_Deinit(); // disable Servo Output |
861 | counter = 50; // reset counter for enabling Servo Output |
863 | counter = 50; // reset counter for enabling Servo Output |
862 | } |
864 | } |
863 | } |
865 | } |
864 | } |
866 | } |
865 | 867 | ||
866 | //------------------------------------------------------ |
868 | //------------------------------------------------------ |
867 | void SPI0_GetFlightCtrlVersion(void) |
869 | void SPI0_GetFlightCtrlVersion(void) |
868 | { |
870 | { |
869 | u32 timeout; |
871 | u32 timeout; |
870 | u8 repeat; |
872 | u8 repeat; |
871 | u8 msg[64]; |
873 | u8 msg[64]; |
872 | 874 | ||
873 | UART1_PutString("\r\n Looking for FlightControl"); |
875 | UART1_PutString("\r\n Looking for FlightControl"); |
874 | FC_Version.Major = 0xFF; |
876 | FC_Version.Major = 0xFF; |
875 | FC_Version.Minor = 0xFF; |
877 | FC_Version.Minor = 0xFF; |
876 | FC_Version.Patch = 0xFF; |
878 | FC_Version.Patch = 0xFF; |
877 | FC_Version.Compatible = 0xFF; |
879 | FC_Version.Compatible = 0xFF; |
878 | 880 | ||
879 | // polling FC version info |
881 | // polling FC version info |
880 | repeat = 0; |
882 | repeat = 0; |
881 | do |
883 | do |
882 | { |
884 | { |
883 | timeout = SetDelay(250); |
885 | timeout = SetDelay(250); |
884 | do |
886 | do |
885 | { |
887 | { |
886 | SPI0_UpdateBuffer(); |
888 | SPI0_UpdateBuffer(); |
887 | if (FC_Version.Major != 0xFF) break; |
889 | if (FC_Version.Major != 0xFF) break; |
888 | }while (!CheckDelay(timeout)); |
890 | }while (!CheckDelay(timeout)); |
889 | UART1_PutString("."); |
891 | UART1_PutString("."); |
890 | repeat++; |
892 | repeat++; |
891 | FCCalibActive = 1; |
893 | FCCalibActive = 1; |
892 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
894 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
893 | // if we got it |
895 | // if we got it |
894 | if (FC_Version.Major != 0xFF) |
896 | if (FC_Version.Major != 0xFF) |
895 | { |
897 | { |
896 | 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); |
898 | 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); |
897 | UART1_PutString(msg); |
899 | UART1_PutString(msg); |
898 | } |
900 | } |
899 | else UART1_PutString("\n\r not found!"); |
901 | else UART1_PutString("\n\r not found!"); |
900 | } |
902 | } |
901 | 903 | ||
902 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
904 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
903 | // + extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
905 | // + extended Current measurement -> 200 = 20A 201 = 21A 255 = 75A (20+55) |
904 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
906 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
905 | u16 BL3_Current(u8 who) // in 0,1A |
907 | u16 BL3_Current(u8 who) // in 0,1A |
906 | { |
908 | { |
907 | if(Motor[who].Current <= 200) return((u16) Motor[who].Current); |
909 | if(Motor[who].Current <= 200) return((u16) Motor[who].Current); |
908 | else |
910 | else |
909 | { |
911 | { |
910 | if(Motor_Version[who] & MOTOR_STATE_BL30) return(200 + 10 * (u16) (Motor[who].Current - 200)); |
912 | if(Motor_Version[who] & MOTOR_STATE_BL30) return(200 + 10 * (u16) (Motor[who].Current - 200)); |
911 | else return((u16) Motor[who].Current); |
913 | else return((u16) Motor[who].Current); |
912 | } |
914 | } |
913 | } |
915 | } |
914 | 916 | ||
915 | 917 |