Skip to content

Instantly share code, notes, and snippets.

@psfleming
Created September 22, 2018 17:35
Show Gist options
  • Save psfleming/b8b440d271404ce50fca0431befdb98a to your computer and use it in GitHub Desktop.
Save psfleming/b8b440d271404ce50fca0431befdb98a to your computer and use it in GitHub Desktop.
Set FT8Call gps grid using gpsd and api
require 'gpsd_client'
require 'maidenhead'
require 'socket'
require 'json'
ft8call_port = 2237
gpsd = GpsdClient::Gpsd.new()
gpsd.start()
apicmd = {}
# get maidenhead if gps is ready
if gpsd.started?
pos = gpsd.get_position
maid = Maidenhead.to_maidenhead(pos[:lat], pos[:lon], precision = 5)
puts "lat = #{pos[:lat]}, lon = #{pos[:lon]}, grid = #{maid}"
apicmd = {:type => "STATION.SET_GRID", :value => maid}
end
# send if we have data
Socket.udp_server_loop(ft8call_port) { |msg, msg_src|
if apicmd.length > 0 then
puts "Sending #{apicmd}"
msg_src.reply apicmd.to_json
break
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment