List of usage examples for java.lang Short reverseBytes
@HotSpotIntrinsicCandidate public static short reverseBytes(short i)
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public Status leaveSync(long timeout, Address addrOfInterest, int mask) throws Exception { ByteArrayObject _res = new ByteArrayObject(); _res.addBytesShort(Short.reverseBytes(addrOfInterest.getNetworkAddress().shortValue()), 2);/* * Short * Network * Address */ byte[] deviceAddress = DataManipulation .toByteVect(gal.get_GalNode().get_node().getAddress().getNetworkAddress(), 8); byte[] _reversed = DataManipulation.reverseBytes(deviceAddress); for (byte b : _reversed) _res.addByte(b);/*from w ww .j av a2s . c o m*/ byte options = 0; options = (byte) (options & GatewayConstants.LEAVE_REJOIN); options = (byte) (options & GatewayConstants.LEAVE_REMOVE_CHILDERN); _res.addByte(options); _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPMgmtLeaveRequest);/* * StartSequence * + * Control */ if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Leave command:" + _res.ToHexString()); } addToSendDataQueue(_res); if (addrOfInterest.getIeeeAddress() == null) { BigInteger _add = gal.getIeeeAddress_FromNetworkCache(addrOfInterest.getNetworkAddress()); if (_add != null) addrOfInterest.setIeeeAddress(_add); } if (addrOfInterest.getIeeeAddress() != null) { Status _st = ClearDeviceKeyPairSet(timeout, addrOfInterest); if (_st.getCode() == GatewayConstants.SUCCESS) ClearNeighborTableEntry(timeout, addrOfInterest); } Status status = new Status(); status.setCode((short) GatewayConstants.SUCCESS); return status; }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public ServiceDescriptor getServiceDescriptor(long timeout, Address addrOfInterest, short endpoint) throws IOException, Exception, GatewayException { ByteArrayObject _res = new ByteArrayObject(); _res.addBytesShort(Short.reverseBytes(addrOfInterest.getNetworkAddress().shortValue()), 2);/* ShortNetworkAddress */ _res.addBytesShort(Short.reverseBytes(addrOfInterest.getNetworkAddress().shortValue()), 2);/* ShortNetworkAddress */ _res.addByte((byte) endpoint);/* EndPoint */ _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPSimpleDescriptorRequest);/* * StartSequence * + * Control */ String Key = String.format("%04X", addrOfInterest.getNetworkAddress()) + String.format("%02X", endpoint); ParserLocker lock = new ParserLocker(); lock.setType(TypeMessage.GET_SIMPLE_DESCRIPTOR); lock.set_Key(Key);/*from w w w. j ava 2s .co m*/ Status status = null; try { synchronized (listLocker) { listLocker.add(lock); } addToSendDataQueue(_res); synchronized (lock) { try { lock.wait(timeout); } catch (InterruptedException e) { } } status = lock.getStatus(); synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } catch (Exception e) { synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } if (status.getCode() == ParserLocker.INVALID_ID) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.error("Timeout expired in ZDP-SimpleDescriptor.Request"); } throw new GatewayException("Timeout expired in ZDP-SimpleDescriptor.Request"); } else { if (status.getCode() != 0) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Returned Status: " + status.getCode()); } throw new GatewayException("Error on ZDP-SimpleDescriptor.Request. Status code:" + status.getCode() + " Status Message: " + status.getMessage()); } else { ServiceDescriptor _tores = (ServiceDescriptor) lock.get_objectOfResponse(); return _tores; } } }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public BindingList getNodeBindings(long timeout, Address addrOfInterest, short index) throws IOException, Exception, GatewayException { ByteArrayObject _res = new ByteArrayObject(); if (addrOfInterest.getNetworkAddress() == null) addrOfInterest.setNetworkAddress(gal.getShortAddress_FromNetworkCache(addrOfInterest.getIeeeAddress())); _res.addBytesShort(Short.reverseBytes(addrOfInterest.getNetworkAddress().shortValue()), 2);/* ShortNetworkAddress */ _res.addByte((byte) index);/* startIndex */ _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPMgmtBindRequest);/* * StartSequence * + * Control */ ParserLocker lock = new ParserLocker(); lock.setType(TypeMessage.GET_BINDINGS); Status status = null;/*from w w w.java2 s .c o m*/ try { synchronized (listLocker) { listLocker.add(lock); } addToSendDataQueue(_res); synchronized (lock) { try { lock.wait(timeout); } catch (InterruptedException e) { } } status = lock.getStatus(); synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } catch (Exception e) { synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } if (status.getCode() == ParserLocker.INVALID_ID) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.error("Timeout expired in ZDP-Mgmt_Bind.Request"); } throw new GatewayException("Timeout expired in ZDP-Mgmt_Bind.Request"); } else { if (status.getCode() != 0) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Returned Status: " + status.getCode()); } throw new GatewayException("Error on ZDP-Mgmt_Bind.Request. Status code:" + status.getCode() + " Status Message: " + status.getMessage()); } else { BindingList _tores = (BindingList) lock.get_objectOfResponse(); return _tores; } } }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public Status addBinding(long timeout, Binding binding) throws IOException, Exception, GatewayException { byte[] _reversed; ByteArrayObject _res = new ByteArrayObject(); _res.addBytesShort(Short.reverseBytes( gal.getShortAddress_FromNetworkCache(binding.getSourceIEEEAddress()).shortValue()), 2); byte[] ieeeAddress = DataManipulation.toByteVect(binding.getSourceIEEEAddress(), 8); _reversed = DataManipulation.reverseBytes(ieeeAddress); for (byte b : _reversed) /* Source IEEEAddress */ _res.addByte(b);/*from ww w . j av a2s .co m*/ _res.addByte((byte) binding.getSourceEndpoint());/* Source EndPoint */ Integer _clusterID = binding.getClusterID(); _res.addBytesShort(Short.reverseBytes(_clusterID.shortValue()), 2);/* ClusterID */ if (binding.getDeviceDestination().size() > 0 && binding.getGroupDestination().size() > 0) throw new GatewayException("The Address mode can only be one between Group or Device!"); else if (binding.getDeviceDestination().size() == 1) { _res.addByte((byte) 0x03);/* * Destination AddressMode IeeeAddress + * EndPoint */ byte[] _DestinationieeeAddress = DataManipulation .toByteVect(binding.getDeviceDestination().get(0).getAddress(), 8); _reversed = DataManipulation.reverseBytes(_DestinationieeeAddress); for (byte b : _reversed) /* Destination IEEEAddress */ _res.addByte(b); _res.addByte((byte) binding.getDeviceDestination().get(0).getEndpoint());/* * Destination * EndPoint */ } else if (binding.getGroupDestination().size() == 1) { _res.addByte((byte) 0x01);/* Destination AddressMode Group */ byte[] _DestinationGroupAddress = DataManipulation .toByteVect(binding.getGroupDestination().get(0).longValue(), 8); _reversed = DataManipulation.reverseBytes(_DestinationGroupAddress); for (byte b : _reversed) /* Destination Group */ _res.addByte(b); } else { throw new GatewayException("The Address mode can only be one Group or one Device!"); } _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPBindRequest);/* * StartSequence * + * Control */ ParserLocker lock = new ParserLocker(); lock.setType(TypeMessage.ADD_BINDING); Status status = null; try { synchronized (listLocker) { listLocker.add(lock); } addToSendDataQueue(_res); synchronized (lock) { try { lock.wait(timeout); } catch (InterruptedException e) { } } status = lock.getStatus(); synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } catch (Exception e) { synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } if (status.getCode() == ParserLocker.INVALID_ID) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.error("Timeout expired in ZDP-BIND.Response"); } throw new GatewayException("Timeout expired in ZDP-BIND.Request"); } else { if (status.getCode() != 0) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Returned Status: " + status.getCode()); } throw new GatewayException("Error on ZDP-BIND.Request. Status code:" + status.getCode() + " Status Message: " + status.getMessage()); } else { return lock.getStatus(); } } }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public Status removeBinding(long timeout, Binding binding) throws IOException, Exception, GatewayException { byte[] _reversed; ByteArrayObject _res = new ByteArrayObject(); _res.addBytesShort(Short.reverseBytes( gal.getShortAddress_FromNetworkCache(binding.getSourceIEEEAddress()).shortValue()), 2); byte[] ieeeAddress = DataManipulation.toByteVect(binding.getSourceIEEEAddress(), 8); _reversed = DataManipulation.reverseBytes(ieeeAddress); for (byte b : _reversed) /* Source IEEEAddress */ _res.addByte(b);/* w ww . ja v a2 s . co m*/ _res.addByte((byte) binding.getSourceEndpoint());/* Source EndPoint */ Integer _clusterID = binding.getClusterID(); _res.addBytesShort(Short.reverseBytes(_clusterID.shortValue()), 2);/* ClusterID */ if (binding.getDeviceDestination().size() > 0 && binding.getGroupDestination().size() > 0) throw new GatewayException("The Address mode can only be one between Group or Device!"); else if (binding.getDeviceDestination().size() == 1) { _res.addByte((byte) 0x03);/* * Destination AddressMode IeeeAddress + * EndPoint */ byte[] _DestinationieeeAddress = DataManipulation .toByteVect(binding.getDeviceDestination().get(0).getAddress(), 8); _reversed = DataManipulation.reverseBytes(_DestinationieeeAddress); for (byte b : _reversed) /* Destination IEEEAddress */ _res.addByte(b); _res.addByte((byte) binding.getDeviceDestination().get(0).getEndpoint());/* * Destination * EndPoint */ } else if (binding.getGroupDestination().size() == 1) { _res.addByte((byte) 0x01);/* Destination AddressMode Group */ byte[] _DestinationGroupAddress = DataManipulation .toByteVect(binding.getGroupDestination().get(0).longValue(), 8); _reversed = DataManipulation.reverseBytes(_DestinationGroupAddress); for (byte b : _reversed) /* Destination Group */ _res.addByte(b); } else { throw new GatewayException("The Address mode can only be one Group or one Device!"); } _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPUnbindRequest);/* * StartSequence * + * Control */ ParserLocker lock = new ParserLocker(); lock.setType(TypeMessage.REMOVE_BINDING); Status status = null; try { synchronized (listLocker) { listLocker.add(lock); } addToSendDataQueue(_res); synchronized (lock) { try { lock.wait(timeout); } catch (InterruptedException e) { } } status = lock.getStatus(); synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } catch (Exception e) { synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } if (status.getCode() == ParserLocker.INVALID_ID) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.error("Timeout expired in ZDP-UNBIND.Response"); } throw new GatewayException("Timeout expired in ZDP-UNBIND.Request"); } else { if (status.getCode() != 0) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Returned Status: " + status.getCode()); } throw new GatewayException("Error on ZDP-UNBIND.Request. Status code:" + status.getCode() + " Status Message: " + status.getMessage()); } else { return lock.getStatus(); } } }
From source file:org.energy_home.jemma.javagal.layers.data.implementations.IDataLayerImplementation.DataFreescale.java
@Override public Mgmt_LQI_rsp Mgmt_Lqi_Request(long timeout, Address addrOfInterest, short startIndex) throws IOException, Exception, GatewayException { ByteArrayObject _res = new ByteArrayObject(); _res.addBytesShort(Short.reverseBytes(addrOfInterest.getNetworkAddress().shortValue()), 2); _res.addByte((byte) startIndex); _res = Set_SequenceStart_And_FSC(_res, FreescaleConstants.ZDPMgmtLqiRequest); if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Mgmt_Lqi_Request command:" + _res.ToHexString()); }/* ww w.j ava2 s . com*/ String __Key = String.format("%04X", addrOfInterest.getNetworkAddress()); ParserLocker lock = new ParserLocker(); lock.setType(TypeMessage.LQI_REQ); lock.set_Key(__Key); Status status = null; try { synchronized (listLocker) { listLocker.add(lock); } addToSendDataQueue(_res); synchronized (lock) { try { lock.wait(timeout); } catch (InterruptedException e) { } } status = lock.getStatus(); synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } catch (Exception e) { synchronized (listLocker) { if (listLocker.contains(lock)) listLocker.remove(lock); } } if (status.getCode() == ParserLocker.INVALID_ID) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.error("Timeout expired in ZDP-Mgmt_Lqi.Request"); } throw new GatewayException("Timeout expired in ZDP-Mgmt_Lqi.Request"); } else { if (status.getCode() != 0) { if (gal.getPropertiesManager().getDebugEnabled()) { logger.info("Returned Status: " + status.getCode()); } throw new GatewayException("Error on ZDP-Mgmt_Lqi.Request. Status code:" + status.getCode() + " Status Message: " + status.getMessage()); } return (Mgmt_LQI_rsp) lock.get_objectOfResponse(); } }