예제 #1
0
def evaluate_morse(led, test_rounds, test_period):
    data_len = 1024
    error = True
    latency = False
    throughput = True
    evaluator = VlcMetrics()
    path = os.path.join(__location__, "..", "results", "error_data_len",
                        led.get_name(), "data_len_" + str(data_len))
    test_data = "abcdefghijklmnopqrstuvwxyz0123456789"
    while evaluator.get_data_rounds() < test_rounds:
        print("evaluation round: ", evaluator.get_data_rounds())
        conn = ReceiveLightControl.Connector.local
        action = ReceiveLightControl.Action.evaluate_morse
        light_control = ReceiveLightControl(
            action,
            conn=conn,
            evaluator=evaluator,
            evaluate_period=test_period,
            evaluate_template=test_data,
            evaluate_error=error,
            evaluate_latency=latency,
            evaluate_throughput=throughput,
            sampling_interval=led.get_sampling_interval())
        light_control.start()
        print("-------------------")
    evaluator.check_data()
    evaluator.print_data()
    serializer = DillSerializer(path)
    serializer.serialize(evaluator)
예제 #2
0
def test_parse_manchester():
    light_control = ReceiveLightControl(
        ReceiveLightControl.Action.parse_manchester,
        conn=ReceiveLightControl.Connector.socket,
        evaluate_ip="192.168.0.2",
        evaluate_port=11234)
    light_control.start()
예제 #3
0
def evaluate_vlc_parameters(test_rounds,
                            test_period,
                            test_data,
                            morse=True,
                            throughput=True,
                            error=True,
                            latency=False,
                            manchester_ip="192.168.0.2",
                            manchester_port=11234):
    basedir_results = os.path.join(__location__, "..", "results",
                                   "vlc_parameters")
    time_base_unit = 50000
    sampling_intervals = [
        5000, 10000, 15000, 20000, 25000, 30000, 50000, 100000, 150000
    ]  # ns
    # 5000, 10000, 15000, 20000, 25000, 30000, 50000, 100000, 150000 # pervasive LED
    # 100000, 110000, 120000, 130000, 140000, 150000 # directed LED
    for sampling_interval in sampling_intervals:
        if morse:
            print("sampling interval: ", sampling_interval)
        evaluator = VlcMetrics()
        while evaluator.get_data_rounds() < test_rounds:
            print("evaluation round: ", evaluator.get_data_rounds())
            if morse:
                action = ReceiveLightControl.Action.evaluate_morse
                conn = ReceiveLightControl.Connector.local
                data_encoding = "morse"
            else:
                action = ReceiveLightControl.Action.evaluate_manchester
                conn = ReceiveLightControl.Connector.socket
                data_encoding = "manchester"
            print("start evaluation")
            light_control = ReceiveLightControl(
                action,
                conn=conn,
                evaluator=evaluator,
                evaluate_period=test_period,
                evaluate_template=test_data,
                evaluate_throughput=throughput,
                evaluate_error=error,
                evaluate_latency=latency,
                sampling_interval=sampling_interval,
                evaluate_ip=manchester_ip,
                evaluate_port=manchester_port)
            light_control.start()
            print("stop evaluation")
        evaluator.check_data()
        evaluator.print_data()
        if morse:
            filename = "%s_sampling_%d_time_base_unit_%d"
            filename = filename % (data_encoding, sampling_interval,
                                   time_base_unit)
        else:
            filename = "%s_freq_%d"
            filename = filename % (data_encoding)
        serializer = DillSerializer(basedir_results + filename)
        serializer.serialize(evaluator)
        print("---------------------------------")
예제 #4
0
def test_energy_morse_parameter(conversion_to_nanosecond=1000):
    pervasive_led_sampling_intervals = [10, 20, 30]
    #directional_led_sampling_intervals = [20, 30, 50]
    sampling_interval = pervasive_led_sampling_intervals[
        0] * conversion_to_nanosecond
    print("sampling interval: ", sampling_interval)
    light_control = ReceiveLightControl(
        ReceiveLightControl.Action.data_amount_morse,
        sampling_interval=sampling_interval)
    light_control.start()
예제 #5
0
def morse(period, template):
    evaluator = VlcMetrics()
    action = ReceiveLightControl.Action.evaluate_morse
    connector = ReceiveLightControl.Connector.local
    light_control = ReceiveLightControl(action,
                                        conn=connector,
                                        evaluator=evaluator,
                                        evaluate_period=period,
                                        evaluate_template=template,
                                        evaluate_throughput=True,
                                        evaluate_error=True)
    light_control.start()
    return evaluator
예제 #6
0
def manchester(period, template, ip, port):
    evaluator = VlcMetrics()
    action = ReceiveLightControl.Action.evaluate_manchester
    connector = ReceiveLightControl.Connector.socket
    light_control = ReceiveLightControl(action,
                                        conn=connector,
                                        evaluator=evaluator,
                                        evaluate_period=period,
                                        evaluate_template=template,
                                        evaluate_ip=ip,
                                        evaluate_port=port,
                                        evaluate_throughput=True,
                                        evaluate_error=True)
    light_control.start()
    return evaluator
예제 #7
0
def start_latency():
    global send_timestamp
    #sampling_interval = 50000 # directed led
    sampling_interval = 30000  # pervasive led
    latency = True
    test_data = "abcdefghijklmnopqrstuvwxyz0123456789"
    action = ReceiveLightControl.Action.evaluate_morse
    conn = ReceiveLightControl.Connector.local
    light_control = ReceiveLightControl(action,
                                        conn=conn,
                                        evaluate_template=test_data,
                                        evaluate_latency=latency,
                                        callback_latency=received_msg,
                                        sampling_interval=sampling_interval)
    light_control.start()
    control_sender.start_cmd()
예제 #8
0
def test_single_throughput(led, test_data, test_rounds):
    evaluator = VlcMetrics()
    while evaluator.get_data_rounds() < test_rounds:
        print("evaluation round: ", evaluator.get_data_rounds())
        action = ReceiveLightControl.Action.evaluate_morse
        conn = ReceiveLightControl.Connector.local
        light_control = ReceiveLightControl(
            action,
            conn=conn,
            evaluator=evaluator,
            evaluate_period=10,
            #evaluate_data_amount=file_size,
            evaluate_template=test_data,
            evaluate_throughput=True,
            evaluate_error=True,
            #evaluate_latency=latency,
            sampling_interval=led.get_sampling_interval(),
            #evaluate_ip=ip, evaluate_port=port
        )
        light_control.start()
    evaluator.check_data()
    evaluator.print_data()
예제 #9
0
def test_light_propagation(led, test_rounds, test_period, test_data,
                           measurement_point):
    result_file = "../results/signal_propagation/light"
    object_serializer = DillSerializer(result_file)
    evaluation_result = object_serializer.deserialize() if os.path.isfile(
        result_file) else dict()
    action = ReceiveLightControl.Action.evaluate_morse
    conn = ReceiveLightControl.Connector.local
    vlc_metrics = VlcMetrics()
    while vlc_metrics.get_data_rounds() < test_rounds:
        print("evaluation round: ", vlc_metrics.get_data_rounds())
        light_control = ReceiveLightControl(
            action,
            conn=conn,
            evaluator=vlc_metrics,
            evaluate_period=test_period,
            evaluate_template=test_data,
            evaluate_throughput=True,
            evaluate_error=True,
            sampling_interval=led.get_sampling_interval())
        light_control.start()
    vlc_metrics.check_data()
    evaluation_result[measurement_point] = vlc_metrics
    object_serializer.serialize(evaluation_result)
예제 #10
0
파일: test.py 프로젝트: TUM-cm/iPresence
def run_impulse_response():
    '''
    light_control = ReceiveLightControl(ReceiveLightControl.Action.stream_raw_light_signal,
                                        conn=ReceiveLightControl.Connector.mqtt,
                                        mqtt_remote_ip="131.159.24.85",
                                        mqtt_data_format=MqttConnector.FORMAT_VOLTAGE)
    light_control.start()
    '''

    evaluate_period = 10
    remote_light_sensing = []
    remote_light_emitting = []
    path_evaluation_data = "../evaluation/results/impulse_response/voltage_"
    led_actions = [
        LedAction(2, SenderDevice.high, 0.1),
        LedAction(5, SenderDevice.high, 0.5),
        LedAction(7, SenderDevice.high, 1)
    ]

    #remote_nodes = [("192.168.7.2", "01.05.038_desk", led_actions), ("131.159.24.85", "01.05.038_window", None)]
    remote_nodes = [("beaglebone.local", "home", led_actions)]
    for ip, description, led_action in remote_nodes:
        light_control = ReceiveLightControl(
            ReceiveLightControl.Action.serialize_raw_light_signal,
            data_path_voltage=path_evaluation_data + description,
            evaluate_period=evaluate_period,
            conn=ReceiveLightControl.Connector.mqtt,
            mqtt_remote_ip=ip,
            mqtt_data_format=MqttConnector.FORMAT_VOLTAGE)
        remote_light_sensing.append(
            threading.Thread(target=light_control.start))
        light_beacon = LightBeacon(ip)
        if led_action:
            for action in led_action:
                light_beacon.add(action.get_delay(), action.get_cmd())
        remote_light_emitting.append(
            threading.Thread(target=light_beacon.start))

    # remote sensing
    for remote_sensing, remote_lighting in zip(remote_light_sensing,
                                               remote_light_emitting):
        remote_sensing.start()
        remote_lighting.start()

    for remote_sensing, remote_lighting in zip(remote_light_sensing,
                                               remote_light_emitting):
        remote_sensing.join()
        remote_lighting.join()
예제 #11
0
def test_energy_encryption(led,
                           morse,
                           eval_ip="192.168.0.2",
                           eval_port=11234,
                           speck=False,
                           aes=False):
    if morse:
        light_control = ReceiveLightControl(
            ReceiveLightControl.Action.data_amount_morse,
            sampling_interval=led.get_sampling_interval())
    else:
        if speck:
            action = ReceiveLightControl.Action.data_amount_manchester_speck
        elif aes:
            action = ReceiveLightControl.Action.data_amount_manchester_aes
        else:
            action = ReceiveLightControl.Action.data_amount_manchester
        light_control = ReceiveLightControl(
            action,
            conn=ReceiveLightControl.Connector.socket,
            evaluate_ip=eval_ip,
            evaluate_port=eval_port)
    light_control.start()
예제 #12
0
service_discovery = MessageServiceDiscovery()


def parse_service_discovery(morse_msg):
    morse_msg = morse_msg
    #print("msg: <{}>".format(morse_msg))
    try:
        service_discovery.parse(morse_msg)
        ssid = service_discovery.get_location()
        pwd = service_discovery.get_password()
        print("ssid: {}".format(ssid))  # ssid
        print("password: {}".format(pwd))
        wifi = wifi_connector.connect(ssid, pwd)
        print("wifi: {}".format(wifi))
        if wifi:
            server_ip = wifi_connector.get_ip("wlan0")
            server_ip = server_ip.split(".")
            server_ip[-1] = str(1)  # gateway
            server_ip = ".".join(server_ip)
            coupling_client.start(server_ip, server_port)
    except TypeError:
        pass


led = Testbed.Pervasive_LED
light_control = ReceiveLightControl(
    ReceiveLightControl.Action.morse_callback,
    sampling_interval=led.get_sampling_interval(),
    callback_morse=parse_service_discovery)
light_control.start()
예제 #13
0
def evaluate_comparison(led,
                        test_rounds,
                        test_period,
                        test_data,
                        morse=True,
                        throughput=True,
                        error=True,
                        latency=False,
                        manchester_ip="192.168.0.2",
                        manchester_port=11234):
    basedir_results = os.path.join(__location__, "..", "results",
                                   "vlc-performance")
    # 1400 B/s throughput from previous evaluation for best working VLC parameters
    # 1 kb = 0.7 s > 10 s
    # 5 kB = 3.7 s > 40 s
    # 10 kB = 7.3 s > 1 min.
    # 100 kB = 73 s (1,20 min.) > 12 min.
    # 200 kB = 146 s (2,5 min.) > 25 min.
    # 500 kB = 365 s = (6 min.) > 60 min.
    file_sizes = [1024, 5120, 10240, 102400]  # 512000
    energy_measurements = EnergyMeasurements()
    for file_size in file_sizes:
        print("file size: ", file_size)
        evaluator = VlcMetrics()
        while evaluator.get_data_rounds() < test_rounds:
            print("evaluation round: ", evaluator.get_data_rounds())
            if morse:
                action = ReceiveLightControl.Action.evaluate_morse
                conn = ReceiveLightControl.Connector.local
                data_encoding = "morse"
            else:
                action = ReceiveLightControl.Action.evaluate_manchester
                conn = ReceiveLightControl.Connector.socket
                data_encoding = "manchester"

            print("start energy measurements")
            energy_measurements.start_periodic_sampling()
            print("start evaluation")
            light_control = ReceiveLightControl(
                action,
                conn=conn,
                evaluator=evaluator,
                evaluate_period=test_period,
                evaluate_data_amount=file_size,
                evaluate_template=test_data,
                evaluate_throughput=throughput,
                evaluate_error=error,
                evaluate_latency=latency,
                sampling_interval=led.get_sampling_interval(),
                evaluate_ip=manchester_ip,
                evaluate_port=manchester_port)
            light_control.start()
            print("stop energy measurements")
            energy_measurements.stop_periodic_sampling()
            data_period = evaluator.get_data_period()[-1]
            data_amount = evaluator.get_throughput_total()[-1]
            print("data amount: ", data_amount)
            print("data period: ", data_period)
            energy_mJ = energy_measurements.calculate_energy(data_period)
            evaluator.energy(energy_mJ)
            energy_measurements.reset()
            print("stop evaluation")
        evaluator.check_data()
        evaluator.print_data()
        filename = "%s-file-size-%d" % (data_encoding, file_size)
        serializer = DillSerializer(os.path.join(basedir_results, filename))
        serializer.serialize(evaluator)
        print("---------------------------------")
    energy_measurements.closeDevice()
예제 #14
0
def test_parse_morse(led):
    light_control = ReceiveLightControl(
        ReceiveLightControl.Action.parse_morse,
        sampling_interval=led.get_sampling_interval())
    light_control.start()