Generic messages

Command result

Command results are messages sent by an interface to the host to indicate the result of a requested operation. The whad_generic_cmd_result() function provides an easy way to create such messages:

Message msg;

/* Create a command result message indicating an error. */
whad_generic_cmd_result(&msg, WHAD_RESULT_ERROR);

Verbose messages

Verbose messages contain text that will be sent to the host and that will be displayed when verbose mode is enabled by the user. These messages can be created using the whad_verbose() function (which is a wrapper for the whad_generic_verbose_message() function):

/* Create a verbose message. */
whad_verbose("This is some information for the user.");

Debug messages

Debug messages are not intended to be displayed to the user and will only be showed when debug mode is enabled on host-side. These messages can be created through the whad_generic_debug_message() function:

Message msg;

/* Create a debug message. */
whad_generic_debug_message(&msg, 1, "Some debug message.");

Generic API reference

Enums

enum whad_result_code_t

Generic command result codes.

Values:

enumerator WHAD_RESULT_SUCCESS

Operation succeeded.

enumerator WHAD_RESULT_ERROR

An error occurred.

enumerator WHAD_RESULT_PARAMETER_ERROR

A wrong parameter has been supplied.

enumerator WHAD_RESULT_DISCONNECTED

Device has disconnected.

enumerator WHAD_RESULT_WRONG_MODE

Requested operation does not match current operating mode.

enumerator WHAD_RESULT_UNSUPPORTED_DOMAIN

Domain is not supported by this interface.

enumerator WHAD_RESULT_BUSY

Interface is busy and cannot handle the requested operation.

enum whad_generic_msgtype_t

Generic message types

This enumeration is an alias for NanoPb generated constants.

Values:

enumerator WHAD_GENERIC_UNKNOWN

Unknown generic message

enumerator WHAD_GENERIC_CMDRESULT

Command result

enumerator WHAD_GENERIC_VERBOSE

Verbose message

enumerator WHAD_GENERIC_DEBUG

Debug message

enumerator WHAD_GENERIC_PROGRESS

Progress message

Functions

whad_generic_msgtype_t whad_generic_get_message_type(Message *p_message)

Get generic message type from raw message.

Parameters:

p_message[in] Pointer to a NanoPb message structure.

Returns:

whad_generic_msgtype_t Generic message type

whad_result_t whad_generic_cmd_result(Message *p_message, whad_result_code_t result)

Initialize a generic command result message.

Parameters:
  • p_message[in] Pointer to a Message structure

  • result[in] Result code to include in the message

Return values:
  • WHAD_SUCCESS – Success

  • WHAD_ERROR – Wrong message pointer

whad_result_t whad_generic_cmd_result_parse(Message *p_message, whad_result_code_t *p_result)

Initialize a generic command result message.

Parameters:
  • p_message[in] Pointer to a Message structure

  • p_result[inout] Pointer to a result code

Return values:
  • WHAD_SUCCESS – Success

  • WHAD_ERROR – Wrong message pointer or result code pointer

bool whad_verbose_msg_encode_cb(pb_ostream_t *ostream, const pb_field_t *field, void *const *arg)

Generic verbose message encoding callback.

Parameters:
  • ostream[inout] Output stream

  • field[in] Pointer to a field descriptor.

  • arg[in] Pointer to a custom argument storing a pointer onto the text message to encode.

Returns:

true if everything went ok, false otherwise.

whad_result_t whad_generic_verbose_message(Message *p_message, char *psz_message)

Initialize a generic verbose message.

Parameters:
  • p_message[inout] Pointer to a Message structure representing a message.

  • psz_message[in] Pointer to the message string to include in this verbose message.

Return values:
  • WHAD_SUCCESS – Success

  • WHAD_ERROR – Wrong message pointer

whad_result_t whad_generic_verbose_message_parse(Message *p_message, char **ppsz_message)
whad_result_t whad_verbose(char *psz_message)

WHAD verbose helper.

This function sends a verbose message to the host.

Parameters:

psz_message[in] Pointer to the message string to include in this verbose message.

Return values:
  • WHAD_SUCCESS – Success

  • WHAD_ERROR – Wrong message pointer

bool whad_debug_msg_encode_cb(pb_ostream_t *ostream, const pb_field_t *field, void *const *arg)

Generic debug message encoding callback.

Parameters:
  • ostream[inout] Output stream

  • field[in] Pointer to a field descriptor.

  • arg[in] Pointer to a custom argument storing a pointer onto the text message to encode.

Returns:

true if everything went ok, false otherwise.

whad_result_t whad_generic_debug_message(Message *p_message, uint32_t level, char *psz_message)

Initialize a generic debug message.

Parameters:
  • p_message[inout] Pointer to a Messsage structure

  • level[in] Debug level

  • psz_message[in] Pointer to a text string corresponding to the debug message to send

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_generic_progress_message(Message *p_message, uint32_t value)

Initialize a generic progress message.

Parameters:
  • p_message[inout] Pointer to a Messsage structure

  • value[in] Progress value

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_generic_progress_message_parse(Message *p_message, uint32_t *p_value)

Initialize a generic progress message.

Parameters:
  • p_message[in] Pointer to a Messsage structure

  • p_value[inout] Pointer to a progress value

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.