bool CNR_7DOFAnalyticInverseKinematicsComp::SetParameter(Property parameter)
{
	onDestroy();

	if(parameter.FindName("UpperArmLength") == false) {
		PrintMessage("ERROR : CNR_6DOFRobotForwardKinematicsComp::SetParameter() -> Can't find the UpperArmLength in property\n");
		return false;
	}
	if(parameter.FindName("LowerArmLength") == false) {
		PrintMessage("ERROR : CNR_6DOFRobotForwardKinematicsComp::SetParameter() -> Can't find the LowerArmLength in property\n");
		return false;
	}
	if(parameter.FindName("ToolLength") == false) {
		PrintMessage("ERROR : CNR_6DOFRobotForwardKinematicsComp::SetParameter() -> Can't find the ToolLength in property\n");
		return false;
	}
	if(parameter.FindName("RedundantValue") == false) {
		PrintMessage("ERROR : CNR_6DOFRobotForwardKinematicsComp::SetParameter() -> Can't find the RedundantValue in property\n");
		return false;
	}

	PrintMessage("UpperArmLength : %.3f\nLowerArmLength : %.3f\nToolLength : %.3f\nRedundantValue : %.3f\n"
		,atof(parameter.GetValue("UpperArmLength").c_str())
		,atof(parameter.GetValue("LowerArmLength").c_str())
		,atof(parameter.GetValue("ToolLength").c_str())  
		,atof(parameter.GetValue("RedundantValue").c_str()));

	this->parameter = parameter;


	return true;
}
// Call back Declaration
ReturnType HCILab_PowerSTTVoiceRecComp::onInitialize()
{
	//	XML에 저장된 프라퍼티를 parameter에 저장
	Property parameter;
	std::map<std::string, std::string> temp = getPropertyMap();
	parameter.SetProperty(temp);
	
	if(parameter.FindName("WordList") == false) {
		PrintMessage("ERROR : HCILab_PowerSTTVoiceRecComp::onInitialize() -> Can't find the WordList in property\n");
		return OPROS_FIND_PROPERTY_ERROR;
	}

	SetModulePath();
	int err = power_stt_kor_create(strModulePath);
	if( err != 1 )
		PrintMessage("Error:HCILab_PowerSTTVoiceRecComp::power_stt_kor_create ()\n");

	if( LoadList1((char *)parameter.GetValue("WordList").c_str()) ) {
		PrintMessage("INFO:HCILab_PowerSTTVoiceRecComp::onInitialize() %s -> %s\n", parameter.GetValue("WordList").c_str(), strList1.c_str());
		power_stt_kor_set_vocab((char *)strList1.c_str(), "");
	}

	PrintMessage("Success : HCILab_PowerSTTVoiceRecComp::onInitialize()\n");
	return OPROS_SUCCESS;
}
Exemplo n.º 3
0
int HyVisionHvr2130Camera::SetParameter(Property parameter)
{
	if (!parameter.FindName("CameraID") || 
		!parameter.FindName("Width") || 
		!parameter.FindName("Height") ||
		!parameter.FindName("PixelBytes") ||
		!parameter.FindName("Flip") )
	{
		if( !parameter.FindName("CameraID") )
			PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter CameraID.\n");
		if( !parameter.FindName("Width") )
			PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter Width.\n");
		if( !parameter.FindName("Height") )
			PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter Height.\n");
		if( !parameter.FindName("PixelBytes") )
			PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter PixelBytes.\n");
		if( !parameter.FindName("Flip") )
			PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter Flip.\n");

		PrintMessage("Error:HyVisionHvr2130Camera::SetParameter()->Can't find parameter(s) name.\n");
		return API_ERROR;
	}

	_id = atoi( (parameter.GetValue("CameraID")).c_str() );
	_width = atoi( (parameter.GetValue("Width")).c_str() );
	_height = atoi( (parameter.GetValue("Height")).c_str() );
	_pixelByte = atoi( (parameter.GetValue("PixelBytes")).c_str() );
	_flip = atoi( (parameter.GetValue("Flip")).c_str() );
	PrintMessage("SUCCESS:HyVisionHvr2130Camera::SetParameter()->CameraID = %d, Width = %d, Height = %d.\n", _id, _width, _height);

	this->parameter = parameter;

	return API_SUCCESS;
}
int YujinRobot_iRobiQSpeech::Initialize(Property parameter)
{
	if(SetParameter(parameter) == false) {
		return false;
	}

	if(parameter.FindName("IP") == false) {
		PrintMessage("ERROR : YujinRobot_iRobiQSpeech::initialize() -> Can't find the IP Address\n");
		return false;
	}
	std::string ip = parameter.GetValue("IP");

	if(parameter.FindName("Port") == false) {
		PrintMessage("ERROR : YujinRobot_iRobiQSpeech::initialize() -> Can't find the Port Number\n");
		return false;
	}
	unsigned int port = (unsigned int)atoi(parameter.GetValue("Port").c_str());

	if(parameter.FindName("ServiceID") == false) {
		PrintMessage("ERROR : YujinRobot_iRobiQSpeech::initialize() -> Can't find the Service ID\n");
		return false;
	}
	unsigned short serviceId = (unsigned short)atoi(parameter.GetValue("ServiceID").c_str());

	if(iRobiQ_Initialize() == false) {
		return false;
	}

	if(iRobiQ_Connect(ip, port, serviceId) == false) {
		iRobiQ_Finalize();
	}

	return true;
}
int Simulator_GyroSensor::SetParameter(Property parameter)
{
	SimulatorIP		= parameter.GetValue("userMessage").c_str();
	deviceName		= parameter.GetValue("GyroName").c_str();
	RobotName		= parameter.GetValue("RobotName").c_str();
	PortNumber		= atoi(parameter.GetValue("Port").c_str());

	this->parameter = parameter;
	return 0;
}
Exemplo n.º 6
0
int Simulator_LaserScanner::SetParameter(Property parameter)
{
	maximumStep = atoi(parameter.GetValue("MaximumStep").c_str());
	startStep = atoi(parameter.GetValue("StartStep").c_str());
	endStep = atoi(parameter.GetValue("EndStep").c_str());
	deltaStep = atoi(parameter.GetValue("DeltaStep").c_str());

	SimulatorIP	= parameter.GetValue("userMessage").c_str();
	DeviceName	= parameter.GetValue("deviceName").c_str();
	RobotName	= parameter.GetValue("RobotName").c_str();
	PortNumber	= atoi(parameter.GetValue("Port").c_str());


	if(endStep < 0 || endStep > maximumStep) {
		return API_ERROR;
	}

	if(startStep < 0 || startStep >= endStep || startStep >= endStep) {
		return API_ERROR;
	}

	if(deltaStep <= 0 || deltaStep > MAXIMUM_CLUSTER_SIZE) {
		return API_ERROR;
	}

	scanStepSize = (endStep	- startStep) / deltaStep + 1;
	scannedData.resize(scanStepSize);
	m_ClientSocket.StepSize = scanStepSize;

	this->parameter = parameter;

	return 0;

}
Exemplo n.º 7
0
CEVENT(CMDBoard, _ExitPost)
{
    World* world = World::GetPtr();
    Editor* ed = ((EditorExitedArgs*)args)->editor;
    BoardPost* post = (BoardPost*)ed->GetArg();
    Player* mobile = (Player*)caller;
    BoardManager* bmanager = (BoardManager*)world->GetProperty("boards");
    Property* prop = NULL;
    Board* board = NULL;
    int id = 0;

    if (!bmanager)
        {
            mobile->Message(MSG_ERROR, "Can not access the board system.");
            return;
        }

    prop = mobile->variables.FindProperty("board");
    if (!prop)
        {
            mobile->Message(MSG_ERROR, "No board set.");
            return;
        }

    id = prop->GetValue().GetInt();
    board = bmanager->GetBoardByIndex(id);
    if (!board)
        {
            mobile->Message(MSG_ERROR, "The board you have set does not exist.");
            return;
        }

    board->AddPost(post);
}
Exemplo n.º 8
0
int SerialCommunication::Initialize(Property parameter)
{
	if(parameter.FindName("PortName") == false)	return API_ERROR;
	string portName = parameter.GetValue("PortName");
	if(parameter.FindName("TimeOut") == false)		return API_ERROR;
	unsigned long timeOut = (unsigned long)atol(parameter.GetValue("TimeOut").c_str());
	if(parameter.FindName("BaudRate") == false)	return API_ERROR;
	unsigned long baudRate = (unsigned long)atol(parameter.GetValue("BaudRate").c_str());
	if(parameter.FindName("DataBits") == false)	return API_ERROR;
	char dataBits = (char)atoi(parameter.GetValue("DataBits").c_str());
	if(parameter.FindName("StopBits") == false)	return API_ERROR;
	char stopBits = (char)atoi(parameter.GetValue("StopBits").c_str());
	if(parameter.FindName("Parity") == false)		return API_ERROR;
	char parity = (char)atoi(parameter.GetValue("Parity").c_str());
	if(parameter.FindName("FlowControl") == false)	return API_ERROR;
	char flowControl = (char)atoi(parameter.GetValue("FlowControl").c_str());

	if(handle != NULL) {
		return 0;
	}

#ifdef WIN32
	handle = new SerialWindows(portName, timeOut, baudRate, dataBits, stopBits, parity, flowControl);
#else
	handle = new SerialLinux(portName, timeOut, baudRate, dataBits, stopBits, parity, flowControl);
#endif

	this->parameter = parameter;

	return API_SUCCESS;
}
bool KITECH_MonotoneCubicTrajectoryGenerationComp::SetParameter(Property parameter)
{
	if(parameter.FindName("SamplingTime") == false) {
		PrintMessage("ERROR : KITECH_MonotoneCubicTrajectoryGenerationComp::SetParameter() -> Can't find the SamplingTime in property\n");
		return false;
	}
	samplingTime = atof(parameter.GetValue("SamplingTime").c_str());

	if(parameter.FindName("Monotonicity") == false) {
		PrintMessage("ERROR : KITECH_MonotoneCubicTrajectoryGenerationComp::SetParameter() -> Can't find the Monotonicity in property\n");
		return false;
	}
	monotonicity = atof(parameter.GetValue("Monotonicity").c_str());

	this->parameter = parameter;

	return true;
}
int DasaRobot_TetraIR::SetParameter(Property parameter)
{
	if (parameter.FindName("Size") == false) return API_ERROR;
	if (parameter.FindName("RobotIP") == false) return API_ERROR;
	if (parameter.FindName("RobotPort") == false) return API_ERROR;
	
	sensorCount = atoi (parameter.GetValue("Size").c_str());
	robotIP = parameter.GetValue("RobotIP");
	robotPort = atoi (parameter.GetValue("RobotPort").c_str());

	PrintMessage("-- DasaRobot_TetraIR Parameter\n");
	PrintMessage("-- Size              : %d\n", sensorCount);
	PrintMessage("-- RobotIP           : %s\n", robotIP.c_str ());
	PrintMessage("-- RobotPort         : %d\n", robotPort);
	PrintMessage("\n");

	this->parameter = parameter;

	return API_SUCCESS;
}
ReturnType KitechCardinalSplineTrajectoryGenerationComp::SetParameter(Property parameter)
{
	if(parameter.FindName("Tension") == false) {
		PrintMessage("ERROR : KitechCardinalSplineTrajectoryGenerationComp::SetParameter() -> Can't find the Tension in property\n");
		return OPROS_BAD_INPUT_PARAMETER;
	}
	_tension = atof(parameter.GetValue("Tension").c_str());

	_parameter = parameter;

	return _errorCode = OPROS_SUCCESS;
}
 void TypeNameFilter::RefreshContents() {
     Flags.Refresh = false;
     TypeNameFilterArguments* tfa = (TypeNameFilterArguments*)(Arguments->AdditionalArguments);
     RegexMatcher regex(tfa->ComparisonRegex);
     ScopeEnumerator* e = new ScopeEnumerator(*(Arguments->Source),Arguments->Requester);
     if(tfa->IncludeWhenMatches) {
         while (e->MoveNext()) {
             Property* p = e->Current;
             if (regex.Matches(*(p->GetValue()->GetClassTypeInfo()->ClassName))) {
                 Add(*p);
             }
         }
     } else {
         while (e->MoveNext()) {
             Property* p = e->Current;
             if (!regex.Matches(*(p->GetValue()->GetClassTypeInfo()->ClassName))) {
                Add(*p);
             }
         }
     }
     delete e;
 }
Exemplo n.º 13
0
void CMDBoard::List(Player* mobile)
{
    World* world = World::GetPtr();
    BoardManager* bmanager = (BoardManager*)world->GetProperty("boards");
    Property* prop = NULL;
    int id = 0;
    int i = 0;
    Board* board = NULL;
    std::vector<BoardPost*>* posts;
    std::vector<BoardPost*>::iterator it, itEnd;
    std::stringstream st;

    if (!bmanager)
        {
            mobile->Message(MSG_ERROR, "Can not access the board system.");
            return;
        }

    prop = mobile->variables.FindProperty("board");
    if (!prop)
        {
            mobile->Message(MSG_ERROR, "No board set.");
            mobile->Message(MSG_ERROR, "Use board set to choose a board.");
            return;
        }

    id = prop->GetValue().GetInt();
    board = bmanager->GetBoardByIndex(id);
    if (!board)
        {
            mobile->Message(MSG_ERROR, "The board you have set does not exist.");
            return;
        }

    posts = board->GetPosts();
    if (!posts->size())
        {
            mobile->Message(MSG_INFO, "No messages.");
            return;
        }

    st << left << "#" << setw(12) << "poster" << right << "subject" << endl;
    st << Repete("-", 80) << endl;
    itEnd = posts->end();
    i = 1;
    for (it = posts->begin(); it != itEnd; ++it, ++i)
        {
            st << left << "[" << setw(5) << i << "]" << setw(12) << (*it)->GetPoster() << right << (*it)->GetSubject() << endl;
        }
    mobile->Message(MSG_LIST, st.str());
}
Exemplo n.º 14
0
 Property* Alias::GetProxy() {
     if(IsPath) {
         if (mAliasedPath != NULL) {
             Property* p = mAliasedPath->GetProperty(Creator,NULL,PropertyModes::Traversing);
             if (p != NULL) {
                 // Do not cache path value.
                 return p->GetValue();
             }
         }
     } else if (mCachedProperty == NULL && mAliasedProperty != NULL) {
         mCachedProperty = mAliasedProperty->GetValue();
     }
     return mCachedProperty == NULL ? Property::NullProperty : mCachedProperty;
 }
int Robotis_DynamixelUART::SetParameter(Property parameter)
{
	if(parameter.FindName("MaximumPower") == false)				goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.maximumPower = atof(parameter.GetValue("MaximumPower").c_str());

	if(parameter.FindName("LinePerRevolution") == false)		goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.linePerRevolution = atof(parameter.GetValue("LinePerRevolution").c_str());
	//	엔코더가 고정되어 있기 때문에 강제로 값을 설정
	_profile.linePerRevolution = 360.0 * 1023.0 / 300.0;

	if(parameter.FindName("ReductionRatio") == false)			goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.reductionRatio = atof(parameter.GetValue("ReductionRatio").c_str());

	if(parameter.FindName("MaximumVelocity") == false)			goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.maximumVelocity = atof(parameter.GetValue("MaximumVelocity").c_str());

	if(parameter.FindName("Acceleration") == false)				goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.acceleration = atof(parameter.GetValue("Acceleration").c_str());

	if(parameter.FindName("MinimumPositionLimit") == false)		goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.minimumPositionLimit = atof(parameter.GetValue("MinimumPositionLimit").c_str());

	if(parameter.FindName("MaximumPositionLimit") == false)		goto ERROR_Robotis_DynamixelUART_SetParameter;
	_profile.maximumPositionLimit = atof(parameter.GetValue("MaximumPositionLimit").c_str());

	if(dynamixel == NULL) {
		if(uart == NULL) {
			return API_ERROR;
		}
		dynamixel = new DynamixelUART(uart, 0);
	}

	if(dynamixel->SetTorqueLimit((unsigned short)(_profile.maximumPower)) == false) {
		PrintMessage("ERROR : Robotis_DynamixelUART::SetParameter() -> Occur a error in SetTorqueLimit().\n");
		return API_ERROR;
	}

	if(dynamixel->SetMovingSpeed((unsigned short)(_profile.maximumVelocity * 60 * _profile.reductionRatio / 360.0)) == false) {
		PrintMessage("ERROR : Robotis_DynamixelUART::SetParameter() -> Occur a error in SetMovingSpeed().\n");
		return API_ERROR;
	}
	
	this->parameter = parameter;

	return API_SUCCESS;

ERROR_Robotis_DynamixelUART_SetParameter :
	PrintMessage("ERROR : Faulhaber_MCDC2805::SetParameter() -> Can't find parameters\n");
	return API_ERROR;
}
Exemplo n.º 16
0
void CMDBoard::Read(Player* mobile, int id)
{
    World* world = World::GetPtr();
    BoardPost*post = NULL;
    BoardManager* bmanager = (BoardManager*)world->GetProperty("boards");
    Board* board = NULL;
    Property* prop = NULL;
    int boardid = 0;
    std::stringstream st;

    if (!bmanager)
        {
            mobile->Message(MSG_ERROR, "Can not access the board system.");
            return;
        }

    prop = mobile->variables.FindProperty("board");
    if (!prop)
        {
            mobile->Message(MSG_ERROR, "No board set.");
            mobile->Message(MSG_ERROR, "Use board set to choose a board.");
            return;
        }

    boardid = prop->GetValue().GetInt();
    board = bmanager->GetBoardByIndex(boardid);
    if (!board)
        {
            mobile->Message(MSG_ERROR, "The board you have set does not exist.");
            return;
        }

    post = board->GetPostByIndex(id);
    if (!post)
        {
            mobile->Message(MSG_ERROR, "That post does not exist.");
            return;
        }

    st << left << setw(15) << "From: " << right << post->GetPoster() << endl;
    st << left << setw(15) << "Subject: " << right << post->GetSubject() << endl;
    st << post->GetMessage() << endl;
    mobile->Message(MSG_INFO, st.str());
}
int YujinRobot_iRobiQBumper::SetParameter(Property parameter)
{
	if(parameter.FindName("Size") == false)				return API_ERROR;
	int size = atoi(parameter.GetValue("Size").c_str());

	if(size < 0) {
		return API_ERROR;
	}

	char name[128];
	for(int i = 0; i < size; i++) {
		sprintf(name, "X%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
		
		sprintf(name, "Y%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
		
		sprintf(name, "Z%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
		
		sprintf(name, "Roll%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
		
		sprintf(name, "Pitch%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
		
		sprintf(name, "Yaw%d", i);
		if(parameter.FindName(string(name)) == false)			goto ERROR_YujinRobot_iRobiQBumper_SetParameter;
	}

	this->parameter = parameter;

	return API_SUCCESS;

ERROR_YujinRobot_iRobiQBumper_SetParameter :
	PrintMessage("ERROR : YujinRobot_iRobiQBumper::SetParameter() -> Can't find a property in parameter.\n");
	return API_ERROR;
}
Exemplo n.º 18
0
int ESD_CAN::Initialize(Property parameter)
{
	if(isInitialized == true) {
		return API_SUCCESS;
	}

	if(parameter.FindName("Channel") == false)			return API_ERROR;
	channel = atoi(parameter.GetValue("Channel").c_str());

	if(channel < 0) {
		return API_ERROR;
	}

	if(canInfo.find(channel) != canInfo.end()) {
		canInfo[channel]->nHandle++;
		isInitialized = true;
		return API_SUCCESS;
	}

	if(parameter.FindName("TimeOut") == false)			return API_ERROR;
	long timeOut = atol(parameter.GetValue("TimeOut").c_str());
	if(parameter.FindName("BitRate") == false)			return API_ERROR;
	long bitRate = atol(parameter.GetValue("BitRate").c_str());
	if(parameter.FindName("AcceptanceMask") == false)			return API_ERROR;
	long acceptanceMask = atol(parameter.GetValue("AcceptanceMask").c_str());
	if(parameter.FindName("AcceptanceCode") == false)			return API_ERROR;
	long acceptanceCode = atol(parameter.GetValue("AcceptanceCode").c_str());
	if(parameter.FindName("Mode") == false)			return API_ERROR;
	bool isExtended = true;
	if(atoi(parameter.GetValue("Mode").c_str()) == 0) {
		isExtended = false;
	}

	ESDCANInfo *tmp = new ESDCANInfo(channel, bitRate, acceptanceMask, acceptanceCode, isExtended, timeOut);
	canInfo[channel] = tmp;
	canInfo[channel]->nHandle++;

	isInitialized = true;

	return API_SUCCESS;
}
Exemplo n.º 19
0
int Simulator_Manipulator::SetParameter(Property parameter)
{
	if(parameter.FindName("NumberOfJoints") == false)		return API_ERROR;

	if(parameter.FindName("IP") == false)					return API_ERROR;
	if(parameter.FindName("Port") == false)					return API_ERROR;
	if(parameter.FindName("RobotName") == false)			return API_ERROR;

	_numberOfJoints = atoi(parameter.GetValue("NumberOfJoints").c_str());
	_devicesName.resize(_numberOfJoints * 2);

	char name[128];

	for(size_t i = 0; i < _numberOfJoints; i++) {
		sprintf(name, "MotorName%d", i);
		if(parameter.FindName(name) == false) {
			_numberOfJoints = 0;
			_devicesName.clear();
			return API_ERROR;
		}
		_devicesName[i] = parameter.GetValue(name);

		sprintf(name, "EncoderName%d", i);
		if(parameter.FindName(name) == false) {
			_numberOfJoints = 0;
			_devicesName.clear();
			return API_ERROR;
		}
		_devicesName[i + _numberOfJoints] = parameter.GetValue(name);
	}

	_ip = parameter.GetValue("IP");
	_port = atoi(parameter.GetValue("Port").c_str());
	_robotName = parameter.GetValue("RobotName");

	return API_SUCCESS;
}
Exemplo n.º 20
0
// Call back Declaration
ReturnType GyroSensorComp::onInitialize()
{
	Property parameter;
	std::map<std::string, std::string> temp = getPropertyMap();
	parameter.SetProperty(temp);
	
	if(parameter.FindName("ApiName") == false) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't find the APIName in property\n");
		return lastError = OPROS_FIND_PROPERTY_ERROR;
	}
	
#if defined(WIN32)
	//	DLL 로드
	hOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("ApiName").c_str());
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("ApiName").c_str());
		return lastError = OPROS_FIND_DLL_ERROR;
	}
	
	//	API 로드
	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)GetProcAddress(hOprosAPI, "GetAPI");
	if(getOprosAPI == NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return lastError = OPROS_LOAD_DLL_ERROR;
	}

	//	API Casting
	gyroSensor = dynamic_cast<GyroSensor *>(getOprosAPI());
	if(gyroSensor == NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't get a handle of AccelerationSensor API\n");
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return lastError = OPROS_LOAD_DLL_ERROR;
	}
#else
	//	Shared Library 로드
	hOprosAPI = dlopen(parameter.GetValue("ApiName").c_str(), RTLD_NOW);
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("ApiName").c_str());
		return lastError = OPROS_FIND_DLL_ERROR;
	}

	//	API 로드
	GET_OPROS_API getOprosAPI = (GET_OPROS_API)dlsym(hOprosAPI, "GetAPI");
	char *error = dlerror();
	if(error != NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return lastError = OPROS_LOAD_DLL_ERROR;
	}
	
	//	API Casting
	gyroSensor = static_cast<GyroSensor *>(getOprosAPI());
	if(gyroSensor == NULL) {
		PrintMessage("ERROR : GyroSensorComp::onInitialize() -> Can't get a handle of AccelerationSensor API\n");
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return lastError = OPROS_LOAD_DLL_ERROR;
	}
#endif

	if(gyroSensor->Initialize(parameter) != API_SUCCESS) {
		delete gyroSensor;
		gyroSensor = NULL;

#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return lastError = OPROS_INITIALIZE_API_ERROR;
	}

	return lastError = OPROS_SUCCESS;
}
Exemplo n.º 21
0
int VidereSthDcsgVarMultiCamera::SetParameter(Property parameter)
{
	if (!parameter.FindName("Count") ) {
		PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name.\n");
		return API_ERROR;
	}
	_nCameraCount = atoi( (parameter.GetValue("Count")).c_str() );

	if( 0 < _nCameraCount ) {
		if( _id ) {
			free(_id);			_id = 0;
		}
		if( _width ) {
			free(_width);		_width = 0;
		}
		if( _height ) {
			free(_height);		_height = 0;
		}
		if( _pixelByte ) {
			free(_pixelByte);	_pixelByte = 0;
		}
		if( _flip ) {
			free(_flip);		_flip = 0;
		}

		_id = (int *)malloc(_nCameraCount*sizeof(int));
		_width = (int *)malloc(_nCameraCount*sizeof(int));
		_height = (int *)malloc(_nCameraCount*sizeof(int));
		_pixelByte = (int *)malloc(_nCameraCount*sizeof(int));
		_flip = (int *)malloc(_nCameraCount*sizeof(int));

		//	CalibratedParameter parameter를 확인하여 없으면 에러 리턴
		if(parameter.FindName("CalibrationFilename") == false) {
			PrintMessage("WARNING : VidereSthDcsgVarMultiCamera::SetParameter() -> Can't find the Calibration file in property\n");
			//return API_ERROR;
			_calibrationFilename = parameter.GetValue("APIName");	// apiname으로 대체
		}
		else _calibrationFilename = parameter.GetValue("CalibrationFilename");

		char str[256];
		for( int i = 0  ;  i < _nCameraCount  ;  i++ ) {
			sprintf(str, "CameraID%d", i);
			if( !parameter.FindName(str) ) {
				PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name %s\n", str);
				return API_ERROR;
			}
			_id[i] = atoi( (parameter.GetValue(string(str))).c_str() );

			sprintf(str, "Width%d", i);
			if( !parameter.FindName(str) ) {
				PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name %s\n", str);
				return API_ERROR;
			}
			_width[i] = atoi( (parameter.GetValue(string(str))).c_str() );

			sprintf(str, "Height%d", i);
			if( !parameter.FindName(str) ) {
				PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name %s\n", str);
				return API_ERROR;
			}
			_height[i] = atoi( (parameter.GetValue(string(str))).c_str() );

			sprintf(str, "PixelBytes%d", i);
			if( !parameter.FindName(str) ) {
				PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name %s\n", str);
				return API_ERROR;
			}
			_pixelByte[i] = atoi( (parameter.GetValue(string(str))).c_str() );

			sprintf(str, "Flip%d", i);
			if( !parameter.FindName(str) ) {
				PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Can't find parameter(s) name %s\n", str);
				return API_ERROR;
			}
			_flip[i] = atoi( (parameter.GetValue(string(str))).c_str() );

			// check image size
			if(i>0)
			{
				if(_width[0]!=_width[i] || _height[0]!=_height[i] || _pixelByte[0]!=_pixelByte[i])
				{
					PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter() -> Each camera must have same parameters(width,height,pixelbytes)!\n");
					return API_ERROR;
				}
			}

		}

		PrintMessage("SUCCESS: VidereSthDcsgVarMultiCamera::SetParameter() OK!\n");
		PrintMessage("Count:%d, calibrationFilename:%s\n", _nCameraCount, _calibrationFilename.c_str() );
		for(int i=0; i<_nCameraCount;i++) 
			PrintMessage("CameraID:%d, width:%d, height:%d, pixelbytes:%d, flip:%d\n", _id[i],_width[i],_height[i],_pixelByte[i],_flip[i]);


		this->parameter = parameter;


		return API_SUCCESS;
	}
	else {
		PrintMessage("Error:VidereSthDcsgVarMultiCamera::SetParameter()->Camera count is 0.\n");
		return API_ERROR;
	}
}
bool KITECH_InverseDynamicsControlComp::SetParameter(Property parameter)
{
	int jointCount;
	int jointType, jointAxis;
	double x, y, z, phi, theta, psi;
	double mass, cx, cy, cz;
	double ixx, iyy, izz, ixy, iyz, izx;
	
	char name[128];
	double gravity[3] = {0., 0., -9.81 };

	onDestroy();

	//	Setup a control period
	if(parameter.FindName("Period") == false) {
		PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find the Period in property\n");
		return false;
	}
	_dynamics = new InverseDynamicsControl(gravity, atof(parameter.GetValue("Period").c_str()));

	//	Setup a count of joints
	if(parameter.FindName("JointCount") == false) {
		PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find the JointCount in property\n");
		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
	}
	jointCount = atoi(parameter.GetValue("JointCount").c_str());

	//	Set gains
	if(parameter.FindName("Kp") == false) {
		PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find the JointCount in property\n");
		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
	}
	_dynamics->SetKp(atof(parameter.GetValue("Kp").c_str()));

	if(parameter.FindName("Ki") == false) {
		PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find the JointCount in property\n");
		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
	}
	_dynamics->SetKi(atof(parameter.GetValue("Ki").c_str()));

	if(parameter.FindName("Kd") == false) {
		PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find the JointCount in property\n");
		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
	}
	_dynamics->SetKd(atof(parameter.GetValue("Kd").c_str()));

			
	//	Setup a joint information
	PrintMessage("KITECH_InverseDynamicsControlComp Joint Information\n");

	for(int i = 0; i < jointCount; i++) {
		sprintf(name, "JointType%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										jointType = atoi(parameter.GetValue(name).c_str());

		sprintf(name, "JointAxis%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										jointAxis = atoi(parameter.GetValue(name).c_str());

		sprintf(name, "X%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										x = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Y%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										y = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Z%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										z = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Phi%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										phi = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Theta%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										theta = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Psi%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										psi = atof(parameter.GetValue(name).c_str());

		sprintf(name, "Mass%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										mass = atof(parameter.GetValue(name).c_str());

		
		sprintf(name, "CX%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										cx = atof(parameter.GetValue(name).c_str());

		
		sprintf(name, "CY%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										cy = atof(parameter.GetValue(name).c_str());

		sprintf(name, "CZ%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										cz = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IXX%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										ixx = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IYY%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										iyy = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IZZ%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										izz = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IXY%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										ixy = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IYZ%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										iyz = atof(parameter.GetValue(name).c_str());

		sprintf(name, "IZX%d", i);
		if(parameter.FindName(name) == false)		goto ERROR_KITECH_InverseDynamicsControlComp_SetParameter;
		else										izx = atof(parameter.GetValue(name).c_str());

		_dynamics->AttachJoint(jointType, jointAxis, mass, cx, cy, cz, ixx, iyy, izz, ixy, iyz, izx, x, y, z, phi, theta, psi, 0.3);

		PrintMessage("Axis%d %d %d %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
					i, jointType, jointAxis, x, y, z, phi, theta, psi, mass, cx, cy, cz, ixx, iyy, izz, ixy, iyz, izx);
	}

	this->parameter = parameter;

	return true;

ERROR_KITECH_InverseDynamicsControlComp_SetParameter :
	PrintMessage("ERROR : KITECH_InverseDynamicsControlComp::SetParameter() -> Can't find parameters in property\n");
	onDestroy();
	return false;
}
Exemplo n.º 23
0
int KITECH_SDM8::InitializeUART(Property parameter)
{
	Property uartParameter;

	if(parameter.FindName("UARTAPIName") == false)	return API_ERROR;
	if(parameter.FindName("PortName") == false)	return API_ERROR;	uartParameter.SetValue("PortName", parameter.GetValue("PortName"));
	if(parameter.FindName("TimeOut") == false)		return API_ERROR;	uartParameter.SetValue("TimeOut", parameter.GetValue("TimeOut"));
	if(parameter.FindName("BaudRate") == false)	return API_ERROR;	uartParameter.SetValue("BaudRate", parameter.GetValue("BaudRate"));
	if(parameter.FindName("DataBits") == false)	return API_ERROR;	uartParameter.SetValue("DataBits", parameter.GetValue("DataBits"));
	if(parameter.FindName("StopBits") == false)	return API_ERROR;	uartParameter.SetValue("StopBits", parameter.GetValue("StopBits"));
	if(parameter.FindName("Parity") == false)		return API_ERROR;	uartParameter.SetValue("Parity", parameter.GetValue("Parity"));
	if(parameter.FindName("FlowControl") == false)	return API_ERROR;	uartParameter.SetValue("FlowControl", parameter.GetValue("FlowControl"));

	if(uart != NULL) {
		delete uart;
	}
#if defined(WIN32)
	//	DLL 로드
	hOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("UARTAPIName").c_str());
	if(hOprosAPI == NULL) {
		return API_ERROR;
	}

	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)GetProcAddress(hOprosAPI, "GetAPI");
	if(getOprosAPI == NULL) {
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return API_ERROR;
	}
#else
	hOprosAPI = dlopen(parameter.GetValue("UARTAPIName").c_str(), RTLD_LAZY);
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : InitializeUART() -> dlopen (%s)\n",parameter.GetValue("UARTDllName").c_str());
		return API_ERROR;
	}

	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)dlsym(hOprosAPI, "GetAPI");
	char *error = dlerror();
	if(error != NULL) {
		PrintMessage ("ERROR -> %s\n", error);
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return API_ERROR;
	}
#endif

	uart = (UART *)getOprosAPI();
	if(uart == NULL) {
#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return API_ERROR;
	}

	//	API 초기화
	if(uart->Initialize(uartParameter) < 0) {
		FinalizeUART();
		return API_ERROR;
	}

	if(uart->Enable() < 0) {
		FinalizeUART();
		return API_ERROR;
	}

	return API_SUCCESS;
}
Exemplo n.º 24
0
int KITECH_SDM8::SetParameter(Property parameter)
{
	if(uart == NULL) {
		PrintMessage("ERROR : KITECH_SDM8::SetParameter() -> A handle of UART is NULL.\n");
		return API_ERROR;
	}

	if(parameter.FindName("Size") == false)				return API_ERROR;
	int size = atoi(parameter.GetValue("Size").c_str());

	if(size <= 0) 	return API_ERROR;
	
	joints.clear();
	joints.resize(size);

	char temp[64];
	
	for(int i = 0; i < size; i++) {
		sprintf(temp, "ID%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].id = atoi(parameter.GetValue(temp).c_str());

		sprintf(temp, "MaximumPower%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].maximumPower = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "LinePerRevolution%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].linePerRevolution = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "ReductionRatio%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].reductionRatio = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "MaximumVelocity%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].maximumVelocity = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "Acceleration%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].acceleration = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "MinimumPositionLimit%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].minimumPositionLimit = atof(parameter.GetValue(temp).c_str());

		sprintf(temp, "MaximumPositionLimit%d", i);
		if(parameter.FindName(string(temp)) == false)			goto ERROR_KITECH_SDM8_SET_PARAMETER;
		joints[i].maximumPositionLimit = atof(parameter.GetValue(temp).c_str());		

		joints[i].deg2pulse = ENCODER_RESOLUTION / 360.0 / joints[i].reductionRatio;
		joints[i].deg2rpm = 60.0 / 360.0 / joints[i].reductionRatio;

		joints[i].dynamixel = new RobotisDynamixelUART(joints[i].id, uart);
	}
	
	for(size_t i = 0; i < joints.size(); i++) {
		joints[i].dynamixel->SetMovingspeed(100);
	}

	this->parameter = parameter;

	return API_SUCCESS;

ERROR_KITECH_SDM8_SET_PARAMETER :
	PrintMessage("ERROR : KITECH_SDM8::SetParameter() -> Can't find parameters\n");
	joints.clear();
	joints.resize(size);
	return API_ERROR;
}
int DasaRobot_MobilityUltrasonic::InitializeUART(Property parameter)
{
	Property uartParameter;
	char *error = NULL;

	if(parameter.FindName("UARTAPIName") == false)	goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	if(parameter.FindName("PortName") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("PortName", parameter.GetValue("PortName"));
	if(parameter.FindName("TimeOut") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("TimeOut", parameter.GetValue("TimeOut"));
	if(parameter.FindName("BaudRate") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("BaudRate", parameter.GetValue("BaudRate"));
	if(parameter.FindName("DataBits") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("DataBits", parameter.GetValue("DataBits"));
	if(parameter.FindName("StopBits") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("StopBits", parameter.GetValue("StopBits"));
	if(parameter.FindName("Parity") == false)		goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("Parity", parameter.GetValue("Parity"));
	if(parameter.FindName("FlowControl") == false)	goto ERROR_DasaRobot_MobilityUltrasonic_InitializeUART;
	else	uartParameter.SetValue("FlowControl", parameter.GetValue("FlowControl"));

	if(uart != NULL) {
		delete uart;
		uart = NULL;
	}
#if defined(WIN32)
	//	DLL 로드
	hOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("UARTAPIName").c_str());
	if(hOprosAPI == NULL) {
		return API_ERROR;
	}

	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)GetProcAddress(hOprosAPI, "GetAPI");
	if(getOprosAPI == NULL) {
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return API_ERROR;
	}
#else
	hOprosAPI = dlopen(parameter.GetValue("UARTAPIName").c_str(), RTLD_LAZY);
	if(hOprosAPI == NULL) {
		return API_ERROR;
	}

	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)dlsym(hOprosAPI, "GetAPI");
	error = dlerror();
	if(error != NULL) {
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return API_ERROR;
	}
#endif

	uart = (UART *)getOprosAPI();
	if(uart == NULL) {
		Finalize();
		return API_ERROR;
	}

	//	API 초기화
	if(uart->Initialize(uartParameter) < 0) {
		Finalize();
		return API_ERROR;
	}

	if(uart->Enable() < 0) {
		Finalize();
		return API_ERROR;
	}

	return API_SUCCESS;

ERROR_DasaRobot_MobilityUltrasonic_InitializeUART :
	PrintMessage("ERROR : DasaRobot_MobilityUltrasonic::InitializeUART() -> Can't find a property in parameter.\n");
	return API_ERROR;
}
Exemplo n.º 26
0
void CONFIG::Run(void) {
	static const char* const params[] = {
		"-r", "-wcp", "-wcd", "-wc", "-writeconf", "-l", "-rmconf",
		"-h", "-help", "-?", "-axclear", "-axadd", "-axtype", "-get", "-set",
		"-writelang", "-wl", "-securemode", "" };
	enum prs {
		P_NOMATCH, P_NOPARAMS, // fixed return values for GetParameterFromList
		P_RESTART,
		P_WRITECONF_PORTABLE, P_WRITECONF_DEFAULT, P_WRITECONF, P_WRITECONF2,
		P_LISTCONF,	P_KILLCONF,
		P_HELP, P_HELP2, P_HELP3,
		P_AUTOEXEC_CLEAR, P_AUTOEXEC_ADD, P_AUTOEXEC_TYPE,
		P_GETPROP, P_SETPROP,
		P_WRITELANG, P_WRITELANG2,
		P_SECURE
	} presult = P_NOMATCH;
	
	bool first = true;
	std::vector<std::string> pvars;
	// Loop through the passed parameters
	while(presult != P_NOPARAMS) {
		presult = (enum prs)cmd->GetParameterFromList(params, pvars);
		switch(presult) {
		
		case P_RESTART:
			if (securemode_check()) return;
			if (pvars.size() == 0) restart_program(control->startup_params);
			else {
				std::vector<std::string> restart_params;
				restart_params.push_back(control->cmdline->GetFileName());
				for(size_t i = 0; i < pvars.size(); i++) {
					restart_params.push_back(pvars[i]);
					if (pvars[i].find(' ') != std::string::npos) {
						pvars[i] = "\""+pvars[i]+"\""; // add back spaces
					}
				}
				// the rest on the commandline, too
				cmd->FillVector(restart_params);
				restart_program(restart_params);
			}
			return;
		
		case P_LISTCONF: {
			Bitu size = control->configfiles.size();
			std::string config_path;
			Cross::GetPlatformConfigDir(config_path);
			WriteOut(MSG_Get("PROGRAM_CONFIG_CONFDIR"), VERSION,config_path.c_str());
			if (size==0) WriteOut(MSG_Get("PROGRAM_CONFIG_NOCONFIGFILE"));
			else {
				WriteOut(MSG_Get("PROGRAM_CONFIG_PRIMARY_CONF"),control->configfiles.front().c_str());
				if (size > 1) {
					WriteOut(MSG_Get("PROGRAM_CONFIG_ADDITIONAL_CONF"));
					for(Bitu i = 1; i < size; i++)
						WriteOut("%s\n",control->configfiles[i].c_str());
				}
			}
			if (control->startup_params.size() > 0) {
				std::string test;
				for(size_t k = 0; k < control->startup_params.size(); k++)
					test += control->startup_params[k] + " ";
				WriteOut(MSG_Get("PROGRAM_CONFIG_PRINT_STARTUP"), test.c_str());
			}
			break;
		}
		case P_WRITECONF: case P_WRITECONF2:
			if (securemode_check()) return;
			if (pvars.size() > 1) return;
			else if (pvars.size() == 1) {
				// write config to specific file, except if it is an absolute path
				writeconf(pvars[0], !Cross::IsPathAbsolute(pvars[0]));
			} else {
				// -wc without parameter: write primary config file
				if (control->configfiles.size()) writeconf(control->configfiles[0], false);
				else WriteOut(MSG_Get("PROGRAM_CONFIG_NOCONFIGFILE"));
			}
			break;
		case P_WRITECONF_DEFAULT: {
			// write to /userdir/dosbox0.xx.conf
			if (securemode_check()) return;
			if (pvars.size() > 0) return;
			std::string confname;
			Cross::GetPlatformConfigName(confname);
			writeconf(confname, true);
			break;
		}
		case P_WRITECONF_PORTABLE:
			if (securemode_check()) return;
			if (pvars.size() > 1) return;
			else if (pvars.size() == 1) {
				// write config to startup directory
				writeconf(pvars[0], false);
			} else {
				// -wcp without parameter: write dosbox.conf to startup directory
				if (control->configfiles.size()) writeconf(std::string("dosbox.conf"), false);
				else WriteOut(MSG_Get("PROGRAM_CONFIG_NOCONFIGFILE"));
			}
			break;

		case P_NOPARAMS:
			if (!first) break;

		case P_NOMATCH:
			WriteOut(MSG_Get("PROGRAM_CONFIG_USAGE"));
			return;

		case P_HELP: case P_HELP2: case P_HELP3: {
			switch(pvars.size()) {
			case 0:
				WriteOut(MSG_Get("PROGRAM_CONFIG_USAGE"));
				return;
			case 1: {
				if (!strcasecmp("sections",pvars[0].c_str())) {
					// list the sections
					WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_SECTLIST"));
					Bitu i = 0;
					while(true) {
						Section* sec = control->GetSection(i++);
						if (!sec) break;
						WriteOut("%s\n",sec->GetName());
					}
					return;
				}
				// if it's a section, leave it as one-param
				Section* sec = control->GetSection(pvars[0].c_str());
				if (!sec) {
					// could be a property
					sec = control->GetSectionFromProperty(pvars[0].c_str());
					if (!sec) {
						WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
						return;
					}
					pvars.insert(pvars.begin(),std::string(sec->GetName()));
				}
				break;
			}
			case 2: {
				// sanity check
				Section* sec = control->GetSection(pvars[0].c_str());
				Section* sec2 = control->GetSectionFromProperty(pvars[1].c_str());
				if (sec != sec2) {
					WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
				}
				break;
			}
			default:
				WriteOut(MSG_Get("PROGRAM_CONFIG_USAGE"));
				return;
			}	
			// if we have one value in pvars, it's a section
			// two values are section + property
			Section* sec = control->GetSection(pvars[0].c_str());
			if (sec==NULL) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
				return;
			}
			Section_prop* psec = dynamic_cast <Section_prop*>(sec);
			if (psec==NULL) {
				// failed; maybe it's the autoexec section?
				Section_line* pline = dynamic_cast <Section_line*>(sec);
				if (pline==NULL) E_Exit("Section dynamic cast failed.");

				WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_LINEHLP"),
					pline->GetName(),
					// this is 'unclean' but the autoexec section has no help associated
					MSG_Get("AUTOEXEC_CONFIGFILE_HELP"),
					pline->data.c_str() );
				return;
			} 
			if (pvars.size()==1) {
				size_t i = 0;
				WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_SECTHLP"),pvars[0].c_str());
				while(true) {
					// list the properties
					Property* p = psec->Get_prop(i++);
					if (p==NULL) break;
					WriteOut("%s\n", p->propname.c_str());
				}
			} else {
				// find the property by it's name
				size_t i = 0;
				while (true) {
					Property *p = psec->Get_prop(i++);
					if (p==NULL) break;
					if (!strcasecmp(p->propname.c_str(),pvars[1].c_str())) {
						// found it; make the list of possible values
						std::string propvalues;
						std::vector<Value> pv = p->GetValues();
						
						if (p->Get_type()==Value::V_BOOL) {
							// possible values for boolean are true, false
							propvalues += "true, false";
						} else if (p->Get_type()==Value::V_INT) {
							// print min, max for integer values if used
							Prop_int* pint = dynamic_cast <Prop_int*>(p);
							if (pint==NULL) E_Exit("Int property dynamic cast failed.");
							if (pint->getMin() != pint->getMax()) {
								std::ostringstream oss;
								oss << pint->getMin();
								oss << "..";
								oss << pint->getMax();
								propvalues += oss.str();
							}
						}
						for(Bitu k = 0; k < pv.size(); k++) {
							if (pv[k].ToString() =="%u")
								propvalues += MSG_Get("PROGRAM_CONFIG_HLP_POSINT");
							else propvalues += pv[k].ToString();
							if ((k+1) < pv.size()) propvalues += ", ";
						}

						WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_PROPHLP"),
							p->propname.c_str(),
							sec->GetName(),
							p->Get_help(),propvalues.c_str(),
							p->Get_Default_Value().ToString().c_str(),
							p->GetValue().ToString().c_str());
						// print 'changability'
						if (p->getChange()==Property::Changeable::OnlyAtStart) {
							WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_NOCHANGE"));
						}
						return;
					}
				}
				break;
			}
			return;
		}
		case P_AUTOEXEC_CLEAR: {
			Section_line* sec = dynamic_cast <Section_line*>
				(control->GetSection(std::string("autoexec")));
			sec->data.clear();
			break;
		}
		case P_AUTOEXEC_ADD: {
			if (pvars.size() == 0) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_MISSINGPARAM"));
				return;
			}
			Section_line* sec = dynamic_cast <Section_line*>
				(control->GetSection(std::string("autoexec")));

			for(Bitu i = 0; i < pvars.size(); i++) sec->HandleInputline(pvars[i]);
			break;
		}
		case P_AUTOEXEC_TYPE: {
			Section_line* sec = dynamic_cast <Section_line*>
				(control->GetSection(std::string("autoexec")));
			WriteOut("\n%s",sec->data.c_str());
			break;
		}
		case P_GETPROP: {
			// "section property"
			// "property"
			// "section"
			// "section" "property"
			if (pvars.size()==0) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_GET_SYNTAX"));
				return;
			}
			std::string::size_type spcpos = pvars[0].find_first_of(' ');
			// split on the ' '
			if (spcpos != std::string::npos) {
				pvars.insert(++pvars.begin(),pvars[0].substr(spcpos+1));
				pvars[0].erase(spcpos);
			}
			switch(pvars.size()) {
			case 1: {
				// property/section only
				// is it a section?
				Section* sec = control->GetSection(pvars[0].c_str());
				if (sec) {
					// list properties in section
					Bitu i = 0;
					Section_prop* psec = dynamic_cast <Section_prop*>(sec);
					if (psec==NULL) {
						// autoexec section
						Section_line* pline = dynamic_cast <Section_line*>(sec);
						if (pline==NULL) E_Exit("Section dynamic cast failed.");

						WriteOut("%s",pline->data.c_str());
						break;
					}
					while(true) {
						// list the properties
						Property* p = psec->Get_prop(i++);
						if (p==NULL) break;
						WriteOut("%s=%s\n", p->propname.c_str(),
							p->GetValue().ToString().c_str());
					}
				} else {
					// no: maybe it's a property?
					sec = control->GetSectionFromProperty(pvars[0].c_str());
					if (!sec) {
						WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
						return;
					}
					// it's a property name
					std::string val = sec->GetPropValue(pvars[0].c_str());
					WriteOut("%s",val.c_str());
				}
				break;
			}
			case 2: {
				// section + property
				Section* sec = control->GetSection(pvars[0].c_str());
				if (!sec) {
					WriteOut(MSG_Get("PROGRAM_CONFIG_SECTION_ERROR"));
					return;
				}
				std::string val = sec->GetPropValue(pvars[1].c_str());
				if (val == NO_SUCH_PROPERTY) {
					WriteOut(MSG_Get("PROGRAM_CONFIG_NO_PROPERTY"),
						pvars[1].c_str(),pvars[0].c_str());   
					return;
				}
				WriteOut("%s",val.c_str());
				break;
			}
			default:
				WriteOut(MSG_Get("PROGRAM_CONFIG_GET_SYNTAX"));
				return;
			}
			return;
		}
		case P_SETPROP:	{
			// Code for the configuration changes
			// Official format: config -set "section property=value"
			// Accepted: with or without -set, 
			// "section property value"
			// "section property=value"
			// "property" "value"
			// "section" "property=value"
			// "section" "property=value" "value" "value" ...
			// "section" "property" "value" "value" ...
			// "section property" "value" "value" ...
			// "property" "value" "value" ...
			// "property=value" "value" "value" ...

			if (pvars.size()==0) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_SET_SYNTAX"));
				return;
			}

			// add rest of command
			std::string rest;
			if (cmd->GetStringRemain(rest)) pvars.push_back(rest);

			// attempt to split off the first word
			std::string::size_type spcpos = pvars[0].find_first_of(' ');
			std::string::size_type equpos = pvars[0].find_first_of('=');

			if ((equpos != std::string::npos) && 
				((spcpos == std::string::npos) || (equpos < spcpos))) {
				// If we have a '=' possibly before a ' ' split on the =
				pvars.insert(++pvars.begin(),pvars[0].substr(equpos+1));
				pvars[0].erase(equpos);
				// As we had a = the first thing must be a property now
				Section* sec=control->GetSectionFromProperty(pvars[0].c_str());
				if (sec) pvars.insert(pvars.begin(),std::string(sec->GetName()));
				else {
					WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
					return;
				}
				// order in the vector should be ok now
			} else {
				if ((spcpos != std::string::npos) &&
					((equpos == std::string::npos) || (spcpos < equpos))) {
					// ' ' before a possible '=', split on the ' '
					pvars.insert(++pvars.begin(),pvars[0].substr(spcpos+1));
					pvars[0].erase(spcpos);
				}
				// check if the first parameter is a section or property
				Section* sec = control->GetSection(pvars[0].c_str());
				if (!sec) {
					// not a section: little duplicate from above
					Section* sec=control->GetSectionFromProperty(pvars[0].c_str());
					if (sec) pvars.insert(pvars.begin(),std::string(sec->GetName()));
					else {
						WriteOut(MSG_Get("PROGRAM_CONFIG_PROPERTY_ERROR"));
						return;
					}
				} else {
					// first of pvars is most likely a section, but could still be gus
					// have a look at the second parameter
					if (pvars.size() < 2) {
						WriteOut(MSG_Get("PROGRAM_CONFIG_SET_SYNTAX"));
						return;
					}
					std::string::size_type spcpos2 = pvars[1].find_first_of(' ');
					std::string::size_type equpos2 = pvars[1].find_first_of('=');
					if ((equpos2 != std::string::npos) && 
						((spcpos2 == std::string::npos) || (equpos2 < spcpos2))) {
						// split on the =
						pvars.insert(pvars.begin()+2,pvars[1].substr(equpos2+1));
						pvars[1].erase(equpos2);
					} else if ((spcpos2 != std::string::npos) &&
						((equpos2 == std::string::npos) || (spcpos2 < equpos2))) {
						// split on the ' '
						pvars.insert(pvars.begin()+2,pvars[1].substr(spcpos2+1));
						pvars[1].erase(spcpos2);
					}
					// is this a property?
					Section* sec2 = control->GetSectionFromProperty(pvars[1].c_str());
					if (!sec2) {
						// not a property, 
						Section* sec3 = control->GetSectionFromProperty(pvars[0].c_str());
						if (sec3) {
							// section and property name are identical
							pvars.insert(pvars.begin(),pvars[0]);
						} // else has been checked above already
					}
				}
			}
			if(pvars.size() < 3) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_SET_SYNTAX"));
				return;
			}
			// check if the property actually exists in the section
			Section* sec2 = control->GetSectionFromProperty(pvars[1].c_str());
			if (!sec2) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_NO_PROPERTY"),
					pvars[1].c_str(),pvars[0].c_str());
				return;
			}
			// Input has been parsed (pvar[0]=section, [1]=property, [2]=value)
			// now execute
			Section* tsec = control->GetSection(pvars[0]);
			std::string value;
			value += pvars[2];
			for(Bitu i = 3; i < pvars.size(); i++) value += (std::string(" ") + pvars[i]);
			std::string inputline = pvars[1] + "=" + value;
			
			tsec->ExecuteDestroy(false);
			bool change_success = tsec->HandleInputline(inputline.c_str());
			if (!change_success) WriteOut(MSG_Get("PROGRAM_CONFIG_VALUE_ERROR"),
				value.c_str(),pvars[1].c_str());
			tsec->ExecuteInit(false);
			return;
		}
		case P_WRITELANG: case P_WRITELANG2:
			// In secure mode don't allow a new languagefile to be created
			// Who knows which kind of file we would overwrite.
			if (securemode_check()) return;
			if (pvars.size() < 1) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_MISSINGPARAM"));
				return;
			}
			if (!MSG_Write(pvars[0].c_str())) {
				WriteOut(MSG_Get("PROGRAM_CONFIG_FILE_ERROR"),pvars[0].c_str());
				return;
			}
			break;

		case P_SECURE:
			// Code for switching to secure mode
			control->SwitchToSecureMode();
			WriteOut(MSG_Get("PROGRAM_CONFIG_SECURE_ON"));
			return;

		default:
			E_Exit("bug");
			break;
		}
		first = false;
	}
	return;
}
Exemplo n.º 27
0
// Call back Declaration
ReturnType KinectComp::onInitialize()
{
	//	XML에 저장된 프라퍼티를 parameter에 저장	
	std::map<std::string, std::string>& propertyMap = getPropertyMap();
	Property parameter;
	parameter.SetProperty(propertyMap);

	//	dll 파일이름을 확인하여 없으면 에러 리턴
	if (parameter.FindName("APIName") == false)
	{
		PrintMessage(DEBUG_MESSAGE("Can't find the APIName in property").c_str());
		return OPROS_FIND_PROPERTY_ERROR;
	}

	//DLL 로드
	mhOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("APIName").c_str());
	if (mhOprosAPI == NULL)
	{
		PrintMessage(DEBUG_MESSAGE("Can't get a handle of GetAPI Funtion").c_str());
		PrintMessage(DEBUG_MESSAGE("Can't get a DLL").c_str());

		return OPROS_FIND_DLL_ERROR;
	}

	//API 로드
	GET_OPROS_API getOprosAPI = (GET_OPROS_API)GetProcAddress(mhOprosAPI, "GetAPI");
	if (getOprosAPI == NULL)
	{
		PrintMessage(DEBUG_MESSAGE("Can't get a handle of GetAPI Funtion").c_str());
		PrintMessage(DEBUG_MESSAGE("Can't load API").c_str());

		FreeLibrary(mhOprosAPI);
		mhOprosAPI = NULL;

		return OPROS_LOAD_DLL_ERROR;
	}

	mpKinect = dynamic_cast<Kinect *>(getOprosAPI());
	if(mpKinect == NULL)
	{
		PrintMessage(DEBUG_MESSAGE("Can't get a handle of Kinect API").c_str());
		PrintMessage(DEBUG_MESSAGE("Can't get a Casting").c_str());

		FreeLibrary(mhOprosAPI);
		mhOprosAPI = NULL;

		return OPROS_LOAD_DLL_ERROR;
	}

	//API 초기화
	if(mpKinect->Initialize(parameter) != API_SUCCESS)
	{
		PrintMessage(DEBUG_MESSAGE("Can't initialize a Kinect API").c_str());

		delete mpKinect;
		mpKinect = NULL;

		FreeLibrary(mhOprosAPI);
		mhOprosAPI = NULL;

		return OPROS_INITIALIZE_API_ERROR;
	}

	return OPROS_SUCCESS;
}
Exemplo n.º 28
0
// Call back Declaration
ReturnType TCPIPComp::onInitialize()
{
	//	XML에 저장된 프라퍼티를 parameter에 저장
	Property parameter;
	std::map<std::string, std::string> temp = getPropertyMap();
	parameter.SetProperty(temp);
	
	//	dll 파일이름을 확인하여 없으면 에러 리턴
	if(parameter.FindName("APIName") == false) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't find the APIName in property\n");
		return OPROS_FIND_PROPERTY_ERROR;
	}

#if defined(WIN32)
	//	Load a DLL
	hOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("APIName").c_str());
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("APIName").c_str());
		return OPROS_FIND_DLL_ERROR;
	}
	
	//	Load a API
	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)GetProcAddress(hOprosAPI, "GetAPI");
	if(getOprosAPI == NULL) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}
#else
	//	Load a shared library
	hOprosAPI = dlopen(parameter.GetValue("DllName").c_str(), RTLD_LAZY);
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("DllName").c_str());
		return OPROS_FIND_DLL_ERROR;
	}

	//	Load a API
	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)dlsym(hOprosAPI, "GetAPI");
	char *error = dlerror();
	if(error != NULL) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}
#endif
	
	tcpip = dynamic_cast<TCPIP *>(getOprosAPI());
	if(tcpip == NULL) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't get a handle of TCPIP API\n");
#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}

	if(tcpip->Initialize(parameter) != API_SUCCESS) {
		PrintMessage("ERROR : TCPIPComp::onInitialize() -> Can't initialize a TCPIP API\n");
		delete tcpip;
		tcpip = NULL;

#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return OPROS_INITIALIZE_API_ERROR;
	}

	error = 0;

	return OPROS_SUCCESS;
}
Exemplo n.º 29
0
// Call back Declaration
ReturnType JoystickComp::onInitialize()
{
	//	XML에 저장된 프라퍼티를 parameter에 저장
	Property parameter;
	std::map<std::string, std::string> temp = getPropertyMap();
	parameter.SetProperty(temp);
	
	//	dll 파일이름을 확인하여 없으면 에러 리턴
	if(parameter.FindName("APIName") == false) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't find the APIName in property\n");
		return OPROS_FIND_PROPERTY_ERROR;
	}

#if defined(WIN32)
	//	DLL 로드
	hOprosAPI = LoadLibrary((LPCSTR)parameter.GetValue("APIName").c_str());
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("APIName").c_str());
		return OPROS_FIND_DLL_ERROR;
	}
	
	//	API 로드
	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)GetProcAddress(hOprosAPI, "GetAPI");
	if(getOprosAPI == NULL) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		FreeLibrary(hOprosAPI);
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}
#else
	hOprosAPI = dlopen(parameter.GetValue("APIName").c_str(), RTLD_LAZY);
	if(hOprosAPI == NULL) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't find the %s\n", parameter.GetValue("APIName").c_str());
		return OPROS_FIND_DLL_ERROR;
	}

	GET_OPROS_API getOprosAPI;
	getOprosAPI = (GET_OPROS_API)dlsym(hOprosAPI, "GetAPI");
	char *lastError = dlerror();
	if(lastError != NULL) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't get a handle of GetAPI Funtion\n");
		dlclose(hOprosAPI);
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}
#endif
	
	joystick = static_cast<Joystick *>(getOprosAPI());
	if(joystick == NULL) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't get a handle of Joystick API\n");
#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return OPROS_LOAD_DLL_ERROR;
	}

	//	API 초기화
	if(joystick->Initialize(parameter) != API_SUCCESS) {
		PrintMessage("ERROR : JoystickComp::onInitialize() -> Can't intilaize a Joystick API\n");
		
		delete joystick;
		joystick = NULL;

#if defined(WIN32)
		FreeLibrary(hOprosAPI);
#else
		dlclose(hOprosAPI);
#endif
		hOprosAPI = NULL;
		return OPROS_INITIALIZE_API_ERROR;
	}

	lastError = OPROS_SUCCESS;

	PrintMessage("SUCCESS : JoystickComp::onInitialize()\n");
	return OPROS_SUCCESS;
}
Exemplo n.º 30
0
int SerialCommunication::SetParameter(Property parameter)
{
	if(parameter.FindName("TimeOut") == false)		return API_ERROR;
	unsigned long timeOut = (unsigned long)atol(parameter.GetValue("TimeOut").c_str());
	if(parameter.FindName("BaudRate") == false)	return API_ERROR;
	unsigned long baudRate = (unsigned long)atol(parameter.GetValue("BaudRate").c_str());
	if(parameter.FindName("DataBits") == false)	return API_ERROR;
	char dataBits = (char)atoi(parameter.GetValue("DataBits").c_str());
	if(parameter.FindName("StopBits") == false)	return API_ERROR;
	char stopBits = (char)atoi(parameter.GetValue("StopBits").c_str());
	if(parameter.FindName("Parity") == false)		return API_ERROR;
	char parity = (char)atoi(parameter.GetValue("Parity").c_str());
	if(parameter.FindName("FlowControl") == false)	return API_ERROR;
	char flowControl = (char)atoi(parameter.GetValue("FlowControl").c_str());
	
	if(handle != NULL) {
		if(handle->SetParameter(timeOut, baudRate, dataBits, stopBits, parity, flowControl) < 0) {
			return API_ERROR;
		}
	}

	this->parameter.SetValue("TimeOut", parameter.GetValue("TimeOut"));
	this->parameter.SetValue("BaudRate", parameter.GetValue("BaudRate"));
	this->parameter.SetValue("DataBits", parameter.GetValue("DataBits"));
	this->parameter.SetValue("StopBits", parameter.GetValue("StopBits"));
	this->parameter.SetValue("Parity", parameter.GetValue("Parity"));
	this->parameter.SetValue("FlowControl", parameter.GetValue("FlowControl"));
	
	return API_SUCCESS;
}