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