PX4 Firmware
PX4 Autopilot Software http://px4.io
adis16448_main.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* Copyright (c) 2018-2019 PX4 Development Team. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
*
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in
13
* the documentation and/or other materials provided with the
14
* distribution.
15
* 3. Neither the name PX4 nor the names of its contributors may be
16
* used to endorse or promote products derived from this software
17
* without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
* POSSIBILITY OF SUCH DAMAGE.
31
*
32
****************************************************************************/
33
34
#include "
ADIS16448.h
"
35
36
#include <px4_platform_common/getopt.h>
37
38
namespace
adis16448
39
{
40
ADIS16448
*
g_dev
{
nullptr
};
41
42
static
int
start
(
enum
Rotation
rotation)
43
{
44
if
(
g_dev
!=
nullptr
) {
45
PX4_WARN(
"already started"
);
46
return
0;
47
}
48
49
// create the driver
50
#if defined(PX4_SPI_BUS_EXT)
51
g_dev
=
new
ADIS16448
(PX4_SPI_BUS_EXT, PX4_SPIDEV_EXT_MPU, rotation);
52
#elif defined(PX4_SPIDEV_EXTERNAL1_1)
53
g_dev
=
new
ADIS16448
(PX4_SPI_BUS_EXTERNAL1, PX4_SPIDEV_EXTERNAL1_1, rotation);
54
#else
55
PX4_ERR(
"External SPI not available"
);
56
return
-1;
57
#endif
58
59
if
(
g_dev
==
nullptr
) {
60
PX4_ERR(
"driver start failed"
);
61
return
-1;
62
}
63
64
if
(
g_dev
->
init
() != PX4_OK) {
65
PX4_ERR(
"driver init failed"
);
66
delete
g_dev
;
67
g_dev
=
nullptr
;
68
return
-1;
69
}
70
71
return
0;
72
}
73
74
static
int
stop
()
75
{
76
if
(
g_dev
==
nullptr
) {
77
PX4_WARN(
"driver not running"
);
78
return
-1;
79
}
80
81
delete
g_dev
;
82
g_dev
=
nullptr
;
83
84
return
0;
85
}
86
87
static
int
status
()
88
{
89
if
(
g_dev
==
nullptr
) {
90
PX4_INFO(
"driver not running"
);
91
return
0;
92
}
93
94
g_dev
->
print_info
();
95
96
return
0;
97
}
98
99
static
int
usage
()
100
{
101
PX4_INFO(
"missing command: try 'start', 'stop', 'status'"
);
102
PX4_INFO(
"options:"
);
103
PX4_INFO(
" -R rotation"
);
104
105
return
0;
106
}
107
108
}
// namespace adis16448
109
110
extern
"C"
int
adis16448_main
(
int
argc,
char
*argv[])
111
{
112
enum
Rotation
rotation =
ROTATION_NONE
;
113
int
myoptind = 1;
114
int
ch = 0;
115
const
char
*myoptarg =
nullptr
;
116
117
// start options
118
while
((ch = px4_getopt(argc, argv,
"R:"
, &myoptind, &myoptarg)) != EOF) {
119
switch
(ch) {
120
case
'R'
:
121
rotation = (
enum
Rotation
)atoi(myoptarg);
122
break
;
123
124
default
:
125
return
adis16448::usage
();
126
}
127
}
128
129
const
char
*verb = argv[myoptind];
130
131
if
(!strcmp(verb,
"start"
)) {
132
return
adis16448::start
(rotation);
133
134
}
else
if
(!strcmp(verb,
"stop"
)) {
135
return
adis16448::stop
();
136
137
}
else
if
(!strcmp(verb,
"status"
)) {
138
return
adis16448::status
();
139
}
140
141
return
adis16448::usage
();
142
}
adis16448::start
static int start(enum Rotation rotation)
Definition:
adis16448_main.cpp:42
adis16448::g_dev
ADIS16448 * g_dev
Definition:
adis16448_main.cpp:40
ADIS16448::print_info
void print_info()
Diagnostics - print some basic information about the driver and sensor.
Definition:
ADIS16448.cpp:313
adis16448::stop
static int stop()
Definition:
adis16448_main.cpp:74
adis16448_main
int adis16448_main(int argc, char *argv[])
Definition:
adis16448_main.cpp:110
ROTATION_NONE
Definition:
rotation.h:52
ADIS16448.h
Rotation
Rotation
Enum for board and external compass rotations.
Definition:
rotation.h:51
ADIS16448::init
virtual int init()
Definition:
ADIS16448.cpp:73
adis16448::usage
static int usage()
Definition:
adis16448_main.cpp:99
adis16448::status
static int status()
Definition:
adis16448_main.cpp:87
adis16448
Definition:
adis16448_main.cpp:38
ADIS16448
Definition:
ADIS16448.h:101
src
drivers
imu
adis16448
adis16448_main.cpp
Generated by
1.8.13