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