diff --git a/scripts/emulator/bridge.py b/scripts/emulator/bridge.py index 6a36796bc..3df3a779b 100644 --- a/scripts/emulator/bridge.py +++ b/scripts/emulator/bridge.py @@ -9,30 +9,30 @@ PACKET_SIZE = 64 -device = ('0.0.0.0', 21324) +main = ('0.0.0.0', 21324) debug = ('0.0.0.0', 21325) -s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) -s.connect(device) + +ms = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +ms.connect(main) + +ds = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +ds.connect(debug) app = Flask(__name__) @app.route('/exchange/', methods=['GET', 'POST']) def exchange(kind): - kk = device - if kind == 'debug': - kk = debug + kk = ds if kind == 'debug' else ms if request.method == 'POST': - content = request.get_json(silent=True) msg = bytearray.fromhex(content["data"]) - s.send(msg) - + kk.send(msg) return Response('{}', status=200, mimetype='application/json') if request.method == 'GET': - data = s.recv(PACKET_SIZE) + data = kk.recv(PACKET_SIZE) body = '{"data":"' + binascii.hexlify(data).decode("utf-8") + '"}' return Response(body, status=200, mimetype='application/json')