hamnet 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/hamnet.rb +144 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjVhMGIxNTg4MWUyMTcyYWJlODg2NGMwMmQzZmI5YTlhM2MxMmJlNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTY1YmU2NzBhYWYzY2MwMTY2MTlmOWIxYTQxNGJlMDViYjljZGM5YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZmYwNjRiYTkxZWM5NzExYjJhOTIxMjhhZjQxM2FkNTk3ZmJiMWZiMjc5M2Zi
|
10
|
+
ODk4ZWI0MDZkYmY4YjlhYTE5MDVhZTMyZmZjYWU3YjI2YzExZmIzZDBlMDIz
|
11
|
+
ZDcwMDYxMTk1OGI3MDMyNGE1ZjJkMDIwYjAyY2ViYjZhMTA1MmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTllNmRkZTdjNWE3NjI2Y2M2NDQ5YzIyMzAxOGIwMTVjZjVhMTM4ZDk2Njky
|
14
|
+
ZjBjM2NhYzVjMjZhNGQ5NTU5Y2NiNjQwMGZmODJlYjY4NDViYzQwODI0NDY0
|
15
|
+
ZTE0MmNmMTVjNzkzYThjYTcwNjQ5ZWY0MTcwYjZjMzMwNGUwMTM=
|
data/lib/hamnet.rb
CHANGED
@@ -14,6 +14,7 @@ require 'zlib'
|
|
14
14
|
require 'base64'
|
15
15
|
require 'time'
|
16
16
|
require 'thread'
|
17
|
+
require 'fldigi'
|
17
18
|
|
18
19
|
HAMNET_FRAME_ACK=0
|
19
20
|
HAMNET_FRAME_SIMPLE=1
|
@@ -178,25 +179,152 @@ class RxFrame < Frame
|
|
178
179
|
end
|
179
180
|
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
frames=Array.new()
|
184
|
-
done=false
|
182
|
+
class Hamnet
|
183
|
+
attr_accessor :mycall, :dialfreq, :carrier, :modem
|
185
184
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
185
|
+
def initialize(mycall, dialfreq, carrier, modem)
|
186
|
+
@mycall=mycall.downcase
|
187
|
+
@dialfreq=dialfreq.to_f
|
188
|
+
@carrier=carrier.to_i
|
189
|
+
@modem=modem
|
190
|
+
@sequence=0
|
191
|
+
|
192
|
+
@queue_send=Array.new()
|
193
|
+
@queue_recv=Array.new()
|
194
|
+
@send_lock=Mutex.new()
|
195
|
+
@recv_lock=Mutex.new()
|
196
|
+
@seq_lock=Mutex.new()
|
197
|
+
|
198
|
+
@fldigi=Fldigi.new()
|
199
|
+
|
200
|
+
# May not need this. Seems to depend on ruby version.
|
201
|
+
#if !XMLRPC::Config::ENABLE_NIL_PARSER
|
202
|
+
#v, $VERBOSE=$VERBOSE, nil
|
203
|
+
#XMLRPC::Config::ENABLE_NIL_PARSER=true
|
204
|
+
#$VERBOSE=v
|
205
|
+
#end
|
206
|
+
|
207
|
+
# Light up FLDigi.
|
208
|
+
@fldigi.receive()
|
209
|
+
@fldigi.afc=false
|
210
|
+
@fldigi.modem=@modem
|
211
|
+
@fldigi.carrier=@carrier
|
212
|
+
@fldigi.clear_tx_data()
|
213
|
+
@fldigi.get_tx_data()
|
214
|
+
@fldigi.get_rx_data()
|
215
|
+
@fldigi.config()
|
216
|
+
|
217
|
+
# Crank up the main thread.
|
218
|
+
@loopthread=Thread.new { self.main_loop() }
|
219
|
+
@loopthread.abort_on_exception=true
|
220
|
+
end
|
221
|
+
|
222
|
+
def main_loop
|
223
|
+
rxdata=""
|
224
|
+
frame=nil
|
225
|
+
while true
|
226
|
+
|
227
|
+
# First, send any queued outgoing frames.
|
228
|
+
@send_lock.synchronize {
|
229
|
+
while @queue_send.length>0 do
|
230
|
+
f=@queue_send.shift
|
231
|
+
puts "Transmit frame:\n#{f.to_s}"
|
232
|
+
@fldigi.add_tx_string(f.to_s)
|
233
|
+
@fldigi.send_buffer(true)
|
234
|
+
end
|
235
|
+
}
|
236
|
+
|
237
|
+
# Get any new data from fldigi. Strip out any Unicode bullshit.
|
238
|
+
rx=@fldigi.get_rx_data()
|
239
|
+
rx.each_codepoint do |i|
|
240
|
+
if i>=32 and i<=126
|
241
|
+
rxdata=rxdata+i.chr
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
if rxdata.length>1024
|
246
|
+
l=rxdata.length
|
247
|
+
rxdata=rxdata[80,l-1024]
|
248
|
+
end
|
249
|
+
|
250
|
+
if rxdata.scan(/</).length==0
|
251
|
+
rxdata=""
|
252
|
+
elsif rxdata.scan(/<<</).length>0
|
253
|
+
rxdata=rxdata.match(/<<<.*/).to_s
|
254
|
+
end
|
255
|
+
|
256
|
+
# If there's a valid frame in there, process it.
|
257
|
+
if rxdata.match(/<<<.*>>>/).to_s.length>0
|
258
|
+
rawframe=rxdata.reverse.match(/>>>.*?<<</).to_s.reverse
|
259
|
+
|
260
|
+
# Parse the recieved frame.
|
261
|
+
if rawframe.length>0
|
262
|
+
frame=RxFrame.new(rawframe)
|
263
|
+
|
264
|
+
if frame.valid and frame.to==@mycall
|
265
|
+
@recv_lock.synchronize {
|
266
|
+
puts "Received valid frame with my call sign:"
|
267
|
+
p frame
|
268
|
+
@queue_recv.push(frame)
|
269
|
+
}
|
270
|
+
end
|
271
|
+
|
272
|
+
# Remove the frame text from the buffer.
|
273
|
+
rxdata.slice!(rawframe)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
# If there's a valid ping frame in the recv_queue, remove it and
|
278
|
+
# generate a reply ping frame.
|
279
|
+
@recv_lock.synchronize {
|
280
|
+
if @queue_recv.length>0
|
281
|
+
puts "length: #{@queue_recv.length}"
|
282
|
+
p @queue_recv
|
283
|
+
tmp_queue=Array.new()
|
284
|
+
@queue_recv.each do |tmpframe|
|
285
|
+
if tmpframe.type==HAMNET_FRAME_PING
|
286
|
+
self.send_frame(TxFrame.new(@mycall, tmpframe.from, HAMNET_FRAME_PING_REPLY, 0, @fldigi.radio_freq().to_s, true))
|
287
|
+
elsif tmpframe.type==HAMNET_FRAME_PING_REPLY
|
288
|
+
puts "Received a reply to our ping:"
|
289
|
+
p tmpframe
|
290
|
+
else
|
291
|
+
tmp_queue.push(tmpframe)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
@queue_recv=tmp_queue
|
295
|
+
end
|
296
|
+
}
|
297
|
+
|
298
|
+
sleep 1
|
191
299
|
end
|
192
|
-
frames.push(TxFrame.new(from, to, type, sequence, chunk, done))
|
193
|
-
sequence=sequence+1
|
194
300
|
end
|
195
301
|
|
196
|
-
|
197
|
-
|
198
|
-
|
302
|
+
def send_frame(frame)
|
303
|
+
len=nil
|
304
|
+
@send_lock.synchronize {
|
305
|
+
@seq_lock.synchronize {
|
306
|
+
frame.sequence=@sequence
|
307
|
+
@sequence=@sequence+1
|
308
|
+
@queue_send.push(frame)
|
309
|
+
puts "Frame added to queue_send:\n#{frame.to_s}"
|
310
|
+
len=@queue_send.length
|
311
|
+
}
|
312
|
+
}
|
313
|
+
return(len)
|
314
|
+
end
|
315
|
+
|
316
|
+
def recv_frame()
|
317
|
+
frame=nil
|
318
|
+
@recv_lock.synchronize {
|
319
|
+
if @queue_recv.length>0
|
320
|
+
frame=@queue_recv.shift
|
321
|
+
end
|
322
|
+
}
|
323
|
+
return(frame)
|
324
|
+
end
|
325
|
+
|
326
|
+
def ping(hiscall)
|
327
|
+
self.send_frame(TxFrame.new(@mycall, hiscall, HAMNET_FRAME_PING, 0, nil, true))
|
328
|
+
return(nil)
|
199
329
|
end
|
200
|
-
|
201
|
-
return frames
|
202
330
|
end
|