PX4 Firmware
PX4 Autopilot Software http://px4.io
adis16497_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 "
ADIS16497.hpp
"
35
36
#include <px4_platform_common/getopt.h>
37
38
namespace
adis16497
39
{
40
ADIS16497
*
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_SPIDEV_EXTERNAL1_1)
51
g_dev
=
new
ADIS16497
(PX4_SPI_BUS_EXTERNAL1, PX4_SPIDEV_EXTERNAL1_1, rotation);
52
#else
53
PX4_ERR(
"External SPI not available"
);
54
return
-1;
55
#endif
56
57
if
(
g_dev
==
nullptr
) {
58
PX4_ERR(
"driver start failed"
);
59
return
-1;
60
}
61
62
if
(
g_dev
->
init
() != PX4_OK) {
63
PX4_ERR(
"driver init failed"
);
64
delete
g_dev
;
65
g_dev
=
nullptr
;
66
return
-1;
67
}
68
69
return
0;
70
}
71
72
static
int
stop
()
73
{
74
if
(
g_dev
==
nullptr
) {
75
PX4_WARN(
"driver not running"
);
76
return
-1;
77
}
78
79
delete
g_dev
;
80
g_dev
=
nullptr
;
81
82
return
0;
83
}
84
85
static
int
status
()
86
{
87
if
(
g_dev
==
nullptr
) {
88
PX4_INFO(
"driver not running"
);
89
return
0;
90
}
91
92
g_dev
->
print_info
();
93
94
return
0;
95
}
96
97
static
int
usage
()
98
{
99
PX4_INFO(
"missing command: try 'start', 'stop', 'status'"
);
100
PX4_INFO(
"options:"
);
101
PX4_INFO(
" -R rotation"
);
102
103
return
0;
104
}
105
106
}
// namespace adis16497
107
108
extern
"C"
int
adis16497_main
(
int
argc,
char
*argv[])
109
{
110
enum
Rotation
rotation =
ROTATION_NONE
;
111
int
myoptind = 1;
112
int
ch = 0;
113
const
char
*myoptarg =
nullptr
;
114
115
// start options
116
while
((ch = px4_getopt(argc, argv,
"R:"
, &myoptind, &myoptarg)) != EOF) {
117
switch
(ch) {
118
case
'R'
:
119
rotation = (
enum
Rotation
)atoi(myoptarg);
120
break
;
121
122
default
:
123
return
adis16497::usage
();
124
}
125
}
126
127
const
char
*verb = argv[myoptind];
128
129
if
(!strcmp(verb,
"start"
)) {
130
return
adis16497::start
(rotation);
131
132
}
else
if
(!strcmp(verb,
"stop"
)) {
133
return
adis16497::stop
();
134
135
}
else
if
(!strcmp(verb,
"status"
)) {
136
return
adis16497::status
();
137
}
138
139
return
adis16497::usage
();
140
}
adis16497_main
int adis16497_main(int argc, char *argv[])
Definition:
adis16497_main.cpp:108
adis16497::start
static int start(enum Rotation rotation)
Definition:
adis16497_main.cpp:42
ROTATION_NONE
Definition:
rotation.h:52
ADIS16497::init
virtual int init()
Definition:
ADIS16497.cpp:102
adis16497::g_dev
ADIS16497 * g_dev
Definition:
adis16497_main.cpp:40
adis16497::usage
static int usage()
Definition:
adis16497_main.cpp:97
Rotation
Rotation
Enum for board and external compass rotations.
Definition:
rotation.h:51
adis16497
Definition:
adis16497_main.cpp:38
ADIS16497
Definition:
ADIS16497.hpp:86
ADIS16497.hpp
adis16497::status
static int status()
Definition:
adis16497_main.cpp:85
adis16497::stop
static int stop()
Definition:
adis16497_main.cpp:72
ADIS16497::print_info
void print_info()
Definition:
ADIS16497.cpp:466
src
drivers
imu
adis16497
adis16497_main.cpp
Generated by
1.8.13