Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion autocoder/QmParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def parseTrans(qmTrans: ElementTreeType,
number_gen: UniqueNumberGenerator):

source = xmiNode.id
target = int(qmTrans.get('target')) if qmTrans.get('target') else None
target = None

if (qmTrans.get("target") != "None"):
target = int(qmTrans.get('target')) if qmTrans.get('target') else None

kind = qmTrans.get('kind')
guard = qmlib.pick_guard(qmTrans)
action = flatt.pick_action(qmTrans)
Expand Down Expand Up @@ -106,6 +110,7 @@ def populateXmiModel(qmRoot: ElementTreeType,
# Replace the relative target attributes with ID's
for node in qmFix.iter():
target = node.get("target")

if target is not None:
targetId = flatt.state_from_target(node).get("id")
node.set("target", str(targetId))
Expand Down
4 changes: 2 additions & 2 deletions autocoder/Stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def getQmRoot(modelFileName: str) -> Tuple[ElementTreeType, XmiModel] :
print("*** Error - missing namespace argument for the fprime backend")
exit(0)
else:
fppcoder.generateCode(xmiModel)
fprimecoder.generateCode(qmRoot, args.noImpl, args.namespace)
fppcoder.generateCode(xmiModel)
fprimecoder.generateCode(qmRoot, args.noImpl, args.namespace)



Expand Down
12 changes: 10 additions & 2 deletions autocoder/flattenstatemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,18 @@ def get_this_state(tran: ElementTreeType) -> Optional[str]:

def get_state_from_index(root: ElementTreeType, index: int) -> ElementTreeType:
count = 0

for child in root:
if child.tag == 'state' or child.tag == 'tran':
count = count + 1

if index == count:
assert child.tag == 'state'
return child
if (child.tag == "state"):
return child;
else:
assert child.tag == "tran"

return child
assert 0


Expand Down Expand Up @@ -202,10 +208,12 @@ def mark_self_transition(tran: ElementTreeType):
# -----------------------------------------------------------------------
def state_from_target(tran: ElementTreeType) -> ElementTreeType:
target = tran.get('target')

if target is None:
return tran.getparent()
else:
root = tran

for i in target.split('/'):
if i == "..":
root = root.getparent()
Expand Down
58 changes: 29 additions & 29 deletions autocoder/fprime_backend/fprimeImplTemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ class FprimeImplTemplate:
# -------------------------------------------------------------------------------
# stateEnumFpp
# -------------------------------------------------------------------------------
def stateEnumFpp(self, smname: str, namespace: str, stateList: List[str]):
template = Template("""

enum $(smname)States {
#set $counter = 0
#for $state in $stateList
$(state) = $counter
#set $counter = $counter + 1
#end for
def stateEnumFpp(self, smname: str, namespace: str, stateList: List[str]):
template = Template("""
module $(namespace){
enum $(smname)_State{
#set $counter = 0
#for $state in $stateList
$(state) = $counter
#set $counter = $counter + 1
#end for
}
}

""")
template.smname = smname
template.namespace = namespace
template.stateList = stateList
template.smname = smname
template.namespace = namespace
template.stateList = stateList

return str(template)
return str(template)

# -------------------------------------------------------------------------------
# componentHdrFile
# -------------------------------------------------------------------------------
def componentHdrFile(self, smname: str, namespace: str, component: str, funcList: List[str]) -> str:
template = Template("""
def componentHdrFile(self, smname: str, namespace: str, component: str, funcList: List[str]) -> str:
template = Template("""


#ifndef _SIGNAL_GEN_HPP_
Expand Down Expand Up @@ -69,18 +69,18 @@ class $(component) : public $(smname)_Interface {

""")

template.funcList = funcList
template.smname = smname
template.namespace = namespace
template.component = component
template.funcList = funcList
template.smname = smname
template.namespace = namespace
template.component = component

return str(template)
return str(template)

# -------------------------------------------------------------------------------
# componentFile
# -------------------------------------------------------------------------------
def componentFile(self, smname: str, namespace: str, component: str, guardFunctions: List[ImplFunc], actionFunctions: List[ImplFunc]) -> str:
template = Template("""
def componentFile(self, smname: str, namespace: str, component: str, guardFunctions: List[ImplFunc], actionFunctions: List[ImplFunc]) -> str:
template = Template("""

\#include "$(component).hpp"
\#include "$(smname).hpp"
Expand Down Expand Up @@ -110,11 +110,11 @@ def componentFile(self, smname: str, namespace: str, component: str, guardFuncti

""")

template.guardFunctions = guardFunctions
template.actionFunctions = actionFunctions
template.smname = smname
template.namespace = namespace
template.component = component
template.guardFunctions = guardFunctions
template.actionFunctions = actionFunctions
template.smname = smname
template.namespace = namespace
template.component = component

return str(template)
return str(template)

15 changes: 9 additions & 6 deletions autocoder/fprime_backend/fprimecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class FprimeConfig(BaseModel):
#
# Print the state-machine header file
# -----------------------------------------------------------------------
def printSmHeader(smname: str,
qmRoot: ElementTreeType,
namespace: str):
def printSmHeader(
smname: str,
qmRoot: ElementTreeType,
namespace: str,
):

hFile = open(smname+".hpp", "w")
eventList = []
Expand All @@ -61,7 +63,7 @@ def printSmHeader(smname: str,

funcList = get_function_signatures(qmRoot, smname)

hFile.write(codeTemplate.fileHeader(smname, stateList, eventList, namespace, funcList ))
hFile.write(codeTemplate.fileHeader(smname, stateList, eventList, namespace, funcList))


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -401,7 +403,7 @@ def printEnumFpp(smname: str,

# Open the generated files

fileName = smname + ".fppi"
fileName = smname + "_State.fpp"
file = open(fileName, "w")
print(f'Generating {fileName}')

Expand Down Expand Up @@ -434,7 +436,8 @@ def printEnumFpp(smname: str,
# -----------------------------------------------------------------------
def generateCode(qmRoot: ElementTreeType,
noImpl: bool,
namespace: str):
namespace: str,
):

global codeTemplate
global unitTestTemplate
Expand Down
Loading