DSL implementation for UNICOSCPC Ivan Prieto Barreiro Jeffrey
DSL implementation for UNICOS-CPC Ivan Prieto Barreiro Jeffrey Goderie BE-ICS
Summary 1. UNICOS & UAB • UNICOS Framework • UAB (Code generation tool) • Code Templates 2. DSL Implementation • Project Structure • Issues / How to. . Custom Interpreter 4. Custom Na. BL and TS 3. 19/01/2016 2
UNICOS & UAB 19/01/2016 3
UNICOS Framework UNified Industrial Control System is a: • CERN-made framework to develop industrial control applications • It deals with the two upper layers of a control system Provides • Methodology to design & develop applications which run in COTS products (e. g. SCADA & PLCs) • Set of standard device types (objects) for the supervision and control layers • Automatic code generation tool (UAB) 19/01/2016 4
UAB: UNICOS Application Builder Tool used to generate code for UNICOS applications • UCPC: Generates code for the control and supervision layers • Main inputs: Device type definitions, specs. file & code templates • Device Types PID Alarm Device Instantiation Templates Control Application Analog Specifications Touch Panels Process Logic Templates PLC S 7 Inputs Outputs 19/01/2016 5
UAB: Device Type Definitions & Specs Spec. template generation Device Inputs Device outputs Device spec fields 19/01/2016 6
Code Templates Features • Scripts implemented in Jython. • Used for data validation & code generation. Different Nature • Global templates (provided) • Instance templates (provided) • Logic templates (application specific) 19/01/2016 7
Logic Templates Main use cases Generate code dynamically based on queries to the specs file 2. Generate code for modular and repeatable process 3. Generate code too long to be written by hand 1. Examples Use Cases 1 & 3 1. Get all the devices from the specs matching condition XXX 2. For each device: Get master device • generate code YYY • Use Case 2 S 01 OO 01 On. Off V 01 Input IF S 01 == TRUE THEN V 01 : = TRUE; ELSE V 01 : = FALSE; END_IF; On. Off Output On. Off 19/01/2016 IF On. Off_Input == TRUE THEN On. Off_Output : = TRUE; ELSE On. Off_Output : = FALSE; END_IF; 8
Writing Logic Templates PLC code generated from strings • No syntactic/semantic checkings • Errors detected after generate, import & compile • No syntactic/semantic checkings during edition • Errors detected during compilation • Error messages could be improved • 19/01/2016 9
Logic Template Execution Calls to logic templates are parameterized • Several instances can use the same logic template • SCL (Siemens): 1 output file for each instance • 19/01/2016 10
Generation Workflow UNICOS application sources Specs. file (device instances) Import & Compile Code Generation Control Code Inputs Compilation Error!!! Templates UAB CPC Wizard 19/01/2016 11
How a DSL can help? Provide a language for writing logic templates: • Similar to the PLC languages (SCL, ST) • With additional functionalities to: • Query data from the specs • Generate code dynamically based on the query results Provide a language editor: • Syntactic & semantic checks while editing • Code completion for: • Device instances defined in the specs • Device type definitions (device IOs) • Variables, function arguments… • Visualize the generated code in real-time • Navigation, refactoring, contextual information (hover text), … 19/01/2016 12
DSL Implementation 19/01/2016 13
Project Structure Scripting Schneider DSL Siemens Template DSL 19/01/2016 Schneider Template DSL 14
Issues / How to. . Sunshine • Parameterized calls to templates (input parameters, output file names) • Get error and warning messages • Set the output folder for the generated files Performance • Na. BL : big files or complex structures (arrays of structs with arrays …) Language Composition • How to achieve language composition avoiding multiple copy/paste? Language Building & Testing Trigger builds in Java 1. 8 • How to trigger tests (parsing, syntax, semantic…) automatically with Jenkins & Maven • Spoofax Documentation Missing • E. g. : Type System 19/01/2016 15
Custom Interpreter 19/01/2016 16
Dyn. Sem Pros • • • Cons Language independent metalanguage No need to keep track of stacks Works great for standard operations/functions • • • 19/01/2016 No documentation Functionality limited for nonbasic operations/functions Limited capability of handling non-standard data types 17
Custom Interpreter Pros • • • Works on Java-end, so can handle any Object High speed, low resource cost “Unlimited” extendable functionality Cons • • • 19/01/2016 Bug-prone due to full stack control Language dependent implementation, though mostly modular No documentation (yet) 18
Implementation Details 19/01/2016 19
Custom Na. BL and TS
NABL and TS Pros • • Semantic definitions of language structures. Powerful features in both Na. BL and TS. Less mistakes because of auto-generation Back-end is language independent Cons • • 19/01/2016 Subsequent Scoping is not propagated into parent/children scopes. On complex or large files Na. BL storing becomes quite costly, causing errors to take long to be updated. Strange things can happen due to the way Na. BL has been created. Generated. str files difficult to understand 21
N(ew)NABL and N(ew)TS Pros • • • Cons Faster: Completely run on Java’s Hash. Maps Subsequent scoping throughout tree Full control of both front- and back-end implementations • • 19/01/2016 Might not be fully modular in its current state No automatic. str file generation Currently only works for a subset of Na. BL Need to implement multi-file analysis 22
NNa. BL • • Multi-step declaration and validation Check for new information on each iteration When no new info has been added, validate the AST Tier plus steps depend on NTS 19/01/2016 23
Example(1/4) Na. BL code Example file 19/01/2016 24
Example (2/4) 19/01/2016 25
Example (3/4) 19/01/2016 26
Example (4/4) 19/01/2016 27
NTS Structure depends greatly on NNa. BL • Will be largely in line with current implementation • Final structure has yet to be designed • 19/01/2016 28
- Slides: 29