Generic hardware access library
|
00001 #include "hal/CommandSequence.hh" 00002 #include <list> 00003 00004 HAL::CommandSequence::CommandSequence( std::string name, 00005 HAL::CommandSequenceReader& reader, 00006 const HAL::AddressTableInterface& addressTable) 00007 throw( HAL::SequencerSyntaxError, HAL::NoSuchItemException ) 00008 : name( name ), 00009 reader(reader), 00010 addressTable( addressTable) { 00011 rescan(); 00012 } 00013 00014 void HAL::CommandSequence::rescan() 00015 throw ( HAL::NoSuchItemException, 00016 HAL::SequencerSyntaxError) { 00017 reader.rescan(); 00018 commandList.clear(); 00019 commandIndex = 0; 00020 labelMap.clear(); 00021 variableMap.clear(); 00022 std::list<std::string> commandStringList; 00023 HAL::CommandCreator commandCreator; 00024 while ( reader.next( commandStringList ) ) { 00025 commandList.push_back( commandCreator.create(commandStringList, 00026 addressTable, 00027 *this)); 00028 commandIndex++; 00029 } 00030 } 00031 00032 HAL::CommandSequence::~CommandSequence() { 00033 for ( commandIterator = commandList.begin(); 00034 commandIterator != commandList.end(); 00035 commandIterator++ ) { 00036 delete(*commandIterator); 00037 } 00038 } 00039 00040 void HAL::CommandSequence::run( const HAL::HardwareDeviceInterface& device ) 00041 throw( HAL::SequencerSyntaxError, 00042 HAL::IllegalOperationException, 00043 HAL::BusAdapterException, 00044 HAL::MaskBoundaryException, 00045 HAL::TimeoutException ) { 00046 for (commandIterator = commandList.begin(); 00047 commandIterator != commandList.end(); 00048 commandIterator++) { 00049 (*commandIterator)->excecute(device); 00050 } 00051 } 00052 00053 uint32_t* HAL::CommandSequence::addVariable( std::string name, 00054 uint32_t initValue ) { 00055 variableMap[ name ] = initValue; 00056 return &(variableMap[name]); 00057 } 00058 00059 void HAL::CommandSequence::addLabel( std::string labelName ) { 00060 // this is called during building up the sequence. The end of the sequence 00061 // contains the pointer to the command which is one before the label. 00062 // Therefore the rescan method must increment the iterators of the label 00063 // Map at the end by one. 00064 labelMap[ labelName ] = commandIndex; 00065 } 00066 00067 uint32_t HAL::CommandSequence::getVariable( std::string name ) const 00068 throw( HAL::SequencerSyntaxError ) { 00069 existVariable( name ); 00070 return ((*variableMap.find( name )).second); 00071 } 00072 00073 uint32_t* HAL::CommandSequence::getVariablePointer( std::string name ) 00074 throw( HAL::SequencerSyntaxError ) { 00075 existVariable( name ); 00076 return &((*variableMap.find( name )).second); 00077 } 00078 00079 void HAL::CommandSequence::setVariable( std::string name, 00080 uint32_t value ) 00081 throw( HAL::SequencerSyntaxError ) { 00082 existVariable( name ); 00083 variableMap[ name ] = value; 00084 } 00085 00086 void HAL::CommandSequence::gotoLabel( std::string labelName ) 00087 throw ( HAL::SequencerSyntaxError ) { 00088 existLabel( labelName ); 00089 commandIterator = (commandList.begin() + labelMap[ labelName ]); 00090 } 00091 00092 void HAL::CommandSequence::existVariable( std::string variableName ) const 00093 throw( HAL::SequencerSyntaxError ) { 00094 if (variableName[0] != '$') { 00095 std::string text = "Unvalid Variable name : " + variableName + 00096 "\n Variables must start with a \"$\"." + 00097 "\n (HAL::CommandSequence::existVariable)"; 00098 throw(HAL::SequencerSyntaxError( text )); 00099 } 00100 if ( variableMap.find( variableName ) == variableMap.end() ) { 00101 std::string text = "No such Variable : " + variableName + 00102 "\n (HAL::CommandSequence::existVariable)"; 00103 throw (HAL::SequencerSyntaxError( text ) ); 00104 } 00105 } 00106 00107 void HAL::CommandSequence::existLabel( std::string labelName ) const 00108 throw ( HAL::SequencerSyntaxError ) { 00109 if ( labelMap.find( labelName ) == labelMap.end() ) { 00110 std::string text = "No such Label : " + labelName + 00111 "\n (HAL::CommandSequence::existLabel)"; 00112 throw (HAL::SequencerSyntaxError( text ) ); 00113 } 00114 } 00115