Subversion Repositories FlightCtrl

Rev

Rev 197 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 197 Rev 209
1
/*
1
/*
2
This program (files gps.c and gps.h) is free software; you can redistribute it and/or modify
2
This program (files gps.c and gps.h) is free software; you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by the Free Software Foundation;
3
it under the terms of the GNU General Public License as published by the Free Software Foundation;
4
either version 3 of the License, or (at your option) any later version.  
4
either version 3 of the License, or (at your option) any later version.  
5
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
6
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7
GNU General Public License for more details. You should have received a copy of the GNU General Public License
7
GNU General Public License for more details. You should have received a copy of the GNU General Public License
8
along with this program. If not, see <http://www.gnu.org/licenses/>.
8
along with this program. If not, see <http://www.gnu.org/licenses/>.
9
 
9
 
10
Please note: All the other files for the project "Mikrokopter" by H.Buss are under the license (license_buss.txt) published by www.mikrokopter.de
10
Please note: All the other files for the project "Mikrokopter" by H.Buss are under the license (license_buss.txt) published by www.mikrokopter.de
11
*/
11
*/
12
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
Peter Muehlenbrock
13
Peter Muehlenbrock
14
Auswertung der Daten vom GPS im ublox Format
14
Auswertung der Daten vom GPS im ublox Format
15
Hold Modus mit PID Regler
15
Hold Modus mit PID Regler
16
Stand 2.10.2007
16
Stand 2.10.2007
17
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
*/
18
*/
19
#include "main.h"
19
#include "main.h"
20
//#include "gps.h"
20
//#include "gps.h"
21
 
21
 
22
// Defines fuer ublox Messageformat um Auswertung zu steuern
22
// Defines fuer ublox Messageformat um Auswertung zu steuern
23
#define                 UBLOX_IDLE              0
23
#define                 UBLOX_IDLE              0
24
#define                 UBLOX_SYNC1             1
24
#define                 UBLOX_SYNC1             1
25
#define                 UBLOX_SYNC2             2
25
#define                 UBLOX_SYNC2             2
26
#define                 UBLOX_CLASS             3
26
#define                 UBLOX_CLASS             3
27
#define                 UBLOX_ID                4
27
#define                 UBLOX_ID                4
28
#define                 UBLOX_LEN1              5
28
#define                 UBLOX_LEN1              5
29
#define                 UBLOX_LEN2              6
29
#define                 UBLOX_LEN2              6
30
#define                 UBLOX_CKA               7
30
#define                 UBLOX_CKA               7
31
#define                 UBLOX_CKB               8
31
#define                 UBLOX_CKB               8
32
#define                 UBLOX_PAYLOAD   9
32
#define                 UBLOX_PAYLOAD   9
33
 
33
 
34
// ublox Protokoll Identifier 
34
// ublox Protokoll Identifier 
35
#define                 UBLOX_NAV_POSUTM                0x08
35
#define                 UBLOX_NAV_POSUTM                0x08
36
#define                 UBLOX_NAV_STATUS                0x03
36
#define                 UBLOX_NAV_STATUS                0x03
37
#define                 UBLOX_NAV_VELED                 0x12
37
#define                 UBLOX_NAV_VELED                 0x12
38
#define                 UBLOX_NAV_CLASS                 0x01
38
#define                 UBLOX_NAV_CLASS                 0x01
39
#define                 UBLOX_SYNCH1_CHAR               0xB5
39
#define                 UBLOX_SYNCH1_CHAR               0xB5
40
#define                 UBLOX_SYNCH2_CHAR               0x62
40
#define                 UBLOX_SYNCH2_CHAR               0x62
41
 
41
 
42
signed int GPS_Nick = 0;
42
signed int      GPS_Nick = 0;
43
signed int GPS_Roll = 0;
43
signed int      GPS_Roll = 0;
44
short int ublox_msg_state = UBLOX_IDLE;
44
short int       ublox_msg_state = UBLOX_IDLE;
45
static uint8_t  chk_a =0; //Checksum
45
static          uint8_t chk_a =0; //Checksum
46
static uint8_t  chk_b =0;
46
static          uint8_t chk_b =0;
47
short int gps_state;
47
short int       gps_state;
48
short int  gps_updte_flag;
48
short int       gps_updte_flag;
49
signed int GPS_hdng_abs_2trgt; //Winkel zum Ziel bezogen auf Nordpol
49
signed int      GPS_hdng_abs_2trgt; //Winkel zum Ziel bezogen auf Nordpol
50
signed int GPS_hdng_rel_2trgt; //Winkel zum Ziel bezogen auf Nordachse des Kopters
50
signed int      GPS_hdng_rel_2trgt; //Winkel zum Ziel bezogen auf Nordachse des Kopters
51
signed int GPS_dist_2trgt; //vorzeichenlose Distanz zum Ziel 
51
signed int      GPS_dist_2trgt; //vorzeichenlose Distanz zum Ziel 
52
signed int gps_int_x,gps_int_y,gps_reg_x,gps_reg_y;                            
-
 
53
signed int ;
52
signed int      gps_int_x,gps_int_y,gps_reg_x,gps_reg_y;                               
54
static unsigned int rx_len;
-
 
55
unsigned int cnt0,cnt1,cnt2; //******Provisorisch
53
static unsigned int rx_len;
56
static unsigned int ptr_payload_data_end;
54
static unsigned int ptr_payload_data_end;
57
unsigned int gps_alive_cnt; // Wird bei jedem gueltigen GPS Telegramm hochgezaehlt
55
unsigned int            gps_alive_cnt; // Wird bei jedem gueltigen GPS Telegramm hochgezaehlt
58
 
56
 
59
static uint8_t *ptr_payload_data;
57
static uint8_t *ptr_payload_data;
60
static uint8_t *ptr_pac_status;
58
static uint8_t *ptr_pac_status;
61
 
59
 
62
short int Get_GPS_data(void);
60
short int Get_GPS_data(void);
63
 
61
 
64
NAV_POSUTM_t actual_pos;    // Aktuelle Nav Daten werden hier im ublox Format abgelegt
62
NAV_POSUTM_t actual_pos;    // Aktuelle Nav Daten werden hier im ublox Format abgelegt
65
NAV_STATUS_t actual_status; // Aktueller Nav Status
63
NAV_STATUS_t actual_status; // Aktueller Nav Status
66
NAV_VELNED_t actual_speed;  // Aktueller Geschwindigkeits und Richtungsdaten
64
NAV_VELNED_t actual_speed;  // Aktueller Geschwindigkeits und Richtungsdaten
67
 
65
 
68
GPS_ABS_POSITION_t              gps_act_position;               // Alle wichtigen Daten zusammengefasst
66
GPS_ABS_POSITION_t              gps_act_position;               // Alle wichtigen Daten zusammengefasst
69
GPS_ABS_POSITION_t              gps_home_position;      // Die Startposition, beim Kalibrieren ermittelt
67
GPS_ABS_POSITION_t              gps_home_position;      // Die Startposition, beim Kalibrieren ermittelt
70
GPS_REL_POSITION_t              gps_rel_act_position;   // Die aktuelle relative Position bezogen auf Home Position
68
GPS_REL_POSITION_t              gps_rel_act_position;   // Die aktuelle relative Position bezogen auf Home Position
71
GPS_REL_POSITION_t              gps_rel_hold_position;  // Die gespeicherte Sollposition fuer GPS_ Hold Mode
69
GPS_REL_POSITION_t              gps_rel_hold_position;  // Die gespeicherte Sollposition fuer GPS_ Hold Mode
72
 
70
 
73
// Initialisierung
71
// Initialisierung
74
void GPS_Neutral(void)
72
void GPS_Neutral(void)
75
{
73
{
76
        ublox_msg_state                         =       UBLOX_IDLE;
74
        ublox_msg_state                         =       UBLOX_IDLE;
77
        gps_state                                       =       GPS_CRTL_IDLE;
75
        gps_state                                       =       GPS_CRTL_IDLE;
78
        actual_pos.status                       =       0;
76
        actual_pos.status                       =       0;
79
        actual_speed.status                     =       0;
77
        actual_speed.status                     =       0;
80
        actual_status.status            =       0;
78
        actual_status.status            =       0;
81
        gps_home_position.status        =       0; // Noch keine gueltige Home Position
79
        gps_home_position.status        =       0; // Noch keine gueltige Home Position
82
        gps_act_position.status         =       0;
80
        gps_act_position.status         =       0;
83
        gps_rel_act_position.status     =       0;     
81
        gps_rel_act_position.status     =       0;     
84
        GPS_Nick                                        =       0;
82
        GPS_Nick                                        =       0;
85
        GPS_Roll                                        =       0;
83
        GPS_Roll                                        =       0;
86
        gps_updte_flag                          =       0;
84
        gps_updte_flag                          =       0;
87
        gps_int_x                                       =       0;
85
        gps_int_x                                       =       0;
88
        gps_int_y                                       =       0;
86
        gps_int_y                                       =       0;
89
        gps_alive_cnt                           =       0;
87
        gps_alive_cnt                           =       0;
90
 
-
 
91
}
88
}
92
 
89
 
93
// Home Position sichern falls Daten verfuegbar sind. 
90
// Home Position sichern falls Daten verfuegbar sind. 
94
void GPS_Save_Home(void)
91
void GPS_Save_Home(void)
95
{
92
{
96
        short int n;
93
        short int n;
97
        n = Get_GPS_data();
94
        n = Get_GPS_data();
98
        if (n == 0)   // Gueltige  und aktuelle Daten ?   
95
        if (n == 0)   // Gueltige  und aktuelle Daten ?   
99
        {
96
        {
100
                // Neue GPS Daten liegen vor
97
                // Neue GPS Daten liegen vor
101
                gps_home_position.utm_east      = gps_act_position.utm_east;   
98
                gps_home_position.utm_east      = gps_act_position.utm_east;   
102
                gps_home_position.utm_north     = gps_act_position.utm_north;  
99
                gps_home_position.utm_north     = gps_act_position.utm_north;  
103
                gps_home_position.utm_alt       = gps_act_position.utm_alt;
100
                gps_home_position.utm_alt       = gps_act_position.utm_alt;
104
                gps_home_position.status        = 1; // Home Position gueltig                   
101
                gps_home_position.status        = 1; // Home Position gueltig                   
105
        }
102
        }
106
}
103
}
107
 
104
 
108
// Relative Position zur Home Position bestimmen
105
// Relative Position zur Home Position bestimmen
109
// Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig
106
// Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig
110
short int Get_Rel_Position(void)
107
short int Get_Rel_Position(void)
111
{
108
{
112
        short int n = 0;
109
        short int n = 0;
113
        n = Get_GPS_data();
110
        n = Get_GPS_data();
114
        if (n >=1) return (n); // nix zu tun, weil keine neue Daten da sind
111
        if (n >=1) return (n); // nix zu tun, weil keine neue Daten da sind
115
        if (gps_alive_cnt < 400) gps_alive_cnt += 300; // Timeoutzaehler. Wird in MotorreglerRoutine ueberwacht und dekrementiert
112
        if (gps_alive_cnt < 400) gps_alive_cnt += 300; // Timeoutzaehler. Wird in MotorreglerRoutine ueberwacht und dekrementiert
116
        if  (gps_home_position.status > 0) //Nur wenn Home Position vorliegt
113
        if  (gps_home_position.status > 0) //Nur wenn Home Position vorliegt
117
        {
114
        {
118
                gps_rel_act_position.utm_east   = (int)  (gps_act_position.utm_east - gps_home_position.utm_east);
115
                gps_rel_act_position.utm_east   = (int)  (gps_act_position.utm_east - gps_home_position.utm_east);
119
                gps_rel_act_position.utm_north  = (int)  (gps_act_position.utm_north - gps_home_position.utm_north);
116
                gps_rel_act_position.utm_north  = (int)  (gps_act_position.utm_north - gps_home_position.utm_north);
120
                gps_rel_act_position.status     = 1; // gueltige Positionsdaten
117
                gps_rel_act_position.status     = 1; // gueltige Positionsdaten
121
                n = 0;
118
                n = 0;
122
                gps_updte_flag = 1; // zeigt an, dass neue Daten vorliegen.
119
                gps_updte_flag = 1; // zeigt an, dass neue Daten vorliegen.
123
        }
120
        }
124
        else
121
        else
125
        {
122
        {
126
                n = 2; //keine gueltigen Daten vorhanden
123
                n = 2; //keine gueltigen Daten vorhanden
127
                gps_rel_act_position.status = 0; //keine gueltige Position weil keine home Position da ist.
124
                gps_rel_act_position.status = 0; //keine gueltige Position weil keine home Position da ist.
128
        }      
125
        }      
129
        return (n);
126
        return (n);
130
}
127
}
131
 
128
 
132
// Daten aus aktuellen ublox Messages extrahieren 
129
// Daten aus aktuellen ublox Messages extrahieren 
133
// Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig
130
// Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig
134
short int Get_GPS_data(void)
131
short int Get_GPS_data(void)
135
{
132
{
136
        short int n = 1;
133
        short int n = 1;
137
 
134
 
138
        if (actual_pos.status == 0) return (1); //damit es schnell geht, wenn nix zu tun ist
135
        if (actual_pos.status == 0) return (1); //damit es schnell geht, wenn nix zu tun ist
139
        if ((actual_pos.status > 0) && (actual_status.status > 0) && (actual_speed.status > 0))
136
        if ((actual_pos.status > 0) && (actual_status.status > 0) && (actual_speed.status > 0))
140
        {
137
        {
141
                cnt1++; //**** noch Rausschmeissen
-
 
142
                if (((actual_status.gpsfix_type & 0x03) >=2) && ((actual_status.nav_status_flag & 0x01) >=1)) // nur wenn Daten aktuell und gueltig sind
138
                if (((actual_status.gpsfix_type & 0x03) >=2) && ((actual_status.nav_status_flag & 0x01) >=1)) // nur wenn Daten aktuell und gueltig sind
143
                {
139
                {
144
                        gps_act_position.utm_east       = actual_pos.utm_east/10;
140
                        gps_act_position.utm_east       = actual_pos.utm_east/10;
145
                        gps_act_position.utm_north      = actual_pos.utm_north/10;
141
                        gps_act_position.utm_north      = actual_pos.utm_north/10;
146
                        gps_act_position.utm_alt        = actual_pos.utm_alt/10;
142
                        gps_act_position.utm_alt        = actual_pos.utm_alt/10;
147
                        gps_act_position.speed_gnd      = actual_speed.speed_gnd/10;
143
                        gps_act_position.speed_gnd      = actual_speed.speed_gnd/10;
148
                        gps_act_position.speed_gnd      = actual_speed.speed_gnd/10;
144
                        gps_act_position.speed_gnd      = actual_speed.speed_gnd/10;
149
                        gps_act_position.heading        = actual_speed.heading/100000;
145
                        gps_act_position.heading        = actual_speed.heading/100000;
150
                        gps_act_position.status         = 1;
146
                        gps_act_position.status         = 1;
151
                        n                                                       = 0; //Daten gueltig
147
                        n                                                       = 0; //Daten gueltig
152
                }
148
                }
153
                else
149
                else
154
                {
150
                {
155
                        gps_act_position.status = 0; //Keine gueltigen Daten
151
                        gps_act_position.status = 0; //Keine gueltigen Daten
156
                        n                                               = 2;
152
                        n                                               = 2;
157
                }
153
                }
158
                actual_pos.status               = 0; //neue ublox Messages anfordern
154
                actual_pos.status               = 0; //neue ublox Messages anfordern
159
                actual_status.status    = 0;
155
                actual_status.status    = 0;
160
                actual_speed.status     = 0;
156
                actual_speed.status     = 0;
161
        }      
157
        }      
162
        return (n);    
158
        return (n);    
163
}
159
}
164
 
160
 
165
 
161
 
166
/*
162
/*
167
Daten vom GPS im ublox MSG Format auswerten
163
Daten vom GPS im ublox MSG Format auswerten
168
Die Routine wird bei jedem Empfang eines Zeichens vom GPS Modul durch den UART IRQ aufgerufen
164
Die Routine wird bei jedem Empfang eines Zeichens vom GPS Modul durch den UART IRQ aufgerufen
169
// Die UBX Messages NAV_POSUTM, NAV_STATUS und NAV_VALED muessen aktiviert sein
165
// Die UBX Messages NAV_POSUTM, NAV_STATUS und NAV_VALED muessen aktiviert sein
170
*/
166
*/
171
void Get_Ublox_Msg(uint8_t rx)
167
void Get_Ublox_Msg(uint8_t rx)
172
{
168
{
173
 
-
 
174
        switch (ublox_msg_state)
169
        switch (ublox_msg_state)
175
        {
170
        {
176
 
171
 
177
                case UBLOX_IDLE: // Zuerst Synchcharacters pruefen
172
                case UBLOX_IDLE: // Zuerst Synchcharacters pruefen
178
                        if ( rx == UBLOX_SYNCH1_CHAR ) ublox_msg_state = UBLOX_SYNC1;
173
                        if ( rx == UBLOX_SYNCH1_CHAR ) ublox_msg_state = UBLOX_SYNC1;
179
                        else ublox_msg_state = UBLOX_IDLE;
174
                        else ublox_msg_state = UBLOX_IDLE;
180
                        break;
175
                        break;
181
 
176
 
182
                case UBLOX_SYNC1:
177
                case UBLOX_SYNC1:
183
 
178
 
184
                        if (rx == UBLOX_SYNCH2_CHAR) ublox_msg_state = UBLOX_SYNC2;
179
                        if (rx == UBLOX_SYNCH2_CHAR) ublox_msg_state = UBLOX_SYNC2;
185
                        else ublox_msg_state = UBLOX_IDLE;
180
                        else ublox_msg_state = UBLOX_IDLE;
186
                        chk_a = 0,chk_b = 0;
181
                        chk_a = 0,chk_b = 0;
187
                        break;
182
                        break;
188
 
183
 
189
                case UBLOX_SYNC2:
184
                case UBLOX_SYNC2:
190
                        if (rx == UBLOX_NAV_CLASS) ublox_msg_state = UBLOX_CLASS;      
185
                        if (rx == UBLOX_NAV_CLASS) ublox_msg_state = UBLOX_CLASS;      
191
                        else ublox_msg_state = UBLOX_IDLE;
186
                        else ublox_msg_state = UBLOX_IDLE;
192
                        break;
187
                        break;
193
 
188
 
194
                case UBLOX_CLASS: // Nur NAV Meldungen auswerten
189
                case UBLOX_CLASS: // Nur NAV Meldungen auswerten
195
                        switch (rx)
190
                        switch (rx)
196
                        {
191
                        {
197
                                case UBLOX_NAV_POSUTM:
192
                                case UBLOX_NAV_POSUTM:
198
                                        ptr_pac_status  =       &actual_pos.status;
193
                                        ptr_pac_status  =       &actual_pos.status;
199
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; //Abbruch weil Daten noch nicht verwendet wurden
194
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; //Abbruch weil Daten noch nicht verwendet wurden
200
                                        else
195
                                        else
201
                                        {
196
                                        {
202
                                                ptr_payload_data                = &actual_pos;
197
                                                ptr_payload_data                = &actual_pos;
203
                                                ptr_payload_data_end    = &actual_pos.status;
198
                                                ptr_payload_data_end    = &actual_pos.status;
204
                                                ublox_msg_state                 = UBLOX_LEN1;
199
                                                ublox_msg_state                 = UBLOX_LEN1;
205
                                        }
200
                                        }
206
                                        break;
201
                                        break;
207
 
202
 
208
                                case UBLOX_NAV_STATUS:
203
                                case UBLOX_NAV_STATUS:
209
                                        ptr_pac_status  =       &actual_status.status;
204
                                        ptr_pac_status  =       &actual_status.status;
210
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE;
205
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE;
211
                                        else
206
                                        else
212
                                        {
207
                                        {
213
                                                ptr_payload_data                = &actual_status;
208
                                                ptr_payload_data                = &actual_status;
214
                                                ptr_payload_data_end    = &actual_status.status;
209
                                                ptr_payload_data_end    = &actual_status.status;
215
                                                ublox_msg_state                 = UBLOX_LEN1;
210
                                                ublox_msg_state                 = UBLOX_LEN1;
216
                                        }
211
                                        }
217
                                        break;
212
                                        break;
218
 
213
 
219
                                case UBLOX_NAV_VELED:
214
                                case UBLOX_NAV_VELED:
220
                                        ptr_pac_status          =       &actual_speed.status;
215
                                        ptr_pac_status          =       &actual_speed.status;
221
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE;
216
                                        if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE;
222
                                        else
217
                                        else
223
                                        {
218
                                        {
224
                                                ptr_payload_data                = &actual_speed;
219
                                                ptr_payload_data                = &actual_speed;
225
                                                ptr_payload_data_end    = &actual_speed.status;
220
                                                ptr_payload_data_end    = &actual_speed.status;
226
                                                ublox_msg_state                 = UBLOX_LEN1;
221
                                                ublox_msg_state                 = UBLOX_LEN1;
227
                                        }
222
                                        }
228
                                        break;
223
                                        break;
229
 
224
 
230
                                default:
225
                                default:
231
                                        ublox_msg_state = UBLOX_IDLE;
226
                                        ublox_msg_state = UBLOX_IDLE;
232
                                        break; 
227
                                        break; 
233
                        }
228
                        }
234
                        chk_a   = UBLOX_NAV_CLASS + rx;
229
                        chk_a   = UBLOX_NAV_CLASS + rx;
235
                        chk_b   = UBLOX_NAV_CLASS + chk_a;                     
230
                        chk_b   = UBLOX_NAV_CLASS + chk_a;                     
236
                        break;
231
                        break;
237
 
232
 
238
                case UBLOX_LEN1: // Laenge auswerten
233
                case UBLOX_LEN1: // Laenge auswerten
239
                        rx_len  = rx;
234
                        rx_len  = rx;
240
                        chk_a   += rx;
235
                        chk_a   += rx;
241
                        chk_b   += chk_a;              
236
                        chk_b   += chk_a;              
242
                        ublox_msg_state = UBLOX_LEN2;
237
                        ublox_msg_state = UBLOX_LEN2;
243
                        break;
238
                        break;
244
 
239
 
245
 
240
 
246
                case UBLOX_LEN2: // Laenge auswerten
241
                case UBLOX_LEN2: // Laenge auswerten
247
                        rx_len = rx_len + (rx *256); // Laenge ermitteln
242
                        rx_len = rx_len + (rx *256); // Laenge ermitteln
248
                        chk_a   += rx;
243
                        chk_a   += rx;
249
                        chk_b   += chk_a;      
244
                        chk_b   += chk_a;      
250
                        ublox_msg_state = UBLOX_PAYLOAD;
245
                        ublox_msg_state = UBLOX_PAYLOAD;
251
                        break;
246
                        break;
252
 
247
 
253
                case UBLOX_PAYLOAD: // jetzt Nutzdaten einlesen
248
                case UBLOX_PAYLOAD: // jetzt Nutzdaten einlesen
254
                        if (rx_len > 0)
249
                        if (rx_len > 0)
255
                        {
250
                        {
256
                                *ptr_payload_data = rx;
251
                                *ptr_payload_data = rx;
257
                                chk_a   += rx;
252
                                chk_a   += rx;
258
                                chk_b   += chk_a;
253
                                chk_b   += chk_a;
259
                                --rx_len;      
254
                                --rx_len;      
260
                                if ((rx_len > 0) && (ptr_payload_data <= ptr_payload_data_end))                          
255
                                if ((rx_len > 0) && (ptr_payload_data <= ptr_payload_data_end))                          
261
                                {
256
                                {
262
                                        ptr_payload_data++;
257
                                        ptr_payload_data++;
263
                                        ublox_msg_state = UBLOX_PAYLOAD;
258
                                        ublox_msg_state = UBLOX_PAYLOAD;
264
                            }
259
                            }
265
                                else ublox_msg_state = UBLOX_CKA;
260
                                else ublox_msg_state = UBLOX_CKA;
266
                        }      
261
                        }      
267
                        else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler
262
                        else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler
268
                        break;
263
                        break;
269
 
264
 
270
                case UBLOX_CKA: // Checksum pruefen
265
                case UBLOX_CKA: // Checksum pruefen
271
                        if (rx == chk_a) ublox_msg_state = UBLOX_CKB;                          
266
                        if (rx == chk_a) ublox_msg_state = UBLOX_CKB;                          
272
                        else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler
267
                        else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler
273
                        break;
268
                        break;
274
 
269
 
275
                case UBLOX_CKB: // Checksum pruefen
270
                case UBLOX_CKB: // Checksum pruefen
276
                        if (rx == chk_b) *ptr_pac_status = 1; // Paket ok
271
                        if (rx == chk_b) *ptr_pac_status = 1; // Paket ok
277
                        ublox_msg_state    = UBLOX_IDLE;
272
                        ublox_msg_state    = UBLOX_IDLE;
278
                        break;
273
                        break;
279
 
274
 
280
                default:
275
                default:
281
                        ublox_msg_state = UBLOX_IDLE;          
276
                        ublox_msg_state = UBLOX_IDLE;          
282
                        break;
277
                        break;
283
        }
278
        }
284
}
279
}
285
       
280
       
286
//Zentrale Statemachine fuer alle GPS relevanten Regelungsablauefe
281
//Zentrale Statemachine fuer alle GPS relevanten Regelungsablauefe
287
short int GPS_CRTL(short int cmd)
282
short int GPS_CRTL(short int cmd)
288
{
283
{
289
        static unsigned int cnt;                                //Zaehler fuer diverse Verzoegerungen 
284
        static unsigned int cnt;                                //Zaehler fuer diverse Verzoegerungen 
290
        static signed int int_east,int_north;   //Integrierer 
285
        static signed int int_east,int_north;   //Integrierer 
291
        static signed int dist_north,dist_east;
286
        static signed int dist_north,dist_east;
292
        static signed int diff_east,diff_north;         // Differenzierer  (Differenz zum  vorhergehenden x bzw. y  Wert)
287
        static signed int diff_east,diff_north;         // Differenzierer  (Differenz zum  vorhergehenden x bzw. y  Wert)
293
        static signed int diff_east_f,diff_north_f; // Differenzierer,  gefiltert
288
        static signed int diff_east_f,diff_north_f; // Differenzierer,  gefiltert
294
        signed int n,diff_v;
289
        signed int n,diff_v;
295
        long signed int dev,n_l;
290
        long signed int dev,n_l;
296
        switch (cmd)
291
        switch (cmd)
297
        {
292
        {
298
 
293
 
299
                case GPS_CMD_REQ_HOME: // Es soll zum Startpunkt zurueckgeflogen werden. 
294
                case GPS_CMD_REQ_HOME: // Es soll zum Startpunkt zurueckgeflogen werden. 
300
                // Noch einiges zu ueberlegen und zu tun
295
                // Noch einiges zu ueberlegen und zu tun
301
                   return(GPS_STST_PEND); // noch warten
296
                   return(GPS_STST_PEND); // noch warten
302
                   break;
297
                   break;
303
// ******************************
298
// ******************************
304
 
299
 
305
                case GPS_CMD_REQ_HOLD: // Die Lageregelung soll aktiviert werden.
300
                case GPS_CMD_REQ_HOLD: // Die Lageregelung soll aktiviert werden.
306
                        if (gps_state != GPS_CRTL_HOLD_ACTIVE)
301
                        if (gps_state != GPS_CRTL_HOLD_ACTIVE)
307
                        {
302
                        {
308
                                cnt++;
303
                                cnt++;
309
                                if (cnt > 500) // erst nach Verzoegerung 
304
                                if (cnt > 500) // erst nach Verzoegerung 
310
                                {
305
                                {
311
                                        cnt     =       0;
306
                                        cnt     =       0;
312
                                        // aktuelle positionsdaten abespeichern
307
                                        // aktuelle positionsdaten abespeichern
313
                                        if (gps_rel_act_position.status > 0)
308
                                        if (gps_rel_act_position.status > 0)
314
                                        {
309
                                        {
315
                                                int_east                = 0;
310
                                                int_east                = 0;
316
                                                int_north               = 0;
311
                                                int_north               = 0;
317
                                                gps_reg_x               = 0;
312
                                                gps_reg_x               = 0;
318
                                                gps_reg_y               = 0;
313
                                                gps_reg_y               = 0;
319
                                                dist_east               = 0;
314
                                                dist_east               = 0;
320
                                                dist_north              = 0;
315
                                                dist_north              = 0;
321
                                                diff_east_f             = 0;
316
                                                diff_east_f             = 0;
322
                                                diff_north_f    = 0;
317
                                                diff_north_f    = 0;
323
                                                diff_east               = 0;
318
                                                diff_east               = 0;
324
                                                diff_north              = 0;
319
                                                diff_north              = 0;
325
                                                gps_rel_hold_position.utm_east  = gps_rel_act_position.utm_east;
320
                                                gps_rel_hold_position.utm_east  = gps_rel_act_position.utm_east;
326
                                                gps_rel_hold_position.utm_north = gps_rel_act_position.utm_north;
321
                                                gps_rel_hold_position.utm_north = gps_rel_act_position.utm_north;
327
                                                gps_rel_hold_position.status    = 1; // gueltige Positionsdaten 
322
                                                gps_rel_hold_position.status    = 1; // gueltige Positionsdaten 
328
                                                gps_state                                               = GPS_CRTL_HOLD_ACTIVE;
323
                                                gps_state                                               = GPS_CRTL_HOLD_ACTIVE;
329
                                                return (GPS_STST_OK);                          
324
                                                return (GPS_STST_OK);                          
330
                                        }
325
                                        }
331
                                        else
326
                                        else
332
                                        {
327
                                        {
333
                                                gps_rel_hold_position.status    =       0;  //Keine Daten verfuegbar
328
                                                gps_rel_hold_position.status    =       0;  //Keine Daten verfuegbar
334
                                                gps_state                                               = GPS_CRTL_IDLE;
329
                                                gps_state                                               = GPS_CRTL_IDLE;
335
                                                return(GPS_STST_ERR); // Keine Daten da
330
                                                return(GPS_STST_ERR); // Keine Daten da
336
                                        }
331
                                        }
337
                                }
332
                                }
338
                                else return(GPS_STST_PEND); // noch warten
333
                                else return(GPS_STST_PEND); // noch warten
339
                        }
334
                        }
340
                        break;
335
                        break;
341
 
336
 
342
                case GPS_CMD_STOP: // Lageregelung beenden
337
                case GPS_CMD_STOP: // Lageregelung beenden
343
                        cnt                             =       0;
338
                        cnt                             =       0;
344
                        GPS_Nick                =       0;
339
                        GPS_Nick                =       0;
345
                        GPS_Roll                =       0;
340
                        GPS_Roll                =       0;
346
                        gps_int_x               =       0;
341
                        gps_int_x               =       0;
347
                        gps_int_y               =       0;
342
                        gps_int_y               =       0;
348
                        gps_state       =       GPS_CRTL_IDLE;
343
                        gps_state       =       GPS_CRTL_IDLE;
349
                        return (GPS_STST_OK);
344
                        return (GPS_STST_OK);
350
                        break;
345
                        break;
351
 
346
 
352
                default:
347
                default:
353
                        return (GPS_STST_ERR);
348
                        return (GPS_STST_ERR);
354
                        break;
349
                        break;
355
        }
350
        }
356
 
351
 
357
        switch (gps_state)
352
        switch (gps_state)
358
        {      
353
        {      
359
                case GPS_CRTL_IDLE:
354
                case GPS_CRTL_IDLE:
360
                        cnt             =       0;
355
                        cnt             =       0;
361
                        return (GPS_STST_OK);
356
                        return (GPS_STST_OK);
362
                        break;
357
                        break;
363
 
358
 
364
                case GPS_CRTL_HOLD_ACTIVE:    // Hier werden die Daten fuer Nick und Roll errechnet
359
                case GPS_CRTL_HOLD_ACTIVE:    // Hier werden die Daten fuer Nick und Roll errechnet
365
                        if (gps_updte_flag == 1)  //nur wenn neue GPS Daten vorliegen
360
                        if (gps_updte_flag == 1)  //nur wenn neue GPS Daten vorliegen
366
                        {
361
                        {
367
                                gps_updte_flag = 0;
362
                                gps_updte_flag = 0;
368
                                // ab hier wird geregelt
363
                                // ab hier wird geregelt
369
                                diff_east       = -dist_east;     //Alten Wert fuer Differenzier schon mal abziehen
364
                                diff_east       = -dist_east;     //Alten Wert fuer Differenzier schon mal abziehen
370
                                diff_north      = -dist_north;
365
                                diff_north      = -dist_north;
371
                                dist_east       = gps_rel_hold_position.utm_east  - gps_rel_act_position.utm_east;
366
                                dist_east       = gps_rel_hold_position.utm_east  - gps_rel_act_position.utm_east;
372
                                dist_north      = gps_rel_hold_position.utm_north - gps_rel_act_position.utm_north;
367
                                dist_north      = gps_rel_hold_position.utm_north - gps_rel_act_position.utm_north;
373
                                int_east        += dist_east;
368
                                int_east        += dist_east;
374
                                int_north   += dist_north;
369
                                int_north   += dist_north;
375
                                diff_east       += dist_east;   // Differenz zur vorhergehenden East Position
370
                                diff_east       += dist_east;   // Differenz zur vorhergehenden East Position
376
                                diff_north      += dist_north;  // Differenz zur vorhergehenden North Position
371
                                diff_north      += dist_north;  // Differenz zur vorhergehenden North Position
377
 
372
 
378
                                diff_east_f             = ((diff_east_f )/4) + (diff_east*3/4); //Differenzierer filtern        
373
                                diff_east_f             = ((diff_east_f )/4) + (diff_east*3/4); //Differenzierer filtern        
379
                                diff_north_f    = ((diff_north_f)/4) + (diff_north*3/4); //Differenzierer filtern       
374
                                diff_north_f    = ((diff_north_f)/4) + (diff_north*3/4); //Differenzierer filtern       
380
 
375
 
381
                                #define GPSINT_MAX 2048 //neuer Wert ab 1.10.2007 Begrenzung 
376
                                #define GPSINT_MAX 2048 //neuer Wert ab 1.10.2007 Begrenzung 
382
                                if ((abs(int_east) > GPSINT_MAX) || (abs(int_north)> GPSINT_MAX)) //Bei zu hohem Wert Integrator auf Wert halten
377
                                if ((abs(int_east) > GPSINT_MAX) || (abs(int_north)> GPSINT_MAX)) //Bei zu hohem Wert Integrator auf Wert halten
383
                                {
378
                                {
384
                                        int_east        -= dist_east;
379
                                        int_east        -= dist_east;
385
                                        int_north   -= dist_north;                                     
380
                                        int_north   -= dist_north;                                     
386
                                }
381
                                }
387
                                //Variable Verstarkung fuer Differenzierer ermitteln. Je weiter vom Ziel wir entfernt sind
382
                                // Variable Verstarkung fuer Differenzierer ermitteln. Je weiter vom Ziel wir entfernt sind
388
                                // desto groesser wird der Faktor. Es gibt aber einen Maximalwert. bei 0 ist die Verstaerkung 1
383
                                // desto groesser wird der Faktor. Es gibt aber einen Maximalwert. Bei 0 ist die Verstaerkung immer 1
389
                                #define GPS_DIFF_MAX_V 20 //maximale Verstaerkung * 10
384
                                #define GPS_DIFF_MAX_V 20 //maximale Verstaerkung * 10
390
                                #define GPS_DIFF_MAX_D 40 //Entfernung bei der maximale Verstaerkung erreicht wird in (dm)
385
                                #define GPS_DIFF_MAX_D 30 //Entfernung bei der maximale Verstaerkung erreicht wird in 10cm
391
                                signed long dist;
386
                                signed long dist;
392
                                int phi;
387
                                int phi;
393
                                phi = arctan_i(abs(dist_north),abs(dist_east));
388
                                phi = arctan_i(abs(dist_north),abs(dist_east));
394
                                if (abs(dist_east) > abs(dist_north) ) //Zunaechst Entfernung zum Ziel ermitteln
389
                                if (abs(dist_east) > abs(dist_north) ) //Zunaechst Entfernung zum Ziel ermitteln
395
                                {
390
                                {
396
                                        dist = (long)dist_east; //Groesseren Wert wegen besserer Genauigkeit nehmen
391
                                        dist = (long)dist_east; //Groesseren Wert wegen besserer Genauigkeit nehmen
397
                                        dist = abs((dist *1000) / (long) sin_i(phi));
392
                                        dist = abs((dist *1000) / (long) sin_i(phi));
398
                                }
393
                                }
399
                                else
394
                                else
400
                                {
395
                                {
401
                                        dist = (long)dist_north;
396
                                        dist = (long)dist_north;
402
                                        dist = abs((dist *1000) / (long) cos_i(phi));
397
                                        dist = abs((dist *1000) / (long) cos_i(phi));
403
                                }
398
                                }
404
                                diff_v = (int)((dist * (GPS_DIFF_MAX_V - 10)) / GPS_DIFF_MAX_D) +10; //Verstaerkung * 10
399
                                diff_v = (int)((dist * (GPS_DIFF_MAX_V - 10)) / GPS_DIFF_MAX_D) +10; //Verstaerkung * 10
405
                                if (diff_v > GPS_DIFF_MAX_V) diff_v = GPS_DIFF_MAX_V;
400
                                if (diff_v > GPS_DIFF_MAX_V) diff_v = GPS_DIFF_MAX_V; //begrenzen
406
 
401
 
407
                                //PID Regler Werte aufsummieren
402
                                //PID Regler Werte aufsummieren
408
                                gps_reg_x = ((int_east  * Parameter_UserParam2)/32) + ((dist_east  * Parameter_UserParam1)/8)+ ((diff_east_f  * diff_v * Parameter_UserParam3)/10);  // I + P +D  Anteil X Achse
403
                                gps_reg_x = ((int_east  * Parameter_UserParam2)/32) + ((dist_east  * Parameter_UserParam1)/8)+ ((diff_east_f  * diff_v * Parameter_UserParam3)/10);  // I + P +D  Anteil X Achse
409
                                gps_reg_y = ((int_north * Parameter_UserParam2)/32) + ((dist_north * Parameter_UserParam1)/8)+ ((diff_north_f * diff_v * Parameter_UserParam3)/10);  // I + P +D  Anteil Y Achse
404
                                gps_reg_y = ((int_north * Parameter_UserParam2)/32) + ((dist_north * Parameter_UserParam1)/8)+ ((diff_north_f * diff_v * Parameter_UserParam3)/10);  // I + P +D  Anteil Y Achse
410
 
405
 
411
                                //Ziel-Richtung bezogen auf Nordpol bestimmen
406
                                //Ziel-Richtung bezogen auf Nordpol bestimmen
412
                                GPS_hdng_abs_2trgt = arctan_i(gps_reg_x,gps_reg_y);
407
                                GPS_hdng_abs_2trgt = arctan_i(gps_reg_x,gps_reg_y);
413
 
408
 
414
                                // in Winkel 0...360 Grad umrechnen
409
                                // in Winkel 0...360 Grad umrechnen
415
                                if ((gps_reg_x >= 0)) GPS_hdng_abs_2trgt = ( 90-GPS_hdng_abs_2trgt);
410
                                if ((gps_reg_x >= 0)) GPS_hdng_abs_2trgt = ( 90-GPS_hdng_abs_2trgt);
416
                                else  GPS_hdng_abs_2trgt = (270 - GPS_hdng_abs_2trgt);
411
                                else  GPS_hdng_abs_2trgt = (270 - GPS_hdng_abs_2trgt);
417
 
412
 
418
                                // Relative Richtung in bezug auf Nordachse des Kopters errechen
413
                                // Relative Richtung in bezug auf Nordachse des Kopters errechen
419
                                n= GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
414
                                n= GyroKomp_Int/GYROKOMP_INC_GRAD_DEFAULT;
420
                                GPS_hdng_rel_2trgt      =       GPS_hdng_abs_2trgt - n;
415
                                GPS_hdng_rel_2trgt      =       GPS_hdng_abs_2trgt - n;
421
                                if      ((GPS_hdng_rel_2trgt >180) && (GPS_hdng_abs_2trgt >=180)) GPS_hdng_rel_2trgt = GPS_hdng_rel_2trgt-360;
416
                                if      ((GPS_hdng_rel_2trgt >180) && (GPS_hdng_abs_2trgt >=180)) GPS_hdng_rel_2trgt = GPS_hdng_rel_2trgt-360;
422
                                else if (GPS_hdng_rel_2trgt >180)  GPS_hdng_rel_2trgt = 360 - GPS_hdng_rel_2trgt;
417
                                else if (GPS_hdng_rel_2trgt >180)  GPS_hdng_rel_2trgt = 360 - GPS_hdng_rel_2trgt;
423
                                else if (GPS_hdng_rel_2trgt <-180)  GPS_hdng_rel_2trgt = 360 + GPS_hdng_rel_2trgt;
418
                                else if (GPS_hdng_rel_2trgt <-180)  GPS_hdng_rel_2trgt = 360 + GPS_hdng_rel_2trgt;
424
                               
419
                               
425
                                // Regelabweichung aus x,y zu Ziel in Distanz umrechnen 
420
                                // Regelabweichung aus x,y zu Ziel in Distanz umrechnen 
426
                                if (abs(gps_reg_x) > abs(gps_reg_y) )
421
                                if (abs(gps_reg_x) > abs(gps_reg_y) )
427
                                {
422
                                {
428
                                        dev = (long)gps_reg_x; //Groesseren Wert wegen besserer Genauigkeit nehmen
423
                                        dev = (long)gps_reg_x; //Groesseren Wert wegen besserer Genauigkeit nehmen
429
                                        dev = abs((dev *1000) / (long) sin_i(GPS_hdng_abs_2trgt));
424
                                        dev = abs((dev *1000) / (long) sin_i(GPS_hdng_abs_2trgt));
430
                                }
425
                                }
431
                                else
426
                                else
432
                                {
427
                                {
433
                                        dev = (long)gps_reg_y;
428
                                        dev = (long)gps_reg_y;
434
                                        dev = abs((dev *1000) / (long) cos_i(GPS_hdng_abs_2trgt));
429
                                        dev = abs((dev *1000) / (long) cos_i(GPS_hdng_abs_2trgt));
435
                                }
430
                                }
436
                                GPS_dist_2trgt  = (int) dev;
431
                                GPS_dist_2trgt  = (int) dev;
437
                                // Winkel und Distanz in Nick und Rollgroessen umrechnen
432
                                // Winkel und Distanz in Nick und Rollgroessen umrechnen
438
                                GPS_Roll = (int) +( (dev * (long) sin_i(GPS_hdng_rel_2trgt))/1000);
433
                                GPS_Roll = (int) +( (dev * (long) sin_i(GPS_hdng_rel_2trgt))/1000);
439
                                GPS_Nick = (int) -( (dev * (long) cos_i(GPS_hdng_rel_2trgt))/1000);
434
                                GPS_Nick = (int) -( (dev * (long) cos_i(GPS_hdng_rel_2trgt))/1000);
440
                                       
435
                                       
441
                                #define GPS_V 8 // auf Maximalwert normieren. Teilerfaktor ist 8
436
                                #define GPS_V 8 // auf Maximalwert normieren. Teilerfaktor ist 8
442
                                if (GPS_Roll > (GPS_NICKROLL_MAX * GPS_V)) GPS_Roll = (GPS_NICKROLL_MAX * GPS_V);
437
                                if (GPS_Roll > (GPS_NICKROLL_MAX * GPS_V)) GPS_Roll = (GPS_NICKROLL_MAX * GPS_V);
443
                                else if (GPS_Roll < -(GPS_NICKROLL_MAX * GPS_V)) GPS_Roll = -(GPS_NICKROLL_MAX * GPS_V);
438
                                else if (GPS_Roll < -(GPS_NICKROLL_MAX * GPS_V)) GPS_Roll = -(GPS_NICKROLL_MAX * GPS_V);
444
                                if (GPS_Nick > (GPS_NICKROLL_MAX * GPS_V)) GPS_Nick = (GPS_NICKROLL_MAX * GPS_V);
439
                                if (GPS_Nick > (GPS_NICKROLL_MAX * GPS_V)) GPS_Nick = (GPS_NICKROLL_MAX * GPS_V);
445
                                else if (GPS_Nick < -(GPS_NICKROLL_MAX * GPS_V)) GPS_Nick = -(GPS_NICKROLL_MAX * GPS_V);
440
                                else if (GPS_Nick < -(GPS_NICKROLL_MAX * GPS_V)) GPS_Nick = -(GPS_NICKROLL_MAX * GPS_V);
446
 
441
 
447
                                //Kleine Werte verstaerken, Grosse abschwaechen
442
                                //Kleine Werte verstaerken, Grosse abschwaechen
448
                                n                       = sin_i((GPS_Roll*90)/(GPS_NICKROLL_MAX * GPS_V));
443
                                n                       = sin_i((GPS_Roll*90)/(GPS_NICKROLL_MAX * GPS_V));
449
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
444
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
450
                                GPS_Roll        = (int) n_l;
445
                                GPS_Roll        = (int) n_l;
451
                                n                       = sin_i((GPS_Nick*90)/(GPS_NICKROLL_MAX * GPS_V));
446
                                n                       = sin_i((GPS_Nick*90)/(GPS_NICKROLL_MAX * GPS_V));
452
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
447
                                n_l                     = ((long) GPS_NICKROLL_MAX  * (long) n)/1000;
453
                                GPS_Nick        = (int) n_l;
448
                                GPS_Nick        = (int) n_l;
454
                                 
449
                                 
455
                                if ((abs(dist_east) > GPS_DIST_MAX) || (abs(dist_north) > GPS_DIST_MAX))  // bei zu grossem Abstand abbrechen
450
                                if ((abs(dist_east) > GPS_DIST_MAX) || (abs(dist_north) > GPS_DIST_MAX))  // bei zu grossem Abstand abbrechen
456
                                {
451
                                {
457
                                        GPS_Roll        = 0;
452
                                        GPS_Roll        = 0;
458
                                        GPS_Nick        = 0;
453
                                        GPS_Nick        = 0;
459
                                        gps_state       = GPS_CRTL_IDLE;
454
                                        gps_state       = GPS_CRTL_IDLE;
460
                                        return (GPS_STST_ERR); 
455
                                        return (GPS_STST_ERR); 
461
                                        break;                                 
456
                                        break;                                 
462
                                }
457
                                }
463
                        }
458
                        }
464
                        else return (GPS_STST_OK);
459
                        else return (GPS_STST_OK);
465
                        break;
460
                        break;
466
 
461
 
467
                default:
462
                default:
468
                        gps_state       = GPS_CRTL_IDLE;
463
                        gps_state       = GPS_CRTL_IDLE;
469
                        return (GPS_STST_ERR);
464
                        return (GPS_STST_ERR);
470
                        break;
465
                        break;
471
        }      
466
        }      
472
        return (GPS_STST_ERR);
467
        return (GPS_STST_ERR);
473
                       
468
                       
474
}
469
}
475
 
470
 
476
 
471