forked from oberasoftware/zwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V2 fully event driven implementation is now working, removed all conv…
…ersion mechanisms and they are now based on event receivers
- Loading branch information
Showing
65 changed files
with
561 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/oberasoftware/home/zwave/ZWaveConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.oberasoftware.home.zwave; | ||
|
||
import com.oberasoftware.base.BaseConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
/** | ||
* @author renarj | ||
*/ | ||
@Configuration | ||
@ComponentScan | ||
@Import(BaseConfiguration.class) | ||
public class ZWaveConfiguration { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/main/java/com/oberasoftware/home/zwave/api/events/Subscribe.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
src/main/java/com/oberasoftware/home/zwave/converter/ActionConverterBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.oberasoftware.home.zwave.converter; | ||
|
||
import com.oberasoftware.home.zwave.messages.ZWaveRawMessage; | ||
import com.oberasoftware.home.zwave.messages.types.CommandClass; | ||
import com.oberasoftware.home.zwave.messages.types.ControllerMessageType; | ||
import com.oberasoftware.home.zwave.messages.types.MessageType; | ||
import com.oberasoftware.home.zwave.threading.ActionConvertedEvent; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
/** | ||
* @author renarj | ||
*/ | ||
public class ActionConverterBuilder { | ||
private static final Logger LOG = getLogger(ActionConverterBuilder.class); | ||
|
||
private final List<Byte> payload = new ArrayList<>(); | ||
private final Optional<Integer> nodeId; | ||
private final ControllerMessageType controllerMessageType; | ||
private final MessageType messageType; | ||
|
||
private Optional<Integer> callbackId = Optional.empty(); | ||
|
||
public ActionConverterBuilder(Optional<Integer> nodeId, ControllerMessageType controllerMessageType, MessageType messageType) { | ||
this.nodeId = nodeId; | ||
this.controllerMessageType = controllerMessageType; | ||
this.messageType = messageType; | ||
} | ||
|
||
public static ActionConverterBuilder create(ControllerMessageType controllerMessageType, MessageType messageType) { | ||
return new ActionConverterBuilder(Optional.empty(), controllerMessageType, messageType); | ||
} | ||
|
||
public static ActionConverterBuilder create(ControllerMessageType controllerMessageType, MessageType messageType, int nodeId) { | ||
return new ActionConverterBuilder(Optional.of(nodeId), controllerMessageType, messageType); | ||
} | ||
|
||
public ActionConverterBuilder callback(int callbackId) { | ||
this.callbackId = Optional.of(callbackId); | ||
return this; | ||
} | ||
|
||
public ActionConverterBuilder addByte(byte b) { | ||
payload.add(b); | ||
|
||
return this; | ||
} | ||
|
||
public ActionConverterBuilder addInt(int i) { | ||
payload.add((byte)i); | ||
return this; | ||
} | ||
|
||
public ActionConverterBuilder addCommandClass(CommandClass commandClass) { | ||
addInt(commandClass.getClassCode()); | ||
return this; | ||
} | ||
|
||
public ActionConvertedEvent construct() { | ||
ZWaveRawMessage message; | ||
//we get the initial payload lenght without any potential nodeId | ||
int payloadLenght = payload.size(); | ||
|
||
if(nodeId.isPresent()) { | ||
message = new ZWaveRawMessage(nodeId.get(), controllerMessageType, messageType); | ||
//in case a nodeId is known this will always be the first byte | ||
payload.add(0, nodeId.get().byteValue()); | ||
} else { | ||
message = new ZWaveRawMessage(controllerMessageType, messageType); | ||
} | ||
if(callbackId.isPresent()) { | ||
message.setCallbackId(callbackId.get()); | ||
} | ||
|
||
if(payloadLenght != 0) { | ||
//when there is a payload we specify the length, this is always the 2nd byte | ||
payload.add(1, (byte) payloadLenght); | ||
} | ||
|
||
//It could be an empty payload in case of controller messages | ||
if(!payload.isEmpty()) { | ||
byte[] buffer = new byte[payload.size()]; | ||
for (int i = 0; i < payload.size(); i++) { | ||
buffer[i] = payload.get(i); | ||
} | ||
message.setMessage(buffer); | ||
} | ||
|
||
LOG.trace("Message converted: {}", message); | ||
|
||
return new ActionConvertedEvent(message); | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/main/java/com/oberasoftware/home/zwave/converter/ConverterFactory.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.