From 8bd2be1c1f1ec324677c8438a04224c534e6d3dc Mon Sep 17 00:00:00 2001 From: Jeff Smith Date: Wed, 8 Nov 2017 19:17:20 -0600 Subject: [PATCH] Add antenna diagnostics and selection (#22) * Implement antenna detection * Add get_rx_tx_ports function * Add get_antenna_return_loss function * Search on single antenna using current antenna config * Bump to 0.5.0. --- lib/tm_mercury/message.ex | 12 ++++++++++++ lib/tm_mercury/protocol/command.ex | 4 ++++ lib/tm_mercury/reader.ex | 24 +++++++++++++++++++++++- mix.exs | 2 +- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/tm_mercury/message.ex b/lib/tm_mercury/message.ex index 643b63e..e658fe9 100644 --- a/lib/tm_mercury/message.ex +++ b/lib/tm_mercury/message.ex @@ -65,6 +65,18 @@ defmodule TM.Mercury.Message do Map.put(msg, :data, TM.Mercury.Tag.Protocol.decode!(tag_protocol)) end + def decode(%Message{opcode: :get_antenna_port, data: <<0x05, tail :: binary>>} = msg) do + # Antenna detection + ant_list = for <>, do: {ant, status} + Map.put(msg, :data, ant_list) + end + + def decode(%Message{opcode: :get_antenna_port, data: <<0x06, tail :: binary>>} = msg) do + # Antenna return loss + ant_list = for <>, do: {ant, loss} + Map.put(msg, :data, ant_list) + end + def decode(%Message{opcode: :get_antenna_port} = msg) do <> = msg.data Map.put(msg, :data, {tx, rx}) diff --git a/lib/tm_mercury/protocol/command.ex b/lib/tm_mercury/protocol/command.ex index a941478..3917dc5 100644 --- a/lib/tm_mercury/protocol/command.ex +++ b/lib/tm_mercury/protocol/command.ex @@ -108,6 +108,10 @@ defmodule TM.Mercury.Protocol.Command do {:ok, Message.encode(code, <<2, ant :: binary>>)} end + defp build_command(_rdr, {:get_antenna_port, code}, [sub|[]]) do + {:ok, Message.encode(code, <>)} + end + defp build_command(_rdr, {:get_reader_stats, code}, [option, flags]) do with {:ok, encoded_option} <- Stats.Option.encode(option), {:ok, encoded_flags} <- Stats.Flag.encode(flags), diff --git a/lib/tm_mercury/reader.ex b/lib/tm_mercury/reader.ex index b8a1c0d..3c08413 100644 --- a/lib/tm_mercury/reader.ex +++ b/lib/tm_mercury/reader.ex @@ -207,6 +207,28 @@ defmodule TM.Mercury.Reader do GenServer.call(pid, [:set_antenna_port, ports]) end + @doc """ + Enumerate the logical antenna ports and report the antenna + detection status of each one. + """ + def detect_antennas(pid) do + GenServer.call(pid, [:get_antenna_port, 0x05]) + end + + @doc """ + Return the current TX and RX antenna port. + """ + def get_tx_rx_ports(pid) do + GenServer.call(pid, [:get_antenna_port, 0x00]) + end + + @doc """ + Return the antenna return loss of logical antenna ports. + """ + def get_antenna_return_loss(pid) do + GenServer.call(pid, [:get_antenna_port, 0x06]) + end + @doc """ TODO """ @@ -601,7 +623,7 @@ defmodule TM.Mercury.Reader do end defp execute_read_sync(ts, rdr, timeout, rp) do - flags = [:configured_list, :large_tag_population_support] + flags = [:configured_antenna, :large_tag_population_support] |> add_flag(:fast_search, rp) try do diff --git a/mix.exs b/mix.exs index 662a67a..88c29bc 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule TM.Mercury.Mixfile do def project do [app: :tm_mercury, - version: "0.5.0-dev", + version: "0.5.0", elixir: "~> 1.4", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod,