Пример #1
0
def init():
    """
    Initialize the main class. This must be called by the main window class once all windows, 
    menus, etc. are created, configured and ready.
    """
    global KOB, Internet, Recorder
    KOB = kob.KOB(port=config.serial_port,
                  interfaceType=config.interface_type,
                  audio=config.sound,
                  callback=from_key)
    Internet = internet.Internet(config.station, callback=from_internet)
    # Let the user know if 'invert key input' is enabled (typically only used for MODEM input)
    if config.invert_key_input:
        log.warn("IMPORTANT! Key input signal invert is enabled (typically only used with a MODEM). " + \
            "To enable/disable this setting use `Configure --iki`.")
    ts = recorder.get_timestamp()
    dt = datetime.fromtimestamp(ts / 1000.0)
    dateTimeStr = str("{:04}{:02}{:02}-{:02}{:02}").format(
        dt.year, dt.month, dt.day, dt.hour, dt.minute)
    targetFileName = "Session-" + dateTimeStr + ".json"
    log.info("Record to '{}'".format(targetFileName))
    Recorder = recorder.Recorder(targetFileName, None, station_id=sender_ID, wire=config.wire, \
        play_code_callback=from_recorder, \
        play_sender_id_callback=ka.trigger_update_current_sender, \
        play_station_list_callback=ka.trigger_update_station_active, \
        play_wire_callback=ka.trigger_player_wire_change)
    kobkeyboard.init()
    # If the configuration indicates that an application should automatically connect -
    # connect to the currently configured wire.
    if config.auto_connect:
        ka.doConnect()  # Suggest a connect.
Пример #2
0
    grpPause = args.grpPause if args.grpPause > 0.0 else args.artPause

    # Number of days (from today) of articles to read before repeating:
    days = args.days

    # The wait time (in seconds) after someone else transmits before resuming feed:
    wait = args.wait

    playback_finished = threading.Event()
    playback_last_sender = None

    mySender = morse.Sender(wpm, cwpm, codeType=code_type)
    myInternet = internet.Internet(idText)
    audio_setting = strtobool(str(args.sound))
    myKOB = kob.KOB(port=args.serial_port,
                    interfaceType=args.interface_type,
                    audio=audio_setting)

    myInternet.connect(wire)

    # create thread to listen for activity on the wire
    tLastSender = time.time()  # time of last activity
    listenerThread = threading.Thread(target=checkForActivity)
    listenerThread.daemon = True
    listenerThread.start()

    # See if the URI is a PyKOB recorder file or a RSS file/feed
    isRecording = False
    # See if the URI is a recording file
    #  There are more effecient ways to do this with Mac/Linux,
    #  but this seems to be needed with Windows.
Пример #3
0
    TIMEOUT = 30.0  # time to send after last indication of live listener (sec)
    TICK = (-1, +1, -200, +1, -200, +2) + 3 * (-200, +2)
    NOTICK = 5 * (-200, +2)
    MARK = (-1, +1) + 9 * (-200, +1) + (-200, +2)

    log.log('Starting Time {0}'.format(VERSION))

    nargs = len(sys.argv)
    mode = sys.argv[1][0] if nargs > 1 else 'c'
    if nargs > 2:
        wire = int(sys.argv[2])
        idText = sys.argv[3]
    else:
        wire = None

    myKOB = kob.KOB(PORT, SOUND)

    if wire:
        myInternet = internet.Internet(idText)
        myInternet.connect(wire)
        time.sleep(1)

        def checkForListener():
            while True:
                myInternet.read(
                )  # activate the reader to get tLastListener updates

        listenerThread = threading.Thread(target=checkForListener)
        listenerThread.daemon = True
        listenerThread.start()
Пример #4
0
    #
    if (args.Interval < 1) or (args.Interval > 1440):
        print("Time announcement interval must be betwen 1 and 1440.")
        sys.exit(1)
    annc_interval = args.Interval * 60  # announcement interval (sec)
    local_text = args.Text

    myRecorder = None
    if (args.Record):
        ts = recorder.get_timestamp()
        targetFileName = "Clock." + str(ts) + ".json"
        myRecorder = recorder.Recorder(targetFileName,
                                       None,
                                       station_id="Clock")

    myKOB = kob.KOB(port=port, audio=sound)
    mySender = morse.Sender(text_speed)

    # Announce the current time right now
    now = time.localtime()
    msg = announcement(now.tm_hour, now.tm_min)
    announce(msg, myKOB, mySender, myRecorder)

    # Loop, making announcements as configured (every hour, on the hour, during the daytime)
    while True:
        t = time.localtime()
        next_time = round_up(hms_to_seconds(t.tm_hour, t.tm_min, t.tm_sec),
                             annc_interval)  # next announcement (sec)
        if next_time < start_time:
            next_time = start_time
        now = hms_to_seconds(t.tm_hour, t.tm_min,
Пример #5
0
        code = mySender.encode(char)
        myKOB.sounder(code)  # to pace the code sent to the wire
        myInternet.write(code)


try:
    if DEBUG:
        print(DEBUG)
        sendForecast(DEBUG)
        exit()

    myInternet = internet.Internet(IDTEXT)
    myInternet.connect(WIRE)
    myReader = morse.Reader(callback=readerCallback)
    mySender = morse.Sender(WPM)
    myKOB = kob.KOB(port=None, audio=False)
    myReader.setWPM(WPM)
    code = []
    bracket = False
    msg = ''
    while True:
        try:
            code += myInternet.read()
            if code[-1] == 1:
                log.log('Weather.py: {}'.format(code))
                myReader.decode(code)
                myReader.flush()
                code = []
                bracket = False
                msg = ''
        except:
Пример #6
0
                    help='file (in MorseKOB recorder format) to be played back.')
    arg_parser.add_argument("--list", action="store_true", default=False, help="Display the recorded data as it is played.", dest="listData")
    arg_parser.add_argument("--speedfactor", type=int, metavar="n", default=100, help="Factor (percentage) to adjust playback speed by (Default 100).", dest="speedFactor")
    arg_parser.add_argument("--maxsilence", type=int, metavar="n", default=5, help="Longest silence duration to play, in seconds. A value of '0' will reproduce all silence as recorded (Defalut 5).", dest="maxSilence")
    args = arg_parser.parse_args()
    
    interface_type = args.interface_type
    port = args.serial_port # serial port for KOB/sounder interface
    sound = strtobool(args.sound)
    sounder = strtobool(args.sounder)
    playback_file = args.playback_file

    # Validate that the file can be opened
    try:
        fp = open(playback_file, 'r')
        fp.close()
    except FileNotFoundError:
        log.err("Recording file not found: {}".format(playback_file))

    myKOB = kob.KOB(port=port, audio=sound, interfaceType=interface_type)

    myRecorder = recorder.Recorder(None, playback_file, play_code_callback=callbackPlay, play_finished_callback=callbackPlayFinished, station_id="Player")
    myRecorder.playback_start(list_data=args.listData, max_silence=args.maxSilence, speed_factor=args.speedFactor)
    # Wait until playback is finished
    while not playback_finished.is_set():
        time.sleep(0.5)
except KeyboardInterrupt:
    print("\nEarly exit.")
    myRecorder.playback_stop()
    sys.exit(0)     # ^C is considered a normal exit.
Пример #7
0
                return  # Stop signalled - return from run method


"""
Test code
"""
if __name__ == "__main__":
    # Self-test
    from pykob import morse

    test_target_filename = "test." + str(get_timestamp()) + ".json"
    myRecorder = Recorder(test_target_filename,
                          test_target_filename,
                          station_id="Test Recorder",
                          wire=-1)
    mySender = morse.Sender(20)

    # 'HI' at 20 wpm as a test
    print("HI")
    codesequence = (-1000, +2, -1000, +60, -60, +60, -60, +60, -60, +60, -180,
                    +60, -60, +60, -1000, +1)
    myRecorder.record(codesequence, kob.CodeSource.local)
    # Append more text to the same file
    for c in "This is a test":
        codesequence = mySender.encode(c, True)
        myRecorder.record(codesequence, kob.CodeSource.local, c)
    print()
    # Play the file
    myKOB = kob.KOB(port=None, audio=True)
    myRecorder.playback(myKOB)
Пример #8
0
IDTEXT = 'Test feed, XX'  # text to identify your feed, with office call
msgs = [  # 24-hour clock, no leading zeros
    (822, '~ DS HN OS +     ~ GA +   ~ OS HN NO 18 D 822 HN +    ~ OK DS +'),
    (1201, '~ DS NB OS +    ~ GA +  ~ OS NB NO 18 BY 1159 NB +   ~ OK DS +'),
    (1528, '~ DS U OS +     ~ GA +   ~ OS U NO 18 BY 239 U +     ~ OK DS +')
]
# last entry ends with )] instead of ),

msgs.sort(key=lambda m: m[0])  # sort messages by time
for i in range(len(msgs) - 1):  # adjust duplicate times
    if msgs[i + 1][0] <= msgs[i][0]:
        msgs[i + 1] = (msgs[i][0] + 1, msgs[i + 1][1])
#for m in msgs:
#    print(m[0], m[1])  # uncomment to display sorted message list

myKOB = kob.KOB(port=PORT, audio=SOUND)
if WIRE:
    myInternet = internet.Internet(IDTEXT)
    myInternet.connect(WIRE)
mySender = morse.Sender(WPM)

try:
    while True:
        for m in msgs:
            t0 = time.localtime()
            now = t0.tm_hour * 3600 + t0.tm_min * 60 + t0.tm_sec  # current time (sec)
            t1, s = m
            tMsg = 3600 * (t1 // 100) + 60 * (t1 % 100)  # time to send message
            dt = tMsg - now  # time to wait
            if dt > 0:
                time.sleep(dt)
Пример #9
0
import sys
from pykob import kob
from pykob import config

try:
    interface = config.serial_port

    myKOB = kob.KOB(port=interface)
    myKOB.setSounder(False)
    while True:
        print(myKOB.key())
except KeyboardInterrupt:
    print()
    print("Thank you for using the Closer-Test!")
    sys.exit(0)     # Indicate this was a normal exit