CARMA C++
SubsystemFrame.h
Go to the documentation of this file.
1 #ifndef CARMA_MONITOR_SUBSYSTEMFRAME_H
2 #define CARMA_MONITOR_SUBSYSTEMFRAME_H
3 
17 #include "carma/monitor/types.h"
20 #include "carma/monitor/SubsystemFrameHeader.h"
21 
22 #include <map>
23 
24 namespace carma {
25 namespace monitor {
26 
27 
28 void SetFlag( unsigned short & flags,
29  const unsigned short & mask );
30 
31 void UnsetFlag( unsigned short & flags,
32  const unsigned short & mask );
33 
34 unsigned short GetFlag( const unsigned short & flags,
35  const unsigned short & mask );
36 
37 
42 struct SubsystemDataPointers;
43 
44 class MonitorPointSet;
45 struct TransportSubsystemFrame;
46 
47 
81 
82  public:
83  static const int MONITOR_POINT_ABSENT = -1;
84 
93  const SubsystemHeader & getSubsystemHeader() const;
94 
95  const SubsystemDataPointers & getSubsystemDataPointers() const;
96 
104  long getFrameCount () const ;
105 
113  long setFrameCount (const long frameCount) ;
114 
120  bool isCurrentFrame () const ;
121 
122  static bool mjdIsCurrentFrame( double mjd, double * mjdDelta );
123 
132  uchar getStatusFlags() const ;
133 
142  void setStatusFlags (uchar status) ;
143 
151  long getMaxNumMonitorPoints () const ;
152 
160  long getMaxNumSamples () const ;
161 
170  MonitorPointHeader getHeaderByTagID (const tagIDType tagID) const;
171 
179  MonitorPointHeader getHeaderByIndex (int index) const ;
180 
188  int getIndex (const tagIDType tagID) const;
189 
196  tagIDType getTagID (const int index) const ;
197 
205  bool isValid (const tagIDType tagID) const ;
206 
212  ushort getSubsystemID( ) const;
213 
219  void setSubsystemID (ushort subsystemID) ;
220 
231  static ushort numSamplesToAllocate (const ushort nSamplesPerCycle) ;
232 
245  static long maxNumSamplesIncludingAverages (const long maxMonitorPoints,
246  const long maxSamples) ;
247 
260  static size_t sizeFrame (long maxMonitorPoints, long maxSamples);
261 
274  static void
275  setFrameSize( SubsystemHeader & frame,
276  SubsystemDataPointers & dataPointers,
277  long maxMonitorPoints,
278  long maxSamples );
279 
289 
290  static void syncSubsystemToNewFrameData(
291  SubsystemHeader & frame,
292  SubsystemDataPointers & dataPointers );
293 
300  static long computeCurrentFrameTime () ;
301 
308  long getNumMonitorPoints() const ;
309 
318  long getNumMonitorPoints (MonitorValueType type) const;
319 
328  long getNumMonitorSamples (MonitorValueType type) const;
329 
337  long getNumMonitorSamples () const ;
338 
344  unsigned int getHighwaterNumMonitorSamples ( MonitorValueType type );
345 
354  long getNumSingleSamplePoints () const ;
355 
364  long countNumSingleSamplePoints () const ;
365 
374  void setNumSingleSamplePoints (const long numSingleSamples) ;
375 
383  ushort getNumSamplesPerCycle (const tagIDType tagID) const ;
384 
393  ushort getNumSamplesPerCycle (const int index) const ;
394 
405  void setNumSamplesPerCycle (int index, const ushort samples);
406 
419  MonitorPointSample getSampleValue (const tagIDType tagID,
420  ushort iSample) const ;
421 
434  MonitorPointSample getSampleValue (const int index, ushort iSample) const ;
435 
446  bool validSampleValue (const tagIDType tagID,
447  const MonitorPointSample& value) const ;
448 
457  const MonitorPointSample getSampleAverage (const tagIDType tagID) const ;
458 
467  const MonitorPointSample getSampleAverage (const int index) const ;
468 
477  MonitorValueType getValueType (const tagIDType tagID) const ;
478 
487  MonitorValueType getValueType (const int index) const ;
488 
498  void setLastWriterDelay (double time);
499 
509  double getLastWriterDelay () const ;
510 
518  void setLastWriteTime( double mjdTimestamp );
519  void setLastWriteTime( );
520 
528  double getLastWriteTime () const ;
529 
538  void setScriberWriteDelay (double writeDelay);
539 
548  double getScriberWriteDelay () const ;
549 
550 
557  void setScriberWriteTime( double mjdTimestamp );
558  void setScriberWriteTime( );
559 
566  double getScriberWriteTime () const ;
567 
574  void setPublishTime( double mjdTimestamp );
575  void setPublishTime( );
576 
583  double getPublishTime () const ;
584 
591  void setReceiveTime( double mjdTimestamp );
592  void setReceiveTime( );
593 
600  double getReceiveTime() const ;
601 
606  void clearAllTimes();
607 
613  bool isPublished () const ;
614 
618  void setPublished () ;
619 
623  void clearPublished () ;
624 
632  bool received () const ;
633 
637  void setReceived () ;
638 
642  void clearReceived () ;
643 
648  void markFramePublished();
649 
654  void markFrameReceived();
655 
656  struct AllocMpInfo {
657  tagIDType tagID;
658  MonitorValueType valueType;
659  ushort nSamplesPerCycle;
660  };
661 
662  // Allocates space for new monitor point in the subsystem frame.
663  // Returns the offset into the value array for the next new monitor point
664  // throw ErrorException when no more space available for monitor points
673  void allocateMonitorPoints( const AllocMpInfo * infos,
674  size_t infosCount,
675  bool markMpsAsModified = true );
676 
685  SubsystemDataPointers & dataPointers,
686  bool embeddedInAFullSystem );
687 
693  virtual ~SubsystemFrame( );
694 
702  void consolidateSamples();
703 
722  void writeToTransport( TransportSubsystemFrame & transFrame );
723 
737  void writeFromTransportFrame( const TransportSubsystemFrame & transFrame );
738 
753  void writeFromPointSet( const MonitorSampleValues & samples );
754 
761  void setNumMonitorPoints (ushort numMonitorPoints) ;
762 
769  void setNumMonitorSamples (ushort numSamples) ;
770 
777  void setNumActualSamples (ushort numSamples) ;
778 
784  int getNumActualSamples () const ;
785 
786  protected:
787 
798  SubsystemFrame( ushort subsystemID,
799  unsigned short numMonitorPoints,
800  unsigned short numSamples,
801  bool leakStorage );
802 
807  void clearSamples();
808 
816  int getNumAllocatedSamples () const ;
817 
818  // Allocates space for new monitor point values in the subsystem frame.
835  ushort allocateSamples (int headerOffset, ushort sampleOffset,
836  ushort nSamplesPerCycle = 1);
847  void setMonitorPointSet (MonitorPointSet* set) ;
848 
860  void writeSampleValue (const int index,
861  const MonitorSampleValue& value, ushort iSample);
862 
872  int findMonitorPoint(const tagIDType tagID) const ;
873 
881  MonitorSampleValue* getSamples() const ;
882 
883  const MonitorHeader & getMonitorHeaderRefByIndex( int index ) const;
884  MonitorHeader & getWritableMonitorHeaderRefByIndex( int index ) const;
885 
886  friend class MonitorPointSet;
887 
888  private:
889  // No copying
890  SubsystemFrame( const SubsystemFrame & rhs );
891  SubsystemFrame & operator=( const SubsystemFrame & rhs );
892 
893  protected:
894  SubsystemHeader & frame_;
895  SubsystemDataPointers & dataPointers_;
896 
897  private:
898  const bool shouldDeallocateStorage_;
899  const bool embeddedInAFullSystem_;
900  MonitorPointSet * set_;
901  ::std::map< MonitorValueType, unsigned int > highwaterMonitorSamples_;
902 };
903 
904 
915  : public virtual carma::util::BaseException {
916  public:
917  IllegalMonitorPointExceptionObj (const char* mesg,
918  const char* fileName = __FILE__,
919  const int lineNum = __LINE__) ;
920  IllegalMonitorPointExceptionObj (std::ostringstream& errStream,
921  const char* fileName = __FILE__,
922  const int lineNum = __LINE__) ;
923  IllegalMonitorPointExceptionObj (const tagIDType tagID,
924  const ushort subsystemID,
925  const char* fileName = __FILE__,
926  const int lineNum = __LINE__) ;
927 };
928 
929 
930 inline void
931 SetFlag( unsigned short & flags,
932  const unsigned short & mask ) {
933  flags |= mask;
934 }
935 
936 
937 inline void
938 UnsetFlag( unsigned short & flags,
939  const unsigned short & mask ) {
940  flags &= (~mask);
941 }
942 
943 
944 inline unsigned short
945 GetFlag( const unsigned short & flags,
946  const unsigned short & mask ) {
947  return (flags & mask);
948 }
949 
950 
951 } // namespace carma::monitor
952 } // namespace carma
953 
954 
955 inline long
957 {
958  return frame_.numMonitorPoints;
959 }
960 
961 
962 inline unsigned short
964 {
965  return frame_.subsystemID;
966 }
967 
968 
969 inline void
971 {
972  set_ = s;
973 }
974 
975 
976 inline const carma::monitor::SubsystemHeader &
978 {
979  return frame_;
980 }
981 
982 
983 inline const carma::monitor::SubsystemDataPointers &
984 carma::monitor::SubsystemFrame::getSubsystemDataPointers( ) const
985 {
986  return dataPointers_;
987 }
988 
989 
990 inline int
992 {
993  return frame_.numSamples;
994 }
995 
996 
997 inline const carma::monitor::MonitorHeader &
998 carma::monitor::SubsystemFrame::getMonitorHeaderRefByIndex(
999  const int index ) const
1000 {
1001  return dataPointers_.monitorHeaders[ index ];
1002 }
1003 
1004 
1005 inline unsigned short
1007 {
1008  return getMonitorHeaderRefByIndex( index ).getNumSamplesPerCycle();
1009 }
1010 
1011 
1012 #endif
long getMaxNumMonitorPoints() const
Returns maximum number of monitor points this subsystem frame can accommodate.
MonitorValueType getValueType(const tagIDType tagID) const
Returns type of sample value associated with the monitor point specified by tagID.
const MonitorPointSample getSampleAverage(const tagIDType tagID) const
Returns average of all samples in current cycle as a MonitorPointSample object.
bool isPublished() const
True if this subsystem frame has been published.
short MonitorValueType
Enumeration of possible types for monitor point values.
void setStatusFlags(uchar status)
Sets status flags for subsystem frame.
const SubsystemHeader & getSubsystemHeader() const
Returns reference to internal structure.
void setScriberWriteTime(double mjdTimestamp)
Sets the time of the last scriber write to the associated subsystem IPQ.
void setNumActualSamples(ushort numSamples)
Sets number of actual monitor samples for this subsystem frame.
bool received() const
True if this subsystem frame has been received by the frame collator (in the ACC).
void clearAllTimes()
Resets lastWriteTime, scriberWriteTime, publishTime and receiveTime to 0.
void clearReceived()
Clears status flag to indicate that this frame has not been received.
void setReceiveTime(double mjdTimestamp)
Sets the time when this subsystem frame was received at the ACC.
This is the include file for Carma exception handling utilities.
Class representing a data sample for a MonitorPoint.
void setScriberWriteDelay(double writeDelay)
Sets the delay used by the scriber part of the frameScriberPublisher to write to the associated IPQ i...
static long maxNumSamplesIncludingAverages(const long maxMonitorPoints, const long maxSamples)
Returns number of samples to allocate for the entire subsystem given the maximum number of monitor po...
void setMonitorPointSet(MonitorPointSet *set)
Used when subsystem frame is generated from a MonitorPointSet object using the MonitorPointSet::getSu...
A class that manages the sets of monitor points for a monitor subsystem.
long getNumSingleSamplePoints() const
Returns total allocated number of monitor points with one sample per cycle, a sampling rate of 2 Hz...
double getReceiveTime() const
Returns the time when this subsystem frame was received at the ACC.
void allocateMonitorPoints(const AllocMpInfo *infos, size_t infosCount, bool markMpsAsModified=true)
method to allocate space within the subsystem frame for a monitor point and its samples.
double getPublishTime() const
Returns the time when this subsystem frame was published to the ACC.
MonitorPointSample getSampleValue(const tagIDType tagID, ushort iSample) const
Returns requested monitor sample as a MonitorPointSample object.
void setPublished()
Sets status flag to indicate that this frame is published.
ushort getNumSamplesPerCycle(const tagIDType tagID) const
Returns number of samples per cycle (0.5*sampling rate) associated with the monitor point with tagID ...
static size_t sizeFrame(long maxMonitorPoints, long maxSamples)
This method is used to compute the size of a subsystem frame when the the maximum number of monitor p...
tagIDType getTagID(const int index) const
Returns tagID of the monitor point with header at index "index" in the monitorHeaders array in this s...
void writeToTransport(TransportSubsystemFrame &transFrame)
Returns a TransportSubsystemFrame filled with monitor sample values from this subsystem frame...
unsigned int getHighwaterNumMonitorSamples(MonitorValueType type)
Get highwater number of monitor samples.
Contains sample values from all monitor points in a monitor subsystem.
static long computeCurrentFrameTime()
Static method used to calculate frame count as number of half-seconds since Januray 1...
Structure for storing monitor point sample, including value.
MonitorPointHeader getHeaderByIndex(int index) const
Returns maximum number of monitor samples this subsystem frame can accommodate.
Class wrapper for monitor point headers stored in a subsystem frame.
SubsystemFrame(SubsystemHeader &frame, SubsystemDataPointers &dataPointers, bool embeddedInAFullSystem)
Constructor that constructs around a SubsystemHeader structure.
virtual ~SubsystemFrame()
Destructor.
long getMaxNumSamples() const
Returns maximum number of monitor samples this subsystem frame can accommodate.
void setReceived()
Sets status flag to indicate that this frame was received.
void markFramePublished()
Convenience method that sets the publish time and sets the status flag to indicate that the frame was...
MonitorPointHeader getHeaderByTagID(const tagIDType tagID) const
Returns MonitorPointHeader object corresponding to the monitor point with the specified tagID...
double getScriberWriteDelay() const
Returns the delay used by the scriber part of the frameScriberPublisher to write to the associated IP...
void writeFromTransportFrame(const TransportSubsystemFrame &transFrame)
Takes the sample values from a transported subsystem frame and fills them into this subsystem frame...
void setLastWriteTime(double mjdTimestamp)
Sets the time of the last client write to the associated frame scriber publisher process.
void setLastWriterDelay(double time)
Sets the delay used by the last client to write to the associated frame scriber publisher process...
void writeSampleValue(const int index, const MonitorSampleValue &value, ushort iSample)
Writes specified sample value &#39;value&#39; into this subsystem frame as sample with sample number &#39;iSample...
uchar getStatusFlags() const
Returns status flags for subsystem frame.
void writeFromPointSet(const MonitorSampleValues &samples)
Takes the sample values from a transported sequence of sample values and fills them into this subsyst...
Base exception class for managing carma errors.
Definition: BaseException.h:48
void setPublishTime(double mjdTimestamp)
Sets the time when this subsystem frame was published to the ACC.
int findMonitorPoint(const tagIDType tagID) const
Returns the index to the monitor point header corresponding to specified &#39;tagID&#39;. ...
void setNumMonitorSamples(ushort numSamples)
Sets number of monitor samples for this subsystem frame.
bool isCurrentFrame() const
Method returns true if frame&#39;s timestamp is current; false otherwise.
void clearSamples()
Clears all samples in this subsystem frame.
void markFrameReceived()
Convenience method that sets the recive time and sets the status flag to indicate that the frame was ...
static ushort numSamplesToAllocate(const ushort nSamplesPerCycle)
Returns the number of samples to allocate for a sampling rate specified as number of samples per cycl...
long getNumMonitorPoints() const
Returns allocated number of monitor points - in other words, the actual number of monitor points pres...
ushort allocateSamples(int headerOffset, ushort sampleOffset, ushort nSamplesPerCycle=1)
Allocates monitor samples in this subsystem frame for a monitor point with header at &#39;headerOffset&#39;...
ushort getSubsystemID() const
Returns subsystemID of this subsystem frame.
void setNumSingleSamplePoints(const long numSingleSamples)
Sets total allocated number of monitor points with one sample per cycle, a sampling rate of 2 Hz...
int getNumAllocatedSamples() const
Returns the number of allocated samples.
Class wrapper for monitor point samples stored in a subsystem frame.
double getLastWriterDelay() const
Returns the delay used by the last client to write to the associated frame scriber publisher process...
long getNumMonitorSamples() const
Returns total allocated number of monitor samples in this subsystem frame.
void setNumSamplesPerCycle(int index, const ushort samples)
Sets number of samples per cycle (0.5*sampling rate) associated with the monitor point at index == &#39;i...
double getLastWriteTime() const
Gets the time of the last client write to the associated frame scriber publisher process.
MonitorSampleValue * getSamples() const
Returns pointer to beginning of monitor sample array in this subsystem frame.
void setSubsystemID(ushort subsystemID)
Sets subsystemID of this subsystem frame.
type definitions for monitor system
int getIndex(const tagIDType tagID) const
Returns index of monitor point header corresponding to the specified tagID, in monitor header array i...
Structure used to manage memory for a subsystem frame.
Frame containing monitor points for a monitor subsystem frame.
void setNumMonitorPoints(ushort numMonitorPoints)
Sets number of monitor points for this subsystem frame.
long countNumSingleSamplePoints() const
Counts number of single sample monitor points in this subsystem frame.
long setFrameCount(const long frameCount)
Sets the frame&#39;s timestamp.
Exception class thrown when an invalid monitor point is detected.
static void setFrameSize(SubsystemHeader &frame, SubsystemDataPointers &dataPointers, long maxMonitorPoints, long maxSamples)
Sets size parameters in the subsystem frame.
int getNumActualSamples() const
Returns number of monitor samples for this subsystem frame.
void consolidateSamples()
Consolidates storage in the array of monitor samples.
long getFrameCount() const
Gets the frame&#39;s timestamp.
double getScriberWriteTime() const
Gets the time of the last scriber write to the associated subsystem IPQ.
void clearPublished()
Clears status flag to indicate that this frame is not published.
bool isValid(const tagIDType tagID) const
True if tagID is that of a valid monitor point within this subsystem frame.
void syncSubsystemToNewFrameData()
Sets the pointers to the monitor point index array (monitorPointIndex), monitor point header array (m...
bool validSampleValue(const tagIDType tagID, const MonitorPointSample &value) const
True if sample is valid - this means that the tagID of the monitor point is valid in this subsystem f...
Wrapper class for monitor point header information.