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
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
Specs
message() :: Kitt.Message.BSM.t() | Kitt.Message.CSR.t() | Kitt.Message.EVA.t() | Kitt.Message.ICA.t() | Kitt.Message.MAP.t() | Kitt.Message.PSM.t() | Kitt.Message.RSA.t() | Kitt.Message.SPAT.t() | Kitt.Message.SRM.t() | Kitt.Message.SSM.t() | Kitt.Message.TIM.t()
A struct-encoded instance of a J2735 standard message
Link to this section Functions
Specs
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.
Specs
The same as Kitt.decode_frame/2
but returns the decoded message struct directly
without the :ok
tuple wrapper or raises a DSRCDecodeError
exception.
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}
.
Specs
Same as decode_message/3
but returns the decoded struct directly or else raises
a DSRCDecodeError exception.
Specs
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.
Specs
The same as Kitt.encode_frame/2
but returns the encoded message binary directly
without the :ok
tuple wrapper or raises a DSRCEncodeError
exception.
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.
Specs
Same as encode_message/3
but returns the encoded message binary directly
or else raises a DSRCEncodeError exception.
Specs
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.
Specs
Same as encode_struct/2
but returns the encoded message binary directly
or else raises a DSRCEncodeError exception.