plcopen/InstanceTagnameCollector.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sun, 06 Jan 2019 01:22:46 +0300
changeset 2499 68f4f2d4516b
parent 1953 5736d25bb393
child 3750 f62625418bff
permissions -rw-r--r--
use pregenerated CRC32 lookup tables for retain on Win32 and GNU/Linux

This code could be possible reused on low-end targets with limited RAM.

code to generate lookup table:
[---------------------------------------------------------------------]

/* CRC lookup table and initial state. */
uint32_t crc32_table[256];

/* Generate CRC32 lookup table. */
void GenerateCRC32Table(void)
{
unsigned int i, j;
/* Use CRC-32-IEEE 802.3 polynomial 0x04C11DB7 (bit reflected). */
uint32_t poly = 0xEDB88320;

for (i = 0; i <= 0xFF; i++)
{
uint32_t c = i;
for (j = 0 ; j < 8 ; j++)
c = (c & 1) ? (c >> 1 ) ^ poly : (c >> 1);
crc32_table[i] = c;
}
}

void main(void)
{
GenerateCRC32Table();
int j=0;
for(int i=0; i<256; i++) {
printf("0x%08X, ", crc32_table[i]);
if (++j >= 8) {
j = 0;
printf("\n");
}
}
}
[---------------------------------------------------------------------]
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     3
# This file is part of Beremiz.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     5
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
     7
from plcopen.XSLTModelQuery import XSLTModelQuery
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     8
from plcopen.types_enums import *
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     9
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    10
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    11
class InstanceTagName(object):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    12
    """Helpers object for generating instance tagname"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    13
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    14
    def __init__(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    15
        self.TagName = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    16
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    17
    def GetTagName(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    18
        return self.TagName
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    19
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    20
    def ConfigTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    21
        self.TagName = ComputeConfigurationName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    22
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    23
    def ResourceTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    24
        self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    25
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    26
    def PouTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    27
        self.TagName = ComputePouName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    28
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    29
    def ActionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    30
        self.TagName = ComputePouActionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    31
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    32
    def TransitionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    33
        self.TagName = ComputePouTransitionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    34
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    35
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    36
class InstanceTagnameCollector(XSLTModelQuery):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    37
    """ object for collecting instances path list"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    38
    def __init__(self, controller):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    39
        XSLTModelQuery.__init__(self,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    40
                                controller,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    41
                                "instance_tagname.xslt",
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    42
                                [(name, self.FactoryCaller(name))
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    43
                                 for name in ["ConfigTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    44
                                              "ResourceTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    45
                                              "PouTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    46
                                              "ActionTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    47
                                              "TransitionTagName"]])
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    48
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    49
    def FactoryCaller(self, funcname):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    50
        def CallFactory(*args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    51
            return getattr(self.factory, funcname)(*args)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    52
        return CallFactory
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    53
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    54
    def Collect(self, root, debug, instance_path):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    55
        self.factory = InstanceTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    56
        self._process_xslt(root, debug, instance_path=instance_path)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    57
        res = self.factory.GetTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    58
        self.factory = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    59
        return res