plugins/canfestival/canfestival.py
author lbessard
Fri, 27 Jun 2008 09:28:52 +0200
changeset 176 d8cacbf276b5
parent 174 dc81d1d0f463
child 178 2390b409eb93
permissions -rw-r--r--
Close Project menu item implemented
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
     1
import os, sys
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     2
base_folder = os.path.split(sys.path[0])[0]
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 47
diff changeset
     3
CanFestivalPath = os.path.join(base_folder, "CanFestival-3")
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 47
diff changeset
     4
sys.path.append(os.path.join(CanFestivalPath, "objdictgen"))
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 18
diff changeset
     5
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     6
from nodelist import NodeList
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     7
from nodemanager import NodeManager
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
     8
import config_utils, gen_cfile
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
     9
from networkedit import networkedit
77
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    10
from objdictedit import objdictedit
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 47
diff changeset
    11
import canfestival_config
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
    12
from plugger import PlugTemplate
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    13
from commondialogs import CreateNodeDialog
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    14
import wx
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    15
77
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    16
from gnosis.xml.pickle import *
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    17
from gnosis.xml.pickle.util import setParanoia
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    18
setParanoia(0)
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    19
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    20
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    21
#                    SLAVE
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    22
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    23
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    24
class _SlavePlug(NodeManager):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    25
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    26
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    27
      <xsd:element name="CanFestivalSlaveNode">
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    28
        <xsd:complexType>
86
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
    29
          <xsd:attribute name="CAN_Device" type="xsd:string" use="required"/>
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
    30
          <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required"/>
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
    31
          <xsd:attribute name="NodeId" type="xsd:string" use="required"/>
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    32
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    33
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    34
    </xsd:schema>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    35
    """
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    36
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    37
    def GetSlaveODPath(self):
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    38
        return os.path.join(self.PlugPath(), 'slave.od')
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    39
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    40
    def __init__(self):
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    41
        # TODO change netname when name change
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    42
        NodeManager.__init__(self)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    43
        odfilepath = self.GetSlaveODPath()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    44
        if(os.path.isfile(odfilepath)):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    45
            self.OpenFileInCurrent(odfilepath)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    46
        else:
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    47
            self.FilePath = ""
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    48
            dialog = CreateNodeDialog(None, wx.OK)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    49
            dialog.Type.Enable(False)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    50
            dialog.GenSYNC.Enable(False)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    51
            if dialog.ShowModal() == wx.ID_OK:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    52
                name, id, nodetype, description = dialog.GetValues()
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    53
                profile, filepath = dialog.GetProfile()
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    54
                NMT = dialog.GetNMTManagement()
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    55
                options = dialog.GetOptions()
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    56
                self.CreateNewNode(name,       # Name - will be changed at build time
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    57
                                   id,         # NodeID - will be changed at build time
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    58
                                   "slave",    # Type
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    59
                                   description,# description 
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    60
                                   profile,    # profile
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    61
                                   filepath,   # prfile filepath
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    62
                                   NMT,        # NMT
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    63
                                   options)     # options
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    64
            else:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    65
                self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    66
                                   0x00,         # NodeID - will be changed at build time
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    67
                                   "slave",      # Type
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    68
                                   "",           # description 
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    69
                                   "None",       # profile
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    70
                                   "", # prfile filepath
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    71
                                   "heartbeat",  # NMT
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    72
                                   [])           # options
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
    73
            dialog.Destroy()
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    74
    _View = None
18
0fac6d621a24 Base build mechanism layout.
etisserant
parents: 17
diff changeset
    75
    def _OpenView(self, logger):
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    76
        if not self._View:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    77
            def _onclose():
30
ea685658b388 Fixed onclose bug
etisserant
parents: 26
diff changeset
    78
                self._View = None
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    79
            def _onsave():
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    80
                self.GetPlugRoot().SaveProject()
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    81
            self._View = objdictedit(self.GetPlugRoot().AppFrame, self)
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    82
            # TODO redefine BusId when IEC channel change
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    83
            self._View.SetBusId(self.GetCurrentLocation())
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    84
            self._View._onclose = _onclose
25
fa7503684c28 Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents: 24
diff changeset
    85
            self._View._onsave = _onsave
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    86
            self._View.Show()
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    87
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 59
diff changeset
    88
    PluginMethods = [
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 77
diff changeset
    89
        {"bitmap" : os.path.join("images", "NetworkEdit"),
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    90
         "name" : "Edit slave", 
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    91
         "tooltip" : "Edit CanOpen slave with ObjdictEdit",
105
434aed8dc58d Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents: 95
diff changeset
    92
         "method" : "_OpenView"},
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 59
diff changeset
    93
    ]
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    94
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    95
    def OnPlugClose(self):
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    96
        if self._View:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    97
            self._View.Close()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    98
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
    99
    def PlugTestModified(self):
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   100
        return self.ChangesToSave or self.OneFileHasChanged()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   101
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
   102
    def OnPlugSave(self):
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   103
        return self.SaveCurrentInFile(self.GetSlaveODPath())
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   104
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   105
    def PlugGenerate_C(self, buildpath, locations, logger):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   106
        """
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   107
        Generate C code
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   108
        @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
   109
        @param locations: List of complete variables locations \
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   110
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   111
            "NAME" : name of the variable (generally "__IW0_1_2" style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   112
            "DIR" : direction "Q","I" or "M"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   113
            "SIZE" : size "X", "B", "W", "D", "L"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   114
            "LOC" : tuple of interger for IEC location (0,1,2,...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   115
            }, ...]
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   116
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   117
        """
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   118
        current_location = self.GetCurrentLocation()
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   119
        # define a unique name for the generated C file
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   120
        prefix = "_".join(map(str, current_location))
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 47
diff changeset
   121
        Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix )
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   122
        # Create a new copy of the model
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   123
        slave = self.GetCurrentNodeCopy()
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   124
        slave.SetNodeName("OD_%s"%prefix)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   125
        # allow access to local OD from Slave PLC
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   126
        pointers = config_utils.LocalODPointers(locations, current_location, slave)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   127
        res = gen_cfile.GenerateFile(Gen_OD_path, slave, pointers)
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   128
        if res :
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   129
            raise Exception, res
172
8eefeccbd021 Adding support for modification in CanFestival eds_utils
lbessard
parents: 169
diff changeset
   130
        res = eds_utils.GenerateEDSFile(os.path.join(buildpath, "Slave_%s.eds"%prefix), slave)
8eefeccbd021 Adding support for modification in CanFestival eds_utils
lbessard
parents: 169
diff changeset
   131
        if res :
8eefeccbd021 Adding support for modification in CanFestival eds_utils
lbessard
parents: 169
diff changeset
   132
            raise Exception, res
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   133
        return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   134
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   135
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   136
#                    MASTER
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   137
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   138
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   139
class _NodeListPlug(NodeList):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   140
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   141
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   142
      <xsd:element name="CanFestivalNode">
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   143
        <xsd:complexType>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   144
          <xsd:attribute name="CAN_Device" type="xsd:string" use="required"/>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   145
          <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required"/>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   146
          <xsd:attribute name="NodeId" type="xsd:string" use="required"/>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   147
          <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   148
        </xsd:complexType>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   149
      </xsd:element>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   150
    </xsd:schema>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   151
    """
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   152
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   153
    def __init__(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   154
        manager = NodeManager()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   155
        # TODO change netname when name change
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   156
        NodeList.__init__(self, manager, self.BaseParams.getName())
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   157
        self.LoadProject(self.PlugPath())
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   158
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   159
    _View = None
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   160
    def _OpenView(self, logger):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   161
        if not self._View:
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   162
            def _onclose():
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   163
                self._View = None
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   164
            def _onsave():
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   165
                self.GetPlugRoot().SaveProject()
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   166
            self._View = networkedit(self.GetPlugRoot().AppFrame, self)
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   167
            # TODO redefine BusId when IEC channel change
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   168
            self._View.SetBusId(self.GetCurrentLocation())
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   169
            self._View._onclose = _onclose
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   170
            self._View._onsave = _onsave
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   171
            self._View.Show()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   172
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   173
    def _ShowMasterGenerated(self, logger):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   174
        buildpath = self._getBuildPath()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   175
        # Eventually create build dir
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   176
        if not os.path.exists(buildpath):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   177
            logger.write_error("Error: No PLC built\n")
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   178
            return
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   179
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   180
        masterpath = os.path.join(buildpath, "MasterGenerated.od")
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   181
        if not os.path.exists(masterpath):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   182
            logger.write_error("Error: No Master generated\n")
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   183
            return
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   184
        
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   185
        new_dialog = objdictedit(None, filesOpen=[masterpath])
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   186
        new_dialog.Show()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   187
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   188
    PluginMethods = [
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   189
        {"bitmap" : os.path.join("images", "NetworkEdit"),
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   190
         "name" : "Edit network", 
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   191
         "tooltip" : "Edit CanOpen Network with NetworkEdit",
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   192
         "method" : "_OpenView"},
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   193
        {"name" : "Show Master", 
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   194
         "tooltip" : "Show Master generated by config_utils",
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   195
         "method" : "_ShowMasterGenerated"}
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   196
    ]
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   197
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   198
    def OnPlugClose(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   199
        if self._View:
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   200
            self._View.Close()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   201
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   202
    def PlugTestModified(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   203
        return self.ChangesToSave or self.HasChanged()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   204
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   205
    def OnPlugSave(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   206
        self.SetRoot(self.PlugPath())
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   207
        return self.SaveProject() is not None
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   208
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   209
    def PlugGenerate_C(self, buildpath, locations, logger):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   210
        """
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   211
        Generate C code
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   212
        @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   213
        @param locations: List of complete variables locations \
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   214
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   215
            "NAME" : name of the variable (generally "__IW0_1_2" style)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   216
            "DIR" : direction "Q","I" or "M"
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   217
            "SIZE" : size "X", "B", "W", "D", "L"
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   218
            "LOC" : tuple of interger for IEC location (0,1,2,...)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   219
            }, ...]
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   220
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   221
        """
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   222
        current_location = self.GetCurrentLocation()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   223
        # define a unique name for the generated C file
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   224
        prefix = "_".join(map(str, current_location))
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   225
        Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix )
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   226
        # Create a new copy of the model with DCF loaded with PDO mappings for desired location
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   227
        master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix)
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   228
        # allow access to local OD from Master PLC
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   229
        pointers.update(config_utils.LocalODPointers(locations, current_location, master))
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   230
        # Do generate C file.
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   231
        res = gen_cfile.GenerateFile(Gen_OD_path, master, pointers)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   232
        if res :
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   233
            raise Exception, res
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   234
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   235
        file = open(os.path.join(buildpath, "MasterGenerated.od"), "w")
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   236
        dump(master, file)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   237
        file.close()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   238
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   239
        return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   240
    
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   241
class RootClass:
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   242
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   243
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   244
      <xsd:element name="CanFestivalInstance">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   245
        <xsd:complexType>
86
f0a9d74e3b26 Adding support for the new version of xmlclass
lbessard
parents: 82
diff changeset
   246
          <xsd:attribute name="CAN_Driver" type="xsd:string" use="required"/>
157
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   247
          <xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/>
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   248
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   249
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   250
    </xsd:schema>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   251
    """
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   252
    PlugChildsTypes = [("CanOpenNode",_NodeListPlug, "CanOpen Master"),
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   253
                       ("CanOpenSlave",_SlavePlug, "CanOpen Slave")]
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   254
    def GetParamsAttributes(self, path = None):
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   255
        infos = PlugTemplate.GetParamsAttributes(self, path = None)
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   256
        for element in infos:
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   257
            if element["name"] == "CanFestivalInstance":
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   258
                for child in element["children"]:
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   259
                    if child["name"] == "CAN_Driver":
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   260
                        DLL_LIST= getattr(canfestival_config,"DLL_LIST",None)
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   261
                        if DLL_LIST is not None:
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   262
                            child["type"] = DLL_LIST
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   263
                        return infos    
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   264
        return infos
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   265
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   266
    def PlugGenerate_C(self, buildpath, locations, logger):
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   267
        
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   268
        format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())),
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   269
                       "candriver" : self.CanFestivalInstance.getCAN_Driver(),
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   270
                       "nodes_includes" : "",
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   271
                       "board_decls" : "",
59
b6ff896ff58b Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents: 57
diff changeset
   272
                       "nodes_declare" : "",
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   273
                       "nodes_init" : "",
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   274
                       "nodes_open" : "",
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   275
                       "nodes_close" : "",
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   276
                       "nodes_send_sync" : "",
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   277
                       "nodes_proceed_sync" : "",
174
dc81d1d0f463 Fixed slavebootup bug in generated code.
etisserant
parents: 172
diff changeset
   278
                       "slavebootups" : "",
dc81d1d0f463 Fixed slavebootup bug in generated code.
etisserant
parents: 172
diff changeset
   279
                       "slavebootup_register" : ""}
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   280
        for child in self.IECSortedChilds():
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   281
            childlocstr = "_".join(map(str,child.GetCurrentLocation()))
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   282
            nodename = "OD_%s" % childlocstr
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   283
            
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   284
            # Try to get Slave Node
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   285
            child_data = getattr(child, "CanFestivalSlaveNode", None)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   286
            if child_data is None:
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   287
                # Not a slave -> master
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   288
                child_data = getattr(child, "CanFestivalNode")
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   289
                # Apply sync setting
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   290
                if child_data.getSync_TPDOs():
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   291
                    format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n    '%(nodename)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   292
                    format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n    '%(nodename)
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   293
                # initialize and declare node table for post_SlaveBootup lookup
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   294
                
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   295
                SlaveIDs = child.GetSlaveIDs()
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   296
                for id in SlaveIDs:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   297
                    format_dict["slavebootups"] += """
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   298
int %s_slave_%d_booted = 0;
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   299
"""%(nodename, id)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   300
                format_dict["slavebootups"] += """
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   301
static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   302
    switch(nodeId){
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   303
"""%(nodename)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   304
                for id in SlaveIDs:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   305
                    format_dict["slavebootups"] += """
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   306
        case %d:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   307
            %s_slave_%d_booted = 1;
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   308
            break;
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   309
"""%(id, nodename, id)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   310
                format_dict["slavebootups"] += """
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   311
        default:
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   312
            break;
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   313
    }
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   314
    if( """
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   315
                format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs])
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   316
                
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   317
                format_dict["slavebootups"] += """ )
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   318
        Master_post_SlaveBootup(d,nodeId);
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   319
}
174
dc81d1d0f463 Fixed slavebootup bug in generated code.
etisserant
parents: 172
diff changeset
   320
"""
dc81d1d0f463 Fixed slavebootup bug in generated code.
etisserant
parents: 172
diff changeset
   321
                format_dict["slavebootup_register"] += """
169
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   322
%s_Data.post_SlaveBootup = %s_post_SlaveBootup;
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   323
"""%(nodename,nodename)
8e87b69286c0 SlaveBootup now set operational state for both local node and network nodes only when all nodes declared in network edit have been initialized.
etisserant
parents: 166
diff changeset
   324
                
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   325
            format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename)
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   326
            format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%(
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   327
                   nodename,
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   328
                   child_data.getCAN_Device(),
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   329
                   child_data.getCAN_Baudrate())
59
b6ff896ff58b Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents: 57
diff changeset
   330
            format_dict["nodes_declare"] += 'NODE_DECLARE(%s, %s)\n    '%(
b6ff896ff58b Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents: 57
diff changeset
   331
                   nodename,
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   332
                   child_data.getNodeId())
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   333
            format_dict["nodes_init"] += 'NODE_INIT(%s, %s)\n    '%(
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   334
                   nodename,
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   335
                   child_data.getNodeId())
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   336
            format_dict["nodes_open"] += 'NODE_OPEN(%s)\n    '%(nodename)
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   337
            format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n    '%(nodename)
157
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   338
        
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   339
        if sys.platform == 'win32':
157
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   340
            if self.CanFestivalInstance.getDebug_mode() and os.path.isfile(os.path.join("%s"%(format_dict["candriver"] + '_DEBUG.dll'))):
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   341
                    format_dict["candriver"] += '_DEBUG.dll'
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   342
            else:
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   343
                format_dict["candriver"] += '.dll'
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   344
        
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   345
        filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c")
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   346
        cf_main = open(filename).read() % format_dict
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   347
        cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict)
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   348
        f = open(cf_main_path,'w')
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   349
        f.write(cf_main)
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   350
        f.close()
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   351
        
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   352
        return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   353
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   354