Rev 1916 | Rev 1936 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1916 | Rev 1920 | ||
---|---|---|---|
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 | unsigned char NC_GPS_ModeCharacter = ' '; |
|
27 | signed int POI_KameraNick = 0; // in 0,1° |
28 | signed int POI_KameraNick = 0; // in 0,1° |
28 | vector16_t MagVec = {0,0,0}; |
29 | vector16_t MagVec = {0,0,0}; |
29 | 30 | ||
30 | #ifdef USE_SPI_COMMUNICATION |
31 | #ifdef USE_SPI_COMMUNICATION |
31 | 32 | ||
32 | //------------------------------------------------------ |
33 | //------------------------------------------------------ |
33 | void SPI_MasterInit(void) |
34 | void SPI_MasterInit(void) |
34 | { |
35 | { |
35 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
36 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
36 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
37 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
37 | 38 | ||
38 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
39 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
39 | SPSR = 0;//(1<<SPI2X); |
40 | SPSR = 0;//(1<<SPI2X); |
40 | 41 | ||
41 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
42 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
42 | SPITransferCompleted = 1; |
43 | SPITransferCompleted = 1; |
43 | 44 | ||
44 | //SPDR = 0x00; // dummy write |
45 | //SPDR = 0x00; // dummy write |
45 | 46 | ||
46 | ToNaviCtrl.Sync1 = 0xAA; |
47 | ToNaviCtrl.Sync1 = 0xAA; |
47 | ToNaviCtrl.Sync2 = 0x83; |
48 | ToNaviCtrl.Sync2 = 0x83; |
48 | 49 | ||
49 | ToNaviCtrl.Command = SPI_FCCMD_USER; |
50 | ToNaviCtrl.Command = SPI_FCCMD_USER; |
50 | ToNaviCtrl.IntegralNick = 0; |
51 | ToNaviCtrl.IntegralNick = 0; |
51 | ToNaviCtrl.IntegralRoll = 0; |
52 | ToNaviCtrl.IntegralRoll = 0; |
52 | FromNaviCtrl_Value.SerialDataOkay = 0; |
53 | FromNaviCtrl_Value.SerialDataOkay = 0; |
53 | SPI_RxDataValid = 0; |
54 | SPI_RxDataValid = 0; |
54 | 55 | ||
55 | } |
56 | } |
56 | 57 | ||
57 | //------------------------------------------------------ |
58 | //------------------------------------------------------ |
58 | void SPI_StartTransmitPacket(void) |
59 | void SPI_StartTransmitPacket(void) |
59 | { |
60 | { |
60 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
61 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
61 | if (!SPITransferCompleted) return; |
62 | if (!SPITransferCompleted) return; |
62 | // _delay_us(30); |
63 | // _delay_us(30); |
63 | 64 | ||
64 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
65 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
65 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
66 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
66 | 67 | ||
67 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
68 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
68 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
69 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
69 | 70 | ||
70 | SPITransferCompleted = 0; |
71 | SPITransferCompleted = 0; |
71 | UpdateSPI_Buffer(); // update buffer |
72 | UpdateSPI_Buffer(); // update buffer |
72 | 73 | ||
73 | SPI_BufferIndex = 1; |
74 | SPI_BufferIndex = 1; |
74 | //ebugOut.Analog[16]++; |
75 | //ebugOut.Analog[16]++; |
75 | // -- Debug-Output --- |
76 | // -- Debug-Output --- |
76 | //---- |
77 | //---- |
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 | 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 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
79 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
79 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
80 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
80 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
81 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
81 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
82 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
82 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
83 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
83 | 84 | ||
84 | } |
85 | } |
85 | 86 | ||
86 | //------------------------------------------------------ |
87 | //------------------------------------------------------ |
87 | //SIGNAL(SIG_SPI) |
88 | //SIGNAL(SIG_SPI) |
88 | void SPI_TransmitByte(void) |
89 | void SPI_TransmitByte(void) |
89 | { |
90 | { |
90 | static unsigned char SPI_RXState = 0; |
91 | static unsigned char SPI_RXState = 0; |
91 | unsigned char rxdata; |
92 | unsigned char rxdata; |
92 | static unsigned char rxchksum; |
93 | static unsigned char rxchksum; |
93 | 94 | ||
94 | if (SPITransferCompleted) return; |
95 | if (SPITransferCompleted) return; |
95 | if (!(SPSR & (1 << SPIF))) return; |
96 | if (!(SPSR & (1 << SPIF))) return; |
96 | SendSPI = 4; |
97 | SendSPI = 4; |
97 | 98 | ||
98 | // _delay_us(30); |
99 | // _delay_us(30); |
99 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
100 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
100 | 101 | ||
101 | rxdata = SPDR; |
102 | rxdata = SPDR; |
102 | switch ( SPI_RXState) |
103 | switch ( SPI_RXState) |
103 | { |
104 | { |
104 | case 0: |
105 | case 0: |
105 | 106 | ||
106 | SPI_RxBufferIndex = 0; |
107 | SPI_RxBufferIndex = 0; |
107 | rxchksum = rxdata; |
108 | rxchksum = rxdata; |
108 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
109 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
109 | 110 | ||
110 | break; |
111 | break; |
111 | 112 | ||
112 | case 1: |
113 | case 1: |
113 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
114 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
114 | else SPI_RXState = 0; |
115 | else SPI_RXState = 0; |
115 | break; |
116 | break; |
116 | 117 | ||
117 | case 2: |
118 | case 2: |
118 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
119 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
119 | //DebugOut.Analog[19]++; |
120 | //DebugOut.Analog[19]++; |
120 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
121 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
121 | { |
122 | { |
122 | 123 | ||
123 | if (rxdata == rxchksum) |
124 | if (rxdata == rxchksum) |
124 | { |
125 | { |
125 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
126 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
126 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
127 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
127 | SPI_RxDataValid = 1; |
128 | SPI_RxDataValid = 1; |
128 | } |
129 | } |
129 | else |
130 | else |
130 | { |
131 | { |
131 | SPI_RxDataValid = 0; |
132 | SPI_RxDataValid = 0; |
132 | } |
133 | } |
133 | 134 | ||
134 | 135 | ||
135 | SPI_RXState = 0; |
136 | SPI_RXState = 0; |
136 | } |
137 | } |
137 | else rxchksum += rxdata; |
138 | else rxchksum += rxdata; |
138 | break; |
139 | break; |
139 | 140 | ||
140 | } |
141 | } |
141 | 142 | ||
142 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
143 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
143 | { |
144 | { |
144 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
145 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
145 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
146 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
146 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
147 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
147 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
148 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
148 | 149 | ||
149 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
150 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
150 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
151 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
151 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
152 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
152 | 153 | ||
153 | } |
154 | } |
154 | else SPITransferCompleted = 1; |
155 | else SPITransferCompleted = 1; |
155 | 156 | ||
156 | SPI_BufferIndex++; |
157 | SPI_BufferIndex++; |
157 | } |
158 | } |
158 | 159 | ||
159 | 160 | ||
160 | //------------------------------------------------------ |
161 | //------------------------------------------------------ |
161 | void UpdateSPI_Buffer(void) |
162 | void UpdateSPI_Buffer(void) |
162 | { |
163 | { |
163 | signed int tmp; |
164 | signed int tmp; |
164 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
165 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / (long)(EE_Parameter.GyroAccFaktor * 4)); |
165 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
166 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / (long)(EE_Parameter.GyroAccFaktor * 4)); |
166 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
167 | ToNaviCtrl.GyroCompass = (10 * ErsatzKompass) / GIER_GRAD_FAKTOR; |
167 | ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier; |
168 | ToNaviCtrl.GyroGier = (signed int) AdNeutralGier - AdWertGier; |
168 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
169 | ToNaviCtrl.AccNick = ((int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc))/4; |
169 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
170 | ToNaviCtrl.AccRoll = ((int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc))/4; |
170 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
171 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
171 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
172 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
172 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
173 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
173 | switch(ToNaviCtrl.Command) // |
174 | switch(ToNaviCtrl.Command) // |
174 | { |
175 | { |
175 | case SPI_FCCMD_USER: |
176 | case SPI_FCCMD_USER: |
176 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
177 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
177 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
178 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
178 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
179 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
179 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
180 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
180 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
181 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
181 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
182 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
182 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
183 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
183 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
184 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
184 | ToNaviCtrl.Param.Byte[8] = FC_StatusFlags; |
185 | ToNaviCtrl.Param.Byte[8] = FC_StatusFlags; |
185 | FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START); |
186 | FC_StatusFlags &= ~(FC_STATUS_CALIBRATE | FC_STATUS_START); |
186 | ToNaviCtrl.Param.Byte[9] = GetActiveParamSet(); |
187 | ToNaviCtrl.Param.Byte[9] = GetActiveParamSet(); |
187 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.ComingHomeAltitude; |
188 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.ComingHomeAltitude; |
188 | ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2; |
189 | ToNaviCtrl.Param.Byte[11] = FC_StatusFlags2; |
189 | break; |
190 | break; |
190 | 191 | ||
191 | case SPI_FCCMD_ACCU: |
192 | case SPI_FCCMD_ACCU: |
192 | ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A |
193 | ToNaviCtrl.Param.Int[0] = Capacity.ActualCurrent; // 0.1A |
193 | ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh |
194 | ToNaviCtrl.Param.Int[1] = Capacity.UsedCapacity; // mAh |
194 | ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V |
195 | ToNaviCtrl.Param.Byte[4] = (unsigned char) UBat; // 0.1V |
195 | ToNaviCtrl.Param.Byte[5] = (unsigned char) BattLowVoltageWarning; //0.1V |
196 | ToNaviCtrl.Param.Byte[5] = (unsigned char) BattLowVoltageWarning; //0.1V |
196 | ToNaviCtrl.Param.Byte[6] = VarioCharacter; |
197 | ToNaviCtrl.Param.Byte[6] = VarioCharacter; |
197 | ToNaviCtrl.Param.Byte[7] = Parameter_GlobalConfig; |
198 | ToNaviCtrl.Param.Byte[7] = Parameter_GlobalConfig; |
198 | ToNaviCtrl.Param.Byte[8] = Parameter_ExtraConfig; |
199 | ToNaviCtrl.Param.Byte[8] = Parameter_ExtraConfig; |
199 | break; |
200 | break; |
200 | 201 | ||
201 | case SPI_FCCMD_PARAMETER1: |
202 | case SPI_FCCMD_PARAMETER1: |
202 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard |
203 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.NaviGpsModeControl; // Parameters for the Naviboard |
203 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
204 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviGpsGain; |
204 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
205 | ToNaviCtrl.Param.Byte[2] = EE_Parameter.NaviGpsP; |
205 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
206 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.NaviGpsI; |
206 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
207 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.NaviGpsD; |
207 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
208 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.NaviGpsACC; |
208 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
209 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
209 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
210 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
210 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
211 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviOperatingRadius; |
211 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
212 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.NaviWindCorrection; |
212 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation; |
213 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.NaviSpeedCompensation; |
213 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
214 | ToNaviCtrl.Param.Byte[11] = EE_Parameter.NaviAngleLimitation; |
214 | break; |
215 | break; |
215 | 216 | ||
216 | case SPI_FCCMD_STICK: |
217 | case SPI_FCCMD_STICK: |
217 | cli(); |
218 | cli(); |
218 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
219 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
219 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
220 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
220 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
221 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
221 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
222 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
222 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
223 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
223 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
224 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
224 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
225 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
225 | sei(); |
226 | sei(); |
226 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
227 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
227 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0]; |
228 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti[0]; |
228 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1]; |
229 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti[1]; |
229 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2]; |
230 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti[2]; |
230 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3]; |
231 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti[3]; |
231 | ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4]; |
232 | ToNaviCtrl.Param.Byte[8] = (unsigned char) Poti[4]; |
232 | ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5]; |
233 | ToNaviCtrl.Param.Byte[9] = (unsigned char) Poti[5]; |
233 | ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6]; |
234 | ToNaviCtrl.Param.Byte[10] = (unsigned char) Poti[6]; |
234 | ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7]; |
235 | ToNaviCtrl.Param.Byte[11] = (unsigned char) Poti[7]; |
235 | break; |
236 | break; |
236 | case SPI_FCCMD_MISC: |
237 | case SPI_FCCMD_MISC: |
237 | if(WinkelOut.CalcState > 5) |
238 | if(WinkelOut.CalcState > 5) |
238 | { |
239 | { |
239 | WinkelOut.CalcState = 0; |
240 | WinkelOut.CalcState = 0; |
240 | ToNaviCtrl.Param.Byte[0] = 5; |
241 | ToNaviCtrl.Param.Byte[0] = 5; |
241 | } |
242 | } |
242 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
243 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
243 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
244 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.NaviPH_LoginTime; |
244 | ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); |
245 | ToNaviCtrl.Param.Int[1] = (int)(HoehenWert/5); |
245 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
246 | ToNaviCtrl.Param.Int[2] = (int)(SollHoehe/5); |
246 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
247 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsPLimit; |
247 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
248 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviGpsILimit; |
248 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
249 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.NaviGpsDLimit; |
249 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay; |
250 | ToNaviCtrl.Param.Byte[9] = (unsigned char) SenderOkay; |
250 | ToNaviCtrl.Param.Byte[10] = (unsigned char) PPM_in[0]; |
251 | ToNaviCtrl.Param.Byte[10] = (unsigned char) PPM_in[0]; |
251 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil |
252 | ToNaviCtrl.Param.Byte[11] = DebugOut.Analog[7] / 4; //GasMischanteil |
252 | break; |
253 | break; |
253 | case SPI_FCCMD_VERSION: |
254 | case SPI_FCCMD_VERSION: |
254 | ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR; |
255 | ToNaviCtrl.Param.Byte[0] = VERSION_MAJOR; |
255 | ToNaviCtrl.Param.Byte[1] = VERSION_MINOR; |
256 | ToNaviCtrl.Param.Byte[1] = VERSION_MINOR; |
256 | ToNaviCtrl.Param.Byte[2] = VERSION_PATCH; |
257 | ToNaviCtrl.Param.Byte[2] = VERSION_PATCH; |
257 | ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE; |
258 | ToNaviCtrl.Param.Byte[3] = NC_SPI_COMPATIBLE; |
258 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
259 | ToNaviCtrl.Param.Byte[4] = PlatinenVersion; |
259 | ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0]; |
260 | ToNaviCtrl.Param.Byte[5] = VersionInfo.HardwareError[0]; |
260 | ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1]; |
261 | ToNaviCtrl.Param.Byte[6] = VersionInfo.HardwareError[1]; |
261 | ToNaviCtrl.Param.Byte[7] = VersionInfo.HardwareError[2]; |
262 | ToNaviCtrl.Param.Byte[7] = VersionInfo.HardwareError[2]; |
262 | ToNaviCtrl.Param.Byte[8] = VersionInfo.HardwareError[3]; |
263 | ToNaviCtrl.Param.Byte[8] = VersionInfo.HardwareError[3]; |
263 | ToNaviCtrl.Param.Byte[9] = VersionInfo.HardwareError[4]; |
264 | ToNaviCtrl.Param.Byte[9] = VersionInfo.HardwareError[4]; |
264 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle; |
265 | ToNaviCtrl.Param.Byte[10] = EE_Parameter.OrientationAngle; |
265 | break; |
266 | break; |
266 | case SPI_FCCMD_SERVOS: |
267 | case SPI_FCCMD_SERVOS: |
267 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
268 | ToNaviCtrl.Param.Byte[0] = EE_Parameter.ServoNickRefresh; // Parameters for the Servo Control |
268 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
269 | ToNaviCtrl.Param.Byte[1] = EE_Parameter.ServoCompInvert; |
269 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
270 | ToNaviCtrl.Param.Byte[2] = Parameter_ServoNickControl; |
270 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
271 | ToNaviCtrl.Param.Byte[3] = EE_Parameter.ServoNickComp; |
271 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
272 | ToNaviCtrl.Param.Byte[4] = EE_Parameter.ServoNickMin; |
272 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
273 | ToNaviCtrl.Param.Byte[5] = EE_Parameter.ServoNickMax; |
273 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
274 | ToNaviCtrl.Param.Byte[6] = Parameter_ServoRollControl; |
274 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
275 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.ServoRollComp; |
275 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
276 | ToNaviCtrl.Param.Byte[8] = EE_Parameter.ServoRollMin; |
276 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
277 | ToNaviCtrl.Param.Byte[9] = EE_Parameter.ServoRollMax; |
277 | break; |
278 | break; |
278 | } |
279 | } |
279 | 280 | ||
280 | if(SPI_RxDataValid) |
281 | if(SPI_RxDataValid) |
281 | { |
282 | { |
282 | NaviDataOkay = 250; |
283 | NaviDataOkay = 250; |
283 | CalculateCompassTimer = 1; |
284 | CalculateCompassTimer = 1; |
284 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
285 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
285 | { |
286 | { |
286 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
287 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
287 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
288 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
288 | } |
289 | } |
289 | 290 | ||
290 | // update compass readings |
291 | // update compass readings |
291 | MagVec.x = FromNaviCtrl.MagVecX; |
292 | MagVec.x = FromNaviCtrl.MagVecX; |
292 | MagVec.y = FromNaviCtrl.MagVecY; |
293 | MagVec.y = FromNaviCtrl.MagVecY; |
293 | MagVec.z = FromNaviCtrl.MagVecZ; |
294 | MagVec.z = FromNaviCtrl.MagVecZ; |
294 | 295 | ||
295 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
296 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
296 | KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
297 | KompassRichtung = ((540 + KompassValue - KompassSollWert) % 360) - 180; |
297 | 298 | ||
298 | if(FromNaviCtrl.BeepTime > beeptime /*&& !WinkelOut.CalcState*/) beeptime = FromNaviCtrl.BeepTime; |
299 | if(FromNaviCtrl.BeepTime > beeptime /*&& !WinkelOut.CalcState*/) beeptime = FromNaviCtrl.BeepTime; |
299 | #define FLAG_GPS_AID 0x01 |
300 | #define FLAG_GPS_AID 0x01 |
300 | switch (FromNaviCtrl.Command) |
301 | switch (FromNaviCtrl.Command) |
301 | { |
302 | { |
302 | case SPI_NCCMD_KALMAN: |
303 | case SPI_NCCMD_KALMAN: |
303 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
304 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.sByte[0]; |
304 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
305 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.sByte[1]; |
305 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
306 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.sByte[2]; |
306 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3]; |
307 | FromNaviCtrl_Value.SerialDataOkay = FromNaviCtrl.Param.Byte[3]; |
307 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
308 | FromNaviCtrl_Value.GpsZ = FromNaviCtrl.Param.Byte[4]; |
308 | FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5]; |
309 | FromNC_Rotate_C = FromNaviCtrl.Param.Byte[5]; |
309 | FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6]; |
310 | FromNC_Rotate_S = FromNaviCtrl.Param.Byte[6]; |
310 | if(FromNaviCtrl.Param.Byte[7] & FLAG_GPS_AID) GPS_AidMode = 1; else GPS_AidMode = 0; |
311 | if(FromNaviCtrl.Param.Byte[7] & FLAG_GPS_AID) GPS_AidMode = 1; else GPS_AidMode = 0; |
311 | if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0) |
312 | if(CareFree && FromNaviCtrl.Param.sInt[4] >= 0) |
312 | { |
313 | { |
313 | KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben |
314 | KompassSollWert = FromNaviCtrl.Param.sInt[4]; // bei Carefree kann NC den Kompass-Sollwinkel vorgeben |
314 | if(EE_Parameter.CamOrientation) // Kamera angle is not front |
315 | if(EE_Parameter.CamOrientation) // Kamera angle is not front |
315 | { |
316 | { |
316 | KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15); |
317 | KompassSollWert += 360 - ((unsigned int) EE_Parameter.CamOrientation * 15); |
317 | KompassSollWert %= 360; |
318 | KompassSollWert %= 360; |
318 | } |
319 | } |
319 | } |
320 | } |
320 | POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel |
321 | POI_KameraNick = (POI_KameraNick + FromNaviCtrl.Param.sInt[5]) / 2; // FromNaviCtrl.Param.sInt[5]; // Nickwinkel |
321 | break; |
322 | break; |
322 | case SPI_NCCMD_VERSION: |
323 | case SPI_NCCMD_VERSION: |
323 | NC_Version.Major = FromNaviCtrl.Param.Byte[0]; |
324 | NC_Version.Major = FromNaviCtrl.Param.Byte[0]; |
324 | NC_Version.Minor = FromNaviCtrl.Param.Byte[1]; |
325 | NC_Version.Minor = FromNaviCtrl.Param.Byte[1]; |
325 | NC_Version.Patch = FromNaviCtrl.Param.Byte[2]; |
326 | NC_Version.Patch = FromNaviCtrl.Param.Byte[2]; |
326 | NC_Version.Compatible = FromNaviCtrl.Param.Byte[3]; |
327 | NC_Version.Compatible = FromNaviCtrl.Param.Byte[3]; |
327 | NC_Version.Hardware = FromNaviCtrl.Param.Byte[4]; |
328 | NC_Version.Hardware = FromNaviCtrl.Param.Byte[4]; |
328 | DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5]; |
329 | DebugOut.Status[0] |= FromNaviCtrl.Param.Byte[5]; |
329 | NC_ErrorCode = FromNaviCtrl.Param.Byte[6]; |
- | |
330 | DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08)); |
330 | DebugOut.Status[1] = (DebugOut.Status[1] & (0x01|0x02)) | (FromNaviCtrl.Param.Byte[6] & (0x04 | 0x08)); |
- | 331 | NC_ErrorCode = FromNaviCtrl.Param.Byte[7]; |
|
- | 332 | NC_GPS_ModeCharacter = FromNaviCtrl.Param.Byte[8]; |
|
331 | break; |
333 | break; |
332 | 334 | ||
333 | case SPI_NCCMD_GPSINFO: |
335 | case SPI_NCCMD_GPSINFO: |
334 | GPSInfo.Flags = FromNaviCtrl.Param.Byte[0]; |
336 | GPSInfo.Flags = FromNaviCtrl.Param.Byte[0]; |
335 | GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1]; |
337 | GPSInfo.NumOfSats = FromNaviCtrl.Param.Byte[1]; |
336 | GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2]; |
338 | GPSInfo.SatFix = FromNaviCtrl.Param.Byte[2]; |
337 | GPSInfo.Speed = FromNaviCtrl.Param.Byte[3]; |
339 | GPSInfo.Speed = FromNaviCtrl.Param.Byte[3]; |
338 | GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2]; |
340 | GPSInfo.HomeDistance = FromNaviCtrl.Param.Int[2]; |
339 | GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3]; |
341 | GPSInfo.HomeBearing = FromNaviCtrl.Param.sInt[3]; |
340 | PPM_in[25] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value |
342 | PPM_in[25] = (signed char) FromNaviCtrl.Param.Byte[8]; // WP_EVENT-Channel-Value |
341 | FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9]; |
343 | FromNC_AltitudeSpeed = FromNaviCtrl.Param.Byte[9]; |
342 | FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10; // in cm |
344 | FromNC_AltitudeSetpoint = (long) FromNaviCtrl.Param.sInt[5] * 10; // in cm |
343 | break; |
345 | break; |
344 | // 0 = 0,1 |
346 | // 0 = 0,1 |
345 | // 1 = 2,3 |
347 | // 1 = 2,3 |
346 | // 2 = 4,5 |
348 | // 2 = 4,5 |
347 | // 3 = 6,7 |
349 | // 3 = 6,7 |
348 | // 4 = 8,9 |
350 | // 4 = 8,9 |
349 | // 5 = 10,11 |
351 | // 5 = 10,11 |
350 | default: |
352 | default: |
351 | break; |
353 | break; |
352 | } |
354 | } |
353 | } |
355 | } |
354 | else |
356 | else |
355 | { |
357 | { |
356 | // KompassValue = 0; |
358 | // KompassValue = 0; |
357 | // KompassRichtung = 0; |
359 | // KompassRichtung = 0; |
358 | GPS_Nick = 0; |
360 | GPS_Nick = 0; |
359 | GPS_Roll = 0; |
361 | GPS_Roll = 0; |
360 | } |
362 | } |
361 | } |
363 | } |
362 | 364 | ||
363 | #endif |
365 | #endif |
364 | 366 | ||
365 | 367 | ||
366 | 368 |