Exemplo n.º 1
0
def domainInterface2dict(semObj):
    out = a3t.gen2dict(semObj)

    da = a3t.inTwo(semObj, "domainAdapter2domainInterface")
    if da == None:
        reportError("Domain interface must take a domain adapter on input.", semObj)
        ## Have to short-circuit to prevent weird errors from happening.
        return out
    else:
        attributes = a3t.getAttributes(da)
        out["parameters"] = attributes

    iCall = a3t.outOne(semObj, "domainInterface2Interface")
    i = a3t.outTwo(semObj, "domainInterface2Interface")
    if i == None:
        reportError("Domain interface must call a local interface.", semObj)
    else:
        name = a3t.evalAtom3Type(i.name)
        calls = a3t.gen2dict(iCall)
        iParameters = a3t.evalAtom3Type(i.parameters)
        calls["name"] = name
        out["calls"] = calls

        ## Constraints on interface call.
        testCall(calls["arguments"], out["parameters"], iParameters, iCall)

    deleteEmptyKeys(out)

    testValidName(out.get("name"), semObj)

    return out
Exemplo n.º 2
0
def testPrimitiveCall(out, primCall):
    primitive = a3t.outOne(primCall)
    theirParams = a3t.evalAtom3Type(primitive.parameters)
    myArgs = a3t.evalAtom3Type(primCall.arguments)
    myLocals = a3t.evalAtom3Type(a3t.inOne(primCall).parameters)
    testCall(myArgs, myLocals, theirParams, primCall)

    if out["delay"] < 0:
        reportError("Delay must be >0.", primCall)
Exemplo n.º 3
0
def json_serialize(atom3i):
    """
  Main entry point for ATom3.
  """
    a3t.setInstance(atom3i)
    root = dict()

    print
    print
    print "=============== COMPILING ====================="
    print
    print

    asg = getASG()
    graphName = a3t.evalAtom3Type(asg.name)
    graphAuthor = a3t.evalAtom3Type(asg.author)
    fp = None
    filename = None
    filepath = None

    if graphName == None or len(graphName) == 0:
        reportError("Please give your model a name.")
    else:
        try:
            filename = graphName + ".rdis.json"
            filepath = genPath(filename)
            fp = open(filepath, "w")
        except IOError as e:
            reportError(str(e))

    root["name"] = graphName
    root["author"] = graphAuthor

    addPrimitives(root)
    addInterfaces(root)
    addConnections(root)
    addDomainInterfaces(root)
    addDomainOutputs(root)
    addStateVars(root)

    if not hasErrors():
        json.dump(root, fp, indent=2)
        fp.close()
        tkMessageBox.showinfo("RDIS", "Model successfully serialized to file: " + filepath)
    else:
        errors = getErrors()
        print (str(len(errors)) + " error(s) in total.")
        i = 0
        for error in errors:
            i += 1
            print "  {:2}. ".format(i) + error[0]
        return errors[0]
Exemplo n.º 4
0
def primitive2dict(primitive):
    out = a3t.gen2dict(primitive)
    cnx = getPrimitiveConnection(primitive)
    deleteEmptyKeys(out)

    if cnx != None:
        out["connection"] = a3t.evalAtom3Type(cnx.name)

    testPrimitive(out, primitive)

    return out
Exemplo n.º 5
0
def getPrimitiveCalls(interface, parameters):
    semCalls = a3t.filterOutboundEdges(interface, "interface2primitive")
    output = list()

    for semCall in semCalls:
        out = a3t.gen2dict(semCall)
        primitive = a3t.outOne(semCall)
        print semCall
        out["name"] = a3t.evalAtom3Type(primitive.name)

        testPrimitiveCall(out, semCall)
        output.append(out)

    return output
Exemplo n.º 6
0
Arquivo: rosc.py Projeto: OEP/rdis
def getTwistCallback(rosTopic):
  """
  Gets twist callback textblob for given topic.
  """
  global gTwistCallbackTemplate
  tname = nameOf(rosTopic)
  di = getInterface(rosTopic)
  dit = getInterfaceAdapter(di)
  rdisStmts = getMappings( dit )

  return gTwistCallbackTemplate.format(
    name = tname,
    toRdis = rdisStmts,
    domainInterface = a3t.evalAtom3Type(di.name),
  )
Exemplo n.º 7
0
def connection2dict(semObj):
    out = a3t.gen2dict(semObj)

    k = a3t.outOne(semObj, "connectionKeepalive")
    s = a3t.outOne(semObj, "connectionStartup")
    t = a3t.outOne(semObj, "connectionTerminate")

    for thing in (("keepalive", k), ("startup", s), ("terminate", t)):
        if thing[1] != None:
            out[thing[0]] = a3t.gen2dict(thing[1])
            out[thing[0]]["name"] = a3t.evalAtom3Type(a3t.outOne(thing[1]).name)

            ## Get arguments for remote interface.
            myLocals = []
            myArgs = out[thing[0]]["arguments"]
            theirParams = a3t.evalAtom3Type(a3t.outOne(thing[1]).parameters)

            testCall(myArgs, myLocals, theirParams, thing[1])

            if thing[0] == "keepalive":
                testKeepalive(out["keepalive"], k)
                if out["keepalive"]["interval"] <= 0:
                    reportError("Keepalive interval should be >0.", k)

    addThreading(out, semObj)

    deleteEmptyKeys(out)

    if isinstance(semObj, SerialConnection):
        testSerial(out, semObj)
    else:
        reportError("Unbound connection type: {}".format(repr(semObj.__class__)), semObj)

    testValidName(out.get("name"), semObj)

    return out
Exemplo n.º 8
0
def interface2dict(interface):
    """
  Converts interface semantic object into a Python dict.
  """
    out = a3t.gen2dict(interface)
    out["primitiveCalls"] = getPrimitiveCalls(interface, out["parameters"])

    do = a3t.outTwo(interface, "interface2domainOutput")

    if do != None:
        outputName = a3t.evalAtom3Type(do.name)
        out["triggers"] = outputName

    deleteEmptyKeys(out)

    testValidName(out.get("name"), interface)

    return out
Exemplo n.º 9
0
Arquivo: rosc.py Projeto: OEP/rdis
def compileNode(rosNode):
  """
  Compiles a particular ROS node.
  """
  global gNodeTemplate
  print
  print
  print "==================== COMPILING ========================="
  print
  print

  nname = a3t.evalAtom3Type(rosNode.name)
  ncallbacks = getCallbackSection(rosNode)
  ninitialization = getInitializationSection(rosNode)
  filepath = genPath("{}.gen.py".format(nname))

  if not hasErrors():
    try:
      fp = open(filepath, "w")
      fp.write(
        gNodeTemplate.format(
          nodeName=nname,
          callbackSection=ncallbacks,
          initializationSection=ninitialization
        )
      )
      fp.close()
      print "Written: {}".format(filepath)
      return filepath
    except IOError as e:
      print "Error writing to '{}': {}".format(
        filepath,
        str(e)
      )
      reportError(str(e), None)
  return False
Exemplo n.º 10
0
Arquivo: rosc.py Projeto: OEP/rdis
def nameOf(semObj):
  """
  Gets attribute "name" from semantic object.
  """
  return a3t.evalAtom3Type(semObj.name)
Exemplo n.º 11
0
def getStateVarNames():
    """
  Returns a list of StateVar names.
  """
    nameOf = lambda x: a3t.evalAtom3Type(x.name)
    return list(map(nameOf, getStateVars()))