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