Class: Ax25::IGateTcp
- Inherits:
-
Object
- Object
- Ax25::IGateTcp
- Includes:
- Encoder
- Defined in:
- lib/ax25/encoder/igate_tcp.rb
Constant Summary collapse
- DEFAULT_APRSIS_URL =
'http://srvr.aprs-is.net:8080'
- DEFAULT_APRSIS_SERVER =
'rotate.aprs.net'
- DEFAULT_APRSIS_FILTER_PORT =
14580
Instance Method Summary collapse
- #close(*args, **kwargs) ⇒ Object
- #connect(server = nil, port = nil, aprs_filter = nil, *args, aprsis_socket_override: nil, **kwargs) ⇒ Object
- #read(filter_logresp = true, *args, **kwargs) ⇒ Object
- #write(frame, *args, **kwargs) ⇒ Object
Instance Method Details
#close(*args, **kwargs) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/ax25/encoder/igate_tcp.rb', line 117 def close(*args, **kwargs) @lock.synchronize do if @aprsis_sock @aprsis_sock.close reset_buffer @aprsis_sock = nil end end end |
#connect(server = nil, port = nil, aprs_filter = nil, *args, aprsis_socket_override: nil, **kwargs) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ax25/encoder/igate_tcp.rb', line 85 def connect(server=nil, port=nil, aprs_filter=nil, *args, aprsis_socket_override: nil, **kwargs) @lock.synchronize do unless @aprsis_sock reset_buffer unless server server = DEFAULT_APRSIS_SERVER end unless port port = DEFAULT_APRSIS_FILTER_PORT end if aprs_filter.nil? @full_auth = @auth else @full_auth = [@auth, 'filter', aprs_filter].join(' ') end @server = server @port = port if aprsis_socket_override.nil? @aprsis_sock = TCPSocket.open(@server, @port) else @aprsis_sock = aprsis_socket_override end @aprsis_sock.puts( @full_auth + "\r\n" ) end end end |
#read(filter_logresp = true, *args, **kwargs) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ax25/encoder/igate_tcp.rb', line 128 def read(filter_logresp=true, *args, **kwargs) @lock.synchronize do # check if there is any data waiting read_more = true while read_more begin read_line = @aprsis_sock.read_nonblock(100) unless read_line.nil? @data_buffer << read_line end ## Lets not read in more than one frame at a time so we dont get stuck in a loop read_more = false if @data_buffer.include? "\r\n" 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" partial = true if @data_buffer.end_with? "\r\n" partial = false end packets = @data_buffer.split("\r\n") if partial @data_buffer = packets.pop.dup else @data_buffer = '' end packets.each do |packet| @packet_buffer << packet.dup end end # return the next packet that matches the filter while @packet_buffer.length > 0 packet = @packet_buffer.pop unless (filter_logresp and packet.start_with?('#')) return IGateTcp::decode_frame(packet) end end return nil end end |
#write(frame, *args, **kwargs) ⇒ Object
177 178 179 180 181 182 |
# File 'lib/ax25/encoder/igate_tcp.rb', line 177 def write(frame, *args, **kwargs) @lock.synchronize do encoded_frame = IGateTcp::encode_frame(frame) @aprsis_sock.puts( encoded_frame ) end end |