Search in sources :

Example 41 with ObservableValue

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;
}
Also used : Clock(de.neemann.digital.core.wiring.Clock) LineEmitter(de.neemann.digital.testing.parser.LineEmitter) Signal(de.neemann.digital.core.Signal) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Lang(de.neemann.digital.lang.Lang) ValueTable(de.neemann.digital.data.ValueTable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Model(de.neemann.digital.core.Model) Value(de.neemann.digital.data.Value) Context(de.neemann.digital.testing.parser.Context) NodeException(de.neemann.digital.core.NodeException) Context(de.neemann.digital.testing.parser.Context) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Clock(de.neemann.digital.core.wiring.Clock) Signal(de.neemann.digital.core.Signal) HashSet(java.util.HashSet)

Example 42 with ObservableValue

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)));
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue)

Example 43 with ObservableValue

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);
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue)

Example 44 with ObservableValue

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;
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeWithoutDelay(de.neemann.digital.core.NodeWithoutDelay)

Example 45 with ObservableValue

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;
    }
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) PinDescription(de.neemann.digital.core.element.PinDescription) ObservableValue(de.neemann.digital.core.ObservableValue) ArrayList(java.util.ArrayList) NodeException(de.neemann.digital.core.NodeException)

Aggregations

ObservableValue (de.neemann.digital.core.ObservableValue)88 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)73 TestExecuter (de.neemann.digital.TestExecuter)61 Model (de.neemann.digital.core.Model)56 ObservableValues (de.neemann.digital.core.ObservableValues)17 NodeException (de.neemann.digital.core.NodeException)5 ArrayList (java.util.ArrayList)4 BitsException (de.neemann.digital.core.BitsException)3 FanIn (de.neemann.digital.core.basic.FanIn)3 Signal (de.neemann.digital.core.Signal)2 Element (de.neemann.digital.core.element.Element)2 Clock (de.neemann.digital.core.wiring.Clock)2 Delay (de.neemann.digital.core.wiring.Delay)2 DataBus (de.neemann.digital.core.wiring.bus.DataBus)2 IOState (de.neemann.digital.draw.elements.IOState)2 CircuitComponent (de.neemann.digital.gui.components.CircuitComponent)2 Sync (de.neemann.digital.gui.sync.Sync)2 BurnException (de.neemann.digital.core.BurnException)1 Node (de.neemann.digital.core.Node)1 NodeWithoutDelay (de.neemann.digital.core.NodeWithoutDelay)1