// IoT driver packages
import iotcode.interfaces.*;
-//import iotcode.annotation.*;
+import iotcode.annotation.*;
// Standard Java packages
import java.rmi.server.UnicastRemoteObject;
// Checker annotations
-import iotchecker.qual.*;
+//import iotchecker.qual.*;
/** Class SpeakerController for the smart home application benchmark
* <p>
/**
* IoT Sets of Devices
*/
- @config private IoTSet < @NonLocalRemote GPSGateway > gpsSet;
- @config private IoTSet < @NonLocalRemote Speaker > speakerSet;
+ @config private IoTSet < GPSGatewaySmart > gpsSet;
+ @config private IoTSet < SpeakerSmart > speakerSet;
/**
* IoT Sets of Things that are not devices such as rooms
*/
- @config private IoTSet < @NonLocalRemote Room > audioRooms;
+ @config private IoTSet < RoomSmart > audioRooms;
/**
* IoT Relations
*/
- @config private IoTRelation < @NonLocalRemote Room, @NonLocalRemote Speaker > roomSpeakerRel;
+ @config private IoTRelation < RoomSmart, SpeakerSmart > roomSpeakerRel;
/**
* The state that the room main lights are supposed to be in
*/
- Map < @NonLocalRemote Room, Boolean > roomSpeakersOnOffStatus = new HashMap < @NonLocalRemote Room, Boolean > ();
+ Map < RoomSmart, Boolean > roomSpeakersOnOffStatus = new HashMap < RoomSmart, Boolean > ();
// used to notify if new data is available
private AtomicBoolean newDataAvailable = new AtomicBoolean(false);
/** Callback method for when room ID is retrieved.
*
- * @param _ggw [GPSGateway].
+ * @param _roomIdentifier [int].
* @return [void] None.
*/
- public void newRoomIDRetrieved(@NonLocalRemote GPSGateway _ggw) {
-
- try {
- // get the parameters that the interface (phone app) reads from the user
- roomIdentifier = _ggw.getRoomID();
+ public void newRoomIDRetrieved(int _roomIdentifier) {
- System.out.println("DEBUG: New room ID is retrieved from phone!!! Room: " + roomIdentifier);
-
- // Data is read, so we set this back to false
- _ggw.setNewRoomIDAvailable(false);
- } catch (RemoteException ex) {
- ex.printStackTrace();
- }
+ roomIdentifier = _roomIdentifier;
+ System.out.println("DEBUG: New room ID is retrieved from phone!!! Room: " + roomIdentifier);
// new data available so set it to true
newDataAvailable.set(true);
/** Callback method for when ring status is retrieved.
*
- * @param _ggw [GPSGateway].
+ * @param _ringStatus [boolean].
* @return [void] None.
*/
- public void newRingStatusRetrieved(@NonLocalRemote GPSGateway _ggw) {
-
- try {
- // get the parameters that the interface (phone app) reads from the user
- ringStatus = _ggw.getRingStatus();
+ public void newRingStatusRetrieved(boolean _ringStatus) {
- System.out.println("DEBUG: New ring status is retrieved from phone!!! Status: " + ringStatus);
-
- // Data is read, so we set this back to false
- _ggw.setNewRingStatusAvailable(false);
- } catch (RemoteException ex) {
- ex.printStackTrace();
- }
+ ringStatus = _ringStatus;
+ System.out.println("DEBUG: New ring status is retrieved from phone!!! Status: " + ringStatus);
// new data available so set it to true
newDataAvailable.set(true);
/** Callback method when a speaker has finished playing what is in its audio buffer.
*
- * @param _speaker [Speaker].
* @return [void] None.
*/
- public void speakerDone(@NonLocalRemote Speaker _speaker) {
- for (@NonLocalRemote Speaker speakers : speakerSet.values()) {
+ public void speakerDone() {
+ for (SpeakerSmart speakers : speakerSet.values()) {
playbackDone.set(true);
}
}
private void updateSpeakersAction() {
// Stream music on speakers based on their status
- for (@NonLocalRemote Room room : audioRooms.values()) {
+ for (RoomSmart room : audioRooms.values()) {
// Check status of the room
if (roomSpeakersOnOffStatus.get(room)) {
// Get the speaker objects one by one assuming that we could have
// more than one speaker per room
- for (@NonLocalRemote Speaker speakers : roomSpeakerRel.get(room)) {
+ for (SpeakerSmart speakers : roomSpeakerRel.get(room)) {
// System.out.println("DEBUG: Turn on speaker!");
- try {
+ //try {
// start the speaker playback if the speaker is not playing yet
if (!speakers.getPlaybackState()) {
- System.out.println("Turning a speaker On");
+ System.out.println("Turning a speaker On in room: " + room.getRoomID());
speakers.startPlayback();
speakers.setPosition(currentPosition);
}
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ //} catch (RemoteException e) {
+ // e.printStackTrace();
+ //}
}
if (currPosCount != 0) {
if (Math.abs(currentPosOfSpeakers - currentPosition) > CURRENT_POSITION_SAMPLE_THRESHOLD) {
// we were kind of far so update all the positions
- for (@NonLocalRemote Speaker speakers : roomSpeakerRel.get(room)) {
- try {
+ for (SpeakerSmart speakers : roomSpeakerRel.get(room)) {
+ //try {
speakers.setPosition(currentPosOfSpeakers);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ //} catch (RemoteException e) {
+ // e.printStackTrace();
+ //}
}
}
- } else {
+ } /*else {
// Room status is "off"
// used to get the average of the speakers position
// Get the speaker objects one by one assuming that we could have
// more than one speaker per room
- for (@NonLocalRemote Speaker speakers : roomSpeakerRel.get(room)) {
+ for (Speaker speakers : roomSpeakerRel.get(room)) {
// System.out.println("DEBUG: Turn off speaker!");
try {
// Turning off speaker if they are still on
if (currPosCount != 0) {
currentPosition = (int)(currPosTotal / currPosCount);
}
- }
+ }*/
}
// a speaker has finished playing and so we should change all the audio buffers
if (ringStatus) {
// Turn off all speakers if ring status is true (phone is ringing)
- for (@NonLocalRemote Room room : audioRooms.values()) {
+ for (RoomSmart room : audioRooms.values()) {
// System.out.println("DEBUG: Update status off for speakers! Phone is ringing!!!");
// Turn off speaker
// Phone is not ringing... just play music on the right speaker
// Check for every room
- for (@NonLocalRemote Room room : audioRooms.values()) {
+ for (RoomSmart room : audioRooms.values()) {
- try {
+ //try {
// Turn on the right speaker based on room ID sent from phone app
// Stream audio to a speaker based on room ID
if (room.getRoomID() == roomIdentifier) {
roomSpeakersOnOffStatus.put(room, false);
}
- } catch (RemoteException ex) {
- ex.printStackTrace();
- }
+ //} catch (RemoteException ex) {
+ // ex.printStackTrace();
+ //}
}
}
// Finish processing data - put this back to false
System.out.println("Stopping all device playback");
// stop all devices that are still playing and clear their buffers
// they are about to end playback anyways
- for (@NonLocalRemote Speaker speakers : speakerSet.values()) {
+ for (SpeakerSmart speakers : speakerSet.values()) {
try {
if (speakers.getPlaybackState()) {
System.out.println("Loading Speakers");
// send the new data to all the speakers
- for (@NonLocalRemote Speaker speakers : speakerSet.values()) {
+ for (SpeakerSmart speakers : speakerSet.values()) {
System.out.println("Loading a single speaker with data");
try {
speakers.loadData(compressedArray, 0, compressedArray.length);
public void init() throws RemoteException, InterruptedException {
// Initialize the rooms
- for (@NonLocalRemote Room room : audioRooms.values()) {
+ for (RoomSmart room : audioRooms.values()) {
// All rooms start with the speakers turned off
roomSpeakersOnOffStatus.put(room, false);
}
// Setup the cameras, start them all and assign each one a motion detector
- for (@NonLocalRemote GPSGateway gw : gpsSet.values()) {
+ for (GPSGatewaySmart gw : gpsSet.values()) {
- try {
+ //try {
// initialize, register callback, and start the gateway
gw.init();
gw.registerCallback(this);
gw.start();
- } catch (RemoteException ex) {
- ex.printStackTrace();
- }
+ //} catch (RemoteException ex) {
+ // ex.printStackTrace();
+ //}
}
//Initialize the speakers
- for (@NonLocalRemote Speaker speakers : speakerSet.values()) {
+ for (SpeakerSmart speakers : speakerSet.values()) {
speakers.init();
}