Skip to content

Commit

Permalink
Add antenna diagnostics and selection (#22)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
electricshaman authored Nov 9, 2017
1 parent 519212c commit 8bd2be1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/tm_mercury/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<ant, status <- tail>>, 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 <<ant, loss <- tail>>, do: {ant, loss}
Map.put(msg, :data, ant_list)
end

def decode(%Message{opcode: :get_antenna_port} = msg) do
<<tx :: uint8, rx :: uint8 >> = msg.data
Map.put(msg, :data, {tx, rx})
Expand Down
4 changes: 4 additions & 0 deletions lib/tm_mercury/protocol/command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, <<sub>>)}
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),
Expand Down
24 changes: 23 additions & 1 deletion lib/tm_mercury/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bd2be1

Please sign in to comment.