def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_PLANNER_REPORT_VACUUM_ORDERS)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_MOVE_ORDER_COMMANDER_PLANNER)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_UPDATE_REQUEST_PLANNER_SENSOR)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_VACUUM_NEW_POSITION_PLANNER)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_UPDATE_WORLD_PLANNER)
Exemple #6
0
    def determineXMLInformation(self,passedXML) :
        self.parseXMLString(passedXML)
        [name,type] = self.getObjectClassNameAndType()
        incomingXML = None
	#print("Name: {0} Type: {1}".format(name,type))


        if( (name=="Planner") and (type == "Vacuum Orders")) :
            # This is a message to be sent to a planner that contains
            # the orders to a vacuum from the commander. Define the
            # vacuum and its position.
            
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a planner from a commander with the orders for a vacuum")

            incomingXML.specifyInformationType(XMLParser.MESSAGE_PLANNER_REPORT_VACUUM_ORDERS)



        elif( (name=="Planner") and (type == "Vacuum Recommendation")) :
            # This is a message from a commander sent to a planner to
            # let the planner know the recommendation made for the
            # movement of a vacuum. Define the vacuum and its
            # position.
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a commander to a planner with the suggested orders for a vacuum")

            incomingXML.specifyInformationType(XMLParser.MESSAGE_RECOMMEND_ORDER_COMMANDER_PLANNER)



        elif( (name=="Commander") and (type=="Vacuum Recommendation")) :
            # This is a message from Planner to send the
            # recommendation of a move to the commander. Define the
            # vacuum and its position.
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a planner to a commander with the suggested orders for a vacuum")


            incomingXML.specifyInformationType(XMLParser.MESSAGE_RECOMMEND_ORDER_PLANNER_COMMANDER)


        elif( (name=="World") and (type=="Clean Grid")) :
            # This is the message from a Vacuum to send its location
            # to the world. Define the vacuum and its position.
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a vacuum to the world to indicate a spot is cleaned.")

            incomingXML.specifyInformationType(XMLParser.MESSAGE_VACUUM_WORLD_CLEAN_GRID)




        elif( (name=="Vacuum") and (type=="Move Order")) :
            # This is a message send from a Commander to a Vacuum to
            # give the vacuum the order to move. Define the vacuum and
            # its future position.
            
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a planner to a commander with the suggested orders for a vacuum")

            incomingXML.specifyInformationType(XMLParser.MESSAGE_MOVE_ORDER_COMMANDER_VACUUM)




        elif( (name=="Planner") and (type=="Move Order")) :
            # This is a message from the commander to the planner to
            # let the planner know what order was sent. Define the
            # vacuum and its position.
            
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])
                    

                if(self.DEBUG) :
                    print("This data represents information from a planner to a commander with the suggested orders for a vacuum")

            incomingXML.specifyInformationType(XMLParser.MESSAGE_MOVE_ORDER_COMMANDER_PLANNER)



        elif( (name=="Commander") and (type=="Get Report")) :
            # This is a message from the Vacuum to the commander to
            # let the commander know the position and status of a
            # vacuum. Need to define the position and status.
            incomingXML = XMLMessageGetReportVacuumCommander()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")

                status = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","status")

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])

                if(status) :
                    incomingXML.setStatus(status[3][1][2])

                pos = incomingXML.getPos()
                #print("id: {0} pos: {1},{2} Status: {3}".format(
                #    incomingXML.getVacuumID(),pos[0],pos[1],incomingXML.getStatus()))
                                

                if(self.DEBUG) :
                    print("This data represents information from a planner to a commander with the suggested orders for a vacuum")



        elif( (name=="Sensor") and (type=="World Status")) :
            # This is a message from the World to the Sensor to let it
            # know the status of the world.
            incomingXML = XMLMessageWorldStatus()



        elif( (name=="Sensor") and (type=="World Wetness")) :
            # This is a message from the world to the Sensor to let it
            # know the wetness levels of the world.
            incomingXML = XMLMessageWorldWetness()



        elif( (name=="Planner") and (type=="Update")) :
            # This is a message from the Sensor to the planner to let
            # it know the status of the world.
            incomingXML = XMLMessageUpdateWorldPlanner()



        elif( (name=="Sensor") and (type=="Send Planner Update")) :
            # This is a message from the planner to the sensor to
            # request an update.
            incomingXML = XMLMessageUpdatePlannerSensor()



        elif( (name=="Planner") and (type=="Sensor Status")) :
            # This is a message from the Sensor to the Planner to
            # provide a status of the world as the Sensor currently
            # understands it.
            incomingXML = XMLMessageSensorStatus()



        elif( (name=="Planner") and (type=="Sensor Wetness")) :
            # This is message from the Sensor to the Planner to let
            # the Planner know what the Sensor thinks is the current
            # wetness levels of the world.
            incomingXML = XMLMessageSensorWetness()



        elif( (name=="Planner") and (type=="New Vacuum Location")) :
            # This is a message from the Vacuum to the planner to give
            # the planner a report of its activities. Define the
            # vacuum and its position.
            
            incomingXML = XMLMessageVacuumIDPosBase()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                xPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","xPos")
                yPos = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","yPos")
                #print("{0}\n{1}\n{2}".format(vacuum,xPos,yPos))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(xPos) :
                    incomingXML.setXPos(xPos[3][1][2])

                if(yPos) :
                    incomingXML.setYPos(yPos[3][1][2])

            incomingXML.specifyInformationType(XMLParser.MESSAGE_VACUUM_NEW_POSITION_PLANNER)



        elif( (name=="Vacuum") and (type=="World Time")) :
            # This is a message from the world to the vacuum. It lets
            # the vacuum know what the world time is. Set the vacuum's
            # ID and the time.
            
            incomingXML = XMLMessageWorldVacuumCurrentTime()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                time = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","time")
                #print("{0}\n{1}".format(vacuum,time))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(time) :
                    incomingXML.setTime(time[3][1][2])


        elif( (name=="World") and (type=="Add Expenditure")) :
            # This is a message from a vacuum to the World. It sends
            # an expenditure required for the vacuum.
            incomingXML = XMLMessageVacuumAddExpenditureWorld()
            dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
                vacuum = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","vacuumID")
                expenditure = self.walkObjectChildrenByNameContents(
                    dimensions[3],"dimension","name","expenditure")
                #print("{0}\n{1}".format(vacuum,expenditure))

                if(vacuum) :
                    incomingXML.setVacuumID(vacuum[3][1][2])

                if(expenditure) :
                    incomingXML.setExpenditure(expenditure[3][1][2])


        elif( (name=="External") and (type=="parameter")) :
	    # This is an external message. It has information about a
	    # set of parameters.
	    incomingXML = XMLMessageExternalParameter()

	    # Get all of the information associated with the
	    # dimensions that were passed.
	    dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
		# For each dimension go through and decide what type of dimension it is.
		for dimension in dimensions[3]:
		    name  = self.getChildWithName([dimension],"name")    # Get the name leaf on the tree
		    value = self.getChildWithName([dimension],"value")   # Get the value leaf on the tree

		    #print("Value {0} - {1}".format(name[2],value[2]))
		    for key, val in XMLMessageExternalParameter.ParameterTitles.iteritems():
			# Go through each member of the possible parameters and check for a match
			#print("check {0} - {1}".format(key,val))
			if(val == name[2]) :
			    # This is the same type. Set the parameter
			    incomingXML.setParameterValue(key,value[2])
			    break


        elif( (name=="External") and (type=="command")) :
	    # This is an external message. It has information about an
	    # action to take.
	    incomingXML = XMLMessageExternalCommand()

	    # Get all of the information associated with the
	    # dimensions that were passed.
	    dimensions = self.getChildWithName(self.getBuffer(),"dimensions")

            if(dimensions) :
		# For each dimension go through and decide what type of dimension it is.
		for dimension in dimensions[3]:
		    name  = self.getChildWithName([dimension],"name")    # Get the name leaf on the tree


		    #print("Value {0} - {1}".format(name[2],value[2]))
		    for key, val in XMLMessageExternalCommand.ParameterTitles.iteritems():
			# Go through each member of the possible parameters and check for a match
			#print("check {0} - {1}".format(key,name[2]))
			if(val == name[2]) :
			    # This is the same type. Set the parameter
			    #print("Setting: {0}".format(key))
			    incomingXML.setParameterValue(key)
			    break



        if(incomingXML) :
            # If an incoming XML object was created then pass along
            # the array object that was set. If no array object was
            # set before calling this method then this will not do
            # anything. It is caught in the set buffer method.
            incomingXML.setBuffer(self.getBuffer())

        return(incomingXML)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_VACUUM_WORLD_CLEAN_GRID)
    def __init__(self,expenditure=0.0) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_VACUUM_WORLD_ADD_EXPENDITURE)
        self.setExpenditure(expenditure)
    def __init__(self) :
        XMLMessageVacuumIDPosBase.__init__(self)
	self.setMyInformationType(self.MESSAGE_GET_REPORT_VACUUM_COMMANDER)
        self.status = None
 def createDimensions(self):
     # Creates the dimensions node in the xml tree. It adds the
     # objectClass node as a child of the dimensions node. Finally
     # a "name" node is added as a child of the dimensions node.
     XMLMessageVacuumIDPosBase.createDimensions(self)
     self.setStatusNode()