Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Created November 27, 2011 01:53
Show Gist options
  • Select an option

  • Save aaronpk/1396786 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpk/1396786 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'socket'
socket = UDPSocket.new
# Encode Latitude (((latitude + 90) / 180) * 4294967296)
# Encode Longitude (((longitude + 180) / 360) * 4294967296)
# Decode Latitude (((latitude / 4294967296) * 180) - 90)
# Decode Longitude (((longitude / 4294967296) * 360) - 180)
# Valid packet
socket.send("\x41" +
# Date
[Time.now.to_i].pack('N') +
# Latitude
[(((45.5246 + 90) / 180) * 4294967296)].pack('N') +
# Longitude
[(((-122.6843 + 180) / 360) * 4294967296)].pack('N') +
# Speed Heading Altitude Accuracy Battery
[20].pack('n') + [190].pack('n') + [1320].pack('n') + [28].pack('n') + [97].pack('n') +
# UUID
"\x12\x34\x56\x78\x90\xAB\xCD\xEF\x12\x34\x56\x78\x90\xAB\xCD\xEF", 0, 'localhost', 43333)
response, sender = socket.recvfrom(4)
puts "Response: " + response.unpack('N')[0].to_s
# Wrong UUID length
socket.send("\x41" +
# Latitude
[(((45.5246 + 90) / 180) * 4294967296)].pack('N') +
# Longitude
[(((-122.6843 + 180) / 360) * 4294967296)].pack('N') +
# Speed Heading Altitude Accuracy Battery
[20].pack('n') + [190].pack('n') + [1320].pack('n') + [28].pack('n') + [97].pack('n') +
# UUID
"\x34\x56\x78\x90\xAB\xCD\xEF\x12\x34\x56\x78\x90\xAB\xCD\xEF", 0, 'localhost', 43333)
response, sender = socket.recvfrom(4)
puts "Response: " + response.unpack('N')[0].to_s
# Wrong message length
socket.send("\x41" +
# Date
[Time.now.to_i].pack('N') +
# Latitude
[(((45.5246 + 90) / 180) * 4294967296)].pack('N') +
# Longitude
[(((-122.6843 + 180) / 360) * 4294967296)].pack('N') +
# Speed Heading Altitude Accuracy Battery
[20].pack('n') + [190].pack('n') + [1320].pack('n') + [28].pack('n') +
# UUID
"\x12\x34\x56\x78\x90\xAB\xCD\xEF\x12\x34\x56\x78\x90\xAB\xCD\xEF", 0, 'localhost', 43333)
response, sender = socket.recvfrom(4)
puts "Response: " + response.unpack('N')[0].to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment