コード例 #1
0
ファイル: lib_generation.py プロジェクト: pnnferreira/contiki
	def parse_config(self, config_simgen):

		self.check_config(config_simgen)

		outputfolder = config_simgen.outputfolder
		template_path = config_simgen.template
		mkdir(outputfolder)
		cleardir(outputfolder)

		now = time.strftime("%Y%m%d%H%M%S")

		previous_count = 0
		if config_simgen.topology != 'preset':
			for mote_count in config_simgen.mote_count:
				sim = self.init_simulation(template_path, config_simgen)
				coords = generators.gen(config_simgen, mote_count)
				if(previous_count == len(coords)):
					continue
				previous_count = len(coords)
				simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(len(coords)) + '-' + now + '.csc'
				self.place_motes(sim, coords, simfilepath, config_simgen)

		else: #preset
			simlist = generators.load_preset(config_simgen.preset_data_path)
			for coords in simlist:
				sim = self.init_simulation(template_path, config_simgen)
				simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + os.path.splitext(os.path.basename(config_simgen.preset_data_path))[0] + '-' + str(len(coords)) + '-' + now + '.csc'
				self.place_motes(sim, coords, simfilepath, config_simgen)

		print("Done. Generated %d simfiles" % len(self.simfiles))
		return True
コード例 #2
0
ファイル: lib_generation.py プロジェクト: TiagoLourenco/6lbr
	def parse_config(self, config_simgen):
		if hasattr(config_simgen, 'outputfolder'):
			outputfolder = config_simgen.outputfolder
		else:
			outputfolder = '..' + os.path.sep + 'output'

		if hasattr(config_simgen, 'template'):
			template_path = config_simgen.template
		else:
			template_path = '..' + os.path.sep + 'templates' . os.path.sep + 'cooja-template-udgm.csc'

		mkdir(outputfolder)
		cleardir(outputfolder)

		now = time.strftime("%Y%m%d%H%M%S")

		previous_count = 0
		if config_simgen.topology != 'preset':
			for mote_count in config_simgen.mote_count:
				sim = Sim(template_path)

				for mote_type in config_simgen.mote_types:
					mote_type_obj = SimMoteType(    mote_type['shortname'],
									mote_type['fw_folder'],
									mote_type['maketarget'],
									mote_type['makeargs'],
									mote_type['serial'],
									mote_type['description'])
					self.mote_types.append(mote_type_obj)
					sim.insert_sky_motetype(mote_type_obj)

				sim.udgm_set_range(config_simgen.tx_range)
				sim.udgm_set_interference_range(config_simgen.tx_interference)

				coords = generators.gen(config_simgen, mote_count)
				if(previous_count == len(coords)):
					continue

				previous_count = len(coords)

				motenames = self.assign_mote_types(config_simgen.assignment, len(coords))
				simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(len(coords)) + '-' + now + '.csc'

				for index,coord in enumerate(coords):
					nodeid = index + 1
					mote = SimMote(self.mote_type_from_shortname(motenames[index]), nodeid)
					mote.set_coords(coord[0], coord[1], coord[2])
					self.motelist.append(mote)

				sim.add_motes(self.motelist)
				sim.set_timeout(999999999) #stop time in ms

				if hasattr(config_simgen, 'mobility'):
					sim.add_mobility(config_simgen.mobility)

				if hasattr(config_simgen, 'interactive_mobility'):
					self.add_mobility_data(config_simgen.interactive_mobility)

				sim.save_simfile(simfilepath)
				self.simfiles.append(simfilepath)
				print("****\n%s" % simfilepath)
				export_mote_list(simfilepath[:-4]+'.motes', self.motelist)

				self.motelist=[]
		else: #preset
			simlist = generators.load_preset(config_simgen.preset_data_path)
			for coords in simlist:
				sim = Sim(template_path)

				for mote_type in config_simgen.mote_types:
					mote_type_obj = SimMoteType(    mote_type['shortname'],
									mote_type['fw_folder'],
									mote_type['maketarget'],
									mote_type['makeargs'],
									mote_type['serial'],
									mote_type['description'])
					self.mote_types.append(mote_type_obj)
					sim.insert_sky_motetype(mote_type_obj)

				sim.udgm_set_range(config_simgen.tx_range)
				sim.udgm_set_interference_range(config_simgen.tx_interference)

				motenames = self.assign_mote_types(config_simgen.assignment, len(coords))
				"""
				if hasattr(config_simgen, 'label'):
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '_' + config_simgen.label + '-' + str(len(coords)) + '-' + now + '.csc'
				else:
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(len(coords)) + '-' + now + '.csc'
				"""
				simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + os.path.splitext(os.path.basename(config_simgen.preset_data_path))[0] + '-' + str(len(coords)) + '-' + now + '.csc'

				for index,coord in enumerate(coords):
					nodeid = index + 1
					mote = SimMote(self.mote_type_from_shortname(motenames[index]), nodeid)
					mote.set_coords(coord['x'], coord['y'], coord['z'])
					self.motelist.append(mote)

				sim.add_motes(self.motelist)
				sim.set_timeout(999999999) #stop time in ms

				if hasattr(config_simgen, 'mobility'):
					sim.add_mobility(config_simgen.mobility)

				if hasattr(config_simgen, 'interactive_mobility'):
					self.add_mobility_data(config_simgen.interactive_mobility)

				sim.save_simfile(simfilepath)
				self.simfiles.append(simfilepath)
				print("****\n%s" % simfilepath)
				export_mote_list(simfilepath[:-4]+'.motes', self.motelist)

				self.motelist=[]

		print("Done. Generated %d simfiles" % len(self.simfiles))
		return True
コード例 #3
0
ファイル: lib_generation.py プロジェクト: vickyviolin/6lbr
    def parse_config(self, config_simgen):
        if hasattr(config_simgen, 'outputfolder'):
            outputfolder = config_simgen.outputfolder
        else:
            outputfolder = '..' + os.path.sep + 'output'

        if hasattr(config_simgen, 'template'):
            template_path = config_simgen.template
        else:
            template_path = '..' + os.path.sep + 'templates'.os.path.sep + 'cooja-template-udgm.csc'

        mkdir(outputfolder)
        cleardir(outputfolder)

        now = time.strftime("%Y%m%d%H%M%S")

        previous_count = 0
        if config_simgen.topology != 'preset':
            for mote_count in config_simgen.mote_count:
                sim = Sim(template_path)

                for mote_type in config_simgen.mote_types:
                    mote_type_obj = SimMoteType(mote_type['shortname'],
                                                mote_type['fw_folder'],
                                                mote_type['maketarget'],
                                                mote_type['makeargs'],
                                                mote_type['serial'],
                                                mote_type['description'])
                    self.mote_types.append(mote_type_obj)
                    sim.insert_sky_motetype(mote_type_obj)

                sim.udgm_set_range(config_simgen.tx_range)
                sim.udgm_set_interference_range(config_simgen.tx_interference)

                coords = generators.gen(config_simgen, mote_count)
                if (previous_count == len(coords)):
                    continue

                previous_count = len(coords)

                motenames = self.assign_mote_types(config_simgen.assignment,
                                                   len(coords))
                simfilepath = os.path.normpath(
                    outputfolder
                ) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(
                    len(coords)) + '-' + now + '.csc'

                for index, coord in enumerate(coords):
                    nodeid = index + 1
                    mote = SimMote(
                        self.mote_type_from_shortname(motenames[index]),
                        nodeid)
                    mote.set_coords(coord[0], coord[1], coord[2])
                    self.motelist.append(mote)

                sim.add_motes(self.motelist)
                sim.set_timeout(999999999)  #stop time in ms

                if hasattr(config_simgen, 'mobility'):
                    sim.add_mobility(config_simgen.mobility)

                if hasattr(config_simgen, 'interactive_mobility'):
                    self.add_mobility_data(config_simgen.interactive_mobility)

                sim.save_simfile(simfilepath)
                self.simfiles.append(simfilepath)
                print("****\n%s" % simfilepath)
                export_mote_list(simfilepath[:-4] + '.motes', self.motelist)

                self.motelist = []
        else:  #preset
            simlist = generators.load_preset(config_simgen.preset_data_path)
            for coords in simlist:
                sim = Sim(template_path)

                for mote_type in config_simgen.mote_types:
                    mote_type_obj = SimMoteType(mote_type['shortname'],
                                                mote_type['fw_folder'],
                                                mote_type['maketarget'],
                                                mote_type['makeargs'],
                                                mote_type['serial'],
                                                mote_type['description'])
                    self.mote_types.append(mote_type_obj)
                    sim.insert_sky_motetype(mote_type_obj)

                sim.udgm_set_range(config_simgen.tx_range)
                sim.udgm_set_interference_range(config_simgen.tx_interference)

                motenames = self.assign_mote_types(config_simgen.assignment,
                                                   len(coords))
                """
				if hasattr(config_simgen, 'label'):
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '_' + config_simgen.label + '-' + str(len(coords)) + '-' + now + '.csc'
				else:
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(len(coords)) + '-' + now + '.csc'
				"""
                simfilepath = os.path.normpath(
                    outputfolder
                ) + os.path.sep + 'coojasim-' + os.path.splitext(
                    os.path.basename(
                        config_simgen.preset_data_path))[0] + '-' + str(
                            len(coords)) + '-' + now + '.csc'

                for index, coord in enumerate(coords):
                    nodeid = index + 1
                    mote = SimMote(
                        self.mote_type_from_shortname(motenames[index]),
                        nodeid)
                    mote.set_coords(coord['x'], coord['y'], coord['z'])
                    self.motelist.append(mote)

                sim.add_motes(self.motelist)
                sim.set_timeout(999999999)  #stop time in ms

                if hasattr(config_simgen, 'mobility'):
                    sim.add_mobility(config_simgen.mobility)

                if hasattr(config_simgen, 'interactive_mobility'):
                    self.add_mobility_data(config_simgen.interactive_mobility)

                sim.save_simfile(simfilepath)
                self.simfiles.append(simfilepath)
                print("****\n%s" % simfilepath)
                export_mote_list(simfilepath[:-4] + '.motes', self.motelist)

                self.motelist = []

        print("Done. Generated %d simfiles" % len(self.simfiles))
        return True
コード例 #4
0
ファイル: lib_generation.py プロジェクト: sdefauw/contiki
    def parse_config(self, config_simgen):
        if hasattr(config_simgen, "outputfolder"):
            outputfolder = config_simgen.outputfolder
        else:
            outputfolder = ".." + os.path.sep + "output"

        if hasattr(config_simgen, "template"):
            template_path = config_simgen.template
        else:
            template_path = ".." + os.path.sep + "templates".os.path.sep + "cooja-template-udgm.csc"

        mkdir(outputfolder)
        cleardir(outputfolder)

        now = time.strftime("%Y%m%d%H%M%S")

        previous_count = 0
        if config_simgen.topology != "preset":
            for mote_count in config_simgen.mote_count:
                sim = Sim(template_path)

                for mote_type in config_simgen.mote_types:
                    platform = "sky"
                    if "platform" in mote_type:
                        platform = mote_type["platform"]
                    mote_type_obj = SimMoteType(
                        mote_type["shortname"],
                        mote_type["fw_folder"],
                        mote_type["maketarget"],
                        mote_type["makeargs"],
                        mote_type["serial"],
                        mote_type["description"],
                        platform,
                    )
                    self.mote_types.append(mote_type_obj)
                    sim.insert_sky_motetype(mote_type_obj)

                sim.udgm_set_range(config_simgen.tx_range)
                sim.udgm_set_interference_range(config_simgen.tx_interference)

                coords = generators.gen(config_simgen, mote_count)
                if previous_count == len(coords):
                    continue

                previous_count = len(coords)

                motenames = self.assign_mote_types(config_simgen.assignment, len(coords))
                simfilepath = (
                    os.path.normpath(outputfolder)
                    + os.path.sep
                    + "coojasim-"
                    + config_simgen.topology
                    + "-"
                    + str(len(coords))
                    + "-"
                    + now
                    + ".csc"
                )

                for index, coord in enumerate(coords):
                    nodeid = index + 1
                    mote = SimMote(self.mote_type_from_shortname(motenames[index]), nodeid)
                    mote.set_coords(coord[0], coord[1], coord[2])
                    self.motelist.append(mote)

                sim.add_motes(self.motelist)
                if config_simgen.script_file:
                    sim.set_script(config_simgen.script_file)
                else:
                    sim.set_timeout(999999999)  # stop time in ms

                if hasattr(config_simgen, "mobility"):
                    sim.add_mobility(config_simgen.mobility)

                if hasattr(config_simgen, "interactive_mobility"):
                    self.add_mobility_data(config_simgen.interactive_mobility)

                sim.save_simfile(simfilepath)
                self.simfiles.append(simfilepath)
                print ("****\n%s" % simfilepath)
                export_mote_list(simfilepath[:-4] + ".motes", self.motelist)

                self.motelist = []
        else:  # preset
            simlist = generators.load_preset(config_simgen.preset_data_path)
            for coords in simlist:
                sim = Sim(template_path)

                for mote_type in config_simgen.mote_types:
                    platform = "sky"
                    if "platform" in mote_type:
                        platform = mote_type["platform"]
                    mote_type_obj = SimMoteType(
                        mote_type["shortname"],
                        mote_type["fw_folder"],
                        mote_type["maketarget"],
                        mote_type["makeargs"],
                        mote_type["serial"],
                        mote_type["description"],
                        platform,
                    )
                    self.mote_types.append(mote_type_obj)
                    sim.insert_sky_motetype(mote_type_obj)

                sim.udgm_set_range(config_simgen.tx_range)
                sim.udgm_set_interference_range(config_simgen.tx_interference)

                motenames = self.assign_mote_types(config_simgen.assignment, len(coords))
                """
				if hasattr(config_simgen, 'label'):
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '_' + config_simgen.label + '-' + str(len(coords)) + '-' + now + '.csc'
				else:
					simfilepath = os.path.normpath(outputfolder) + os.path.sep + 'coojasim-' + config_simgen.topology + '-' + str(len(coords)) + '-' + now + '.csc'
				"""
                simfilepath = (
                    os.path.normpath(outputfolder)
                    + os.path.sep
                    + "coojasim-"
                    + os.path.splitext(os.path.basename(config_simgen.preset_data_path))[0]
                    + "-"
                    + str(len(coords))
                    + "-"
                    + now
                    + ".csc"
                )

                for index, coord in enumerate(coords):
                    nodeid = index + 1
                    mote = SimMote(self.mote_type_from_shortname(motenames[index]), nodeid)
                    mote.set_coords(coord["x"], coord["y"], coord["z"])
                    self.motelist.append(mote)

                sim.add_motes(self.motelist)
                if config_simgen.script_file:
                    sim.set_script(config_simgen.script_file)
                else:
                    sim.set_timeout(999999999)  # stop time in ms

                if hasattr(config_simgen, "mobility"):
                    sim.add_mobility(config_simgen.mobility)

                if hasattr(config_simgen, "interactive_mobility"):
                    self.add_mobility_data(config_simgen.interactive_mobility)

                sim.save_simfile(simfilepath)
                self.simfiles.append(simfilepath)
                print ("****\n%s" % simfilepath)
                export_mote_list(simfilepath[:-4] + ".motes", self.motelist)

                self.motelist = []

        print ("Done. Generated %d simfiles" % len(self.simfiles))
        return True