Skip to content
Snippets Groups Projects
Commit 93f798fc authored by al.schwinn's avatar al.schwinn
Browse files

[SIL-259] Main skeleton of the VC controller was missing

parent f55ea0cd
No related branches found
No related tags found
No related merge requests found
...@@ -597,14 +597,25 @@ def generateVirtualS7Sources(deployDOM, classDOCList, deploy, workspacePath,logT ...@@ -597,14 +597,25 @@ def generateVirtualS7Sources(deployDOM, classDOCList, deploy, workspacePath,logT
# Prepare the source (<.h> file) with its diagnostic data-block header # Prepare the source (<.h> file) with its diagnostic data-block header
duCodeString = virtualS7Template.vs7DuHeader(deploy.plcName, deploy.deployVersion, duConstructor, includeDesign, allocDesign, deleteDesign, getDesign) duCodeString = virtualS7Template.vs7DuHeader(deploy.plcName, deploy.deployVersion, duConstructor, includeDesign, allocDesign, deleteDesign, getDesign)
# Finally, write the DEPLOY-UNIT generated code into the temporal output file # Write the DEPLOY-UNIT generated code into the temporal output file
sourcesPath = iefiles.getControllerSourcesDirectory(workspacePath, deploy.plcName, deploy.deployVersion) sourcesPath = iefiles.getControllerSourcesDirectory(workspacePath, deploy.plcName, deploy.deployVersion)
sourcesFile = os.path.normpath(sourcesPath + "/%s_%s.h" % (deploy.plcName, deploy.deployVersion)) sourcesFile = os.path.normpath(sourcesPath + "/%s_%s.h" % (deploy.plcName, deploy.deployVersion))
iecommon.logInfo("Generate PLC sources: %s" %sourcesFile,logTopics); iecommon.logInfo("Generate PLC sources: %s" %sourcesFile,logTopics);
fdesc = open(sourcesFile, "w") fdesc = open(sourcesFile, "w")
fdesc.write(duCodeString) fdesc.write(duCodeString)
fdesc.close() fdesc.close()
# Prepare the source (<.h> file) with its diagnostic data-block header
mainCodeString = virtualS7Template.vs7MainCode(deploy.plcName, deploy.deployVersion)
# Finally, write the DEPLOY-UNIT generated code into the temporal output file
sourcesPath = iefiles.getControllerSourcesDirectory(workspacePath, deploy.plcName, deploy.deployVersion)
sourcesFile = os.path.normpath(sourcesPath + "/%s_%s.cpp" % (deploy.plcName, deploy.deployVersion))
iecommon.logInfo("Generate PLC sources: %s" %sourcesFile,logTopics);
fdesc = open(sourcesFile, "w")
fdesc.write(mainCodeString)
fdesc.close()
# Clean-up the memory before return # Clean-up the memory before return
deployDOM.unlink() deployDOM.unlink()
......
...@@ -95,7 +95,7 @@ class Controller(object): ...@@ -95,7 +95,7 @@ class Controller(object):
return RabbitController(controllerNode) return RabbitController(controllerNode)
elif type == "NI-Controller": elif type == "NI-Controller":
return NIController(controllerNode) return NIController(controllerNode)
elif type == "PC-Controller": elif type == "Virtual-Controller":
return VirtualS7Controller(controllerNode) return VirtualS7Controller(controllerNode)
else: else:
raise Exception( "Controller-Type " + type + " not supported" ) raise Exception( "Controller-Type " + type + " not supported" )
...@@ -141,12 +141,10 @@ class RabbitController(Controller): ...@@ -141,12 +141,10 @@ class RabbitController(Controller):
self.baseAddress = self.baseAddress * self.addressFactor self.baseAddress = self.baseAddress * self.addressFactor
class VirtualS7Controller(Controller): class VirtualS7Controller(Controller):
addressFactor = 1
def __init__(self, xmlNode): def __init__(self, xmlNode):
super(VirtualS7Controller, self).__init__(xmlNode) super(VirtualS7Controller, self).__init__(xmlNode)
self.brand = "SIEMENS" self.brand = "SIEMENS"
self.baseAddress = long(self.plcNode.prop('base-address')) self.baseAddress = long(self.plcNode.prop('base-address'))
self.baseAddress = self.baseAddress * self.addressFactor
class NIController(Controller): class NIController(Controller):
def __init__(self, xmlNode): def __init__(self, xmlNode):
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# Project: SILECS # Project: SILECS
# Author: F.Locci/ BE-CO # Author: F.Locci/ BE-CO
# Date: August 2012 # Date: August 2012
...@@ -116,6 +115,42 @@ public: ...@@ -116,6 +115,42 @@ public:
#endif #endif
""" """
mainCode = """
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <silecs-virtual-controller/core/SilecsSnap7Server.h>
#include "%s_%s.h"
class UserSnap7Server : public SilecsServer::SilecsSnap7Server
{
public:
UserSnap7Server(%s::DeployUnit* du) : SilecsSnap7Server(du, true) {}
virtual ~UserSnap7Server() {}
virtual void userFunction()
{
// Implement the specific process control here!
// Look at SILECS Wikis: 'Create a virtual controller' chapter
}
};
int main(int argc, char*argv[])
{
%s::DeployUnit du;
UserSnap7Server server(&du);
if (server.startServer() < 0)
{
std::cout << "Failed to start the VC server: " << du.getName() << std::endl;
return -1;
}
return 0;
}
"""
#========================================================================= #=========================================================================
# Virtual S7 CLASS template # Virtual S7 CLASS template
#========================================================================= #=========================================================================
...@@ -360,6 +395,11 @@ class Design; ...@@ -360,6 +395,11 @@ class Design;
# Virtual S7 generation Sub-function # Virtual S7 generation Sub-function
#========================================================================= #=========================================================================
# SERVER MAIN code generation ---------------------------------------------
def vs7MainCode(deployName, deployVersion):
fullDeployName = deployName + '_' + deployVersion.replace(".", "_")
return mainCode %(deployName, deployVersion, fullDeployName, fullDeployName)
# DEPLOY-UNIT generation ------------------------------------------------- # DEPLOY-UNIT generation -------------------------------------------------
def vs7DuHeader(deployName, deployVersion, duConstructor, designIncludes, designAllocs, designDeletes, designGetters): def vs7DuHeader(deployName, deployVersion, duConstructor, designIncludes, designAllocs, designDeletes, designGetters):
deployVersion = deployVersion.replace(".", "_") deployVersion = deployVersion.replace(".", "_")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment