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