Skip to content

Instantly share code, notes, and snippets.

@jh4xsy
Created May 28, 2026 03:44
Show Gist options
  • Select an option

  • Save jh4xsy/fd4fda3f9342b680c0b3a2fe7e5b35a2 to your computer and use it in GitHub Desktop.

Select an option

Save jh4xsy/fd4fda3f9342b680c0b3a2fe7e5b35a2 to your computer and use it in GitHub Desktop.
Fox Delta ST2 emulator
#!/usr/bin/env ruby
#
# st2emu.rb - Fox Delta ST2 emulator
# 2026-05-23 by JH4XSY/1
#
# このエミュレータは、仮想的なシリアルポートを作成し、軌道計算ソフトに、送られてきたAz,Elの値を返します。
require 'pty'
require 'fileutils'
LINK_PATH = "/tmp/ttyV0"
def start_emulator
PTY.open do |master, slave|
FileUtils.rm_f(LINK_PATH)
File.symlink(slave.path, LINK_PATH)
puts "=== ST2 Emulator v0.1 by JH4XSY/1 ==="
puts "Assigned Rotator Device: #{LINK_PATH}"
current_az, current_el = 0.0, 0.0
loop do
if IO.select([master], nil, nil, 1)
begin
line = master.gets
next if line.nil?
command = line.strip.upcase
# 1. 方位角(AZ)の解析
if command =~ /AZ\s*([\d\.]+)/
current_az = $1.to_f
end
# 2. 仰角(EL)の解析
if command =~ /EL\s*([\d\.]+)/
current_el = $1.to_f
end
# 3. ステータス要求に対する応答
if command.include?("C")
response = sprintf("%+07.1f%+07.1f\r\n", current_az, current_el)
master.write(response)
end
output = "\rGot Az=#{sprintf('%5.1f', current_az)} El=#{sprintf('%4.1f', current_el)} | Feedback: #{response}\e[K"
print output
rescue Errno::EIO
# ソフト側がポートを閉じた場合
sleep 1
end
end
end
end
ensure
FileUtils.rm_f(LINK_PATH)
end
start_emulator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment