keyhole 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/keyhole.rb +1 -0
- data/lib/sat_parser.rb +45 -5
- metadata +3 -3
data/lib/keyhole.rb
CHANGED
data/lib/sat_parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class SatParser < EventMachine::Connection
|
2
2
|
|
3
|
-
attr_accessor :db
|
3
|
+
attr_accessor :db, :imei, :latest_location, :hdop
|
4
4
|
|
5
5
|
def post_init
|
6
6
|
puts self.inspect
|
@@ -9,16 +9,56 @@ class SatParser < EventMachine::Connection
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def receive_data(data)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
data = data.split(",")
|
13
|
+
self.imei = data[0]
|
14
|
+
loc = {
|
15
|
+
:longitude => parse_lng(data[5]),
|
16
|
+
:latitude => parse_lat(data[6]),
|
17
|
+
:altitude => data[7],
|
18
|
+
:nos => data[10].split(/\*/)[0],
|
19
|
+
:hdop => data[10].split(/\*/)[1],
|
20
|
+
:tracker => get_tracker_id(data[0])
|
21
|
+
}
|
22
|
+
|
23
|
+
self.latest_location = loc
|
24
|
+
self.hdop = loc[:hdop]
|
25
|
+
|
26
|
+
q = @db.query("insert into locations(longitude, latitude, altitude, nos, hdop, tracker_id) value('#{loc[:longitude]}','#{loc[:latitude]}', #{loc[:altitude]}, #{loc[:nos]}, #{loc[:hdop]}, #{loc[:tracker]});")
|
27
|
+
|
15
28
|
q.callback{|res| puts res.inspect}
|
16
29
|
q.errback{|res| puts "E:"+res.inspect}
|
17
|
-
|
30
|
+
|
31
|
+
$channel << JSON.generate(loc)
|
18
32
|
end
|
19
33
|
|
20
34
|
def unbind
|
21
35
|
$channel << "GSAT closed connection"
|
22
36
|
end
|
23
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def parse_lat(lat)
|
41
|
+
fraction = ((lat[3..4].to_f * 60) + (lat[5..9].to_f*60.0)) / 3600.0
|
42
|
+
sum = lat[1..2].to_f + fraction
|
43
|
+
if(lat[0] == 'S')
|
44
|
+
return -sum
|
45
|
+
else
|
46
|
+
return sum
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_lng(lng)
|
51
|
+
fraction = ((lng[4..5].to_f * 60) + (lng[6..10].to_f*60.0)) / 3600.0
|
52
|
+
sum = lng[1..3].to_f + fraction
|
53
|
+
if(lng[0] == 'W')
|
54
|
+
return -sum
|
55
|
+
else
|
56
|
+
return sum
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_tracker_id(imei)
|
61
|
+
return 3
|
62
|
+
end
|
63
|
+
|
24
64
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keyhole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- buffpojken
|