blob: c3eb3959c81529e8cdbe0f6906155e1862aad247 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*******************************************************************************/
package org.eclipse.apogy.core.programs.controllers.impl;
import org.eclipse.apogy.common.emf.transaction.ApogyCommonTransactionFacade;
import org.eclipse.apogy.common.io.jinput.EComponent;
import org.eclipse.apogy.core.programs.controllers.ApogyCoreProgramsControllersFacade;
import org.eclipse.apogy.core.programs.controllers.ApogyCoreProgramsControllersPackage;
import org.eclipse.apogy.core.programs.controllers.OperationCallControllerBinding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ControllerValueSourceCustomImpl extends ControllerValueSourceImpl {
private static final Logger Logger = LoggerFactory.getLogger(ControllerValueSourceImpl.class);
public EComponent getComponent() {
if (getEComponentQualifier() != null) {
return org.eclipse.apogy.common.io.jinput.Activator.getEControllerEnvironment()
.resolveEComponent(getEComponentQualifier());
} else {
return null;
}
}
@Override
public Object getSourceValue() {
EComponent component = getComponent();
if (component != null) {
float data = 0.0f;
if (getConditioning() != null) {
data = getConditioning().conditionInput(component);
// TODO Convert to the DataTypeArgument units if applicable.
} else {
data = component.getPollData();
}
// Converts the float to the required data type
Object value = ApogyCoreProgramsControllersFacade.INSTANCE
.createValue(getBindedEDataTypeArgument().getEParameter(), data);
// Update last value (used for display purposes).
ApogyCommonTransactionFacade.INSTANCE.basicSet(this,
ApogyCoreProgramsControllersPackage.Literals.CONTROLLER_VALUE_SOURCE__LAST_VALUE, value);
return value;
} else {
if (getBindedEDataTypeArgument() != null && getBindedEDataTypeArgument().getOperationCall() != null
&& ((OperationCallControllerBinding) getBindedEDataTypeArgument().getOperationCall()).isStarted()) {
Logger.error("The controller component named < " + getEComponentQualifier()
+ "> is not binded! Ensure the appropriated Controller are connected.");
}
return null;
}
}
} // ControllerValueSourceImpl