Class: AstmServer
- Inherits:
-
Object
- Object
- AstmServer
- Includes:
- LabInterface
- Defined in:
- lib/ruby_astm/astm_server.rb
Constant Summary
Constants included from LabInterface
LabInterface::ACK, LabInterface::CR, LabInterface::ENQ, LabInterface::EOT, LabInterface::ETX, LabInterface::LF, LabInterface::STX
Instance Attribute Summary
Attributes included from LabInterface
#data_buffer, #data_bytes, #ethernet_connections, #ethernet_server, #headers, #mapping, #mid_frame_end_detected, #respond_to_queries, #serial_baud, #serial_connections, #serial_parity, #serial_port, #server_ip, #server_port, #test_data_bytes, #usb_baud, #usb_parity, #usb_port
Instance Method Summary collapse
-
#initialize(ethernet_connections, serial_connections, mpg = nil, respond_to_queries = nil) ⇒ AstmServer
constructor
DEFAULT SERIAL PORT : /dev/ttyS0 DEFAULT USB PORT : /dev/ttyUSB0 @param ethernet_connections : each element is expected to be a hash, with keys for :server_ip, :server_port.
- #start_server ⇒ Object
Methods included from LabInterface
#checksum, #generate_response, included, #is_mid_frame_end?, #pre_process_bytes, #process_byte_file, #process_text, #process_text_file, #process_type, #receive_data, #root, #send_enq, #terminator, #unbind, #write_bytes_to_file
Constructor Details
#initialize(ethernet_connections, serial_connections, mpg = nil, respond_to_queries = nil) ⇒ AstmServer
DEFAULT SERIAL PORT : /dev/ttyS0 DEFAULT USB PORT : /dev/ttyUSB0 @param ethernet_connections : each element is expected to be a hash, with keys for :server_ip, :server_port. @param serial_connections : each element is expected to be a hash with port_address, baud_rate, and parity def initialize(server_ip=nil,server_port=nil,mpg=nil,respond_to_queries=false,serial_port=‘/dev/ttyS0’,usb_port=‘/dev/ttyUSB0’,serial_baud=9600,serial_parity=8,usb_baud=19200,usb_parity=8)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_astm/astm_server.rb', line 18 def initialize(ethernet_connections,serial_connections,mpg=nil,respond_to_queries=nil) $redis = Redis.new self.class.log("Initializing AstmServer") self.ethernet_connections = ethernet_connections self.serial_connections = serial_connections self.server_ip = server_ip || "127.0.0.1" self.server_port = server_port || 3000 self.respond_to_queries = respond_to_queries self.serial_port = serial_port self.serial_baud = serial_baud self.serial_parity = serial_parity self.usb_port = usb_port self.usb_baud = usb_baud self.usb_parity = usb_parity $mappings = JSON.parse(IO.read(mpg || self.class.default_mappings)) end |
Instance Method Details
#start_server ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_astm/astm_server.rb', line 35 def start_server EventMachine.run { self.ethernet_connections.each do |econn| raise "please provide a valid ethernet configuration with ip address" unless econn[:server_ip] raise "please provide a valid ethernet configuration with port" unless econn[:server_port] EventMachine::start_server econn[:server_ip], econn[:server_port], LabInterface self.class.log("Running ETHERNET with configuration #{econn}") end self.serial_connections.each do |sconn| raise "please provide a valid serial configuration with port address" unless sconn[:port_address] raise "please provide a valid serial configuration with baud rate" unless sconn[:baud_rate] raise "please provide a valid serial configuration with parity" unless sconn[:parity] EventMachine.open_serial(sconn[:port_address], sconn[:baud_rate], sconn[:parity],LabInterface) puts "RUNNING SERIAL port with configuration : #{sconn}" end } end |