From e96c26cdc3307bdffb3f31f1fdd9b9f7a61f700d Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Mon, 6 Sep 2021 22:49:52 -0400 Subject: [PATCH] Fixed bugs in aprs-is, it now appears fully functional --- lib/apex/igate_tcp.rb | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/apex/igate_tcp.rb b/lib/apex/igate_tcp.rb index 8d1130a..a559e78 100644 --- a/lib/apex/igate_tcp.rb +++ b/lib/apex/igate_tcp.rb @@ -1,3 +1,5 @@ +require 'apex/app_info' + module Apex class IGateTcp DEFAULT_APRSIS_URL = 'http://srvr.aprs-is.net:8080' @@ -7,7 +9,7 @@ module Apex protected def initialize(user, password='-1') @user = user - @auth = ['user', user, 'pass', password, 'vers', 'APEX-APRS Ruby Module'].join(' ') + @auth = ['user', user, 'pass', password, 'vers', "APEX #{VERSION}"].join(' ') @aprsis_sock = nil @data_buffer = '' @packet_buffer = [] @@ -75,16 +77,16 @@ module Apex port = DEFAULT_APRSIS_FILTER_PORT end - unless aprs_filter - aprs_filter = ['p', @user].join('/') + if aprs_filter.nil? + @full_auth = @auth + else + @full_auth = [@auth, 'filter', aprs_filter].join(' ') end - @full_auth = [@auth, 'filter', aprs_filter].join(' ') - @server = server @port = port @aprsis_sock = TCPSocket.open(@server, @port) - @aprsis_sock.puts( @full_auth + '\r\n' ) + @aprsis_sock.puts( @full_auth + "\r\n" ) end end end @@ -106,28 +108,24 @@ module Apex # check if there is any data waiting read_more = true while read_more - selected = IO.select([@aprsis_sock], [], [], 0) - if selected.nil? == false - ready_len = selected.first.length - if ready_len > 0 - recvd_data = @aprsis_sock.read(ready_len) - if recvd_data - @data_buffer += recvd_data - end - end - else - read_more = false + begin + read_line = @aprsis_sock.read_nonblock(100) + unless read_line.nil? + @data_buffer << read_line + end + rescue IO::WaitReadable + read_more = false end end # check for any complete packets and move them to the packet buffer - if @data_buffer.include? '\r\n' + if @data_buffer.include? "\r\n" partial = true - if @data_buffer.end_with? '\r\n' + if @data_buffer.end_with? "\r\n" partial = false end - packets = @data_buffer.split('\r\n') + packets = @data_buffer.split("\r\n") if partial @data_buffer = packets.pop.dup else @@ -142,7 +140,7 @@ module Apex # return the next packet that matches the filter while @packet_buffer.length > 0 packet = @packet_buffer.pop - unless filter_logresp and packet.start_with?('#') and packet.include? 'logresp' + unless (filter_logresp and packet.start_with?('#')) return IGateTcp::decode_frame(packet) end end -- GitLab