<filename>tests/network/bluetooth_test.py<gh_stars>0
#!/usr/bin/env python3

"""
Created on 27 Oct 2016

@author: <NAME> (<EMAIL>)
"""

from scs_core.data.json import JSONify
from scs_core.monitor.monitor_response import MonitorResponse

from scs_host.network.bluetooth_connection import BluetoothConnection
from scs_host.network.bluetooth_serial import BluetoothSerial


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

class EchoHandler(object):
    """
    classdocs
    """

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

    # noinspection PyMethodMayBeStatic
    def respond(self, command):
        message = None
        error = None

        try:
            message = command

        except Exception as ex:
            error = ex.__class__.__name__ + ":" + str(ex)

        response = MonitorResponse(message, error)

        return JSONify.dumps(response)


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

handler = EchoHandler()

BluetoothConnection.enable()


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

for state in BluetoothConnection.monitor():
    print("state:[%s]" % state, end='\r\n')

    if state == BluetoothConnection.FAILED:
        print("FAILED")
        exit(-1)

    if state == BluetoothConnection.STOPPED:
        break

    if state == BluetoothConnection.CONNECTED:
        BluetoothSerial.monitor(handler)

print("DONE", end='\r\n')


<filename>tests/network/bluetooth_test.py<gh_stars>0
#!/usr/bin/env python3

"""
Created on 27 Oct 2016

@author: <NAME> (<EMAIL>)
"""

from scs_core.data.json import JSONify
from scs_core.monitor.monitor_response import MonitorResponse

from scs_host.network.bluetooth_connection import BluetoothConnection
from scs_host.network.bluetooth_serial import BluetoothSerial


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

class EchoHandler(object):
    """
    classdocs
    """

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

    # noinspection PyMethodMayBeStatic
    def respond(self, command):
        message = None
        error = None

        try:
            message = command

        except Exception as ex:
            error = ex.__class__.__name__ + ":" + str(ex)

        response = MonitorResponse(message, error)

        return JSONify.dumps(response)


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

handler = EchoHandler()

BluetoothConnection.enable()


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

for state in BluetoothConnection.monitor():
    print("state:[%s]" % state, end='\r\n')

    if state == BluetoothConnection.FAILED:
        print("FAILED")
        exit(-1)

    if state == BluetoothConnection.STOPPED:
        break

    if state == BluetoothConnection.CONNECTED:
        BluetoothSerial.monitor(handler)

print("DONE", end='\r\n')


#!/usr/bin/env python3 Created on 27 Oct 2016  @author: <NAME> (<EMAIL>) # -------------------------------------------------------------------------------------------------------------------- classdocs # ---------------------------------------------------------------------------------------------------------------- # noinspection PyMethodMayBeStatic # -------------------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------------------