Example program to create raw and buffered MIP packets using C++.
More...
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
- Copyright
- Copyright (c) 2025 MicroStrain by HBK Licensed under MIT License
◆ USE_MANUAL_BUFFERS
#define USE_MANUAL_BUFFERS false |
- Note
- Manual buffers are a similar approach to the C API of the MIP SDK
◆ printPacket()
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
-
_packetView | Reference 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
-
_descriptorSet | Descriptor set to use for the packet |
- Returns
- A PacketBuf containing the initialized packet
◆ addChecksumToPacket()
Finalizes the packet by computing and appending the checksum. This should be called after all fields have been added to the packet.
- Parameters
-
_packetView | Reference to the packet to finalize with checksum |
◆ addPingCommandToPacket()
Creates a field with the Base Ping command descriptor (0x01) with no payload data.
- Parameters
-
_packetView | Reference to the packet to add the field to |
◆ addCommSpeedBytesToPacket()
Demonstrates adding a field using pre-serialized payload data. This is the most efficient method when payload data is already available.
- Parameters
-
_packetView | Reference to the packet to add the field to |
◆ addCommSpeedFieldToPacket()
Shows how to add a field using the field struct definitions, which is the recommended approach for creating fields from parameter values.
- Parameters
-
_packetView | Reference 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.
- 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
-
_packetView | Reference to the packet to add the field to |
◆ addMessageFormatFieldToPacket()
Creates a field for configuring the message format with multiple descriptors, showing how to handle variable-length payloads.
- Note
- Similar to field 3 except that we have a variable-length payload. Again, this is the recommended method for field creation.
- Parameters
-
_packetView | Reference to the packet to add the field to |
◆ addPollDataFieldToPacket()
Shows how to create a field with a variable-length payload by manually serializing parameters and handling field length updates.
- 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
-
_packetView | Reference 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
-
_serializer | Reference 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
-
_serializer | Reference to the serializer containing the field data |
◆ extractSensorAccelScaledField()
Deserializes a 3D vector of float values representing scaled accelerometer measurements in m/s^2 and displays them if successfully extracted.
- Parameters
-
_serializer | Reference to the serializer containing the field data |
◆ extractSensorGyroScaledField()
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
-
_serializer | Reference to the serializer containing the field data |
◆ extractSensorDeltaThetaField()
Deserializes a 3D vector of float values representing angular displacement measurements in radians using the field structure. Displays the values if successfully extracted.
- Parameters
-
_serializer | Reference 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
-
_fieldView | Reference 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:
- Initial checksum
- Ping command field
- Comm speed bytes field
- Comm speed field
- Comm speed serializer bytes field
- 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:
- A 3DM Message Format command packet (Packet 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 |