diff --git a/silecs-codegen/src/xml/genplcsrc.py b/silecs-codegen/src/xml/genplcsrc.py index 4852296131ab12edfd36d6b1fa1078e6557e2a96..a259f4fe26cdb2f983eb4c35072aaca956b5ff21 100644 --- a/silecs-codegen/src/xml/genplcsrc.py +++ b/silecs-codegen/src/xml/genplcsrc.py @@ -597,14 +597,25 @@ def generateVirtualS7Sources(deployDOM, classDOCList, deploy, workspacePath,logT # Prepare the source (<.h> file) with its diagnostic data-block header 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) sourcesFile = os.path.normpath(sourcesPath + "/%s_%s.h" % (deploy.plcName, deploy.deployVersion)) iecommon.logInfo("Generate PLC sources: %s" %sourcesFile,logTopics); fdesc = open(sourcesFile, "w") fdesc.write(duCodeString) 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 deployDOM.unlink() diff --git a/silecs-codegen/src/xml/model/Deploy/Controller.py b/silecs-codegen/src/xml/model/Deploy/Controller.py index d9fdc817803a3bc4fe7eda31b8e79014b2c61d0e..83f710347af102a7dea11bbb5cd8a4ec2ff2a336 100644 --- a/silecs-codegen/src/xml/model/Deploy/Controller.py +++ b/silecs-codegen/src/xml/model/Deploy/Controller.py @@ -95,7 +95,7 @@ class Controller(object): return RabbitController(controllerNode) elif type == "NI-Controller": return NIController(controllerNode) - elif type == "PC-Controller": + elif type == "Virtual-Controller": return VirtualS7Controller(controllerNode) else: raise Exception( "Controller-Type " + type + " not supported" ) @@ -141,12 +141,10 @@ class RabbitController(Controller): self.baseAddress = self.baseAddress * self.addressFactor class VirtualS7Controller(Controller): - addressFactor = 1 def __init__(self, xmlNode): super(VirtualS7Controller, self).__init__(xmlNode) self.brand = "SIEMENS" self.baseAddress = long(self.plcNode.prop('base-address')) - self.baseAddress = self.baseAddress * self.addressFactor class NIController(Controller): def __init__(self, xmlNode): diff --git a/silecs-codegen/src/xml/virtualS7Template.py b/silecs-codegen/src/xml/virtualS7Template.py index 88903d072ae4562a3216e8adc83397a2b16eb6c8..59e167240f555acd5f4dec32ff4f90f0b561bb84 100644 --- a/silecs-codegen/src/xml/virtualS7Template.py +++ b/silecs-codegen/src/xml/virtualS7Template.py @@ -13,7 +13,6 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - # Project: SILECS # Author: F.Locci/ BE-CO # Date: August 2012 @@ -116,6 +115,42 @@ public: #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 #========================================================================= @@ -360,6 +395,11 @@ class Design; # 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 ------------------------------------------------- def vs7DuHeader(deployName, deployVersion, duConstructor, designIncludes, designAllocs, designDeletes, designGetters): deployVersion = deployVersion.replace(".", "_")