Menu

How to encode a DateTime object

Help
2016-09-05
2016-09-07
  • Jeremy Begg

    Jeremy Begg - 2016-09-05

    Hi,

    One of the properties we need to publish is a BACNET_DATE_TIME value.
    There seems to be some support for it in src/datetime.c but I don't see routines for encoding or decoding these.

    Using the example BACnet server (in the demo directory) would it be as simple as ...

    int DateTime_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) {
    ...
        BACNET_DATE_TIME bdatetime;
        switch (rpdata->object_property) {
    ...
            case PROP_PRESENT_VALUE:
                // get the local date & time as a BACNET_DATE_TIME value
                get_datetime(&bdatetime);
                // encode it as a date followed by a time
                apdu_len = encode_application_date(&apdu[0], &bdatetime.date);
                apdu_len += encode_application_time(&apdu[apdu_len], &bdatetime.time);
                break;
    

    Thanks,
    Jeremy Begg

     
  • Steve Karg

    Steve Karg - 2016-09-07

    Yes, it is as simple as that. There is already a helper in src/datetime.c file:

    bacapp_encode_datetime()
    
     

Log in to post a comment.