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