fldigi 0.1.4 → 0.1.6
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.
- data/lib/fldigi.rb +83 -33
- metadata +2 -2
data/lib/fldigi.rb
CHANGED
@@ -20,11 +20,36 @@
|
|
20
20
|
#
|
21
21
|
# XMLRPC::Config::ENABLE_NIL_PARSER=true
|
22
22
|
|
23
|
+
require 'time'
|
23
24
|
require 'xmlrpc/client'
|
24
25
|
require 'thread'
|
25
26
|
|
27
|
+
# Turn 1/0 into false/true (some XMLRPC libraries seem to return 1/0,
|
28
|
+
# others true/false). This cleans up the code a bit.
|
29
|
+
def torf(n)
|
30
|
+
if n==0 or n==false
|
31
|
+
return false
|
32
|
+
else
|
33
|
+
return true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Hold the error message generated (along with a timestamp).
|
38
|
+
class Error
|
39
|
+
attr_accessor :timestamp, :text
|
40
|
+
|
41
|
+
def initialize(text)
|
42
|
+
@timestamp=Time.now()
|
43
|
+
@text=text
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_s
|
47
|
+
"#{@timestamp.to_s}: #{@text}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
26
51
|
class Fldigi
|
27
|
-
attr_accessor :rigctl, :dial_freq, :carrier, :call, :modem, :afc, :rsid, :sideband, :squelch, :slevel, :spot, :delay, :grid, :phg, :band, :offset, :start_wait, :char_wait, :debug
|
52
|
+
attr_accessor :rigctl, :dial_freq, :carrier, :call, :modem, :afc, :rsid, :sideband, :squelch, :slevel, :spot, :delay, :grid, :phg, :band, :offset, :start_wait, :char_wait, :debug, :errors
|
28
53
|
|
29
54
|
# Do the initial setup. All arguments are optional, default is
|
30
55
|
# rigctl, localhost, standard port. If you have no rig control,
|
@@ -39,6 +64,7 @@ class Fldigi
|
|
39
64
|
@port=port
|
40
65
|
@message=""
|
41
66
|
@rigctl=rigctl
|
67
|
+
@errors=Array.new
|
42
68
|
|
43
69
|
# Set up the defaults.
|
44
70
|
@dial_freq=14070000.0
|
@@ -79,6 +105,11 @@ class Fldigi
|
|
79
105
|
@m=Mutex.new
|
80
106
|
end
|
81
107
|
|
108
|
+
# Add an error message to the queue.
|
109
|
+
def error(text)
|
110
|
+
@errors.push(Error.new(text))
|
111
|
+
end
|
112
|
+
|
82
113
|
# Send an XML-RPC command to FLDigi.
|
83
114
|
def sendcmd(cmd, param=-1)
|
84
115
|
if param==-1
|
@@ -139,7 +170,8 @@ class Fldigi
|
|
139
170
|
if @modem==self.sendcmd("modem.get_name")
|
140
171
|
@modem_old=@modem
|
141
172
|
else
|
142
|
-
|
173
|
+
self.error("modem.set_name failed with value #{@modem}")
|
174
|
+
puts "modem.set_name failed" if @debug
|
143
175
|
status=false
|
144
176
|
end
|
145
177
|
end
|
@@ -147,38 +179,42 @@ class Fldigi
|
|
147
179
|
|
148
180
|
# Turn spot on/off (true/false).
|
149
181
|
if @spot!=@spot_old
|
150
|
-
|
151
|
-
if (ret==1 and @spot==true) or (ret==0 and @spot==false) or (ret==@spot)
|
182
|
+
if torf(self.sendcmd("spot.get_auto"))==@spot
|
152
183
|
@spot_old=@spot
|
153
184
|
else
|
154
185
|
self.sendcmd("spot.set_auto", @spot)
|
155
|
-
|
156
|
-
if (ret==1 and @spot==true) or (ret==0 and @spot==false) or (ret==@spot)
|
186
|
+
if torf(self.sendcmd("spot.get_auto"))==@spot
|
157
187
|
@spot_old=@spot
|
158
188
|
else
|
159
|
-
|
189
|
+
self.error("spot.set_auto failed with value #{@spot}")
|
190
|
+
puts "spot.set_auto failed" if @debug
|
160
191
|
status=false
|
161
192
|
end
|
162
193
|
end
|
163
194
|
end
|
164
195
|
|
165
|
-
# Turn AFC on/off (true/false).
|
166
|
-
|
167
|
-
|
168
|
-
|
196
|
+
# Turn AFC on/off (true/false). Some modes don't work with
|
197
|
+
# AFC. There seems to be a great deal of inconsistency (a bug,
|
198
|
+
# maybe?) in reading the AFC value back from FLDigi. Every test I
|
199
|
+
# can come up with points to a bug in their code, not mine. Until
|
200
|
+
# we can get this sorted out, don't consider failure to set AFC as
|
201
|
+
# fatal. Just unset it, and continue on. ToDo: Verify bug in
|
202
|
+
# FLDigi, then fix.
|
203
|
+
if (@afc!=@afc_old)
|
204
|
+
if torf(self.sendcmd("main.get_afc"))==@afc
|
169
205
|
@afc_old=@afc
|
170
206
|
else
|
171
207
|
self.sendcmd("main.set_afc", @afc)
|
172
|
-
|
173
|
-
|
208
|
+
sleep 0.25
|
209
|
+
if torf(self.sendcmd("main.get_afc"))==@afc
|
174
210
|
@afc_old=@afc
|
175
211
|
else
|
176
|
-
|
177
|
-
|
212
|
+
@afc=false
|
213
|
+
puts "main.set_afc failed, so leaving turned off" if @debug
|
178
214
|
end
|
179
215
|
end
|
180
216
|
end
|
181
|
-
|
217
|
+
|
182
218
|
# Set the sideband ("USB"/"LSB"). ToDo: make sure this is
|
183
219
|
# correct.
|
184
220
|
if @sideband!=@sideband_old
|
@@ -189,7 +225,8 @@ class Fldigi
|
|
189
225
|
if @sideband==self.sendcmd("main.get_sideband")
|
190
226
|
@sideband_old=@sideband
|
191
227
|
else
|
192
|
-
|
228
|
+
self.error("main.set_sideband failed with value #{@sideband}")
|
229
|
+
puts "main.set_sideband failed" if @debug
|
193
230
|
status=false
|
194
231
|
end
|
195
232
|
end
|
@@ -197,16 +234,15 @@ class Fldigi
|
|
197
234
|
|
198
235
|
# Turn RSID receive on/off (true/false).
|
199
236
|
if @rsid!=@rsid_old
|
200
|
-
|
201
|
-
if (ret==1 and @rsid==true) or (ret==0 and @rsid==false) or (ret==@rsid)
|
237
|
+
if torf(self.sendcmd("main.get_rsid"))==@rsid
|
202
238
|
@rsid_old=@rsid
|
203
239
|
else
|
204
240
|
self.sendcmd("main.set_rsid", @rsid)
|
205
|
-
|
206
|
-
if (ret==1 and @rsid==true) or (ret==0 and @rsid==false) or (ret==@rsid)
|
241
|
+
if torf(self.sendcmd("main.get_rsid"))==@rsid
|
207
242
|
@rsid_old=@rsid
|
208
243
|
else
|
209
|
-
|
244
|
+
self.error("main.set_rsid failed with value #{@rsid}")
|
245
|
+
puts "main.set_rsid failed" if @debug
|
210
246
|
status=false
|
211
247
|
end
|
212
248
|
end
|
@@ -214,16 +250,15 @@ class Fldigi
|
|
214
250
|
|
215
251
|
# Turn squelch on/off (true/false).
|
216
252
|
if @squelch!=@squelch_old
|
217
|
-
|
218
|
-
if (ret==1 and @squelch==true) or (ret==0 and @squelch==false) or (ret==@squelch)
|
253
|
+
if torf(self.sendcmd("main.get_squelch"))==@squelch
|
219
254
|
@squelch_old=@squelch
|
220
255
|
else
|
221
256
|
self.sendcmd("main.set_squelch", @squelch)
|
222
|
-
|
223
|
-
if (ret==1 and @squelch==true) or (ret==0 and @squelch==false) or (ret==@squelch)
|
257
|
+
if torf(self.sendcmd("main.get_squelch"))==@squelch
|
224
258
|
@squelch_old=@squelch
|
225
259
|
else
|
226
|
-
|
260
|
+
self.error("main.set_squelch failed with value #{@squelch}")
|
261
|
+
puts "main.set_squelch failed" if @debug
|
227
262
|
status=false
|
228
263
|
end
|
229
264
|
end
|
@@ -239,7 +274,8 @@ class Fldigi
|
|
239
274
|
if @slevel==self.sendcmd("main.get_squelch_level")
|
240
275
|
@slevel=@slevel.to_f
|
241
276
|
else
|
242
|
-
|
277
|
+
self.error("main.set_squelch_level failed with value #{@slevel}")
|
278
|
+
puts "main.set_squelch_level failed" if @debug
|
243
279
|
status=false
|
244
280
|
end
|
245
281
|
end
|
@@ -271,7 +307,9 @@ class Fldigi
|
|
271
307
|
# "1000" on the other radio, as well. There's no good, clean,
|
272
308
|
# all-purpose solution to this one, but at least it allows for
|
273
309
|
# consistent and automated use of the library without having to do
|
274
|
-
# the conversions in your own code.
|
310
|
+
# the conversions in your own code. We give ourselves two tries to
|
311
|
+
# get the freq right, since some rigs seem to act a bit odd when
|
312
|
+
# changing bands.
|
275
313
|
@dial_freq=@dial_freq.to_i
|
276
314
|
if (@dial_freq!=@dial_freq_old or @offset!=@offset_old) and @rigctl
|
277
315
|
@dial_freq_old=@dial_freq
|
@@ -280,8 +318,13 @@ class Fldigi
|
|
280
318
|
self.sendcmd("main.set_frequency", @dial_freq+@offset.to_f)
|
281
319
|
sleep 0.5
|
282
320
|
if @dial_freq+@offset.to_i!=self.sendcmd("main.get_frequency").to_f
|
283
|
-
|
284
|
-
|
321
|
+
self.sendcmd("main.set_frequency", @dial_freq+@offset.to_f)
|
322
|
+
sleep 0.5
|
323
|
+
if @dial_freq+@offset.to_i!=self.sendcmd("main.get_frequency").to_f
|
324
|
+
self.error("main.set_frequency failed with value #{@dial_freq}")
|
325
|
+
puts "main.set_frequency failed" if @debug
|
326
|
+
status=false
|
327
|
+
end
|
285
328
|
end
|
286
329
|
end
|
287
330
|
end
|
@@ -316,6 +359,7 @@ class Fldigi
|
|
316
359
|
if self.sendcmd("main.get_trx_status")=="tx"
|
317
360
|
return true
|
318
361
|
else
|
362
|
+
self.error("main.tx failed")
|
319
363
|
return false
|
320
364
|
end
|
321
365
|
end
|
@@ -355,7 +399,7 @@ class Fldigi
|
|
355
399
|
|
356
400
|
# Send the currently buffered data using the carrier, mode,
|
357
401
|
# frequency, etc. currently configured. The current code will wait
|
358
|
-
# up to @start_wait
|
402
|
+
# up to @start_wait seconds for the first character to be
|
359
403
|
# transmitted (this gives time for really slow modems to get
|
360
404
|
# rolling). Once the first sent character is detected, it makes
|
361
405
|
# sure it sees as least one character every @char_wait (2) seconds
|
@@ -372,6 +416,8 @@ class Fldigi
|
|
372
416
|
def send_buffer(verbose=false)
|
373
417
|
if @message.length > 0
|
374
418
|
self.transmit()
|
419
|
+
send_length=@message.length
|
420
|
+
send_start=Time.now()
|
375
421
|
show=""
|
376
422
|
while @message.length > 0
|
377
423
|
@m.synchronize do
|
@@ -380,7 +426,7 @@ class Fldigi
|
|
380
426
|
end
|
381
427
|
waited=0
|
382
428
|
max=@start_wait
|
383
|
-
|
429
|
+
|
384
430
|
result=""
|
385
431
|
while waited<max
|
386
432
|
waited=waited+1
|
@@ -398,6 +444,8 @@ class Fldigi
|
|
398
444
|
end
|
399
445
|
end
|
400
446
|
self.receive()
|
447
|
+
send_end=Time.now()
|
448
|
+
puts "#{send_length} characters sent in #{(send_end-send_start).to_i} seconds, #{((((send_length/(send_end.to_f-send_start.to_f))*10)+0.5).to_i)/10.to_f} chars/sec." if @debug
|
401
449
|
return show
|
402
450
|
end
|
403
451
|
|
@@ -527,6 +575,7 @@ class Fldigi
|
|
527
575
|
@dial_freq=50291000
|
528
576
|
@fsym="vb"
|
529
577
|
else
|
578
|
+
self.error("Invalid propnet band: #{band}")
|
530
579
|
return false
|
531
580
|
end
|
532
581
|
|
@@ -558,6 +607,7 @@ class Fldigi
|
|
558
607
|
self.add_tx_string("CQ CQ CQ de #{@call} #{@call} #{@call} pse k")
|
559
608
|
return true
|
560
609
|
else
|
610
|
+
self.error("Unable to queue CQ string.")
|
561
611
|
return false
|
562
612
|
end
|
563
613
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fldigi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A library for talking to FLDigi.
|
15
15
|
email: jeff@gritch.org
|