Recent Changes - Search:

Create Your Own Scripts to Conduct Advanced Experiments

Creating a more Complex scenario

In order to create a more complex experimental scenario you can create a specific experimental script for your own

Script Files are available in the "scripts" directory.

Reset Devices

In order to reset a number of Devices you need to create a List of the Devices to reset and make a request to the WSNAsyncWrapper for the Reset.

Creating the List of Nodes by providing a comma separated list (e.g., urn:node:0x1,urn:node:0x2):

	List nodeURNs;
	nodeURNs = Lists.newArrayList(nodeUrnsToReset.split(","));

Make a request to the WSNAsyncWrapper with arguments the List of Devices, the Timeout interval and the Unit of measurement for the Timeout:

	Future resetFuture = wsn.resetNodes(nodeURNs, 10, TimeUnit.SECONDS);

Finally you can get the result of the execution using the get() method on the Future object returned by the previous call:

	try {
	  JobResult resetJobResult = resetFuture.get();
	  resetJobResult.printResults(System.out, csv);
	  System.exit(resetJobResult.getSuccessPercent() < 100 ? 1 : 0);
	} catch (ExecutionException e) {
	  if (e.getCause() instanceof TimeoutException) {
	    log.info("Call timed out. Exiting...");
	  }
	}

Communicate with the Devices

To send a message you need to provide the payload to send in a comma separated list. The bytes of the the payload can be provided in decimal, hex or binary format using 0xor 0b prefixes.

	// Supported Prefixes are "0x" and "0b", otherwise Base_10 (DEZ) is assumed	
	String[] splitMessage = messageToSend.split(",");
	byte[] messageToSendBytes = new byte[splitMessage.length];
	String messageForOutputInLog = "";
	for (int i=0;i<splitMessage.length;i++) {
	  int type = 10;
	  if (splitMessage[i].startsWith("0x")) {
	    type = 16;
	    splitMessage[i]=splitMessage[i].replace("0x","");
	  } else if (splitMessage[i].startsWith("0b")) {
	    type = 2;
	    splitMessage[i]=splitMessage[i].replace("0b","");
	  }
	  BigInteger b = new BigInteger(splitMessage[i], type);
	  messageToSendBytes[i] = (byte) b.intValue() ;
	  messageForOutputInLog = messageForOutputInLog + b.intValue() +" ";
	}

Then we need to construct a Message and add the payload created above to the message in order to forward it to the devices. The message also needs to contain a timestamp for the sent Time and a source device id.

	// Constructing the Message
	Message binaryMessage = new Message();
	binaryMessage.setBinaryData(messageToSendBytes);

	GregorianCalendar c = new GregorianCalendar();
	c.setTimeInMillis(System.currentTimeMillis());

	binaryMessage.setTimestamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(c));
	binaryMessage.setSourceNodeId("urn:wisebed:uzl1:0xFFFF");

The created Binary message is the forwared to the WSNAsyncWrapper, together with the destination devices, and the timeout threshold for the Request.

	Future sendFuture = wsn.send(nodeURNs, binaryMessage, 10, TimeUnit.SECONDS);

Again the Result of the sent request can be received using the get() method of the Future object returned by the call to the ''WSNAsyncWrapper

	try {
          JobResult sendJobResult = sendFuture.get();
	  sendJobResult.printResults(System.out, csv);
	  System.exit(sendJobResult.getSuccessPercent() < 100 ? 1 : 0);
	} catch (ExecutionException e) {
	  if (e.getCause() instanceof TimeoutException) {
	    log.info("Call timed out. Exiting...");
	  }
	}

Flash Devices

In order to flash selected devices with a new binary image we need to do to he following: Create a list of program Indices and a list of binaries to flash to the devices.

	List programIndices = new ArrayList();
	List programs = new ArrayList();

Initialize the Program Indecies with 0

        for (int i=0; i<nodeURNs.size(); i++) {
          programIndices.add(0);
        }

Load the binary to the program List using the helper provided by the client:

	programs.add(helper.readProgram(
          imageToFlashPath,  //path to the image
          "",
          "",
          "iSense",          //target devices
          "1.0"              //version
        ));

Send the flash request to the WSNAsyncWrapper and retrieve a Future object that contains the status of the request:

	Future flashFuture = wsn.flashPrograms(nodeURNs, programIndices, programs, 3, TimeUnit.MINUTES);

Wait for the Operation to finish:

	try {
	  JobResult flashJobResult = flashFuture.get();
	  flashJobResult.printResults(System.out, csv);
	  System.exit(flashJobResult.getSuccessPercent() < 100 ? 1 : 0);
	} catch (ExecutionException e) {
	  if (e.getCause() instanceof TimeoutException) {
	    log.info("Call timed out. Exiting...");
	  }
	}
Edit - History - Print - Recent Changes - Search
Page last modified on December 05, 2012, at 07:10 PM