MIP_SDK  v3.0.0-736-g212583cf
MicroStrain Communications Library for embedded systems
Functions
MIP Packet Example [C]

Example program to create raw and buffered MIP packets using C. More...

Functions

static void print_packet (const mip_packet_view *_packet_view)
 Prints detailed information about a MIP packet's structure and contents. More...
 
static void initialize_empty_packet (mip_packet_view *_packet_view, uint8_t *_buffer, const size_t _buffer_size, const uint8_t _descriptor_set)
 Initializes an empty MIP packet with the specified descriptor set. More...
 
static void add_checksum_to_packet (mip_packet_view *_packet_view)
 Computes and adds a checksum to a MIP packet. More...
 
static void add_ping_command_to_packet (mip_packet_view *_packet_view)
 Adds a Ping command field to a MIP packet. More...
 
static void add_comm_speed_bytes_to_packet (mip_packet_view *_packet_view)
 Adds a Comm Speed command field using raw bytes. More...
 
static void add_comm_speed_field_to_packet (mip_packet_view *_packet_view)
 Adds a Comm Speed command field using a field struct. More...
 
static void add_comm_speed_serializer_bytes_to_packet (mip_packet_view *_packet_view)
 Adds a Comm Speed command field using manual serialization. More...
 
static void add_message_format_field_to_packet (mip_packet_view *_packet_view)
 Adds a Message Format command field using a field struct definition. More...
 
static void add_poll_data_field_to_packet (mip_packet_view *_packet_view)
 Adds a Poll Data command field using manual serialization. More...
 
static void extract_shared_reference_time_field (microstrain_serializer *_serializer)
 Extracts and displays shared reference time field data. More...
 
static void extract_shared_reference_time_delta_field (microstrain_serializer *_serializer)
 Extracts and displays shared reference time delta field data. More...
 
static void extract_sensor_accel_scaled_field (microstrain_serializer *_serializer)
 Extracts and displays scaled accelerometer data. More...
 
static void extract_sensor_gyro_scaled_field (microstrain_serializer *_serializer)
 Extracts and displays scaled gyroscope data. More...
 
static void extract_sensor_delta_theta_field (microstrain_serializer *_serializer)
 Extracts and displays delta theta (angular displacement) data. More...
 
static void extract_sensor_delta_velocity_field (const mip_field_view *_field_view)
 Extracts and displays delta velocity data. More...
 
static void create_from_scratch_packet_1 ()
 Creates a MIP packet from scratch with multiple fields. More...
 
static void create_from_scratch_packet_2_and_3 ()
 Creates two MIP packets from scratch for demonstration purposes. More...
 
static void create_from_raw_buffer_packet_4 ()
 Demonstrates creating and working with a MIP packet from raw buffer data. More...
 

Detailed Description

For this example, we have broken down each piece into separate functions for easier documentation and is not necessary in practice. This is not an exhaustive example of all MIP packet features. If this example does not meet your specific setup needs, please consult the MIP SDK API documentation for the proper commands.

License

Function Documentation

◆ print_packet()

static void print_packet ( const mip_packet_view *  _packet_view)
static

This function inspects and displays:

  • Total packet length
  • Raw packet bytes in hex format
  • MIP SYNC bytes
  • Descriptor set
  • Payload length
  • Field information for each field in the packet
  • Checksum values and validity
Parameters
_packet_viewPointer to the MIP packet view to inspect

◆ initialize_empty_packet()

static void initialize_empty_packet ( mip_packet_view *  _packet_view,
uint8_t *  _buffer,
const size_t  _buffer_size,
const uint8_t  _descriptor_set 
)
static

Creates a new MIP packet in the provided buffer and initializes it with the given descriptor set. The packet is initially empty and invalid until fields are added.

Parameters
_packet_viewPointer to packet view to initialize
_bufferBuffer to store the packet data
_buffer_sizeSize of the buffer in bytes
_descriptor_setDescriptor set to use for the packet

◆ add_checksum_to_packet()

static void add_checksum_to_packet ( mip_packet_view *  _packet_view)
static

Finalizes the packet by computing and appending the checksum. This should be called after all fields have been added to the packet.

Parameters
_packet_viewPointer to the packet to finalize with checksum

◆ add_ping_command_to_packet()

static void add_ping_command_to_packet ( mip_packet_view *  _packet_view)
static

Creates a field with the Base Ping command descriptor (0x01) with no payload data.

Remarks
Field 1
Parameters
_packet_viewPointer to the packet to add the field to

◆ add_comm_speed_bytes_to_packet()

static void add_comm_speed_bytes_to_packet ( mip_packet_view *  _packet_view)
static

Demonstrates adding a field using pre-serialized payload data. This is the most efficient method when payload data is already available.

Remarks
Field 2
Parameters
_packet_viewPointer to the packet to add the field to

◆ add_comm_speed_field_to_packet()

static void add_comm_speed_field_to_packet ( mip_packet_view *  _packet_view)
static

Shows how to add a field using the field struct definitions, which is the recommended approach for creating fields from parameter values.

Remarks
Field 3
Parameters
_packet_viewPointer to the packet to add the field to

◆ add_comm_speed_serializer_bytes_to_packet()

static void add_comm_speed_serializer_bytes_to_packet ( mip_packet_view *  _packet_view)
static

Demonstrates low-level field creation by manually serializing parameters. Shows the underlying process that happens with struct-based methods.

Remarks
Field 4
Note
This is exactly the same as field 3 but without the helper functions. This is intended to show what happens "behind the scenes".
Parameters
_packet_viewPointer to the packet to add the field to

◆ add_message_format_field_to_packet()

static void add_message_format_field_to_packet ( mip_packet_view *  _packet_view)
static

Creates a field for configuring the message format with multiple descriptors, showing how to handle variable-length payloads.

Remarks
Field 5
Note
Similar to field 3 except that we have a variable-length payload. Again, this is the recommended method for field creation.
Parameters
_packet_viewPointer to the packet to add the field to

◆ add_poll_data_field_to_packet()

static void add_poll_data_field_to_packet ( mip_packet_view *  _packet_view)
static

Shows how to create a field with a variable-length payload by manually serializing parameters and handling field length updates.

Remarks
Field 6
Note
This is similar to field 4 except with a variable-length payload. This is also similar to field 5 but with lower level function calls and a slightly different command.
Parameters
_packet_viewPointer to the packet to add the field to

◆ extract_shared_reference_time_field()

static void extract_shared_reference_time_field ( microstrain_serializer *  _serializer)
static

Deserializes a 64-bit nanosecond timestamp from the field payload and displays it if successfully extracted. This represents the device's reference time.

Parameters
_serializerPointer to the serializer containing the field data

◆ extract_shared_reference_time_delta_field()

static void extract_shared_reference_time_delta_field ( microstrain_serializer *  _serializer)
static

Deserializes a 64-bit nanosecond time difference from the field payload and displays it if successfully extracted. This represents the time elapsed since the last reference time.

Parameters
_serializerPointer to the serializer containing the field data

◆ extract_sensor_accel_scaled_field()

static void extract_sensor_accel_scaled_field ( microstrain_serializer *  _serializer)
static

Deserializes a 3D vector of float values representing scaled accelerometer measurements in m/s^2 and displays them if successfully extracted.

Parameters
_serializerPointer to the serializer containing the field data

◆ extract_sensor_gyro_scaled_field()

static void extract_sensor_gyro_scaled_field ( microstrain_serializer *  _serializer)
static

Deserializes a 3D vector of float values representing scaled gyroscope measurements in rad/s using the field structure. Displays the values if successfully extracted.

Parameters
_serializerPointer to the serializer containing the field data

◆ extract_sensor_delta_theta_field()

static void extract_sensor_delta_theta_field ( microstrain_serializer *  _serializer)
static

Deserializes a 3D vector of float values representing angular displacement measurements in radians using the field structure. Displays the values if successfully extracted.

Parameters
_serializerPointer to the serializer containing the field data

◆ extract_sensor_delta_velocity_field()

static void extract_sensor_delta_velocity_field ( const mip_field_view *  _field_view)
static

Deserializes a 3D vector of float values representing velocity change measurements in m/s using the field structure. Displays the values if successfully extracted.

Parameters
_field_viewPointer to the field view containing the data

◆ create_from_scratch_packet_1()

static void create_from_scratch_packet_1 ( )
static

This function demonstrates how to create a MIP packet containing multiple fields and a checksum. It creates a packet with the following structure:

  1. Initial checksum
  2. Ping command field
  3. Comm speed bytes field
  4. Comm speed field
  5. Comm speed serializer bytes field
  6. Final checksum

The function shows several important concepts:

  • Creating an empty packet with a buffer
  • Initializing a packet with a descriptor set
  • Adding multiple fields to a packet
  • Adding checksums at different stages
  • Proper packet completion sequence
Note
This is a demonstration function showing how to build a complex MIP packet from scratch. The packet created would typically be sent to a device immediately after creation.
See also
initialize_empty_packet
add_checksum_to_packet
add_ping_command_to_packet
add_comm_speed_bytes_to_packet
add_comm_speed_field_to_packet
add_comm_speed_serializer_bytes_to_packet

◆ create_from_scratch_packet_2_and_3()

static void create_from_scratch_packet_2_and_3 ( )
static

This function demonstrates how to create two different types of MIP packets:

  1. A 3DM Message Format command packet (Packet 2)
  2. A 3DM Poll Data command packet (Packet 3)

The function shows the process of:

  • Initializing an empty packet
  • Different ways of adding fields to the packet
  • Adding checksums
  • Resetting and reusing the packet buffer
Note
This is a demonstration function and the packets created would typically be sent to a device immediately after creation
See also
initialize_empty_packet
add_message_format_field_to_packet
add_poll_data_field_to_packet
add_checksum_to_packet
mip_packet_reset
print_packet

◆ create_from_raw_buffer_packet_4()

static void create_from_raw_buffer_packet_4 ( )
static

This function shows how to:

  • Create a packet view from existing raw buffer data
  • Validate the packet structure and checksum
  • Access and display packet contents
  • Extract specific sensor data fields based on their descriptors
  • Process field data using the serialization tools
Remarks
The example uses a hardcoded packet containing multiple sensor data fields for demonstration purposes.
Note
This is typically not done and is used to demonstrate how to extract data from a raw buffer
See also
print_packet
extract_shared_reference_time_field
extract_sensor_accel_scaled_field
extract_sensor_gyro_scaled_field
extract_sensor_delta_theta_field
extract_sensor_delta_velocity_field