private int restart ( final boolean basic , final Destination dst , final int eraseCode , final int channel ) throws KNXTimeoutException , KNXRemoteException , KNXLinkClosedException , KNXDisconnectException , InterruptedException { int time = 0 ; if ( basic ) { send ( dst , priority , DataUnitBuilder . createLengthOptimizedAPDU ( RESTART , null ) , 0 ) ; } else { final byte [ ] sdu = new byte [ ] { 0x01 , ( byte ) eraseCode , ( byte ) channel , } ; final byte [ ] send = DataUnitBuilder . createLengthOptimizedAPDU ( RESTART , sdu ) ; final byte [ ] apdu = sendWait2 ( dst , priority , send , RESTART , 3 , 3 ) ; // check we get a restart response if ( ( apdu [ 1 ] & 0x32 ) == 0 ) throw new KNXInvalidResponseException ( "restart response bit not set" ) ; // defined error codes: 0,1,2,3 final String [ ] codes = new String [ ] { "Success" , "Access Denied" , "Unsupported Erase Code" , "Invalid Channel Number" , "Unknown Error" } ; final int error = Math . min ( apdu [ 2 ] & 0xff , 4 ) ; if ( error > 0 ) throw new KNXRemoteException ( "master reset: " + codes [ error ] ) ; time = ( ( apdu [ 3 ] & 0xff ) << 8 ) | ( apdu [ 4 ] & 0xff ) ; } if ( dst . isConnectionOriented ( ) ) { // a remote endpoint is allowed to not send a TL disconnect before restart, but // a TL disconnect timeout shall not be treated as protocol error final Object lock = new Object ( ) ; final TransportListener l = new TLListener ( ) { @ Override public void disconnected ( final Destination d ) { if ( d . equals ( dst ) ) synchronized ( lock ) { lock . notify ( ) ; } } ; } ; tl . addTransportListener ( l ) ; try { synchronized ( lock ) { while ( dst . getState ( ) != Destination . State . Disconnected ) lock . wait ( ) ; } } finally { tl . removeTransportListener ( l ) ; } // always force a disconnect from our side tl . disconnect ( dst ) ; } return time ; }
for erase codes 1 3 4 the channel should be 0