Jump to main content | Jump to Primary Navigation | Jump to Sub Navigation


 

Tutorial 6: External Types

Previous tutorial Back to main tutorial page

DevBot provides many built-in property types that are usable in drivers and controller code. See type.h for more information about the API these types provide. In most respects, external types are identical to these internal types, but they must be loaded before they can be used. They may also have third-party APIs which do not conform to those of the internal types.

Although drivers will typically link against and register any external types their properties require, controller programs must also link against and register any external types they employ.

This tutorial assumes you are aware of the 'short' type, manufactured in Drivers 4: Creating custom types.

Contents

  1. Loading an external type
  2. Type-specific API

Loading an external type

Programs wishing to load external types must include type.h. They must also be linked against the external type, and include the external type's header. This is necessary because the external type may provide additional APIs outside of the core DevBot type architecture.

The function bot_type_register() must be invoked to load an external type. Invoking this function adds the type to DevBot's internal registry, allowing it to be used by user/controller code. External types should provide an accessor which returns a BotPropertyType for use with this registration function (e.g. bot_short_get_type).

    bot_type_register(bot_short_get_type());

Type-specific API

External types will typically provide additional functionality specific to that type. However, our manufactured 'short' type looks like other core primitives.

    int16_t shrt = bot_property_get_short(p);

A list of accessors (including bot_property_get_short) can be found in Drivers 4: Creating custom types.

Bringing it all together

int main(int argc, char **argv)
{
    BotHost *host = bot_host_create("127.0.0.1:1234");

    /* Register the type with DevBot */
    bot_type_register(bot_short_get_type());

    /* Look up the 'short' property */
    BotProperty *p = bot_host_register_property(host, "Device/ShortProperty");

    /* Obtain the property value and display it */
    int16_t shrt = bot_property_get_short(p);
    printf("value was: %hd\n", shrt);

    return 0;
}

Previous tutorial Back to main tutorial page