     Logger.debug "State will be #{inspect state}"
     {:ok, state}
   end
+  def init([pid]) when is_pid(pid) do
+    Logger.debug("HCI.init with emulator pid #{inspect pid}")
+    state = %__MODULE__{port: pid}
+    Logger.debug "State will be #{inspect state}"
+    {:ok, state}
+  end
 
   def handle_call({:hci_receive, [timeout]}, from, s = %__MODULE__{messages: q, receiver: nil}) do
     case :queue.out(q) do


  @spec hci_receive(non_neg_integer) :: {:ok, any} | {:error, any}
  def hci_receive(timeout \\ 5_000) when is_integer(timeout) and timeout >= 0 do
    GenServer.call(__MODULE__, {:hci_recieve, [timeout]})
  end



  def terminate(reason, _state = %__MODULE__{port: port}) do
    Logger.debug("HCI is shutting down for reason: #{inspect reason}")
    # kill the port
    if (is_port(port)),
      do: Port.close(port),
    else: Process.exit(port, :normal)
    :ok
  end

