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