示例#1
0
def main():

    # import python's standard time module
    import time

    # import Controller and other blocks from modules
    from pyctrl import Controller
    from pyctrl.block import Printer
    from pyctrl.block.clock import TimerClock

    # initialize controller
    hello = Controller()

    # add the signal myclock
    hello.add_signal('myclock')

    # add a TimerClock as a source
    hello.add_source('myclock', TimerClock(period=1), ['myclock'], enable=True)

    # add a Printer as a sink
    hello.add_sink('message',
                   Printer(message='Hello World!'), ['myclock'],
                   enable=True)

    try:
        # run the controller
        with hello:
            # do nothing for 5 seconds
            time.sleep(5)

    except KeyboardInterrupt:
        pass

    finally:
        print('Done')
示例#2
0
def main():

    # import python's standard time module
    import time

    # import Controller and other blocks from modules
    from pyctrl.client import Controller
    from pyctrl.block import Printer

    # initialize controller
    hello = Controller(host='localhost',
                       port=9999,
                       module='pyctrl.timer',
                       kwargs={'period': 1})

    # add a Printer as a sink
    hello.add_sink('message',
                   Printer(message='Hello World @ {:4.2f}s'), ['clock'],
                   enable=True)

    # print controller information
    print(hello.info('all'))

    try:
        # run the controller
        with hello:
            # do nothing for 5 seconds
            time.sleep(5)

    except KeyboardInterrupt:
        pass
示例#3
0
def main():

    # import python's standard time module
    import time

    # import Controller and other blocks from modules
    from pyctrl import Controller
    from pyctrl.block import Printer, Constant

    # initialize controller
    hello = Controller()

    # add a Printer as a timer
    hello.add_timer('message',
                    Printer(message='Hello World @ {:3.1f} s '), ['clock'],
                    None,
                    period=1,
                    repeat=True)

    # Add a timer to stop the controller
    hello.add_timer('stop',
                    Constant(value=0),
                    None, ['is_running'],
                    period=5,
                    repeat=False)

    # add a Printer as a sink
    hello.add_sink('message',
                   Printer(message='Current time {:5.3f} s', endln='\r'),
                   ['clock'])

    # print controller info
    print(hello.info('all'))

    try:

        # run the controller
        print('> Run the controller.')
        with hello:

            # wait for the controller to finish on its own
            hello.join()

        print('> Done with the controller.')

    except KeyboardInterrupt:
        pass
示例#4
0
def main():

    # import Controller and other blocks from modules
    from pyctrl.timer import Controller
    from pyctrl.block import Interp, Constant, Printer

    # initialize controller
    Ts = 0.1
    hello = Controller(period=Ts)

    # add pwm signal
    hello.add_signal('pwm')

    # build interpolated input signal
    ts = [0, 1, 2, 3, 4, 5, 5, 6]
    us = [0, 0, 100, 100, -50, -50, 0, 0]

    # add filter to interpolate data
    hello.add_filter('input', Interp(xp=us, fp=ts), ['clock'], ['pwm'])

    # add logger
    hello.add_sink(
        'printer',
        Printer(message='time = {:3.1f} s, motor = {:+6.1f} %', endln='\r'),
        ['clock', 'pwm'])

    # Add a timer to stop the controller
    hello.add_timer('stop',
                    Constant(value=0),
                    None, ['is_running'],
                    period=6,
                    repeat=False)

    # print controller info
    print(hello.info('all'))

    try:

        # run the controller
        print('> Run the controller.')
        with hello:

            # wait for the controller to finish on its own
            hello.join()

        print('> Done with the controller.')

    except KeyboardInterrupt:
        pass
示例#5
0
def main():

    # import python's standard time module
    import time

    # import Controller and other blocks from modules
    from pyctrl.timer import Controller
    from pyctrl.block import Printer

    # initialize controller
    hello = Controller(period = 1)

    # add a Printer as a sink
    hello.add_sink('message',
		   Printer(message = 'Hello World @ {:3.1f} s'),
		   ['clock'],
                   enable = True)

    # print controller info
    print(hello.info('all'))
    
    try:
        # run the controller
        print('> Run the controller.')

        print('> Do nothing for 5 s with the controller on...')
        with hello:
	    # do nothing for 5 seconds
            time.sleep(5)

        print('> Do nothing for 2 s with the controller off...')
        time.sleep(2)
        
        print('> Do nothing for 5 s with the controller on...')
        with hello:
	    # do nothing for 5 seconds
            time.sleep(5)
            
        print('> Done with the controller.')

    except KeyboardInterrupt:
        pass
示例#6
0
pilot.add_signal('northspeed')
pilot.add_signal('eastspeed')

pilot.add_signal('aileron')
pilot.add_signal('elevator')
pilot.add_signal('rudder')
pilot.add_signal('throttle')

pilot.add_source('fg_source',
                 FgSource(),
                 ['speed', 'heading', 'altitude', 'climb', 'pitch', 'bank',
                  'engine', 'latitude', 'longitude', 'northspeed', 'eastspeed'],
                 enable = True)

pilot.add_sink('debug_print',
               Printer(message = 'speed: {}, heading: {}'),
               ['speed', 'heading'],
               enable = True)

pilot.add_sink('fg_sender',
               FgSink(),
               ['aileron', 'elevator', 'rudder', 'throttle'],
               enable = True)

try:
    # run the controller
    with pilot:
        # do nothing for 5 seconds
        while True:
            time.sleep(1)
示例#7
0
def main():

    import sys

    # import Controller and other blocks from modules
    from pyctrl.timer import Controller
    from pyctrl.block import Interp, Printer, Constant, Logger

    # initialize controller
    Ts = 0.01
    hello = Controller(period=Ts)

    # add pwm signal
    hello.add_signal('pwm')

    # build interpolated input signal
    ts = [0, 1, 2, 3, 4, 5, 5, 6]
    us = [0, 0, 100, 100, -50, -50, 0, 0]

    # add filter to interpolate data
    hello.add_filter('input', Interp(xp=us, fp=ts), ['clock'], ['pwm'])

    # add logger
    hello.add_sink(
        'printer',
        Printer(message='time = {:3.1f} s, motor = {:+6.1f} %', endln='\r'),
        ['clock', 'pwm'])

    # add logger
    hello.add_sink('logger', Logger(), ['clock', 'pwm'])

    # Add a timer to stop the controller
    hello.add_timer('stop',
                    Constant(value=0),
                    None, ['is_running'],
                    period=6,
                    repeat=False)

    # print controller info
    print(hello.info('all'))

    try:

        # run the controller
        print('> Run the controller.')
        with hello:

            # wait for the controller to finish on its own
            hello.join()

        print('> Done with the controller.')

    except KeyboardInterrupt:
        pass

    # retrieve data from logger
    data = hello.get_sink('logger', 'log')

    try:

        # import matplotlib
        import matplotlib.pyplot as plt

    except:

        print('! Could not load matplotlib, skipping plots')
        sys.exit(0)

    print('> Will plot')

    try:

        # start plot
        plt.figure()

    except:

        print('! Could not plot graphics')
        print('> Make sure you have a connection to a windows manager')
        sys.exit(0)

    # plot input
    plt.plot(data['clock'], data['motor'], 'b')
    plt.ylabel('pwm (%)')
    plt.xlabel('time (s)')
    plt.ylim((-120, 120))
    plt.xlim(0, 6)
    plt.grid()

    # show plots
    plt.show()
示例#8
0
def test_webserver():

    import subprocess
    import time
    import numpy
    from pyctrl.flask.server import JSONDecoder, JSONEncoder
        
    if start_server:
        
        # initiate server
        print('> Starting server')

        server = subprocess.Popen(["python3",
                                   "pyctrl/flask/server.py"],
                                  stdout = subprocess.PIPE)
        
        time.sleep(2)

    try:

        # reset controller
        url = "http://127.0.0.1:5000/reset"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer
        
        # check index page
        answer = b"<div><p>&lt;class 'pyctrl.timer.Controller'&gt; with: 0 timer(s), 3 signal(s), 1 source(s), 0 filter(s), and 0 sink(s)</p><h2>timers</h2><ol></ol><h2>signals</h2><ol><li>clock</li><li>duty</li><li>is_running</li></ol><h2>sources</h2><ol><li>clock[TimerClock, disabled] &Gt; clock</li></ol><h2>filters</h2><ol></ol><h2>sinks</h2><ol></ol></div>"

        # check info page
        url = "http://127.0.0.1:5000/info"
        output = subprocess.check_output(["curl", url])
        assert output == answer

        # S I N K S
        
        # add sink
        url = r'"http://127.0.0.1:5000/add/sink/printer/pyctrl.block/Printer?inputs=\[\"clock\",\"is_running\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get sink
        url = "http://127.0.0.1:5000/get/sink/printer"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)

        from pyctrl.block import Printer
        assert result['printer'].get() == Printer().get()

        # get attribute/sink
        url = r'"http://127.0.0.1:5000/get/sink/printer?keys=\"enabled\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True}

        assert result == answer

        # get attribute/sink (multiple)
        url = '"http://127.0.0.1:5000/get/sink/printer?keys=\[\\"enabled\\",\\"endln\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'endln': '\n'}

        assert result == answer
        
        # set attribute/sink
        url = 'http://127.0.0.1:5000/set/sink/printer?enabled=false'
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/sink
        url = '"http://127.0.0.1:5000/get/sink/printer?keys=\\"enabled\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': False}

        assert result == answer
        
        # set attribute/sink
        url = '"http://127.0.0.1:5000/set/sink/printer?endln=\\"\\r\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/sink
        url = '"http://127.0.0.1:5000/get/sink/printer?keys=\\"endln\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'endln': '\r'}

        assert result == answer
        
        # set attribute/sink (multiple)
        url = '"http://127.0.0.1:5000/set/sink/printer?enabled=true&endln=\\"\\r\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/sink (multiple)
        url = '"http://127.0.0.1:5000/get/sink/printer?keys=\[\\"enabled\\",\\"endln\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'endln': '\r' }

        assert result == answer
        
        # add sink with parameter
        url = r'"http://127.0.0.1:5000/add/sink/printer/pyctrl.block/Printer?inputs=\[\"clock\",\"is_running\"\]&kwargs=\{\"endln\":\"\\r\"\}"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/sink (multiple)
        url = '"http://127.0.0.1:5000/get/sink/printer?keys=\[\\"enabled\\",\\"endln\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'endln': '\r' }

        assert result == answer
        
        # S O U R C E
        
        # add source
        url = r'"http://127.0.0.1:5000/add/source/constant/pyctrl.block/Constant?outputs=\[\"signal\"\]&kwargs=\{\"value\":3\}"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get source
        url = "http://127.0.0.1:5000/get/source/constant"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)

        from pyctrl.block import Constant
        assert result['constant'].get() == Constant(value = 3).get()

        # get attribute/source
        url = r'"http://127.0.0.1:5000/get/source/constant?keys=\"enabled\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True}

        assert result == answer

        # get attribute/source (multiple)
        url = r'"http://127.0.0.1:5000/get/source/constant?keys=\[\"enabled\",\"value\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'value': 3}

        assert result == answer
        
        # set attribute/source
        url = 'http://127.0.0.1:5000/set/source/constant?enabled=false'
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/source
        url = '"http://127.0.0.1:5000/get/source/constant?keys=\\"enabled\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': False}

        assert result == answer
        
        # set attribute/source
        url = '"http://127.0.0.1:5000/set/source/constant?value=4"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/source
        url = '"http://127.0.0.1:5000/get/source/constant?keys=\\"value\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'value': 4}

        assert result == answer
        
        # set attribute/source (multiple)
        url = '"http://127.0.0.1:5000/set/source/constant?enabled=true&value=5"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/source (multiple)
        url = '"http://127.0.0.1:5000/get/source/constant?keys=\[\\"enabled\\",\\"value\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'value': 5 }

        assert result == answer

        # F I L T E R
        
        # add filter
        url = r'"http://127.0.0.1:5000/add/filter/gain/pyctrl.block.system/Gain?inputs=\[\"inp\"\]&outputs=\[\"out\"\]&kwargs=\{\"gain\":3\}"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get filter
        url = "http://127.0.0.1:5000/get/filter/gain"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)

        from pyctrl.block.system import Gain
        assert result['gain'].get() == Gain(gain = 3).get()

        # get attribute/filter
        url = r'"http://127.0.0.1:5000/get/filter/gain?keys=\"enabled\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True}

        assert result == answer

        # get attribute/filter (multiple)
        url = r'"http://127.0.0.1:5000/get/filter/gain?keys=\[\"enabled\",\"gain\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'gain': 3}

        assert result == answer
        
        # set attribute/filter
        url = 'http://127.0.0.1:5000/set/filter/gain?enabled=false'
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/filter
        url = '"http://127.0.0.1:5000/get/filter/gain?keys=\\"enabled\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': False}

        assert result == answer
        
        # set attribute/filter
        url = '"http://127.0.0.1:5000/set/filter/gain?gain=4"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/filter
        url = '"http://127.0.0.1:5000/get/filter/gain?keys=\\"gain\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'gain': 4}

        assert result == answer
        
        # set attribute/filter (multiple)
        url = '"http://127.0.0.1:5000/set/filter/gain?enabled=true&gain=5"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/filter (multiple)
        url = '"http://127.0.0.1:5000/get/filter/gain?keys=\[\\"enabled\\",\\"gain\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'gain': 5 }

        assert result == answer
        
        # T I M E R
        
        # add timer
        url = r'"http://127.0.0.1:5000/add/timer/gain/pyctrl.block.system/Gain?inputs=\[\"inp\"\]&outputs=\[\"out\"\]&kwargs=\{\"gain\":3\}&period=1"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get timer
        url = "http://127.0.0.1:5000/get/timer/gain"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)

        from pyctrl.block.system import Gain
        assert result['gain'].get() == Gain(gain = 3).get()

        # get attribute/timer
        url = r'"http://127.0.0.1:5000/get/timer/gain?keys=\"enabled\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True}

        assert result == answer

        # get attribute/timer (multiple)
        url = r'"http://127.0.0.1:5000/get/timer/gain?keys=\[\"enabled\",\"gain\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'gain': 3}

        assert result == answer
        
        # set attribute/timer
        url = 'http://127.0.0.1:5000/set/timer/gain?enabled=false'
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/timer
        url = '"http://127.0.0.1:5000/get/timer/gain?keys=\\"enabled\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': False}

        assert result == answer
        
        # set attribute/timer
        url = '"http://127.0.0.1:5000/set/timer/gain?gain=4"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/timer
        url = '"http://127.0.0.1:5000/get/timer/gain?keys=\\"gain\\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'gain': 4}

        assert result == answer
        
        # set attribute/timer (multiple)
        url = '"http://127.0.0.1:5000/set/timer/gain?enabled=true&gain=5"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer

        # get attribute/timer (multiple)
        url = '"http://127.0.0.1:5000/get/timer/gain?keys=\[\\"enabled\\",\\"gain\\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'enabled': True, 'gain': 5 }

        assert result == answer

        answer = b"<div><p>&lt;class 'pyctrl.timer.Controller'&gt; with: 1 timer(s), 6 signal(s), 2 source(s), 1 filter(s), and 1 sink(s)</p><h2>timers</h2><ol><li>inp &Gt; gain[Gain, period = 1, repeat, enabled] &Gt; out</li></ol><h2>signals</h2><ol><li>clock</li><li>duty</li><li>inp</li><li>is_running</li><li>out</li><li>signal</li></ol><h2>sources</h2><ol><li>clock[TimerClock, disabled] &Gt; clock</li><li>constant[Constant, enabled] &Gt; signal</li></ol><h2>filters</h2><ol><li>inp &Gt; gain[Gain, enabled] &Gt; out</li></ol><h2>sinks</h2><ol><li>clock, is_running &Gt; printer[Printer, enabled]</li></ol></div>"
        
        # check info page
        url = "http://127.0.0.1:5000/info"
        output = subprocess.check_output(["curl", url])

        assert output == answer
        
        # reset controller
        
        url = "http://127.0.0.1:5000/set/controller/pyctrl/Controller"
        output = subprocess.check_output(["curl", url]).decode("utf-8")

        answer = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to target URL: <a href="/">/</a>.  If not click the link.'
        
        assert output == answer
        
        # check info page
        url = "http://127.0.0.1:5000/info"
        output = subprocess.check_output(["curl", url])

        answer = b"<div><p>&lt;class 'pyctrl.Controller'&gt; with: 0 timer(s), 3 signal(s), 1 source(s), 0 filter(s), and 0 sink(s)</p><h2>timers</h2><ol></ol><h2>signals</h2><ol><li>clock</li><li>duty</li><li>is_running</li></ol><h2>sources</h2><ol><li>clock[Clock, disabled] &Gt; clock</li></ol><h2>filters</h2><ol></ol><h2>sinks</h2><ol></ol></div>"
        
        assert output == answer
        
        # reset controller
        url = "http://127.0.0.1:5000/set/controller/pyctrl.timer/Controller?kwargs=\{\"period\":1\}"
        output = subprocess.check_output(["curl", url]).decode("utf-8")

        answer = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>Redirecting...</title>\n<h1>Redirecting...</h1>\n<p>You should be redirected automatically to target URL: <a href="/">/</a>.  If not click the link.'

        assert output == answer

        # get attribute/timer
        url = r'"http://127.0.0.1:5000/get/source/clock?keys=\"period\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'period': 1}
        
        assert result == answer

        # add logger
        url = r'"http://127.0.0.1:5000/add/sink/logger/pyctrl.block/Logger?inputs=\[\"clock\",\"is_running\"\]"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer
       
        # start
        url = "http://127.0.0.1:5000/start"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        time.sleep(3)
        
        # stop
        url = "http://127.0.0.1:5000/stop"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        # get log
        url = r'"http://127.0.0.1:5000/get/sink/logger?keys=\"log\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)['log']

        assert isinstance(result['clock'], numpy.ndarray)
        assert isinstance(result['is_running'], numpy.ndarray)
        assert result['is_running'].shape == result['clock'].shape
        assert result['clock'].shape[0] >= 3
        assert result['clock'].shape[1] == 1
        assert result['clock'][-1,0] - result['clock'][0,0] < 4
        
        # start
        url = "http://127.0.0.1:5000/start"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        time.sleep(3)
        
        # stop
        url = "http://127.0.0.1:5000/stop"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer
        
        # get log
        url = r'"http://127.0.0.1:5000/get/sink/logger?keys=\"log\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)['log']

        assert isinstance(result['clock'], numpy.ndarray)
        assert isinstance(result['is_running'], numpy.ndarray)
        assert result['is_running'].shape == result['clock'].shape
        assert result['clock'].shape[0] > 6
        assert result['clock'].shape[1] == 1
        assert result['clock'][-1,0] - result['clock'][0,0] > 6
        
        # add logger with auto_reset
        url = r'"http://127.0.0.1:5000/add/sink/logger/pyctrl.block/Logger?inputs=\[\"clock\",\"is_running\"\]&kwargs=\{\"auto_reset\":true\}"'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}

        assert result == answer
       
        # start
        url = "http://127.0.0.1:5000/start"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        time.sleep(3)
        
        # stop
        url = "http://127.0.0.1:5000/stop"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        # get log
        url = r'"http://127.0.0.1:5000/get/sink/logger?keys=\"log\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)['log']

        print('log = {}'.format(result))
        
        assert isinstance(result['clock'], numpy.ndarray)
        assert isinstance(result['is_running'], numpy.ndarray)
        assert result['is_running'].shape == result['clock'].shape
        assert result['clock'].shape[0] >= 3
        assert result['clock'].shape[1] == 1
        assert result['clock'][-1,0] - result['clock'][0,0] < 4
        
        # start
        url = "http://127.0.0.1:5000/start"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer

        time.sleep(3)
        
        # stop
        url = "http://127.0.0.1:5000/stop"
        output = subprocess.check_output(["curl", url]).decode("utf-8")
        result = JSONDecoder().decode(output)
        answer = {'status': 'success'}
        
        assert result == answer
        
        # get log
        url = r'"http://127.0.0.1:5000/get/sink/logger?keys=\"log\""'
        output = subprocess.check_output('curl ' + url, shell=True).decode("utf-8")
        result = JSONDecoder().decode(output)['log']

        print('log = {}'.format(result))
        
        assert isinstance(result['clock'], numpy.ndarray)
        assert isinstance(result['is_running'], numpy.ndarray)
        assert result['is_running'].shape == result['clock'].shape
        assert result['clock'].shape[0] >= 3
        assert result['clock'].shape[1] == 1
        assert result['clock'][-1,0] - result['clock'][0,0] < 4
        
    except Exception as e:
        
        print('** EXCEPTION RAISED **')
        print(e)
        raise e
    
    finally:
        
        if start_server:
            
            # stop server
            print('> Terminating server')
            server.terminate()