Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

MIP Packet Example (C++)

This example demonstrates how to create, manipulate, and work with raw and buffered MIP packets with the MIP SDK using the C++ API.

Overview

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

Configuration

This example does not require device connection and works entirely with in-memory packet operations.

Usage

  1. Compile and run the example (no device connection required)
  2. The program will:
    • Create various MIP packets
    • Demonstrate packet manipulation
    • Show serialization/deserialization
    • Display packet contents
    • Validate packet integrity
    • Clean up and exit

Building

With CMake (Recommended)

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.

Standalone Command Line

mkdir build
cd build
cmake .. -DMIP_SDK_ROOT_DIR:PATH=<path_to_mip_sdk>

Without CMake

If the project cannot be configured using CMake, then the following project configurations are required:

Required Libraries

Link against these libraries:

  • mip - Core MIP SDK library
  • microstrain - Core MicroStrain SDK library

Make sure to include those library paths as additional link directories if needed

Include Directories

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

Key Functions

Packet Creation and Management

  • initializeEmptyPacket() - Creates an empty packet for a given descriptor set
  • addChecksumToPacket() - Computes and adds the checksum to a packet
  • printPacket() - Displays packet contents and structure

Field Addition Functions

  • Functions to add various MIP data fields to packets
  • Support for different data types (sensor, shared, command data)
  • Proper field serialization and formatting

Packet Utilities

  • Packet validation and integrity checking
  • Buffer management for packet storage
  • Cross-platform packet handling

Data Handling

This example uses modern C++ features including:

  • Type Safety: Strongly typed data structures for each message type
  • String Handling: Safe C++ string operations

C++ Implementation Features

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)

Packet Operations Demonstrated

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

MIP Descriptor Sets

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

Packet Output Format

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

Error Handling

The example includes comprehensive error handling with:

  • Packet validation checks
  • Buffer overflow protection
  • Serialization error detection

C++ Features

This example demonstrates:

  • Type-safe MIP command interfaces
  • RAII resource management
  • Standard library integration

Type Safety and Documentation

This example provides additional C++ benefits:

  • Built-in Documentation: Data structures include DOC_NAME constants for easy reference
  • Strongly Typed Enums: C++ enum classes prevent accidental misuse
  • Automatic Descriptors: DESCRIPTOR constants eliminate magic numbers

Use Cases

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

Requirements

  • MIP SDK library with C++ support
  • C++11 or later compiler
  • No device connection required

See Also

  • C version: mip_packet_example.c
  • Other examples in the examples/ directory
  • MIP SDK documentation
  • MIP Protocol specification