Class: Cosmos::BridgeConfig

Inherits:
Object show all
Defined in:
lib/cosmos/bridge/bridge_config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ BridgeConfig

Returns a new instance of BridgeConfig.



30
31
32
33
34
# File 'lib/cosmos/bridge/bridge_config.rb', line 30

def initialize(filename)
  @interfaces = {}
  @routers = {}
  process_file(filename)
end

Instance Attribute Details

#interfacesHash<String, Interface>

Returns Interfaces hash.

Returns:



26
27
28
# File 'lib/cosmos/bridge/bridge_config.rb', line 26

def interfaces
  @interfaces
end

#routersHash<String, Interface>

Returns Routers hash.

Returns:



28
29
30
# File 'lib/cosmos/bridge/bridge_config.rb', line 28

def routers
  @routers
end

Class Method Details

.generate_default(filename) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cosmos/bridge/bridge_config.rb', line 36

def self.generate_default(filename)
  default_config = <<~EOF
            # Example Host Bridge Configuration for a Serial Port
            #
            # INTERFACE <Interface Name> <Interface File> <Interface Params...>
            # INTERFACE <Interface Name> serial_interface.rb <Write Port> <Read Port> <Baud Rate> <Parity ODD/EVEN/NONE> <Stop Bits> <Write Timeout> <Read Timeout> <Protocol Name> <Protocol Params>
            # INTERFACE <Interface Name> serial_interface.rb <Write Port> <Read Port> <Baud Rate> <Parity ODD/EVEN/NONE> <Stop Bits> <Write Timeout> <Read Timeout> BURST <Discard Leading Bytes> <Sync Pattern> <Add Sync On Write>
            # INTERFACE SERIAL_INT serial_interface.rb /dev/ttyS1 /dev/ttyS1 38400 ODD 1 10.0 nil BURST 4 0xDEADBEEF
            INTERFACE SERIAL_INT serial_interface.rb COM1 COM1 9600 NONE 1 10.0 nil BURST
    #{'        '}
            # ROUTER <Router Name> <Interface File> <Interface Params...>
            # ROUTER SERIAL_ROUTER tcpip_server_interface.rb <Write Port> <Read Port> <Write Timeout> <Read Timeout> <Protocol Name> <Protocol Params>
            # ROUTER SERIAL_ROUTER tcpip_server_interface.rb <Write Port> <Read Port> <Write Timeout> <Read Timeout> BURST <Discard Leading Bytes> <Sync Pattern> <Add Sync On Write>
            ROUTER SERIAL_ROUTER tcpip_server_interface.rb 2950 2950 10.0 nil BURST
              # ROUTE <Interface Name>
              ROUTE SERIAL_INT
    #{'        '}
  EOF

  Logger.info "Writing #{filename}"
  File.open(filename, 'w') do |file|
    file.write(default_config)
  end
end