Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we define static address for objects #508

Open
coskunyildirimcosel opened this issue Oct 9, 2023 · 4 comments
Open

How can we define static address for objects #508

coskunyildirimcosel opened this issue Oct 9, 2023 · 4 comments

Comments

@coskunyildirimcosel
Copy link

Hello,
I want to remove the max address limit on objects and statically assign the address I want. I want objects to be added according to the assigned address. How can we do this?

@skarg
Copy link
Collaborator

skarg commented Oct 9, 2023

Can you clarify specifically what you mean by max address limit on objects? Perhaps give an example of the problem?

Usually when discussing addresses, I assume you are asking about the address binding to device object instance.

The src/bacnet/basic/binding/address.c module is an example of how to 'bind' network MAC address to object-instance. There is a function address_add() for adding new bindings, and is usually called by response from I-Am service. It can also be called from a file if you have one, and there is an example of using the output from Who-Is example to fill the address_cache file. At the moment, the address.c module uses MAX_ADDRESS_CACHE as maximum size of address bindings in a static array.

If address.c module doesn't suit your needs, you should construct your own module to store address bindings.

@coskunyildirimcosel
Copy link
Author

Hello Steve,
Thank you for your quick response.
For example, we have a MAX_ANALOG_INPUTS limit on Analog_Input.
Instead I want to assign an object with a random static address.
When I add Analog_Input_Present_Value(55) I want an object with address 55 to be created automatically. Currently when I set Max_analog_inputs to 55 I create objects from 0 to 54 that I don't need.
I hope I could explain.

@skarg
Copy link
Collaborator

skarg commented Oct 9, 2023

There are lots of methods to create static objects at arbitrary instances. Keep the 'instance' and 'index' consistent with each other so that the device object can iterate through the object list.

There are examples using the 'keylist.c' library to dynamically create objects - see an example ao.c module,

Here is an example where you can modify the object data structure to include the object_instance:

struct object_data {
    const uint32_t Object_Instance;
    const char *Object_Name;
    uint16_t Units;
    float Min_Value;
    float Max_Value;
    bool Writable : 1;
    bool Out_Of_Service : 1;
    float Present_Value;
};

Create a static object property value table:

/* default values */
static struct object_data Object_List[] = {
    { 55, "Sensor 4A", UNITS_DEGREES_CELSIUS, 0.0, 100.0, true, false, 18.0 }
};
/* number of objects */
static size_t Objects_List_Size = sizeof(Object_List) / sizeof(Object_List[0]);

/**
 * @brief Determines the number of objects N
 * @return  Number of objects N
 */
unsigned Analog_Input_Count(void)
{
    return Objects_List_Size;
}

/**
 * @brief Return the object or NULL if not found.
 * @param  object_instance - object-instance number of the object
 * @return  object if the instance is found, and NULL if not
 */
static struct object_data *Object_List_Element(uint32_t object_instance)
{
    unsigned index;

    for (index = 0; index < Objects_List_Size; index++) {
        if (Object_List[index].object_instance == object_instance) {
            return &Object_List[index];
        }
    }

    return NULL;
}

/**
 * @brief Determines the object instance-number for a given 0..N index
 * @param  index - 0..N value
 * @return  object instance-number for the given index
 */
uint32_t Analog_Input_Index_To_Instance(unsigned index)
{
    uint32_t object_instance = UINT32_MAX;
    
    if (index < Objects_List_Size) {
        object_instance = Object_List[index].object_instance;
    }

    return object_instance;
}

/**
 * @brief For a given object instance-number, determines a 0..N index
 * @param  object_instance - object-instance number of the object
 * @return  index for the given instance-number, or N if not valid.
 */
unsigned Analog_Input_Instance_To_Index(uint32_t object_instance)
{
    unsigned index;

    for (index = 0; index < Objects_List_Size; index++) {
        if (Object_List[index].object_instance == object_instance) {
            break;
        }
    }

    return index;
}

/**
 * @brief For a given object instance-number, gets the present-value
 * @param  object_instance - object-instance number of the object
 * @return  present-value of the object
 */
float Analog_Input_Present_Value(uint32_t object_instance)
{
    float value = 0;
    struct object_data *pObject;

    pObject = Object_List_Element(object_instance);
    if (pObject) {
        value = pObject->value;
    }

    return value;
}

@coskunyildirimcosel
Copy link
Author

Ok thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants