0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

aisをleafletで描いてみた

0
Last updated at Posted at 2026-05-26

ais_rtlの受信データをjsonにするmrubyスクリプトを作ってみました。サブルーチンは前の記事の物を使っています。

    json = "/root/htdocs/json/skt.json"

    s = UDPSocket.open
    s.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
    s.bind("0.0.0.0", 10110)

    db = Hash.new

    loop do
      sen, addr = s.recvfrom(256)

      bits = senbit sen

      id = strint bits[0,6]
      if (id >= 1) && (id <= 3) then

        time = Time.now.to_i
        mmsi = strint bits[8,30]
        st = strint bits[38,4]
        lon = strint bits[61,28]
        lon /= 600000.0
        lat = strint bits[89,27]
        lat /= 600000.0
        sog = strint bits[50,10]
        sog /= 10.0
        cog = strint bits[116,12]
        cog /= 10.0
        hdg = strint bits[129,9]
        db.store(mmsi, [time, st, lon, lat, sog, hdg, cog])
      end

      # delete over 12 hour recode
      now = Time.now.to_i
      db.delete_if {|key, value|
         value[0] < now - (3600 * 12)
      }

      File.open(json,"w+") do |json|
        data = ""
        db.each{|key, value|
          if data.length != 0 then
            data += ','
          end
          data += '{"mmsi":' + key.to_s
          data += ',"time":' + value[0].to_s
          data += ',"status":' + value[1].to_s
          data += ',"lon":' + value[2].to_s
          data += ',"lat":' + value[3].to_s
          data += ',"speed":' + value[4].to_s
          data += ',"heading":' + value[5].to_s 
          data += ',"course":' + value[6].to_s
          data += '}'
        }
        json.puts('[' + data + ']')
      end

    end

これをdump1090と同じようにして描いてみます。httpはmini_httpdで処理します。

image.png

dump1090はマーカーと地図が重なるので淡色地図にしましたが、AISは海の上で重なることがないので、標準地図を使いました。

北防波堤の先端は最近作られたもののようです。

FreeBSD/mipsのAtheros AR7242だとmrubyはほとんどCPU負荷になりませんがrtl_aisはかなり負荷大きくてidelが10%くらいしかありません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?