use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class TestExecutor method create.
/**
* Creates the result by comparing the testing vector with the given model-
*
* @param model the model to check
* @return this for chained calls
* @throws TestingDataException DataException
* @throws NodeException NodeException
*/
public TestExecutor create(Model model) throws TestingDataException, NodeException {
allPassed = true;
HashSet<String> usedSignals = new HashSet<>();
inputs = new ArrayList<>();
outputs = new ArrayList<>();
for (Signal s : model.getInputs()) {
final int index = getIndexOf(s.getName());
if (index >= 0) {
inputs.add(new TestSignal(index, s.getValue()));
addTo(usedSignals, s.getName());
}
ObservableValue outValue = s.getBidirectionalReader();
if (outValue != null) {
final String outName = s.getName() + "_out";
final int inIndex = getIndexOf(outName);
if (inIndex >= 0) {
outputs.add(new TestSignal(inIndex, outValue));
addTo(usedSignals, outName);
}
}
}
for (Clock c : model.getClocks()) {
final int index = getIndexOf(c.getLabel());
if (index >= 0) {
inputs.add(new TestSignal(index, c.getClockOutput()));
addTo(usedSignals, c.getLabel());
}
}
for (Signal s : model.getOutputs()) {
final int index = getIndexOf(s.getName());
if (index >= 0) {
outputs.add(new TestSignal(index, s.getValue()));
addTo(usedSignals, s.getName());
}
}
for (String name : names) if (!usedSignals.contains(name))
throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
if (inputs.size() == 0)
throw new TestingDataException(Lang.get("err_noTestInputSignalsDefined"));
if (outputs.size() == 0)
throw new TestingDataException(Lang.get("err_noTestOutputSignalsDefined"));
model.init();
try {
lines.emitLines(new LineListenerResolveDontCare(values -> checkRow(model, values), inputs), new Context());
} catch (ParserException e) {
throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
} catch (RuntimeException e) {
if (allPassed) {
allPassed = false;
exception = e;
}
}
return this;
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class StdIOInterface method readValues.
@Override
public void readValues(ObservableValues values) throws IOException {
String line = readLine();
if (line != null) {
int pos = PREFIX.length();
int len = line.length();
for (ObservableValue v : values) {
final int bits = v.getBits();
if (pos + bits > len)
throw new IOException(Lang.get("err_notEnoughDataReceived_O", getConsoleOut()));
long value = 0;
long highZ = 0;
long mask = 1;
for (int i = 0; i < bits; i++) {
char c = line.charAt(pos);
switch(c) {
case 'Z':
highZ |= mask;
break;
case 'H':
case '1':
value |= mask;
break;
case 'W':
case 'X':
case 'U':
case 'L':
case '0':
break;
default:
throw new IOException(Lang.get("err_invalidCharacterReceived_N_O", "" + c, getConsoleOut()));
}
mask <<= 1;
pos++;
}
v.set(value, highZ);
}
} else
throw new IOException(Lang.get("err_processTerminatedUnexpected_O", getConsoleOutNoWarn(consoleOut)));
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class Pins method bindOutputsToOutputPins.
/**
* Binds the outputs to the pins.
* The {@link Pin#setValue(ObservableValue)} method is called with one of the given outputs
*
* @param outs outputs
* @throws PinException thrown if pin not found
*/
public void bindOutputsToOutputPins(ObservableValues outs) throws PinException {
for (ObservableValue o : outs) {
Pin pin = outputs.get(o.getName());
if (pin == null)
throw new PinException(Lang.get("err_pin_N_unknown", o.getName()));
pin.setValue(o);
}
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class InverterConfig method invert.
/**
* Handles the inverting of a input signal
* if the given input is not to invert, the original input is returned,
* If the input is to invert, a inverted input is returned. This invert does not add
* a additional delay time.
*
* @param name the name of the signal
* @param orig the original input signal
* @return the inverted or the original input
*/
public ObservableValue invert(String name, ObservableValue orig) {
if (inputs == null)
return orig;
if (!inputs.contains(name))
return orig;
ObservableValue out = new ObservableValue("~" + orig.getName(), orig.getBits());
orig.addObserver(new NodeWithoutDelay(out) {
@Override
public void hasChanged() {
out.set(~orig.getValue(), orig.getHighZ());
}
});
out.set(~orig.getValue(), orig.getHighZ());
return out;
}
use of de.neemann.digital.core.ObservableValue in project Digital by hneemann.
the class ModelEntry method applyInputs.
/**
* Sets the Inputs of the element contained in this entry
*
* @throws PinException PinException
* @throws NodeException NodeException
*/
public void applyInputs() throws PinException, NodeException {
try {
HashMap<String, Pin> ins = pins.getInputs();
InverterConfig ic = visualElement.getElementAttributes().get(Keys.INVERTER_CONFIG);
ObservableValues values = ObservableValues.EMPTY_LIST;
ArrayList<ObservableValue> inputs = new ArrayList<>();
for (PinDescription inputName : inputNames) {
Pin pin = ins.get(inputName.getName());
if (pin == null)
throw new PinException(Lang.get("err_pin_N0_atElement_N1_notFound", inputName, visualElement), containingVisualElement);
ObservableValue value = pin.getValue();
if (value == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", inputName, visualElement), containingVisualElement);
inputs.add(ic.invert(inputName.getName(), value));
}
ArrayList<ObservableValue> bidirect = null;
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.both) {
if (bidirect == null)
bidirect = new ArrayList<>();
final ObservableValue readerValue = p.getReaderValue();
if (readerValue == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", p.getName(), visualElement), containingVisualElement);
bidirect.add(readerValue);
}
}
if (bidirect != null)
inputs.addAll(bidirect);
if (inputs.size() > 0) {
values = new ObservableValues(inputs);
element.setInputs(values);
}
ioState = new IOState(values, element.getOutputs(), element);
} catch (PinException | NodeException e) {
e.setOrigin(origin);
e.setVisualElement(containingVisualElement);
throw e;
}
}
Aggregations