Generic hardware access library
|
00001 #include "hal/PollItemFactory.hh" 00002 #include <list> 00003 00004 HAL::SequencerCommand* HAL::PollItemFactory::create( std::list<std::string>& arguments, 00005 const HAL::AddressTableInterface& addressTable, 00006 HAL::CommandSequence& sequence ) 00007 throw (HAL::SequencerSyntaxError, HAL::NoSuchItemException) { 00008 00009 if ( arguments.size() < 4 || arguments.size() > 6 ) { 00010 throw ( HAL::SequencerSyntaxError("pollItem command must have four to six arguments.")); 00011 } 00012 std::string item = arguments.front(); 00013 arguments.pop_front(); 00014 // we check immediately if the item exists. So the program gets an 00015 // exception immediately and not only when the script is run 00016 if ( ! addressTable.exists( item ) ) { 00017 std::string text = "Item \"" + item + 00018 "\" does not exist in HAL::AddressTable" + 00019 "\n (HAL::PollItemFactory::create)"; 00020 throw (HAL::NoSuchItemException( text, __FILE__, __LINE__, __FUNCTION__ )); 00021 } 00022 00023 HAL::PollItemCommand* commandPtr = new HAL::PollItemCommand (item, sequence); 00024 00025 std::string referenceValueStr = arguments.front(); 00026 arguments.pop_front(); 00027 if (referenceValueStr[0] != '$') { 00028 commandPtr->setReferenceValue( stringToNumber( referenceValueStr ) ); 00029 } else { 00030 commandPtr->setReferenceValuePointer( sequence.getVariablePointer( referenceValueStr )); 00031 } 00032 00033 std::string timeoutStr = arguments.front(); 00034 arguments.pop_front(); 00035 if (timeoutStr[0] != '$') { 00036 commandPtr->setTimeout( stringToNumber( timeoutStr ) ); 00037 } else { 00038 commandPtr->setTimeoutPointer( sequence.getVariablePointer( timeoutStr )); 00039 } 00040 00041 std::string resultStr = arguments.front(); 00042 arguments.pop_front(); 00043 if (resultStr[0] != '$') { 00044 throw ( HAL::SequencerSyntaxError("PollItem command must have variable as fourth argument\n (HAL::PollItemFactory::create)")); 00045 } else { 00046 commandPtr->setResultPointer( sequence.getVariablePointer( resultStr )); 00047 } 00048 00049 if ( arguments.size() >= 1 ) { 00050 std::string pollMethodStr = arguments.front(); 00051 arguments.pop_front(); 00052 if (pollMethodStr == "HAL_POLL_UNTIL_EQUAL") { 00053 commandPtr->setPollMethod( HalPollMethod(HAL_POLL_UNTIL_EQUAL)); 00054 } else if (pollMethodStr == "HAL_POLL_UNTIL_DIFFERENT") { 00055 commandPtr->setPollMethod( HalPollMethod(HAL_POLL_UNTIL_DIFFERENT)); 00056 } else { 00057 std::string text = "If present fifth argument must be 'HAL_POLL_UNTIL_EQUAL' or 'HAL_POLL_UNTIL_DIFFERENT'\n (HAL::PollItemFactory::create)"; 00058 throw (HAL::SequencerSyntaxError( text )); 00059 ; 00060 } 00061 } 00062 00063 if ( arguments.size() >= 1 ) { 00064 std::string offsetStr = arguments.front(); 00065 arguments.pop_front(); 00066 if (offsetStr[0] != '$') { 00067 commandPtr->setOffset( stringToNumber( offsetStr )); 00068 } else { 00069 commandPtr->setOffsetPointer( sequence.getVariablePointer( offsetStr )); 00070 } 00071 } 00072 00073 return commandPtr; 00074 }