/* 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. */ #include "BaseIUBaseBus.hh" using namespace std; //! Constructor to create a new object for a IU base bus. After //! creating the communication port object it creates the BaseIUBoard //! objects corresponding to the boards in this BaseIU bus. BaseIUBaseBus::BaseIUBaseBus(BaseIUVirtBusID& devID) : BaseIUVirtBus(devID) { if (bmDebFlag > 1) { cout << "BaseIUBaseBus::BaseIUBaseBus() : "; cout << "Bus for port " << hex << showbase << bmDevice->GetPortName() << " will create the boards " << endl; } // Create the parameters that belong to a bus InitParameters(); //! Create a imaginary board with address equal to 0 //! This board will be used to request parameter readback from the whole bus BaseIUBaseBoard* fakeBoard = new BaseIUBaseBoard(*this, 0); MtxLock objLock(bmMutex); bvbBoard[0] = fakeBoard; objLock.Unlock(); vector addrVec = this->GetAddressVector(); if (bmDebFlag > 1) { cout << "BaseIUBaseBus::BaseIUBaseBus() : Got the address vector with size " << addrVec.size() << endl; } //! Loop over boards that responded to the broadcast and synch //! them with the hardware for (unsigned iBoard = 0; iBoard < addrVec.size(); iBoard++) { int address = addrVec[iBoard]; //! If board with this address did not exist create it on the fly if (bvbBoard.count(address) == 0) { if (bmDebFlag > 1) { cout << "BaseIUBaseBus::BaseIUBaseBus() : The board with address " << address << " does not exist in the board map for port name " << bmDevice->GetPortName() << endl; } BaseIUBaseBoard* tmpBoard = new BaseIUBaseBoard(*this, address); objLock.Lock(); bvbBoard[address] = tmpBoard; objLock.Unlock(); } } if (bmDebFlag > 1) cout << "BaseIUBaseBus::BaseIUBaseBus() : Finished constructing bus for port " << hex << showbase << bmDevice->GetPortName() << endl; return; } //! Copy constructor, should not be used BaseIUBaseBus::BaseIUBaseBus(BaseIUBaseBus& bus) : BaseIUVirtBus(bus) { cerr << "BaseIUBaseBus::BaseIUBaseBus() : Error, copy constructor cannot be used" << endl; return; } //! Create the parameters that belong to the each bus on the board. void BaseIUBaseBus::InitParameters() { if (bmDebFlag > 1) { cout << "BaseIUBaseBus::InitParameters() : Initializing base bus parameters for " << "bus with address " << bmAddress << endl; } { //! Digital I/O parameter for the anagate device BaseIUVirtPar* parPtr = new BaseIUParDigital(BaseIUParDigital::bpdParType, *this); MtxLock objLock(bmMutex); bvbPar[BaseIUParDigital::bpdParType][BaseIUParDigital::bpdParType] = parPtr; } { //! Board unnamed status parameter named. Name does not have impact //! for the status parameter. This parameter is supposed to indicate if all busses are //! on or at least one of the busses is off or not responding. Such a parameter //! does not really exist in the hardware, but is calculated based on the statuses of //! all boards on this bus. BaseIUVirtPar* parPtr = new BaseIUParBusStatus(BaseIUParStatus::bpsParType, *this); // cout << "Right now pointer is " << showbase << hex << parPtr << endl; MtxLock objLock(bmMutex); bvbPar[BaseIUParStatus::bpsParType][BaseIUParStatus::bpsParType] = parPtr; // cout << "Pointer for " << BaseIUParStatus::bpsParType << " , " << BaseIUParStatus::bpsParType << " is " << // showbase << hex << bvbPar[BaseIUParStatus::bpsParType][BaseIUParStatus::bpsParType] << endl; } return; } // Set values for all parameters for certain types and name. void BaseIUBaseBus::SetParameter(string type, string bitName, void* setValPtr) { // map >::iterator typeIter; // bool* bitValPtr = reinterpret_cast( setValPtr ); // bvbPar[type][type]->SetBit( *bitValPtr, bitName ); bool setVal = *reinterpret_cast(setValPtr); // Get the boolean value from pointer // Loop all known boards on this bus and set the bit for the given parameter type // to the specified value MtxLock objLock(bmMutex); cout << "Setting bus parameter write value " << bitName << " for all boards port " << bmDevice->GetPortName() << " to " << setVal << endl; map::iterator itBoard; for (itBoard = bvbBoard.begin(); itBoard != bvbBoard.end(); itBoard++) { int boardAddress = itBoard->first; if (boardAddress != 0) { // cout << "Will set bit " << bitName << " for base " << hex << showbase << boardAddress << " port " // << bmDevice->GetPortName() << " to " << setVal << endl; BaseIUVirtBoard* boardPtr = itBoard->second; // For bus we use only STATUS or DIGITAL types where the name is the same as type BaseIUVirtPar* parPtr = boardPtr->GetParameter(type, type); parPtr->SetBit(setVal, bitName); } } cout << "Done setting parameter write value " << bitName << " for all bases port " << bmDevice->GetPortName() << " to " << setVal << endl; return; }