This example demonstrates how to create, manipulate, and work with raw and buffered MIP packets with the MIP SDK using the C++ API.
The example showcases basic MIP packet operations, including:
- Creating empty MIP packets
- Adding data fields to packets
- Computing and adding checksums
- Packet serialization and deserialization
- Working with different MIP descriptor sets
- Packet validation and error handling
This example does not require device connection and works entirely with in-memory packet operations.
- Compile and run the example (no device connection required)
- The program will:
- Create various MIP packets
- Demonstrate packet manipulation
- Show serialization/deserialization
- Display packet contents
- Validate packet integrity
- Clean up and exit
The project can be configured on its own using the supplied CMakeLists.txt.
The file is configured to work directly in the MIP SDK project or as a standalone project.
If building outside the MIP SDK project, all that's needed is to define MIP_SDK_ROOT_DIR.
When building within the MIP SDK project, make sure to enable the examples using the MICROSTRAIN_BUILD_EXAMPLES
CMake option.
mkdir build
cd build
cmake .. -DMIP_SDK_ROOT_DIR:PATH=<path_to_mip_sdk>If the project cannot be configured using CMake, then the following project configurations are required:
Link against these libraries:
mip- Core MIP SDK librarymicrostrain- Core MicroStrain SDK library
Make sure to include those library paths as additional link directories if needed
Add these include directories:
[path_to_mip_sdk_include]/c[path_to_mip_sdk_include]/cpp[path_to_project_root]
path_to_mip_sdk_include can be installed paths or source paths:
- Unix -
/usr/include/microstrain - Windows -
C:/Program Files/MIP_SDK/include/microstrain - Source:
[mip_sdk_project_root]/src
initializeEmptyPacket()- Creates an empty packet for a given descriptor setaddChecksumToPacket()- Computes and adds the checksum to a packetprintPacket()- Displays packet contents and structure
- Functions to add various MIP data fields to packets
- Support for different data types (sensor, shared, command data)
- Proper field serialization and formatting
- Packet validation and integrity checking
- Buffer management for packet storage
- Cross-platform packet handling
This example uses modern C++ features including:
- Type Safety: Strongly typed data structures for each message type
- String Handling: Safe C++ string operations
This example demonstrates:
- Modern C++ Packet API: RAII-based packet management
- Type-Safe MIP Command Interfaces: Compile-time type checking
- Exception Safety: Proper error handling and resource cleanup
- STL Integration: Use of standard library containers and algorithms
- Portability: Cross-platform compatibility (Windows/Unix)
The example covers the following packet operations:
- Empty Packet Creation: Initialize packets for different descriptor sets
- Field Addition: Add various data fields to packets
- Checksum Calculation: Compute and validate packet checksums
- Packet Validation: Verify packet structure and integrity
- Buffer Operations: Manage packet buffers and memory
- Data Extraction: Parse and extract data from packets
The example works with various MIP descriptor sets:
- Base Commands: Fundamental device commands
- 3DM Commands: Device management commands
- Sensor Data: IMU and sensor data fields
- Shared Data: Common data structures across devices
The example displays packet information in the following format:
Packet information:
Packet Length = 16
Raw Packet = 7565010A0201080901010001C200BE2F
MIP SYNC1 = 0x75
MIP SYNC2 = 0x65
Descriptor Set = 0x01
Payload Length = 0x0A
Fields:
Field Length = 0x02
Field Descriptor = 0x01
Raw Payload =
Field Length = 0x08
Field Descriptor = 0x09
Raw Payload = 01010001C200
Checksum (Valid):
MSB = 0xBE
LSB = 0x2F
The example includes comprehensive error handling with:
- Packet validation checks
- Buffer overflow protection
- Serialization error detection
This example demonstrates:
- Type-safe MIP command interfaces
- RAII resource management
- Standard library integration
This example provides additional C++ benefits:
- Built-in Documentation: Data structures include
DOC_NAMEconstants for easy reference - Strongly Typed Enums: C++ enum classes prevent accidental misuse
- Automatic Descriptors:
DESCRIPTORconstants eliminate magic numbers
This example is useful for:
- Understanding MIP packet structure
- Custom packet creation and parsing
- Debugging communication issues
- Learning MIP protocol internals
- Building custom MIP applications
- MIP SDK library with C++ support
- C++11 or later compiler
- No device connection required
- C version:
mip_packet_example.c - Other examples in the
examples/directory - MIP SDK documentation
- MIP Protocol specification