Commit 65f3d9a0 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥
Browse files

Got igate working from apex library 1.0.3

parent 2df09784
require 'yaml' require 'yaml'
require 'peak/tnc_port' require 'peak/tnc_port'
require 'apex/aprs_kiss' require 'apex/aprs_kiss'
require 'apex/igate_tcp'
require 'kiss' require 'kiss'
require 'aprs_is' require 'aprs_is'
...@@ -39,6 +40,7 @@ module Peak ...@@ -39,6 +40,7 @@ module Peak
igate_callsign = nil igate_callsign = nil
igate_server_port = 14580 igate_server_port = 14580
igate_password = nil igate_password = nil
igate_echo = 'none'
config.each do |section_name, section_content| config.each do |section_name, section_content|
if section_name.eql?('IGATE') if section_name.eql?('IGATE')
return nil unless config_lookup_enforce(section_content, 'server') return nil unless config_lookup_enforce(section_content, 'server')
...@@ -49,20 +51,22 @@ module Peak ...@@ -49,20 +51,22 @@ module Peak
igate_server_port = section_content['server_port'] if section_content.key? 'server_port' igate_server_port = section_content['server_port'] if section_content.key? 'server_port'
igate_echo = section_content['echo'] if section_content.key? 'echo'
return nil unless config_lookup_enforce(section_content, 'password') return nil unless config_lookup_enforce(section_content, 'password')
igate_password = section_content['pasword'] igate_password = section_content['password']
end end
end end
igate = nil igate = nil
port_map = {}
unless igate_server.nil? unless igate_server.nil?
igate = AprsIs::Client.new(hostname: igate_server, port: igate_server_port) igate = Apex::IGateTcp.new(igate_callsign, igate_password)
igate.login(igate_callsign) igate.connect(igate_server, igate_server_port)
port_map['IGATE'] = TncPort.new(igate: igate, echo_frames: igate_echo)
end end
port_map = {}
config.each do |section_name, section_content| config.each do |section_name, section_content|
if section_name.start_with?('TNC ') if section_name.start_with?('TNC ')
tnc_name = section_name.strip.split(' ')[1].strip tnc_name = section_name.strip.split(' ')[1].strip
...@@ -131,7 +135,7 @@ module Peak ...@@ -131,7 +135,7 @@ module Peak
end end
echo_state = port_section['echo'] echo_state = port_section['echo']
port_map[port_name] = TncPort.new(kiss_tnc, port_name, port_identifier, port_net, echo_state, tnc_port, igate = igate) port_map[port_name] = TncPort.new(kiss_tnc, port_name, port_identifier, port_net, port = tnc_port, echo_frames: echo_state)
end end
end end
......
...@@ -50,6 +50,17 @@ module Peak ...@@ -50,6 +50,17 @@ module Peak
end end
end end
end end
if section_name.eql? "IGATE"
@port_info["IGATE"] = {
:port_identifier => section_content['callsign'],
:port_net => "TCPIP",
:tnc_port => 0,
:old_paradigm => [],
:new_paradigm => [],
:preemptive => true
}
end
end end
end end
...@@ -682,4 +693,4 @@ module Peak ...@@ -682,4 +693,4 @@ module Peak
end end
end end
end end
end end
\ No newline at end of file
...@@ -3,30 +3,64 @@ require 'peak/echo' ...@@ -3,30 +3,64 @@ require 'peak/echo'
module Peak module Peak
class TncPort class TncPort
protected protected
def initialize(data_stream, name, identifier, net, echo_frames = 'none', port=0, igate=nil) def initialize(data_stream = nil, name = nil, identifier = nil, net = nil, port = nil, echo_frames: 'none', igate: nil)
@data_stream = data_stream unless data_stream.nil?
@port = port throw "igate can not be set if data_stream is set" unless igate.nil?
@name = name throw "name can not be nil if data_stream is set" if name.nil? or name.eql? ""
@identifier = identifier throw "net can not be nil if data_stream is set" if net.nil? or net.eql? ""
@net = net
@data_stream = data_stream
@port = port
@port = 0 if port.nil?
@name = name
@identifier = identifier
@net = net
@igate = nil
end
unless igate.nil?
throw "igate can not be set if data_stream is set" unless data_stream.nil?
throw "name can not be set if igate is set" unless name.nil?
throw "identifier can not be set if igate is set" unless identifier.nil?
throw "net can not be set if igate is set" unless net.nil?
throw "port can not be set if igate is set" unless port.nil?
@igate = igate
@name = "IGATE"
@net = "APRSIS"
@port = 0
@identifier = nil
@data_stream = nil
end
if igate.nil? and data_stream.nil?
throw "either igate or data_stream must be set"
end
@echo_frames = echo_frames @echo_frames = echo_frames
@igate = igate
end end
public public
def connect(*args, **kwargs) def connect(*args, **kwargs)
@data_stream.connect(*args, **kwargs) @data_stream.connect(*args, **kwargs) unless @data_stream.nil?
end end
public public
def close(*args, **kwargs) def close(*args, **kwargs)
@data_stream.close(*args, **kwargs) @data_stream.close(*args, **kwargs) unless @data_stream.nil?
end end
public public
def read(*args, **kwargs) def read(*args, **kwargs)
read_frame = @data_stream.read(*args, **kwargs) read_frame = nil
@igate.send_message(read_frame) unless @igate.nil? if not @igate.nil?
read_frame = @igate.read(*args, **kwargs)
elsif not @data_stream.nil?
read_frame = @data_stream.read(*args, **kwargs)
end
return nil if read_frame.nil?
if (@echo_frames == 'all' or @echo_frames == 'in') and read_frame if (@echo_frames == 'all' or @echo_frames == 'in') and read_frame
Peak::echo_color_frame(read_frame, @name, true) Peak::echo_color_frame(read_frame, @name, true)
end end
...@@ -35,7 +69,12 @@ module Peak ...@@ -35,7 +69,12 @@ module Peak
public public
def write(frame, *args, **kwargs) def write(frame, *args, **kwargs)
@data_stream.write(frame, @port, *args, **kwargs) if not @igate.nil?
@igate.send_message(frame, *args, **kwargs)
elsif not @data_stream.nil?
@data_stream.write(frame, @port, *args, **kwargs)
end
if (@echo_frames == 'all' or @echo_frames == 'out') and frame if (@echo_frames == 'all' or @echo_frames == 'out') and frame
Peak::echo_color_frame(frame, @name, false) Peak::echo_color_frame(frame, @name, false)
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment