Chapter 25 - Create Your Device Discovery Response

  1. Depending on whether you created a special discover request BYourDriverDeviceDiscoverRequest or whether you are having your driver's ping request BYourDriverPingRequest also serve as the discovery request, you should follow either A or B but not both.

    A. If you created a class named BYourDriverDeviceDiscoverRequest in the previous chapters of the day's lesson:

    Create a class named BYourDriverDeviceDiscoveryResponse that extends BDdfResponse and implements BIDdfDiscoverResponse. Create this class in the package com.yourCompany.yourDriver.comm.rsp.

    package com.yourCompany.yourDriver.comm.rsp;
    
    import com.tridium.ddf.comm.rsp.*;
    import javax.baja.sys.*;
    
    public class BYourDriverDeviceDiscoverResponse
      extends BDdfResponse
      implements BIDdfDiscoverResponse
    {
      /*-
      class BYourDriverDeviceDiscoverResponse
      {
      }
      -*/
    }
    

    B. If you decided to have your driver's ping request and device id also serve as the discover request/discover parameters:

    Update the class declaration for BYourDriverPingResponse and declare it so that it implements BIDdfDiscoverResponse. Also add a statement to import com.tridium.ddf.discover.*.

    package com.yourCompany.yourDriver.comm.rsp;
    
    import com.tridium.ddf.comm.*;
    import com.tridium.ddf.discover.*;
    
    import javax.baja.sys.*;
    
    public class BYourDriverPingResponse
      extends BDdfResponse
      implements BIDdfDiscoverResponse
    {
      ...
    }
    

  2. In either case, please proceed as follows.
  3. Define the getDiscoveryChildren method on the device discovery response. This is a requirement of the BIDdfDiscoverResponse interface.

        /**
         * This method parses the response byte array and returns an
         * array of BYourDriverDeviceId objects describing the devices
         * that this response is able to identify. This is called during
         * the auto discovery process.
         */
        public BIDdfDiscoveryObject[] parseDiscoveryObjects(Context c)
        {
          return null;
        }
    

  4. The parseDiscoveryObjects method should return an array of BIDdfDiscoveryObject structures that describe the field-devices that are identified in the response bytes. We recommend that you return an array of BYourDriverDeviceId objects. It just so happens that BYourDriverDeviceId objects already implement BIDdfDiscoveryObject (since BYourDriverDeviceId extends BDdfIdParams which implements BIDdfDiscoveryObject).

        /**
         * In our hypothetical protocol, we know that by receiving any
         * response to the ping request than the deviceId of the transaction
         * represents a device that is online.
         */
        public BIDdfDiscoveryObject[] parseDiscoveryObjects(Context c)
        { // Returns an array of size one, containing just the deviceId
          // Of the response. Please note that for drivers that are not
          // Re-using the ping request as a discovery request, then this
          // Method should parse through the response bytes and make an
          // Array of BYourDriverDeviceId whose length corresponds to
          // The number of device entries that you determine are present
          // In the response bytes. Then assign each BYourDriverDeviceId
          // Entry in the array based on what you are able to parse from
          // The response bytes.
          return new BIDdfDiscoveryObject[]{
            (BIDdfDiscoveryObject)getDeviceId().newCopy()
          };
        }