Rev 2309 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2309 | Rev 2333 | ||
---|---|---|---|
1 | // ######################## SPI - FlightCtrl ################### |
1 | // ######################## SPI - FlightCtrl ################### |
2 | #include "main.h" |
2 | #include "main.h" |
3 | #include "eeprom.h" |
3 | #include "eeprom.h" |
4 | 4 | ||
5 | //struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
5 | //struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
6 | //struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
6 | //struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
7 | struct str_ToNaviCtrl ToNaviCtrl; |
7 | struct str_ToNaviCtrl ToNaviCtrl; |
8 | struct str_FromNaviCtrl FromNaviCtrl; |
8 | struct str_FromNaviCtrl FromNaviCtrl; |
9 | struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
9 | struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
10 | struct str_SPI_VersionInfo NC_Version; |
10 | struct str_SPI_VersionInfo NC_Version; |
11 | struct str_GPSInfo GPSInfo; |
11 | struct str_GPSInfo GPSInfo; |
12 | 12 | ||
13 | unsigned char SPI_BufferIndex; |
13 | unsigned char SPI_BufferIndex; |
14 | unsigned char SPI_RxBufferIndex; |
14 | unsigned char SPI_RxBufferIndex; |
15 | signed char FromNC_Rotate_C = 32, FromNC_Rotate_S = 0; |
15 | signed char FromNC_Rotate_C = 32, FromNC_Rotate_S = 0; |
16 | 16 | ||
17 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
17 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
18 | unsigned char *SPI_TX_Buffer; |
18 | unsigned char *SPI_TX_Buffer; |
19 | 19 | ||
20 | unsigned char SPITransferCompleted, SPI_ChkSum; |
20 | unsigned char SPITransferCompleted, SPI_ChkSum; |
21 | unsigned char SPI_RxDataValid,NaviDataOkay = 250; |
21 | unsigned char SPI_RxDataValid,NaviDataOkay = 250; |
22 | 22 | ||
23 | unsigned char SPI_CommandSequence[] = { SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_PARAMETER1, |
23 | unsigned char SPI_CommandSequence[] = { SPI_FCCMD_STICK, SPI_FCCMD_USER, SPI_FCCMD_PARAMETER1, |
24 | SPI_FCCMD_STICK, SPI_FCCMD_MISC, SPI_FCCMD_VERSION, |
24 | SPI_FCCMD_STICK, SPI_FCCMD_MISC, SPI_FCCMD_VERSION, |
25 | SPI_FCCMD_STICK, SPI_FCCMD_SERVOS, SPI_FCCMD_ACCU, |
25 | SPI_FCCMD_STICK, SPI_FCCMD_SERVOS, SPI_FCCMD_ACCU, |
26 | SPI_FCCMD_STICK, SPI_FCCMD_PARAMETER2 |
26 | SPI_FCCMD_STICK, SPI_FCCMD_PARAMETER2 |
27 | }; |
27 | }; |
28 | unsigned char SPI_CommandCounter = 0; |
28 | unsigned char SPI_CommandCounter = 0; |
29 | unsigned char NC_ErrorCode = 0; |
29 | unsigned char NC_ErrorCode = 0; |
30 | unsigned char NC_GPS_ModeCharacter = ' '; |
30 | unsigned char NC_GPS_ModeCharacter = ' '; |
31 | unsigned char EarthMagneticField = 0; |
31 | unsigned char EarthMagneticField = 0; |
32 | unsigned char EarthMagneticInclination = 0, EarthMagneticInclinationTheoretic = 0; |
32 | unsigned char EarthMagneticInclination = 0, EarthMagneticInclinationTheoretic = 0; |
33 | unsigned char NC_To_FC_Flags = 0; |
33 | unsigned char NC_To_FC_Flags = 0; |
34 | unsigned char NC_To_FC_MaxAltitude = 0; // this is a Parameter on the SD-card |
34 | unsigned char NC_To_FC_MaxAltitude = 0; // this is a Parameter on the SD-card |
35 | signed int POI_KameraNick = 0; // in 0,1° |
35 | signed int POI_KameraNick = 0; // in 0,1° |
36 | vector16_t MagVec = {0,0,0}; |
36 | vector16_t MagVec = {0,0,0}; |
37 | 37 | ||
38 | #ifdef USE_SPI_COMMUNICATION |
38 | #ifdef USE_SPI_COMMUNICATION |
39 | 39 | ||
40 | //------------------------------------------------------ |
40 | //------------------------------------------------------ |
41 | void SPI_MasterInit(void) |
41 | void SPI_MasterInit(void) |
42 | { |
42 | { |
43 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
43 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
44 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
44 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
45 | 45 | ||
46 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
46 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
47 | SPSR = 0;//(1<<SPI2X); |
47 | SPSR = 0;//(1<<SPI2X); |
48 | 48 | ||
49 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
49 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
50 | SPITransferCompleted = 1; |
50 | SPITransferCompleted = 1; |
51 | 51 | ||
52 | //SPDR = 0x00; // dummy write |
52 | //SPDR = 0x00; // dummy write |
53 | 53 | ||
54 | ToNaviCtrl.Sync1 = 0xAA; |
54 | ToNaviCtrl.Sync1 = 0xAA; |
55 | ToNaviCtrl.Sync2 = 0x83; |
55 | ToNaviCtrl.Sync2 = 0x83; |
56 | 56 | ||
57 | ToNaviCtrl.Command = SPI_FCCMD_USER; |
57 | ToNaviCtrl.Command = SPI_FCCMD_USER; |
58 | ToNaviCtrl.IntegralNick = 0; |
58 | ToNaviCtrl.IntegralNick = 0; |
59 | ToNaviCtrl.IntegralRoll = 0; |
59 | ToNaviCtrl.IntegralRoll = 0; |
60 | FromNaviCtrl_Value.SerialDataOkay = 0; |
60 | FromNaviCtrl_Value.SerialDataOkay = 0; |
61 | SPI_RxDataValid = 0; |
61 | SPI_RxDataValid = 0; |
62 | 62 | ||
63 | } |
63 | } |
64 | 64 | ||
65 | //------------------------------------------------------ |
65 | //------------------------------------------------------ |
66 | void SPI_StartTransmitPacket(void) |
66 | void SPI_StartTransmitPacket(void) |
67 | { |
67 | { |
68 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
68 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
69 | if (!SPITransferCompleted) return; |
69 | if (!SPITransferCompleted) return; |
70 | // _delay_us(30); |
70 | // _delay_us(30); |
71 | 71 | ||
72 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
72 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
73 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
73 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
74 | 74 | ||
75 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
75 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
76 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
76 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
77 | 77 | ||
78 | SPITransferCompleted = 0; |
78 | SPITransferCompleted = 0; |
79 | UpdateSPI_Buffer(); // update buffer |
79 | UpdateSPI_Buffer(); // update buffer |
80 | 80 | ||
81 | SPI_BufferIndex = 1; |
81 | SPI_BufferIndex = 1; |
82 | // -- Debug-Output --- |
82 | // -- Debug-Output --- |
83 | //---- |
83 | //---- |
84 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
84 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
85 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
85 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
86 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
86 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
87 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
87 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
88 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
88 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
89 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
89 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
90 | 90 | ||
91 | } |
91 | } |
92 | 92 | ||
93 | //------------------------------------------------------ |
93 | //------------------------------------------------------ |
94 | //SIGNAL(SIG_SPI) |
94 | //SIGNAL(SIG_SPI) |
95 | void SPI_TransmitByte(void) |
95 | void SPI_TransmitByte(void) |
96 | { |
96 | { |
97 | static unsigned char SPI_RXState = 0; |
97 | static unsigned char SPI_RXState = 0; |
98 | unsigned char rxdata; |
98 | unsigned char rxdata; |
99 | static unsigned char rxchksum; |
99 | static unsigned char rxchksum; |
100 | 100 | ||
101 | if (SPITransferCompleted) return; |
101 | if (SPITransferCompleted) return; |
102 | if (!(SPSR & (1 << SPIF))) return; |
102 | if (!(SPSR & (1 << SPIF))) return; |
103 | SendSPI = 4; |
103 | SendSPI = 4; |
104 | 104 | ||
105 | // _delay_us(30); |
105 | // _delay_us(30); |
106 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
106 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
107 | 107 | ||
108 | rxdata = SPDR; |
108 | rxdata = SPDR; |
109 | switch ( SPI_RXState) |
109 | switch ( SPI_RXState) |
110 | { |
110 | { |
111 | case 0: |
111 | case 0: |
112 | 112 | ||
113 | SPI_RxBufferIndex = 0; |
113 | SPI_RxBufferIndex = 0; |
114 | rxchksum = rxdata; |
114 | rxchksum = rxdata; |
115 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
115 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
116 | 116 | ||
117 | break; |
117 | break; |
118 | 118 | ||
119 | case 1: |
119 | case 1: |
120 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
120 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
121 | else SPI_RXState = 0; |
121 | else SPI_RXState = 0; |
122 | break; |
122 | break; |
123 | 123 | ||
124 | case 2: |
124 | case 2: |
125 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
125 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
126 | //DebugOut.Analog[19]++; |
126 | //DebugOut.Analog[19]++; |
127 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
127 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
128 | { |
128 | { |
129 | 129 | ||
130 | if (rxdata == rxchksum) |
130 | if (rxdata == rxchksum) |
131 | { |
131 | { |
132 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
132 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
133 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
133 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
134 | SPI_RxDataValid = 1; |
134 | SPI_RxDataValid = 1; |
135 | } |
135 | } |
136 | else |
136 | else |
137 | { |
137 | { |
138 | SPI_RxDataValid = 0; |
138 | SPI_RxDataValid = 0; |
139 | } |
139 | } |
140 | 140 | ||
141 | 141 | ||
142 | SPI_RXState = 0; |
142 | SPI_RXState = 0; |
143 | } |
143 | } |
144 | else rxchksum += rxdata; |
144 | else rxchksum += rxdata; |
145 | break; |
145 | break; |
146 | 146 | ||
147 | } |
147 | } |
148 | 148 | ||
149 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
149 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
150 | { |
150 | { |
151 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
151 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
152 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
152 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
153 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
153 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
154 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
154 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
155 | 155 | ||
156 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
156 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
157 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
157 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
158 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
158 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
159 | 159 | ||
160 | } |
160 | } |
161 | else SPITransferCompleted = 1; |
161 | else SPITransferCompleted = 1; |
162 | 162 | ||
163 | SPI_BufferIndex++; |
163 | SPI_BufferIndex++; |
164 | } |
164 | } |
165 | 165 | ||
166 | 166 | ||
167 | //------------------------------------------------------ |
167 | //------------------------------------------------------ |
168 | void UpdateSPI_Buffer(void) |
168 | void UpdateSPI_Buffer(void) |
169 | { |
169 | { |
170 | signed int tmp; |
170 | signed int tmp; |
171 | static unsigned char motorindex, oldcommand = SPI_NCCMD_VERSION; |
171 | static unsigned char motorindex, oldcommand = SPI_NCCMD_VERSION; |
172 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
172 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
173 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
173 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
174 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
174 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
175 | ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier; |
175 | ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier; |
176 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
176 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
177 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
177 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
178 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
178 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
179 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
179 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
180 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
180 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
181 | switch(ToNaviCtrl.Command) // |
181 | switch(ToNaviCtrl.Command) // |
182 | { |
182 | { |
183 | case SPI_FCCMD_USER: |
183 | case SPI_FCCMD_USER: |
184 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
184 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
185 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
185 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
186 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
186 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
187 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
187 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
188 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
188 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
189 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
189 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
190 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
190 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
191 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
191 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
192 | ToNaviCtrl.Param.Byte[8] = FC_StatusFlags; |
192 | ToNaviCtrl.Param.Byte[8] = FC_StatusFlags; |
193 | //if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) ToNaviCtrl.Param.Byte[8] &= ~FC_STATUS_FLY; |
193 | //if(FC_StatusFlags2 & FC_STATUS2_WAIT_FOR_TAKEOFF) ToNaviCtrl.Param.Byte[8] &= ~FC_STATUS_FLY; |
194 | FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START); |
194 | FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START); |
195 | ToNaviCtrl.Param.Byte[9] = GetActiveParamSet(); |
195 | ToNaviCtrl.Param.Byte[9] = ActiveParamSet; |
196 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.ComingHomeAltitude; |
196 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.ComingHomeAltitude; |
197 | ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2; |
197 | ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2; |
198 | break; |
198 | break; |
199 | 199 | ||
200 | case SPI_FCCMD_ACCU: |
200 | case SPI_FCCMD_ACCU: |
201 | ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A |
201 | ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A |
202 | ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh |
202 | ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh |
203 | ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V |
203 | ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V |
204 | ToNaviCtrl.Param.Byte[5] = (unsigned char) BattLowVoltageWarning; //0.1V |
204 | ToNaviCtrl.Param.Byte[5] = (unsigned char) BattLowVoltageWarning; //0.1V |
205 | ToNaviCtrl.Param.Byte[6] = VarioCharacter; |
205 | ToNaviCtrl.Param.Byte[6] = VarioCharacter; |
206 | ToNaviCtrl.Param.Byte[7] = motorindex; |
206 | ToNaviCtrl.Param.Byte[7] = motorindex; |
207 | ToNaviCtrl.Param.Byte[8] = Motor[motorindex].MaxPWM; |
207 | ToNaviCtrl.Param.Byte[8] = Motor[motorindex].MaxPWM; |
208 | ToNaviCtrl.Param.Byte[9] = Motor[motorindex].State; |
208 | ToNaviCtrl.Param.Byte[9] = Motor[motorindex].State; |
209 | ToNaviCtrl.Param.Byte[10] = Motor[motorindex].Temperature; |
209 | ToNaviCtrl.Param.Byte[10] = Motor[motorindex].Temperature; |
210 | ToNaviCtrl.Param.Byte[11] = Motor[motorindex++].Current; |
210 | ToNaviCtrl.Param.Byte[11] = Motor[motorindex++].Current; |
211 | motorindex %= 12; |
211 | motorindex %= 12; |
212 | break; |
212 | break; |
213 | case SPI_FCCMD_PARAMETER1: |
213 | case SPI_FCCMD_PARAMETER1: |
214 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard |
214 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard |
215 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
215 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
216 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
216 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
217 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
217 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
218 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
218 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
219 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
219 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
220 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
220 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
221 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
221 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
222 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
222 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
223 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
223 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
224 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviAccCompensation; |
224 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviAccCompensation; |
225 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
225 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
226 | break; |
226 | break; |
227 | case SPI_FCCMD_PARAMETER2: |
227 | case SPI_FCCMD_PARAMETER2: |
228 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviOut1Parameter; // Distance between Photo releases |
228 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviOut1Parameter; // Distance between Photo releases |
229 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
229 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
230 | // create the ToNC_SpeakHoTT |
230 | // create the ToNC_SpeakHoTT |
231 | if(EE_Parameter.Receiver != RECEIVER_HOTT) |
231 | if(EE_Parameter.Receiver != RECEIVER_HOTT) |
232 | { |
232 | { |
233 | if(JetiBeep != 'B') JetiBeep = pgm_read_byte(&JETI_CODE[HoTT_Waring()]); |
233 | if(JetiBeep != 'B') JetiBeep = pgm_read_byte(&JETI_CODE[HoTT_Waring()]); |
234 | else HoTT_Waring(); |
234 | else HoTT_Waring(); |
235 | } |
235 | } |
236 | ToNaviCtrl.Param.Byte[1] = ToNC_SpeakHoTT; |
236 | ToNaviCtrl.Param.Byte[1] = ToNC_SpeakHoTT; |
237 | #else |
237 | #else |
238 | ToNaviCtrl.Param.Byte[1] = 0; |
238 | ToNaviCtrl.Param.Byte[1] = 0; |
239 | #endif |
239 | #endif |
240 | break; |
240 | break; |
241 | case SPI_FCCMD_STICK: |
241 | case SPI_FCCMD_STICK: |
242 | cli(); |
242 | cli(); |
243 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
243 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
244 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
244 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
245 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
245 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
246 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
246 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
247 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
247 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
248 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
248 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
249 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
249 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
250 | sei(); |
250 | sei(); |
251 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
251 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
252 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0]; |
252 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0]; |
253 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1]; |
253 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1]; |
254 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2]; |
254 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2]; |
255 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3]; |
255 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3]; |
256 | ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4]; |
256 | ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4]; |
257 | ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5]; |
257 | ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5]; |
258 | ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6]; |
258 | ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6]; |
259 | ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7]; |
259 | ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7]; |
260 | break; |
260 | break; |
261 | case SPI_FCCMD_MISC: |
261 | case SPI_FCCMD_MISC: |
262 | if(WinkelOut.CalcState > 5) |
262 | if(WinkelOut.CalcState > 5) |
263 | { |
263 | { |
264 | WinkelOut.CalcState = 0; |
264 | WinkelOut.CalcState = 0; |
265 | ToNaviCtrl.Param.Byte[0] = 5; |
265 | ToNaviCtrl.Param.Byte[0] = 5; |
266 | } |
266 | } |
267 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
267 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
268 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
268 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
269 | ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); |
269 | ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); |
270 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
270 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
271 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
271 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
272 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
272 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
273 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
273 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
274 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay; |
274 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay; |
275 | ToNaviCtrl.Param.Byte[10] = (unsigned char) PPM_in[0]; |
275 | ToNaviCtrl.Param.Byte[10] = (unsigned char) PPM_in[0]; |
276 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil |
276 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil |
277 | break; |
277 | break; |
278 | case SPI_FCCMD_VERSION: |
278 | case SPI_FCCMD_VERSION: |
279 | ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR; |
279 | ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR; |
280 | ToNaviCtrl.Param.Byte[1] = VERSION_MINOR; |
280 | ToNaviCtrl.Param.Byte[1] = VERSION_MINOR; |
281 | ToNaviCtrl.Param.Byte[2] = VERSION_PATCH; |
281 | ToNaviCtrl.Param.Byte[2] = VERSION_PATCH; |
282 | ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE; |
282 | ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE; |
283 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
283 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
284 | ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0]; |
284 | ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0]; |
285 | ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1]; |
285 | ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1]; |
286 | VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; // VersionInfo.HardwareError[0] = 0; |
286 | VersionInfo.HardwareError[0] &= ~FC_ERROR0_CAREFREE; // VersionInfo.HardwareError[0] = 0; |
287 | VersionInfo.HardwareError[1] &= FC_ERROR1_MIXER; |
287 | VersionInfo.HardwareError[1] &= FC_ERROR1_MIXER; |
288 | ToNaviCtrl.Param.Byte[7] = VersionInfo.HardwareError[2]; // unused |
288 | ToNaviCtrl.Param.Byte[7] = VersionInfo.HardwareError[2]; // unused |
289 | ToNaviCtrl.Param.Byte[8] = Parameter_GlobalConfig; |
289 | ToNaviCtrl.Param.Byte[8] = Parameter_GlobalConfig; |
290 | ToNaviCtrl.Param.Byte[9] = Parameter_ExtraConfig; |
290 | ToNaviCtrl.Param.Byte[9] = Parameter_ExtraConfig; |
291 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle; |
291 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle; |
292 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.GlobalConfig3; |
292 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.GlobalConfig3; |
293 | break; |
293 | break; |
294 | case SPI_FCCMD_SERVOS: |
294 | case SPI_FCCMD_SERVOS: |
295 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
295 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
296 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
296 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
297 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
297 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
298 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
298 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
299 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
299 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
300 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
300 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
301 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
301 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
302 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
302 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
303 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
303 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
304 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
304 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
305 | ToNaviCtrl.Param.Byte[10] = Capacity.MinOfMaxPWM; |
305 | ToNaviCtrl.Param.Byte[10] = Capacity.MinOfMaxPWM; |
306 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[28]; // I2C-Error counter |
306 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[28]; // I2C-Error counter |
307 | break; |
307 | break; |
308 | } |
308 | } |
309 | 309 | ||
310 | if(SPI_RxDataValid) |
310 | if(SPI_RxDataValid) |
311 | { |
311 | { |
312 | if(FromNaviCtrl.Command != oldcommand) NaviDataOkay = 250; |
312 | if(FromNaviCtrl.Command != oldcommand) NaviDataOkay = 250; |
313 | oldcommand = FromNaviCtrl.Command; |
313 | oldcommand = FromNaviCtrl.Command; |
314 | CalculateCompassTimer = 1; |
314 | CalculateCompassTimer = 1; |
315 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
315 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
316 | { |
316 | { |
317 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
317 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
318 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
318 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
319 | } |
319 | } |
320 | 320 | ||
321 | // update compass readings |
321 | // update compass readings |
322 | // MagVec.x = FromNaviCtrl.MagVecX; |
322 | // MagVec.x = FromNaviCtrl.MagVecX; |
323 | // MagVec.y = FromNaviCtrl.MagVecY; |
323 | // MagVec.y = FromNaviCtrl.MagVecY; |
324 | // MagVec.z = FromNaviCtrl.MagVecZ; |
324 | // MagVec.z = FromNaviCtrl.MagVecZ; |
325 | 325 | ||
326 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
326 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
327 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
327 | // KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
328 | 328 | ||
329 | if(FromNaviCtrl.BeepTime > beeptime && !DisableRcOffBeeping) beeptime = FromNaviCtrl.BeepTime; |
329 | if(FromNaviCtrl.BeepTime > beeptime && !DisableRcOffBeeping) beeptime = FromNaviCtrl.BeepTime; |
330 | switch (FromNaviCtrl.Command) |
330 | switch (FromNaviCtrl.Command) |
331 | { |
331 | { |
332 | case SPI_NCCMD_KALMAN: |
332 | case SPI_NCCMD_KALMAN: |
333 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
333 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
334 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
334 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
335 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
335 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
336 | KompassFusion = FromNaviCtrl.Param.sByte[3]; |
336 | KompassFusion = FromNaviCtrl.Param.sByte[3]; |
337 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
337 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
338 | FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5]; |
338 | FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5]; |
339 | FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6]; |
339 | FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6]; |
340 | GPS_Aid_StickMultiplikator = FromNaviCtrl.Param.Byte[7]; |
340 | GPS_Aid_StickMultiplikator = FromNaviCtrl.Param.Byte[7]; |
341 | if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0) |
341 | if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0) |
342 | { |
342 | { |
343 | KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben |
343 | KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben |
344 | if(EE_Parameter.CamOrientation) // Kamera angle is not front |
344 | if(EE_Parameter.CamOrientation) // Kamera angle is not front |
345 | { |
345 | { |
346 | KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15); |
346 | KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15); |
347 | KompassSollWert %= 360; |
347 | KompassSollWert %= 360; |
348 | } |
348 | } |
349 | } |
349 | } |
350 | POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel |
350 | POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel |
351 | break; |
351 | break; |
352 | case SPI_NCCMD_VERSION: |
352 | case SPI_NCCMD_VERSION: |
353 | NC_Version.Major = FromNaviCtrl.Param.Byte[0]; |
353 | NC_Version.Major = FromNaviCtrl.Param.Byte[0]; |
354 | NC_Version.Minor = FromNaviCtrl.Param.Byte[1]; |
354 | NC_Version.Minor = FromNaviCtrl.Param.Byte[1]; |
355 | NC_Version.Patch = FromNaviCtrl.Param.Byte[2]; |
355 | NC_Version.Patch = FromNaviCtrl.Param.Byte[2]; |
356 | NC_Version.Compatible = FromNaviCtrl.Param.Byte[3]; |
356 | NC_Version.Compatible = FromNaviCtrl.Param.Byte[3]; |
357 | NC_Version.Hardware = FromNaviCtrl.Param.Byte[4]; |
357 | NC_Version.Hardware = FromNaviCtrl.Param.Byte[4]; |
358 | DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5]; |
358 | DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5]; |
359 | DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08)); |
359 | DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08)); |
360 | NC_ErrorCode = FromNaviCtrl.Param.Byte[7]; |
360 | NC_ErrorCode = FromNaviCtrl.Param.Byte[7]; |
361 | NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8]; |
361 | NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8]; |
362 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[9]; |
362 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[9]; |
363 | NC_To_FC_Flags = FromNaviCtrl.Param.Byte[10]; |
363 | NC_To_FC_Flags = FromNaviCtrl.Param.Byte[10]; |
364 | NC_To_FC_MaxAltitude = FromNaviCtrl.Param.Byte[11]; |
364 | NC_To_FC_MaxAltitude = FromNaviCtrl.Param.Byte[11]; |
365 | break; |
365 | break; |
366 | case SPI_NCCMD_GPSINFO: |
366 | case SPI_NCCMD_GPSINFO: |
367 | GPSInfo.Flags = FromNaviCtrl.Param.Byte[0]; |
367 | GPSInfo.Flags = FromNaviCtrl.Param.Byte[0]; |
368 | GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1]; |
368 | GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1]; |
369 | GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2]; |
369 | GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2]; |
370 | GPSInfo.Speed = FromNaviCtrl.Param.Byte[3]; |
370 | GPSInfo.Speed = FromNaviCtrl.Param.Byte[3]; |
371 | GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2]; |
371 | GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2]; |
372 | GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3]; |
372 | GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3]; |
373 | PPM_in[25] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value (FromNC_WP_EventChannel) |
373 | PPM_in[25] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value (FromNC_WP_EventChannel) |
374 | FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9]; |
374 | FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9]; |
375 | FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10; // in cm |
375 | FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10; // in cm |
376 | break; |
376 | break; |
377 | case SPI_MISC: |
377 | case SPI_MISC: |
378 | EarthMagneticField = FromNaviCtrl.Param.Byte[0]; |
378 | EarthMagneticField = FromNaviCtrl.Param.Byte[0]; |
379 | EarthMagneticInclination = FromNaviCtrl.Param.Byte[1]; |
379 | EarthMagneticInclination = FromNaviCtrl.Param.Byte[1]; |
380 | EarthMagneticInclinationTheoretic = FromNaviCtrl.Param.Byte[2]; |
380 | EarthMagneticInclinationTheoretic = FromNaviCtrl.Param.Byte[2]; |
381 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
381 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
382 | if(FromNaviCtrl.Param.Byte[3]) |
382 | if(FromNaviCtrl.Param.Byte[3]) |
383 | if(!SpeakHoTT || (SpeakHoTT >= SPEAK_GPS_HOLD && SpeakHoTT <= SPEAK_GPS_OFF)) SpeakHoTT = FromNaviCtrl.Param.Byte[3]; |
383 | if(!SpeakHoTT || (SpeakHoTT >= SPEAK_GPS_HOLD && SpeakHoTT <= SPEAK_GPS_OFF)) SpeakHoTT = FromNaviCtrl.Param.Byte[3]; |
384 | NaviData_WaypointIndex = FromNaviCtrl.Param.Byte[4]; |
384 | NaviData_WaypointIndex = FromNaviCtrl.Param.Byte[4]; |
385 | NaviData_WaypointNumber = FromNaviCtrl.Param.Byte[5]; |
385 | NaviData_WaypointNumber = FromNaviCtrl.Param.Byte[5]; |
386 | NaviData_TargetDistance = FromNaviCtrl.Param.Int[3]; |
386 | NaviData_TargetDistance = FromNaviCtrl.Param.Int[3]; |
387 | NaviData_TargetHoldTime = FromNaviCtrl.Param.Byte[8]; |
387 | NaviData_TargetHoldTime = FromNaviCtrl.Param.Byte[8]; |
388 | #endif |
388 | #endif |
389 | break; |
389 | break; |
390 | 390 | ||
391 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
391 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
392 | case SPI_NCCMD_HOTT_DATA: |
392 | case SPI_NCCMD_HOTT_DATA: |
393 | if(EE_Parameter.Receiver == RECEIVER_HOTT) NC_Fills_HoTT_Telemety(); |
393 | if(EE_Parameter.Receiver == RECEIVER_HOTT) NC_Fills_HoTT_Telemety(); |
394 | break; |
394 | break; |
395 | #endif |
395 | #endif |
396 | 396 | ||
397 | // 0 = 0,1 |
397 | // 0 = 0,1 |
398 | // 1 = 2,3 |
398 | // 1 = 2,3 |
399 | // 2 = 4,5 |
399 | // 2 = 4,5 |
400 | // 3 = 6,7 |
400 | // 3 = 6,7 |
401 | // 4 = 8,9 |
401 | // 4 = 8,9 |
402 | // 5 = 10,11 |
402 | // 5 = 10,11 |
403 | default: |
403 | default: |
404 | break; |
404 | break; |
405 | } |
405 | } |
406 | } |
406 | } |
407 | else |
407 | else |
408 | { |
408 | { |
409 | // KompassValue = 0; |
409 | // KompassValue = 0; |
410 | // KompassRichtung = 0; |
410 | // KompassRichtung = 0; |
411 | GPS_Nick = 0; |
411 | GPS_Nick = 0; |
412 | GPS_Roll = 0; |
412 | GPS_Roll = 0; |
413 | } |
413 | } |
414 | } |
414 | } |
415 | 415 | ||
416 | #endif |
416 | #endif |
417 | 417 | ||
418 | 418 | ||
419 | 419 |