Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/
package org.eclipse.basyx.models.controlcomponent;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.function.Function;
/**
* BaSys 4.0 control component interface. This is a VAB object that cannot be
* serialized.
*
* @author kuhn
*
*/
public abstract class ControlComponent extends HashMap {
// Miscellaneous String constants
public static final String STATUS = "STATUS";
public static final String OPERATIONS = "OPERATIONS";
// String constants for operations
public static final String OPERATION_CLEAR = "CLEAR";
public static final String OPERATION_STOP = "STOP";
public static final String OPERATION_ABORT = "ABORT";
public static final String OPERATION_RESET = "RESET";
public static final String OPERATION_START = "START";
public static final String OPERATION_MANUAL = "MANUAL";
public static final String OPERATION_AUTO = "AUTO";
public static final String OPERATION_PRIORITY = "PRIO";
public static final String OPERATION_OCCUPY = "OCCUPY";
public static final String OPERATION_FREE = "FREE";
// String constants for setting execution state
public static final String CMD = "cmd";
// String constants for status
public static final String ERROR_STATE = "ER";
public static final String WORK_STATE = "WORKST";
public static final String OP_MODE = "OPMODE";
public static final String EX_STATE = "EXST";
public static final String EX_MODE = "EXMODE";
public static final String OCCUPIER = "OCCUPIER";
public static final String OCCUPATION_STATE = "OCCST";
/**
* The status map implements the service/ substructure of the control component
* structure. It also indicates variable changes via callbacks of the outer
* class.
*
* @author kuhn
*
*/
class StatusMap extends HashMap {
/**
* Version number of serialized instances
*/
private static final long serialVersionUID = 1L;
/**
* Constructor
*/
public StatusMap() {
// Populate control component "status" sub structure
put(OCCUPATION_STATE, OccupationState.FREE.getValue()); // Occupation state: FREE
put(OCCUPIER, ""); // Occupier: none
put(EX_MODE, ExecutionMode.AUTO.getValue()); // Execution mode: AUTO
put(EX_STATE, ExecutionState.IDLE.getValue()); // Execution state: IDLE
put(OP_MODE, ""); // Component specific operation mode (e.g. active service)
put(WORK_STATE, ""); // Component specific work state
put(ERROR_STATE, ""); // Component error state
}
/**
* Update an value
*
* @return Added value
*/
@Override
public Object put(String key, Object parValue) {
// Value to be put in map
Object value = parValue;
// - Eventually we have to change the value to be put into the variable
switch (key) {
case EX_STATE:
value = filterExecutionState(value.toString());
break;
case OP_MODE:
value = filterOperationMode(value.toString());
break;
}
// Invoke base implementation
Object result = super.put(key, value);
// Indicate value change
for (ControlComponentChangeListener listener : listeners)
listener.onVariableChange(key, value);
// Indicate specific changes to callback operations of control component
switch (key) {
case OCCUPATION_STATE:
for (ControlComponentChangeListener listener : listeners)
listener.onNewOccupationState(OccupationState.byValue((int) value));
break;
case OCCUPIER:
for (ControlComponentChangeListener listener : listeners)
listener.onNewOccupier(value.toString());
break;
case EX_MODE:
for (ControlComponentChangeListener listener : listeners)
listener.onChangedExecutionMode(ExecutionMode.byValue((int) value));
break;
case EX_STATE:
for (ControlComponentChangeListener listener : listeners)
listener.onChangedExecutionState(ExecutionState.byValue(value.toString()));
break;
case OP_MODE:
for (ControlComponentChangeListener listener : listeners)
listener.onChangedOperationMode(value.toString());
break;
case WORK_STATE:
for (ControlComponentChangeListener listener : listeners)
listener.onChangedWorkState(value.toString());
break;
case ERROR_STATE:
for (ControlComponentChangeListener listener : listeners)
listener.onChangedErrorState(value.toString());
break;
}
// Return result
return result;
}
}
/**
* Version number of serialized instances
*/
private static final long serialVersionUID = 1L;
/**
* Operations map
*/
protected Map> operations = new HashMap<>();
/**
* Saved occupier ID in case of local occupier overwrite
*/
protected String savedOccupierID = null;
/**
* Status map
*/
protected Map status = null;
/**
* Changed control component state listeners
*/
protected Collection listeners = new LinkedList<>();
/**
* Constructor
*/
@SuppressWarnings("unchecked")
public ControlComponent() {
// Add control component output signals to map
// - "status" sub structure
status = new StatusMap();
put(STATUS, status);
// Input signals
// - Command / stores last command
put(CMD, ""); // No command
// Operations
// - Add "operations" sub structure
put(OPERATIONS, operations);
// - Populate service operations
operations.put(OPERATION_FREE, (Function