log.warn("Failed to send request.") else: log.warn("'%s' path doesn't exist." % send) else: log.info("Help: Type \"tx\" to transmit a file or \"rx\" to receive a file.") except KeyboardInterrupt: break except Exception, ex: log.fatal(ex) log.info("Cleaning up...") ddp.dispose() ddp = None log.info("Exiting...") sys.exit(0) def readInput(): return sys.stdin.readline().replace("\r", "").replace("\n", "") def xmlFTSettingsRead(): global ALLOW_UNSIGNED_PACKETS, BACKEND_DATAMODE, BACKEND_HOSTNAME, BACKEND_PORT, DEBUG_MODE, DISABLE_CRYPTO, SPECIFICATION, USE_TCP if os.path.exists(XML_SETTINGS_FILE): xmldoc = minidom.parse(XML_SETTINGS_FILE)
else: log.warn("Failed to pass the packet on to DDP.") client.sendall("HTTP/1.1 404 Not Found\n\n<html>Failed to transmit the packet via DDP.</html>\n\n") # Get the connection closed break else: break except Exception, ex: log.fatal(ex) log.info("Closed connection from %s:%d." % (address[0], address[1])) client.close() def listenerTCPSub(): global listener_tcp, listener_tcp_alive while listener_tcp_alive: try: client, address = listener_tcp.accept() log.info("Accepted connection from %s:%d." % (address[0], address[1])) listenerTCPHandler(client, address) except Exception, ex:
class Rig(): def __init__(self, id, hostname = "localhost", port = 7362, data_mode = "PSK500R", carrier_frequency = 1000, sideband = "USB", retries = 3, data_length = 128, tx_wait = 0.5, rx_wait = 0.1, timeout = 10., ack_timeout = 0.25, tx_hangtime = 0.25, specification = 0, extension_init = None, disable_ec = False, disable_crypto = True, allow_unsigned_packets = True, application = "DDP Example: Repeater", ignore_broadcast_packets = True, repeater_mode = True, debug_mode = False): self.DEBUG_MODE = debug_mode self.ID = int(id) self.ddp = DDP(hostname, port, data_mode, carrier_frequency, sideband, retries, data_length, tx_wait, rx_wait, timeout, ack_timeout, tx_hangtime, specification, extension_init, disable_ec, disable_crypto, allow_unsigned_packets, application, ignore_broadcast_packets, repeater_mode, debug_mode) self.linked_rig = None self.main_thread = None self.run_queue = True self.log = DanLog("RIG%d" % self.ID) self.log.info("Initialising...") def dispose(self): if self.DEBUG_MODE: self.log.info("Running...") self.ddp.dispose() def mainLoop(self): if self.DEBUG_MODE: self.log.info("Running...") while self.run_queue: packet = self.receivePacket(120.) if packet is not None: # Reconstruct the packet so it can be transmitted to the linked rig lr_ddp = self.linked_rig.ddp recon = lr_ddp.constructPacket(packet[lr_ddp.SECTION_SOURCE], REPEATER_CALLSIGN, packet[lr_ddp.SECTION_DESTINATION], packet[lr_ddp.SECTION_FLAGS], self.ddp.decodeData(packet[lr_ddp.SECTION_DATA], packet[lr_ddp.SECTION_FLAGS]), packet[lr_ddp.SECTION_APPLICATION_ID], packet[lr_ddp.SECTION_SIGNATURE]) # Re-transmit the packet self.transmitPacket(recon) def receivePacket(self, timeout = 60.): if self.DEBUG_MODE: self.log.info("Running...") return self.ddp.receivePacket(timeout) def setCallsign(self, callsign): if self.DEBUG_MODE: self.log.info("Running...") self.ddp.setCallsign(callsign) def setLinkedRig(self, rig): if self.DEBUG_MODE: self.log.info("Running...") self.linked_rig = rig def start(self): if self.DEBUG_MODE: self.log.info("Running...") self.run_queue = True self.main_thread = threading.Thread(target = self.mainLoop) self.main_thread.setDaemon(1) self.main_thread.start() def stop(self): if self.DEBUG_MODE: self.log.info("Running...") self.run_queue = False def transmitPacket(self, packet): if self.DEBUG_MODE: self.log.info("Running...") self.ddp.transmitRawPacket(packet)