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

initial commit of all silecs-gsi projects

parent d1039eaa
No related branches found
No related tags found
No related merge requests found
Showing
with 3024 additions and 0 deletions
File added
File added
This diff is collapsed.
File added
File added
This diff is collapsed.
File added
File added
This diff is collapsed.
File added
File added
#!/usr/bin/python
# Copyright 2016 CERN and GSI
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import time
import re
import os
import sys
import getpass
import codecs
import commands
import iecommon
import libxml2
#==================================================================
# LOGGING
#==================================================================
def logHeader(level):
global project, program
_time = time.strftime("%Y/%m/%d-%H:%M:%S")
program = sys.argv[0]
return "[%s SILECS %s %s] " %(_time, program, level)
def logError(msg, exit,logTopics={}):
if 'errorlog' in logTopics:
if logTopics['errorlog'] == True:
_logMsg = "%s%s" %(logHeader("ERROR"), msg)
print _logMsg
if exit:
raise Exception(_logMsg)
def logInfo(msg,logTopics={}):
if 'infolog' in logTopics:
if logTopics['infolog'] == True:
_logMsg = "%s%s" %(logHeader("INFO"), msg)
print _logMsg
def logDebug(msg,logTopics={}):
if 'debuglog' in logTopics:
if logTopics['debuglog'] == True:
_logMsg = "%s%s" %(logHeader("DEBUG"), msg)
print _logMsg
# Append message to a text file
def logToFile(path,msg):
with open(path, "a") as logFile:
logFile.write(logHeader("CMD") + msg + "\n")
#-------------------------------------------------------------------------
# General XML Parsing
#-------------------------------------------------------------------------
def hasChildren(element):
children = element.xpathEval("*")
if len(children):
return True
return False
def getFirstChild(element):
return element.xpathEval("*")[0]
def isChildElement(node,elementName):
if not type(elementName) is str:
raise Exception("Error: Wrong Type Parsed")
for subnode in node:
if subnode.get_name() == elementName:
return True
return False
def getChildElement(node,elementName):
for subnode in node:
if subnode.get_name() == elementName:
return subnode
return null
def getOrCreateChildElement(node,elementName):
namedChilds = node.xpathEval(elementName)
if len(namedChilds):
return namedChilds[0]
newElement = libxml2.newNode(elementName)
node.addChild(newElement)
return newElement
def getOrCreateNamedChildElement(node,elementName, attributeNameValue, attributeName="name"):
elements = node.xpathEval(elementName + "[@" + attributeName + "='" + attributeNameValue + "']")
if len(elements):
return elements[0]
newNode = libxml2.newNode(elementName)
node.addChild(newNode)
newNode.setProp(attributeName, attributeNameValue)
return newNode
def getOrCreateNamedPreviousSiblingElement(parent,node,elementName, attributeNameValue):
alreadyAvailable = node.get_parent().xpathEval(elementName + "[@name='" + attributeNameValue + "']")
if len(alreadyAvailable):
return alreadyAvailable[0]
newNode = libxml2.newNode(elementName)
node.addPrevSibling(newNode)
newNode.setProp("name", attributeNameValue)
return newNode
def getOrCreatePreviousSiblingElement(node,elementName):
alreadyAvailable = node.get_parent().xpathEval(elementName)
if len(alreadyAvailable):
return alreadyAvailable[0]
iecommon.logDebug("Not Found: Name:"+ elementName, {'debuglog': True})
newNode = libxml2.newNode(elementName)
node.addPrevSibling(newNode)
return newNode
def getOrCreateNamedFirstChild(parent,elementName, attributeNameValue):
elements = parent.xpathEval(elementName + "[@name='" + attributeNameValue + "']")
if len(elements):
return elements[0]
newNode = libxml2.newNode(elementName)
newNode.setProp('name', attributeNameValue)
if parent.get_children():
firstChild = parent.xpathEval("*")[0]
firstChild.addPrevSibling(newNode)
else:
parent.addChild(newNode)
return newNode
def fillAttributes(element, attrs):
for name,value in attrs.iteritems():
if not type(value) is str:
raise Exception("Error: Wrong Type Parsed for attribute: " + name)
element.setProp(name, value)
return element
#-------------------------------------------------------------------------
# Given an SILECS data type, returns the corresponding FESA data type
# For the time being FESA does not support unsigned data types in properties
# so here unsigned types are considered as signed to allow users to link
# any field to properties
#-------------------------------------------------------------------------
def getFesaDataType(type):
return {
'int8' :'int8_t',
'uint8' :'int16_t',
'int16' :'int16_t',
'uint16' :'int32_t',
'int32' :'int32_t',
'uint32' :'int64_t',
'int64' :'int64_t',
'uint64' :'uint64_t', # only for PXI, but not supported from Java! Not possible to use it in FESA properties
'float32' :'float',
'float64' :'double',
'date' :'double',
'char' :'int8_t',
'byte' :'int16_t',
'word' :'int32_t',
'dword' :'int64_t',
'int' :'int16_t',
'dint' :'int32_t',
'real' :'float',
'dt' :'double',
'string' :'char'
}[type]
def getCDataType(type):
return {
'int8' :'int8_t',
'uint8' :'uint8_t',
'int16' :'int16_t',
'uint16' :'uint16_t',
'int32' :'int32_t',
'uint32' :'uint32_t',
'int64' :'int64_t',
'uint64' :'uint64_t',
'float32' :'float',
'float64' :'double',
'date' :'double',
'char' :'int8_t',
'byte' :'int16_t',
'word' :'int32_t',
'dword' :'int64_t',
'int' :'int16_t',
'dint' :'int32_t',
'real' :'float',
'dt' :'double',
'string' :'std::string'
}[type]
#-------------------------------------------------------------------------
# Given data type, returns the corresponding
# SILECS data type
#-------------------------------------------------------------------------
def getSilecsDataType(type):
return {
'byte' :'uint8',
'char' :'int8',
'unsigned char' :'uint8',
'short' :'int16',
'unsigned short':'uint16',
'long' :'int32', # conversion relies on 32-bit platform (FESA 3 does not support long type anymore)
'unsigned long' :'uint32',
'double' :'float64',
'float' :'float32',
'word' :'uint16',
'dword' :'uint32',
'int' :'int16',
'dint' :'int32',
'real' :'float32',
'dt' :'date',
'uint8' :'uint8',
'int8' :'int8',
'uint16' :'uint16',
'int16' :'int16',
'uint32' :'uint32',
'int32' :'int32',
'uint64' :'uint64',
'int64' :'int64',
'float32' :'float32',
'float64' :'float64',
'date' :'date',
'string' : 'string'
}[type]
def capitalizeString(text):
str = ""
if len(text) > 0:
str += text[0].upper()
str += text[1:]
return str
def addSilecsHeaderToClasses(silecsDeployDOM):
controllers = silecsDeployDOM.xpathEval("/SILECS-Deploy/Controller")
for controller in controllers:
silecsHeaderDesign = libxml2.newNode("SilecsDesign")
silecsHeaderDesign.setProp("silecs-design-name","SilecsHeader")
silecsHeaderDesign.setProp("silecs-design-version","1.0.0")
silecsHeaderDevice = libxml2.newNode("Device")
silecsHeaderDevice.setProp("device-name","SilecsHeader")
silecsHeaderDesign.addChild(silecsHeaderDevice)
silecsDesigns = controller.xpathEval("SilecsDesign")
silecsDesigns[0].addPrevSibling(silecsHeaderDesign)
#Major changes: Public API, database and PLC code generation may be impacted
def getMajorSilecsVersion(silecsVersionString):
firstDot = silecsVersionString.find('.')
return silecsVersionString[0:firstDot]
#Minor changes: New functionality: backward-compatible
def getMinorSilecsVersion(silecsVersionString):
firstDot = silecsVersionString.find('.')
secondDot = silecsVersionString.find('.',firstDot)
return silecsVersionString[firstDot:secondDot]
#Patches and bug fixes: backward compatible
def getPatchSilecsVersion(silecsVersionString):
firstDot = silecsVersionString.find('.')
secondDot = silecsVersionString.find('.',firstDot)
return silecsVersionString[secondDot:]
File added
File added
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
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