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

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

Macros

#define USE_MANUAL_BUFFERS   false
 Whether to create packets with a user-defined buffer or not. More...
 

Functions

static void printPacket (const mip::PacketView &_packetView)
 Prints detailed information about a MIP packet's structure and contents. More...
 
static mip::PacketBuf initializeEmptyPacket (const uint8_t _descriptorSet)
 Creates an empty MIP packet using automatic buffer management. More...
 
static void addChecksumToPacket (mip::PacketView &_packetView)
 Computes and adds a checksum to a MIP packet. More...
 
static void addPingCommandToPacket (mip::PacketView &_packetView)
 Adds a Ping command field to a MIP packet. More...
 
static void addCommSpeedBytesToPacket (mip::PacketView &_packetView)
 Adds a Comm Speed command field using raw bytes. More...
 
static void addCommSpeedFieldToPacket (mip::PacketView &_packetView)
 Adds a Comm Speed command field using a field struct. More...
 
static void addCommSpeedSerializerBytesToPacket (mip::PacketView &_packetView)
 Adds a Comm Speed command field using manual serialization. More...
 
static void addMessageFormatFieldToPacket (mip::PacketView &_packetView)
 Adds a Message Format command field using a field struct definition. More...
 
static void addPollDataFieldToPacket (mip::PacketView &_packetView)
 Adds a Poll Data command field using manual serialization. More...
 
static void extractSharedReferenceTimeField (mip::Serializer &_serializer)
 Extracts and displays shared reference time field data. More...
 
static void extractSharedReferenceTimeDeltaField (mip::Serializer &_serializer)
 Extracts and displays shared reference time delta field data. More...
 
static void extractSensorAccelScaledField (mip::Serializer &_serializer)
 Extracts and displays scaled accelerometer data. More...
 
static void extractSensorGyroScaledField (mip::Serializer &_serializer)
 Extracts and displays scaled gyroscope data. More...
 
static void extractSensorDeltaThetaField (mip::Serializer &_serializer)
 Extracts and displays delta theta (angular displacement) data. More...
 
static void extractSensorDeltaVelocityField (const mip::FieldView &_fieldView)
 Extracts and displays delta velocity data. More...
 
static void createFromScratchPacket1 ()
 Creates a MIP packet from scratch with multiple fields. More...
 
static void createFromScratchPacket2And3 ()
 Creates two MIP packets from scratch for demonstration purposes. More...
 
static void createFromRawBufferPacket4 ()
 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

Macro Definition Documentation

◆ USE_MANUAL_BUFFERS

#define USE_MANUAL_BUFFERS   false
Note
Manual buffers are a similar approach to the C API of the MIP SDK

Function Documentation

◆ printPacket()

static void printPacket ( const mip::PacketView _packetView)
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
_packetViewReference to the MIP packet view to inspect

◆ initializeEmptyPacket()

static mip::PacketBuf initializeEmptyPacket ( const uint8_t  _descriptorSet)
static

Initializes a MIP packet using the PacketBuf class which handles buffer allocation internally. This demonstrates the higher-level packet creation API. The packet is initially empty and invalid until fields are added.

Parameters
_descriptorSetDescriptor set to use for the packet
Returns
A PacketBuf containing the initialized packet

◆ addChecksumToPacket()

static void addChecksumToPacket ( mip::PacketView _packetView)
static

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

Parameters
_packetViewReference to the packet to finalize with checksum

◆ addPingCommandToPacket()

static void addPingCommandToPacket ( mip::PacketView _packetView)
static

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

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

◆ addCommSpeedBytesToPacket()

static void addCommSpeedBytesToPacket ( mip::PacketView _packetView)
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
_packetViewReference to the packet to add the field to

◆ addCommSpeedFieldToPacket()

static void addCommSpeedFieldToPacket ( mip::PacketView _packetView)
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
_packetViewReference to the packet to add the field to

◆ addCommSpeedSerializerBytesToPacket()

static void addCommSpeedSerializerBytesToPacket ( mip::PacketView _packetView)
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
_packetViewReference to the packet to add the field to

◆ addMessageFormatFieldToPacket()

static void addMessageFormatFieldToPacket ( mip::PacketView _packetView)
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
_packetViewReference to the packet to add the field to

◆ addPollDataFieldToPacket()

static void addPollDataFieldToPacket ( mip::PacketView _packetView)
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
_packetViewReference to the packet to add the field to

◆ extractSharedReferenceTimeField()

static void extractSharedReferenceTimeField ( mip::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
_serializerReference to the serializer containing the field data

◆ extractSharedReferenceTimeDeltaField()

static void extractSharedReferenceTimeDeltaField ( mip::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
_serializerReference to the serializer containing the field data

◆ extractSensorAccelScaledField()

static void extractSensorAccelScaledField ( mip::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
_serializerReference to the serializer containing the field data

◆ extractSensorGyroScaledField()

static void extractSensorGyroScaledField ( mip::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
_serializerReference to the serializer containing the field data

◆ extractSensorDeltaThetaField()

static void extractSensorDeltaThetaField ( mip::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
_serializerReference to the serializer containing the field data

◆ extractSensorDeltaVelocityField()

static void extractSensorDeltaVelocityField ( const mip::FieldView _fieldView)
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
_fieldViewReference to the field view containing the data

◆ createFromScratchPacket1()

static void createFromScratchPacket1 ( )
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
initializeEmptyPacket
addChecksumToPacket
addPingCommandToPacket
addCommSpeedBytesToPacket
addCommSpeedFieldToPacket
addCommSpeedSerializerBytesToPacket

◆ createFromScratchPacket2And3()

static void createFromScratchPacket2And3 ( )
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
initializeEmptyPacket
addMessageFormatFieldToPacket
addPollDataFieldToPacket
addChecksumToPacket
mip::PacketView::reset
printPacket

◆ createFromRawBufferPacket4()

static void createFromRawBufferPacket4 ( )
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
printPacket
extractSharedReferenceTimeField
extractSensorAccelScaledField
extractSensorGyroScaledField
extractSensorDeltaThetaField
extractSensorDeltaVelocityField