Network Discovery using C-Bus Module

Discussion in 'General Discussion' started by Valery R., Sep 26, 2005.

  1. Valery R.

    Valery R.

    Joined:
    Sep 7, 2004
    Messages:
    27
    Likes Received:
    0
    I want to scan the network and find units, their addresses etc, using the cbus_discovery_ functions.

    I've set the discovery parameters (cbus_discovery_vf_set_parameters(CBUS_DISCOVERY_UNIT_TYPE|CBUS_DISCOVERY_GROUPS)), registered a handler (discovery_handler(int8u network, int8u unit_address, int16u parameter, int8u *parameter_data, int8u byte_count)) and initiated discovery (cbus_discovery_vf_initiate(0)).

    But when I read the parameter_data (in registered handler) I get only one first byte. So, for example for DIMDM8, I get: UNIT_TYPE - 68 (ASCII "D"), GROUPS - 4 (the first one in the list).
    And I don't know how to get the other 7 bytes.

    Valery R.
     
    Valery R., Sep 26, 2005
    #1
  2. Valery R.

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,391
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Here is some example code for a discovery handler:

    Code:
    /****************************************************************************
     * Append formatted text to a string. Something sprintf cannot do.
     ****************************************************************************/
    static int asprintf(char *cp_buffer,
                        const char *cp_format,
                        ...)
    {
      va_list p_args;
      int     i_count;
    
      va_start(p_args, cp_format);
      i_count = vsprintf(&cp_buffer[strlen(cp_buffer)],
                         cp_format,
                         p_args);
      va_end(p_args);
      return i_count;
    }
    
    
    /****************************************************************************
     * The discovery handler
     ****************************************************************************/
    static void discovery_parameter_handler(int8u network,
                                            int8u unit_address,
                                            int16u parameter,
                                            int8u * parameter_data,
                                            int8u i_count)
    {
      char s[100];
      int i;
    
      sprintf(s, "Discovery : Unit %X",
              unit_address);
    
      switch (parameter)
        {
        case CBUS_DISCOVERY_NONE :
          break;
        case CBUS_DISCOVERY_UNIT_TYPE :
          print_message("Discovery : ------------");
          asprintf(s, ", type %.8s",
                   (char *) parameter_data);
          break;
        case CBUS_DISCOVERY_MANUFACTURER :
          asprintf(s, ", manufacturer %.8s",
                   (char *) parameter_data);
          break;
        case CBUS_DISCOVERY_VERSION :
          asprintf(s, ", version %.8s",
                   (char *) parameter_data);
          break;
        case CBUS_DISCOVERY_GROUPS :
          asprintf(s, ", groups ");
          for (i=0; i<i_count; i++)
            {
              asprintf(s, "%02X ",
                       parameter_data[i]);
            }
          break;
        case CBUS_DISCOVERY_LEVELS :
          asprintf(s, ", levels ");
          for (i=0; i<i_count; i++)
            {
              asprintf(s, "%02X ",
                       parameter_data[i]);
            }
          break;
        case CBUS_DISCOVERY_APPLICATIONS :
          asprintf(s, ", apps ");
          for (i=0; i<2; i++)
            {
              asprintf(s, "%02X ", parameter_data[i]);
            }
          break;
        case CBUS_DISCOVERY_SERIAL_NUMBER :
          asprintf(s, ", serial no ");
          for (i=0; i<4; i++)
            {
              asprintf(s, "%02X", parameter_data[i]);
            }
          break;
        case CBUS_DISCOVERY_STATUS :
          if (parameter_data[0] & 0x01)
            strcat(s, ", output unit");
          else
            strcat(s, ", input unit");
          break;
        case CBUS_DISCOVERY_AREA :
          asprintf(s, ", area address %02X",
                   parameter_data[0]);
          break;
        case CBUS_DISCOVERY_CONFLICT :
          strcat(s, ", unit address conflict");
          break;
        }
      print_message(s);
    }
    
    
    /****************************************************************************
     * The discovery complete handler
     ****************************************************************************/
    static void discovery_complete_handler()
    {
      print_message("Discovery Complete");
    }
     
    Last edited by a moderator: Sep 27, 2005
    ashleigh, Sep 27, 2005
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.