2017-07-19 23:09:54 +00:00
|
|
|
#!/usr/bin/env python2
|
2008-05-04 21:47:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2003-08-25 22:26:08 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
## Uncomment to run this script from an in-tree build (or adjust to the
|
|
|
|
## build directory) without installing the bindings.
|
|
|
|
#sys.path.append ('.')
|
|
|
|
#sys.path.append ('.libs')
|
2003-08-25 22:26:08 +00:00
|
|
|
|
|
|
|
import Hamlib
|
|
|
|
|
2019-10-11 23:47:44 +00:00
|
|
|
def StartUp(verbose):
|
2017-07-19 23:09:54 +00:00
|
|
|
"""Simple script to test the Hamlib.py module with Python2."""
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "%s: Python %s; %s\n" \
|
|
|
|
% (sys.argv[0], sys.version.split()[0], Hamlib.cvar.hamlib_version)
|
|
|
|
|
2019-10-11 23:47:44 +00:00
|
|
|
Hamlib.rig_set_debug([Hamlib.RIG_DEBUG_NONE, Hamlib.RIG_DEBUG_VERBOSE][verbose])
|
2003-08-25 22:26:08 +00:00
|
|
|
|
|
|
|
# Init RIG_MODEL_DUMMY
|
2017-07-23 02:44:57 +00:00
|
|
|
my_rig = Hamlib.Rig(Hamlib.RIG_MODEL_DUMMY)
|
2017-07-19 23:09:54 +00:00
|
|
|
my_rig.set_conf("rig_pathname", "/dev/Rig")
|
|
|
|
my_rig.set_conf("retry", "5")
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
my_rig.open()
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2008-05-04 21:47:06 +00:00
|
|
|
rpath = my_rig.get_conf("rig_pathname")
|
|
|
|
retry = my_rig.get_conf("retry")
|
2017-07-19 23:09:54 +00:00
|
|
|
|
|
|
|
print "status(str):\t\t", Hamlib.rigerror(my_rig.error_status)
|
2020-09-12 13:59:55 +00:00
|
|
|
print "get_conf:\t\tpath = %s, retry = %s" \
|
|
|
|
% (rpath, retry)
|
2017-07-19 23:09:54 +00:00
|
|
|
|
|
|
|
my_rig.set_freq(Hamlib.RIG_VFO_B, 5700000000)
|
|
|
|
my_rig.set_vfo(Hamlib.RIG_VFO_B)
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "freq:\t\t\t", my_rig.get_freq()
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
my_rig.set_freq(Hamlib.RIG_VFO_A, 145550000)
|
2010-04-05 10:10:16 +00:00
|
|
|
(mode, width) = my_rig.get_mode()
|
2017-07-19 23:09:54 +00:00
|
|
|
|
|
|
|
print "mode:\t\t\t", Hamlib.rig_strrmode(mode), "\nbandwidth:\t\t", width
|
|
|
|
|
2010-04-05 10:10:16 +00:00
|
|
|
my_rig.set_mode(Hamlib.RIG_MODE_CW)
|
2008-05-04 21:47:06 +00:00
|
|
|
(mode, width) = my_rig.get_mode()
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "mode:\t\t\t", Hamlib.rig_strrmode(mode), "\nbandwidth:\t\t", width
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "Backend copyright:\t", my_rig.caps.copyright
|
|
|
|
print "Model:\t\t\t", my_rig.caps.model_name
|
|
|
|
print "Manufacturer:\t\t", my_rig.caps.mfg_name
|
|
|
|
print "Backend version:\t", my_rig.caps.version
|
2017-07-23 02:44:57 +00:00
|
|
|
print "Backend status:\t\t", Hamlib.rig_strstatus(my_rig.caps.status)
|
2012-11-28 23:11:41 +00:00
|
|
|
print "Rig info:\t\t", my_rig.get_info()
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2020-03-30 04:57:28 +00:00
|
|
|
my_rig.set_level("VOXDELAY", 1)
|
2017-07-19 23:09:54 +00:00
|
|
|
|
2020-03-30 04:57:28 +00:00
|
|
|
print "VOX delay:\t\t", my_rig.get_level_i("VOXDELAY")
|
2017-07-19 23:09:54 +00:00
|
|
|
|
2020-03-30 04:57:28 +00:00
|
|
|
my_rig.set_level(Hamlib.RIG_LEVEL_VOXDELAY, 5)
|
2017-07-19 23:09:54 +00:00
|
|
|
|
2020-03-30 04:57:28 +00:00
|
|
|
print "VOX delay:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_VOXDELAY)
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2016-11-03 12:07:13 +00:00
|
|
|
af = 12.34
|
2017-07-19 23:09:54 +00:00
|
|
|
|
|
|
|
print "Setting AF to %0.2f...." % (af)
|
|
|
|
|
2017-07-23 02:44:57 +00:00
|
|
|
my_rig.set_level("AF", af)
|
2016-11-03 12:07:13 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "status:\t\t\t%s - %s" % (my_rig.error_status,
|
|
|
|
Hamlib.rigerror(my_rig.error_status))
|
|
|
|
|
|
|
|
print "AF level:\t\t%0.2f" % my_rig.get_level_f(Hamlib.RIG_LEVEL_AF)
|
2012-11-28 23:11:41 +00:00
|
|
|
print "strength:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH)
|
2017-07-19 23:09:54 +00:00
|
|
|
print "status:\t\t\t", my_rig.error_status
|
|
|
|
print "status(str):\t\t", Hamlib.rigerror(my_rig.error_status)
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2008-05-04 21:47:06 +00:00
|
|
|
chan = Hamlib.channel(Hamlib.RIG_VFO_B)
|
2020-05-02 03:37:53 +00:00
|
|
|
my_rig.get_channel(chan,1)
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
print "get_channel status:\t", my_rig.error_status
|
|
|
|
print "VFO:\t\t\t", Hamlib.rig_strvfo(chan.vfo), ", ", chan.freq
|
2016-08-27 19:24:17 +00:00
|
|
|
print "Attenuators:\t\t", my_rig.caps.attenuator
|
2013-02-13 00:39:47 +00:00
|
|
|
print "\nSending Morse, '73'"
|
|
|
|
|
2017-07-19 23:09:54 +00:00
|
|
|
my_rig.send_morse(Hamlib.RIG_VFO_A, "73")
|
2003-08-25 22:26:08 +00:00
|
|
|
my_rig.close ()
|
|
|
|
|
2008-05-04 21:47:06 +00:00
|
|
|
print "\nSome static functions:"
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2012-11-28 23:11:41 +00:00
|
|
|
err, lon1, lat1 = Hamlib.locator2longlat("IN98XC")
|
|
|
|
err, lon2, lat2 = Hamlib.locator2longlat("DM33DX")
|
|
|
|
err, loc1 = Hamlib.longlat2locator(lon1, lat1, 3)
|
|
|
|
err, loc2 = Hamlib.longlat2locator(lon2, lat2, 3)
|
2017-07-19 23:09:54 +00:00
|
|
|
|
2012-11-28 23:11:41 +00:00
|
|
|
print "Loc1:\t\tIN98XC -> %9.4f, %9.4f -> %s" % (lon1, lat1, loc1)
|
|
|
|
print "Loc2:\t\tDM33DX -> %9.4f, %9.4f -> %s" % (lon2, lat2, loc2)
|
|
|
|
|
|
|
|
err, dist, az = Hamlib.qrb(lon1, lat1, lon2, lat2)
|
2003-08-25 22:26:08 +00:00
|
|
|
longpath = Hamlib.distance_long_path(dist)
|
2017-07-19 23:09:54 +00:00
|
|
|
|
2012-11-28 23:11:41 +00:00
|
|
|
print "Distance:\t%.3f km, azimuth %.2f, long path:\t%.3f km" \
|
2017-07-19 23:09:54 +00:00
|
|
|
% (dist, az, longpath)
|
2012-11-28 23:11:41 +00:00
|
|
|
|
|
|
|
# dec2dms expects values from 180 to -180
|
|
|
|
# sw is 1 when deg is negative (west or south) as 0 cannot be signed
|
|
|
|
err, deg1, mins1, sec1, sw1 = Hamlib.dec2dms(lon1)
|
|
|
|
err, deg2, mins2, sec2, sw2 = Hamlib.dec2dms(lat1)
|
|
|
|
|
|
|
|
lon3 = Hamlib.dms2dec(deg1, mins1, sec1, sw1)
|
|
|
|
lat3 = Hamlib.dms2dec(deg2, mins2, sec2, sw2)
|
|
|
|
|
|
|
|
print 'Longitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \
|
2017-07-19 23:09:54 +00:00
|
|
|
% (lon1, deg1, mins1, sec1, ('W' if sw1 else 'E'), lon3)
|
2003-08-25 22:26:08 +00:00
|
|
|
|
2012-11-28 23:11:41 +00:00
|
|
|
print 'Latitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \
|
2017-07-19 23:09:54 +00:00
|
|
|
% (lat1, deg2, mins2, sec2, ('S' if sw2 else 'N'), lat3)
|
|
|
|
|
2003-08-25 22:26:08 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-10-11 23:47:44 +00:00
|
|
|
StartUp([0,1]["-v" in sys.argv])
|