Giter Club home page Giter Club logo

Comments (4)

skarg avatar skarg commented on June 20, 2024 1

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;
}

from bacnet-stack.

skarg avatar skarg commented on June 20, 2024

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.

from bacnet-stack.

coskunyildirimcosel avatar coskunyildirimcosel commented on June 20, 2024

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.

from bacnet-stack.

coskunyildirimcosel avatar coskunyildirimcosel commented on June 20, 2024

Ok thank you very much

from bacnet-stack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.