1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/env python
#
# Copyright 2009 Dan Smith <dsmith@danplanet.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import serial
import commands
from chirp import idrp, chirp_common
def open_device():
try:
s = serial.Serial(port="/dev/icom",
baudrate=idrp.IDRPx000V.BAUD_RATE,
timeout=0.1)
except Exception as e:
print "Unable to open serial port %s: %s" % ("/dev/icom", e)
return None
rp = idrp.IDRPx000V(s)
return rp
def read_freq():
rp = open_device()
if not rp:
return 0
try:
mem = rp.get_memory(0)
except Exception as e:
print "Unable to read memory from device: %s" % e
return 0
rp.pipe.close()
return mem.freq
def _set_freq(rp):
try:
mem = rp.get_memory(0)
except Exception as e:
print "Unable to read memory from device: %s" % e
return False
print "\nNew frequency [%s]: " % chirp_common.format_freq(mem.freq),
input = sys.stdin.readline().strip()
if not input:
print "Frequency unchanged"
return False
try:
mem.freq = chirp_common.parse_freq(input)
except Exception:
print "Invalid entry `%s'" % input
return False
try:
rp.set_memory(mem)
except Exception as e:
print "Failed to set frequency to %s: %s" % \
(chirp_common.format_freq(mem.freq), e)
return False
print "Successfully set frequency to %s" % \
chirp_common.format_freq(mem.freq)
return True
def set_freq():
rp = open_device()
if not rp:
return
try:
res = _set_freq(rp)
except Exception as e:
print "Unknown error while setting frequency: %s" % e
res = False
rp.pipe.close()
return res
def main_menu():
print "Looking for a repeater...",
sys.stdout.flush()
freq = read_freq()
if not freq:
return 1
print "\r \r",
cmd = ""
while cmd != "3":
print """
KK7DS ID-RP* Frequency Tool
Current Setting: %s
--------------------------------
1. Set repeater frequency
2. Re-read current frequency
3. Quit
--------------------------------
> """ % chirp_common.format_freq(freq),
cmd = sys.stdin.readline().strip()
if cmd == "1":
if set_freq():
freq = read_freq()
elif cmd == "2":
freq = read_freq()
elif cmd != "3":
print "Invalid entry"
return 0
if __name__ == "__main__":
if os.path.exists("tools/icomsio.sh"):
path = "tools/icomsio.sh"
else:
path = "icomsio.sh"
r = os.system(path)
if r:
sys.exit(r)
if not os.geteuid() == 0:
print "Sorry, this must be run as root"
sys.exit(1)
sys.exit(main_menu())
|