def do_send(self, arg):
     "form an send a packet with all custom data\n Usage: send then follow prompts\nType -cancel to cancel"
     if self.callsign == None:
         print("Set your callsign with 'callsign <callsign>'")
     else:
         dest, digi, info = "", "", ""
         print(
             "Enter Destination, leaving blank is accpetable\n ex: 'KN6EVU'"
         )
         dest = input(">> ")
         if dest.lower() == "-cancel":
             print("Canceled")
             return
         print(
             "Enter Digipeaters, leaving blank is accpetable\n ex: 'WIDE1-1,WIDE2-1'"
         )
         digi = input(">> ")
         if digi.lower() == "-cancel":
             print("Canceled")
             return
         while info == "":
             print(
                 "Enter Packet Info, leaving blank is NOT accpetable\n ex: ':EMAIL :[email protected] Test email'"
             )
             info = input(">> ")
         if info == "-cancel":
             print("Canceled")
         else:
             print("Dest: %s | Source: %s | Digis: %s | %s |" %
                   (dest, self.callsign, digi, info))
             pack_data = packet.gen_packet(self.callsign.encode(),
                                           dest.encode(), digi.encode(),
                                           info.encode())
             audio = afsk.encode(pack_data.unparse())
             audiogen.play(audio, blocking=True)
예제 #2
0
파일: ax25.py 프로젝트: qbit/afsk
def main(arguments=None):
    parser = argparse.ArgumentParser(description="")
    parser.add_argument("-c", "--callsign", required=True, help="Your ham callsign. REQUIRED.")
    parser.add_argument("info", metavar="INFO", help="APRS message body")
    parser.add_argument(
        "--destination", default=b"APRS", help="AX.25 destination address. See http://www.aprs.org/aprs11/tocalls.txt"
    )
    parser.add_argument(
        "-d", "--digipeaters", default=b"WIDE1-1,WIDE2-1", help="Comma separated list of digipeaters to address."
    )
    parser.add_argument("-o", "--output", default=None, help="Write audio to wav file. Use '-' for stdout.")
    parser.add_argument("-v", "--verbose", action="count", help="Print more debugging output.")
    args = parser.parse_args(args=arguments)

    if args.verbose == 0:
        logging.basicConfig(level=logging.INFO)
    elif args.verbose >= 1:
        logging.basicConfig(level=logging.DEBUG)

    packet = UI(
        destination=args.destination, source=args.callsign, info=args.info, digipeaters=args.digipeaters.split(b",")
    )

    print("Sending packet: '{0}'".format(packet))
    logger.debug(r"Packet bits:\n{0!r}".format(packet.unparse()))

    audio = afsk.encode(packet.unparse())

    if args.output == "-":
        audiogen.sampler.write_wav(sys.stdout, audio)
    elif args.output is not None:
        with open(args.output, "wb") as f:
            audiogen.sampler.write_wav(f, audio)
    else:
        audiogen.sampler.play(audio, blocking=True)
예제 #3
0
def main(arguments=None):
    parser = argparse.ArgumentParser(description='')
    parser.add_argument('-c',
                        '--callsign',
                        required=True,
                        help='Your ham callsign. REQUIRED.')
    parser.add_argument('info', metavar='INFO', help='APRS message body')
    parser.add_argument(
        '--destination',
        default=b'APRS',
        help=
        'AX.25 destination address. See http://www.aprs.org/aprs11/tocalls.txt'
    )
    parser.add_argument(
        '-d',
        '--digipeaters',
        '--path',
        default=b'WIDE1-1,WIDE2-1',
        help=
        'Digipeater path to use. "New Paradigm" recommendations are "WIDE1-1,WIDE2-1" for mobile and "WIDE2-1" for fixed stations. Defaults to "WIDE1-1,WIDE2-1."'
    )
    parser.add_argument('-o',
                        '--output',
                        default=None,
                        help='Write audio to wav file. Use \'-\' for stdout.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Print more debugging output.')
    args = parser.parse_args(args=arguments)

    if args.verbose == 0:
        logging.basicConfig(level=logging.INFO)
    elif args.verbose >= 1:
        logging.basicConfig(level=logging.DEBUG)

    packet = UI(
        destination=args.destination,
        source=args.callsign,
        info=args.info,
        digipeaters=args.digipeaters.split(b','),
    )

    logger.info(r"Sending packet: '{0}'".format(packet))
    logger.debug(r"Packet bits:\n{0!r}".format(packet.unparse()))

    audio = afsk.encode(packet.unparse())

    if args.output == '-':
        audiogen.sampler.write_wav(sys.stdout, audio)
    elif args.output is not None:
        with open(args.output, 'wb') as f:
            audiogen.sampler.write_wav(f, audio)
    else:
        audiogen.sampler.play(audio, blocking=True)
예제 #4
0
파일: aprs.py 프로젝트: mfhepp/stratosphere
def send_aprs(aprs_info, frequency=config.APRS_FREQUENCY,
              ssid=config.APRS_SSID, aprs_path=config.APRS_PATH,
              aprs_destination=b'APRS', full_power=False):
    """Transmits the given APRS message via the DRA818 transceiver.

    Args:
        aprs_info (str): The actual APRS payload.
        frequency (float): The frequency in MHz. Must be a multiple of
        25 KHz and within the allowed ham radio band allocation.
        ssid (str): The APRS SSID (e.g. 'CALLSIGN-7')
        aprs_path (str): The APRS path.
        aprs_destination (str): The APRS destination. Needed for telemetry
        definitions, since they have to be addressed to the SSID of the
        sender of the telemetry data packages.
        full_power (boolean): True sets the RF power level to the
        maximum of 1 W, False sets it to 0.5W.

    Returns:
        True: Transmission successful.
        False: Transmission failed.
    """

    try:
        # See https://github.com/casebeer/afsk
        packet = afsk.ax25.UI(
            destination=aprs_destination,
            source=ssid,
            info=aprs_info,
            digipeaters=aprs_path.split(b','))
        logging.info(r"APRS packet content: '{0}'".format(packet))
        # fn = os.path.join(config.USB_DIR, 'aprs.wav')
#TODO
        fn = '/home/pi/aprs.wav'
        logging.info('Now generating file %s for APRS packet.' % fn)
        audio = afsk.encode(packet.unparse())
        with open(fn, 'wb') as f:
            audiogen.sampler.write_wav(f, audio)
        # TODO: It would be better to play the APRS directly from memory,
        # but setting up PyAudio on Raspbian did not work.
        # So we take the USB stick instead of the SDCARD in order to
        # minimize wear-off on the latter.
        # The downside is that failure of the USB stick will break
        # APRS completely.
        if not os.path.exists(fn):
            logging.error('Error: Problem generating APRS wav file.')
            return False
        logging.info('Sending APRS packet from %s via %s [%f MHz]' % (
            ssid, aprs_path, frequency))
        # When converting APRS string to audio using Bell 202, mind the
        # pre-emphasis problems, see pre-emphasis settings, see also
        # http://www.febo.com/packet/layer-one/transmit.html
        # but this is already done:
        # transceiver.set_filters(pre_emphasis=config.PRE_EMPHASIS)
        # TODO: Think about software-based volume / modulation control
        # maybe using ALSA via Python wrapper, see e.g.
        # http://larsimmisch.github.io/pyalsaaudio/pyalsaaudio.html#alsa-and-python
        # Also see
        # http://www.forum-raspberrypi.de/Thread-suche-python-befehl-fuer-den-alsa-amixer
        attempts = 0
        while attempts < 3:
            try:
                transceiver = dra818.DRA818(
                    uart=config.SERIAL_PORT_TRANSCEIVER,
                    ptt_pin=config.DRA818_PTT,
                    power_down_pin=config.DRA818_PD,
                    rf_power_level_pin=config.DRA818_HL,
                    frequency=frequency,
                    squelch_level=config.SQUELCH)
                break
            except dra818.DRA818_Error:
                attempts += 1
                logging.warning(
                    'Warning: Problem setting up transceiver, retrying.')
        attempts = 0
        while attempts < 3:
            status = transceiver.transmit_audio_file(
                frequency, [fn], full_power=full_power)
            if status:
                break
            else:
                attempts += 1
        try:
            os.remove(fn)
        except OSError:
            pass
    except Exception as msg:
        logging.exception(msg)
    finally:
        transceiver.stop_transmitter()
    return status
예제 #5
0
파일: aprs.py 프로젝트: mfhepp/stratosphere
def send_aprs(aprs_info,
              frequency=config.APRS_FREQUENCY,
              ssid=config.APRS_SSID,
              aprs_path=config.APRS_PATH,
              aprs_destination=b'APRS',
              full_power=False):
    """Transmits the given APRS message via the DRA818 transceiver.

    Args:
        aprs_info (str): The actual APRS payload.
        frequency (float): The frequency in MHz. Must be a multiple of
        25 KHz and within the allowed ham radio band allocation.
        ssid (str): The APRS SSID (e.g. 'CALLSIGN-7')
        aprs_path (str): The APRS path.
        aprs_destination (str): The APRS destination. Needed for telemetry
        definitions, since they have to be addressed to the SSID of the
        sender of the telemetry data packages.
        full_power (boolean): True sets the RF power level to the
        maximum of 1 W, False sets it to 0.5W.

    Returns:
        True: Transmission successful.
        False: Transmission failed.
    """

    try:
        # See https://github.com/casebeer/afsk
        packet = afsk.ax25.UI(destination=aprs_destination,
                              source=ssid,
                              info=aprs_info,
                              digipeaters=aprs_path.split(b','))
        logging.info(r"APRS packet content: '{0}'".format(packet))
        # fn = os.path.join(config.USB_DIR, 'aprs.wav')
        #TODO
        fn = '/home/pi/aprs.wav'
        logging.info('Now generating file %s for APRS packet.' % fn)
        audio = afsk.encode(packet.unparse())
        with open(fn, 'wb') as f:
            audiogen.sampler.write_wav(f, audio)
        # TODO: It would be better to play the APRS directly from memory,
        # but setting up PyAudio on Raspbian did not work.
        # So we take the USB stick instead of the SDCARD in order to
        # minimize wear-off on the latter.
        # The downside is that failure of the USB stick will break
        # APRS completely.
        if not os.path.exists(fn):
            logging.error('Error: Problem generating APRS wav file.')
            return False
        logging.info('Sending APRS packet from %s via %s [%f MHz]' %
                     (ssid, aprs_path, frequency))
        # When converting APRS string to audio using Bell 202, mind the
        # pre-emphasis problems, see pre-emphasis settings, see also
        # http://www.febo.com/packet/layer-one/transmit.html
        # but this is already done:
        # transceiver.set_filters(pre_emphasis=config.PRE_EMPHASIS)
        # TODO: Think about software-based volume / modulation control
        # maybe using ALSA via Python wrapper, see e.g.
        # http://larsimmisch.github.io/pyalsaaudio/pyalsaaudio.html#alsa-and-python
        # Also see
        # http://www.forum-raspberrypi.de/Thread-suche-python-befehl-fuer-den-alsa-amixer
        attempts = 0
        while attempts < 3:
            try:
                transceiver = dra818.DRA818(
                    uart=config.SERIAL_PORT_TRANSCEIVER,
                    ptt_pin=config.DRA818_PTT,
                    power_down_pin=config.DRA818_PD,
                    rf_power_level_pin=config.DRA818_HL,
                    frequency=frequency,
                    squelch_level=config.SQUELCH)
                break
            except dra818.DRA818_Error:
                attempts += 1
                logging.warning(
                    'Warning: Problem setting up transceiver, retrying.')
        attempts = 0
        while attempts < 3:
            status = transceiver.transmit_audio_file(frequency, [fn],
                                                     full_power=full_power)
            if status:
                break
            else:
                attempts += 1
        try:
            os.remove(fn)
        except OSError:
            pass
    except Exception as msg:
        logging.exception(msg)
    finally:
        transceiver.stop_transmitter()
    return status
예제 #6
0
파일: ax25.py 프로젝트: casebeer/afsk
def main(arguments=None):
	parser = argparse.ArgumentParser(description='')
	parser.add_argument(
		'-c',
		'--callsign', 
		required=True,
		help='Your ham callsign. REQUIRED.'
	)
	parser.add_argument(
		'info', 
		metavar='INFO',
		help='APRS message body'
	)
	parser.add_argument(
		'--destination',
		default=b'APRS',
		help='AX.25 destination address. See http://www.aprs.org/aprs11/tocalls.txt'
	)
	parser.add_argument(
		'-d',
		'--digipeaters',
		'--path',
		default=b'WIDE1-1,WIDE2-1',
		help='Digipeater path to use. "New Paradigm" recommendations are "WIDE1-1,WIDE2-1" for mobile and "WIDE2-1" for fixed stations. Defaults to "WIDE1-1,WIDE2-1."'
	)
	parser.add_argument(
		'-o',
		'--output', 
		default=None,
		help='Write audio to wav file. Use \'-\' for stdout.'
	)
	parser.add_argument(
		'-v',
		'--verbose',
		action='count',
		help='Print more debugging output.'
	)
	args = parser.parse_args(args=arguments)

	if args.verbose == 0:
		logging.basicConfig(level=logging.INFO)
	elif args.verbose >=1:
		logging.basicConfig(level=logging.DEBUG)

	packet = UI(
		destination=args.destination,
		source=args.callsign, 
		info=args.info,
		digipeaters=args.digipeaters.split(b','),
	)

	logger.info(r"Sending packet: '{0}'".format(packet))
	logger.debug(r"Packet bits:\n{0!r}".format(packet.unparse()))

	audio = afsk.encode(packet.unparse())

	if args.output == '-':
		audiogen.sampler.write_wav(sys.stdout, audio)
	elif args.output is not None:
		with open(args.output, 'wb') as f:
			audiogen.sampler.write_wav(f, audio)
	else:
		audiogen.sampler.play(audio, blocking=True)
#   test_send.py
#       sends a test packet
#--------------------------------------------------------------------------
#
# --------------------------------------------------------------------------
# Imports

import afsk
import packet
import audiogen
import time

# --------------------------------------------------------------------------

dest = b"QSAT"
callsign = b"KN6EVU"
digi = b""

for i in range(5):

    info = b"Testing packet: Sending packet %b" % (str(i).encode())

    print(("Dest: %s | Source: %s | Digis: %s | %s |" %
           (dest.decode(), callsign.decode(), digi.decode(), info.decode())))

    pack_data = packet.gen_packet(callsign, dest, digi, info)

    audio = afsk.encode(pack_data.unparse())
    audiogen.play(audio, blocking=True)
    time.sleep(.5)