예제 #1
0
def test():
    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = skibase.args_add_log(parser)
    parser = args_add_dbgled(parser)
    args = parser.parse_args()

    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)

    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])

    # dbgled
    program = 0
    dbgled_obj = dbgled_start(program, args.dbgpin)

    # Loop
    skibase.log_notice("Running DbgPin unittest")
    counter = 0
    while not skibase.signal_counter and dbgled_obj.status():
        dbgled_obj.program = counter
        time.sleep(5)
        counter += 1

    dbgled_obj = dbgled_stop(dbgled_obj)
    skibase.log_notice("DbgPin unittest ended")
예제 #2
0
def test():
    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = skibase.args_add_log(parser)
    parser = args_add_sphat(parser)
    args = parser.parse_args()

    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)

    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])

    # sphat
    program = 0
    sphat_obj = sphat_start(program)

    # Loop
    skibase.log_notice("Running Scroll PHAT unittest")
    counter = 0
    while not skibase.signal_counter and sphat_obj.status():
        sphat_obj.program = counter % 9
        time.sleep(8)
        counter += 1

    sphat_obj = sphat_stop(sphat_obj)
    skibase.log_notice("Scroll PHAT unittest ended")
예제 #3
0
파일: wd.py 프로젝트: nens90/skiPi
def test():
    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = skibase.args_add_log(parser)
    parser = args_add_wd(parser)
    args = parser.parse_args()

    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)

    # Watchdog
    wd_set_handle(args.watchdog)

    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])

    # Expect the main-loop to kick the watchdog again before time runs out.
    wd_kick()

    # Loop
    skibase.log_notice("Running watchdog unittest")
    next_kick = 0
    while not skibase.signal_counter:
        next_kick = wd_check(next_kick)
        skibase.log_info(".", end='')
        time.sleep(0.8)

    skibase.log_notice("\nWatchdog unittest ended...")
예제 #4
0
def loop(main_queue, program_id, kfnet_obj, butt_obj, sphat_obj, ws281x_obj,
         dbgled_obj):
    next_kick = 0
    program_can_change_again = 0

    while not skibase.signal_counter \
      and kfnet_obj.status() \
      and butt_obj.status() \
      and sphat_obj.status() \
      and ws281x_obj.status() \
      and dbgled_obj.status():
        next_kick = wd.wd_check(next_kick)
        try:
            task = main_queue.get(block=True, timeout=LOOP_SPEED)
        except queue.Empty:
            task = None
        if task:
            if task == skibase.TASK_BUTTON_PRESS:
                now = skibase.get_time_millis()
                if now >= program_can_change_again:
                    program_id = get_next_program(program_id)
                    # Add program_id to kfnet as a task that is transmitted
                    # Do not execute task yet, but wait for kfnet to relay
                    # the task back when it is sent. This should make the
                    # network appear more "in sync".
                    kfnet_obj.queue_task(skibase.TASK_PROGRAM + program_id)
                    skibase.log_info("task: press: %s" % \
                      program_id_to_str(program_id))
                    program_can_change_again = now + PROGRAM_CHANGE_BLOCK_MS
                else:
                    skibase.log_info("Ignoring program change.")
            elif task == skibase.TASK_BUTTON_LONG_1:
                skibase.log_info("task: long press")
                ws281x_obj.program = 0xff
                sphat_obj.program = 0xff
                dbgled_obj.program = 0xff
            elif task == skibase.TASK_BUTTON_LONG_2:
                do_shutdown()
                main_queue.task_done()
                break
            elif (task & skibase.MAJOR_TASK) == skibase.TASK_DELAY_MS:
                skibase.log_info("task: delay")
                do_delay_task(task)
            elif (task & skibase.MAJOR_TASK) == skibase.TASK_PROGRAM:
                program_id = get_program_from_task(task)
                ws281x_obj.program = program_id
                sphat_obj.program = program_id
                dbgled_obj.program = program_id
                skibase.log_notice("task: program: %s" % \
                  program_id_to_str(program_id))
            else:
                skibase.log_warning("skipi got unknown task!")
                try:
                    skibase.log_warning("task: %s" % task_to_str(task))
                except:
                    skibase.log_warning("log task failed...")
                    print(task)
            main_queue.task_done()
예제 #5
0
def test():
    skibase.set_time_start()

    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = skibase.args_add_log(parser)
    parser = args_add_kfnet(parser)
    args = parser.parse_args()

    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)

    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])

    # Start queue
    main_queue = queue.Queue()

    # Start kfnet
    kfnet_obj = kfnet_start(main_queue, args.interface, MCAST_GRP,
                            args.ip_addr, args.mcast_port)

    # Loop (main)
    skibase.log_notice("Running Kesselfall network unittest")
    counter = random.randint(0, 0xFF)
    t_next_send = skibase.get_time_millis()
    while not skibase.signal_counter and kfnet_obj.status():
        try:
            task = main_queue.get(block=True, timeout=0.25)
        except queue.Empty:
            task = None
        if task:
            try:
                skibase.log_notice("-> task: %s" % skibase.task_to_str(task))
            except:
                skibase.log_warning("kfnet got unknown task")
            main_queue.task_done()
        if t_next_send < skibase.get_time_millis():
            # Send packet to kfnet task
            # otherwise use kfnet_obj.queue_task(task)
            packet = kfnet_obj.create_packet()
            packet.task = skibase.TASK_PROGRAM + \
                          (counter & skibase.MINOR_TASK)
            kfnet_obj.queue_packet(packet)
            skibase.log_notice("<- Packet: %s :: task: %s" %\
              (packet.id.decode(), task_to_str(packet.task)))
            t_next_send = t_next_send \
                          + random.randint(CHANGE_RATE_MIN, CHANGE_RATE_MAX)
            counter += 1

    kfnet_obj = kfnet_stop(kfnet_obj)
    skibase.log_notice("Kesselfall network unittest ended")
예제 #6
0
def main():
    skibase.set_time_start()

    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = args_add_all(parser)
    args = parser.parse_args()

    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)

    # Watchdog
    wd.wd_set_handle(args.watchdog)

    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])

    # Start queue
    main_queue = queue.Queue()

    # Expect the main-loop to kick the watchdog again before time runs out.
    wd.wd_kick()

    # Start Debug LED
    dbgled_obj = dbgled.dbgled_start(args.start_program, args.dbgpin)
    # Start scroll phat
    sphat_obj = sphat.sphat_start(args.start_program)
    # Start LED strip (WS281x)
    ws281x_obj = ws281x.ws281x_start(args.start_program, args.color)
    # Start the Kesselfall network protocol
    kfnet_obj = kfnet.kfnet_start(main_queue, args.interface, kfnet.MCAST_GRP,
                                  args.ip_addr, args.mcast_port)
    # Start button
    butt_obj = butt.butt_start(main_queue)

    # Run
    skibase.log_notice("Running skipi")
    loop(main_queue, args.start_program, kfnet_obj, butt_obj, sphat_obj,
         ws281x_obj, dbgled_obj)

    # Stop
    skibase.log_notice("Stopping skipi")
    kfnet_obj = kfnet.kfnet_stop(kfnet_obj)
    butt_obj = butt.butt_stop(butt_obj)
    sphat_obj = sphat.sphat_stop(sphat_obj)
    ws281x_obj = ws281x.ws281x_stop(ws281x_obj)
    dbgled_obj = dbgled.dbgled_stop(dbgled_obj)
    # Empty queue and stop
    while main_queue.empty() is False:
        main_queue.get()
        main_queue.task_done()
    skibase.log_notice("\nskipi ended...")
예제 #7
0
파일: butt.py 프로젝트: nens90/skiPi
def test():
    # Arguments
    parser = argparse.ArgumentParser(description=__doc__)
    parser = skibase.args_add_log(parser)
    parser = args_add_butt(parser)
    args = parser.parse_args()
    
    # Parse
    skibase.log_config(args.loglevel.upper(), args.syslog)
    
    # Signal
    skibase.signal_setup([signal.SIGINT, signal.SIGTERM])
    
    # Start queue
    main_queue = queue.Queue()
    
    # Start Butt
    butt_obj = butt_start(main_queue)
    
    # Loop
    skibase.log_notice("Running butt unittest")
    while not skibase.signal_counter and butt_obj.status():
        try:
            task = main_queue.get(block=True, timeout=0.25)
        except queue.Empty:
            task = None
        if task is not None:
            if task == skibase.TASK_BUTTON_PRESS:
                skibase.log_notice("butt press")
            elif task == skibase.TASK_BUTTON_LONG:
                skibase.log_notice("butt long press")
            else:
                skibase.log_warning("butt got unknown task")
        
    # Stop Butt
    butt_stop(butt_obj)

    skibase.log_notice("butt unittest ended")
예제 #8
0
def do_shutdown():
    skibase.log_notice("Calling shutdown")
    cmd = "sudo nohup sh -c 'sleep 5 && shutdown -h now' >/dev/null 2>&1 &"
    subprocess.call(cmd, shell=True)
    wd.wd_kick()  # should work with a sleep and a watchdog kick