List of usage examples for org.apache.commons.net.util Base64 decodeBase64
public static byte[] decodeBase64(byte[] base64Data)
From source file:org.openhab.binding.max.internal.command.S_CommandTest.java
@Test public void BaseCommandTest() { S_Command scmd = new S_Command("0b0da3", 1, ThermostatModeType.MANUAL, 20.0); String commandStr = scmd.getCommandString(); String base64Data = commandStr.substring(3); byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF;/*from ww w.j a v a 2 s.c o m*/ } String decodedString = Utils.toHex(data); assertEquals("s:AARAAAAACw2jAWg=\r\n", commandStr); assertEquals("011000000002C368C05A", decodedString); }
From source file:org.openhab.binding.max.internal.command.TCommandTest.java
@Test public void BaseCommandTest() { TCommand scmd = new TCommand("0f1d54", false); String commandStr = scmd.getCommandString(); String base64Data = commandStr.split(",")[2]; byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF;// w w w .j av a2 s .c om } String decodedString = Utils.toHex(data); assertEquals("t:01,0,Dx1U\r\n", commandStr); assertEquals("0F1D54", decodedString); }
From source file:org.openhab.binding.max.internal.command.TCommandTest.java
@Test public void AddRoomTest() { TCommand scmd = new TCommand("0f1d54", false); scmd.addRoom("0b0da3"); String commandStr = scmd.getCommandString(); String base64Data = commandStr.split(",")[2]; byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF;//from w ww . ja v a 2 s . c o m } String decodedString = Utils.toHex(data); assertEquals("t:02,0,Cw2jDx1U\r\n", commandStr); assertEquals("0B0DA30F1D54", decodedString); }
From source file:org.openhab.binding.max.internal.command.T_CommandTest.java
@Test public void BaseCommandTest() { T_Command scmd = new T_Command("0f1d54", false); String commandStr = scmd.getCommandString(); String base64Data = commandStr.split(",")[2]; byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF;/*ww w .j a v a 2 s .c o m*/ } String decodedString = Utils.toHex(data); assertEquals("t:01,0,Dx1U\r\n", commandStr); assertEquals("0F1D54", decodedString); }
From source file:org.openhab.binding.max.internal.command.T_CommandTest.java
@Test public void AddRoomTest() { T_Command scmd = new T_Command("0f1d54", false); scmd.addRoom("0b0da3"); String commandStr = scmd.getCommandString(); String base64Data = commandStr.split(",")[2]; byte[] bytes = Base64.decodeBase64(base64Data.getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF;/*from w ww .jav a 2s . co m*/ } String decodedString = Utils.toHex(data); assertEquals("t:02,0,Cw2jDx1U\r\n", commandStr); assertEquals("0B0DA30F1D54", decodedString); }
From source file:org.openhab.binding.max.internal.message.CMessage.java
public CMessage(String raw) { super(raw);/*from w ww . j av a 2 s .c o m*/ String[] tokens = this.getPayload().split(Message.DELIMETER); rfAddress = tokens[0]; byte[] bytes = Base64.decodeBase64(tokens[1].getBytes(StandardCharsets.UTF_8)); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF; } length = data[0]; if (length != data.length - 1) { logger.debug("C Message malformed: wrong data length. Expected bytes {}, actual bytes {}", length, data.length - 1); } String rfAddress2 = Utils.toHex(data[1], data[2], data[3]); if (!rfAddress.toUpperCase().equals(rfAddress2.toUpperCase())) { logger.debug("C Message malformed: wrong RF address. Expected address {}, actual address {}", rfAddress.toUpperCase(), rfAddress2.toUpperCase()); } deviceType = DeviceType.create(data[4]); roomId = data[5] & 0xFF; serialNumber = getSerialNumber(bytes); if (deviceType == DeviceType.HeatingThermostatPlus || deviceType == DeviceType.HeatingThermostat || deviceType == DeviceType.WallMountedThermostat) { parseHeatingThermostatData(bytes); } if (deviceType == DeviceType.Cube) { parseCubeData(bytes); } if (deviceType == DeviceType.EcoSwitch || deviceType == DeviceType.ShutterContact) { logger.trace("Device {} type {} Data: '{}'", rfAddress, deviceType, parseData(bytes)); } }
From source file:org.openhab.binding.max.internal.message.C_Message.java
public C_Message(String raw) { super(raw);/*from w w w . j a v a 2 s . c om*/ String[] tokens = this.getPayload().split(Message.DELIMETER); rfAddress = tokens[0]; byte[] bytes = Base64.decodeBase64(tokens[1].getBytes()); int[] data = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { data[i] = bytes[i] & 0xFF; } length = data[0]; if (length != data.length - 1) { logger.debug("C_Message malformed: wrong data length. Expected bytes {}, actual bytes {}", length, data.length - 1); } String rfAddress2 = Utils.toHex(data[1], data[2], data[3]); if (!rfAddress.toUpperCase().equals(rfAddress2.toUpperCase())) { logger.debug("C_Message malformed: wrong RF address. Expected address {}, actual address {}", rfAddress.toUpperCase(), rfAddress2.toUpperCase()); } deviceType = DeviceType.create(data[4]); serialNumber = getSerialNumber(bytes); if (deviceType == DeviceType.HeatingThermostatPlus || deviceType == DeviceType.HeatingThermostat || deviceType == DeviceType.WallMountedThermostat) parseHeatingThermostatData(bytes); if (deviceType == DeviceType.EcoSwitch || deviceType == DeviceType.ShutterContact) logger.trace("Device {} type {} Data:", rfAddress, deviceType.toString(), parseData(bytes)); }
From source file:org.openhab.binding.max.internal.message.LMessage.java
public Collection<? extends Device> getDevices(List<DeviceConfiguration> configurations) { final List<Device> devices = new ArrayList<>(); final byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes(StandardCharsets.UTF_8)); final MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); while (tokenizer.hasMoreElements()) { byte[] token = tokenizer.nextElement(); final Device tempDevice = Device.create(token, configurations); if (tempDevice != null) { devices.add(tempDevice);// ww w .j a v a 2 s. co m } } return devices; }
From source file:org.openhab.binding.max.internal.message.LMessage.java
public Collection<? extends Device> updateDevices(List<Device> devices, List<DeviceConfiguration> configurations) { byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes(StandardCharsets.UTF_8)); MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); while (tokenizer.hasMoreElements()) { byte[] token = tokenizer.nextElement(); String rfAddress = Utils.toHex(token[0] & 0xFF, token[1] & 0xFF, token[2] & 0xFF); // logger.debug("token: "+token+" rfaddress: "+rfAddress); Device foundDevice = null;/*w w w .ja v a 2s . c om*/ for (Device device : devices) { // logger.debug(device.getRFAddress().toUpperCase()+ " vs "+rfAddress); if (device.getRFAddress().toUpperCase().equals(rfAddress)) { // logger.debug("Updating device..."+rfAddress); foundDevice = device; } } if (foundDevice != null) { foundDevice = Device.update(token, configurations, foundDevice); // devices.remove(token); // devices.add(foundDevice); } else { Device tempDevice = Device.create(token, configurations); if (tempDevice != null) { devices.add(tempDevice); } } } return devices; }
From source file:org.openhab.binding.max.internal.message.L_Message.java
public Collection<? extends Device> getDevices(List<DeviceConfiguration> configurations) { List<Device> devices = new ArrayList<Device>(); byte[] decodedRawMessage = Base64.decodeBase64(getPayload().getBytes()); MaxTokenizer tokenizer = new MaxTokenizer(decodedRawMessage); while (tokenizer.hasMoreElements()) { byte[] token = tokenizer.nextElement(); Device tempDevice = Device.create(token, configurations); if (tempDevice != null) { devices.add(tempDevice);// w w w . java2s. c o m } } return devices; }