From 339af6b1b8d502fe5793ec86008d7f6f7925aef3 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Fri, 6 Jan 2017 16:35:38 -0800 Subject: [PATCH] Adding a (potential) initialization for Alarm; Modifying IoTSocket to allocate a larger byte buffer array when needed --- .../HomeSecurityController/HomeSecurityController.java | 10 ++++++++-- iotjava/iotrmi/Java/IoTSocket.java | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/benchmarks/HomeSecurityController/HomeSecurityController.java b/benchmarks/HomeSecurityController/HomeSecurityController.java index bab46cd..8647f2e 100644 --- a/benchmarks/HomeSecurityController/HomeSecurityController.java +++ b/benchmarks/HomeSecurityController/HomeSecurityController.java @@ -42,6 +42,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { private static final int CAMERA_FPS = 15; private static final int CHECK_TIME_WAIT = 1; // in seconds private static final int SECOND_TO_TURN_ON = 60; // in seconds + private static final int SECOND_TO_TURN_OFF = 1; // in seconds /** * IoT Sets and Relations @@ -194,6 +195,11 @@ public class HomeSecurityController implements SmartthingsSensorCallback { try { alm.init(); System.out.println("DEBUG: Initialized alarm!"); + // TODO: Check that this initialization works for multiple times - might be that setZone() only works once! + //for (RoomSmart room : roomSet.values()) { + // turnOffAlarms(room.getRoomID()); + // System.out.println("DEBUG: Initialized alarm for room (turn off): " + room.getRoomID()); + //} } catch (Exception e) { e.printStackTrace(); } @@ -393,7 +399,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { // Get and init the alarm (this single alarm set can serve multiple zones / rooms) Iterator alarmIt = alarmSet.iterator(); AlarmSmart alm = (AlarmSmart) alarmIt.next(); - alm.setZone(zoneId, true, SECOND_TO_TURN_ON); + alm.setZone(zoneId, true, SECOND_TO_TURN_OFF); } @@ -407,7 +413,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { Iterator alarmIt = alarmSet.iterator(); AlarmSmart alm = (AlarmSmart) alarmIt.next(); // Turn this alarm off indefinitely - alm.setZone(zoneId, false, -1); + alm.setZone(zoneId, false, SECOND_TO_TURN_ON); } diff --git a/iotjava/iotrmi/Java/IoTSocket.java b/iotjava/iotrmi/Java/IoTSocket.java index ba8af4a..7585513 100644 --- a/iotjava/iotrmi/Java/IoTSocket.java +++ b/iotjava/iotrmi/Java/IoTSocket.java @@ -85,6 +85,12 @@ public abstract class IoTSocket { // Receive until maxlen if (maxlen>BUFFSIZE) { System.out.println("IoTSocketClient/Server: Sending more bytes then will fit in buffer! Number of bytes: " + maxlen); + // Allocate a bigger array when needed + int newLen = 2; + while (newLen < maxlen) // Shift until we get a new buffer size that's bigger than maxLen (basically power of 2) + newLen = newLen << 1; + System.out.println("IoTSocketClient/Server: Allocating a bigger buffer now with size: " + newLen); + data = new byte[newLen]; } val = new byte[maxlen]; while (totalbytes < maxlen) -- 2.34.1