LRAUV  revA
NavChartDb Class Reference

Reads a standard electronic navigation chart (ENC) in S-57 format, stores it in a database, and uses the values in the database to estimate nearest contours, coastline, and soundings of a lat/lon pair. More...

#include <NavChartDb.h>

Inheritance diagram for NavChartDb:
Collaboration diagram for NavChartDb:

Classes

class  ClosePoint
 
struct  EncInfo
 

Public Member Functions

 NavChartDb ()
 
virtual ~NavChartDb ()
 
virtual void initialize ()
 Provide a space for initialization before being run. More...
 
virtual void run ()
 The actual "payload" of the component. More...
 
void updateCurrent (const float latitude, const float longitude, bool gotFix)
 Update the curent latitude/longitude pair (in radians) More...
 
float getSeaFloorDepth (const float latitude, const float longitude)
 For a latitude/longitude pair (in radians), return the approximate depth. More...
 
float getDistanceFromShore (const float latitude, const float longitude)
 For a given latitude and longitude (in radians), estimates the distance from the shoreline at that location. More...
 
virtual void uninitialize ()
 Provide a space for uninitialization. More...
 
bool ready ()
 
void setOkToUpdateFromDisk ()
 
void setChartsCfg (const Str chartsCfg)
 
- Public Member Functions inherited from AsyncComponent
bool isIdlePriority ()
 
- Public Member Functions inherited from Component
virtual ~Component ()
 Destructor cleans up readers_ and writers_. More...
 
void registerReader (DataReader *reader)
 
void unregisterReader (DataReader *reader)
 
void registerWriter (DataWriter *writer)
 
void unregisterWriter (DataWriter *writer)
 
void disableMetering (void)
 
FlexArray< DataReader * > & getReaderList (void)
 
FlexArray< DataWriter * > & getWriterList (void)
 
const ModulegetModule ()
 
virtual void configure ()
 Read (or re-read!) configuration settings. More...
 
virtual void execute (void)
 
bool isActive () const
 Indicates if the component is active. More...
 
const CodedStrgetName (void) const
 Returns the name. More...
 
const TimestampgetTimeOfLastRun (void) const
 
ComponentState getState (void)
 Return the component's current state. More...
 
void setState (ComponentState state)
 
RunState getRunState (void)
 Return the component's run state. More...
 
bool isUsingRunState ()
 Return true if using runState. More...
 
void requestData (bool requestingData)
 Tell the component to start (or stop) sending data. More...
 
void requestStart ()
 Tell the component to start runnning. More...
 
void requestPause (const Timespan expectedPauseTime)
 Tell the component to pause runnning. More...
 
void requestResume ()
 Tell the component resume from pause. More...
 
void requestStop ()
 Tell the component to stop runnning. More...
 
virtual RunState start ()
 Do what needs to be done to run Similar to initialize, in old init/run/uninit sequence. More...
 
virtual RunState starting ()
 Might follow a STOP...START sequence Subseqent. More...
 
virtual RunState runnable ()
 Should eventually follow a START request or RESETTING. More...
 
virtual RunState satisfied ()
 Possible return value of a Behavior. More...
 
virtual RunState pause ()
 Pause for a short period (indicated by pauseTime) More...
 
virtual RunState pausing ()
 Might follow a PAUSE request. More...
 
virtual RunState paused ()
 Should eventually follow a PAUSE request: should set continueTime. More...
 
virtual RunState resume ()
 Resume from PAUSE. More...
 
virtual RunState resuming ()
 Might follow a PAUSE...RESUME sequence. More...
 
virtual RunState resetting ()
 Might occur in case of Error. More...
 
virtual RunState stop ()
 Initial state – can be later followed by START. More...
 
virtual RunState stopping ()
 Might follow a STOP request. More...
 
virtual RunState stopped ()
 Should eventually follow a STOP request. More...
 
void setCriticalFailureReported (bool boolVal)
 
void setRecoveringFromCritical (bool boolVal)
 
void setFailureReported (bool boolVal)
 
bool isFailureUninitialized ()
 
void setFailureUninitialized (bool boolVal)
 
void setRetryTimeout (const Timespan &timeout)
 
virtual bool isCompleted (void)
 Query if this component is completed. More...
 
void setPeriod (const Timespan &period)
 Set the period of this component... used if it is periodic. More...
 
const TimespangetPeriod (void)
 Returns the component's period (regardless of whether it is periodic) More...
 
ComponentType getComponentType ()
 Getter function for ComponentType. More...
 
virtual bool isFailed (void) const
 
virtual FailureMode::FailType getFailureType (void) const
 
virtual bool getCriticalFailureReported (void) const
 
virtual bool getFailureReported (void) const
 
virtual Timespan getRetryTimeout (void) const
 
virtual FailureMode::FailType setFailure (FailureMode::FailType failureType)
 
virtual int getFailCount (void) const
 
virtual bool isFailureMissionCritical ()
 
virtual int getAllowableFailures (void) const
 
virtual void setAllowableFailures (int fails)
 
LoggergetLogger (void)
 
virtual int incrementFailCount (void)
 
virtual void resetFailCount (void)
 
virtual int getSkippedRunsSinceFail (void) const
 
virtual int incrementSkippedRunsSinceFail (void)
 
virtual void logVoltage (float voltage, float averageVoltage)
 
virtual void logCurrent (float current, float averageCurrent)
 
const TimestampgetWriteTimestamp (void)
 
void setWriteTimestamp (const Timestamp &writeTimestamp)
 
BlobReadernewBlobReader (const BlobURI &blobURI)
 
BlobReadernewBlobReaderFromUniversal (const Str &componentName, const UniversalBlobURI &blobURI)
 
BlobWriternewBlobWriter (const BlobURI &blobURI, Logger::TimePrecisionType timePrecision=Logger::TIME_PRECISION_MILLIS)
 
ConfigReadernewConfigReader (const ConfigURI &configURI)
 
DataReadernewDataReader (const DataURI &dataURI)
 
DataReadernewDataReaderFromUniversal (const Str &componentName, const UniversalURI &universalURI)
 
DataWriternewDataWriter (const DataURI &dataURI, Logger::TimePrecisionType timePrecision=Logger::TIME_PRECISION_MILLIS)
 
UniversalBlobReadernewUniversalBlobReader (const UniversalBlobURI &universalURI)
 
UniversalBlobWriternewUniversalBlobWriter (const UniversalBlobURI &universalURI, const Unit &accuracyUnit=Units::NONE, const float accuracy=DataElement::NO_ACCURACY, Logger::TimePrecisionType timePrecision=Logger::TIME_PRECISION_MILLIS)
 
UniversalDataReadernewUniversalReader (const UniversalURI &universalURI)
 
UniversalDataWriternewUniversalWriter (const UniversalURI &universalURI, const Unit &accuracyUnit=Units::NONE, const float accuracy=DataElement::NO_ACCURACY, Logger::TimePrecisionType timePrecision=Logger::TIME_PRECISION_MILLIS)
 

Static Public Member Functions

static int CalcGeoIndex (float latitude, float longitude)
 converts a latitude and longitude into a index that covers a small area of the planet (smaller than GEO_GRID_SIZE * GEO_GRID_SIZE ) More...
 
static int MakeGeoIndex (int latIndex, int lonIndex)
 Combines latitude index and longitude index into a single index. More...
 
static int CalcLatIndex (float latitude)
 converts a latitude into a index that covers a small band around the planet More...
 
static int CalcNumLonIndices (int latIndex)
 Returns number of small longitudinal areas in the latIndex band around the planet (each smaller than GEO_GRID_SIZE * GEO_GRID_SIZE) More...
 
static int CalcLonIndex (float longitude, int nLons)
 Calculates longitudinal index of small area in the latIndex band around the planet. More...
 
static NavChartDbGetInstance ()
 

Private Member Functions

 NavChartDb (const NavChartDb &old)
 
void wipeOut ()
 
void updateClosest ()
 For the current latitude/longitude pair (in radians), update closest point on each contour. More...
 
bool initDataDir ()
 
bool saveDepths ()
 
bool loadDepths ()
 
bool createIndices ()
 
bool createSoundings ()
 
bool createContour (const Str *depthStr)
 
bool appendToContour (const Str *depthStr, const int encId, const int resLevel, const float latitude, const float longitude)
 
bool appendToSoundings (const float depth, const int encId, const int resLevel, const float latitude, const float longitude)
 
bool appendToCoverage (const int encId, const int resLevel, const float x0, const float y0, const float x1, const float y1)
 
bool loadCoverage (const int resLevel, EncArea **coverage)
 
bool saveEncs ()
 
bool loadEncs ()
 
bool addEncData (EncInfo *encInfo)
 
StrmapDepth (const float depth)
 
EncAreagetCoverage (int resLevel)
 
float calcDistFromLineSq (const float x, const float y, const float x1, const float y1, const float x2, const float y2)
 
void doIndexing (const Str *depthStr)
 
void updateGeoIndices ()
 

Private Attributes

bool initialized_
 
bool ready_
 
bool okToUpdateFromDisk_
 
int changeOkToUpdateFromDiskTo_
 
FastMap< const Str, EncInfo * > encMap_
 
FastMap< const float, Str * > depthMap_
 
FastMap< const Str *, Str * > depthMtxNameMap_
 
FastMap< const Str *, Str * > depthIdxNameMap_
 
FastMap< const Str *, FastMap< const int, Mtx * > * > depthMtxMap_
 
FastMap< const Str *, Mtx * > depthIdxMap_
 
FastMap< const float, ClosePoint * > closeMap_
 
FlexArrayBase currentGeoIndices_
 
unsigned int currentGeoIndex_
 
ClosePoint workingClosePoints_ [4]
 
ClosePointcloseSoundings_
 
int encId_
 
FlexArray< EncInfo * > encInfos_
 
FlexArray< EncArea * > coverages_
 
EncReaderencReader_
 
ClosePoint currentPoint_
 
int currentCount_
 
int insertCount_
 
float currentDepth_
 
StrcurrentDepthStr_
 
const Str soundingsStr_
 
int indexIndex_
 
int depthIndex_
 
int nextDepthIndex_
 
int changeNextDepthIndexTo_
 
int quadrant_
 
float latitude_
 
float changeLatitudeTo_
 
float longitude_
 
float changeLongitudeTo_
 
bool shoreDone_
 
bool mapDone_
 
StrValue chartsCfg_
 
float cycleTimeoutCfgTmp_
 
Timespan cycleTimeoutCfg_
 
DataWriterclosestDistanceWriter_
 
DataWriternextDistanceWriter_
 
DataWriterclosestDepthWriter_
 
DataWriternextDepthWriter_
 
ConfigReaderchartsCfgReader_
 
ConfigReadercycleTimeoutCfgReader_
 
Mutex currentMutex_
 

Static Private Attributes

static NavChartDbInstance_
 
static const Str NAME
 
static const DataURI CLOSEST_DISTANCE
 
static const DataURI NEXT_DISTANCE
 
static const DataURI CLOSEST_DEPTH
 
static const DataURI NEXT_DEPTH
 
static const RestartConfigURI CHARTS_CFG
 
static const RestartConfigURI CYCLE_TIMEOUT_CFG
 
static const float NUM_LATS
 
static const float LAT_INCREMENT
 
static const Timespan PERIOD
 

Additional Inherited Members

- Public Types inherited from Component
enum  ComponentState {
  BLOCK_CONTINUOUS, BLOCK_PERIODIC, BLOCK_NORMAL, BLOCK_COMPLETED,
  BLOCK_UNKNOWN
}
 In this model, the component has basically two states: wanting to run, and completed (no longer needing to run). More...
 
enum  ComponentType { COMPONENT_ASYNC, COMPONENT_CONFIG, COMPONENT_BEHAVIOR, COMPONENT_SYNC }
 Components can indicate how they want to be handled by their type. More...
 
enum  RunState {
  NO_RUN_STATE = 0, START, STARTING, RUNNABLE,
  SATISFIED, PAUSE, PAUSING, PAUSED,
  RESUME, RESUMING, RESETTING, STOP,
  STOPPING, STOPPED
}
 
- Protected Types inherited from Component
enum  ConfigOption { CONFIG_SIMULATE_HARDWARE, CONFIG_POWER, CONFIG_FREQUENCY, CONFIG_LATENCY }
 
- Protected Member Functions inherited from AsyncComponent
 AsyncComponent (const Str &name, const Module *module, const Timespan period, bool idlePriority=false)
 Protected constructor for components that run in periodic asynchronous threads. More...
 
 AsyncComponent (const Str &name, const Module *module, bool idlePriority=false)
 Protected constructor for components that run in continuous asynchronous threads. More...
 
- Protected Member Functions inherited from Component
virtual ConfigURI getConfigURI (ConfigOption configOption) const
 Should return [myNamespace]::SIMULATE_HARDWARE, or [myNamespace]::POWER, etc. More...
 
virtual ConfigURI getConfigURI (ConfigOption configOption, ElementURI forElement) const
 Should return [myNamespace]::POWER_[forElement], [myNamespace]::LATENCY_[forElement], etc. More...
 
virtual void setDurationOfLastRun (const Timespan &span)
 
virtual void setTimeOfRun (const Timestamp &time)
 
virtual void setTimeOfLastRun (const Timestamp &time)
 
virtual void setDt (const Timespan &dt)
 
virtual bool setEnabled (bool enabled=true)
 
void setRunState (const RunState runState)
 
const Timespan getPauseTime () const
 
virtual void setFailureMissionCritical (bool failureMissionCritical)
 
bool simulateHardware ()
 
- Protected Attributes inherited from AsyncComponent
bool idlePriority_
 
- Protected Attributes inherited from Component
Logger logger_
 
Syslog::Severity debugLevel_
 
ComponentState state_
 Keep track of whether the component has "completed" or should be run again. More...
 
Timespan desiredPeriod_
 
CodedStrname_
 Store the component's name (used for logging purposes) More...
 
Timestamp timeOfRun_
 
Timestamp timeOfLastRun_
 
Timespan durationOfLastRun_
 
Timespan dt_
 
Timespan retryTimeout_
 
bool enabled_
 
bool failureReported_
 Indicates if the failure has been reported – cuts down on syslog. More...
 
bool criticalFailureReported_
 Indicates if a "Critical" failure has been reported – cuts down on syslog. More...
 
bool recoveringFromCritical_
 Indicates that a component had a previous critical failure that has been cleared temporarily awaiting final word from the component itself. More...
 
bool failureUninitialized_
 Indicates if the failure has resulted in an uninitialize call. More...
 
int failCount_
 Number of failures logged by PCaller. More...
 
bool failureMissionCritical_
 If true (default), complete failure ends mission. More...
 
int allowableFailures_
 Number of failures allowed to occur. More...
 
int skippedRunsSinceFail_
 Number of skipped runs since failureMode_ set by failCount_. More...
 
FailureMode::FailType failureType_
 Failed status. If failCount_ > 0, then this may be reset. More...
 
Timestamp timeOfFailure_
 Time of last failure. Relevant only if failed=true. More...
 
Timestamp writeTimestamp_
 Time of last write. More...
 
FlexArray< DataReader * > readers_
 
FlexArray< DataWriter * > writers_
 
const Modulemodule_
 
Timespan pauseTime_
 
bool meteringEnabled_
 If true, metering is enabled. More...
 
DataWriterdurationOfLastRunWriter_
 Writer for durationOfLastRun. More...
 
DataWritervoltageWriter_
 
DataWriteravgVoltageWriter_
 
DataWritercurrentWriter_
 
DataWriteravgCurrentWriter_
 
bool persistentPause_
 True if data is persistent while component is paused. More...
 

Detailed Description

Reads a standard electronic navigation chart (ENC) in S-57 format, stores it in a database, and uses the values in the database to estimate nearest contours, coastline, and soundings of a lat/lon pair.

Constructor & Destructor Documentation

NavChartDb::NavChartDb ( const NavChartDb old)
private

Member Function Documentation

bool NavChartDb::appendToContour ( const Str depthStr,
const int  encId,
const int  resLevel,
const float  latitude,
const float  longitude 
)
private
bool NavChartDb::appendToCoverage ( const int  encId,
const int  resLevel,
const float  x0,
const float  y0,
const float  x1,
const float  y1 
)
private
bool NavChartDb::appendToSoundings ( const float  depth,
const int  encId,
const int  resLevel,
const float  latitude,
const float  longitude 
)
private
float NavChartDb::calcDistFromLineSq ( const float  x,
const float  y,
const float  x1,
const float  y1,
const float  x2,
const float  y2 
)
private
int NavChartDb::CalcGeoIndex ( float  latitude,
float  longitude 
)
static

converts a latitude and longitude into a index that covers a small area of the planet (smaller than GEO_GRID_SIZE * GEO_GRID_SIZE )

References CalcLatIndex(), CalcLonIndex(), CalcNumLonIndices(), and MakeGeoIndex().

Referenced by appendToContour(), and appendToSoundings().

int NavChartDb::CalcLatIndex ( float  latitude)
static

converts a latitude into a index that covers a small band around the planet

References LAT_INCREMENT.

Referenced by CalcGeoIndex(), and updateGeoIndices().

int NavChartDb::CalcLonIndex ( float  longitude,
int  nLons 
)
static

Calculates longitudinal index of small area in the latIndex band around the planet.

References M_2PI.

Referenced by CalcGeoIndex(), and updateGeoIndices().

int NavChartDb::CalcNumLonIndices ( int  latIndex)
static

Returns number of small longitudinal areas in the latIndex band around the planet (each smaller than GEO_GRID_SIZE * GEO_GRID_SIZE)

References Location::EARTH_RADIUS, GEO_GRID_SIZE, and LAT_INCREMENT.

Referenced by CalcGeoIndex(), and updateGeoIndices().

bool NavChartDb::createContour ( const Str depthStr)
private
bool NavChartDb::createIndices ( )
private
bool NavChartDb::createSoundings ( )
private
EncArea * NavChartDb::getCoverage ( int  resLevel)
private
float NavChartDb::getDistanceFromShore ( const float  latitude,
const float  longitude 
)

For a given latitude and longitude (in radians), estimates the distance from the shoreline at that location.

References closeMap_, Location::EARTH_RADIUS, shoreDone_, and AuvMath::Square().

Referenced by NavChart::run(), and OffshoreEnvelope::runIfUnsatisfied().

static NavChartDb* NavChartDb::GetInstance ( )
inlinestatic
float NavChartDb::getSeaFloorDepth ( const float  latitude,
const float  longitude 
)

For a latitude/longitude pair (in radians), return the approximate depth.

References closeMap_, closeSoundings_, NavChartDb::ClosePoint::depth_, shoreDone_, and AuvMath::Square().

Referenced by NavChart::run(), and WaterDepthEnvelope::runIfUnsatisfied().

bool NavChartDb::initDataDir ( )
private
bool NavChartDb::loadCoverage ( const int  resLevel,
EncArea **  coverage 
)
private
bool NavChartDb::loadDepths ( )
private
bool NavChartDb::loadEncs ( )
private
int NavChartDb::MakeGeoIndex ( int  latIndex,
int  lonIndex 
)
static

Combines latitude index and longitude index into a single index.

Referenced by CalcGeoIndex(), and updateGeoIndices().

Str * NavChartDb::mapDepth ( const float  depth)
private
bool NavChartDb::ready ( )
inline
void NavChartDb::setChartsCfg ( const Str  chartsCfg)
void NavChartDb::setOkToUpdateFromDisk ( )
inline

References okToUpdateFromDisk_.

void NavChartDb::uninitialize ( void  )
virtual

Provide a space for uninitialization.

Reimplemented from Component.

References initialized_.

Referenced by OffshoreEnvelope_Test::testRun().

void NavChartDb::updateCurrent ( const float  latitude,
const float  longitude,
bool  gotFix 
)
void NavChartDb::wipeOut ( )
private

Member Data Documentation

float NavChartDb::changeLatitudeTo_
private

Referenced by updateClosest(), and updateCurrent().

float NavChartDb::changeLongitudeTo_
private

Referenced by updateClosest(), and updateCurrent().

int NavChartDb::changeNextDepthIndexTo_
private

Referenced by updateClosest(), and updateCurrent().

int NavChartDb::changeOkToUpdateFromDiskTo_
private

Referenced by updateClosest(), and updateCurrent().

const RestartConfigURI NavChartDb::CHARTS_CFG
staticprivate

Referenced by NavChartDb().

StrValue NavChartDb::chartsCfg_
private

Referenced by initialize(), and setChartsCfg().

ConfigReader* NavChartDb::chartsCfgReader_
private

Referenced by initialize(), and NavChartDb().

FastMap< const float, ClosePoint* > NavChartDb::closeMap_
private
ClosePoint* NavChartDb::closeSoundings_
private
const DataURI NavChartDb::CLOSEST_DEPTH
staticprivate

Referenced by NavChartDb().

const DataURI NavChartDb::CLOSEST_DISTANCE
staticprivate

Referenced by NavChartDb().

DataWriter* NavChartDb::closestDepthWriter_
private

Referenced by NavChartDb().

DataWriter* NavChartDb::closestDistanceWriter_
private

Referenced by NavChartDb().

FlexArray< EncArea* > NavChartDb::coverages_
private

Referenced by getCoverage().

int NavChartDb::currentCount_
private
float NavChartDb::currentDepth_
private

Referenced by addEncData(), and run().

Str* NavChartDb::currentDepthStr_
private

Referenced by addEncData(), and run().

unsigned int NavChartDb::currentGeoIndex_
private

Referenced by updateClosest().

FlexArrayBase NavChartDb::currentGeoIndices_
private

Referenced by updateClosest(), and updateGeoIndices().

Mutex NavChartDb::currentMutex_
private

Referenced by updateClosest(), and updateCurrent().

ClosePoint NavChartDb::currentPoint_
private
const RestartConfigURI NavChartDb::CYCLE_TIMEOUT_CFG
staticprivate

Referenced by NavChartDb().

Timespan NavChartDb::cycleTimeoutCfg_
private

Referenced by initialize(), run(), and updateClosest().

ConfigReader* NavChartDb::cycleTimeoutCfgReader_
private

Referenced by initialize(), and NavChartDb().

float NavChartDb::cycleTimeoutCfgTmp_
private

Referenced by initialize().

FastMap< const Str*, Mtx* > NavChartDb::depthIdxMap_
private
FastMap< const Str*, Str* > NavChartDb::depthIdxNameMap_
private

Referenced by doIndexing(), and ~NavChartDb().

int NavChartDb::depthIndex_
private

Referenced by updateClosest().

FastMap< const float, Str* > NavChartDb::depthMap_
private
FastMap< const Str*, FastMap< const int, Mtx*>* > NavChartDb::depthMtxMap_
private
int NavChartDb::encId_
private
FlexArray<EncInfo*> NavChartDb::encInfos_
private

Referenced by initialize(), and run().

FastMap< const Str, EncInfo* > NavChartDb::encMap_
private
EncReader* NavChartDb::encReader_
private

Referenced by addEncData(), and run().

int NavChartDb::indexIndex_
private

Referenced by createIndices(), and run().

bool NavChartDb::initialized_
private

Referenced by initialize(), run(), and uninitialize().

int NavChartDb::insertCount_
private

Referenced by addEncData(), and run().

NavChartDb * NavChartDb::Instance_
staticprivate
const float NavChartDb::LAT_INCREMENT
staticprivate
float NavChartDb::latitude_
private

Referenced by updateClosest(), and updateGeoIndices().

float NavChartDb::longitude_
private

Referenced by updateClosest(), and updateGeoIndices().

bool NavChartDb::mapDone_
private

Referenced by updateClosest().

const Str NavChartDb::NAME
staticprivate
const DataURI NavChartDb::NEXT_DEPTH
staticprivate

Referenced by NavChartDb().

const DataURI NavChartDb::NEXT_DISTANCE
staticprivate

Referenced by NavChartDb().

int NavChartDb::nextDepthIndex_
private

Referenced by updateClosest().

DataWriter* NavChartDb::nextDepthWriter_
private

Referenced by NavChartDb().

DataWriter* NavChartDb::nextDistanceWriter_
private

Referenced by NavChartDb().

const float NavChartDb::NUM_LATS
staticprivate
bool NavChartDb::okToUpdateFromDisk_
private
const Timespan NavChartDb::PERIOD
staticprivate
int NavChartDb::quadrant_
private
bool NavChartDb::ready_
private

Referenced by ready(), and run().

bool NavChartDb::shoreDone_
private
const Str NavChartDb::soundingsStr_
private
ClosePoint NavChartDb::workingClosePoints_[4]
private

Referenced by updateClosest().


The documentation for this class was generated from the following files: