Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e6dad2560b
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (35 sloc) 1.385 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/env ruby
#
# fhpipe - watches southern cad call directories for closed
# calls and pipes them to firehouse cad_monitor

require 'rubygems'
require 'eventmachine'

# some simple config
port = 7799
host = "localhost"
logfile = "C:\\fhpipe_log\\fd.log"
cad_incoming = "C:\\cad_incoming\\"

module EchoServer

  def post_init
    @log = File.open(logfile, 'a')
    @log.write("-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] CONNECTION ESTABLISHED\n")
  end

  def receive_data data
    send_data "-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] DATA RECEIVED BY SERVER\n"

    filename = data.split('>')[0]
    filedata = data.split('>')[1]
    
    @log.write("-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] INCOMING DATA\n")
    @log.write("-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] WRITING TO FILENAME: #{filename}\n")

    # DEBUG
    # puts filedata
    File.open(cad_incoming+filename, 'a') {|f| f.write(cad_incoming+filedata) } unless File.exists?(cad_incoming+filename)

    @log.write("\n-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] WRITE COMPLETE\n")
  end

  def unbind
    @log.write("-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] CONNECTION TERMINATED\n")
  end
end

EventMachine::run {
  puts "-- [#{Time.now.strftime("%H:%M:%S %d%b%Y").upcase}] LISTENING ON PORT #{port}"
  EventMachine::start_server host, port, EchoServer
}
Something went wrong with that request. Please try again.