Rev 1378 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1378 | Rev 1476 | ||
---|---|---|---|
1 | // ######################## SPI - FlightCtrl ################### |
1 | // ######################## SPI - FlightCtrl ################### |
2 | #include "main.h" |
2 | #include "main.h" |
3 | 3 | ||
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 SPI_VersionInfo; |
10 | struct str_SPI_VersionInfo SPI_VersionInfo; |
11 | 11 | ||
12 | unsigned char SPI_BufferIndex; |
12 | unsigned char SPI_BufferIndex; |
13 | unsigned char SPI_RxBufferIndex; |
13 | unsigned char SPI_RxBufferIndex; |
14 | 14 | ||
15 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
15 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
16 | unsigned char *SPI_TX_Buffer; |
16 | unsigned char *SPI_TX_Buffer; |
17 | 17 | ||
18 | unsigned char SPITransferCompleted, SPI_ChkSum; |
18 | unsigned char SPITransferCompleted, SPI_ChkSum; |
19 | unsigned char SPI_RxDataValid,NaviDataOkay = 0; |
19 | unsigned char SPI_RxDataValid,NaviDataOkay = 0; |
20 | 20 | ||
21 | unsigned char SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_MISC, SPI_CMD_VERSION, SPI_CMD_SERVOS }; |
21 | unsigned char SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_MISC, SPI_CMD_VERSION, SPI_CMD_SERVOS }; |
22 | unsigned char SPI_CommandCounter = 0; |
22 | unsigned char SPI_CommandCounter = 0; |
23 | 23 | ||
24 | #ifdef USE_SPI_COMMUNICATION |
24 | #ifdef USE_SPI_COMMUNICATION |
25 | 25 | ||
26 | //------------------------------------------------------ |
26 | //------------------------------------------------------ |
27 | void SPI_MasterInit(void) |
27 | void SPI_MasterInit(void) |
28 | { |
28 | { |
29 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
29 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
30 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
30 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
31 | 31 | ||
32 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
32 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
33 | SPSR = 0;//(1<<SPI2X); |
33 | SPSR = 0;//(1<<SPI2X); |
34 | 34 | ||
35 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
35 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
36 | SPITransferCompleted = 1; |
36 | SPITransferCompleted = 1; |
37 | 37 | ||
38 | //SPDR = 0x00; // dummy write |
38 | //SPDR = 0x00; // dummy write |
39 | 39 | ||
40 | ToNaviCtrl.Sync1 = 0xAA; |
40 | ToNaviCtrl.Sync1 = 0xAA; |
41 | ToNaviCtrl.Sync2 = 0x83; |
41 | ToNaviCtrl.Sync2 = 0x83; |
42 | 42 | ||
43 | ToNaviCtrl.Command = SPI_CMD_USER; |
43 | ToNaviCtrl.Command = SPI_CMD_USER; |
44 | ToNaviCtrl.IntegralNick = 0; |
44 | ToNaviCtrl.IntegralNick = 0; |
45 | ToNaviCtrl.IntegralRoll = 0; |
45 | ToNaviCtrl.IntegralRoll = 0; |
46 | FromNaviCtrl_Value.SerialDataOkay = 0; |
46 | FromNaviCtrl_Value.SerialDataOkay = 0; |
47 | SPI_RxDataValid = 0; |
47 | SPI_RxDataValid = 0; |
48 | 48 | ||
49 | SPI_VersionInfo.Major = VERSION_MAJOR; |
49 | SPI_VersionInfo.Major = VERSION_MAJOR; |
50 | SPI_VersionInfo.Minor = VERSION_MINOR; |
50 | SPI_VersionInfo.Minor = VERSION_MINOR; |
51 | SPI_VersionInfo.Patch = VERSION_PATCH; |
51 | SPI_VersionInfo.Patch = VERSION_PATCH; |
52 | SPI_VersionInfo.Compatible = NC_SPI_COMPATIBLE; |
52 | SPI_VersionInfo.Compatible = NC_SPI_COMPATIBLE; |
53 | } |
53 | } |
54 | 54 | ||
55 | //------------------------------------------------------ |
55 | //------------------------------------------------------ |
56 | void SPI_StartTransmitPacket(void) |
56 | void SPI_StartTransmitPacket(void) |
57 | { |
57 | { |
58 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
58 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
59 | if (!SPITransferCompleted) return; |
59 | if (!SPITransferCompleted) return; |
60 | // _delay_us(30); |
60 | // _delay_us(30); |
61 | 61 | ||
62 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
62 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
63 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
63 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
64 | 64 | ||
65 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
65 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
66 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
66 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
67 | 67 | ||
68 | SPITransferCompleted = 0; |
68 | SPITransferCompleted = 0; |
69 | UpdateSPI_Buffer(); // update buffer |
69 | UpdateSPI_Buffer(); // update buffer |
70 | 70 | ||
71 | SPI_BufferIndex = 1; |
71 | SPI_BufferIndex = 1; |
72 | //ebugOut.Analog[16]++; |
72 | //ebugOut.Analog[16]++; |
73 | // -- Debug-Output --- |
73 | // -- Debug-Output --- |
74 | //---- |
74 | //---- |
75 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
75 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
76 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
76 | 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"); |
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 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
78 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
79 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
79 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
80 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
80 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
81 | 81 | ||
82 | } |
82 | } |
83 | 83 | ||
84 | //------------------------------------------------------ |
84 | //------------------------------------------------------ |
85 | //SIGNAL(SIG_SPI) |
85 | //SIGNAL(SIG_SPI) |
86 | void SPI_TransmitByte(void) |
86 | void SPI_TransmitByte(void) |
87 | { |
87 | { |
88 | static unsigned char SPI_RXState = 0; |
88 | static unsigned char SPI_RXState = 0; |
89 | unsigned char rxdata; |
89 | unsigned char rxdata; |
90 | static unsigned char rxchksum; |
90 | static unsigned char rxchksum; |
91 | 91 | ||
92 | if (SPITransferCompleted) return; |
92 | if (SPITransferCompleted) return; |
93 | if (!(SPSR & (1 << SPIF))) return; |
93 | if (!(SPSR & (1 << SPIF))) return; |
94 | SendSPI = 4; |
94 | SendSPI = 4; |
95 | 95 | ||
96 | // _delay_us(30); |
96 | // _delay_us(30); |
97 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
97 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
98 | 98 | ||
99 | rxdata = SPDR; |
99 | rxdata = SPDR; |
100 | switch ( SPI_RXState) |
100 | switch ( SPI_RXState) |
101 | { |
101 | { |
102 | case 0: |
102 | case 0: |
103 | 103 | ||
104 | SPI_RxBufferIndex = 0; |
104 | SPI_RxBufferIndex = 0; |
105 | //DebugOut.Analog[17]++; |
105 | //DebugOut.Analog[17]++; |
106 | rxchksum = rxdata; |
106 | rxchksum = rxdata; |
107 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
107 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
108 | 108 | ||
109 | break; |
109 | break; |
110 | 110 | ||
111 | case 1: |
111 | case 1: |
112 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
112 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
113 | else SPI_RXState = 0; |
113 | else SPI_RXState = 0; |
114 | //DebugOut.Analog[18]++; |
114 | //DebugOut.Analog[18]++; |
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 | 126 | ||
127 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
127 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
128 | 128 | ||
129 | SPI_RxDataValid = 1; |
129 | SPI_RxDataValid = 1; |
130 | } |
130 | } |
131 | else SPI_RxDataValid = 0; |
131 | else SPI_RxDataValid = 0; |
132 | 132 | ||
133 | SPI_RXState = 0; |
133 | SPI_RXState = 0; |
134 | } |
134 | } |
135 | else rxchksum += rxdata; |
135 | else rxchksum += rxdata; |
136 | break; |
136 | break; |
137 | 137 | ||
138 | } |
138 | } |
139 | 139 | ||
140 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
140 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
141 | { |
141 | { |
142 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
142 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
143 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
143 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
144 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
144 | 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"); |
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 | 146 | ||
147 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
147 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
148 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
148 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
149 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
149 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
150 | 150 | ||
151 | } |
151 | } |
152 | else SPITransferCompleted = 1; |
152 | else SPITransferCompleted = 1; |
153 | 153 | ||
154 | SPI_BufferIndex++; |
154 | SPI_BufferIndex++; |
155 | } |
155 | } |
156 | 156 | ||
157 | 157 | ||
158 | //------------------------------------------------------ |
158 | //------------------------------------------------------ |
159 | void UpdateSPI_Buffer(void) |
159 | void UpdateSPI_Buffer(void) |
160 | { |
160 | { |
161 | signed int tmp; |
161 | signed int tmp; |
162 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
162 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
163 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
163 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
164 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
164 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
165 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
165 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
166 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
166 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
167 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
167 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
168 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
168 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
169 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
169 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
170 | switch(ToNaviCtrl.Command) // |
170 | switch(ToNaviCtrl.Command) // |
171 | { |
171 | { |
172 | case SPI_CMD_USER: |
172 | case SPI_CMD_USER: |
173 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
173 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
174 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
174 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
175 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
175 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
176 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
176 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
177 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
177 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
178 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
178 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
179 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
179 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
180 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
180 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
181 | ToNaviCtrl.Param.Byte[8] = (unsigned char) MikroKopterFlags; |
181 | ToNaviCtrl.Param.Byte[8] = (unsigned char) MikroKopterFlags; |
182 | MikroKopterFlags &= ~(FLAG_CALIBRATE | FLAG_START); |
182 | MikroKopterFlags &= ~(FLAG_CALIBRATE | FLAG_START); |
183 | ToNaviCtrl.Param.Byte[9] = (unsigned char) UBat; |
183 | ToNaviCtrl.Param.Byte[9] = (unsigned char) UBat; |
184 | ToNaviCtrl.Param.Byte[10] =(unsigned char) BattLowVoltageWarning; |
184 | ToNaviCtrl.Param.Byte[10] =(unsigned char) BattLowVoltageWarning; |
185 | ToNaviCtrl.Param.Byte[11] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
185 | ToNaviCtrl.Param.Byte[11] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
186 | break; |
186 | break; |
187 | 187 | ||
188 | case SPI_CMD_PARAMETER1: |
188 | case SPI_CMD_PARAMETER1: |
189 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard |
189 | //ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard // MartinR: so war es |
- | 190 | ToNaviCtrl.Param.Byte[0] = Parameter_NaviGpsModeControl; // MartinR: wird wiederverwendet für GPS free bei HH |
|
- | 191 | ||
190 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
192 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
191 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
193 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
192 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
194 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
193 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
195 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
194 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
196 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
195 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
197 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
196 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
198 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
197 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
199 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
198 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
200 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
199 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation; |
201 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation; |
200 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
202 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
201 | break; |
203 | break; |
202 | 204 | ||
203 | case SPI_CMD_STICK: |
205 | case SPI_CMD_STICK: |
204 | cli(); |
206 | cli(); |
205 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
207 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
206 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
208 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
207 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
209 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
208 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
210 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
209 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
211 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
210 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
212 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
211 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
213 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
212 | sei(); |
214 | sei(); |
213 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
215 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
214 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti1; |
216 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti1; |
215 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti2; |
217 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti2; |
216 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti3; |
218 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti3; |
217 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti4; |
219 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti4; |
218 | ToNaviCtrl.Param.Byte[8] = (unsigned char) SenderOkay; |
220 | ToNaviCtrl.Param.Byte[8] = (unsigned char) SenderOkay; |
219 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderRSSI; |
221 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderRSSI; |
220 | ToNaviCtrl.Param.Byte[10] = DebugOut.Analog[7] / 4; //GasMischanteil |
222 | ToNaviCtrl.Param.Byte[10] = DebugOut.Analog[7] / 4; //GasMischanteil |
221 | break; |
223 | break; |
222 | case SPI_CMD_MISC: |
224 | case SPI_CMD_MISC: |
223 | if(WinkelOut.CalcState > 5) |
225 | if(WinkelOut.CalcState > 5) |
224 | { |
226 | { |
225 | WinkelOut.CalcState = 0; |
227 | WinkelOut.CalcState = 0; |
226 | ToNaviCtrl.Param.Byte[0] = 5; |
228 | ToNaviCtrl.Param.Byte[0] = 5; |
227 | } |
229 | } |
228 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
230 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
229 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
231 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
230 | ToNaviCtrl.Param.Int[1] = DebugOut.Analog[5];// = HoehenWert/5; |
232 | ToNaviCtrl.Param.Int[1] = DebugOut.Analog[5];// = HoehenWert/5; |
231 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
233 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
232 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
234 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
233 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
235 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
234 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
236 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
235 | break; |
237 | break; |
236 | 238 | ||
237 | case SPI_CMD_VERSION: |
239 | case SPI_CMD_VERSION: |
238 | ToNaviCtrl.Param.Byte[0] = SPI_VersionInfo.Major; |
240 | ToNaviCtrl.Param.Byte[0] = SPI_VersionInfo.Major; |
239 | ToNaviCtrl.Param.Byte[1] = SPI_VersionInfo.Minor; |
241 | ToNaviCtrl.Param.Byte[1] = SPI_VersionInfo.Minor; |
240 | ToNaviCtrl.Param.Byte[2] = SPI_VersionInfo.Patch; |
242 | ToNaviCtrl.Param.Byte[2] = SPI_VersionInfo.Patch; |
241 | ToNaviCtrl.Param.Byte[3] = SPI_VersionInfo.Compatible; |
243 | ToNaviCtrl.Param.Byte[3] = SPI_VersionInfo.Compatible; |
242 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
244 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
243 | break; |
245 | break; |
244 | 246 | ||
245 | case SPI_CMD_SERVOS: |
247 | case SPI_CMD_SERVOS: |
246 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
248 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
247 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
249 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
248 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
250 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
249 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
251 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
250 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
252 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
251 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
253 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
252 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
254 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
253 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
255 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
254 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
256 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
255 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
257 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
256 | break; |
258 | break; |
257 | } |
259 | } |
258 | 260 | ||
259 | if(SPI_RxDataValid) |
261 | if(SPI_RxDataValid) |
260 | { |
262 | { |
261 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
263 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
262 | { |
264 | { |
263 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
265 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
264 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
266 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
265 | NaviDataOkay = 250; |
267 | NaviDataOkay = 250; |
266 | } |
268 | } |
267 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
269 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
268 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
270 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
269 | 271 | ||
270 | if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime; |
272 | if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime; |
271 | 273 | ||
272 | switch (FromNaviCtrl.Command) |
274 | switch (FromNaviCtrl.Command) |
273 | { |
275 | { |
274 | case SPI_KALMAN: |
276 | case SPI_KALMAN: |
275 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
277 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
276 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
278 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
277 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
279 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
278 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3]; |
280 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3]; |
279 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
281 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
280 | break; |
282 | break; |
281 | 283 | ||
282 | default: |
284 | default: |
283 | break; |
285 | break; |
284 | } |
286 | } |
285 | } |
287 | } |
286 | else |
288 | else |
287 | { |
289 | { |
288 | // KompassValue = 0; |
290 | // KompassValue = 0; |
289 | // KompassRichtung = 0; |
291 | // KompassRichtung = 0; |
290 | GPS_Nick = 0; |
292 | GPS_Nick = 0; |
291 | GPS_Roll = 0; |
293 | GPS_Roll = 0; |
292 | } |
294 | } |
293 | } |
295 | } |
294 | 296 | ||
295 | #endif |
297 | #endif |
296 | 298 | ||
297 | 299 | ||
298 | 300 |