hamnet 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/hamnet.rb +144 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTAxZTNiMmI2NmRlY2I5ZDVkNGJkNjVjMDRkY2IxYmY3YWI2N2FlYQ==
4
+ YjVhMGIxNTg4MWUyMTcyYWJlODg2NGMwMmQzZmI5YTlhM2MxMmJlNA==
5
5
  data.tar.gz: !binary |-
6
- NWEzN2Y4ODVkY2YwZjU0Y2U0YTQ3OWJmMTgyYTk1MGM3OTMzNjIwMA==
6
+ OTY1YmU2NzBhYWYzY2MwMTY2MTlmOWIxYTQxNGJlMDViYjljZGM5YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTgzNDY1M2Y4OWQ2ZWVkNzU3MTU4Y2YxNDg1YWI3M2ZjZWRjMDgwNzcxMGM1
10
- N2RlYzYxMTc5OGFkZDdhZWE3MWU3OTlmODU1NmI1YWU1OWMzMGVhNDA4ODEy
11
- Y2E3YTJlNmM4ZmUyOTk0OWNmNzI4MGYzYWViNTNkYzc1OGZlYzg=
9
+ ZmYwNjRiYTkxZWM5NzExYjJhOTIxMjhhZjQxM2FkNTk3ZmJiMWZiMjc5M2Zi
10
+ ODk4ZWI0MDZkYmY4YjlhYTE5MDVhZTMyZmZjYWU3YjI2YzExZmIzZDBlMDIz
11
+ ZDcwMDYxMTk1OGI3MDMyNGE1ZjJkMDIwYjAyY2ViYjZhMTA1MmE=
12
12
  data.tar.gz: !binary |-
13
- ZTJmMmJhYzRlMWY1ZWI0NmFhMzM2NzJlNjM1NTg3MDY0YTZiNmU4MDBjZWVl
14
- YjVmMTJlMWZjMTMzN2UyYTM2MzI1NmJjMDliZWUwMWQ1OWVkY2M2YzBmOGE5
15
- NmQ2YTI4ZDZjYzVmZTYzNmMzZTI1ZTI1OTIzMjJlOTFkNjQ3NmM=
13
+ MTllNmRkZTdjNWE3NjI2Y2M2NDQ5YzIyMzAxOGIwMTVjZjVhMTM4ZDk2Njky
14
+ ZjBjM2NhYzVjMjZhNGQ5NTU5Y2NiNjQwMGZmODJlYjY4NDViYzQwODI0NDY0
15
+ ZTE0MmNmMTVjNzkzYThjYTcwNjQ5ZWY0MTcwYjZjMzMwNGUwMTM=
@@ -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
- def sendstring(from, to, type, text, max)
182
- sequence=0
183
- frames=Array.new()
184
- done=false
182
+ class Hamnet
183
+ attr_accessor :mycall, :dialfreq, :carrier, :modem
185
184
 
186
- while text.length > max
187
- chunk=text[0,max]
188
- text=text[max,text.length-max]
189
- if text.length==0
190
- done=true
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
- if text.length > 0
197
- frames.push(TxFrame.new(from, to, type, sequence, text, true))
198
- sequence=sequence+1
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Francis, N0GQ