/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _BaseIUParStatus_HH_ #define _BaseIUParStatus_HH_ extern "C" { #include #include #include #include }; #include #include #include #include #include "BaseIUVirtPar.hh" using namespace std; class BaseIUParStatus : public BaseIUVirtPar { protected: //! Readback value after for the status. It is //! one status word for all pins. Member functions will //! deal with separation of different pins. uint8_t bpsReadValue; //! To-be-written value before being converted to integer uint16_t bpsWriteValue; //! Mask to protect the unwanted bits being written to. static uint16_t bpsWriteProtectionMask; BaseIUParStatus(); //! Get the deque after sending read request and process it to //! retrieve the parameter value on the board. If there was not //! message found then the return value is false. Otherwise it is true. //! If clearFlag is true the content of the FIFO will be cleared. virtual bool ProcessDeque( bool clearFlag = true ); public: // static int bpsDummyInt; static const string bpsParType; // static const string bpsParName; static const int bpsComndByte; //! Map to keep the extra bytes which need to be sent to the //! base to perform particular operation. The key in the mao //! is tha name of the pin, the second is a pair of two-bytes. //! First one specifies the enable operation, the second one //! specifies the disable operation. static map > bpsExtraByteMap; //! Map to keep the masks for retrieval of the status of //! various pins. The key is the name of the pin whose status //! needs to be retrieved, the value is the mask that needs //! to be bitwise "and"-ed to extract the status of the pin. static map bpsPinMaskMap; //! Main constructor BaseIUParStatus( string name, BaseIUModule& board ); //! Short constructor, no device no address BaseIUParStatus( string name ); //! Copy constructor BaseIUParStatus( const BaseIUParStatus& par ); //! Destructor virtual ~BaseIUParStatus(); //! Assignment operator BaseIUParStatus& operator=( const BaseIUParStatus& par ); //! Return pin status from the board bool GetPinStatus( const string pinName ); //! Sets the write value based on the pin name and the //! binary status for that bin virtual uint16_t SetPinStatus( const string pinName, const bool status = true ); //! Cloning function defined for polymorphism for copy constructor //! Invokes the copy constructor for this class and returns the //! the address of the resulting object virtual BaseIUVirtPar* CloneParameter(); //! Method to sync the parameter with the value on the hardware virtual bool Sync( bool dir = 0 ); //! Request read of this ADC for all boards on the bus virtual void ReadRequest( BaseIUDevice* dev, string name ); // Set the write values for this object from the write value of another parameter. // It is assumed that the two parameters are of the same class, otherwise the // program will seg. fault. virtual void SetWriteValueFrom( BaseIUVirtPar& fakePar ); //! Initialize the constants in the maps static int InitMaps(); uint16_t ReadToWrite( uint8_t readVal ); virtual bool GetBit( const string name ); virtual bool SetBit( const bool pinON, const string bitName = "" ) { SetPinStatus( bitName, pinON ); return pinON; } inline uint8_t GetReadValue() { MtxLock scopeLock( bmMutex ); return bpsReadValue; } inline uint16_t GetWriteValue() { MtxLock scopeLock( bmMutex ); return bpsWriteValue; } inline uint16_t GetWriteValue( uint16_t val ) { MtxLock scopeLock( bmMutex ); return ( bpsWriteValue = val ); } static uint16_t SetPinToWrite( string pinName, bool pinON, uint16_t startVal ); //! Method to check if the bits in the read value match //! the corresponding bits in the write value. This is //! because the meaning of the bits in the return values //! and the bits in the value that is send to the board //! for enabling/disabling do not have an easy correspondence. //! The mapping of the bits is inside this method. static bool BitsMatch( uint8_t readVal, uint16_t writeVal ); // Get write bit protection mask inline static uint16_t GetWriteProtectionMask() { MtxLock classLock( bmGlobMutex); return bpsWriteProtectionMask;} }; #endif // _BaseIUParStatus_HH_