Package se.sics.cooja

Examples of se.sics.cooja.MoteMemory


      return createErrorMessage("No mote ID specified");
    int moteNr = Integer.parseInt(mote);
    if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
      return createErrorMessage("Bad mote ID specified: " + moteNr);
    }
    MoteMemory memory = simulation.getMote(moteNr).getMemory();
   
    // Read integer variable
    if (type.equals("int")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      int val = ((AddressMemory) memory).getIntValueOf(variable);
      return XML_OK_START + val + XML_OK_END;
    } else if (type.equals("variable")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      byte[] val = ((AddressMemory) memory).getByteArray(variable, sizeParsed);
      String ret = "";
      for (byte b: val)
        ret += (int) (0xff&b) + " ";
      ret = ret.trim();
      return XML_OK_START + ret + XML_OK_END;
    } else if (type.equals("address")) {
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }

      byte[] val = memory.getMemorySegment(addressParsed, sizeParsed);
      String ret = "";
      for (byte b: val)
        ret += (int) (0xff&b) + " ";
      ret = ret.trim();
      return XML_OK_START + ret + XML_OK_END;
View Full Code Here


      return createErrorMessage("No mote ID specified");
    int moteNr = Integer.parseInt(mote);
    if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
      return createErrorMessage("Bad mote ID specified: " + moteNr);
    }
    MoteMemory memory = simulation.getMote(moteNr).getMemory();
   
    // Write integer variable
    if (type.equals("int")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      if (value.contains(" "))
        return createErrorMessage("Integer value must not contain spaces: " + value);

      int val;
      try {
        val = Integer.parseInt(value);
      } catch (NumberFormatException e) {
        return createErrorMessage("Bad integer value specified: " + e);
      }
     
      ((AddressMemory) memory).setIntValueOf(variable, val);
      return XML_OK;
    } else if (type.equals("variable")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      String[] bytesParsed = value.split(" ");
      if (bytesParsed.length != sizeParsed)
        return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);

      byte[] val = new byte[bytesParsed.length];
      for (int i=0; i < sizeParsed; i++) {
        val[i] = Byte.parseByte(bytesParsed[i]);
      }

      ((AddressMemory) memory).setByteArray(variable, val);
      return XML_OK;
    } else if (type.equals("address")) {
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      String[] bytesParsed = value.split(" ");
      if (bytesParsed.length != sizeParsed)
        return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);

      byte[] val = new byte[bytesParsed.length];
      for (int i=0; i < sizeParsed; i++) {
        val[i] = Byte.parseByte(bytesParsed[i]);
      }

      memory.setMemorySegment(addressParsed, val);
      return XML_OK;
    }

    return createErrorMessage("Bad write memory type specified: " + type);
  }
View Full Code Here

      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new IntegerWatchpoint(moteObject, variable);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Variable watchpoint
    if (type.equals(XML_WATCHPOINT_VARIABLE)) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new VariableWatchpoint(moteObject, variable, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }


    // Memory area watchpoint
    if (type.equals(XML_WATCHPOINT_ADDRESS)) {
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      Eventpoint newEventpoint = new Watchpoint(moteObject, addressParsed, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }
View Full Code Here

      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
       
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variable address (not address memory)");

      if (!((AddressMemory) memory).variableExists(variable)) {
View Full Code Here

      return createErrorMessage("No mote ID specified");
    int moteNr = Integer.parseInt(mote);
    if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
      return createErrorMessage("Bad mote ID specified: " + moteNr);
    }
    MoteMemory memory = simulation.getMote(moteNr).getMemory();
   
    // Read integer variable
    if (type.equals("int")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      int val = ((AddressMemory) memory).getIntValueOf(variable);
      return XML_OK_START + val + XML_OK_END;
    } else if (type.equals("variable")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      byte[] val = ((AddressMemory) memory).getByteArray(variable, sizeParsed);
      String ret = "";
      for (byte b: val)
        ret += (int) (0xff&b) + " ";
      ret = ret.trim();
      return XML_OK_START + ret + XML_OK_END;
    } else if (type.equals("address")) {
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }

      byte[] val = memory.getMemorySegment(addressParsed, sizeParsed);
      String ret = "";
      for (byte b: val)
        ret += (int) (0xff&b) + " ";
      ret = ret.trim();
      return XML_OK_START + ret + XML_OK_END;
View Full Code Here

      return createErrorMessage("No mote ID specified");
    int moteNr = Integer.parseInt(mote);
    if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
      return createErrorMessage("Bad mote ID specified: " + moteNr);
    }
    MoteMemory memory = simulation.getMote(moteNr).getMemory();
   
    // Write integer variable
    if (type.equals("int")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      if (value.contains(" "))
        return createErrorMessage("Integer value must not contain spaces: " + value);

      int val;
      try {
        val = Integer.parseInt(value);
      } catch (NumberFormatException e) {
        return createErrorMessage("Bad integer value specified: " + e);
      }
     
      ((AddressMemory) memory).setIntValueOf(variable, val);
      return XML_OK;
    } else if (type.equals("variable")) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      String[] bytesParsed = value.split(" ");
      if (bytesParsed.length != sizeParsed)
        return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);

      byte[] val = new byte[bytesParsed.length];
      for (int i=0; i < sizeParsed; i++) {
        val[i] = Byte.parseByte(bytesParsed[i]);
      }

      ((AddressMemory) memory).setByteArray(variable, val);
      return XML_OK;
    } else if (type.equals("address")) {
     
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }

      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }

      if (value == null)
        return createErrorMessage("No value specified");
      String[] bytesParsed = value.split(" ");
      if (bytesParsed.length != sizeParsed)
        return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);

      byte[] val = new byte[bytesParsed.length];
      for (int i=0; i < sizeParsed; i++) {
        val[i] = Byte.parseByte(bytesParsed[i]);
      }

      memory.setMemorySegment(addressParsed, val);
      return XML_OK;
    }

    return createErrorMessage("Bad write memory type specified: " + type);
  }
View Full Code Here

      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new IntegerWatchpoint(moteObject, variable);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }

    // Variable watchpoint
    if (type.equals(XML_WATCHPOINT_VARIABLE)) {
      if (variable == null)
        return createErrorMessage("No variable name specified");
      if (variable.contains(" "))
        return createErrorMessage("Variable name must not contain spaces: " + variable);
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);

      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't write mote memory variables (not address memory)");
     
      if (!((AddressMemory) memory).variableExists(variable)) {
        return createErrorMessage("Variable does not exist: " + variable);
      }

      Eventpoint newEventpoint = new VariableWatchpoint(moteObject, variable, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }


    // Memory area watchpoint
    if (type.equals(XML_WATCHPOINT_ADDRESS)) {
      if (mote == null)
        return createErrorMessage("No mote ID specified");
      if (size == null)
        return createErrorMessage("No size specified");
      int sizeParsed = Integer.parseInt(size);
      if (sizeParsed < 0) {
        return createErrorMessage("Bad size specified: " + sizeParsed);
      }
      int addressParsed = Integer.parseInt(address);
      if (addressParsed < 0) {
        return createErrorMessage("Bad start address specified: " + addressParsed);
      }
      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
     
      Eventpoint newEventpoint = new Watchpoint(moteObject, addressParsed, sizeParsed);
      myEvaluator.addEventpoint(newEventpoint);
      return createOkMessage(newEventpoint, simulation.getSimulationTime());
    }
View Full Code Here

      int moteNr = Integer.parseInt(mote);
      if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
        return createErrorMessage("Bad mote ID specified: " + moteNr);
      }
      Mote moteObject = simulation.getMote(moteNr);
      MoteMemory memory = simulation.getMote(moteNr).getMemory();
       
      if (!(memory instanceof AddressMemory))
        return createErrorMessage("Can't read mote memory variable address (not address memory)");

      if (!((AddressMemory) memory).variableExists(variable)) {
View Full Code Here

TOP

Related Classes of se.sics.cooja.MoteMemory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.