Kitt.Encoder (kitt v0.4.0) View Source

Encoding and decoding functions for specific message types and frame defined by the J2735-standard.

Calls the lower-level :DSRC functions generated by the ASN1 definition files and converts the resulting maps to Elixir structs as well as the reverse order for conversion from maps and structs to hexadecimal or binary encoded messages

Link to this section Summary

Types

A struct-encoded instance of a J2735 standard message

Functions

Takes an encoded DSRC Message Frame and decodes it to a Kitt struct of the encoded type.

The same as Kitt.decode_frame/2 but returns the decoded message struct directly without the :ok tuple wrapper or raises a DSRCDecodeError exception.

Takes a binary encoded J2735 message and an explicit message type atom and decodes the message to a Kitt struct. Any sub-fields of the struct that are defined by Kitt as a struct are recursively instantiated.

Same as decode_message/3 but returns the decoded struct directly or else raises a DSRCDecodeError exception.

Takes a Kitt message struct and converts it to either a binary or hex version of the message data wrapped in a Message Frame structure tagged with the appropriate ID number.

The same as Kitt.encode_frame/2 but returns the encoded message binary directly without the :ok tuple wrapper or raises a DSRCEncodeError exception.

Takes a Kitt message struct or comparable message data as a basic Elixir map as well as an explicit message type atom and encodes the message to a binary representation of the message.

Same as encode_message/3 but returns the encoded message binary directly or else raises a DSRCEncodeError exception.

Takes a Kitt message struct and encodes it to a binary representation of the message.

Same as encode_struct/2 but returns the encoded message binary directly or else raises a DSRCEncodeError exception.

Link to this section Types

Link to this section Functions

Link to this function

decode_frame(message, opts \\ [])

View Source

Specs

decode_frame(binary(), [{:format, :hex | :binary}]) ::
  {:ok, message()} | {:error, term()}

Takes an encoded DSRC Message Frame and decodes it to a Kitt struct of the encoded type.

Data elements contained within the struct as sub-values with a defined Kitt struct type are recursively instantiated as well.

The default input format is a hexadecimal string encoding unless specified by passing the optional keyword argument format: :hex | :binary

Returns the struct wrapped in an :ok tuple or an {:error, reason} tuple.

Link to this function

decode_frame!(message, opts \\ [])

View Source

Specs

decode_frame!(binary(), [{:format, :hex | :binary}]) :: message()

The same as Kitt.decode_frame/2 but returns the decoded message struct directly without the :ok tuple wrapper or raises a DSRCDecodeError exception.

Link to this function

decode_message(message, type, opts \\ [])

View Source

Specs

decode_message(binary(), atom(), [{:format, :hex | :binary}]) ::
  {:ok, message()} | {:error, term()}

Takes a binary encoded J2735 message and an explicit message type atom and decodes the message to a Kitt struct. Any sub-fields of the struct that are defined by Kitt as a struct are recursively instantiated.

By default the binary message is assumed to be in a hexadecimal string but the input format can be explicitly supplied via the keyword argument format: :hex | :binary.

Returns the resulting message struct wrapped in an :ok tuple, else returns {:error, reason}.

Link to this function

decode_message!(message, type, opts \\ [])

View Source

Specs

decode_message!(binary(), atom(), [{:format, :hex | :binary}]) :: message()

Same as decode_message/3 but returns the decoded struct directly or else raises a DSRCDecodeError exception.

Link to this function

encode_frame(message, opts \\ [])

View Source

Specs

encode_frame(message(), [{:format, :hex | :binary}]) ::
  {:ok, binary()} | {:error, term()}

Takes a Kitt message struct and converts it to either a binary or hex version of the message data wrapped in a Message Frame structure tagged with the appropriate ID number.

The default output format is hexadecimal. Optionally define the desired output by passing the keyword flag format: :hex | :binary.

Returns the encoded message wrapped in an :ok tuple or an {:error, reason} tuple.

Link to this function

encode_frame!(message, opts \\ [])

View Source

Specs

encode_frame!(message(), [{:format, :binary | :hex}]) :: binary()

The same as Kitt.encode_frame/2 but returns the encoded message binary directly without the :ok tuple wrapper or raises a DSRCEncodeError exception.

Link to this function

encode_message(message, type, opts \\ [])

View Source

Specs

encode_message(message() | map(), atom(), [{:format, :hex | :binary}]) ::
  {:ok, binary()} | {:error, term()}

Takes a Kitt message struct or comparable message data as a basic Elixir map as well as an explicit message type atom and encodes the message to a binary representation of the message.

By default the message is encoded to a hexadecimal representation but the optional keyword argument format: :hex | :binary can explicitly define the desired output format.

Resulting binary is wrapped in an :ok tuple, else an {:error, reason} is returned.

Link to this function

encode_message!(message, type, opts \\ [])

View Source

Specs

encode_message!(message(), atom(), [{:format, :hex | :binary}]) :: binary()

Same as encode_message/3 but returns the encoded message binary directly or else raises a DSRCEncodeError exception.

Link to this function

encode_struct(message, opts \\ [])

View Source

Specs

encode_struct(message(), [{:format, :hex | :binary}]) ::
  {:ok, binary()} | {:error, term()}

Takes a Kitt message struct and encodes it to a binary representation of the message.

By default the message is encoded to a hexadecimal representation but the optional keyword argument format: :hex | :binary can explicitly define the desired output format.

Resulting binary is wrapped in an :ok tuple, else an {:error, reason} is returned.

Link to this function

encode_struct!(message, opts \\ [])

View Source

Specs

encode_struct!(message(), [{:format, :hex | :binary}]) :: binary()

Same as encode_struct/2 but returns the encoded message binary directly or else raises a DSRCEncodeError exception.