plugins/canfestival/canfestival.py
author etisserant
Tue, 11 Sep 2007 16:10:27 +0200
changeset 30 ea685658b388
parent 26 7bc11b005c8b
child 32 4bdc888e634b
permissions -rw-r--r--
Fixed onclose bug
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     1
import os, sys
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     2
base_folder = os.path.split(sys.path[0])[0]
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     3
sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen"))
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     4
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     5
from nodelist import NodeList
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     6
from nodemanager import NodeManager
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     7
import config_utils, gen_cfile
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     8
from networkedit import networkedit
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     9
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    10
class _NetworkEdit(networkedit):
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    11
    " Overload some of CanFestival Network Editor methods "
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    12
    def OnCloseFrame(self, event):
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    13
        " Do reset _NodeListPlug.View when closed"
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    14
        self._onclose()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    15
        event.Skip()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    16
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    17
class _NodeListPlug(NodeList):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    18
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    19
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    20
      <xsd:element name="CanFestivalNode">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    21
        <xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    22
          <xsd:attribute name="CAN_Device" type="xsd:string" use="required" />
26
7bc11b005c8b added sync option
etisserant
parents: 25
diff changeset
    23
          <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/>
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    24
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    25
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    26
    </xsd:schema>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    27
    """
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    28
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    29
    def __init__(self):
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    30
        manager = NodeManager()
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    31
        # TODO change netname when name change
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    32
        NodeList.__init__(self, manager, self.BaseParams.getName())
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    33
        self.LoadProject(self.PlugPath())
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    34
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    35
    _View = None
18
0fac6d621a24 Base build mechanism layout.
etisserant
parents: 17
diff changeset
    36
    def _OpenView(self, logger):
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    37
        if not self._View:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    38
            def _onclose():
30
ea685658b388 Fixed onclose bug
etisserant
parents: 26
diff changeset
    39
                self._View = None
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    40
            def _onsave():
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    41
                self.GetPlugRoot().SaveProject()
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    42
            self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self)
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    43
            # TODO redefine BusId when IEC channel change
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    44
            self._View.SetBusId(self.GetCurrentLocation())
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    45
            self._View._onclose = _onclose
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    46
            self._View._onsave = _onsave
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    47
            self._View.Show()
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    48
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    49
    PluginMethods = [("NetworkEdit",_OpenView)]
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    50
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    51
    def OnPlugClose(self):
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    52
        if self._View:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    53
            self._View.Close()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    54
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    55
    def PlugTestModified(self):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    56
        return self.HasChanged()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    57
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    58
    def OnPlugSave(self):
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    59
        self.SaveProject()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    60
        return True
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    61
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
    62
    def PlugGenerate_C(self, buildpath, locations, logger):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    63
        """
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    64
        Generate C code
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    65
        @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    66
        @param locations: List of complete variables locations \
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    67
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    68
            "NAME" : name of the variable (generally "__IW0_1_2" style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    69
            "DIR" : direction "Q","I" or "M"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    70
            "SIZE" : size "X", "B", "W", "D", "L"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    71
            "LOC" : tuple of interger for IEC location (0,1,2,...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    72
            }, ...]
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    73
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    74
        """
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
    75
        current_location = self.GetCurrentLocation()
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    76
        # define a unique name for the generated C file
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    77
        prefix = "_".join(map(lambda x:str(x), current_location))
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    78
        Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" )
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
    79
        # Create a new copy of the model with DCF loaded with PDO mappings for desired location
26
7bc11b005c8b added sync option
etisserant
parents: 25
diff changeset
    80
        master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs())
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    81
        res = gen_cfile.GenerateFile(Gen_OD_path, master)
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    82
        if res :
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    83
            raise Exception, res
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
    84
        
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
    85
        return [(Gen_OD_path,"")],""
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    86
    
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    87
class RootClass:
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    88
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    89
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    90
      <xsd:element name="CanFestivalInstance">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    91
        <xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    92
          <xsd:attribute name="CAN_Driver" type="xsd:string" use="required" />
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    93
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    94
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    95
    </xsd:schema>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    96
    """
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    97
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    98
    PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    99
    
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   100
    def PlugGenerate_C(self, buildpath, locations, logger):
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   101
        return [],""
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   102
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   103