bool CProto::WriteDataByLocalIdentifier() { TRACE_FUN( Routine, "CProto::WriteDataByLocalIdentifier" ); bool ret( false ); ResetError(); _writeResultCode = wrcNotExecuted; l2max::CByteArray param; l2max::CBuffer paramStream( ¶m ); paramStream.open( l2max::CAbstractIODevice::omWriteOnly ); _abstractMode4->Serialize( paramStream ); l2max::CByteArray resp; if( ret = MakeTransaction( mECUFunc, param, resp ) ) { HAbstractMode4 abstractMode4Clone( _abstractMode4->clone() ); l2max::CBuffer respStream( &resp ); respStream.open( l2max::CAbstractIODevice::omReadOnly ); if( ret = abstractMode4Clone->Deserialize( respStream ) ) { if( *_abstractMode4 == *abstractMode4Clone ) { _writeResultCode = wrcAccept; } else { _writeResultCode = wrcReject; } } else { CAbstractProto::_errorCode = ecBinaryError; _errorCode = ecMode4Deserialization; } } return ret; }
static Box fromString(const std::string &str) { // boost::regex boxReg("((\\r\\n|\\n)+)?obj box ID[\\t ]+\\d+[\\t ]+" // "mat ID \\d+[\\t ]+(([-+]?[0-9]*\\.?[0-9]+[\\t ]+){14})" // "([-+]?[0-9]*\\.?[0-9]+"); // if (!boost::regex_match(str, boxReg)) // throw std::invalid_argument("Invalid box parameter string"); std::stringstream paramStream(str); // Skip the "obj box ID" preamble std::string dummy; for (int i = 0; i < 3; ++i) paramStream >> dummy; int id, matId; paramStream >> id; // Skip the "mat ID" preamble for (int i = 0; i < 2; ++i) paramStream >> dummy; paramStream >> matId; Eigen::Vector4d center, u, v, w; center = Eigen::Vector4d::Ones(); u = v = w = Eigen::Vector4d::Zero(); for (int i = 0; i < 3; i++) { paramStream >> center[i]; } for (int i = 0; i < 3; i++) { paramStream >> u[i]; } for (int i = 0; i < 3; i++) { paramStream >> v[i]; } for (int i = 0; i < 3; i++) { paramStream >> w[i]; } double uWidth, vWidth, wWidth; paramStream >> uWidth >> vWidth >> wWidth; return Box(center, u, v, w, id, matId, uWidth, vWidth, wWidth); }
bool CProto::ReadDataByLocalIdentifier() { TRACE_FUN( Routine, "CProto::ReadDataByLocalIdentifier" ); bool ret( false ); ResetError(); l2max::CByteArray param; l2max::CBuffer paramStream( ¶m ); paramStream << ( unsigned char )( 0x00 ); l2max::CByteArray resp; if( ret = MakeTransaction( mTransmitData, param, resp ) ) { l2max::CBuffer respStream( &resp ); respStream.open( l2max::CAbstractIODevice::omReadOnly ); if( ret = _abstractMode1Data0->Deserialize( respStream ) ) { if( !_abstractMode4.IsNull() ) { _abstractMode4->Synchronize(); } } else { CAbstractProto::_errorCode = ecBinaryError; _errorCode = ecMode1Data0Deserialization; } } return ret; }
/////////////////////////////////////////////////////////////////////////////// // Parse the command line into its pieces. /////////////////////////////////////////////////////////////////////////////// void ParseCommandLine::parseLine( int argc, char* argv[] ) { // Add the options piece to the usage string, because there always are at // least two types of options (help and version information). usageString += "[options]"; // Convert the command line into strings. // During this process, transform all flags into lower case. vector<string> cmdLine; for( int i = 1; i < argc; i++ ) { string next( argv[i] ); if( next[0] == '-' ) { transform( next.begin(), next.end(), next.begin(), ::tolower ); } cmdLine.push_back( next ); } //unsigned int length = cmdLine.size(); // Check if a help flag exists. // If one does, print out a usage message, set an error, and return. // This isn't a real error, it's just to stop parsing and running later. vector<string>::iterator helpIt; for( unsigned int i = 1; i <= standardHelpFlags.size(); i++ ) { string next = standardHelpFlags[i-1]; helpIt = find( cmdLine.begin(), cmdLine.end(), next ); if( helpIt != cmdLine.end() ) { usage(); setError(); return; } } // Check if a version flag exists. // If one does, print out a version message, set an error, and return. // This isn't a real error, it's just to stop parsing and running later. vector<string>::iterator versionIt; for( unsigned int i = 1; i <= standardVersionFlags.size(); i++ ) { string next = standardVersionFlags[i-1]; versionIt = find( cmdLine.begin(), cmdLine.end(), next ); if( versionIt != cmdLine.end() ) { cout << interfaceName << ": Version " << version << "." << endl << "Copyright Mathews Lab, University of Rochester." << endl; setError(); return; } } // Populate the parsed data map. unsigned int numParams = 0; for( unsigned int i = 1; i <= cmdLine.size(); i++ ) { // Get the next command line argument. string next = cmdLine[i-1]; // If the argument doesn't start with "-", call it a parameter. if( next[0] != '-' ) { numParams++; stringstream paramStream( stringstream::in | stringstream::out ); paramStream << "param" << numParams; parsedData[paramStream.str()] = next; } // Otherwise, process the flag. else { // Create a variable to track whether the flag exists. bool exists = false; // Check the flag against the possible flags with no parameters. // Set the flag's value if found. set<string>::iterator it1; set<string> s1 = lowerOptionsNoFlags; for( it1 = s1.begin(); it1 != s1.end(); it1++ ) { string flag = *it1; if( next == flag ) { parsedData[next] = ""; exists = true; } } // Check the flag against the possible options with parameters. // Set the flag's value if found. // Only do this if a flag wasn't previously found. if( exists == false ) { set<string>::iterator it2; set<string> s2 = lowerOptionsWithFlags; for( it2 = s2.begin(); it2 != s2.end(); it2++ ) { string flag = *it2; if( next == flag ) { bool noParam = ( i == cmdLine.size() ) || ( cmdLine[i][0] == '-' ); if( noParam == true ) { double test = 0.0; stringstream testStream( cmdLine[i] ); if( testStream >> test ) { noParam = false; } } if( noParam ) { cerr << "Option missing for flag: " << next << endl; setError(); return; } else { parsedData[next] = cmdLine[i]; exists = true; i++; } } } }