The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.
This URL has Read-Only access.
root / trunk / DomotiGaServer / CGPS.class @ 693
History | View | Annotate | Download (5.5 kB)
| 1 | ' Gambas class file |
|---|---|
| 2 | |
| 3 | ' Description: |
| 4 | ' CGPS.class |
| 5 | ' u-blox AG MS1E GPS module (NMEA) support to get GPS time, precise position, and altitude |
| 6 | ' GPS module version: $Version 1.3.4P00283 uBlx308 |
| 7 | |
| 8 | ' Development Status: |
| 9 | ' Reads serial data, needs parsing to be implemented. |
| 10 | ' Wrote it for fun, no serious purpose for a non mobile server. |
| 11 | |
| 12 | ' Links: |
| 13 | ' http://aprs.gids.nl/nmea/ |
| 14 | |
| 15 | ' DomotiGa - an open source home automation program. |
| 16 | ' Copyright(C) 2008-2009 Ron Klinkien |
| 17 | ' Module additions Copyright(C) 2009 by Timo Sariwating |
| 18 | |
| 19 | ' Read file called COPYING for license details. |
| 20 | |
| 21 | ' Notes: |
| 22 | ' NMEA sentences: |
| 23 | ' $GPBOD - Bearing, origin TO destination |
| 24 | ' $GPBWC - Bearing AND distance TO waypoint, great circle |
| 25 | ' $GPGGA - Global Positioning System Fix Data |
| 26 | ' $GPGLL - Geographic position, latitude / longitude |
| 27 | ' $GPGSA - GPS DOP AND active satellites |
| 28 | ' $GPGSV - GPS Satellites IN view |
| 29 | ' $GPHDT - Heading, TRUE |
| 30 | ' $GPR00 - List OF waypoints IN currently active route |
| 31 | ' $GPRMA - Recommended minimum specific Loran - C data |
| 32 | ' $GPRMB - Recommended minimum navigation info |
| 33 | ' $GPRMC - Recommended minimum specific GPS / Transit data |
| 34 | ' $GPRTE - Routes |
| 35 | ' $GPTRF - Transit Fix Data |
| 36 | ' $GPSTN - Multiple Data ID |
| 37 | ' $GPVBW - Dual Ground / Water Speed |
| 38 | ' $GPVTG - Track made good AND ground speed |
| 39 | ' $GPWPL - Waypoint location |
| 40 | ' $GPXTE - Cross - track ERROR , Measured |
| 41 | ' $GPZDA - Date & Time |
| 42 | |
| 43 | PROPERTY Port AS String |
| 44 | PROPERTY Baud AS String |
| 45 | PROPERTY GPSDebug AS Boolean |
| 46 | |
| 47 | PRIVATE sPort AS String |
| 48 | PRIVATE sBaud AS String |
| 49 | PRIVATE bGPSDebug AS Boolean |
| 50 | |
| 51 | PUBLIC hGPS AS NEW SerialPort |
| 52 | |
| 53 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 54 | ' open serial port |
| 55 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 56 | PUBLIC FUNCTION Connect() AS Boolean |
| 57 | |
| 58 | ' try to close the port |
| 59 | TRY hGPS.Close |
| 60 | |
| 61 | ' get a new one |
| 62 | hGPS = NEW Serialport AS "GPS" |
| 63 | WITH hGPS |
| 64 | .PortName = sPort |
| 65 | .Speed = sBaud |
| 66 | .Parity = 0 |
| 67 | .DataBits = 8 |
| 68 | .StopBits = 1 |
| 69 | .FlowControl = 0 |
| 70 | .Open() |
| 71 | END WITH |
| 72 | |
| 73 | ' all ok |
| 74 | RETURN TRUE |
| 75 | |
| 76 | CATCH ' some errors |
| 77 | Main.WriteLog(("GPS Error: ") & ERROR.Text)
|
| 78 | RETURN FALSE |
| 79 | |
| 80 | END |
| 81 | |
| 82 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 83 | ' close port |
| 84 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 85 | PUBLIC FUNCTION Disconnect() AS Boolean |
| 86 | |
| 87 | ' try to close the connection |
| 88 | TRY hGPS.Close |
| 89 | Main.WriteLog(("GPS serial port close."))
|
| 90 | |
| 91 | ' all ok |
| 92 | RETURN TRUE |
| 93 | |
| 94 | CATCH ' some errors |
| 95 | Main.WriteLog(("GPS Error: ") & ERROR.Text)
|
| 96 | RETURN FALSE |
| 97 | |
| 98 | END |
| 99 | |
| 100 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 101 | ' got data input |
| 102 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 103 | PUBLIC SUB GPS_Read() |
| 104 | |
| 105 | DIM sData AS String |
| 106 | |
| 107 | LINE INPUT #hGPS, sData |
| 108 | SELECT CASE Mid$(sdata, 2, 5) |
| 109 | CASE "GPGLL" ' position |
| 110 | Main.WriteDebugLog(("[GPS] Position: ") & sData)
|
| 111 | CASE "GPZDA" ' date & time |
| 112 | Main.WriteDebugLog(("[GPS] Date & Time: ") & sData)
|
| 113 | CASE "GPGGA" ' fix data |
| 114 | GPSFix(sData) |
| 115 | CASE "GPGSV" ' satellites in view |
| 116 | 'Main.WriteDebugLog("[GPS] Satellites in view: " & sData)
|
| 117 | END SELECT |
| 118 | |
| 119 | END |
| 120 | |
| 121 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 122 | ' parse fix data |
| 123 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 124 | PRIVATE FUNCTION GPSFix(sValue AS String) |
| 125 | |
| 126 | DIM sGPSFix AS String[] |
| 127 | DIM sB, sC AS String |
| 128 | DIM iCounter AS Integer = 1 |
| 129 | |
| 130 | sGPSFix = Split(sValue, ",") |
| 131 | |
| 132 | FOR EACH sB IN sGPSFix |
| 133 | SELECT CASE (iCounter) |
| 134 | CASE 1 |
| 135 | INC iCounter |
| 136 | CASE 2 |
| 137 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Time: ") & sB)
|
| 138 | INC iCounter |
| 139 | CASE 3 |
| 140 | sC = sB |
| 141 | INC iCounter |
| 142 | CASE 4 |
| 143 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Latitude: ") & sC & " " & sB)
|
| 144 | sC = "" |
| 145 | INC iCounter |
| 146 | CASE 5 |
| 147 | sC = sB |
| 148 | INC iCounter |
| 149 | CASE 6 |
| 150 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Longitude: ") & sC & " " & sB)
|
| 151 | sC = "" |
| 152 | INC iCounter |
| 153 | CASE 7 |
| 154 | IF bGPSDebug THEN |
| 155 | SELECT CASE (sB) |
| 156 | CASE 0 |
| 157 | Main.WriteDebugLog(("[GPS] Fix Quality: Invalid"))
|
| 158 | INC iCounter |
| 159 | CASE 1 |
| 160 | Main.WriteDebugLog(("[GPS] Fix Quality: GPS Fix"))
|
| 161 | INC iCounter |
| 162 | CASE 2 |
| 163 | Main.WriteDebugLog(("[GPS] Fix Quality: DGPS Fix"))
|
| 164 | INC iCounter |
| 165 | END SELECT |
| 166 | ELSE |
| 167 | INC iCounter |
| 168 | ENDIF |
| 169 | CASE 8 |
| 170 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Number of Satellites: ") & sB)
|
| 171 | INC iCounter |
| 172 | CASE 9 |
| 173 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] HDOP: ") & sB)
|
| 174 | INC iCounter |
| 175 | CASE 10 |
| 176 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Altitude: ") & sB)
|
| 177 | INC iCounter |
| 178 | CASE 11 |
| 179 | INC iCounter |
| 180 | CASE 12 |
| 181 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Heigh above WGS84: ") & sB)
|
| 182 | INC iCounter |
| 183 | CASE 13 |
| 184 | INC iCounter |
| 185 | CASE 14 |
| 186 | IF bGPSDebug THEN Main.WriteDebugLog(("[GPS] Time since last DGPS update: ") & sB)
|
| 187 | INC iCounter |
| 188 | CASE 15 |
| 189 | IF bGPSDebug THEN |
| 190 | Main.WriteDebugLog(("[GPS] DGPS Station ID: ") & Left$(sB, 4))
|
| 191 | Main.WriteDebugLog(("[GPS] CheckSum: ") & Right$(sB, -4))
|
| 192 | ENDIF |
| 193 | END SELECT |
| 194 | NEXT |
| 195 | |
| 196 | END |
| 197 | |
| 198 | ' implement the properties |
| 199 | PRIVATE FUNCTION Port_Read() AS String |
| 200 | |
| 201 | RETURN sPort |
| 202 | |
| 203 | END |
| 204 | |
| 205 | PRIVATE SUB Port_Write(sValue AS String) |
| 206 | |
| 207 | sPort = sValue |
| 208 | |
| 209 | END |
| 210 | |
| 211 | PRIVATE FUNCTION Baud_Read() AS String |
| 212 | |
| 213 | RETURN sBaud |
| 214 | |
| 215 | END |
| 216 | |
| 217 | PRIVATE SUB Baud_Write(sValue AS String) |
| 218 | |
| 219 | sBaud = sValue |
| 220 | |
| 221 | END |
| 222 | |
| 223 | PRIVATE FUNCTION GPSDebug_Read() AS Boolean |
| 224 | |
| 225 | RETURN bGPSDebug |
| 226 | |
| 227 | END |
| 228 | |
| 229 | PRIVATE SUB GPSDebug_Write(sValue AS Boolean) |
| 230 | |
| 231 | bGPSDebug = sValue |
| 232 | |
| 233 | END |
