Class: OpenC3::BridgeConfig

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, existing_variables = {}) ⇒ BridgeConfig

Returns a new instance of BridgeConfig.



33
34
35
36
37
# File 'lib/openc3/bridge/bridge_config.rb', line 33

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

Instance Attribute Details

#interfacesHash<String, Interface>

Returns Interfaces hash.

Returns:



29
30
31
# File 'lib/openc3/bridge/bridge_config.rb', line 29

def interfaces
  @interfaces
end

#routersHash<String, Interface>

Returns Routers hash.

Returns:



31
32
33
# File 'lib/openc3/bridge/bridge_config.rb', line 31

def routers
  @routers
end

Class Method Details

.generate_default(filename) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/openc3/bridge/bridge_config.rb', line 39

def self.generate_default(filename)
  default_config = <<~EOF
    # Write serial port name
    VARIABLE write_port_name COM1
    #{'        '}
    # Read serial port name
    VARIABLE read_port_name COM1
    #{'        '}
    # Baud Rate
    VARIABLE baud_rate 115200
    #{'        '}
    # Parity - NONE, ODD, or EVEN
    VARIABLE parity NONE
    #{'        '}
    # Stop bits - 0, 1, or 2
    VARIABLE stop_bits 1
    #{'        '}
    # Write Timeout
    VARIABLE write_timeout 10.0
    #{'        '}
    # Read Timeout
    VARIABLE read_timeout nil
    #{'        '}
    # Flow Control - NONE, or RTSCTS
    VARIABLE flow_control NONE
    #{'        '}
    # Data bits per word - Typically 8
    VARIABLE data_bits 8
    #{'        '}
    # Port to listen for connections from COSMOS - Plugin must match
    VARIABLE router_port 2950
    #{'        '}
    # Port to listen on for connections from COSMOS. Defaults to localhost for security. Will need to be opened
    # if COSMOS is on another machine.
    VARIABLE router_listen_address 127.0.0.1
    #{'        '}
    INTERFACE SERIAL_INT serial_interface.rb <%= write_port_name %> <%= read_port_name %> <%= baud_rate %> <%= parity %> <%= stop_bits %> <%= write_timeout %> <%= read_timeout %>
      OPTION FLOW_CONTROL <%= flow_control %>
      OPTION DATA_BITS <%= data_bits %>
    #{'        '}
    ROUTER SERIAL_ROUTER tcpip_server_interface.rb <%= router_port %> <%= router_port %> 10.0 nil BURST
      ROUTE SERIAL_INT
      OPTION LISTEN_ADDRESS <%= router_listen_address %>
    #{'        '}
  EOF

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