commit 16/06/2025
This commit is contained in:
43
src/pa/VX3K.java
Normal file
43
src/pa/VX3K.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package pa;
|
||||
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class VX3K {
|
||||
private final InetSocketAddress inetSocketAddress;
|
||||
|
||||
public VX3K(String ipaddress, int port){
|
||||
this.inetSocketAddress = new InetSocketAddress(ipaddress, port);
|
||||
}
|
||||
|
||||
public void PseudoContactInput(VX3KPseudoContactInput input, @NonNull Consumer<@NonNull VX3KCommandResult> callback){
|
||||
|
||||
try(SocketChannel channel = SocketChannel.open(inetSocketAddress)){
|
||||
channel.write(input.getBuffer());
|
||||
input.getBuffer().clear();
|
||||
int read = channel.read(input.getBuffer());
|
||||
if (read>0){
|
||||
short command = input.getBuffer().getShort(0);
|
||||
short responsecode = input.getBuffer().getShort(1);
|
||||
if (command == input.getCommandID()){
|
||||
if (responsecode == 0x0000){
|
||||
callback.accept(new VX3KCommandResult(input.getCommandID(), true, "success"));
|
||||
} else callback.accept(new VX3KCommandResult(input.getCommandID(), false , "Code:"+responsecode ));
|
||||
} else callback.accept(new VX3KCommandResult(input.getCommandID(), false, "Invalid CommandID reply"));
|
||||
} else callback.accept( new VX3KCommandResult(input.getCommandID(), false, "Read 0"));
|
||||
} catch (Exception e){
|
||||
Logger.error("PseudoContactInput failed, Message {}", e.getMessage());
|
||||
callback.accept(new VX3KCommandResult(input.getCommandID(), false, "Exception"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user