/* 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 _BaseIUParDigital_HH_ #define _BaseIUParDigital_HH_ extern "C" { #include #include #include #include }; #include #include #include #include #include "BaseIUVirtPar.hh" class BaseIUParDigital : public BaseIUVirtPar { protected: //! Read back value after for the status. It is //! one status word for all pins. Member functions will //! deal with separation of different pins. uint32_t bpdReadValue; //! To-be-written value uint16_t bpdWriteValue; static const uint32_t bpdInputMask ; // Mask for input bytes static const uint32_t bpdOutputMask; // Mask for output bytes BaseIUParDigital(); //! 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. bool ReadDigital(); public: static const string bpdParType; static const int bpdComndByte; //! 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 > bpdExtraByteMap; //! Map to keep the masks for retrieval of the status of //! various pins. The key is the name of the pin who's 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 bpdPinMaskMap; //! Main constructor BaseIUParDigital( string name, BaseIUModule& board ); //! Short constructor, no device no address BaseIUParDigital( string name ); //! Copy constructor BaseIUParDigital( const BaseIUParDigital& par ); //! Destructor virtual ~BaseIUParDigital(); //! Assignment operator BaseIUParDigital& operator=( const BaseIUParDigital& par ); //! Return input pin status for the parent bus bool GetInputBit(); //! Return output pin status for the parent bus bool GetOutputBit(); //! Sets the write value based on the pin name and the //! binary status for that bin 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(); // Digital parameters are not related to the bases, // therefore this method is overriden to retur false value. virtual inline bool IsBoardDependent() { return false; } //! Method to sync the parameter with the value on the hardware virtual bool Sync( bool dir = 0 ); //! Method to process deque from CANbus virtual bool ProcessDeque( bool clearFlag = 0 ) ; //! Request read of this pin 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 ); //! Check if the pin is set to 1 virtual bool GetBit( const string bitName = "" ); //! Set the pin to 1 virtual bool SetBit( const bool bitON, const string bitName = "" ) { SetPinStatus( bitName, bitON ); return bitON; } inline uint32_t GetReadValue() { MtxLock scopeLock( bmMutex ); return bpdReadValue; } virtual inline long GetLong( ) {return GetReadValue();} inline uint16_t GetWriteValue() { MtxLock scopeLock( bmMutex ); return bpdWriteValue; } inline uint16_t SetWriteValue( uint16_t val ) { MtxLock scopeLock( bmMutex ); return ( bpdWriteValue = val ); } static uint16_t SetPinToWrite( string pinName, bool pinON, uint16_t startVal ); }; #endif // _BaseIUParDigital_HH_