This is the course project for UofM COMP4720, Fall 2011
- Kyle Kaufmann
- Brian Turchyn
- Netbeans
- SunSpot SDK
- Load project into NetBeans
- Connect SunSpot
- Right-click on project and select Build “Project + Deploy To SunSPOT”
The software is designed to collect a value between 0 and 8 via the button controls (which should represent the attention level of the user). Every 5 seconds, the SPOT broadcasts its current value on port 42.
Data is collected from other broadcasted SPOTs. This value is stored in the AttentionHistory class, which houses a Vector of AttentionLevel objects, along with a number of utility methods related to that data (including average calculation, checking if the value is already there, etc).
Data is sent as a series of three writes to a datagram, sending off the device ID, attention level, and timestamp (in order). This information is re-sent every 5 seconds, acting as both a value update and a keep-alive packet.
When data is received, it is assembled into an AttentionLevel object (upon confirming that the data is valid), which is simply a Java class that acts as a data object, neatly grouping the three pieces of information we need to store: device ID, attention level, and the transmission date from the perspective of the original sender. The data is checked to see if it has already been received before by looking in the AttentionHistory instance. If it has been received, the data is ignored. If it has not, the data is inserted into AttentionHistory if no existing value for that SPOT ID has been received, or if the SPOT already has a value in the history, that value has been updated. Whenever the AttentionHistory is updated, a new average is calculated and stored.
The AttentionHistory class is a wrapper around a Vector object, used for storing a history of previously sent attention levels. Included in the class is a thread that wakes up on a regular basis, and cleans the Vector of any objects that are older than 20 seconds. Based on what was agreed upon, we working under the assumption that the user is no longer transmitting after 20 seconds, and they should no longer be factored into the average. The average is calculated simply by summing up the values of all the stored values and dividing by the number of entries in the AttentionHistory instance. Since no device can have more than one entry, we can safely use this number. The result is cached elsewhere for the LED updates, and the value is updated when a change to the history occurs (insert, update, delete)
The LEDs flash approximately every 4.5 seconds for 0.5 seconds to show the current average of all the collected values. The display will then go back to the value of the SPOT itself.
When shook across the Y axis (top-to-bottom), the SPOT will begin the ‘stress test’ action, which will saturate the network with 100 packets with random IDs and the value that is currently on the SPOT. Two white flashes denote the start of this, and another two denote the end of this (not including the hard-coded 5 second cooldown to avoid abuse). This was implemented to properly test out how the software would handle extremely large numbers of clients connected to the network without actually having access to 100+ SPOTs.