Rev 1949 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1949 | Rev 1950 | ||
|---|---|---|---|
| 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.GpsNmeaData") |
38 | if (json_data.method == "MBB.GpsNmeaData") |
| 39 | { |
39 | { |
| 40 | if (json_data.params.nmea.substr(0, 6) == "$GPGGA") |
40 | if (json_data.params.nmea.substr(0, 6) == "$GPGGA") |
| 41 | { |
41 | { |
| 42 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = json_data.params.nmea; |
42 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = json_data.params.nmea; |
| 43 | } |
43 | } |
| 44 | else if (json_data.params.nmea.substr(0, 6) == "$GPRMC") |
44 | else if (json_data.params.nmea.substr(0, 6) == "$GPRMC") |
| 45 | { |
45 | { |
| 46 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = json_data.params.nmea; |
46 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = json_data.params.nmea; |
| 47 | 47 | ||
| 48 | Mbb_Clients[client_id]["Position"] = _Mbb_NmeaToPosition(client_id); |
48 | Mbb_Clients[client_id]["Position"] = _Mbb_NmeaToPosition(client_id); |
| 49 | 49 | ||
| 50 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
50 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 51 | { |
51 | { |
| 52 | Mbb_Susbscribers[n]("position", Mbb_Clients[client_id]); |
52 | Mbb_Susbscribers[n]("position", Mbb_Clients[client_id]); |
| 53 | } |
53 | } |
| 54 | 54 | ||
| 55 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
55 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
| 56 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
56 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
| 57 | Mbb_Clients[client_id]["Position"] = false; |
57 | Mbb_Clients[client_id]["Position"] = false; |
| 58 | } |
58 | } |
| 59 | } |
59 | } |
| 60 | else /*if (json_data.method == "MBB.Connected")*/ |
60 | else /*if (json_data.method == "MBB.Connected")*/ |
| 61 | { |
61 | { |
| 62 | json_data = { "params" : { "Imei" : "004401700721448" } }; |
62 | json_data = { "params" : { "Imei" : "004401700721448" } }; |
| 63 | 63 | ||
| 64 | Log("Client " + client_id + " has IMEI " + json_data.params.Imei); |
64 | Log("Client " + client_id + " has IMEI " + json_data.params.Imei); |
| 65 | 65 | ||
| 66 | Mbb_Clients[client_id]["Id"] = client_id; |
66 | Mbb_Clients[client_id]["Id"] = client_id; |
| 67 | Mbb_Clients[client_id]["Info"] = json_data.params; |
67 | Mbb_Clients[client_id]["Info"] = json_data.params; |
| 68 | Mbb_Clients[client_id]["Position"] = false; |
68 | Mbb_Clients[client_id]["Position"] = false; |
| 69 | Mbb_Clients[client_id]["LastNmea"] = {}; |
69 | Mbb_Clients[client_id]["LastNmea"] = {}; |
| 70 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
70 | Mbb_Clients[client_id]["LastNmea"]["GGA"] = ""; |
| 71 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
71 | Mbb_Clients[client_id]["LastNmea"]["RMC"] = ""; |
| 72 | 72 | ||
| 73 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
73 | for (var n = 0; n < Mbb_Susbscribers.length; n++) |
| 74 | { |
74 | { |
| 75 | Mbb_Susbscribers[n]("connected", Mbb_Clients[client_id]); |
75 | Mbb_Susbscribers[n]("connected", Mbb_Clients[client_id]); |
| 76 | } |
76 | } |
| 77 | } |
77 | } |
| 78 | /*else |
78 | /*else |
| 79 | { |
79 | { |
| 80 | Log("Got unknown data \"" + json_data + "\" from client " + client_id); |
80 | Log("Got unknown data \"" + json_data + "\" from client " + client_id); |
| 81 | }*/ |
81 | }*/ |
| 82 | } |
82 | } |
| 83 | 83 | ||
| 84 | function Mbb_SendData(client_id, json_data) |
84 | function Mbb_SendData(client_id, json_data) |
| 85 | { |
85 | { |
| 86 | return MbbExport_SendData(client_id, JSON.Stringify(json_data)); |
86 | return MbbExport_SendData(client_id, JSON.Stringify(json_data)); |
| 87 | } |
87 | } |
| 88 | 88 | ||
| 89 | function _Mbb_NmeaToPosition(client_id) |
89 | function _Mbb_NmeaToPosition(client_id) |
| 90 | { |
90 | { |
| 91 | /* |
91 | /* |
| 92 | GGA Global Positioning System Fix Data |
92 | GGA Global Positioning System Fix Data |
| 93 | * 123519 Fix taken at 12:35:19 UTC |
93 | * 123519 Fix taken at 12:35:19 UTC |
| 94 | * 4807.038,N Latitude 48 deg 07.038' N |
94 | * 4807.038,N Latitude 48 deg 07.038' N |
| 95 | * 01131.000,E Longitude 11 deg 31.000' E |
95 | * 01131.000,E Longitude 11 deg 31.000' E |
| 96 | 1 Fix quality: 0 = invalid |
96 | 1 Fix quality: 0 = invalid |
| 97 | 1 = GPS fix (SPS) |
97 | 1 = GPS fix (SPS) |
| 98 | 2 = DGPS fix |
98 | 2 = DGPS fix |
| 99 | 3 = PPS fix |
99 | 3 = PPS fix |
| 100 | 4 = Real Time Kinematic |
100 | 4 = Real Time Kinematic |
| 101 | 5 = Float RTK |
101 | 5 = Float RTK |
| 102 | 6 = estimated (dead reckoning) (2.3 feature) |
102 | 6 = estimated (dead reckoning) (2.3 feature) |
| 103 | 7 = Manual input mode |
103 | 7 = Manual input mode |
| 104 | 8 = Simulation mode |
104 | 8 = Simulation mode |
| 105 | * 08 Number of satellites being tracked |
105 | * 08 Number of satellites being tracked |
| 106 | * 0.9 Horizontal dilution of position |
106 | * 0.9 Horizontal dilution of position |
| 107 | * 545.4,M Altitude, Meters, above mean sea level |
107 | * 545.4,M Altitude, Meters, above mean sea level |
| 108 | * 46.9,M Height of geoid (mean sea level) above WGS84 |
108 | * 46.9,M Height of geoid (mean sea level) above WGS84 |
| 109 | ellipsoid |
109 | ellipsoid |
| 110 | (empty field) time in seconds since last DGPS update |
110 | (empty field) time in seconds since last DGPS update |
| 111 | (empty field) DGPS station ID number |
111 | (empty field) DGPS station ID number |
| 112 | *47 the checksum data, always begins with * |
112 | *47 the checksum data, always begins with * |
| 113 | |
113 | |
| 114 | |
114 | |
| 115 | $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A |
115 | $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A |
| 116 | 116 | ||
| 117 | RMC Recommended Minimum sentence C |
117 | RMC Recommended Minimum sentence C |
| 118 | * 123519 Fix taken at 12:35:19 UTC |
118 | * 123519 Fix taken at 12:35:19 UTC |
| 119 | * A Status A=active or V=Void. |
119 | * A Status A=active or V=Void. |
| 120 | * 4807.038,N Latitude 48 deg 07.038' N |
120 | * 4807.038,N Latitude 48 deg 07.038' N |
| 121 | * 01131.000,E Longitude 11 deg 31.000' E |
121 | * 01131.000,E Longitude 11 deg 31.000' E |
| 122 | * 022.4 Speed over the ground in knots |
122 | * 022.4 Speed over the ground in knots |
| 123 | * 084.4 Track angle in degrees True |
123 | * 084.4 Track angle in degrees True |
| 124 | * 230394 Date - 23rd of March 1994 |
124 | * 230394 Date - 23rd of March 1994 |
| 125 | * 003.1,W Magnetic Variation |
125 | * 003.1,W Magnetic Variation |
| 126 | *6A The checksum data, always begins with * |
126 | *6A The checksum data, always begins with * |
| 127 | */ |
127 | */ |
| 128 | 128 | ||
| 129 | 129 | ||
| 130 | var nmea_rmc_parts = Mbb_Clients[client_id]["LastNmea"]["RMC"].split(","); |
130 | var nmea_rmc_parts = Mbb_Clients[client_id]["LastNmea"]["RMC"].split(","); |
| 131 | 131 | ||
| 132 | if (nmea_rmc_parts[2] == "A") |
132 | if (nmea_rmc_parts[2] == "A") |
| 133 | { |
133 | { |
| 134 | var nmea_gga_parts = Mbb_Clients[client_id]["LastNmea"]["GGA"].split(","); |
134 | var nmea_gga_parts = Mbb_Clients[client_id]["LastNmea"]["GGA"].split(","); |
| 135 | var position = {}; |
135 | var position = {}; |
| 136 | 136 | ||
| 137 | position["Datetime"] = "20" + nmea_rmc_parts[9].substr(4, 2) + "-" + nmea_rmc_parts[9].substr(2, 2) + "-" + nmea_rmc_parts[9].substr(0, 2); |
137 | position["Datetime"] = "20" + nmea_rmc_parts[9].substr(4, 2) + "-" + nmea_rmc_parts[9].substr(2, 2) + "-" + nmea_rmc_parts[9].substr(0, 2); |
| 138 | position["Datetime"] += " " + nmea_rmc_parts[1].substr(0, 2) + ":" + nmea_rmc_parts[1].substr(2, 2) + ":" + nmea_rmc_parts[1].substr(4, 2) + " UTC"; |
138 | position["Datetime"] += " " + nmea_rmc_parts[1].substr(0, 2) + ":" + nmea_rmc_parts[1].substr(2, 2) + ":" + nmea_rmc_parts[1].substr(4, 2) + " UTC"; |
| 139 | 139 | ||
| 140 | position["Latitude"] = nmea_rmc_parts[3] + "," + nmea_rmc_parts[4]; |
- | |
| 141 | position["Longitude"] = nmea_rmc_parts[5] + "," + nmea_rmc_parts[6]; |
- | |
| 142 | position["HorizontalDilution"] = nmea_gga_parts[8]; |
- | |
| 143 | 140 | ||
| - | 141 | /* Calculate decimal latitude */ |
|
| 144 |
|
142 | var degrees = parseFloat(nmea_rmc_parts[3].substr(0, 2)); |
| 145 |
|
143 | var decimal = parseFloat(nmea_rmc_parts[3].substr(2)); |
| 146 | 144 | ||
| 147 | position[" |
145 | position["Latitude"] = degrees + (decimal / 60.0); |
| 148 | 146 | ||
| - | 147 | if (nmea_rmc_parts[4] == "S") |
|
| - | 148 | { |
|
| - | 149 | position["Latitude"] = -position["Latitude"]; |
|
| - | 150 | } |
|
| - | 151 | ||
| - | 152 | /* Calculate decimal longitude */ |
|
| - | 153 | var degrees = parseFloat(nmea_rmc_parts[5].substr(0, 3)); |
|
| - | 154 | var decimal = parseFloat(nmea_rmc_parts[5].substr(3)); |
|
| - | 155 | ||
| - | 156 | position["Longitude"] = degrees + (decimal / 60.0); |
|
| - | 157 | ||
| - | 158 | if (nmea_rmc_parts[6] == "W") |
|
| - | 159 | { |
|
| - | 160 | position["Longitude"] = -position["Longitude"]; |
|
| - | 161 | } |
|
| - | 162 | ||
| - | 163 | position["Hdop"] = nmea_gga_parts[8]; |
|
| - | 164 | ||
| - | 165 | position["Satellites"] = nmea_gga_parts[7]; |
|
| - | 166 | ||
| - | 167 | position["Altitude"] = nmea_gga_parts[9]; // Meters |
|
| - | 168 | position["HeightOfGeoid"] = nmea_gga_parts[11] // Meters |
|
| - | 169 | ||
| - | 170 | position["Speed"] = nmea_rmc_parts[7]; // Knots |
|
| 149 | position["Angle"] = nmea_rmc_parts[8]; |
171 | position["Angle"] = nmea_rmc_parts[8]; |
| 150 | 172 | ||
| 151 | if (nmea_rmc_parts[10] != "") |
173 | if (nmea_rmc_parts[10] != "") |
| 152 | { |
174 | { |
| 153 | position[" |
175 | position["MagneticDeclination"] = parseFloat(nmea_rmc_parts[10]); |
| - | 176 | ||
| - | 177 | if (nmea_rmc_parts[11].substr(0, 1) == "W") |
|
| - | 178 | { |
|
| - | 179 | position["MagneticDeclination"] = -position["MagneticDeclination"]; |
|
| - | 180 | } |
|
| 154 | } |
181 | } |
| 155 | 182 | ||
| 156 | return position; |
183 | return position; |
| 157 | } |
184 | } |
| 158 | 185 | ||
| 159 | return false; |
186 | return false; |
| 160 | } |
187 | } |
| 161 | 188 | ||