forked from LORD-MicroStrain/mip_sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_info.cpp
79 lines (66 loc) · 2.53 KB
/
device_info.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/////////////////////////////////////////////////////////////////////////////
//
// device_info.cpp
//
// C++ example program to print device information from any mip-enabled MicroStrain device.
//
//!@section LICENSE
//!
//! THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING
//! CUSTOMERS WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER
//! FOR THEM TO SAVE TIME. AS A RESULT, HBK MICROSTRAIN SHALL NOT BE HELD
//! LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY
//! CLAIMS ARISING FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS
//! OF THE CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
//
/////////////////////////////////////////////////////////////////////////////
#include "example_utils.hpp"
#include <mip/definitions/commands_base.hpp>
#include <stdexcept>
#include <vector>
#include <cstring>
#include <stdio.h>
int main(int argc, const char* argv[])
{
try
{
std::unique_ptr<ExampleUtils> utils = handleCommonArgs(argc, argv);
std::unique_ptr<mip::DeviceInterface>& device = utils->device;
mip::commands_base::BaseDeviceInfo device_info;
mip::CmdResult result = mip::commands_base::getDeviceInfo(*device, &device_info);
if( result == mip::CmdResult::ACK_OK)
{
printf("Success:\n");
auto print_info = [](const char* name, const char info[16])
{
char msg[17] = {0};
std::strncpy(msg, info, 16);
printf(" %s%s\n", name, msg);
};
print_info("Model name: ", device_info.model_name);
print_info("Model number: ", device_info.model_number);
print_info("Serial Number: ", device_info.serial_number);
print_info("Device Options: ", device_info.device_options);
print_info("Lot Number: ", device_info.lot_number);
printf( " Firmware version: %d.%d.%d\n\n",
(device_info.firmware_version / 1000),
(device_info.firmware_version / 100) % 10,
(device_info.firmware_version / 1) % 100
);
}
else
{
printf("Error: command completed with NACK: %s (%d)\n", result.name(), result.value);
}
}
catch(const std::underflow_error& ex)
{
return printCommonUsage(argv);
}
catch(const std::exception& ex)
{
fprintf(stderr, "Error: %s\n", ex.what());
return 1;
}
return 0;
}