code: async def dispatch(request):
      
      if session:
          message = ''
          data = await request.json()
          try:
              log.info("Dispatching {}".format(data))
              _id = data.get('token')
              if not _id:
                  message = '"token" field required for calibration requests'
                  raise AssertionError
              command = data.get('command')
              if not command:
                  message = '"command" field required for calibration requests'
                  raise AssertionError
  
              if _id == session.id:
                  res = await router[command](data)
              else:
                  res = web.json_response(
                      {'message': 'Invalid token: {}'.format(_id)}, status=403)
          except AssertionError:
              res = web.json_response({'message': message}, status=400)
          except Exception as e:
              res = web.json_response(
                  {'message': 'Exception {} raised by dispatch of {}: {}'.format(
                      type(e), data, e)},
                  status=500)
      else:
          res = web.json_response(
              {'message': 'Session must be started before issuing commands'},
              status=418)
      return res
docs: Routes commands to subhandlers based on the command field in the body.