Sun Microsystems V2.0 manual Persistent properties

Page 26

Each physical device is controlled by a single instance of the respective class, accessed through the interfaces listed above. The single instance of the Sun SPOT class creates and manages access to the device driver singletons. The singletons are created only as required.

For example, to get access to the on-board green LED, do:

Iled theLed = Spot.getInstance().getGreenLed();

To turn the LED on and off:

theLed.setOn();

theLed.setOff();

Persistent properties

The sections Manifest and resources and Library manifest properties explain how to define application-specific and library-specific properties. Sometimes it is useful to define persistent properties for an individual SPOT device, and that is the topic of this section. Such properties are always available on the given SPOT regardless of which application is being run.

An 8k byte area of flash is reserved for persistent System properties that can be read and written from SPOT applications and by using ant commands on the host. All properties have a String key and a String value.

We distinguish between user-definedproperties, set either using ant set-system-propertyor from within a SPOT application, from other System properties, such as those defined by Squawk.

Accessing properties from SPOT applications

To obtain the value of a System property do:

System.getProperty(<propName>);

This call returns null if the property has not been defined. All system properties, including user- defined properties, can be accessed this way.

To set the value of a user-defined property do:

Spot.getInstance().setPersistentProperty(<propName>, <propValue>);

A property can be erased by setting its value to null. Setting or erasing a persistent property takes about 250ms. If you wish to set several properties at once, you can optimise performance like this:

Properties propsToWrite = new Properties(); propsToWrite.setProperty("key1", "value1");

propsToWrite.setProperty("key99", "value99"); Spot.getInstance().setPersistentProperties(propsToWrite);

You can also get the value of a user-defined system property by using:

Spot.getInstance().getPersistentProperty(<propName>);

This call is much slower to execute than System.getProperty, because it re-reads the flash memory. Therefore you should normally use System.getProperty to access user-defined properties. However, user-defined properties are loaded from the flash when an isolate starts which means that you will need to use the slower method of access in two situations:

26

Image 26
Contents Page Page Contents Http protocol support Introduction Building and deploying Sun Spot applications Deploying and running a sample applicationBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Deploying a pre-existing jar Incorporating utility classes into your applicationOther user properties Manifest and resourcesExcluding files from the compilation Overview Using the BasestationBuilt-in properties Set up Introduction Base Station configurationRemote operation Connect a Sun Spot base station Take suitable actions during over-the-air downloads Using short names for SPOTsManaging keys and sharing Sun SPOTs BackgroundChanging the owner of a Sun Spot Sharing Sun SPOTsGenerating a new key-pair What is protected?Deploying and running a host application LimitationsIncorporating pre-existing jars into your host application Configuring network featuresYour own host application Mesh routingLogging Hardware configurations and USB powerTrace route Page Thread priorities Overview of an applicationThreads Device Interface Sun Spot device librariesSun Spot device library Persistent properties Accessing flash memory Overriding the Ieee addressUsart Radio communication library Program Radiogram protocol Client end Server endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Shallow Sleep Conserving power using deep sleep modeMonitoring radio activity Activating deep sleep mode Deep SleepDeep sleep behaviour of the standard drivers USB inhibits deep sleepPreconditions for deep sleeping Device Condition to permit deep sleepWriting a device driver Configuring the http protocol Http protocol supportConfiguring projects in an IDE Socket Proxy GUI modeDebugging Classpath configurationJavadoc/source configuration Ant selectapplication Configuring NetBeans as a debug client Configuring Eclipse as a debug clientUsing library suites Advanced topicsWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Property name Meaning ReferencePersistent system properties Memory usage Contents of the arm directoryContents of the lib directory Start address Space UseContents of the bin directory preverify.exe Contents of the upgrade directory Contents of the tests directory