Chapter 24 - Create Your Device Discovery Request

In the previous chapter you reviewed your driver's protocol in search of a protocol request that retrieves information about multiple field-devices. If you were able to find such a request, we will ask you to create a corresponding request class for your driver. If you were unable to find such a request, and if your driver uses a serial, master-slave protocol, then we will ask you update your driver's ping request and ping response classes to make them also serve as the discover request and discover response.


A. If you created a BYourDriverDeviceDiscoverParams class in the previous chapter:
  1. Create a class named BYourDriverDeviceDiscoverRequest that extends BDdfDiscoveryRequest in the package com.yourCompany.yourDriver.comm.req
  2. Define the toByteArray method. In the toByteArray method, call getDiscoverParameters() and cast the result to BYourDriverDeviceDiscoverParams. Most of the information that you need will be available in this instance of your driver's BYourDriverDeviceDiscoverParams class. You created this class in the previous chapter.

    package com.yourCompany.yourDriver.comm.req;
    
    import com.tridium.ddf.identify.*;
    import com.tridium.ddf.comm.req.*;
    import javax.baja.sys.*;
    
    public class BYourDriverDeviceDiscoverRequest
      extends BDdfDiscoveryRequest
    {
      /*-
      class BYourDriverDeviceDiscoverRequest
      {
      }
      -*/
    
      public byte[] toByteArray()
      {
        BYourDriverDeviceDiscoverParams devDscvParams =
          (BYourDriverDeviceDiscoverParams)getDiscoverParameters();
    
        return new byte[]{
          //...
          // Substitute value1 and value2 with your own properties
          (byte)devDscvParams.getValue1(),
          (byte)devDscvParams.getValue2(),
          //...
        }
      }
    

  3. Update BYourDriverDeviceDiscoverParams (from the previous chapter) - Finish defining the following method:

        public Type getDiscoverRequestType()
        {
          return BYourDriverDeviceDiscoverRequest.TYPE
        }
    


B. If you modified the BYourDriverDeviceId class in the previous chapter to serve in the device discovery:
  1. Modify the declaration of BYourDriverPingRequest and make it implement BIDdfDiscoverRequest. Also make it import the following additional packages:

    ...
    
    import com.tridium.ddf.discover.*;
    import com.tridium.ddf.identify.*;
    
    ...
    
    public class BTestDriverPingRequest
      extends BDdfPingRequest
      implements BIDdfDiscoverRequest
    {
     ...
    }
    

  2. Add the following property to the slotomatic statement of BYourDriverDevicePingRequest

      /*-
      class BYourDriverPingRequest
      {
        properties
        {
          ...
          discoverParameters : BDdfIdParams
             -- This provides the necessary data that the toByteArray method
             -- Needs in order to construct the byte array.
             -- NOTE: During auto-discovery, the auto discovery job loops
             -- through all possible combinations of discoverParameters. Each
             -- pass through the loop, the next discoverParameters value for
             -- your driver is passed to this property. When you implement
             -- the toByteArray method, you may cast this to your own
             -- discoveryParameters class (that is what it will ultimately be).
            default{[new BYourDriverDeviceId()]}
          ...
        }
    
      }
      -*/
    

  3. Add the following methods to BYourDriverDevicePingRequest. Please add them exactly as-is. You shouldn't need to modify these methods, except maybe to change the comments.

      /**
       * The setDiscoverer method will be passed an instance of
       * IDdfDiscoverer. You need to retain the reference on
       * the instance and return it (whenever requested) from
       * the getDiscoverer method.
       */
      IDdfDiscoverer discoverer = null;
      /**
       * The BDdfAutoDiscoveryJob will pass an inner instance
       * of itself to the setDiscoverer method. In there, you
       * need to save away the reference. In here, please return
       * the most recent reference that was passed to the
       * setDiscoverer method.
       */
      public IDdfDiscoverer getDiscoverer(){return discoverer;}
      /**
       * The BDdfAutoDiscoveryJob will pass an inner instance
       * of itself here. Please save away the reference. Other
       * than that, you should not need to concern yourself
       * with this.
       */
      public void setDiscoverer(IDdfDiscoverer discoverer)
      {
        this.discoverer=discoverer;
      }