mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-04 12:35:54 +01:00
Add vehicle graph core: .vhg loader, logic and cab blocks, -graph-run and -graph-catalog
This commit is contained in:
2
tools/vehicle_graph/tests/bad-choice.vhg
Normal file
2
tools/vehicle_graph/tests/bad-choice.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error has to be one of
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "sw", "type": "cab.switch", "params": { "behaviour": "bistabilny" } } ] }
|
||||
2
tools/vehicle_graph/tests/bad-param-type.vhg
Normal file
2
tools/vehicle_graph/tests/bad-param-type.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error has to be a number
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "sw", "type": "cab.switch", "params": { "positions": "3" } } ] }
|
||||
36
tools/vehicle_graph/tests/blocks.expected.csv
Normal file
36
tools/vehicle_graph/tests/blocks.expected.csv
Normal file
@@ -0,0 +1,36 @@
|
||||
time;x.q;y.q;and.q;or.q;xor.q;nand.q;nor.q;not.q;sr.q;sr_set.q;ton.q;tof.q;delay.q;hyst.q;le.q;div.q;min.q;sel.q;button.pos;button.index;lever.pos;lever.index;sr:state;sr_set:state;ton:elapsed;tof:elapsed;button:position;lever:position
|
||||
0.1;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.1;0;0;2
|
||||
0.2;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.2;0;0;2
|
||||
0.3;1;0;0;1;1;1;0;0;1;1;0;1;1;0;1;0;0;1;0;0;0;2;1;1;0.3;0;0;2
|
||||
0.4;1;1;1;1;0;0;0;0;0;1;0;1;1;0;1;1;1;1;0;0;0;2;0;1;0.4;0;0;2
|
||||
0.5;1;1;1;1;0;0;0;0;0;1;1;1;1;0;1;1;1;1;0;0;0;2;0;1;0.5;0;0;2
|
||||
0.6;1;1;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tests/blocks.script
Normal file
16
tools/vehicle_graph/tests/blocks.script
Normal file
@@ -0,0 +1,16 @@
|
||||
0.0 force x.q 1
|
||||
0.3 force y.q 1
|
||||
0.6 force x.q 0
|
||||
0.7 press button
|
||||
0.71 inc lever
|
||||
0.72 inc lever
|
||||
0.9 release button
|
||||
1.0 release lever
|
||||
1.1 force x.q 3
|
||||
1.2 force x.q 5
|
||||
1.3 force x.q 2.5
|
||||
1.4 force x.q 1
|
||||
1.5 force y.q 0
|
||||
1.6 value lever -1.9
|
||||
1.7 unforce x.q
|
||||
2.5 toggle button
|
||||
39
tools/vehicle_graph/tests/blocks.vhg
Normal file
39
tools/vehicle_graph/tests/blocks.vhg
Normal file
@@ -0,0 +1,39 @@
|
||||
// expect: ok
|
||||
// every logic block driven by forced inputs; see blocks.script
|
||||
{
|
||||
"format": "maszyna-vehicle-graph", "version": 2,
|
||||
"nodes": [
|
||||
{ "id": "x", "type": "logic.const", "params": { "value": 0 } },
|
||||
{ "id": "y", "type": "logic.const", "params": { "value": 0 } },
|
||||
{ "id": "and", "type": "logic.and" }, { "id": "or", "type": "logic.or" }, { "id": "xor", "type": "logic.xor" },
|
||||
{ "id": "nand", "type": "logic.nand" }, { "id": "nor", "type": "logic.nor" }, { "id": "not", "type": "logic.not" },
|
||||
{ "id": "sr", "type": "logic.sr" },
|
||||
{ "id": "sr_set", "type": "logic.sr", "params": { "reset_priority": false } },
|
||||
{ "id": "ton", "type": "logic.ton", "params": { "time": 0.5 } },
|
||||
{ "id": "tof", "type": "logic.tof", "params": { "time": 0.5 } },
|
||||
{ "id": "delay", "type": "logic.delay", "params": { "initial": 7 } },
|
||||
{ "id": "hyst", "type": "logic.hyst", "params": { "lo": 2, "hi": 4 } },
|
||||
{ "id": "le", "type": "logic.compare", "params": { "op": "le", "value": 3 } },
|
||||
{ "id": "div", "type": "logic.math", "params": { "op": "div" } },
|
||||
{ "id": "min", "type": "logic.math", "params": { "op": "min" } },
|
||||
{ "id": "sel", "type": "logic.select" },
|
||||
{ "id": "button", "type": "cab.switch", "params": { "behaviour": "monostable" } },
|
||||
{ "id": "lever", "type": "cab.switch", "params": { "behaviour": "multi", "positions": 5, "min": -2, "max": 2, "default": 0, "spring": true } }
|
||||
],
|
||||
"connections": [
|
||||
{ "from": "x.q", "to": "and.a" }, { "from": "y.q", "to": "and.b" },
|
||||
{ "from": "x.q", "to": "or.a" }, { "from": "y.q", "to": "or.b" },
|
||||
{ "from": "x.q", "to": "xor.a" }, { "from": "y.q", "to": "xor.b" },
|
||||
{ "from": "x.q", "to": "nand.a" }, { "from": "y.q", "to": "nand.b" },
|
||||
{ "from": "x.q", "to": "nor.a" }, { "from": "y.q", "to": "nor.b" },
|
||||
{ "from": "x.q", "to": "not.a" },
|
||||
{ "from": "x.q", "to": "sr.s" }, { "from": "y.q", "to": "sr.r" },
|
||||
{ "from": "x.q", "to": "sr_set.s" }, { "from": "y.q", "to": "sr_set.r" },
|
||||
{ "from": "x.q", "to": "ton.a" }, { "from": "x.q", "to": "tof.a" },
|
||||
{ "from": "x.q", "to": "delay.a" },
|
||||
{ "from": "x.q", "to": "hyst.a" }, { "from": "x.q", "to": "le.a" },
|
||||
{ "from": "x.q", "to": "div.a" }, { "from": "y.q", "to": "div.b" },
|
||||
{ "from": "x.q", "to": "min.a" }, { "from": "y.q", "to": "min.b" },
|
||||
{ "from": "button.pos", "to": "sel.sel" }, { "from": "x.q", "to": "sel.a" }, { "from": "lever.pos", "to": "sel.b" }
|
||||
]
|
||||
}
|
||||
3
tools/vehicle_graph/tests/domain-mismatch.vhg
Normal file
3
tools/vehicle_graph/tests/domain-mismatch.vhg
Normal file
@@ -0,0 +1,3 @@
|
||||
// expect: error joins different domains
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "cab.switch" }, { "id": "lamp", "type": "fb.lamp" } ],
|
||||
"connections": [ { "from": "a.pos", "to": "lamp.supply" } ] }
|
||||
2
tools/vehicle_graph/tests/duplicate-id.vhg
Normal file
2
tools/vehicle_graph/tests/duplicate-id.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error duplicate node id
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "logic.not" }, { "id": "a", "type": "logic.not" } ] }
|
||||
15
tools/vehicle_graph/tests/loop-deferred.vhg
Normal file
15
tools/vehicle_graph/tests/loop-deferred.vhg
Normal file
@@ -0,0 +1,15 @@
|
||||
// expect: ok
|
||||
// the same self-holding circuit as loop.vhg, closed through a unit delay
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
|
||||
{ "id": "start", "type": "cab.switch" },
|
||||
{ "id": "hold", "type": "logic.or" },
|
||||
{ "id": "coil", "type": "logic.and" },
|
||||
{ "id": "stop", "type": "logic.const", "params": { "value": 1 } },
|
||||
{ "id": "contact", "type": "logic.delay" }
|
||||
], "connections": [
|
||||
{ "from": "start.pos", "to": "hold.a" },
|
||||
{ "from": "contact.q", "to": "hold.b" },
|
||||
{ "from": "hold.q", "to": "coil.a" },
|
||||
{ "from": "stop.q", "to": "coil.b" },
|
||||
{ "from": "coil.q", "to": "contact.a" }
|
||||
] }
|
||||
12
tools/vehicle_graph/tests/loop.vhg
Normal file
12
tools/vehicle_graph/tests/loop.vhg
Normal file
@@ -0,0 +1,12 @@
|
||||
// expect: error loop without a deferred block
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
|
||||
{ "id": "start", "type": "cab.switch" },
|
||||
{ "id": "hold", "type": "logic.or" },
|
||||
{ "id": "coil", "type": "logic.and" },
|
||||
{ "id": "stop", "type": "logic.const", "params": { "value": 1 } }
|
||||
], "connections": [
|
||||
{ "from": "start.pos", "to": "hold.a" },
|
||||
{ "from": "coil.q", "to": "hold.b" },
|
||||
{ "from": "hold.q", "to": "coil.a" },
|
||||
{ "from": "stop.q", "to": "coil.b" }
|
||||
] }
|
||||
2
tools/vehicle_graph/tests/malformed.vhg
Normal file
2
tools/vehicle_graph/tests/malformed.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error malformed file
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": 5, "type": "logic.not" } ] }
|
||||
4
tools/vehicle_graph/tests/two-sources.vhg
Normal file
4
tools/vehicle_graph/tests/two-sources.vhg
Normal file
@@ -0,0 +1,4 @@
|
||||
// expect: error has more than one source
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [
|
||||
{ "id": "a", "type": "cab.switch" }, { "id": "b", "type": "cab.switch" }, { "id": "n", "type": "logic.not" }
|
||||
], "connections": [ { "from": "a.pos", "to": "n.a" }, { "from": "b.pos", "to": "n.a" } ] }
|
||||
2
tools/vehicle_graph/tests/unconnected.vhg
Normal file
2
tools/vehicle_graph/tests/unconnected.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: warning required input "a" isn't connected
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "n", "type": "logic.not" } ] }
|
||||
2
tools/vehicle_graph/tests/unknown-type.vhg
Normal file
2
tools/vehicle_graph/tests/unknown-type.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error unknown block type
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "x", "type": "el.flux_capacitor" } ] }
|
||||
2
tools/vehicle_graph/tests/version-1.vhg
Normal file
2
tools/vehicle_graph/tests/version-1.vhg
Normal file
@@ -0,0 +1,2 @@
|
||||
// expect: error unsupported file version 1
|
||||
{ "format": "maszyna-vehicle-graph", "version": 1, "nodes": [] }
|
||||
3
tools/vehicle_graph/tests/wrong-direction.vhg
Normal file
3
tools/vehicle_graph/tests/wrong-direction.vhg
Normal file
@@ -0,0 +1,3 @@
|
||||
// expect: error isn't an output
|
||||
{ "format": "maszyna-vehicle-graph", "version": 2, "nodes": [ { "id": "a", "type": "logic.not" }, { "id": "b", "type": "logic.not" } ],
|
||||
"connections": [ { "from": "a.a", "to": "b.a" } ] }
|
||||
Reference in New Issue
Block a user