Rev 1952 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1952 | Rev 1956 | ||
|---|---|---|---|
| 1 | 1 | ||
| 2 | Mbb_Clients = {}; |
2 | Mbb_Clients = {}; |
| 3 | 3 | ||
| 4 | Mbb_Susbscribers = []; |
4 | Mbb_Susbscribers = []; |
| 5 | 5 | ||
| 6 | function Mbb_SubscribeToDeviceStatus(callback) |
6 | function Mbb_SubscribeToDeviceStatus(callback) |
| 7 | { |
7 | { |
| 8 | Mbb_Susbscribers.push(callback); |
8 | Mbb_Susbscribers.push(callback); |
| 9 | } |
9 | } |
| 10 | 10 | ||
| 11 | function Mbb_Connected(client_id) |
11 | function Mbb_Connected(client_id) |
| 12 | { |
12 | { |
| 13 | Log(client_id + " connected!"); |
13 | Log(client_id + " connected!"); |
| 14 | 14 | ||
| 15 | Mbb_Clients[client_id] = {}; |
15 | Mbb_Clients[client_id] = {}; |
| 16 | } |
16 | } |
| 17 | 17 | ||
| 18 | function Mbb_Disconnected(client_id) |
18 | function Mbb_Disconnected(client_id) |
| 19 | { |
19 | { |
| 20 | Log(client_id + " disconnected!"); |
20 | Log(client_id + " disconnected!"); |
| 21 | 21 | ||
| 22 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
22 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 23 | { |
23 | { |
| 24 | Mbb_Susbscribers[n]("disconnected", Mbb_Clients[client_id]); |
24 | Mbb_Susbscribers[n]("disconnected", Mbb_Clients[client_id]); |
| 25 | } |
25 | } |
| 26 | 26 | ||
| 27 | delete Mbb_Clients[client_id]; |
27 | delete Mbb_Clients[client_id]; |
| 28 | } |
28 | } |
| 29 | 29 | ||
| 30 | function Mbb_ReceivedData(client_id, data) |
30 | function Mbb_ReceivedData(client_id, data) |
| 31 | { |
31 | { |
| 32 | Log(data); |
32 | Log(data); |
| 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 |
|
42 | Mbb_Clients[client_id]["Position"] = json_data.params; |
| 43 |
|
43 | |
| 44 |
|
44 | //Log("In params: " + JSON.stringify(json_data.params)); |
| 45 |
|
45 | |
| 46 |
|
46 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 47 | { |
47 | { |
| 48 |
|
48 | Mbb_Susbscribers[n]("position", Mbb_Clients[client_id]); |
| 49 | 49 | } |
|
| 50 | Mbb_Clients[client_id]["Position"] = _Mbb_NmeaToPosition(client_id); |
- | |
| - | 50 | ||
| 51 | 51 | ||
| - | 52 | ||
| 52 |
|
53 | //Log("Out nmea:" + JSON.stringify(_Mbb_NmeaToPosition(json_data.params.NmeaRmc, json_data.params.NmeaGga))); |
| - | 54 | } |
|
| - | 55 | else |
|
| 53 | { |
56 | { |
| 54 | 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 | } |
- | |
| 61 | } |
- | |
| 62 | else |
- | |
| 63 | { |
- | |
| 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 | } |
| 84 | } |
72 | } |
| 85 | else |
73 | else |
| 86 | { |
74 | { |
| 87 | Log("Got unknown data \"" + data + "\" from client " + client_id); |
75 | Log("Got unknown data \"" + data + "\" from client " + client_id); |
| 88 | } |
76 | } |
| 89 | } |
77 | } |
| 90 | 78 | ||
| 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 |
| 102 | * 01131.000,E Longitude 11 deg 31.000' E |
91 | * 01131.000,E Longitude 11 deg 31.000' E |
| 103 | 1 Fix quality: 0 = invalid |
92 | 1 Fix quality: 0 = invalid |
| 104 | 1 = GPS fix (SPS) |
93 | 1 = GPS fix (SPS) |
| 105 | 2 = DGPS fix |
94 | 2 = DGPS fix |
| 106 | 3 = PPS fix |
95 | 3 = PPS fix |
| 107 | 4 = Real Time Kinematic |
96 | 4 = Real Time Kinematic |
| 108 | 5 = Float RTK |
97 | 5 = Float RTK |
| 109 | 6 = estimated (dead reckoning) (2.3 feature) |
98 | 6 = estimated (dead reckoning) (2.3 feature) |
| 110 | 7 = Manual input mode |
99 | 7 = Manual input mode |
| 111 | 8 = Simulation mode |
100 | 8 = Simulation mode |
| 112 | * 08 Number of satellites being tracked |
101 | * 08 Number of satellites being tracked |
| 113 | * 0.9 Horizontal dilution of position |
102 | * 0.9 Horizontal dilution of position |
| 114 | * 545.4,M Altitude, Meters, above mean sea level |
103 | * 545.4,M Altitude, Meters, above mean sea level |
| 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. |
| 127 | * 4807.038,N Latitude 48 deg 07.038' N |
116 | * 4807.038,N Latitude 48 deg 07.038' N |
| 128 | * 01131.000,E Longitude 11 deg 31.000' E |
117 | * 01131.000,E Longitude 11 deg 31.000' E |
| 129 | * 022.4 Speed over the ground in knots |
118 | * 022.4 Speed over the ground in knots |
| 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 | ||
| 195 | - | ||