Skip to content

Commit

Permalink
Merge pull request #155 from keepkey/emulator-bridge-debuglink
Browse files Browse the repository at this point in the history
emulator: fix debug-link in the bridge
  • Loading branch information
keepkeyjon authored Jul 11, 2019
2 parents 064516d + 238256f commit d5a4b30
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions scripts/emulator/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<string:kind>', 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')

Expand Down

0 comments on commit d5a4b30

Please sign in to comment.