2020-11-05 17:01:47 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-07-16 10:52:45
|
2020-12-01 12:05:35 +00:00
|
|
|
* @modify date 2020-11-25 07:39:50
|
2020-11-05 17:01:47 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
const GENERIC_TEMPLATES: {
|
|
|
|
[index: string]: string;
|
|
|
|
} = {
|
|
|
|
// Template to Define new Types.
|
|
|
|
//
|
|
|
|
// Requires the following Input:
|
|
|
|
// {
|
|
|
|
// structName: string,
|
|
|
|
// structId: '{uuid}',
|
|
|
|
// structDefinitionCode: string
|
|
|
|
// }
|
|
|
|
structTemplate: `
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.2">
|
|
|
|
<DUT Name="{{{structName}}}" Id="{{{structId}}}">
|
|
|
|
<Declaration><![CDATA[
|
|
|
|
TYPE {{{structName}}} :
|
|
|
|
STRUCT
|
|
|
|
{{{structDefinitionCode}}}
|
|
|
|
END_STRUCT
|
|
|
|
END_TYPE
|
|
|
|
]]></Declaration>
|
|
|
|
</DUT>
|
|
|
|
</TcPlcObject>
|
|
|
|
`,
|
|
|
|
// Template to define the Places.
|
|
|
|
//
|
|
|
|
// Requires the following Input:
|
|
|
|
// {
|
|
|
|
// structId: '{uuid}',
|
|
|
|
// places: [ {id: string} ],
|
|
|
|
// }
|
|
|
|
statesStructTemplate: `
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.2">
|
|
|
|
<DUT Name="ST_STATE" Id="{{{structId}}}">
|
|
|
|
<Declaration><![CDATA[TYPEST_STATE :
|
|
|
|
STRUCT
|
|
|
|
{{#each places}}
|
|
|
|
{{id}} : INT; (* Element containing the Tokens of the Place {{id}} *)
|
|
|
|
{{/each}}
|
|
|
|
END_STRUCT
|
|
|
|
END_TYPE
|
|
|
|
]]></Declaration>
|
|
|
|
</DUT>
|
|
|
|
</TcPlcObject>
|
|
|
|
`,
|
|
|
|
// Template to define the Places in a GVL.
|
|
|
|
//
|
|
|
|
// Requires the following Input:
|
|
|
|
// {
|
|
|
|
// gvlId: '{uuid}',
|
|
|
|
// }
|
|
|
|
statesGVLTemplate:
|
|
|
|
`
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.2">
|
|
|
|
<GVL Name="GVL_TEST" Id="{{{gvlId}}}">
|
|
|
|
<Declaration><![CDATA[{attribute 'qualified_only'}
|
|
|
|
VAR_GLOBAL
|
|
|
|
aTokens: ST_STATE; (* Struct containing the Tokens of the Net *)
|
|
|
|
END_VAR
|
|
|
|
]></Declaration>
|
|
|
|
</GVL>
|
|
|
|
</TcPlcObject>
|
|
|
|
`,
|
|
|
|
// Template to define a Functionblock.
|
|
|
|
//
|
|
|
|
// Requires the following Input:
|
|
|
|
// {
|
|
|
|
// fBId: '{uuid}',
|
|
|
|
// fbName: string,
|
|
|
|
// // String Containing the Declaration Part
|
|
|
|
// fbDeclaration: string,
|
|
|
|
// // String Containing the Implementation of the FB
|
|
|
|
// fbImplementation: string,
|
|
|
|
// // String Containing the Implementation of the Functions
|
|
|
|
// fbMethods: [{
|
|
|
|
// functionName: string,
|
|
|
|
// // Contains the Returnvalue.
|
|
|
|
// functionReturnValue: string,
|
|
|
|
// // Containing the Inputs
|
|
|
|
// functionInputs: string,
|
|
|
|
// // Containing the Implementation
|
|
|
|
// functionImplementation: string
|
|
|
|
// }],
|
|
|
|
// }
|
2020-12-01 12:05:35 +00:00
|
|
|
fbHeaderTemplate: "" +
|
2020-11-05 17:01:47 +00:00
|
|
|
`
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.2">
|
|
|
|
<POU Name="{{fbName}}" Id="{{{fBId}}}" SpecialFunc="None">
|
|
|
|
<Declaration><![CDATA[FUNCTION_BLOCK {{fbName}}
|
|
|
|
{{{fbDeclaration}}}
|
|
|
|
]]></Declaration>
|
|
|
|
<Implementation>
|
|
|
|
<ST><![CDATA[
|
|
|
|
{{{fbImplementation}}}
|
|
|
|
]]></ST>
|
|
|
|
</Implementation>
|
|
|
|
{{#each fbMethods}}
|
|
|
|
{{> Methods}}
|
|
|
|
{{/each}}
|
|
|
|
</POU>
|
|
|
|
</TcPlcObject>
|
|
|
|
`,
|
|
|
|
// Template to define a Method on a Function-Block.
|
|
|
|
//
|
|
|
|
// Requires the following Input:
|
|
|
|
// {
|
|
|
|
// functionId: '{uuid}',
|
|
|
|
// functionName: string,
|
|
|
|
// // Contains the Returnvalue.
|
|
|
|
// functionReturnValue: string,
|
|
|
|
// // Containing the Inputs
|
|
|
|
// functionInputs: string,
|
|
|
|
// // Containing the Implementation
|
|
|
|
// functionImplementation: string
|
|
|
|
// }
|
2020-12-01 12:05:35 +00:00
|
|
|
fbFunctionTemplate: "" + `
|
2020-11-05 17:01:47 +00:00
|
|
|
<Method Name="{{functionName}}" Id="{{functionId}}">
|
|
|
|
<Declaration><![CDATA[{{functionReturnValue}}
|
|
|
|
VAR_INPUT
|
|
|
|
{{{functionInputs}}}
|
|
|
|
END_VAR
|
|
|
|
]]></Declaration>
|
|
|
|
<Implementation>
|
|
|
|
<ST><![CDATA[
|
|
|
|
{{{functionImplementation}}}
|
|
|
|
]]></ST>
|
|
|
|
</Implementation>
|
|
|
|
</Method>
|
|
|
|
`
|
|
|
|
};
|