Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1704 | - | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + FOR NON COMMERCIAL USE ONLY |
||
8 | // + www.MikroKopter.com |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
15 | // + Verkauf von Luftbildaufnahmen, usw. |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
22 | // + eindeutig als Ursprung verlinkt werden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
25 | // + Benutzung auf eigene Gefahr |
||
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
||
29 | // + mit unserer Zustimmung zulässig |
||
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
34 | // + this list of conditions and the following disclaimer. |
||
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
36 | // + from this software without specific prior written permission. |
||
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
||
38 | // + for non-commercial use (directly or indirectly) |
||
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
40 | // + with our written permission |
||
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
42 | // + clearly linked as origin |
||
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
||
44 | // |
||
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
55 | // + POSSIBILITY OF SUCH DAMAGE. |
||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | #include "gps.h" |
||
58 | #include "uart0.h" |
||
59 | #include "main.h" |
||
60 | #include "timer0.h" |
||
61 | |||
62 | #define GPS_TIMEOUT 1000 // if no new gps data arrive within that time an error is set |
||
63 | #define GPS_MINSATS 4 |
||
64 | |||
65 | //------------------------------------------------------------ |
||
66 | // copy GPS position from source position to target position |
||
67 | uint8_t GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt) |
||
68 | { |
||
69 | uint8_t retval = 0; |
||
70 | if((pGPSPosSrc == 0) || (pGPSPosTgt == 0)) return(retval); // bad pointer |
||
71 | // copy only valid positions |
||
72 | if(pGPSPosSrc->Status != INVALID) |
||
73 | { |
||
74 | // if the source GPS position is not invalid |
||
75 | pGPSPosTgt->Longitude = pGPSPosSrc->Longitude; |
||
76 | pGPSPosTgt->Latitude = pGPSPosSrc->Latitude; |
||
77 | pGPSPosTgt->Altitude = pGPSPosSrc->Altitude; |
||
78 | pGPSPosTgt->Status = NEWDATA; // mark data in target position as new |
||
79 | retval = 1; |
||
80 | } |
||
81 | return(retval); |
||
82 | } |
||
83 | |||
84 | //------------------------------------------------------------ |
||
85 | // clear position data |
||
86 | uint8_t GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
||
87 | { |
||
88 | uint8_t retval = 0; |
||
89 | if(pGPSPos == 0) return(retval); // bad pointer |
||
90 | else |
||
91 | { |
||
92 | pGPSPos->Longitude = 0; |
||
93 | pGPSPos->Latitude = 0; |
||
94 | pGPSPos->Altitude = 0; |
||
95 | pGPSPos->Status = INVALID; |
||
96 | retval = 1; |
||
97 | } |
||
98 | return (retval); |
||
99 | } |
||
100 | |||
101 | |||
102 | //------------------------------------------------------------ |
||
103 | // check for new GPS data |
||
104 | void GPS_Update(void) |
||
105 | { |
||
106 | static uint16_t GPS_Timeout = 0; |
||
107 | static uint16_t beep_rythm = 0; |
||
108 | |||
109 | switch(GPSData.Status) |
||
110 | { |
||
111 | case INVALID: |
||
112 | Error |= ERROR_GPS_RX_TIMEOUT; |
||
113 | GPS_ClearPosition(&(FollowMe.Position)); // clear followme position |
||
114 | break; |
||
115 | |||
116 | case PROCESSED: |
||
117 | // wait for timeout |
||
118 | if(CheckDelay(GPS_Timeout)) |
||
119 | { |
||
120 | GPSData.Status = INVALID; |
||
121 | } |
||
122 | break; |
||
123 | |||
124 | case NEWDATA: |
||
125 | GPS_Timeout = SetDelay(GPS_TIMEOUT); // reset gps timeout |
||
126 | Error &= ~ERROR_GPS_RX_TIMEOUT; // clear possible error |
||
127 | beep_rythm++; |
||
128 | |||
129 | // update data in the FollowMe message |
||
130 | if((GPSData.SatFix & SATFIX_3D) && (GPSData.NumOfSats >= GPS_MINSATS)) |
||
131 | { |
||
132 | GPS_CopyPosition(&(GPSData.Position),&(FollowMe.Position)); |
||
133 | } |
||
134 | else |
||
135 | { |
||
136 | GPS_ClearPosition(&(FollowMe.Position)); // clear followme position |
||
137 | } |
||
138 | |||
139 | // NC like sound on bad gps signals |
||
140 | if(SysState == STATE_SEND_FOLLOWME) |
||
141 | { |
||
142 | if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100; |
||
143 | else if ((GPSData.NumOfSats < GPS_MINSATS) && !(beep_rythm % 5)) BeepTime = 10; |
||
144 | } |
||
145 | |||
146 | GPSData.Status = PROCESSED; // set to processed unlocks the buffer for new data |
||
147 | break; |
||
148 | |||
149 | default: |
||
150 | GPSData.Status = INVALID; |
||
151 | break; |
||
152 | } |
||
153 | } |
||
154 |