1
0
Fork 0

MarkerBeacon uses AbstractInstrument

This commit is contained in:
James Turner 2019-06-03 14:32:38 +01:00
parent a26c671200
commit aad582f2c3
4 changed files with 39 additions and 62 deletions

View file

@ -26,7 +26,10 @@ void AbstractInstrument::readConfig(SGPropertyNode* config,
{
_name = config->getStringValue("name", defaultName.c_str());
_index = config->getIntValue("number", 0);
_powerSupplyPath = "/systems/electrical/outputs/" + defaultName;
if (_powerSupplyPath.empty()) {
_powerSupplyPath = "/systems/electrical/outputs/" + defaultName;
}
if (config->hasChild("power-supply")) {
_powerSupplyPath = config->getStringValue("power-supply");
}
@ -79,6 +82,11 @@ bool AbstractInstrument::isServiceableAndPowered() const
return true;
}
void AbstractInstrument::setDefaultPowerSupplyPath(const std::string &p)
{
_powerSupplyPath = p;
}
void AbstractInstrument::setMinimumSupplyVolts(double v)
{
_minimumSupplyVolts = v;

View file

@ -25,6 +25,7 @@ class AbstractInstrument : public SGSubsystem
public:
protected:
void readConfig(SGPropertyNode* config,
std::string defaultName);
@ -42,6 +43,12 @@ protected:
void setMinimumSupplyVolts(double v);
/**
* specify the default path to use to power the instrument, if it's non-
* standard.
*/
void setDefaultPowerSupplyPath(const std::string &p);
virtual bool isPowerSwitchOn() const;
private:
std::string _name;

View file

@ -21,9 +21,7 @@
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <config.h>
#include <stdio.h> // snprintf
@ -32,6 +30,7 @@
#include <simgear/misc/sg_path.hxx>
#include <simgear/sound/sample_group.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/navlist.hxx>
#include "marker_beacon.hxx"
@ -42,31 +41,14 @@ using std::string;
// Constructor
FGMarkerBeacon::FGMarkerBeacon(SGPropertyNode *node) :
audio_vol(NULL),
outer_blink(false),
middle_blink(false),
inner_blink(false),
name("marker-beacon"),
num(0),
_time_before_search_sec(0.0),
_sgr(NULL)
_time_before_search_sec(0.0)
{
for ( int i = 0; i < node->nChildren(); ++i ) {
SGPropertyNode *child = node->getChild(i);
string cname = child->getName();
string cval = child->getStringValue();
if ( cname == "name" ) {
name = cval;
} else if ( cname == "number" ) {
num = child->getIntValue();
} else {
SG_LOG( SG_INSTR, SG_WARN,
"Error in marker beacon config logic" );
if ( name.length() ) {
SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
}
}
}
// backwards-compatability supply path
setDefaultPowerSupplyPath("/systems/electrical/outputs/nav[0]");
readConfig(node, "marker-beacon");
}
@ -79,27 +61,19 @@ FGMarkerBeacon::~FGMarkerBeacon()
void
FGMarkerBeacon::init ()
{
string branch;
branch = "/instrumentation/" + name;
SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
SGPropertyNode *node = fgGetNode(nodePath(), true );
initServicePowerProperties(node);
// Inputs
sound_working = fgGetNode("/sim/sound/working", true);
lon_node = fgGetNode("/position/longitude-deg", true);
lat_node = fgGetNode("/position/latitude-deg", true);
alt_node = fgGetNode("/position/altitude-ft", true);
bus_power = fgGetNode("/systems/electrical/outputs/nav[0]", true);
power_btn = node->getChild("power-btn", 0, true);
audio_btn = node->getChild("audio-btn", 0, true);
audio_vol = node->getChild("volume", 0, true);
serviceable = node->getChild("serviceable", 0, true);
if (power_btn->getType() == simgear::props::NONE)
power_btn->setBoolValue( true );
if (audio_btn->getType() == simgear::props::NONE)
audio_btn->setBoolValue( true );
if (serviceable->getType() == simgear::props::NONE)
serviceable->setBoolValue( true );
SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
_sgr = smgr->find("avionics", true);
@ -119,8 +93,7 @@ FGMarkerBeacon::reinit ()
void
FGMarkerBeacon::bind ()
{
string branch;
branch = "/instrumentation/" + name;
string branch = nodePath();
fgTie((branch + "/inner").c_str(), this,
&FGMarkerBeacon::get_inner_blink);
@ -136,12 +109,13 @@ FGMarkerBeacon::bind ()
void
FGMarkerBeacon::unbind ()
{
string branch;
branch = "/instrumentation/" + name;
string branch = nodePath();
fgUntie((branch + "/inner").c_str());
fgUntie((branch + "/middle").c_str());
fgUntie((branch + "/outer").c_str());
AbstractInstrument::unbind();
}
@ -160,8 +134,7 @@ FGMarkerBeacon::update(double dt)
search();
}
if ( has_power() && serviceable->getBoolValue()
&& sound_working->getBoolValue()) {
if ( isServiceableAndPowered() && sound_working->getBoolValue()) {
// marker beacon blinking
bool light_on = ( outer_blink || middle_blink || inner_blink );
@ -287,7 +260,7 @@ void FGMarkerBeacon::search()
outer_marker = middle_marker = inner_marker = false;
if ( b == NULL || !inrange || !has_power() || !serviceable->getBoolValue() )
if ( b == NULL || !inrange || !isServiceableAndPowered())
{
// cout << "no marker" << endl;
_sgr->stop( "outer-marker" );

View file

@ -24,27 +24,22 @@
#ifndef _FG_MARKER_BEACON_HXX
#define _FG_MARKER_BEACON_HXX
#include <Main/fg_props.hxx>
#include <simgear/compiler.h>
#include <simgear/structure/subsystem_mgr.hxx>
#include <Instrumentation/AbstractInstrument.hxx>
#include <simgear/timing/timestamp.hxx>
class SGSampleGroup;
class FGMarkerBeacon : public SGSubsystem
class FGMarkerBeacon : public AbstractInstrument
{
// Inputs
SGPropertyNode_ptr lon_node;
SGPropertyNode_ptr lat_node;
SGPropertyNode_ptr alt_node;
SGPropertyNode_ptr bus_power;
SGPropertyNode_ptr power_btn;
SGPropertyNode_ptr audio_btn;
SGPropertyNode_ptr audio_vol;
SGPropertyNode_ptr serviceable;
SGPropertyNode_ptr sound_working;
bool outer_marker;
@ -56,9 +51,6 @@ class FGMarkerBeacon : public SGSubsystem
bool middle_blink;
bool inner_blink;
std::string name;
int num;
// internal periodic station search timer
double _time_before_search_sec;
@ -76,11 +68,11 @@ public:
FGMarkerBeacon(SGPropertyNode *node);
~FGMarkerBeacon();
void init ();
void reinit ();
void bind ();
void unbind ();
void update (double dt);
void init () override;
void reinit () override;
void bind () override;
void unbind () override;
void update (double dt) override;
void search ();
@ -88,9 +80,6 @@ public:
inline bool get_inner_blink () const { return inner_blink; }
inline bool get_middle_blink () const { return middle_blink; }
inline bool get_outer_blink () const { return outer_blink; }
inline bool has_power() const {
return power_btn->getBoolValue() && (bus_power->getDoubleValue() > 1.0);
}
};