Data structure describing a parameter for a Z-Wave command.
Summary
Functions
Decodes an Elixir term from a bitstring according to the parameter specification.
Encodes an Elixir term into a bitstring according to the parameter specification.
Whether the parameter should be included in the resulting list of parameters when decoding a command.
Returns the size of the parameter in bits (or :variable) for variable-length params.
Takes the number of bits specified by the param spec from the front of the bitstring.
Validate a command spec.
Validate a command spec, raising on error.
Types
Functions
Decodes an Elixir term from a bitstring according to the parameter specification.
Encodes an Elixir term into a bitstring according to the parameter specification.
Whether the parameter should be included in the resulting list of parameters when decoding a command.
@spec num_bits(t()) :: non_neg_integer() | :variable
Returns the size of the parameter in bits (or :variable) for variable-length params.
Examples
iex> spec = %Grizzly.ZWave.ParamSpec{type: :uint, size: 16}
iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
16
iex> spec = %Grizzly.ZWave.ParamSpec{type: :binary, size: 32}
iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
32
iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: :variable}
iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
:variable
iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: {:variable, :another_param}}
iex> Grizzly.ZWave.ParamSpec.num_bits(spec)
:variable
@spec take_bits(t(), bitstring(), keyword()) :: {:ok, {bits_taken :: non_neg_integer(), value :: bitstring(), rest :: bitstring()}} | {:error, Grizzly.ZWave.DecodeError.t()}
Takes the number of bits specified by the param spec from the front of the bitstring.
Returns {:ok, {value, rest}} where value is the taken bits and rest is the
remaining bits. If there are not enough bits to take, an error is returned.
Examples
iex> spec = %Grizzly.ZWave.ParamSpec{type: :uint, size: 8}
iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
{:ok, {8, <<0x01>>, <<0x02, 0x03>>}}
iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: 16}
iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
{:ok, {16, <<0x01, 0x02>>, <<0x03>>}}
iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: :variable}
iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, [])
{:ok, {24, <<0x01, 0x02, 0x03>>, <<>>}}
iex> spec = %Grizzly.ZWave.ParamSpec{type: :int, size: {:variable, :length_param}}
iex> Grizzly.ZWave.ParamSpec.take_bits(spec, <<0x01, 0x02, 0x03>>, length_param: 2)
{:ok, {16, <<0x01, 0x02>>, <<0x03>>}}
Validate a command spec.
Validate a command spec, raising on error.