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