public:radio:radio_database:ic-r75
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| public:radio:radio_database:ic-r75 [05/05/23 16:17 BST] – [3. Remote Control] john | public:radio:radio_database:ic-r75 [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | < | ||
| - | |||
| - | |||
| - | ====== IC-R75 ====== | ||
| - | |||
| - | ===== - Details ===== | ||
| - | |||
| - | |||
| - | ===== - Repairs / Mods ===== | ||
| - | |||
| - | * -5V DC/DC converter | ||
| - | * various capacitor failures | ||
| - | |||
| - | * "Turn Off" fault - due to overheating of 13V regulator | ||
| - | * Cured by | ||
| - | * Reduce input voltage to 13.8V | ||
| - | * Improve heatsinking of regulator IC to chassis | ||
| - | |||
| - | ===== - Remote Control ===== | ||
| - | |||
| - | {{ : | ||
| - | |||
| - | |||
| - | * connected to '' | ||
| - | * '' | ||
| - | * '' | ||
| - | * Available controls: < | ||
| - | There are currently 1 radios connected. | ||
| - | ================================= | ||
| - | Status of Radio 1 (IC-R75) | ||
| - | |||
| - | Frequency : 391.000 kHz | ||
| - | Mode: CW | ||
| - | S-Meter: -113.0dBm | ||
| - | 1 : 0 | ||
| - | ================================= | ||
| - | |||
| - | Please choose a radio | ||
| - | |||
| - | There are currently 1 radios connected. | ||
| - | Radio 1 is IC-R75 | ||
| - | Choose a radio number from the list : 1 | ||
| - | |||
| - | The available commands are: | ||
| - | lr : List Radios | ||
| - | sr : Select the Radio to control | ||
| - | gr : Get currently selected Radio name | ||
| - | gm : Get Mode | ||
| - | sm : Set Mode | ||
| - | gf : Get Freq | ||
| - | sf : Set Freq | ||
| - | gs : Get S-meter | ||
| - | gp : Get Pre-amp | ||
| - | pon : Set Pre-amp On | ||
| - | poff : Set Pre-amp Off | ||
| - | gatt : Get Attn | ||
| - | aton : Set Attn On | ||
| - | atoff: Set Attn Off | ||
| - | ga : Get All (status of all radios) | ||
| - | sync : Sync freq/mode on two radios | ||
| - | log : Setup background logging to file | ||
| - | h : Help (show this command list) | ||
| - | q : quit | ||
| - | |||
| - | IC-R75 > | ||
| - | </ | ||
| - | * audio via network using '' | ||
| - | * running on shack '' | ||
| - | * running on Windows laptop // | ||
| - | |||
| - | Remote control is achieved via a SSH connection to shack '' | ||
| - | |||
| - | |||
| - | ===== Documentation ===== | ||
| - | |||
| - | * {{ : | ||
| - | * {{ : | ||
| - | |||
| - | |||
| - | |||
| - | ===== - Further Reading ===== | ||
| - | |||
| - | * Python code for the remote control at '' | ||
| - | |||
| - | ==== server.py ==== | ||
| - | |||
| - | ++++ Code.... | | ||
| - | |||
| - | <code python> | ||
| - | #from aor import * | ||
| - | from icom import * | ||
| - | from conf import * | ||
| - | #from m710 import * | ||
| - | import SocketServer | ||
| - | import time | ||
| - | |||
| - | try: | ||
| - | import readline | ||
| - | except: | ||
| - | pass | ||
| - | |||
| - | lock = threading.Lock() | ||
| - | |||
| - | radios = [] | ||
| - | |||
| - | |||
| - | #r1 = m710(n4) | ||
| - | # | ||
| - | |||
| - | r1 = Icom(n1, a1, cal1) | ||
| - | radios.append(n1) | ||
| - | |||
| - | #r2 = Icom(n2, a2, cal2) | ||
| - | # | ||
| - | |||
| - | #r3 = Ar7030(n3) | ||
| - | # | ||
| - | |||
| - | print radios | ||
| - | print r1.digi_off() | ||
| - | |||
| - | def list_radios(): | ||
| - | radiolist = "" | ||
| - | for n in range(0, len(radios)): | ||
| - | r = radios[n] | ||
| - | radiolist += (r + " ") | ||
| - | return radiolist | ||
| - | |||
| - | |||
| - | def write_file(text): | ||
| - | filename = ' | ||
| - | f = open(filename, | ||
| - | timenow = time.strftime(" | ||
| - | log = " " | ||
| - | f.write(log) | ||
| - | f.close() | ||
| - | |||
| - | |||
| - | def write_con(text): | ||
| - | filename = ' | ||
| - | f = open(filename, | ||
| - | timenow = time.strftime(" | ||
| - | log = " " | ||
| - | f.write(log) | ||
| - | f.close() | ||
| - | |||
| - | |||
| - | # The Server | ||
| - | class ThreadedRequestHandler(SocketServer.StreamRequestHandler): | ||
| - | def handle(self): | ||
| - | # we find the current thread for the client connection just set up, to | ||
| - | # use in the log file | ||
| - | cur_thread = threading.currentThread() | ||
| - | # log the new connection details | ||
| - | write_con(" | ||
| - | # print to the server' | ||
| - | print self.client_address | ||
| - | # loop to handle client requests.... | ||
| - | while True: | ||
| - | # using StreamRequestHandler means our input from the client | ||
| - | # is " | ||
| - | # we read a line at a time, using readline() | ||
| - | cmd = self.rfile.readline().lower() | ||
| - | # to keep things clean, we remove any characters that aren't | ||
| - | # " | ||
| - | # these are between 32 and 127 in the ASCII table | ||
| - | # we look at each character, and then make a new word by | ||
| - | # .join()ing each accepted character with no space in between | ||
| - | asccmd = "" | ||
| - | # we make a list called " | ||
| - | # will be inspected by various functions | ||
| - | words = asccmd.split() | ||
| - | # If a client uses sock.close() itself, to disconnect, it appears that | ||
| - | # we read a continuous stream of "" | ||
| - | # socket, which puts CPU to 100%. | ||
| - | # | ||
| - | # The " | ||
| - | # way to keep the connection up for multiple commands. | ||
| - | # | ||
| - | # Further connection are accepted due to the Threaded nature of the server. | ||
| - | # The CPU load is unacceptable though | ||
| - | # HACK ?>>>>> | ||
| - | # Looking for "" | ||
| - | # the connection from the server end (even though the client has | ||
| - | # gone) cures this. | ||
| - | if cmd == "": | ||
| - | break | ||
| - | else: | ||
| - | pass | ||
| - | # if the words list is empty, go back and get more input | ||
| - | if not words: | ||
| - | continue | ||
| - | # we have input.... | ||
| - | # filter based on the first word - these are the | ||
| - | # pre-set commands the server will accept | ||
| - | # the client wants to know the currently available | ||
| - | # radio names - held in the variable " | ||
| - | elif words[0] == " | ||
| - | self.wfile.write(rnames) | ||
| - | # words[-1] (the last word in the list) will always be the | ||
| - | # radio name. We give the variable " | ||
| - | # identifying which radio object to apply the method to | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | mode = my_radio.get_mode() | ||
| - | self.wfile.write(mode) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | freq = words[1] | ||
| - | freq = my_radio.get_freq() | ||
| - | self.wfile.write(freq) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | mode = words[1] | ||
| - | newmode = my_radio.set_mode(mode) | ||
| - | self.wfile.write(newmode) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | freq = float(words[1]) | ||
| - | newfreq = my_radio.set_freq(freq) | ||
| - | self.wfile.write(newfreq) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | smeter = round(float(my_radio.get_smeter()), | ||
| - | self.wfile.write(smeter) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | s = my_radio.get_s() | ||
| - | self.wfile.write(s) | ||
| - | elif words[0] == " | ||
| - | radios = list_radios() | ||
| - | self.wfile.write(radios) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | preamp = my_radio.get_pre() | ||
| - | self.wfile.write(preamp) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | preamp = my_radio.pre_on() | ||
| - | self.wfile.write(preamp) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | preamp = my_radio.pre_off() | ||
| - | self.wfile.write(preamp) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | att = my_radio.get_att() | ||
| - | self.wfile.write(att) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | att = my_radio.att_on() | ||
| - | self.wfile.write(att) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | att = my_radio.att_off() | ||
| - | self.wfile.write(att) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | tune = my_radio.tune() | ||
| - | self.wfile.write(tune) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | pwr = my_radio.get_pwr() | ||
| - | self.wfile.write(pwr) | ||
| - | elif words[0] == " | ||
| - | my_radio = eval(words[-1]) | ||
| - | spwr = words[1] | ||
| - | pwr = my_radio.set_pwr(spwr) | ||
| - | self.wfile.write(pwr) | ||
| - | elif words[0] == " | ||
| - | write_con(" | ||
| - | self.wfile.write(" | ||
| - | break | ||
| - | else: # nothing in words[0] matches a pre-set command.... | ||
| - | write_file(" | ||
| - | self.wfile.write(" | ||
| - | |||
| - | |||
| - | class ThreadedIcomServer(SocketServer.ThreadingMixIn, | ||
| - | pass | ||
| - | |||
| - | |||
| - | if __name__ == ' | ||
| - | # define the lock to be used on the serial port access | ||
| - | lock = threading.Lock() | ||
| - | |||
| - | # address ('' | ||
| - | address = ('', | ||
| - | server = ThreadedIcomServer(address, | ||
| - | server.allow_reuse_address = True | ||
| - | |||
| - | # define that the server will be threaded, and will serve " | ||
| - | t = threading.Thread(target=server.serve_forever) | ||
| - | # start the server thread | ||
| - | t.start() | ||
| - | |||
| - | write_con( | ||
| - | " | ||
| - | </ | ||
| - | |||
| - | ++++ | ||
| - | ==== icom.py ==== | ||
| - | |||
| - | ++++ Code ... | | ||
| - | |||
| - | <code python> | ||
| - | import serial | ||
| - | import threading | ||
| - | from conf import * | ||
| - | import time | ||
| - | #sport = " | ||
| - | sport = "/ | ||
| - | sbaud = 9600 | ||
| - | |||
| - | lock = threading.Lock() | ||
| - | |||
| - | |||
| - | class Icom(object): | ||
| - | def __init__(self, | ||
| - | self.ser = serial.Serial(sport, | ||
| - | self.model = model | ||
| - | self.radio_address = radio_address | ||
| - | self.cal = cal | ||
| - | | ||
| - | def digi_off(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + digi_off_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return " | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def get_pre(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_pre_cmd + eom | ||
| - | |||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | if result[6] == " | ||
| - | return 0 | ||
| - | elif result[6] == " | ||
| - | return 1 | ||
| - | |||
| - | def get_pwr(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + pwr_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | p1 = ord(result[7]) / 16 | ||
| - | p2 = ord(result[7]) % 16 | ||
| - | p3 = ord(result[6]) / 16 | ||
| - | p4 = ord(result[6]) % 16 | ||
| - | pwr = float(100 * (10 * p3 + p4) + (10 * p1 + p2)) | ||
| - | return int(pwr*100/ | ||
| - | |||
| - | def set_pwr(self, | ||
| - | #if pwr == " | ||
| - | # spwr = " | ||
| - | #elif pwr == " | ||
| - | # spwr = " | ||
| - | #elif pwr == " | ||
| - | # spwr = " | ||
| - | #elif pwr == " | ||
| - | # spwr = " | ||
| - | rigpwr = int(pwr) * 255 / 100 | ||
| - | print " | ||
| - | pwr1 = rigpwr / 100 | ||
| - | pwr2 = rigpwr % 100 | ||
| - | spwr1 = (pwr1 / 10 * 16) | ||
| - | spwr2 = (pwr1 % 10) | ||
| - | spwr3 = (pwr2 / 10 * 16) | ||
| - | spwr4 = (pwr2 % 10) | ||
| - | spwr = chr(spwr1+spwr2) + chr(spwr3+spwr4) | ||
| - | #print "spwr ", spwr | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + pwr_cmd + spwr + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return self.get_pwr() | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def pre_on(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_pre_cmd + set_pre_on + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return " | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def pre_off(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_pre_cmd + set_pre_off + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return " | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def ptt_on(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + ptt_on_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | #print result[5] | ||
| - | if not result[4] == ack: | ||
| - | return "ptt on" | ||
| - | elif result[4] == nak: | ||
| - | return " | ||
| - | | ||
| - | def ptt_off(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + ptt_off_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | #print result[5] | ||
| - | if not result[4] == ack: | ||
| - | return "ptt off" | ||
| - | elif result[4] == nak: | ||
| - | return " | ||
| - | |||
| - | def get_att(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_att_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | if result[5] == " | ||
| - | return 0 | ||
| - | elif result[5] == " | ||
| - | return 1 | ||
| - | |||
| - | def att_on(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_att_cmd + set_att_on + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return " | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def att_off(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_att_cmd + set_att_off + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return " | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received" | ||
| - | |||
| - | def set_freq(self, | ||
| - | fdig = " | ||
| - | bcd = () | ||
| - | for i in (8, 6, 4, 2, 0): | ||
| - | bcd += self.freq_bcd(int(fdig[i]), | ||
| - | set_freq_val = "" | ||
| - | for byte in bcd: | ||
| - | set_freq_val += chr(byte) | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_freq_cmd + set_freq_val + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return "Set Freq success" | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received / Freq not supported" | ||
| - | |||
| - | def get_freq(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + get_freq_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | if len(result) > 0: | ||
| - | f = 0 | ||
| - | for k in [18, 19, 16, 17, 14, 15, 12, 13, 11, 10]: | ||
| - | f = 10 * f + self.nib(result, | ||
| - | self.freq = (float(f) / 1000) | ||
| - | return " | ||
| - | |||
| - | def set_mode(self, | ||
| - | print "in set_mode() with ", mode | ||
| - | if mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | elif mode == " | ||
| - | set_mode_val = " | ||
| - | else: | ||
| - | return "Mode not recognized" | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + set_mode_cmd + set_mode_val + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if result[4] == ack: | ||
| - | return "Set Mode Success" | ||
| - | elif result[4] == nak: | ||
| - | return "NAK received / Mode not supported" | ||
| - | |||
| - | def get_mode(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + get_mode_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | mode = "" | ||
| - | if result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | elif result[5] == " | ||
| - | mode = " | ||
| - | self.mode = mode | ||
| - | return self.mode.upper() | ||
| - | |||
| - | def get_s(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + get_smeter_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | sm1 = ord(result[7]) / 16 | ||
| - | sm2 = ord(result[7]) % 16 | ||
| - | sm3 = ord(result[6]) / 16 | ||
| - | sm4 = ord(result[6]) % 16 | ||
| - | s = float(100 * (10 * sm3 + sm4) + (10 * sm1 + sm2)) | ||
| - | return s | ||
| - | | ||
| - | def get_swr(self): | ||
| - | sendStr = preamble + preamble + self.radio_address + controller + get_swr_cmd + eom | ||
| - | result = self.tx_rx(sendStr) | ||
| - | if not result: | ||
| - | return " | ||
| - | sm1 = ord(result[7]) / 16 | ||
| - | sm2 = ord(result[7]) % 16 | ||
| - | sm3 = ord(result[6]) / 16 | ||
| - | sm4 = ord(result[6]) % 16 | ||
| - | swr = float(100 * (10 * sm3 + sm4) + (10 * sm1 + sm2)) | ||
| - | return swr | ||
| - | |||
| - | def get_smeter(self): | ||
| - | s = float(self.get_s()) | ||
| - | cal = self.cal | ||
| - | s1 = s - cal[0] | ||
| - | s2 = s1 - cal[1] | ||
| - | s3 = s2 - cal[2] | ||
| - | s4 = s3 - cal[3] | ||
| - | s5 = s4 - cal[4] | ||
| - | s6 = s5 - cal[5] | ||
| - | s7 = s6 - cal[6] | ||
| - | if s1 <= 0: | ||
| - | dbm = -123 | ||
| - | adj = s / cal[0] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s2 <= 0: | ||
| - | dbm = -113 | ||
| - | adj = s1 / cal[1] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s3 <= 0: | ||
| - | dbm = -103 | ||
| - | adj = s2 / cal[2] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s4 <= 0: | ||
| - | dbm = -93 | ||
| - | adj = s3 / cal[3] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s5 <= 0: | ||
| - | dbm = -83 | ||
| - | adj = s4 / cal[4] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s6 <= 0: | ||
| - | dbm = -73 | ||
| - | adj = s5 / cal[5] * 10 | ||
| - | return str(dbm + adj) | ||
| - | elif s7 <= 0: | ||
| - | dbm = -63 | ||
| - | adj = s6 / cal[6] * 20 | ||
| - | return str(dbm + adj) | ||
| - | else: | ||
| - | dbm = -43 | ||
| - | adj = s7 / cal[7] * 20 | ||
| - | return str(dbm + adj) | ||
| - | |||
| - | def get_name(self): | ||
| - | return self.model | ||
| - | |||
| - | def tune(self): | ||
| - | print " | ||
| - | curmode = self.get_mode().lower() | ||
| - | #print " | ||
| - | |||
| - | curpwr = self.get_pwr() | ||
| - | if curpwr < 98: | ||
| - | curpwr = curpwr + 1 | ||
| - | |||
| - | #print " | ||
| - | | ||
| - | #print " | ||
| - | self.set_mode(" | ||
| - | self.set_pwr(25) | ||
| - | #print " | ||
| - | #print "PTT On" | ||
| - | self.ptt_on() | ||
| - | time.sleep(2) | ||
| - | swr = self.get_swr() | ||
| - | #print "SWR :", swr | ||
| - | time.sleep(1) | ||
| - | self.ptt_off() | ||
| - | #print "PTT Off" | ||
| - | self.set_mode(curmode) | ||
| - | #print "Mode reset ", | ||
| - | self.set_pwr(curpwr) | ||
| - | print "Tuned : (ref pwr : %s)" % swr | ||
| - | return "Tuned : (ref pwr : %s)" % swr | ||
| - | | ||
| - | def tx_rx(self, sendStr): | ||
| - | lock.acquire() | ||
| - | self.ser.write(sendStr) | ||
| - | echo = self.ser.read(len(sendStr)) | ||
| - | if len(echo) != len(sendStr): | ||
| - | return " | ||
| - | byte = " | ||
| - | result = "" | ||
| - | count = 0 | ||
| - | while byte != eom: | ||
| - | byte = self.ser.read() | ||
| - | #print " | ||
| - | result += byte | ||
| - | count += 1 | ||
| - | if count > 10: | ||
| - | break | ||
| - | lock.release() | ||
| - | #print "" | ||
| - | return result | ||
| - | |||
| - | |||
| - | def nib(self, s, i): | ||
| - | k = ord(s[i / 2]) | ||
| - | if i % 2 == 0: | ||
| - | k = k >> 4 | ||
| - | return k & 0xf | ||
| - | |||
| - | |||
| - | def freq_bcd(self, | ||
| - | return (16 * d1 + d2), | ||
| - | |||
| - | </ | ||
| - | |||
| - | ++++ | ||
| - | |||
| - | ==== conf.py ==== | ||
| - | |||
| - | ++++ Code .... | | ||
| - | |||
| - | <code python> | ||
| - | # header | ||
| - | preamble = " | ||
| - | controller = " | ||
| - | |||
| - | # commands/ | ||
| - | set_freq_cmd = " | ||
| - | set_mode_cmd = " | ||
| - | get_freq_cmd = " | ||
| - | get_mode_cmd = " | ||
| - | get_smeter_cmd = " | ||
| - | get_swr_cmd = " | ||
| - | digi_off_cmd = " | ||
| - | |||
| - | set_pre_cmd = " | ||
| - | |||
| - | set_pre_off = " | ||
| - | set_pre_on = " | ||
| - | |||
| - | set_att_cmd = " | ||
| - | set_att_on = " | ||
| - | set_att_off = " | ||
| - | |||
| - | ptt_on_cmd = " | ||
| - | ptt_off_cmd = " | ||
| - | |||
| - | pwr_cmd = " | ||
| - | |||
| - | # end of message | ||
| - | eom = " | ||
| - | |||
| - | # controller responses | ||
| - | ack = " | ||
| - | nak = " | ||
| - | |||
| - | a1 = " | ||
| - | n1 = " | ||
| - | cal1 = ( 25, 1, 36, 47, 31, 18, 34, 35 ) | ||
| - | |||
| - | a2 = " | ||
| - | # a2 = " | ||
| - | n2 = " | ||
| - | cal2 = ( 27, 28, 58, 10, 14, 14, 35, 42 ) | ||
| - | |||
| - | n3 = " | ||
| - | |||
| - | n4 = " | ||
| - | </ | ||
| - | |||
| - | ++++ | ||
| - | |||
| - | |||
| - | ==== client.py ==== | ||
| - | |||
| - | ++++ Code .... | | ||
| - | |||
| - | <code python> | ||
| - | __author__ = ' | ||
| - | # client to work with server_oo.py | ||
| - | # | ||
| - | |||
| - | # # v0.1 | ||
| - | |||
| - | import socket | ||
| - | |||
| - | try: | ||
| - | import readline | ||
| - | except ImportError: | ||
| - | pass | ||
| - | |||
| - | import threading | ||
| - | import time | ||
| - | |||
| - | |||
| - | HOST, PORT = " | ||
| - | |||
| - | smlog = " | ||
| - | log_active = [] | ||
| - | |||
| - | |||
| - | def make_con(): | ||
| - | global sock | ||
| - | sock = socket.socket(socket.AF_INET, | ||
| - | sock.connect((HOST, | ||
| - | |||
| - | |||
| - | def get_rnum(): | ||
| - | global num | ||
| - | global radios | ||
| - | |||
| - | names = connect(" | ||
| - | |||
| - | radios = names.split() | ||
| - | num = len(radios) | ||
| - | return num | ||
| - | |||
| - | |||
| - | def get_rname(i): | ||
| - | r = radios[i] | ||
| - | return r | ||
| - | |||
| - | |||
| - | def list_radios(): | ||
| - | num = get_rnum() | ||
| - | global radio | ||
| - | print " | ||
| - | for i in range(0, num): | ||
| - | r = get_rname(i) | ||
| - | print "Radio %d is %s" % (i + 1, r) | ||
| - | |||
| - | |||
| - | def get_lradio(): | ||
| - | num = get_rnum() | ||
| - | |||
| - | lradio = raw_input(" | ||
| - | |||
| - | if not lradio: | ||
| - | print " | ||
| - | return False | ||
| - | elif int(lradio) > num: | ||
| - | print " | ||
| - | return False | ||
| - | |||
| - | else: | ||
| - | |||
| - | return lradio | ||
| - | |||
| - | |||
| - | def set_radio(): | ||
| - | num = get_rnum() | ||
| - | # global radio | ||
| - | global radio_num | ||
| - | global rname | ||
| - | print "There are currently %d radios connected." | ||
| - | for i in range(0, num): | ||
| - | r = get_rname(i) | ||
| - | print "Radio %d is %s" % (i + 1, r) | ||
| - | |||
| - | radio = raw_input(" | ||
| - | try: | ||
| - | if not radio: | ||
| - | print " | ||
| - | return False, False | ||
| - | |||
| - | elif int(radio) > num: | ||
| - | print " | ||
| - | return False, False | ||
| - | except ValueError: | ||
| - | print " | ||
| - | return False, False | ||
| - | |||
| - | else: | ||
| - | radio_num = "" | ||
| - | rname = get_rname(int(radio) - 1) | ||
| - | return radio_num, rname | ||
| - | |||
| - | |||
| - | def prompt(): | ||
| - | print "" | ||
| - | print "The available commands are:" | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print "poff : Set Pre-amp Off" | ||
| - | print "gatt : Get Attn" | ||
| - | print "aton : Set Attn On" | ||
| - | print " | ||
| - | print " | ||
| - | print "sync : Sync freq/mode on two radios" | ||
| - | print " | ||
| - | print " | ||
| - | print " | ||
| - | print "" | ||
| - | |||
| - | |||
| - | def start(): | ||
| - | global radio_num | ||
| - | global rname | ||
| - | global sock | ||
| - | |||
| - | data = raw_input(rname + " > " | ||
| - | if len(data.split()) > 1: | ||
| - | print "only one command at a time please" | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | list_radios() | ||
| - | start() | ||
| - | elif data == " | ||
| - | |||
| - | radio_num, rname = set_radio() | ||
| - | |||
| - | while not radio_num: | ||
| - | radio_num, rname = set_radio() | ||
| - | |||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | print "Radio selected is %s" % rname | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | mode = connect(" | ||
| - | print "%s replied: %s" % (rname, mode) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | smode = raw_input(" | ||
| - | mode = connect(" | ||
| - | print "%s replied: %s" % (rname, mode) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | freq = connect(" | ||
| - | print "%s replied: %s kHz" % (rname, freq) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | sfreq = raw_input(" | ||
| - | freq = connect(" | ||
| - | print "%s replied: %s" % (rname, freq) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | smeter = connect(" | ||
| - | print "%s replied: %sdBm" % (rname, smeter) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | preamp = connect(" | ||
| - | print "%s replied: %s" % (rname, preamp) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | preamp = connect(" | ||
| - | print "%s replied: %s" % (rname, preamp) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | preamp = connect(" | ||
| - | print "%s replied: %s" % (rname, preamp) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | preamp = connect(" | ||
| - | print "%s replied: %s" % (rname, preamp) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | att = connect(" | ||
| - | print "%s replied: %s" % (rname, att) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | att = connect(" | ||
| - | print "%s replied: %s" % (rname, att) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | get_all() | ||
| - | start() | ||
| - | |||
| - | |||
| - | elif data == " | ||
| - | fname = raw_input(" | ||
| - | if fname == "": | ||
| - | fname = smlog | ||
| - | # check file is valid | ||
| - | try: | ||
| - | f = open(fname, ' | ||
| - | f.close() | ||
| - | except IOError: | ||
| - | print " | ||
| - | start() | ||
| - | |||
| - | list_radios() | ||
| - | |||
| - | lradio = get_lradio() | ||
| - | |||
| - | while not lradio: | ||
| - | lradio = get_lradio() | ||
| - | |||
| - | rname = get_rname(int(lradio) - 1) | ||
| - | if lradio in log_active: | ||
| - | print " | ||
| - | else: | ||
| - | tlog = int(raw_input(" | ||
| - | p = threading.Thread(target=log, | ||
| - | p.setDaemon(True) | ||
| - | p.start() | ||
| - | log_active.append(lradio) | ||
| - | start() | ||
| - | |||
| - | elif data == " | ||
| - | sync_result = sync() | ||
| - | print sync_result | ||
| - | start() | ||
| - | |||
| - | |||
| - | elif data == " | ||
| - | prompt() | ||
| - | start() | ||
| - | |||
| - | |||
| - | elif data == " | ||
| - | rx = connect(" | ||
| - | print " | ||
| - | |||
| - | else: | ||
| - | prompt() | ||
| - | start() | ||
| - | |||
| - | |||
| - | def get_all(): | ||
| - | num = get_rnum() | ||
| - | global radio | ||
| - | print "There are currently %d radios connected." | ||
| - | print " | ||
| - | for i in range(0, num): | ||
| - | r = get_rname(i) | ||
| - | n = "" | ||
| - | freq = connect(" | ||
| - | mode = connect(" | ||
| - | smeter = connect(" | ||
| - | preamp = connect(" | ||
| - | att = connect(" | ||
| - | |||
| - | print " | ||
| - | print " | ||
| - | print "Mode: %s" % mode | ||
| - | print " | ||
| - | print "%s : %s " % (preamp, att) | ||
| - | print " | ||
| - | |||
| - | print "" | ||
| - | |||
| - | |||
| - | def log(p, t, f): | ||
| - | print " | ||
| - | tlog = t | ||
| - | sradio = get_rname(int(p) - 1) | ||
| - | |||
| - | sr = "" | ||
| - | while True: | ||
| - | try: | ||
| - | frequency = connect(" | ||
| - | smeter = connect(" | ||
| - | mode = connect(" | ||
| - | write_file(f, | ||
| - | time.sleep(tlog) | ||
| - | finally: | ||
| - | pass | ||
| - | |||
| - | |||
| - | def get_mradio(): | ||
| - | num = get_rnum() | ||
| - | |||
| - | mradio = raw_input(" | ||
| - | |||
| - | if not mradio: | ||
| - | print " | ||
| - | return False | ||
| - | elif int(mradio) > num: | ||
| - | print " | ||
| - | return False | ||
| - | |||
| - | else: | ||
| - | |||
| - | return mradio | ||
| - | |||
| - | |||
| - | def get_sradio(): | ||
| - | num = get_rnum() | ||
| - | sradio = raw_input(" | ||
| - | |||
| - | if not sradio: | ||
| - | print " | ||
| - | return False | ||
| - | elif int(sradio) > num: | ||
| - | print " | ||
| - | return False | ||
| - | |||
| - | else: | ||
| - | |||
| - | return sradio | ||
| - | |||
| - | |||
| - | def sync(): | ||
| - | num = get_rnum() | ||
| - | print "" | ||
| - | print "Set SLAVE to the same Frequency and Mode as MASTER.\r\n" | ||
| - | print " | ||
| - | for i in range(0, num): | ||
| - | r = get_rname(i) | ||
| - | print "%d is %s" % (i + 1, r) | ||
| - | |||
| - | mradio = get_mradio() | ||
| - | while not mradio: | ||
| - | mradio = get_mradio() | ||
| - | |||
| - | sradio = get_sradio() | ||
| - | while not sradio: | ||
| - | sradio = get_sradio() | ||
| - | sr = "" | ||
| - | mr = "" | ||
| - | mfreq = connect(" | ||
| - | mmode = connect(" | ||
| - | |||
| - | sfreq = connect(" | ||
| - | smode = connect(" | ||
| - | |||
| - | return (sfreq + " | ||
| - | |||
| - | |||
| - | # Try to send and receive in one-go, to prevent the logging thread and the main prog | ||
| - | # getting the wrong receive data | ||
| - | |||
| - | def connect(data): | ||
| - | try: | ||
| - | lock.acquire() | ||
| - | global sock | ||
| - | sock.sendall(data + " | ||
| - | received = sock.recv(2048) | ||
| - | finally: | ||
| - | lock.release() | ||
| - | |||
| - | return received | ||
| - | |||
| - | |||
| - | def write_file(fname, | ||
| - | filename = fname | ||
| - | f = open(filename, | ||
| - | timenow = time.strftime(" | ||
| - | log = " " | ||
| - | f.write(log) | ||
| - | f.close() | ||
| - | |||
| - | |||
| - | make_con() | ||
| - | |||
| - | lock = threading.Lock() | ||
| - | get_all() | ||
| - | print " | ||
| - | radio_num, rname = set_radio() | ||
| - | while not radio_num: | ||
| - | radio_num, rname = set_radio() | ||
| - | |||
| - | prompt() | ||
| - | start() | ||
| - | |||
| - | </ | ||
| - | |||
| - | ++++ | ||
| - | |||
| - | ==== Page Info ==== | ||
| - | |||
| - | Page created Wed May 25 00:06:01 2022 by John Pumford-Green | ||
| - | |||
| - | Page last updated: ~~LASTMOD~~ | ||
| - | |||
| - | |||
| - | |||
| - | {{tag> | ||
| - | |||
public/radio/radio_database/ic-r75.1683299854.txt.gz · Last modified: (external edit)
