Rev 1952 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1952 | Rev 1956 | ||
|---|---|---|---|
| Line 33... | Line 33... | ||
| 33 | 33 | ||
| 34 | var json_data = eval("(" + data + ")"); |
34 | var json_data = eval("(" + data + ")"); |
| 35 | 35 | ||
| 36 | //Log(JSON.stringify(json_data)); |
36 | //Log(JSON.stringify(json_data)); |
| 37 | 37 | ||
| 38 | if (json_data.method == "MBB. |
38 | if (json_data.method == "MBB.OnPosition") |
| 39 | { |
39 | { |
| 40 | if (Mbb_Clients[client_id]) |
40 | if (Mbb_Clients[client_id]) |
| 41 | { |
41 | { |
| - | 42 | Mbb_Clients[client_id]["Position"] = json_data.params; |
|
| - | 43 | ||
| - | 44 | //Log("In params: " + JSON.stringify(json_data.params)); |
|
| - | 45 | ||
| 42 |
|
46 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 43 | { |
47 | { |
| 44 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = json_data.params.nmea; |
- | |
| 45 | } |
- | |
| 46 | else if (json_data.params.nmea.substr(0, 6) == "$GPRMC") |
- | |
| 47 | { |
- | |
| 48 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = json_data.params.nmea; |
- | |
| 49 | - | ||
| 50 | Mbb_Clients[client_id]["Position"] = _Mbb_NmeaToPosition(client_id); |
- | |
| 51 | - | ||
| 52 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
- | |
| 53 | { |
- | |
| 54 |
|
48 | Mbb_Susbscribers[n]("position", Mbb_Clients[client_id]); |
| 55 | } |
- | |
| 56 | - | ||
| 57 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
- | |
| 58 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
- | |
| 59 | Mbb_Clients[client_id]["Position"] = false; |
- | |
| 60 | } |
49 | } |
| - | 50 | ||
| - | 51 | ||
| - | 52 | ||
| - | 53 | //Log("Out nmea:" + JSON.stringify(_Mbb_NmeaToPosition(json_data.params.NmeaRmc, json_data.params.NmeaGga))); |
|
| 61 | } |
54 | } |
| 62 | else |
55 | else |
| 63 | { |
56 | { |
| 64 | Log("Got data from unknown tracker!"); |
57 | Log("Got data from unknown tracker!"); |
| 65 | } |
58 | } |
| 66 | } |
59 | } |
| 67 | else if (json_data.method == "MBB.OnConnected") |
60 | else if (json_data.method == "MBB.OnConnected") |
| 68 | { |
61 | { |
| 69 | json_data = { "params" : { "Imei" : "004401700721448" } }; // Temporary hack since we get corrupted data from the device |
- | |
| 70 | - | ||
| 71 | Log("Client " + client_id + " has IMEI " + json_data.params.Imei); |
62 | Log("Client " + client_id + " has IMEI " + json_data.params.Imei); |
| 72 | 63 | ||
| 73 | Mbb_Clients[client_id]["Id"] = client_id; |
64 | Mbb_Clients[client_id]["Id"] = client_id; |
| 74 | Mbb_Clients[client_id]["Info"] = json_data.params; |
65 | Mbb_Clients[client_id]["Info"] = json_data.params; |
| 75 | Mbb_Clients[client_id]["Position"] = false; |
66 | Mbb_Clients[client_id]["Position"] = false; |
| 76 | Mbb_Clients[client_id]["LastNmea"] = {}; |
- | |
| 77 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
- | |
| 78 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
- | |
| 79 | 67 | ||
| 80 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
68 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 81 | { |
69 | { |
| 82 | Mbb_Susbscribers[n]("connected", Mbb_Clients[client_id]); |
70 | Mbb_Susbscribers[n]("connected", Mbb_Clients[client_id]); |
| 83 | } |
71 | } |
| Line 91... | Line 79... | ||
| 91 | function Mbb_SendData(client_id, json_data) |
79 | function Mbb_SendData(client_id, json_data) |
| 92 | { |
80 | { |
| 93 | return MbbExport_SendData(client_id, JSON.Stringify(json_data)); |
81 | return MbbExport_SendData(client_id, JSON.Stringify(json_data)); |
| 94 | } |
82 | } |
| 95 | 83 | ||
| - | 84 | ||
| 96 | function _Mbb_NmeaToPosition( |
85 | function _Mbb_NmeaToPosition(rmc, gga) |
| 97 | { |
86 | { |
| 98 | /* |
87 | /* |
| 99 | GGA Global Positioning System Fix Data |
88 | GGA Global Positioning System Fix Data |
| 100 | * 123519 Fix taken at 12:35:19 UTC |
89 | * 123519 Fix taken at 12:35:19 UTC |
| 101 | * 4807.038,N Latitude 48 deg 07.038' N |
90 | * 4807.038,N Latitude 48 deg 07.038' N |
| Line 115... | Line 104... | ||
| 115 | * 46.9,M Height of geoid (mean sea level) above WGS84 |
104 | * 46.9,M Height of geoid (mean sea level) above WGS84 |
| 116 | ellipsoid |
105 | ellipsoid |
| 117 | (empty field) time in seconds since last DGPS update |
106 | (empty field) time in seconds since last DGPS update |
| 118 | (empty field) DGPS station ID number |
107 | (empty field) DGPS station ID number |
| 119 | *47 the checksum data, always begins with * |
108 | *47 the checksum data, always begins with * |
| 120 | |
109 | |
| 121 | |
110 | |
| 122 | $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A |
111 | $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A |
| 123 | 112 | ||
| 124 | RMC Recommended Minimum sentence C |
113 | RMC Recommended Minimum sentence C |
| 125 | * 123519 Fix taken at 12:35:19 UTC |
114 | * 123519 Fix taken at 12:35:19 UTC |
| 126 | * A Status A=active or V=Void. |
115 | * A Status A=active or V=Void. |
| Line 130... | Line 119... | ||
| 130 | * 084.4 Track angle in degrees True |
119 | * 084.4 Track angle in degrees True |
| 131 | * 230394 Date - 23rd of March 1994 |
120 | * 230394 Date - 23rd of March 1994 |
| 132 | * 003.1,W Magnetic Variation |
121 | * 003.1,W Magnetic Variation |
| 133 | *6A The checksum data, always begins with * |
122 | *6A The checksum data, always begins with * |
| 134 | */ |
123 | */ |
| 135 | 124 | ||
| 136 | 125 | ||
| 137 | var nmea_rmc_parts = |
126 | var nmea_rmc_parts = rmc.split(","); |
| 138 | 127 | ||
| 139 | if (nmea_rmc_parts[2] == "A") |
128 | if (nmea_rmc_parts[2] == "A") |
| 140 | { |
129 | { |
| 141 | var nmea_gga_parts = |
130 | var nmea_gga_parts = gga.split(","); |
| 142 | var position = {}; |
131 | var position = {}; |
| 143 | 132 | ||
| 144 | position["Datetime"] = "20" + nmea_rmc_parts[9].substr(4, 2) + "-" + nmea_rmc_parts[9].substr(2, 2) + "-" + nmea_rmc_parts[9].substr(0, 2); |
133 | position["Datetime"] = "20" + nmea_rmc_parts[9].substr(4, 2) + "-" + nmea_rmc_parts[9].substr(2, 2) + "-" + nmea_rmc_parts[9].substr(0, 2); |
| 145 | position["Datetime"] += " " + nmea_rmc_parts[1].substr(0, 2) + ":" + nmea_rmc_parts[1].substr(2, 2) + ":" + nmea_rmc_parts[1].substr(4, 2) + " UTC"; |
134 | position["Datetime"] += " " + nmea_rmc_parts[1].substr(0, 2) + ":" + nmea_rmc_parts[1].substr(2, 2) + ":" + nmea_rmc_parts[1].substr(4, 2) + " UTC"; |
| 146 | 135 | ||
| 147 | 136 | ||
| 148 | /* Calculate decimal latitude */ |
137 | /* Calculate decimal latitude */ |
| 149 | var degrees = parseFloat(nmea_rmc_parts[3].substr(0, 2)); |
138 | var degrees = parseFloat(nmea_rmc_parts[3].substr(0, 2)); |
| 150 | var decimal = parseFloat(nmea_rmc_parts[3].substr(2)); |
139 | var decimal = parseFloat(nmea_rmc_parts[3].substr(2)); |
| 151 | 140 | ||
| 152 | position["Latitude"] = degrees + (decimal / 60.0); |
141 | position["Latitude"] = degrees + (decimal / 60.0); |
| 153 | 142 | ||
| 154 | if (nmea_rmc_parts[4] == "S") |
143 | if (nmea_rmc_parts[4] == "S") |
| 155 | { |
144 | { |
| 156 | position["Latitude"] = -position["Latitude"]; |
145 | position["Latitude"] = -position["Latitude"]; |
| 157 | } |
146 | } |
| 158 | 147 | ||
| 159 | /* Calculate decimal longitude */ |
148 | /* Calculate decimal longitude */ |
| 160 | var degrees = parseFloat(nmea_rmc_parts[5].substr(0, 3)); |
149 | var degrees = parseFloat(nmea_rmc_parts[5].substr(0, 3)); |
| 161 | var decimal = parseFloat(nmea_rmc_parts[5].substr(3)); |
150 | var decimal = parseFloat(nmea_rmc_parts[5].substr(3)); |
| 162 | 151 | ||
| 163 | position["Longitude"] = degrees + (decimal / 60.0); |
152 | position["Longitude"] = degrees + (decimal / 60.0); |
| 164 | 153 | ||
| 165 | if (nmea_rmc_parts[6] == "W") |
154 | if (nmea_rmc_parts[6] == "W") |
| 166 | { |
155 | { |
| 167 | position["Longitude"] = -position["Longitude"]; |
156 | position["Longitude"] = -position["Longitude"]; |
| 168 | } |
157 | } |
| 169 | 158 | ||
| 170 | position["Hdop"] = nmea_gga_parts[8]; |
159 | position["Hdop"] = nmea_gga_parts[8]; |
| 171 | 160 | ||
| 172 | position["Satellites"] = nmea_gga_parts[7]; |
161 | position["Satellites"] = nmea_gga_parts[7]; |
| 173 | 162 | ||
| 174 | position["Altitude"] = nmea_gga_parts[9]; // Meters |
163 | position["Altitude"] = nmea_gga_parts[9]; // Meters |
| 175 | position["HeightOfGeoid"] = nmea_gga_parts[11] // Meters |
164 | position["HeightOfGeoid"] = nmea_gga_parts[11] // Meters |
| 176 | 165 | ||
| 177 | position["Speed"] = nmea_rmc_parts[7]; // Knots |
166 | position["Speed"] = nmea_rmc_parts[7]; // Knots |
| 178 | position["Angle"] = nmea_rmc_parts[8]; |
167 | position["Angle"] = nmea_rmc_parts[8]; |
| 179 | 168 | ||
| 180 | if (nmea_rmc_parts[10] != "") |
- | |
| 181 | { |
- | |
| 182 | position["MagneticDeclination"] = parseFloat(nmea_rmc_parts[10]); |
- | |
| 183 | - | ||
| 184 | if (nmea_rmc_parts[11].substr(0, 1) == "W") |
- | |
| 185 | { |
- | |
| 186 | position["MagneticDeclination"] = -position["MagneticDeclination"]; |
- | |
| 187 | } |
- | |
| 188 | } |
- | |
| 189 | 169 | ||
| 190 | return position; |
170 | return position; |
| 191 | } |
171 | } |
| 192 | 172 | ||
| 193 | return false; |
173 | return false; |
| 194 | } |
174 | } |
| - | 175 | ||