plugins/canfestival/canfestival.py
author smarteh-dev
Thu, 09 Feb 2012 21:23:11 +0100
changeset 680 61746934df41
parent 512 36aeab46f27d
child 684 d376a8b0b602
permissions -rw-r--r--
Adding support for integrating CanFestival plugin panels in Beremiz main frame
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
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
     8
import config_utils, gen_cfile, eds_utils
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
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
    11
import canfestival_config as local_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
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
    16
from SlaveEditor import SlaveEditor
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
    17
from NetworkEditor import NetworkEditor
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
    18
77
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    19
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
    20
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
    21
setParanoia(0)
7de69369373e Adding file with generated master in build folder and a button for editing it with objdictedit
lbessard
parents: 65
diff changeset
    22
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    23
if wx.Platform == '__WXMSW__':
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    24
    DEFAULT_SETTINGS = {
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    25
        "CAN_Driver": "can_tcp_win32",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    26
        "CAN_Device": "127.0.0.1",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    27
        "CAN_Baudrate": "125K",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    28
        "Slave_NodeId": 2,
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    29
        "Master_NodeId": 1,
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    30
    }
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    31
else:
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    32
    DEFAULT_SETTINGS = {
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    33
        "CAN_Driver": "../CanFestival-3/drivers/can_socket/libcanfestival_can_socket.so",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    34
        "CAN_Device": "vcan0",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    35
        "CAN_Baudrate": "125K",
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    36
        "Slave_NodeId": 2,
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    37
        "Master_NodeId": 1,
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    38
    }
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    39
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    40
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    41
#                    SLAVE
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    42
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    43
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    44
class _SlavePlug(NodeManager):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    45
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    46
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
    47
      <xsd:element name="CanFestivalSlaveNode">
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    48
        <xsd:complexType>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    49
          <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/>
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    50
          <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    51
          <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/>
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
    52
          <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/>
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    53
          <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50">
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    54
            <xsd:simpleType>
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    55
                <xsd:restriction base="xsd:integer">
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    56
                    <xsd:minInclusive value="1"/>
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    57
                    <xsd:maxInclusive value="99"/>
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    58
                </xsd:restriction>
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    59
            </xsd:simpleType>
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
    60
          </xsd:attribute>
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    61
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    62
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
    63
    </xsd:schema>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
    64
    """ % DEFAULT_SETTINGS
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
    65
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
    66
    EditorType = SlaveEditor
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    67
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
    68
    def __init__(self):
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
    69
        # TODO change netname when name change
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    70
        NodeManager.__init__(self)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    71
        odfilepath = self.GetSlaveODPath()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    72
        if(os.path.isfile(odfilepath)):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    73
            self.OpenFileInCurrent(odfilepath)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
    74
        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
    75
            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
    76
            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
    77
            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
    78
            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
    79
            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
    80
                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
    81
                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
    82
                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
    83
                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
    84
                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
    85
                                   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
    86
                                   "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
    87
                                   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
    88
                                   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
    89
                                   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
    90
                                   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
    91
                                   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
    92
            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
    93
                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
    94
                                   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
    95
                                   "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
    96
                                   "",           # 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
    97
                                   "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
    98
                                   "", # 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
    99
                                   "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
   100
                                   [])           # 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
   101
            dialog.Destroy()
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   102
            self.OnPlugSave()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   103
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   104
    def GetSlaveODPath(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   105
        return os.path.join(self.PlugPath(), 'slave.od')
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   106
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   107
    def GetCanDevice(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   108
        return self.CanFestivalSlaveNode.getCan_Device()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   109
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   110
    def _OpenView(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   111
        PlugTemplate._OpenView(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   112
        if self._View is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   113
            self._View.SetBusId(self.GetCurrentLocation())
23
e007d9d466d7 minor fixes
etisserant
parents: 22
diff changeset
   114
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 59
diff changeset
   115
    PluginMethods = [
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 77
diff changeset
   116
        {"bitmap" : os.path.join("images", "NetworkEdit"),
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   117
         "name" : "Edit slave", 
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   118
         "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
   119
         "method" : "_OpenView"},
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 59
diff changeset
   120
    ]
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   121
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   122
    def OnPlugClose(self):
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   123
        if self._View:
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   124
            self._View.Close()
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   125
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   126
    def PlugTestModified(self):
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   127
        return self.ChangesToSave or self.OneFileHasChanged()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   128
        
17
ee8cb104dbe0 First commit of Beremiz new version with plugin support
lbessard
parents: 15
diff changeset
   129
    def OnPlugSave(self):
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   130
        return self.SaveCurrentInFile(self.GetSlaveODPath())
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   131
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   132
    def SetParamsAttribute(self, path, value):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   133
        result = PlugTemplate.SetParamsAttribute(self, path, value)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   134
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   135
        # Filter IEC_Channel and Name, that have specific behavior
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   136
        if path == "BaseParams.IEC_Channel" and self._View is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   137
            self._View.SetBusId(self.GetCurrentLocation())
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   138
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   139
        return result
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   140
        
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   141
    def PlugGenerate_C(self, buildpath, locations):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   142
        """
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   143
        Generate C code
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   144
        @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
   145
        @param locations: List of complete variables locations \
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   146
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   147
            "NAME" : name of the variable (generally "__IW0_1_2" style)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   148
            "DIR" : direction "Q","I" or "M"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   149
            "SIZE" : size "X", "B", "W", "D", "L"
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   150
            "LOC" : tuple of interger for IEC location (0,1,2,...)
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   151
            }, ...]
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   152
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   153
        """
24
585d5b387b6a Working CanOpen OD generation
etisserant
parents: 23
diff changeset
   154
        current_location = self.GetCurrentLocation()
22
9a0c535c3272 Pleliminary build process -- C code generation
etisserant
parents: 20
diff changeset
   155
        # define a unique name for the generated C file
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   156
        prefix = "_".join(map(str, current_location))
49
45dc6a944ab6 On the long wat towards generated code comilation...
etisserant
parents: 47
diff changeset
   157
        Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix )
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   158
        # Create a new copy of the model
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   159
        slave = self.GetCurrentNodeCopy()
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   160
        slave.SetNodeName("OD_%s"%prefix)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   161
        # allow access to local OD from Slave PLC
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   162
        pointers = config_utils.LocalODPointers(locations, current_location, slave)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   163
        res = gen_cfile.GenerateFile(Gen_OD_path, slave, pointers)
15
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   164
        if res :
7a473efc4530 More precise design for plugins.... to be continued...
etisserant
parents: 13
diff changeset
   165
            raise Exception, res
172
8eefeccbd021 Adding support for modification in CanFestival eds_utils
lbessard
parents: 169
diff changeset
   166
        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
   167
        if res :
8eefeccbd021 Adding support for modification in CanFestival eds_utils
lbessard
parents: 169
diff changeset
   168
            raise Exception, res
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   169
        return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   170
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   171
    def LoadPrevious(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   172
        self.LoadCurrentPrevious()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   173
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   174
    def LoadNext(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   175
        self.LoadCurrentNext()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   176
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   177
    def GetBufferState(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   178
        return self.GetCurrentBufferState()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   179
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   180
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   181
#                    MASTER
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   182
#--------------------------------------------------
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   183
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   184
class MiniNodeManager(NodeManager):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   185
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   186
    def __init__(self, parent, filepath, fullname):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   187
        NodeManager.__init__(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   188
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   189
        self.OpenFileInCurrent(filepath)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   190
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   191
        self.Parent = parent
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   192
        self.Fullname = fullname
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   193
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   194
    def OnCloseEditor(self, view):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   195
        self.Parent.OnCloseEditor(view)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   196
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   197
    def PlugFullName(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   198
        return self.Fullname
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   199
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   200
    def GetBufferState(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   201
        return self.GetCurrentBufferState()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   202
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   203
class _NodeListPlug(NodeList):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   204
    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
   205
    <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
   206
      <xsd:element name="CanFestivalNode">
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   207
        <xsd:complexType>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   208
          <xsd:attribute name="CAN_Device" type="xsd:string" use="optional" default="%(CAN_Device)s"/>
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   209
          <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   210
          <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/>
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   211
          <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
   212
        </xsd:complexType>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   213
      </xsd:element>
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   214
    </xsd:schema>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   215
    """ % DEFAULT_SETTINGS
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   216
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   217
    EditorType = NetworkEditor
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   218
    
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   219
    def __init__(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   220
        manager = NodeManager()
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   221
        NodeList.__init__(self, manager)
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   222
        self.LoadProject(self.PlugPath())
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   223
        self.SetNetworkName(self.BaseParams.getName())
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   224
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   225
    def GetCanDevice(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   226
        return self.CanFestivalNode.getCan_Device()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   227
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   228
    def SetParamsAttribute(self, path, value):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   229
        result = PlugTemplate.SetParamsAttribute(self, path, value)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   230
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   231
        # Filter IEC_Channel and Name, that have specific behavior
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   232
        if path == "BaseParams.IEC_Channel" and self._View is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   233
            self._View.SetBusId(self.GetCurrentLocation())
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   234
        elif path == "BaseParams.Name":
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   235
            self.SetNetworkName(value)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   236
        
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   237
        return result
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   238
    
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   239
    def _OpenView(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   240
        PlugTemplate._OpenView(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   241
        if self._View is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   242
            self._View.SetBusId(self.GetCurrentLocation())
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   243
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   244
    _GeneratedView = None
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   245
    def _ShowMasterGenerated(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   246
        if self._GeneratedView is None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   247
            buildpath = self._getBuildPath()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   248
            # Eventually create build dir
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   249
            if not os.path.exists(buildpath):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   250
                self.GetPlugRoot().logger.write_error(_("Error: No PLC built\n"))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   251
                return
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   252
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   253
            masterpath = os.path.join(buildpath, "MasterGenerated.od")
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   254
            if not os.path.exists(masterpath):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   255
                self.GetPlugRoot().logger.write_error(_("Error: No Master generated\n"))
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   256
                return
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   257
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   258
            app_frame = self.GetPlugRoot().AppFrame
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   259
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   260
            manager = MiniNodeManager(self, masterpath, self.PlugFullName() + ".generated_master")
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   261
            self._GeneratedView = SlaveEditor(app_frame.TabsOpened, manager, app_frame, False)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   262
            
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   263
            app_frame.EditProjectElement(self._GeneratedView, "MasterGenerated")
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   264
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   265
    def _CloseGenerateView(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   266
        if self._GeneratedView is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   267
            app_frame = self.GetPlugRoot().AppFrame
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   268
            if app_frame is not None:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   269
                app_frame.DeletePage(self._GeneratedView)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   270
    
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   271
    PluginMethods = [
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   272
        {"bitmap" : os.path.join("images", "NetworkEdit"),
361
331d698e1118 Adding support for internationalization
laurent
parents: 341
diff changeset
   273
         "name" : _("Edit network"), 
331d698e1118 Adding support for internationalization
laurent
parents: 341
diff changeset
   274
         "tooltip" : _("Edit CanOpen Network with NetworkEdit"),
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   275
         "method" : "_OpenView"},
372
35cc4c6a2936 Added ShowMaster button icon for Canfestival plugin
edouard
parents: 361
diff changeset
   276
        {"bitmap" : os.path.join("images", "ShowMaster"),
35cc4c6a2936 Added ShowMaster button icon for Canfestival plugin
edouard
parents: 361
diff changeset
   277
         "name" : _("Show Master"), 
361
331d698e1118 Adding support for internationalization
laurent
parents: 341
diff changeset
   278
         "tooltip" : _("Show Master generated by config_utils"),
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   279
         "method" : "_ShowMasterGenerated"}
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   280
    ]
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   281
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   282
    def OnCloseEditor(self, view):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   283
        PlugTemplate.OnCloseEditor(self, view)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   284
        if self._GeneratedView == view:
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   285
            self._GeneratedView = None
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   286
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   287
    def OnPlugClose(self):
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   288
        PlugTemplate.OnPlugClose(self)
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   289
        self._CloseGenerateView()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   290
        return True
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   291
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   292
    def PlugTestModified(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   293
        return self.ChangesToSave or self.HasChanged()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   294
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   295
    def OnPlugSave(self):
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   296
        self.SetRoot(self.PlugPath())
250
01963beca027 Bug with return value of nodelist saving fixed
lbessard
parents: 203
diff changeset
   297
        return self.SaveProject() is None
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   298
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   299
    def PlugGenerate_C(self, buildpath, locations):
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   300
        """
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   301
        Generate C code
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   302
        @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
   303
        @param locations: List of complete variables locations \
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   304
            [{"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
   305
            "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
   306
            "DIR" : direction "Q","I" or "M"
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   307
            "SIZE" : size "X", "B", "W", "D", "L"
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   308
            "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
   309
            }, ...]
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   310
        @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
   311
        """
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   312
        self._CloseGenerateView()
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   313
        current_location = self.GetCurrentLocation()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   314
        # define a unique name for the generated C file
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   315
        prefix = "_".join(map(str, current_location))
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   316
        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
   317
        # Create a new copy of the model with DCF loaded with PDO mappings for desired location
341
d3ae1f0e0220 Get PDOmapping exception from canfestival plugin
greg
parents: 336
diff changeset
   318
        try:
d3ae1f0e0220 Get PDOmapping exception from canfestival plugin
greg
parents: 336
diff changeset
   319
            master, pointers = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix)
d3ae1f0e0220 Get PDOmapping exception from canfestival plugin
greg
parents: 336
diff changeset
   320
        except config_utils.PDOmappingException, e:
d3ae1f0e0220 Get PDOmapping exception from canfestival plugin
greg
parents: 336
diff changeset
   321
            raise Exception, e.message
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   322
        # Do generate C file.
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   323
        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
   324
        if res :
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   325
            raise Exception, res
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   326
        
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   327
        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
   328
        dump(master, file)
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   329
        file.close()
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   330
        
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   331
        return [(Gen_OD_path,local_canfestival_config.getCFLAGS(CanFestivalPath))],"",False
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   332
    
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   333
    def LoadPrevious(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   334
        self.Manager.LoadCurrentPrevious()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   335
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   336
    def LoadNext(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   337
        self.Manager.LoadCurrentNext()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   338
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   339
    def GetBufferState(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   340
        return self.Manager.GetCurrentBufferState()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   341
    
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   342
class RootClass:
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   343
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   344
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   345
      <xsd:element name="CanFestivalInstance">
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   346
        <xsd:complexType>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   347
          <xsd:attribute name="CAN_Driver" type="xsd:string" use="optional" default="%(CAN_Driver)s"/>
157
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   348
          <xsd:attribute name="Debug_mode" type="xsd:boolean" use="optional" default="false"/>
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   349
        </xsd:complexType>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   350
      </xsd:element>
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   351
    </xsd:schema>
411
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   352
    """ % DEFAULT_SETTINGS
8261c8f1e365 Bug on Debug trying to start (and stop) before PLC started fixed.
laurent
parents: 372
diff changeset
   353
    
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
   354
    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
   355
                       ("CanOpenSlave",_SlavePlug, "CanOpen Slave")]
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   356
    def GetParamsAttributes(self, path = None):
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   357
        infos = PlugTemplate.GetParamsAttributes(self, path = None)
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   358
        for element in infos:
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   359
            if element["name"] == "CanFestivalInstance":
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   360
                for child in element["children"]:
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   361
                    if child["name"] == "CAN_Driver":
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   362
                        DLL_LIST= getattr(local_canfestival_config,"DLL_LIST",None)
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   363
                        if DLL_LIST is not None:
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   364
                            child["type"] = DLL_LIST  
95
646a44a12e2a add GetParamsAttributes to canfestival.py to allow dll list in beremiz
greg
parents: 86
diff changeset
   365
        return infos
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   366
    
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   367
    def GetCanDriver(self):
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   368
        return self.CanFestivalInstance.getCAN_Driver()
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   369
    
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   370
    def PlugGenerate_C(self, buildpath, locations):
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   371
        
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   372
        format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())),
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   373
                       "candriver" : self.GetCanDriver(),
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   374
                       "nodes_includes" : "",
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   375
                       "board_decls" : "",
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   376
                       "nodes_init" : "",
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   377
                       "nodes_open" : "",
336
ae3488c79283 Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents: 307
diff changeset
   378
                       "nodes_stop" : "",
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   379
                       "nodes_close" : "",
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   380
                       "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
   381
                       "nodes_proceed_sync" : "",
174
dc81d1d0f463 Fixed slavebootup bug in generated code.
etisserant
parents: 172
diff changeset
   382
                       "slavebootups" : "",
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   383
                       "slavebootup_register" : "",
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   384
                       "post_sync" : "",
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   385
                       "post_sync_register" : "",
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   386
                       }
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   387
        for child in self.IECSortedChilds():
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   388
            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
   389
            nodename = "OD_%s" % childlocstr
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   390
            
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   391
            # Try to get Slave Node
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   392
            child_data = getattr(child, "CanFestivalSlaveNode", None)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   393
            if child_data is None:
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   394
                # Not a slave -> master
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   395
                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
   396
                # Apply sync setting
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   397
                format_dict["nodes_init"] += 'NODE_MASTER_INIT(%s, %s)\n    '%(
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   398
                       nodename,
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   399
                       child_data.getNodeId())
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   400
                if child_data.getSync_TPDOs():
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   401
                    format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n    '%(nodename)
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   402
                    format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n    '%(nodename)
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   403
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   404
                # initialize and declare node boot status variables for post_SlaveBootup lookup
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
   405
                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
   406
                for id in SlaveIDs:
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   407
                    format_dict["slavebootups"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   408
                    "int %s_slave_%d_booted = 0;\n"%(nodename, id))
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   409
                # define post_SlaveBootup lookup functions
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   410
                format_dict["slavebootups"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   411
                    "static void %s_post_SlaveBootup(CO_Data* d, UNS8 nodeId){\n"%(nodename)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   412
                    "    switch(nodeId){\n")
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   413
                # one case per declared node, mark node as booted
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
   414
                for id in SlaveIDs:
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   415
                    format_dict["slavebootups"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   416
                    "        case %d:\n"%(id)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   417
                    "            %s_slave_%d_booted = 1;\n"%(nodename, id)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   418
                    "            break;\n")
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   419
                format_dict["slavebootups"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   420
                    "        default:\n"+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   421
                    "            break;\n"+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   422
                    "    }\n"+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   423
                    "    if( ")
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   424
                # expression to test if all declared nodes booted
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
   425
                format_dict["slavebootups"] += " && ".join(["%s_slave_%d_booted"%(nodename, id) for id in SlaveIDs])
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   426
                format_dict["slavebootups"] += " )\n" + (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   427
                    "        Master_post_SlaveBootup(d,nodeId);\n"+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   428
                    "}\n")
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   429
                # register previously declared func as post_SlaveBootup callback for that node
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   430
                format_dict["slavebootup_register"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   431
                    "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename))
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   432
            else:
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   433
                # Slave node
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   434
                align = child_data.getSync_Align()
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   435
                align_ratio=child_data.getSync_Align_Ratio()
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   436
                if align > 0:
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   437
                    format_dict["post_sync"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   438
                        "static int %s_CalCount = 0;\n"%(nodename)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   439
                        "static void %s_post_sync(CO_Data* d){\n"%(nodename)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   440
                        "    if(%s_CalCount < %d){\n"%(nodename, align)+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   441
                        "        %s_CalCount++;\n"%(nodename)+
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   442
                        "        align_tick(-1);\n"+
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   443
                        "    }else{\n"+
203
cb9901076a21 Added concepts :
etisserant
parents: 178
diff changeset
   444
                        "        align_tick(%d);\n"%(align_ratio)+
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   445
                        "    }\n"+
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   446
                        "}\n")
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   447
                    format_dict["post_sync_register"] += (
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   448
                        "%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename))
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   449
                format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n    '%(
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   450
                       nodename,
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   451
                       child_data.getNodeId())
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   452
    
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   453
            # Include generated OD headers
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   454
            format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename)
178
2390b409eb93 Added PLC tick alignement on external synchronization source feature.
etisserant
parents: 174
diff changeset
   455
            # Declare CAN channels according user filled config
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   456
            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
   457
                   nodename,
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 512
diff changeset
   458
                   child.GetCanDevice(),
166
121b18748de0 Preliminary CANopen slave generation support
etisserant
parents: 163
diff changeset
   459
                   child_data.getCAN_Baudrate())
57
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   460
            format_dict["nodes_open"] += 'NODE_OPEN(%s)\n    '%(nodename)
3b53f9a509d9 Basic CANOpen master node test compiles and run.
etisserant
parents: 52
diff changeset
   461
            format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n    '%(nodename)
336
ae3488c79283 Fixed bug : Segmentation fault or locks when stop PLC if no CAN network.
greg
parents: 307
diff changeset
   462
            format_dict["nodes_stop"] += 'NODE_STOP(%s)\n    '%(nodename)        
163
482ca562d414 Support for extern pointer for located variables + Preliminary slave code (broken)
etisserant
parents: 159
diff changeset
   463
        if sys.platform == 'win32':
157
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   464
            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
   465
                    format_dict["candriver"] += '_DEBUG.dll'
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   466
            else:
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   467
                format_dict["candriver"] += '.dll'
2e6d52c17cab add debug mode for CanFestival dll under windows
greg
parents: 118
diff changeset
   468
        
52
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   469
        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
   470
        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
   471
        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
   472
        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
   473
        f.write(cf_main)
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   474
        f.close()
eaffcd0a2f03 Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents: 49
diff changeset
   475
        
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   476
        return [(cf_main_path, local_canfestival_config.getCFLAGS(CanFestivalPath))],local_canfestival_config.getLDFLAGS(CanFestivalPath), True
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   477
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 427
diff changeset
   478