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