/*---------------------------------------------------------------------------------------------------------------- * CupCarbon: A Smart City & IoT Wireless Sensor Network Simulator * www.cupcarbon.com * ---------------------------------------------------------------------------------------------------------------- * Copyright (C) 2013-2017 CupCarbon * ---------------------------------------------------------------------------------------------------------------- * 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. * * 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/>. *---------------------------------------------------------------------------------------------------------------- * CupCarbon U-One is part of the research project PERSEPTEUR supported by the * French Agence Nationale de la Recherche ANR * under the reference ANR-14-CE24-0017-01. * ---------------------------------------------------------------------------------------------------------------- **/ /** Definition: * This class allows generating sensors between two markers on the map layer * * Command examples: * generate random 50 * -> It generates the defined number of sensors randomly between the two markers on the map layer * ---------------------------------------------------------------------------------------------------------------- */ package cupcarbon_script; /** * @author Ahcene Bounceur * @author Molham Darwish * @version 1.0 */ import device.DeviceList; public class CupCommand_GENERATE extends CupCommand { protected String value; protected String option = ""; //--------------------------------------------------------------------------------------------------------------------- // Constructor // --------------------------------------------------------------------------------------------------------------------- public CupCommand_GENERATE(CupScript script, String option, String value) { this.script = script ; this.value = value; this.option = option; } //--------------------------------------------------------------------------------------------------------------------- // execute generate // It generates the defined number of sensors randomly between the two markers on the map layer // depending on the defined number to be generated // --------------------------------------------------------------------------------------------------------------------- @Override public String execute() { currentExecution = false; String rep = ""; String sOption = script.getVariableValue(option); String sValue = script.getVariableValue(value); if (isExecuted) { switch(sOption) { case ("random") : DeviceList.addRandomSensors(Integer.parseInt(sValue)); rep = " 000 The " + sValue + " Sensors have been generated Randomly"; currentExecution = true; break; default : rep = "001 [ERROR]"; currentExecution = false; } } else { rep = "ERROR IN EXECUTING THE PREVIOUS STEP, THE SCRIPT WILL NOT CONTINUE TO EXECUTE"; script.setBreaked(true); } System.out.println(rep); CupScript.slog.println(rep); isExecuted = currentExecution; return rep; } @Override public String toString() { return "GENERATE"; } }