AP_Beacon: combine duplicate checks into device_ready method
This commit is contained in:
parent
3551609a21
commit
6045612011
@ -103,7 +103,7 @@ bool AP_Beacon::enabled(void)
|
|||||||
// return true if sensor is basically healthy (we are receiving data)
|
// return true if sensor is basically healthy (we are receiving data)
|
||||||
bool AP_Beacon::healthy(void)
|
bool AP_Beacon::healthy(void)
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None) {
|
if (!device_ready()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return _driver->healthy();
|
return _driver->healthy();
|
||||||
@ -112,7 +112,7 @@ bool AP_Beacon::healthy(void)
|
|||||||
// update state. This should be called often from the main loop
|
// update state. This should be called often from the main loop
|
||||||
void AP_Beacon::update(void)
|
void AP_Beacon::update(void)
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None) {
|
if (!device_ready()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_driver->update();
|
_driver->update();
|
||||||
@ -121,7 +121,7 @@ void AP_Beacon::update(void)
|
|||||||
// return origin of position estimate system
|
// return origin of position estimate system
|
||||||
bool AP_Beacon::get_origin(Location &origin_loc) const
|
bool AP_Beacon::get_origin(Location &origin_loc) const
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None) {
|
if (!device_ready()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ bool AP_Beacon::get_origin(Location &origin_loc) const
|
|||||||
// return position in NED from position estimate system's origin
|
// return position in NED from position estimate system's origin
|
||||||
bool AP_Beacon::get_vehicle_position_ned(Vector3f &position, float& accuracy_estimate) const
|
bool AP_Beacon::get_vehicle_position_ned(Vector3f &position, float& accuracy_estimate) const
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None) {
|
if (!device_ready()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ bool AP_Beacon::get_vehicle_position_ned(Vector3f &position, float& accuracy_est
|
|||||||
// return the number of beacons
|
// return the number of beacons
|
||||||
uint8_t AP_Beacon::count() const
|
uint8_t AP_Beacon::count() const
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None) {
|
if (!device_ready()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return num_beacons;
|
return num_beacons;
|
||||||
@ -169,7 +169,7 @@ uint8_t AP_Beacon::count() const
|
|||||||
// return all beacon data
|
// return all beacon data
|
||||||
bool AP_Beacon::get_beacon_data(uint8_t beacon_instance, struct BeaconState& state) const
|
bool AP_Beacon::get_beacon_data(uint8_t beacon_instance, struct BeaconState& state) const
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None || beacon_instance >= num_beacons) {
|
if (!device_ready() || beacon_instance >= num_beacons) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
state = beacon_state[beacon_instance];
|
state = beacon_state[beacon_instance];
|
||||||
@ -206,7 +206,7 @@ float AP_Beacon::beacon_distance(uint8_t beacon_instance) const
|
|||||||
// return beacon position
|
// return beacon position
|
||||||
Vector3f AP_Beacon::beacon_position(uint8_t beacon_instance) const
|
Vector3f AP_Beacon::beacon_position(uint8_t beacon_instance) const
|
||||||
{
|
{
|
||||||
if (_driver == nullptr || _type == AP_BeaconType_None || beacon_instance >= num_beacons) {
|
if (!device_ready() || beacon_instance >= num_beacons) {
|
||||||
Vector3f temp = {};
|
Vector3f temp = {};
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@ -221,3 +221,9 @@ uint32_t AP_Beacon::beacon_last_update_ms(uint8_t beacon_instance) const
|
|||||||
}
|
}
|
||||||
return beacon_state[beacon_instance].distance_update_ms;
|
return beacon_state[beacon_instance].distance_update_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the device is ready
|
||||||
|
bool AP_Beacon::device_ready(void) const
|
||||||
|
{
|
||||||
|
return ((_driver != nullptr) && (_type != AP_BeaconType_None));
|
||||||
|
}
|
||||||
|
@ -92,6 +92,10 @@ public:
|
|||||||
static const struct AP_Param::GroupInfo var_info[];
|
static const struct AP_Param::GroupInfo var_info[];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// check if device is ready
|
||||||
|
bool device_ready(void) const;
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
AP_Int8 _type;
|
AP_Int8 _type;
|
||||||
AP_Float origin_lat;
|
AP_Float origin_lat;
|
||||||
|
Loading…
Reference in New Issue
Block a user