28 lines
767 B
Elixir
28 lines
767 B
Elixir
defmodule Augie.Sensor.Power do
|
|
defstruct ~w[bus_voltage shunt_voltage current power]a
|
|
alias __MODULE__
|
|
|
|
@moduledoc """
|
|
Storage struct for Power telemetry.
|
|
"""
|
|
|
|
@type t :: %Power{bus_voltage: float, shunt_voltage: float, current: float, power: float}
|
|
|
|
@doc """
|
|
Convert incoming telemetry into a structure.
|
|
"""
|
|
@spec build([float]) :: {:ok, Power.t()} | {:error, :bad_data}
|
|
def build([bus_voltage, shunt_voltage, current, power])
|
|
when is_float(bus_voltage) and is_float(shunt_voltage) and is_float(current) and
|
|
is_float(power) do
|
|
{:ok,
|
|
%Power{
|
|
bus_voltage: bus_voltage,
|
|
shunt_voltage: shunt_voltage,
|
|
current: current,
|
|
power: power
|
|
}}
|
|
end
|
|
|
|
def build(_), do: {:error, :bad_data}
|
|
end
|