arcs

Amateur Radio Chat Server with a modern interface
git clone git://squid-tech.com/arcs.git
Log | Files | Refs | README

commit b4c6bf198ba2840d01f2548db4196e45db7975dd
parent e7029cc00d1d58387e160d8f1c5eab01d3f7d780
Author: Josh Moore <jxm5210@g.rit.edu>
Date:   Sat, 21 Dec 2019 16:41:48 -0500

Merge pull request #1 from rouyng/master

create docstrings
Diffstat:
Marcs.py | 133++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 75 insertions(+), 58 deletions(-)

diff --git a/arcs.py b/arcs.py @@ -73,11 +73,12 @@ _USERS = {} _PATH = ["WIDE2-2"] -""" -Send command and data to the KISS TNC. -data should be a byte array. -""" + def KISScmd(port, command, data): + """ + Send command and data to the KISS TNC. + data should be a byte array. + """ out = [] out.append(0xC0) @@ -89,20 +90,22 @@ def KISScmd(port, command, data): port.write(bytearray(out)) -""" -Initialize the KISS TNC. -""" + def KISSinit(port): + """ + Initialize the KISS TNC. + """ KISScmd(port, 0x01, [40]) # TX_DELAY KISScmd(port, 0x02, [128]) # P KISScmd(port, 0x03, [3]) # SlotTime KISScmd(port, 0x04, [20]) # TXtail KISScmd(port, 0x05, [0]) # FullDuplex -""" -AX.25-encode a callsign. -""" + def encodecall(call, final): + """ + AX.25-encode a callsign. + """ if "-" not in call: call = call + "-0" cs, ssid = call.split('-') @@ -112,10 +115,11 @@ def encodecall(call, final): encoded_ssid = (int(ssid) << 1) | 0b01100000 | (0b00000001 if final else 0) return encoded_call + [encoded_ssid] -""" -AX.25-decode a callsign. -""" + def decodecall(call): + """ + AX.25-decode a callsign. + """ decodedcall = "" # decode callsign @@ -131,16 +135,18 @@ def decodecall(call): return decodedcall -""" -Pad a callsign for transmission. -""" + def padcall(call): + """ + Pad a callsign for transmission. + """ return call + " "*(9 - len(call)) -""" -Send an AX.25 packet from source to dest. -""" + def AX25send(port, source, dest, path, msg): + """ + Send an AX.25 packet from source to dest. + """ dest_addr = encodecall(dest.upper(), False) src_addr = encodecall(source.upper(), (path is None) or (len(path) == 0)) c_byte = [0x03] # UI frame @@ -166,10 +172,11 @@ def AX25send(port, source, dest, path, msg): KISScmd(port, 0x00, bytearray(packet_escaped)) -""" -Receive a packet from the KISS TNC as a byte array. -""" + def AX25read(port): + """ + Receive a packet from the KISS TNC as a byte array. + """ inpacket = [] write = False @@ -185,10 +192,11 @@ def AX25read(port): if inb == b'\xC0': write = True -""" -Parse a received packet, returning (dest, source, msg). -""" + def AX25parse(packet): + """ + Parse a received packet, returning (dest, source, msg). + """ dest = decodecall(packet[1:8]) source = decodecall(packet[8:15]) @@ -203,32 +211,36 @@ def AX25parse(packet): return (dest, source, msg) -""" -Send a message from one station to another. -""" + def sendMessage(port, source, dest, path, message): + """ + Send a message from one station to another. + """ AX25send(port, source, "CQ", path, ":" + padcall(dest) + ":" + message) -""" -Transmit the server's beacon message, position, and symbol. -""" + def beacon(port): + """ + Transmit the server's beacon message, position, and symbol. + """ print("BEACON") out = "=" + SERV_LAT + SYMBOL[0] + SERV_LONG + SYMBOL[1] + BEACON_MSG AX25send(port, HOST, "APRS", _PATH, out) -""" -Automatically beacon on a set interval. -""" + def beacond(port): + """ + Automatically beacon on a set interval. + """ while True: beacon(port) time.sleep(BEACON_DELAY) -""" -Send the message to all connected users, and disconnect timed-out users. -""" + def relay(port, sender, msg): + """ + Send the message to all connected users, and disconnect timed-out users. + """ # list of users to disconnect timeouts = [] @@ -248,10 +260,11 @@ def relay(port, sender, msg): print("TIMEOUT " + k) _USERS.pop(k) -""" -Respond to /commands sent by users. -""" + def handleCommand(port, user, command): + """ + Respond to /commands sent by users. + """ if "/ping" in command: # keep the user alive _USERS[user] = (int(time.time()), command) @@ -264,10 +277,11 @@ def handleCommand(port, user, command): print("DISCONNECT " + user) _USERS.pop(user) -""" -Parse an igate packet. -""" + def igateParse(msg): + """ + Parse an igate packet. + """ if not ">" in msg or not '::' in msg: return None @@ -281,10 +295,10 @@ def igateParse(msg): return (recip, sender, rmsg) -""" -Main server daemon that receives and routes messages. -""" def serverd(port, textdisplay): + """ + Main server daemon that receives and routes messages. + """ while True: # receive and parse a packet recv = AX25parse(AX25read(port)) @@ -330,12 +344,13 @@ def serverd(port, textdisplay): textdisplay.insert("end", dispmsg) -""" -Main client daemon that handles incoming messages. -This function behaves similarly to the server daemon, but it doesn't -route traffic anywhere. -""" + def clientd(port, textdisplay): + """ + Main client daemon that handles incoming messages. + This function behaves similarly to the server daemon, but it doesn't + route traffic anywhere. + """ while True: # receive and parse a packet recv = AX25parse(AX25read(port)) @@ -361,20 +376,21 @@ def clientd(port, textdisplay): textdisplay.insert("end", dispmsg) -""" -Automatically keep the client alive by periodically sending /ping commands -to the server. -""" + def alived(port): + """ + Automatically keep the client alive by periodically sending /ping commands + to the server. + """ while True: time.sleep(ALIVED_DELAY) sendMessage(port, MYCALL, HOST, _PATH, "/ping") -""" -Send a chat message from the GUI, and clear the text box. -""" def chatGuiSend(port, disp, entryText): + """ + Send a chat message from the GUI, and clear the text box. + """ msg = entryText.get() disp.insert("end", padcall(MYCALL) + ": " + msg) @@ -387,6 +403,7 @@ def chatGuiSend(port, disp, entryText): entryText.set("") + def main(): global _SERVER global _DEBUG