Formatting cleanup
This commit is contained in:
parent
c7e286f51e
commit
5a1be3c2e4
50 changed files with 283 additions and 282 deletions
|
|
@ -59,28 +59,28 @@ bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start
|
|||
uint64_t data = 0;
|
||||
bool dimValuePresent;
|
||||
uint8_t b1,b2,b3,b4;
|
||||
|
||||
|
||||
//parse preamp
|
||||
|
||||
b1 = *bufStartP;
|
||||
stepBufferPointer(&bufStartP);
|
||||
b2 = *bufStartP;
|
||||
stepBufferPointer(&bufStartP);
|
||||
if(!IS_PREAMP(b1, b2)){
|
||||
if (!IS_PREAMP(b1, b2)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//parse data
|
||||
|
||||
|
||||
uint16_t dataBitsInBuffer = (calculateBufferPointerDistance(bufStartP, bufEndP)-2) / 4; //each bit is representd by 4 high/low
|
||||
if (dataBitsInBuffer == 32) {
|
||||
dimValuePresent = false;
|
||||
}else if(dataBitsInBuffer == 36){
|
||||
} else if (dataBitsInBuffer == 36){
|
||||
dimValuePresent = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
for (uint8_t i = 0; i < dataBitsInBuffer; ++i) {
|
||||
b1 = *bufStartP; //no of high
|
||||
stepBufferPointer(&bufStartP);
|
||||
|
|
@ -103,7 +103,7 @@ bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start
|
|||
}
|
||||
|
||||
//data parsed - send event over serial
|
||||
|
||||
|
||||
Serial.print(F("+Wclass:command;protocol:arctech;model:selflearning;data:0x"));
|
||||
uint8_t hexToSend = (dimValuePresent ? 9 : 8);
|
||||
for (int8_t i = hexToSend - 1; i >= 0; --i) {
|
||||
|
|
|
|||
|
|
@ -17,29 +17,29 @@ void parseRadioRXBuffer() {
|
|||
bool parse = false;
|
||||
while (bufferReadP != bufferWriteP) { //stop if the read pointer is pointing to where the writing is currently performed
|
||||
uint8_t sampleCount = *bufferReadP;
|
||||
|
||||
|
||||
if ( (((uintptr_t)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs)
|
||||
//Serial.print("high:"); Serial.println(sampleCount);
|
||||
if (prevValue >= SILENCE_LENGTH) {
|
||||
startDataP = bufferReadP; //some new data must start here since this is the first "high" after a silent period
|
||||
}
|
||||
|
||||
|
||||
//stream data to stream parsers
|
||||
parseOregonStream(HIGH, sampleCount);
|
||||
|
||||
|
||||
} else { //buffer pointer is even (stores lows)
|
||||
//Serial.print("low:"); Serial.println(sampleCount);
|
||||
if (sampleCount >= SILENCE_LENGTH) { //evaluate if it is time to parse the curernt data
|
||||
endDataP = bufferReadP; //this is a silient period and must be the end of a data
|
||||
if(startDataP != 0){
|
||||
if (startDataP != 0){
|
||||
parse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//stream data to stream parsers
|
||||
parseOregonStream(LOW, sampleCount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//step the read pointer one step
|
||||
|
|
@ -74,11 +74,11 @@ void parseRadioRXBuffer() {
|
|||
//Let all available parsers parse the data set now.
|
||||
parseArctechSelfLearning(startDataP, endDataP);
|
||||
//TODO: add more parsers here
|
||||
|
||||
|
||||
//reset the data pointers since the data have been parsed at this point
|
||||
startDataP = 0;
|
||||
endDataP = 0;
|
||||
|
||||
|
||||
}; //end radioTask
|
||||
|
||||
void sendTCodedData(uint8_t* data, uint8_t T_long, uint8_t* timings, uint8_t repeat, uint8_t pause) {
|
||||
|
|
@ -88,7 +88,7 @@ void sendTCodedData(uint8_t* data, uint8_t T_long, uint8_t* timings, uint8_t rep
|
|||
for (int i = 0; i < T_long; ++i) {
|
||||
uint8_t timeIndex = (data[i / 4] >> (6 - (2 * (i % 4)))) & 0x03;
|
||||
if (timings[timeIndex] > 0 || i == T_long - 1) {
|
||||
if(nextPinState){
|
||||
if (nextPinState){
|
||||
TX_PIN_HIGH();
|
||||
}else{
|
||||
TX_PIN_LOW();
|
||||
|
|
@ -111,7 +111,7 @@ void sendSCodedData(uint8_t* data, uint8_t pulseCount, uint8_t repeat, uint8_t p
|
|||
bool nextPinState = HIGH;
|
||||
for (int i = 0; i < pulseCount; ++i) {
|
||||
if (data[i] > 0 || i == pulseCount - 1) {
|
||||
if(nextPinState){
|
||||
if (nextPinState){
|
||||
TX_PIN_HIGH();
|
||||
}else{
|
||||
TX_PIN_LOW();
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ void loop()
|
|||
|
||||
// Send power consumption
|
||||
#ifdef POWERCON_ENABLED
|
||||
if(timerMultiplier % POWER_TIMER_MULTIPLIER == 0)
|
||||
if (timerMultiplier % POWER_TIMER_MULTIPLIER == 0)
|
||||
{
|
||||
static PowerData powerData;
|
||||
powerSensor->read(powerData); // not needed, only here for future use
|
||||
|
|
@ -103,7 +103,7 @@ void loop()
|
|||
|
||||
// Handle temperature sensor
|
||||
#ifdef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier % TEMPERATURE_TIMER_MULTIPLIER == 0)
|
||||
if (timerMultiplier % TEMPERATURE_TIMER_MULTIPLIER == 0)
|
||||
{
|
||||
static TemperatureData tempData;
|
||||
tempSensor->read(tempData);
|
||||
|
|
@ -114,7 +114,7 @@ void loop()
|
|||
|
||||
// Handle light sensor
|
||||
#ifdef LIGHT_ENABLED
|
||||
if(timerMultiplier % LIGHT_TIMER_MULTIPLIER == 0)
|
||||
if (timerMultiplier % LIGHT_TIMER_MULTIPLIER == 0)
|
||||
{
|
||||
static LightData lightData;
|
||||
lightSensor->read(lightData);
|
||||
|
|
|
|||
|
|
@ -83,14 +83,14 @@ inline void ProtocolOregon::setId(byte data[], byte id)
|
|||
*/
|
||||
inline void ProtocolOregon::setBatteryLevel(byte data[], bool level)
|
||||
{
|
||||
if(!level) data[4] = 0x0C;
|
||||
if (!level) data[4] = 0x0C;
|
||||
else data[4] = 0x00;
|
||||
}
|
||||
|
||||
inline void ProtocolOregon::setTemperature(byte data[], float temp)
|
||||
{
|
||||
// Set temperature sign
|
||||
if(temp < 0)
|
||||
if (temp < 0)
|
||||
{
|
||||
data[6] = 0x08;
|
||||
temp *= -1;
|
||||
|
|
|
|||
18
external/tellstick-core/Protocol.cpp
vendored
18
external/tellstick-core/Protocol.cpp
vendored
|
|
@ -97,7 +97,7 @@ bool Protocol::checkBit(int data, int bitno) {
|
|||
|
||||
|
||||
Protocol *Protocol::getProtocolInstance(const std::wstring &protocolname) {
|
||||
if(TelldusCore::comparei(protocolname, L"arctech")) {
|
||||
if (TelldusCore::comparei(protocolname, L"arctech")) {
|
||||
return new ProtocolNexa();
|
||||
|
||||
} else if (TelldusCore::comparei(protocolname, L"brateck")) {
|
||||
|
|
@ -151,7 +151,7 @@ Protocol *Protocol::getProtocolInstance(const std::wstring &protocolname) {
|
|||
|
||||
std::list<std::string> Protocol::getParametersForProtocol(const std::wstring &protocolName) {
|
||||
std::list<std::string> parameters;
|
||||
if(TelldusCore::comparei(protocolName, L"arctech")) {
|
||||
if (TelldusCore::comparei(protocolName, L"arctech")) {
|
||||
parameters.push_back("house");
|
||||
parameters.push_back("unit");
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ std::list<std::string> Protocol::decodeData(const std::string &fullData) {
|
|||
std::string decoded = "";
|
||||
|
||||
ControllerMessage dataMsg(fullData);
|
||||
if( TelldusCore::comparei(dataMsg.protocol(), L"arctech") ) {
|
||||
if ( TelldusCore::comparei(dataMsg.protocol(), L"arctech") ) {
|
||||
decoded = ProtocolNexa::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
|
|
@ -231,32 +231,32 @@ std::list<std::string> Protocol::decodeData(const std::string &fullData) {
|
|||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"everflourish") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"everflourish") ) {
|
||||
decoded = ProtocolEverflourish::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"fineoffset") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"fineoffset") ) {
|
||||
decoded = ProtocolFineoffset::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"mandolyn") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"mandolyn") ) {
|
||||
decoded = ProtocolMandolyn::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"oregon") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"oregon") ) {
|
||||
decoded = ProtocolOregon::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"x10") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"x10") ) {
|
||||
decoded = ProtocolX10::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
}
|
||||
} else if(TelldusCore::comparei(dataMsg.protocol(), L"hasta") ) {
|
||||
} else if (TelldusCore::comparei(dataMsg.protocol(), L"hasta") ) {
|
||||
decoded = ProtocolHasta::decodeData(dataMsg);
|
||||
if (decoded != "") {
|
||||
retval.push_back(decoded);
|
||||
|
|
|
|||
2
external/tellstick-core/ProtocolX10.cpp
vendored
2
external/tellstick-core/ProtocolX10.cpp
vendored
|
|
@ -175,7 +175,7 @@ std::string ProtocolX10::decodeData(const ControllerMessage& dataMsg) {
|
|||
retString << "house:" << static_cast<char>('A' + intHouse);
|
||||
retString << ";unit:" << unit+1;
|
||||
retString << ";method:";
|
||||
if(method == 0) {
|
||||
if (method == 0) {
|
||||
retString << "turnon;";
|
||||
} else {
|
||||
retString << "turnoff;";
|
||||
|
|
|
|||
8
external/tellstick-rfcmd/ftdi.c
vendored
8
external/tellstick-rfcmd/ftdi.c
vendored
|
|
@ -37,7 +37,7 @@ int usbWriteFtdi(char *cmdstr)
|
|||
char *err = ftdi_get_error_string(&ctx);
|
||||
// FreeBSD says -3 when another rfcmd is running...
|
||||
// Same on other systems?
|
||||
if(retval == -3) {
|
||||
if (retval == -3) {
|
||||
fprintf(stderr, "usb - open error: %s. Is it busy?\n", err);
|
||||
} else {
|
||||
fprintf(stderr, "usb - open error: %s\n", err);
|
||||
|
|
@ -68,8 +68,8 @@ int usbWriteFtdi(char *cmdstr)
|
|||
fprintf(stderr, "usb - write failed: %s\n", err);
|
||||
ftdiCleanup(&ctx);
|
||||
return 5;
|
||||
} else if(retval != strlen(cmdstr)) {
|
||||
fprintf(stderr, "usb - warning: %d bytes written instead of %d\n",
|
||||
} else if (retval != strlen(cmdstr)) {
|
||||
fprintf(stderr, "usb - warning: %d bytes written instead of %d\n",
|
||||
retval, (int)strlen(cmdstr));
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ int usbWriteFtdi(char *cmdstr)
|
|||
usleep(1000);
|
||||
} else if (bytes > 0) {
|
||||
// Done when newline is received
|
||||
if(inb == '\n') {
|
||||
if (inb == '\n') {
|
||||
ftdiCleanup(&ctx);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
40
external/tellstick-rfcmd/rfcmd.c
vendored
40
external/tellstick-rfcmd/rfcmd.c
vendored
|
|
@ -39,8 +39,8 @@
|
|||
|
||||
/*******************************************************************************
|
||||
* Modifications to rfcmd.c ver 2.1.0 done by Tord Andersson
|
||||
* Introduced semaphore protection to avoid problems with simultaneous port
|
||||
* access from several processes (typically cron jobs). Note! Need rt lib.
|
||||
* Introduced semaphore protection to avoid problems with simultaneous port
|
||||
* access from several processes (typically cron jobs). Note! Need rt lib.
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
@ -48,10 +48,10 @@
|
|||
* Added support for RISINGSUN
|
||||
* Note:
|
||||
* 1. Command line syntax:
|
||||
* /usr/local/bin/rfcmd /dev/ttyUSB0 RISINGSUN 4 1 0"
|
||||
* /usr/local/bin/rfcmd /dev/ttyUSB0 RISINGSUN 4 1 0"
|
||||
* Arg 1: device
|
||||
* Arg 2: protocol
|
||||
* Arg 3: code
|
||||
* Arg 3: code
|
||||
* Arg 4: device number
|
||||
* Arg 5: Level (0=off, 1 = on)
|
||||
******************************************************************************/
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Modifications from rfcmd ver 2.1.1 done by Johan Ström
|
||||
* Modifications from rfcmd ver 2.1.1 done by Johan Str<EFBFBD>m
|
||||
* Default disabled semaphores for FreeBSD.
|
||||
* Added status readback in ftdi.c, instead of wasting time in sleep.
|
||||
*
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
|
||||
#define PROG_NAME "rfcmd"
|
||||
#define PROG_VERSION "2.1.1"
|
||||
/* #define RFCMD_DEBUG */
|
||||
/* #define RFCMD_DEBUG */
|
||||
|
||||
/* Local function declarations */
|
||||
int createNexaString(const char * pHouseStr, const char * pChannelStr,
|
||||
|
|
@ -132,18 +132,18 @@ int main( int argc, char **argv )
|
|||
|
||||
char txStr[100];
|
||||
|
||||
if( (argc == 6) && (strcmp(*(argv+2), "NEXA") == 0)) {
|
||||
if ((argc == 6) && (strcmp(*(argv+2), "NEXA") == 0)) {
|
||||
if (createNexaString(*(argv+3), *(argv+4), *(argv+5), txStr, 0) == 0) {
|
||||
printUsage();
|
||||
exit(1);
|
||||
}
|
||||
/* else - a send cmd string was created */
|
||||
} else if( (argc == 6) && (strcmp(*(argv+2), "WAVEMAN") == 0)) {
|
||||
} else if ( (argc == 6) && (strcmp(*(argv+2), "WAVEMAN") == 0)) {
|
||||
if (createNexaString(*(argv+3),*(argv+4), *(argv+5), txStr, 1) == 0) {
|
||||
printUsage();
|
||||
exit(1);
|
||||
}
|
||||
} else if( (argc == 5) && (strcmp(*(argv+2), "SARTANO") == 0)) {
|
||||
} else if ( (argc == 5) && (strcmp(*(argv+2), "SARTANO") == 0)) {
|
||||
if (createSartanoString(*(argv+3), *(argv+4), txStr) == 0) {
|
||||
printUsage();
|
||||
exit(1);
|
||||
|
|
@ -183,11 +183,11 @@ int main( int argc, char **argv )
|
|||
|
||||
#endif
|
||||
|
||||
if(strlen(txStr) > 0) {
|
||||
if (strlen(txStr) > 0) {
|
||||
#ifndef NO_SEMAPHORES
|
||||
/* create the semaphore - will reuse an existing one if it exists */
|
||||
portMutex = sem_open(SEM_NAME,O_CREAT,0644,1);
|
||||
if( portMutex == SEM_FAILED) {
|
||||
if (portMutex == SEM_FAILED) {
|
||||
fprintf(stderr, "%s - Error creating port semaphore\n", PROG_NAME);
|
||||
perror("Semaphore open error");
|
||||
sem_unlink(SEM_NAME);
|
||||
|
|
@ -195,24 +195,24 @@ int main( int argc, char **argv )
|
|||
}
|
||||
|
||||
/* lock semaphore to protect port from multiple access */
|
||||
if(sem_wait(portMutex) != 0) {
|
||||
if (sem_wait(portMutex) != 0) {
|
||||
fprintf(stderr, "%s - Error aquiring port semaphore\n", PROG_NAME);
|
||||
sem_unlink(SEM_NAME);
|
||||
sem_close(portMutex);
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (strcmp(*(argv+1), "LIBUSB") != 0) {
|
||||
if( 0 > ( fd = open( *(argv+1), O_RDWR ) ) ) {
|
||||
if ( 0 > ( fd = open( *(argv+1), O_RDWR ) ) ) {
|
||||
#ifdef __FreeBSD__
|
||||
fprintf(stderr, "%s - Error opening %s; You're on a FreeBSD system, you should probably use LIBUSB.\n", PROG_NAME, *(argv+1));
|
||||
#else
|
||||
fprintf(stderr, "%s - Error opening %s\n", PROG_NAME, *(argv+1));
|
||||
#endif
|
||||
#ifndef NO_SEMAPHORES
|
||||
if(sem_post(portMutex) != 0) {
|
||||
if (sem_post(portMutex) != 0) {
|
||||
fprintf(stderr, "%s - Error releasing port semaphore\n", PROG_NAME);
|
||||
}
|
||||
sem_unlink(SEM_NAME);
|
||||
|
|
@ -251,7 +251,7 @@ int main( int argc, char **argv )
|
|||
exit(1);
|
||||
} else {
|
||||
sem_unlink(SEM_NAME);
|
||||
sem_close(portMutex);
|
||||
sem_close(portMutex);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -342,7 +342,7 @@ int createSartanoString(const char * pChannelStr, const char * pOn_offStr,
|
|||
strcat(pTxStr,"S");
|
||||
for(bit=0;bit<=9;bit++)
|
||||
{
|
||||
if(strncmp(pChannelStr+bit, "1", 1) == 0) { //If it is a "1"
|
||||
if (strncmp(pChannelStr+bit, "1", 1) == 0) { //If it is a "1"
|
||||
strcat(pTxStr,"$k$k");
|
||||
} else {
|
||||
strcat(pTxStr,"$kk$");
|
||||
|
|
@ -364,9 +364,9 @@ int createIkeaString( const char * pSystemStr, const char * pChannelStr, const c
|
|||
{
|
||||
*pStrReturn = '\0'; /* Make sure tx string is empty */
|
||||
|
||||
const char STARTCODE[] = "STTTTTTª";
|
||||
const char STARTCODE[] = "STTTTTT<EFBFBD>";
|
||||
const char TT[] = "TT";
|
||||
const char A[] = "ª";
|
||||
const char A[] = "<EFBFBD>";
|
||||
int systemCode = atoi(pSystemStr) - 1; /* System 1..16 */
|
||||
int channelCode = atoi(pChannelStr); /* Channel 1..10 */
|
||||
int Level = atoi(pLevelStr); /* off,10,20,..,90,on */
|
||||
|
|
@ -658,6 +658,6 @@ void printVersion(void) {
|
|||
printf("\n");
|
||||
printf("Written by:\n");
|
||||
printf("Tord Andersson, Micke Prag, Gudmund Berggren, Tapani Rintala\n");
|
||||
printf("and Johan Ström\n");
|
||||
printf("and Johan Str<EFBFBD>m\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
*/
|
||||
@Override
|
||||
public void register(Event event) {
|
||||
if(event.getDeviceConfig() == null) {
|
||||
if (event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: " + event);
|
||||
return;
|
||||
}
|
||||
if(!availableEvents.contains(event.getDeviceConfig().getClass())) {
|
||||
if (!availableEvents.contains(event.getDeviceConfig().getClass())) {
|
||||
logger.warning("Event data plugin not available: " + event.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
Class<? extends HalEventController> c = event.getController();
|
||||
HalEventController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
if (controller != null)
|
||||
controller.register(event.getDeviceConfig());
|
||||
registeredEvents.add(event);
|
||||
detectedEvents.remove(HalDeviceUtil.findDevice(event.getDeviceConfig(), detectedEvents)); // Remove if this device was detected
|
||||
|
|
@ -91,7 +91,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
*/
|
||||
@Override
|
||||
public void deregister(Event event){
|
||||
if(event.getDeviceConfig() == null) {
|
||||
if (event.getDeviceConfig() == null) {
|
||||
logger.warning("Event config is null: "+ event);
|
||||
return;
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
logger.info("Received report from unregistered event" +
|
||||
"(" + eventConfig.getClass().getSimpleName() + "): " + eventConfig);
|
||||
event = HalDeviceUtil.findDevice(eventConfig, detectedEvents);
|
||||
if(event == null) {
|
||||
if (event == null) {
|
||||
event = new Event();
|
||||
detectedEvents.add(event);
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
}
|
||||
event.setDeviceData(eventData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<HalEventConfig,HalEventData> listener : event.getReportListeners())
|
||||
for (HalDeviceReportListener<HalEventConfig,HalEventData> listener : event.getReportListeners())
|
||||
listener.reportReceived(event.getDeviceConfig(), eventData);
|
||||
|
||||
}catch (SQLException e){
|
||||
|
|
@ -189,7 +189,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
|
||||
public void send(Event event){
|
||||
HalEventController controller = getControllerInstance(event.getController());
|
||||
if(controller != null) {
|
||||
if (controller != null) {
|
||||
controller.send(event.getDeviceConfig(), event.getDeviceData());
|
||||
reportReceived(event.getDeviceConfig(), event.getDeviceData()); // save action to db
|
||||
}
|
||||
|
|
@ -207,9 +207,9 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
if(obj instanceof HalEventConfig) {
|
||||
if (obj instanceof HalEventConfig) {
|
||||
Event event = HalDeviceUtil.findDevice((HalEventConfig) obj, registeredEvents);
|
||||
if(event != null){
|
||||
if (event != null){
|
||||
deregister(event);
|
||||
limboEvents.add(event);
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ public class EventControllerManager extends HalAbstractControllerManager<HalEven
|
|||
public void postConfigurationAction(Configurator configurator, Object obj) {
|
||||
if (obj instanceof HalEventConfig) {
|
||||
Event event = HalDeviceUtil.findDevice((HalEventConfig) obj, limboEvents);
|
||||
if(event != null){
|
||||
if (event != null){
|
||||
register(event);
|
||||
limboEvents.remove(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class HalContext {
|
|||
File dbFile = FileUtil.find(DB_FILE);
|
||||
db = new DBConnection(DBConnection.DBMS.SQLite, DB_FILE);
|
||||
|
||||
if(dbFile == null){
|
||||
if (dbFile == null){
|
||||
logger.info("No database file found, creating new DB...");
|
||||
} else {
|
||||
dbConf = db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||
|
|
@ -92,9 +92,9 @@ public class HalContext {
|
|||
-1);
|
||||
logger.info("DB version: "+ dbVersion);
|
||||
|
||||
if(defaultDBVersion > dbVersion ) {
|
||||
if (defaultDBVersion > dbVersion ) {
|
||||
logger.info("Starting DB upgrade from v" + dbVersion + " to v" + defaultDBVersion + "...");
|
||||
if(dbFile != null){
|
||||
if (dbFile != null){
|
||||
File backupDB = FileUtil.getNextFile(dbFile);
|
||||
logger.fine("Backing up DB to: "+ backupDB);
|
||||
FileUtil.copy(dbFile, backupDB);
|
||||
|
|
@ -115,8 +115,8 @@ public class HalContext {
|
|||
new SQLResultHandler<Object>() {
|
||||
@Override
|
||||
public Object handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||
while(result.next()){
|
||||
if(result.getBoolean("force_upgrade")){
|
||||
while (result.next()){
|
||||
if (result.getBoolean("force_upgrade")){
|
||||
logger.fine("Forced upgrade enabled");
|
||||
handler.setForcedDBUpgrade(true); //set to true if any of the intermediate db version requires it.
|
||||
}
|
||||
|
|
@ -139,19 +139,19 @@ public class HalContext {
|
|||
boolean clearExternalAggrData = false;
|
||||
boolean clearInternalAggrData = false;
|
||||
|
||||
while(result.next()){
|
||||
if(result.getBoolean("clear_external_aggr_data"))
|
||||
while (result.next()){
|
||||
if (result.getBoolean("clear_external_aggr_data"))
|
||||
clearExternalAggrData = true;
|
||||
if(result.getBoolean("clear_internal_aggr_data"))
|
||||
if (result.getBoolean("clear_internal_aggr_data"))
|
||||
clearInternalAggrData = true;
|
||||
}
|
||||
|
||||
if(clearExternalAggrData){
|
||||
if (clearExternalAggrData){
|
||||
logger.fine("Clearing external aggregate data");
|
||||
db.exec("DELETE FROM sensor_data_aggr WHERE sensor_id = "
|
||||
+ "(SELECT sensor.id FROM user, sensor WHERE user.external == 1 AND sensor.user_id = user.id)");
|
||||
}
|
||||
if(clearInternalAggrData){
|
||||
if (clearInternalAggrData){
|
||||
logger.fine("Clearing local aggregate data");
|
||||
db.exec("DELETE FROM sensor_data_aggr WHERE sensor_id IN "
|
||||
+ "(SELECT sensor.id FROM user, sensor WHERE user.external == 0 AND sensor.user_id = user.id)");
|
||||
|
|
|
|||
|
|
@ -67,11 +67,11 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
|
|||
*/
|
||||
@Override
|
||||
public void register(Sensor sensor) {
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
if (sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: " + sensor);
|
||||
return;
|
||||
}
|
||||
if(!availableSensors.contains(sensor.getDeviceConfig().getClass())) {
|
||||
if (!availableSensors.contains(sensor.getDeviceConfig().getClass())) {
|
||||
logger.warning("Sensor data plugin not available: " + sensor.getDeviceConfig().getClass());
|
||||
return;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
|
|||
Class<? extends HalAbstractController> c = sensor.getController();
|
||||
HalAbstractController controller = getControllerInstance(c);
|
||||
|
||||
if(controller != null)
|
||||
if (controller != null)
|
||||
controller.register(sensor.getDeviceConfig());
|
||||
registeredSensors.add(sensor);
|
||||
detectedSensors.remove(
|
||||
|
|
@ -94,7 +94,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
|
|||
*/
|
||||
@Override
|
||||
public void deregister(Sensor sensor){
|
||||
if(sensor.getDeviceConfig() == null) {
|
||||
if (sensor.getDeviceConfig() == null) {
|
||||
logger.warning("Sensor config is null: "+ sensor);
|
||||
return;
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
|
|||
logger.finest("Received report from unregistered sensor" +
|
||||
"(" + sensorConfig.getClass().getSimpleName() + "): " + sensorConfig);
|
||||
sensor = HalDeviceUtil.findDevice(sensorConfig, detectedSensors);
|
||||
if(sensor == null) {
|
||||
if (sensor == null) {
|
||||
sensor = new Sensor();
|
||||
detectedSensors.add(sensor);
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
|
|||
}
|
||||
sensor.setDeviceData(sensorData);
|
||||
// call listeners
|
||||
for(HalDeviceReportListener<HalSensorConfig,HalSensorData> listener : sensor.getReportListeners())
|
||||
for (HalDeviceReportListener<HalSensorConfig,HalSensorData> listener : sensor.getReportListeners())
|
||||
listener.reportReceived(sensorConfig, sensorData);
|
||||
|
||||
} catch (SQLException e){
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
public void run(){
|
||||
try {
|
||||
List<Sensor> sensorList = Sensor.getLocalSensors(HalContext.getDB());
|
||||
for(Sensor sensor : sensorList){
|
||||
for (Sensor sensor : sensorList){
|
||||
logger.fine("Aggregating sensor_id: " + sensor.getId());
|
||||
aggregateSensor(sensor);
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
}
|
||||
|
||||
public void aggregateSensor(Sensor sensor) {
|
||||
if(sensor.getDeviceConfig() == null){
|
||||
if (sensor.getDeviceConfig() == null){
|
||||
logger.fine("The sensor config is not available - ignoring it");
|
||||
return;
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
}
|
||||
|
||||
// Is there any new data to evaluate?
|
||||
if(dbMaxRawTimestamp < dbMaxAggrEndTimestamp || dbMaxRawTimestamp < periodOldestStartTimestamp){
|
||||
if (dbMaxRawTimestamp < dbMaxAggrEndTimestamp || dbMaxRawTimestamp < periodOldestStartTimestamp){
|
||||
logger.fine("No new data to evaluate - aggregation is up to date");
|
||||
return;
|
||||
}
|
||||
|
|
@ -215,8 +215,8 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
"INSERT INTO sensor_data_aggr" +
|
||||
"(sensor_id, sequence_id, timestamp_start, timestamp_end, data, confidence) " +
|
||||
"VALUES(?, ?, ?, ?, ?, ?)");
|
||||
while(result.next()){
|
||||
if(sensorId != result.getInt("sensor_id")){
|
||||
while (result.next()){
|
||||
if (sensorId != result.getInt("sensor_id")){
|
||||
throw new IllegalArgumentException("found entry for aggregation for the wrong sensorId " +
|
||||
"(expecting: "+sensorId+", but was: "+result.getInt("sensor_id")+")");
|
||||
}
|
||||
|
|
@ -224,10 +224,10 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
long timestamp = result.getLong("timestamp");
|
||||
UTCTimePeriod dataPeriod = new UTCTimePeriod(timestamp, this.aggrPeriodLength);
|
||||
|
||||
if(currentPeriod == null)
|
||||
if (currentPeriod == null)
|
||||
currentPeriod = dataPeriod;
|
||||
|
||||
if(!dataPeriod.equals(currentPeriod)){
|
||||
if (!dataPeriod.equals(currentPeriod)){
|
||||
saveData(preparedInsertStmt, confidenceSum, sum, samples, currentPeriod, ++highestSequenceId);
|
||||
|
||||
// Reset variables
|
||||
|
|
@ -242,7 +242,7 @@ public class SensorDataAggregatorDaemon implements HalDaemon {
|
|||
}
|
||||
|
||||
//check if the last period is complete and also should be aggregated
|
||||
if(currentPeriod != null &&
|
||||
if (currentPeriod != null &&
|
||||
currentPeriod.getEndTimestamp() <= new UTCTimePeriod(aggregationStartTime, aggrPeriodLength).getPreviosPeriod().getEndTimestamp()){
|
||||
saveData(preparedInsertStmt, confidenceSum, sum, samples, currentPeriod, ++highestSequenceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class SensorDataCleanupDaemon implements HalDaemon {
|
|||
public void run(){
|
||||
try {
|
||||
List<Sensor> sensorList = Sensor.getSensors(HalContext.getDB());
|
||||
for(Sensor sensor : sensorList){
|
||||
for (Sensor sensor : sensorList){
|
||||
logger.fine("Deleting old aggregated data for sensor id: " + sensor.getId());
|
||||
cleanupSensor(sensor);
|
||||
}
|
||||
|
|
@ -97,8 +97,8 @@ public class SensorDataCleanupDaemon implements HalDaemon {
|
|||
try{
|
||||
HalContext.getDB().getConnection().setAutoCommit(false);
|
||||
PreparedStatement preparedDeleteStmt = HalContext.getDB().getPreparedStatement("DELETE FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id == ?");
|
||||
while(result.next()){
|
||||
if(sensorId != result.getInt("sensor_id")){
|
||||
while (result.next()){
|
||||
if (sensorId != result.getInt("sensor_id")){
|
||||
throw new IllegalArgumentException("Found entry for aggregation for the wrong sensorId (expecting: "+sensorId+", but was: "+result.getInt("sensor_id")+")");
|
||||
}
|
||||
logger.finer("Deleting sensor(id: "+ sensorId +") aggregate entry timestamp: "+ result.getLong("timestamp_start") +" - "+ result.getLong("timestamp_end") + " (" + UTCTimeUtility.timeInMsToString(1+result.getLong("timestamp_end")-result.getLong("timestamp_start")) + ")");
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public abstract class HalAbstractDevice<V extends HalAbstractDevice, C extends H
|
|||
* DeviceData will be reset if the input is set as null.
|
||||
*/
|
||||
public void setDeviceConfig(C data) {
|
||||
if(data != null) {
|
||||
if (data != null) {
|
||||
type = data.getClass().getName();
|
||||
deviceConfig = data;
|
||||
deviceData = getLatestDeviceData(HalContext.getDB());
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Event Settings").setWeight(200);
|
||||
|
||||
eventConfigurations = new ArrayList<>();
|
||||
for(Class c : EventControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
for (Class c : EventControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
eventConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ public class EventConfigWebPage extends HalWebPage {
|
|||
User localUser = User.getLocalUser(db);
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
if (request.containsKey("action")) {
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
Event event;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class EventOverviewWebPage extends HalWebPage {
|
|||
private static final String DETAIL_TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/event_detail.tmpl";
|
||||
|
||||
|
||||
public EventOverviewWebPage(){
|
||||
public EventOverviewWebPage() {
|
||||
super("event_overview");
|
||||
super.getRootNav().createSubNav("Events").createSubNav(this.getId(), "Overview");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ public class HalAlertManager implements HttpPage {
|
|||
private UserMessageManager messageManager = new UserMessageManager();
|
||||
|
||||
|
||||
private HalAlertManager(){}
|
||||
private HalAlertManager() {}
|
||||
|
||||
|
||||
public String getUrl(){
|
||||
public String getUrl() {
|
||||
return "/" + PAGE_NAME;
|
||||
}
|
||||
|
||||
|
|
@ -74,10 +74,10 @@ public class HalAlertManager implements HttpPage {
|
|||
|
||||
|
||||
|
||||
public static void initialize(){
|
||||
public static void initialize() {
|
||||
instance = new HalAlertManager();
|
||||
}
|
||||
public static HalAlertManager getInstance(){
|
||||
public static HalAlertManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class PluginConfigWebPage extends HalWebPage {
|
|||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/plugin_config.tmpl";
|
||||
|
||||
|
||||
public PluginConfigWebPage(){
|
||||
public PluginConfigWebPage() {
|
||||
super("plugins");
|
||||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Plugins").setWeight(500);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class PropertyConfigWebPage extends HalWebPage {
|
|||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/property_config.tmpl";
|
||||
|
||||
|
||||
public PropertyConfigWebPage(){
|
||||
public PropertyConfigWebPage() {
|
||||
super("properties");
|
||||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Properties");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Sensor Settings").setWeight(100);
|
||||
|
||||
sensorConfigurations = new ArrayList<>();
|
||||
for(Class c : SensorControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
for (Class c : SensorControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
sensorConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
User localUser = User.getLocalUser(db);
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
if (request.containsKey("action")) {
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
Sensor sensor;
|
||||
User user;
|
||||
|
|
@ -70,7 +70,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
|
||||
case "modify_local_sensor":
|
||||
sensor = Sensor.getSensor(db, id);
|
||||
if(sensor != null){
|
||||
if (sensor != null) {
|
||||
logger.info("Modifying sensor: " + sensor.getName());
|
||||
sensor.setName(request.get("name"));
|
||||
sensor.setType(request.get("type"));
|
||||
|
|
@ -89,7 +89,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
|
||||
case "remove_local_sensor":
|
||||
sensor = Sensor.getSensor(db, id);
|
||||
if(sensor != null) {
|
||||
if (sensor != null) {
|
||||
logger.warning("Removing sensor: " + sensor.getName());
|
||||
SensorControllerManager.getInstance().deregister(sensor);
|
||||
sensor.delete(db);
|
||||
|
|
@ -122,7 +122,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
|
||||
case "modify_external_user":
|
||||
user = User.getUser(db, id);
|
||||
if(user != null){
|
||||
if (user != null) {
|
||||
logger.info("Modifying external user: " + user.getHostname());
|
||||
user.setHostname(request.get("hostname"));
|
||||
user.setPort(Integer.parseInt(request.get("port")));
|
||||
|
|
@ -154,7 +154,7 @@ public class SensorConfigWebPage extends HalWebPage {
|
|||
// External Sensors
|
||||
case "modify_external_sensor":
|
||||
sensor = Sensor.getSensor(db, id);
|
||||
if(sensor != null){
|
||||
if (sensor != null) {
|
||||
logger.warning("Modifying external sensor: " + sensor.getName());
|
||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||
sensor.save(db);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class SensorOverviewWebPage extends HalWebPage {
|
|||
private static final String DETAIL_TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/sensor_detail.tmpl";
|
||||
|
||||
|
||||
public SensorOverviewWebPage(){
|
||||
public SensorOverviewWebPage() {
|
||||
super("sensor_overview");
|
||||
super.getRootNav().createSubNav("Sensors").createSubNav(this.getId(), "Overview");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ public class TriggerWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Events").createSubNav(this.getId(), "Triggers");
|
||||
|
||||
triggerConfigurators = new ArrayList<>();
|
||||
for(Class c : TriggerManager.getInstance().getAvailableTriggers())
|
||||
for (Class c : TriggerManager.getInstance().getAvailableTriggers())
|
||||
triggerConfigurators.add(new ClassConfigurationData(c));
|
||||
actionConfigurators = new ArrayList<>();
|
||||
for(Class c : TriggerManager.getInstance().getAvailableActions())
|
||||
for (Class c : TriggerManager.getInstance().getAvailableActions())
|
||||
actionConfigurators.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public class TriggerWebPage extends HalWebPage {
|
|||
|
||||
// Triggers
|
||||
case "create_trigger":
|
||||
if (flow == null){
|
||||
if (flow == null) {
|
||||
logger.warning("Invalid flow id: " + request.get("flow-id"));
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
MessageLevel.ERROR, "Invalid flow id: " + request.get("flow-id"), MessageTTL.ONE_VIEW));
|
||||
|
|
@ -107,7 +107,7 @@ public class TriggerWebPage extends HalWebPage {
|
|||
|
||||
// Triggers
|
||||
case "create_action":
|
||||
if (flow == null){
|
||||
if (flow == null) {
|
||||
HalAlertManager.getInstance().addAlert(new UserMessage(
|
||||
MessageLevel.ERROR, "Invalid flow id", MessageTTL.ONE_VIEW));
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class TriggerFlow extends DBBean {
|
|||
public boolean evaluate(){
|
||||
if (triggerList.isEmpty() || !enabled)
|
||||
return false;
|
||||
for(Trigger trigger : triggerList){
|
||||
for (Trigger trigger : triggerList){
|
||||
if (!trigger.evaluate())
|
||||
return false;
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ public class TriggerFlow extends DBBean {
|
|||
public void execute(){
|
||||
if (!enabled)
|
||||
return;
|
||||
for(Action action : actionList){
|
||||
for (Action action : actionList){
|
||||
action.execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ public class TriggerFlow extends DBBean {
|
|||
* Resets all trigger evaluations
|
||||
*/
|
||||
public void reset() {
|
||||
for(Trigger trigger : triggerList){
|
||||
for (Trigger trigger : triggerList){
|
||||
trigger.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class User extends DBBean{
|
|||
@Override
|
||||
public void delete(DBConnection db) throws SQLException {
|
||||
List<Sensor> sensorList = Sensor.getSensors(db, this);
|
||||
for(Sensor sensor : sensorList){
|
||||
for (Sensor sensor : sensorList){
|
||||
sensor.delete(db);
|
||||
}
|
||||
super.delete(db);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
|
|||
+ " ORDER BY timestamp_start ASC");
|
||||
stmt.setLong(1, sensor.getId());
|
||||
stmt.setLong(2, sensor.getUser().getId());
|
||||
switch(aggrPeriodLength){
|
||||
switch(aggrPeriodLength) {
|
||||
case SECOND: stmt.setLong(3, UTCTimeUtility.SECOND_IN_MS-1); break;
|
||||
case MINUTE: stmt.setLong(3, UTCTimeUtility.MINUTE_IN_MS-1); break;
|
||||
case FIVE_MINUTES: stmt.setLong(3, UTCTimeUtility.FIVE_MINUTES_IN_MS-1); break;
|
||||
|
|
@ -61,7 +61,7 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
|
|||
|
||||
private Sensor sensor;
|
||||
|
||||
private AggregateDataListSqlResult(Sensor sensor){
|
||||
private AggregateDataListSqlResult(Sensor sensor) {
|
||||
this.sensor = sensor;
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
|
|||
public ArrayList<AggregateData> handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||
ArrayList<AggregateData> list = new ArrayList<>();
|
||||
long previousTimestampEnd = -1;
|
||||
while (result.next()){
|
||||
while (result.next()) {
|
||||
|
||||
int id = result.getInt("id");
|
||||
long timestampStart = result.getLong("timestamp_start");
|
||||
|
|
@ -84,7 +84,7 @@ public class AggregateDataListSqlResult implements SQLResultHandler<ArrayList<Ag
|
|||
float estimatedData = data/confidence; //estimate the "real" value of the data by looking at the confidence value
|
||||
|
||||
// Add null data point to list if one or more periods of data is missing before this
|
||||
if (previousTimestampEnd != -1 && sensor.getDeviceConfig() != null){
|
||||
if (previousTimestampEnd != -1 && sensor.getDeviceConfig() != null) {
|
||||
boolean shortInterval = timestampEnd-timestampStart < sensor.getDeviceConfig().getDataInterval();
|
||||
long distance = timestampStart - (previousTimestampEnd + 1);
|
||||
if (// Only add nulls if the report interval is smaller than the aggregated interval
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class DeviceDataSqlResult implements SQLResultHandler<HalDeviceData> {
|
|||
private Class<? extends HalDeviceData> clazz;
|
||||
|
||||
|
||||
public DeviceDataSqlResult(Class<? extends HalDeviceData> clazz){
|
||||
public DeviceDataSqlResult(Class<? extends HalDeviceData> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
|
|
@ -27,9 +27,9 @@ public class DeviceDataSqlResult implements SQLResultHandler<HalDeviceData> {
|
|||
dataObj.setTimestamp(result.getLong("timestamp"));
|
||||
return dataObj;
|
||||
}
|
||||
} catch (SQLException e){
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new SQLException(e);
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ public class HistoryDataListSqlResult implements SQLResultHandler<List<HistoryDa
|
|||
public long timestamp;
|
||||
public float data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<HistoryData> handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||
ArrayList<HistoryData> list = new ArrayList<HistoryData>();
|
||||
while(result.next()){
|
||||
while (result.next()) {
|
||||
HistoryData data = new HistoryData();
|
||||
data.timestamp = result.getLong("timestamp");
|
||||
data.data = result.getFloat("data");
|
||||
|
|
|
|||
|
|
@ -7,36 +7,37 @@ public class UTCTimePeriod{
|
|||
private final long end;
|
||||
private final AggregationPeriodLength periodLength;
|
||||
|
||||
public UTCTimePeriod(long timestamp, AggregationPeriodLength periodLength){
|
||||
public UTCTimePeriod(long timestamp, AggregationPeriodLength periodLength) {
|
||||
start = UTCTimeUtility.getTimestampPeriodStart(periodLength, timestamp);
|
||||
end = UTCTimeUtility.getTimestampPeriodEnd(periodLength, timestamp);
|
||||
this.periodLength = periodLength;
|
||||
}
|
||||
|
||||
public long getStartTimestamp(){
|
||||
public long getStartTimestamp() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public long getEndTimestamp(){
|
||||
public long getEndTimestamp() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public UTCTimePeriod getNextPeriod(){
|
||||
public UTCTimePeriod getNextPeriod() {
|
||||
return new UTCTimePeriod(end+1, periodLength);
|
||||
}
|
||||
|
||||
public UTCTimePeriod getPreviosPeriod(){
|
||||
public UTCTimePeriod getPreviosPeriod() {
|
||||
return new UTCTimePeriod(start-1, periodLength);
|
||||
}
|
||||
|
||||
public boolean containsTimestamp(long timestamp){
|
||||
public boolean containsTimestamp(long timestamp) {
|
||||
return start <= timestamp && timestamp <= end;
|
||||
}
|
||||
|
||||
public boolean equals(Object other){
|
||||
if(other == null)
|
||||
public boolean equals(Object other) {
|
||||
if (other == null)
|
||||
return false;
|
||||
if(other instanceof UTCTimePeriod){
|
||||
|
||||
if (other instanceof UTCTimePeriod) {
|
||||
UTCTimePeriod o = (UTCTimePeriod)other;
|
||||
return start == o.start
|
||||
&& end == o.end
|
||||
|
|
@ -45,7 +46,7 @@ public class UTCTimePeriod{
|
|||
return false;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return start + "=>" + end + " (" + UTCTimeUtility.getDateString(start) + "=>" + UTCTimeUtility.getDateString(end) + ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class UTCTimeUtility {
|
|||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(timestamp);
|
||||
cal.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
switch(aggrPeriodLength){
|
||||
switch(aggrPeriodLength) {
|
||||
case YEAR:
|
||||
cal.set(Calendar.DAY_OF_YEAR, 1);
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
|
|
@ -82,7 +82,7 @@ public class UTCTimeUtility {
|
|||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(timestamp);
|
||||
cal.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
switch(aggrPeriodLength){
|
||||
switch(aggrPeriodLength) {
|
||||
case YEAR:
|
||||
cal.set(Calendar.DAY_OF_YEAR, cal.getActualMaximum(Calendar.DAY_OF_YEAR));
|
||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
|
|
@ -137,7 +137,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getMillisecondInSecondFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -145,7 +145,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getSecondOfMinuteFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -153,7 +153,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getMinuteOfHourFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -161,7 +161,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getHourOfDayFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -169,7 +169,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getDayOfWeekFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -177,7 +177,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getDayOfMonthFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -185,7 +185,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getDayOfYearFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -193,7 +193,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getWeekOfYearFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -201,7 +201,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getMonthOfYearFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -209,7 +209,7 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static int getYearFromTimestamp(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
cal.setTimeInMillis(ms);
|
||||
|
|
@ -217,15 +217,15 @@ public class UTCTimeUtility {
|
|||
}
|
||||
|
||||
public static String timeInMsToString(long ms) throws NumberFormatException{
|
||||
if(ms < 0)
|
||||
if (ms < 0)
|
||||
throw new NumberFormatException("argument must be positive");
|
||||
String retval = "";
|
||||
int weeks = (int) (ms / WEEK_IN_MS);
|
||||
if(weeks > 0){
|
||||
if (weeks > 0) {
|
||||
retval += weeks + "w+";
|
||||
}
|
||||
int days = ((int) (ms / DAY_IN_MS)) % 7;
|
||||
if(days > 0){
|
||||
if (days > 0) {
|
||||
retval += days + "d+";
|
||||
}
|
||||
int hours = (int) ((ms % DAY_IN_MS) / HOUR_IN_MS);
|
||||
|
|
@ -239,7 +239,7 @@ public class UTCTimeUtility {
|
|||
return retval;
|
||||
}
|
||||
|
||||
public static String getDateString(long timestamp){
|
||||
public static String getDateString(long timestamp) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
format.setTimeZone(TIMEZONE);
|
||||
Calendar cal = Calendar.getInstance(TIMEZONE, LOCALE);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import static org.junit.Assert.assertTrue;
|
|||
@RunWith(Parameterized.class)
|
||||
public class TimePeriodTest {
|
||||
private final long currentTime_UTC;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param timestamp
|
||||
|
|
@ -25,7 +25,7 @@ public class TimePeriodTest {
|
|||
public TimePeriodTest(long timestamp){
|
||||
this.currentTime_UTC = timestamp;
|
||||
}
|
||||
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> data(){
|
||||
return Arrays.asList(new Object[][] {
|
||||
|
|
@ -46,59 +46,59 @@ public class TimePeriodTest {
|
|||
{System.currentTimeMillis()+(7*UTCTimeUtility.MINUTE_IN_MS)}, //current time + 7m
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testYearTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.YEAR);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMonthTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.MONTH);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWeekTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.WEEK);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDayTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.DAY);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHourTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.HOUR);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test15MiuteTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.FIFTEEN_MINUTES);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test5MiuteTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.FIVE_MINUTES);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMiuteTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.MINUTE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSecondTimePeriod(){
|
||||
testSeriesOfPeriods(AggregationPeriodLength.SECOND);
|
||||
}
|
||||
|
||||
|
||||
private void testSeriesOfPeriods(AggregationPeriodLength periodLength){
|
||||
UTCTimePeriod tp = new UTCTimePeriod(currentTime_UTC, periodLength);
|
||||
|
||||
|
||||
//test next 50 periods
|
||||
UTCTimePeriod prevTp = tp;
|
||||
UTCTimePeriod nextTp = null;
|
||||
for(int i = 0; i < 50; ++i){
|
||||
for (int i = 0; i < 50; ++i){
|
||||
nextTp = prevTp.getNextPeriod();
|
||||
assertTrue("previos period end must be older than the next period end", prevTp.getEndTimestamp() < nextTp.getStartTimestamp());
|
||||
assertTrue("previous period +1ms must be equal to next period start", prevTp.getEndTimestamp()+1 == nextTp.getStartTimestamp());
|
||||
|
|
@ -106,10 +106,10 @@ public class TimePeriodTest {
|
|||
testPeriod(nextTp, periodLength);
|
||||
prevTp = nextTp;
|
||||
}
|
||||
|
||||
|
||||
//test previous 50 periods
|
||||
nextTp = tp;
|
||||
for(int i = 0; i < 50; ++i){
|
||||
for (int i = 0; i < 50; ++i){
|
||||
prevTp = nextTp.getPreviosPeriod();
|
||||
assertTrue("previos period end must be older than the next period end", prevTp.getEndTimestamp() < nextTp.getStartTimestamp());
|
||||
assertTrue("previous period +1ms must be equal to next period start", prevTp.getEndTimestamp()+1 == nextTp.getStartTimestamp());
|
||||
|
|
@ -118,11 +118,11 @@ public class TimePeriodTest {
|
|||
nextTp = prevTp;
|
||||
}
|
||||
}
|
||||
|
||||
private void testPeriod(UTCTimePeriod period, AggregationPeriodLength periodLength){
|
||||
|
||||
private void testPeriod(UTCTimePeriod period, AggregationPeriodLength periodLength){
|
||||
//verify that the period start and end is in the same period
|
||||
assertEquals("start and/or end timestamp is not in the same period", period.getStartTimestamp(), UTCTimeUtility.getTimestampPeriodStart(periodLength, period.getEndTimestamp()));
|
||||
assertEquals("start and/or end timestamp is not in the same period", period.getEndTimestamp(), UTCTimeUtility.getTimestampPeriodEnd(periodLength, period.getStartTimestamp()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
if (deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.put(mqttEvent.getTopic(), mqttEvent);
|
||||
} else throw new IllegalArgumentException(
|
||||
|
|
@ -126,7 +126,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
if (deviceConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) deviceConfig;
|
||||
topics.remove(mqttEvent.getTopic());
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ public class HalMqttController implements HalAutoScannableController, MqttSubscr
|
|||
|
||||
@Override
|
||||
public void send(HalEventConfig eventConfig, HalEventData eventData) {
|
||||
if(eventConfig instanceof HalMqttDeviceConfig) {
|
||||
if (eventConfig instanceof HalMqttDeviceConfig) {
|
||||
HalMqttDeviceConfig mqttEvent = (HalMqttDeviceConfig) eventConfig;
|
||||
mqttBroker.publish(mqttEvent.getTopic(), Double.toString(eventData.getData()).getBytes());
|
||||
} else throw new IllegalArgumentException(
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class CameraConfigWebPage extends HalWebPage {
|
|||
super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Camera Settings").setWeight(200);
|
||||
|
||||
cameraConfigurations = new ArrayList<>();
|
||||
for(Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
for (Class c : CameraControllerManager.getInstance().getAvailableDeviceConfigs())
|
||||
cameraConfigurations.add(new ClassConfigurationData(c));
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ public class CameraConfigWebPage extends HalWebPage {
|
|||
User localUser = User.getLocalUser(db);
|
||||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
if (request.containsKey("action")){
|
||||
int id = (ObjectUtil.isEmpty(request.get("id")) ? -1 : Integer.parseInt(request.get("id")));
|
||||
Camera camera;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
List<User> users = User.getExternalUsers(db);
|
||||
for(User user : users){
|
||||
if(user.getHostname() == null){
|
||||
for (User user : users){
|
||||
if (user.getHostname() == null){
|
||||
logger.fine("Hostname not defined for user: "+ user.getUsername());
|
||||
continue;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
|
||||
// Check server protocol version
|
||||
int version = in.readInt();
|
||||
if(version != PCDataSynchronizationDaemon.PROTOCOL_VERSION){
|
||||
if (version != PCDataSynchronizationDaemon.PROTOCOL_VERSION){
|
||||
logger.warning("Protocol version do not match, skipping user. " +
|
||||
"(local v"+PCDataSynchronizationDaemon.PROTOCOL_VERSION+" != remote v"+version+")");
|
||||
out.writeObject(null); // Tell server we are disconnecting
|
||||
|
|
@ -96,10 +96,10 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
user.setAddress(peerData.address);
|
||||
user.save(db);
|
||||
|
||||
for(SensorDTO sensorDTO : peerData.sensors){
|
||||
for (SensorDTO sensorDTO : peerData.sensors){
|
||||
try { // We might not have the sensor plugin installed
|
||||
Sensor sensor = Sensor.getExternalSensor(db, user, sensorDTO.sensorId);
|
||||
if(sensor == null) { // new sensor
|
||||
if (sensor == null) { // new sensor
|
||||
sensor = new Sensor();
|
||||
logger.fine("Created new external sensor with external_id: "+ sensorDTO.sensorId);
|
||||
}
|
||||
|
|
@ -120,8 +120,8 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
|
||||
// Request sensor data
|
||||
List<Sensor> sensors = Sensor.getSensors(db, user);
|
||||
for(Sensor sensor : sensors){
|
||||
if(sensor.isSynced()) {
|
||||
for (Sensor sensor : sensors){
|
||||
if (sensor.isSynced()) {
|
||||
SensorDataReqDTO req = new SensorDataReqDTO();
|
||||
req.sensorId = sensor.getExternalId();
|
||||
req.offsetSequenceId = Sensor.getHighestSequenceId(sensor.getId());
|
||||
|
|
@ -129,7 +129,7 @@ public class PCDataSynchronizationClient implements HalDaemon {
|
|||
out.writeObject(req);
|
||||
|
||||
SensorDataListDTO dataList = (SensorDataListDTO) in.readObject();
|
||||
if(dataList.aggregationVersion != sensor.getAggregationVersion()){
|
||||
if (dataList.aggregationVersion != sensor.getAggregationVersion()){
|
||||
logger.fine("The peer has modified its aggregated data, clearing aggregate data. oldAggregationVersion:"+sensor.getAggregationVersion()+" , newAggregationVersion:"+dataList.aggregationVersion);
|
||||
|
||||
//clear old aggregated data for sensor
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
Object obj = null;
|
||||
out.writeInt(PROTOCOL_VERSION); // send our protocol version to client
|
||||
out.flush();
|
||||
while((obj = in.readObject()) != null){
|
||||
if(obj instanceof PeerDataReqDTO){
|
||||
while ((obj = in.readObject()) != null){
|
||||
if (obj instanceof PeerDataReqDTO){
|
||||
logger.fine("Client requesting peer data");
|
||||
PeerDataRspDTO rsp = new PeerDataRspDTO();
|
||||
User localUser = User.getLocalUser(db);
|
||||
|
|
@ -111,8 +111,8 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
rsp.address = localUser.getAddress();
|
||||
|
||||
rsp.sensors = new ArrayList<>();
|
||||
for(Sensor sensor : Sensor.getLocalSensors(db)){
|
||||
if(sensor.isSynced()) {
|
||||
for (Sensor sensor : Sensor.getLocalSensors(db)){
|
||||
if (sensor.isSynced()) {
|
||||
SensorDTO dto = new SensorDTO();
|
||||
dto.sensorId = sensor.getId();
|
||||
dto.name = sensor.getName();
|
||||
|
|
@ -123,17 +123,17 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
}
|
||||
out.writeObject(rsp);
|
||||
}
|
||||
if(obj instanceof SensorDataReqDTO){
|
||||
if (obj instanceof SensorDataReqDTO){
|
||||
SensorDataReqDTO req = (SensorDataReqDTO) obj;
|
||||
Sensor sensor = Sensor.getSensor(db, req.sensorId);
|
||||
if(sensor.isSynced()) {
|
||||
if (sensor.isSynced()) {
|
||||
PreparedStatement stmt = db.getPreparedStatement("SELECT * FROM sensor_data_aggr WHERE sensor_id == ? AND sequence_id > ?");
|
||||
stmt.setLong(1, sensor.getId());
|
||||
logger.fine("Client requesting sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId + ", " + req.aggregationVersion);
|
||||
if(req.aggregationVersion != sensor.getAggregationVersion()){
|
||||
if (req.aggregationVersion != sensor.getAggregationVersion()){
|
||||
logger.fine("The requested aggregation version does not match the local version: " + sensor.getAggregationVersion() + ". Will re-send all aggregated data.");
|
||||
stmt.setLong(2, 0); //0 since we want to re-send all data to the peer
|
||||
}else{
|
||||
} else {
|
||||
stmt.setLong(2, req.offsetSequenceId);
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ public class PCDataSynchronizationDaemon extends ThreadedTCPNetworkServer implem
|
|||
logger.fine("Sending " + rsp.size() + " sensor data items to client");
|
||||
out.writeObject(rsp);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
logger.warning("Client requesting non synced sensor data: sensorId: " + req.sensorId + ", offset: " + req.offsetSequenceId);
|
||||
SensorDataListDTO rsp = new SensorDataListDTO();
|
||||
out.writeObject(rsp);
|
||||
|
|
|
|||
|
|
@ -26,44 +26,44 @@ public class RPiController implements HalSensorController {
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
if (deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
int gpioPin = powerConsumptionSensor.getGpioPin();
|
||||
if(!pinToSensorMap.containsKey("GPIO_"+gpioPin)){
|
||||
if (!pinToSensorMap.containsKey("GPIO_"+gpioPin)){
|
||||
RPiInteruptPulseFlankCounter impulseCounter = new RPiInteruptPulseFlankCounter(gpioPin, this);
|
||||
pinToSensorMap.put("GPIO_"+gpioPin, impulseCounter);
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot create a RPiPowerConsumptionSensor on GPIO pin " + gpioPin + " since is already is in use by another sensor.");
|
||||
}
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
} else if (deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
String w1Address = temperatureSensor.get1WAddress();
|
||||
if(!pinToSensorMap.containsKey("W1_"+w1Address)){
|
||||
if (!pinToSensorMap.containsKey("W1_"+w1Address)){
|
||||
RPiDS18B20 ds12b20 = new RPiDS18B20(w1Address, this);
|
||||
pinToSensorMap.put("W1_"+w1Address, ds12b20);
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot create a RPi1WireTemperatureSensor on 1-Wire address " + w1Address + " since is already is in use by another sensor.");
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot register a non-supported sensor");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
if (deviceConfig instanceof RPiPowerConsumptionSensor){
|
||||
RPiPowerConsumptionSensor powerConsumptionSensor = (RPiPowerConsumptionSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("GPIO_"+powerConsumptionSensor.getGpioPin());
|
||||
if(sensorToDeregister != null){
|
||||
if (sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
}
|
||||
} else if(deviceConfig instanceof RPiTemperatureSensor){
|
||||
} else if (deviceConfig instanceof RPiTemperatureSensor){
|
||||
RPiTemperatureSensor temperatureSensor = (RPiTemperatureSensor) deviceConfig;
|
||||
RPiSensor sensorToDeregister = pinToSensorMap.remove("W1_"+temperatureSensor.get1WAddress());
|
||||
if(sensorToDeregister != null){
|
||||
if (sensorToDeregister != null){
|
||||
sensorToDeregister.close();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
logger.warning("Cannot deregister a non-supported sensor");
|
||||
return;
|
||||
}
|
||||
|
|
@ -81,16 +81,16 @@ public class RPiController implements HalSensorController {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
for(String key : this.pinToSensorMap.keySet()){
|
||||
for (String key : this.pinToSensorMap.keySet()){
|
||||
pinToSensorMap.get(key).close();
|
||||
pinToSensorMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendDataReport(HalSensorConfig sensorConfig, HalSensorData sensorData){
|
||||
if(sensorListener != null){
|
||||
if (sensorListener != null){
|
||||
sensorListener.reportReceived(sensorConfig, sensorData);
|
||||
}else{
|
||||
} else {
|
||||
logger.log(Level.WARNING, "Could not report data. No registered listener");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
private int gpioPin = -1;
|
||||
|
||||
|
||||
public RPiPowerConsumptionSensor(){ } //need to be empty for the framework to create an instance
|
||||
public RPiPowerConsumptionSensor() { } //need to be empty for the framework to create an instance
|
||||
public RPiPowerConsumptionSensor(int gpioPin) {
|
||||
this.gpioPin = gpioPin;
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
|
||||
|
||||
@Override
|
||||
public long getDataInterval(){
|
||||
public long getDataInterval() {
|
||||
return 60*1000; // 1 min
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,8 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof RPiPowerConsumptionSensor)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof RPiPowerConsumptionSensor)
|
||||
return ((RPiPowerConsumptionSensor)obj).gpioPin == gpioPin;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig {
|
|||
return gpioPin;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "gpioPin:" + gpioPin;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class RPiTemperatureSensor implements HalSensorConfig {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof RPiTemperatureSensor && w1Address != null)
|
||||
if (obj instanceof RPiTemperatureSensor && w1Address != null)
|
||||
return this.get1WAddress().equals(((RPiTemperatureSensor) obj).w1Address);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import com.pi4j.io.gpio.RaspiPin;
|
|||
|
||||
public class RPiUtility {
|
||||
|
||||
public static Pin getPin(int gpioPin){
|
||||
switch(gpioPin){
|
||||
public static Pin getPin(int gpioPin) {
|
||||
switch(gpioPin) {
|
||||
case 0:
|
||||
return RaspiPin.GPIO_00;
|
||||
case 1:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RPiDS18B20 implements RPiSensor, Runnable {
|
||||
public class RPiDS18B20 implements RPiSensor, Runnable {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private final String DEGREE_SIGN = "\u00b0";
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
private ScheduledExecutorService scheduler;
|
||||
private W1Master w1Mater;
|
||||
|
||||
public RPiDS18B20(String w1Address, RPiController controller){
|
||||
public RPiDS18B20(String w1Address, RPiController controller) {
|
||||
this.controller = controller;
|
||||
this.w1Address = w1Address;
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
w1Mater = new W1Master();
|
||||
|
||||
//print out all sensors found
|
||||
for(TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)){
|
||||
for (TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)) {
|
||||
logger.info(String.format("1-Wire temperature sensor divice found: %-20s: %3.1f"+DEGREE_SIGN+"C\n", device.getName(), device.getTemperature(TemperatureScale.CELSIUS)));
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
scheduler.scheduleAtFixedRate(this, 10, 60, TimeUnit.SECONDS); //wait 10s and run every 60s
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
scheduler.shutdown();
|
||||
try {
|
||||
|
|
@ -52,8 +52,8 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
for(TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)){
|
||||
if(device.getName().equals(w1Address)){
|
||||
for (TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)) {
|
||||
if (device.getName().equals(w1Address)) {
|
||||
controller.sendDataReport(
|
||||
new RPiTemperatureSensor(w1Address),
|
||||
new TemperatureSensorData(
|
||||
|
|
@ -64,5 +64,5 @@ public class RPiDS18B20 implements RPiSensor, Runnable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
private GpioPinDigitalInput irLightSensor;
|
||||
private final int gpioPin;
|
||||
|
||||
public RPiInteruptPulseFlankCounter(int gpioPin, RPiController controller){
|
||||
public RPiInteruptPulseFlankCounter(int gpioPin, RPiController controller) {
|
||||
this.controller = controller;
|
||||
this.gpioPin = gpioPin;
|
||||
|
||||
|
|
@ -42,10 +42,10 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
GpioController gpio = null;
|
||||
try{
|
||||
gpio = GpioFactory.getInstance();
|
||||
}catch(IllegalArgumentException e){
|
||||
}catch(IllegalArgumentException e) {
|
||||
logger.log(Level.SEVERE, "", e);
|
||||
throw e;
|
||||
}catch(UnsatisfiedLinkError e){
|
||||
}catch(UnsatisfiedLinkError e) {
|
||||
logger.log(Level.SEVERE, "", e);
|
||||
throw e;
|
||||
}
|
||||
|
|
@ -55,49 +55,49 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
|
||||
// create and register gpio pin listener. May require the program to be run as sudo if the GPIO pin has not been exported
|
||||
irLightSensor.addListener(this);
|
||||
|
||||
|
||||
//start a daemon thread to save the impulse count every minute
|
||||
Thread thread = new Thread(this);
|
||||
thread.setDaemon(false);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
irLightSensor.removeListener(this);
|
||||
executorPool.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GpioPinListenerDigital interface
|
||||
*/
|
||||
@Override
|
||||
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
|
||||
if(event.getState() == PinState.LOW){ //low = light went on
|
||||
if (event.getState() == PinState.LOW) { //low = light went on
|
||||
//System.out.println("IR LED turned ON");
|
||||
//logger.log(Level.INFO, "IR LED turned on");
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
impulseCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTime = System.nanoTime();
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
impulseCount = 0; //reset the impulse count
|
||||
}
|
||||
while(!executorPool.isShutdown()) {
|
||||
while (!executorPool.isShutdown()) {
|
||||
sleepNano(nanoSecondsSleep); //sleep for some time. This variable will be modified every loop to compensate for the loop time spent.
|
||||
int count = -1;
|
||||
synchronized(impulseCount){
|
||||
synchronized(impulseCount) {
|
||||
count = impulseCount;
|
||||
impulseCount = 0;
|
||||
}
|
||||
save(System.currentTimeMillis(), count); //save the impulse count
|
||||
long estimatedNanoTimeSpent = System.nanoTime() - startTime; //this is where the loop ends
|
||||
startTime = System.nanoTime(); //this is where the loop starts from now on
|
||||
if(estimatedNanoTimeSpent > 0){ //if no overflow
|
||||
if (estimatedNanoTimeSpent > 0) { //if no overflow
|
||||
long nanoSecondsTooMany = estimatedNanoTimeSpent - (REPORT_TIMEOUT*1000000L);
|
||||
//System.out.println("the look took ~" + estimatedNanoTimeSpent + "ns. That is " + nanoSecondsTooMany/1000000L + "ms off");
|
||||
nanoSecondsSleep -= nanoSecondsTooMany / 3; //divide by constant to take into account varaiations im loop time
|
||||
|
|
@ -109,27 +109,27 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
* Sleep for [ns] nanoseconds
|
||||
* @param ns
|
||||
*/
|
||||
private void sleepNano(long ns){
|
||||
private void sleepNano(long ns) {
|
||||
//System.out.println("will go to sleep for " + ns + "ns");
|
||||
try{
|
||||
Thread.sleep(ns/1000000L, (int)(ns%1000000L));
|
||||
}catch(InterruptedException e){
|
||||
}catch(InterruptedException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the data to the database.
|
||||
* This method should block the caller as short time as possible.
|
||||
* This method should try block the same amount of time every time it is called.
|
||||
* Try to make the time spent in the method the same for every call (low variation).
|
||||
*
|
||||
* Try to make the time spent in the method the same for every call (low variation).
|
||||
*
|
||||
* @param timestamp_end
|
||||
* @param data
|
||||
*/
|
||||
private void save(final long timestamp_end, final int data){
|
||||
private void save(final long timestamp_end, final int data) {
|
||||
//offload the timed loop by not doing the db interaction in this thread.
|
||||
executorPool.execute(new Runnable(){
|
||||
executorPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.log(Level.INFO, "Reporting data. timestamp_end="+timestamp_end+", data="+data);
|
||||
|
|
@ -141,5 +141,5 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class TellstickParser {
|
|||
} else if (data.startsWith("+V")) {
|
||||
if (data.length() > 2)
|
||||
firmwareVersion = Integer.parseInt(data.substring(2));
|
||||
}else {
|
||||
} else {
|
||||
logger.severe("Unknown prefix: " + data);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ public class TellstickParser {
|
|||
/**
|
||||
* This method blocks until a send command confirmation is received.
|
||||
*/
|
||||
public synchronized void waitSendConformation(){
|
||||
public synchronized void waitSendConformation() {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
|||
|
|
@ -138,13 +138,13 @@ public class TellstickSerialComm implements Runnable,
|
|||
private String readLine() throws IOException {
|
||||
StringBuilder str = new StringBuilder(50);
|
||||
int c;
|
||||
while((c = in.read()) >= 0){
|
||||
while ((c = in.read()) >= 0) {
|
||||
switch(c) {
|
||||
case -1:
|
||||
return null;
|
||||
case '\n':
|
||||
case '\r':
|
||||
if(str.length() > 0)
|
||||
if (str.length() > 0)
|
||||
return str.toString();
|
||||
break;
|
||||
default:
|
||||
|
|
@ -153,7 +153,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
return str.toString();
|
||||
}
|
||||
protected void handleLine(String data){
|
||||
protected void handleLine(String data) {
|
||||
List<TellstickDecodedEntry> decodeList = parser.decode(data);
|
||||
for (TellstickDecodedEntry entry : decodeList) {
|
||||
if (entry.getData().getTimestamp() < 0)
|
||||
|
|
@ -191,7 +191,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
|
||||
@Override
|
||||
public void send(HalEventConfig deviceConfig, HalEventData deviceData) {
|
||||
if(deviceConfig instanceof TellstickDevice) {
|
||||
if (deviceConfig instanceof TellstickDevice) {
|
||||
TellstickDevice tellstickDevice = (TellstickDevice) deviceConfig;
|
||||
TellstickProtocol prot = TellstickParser.getProtocolInstance(
|
||||
tellstickDevice.getProtocolName(),
|
||||
|
|
@ -208,7 +208,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
if (data == null)
|
||||
return;
|
||||
try {
|
||||
for(int i=0; i<data.length();i++)
|
||||
for (int i=0; i<data.length();i++)
|
||||
out.write(0xFF & data.charAt(i));
|
||||
out.write('\n');
|
||||
out.flush();
|
||||
|
|
@ -223,15 +223,15 @@ public class TellstickSerialComm implements Runnable,
|
|||
|
||||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof TellstickDevice)
|
||||
if (deviceConfig instanceof TellstickDevice)
|
||||
registeredDevices.add(deviceConfig);
|
||||
else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of " + TellstickDevice.class + ": " + deviceConfig.getClass());
|
||||
}
|
||||
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz){
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz) {
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (HalDeviceConfig device : registeredDevices){
|
||||
for (HalDeviceConfig device : registeredDevices) {
|
||||
if (clazz.isAssignableFrom(device.getClass()))
|
||||
list.add((T) device);
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
}
|
||||
|
||||
|
||||
public static TellstickSerialComm getInstance(){
|
||||
public static TellstickSerialComm getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,28 +18,28 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
* @param timing set first timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls0Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls0Timing(int timing) {
|
||||
setPullsTiming(0, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set second timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls1Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls1Timing(int timing) {
|
||||
setPullsTiming(1, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set third timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls2Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls2Timing(int timing) {
|
||||
setPullsTiming(2, timing); return this;
|
||||
}
|
||||
/**
|
||||
* @param timing set fourth timing in us
|
||||
* @return an instance of itself
|
||||
*/
|
||||
public TellstickCmdExtendedSend setPulls3Timing(int timing){
|
||||
public TellstickCmdExtendedSend setPulls3Timing(int timing) {
|
||||
setPullsTiming(3, timing); return this;
|
||||
}
|
||||
/**
|
||||
|
|
@ -47,29 +47,29 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
* @param timing set first pulls length in us between 0-2550
|
||||
* @return an instance of itself
|
||||
*/
|
||||
private void setPullsTiming(int i, int timing){ // TODO: should probably have high and low timing to be called pulls
|
||||
private void setPullsTiming(int i, int timing) { // TODO: should probably have high and low timing to be called pulls
|
||||
if (0 > timing || timing > 2550)
|
||||
throw new IllegalArgumentException("Invalid pulls "+timing+" must be between 0-2550" );
|
||||
cmd[OFFSET_TIMINGS + i] = (byte)(timing/10);
|
||||
}
|
||||
|
||||
|
||||
public TellstickCmdExtendedSend addPulls0(){
|
||||
public TellstickCmdExtendedSend addPulls0() {
|
||||
addPulls(0); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls1(){
|
||||
public TellstickCmdExtendedSend addPulls1() {
|
||||
addPulls(1); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls2(){
|
||||
public TellstickCmdExtendedSend addPulls2() {
|
||||
addPulls(2); return this;
|
||||
}
|
||||
public TellstickCmdExtendedSend addPulls3(){
|
||||
public TellstickCmdExtendedSend addPulls3() {
|
||||
addPulls(3); return this;
|
||||
}
|
||||
private void addPulls(int i) {
|
||||
if (OFFSET_PULSES+(length/4) > cmd.length)
|
||||
throw new IndexOutOfBoundsException("Maximum length "+cmd.length+" reached");
|
||||
switch (length % 4){
|
||||
switch (length % 4) {
|
||||
case 0:
|
||||
cmd[OFFSET_PULSES+ length/4] |= 0b1100_0000 & (i << 6); break;
|
||||
case 1:
|
||||
|
|
@ -83,7 +83,7 @@ public class TellstickCmdExtendedSend implements TellstickCmd{
|
|||
}
|
||||
|
||||
|
||||
public String getTransmissionString(){
|
||||
public String getTransmissionString() {
|
||||
cmd[0] = 'T';
|
||||
cmd[OFFSET_PULSE_LENGTH] = (byte)length;
|
||||
cmd[OFFSET_PULSES+(int)Math.ceil(length/4.0)] = '+';
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class TellstickCmdSend implements TellstickCmd{
|
|||
}
|
||||
|
||||
|
||||
public String getTransmissionString(){
|
||||
public String getTransmissionString() {
|
||||
cmd[0] = 'S';
|
||||
cmd[OFFSET_PULSES+length] = '+';
|
||||
return new String(cmd, 0, OFFSET_PULSES+length+1, StandardCharsets.ISO_8859_1);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ public class NexaSelfLearning implements TellstickDevice, HalEventConfig, Tellst
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NexaSelfLearning)
|
||||
return ((NexaSelfLearning) obj).house == house &&
|
||||
((NexaSelfLearning) obj).group == group &&
|
||||
((NexaSelfLearning)obj).unit == unit;
|
||||
|
|
@ -100,13 +100,13 @@ public class NexaSelfLearning implements TellstickDevice, HalEventConfig, Tellst
|
|||
}
|
||||
@Override
|
||||
public boolean equalsGroup(TellstickDeviceGroup obj) {
|
||||
if(obj instanceof NexaSelfLearning)
|
||||
if (obj instanceof NexaSelfLearning)
|
||||
return ((NexaSelfLearning) obj).house == house &&
|
||||
(((NexaSelfLearning) obj).group || group );
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "house:" + house +
|
||||
", group:" + group +
|
||||
", unit:" + unit;
|
||||
|
|
|
|||
|
|
@ -81,14 +81,14 @@ public class NexaSelfLearningDimmer implements TellstickDevice, HalEventConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearningDimmer)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NexaSelfLearningDimmer)
|
||||
return ((NexaSelfLearningDimmer) obj).house == house &&
|
||||
((NexaSelfLearningDimmer)obj).unit == unit;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "house:" + house +
|
||||
", unit:" + unit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,14 +90,14 @@ public class Oregon0x1A2D implements TellstickDevice, HalSensorConfig {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof Oregon0x1A2D)
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Oregon0x1A2D)
|
||||
return ((Oregon0x1A2D)obj).address == this.address &&
|
||||
((Oregon0x1A2D)obj).sensorType == this.sensorType;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return "address:" + address + ",sensorType:" + sensorType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol {
|
|||
|
||||
|
||||
|
||||
public Oregon0x1A2DProtocol(){
|
||||
public Oregon0x1A2DProtocol() {
|
||||
super(PROTOCOL, MODEL);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol {
|
|||
OregonSensorType sensorType = device.getSensorType();
|
||||
if (sensorType == null)
|
||||
sensorType = OregonSensorType.POWER;
|
||||
switch (sensorType){
|
||||
switch (sensorType) {
|
||||
case HUMIDITY:
|
||||
dataObj = new HumiditySensorData(humidity, timestamp);
|
||||
humidityFound = true;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
OnOffEventData nexaData = new OnOffEventData();
|
||||
|
||||
System.out.println("Up and Running");
|
||||
while(true) {
|
||||
while (true) {
|
||||
Thread.sleep(2000);
|
||||
nexaData.turnOn();
|
||||
nexaDevice.setUnit(0);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class HalZigbeeControllerTest {
|
|||
|
||||
handleConsoleInput('h', controller.networkManager);
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
char input = waitForInout();
|
||||
handleConsoleInput(input, controller.networkManager);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue