#!/usr/bin/python
#
# Orion dump state to file.
# Copyright (c) 2005 Martin S. Ewing, AA6E
# Requires pyserial package (pyserial.sourceforge.net)
# Developed under Python 2.3.4 and Fedora Linux FC3
#
import serial,sys,time,os
#
# Serial port for Orion
#
#DEVICE="/dev/ttyS0"
DEVICE="/dev/ham.orion"
#
IDENT="odump.py 04/2005 AA6E"
#
# Global variables
#
ser = 0 # serial port object
#
# Orion basic I/O
#
def rd():
global ser
MAX=50; c=''; ans=''; i=0
while c <> '\r':
c = ser.read(1)
# Timeout happens when Orion gets funky. Next time should be ok.
if c == '': break #timeout? try again?
ans += c
i += 1
if i > MAX : raise MyExcept, "serial read too long"
return ans[:-1] # trim off final \r
#
def wrt(s):
global ser
if ser.inWaiting(): ser.flushInput() # Orion i/o has slipped
ser.write(s+'\r')
return None
#
def oget(ss): # Get data from Orion
MAX=5; t = ''; i=0;
for i in range(MAX):
wrt(ss)
t = rd()
if len(t)<len(ss) : continue # read string too short
if t[1:len(ss)] == ss[1:] : break # resp. looks good
return t[len(ss):] # return data part only
#
def oget_spl(ss): # Get data from Orion (special for ?AU etc)
MAX=5; t = ''; i=0;
for i in range(MAX):
wrt(ss)
t = rd()
if len(t)<len(ss) : continue # read string too short
if t[1:len(ss)] == ss[1:] : break # resp. looks good
return t[len(ss)-1:] # return data part only, but keep one more to left
#
def oput(ss): # Send a command to Orion
wrt(ss)
t = rd() # Do we get a response?
if len(t) > 0: print "resp=",t
return None
#
# Dump state - all variables - to file
# Dump in format of Orion ASCII command to restore value.
#
def fdump(f):
# Get VFO values
print >>f, "*AF%s" % oget("?AF") # vfo a
print >>f, "*BF%s" % oget("?BF") # vfo b
print >>f, "*KV%s" % oget("?KV") # vfo assignments
print >>f, "*UC%s" % oget("?UC") # Spkr/phones select
# *UR broken
# Main Rx info
print >>f, "*RME%s" % oget("?RME") # Preamp
print >>f, "*RMM%s" % oget("?RMM") # mode
print >>f, "*RMF%s" % oget("?RMF") # Filter
print >>f, "*RMP%s" % oget("?RMP") # PBT
print >>f, "*RMS%s" % oget("?RMS") # SQL
print >>f, "*RMX%s" % oget("?RMX") # XIT
print >>f, "*RMR%s" % oget("?RMR") # RIT
print >>f, "*RMG%s" % oget("?RMG") # RF GAIN
print >>f, "*RMT%s" % oget("?RMT") # Atten
print >>f, "*RMI%s" % oget("?RMI") # Inc = tuning step
print >>f, "*RMA%s" % oget("?RMA") # AGC
print >>f, "*UM%s" % oget("?UM") # Main Rx Vol
# *UB = broken
# Sub Rx info
# (no preamp for sub rx)
print >>f, "*RSM%s" % oget("?RSM") # mode
print >>f, "*RSF%s" % oget("?RSF") # Filter
print >>f, "*RSP%s" % oget("?RSP") # PBT
print >>f, "*RSS%s" % oget("?RSS") # SQL
# no RSX
print >>f, "*RSR%s" % oget("?RSR") # RIT
print >>f, "*RSG%s" % oget("?RSG") # RF GAIN
print >>f, "*RST%s" % oget("?RST") # Atten
print >>f, "*RSI%s" % oget("?RSI") # Inc = tuning step
print >>f, "*RSA%s" % oget("?RSA") # AGC
print >>f, "*US%s" % oget("?US") # Sub Rx Vol
#
print >>f, "*A%s" % oget_spl("?AU") # A lock/unlock
print >>f, "*B%s" % oget_spl("?BU") # B lock/unlock
# Antenna Info
print >>f, "*KA%s" % oget("?KA")
# CW Info
print >>f, "*CK%s" % oget("?CK") # Keyer on/off
print >>f, "*CS%s" % oget("?CS") # Keyer speed
print >>f, "*CW%s" % oget("?CW") # Keyer weight
print >>f, "*CT%s" % oget("?CT") # Sidetone freq
print >>f, "*CV%s" % oget("?CV") # Sidetone (mon) vol.
print >>f, "*CD%s" % oget("?CD") # Keyer rise/fall
print >>f, "*CQ%s" % oget("?CQ") # Keyer QSK del
# TX Info
print >>f, "*TM%s" % oget("?TM") # Mic gain
print >>f, "*TO%s" % oget("?TO") # Mon level
print >>f, "*TP%s" % oget("?TP") # Tx power
print >>f, "*TF%s" % oget("?TF") # Tx bandwidth
print >>f, "*TS%s" % oget("?TS") # Sp proc
print >>f, "*TG%s" % oget("?TG") # VOX trig
print >>f, "*TA%s" % oget("?TA") # VOX anti
print >>f, "*TH%s" % oget("?TH") # VOX hang
# *TT = broken
print >>f, "*TL2%s" % oget("?TL1") # Tune loop 1
print >>f, "*TL2%s" % oget("?TL2") # Tune loop 2
print >>f, "*TD1%s" % oget("?TD1") # Tune loop 1 del
print >>f, "*TD2%s" % oget("?TD2") # Tune loop 2 del
print >>f, "*TX%s" % oget("?TX") # Transverter
return
#
# Main Entry
#
# Usage: odump.py [ filename ['Comment string']]
# If filename is null or "-", use stdout.
#
print IDENT
#
# Open the Orion's channel
#
ser = serial.Serial(DEVICE,baudrate=57600,rtscts=1,timeout=0.2)
ser.flushInput()
ser.flushOutput()
#
# Output file
#
f = 0
if len(sys.argv) > 1 :
if sys.argv[1] != "-" :
name = sys.argv[1]
print "Opening output file %s" % name
f = open(name, mode='w')
if f == 0 :
f = sys.stdout
print >>f, "#", time.asctime(), " Dump of Ten-Tec Orion ",IDENT
if len(sys.argv) > 2 :
print >>f, "# %s" % sys.argv[2]
#
# Wake up the Orion
#
wrt("XX") # Orion ID = syncs the serial port
msg1=rd()
wrt("?V") # Firmware version number
msg2=rd()
print >>f, "#Orion ID & firmware:",msg1,msg2
#
fdump(f)
f.close()
ser.flushInput()
ser.close()