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