Search in sources :

Example 6 with ObservableValues

use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.

the class Splitter64BitTest method test64Bit2.

public void test64Bit2() throws NodeException, PinException {
    ObservableValue a = new ObservableValue("a", 64);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "64").set(Keys.OUTPUT_SPLIT, "16,16,16,16"));
    splitter.setInputs(ovs(a));
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(4, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a).setOutputsOf(splitter);
    sc.check(0x0, 0x0, 0x0, 0x0, 0x0);
    sc.check(-1, 0xffff, 0xffff, 0xffff, 0xffff);
    sc.check(0xffffffffffffffffL, 0xffff, 0xffff, 0xffff, 0xffff);
    sc.check(0xffffffffffff0000L, 0, 0xffff, 0xffff, 0xffff);
    sc.check(0xffffffff0000ffffL, 0xffff, 0, 0xffff, 0xffff);
    sc.check(0xffff0000ffffffffL, 0xffff, 0xffff, 0, 0xffff);
    sc.check(0x0000ffffffffffffL, 0xffff, 0xffff, 0xffff, 0);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 7 with ObservableValues

use of de.neemann.digital.core.ObservableValues 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)

Example 8 with ObservableValues

use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.

the class SplitterMixTest method test2.

public void test2() throws Exception {
    ObservableValue a = new ObservableValue("a", 8);
    ObservableValue b = new ObservableValue("b", 8);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "8,8").set(Keys.OUTPUT_SPLIT, "12,4"));
    splitter.setInputs(ovs(a, b));
    assertEquals(1, a.observerCount());
    assertEquals(2, b.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(2, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
    sc.check(0x00, 0x00, 0x000, 0x0);
    sc.check(0x01, 0x00, 0x001, 0x0);
    sc.check(0x10, 0x00, 0x010, 0x0);
    sc.check(0x00, 0x01, 0x100, 0x0);
    sc.check(0x00, 0x10, 0x000, 0x1);
    sc.check(0x0f, 0x00, 0x00f, 0x0);
    sc.check(0xf0, 0x00, 0x0f0, 0x0);
    sc.check(0x00, 0x0f, 0xf00, 0x0);
    sc.check(0x00, 0xf0, 0x000, 0xf);
    sc.check(0xbc, 0xda, 0xabc, 0xd);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 9 with ObservableValues

use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.

the class SplitterMixTest method test1.

public void test1() throws Exception {
    ObservableValue a = new ObservableValue("a", 8);
    ObservableValue b = new ObservableValue("b", 8);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "8,8").set(Keys.OUTPUT_SPLIT, "4,12"));
    splitter.setInputs(ovs(a, b));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(2, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b).setOutputsOf(splitter);
    sc.check(0x00, 0x00, 0x0, 0x000);
    sc.check(0x01, 0x00, 0x1, 0x000);
    sc.check(0x10, 0x00, 0x0, 0x001);
    sc.check(0x00, 0x01, 0x0, 0x010);
    sc.check(0x00, 0x10, 0x0, 0x100);
    sc.check(0x0f, 0x00, 0xf, 0x000);
    sc.check(0xf0, 0x00, 0x0, 0x00f);
    sc.check(0x00, 0x0f, 0x0, 0x0f0);
    sc.check(0x00, 0xf0, 0x0, 0xf00);
    sc.check(0xc0, 0xab, 0x0, 0xabc);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Example 10 with ObservableValues

use of de.neemann.digital.core.ObservableValues in project Digital by hneemann.

the class SplitterMixTest method test3.

public void test3() throws Exception {
    ObservableValue a = new ObservableValue("a", 4);
    ObservableValue b = new ObservableValue("b", 4);
    ObservableValue c = new ObservableValue("c", 4);
    Splitter splitter = new Splitter(new ElementAttributes().set(Keys.INPUT_SPLIT, "4,4,4").set(Keys.OUTPUT_SPLIT, "2,8,2"));
    splitter.setInputs(ovs(a, b, c));
    assertEquals(2, a.observerCount());
    assertEquals(1, b.observerCount());
    assertEquals(2, c.observerCount());
    ObservableValues outputs = splitter.getOutputs();
    assertEquals(3, outputs.size());
    TestExecuter sc = new TestExecuter().setInputs(a, b, c).setOutputsOf(splitter);
    sc.check(0x0, 0x0, 0x0, 0x0, 0x00, 0x0);
    sc.check(0xf, 0x0, 0x0, 0x3, 0x03, 0x0);
    sc.check(0x0, 0xf, 0x0, 0x0, 0x3c, 0x0);
    sc.check(0x0, 0x0, 0xf, 0x0, 0xc0, 0x3);
    sc.check(0xf, 0xf, 0xf, 0x3, 0xff, 0x3);
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) ObservableValue(de.neemann.digital.core.ObservableValue) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) TestExecuter(de.neemann.digital.TestExecuter)

Aggregations

ObservableValues (de.neemann.digital.core.ObservableValues)22 ObservableValue (de.neemann.digital.core.ObservableValue)17 TestExecuter (de.neemann.digital.TestExecuter)16 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)16 Model (de.neemann.digital.core.Model)3 BitsException (de.neemann.digital.core.BitsException)1 NodeException (de.neemann.digital.core.NodeException)1 PinDescription (de.neemann.digital.core.element.PinDescription)1 ArrayList (java.util.ArrayList)1