// Motion was detected so issue callbacks to all objects that registered
// to receive callback from this class.
for (MotionDetectionCallback c : callbackList) {
- //try {
- c.motionDetected(this);
- //} catch (RemoteException re) {
- //}
+ c.motionDetected(this);
}
} else {
}
}
}
-
-
-
-
- // /*******************************************************************************************************************************************
- // ** Main Method used for testing
- // *******************************************************************************************************************************************/
- // public static void main(String[] args) {
- // MotionDetection mo = new MotionDetection(12, 0.5f, 10, 10);
-
- // AmcrestCamera cam = null;
- // try {
-
- // InetAddress addr = InetAddress.getByName("192.168.1.29");
- // cam = new AmcrestCamera(addr, "admin", "55779CatSoundz32");
- // cam.registerCallback(mo);
- // cam.start();
- // // cam.streamDisconnect();
-
- // } catch (Exception e) {
-
- // }
-
- // while (true) {
-
- // }
-
- // }
}
try {
// Parse the byte array into a Buffered Image
- //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
InputStream in = new ByteArrayInputStream(latestFrame);
img = ImageIO.read(in);
// Save the image and timestamp for use later
imageWriteLock.lock(); // lock the image and timestamp buffers since multithread
- latestImage = img; // image into image buffer
+ latestImage = img; // image into image buffer
// timestamp from camera into timestamo buffer
- //try {
- //long dateLong = _camera.getTimestamp();
- long dateLong = timeStamp;
- possibleDate = new Date(dateLong);
- //} catch (RemoteException e) {
- // e.printStackTrace();
- //}
+ long dateLong = timeStamp;
+ possibleDate = new Date(dateLong);
imageWriteLock.unlock(); // Never forget to unlock
// Motion was detected so issue callbacks to all objects that registered
// to receive callback from this class.
for (MotionDetectionCallback c : callbackList) {
- //try {
- c.motionDetected(this.getTimestampOfLastMotion());
- //} catch (RemoteException re) {
- //}
+ c.motionDetected(this.getTimestampOfLastMotion());
}
} else {
public void init() throws InterruptedException {
for(LightBulbTest lifx : lifx_light_bulb.values()) {
- //Thread thread = new Thread(new Runnable() {
- // public void run() {
- lifx.init();
- // }
- //});
- //thread.start();
+
+ lifx.init();
Thread.sleep(1000);
for (int i = 0; i < 5; i++) {
lifx.setColor(lifx.getHue(), lifx.getSaturation(), i);
Thread.sleep(500);
}
- lifx.turnOff();
- //thread.join();
+ lifx.turnOff();
}
}
}
* @return [void] None.
*/
public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) {
- //public void newCameraFrameAvailable(CameraSmart _camera) {
BufferedImage img = null;
- //byte[] newImg = _camera.getLatestFrame();
try {
- //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
- //InputStream in = new ByteArrayInputStream(newImg);
// Parse the byte array into a Buffered Image
InputStream in = new ByteArrayInputStream(latestFrame);
img = ImageIO.read(in);
// timestamp from camera into timestamp buffer
long dateLong = timeStamp;
- //long dateLong = _camera.getTimestamp();
//System.out.println("DEBUG: New image at time: " + dateLong);
possibleDate = new Date(dateLong);
// Motion was detected so issue callbacks to all objects that registered
// to receive callback from this class.
for (MotionDetectionCallback c : callbackList) {
- //try {
- c.motionDetected(this);
- //} catch (RemoteException re) {
- //}
+ c.motionDetected(this);
}
} else {
}
-
-
// /*******************************************************************************************************************************************
// ** Main Method used for testing
// *******************************************************************************************************************************************/
// try {
// InetAddress addr = InetAddress.getByName("192.168.1.29");
- // cam = new AmcrestCamera(addr, "admin", "55779CatSoundz32");
+ // cam = new AmcrestCamera(addr, "admin", "admin");
// cam.registerCallback(mo);
// cam.start();
- // // cam.streamDisconnect();
// } catch (Exception e) {
import java.rmi.Remote;
import java.rmi.RemoteException;
-// Checker annotations
-//import iotchecker.qual.*;
-
public class AmcrestCamera implements Camera {
/*******************************************************************************************************************************************
public static void main(String[] args) throws Exception {
System.out.println("Running AmcrestCamera!");
-
+
+ // The constructor for IoTDeviceAddress needs to be changed temporarily to make this
+ // to work.
IoTDeviceAddress iotDevAdd = new IoTDeviceAddress(args[0], 12345, 80, false, false);
Set<IoTDeviceAddress> set = new HashSet<IoTDeviceAddress>();
set.add(iotDevAdd);
import iotcode.interfaces.ZoneState;
import iotcode.interfaces.Sprinkler;
-//import iotchecker.qual.*;
-
/** Class BlossomSprinkler for the Blossom Sprinkler.
*
* @author Ali Younis <ayounis @ uci.edu>
import iotcode.interfaces.ZoneState;
import iotcode.interfaces.Alarm;
-//import iotchecker.qual.*;
import iotcode.annotation.*;
/** Class DlinkAlarm for the D-Link Alarm.
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
-// Checker annotations
-//import iotchecker.qual.*;
-import iotcode.annotation.*;
-
// IoT Packages
+import iotcode.annotation.*;
import iotruntime.slave.*;
import iotcode.interfaces.*;
import iotruntime.zigbee.*;
private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
private AtomicBoolean didBind = new AtomicBoolean(false);
- private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei
+ private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); // made by Jiawei
static Semaphore gettingLatestDataMutex = new Semaphore(1);
private List < SmartthingsActuatorSmartCallback > callbackList = new CopyOnWriteArrayList < SmartthingsActuatorSmartCallback > ();
- //made by changwoo
+ // made by Changwoo
sleep(10);
- // System.out.println("BroadcastingRouteRecordRequest ");
- // zigConnection.sendBroadcastingRouteRecordRequest(0x0001);
- // sleep(6);
-
System.out.println("Sending Management Permit Joining Request");
+ // TODO: Might/might not need to send this 3 times
// for(int z=0; z<3; z++){
zigConnection.sendManagementPermitJoiningRequest(0x0002, 0x0036, 0x00);
sleep(0);
}
}
- //made by changwoo
+ // made by Changwoo
private void sleep(int multipleTime){
if(multipleTime<=0){
multipleTime=1;
public void newMessageAvailable(IoTZigbeeMessage _zm) {
- //made by yuting
+ // made by Yuting
if (_zm instanceof IoTZigbeeMessageZdoBindResponse) {
IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm;
if (message.getSucceeded()) {
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
-// Checker annotations
-//import iotchecker.qual.*;
-import iotcode.annotation.*;
-
// IoT Packages
+import iotcode.annotation.*;
import iotruntime.slave.*;
import iotcode.interfaces.*;
import iotruntime.zigbee.*;
private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
private AtomicBoolean didBind = new AtomicBoolean(false);
- private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei
+ private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); // made by Jiawei
static Semaphore gettingLatestDataMutex = new Semaphore(1);
private List < SmartthingsSensorSmartCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorSmartCallback > ();
//made by changwoo
sleep(10);
- // System.out.println("BroadcastingRouteRecordRequest ");
- // zigConnection.sendBroadcastingRouteRecordRequest(0x0001);
- // sleep(6);
-
System.out.println("Sending Management Permit Joining Request");
+ // TODO: Might/might not need to send this 3 times
// for(int z=0; z<3; z++){
zigConnection.sendManagementPermitJoiningRequest(0x0002, 0x0036, 0x00);
sleep(0);
}
}
- //made by changwoo
+ // made by Changwoo
private void sleep(int multipleTime){
if(multipleTime<=0){
multipleTime=1;
}
// made by Jiawei
- //public int getStatus() {
public int getValue() {
int tmp = 0;
public void newMessageAvailable(IoTZigbeeMessage _zm) {
- //made by yuting
+ // made by Yuting
if (_zm instanceof IoTZigbeeMessageZdoBindResponse) {
IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm;
if (message.getSucceeded()) {
import iotruntime.slave.IoTSet;
import iotcode.interfaces.ZoneState;
import iotcode.interfaces.Alarm;
-
-//import iotchecker.qual.*;
import iotcode.annotation.*;
/** Class EspAlarm for the ESP8266 plrg Alarm.
// Will be filled with only 1 address.
@config private IoTSet<IoTDeviceAddress> alm_Addresses;
- /*public EspSprinkler(IoTUDP _udp) {
+ /* TODO: Use this constructor to test this driver manually
+ public EspSprinkler(IoTUDP _udp) {
communicationSockect = _udp;
}*/
boolean onOff = onOffInt != 0;
int duration = Integer.parseInt(splitSting[2].trim());
- //ZoneState zTmp = new ZoneState(zoneNum, onOff, duration);
ZoneState zTmp = new ZoneState();
zTmp.zoneNumber = zoneNum;
zTmp.onOffState = onOff;
import iotcode.interfaces.Sprinkler;
import iotcode.annotation.*;
-//import iotchecker.qual.*;
-
/** Class EspSprinkler for the ESP8266 plrg Sprinkler.
*
* @author Ali Younis <ayounis @ uci.edu>
}
-
-
-
-
-
-
-
import iotcode.annotation.*;
import iotcode.interfaces.*;
-// Checker annotations
-//import iotchecker.qual.*;
/** GPSPhoneGateway that uses IoTRemoteCall and PhoneInfo class
* to get information from a phone app
// Get address
Iterator it = gps_address.iterator();
iotDevAdd = (IoTDeviceAddress) it.next();
-// try {
-// iotDevAdd = new IoTDeviceAddress("192.168.2.100", 1234, 8000);
-// } catch (Exception ex) {
-// }
System.out.println("Address: " + iotDevAdd.getCompleteAddress());
System.out.println("Source port: " + iotDevAdd.getSourcePortNumber());
System.out.println("Destination port: " + iotDevAdd.getDestinationPortNumber());
for (GPSGatewaySmartCallback c : listPGWCallback) {
- //try {
- // Only call back if there is new data
- if (phoneInfo.isNewRoomIDAvailable()) {
+ // Only call back if there is new data
+ if (phoneInfo.isNewRoomIDAvailable()) {
- System.out.println("GPSPhoneGateway: new room ID available - call back!");
- // Call back!
- //c.newRoomIDRetrieved(this);
- c.newRoomIDRetrieved(this.getRoomID());
- //this.setNewRoomIDAvailable(false);
+ System.out.println("GPSPhoneGateway: new room ID available - call back!");
+ // Call back!
+ //c.newRoomIDRetrieved(this);
+ c.newRoomIDRetrieved(this.getRoomID());
+ //this.setNewRoomIDAvailable(false);
- // Set back to false after reading
- phoneInfo.setNewRoomIDAvailable(false);
+ // Set back to false after reading
+ phoneInfo.setNewRoomIDAvailable(false);
- } else if (phoneInfo.isNewRingStatusAvailable()) {
+ } else if (phoneInfo.isNewRingStatusAvailable()) {
- System.out.println("GPSPhoneGateway: new ring status available - call back!");
- // Call back!
- //c.newRingStatusRetrieved(this);
- c.newRingStatusRetrieved(this.getRingStatus());
- //this.setNewRingStatusAvailable(false);
+ System.out.println("GPSPhoneGateway: new ring status available - call back!");
+ // Call back!
+ c.newRingStatusRetrieved(this.getRingStatus());
- // Set back to false after reading
- phoneInfo.setNewRingStatusAvailable(false);
- }
-
- //} catch (RemoteException ex) {
- // ex.printStackTrace();
- //}
+ // Set back to false after reading
+ phoneInfo.setNewRingStatusAvailable(false);
+ }
}
}
}
phoneInfo.setNewRingStatusAvailable(bValue);
}
-
-/* public static void main(String[] args) throws UnknownHostException, RemoteException {
-
- @LocalRemote GPSPhoneGateway gpg = new @LocalRemote GPSPhoneGateway();
- gpg.init();
- gpg.start();
- }*/
}
+
// System.out.println(packetData);
} catch (Exception e) {
- // e.printStackTrace();
+ e.printStackTrace();
}
if (first) {
- sendData[0] = (byte)0x90; // Header bit field
+ sendData[0] = (byte)0x90; // Header bit field
first = false;
} else {
- sendData[0] = (byte)0x80; // Header bit field
+ sendData[0] = (byte)0x80; // Header bit field
}
}
- // TODO: REMOVE THIS
+ // TODO: The following is only for test
/**
* Prepare the speakers for a new song to start playing
*/
@config private IoTSet<IoTDeviceAddress> lb_addresses;
/**
- * Used for testing only
+ * TODO: Used for testing only
*/
/*public LifxLightBulb(IoTUDP udp, byte[] macAddress) {
communicationSockect = udp;
public LifxLightBulb(String macAddress) {
communicationSockect = null;
-
- // Set the Mac Address to a default value
- // Probably not needed for anything
- /*bulbMacAdd[0] = (byte)0x00;
- bulbMacAdd[1] = (byte)0x00;
- bulbMacAdd[2] = (byte)0x00;
- bulbMacAdd[3] = (byte)0x00;
- bulbMacAdd[4] = (byte)0x00;
- bulbMacAdd[5] = (byte)0x00;
- bulbMacAdd[6] = (byte)0x00;
- bulbMacAdd[7] = (byte)0x00;*/
-
bulbMacAddress = DatatypeConverter.parseHexBinary(macAddress);
}
@config private IoTSet<IoTDeviceAddress> motionSensorUdpAddress;
@config private IoTSet<IoTZigbeeAddress> motionSensorZigbeeAddress;
+ // TODO: Test constructor
//public MotionSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
//motionSensorUdpAddress = dSet;
//motionSensorZigbeeAddress = zigSet;
//}
+
public MotionSensor() {
}
zigConnection.init();
System.out.println("Initialized!");
- //made by changwoo
+ // made by Changwoo
sleep(10);
System.out.println("Sending Management Permit Joining Request");
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
while (!didWriteAttrb.get()) {
System.out.println("Sending Write Attribute Request");
zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
System.out.println("Sending Enrollment Reponse");
zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
sleep(0);
}
}
- //made by changwoo
+ // made by Changwoo
private void sleep(int multipleTime){
if(multipleTime<=0){
multipleTime=1;
public void newMessageAvailable(IoTZigbeeMessage _zm) {
- //made by changwoo
+ // made by Changwoo
if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
if(message.getSuccessOrFail()){
}
}//if
- //made by changwoo
+ // made by Changwoo
} else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
if (message.getSuccessOrFail()) {
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
-// Checker annotations
-//import iotchecker.qual.*;
-import iotcode.annotation.*;
-
// IoT Packages
+import iotcode.annotation.*;
import iotruntime.slave.*;
import iotcode.interfaces.*;
import iotruntime.zigbee.*;
@config private IoTSet<IoTDeviceAddress> multipurposeSensorUdpAddress;
@config private IoTSet<IoTZigbeeAddress> multipurposeSensorZigbeeAddress;
+ // TODO: Test constructor
//public MultipurposeSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
//multipurposeSensorUdpAddress = dSet;
//multipurposeSensorZigbeeAddress = zigSet;
zigConnection.init();
System.out.println("Initialized!");
- //made by changwoo
+ // made by Changwoo
sleep(10);
System.out.println("Sending Management Permit Joining Request");
for(int z=0; z<3; z++){
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
while (!didWriteAttrb.get()) {
System.out.println("Sending Write Attribute Request");
zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
System.out.println("Sending Enrollment Reponse");
zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
sleep(0);
}
}
- //made by changwoo
+ // made by Changwoo
private void sleep(int multipleTime){
if(multipleTime<=0){
multipleTime=1;
public void newMessageAvailable(IoTZigbeeMessage _zm) {
- //made by changwoo
+ // made by Changwoo
if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
if(message.getSuccessOrFail()){
}
}//if
- //made by changwoo
- }//if
+ // made by Changwoo
+ }
else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
if (message.getSuccessOrFail()) {
didWriteAttrb.set(true);
- }//if
- }//else if
+ }
+ }
}
public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) {
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
-
-// Checker annotations
-//import iotchecker.qual.*;
-
// IoT Packages
import iotruntime.slave.*;
import iotcode.interfaces.MoistureSensor;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
-// Checker annotations
-//import iotchecker.qual.*;
-import iotcode.annotation.*;
-
// IoT Packages
+import iotcode.annotation.*;
import iotruntime.slave.*;
import iotcode.interfaces.*;
import iotruntime.zigbee.*;
@config private IoTSet<IoTDeviceAddress> waterleakSensorUdpAddress;
@config private IoTSet<IoTZigbeeAddress> waterleakSensorZigbeeAddress;
+ // TODO: Test constructor
//public WaterLeakSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
//waterleakSensorUdpAddress = dSet;
//waterleakSensorZigbeeAddress = zigSet;
zigConnection.init();
System.out.println("Initialized!");
- //made by changwoo
+ // made by Changwoo
sleep(10);
System.out.println("Sending Management Permit Joining Request");
for(int z=0; z<3; z++){
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
while (!didWriteAttrb.get()) {
System.out.println("Sending Write Attribute Request");
zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
sleep(0);
}
- //made by changwoo
+ // made by Changwoo
System.out.println("Sending Enrollment Reponse");
zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
sleep(0);
}
}
- //made by changwoo
+ // made by Changwoo
private void sleep(int multipleTime){
if(multipleTime<=0){
multipleTime=1;
public void newMessageAvailable(IoTZigbeeMessage _zm) {
- //made by changwoo
+ // made by Changwoo
if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
if(message.getSuccessOrFail()){
}
}//if
- //made by changwoo
- }//if
+ // made by Changwoo
+ }
else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
if (message.getSuccessOrFail()) {
didWriteAttrb.set(true);
}//if
- }//else if
+ }
}
public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) {
import iotcode.annotation.*;
import iotcode.interfaces.*;
-// Checker annotations
-//import iotchecker.qual.*;
-
/** WeatherPhoneProxy that uses IoTRemoteCall and WeatherInfo class
* to get information from a phone app
*
/**
* Constructor
*/
- /*public WeatherPhoneGateway() throws RemoteException, UnknownHostException {
-
- iotDevAdd = new IoTDeviceAddress("192.168.2.101", 1234, 8000);
- weatherInfo = new WeatherInfo();
-
- // Launch IoTRemoteCall server in a separate thread
- workerThread = new Thread(new Runnable() {
- public void run() {
- iotRemCall = new IoTRemoteCall(WeatherInfoInterface.class,
- weatherInfo, iotDevAdd.getDestinationPortNumber());
- }
- });
- workerThread.start();
-
- System.out.println("PhoneGateway is started");
-
- }*/
public WeatherPhoneGateway() {
}
// Get address
Iterator it = ph_address.iterator();
iotDevAdd = (IoTDeviceAddress) it.next();
-// try {
-// iotDevAdd = new IoTDeviceAddress("192.168.2.101", 1234, 8000);
-// } catch (Exception ex) {
-// }
System.out.println("Address: " + iotDevAdd.getCompleteAddress());
System.out.println("Source port: " + iotDevAdd.getSourcePortNumber());
System.out.println("Destination port: " + iotDevAdd.getDestinationPortNumber());
System.out.println("We get into doCallbacks!");
System.out.println("weatherInfo.isNewDataAvailable(): " + weatherInfo.isNewDataAvailable());
for (WeatherGatewaySmartCallback c : listPGWCallback) {
- //try {
- //c.informationRetrieved(this);
- c.informationRetrieved(this.getInchesPerWeek(), this.getWeatherZipCode(), this.getDaysToWaterOn(), this.getInchesPerMinute());
- //} catch (RemoteException ex) {
- // ex.printStackTrace();
- //}
- // We have read data - set this back to false
+ c.informationRetrieved(this.getInchesPerWeek(), this.getWeatherZipCode(), this.getDaysToWaterOn(), this.getInchesPerMinute());
}
+ // We have read data - set this back to false
weatherInfo.setNewDataAvailable(false);
}
}
return weatherInfo.getInchesPerMinute();
}
-
-
-// public static void main(String[] args) throws UnknownHostException, RemoteException {
-
-// @LocalRemote WeatherPhoneGateway wpg = new @LocalRemote WeatherPhoneGateway();
-// wpg.init();
-// wpg.start();
-// }
}