View on GitHub

fhnw-bacnet-it.github.io

Github Pages

Create a Demo Application using the Directory Service.

Go back to start page

The project directory-binding-dnssd provides a DNSSD directory binding implementation.
Instead of using the DNSSD binding, we will implement a DummyDirectoryBinding in this example.
The ch.fhnw.bacnetit.ase.network.directory.api.DirectoryService class is the directory interface used by applications and bacnet devices.
All directory bindings implement the ch.fhnw.bacnetit.ase.network.directory.api.DirectoryBinding interface.

import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import ch.fhnw.bacnetit.ase.encoding.api.BACnetEID;
import ch.fhnw.bacnetit.ase.network.directory.api.DirectoryBinding;

// All directory bindings have to implement the DirectoryBinding interface
public class DummyDirectoryBinding implements DirectoryBinding {
    
    // BACnetEID of bds
    private volatile BACnetEID bds = null;
    // Records
    private volatile Map<BACnetEID, URI> records = new ConcurrentHashMap<BACnetEID,URI>();
    
    public DummyDirectoryBinding(){
        
        // Thread to print the current state of records.
        new Thread(new Runnable(){
            @Override
            public void run() {
                
                while(true){
                    StringBuffer sb = new StringBuffer();
                    for (Entry<BACnetEID, URI> entry : records.entrySet()) {
                        sb.append(entry.getKey().getIdentifierAsString()+"->"+entry.getValue()+"\n****\n");
                    }
                    System.out.println("DirectoryBinding:\nBDS:" + ((bds!=null) ? bds.getIdentifierAsString():"not set")+"\n"+sb.toString());
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    @Override
    public void delete(BACnetEID arg0) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public List<BACnetEID> findBDS() {
        if (this.bds != null ){
            List<BACnetEID> bdss = new LinkedList<BACnetEID>();
            bdss.add(bds);
            return bdss;
        }
        return null;
    }

    @Override
    public void register(BACnetEID bacnetEID, URI uri, boolean isBds) {
        if (bacnetEID == null)
                return;
        if (isBds && this.bds == null){
            this.bds = bacnetEID;
            System.out.println("BDS set");
        }
        // Overwrite existing values
        records.put(bacnetEID, uri);
       
        
    }

    @Override
    public void registerObject(String arg0, boolean arg1, String arg2,
            BACnetEID arg3, String arg4, int arg5, int arg6) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public URI resolve(BACnetEID bacnetEID) {
        return this.records.get(bacnetEID);
    }
}
                // Device 1001 of application 1 is BDS. Therefore it has to handle remote directory register requests
                else if (incoming instanceof ConfirmedRequest && ((ConfirmedRequest)incoming).getServiceRequest() instanceof AddListElementRequest){
                    SequenceOf<?> charcterStrings = ((AddListElementRequest)((ConfirmedRequest)incoming).getServiceRequest()).getListOfElements();
                    System.out.println("BDS got an AddListElementRequest");
                    for (Encodable cs : charcterStrings ) {
                        try {
                            DirectoryService.getInstance().register(arg0.getData().getSourceEID(), new URI(cs.toString()), false, false);
                        } catch (URISyntaxException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }

Go to Build from source