Skip to content

Commit e1f050a

Browse files
committed
feat: Datapoint output mapping
1 parent 6df37a9 commit e1f050a

12 files changed

Lines changed: 121 additions & 68 deletions

File tree

language/example/showcase/showcase.bcsctrl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ control ShowcaseController {
44
Manual,
55
Off
66
}
7-
struct RoomStatus {
8-
currentMode: OpMode = OpMode.Auto,
9-
temperature: REAL,
10-
isOccupied: BOOL
11-
}
12-
unit LightingControl {
13-
var currentMode: OpMode = OpMode.;
14-
if (MotionSensor.) {
15-
// Turn on lights...
7+
functionblock HeatingLogic {
8+
inputs {
9+
var iTemp: REAL;
10+
var iMode: OpMode;
11+
}
12+
outputs {
13+
var oHeating: BOOL;
1614
}
15+
logic {
16+
oHeating = iMode == OpMode.Auto && iTemp < 20.5;
17+
}
18+
}
19+
unit MorningWarmUp at TOD#06:00:00 {
20+
var currentMode: OpMode = OpMode.Auto;
21+
use HeatingLogic(iTemp: RoomSensor.Temperature, iMode: currentMode) -> HeatingActuator.IsActive;
1722
}
1823
}

language/example/showcase/showcase.bcshw

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ controller ShowcaseController {
5757
channel Value: BOOL link "Channel 1^Input"
5858
}
5959
}
60+
61+
datapoint RoomSensor {
62+
portgroup: Room1DigitalInputs
63+
channels: {
64+
channel Temperature: REAL link "Channel 2^Input"
65+
}
66+
}
67+
68+
datapoint HeatingActuator {
69+
portgroup: TwoDigitalOutputs
70+
channels: {
71+
channel IsActive: BOOL link "Channel 1^Output"
72+
}
73+
}
6074
}
6175

6276
network {

language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.0.22",
2+
"version": "0.0.23",
33
"name": "bcs-engineering-dsl",
44
"displayName": "BCS Engineering DSL",
55
"icon": "icon.png",

language/puml/bcs-control-metamodel.puml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ package "Literals" {
154154

155155
' Abstract element for what can be referenced by name
156156
abstract class NamedElement
157-
NamedElement <|--- VarDecl
158-
NamedElement <|--- EnumDecl
159-
NamedElement <|--- Datapoint
157+
NamedElement <|-- VarDecl
158+
NamedElement <|-- EnumDecl
159+
NamedElement <|-- Datapoint
160160

161161
' ===== RELATIONSHIPS =====
162162

@@ -213,9 +213,9 @@ UseStmt "1" *-- "1" UseOutput : useOutput
213213
InputMapping "1" ..> "1" VarDecl : inputVar
214214
UseOutput "1" *-- "0..1" SimpleUseResult : singleOutput
215215
UseOutput "1" *-- "0..*" MappingUseResult : mappingOutputs
216-
SimpleUseResult "1" ..> "1" VarDecl : targetOutputVar
216+
SimpleUseResult "1" ..> "1" Ref : target
217217
MappingUseResult "1" ..> "1" VarDecl : fbOutputVar
218-
MappingUseResult "1" ..> "1" VarDecl : targetOutputVar
218+
MappingUseResult "1" ..> "1" Ref : target
219219
EdgeStmt "1" *-- "1" Ref : signal
220220

221221
' --- Expressions ---

language/railroad/svg/bcs-control/MappingUseResult.svg

Lines changed: 7 additions & 7 deletions
Loading

language/railroad/svg/bcs-control/SimpleUseResult.svg

Lines changed: 6 additions & 6 deletions
Loading

language/src/cli/platform/beckhoff/application/statement-converter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from "../../../../language/generated/ast.js";
2626
import { ExpressionConverter } from "./expression-converter.js";
2727
import { GlobalInstanceManager } from "./global-instance-manager.js";
28-
import { getQualifiedReferenceName } from "./qualified_reference_name.js";
2928

3029
/**
3130
* Converts DSL statements to IEC 61131-3 Structured Text and analyzes statement structures.
@@ -120,14 +119,12 @@ export class StatementConverter {
120119
const fb = stmt.functionBlockRef.ref;
121120
const outs = fb ? getOutputs(fb) : [];
122121
const fbOut = outs.length === 1 ? outs[0].name : "output";
123-
const target = getQualifiedReferenceName(
124-
stmt.useOutput.singleOutput.targetOutputVar
125-
);
126-
return out + `${p}${target} := ${instanceName}.${fbOut};\n`;
122+
const target = this.expr.emit(stmt.useOutput.singleOutput.target);
123+
return out + `${p}${target} := ${instanceName}.${fbOut};\n`.trimEnd();
127124
}
128125

129126
for (const m of stmt.useOutput.mappingOutputs) {
130-
const target = getQualifiedReferenceName(m.targetOutputVar);
127+
const target = this.expr.emit(m.target);
131128
const fbOut = m.fbOutputVar.ref?.name ?? "output";
132129
out += `${p}${target} := ${instanceName}.${fbOut};\n`;
133130
}

language/src/language/bcs-control.langium

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ UseOutput:
227227
;
228228

229229
SimpleUseResult:
230-
targetOutputVar=[VarDecl]
230+
target=Ref
231231
;
232232

233233
MappingUseResult:
234-
fbOutputVar=[VarDecl] ':' targetOutputVar=[VarDecl]
234+
fbOutputVar=[VarDecl] ':' target=Ref
235235
;
236236

237237

language/src/language/control/bcs-control-lang-semantic-token-provider.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
isStructFieldDecl,
2222
isUseStmt,
2323
isMappingUseResult,
24-
isSimpleUseResult,
2524
isInputMapping,
2625
isEnumMemberLiteral,
2726
isCaseLiteral,
@@ -213,18 +212,6 @@ export class BCSControlLangSemanticTokenProvider extends AbstractSemanticTokenPr
213212
property: "fbOutputVar",
214213
type: SemanticTokenTypes.parameter,
215214
});
216-
acceptor({
217-
node,
218-
property: "targetOutputVar",
219-
type: SemanticTokenTypes.variable,
220-
});
221-
}
222-
if (isSimpleUseResult(node)) {
223-
acceptor({
224-
node,
225-
property: "targetOutputVar",
226-
type: SemanticTokenTypes.variable,
227-
});
228215
}
229216
if (isInputMapping(node)) {
230217
acceptor({

0 commit comments

Comments
 (0)