Class: SatParser
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- SatParser
- Defined in:
- lib/sat_parser.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
-
#hdop ⇒ Object
Returns the value of attribute hdop.
-
#imei ⇒ Object
Returns the value of attribute imei.
-
#latest_location ⇒ Object
Returns the value of attribute latest_location.
Instance Method Summary collapse
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
3 4 5 |
# File 'lib/sat_parser.rb', line 3 def db @db end |
#hdop ⇒ Object
Returns the value of attribute hdop.
3 4 5 |
# File 'lib/sat_parser.rb', line 3 def hdop @hdop end |
#imei ⇒ Object
Returns the value of attribute imei.
3 4 5 |
# File 'lib/sat_parser.rb', line 3 def imei @imei end |
#latest_location ⇒ Object
Returns the value of attribute latest_location.
3 4 5 |
# File 'lib/sat_parser.rb', line 3 def latest_location @latest_location end |
Instance Method Details
#post_init ⇒ Object
5 6 7 8 9 |
# File 'lib/sat_parser.rb', line 5 def post_init puts self.inspect @db = EventMachine::MySQL.new(:host => "localhost", :username => "root", :database => "keyhole_development") $channel << "{event:'connect', 'type':'tracker'}" end |
#receive_data(data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sat_parser.rb', line 11 def receive_data(data) puts data.inspect data = data.split(",") self.imei = data[0] loc = { :longitude => parse_lng(data[5]), :latitude => parse_lat(data[6]), :altitude => data[7], :nos => data[10].split(/\*/)[0], :hdop => data[10].split(/\*/)[1], :tracker => get_tracker_id(data[0]) } self.latest_location = loc self.hdop = loc[:hdop] q = @db.query("insert into locations(longitude, latitude, altitude, nos, hdop, tracker_id) value('#{loc[:longitude]}','#{loc[:latitude]}', #{loc[:altitude]}, #{loc[:nos]}, #{loc[:hdop].gsub(/[^\d]/,"")}, #{loc[:tracker]});") q.callback{|res| puts res.inspect} q.errback{|res| puts "E:"+res.inspect} $channel << JSON.generate(loc) end |
#unbind ⇒ Object
36 37 38 |
# File 'lib/sat_parser.rb', line 36 def unbind $channel << "GSAT closed connection" end |