apex-aprs 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dbd006d7d8e71ef14b082177848ada159139d92012d859b7ff2c0dfd23bd3d4
4
- data.tar.gz: ffc8ec190f0f310a3842732adedf1be2bed6b01488efc8d90cbd213174f85707
3
+ metadata.gz: 7ab4abfcc8a45fe0ed8cf65e3af8027d5ef5bcf851f70a8e9067207b51699cc8
4
+ data.tar.gz: d9aeb612963bd2f85bd527d94ae8b77794326550590c98b4e51d45c3f8255991
5
5
  SHA512:
6
- metadata.gz: 4b829cea663db7673ae6f53531031f63736f5445cb7c48899a94ee1d7ca3b9848194479858c88fcd23abba18b48229e46ba811e54523c00ea21efcfef133c8ef
7
- data.tar.gz: 0a831f1f9dffa31f6f76b4b060be04e997cc315f7604b701bb8086e4873337aaeea8c62fb4c80409d2a351b0355156cb5187c7e01cfc03bcb5938bfe28b7cee4
6
+ metadata.gz: 436265f8be51ee2cb49ff0f074a60a7d87214a68c56459a4ae33346da851e2013188735a0f1bdeaca974437c49720e80b4641a91f70c04fc476f831cc6e329cb
7
+ data.tar.gz: 6e1e45ee6ee7e680db9d3889a57f6a1c8fe1120fea3cc97484ee4c22158aa07949aaea97a7e2daea363a4fef4d0c09de5930ef1adffacb3b644c5a56da34b52d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ * Implemented the IGateTcp class for handking internet gateways.
6
+
3
7
  ## 1.0.2
4
8
 
5
9
  * Updates to dependencies only.
data/lib/apex/app_info.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apex
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -0,0 +1,160 @@
1
+ require 'apex/app_info'
2
+
3
+ module Apex
4
+ class IGateTcp
5
+ DEFAULT_APRSIS_URL = 'http://srvr.aprs-is.net:8080'
6
+ DEFAULT_APRSIS_SERVER = 'rotate.aprs.net'
7
+ DEFAULT_APRSIS_FILTER_PORT = 14580
8
+
9
+ protected
10
+ def initialize(user, password='-1')
11
+ @user = user
12
+ @auth = ['user', user, 'pass', password, 'vers', "APEX #{VERSION}"].join(' ')
13
+ @aprsis_sock = nil
14
+ @data_buffer = ''
15
+ @packet_buffer = []
16
+ @lock = Mutex.new
17
+ end
18
+
19
+ private
20
+ def reset_buffer
21
+ @data_buffer = ''
22
+ @packet_buffer = []
23
+ end
24
+
25
+ private
26
+ def self.format_path(path_list)
27
+ path_list.join(',')
28
+ end
29
+
30
+ private
31
+ def self.encode_frame(frame)
32
+ formatted_frame = [frame[:source], frame[:destination]].join('>')
33
+ if frame[:path] and frame[:path].length > 0
34
+ formatted_frame = [formatted_frame, IGateTcp::format_path(frame[:path])].join(',')
35
+ end
36
+ formatted_frame += ':'
37
+ formatted_frame += frame[:text]
38
+ return formatted_frame
39
+ end
40
+
41
+ private
42
+ def self.decode_frame(frame)
43
+ decoded_frame = {}
44
+ frame_so_far = ''
45
+ path = nil
46
+ frame.chars.each do |char|
47
+ if char == '>' and !decoded_frame.include? :source
48
+ decoded_frame[:source] = frame_so_far
49
+ frame_so_far = ''
50
+ elsif char == ':' and !path
51
+ path = frame_so_far
52
+ frame_so_far = ''
53
+ else
54
+ frame_so_far = [frame_so_far, char].join
55
+ end
56
+ end
57
+
58
+ path = path.split(',')
59
+ decoded_frame[:destination] = path.shift
60
+ decoded_frame[:path] = path
61
+ decoded_frame[:text] = frame_so_far
62
+
63
+ decoded_frame
64
+ end
65
+
66
+ public
67
+ def connect(server=nil, port=nil, aprs_filter=nil, *args, **kwargs)
68
+ @lock.synchronize do
69
+ unless @aprsis_sock
70
+ reset_buffer
71
+
72
+ unless server
73
+ server = DEFAULT_APRSIS_SERVER
74
+ end
75
+
76
+ unless port
77
+ port = DEFAULT_APRSIS_FILTER_PORT
78
+ end
79
+
80
+ if aprs_filter.nil?
81
+ @full_auth = @auth
82
+ else
83
+ @full_auth = [@auth, 'filter', aprs_filter].join(' ')
84
+ end
85
+
86
+ @server = server
87
+ @port = port
88
+ @aprsis_sock = TCPSocket.open(@server, @port)
89
+ @aprsis_sock.puts( @full_auth + "\r\n" )
90
+ end
91
+ end
92
+ end
93
+
94
+ public
95
+ def close(*args, **kwargs)
96
+ @lock.synchronize do
97
+ if @aprsis_sock
98
+ @aprsis_sock.close
99
+ reset_buffer
100
+ @aprsis_sock = nil
101
+ end
102
+ end
103
+ end
104
+
105
+ public
106
+ def read(filter_logresp=true, *args, **kwargs)
107
+ @lock.synchronize do
108
+ # check if there is any data waiting
109
+ read_more = true
110
+ while read_more
111
+ begin
112
+ read_line = @aprsis_sock.read_nonblock(100)
113
+ unless read_line.nil?
114
+ @data_buffer << read_line
115
+ end
116
+ rescue IO::WaitReadable
117
+ read_more = false
118
+ end
119
+ end
120
+
121
+ # check for any complete packets and move them to the packet buffer
122
+ if @data_buffer.include? "\r\n"
123
+ partial = true
124
+ if @data_buffer.end_with? "\r\n"
125
+ partial = false
126
+ end
127
+
128
+ packets = @data_buffer.split("\r\n")
129
+ if partial
130
+ @data_buffer = packets.pop.dup
131
+ else
132
+ @data_buffer = ''
133
+ end
134
+
135
+ packets.each do |packet|
136
+ @packet_buffer << packet.dup
137
+ end
138
+ end
139
+
140
+ # return the next packet that matches the filter
141
+ while @packet_buffer.length > 0
142
+ packet = @packet_buffer.pop
143
+ unless (filter_logresp and packet.start_with?('#'))
144
+ return IGateTcp::decode_frame(packet)
145
+ end
146
+ end
147
+
148
+ return nil
149
+ end
150
+ end
151
+
152
+ public
153
+ def write(frame, *args, **kwargs)
154
+ @lock.synchronize do
155
+ encoded_frame = IGateTcp::encode_frame(frame)
156
+ @aprsis_sock.puts( encoded_frame )
157
+ end
158
+ end
159
+ end
160
+ end
data/lib/apex.rb CHANGED
@@ -1 +1,2 @@
1
- require 'apex/aprs_kiss'
1
+ require 'apex/aprs_kiss'
2
+ require 'apex/igate_tcp'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apex-aprs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Phillips Freeman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-04 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abstraction
@@ -129,6 +129,7 @@ files:
129
129
  - lib/apex.rb
130
130
  - lib/apex/app_info.rb
131
131
  - lib/apex/aprs_kiss.rb
132
+ - lib/apex/igate_tcp.rb
132
133
  homepage: https://github.com/Syncleus/apex-aprs
133
134
  licenses:
134
135
  - Apache-2.0