Example #1
0
/* encode service */
int rd_encode_apdu(
    uint8_t * apdu,
    uint8_t invoke_id,
    BACNET_REINITIALIZED_STATE state,
    BACNET_CHARACTER_STRING * password)
{
    int len = 0;        /* length of each encoding */
    int apdu_len = 0;   /* total length of the apdu, return value */

    if (apdu) {
        apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
        apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
        apdu[2] = invoke_id;
        apdu[3] = SERVICE_CONFIRMED_REINITIALIZE_DEVICE;
        apdu_len = 4;
        len = encode_context_enumerated(&apdu[apdu_len], 0, state);
        apdu_len += len;
        /* optional password */
        if (password) {
            /* FIXME: must be at least 1 character, limited to 20 characters */
            len =
                encode_context_character_string(&apdu[apdu_len], 1, password);
            apdu_len += len;
        }
    }

    return apdu_len;
}
Example #2
0
/***************************************************
**
** Encodes the service data part of Event Notification
**
****************************************************/
int alarm_ack_encode_service_request(
    uint8_t * apdu,
    BACNET_ALARM_ACK_DATA * data)
{
    int len = 0;        /* length of each encoding */
    int apdu_len = 0;   /* total length of the apdu, return value */

    if (apdu) {
        len =
            encode_context_unsigned(&apdu[apdu_len], 0,
                                    data->ackProcessIdentifier);
        apdu_len += len;

        len =
            encode_context_object_id(&apdu[apdu_len], 1,
                                     (int) data->eventObjectIdentifier.type,
                                     data->eventObjectIdentifier.instance);
        apdu_len += len;

        len =
            encode_context_enumerated(&apdu[apdu_len], 2,
                                      data->eventStateAcked);
        apdu_len += len;

        len =
            bacapp_encode_context_timestamp(&apdu[apdu_len], 3,
                                            &data->eventTimeStamp);
        apdu_len += len;

        len =
            encode_context_character_string(&apdu[apdu_len], 4,
                                            &data->ackSource);
        apdu_len += len;

        len =
            bacapp_encode_context_timestamp(&apdu[apdu_len], 5,
                                            &data->ackTimeStamp);
        apdu_len += len;
    }

    return apdu_len;
}
int lso_encode_apdu(
    uint8_t * apdu,
    uint8_t invoke_id,
    BACNET_LSO_DATA * data)
{
    int len = 0;        /* length of each encoding */
    int apdu_len = 0;   /* total length of the apdu, return value */

    if (apdu && data) {
        apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
        apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
        apdu[2] = invoke_id;
        apdu[3] = SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION;
        apdu_len = 4;
        /* tag 0 - requestingProcessId */
        len = encode_context_unsigned(&apdu[apdu_len], 0, data->processId);
        apdu_len += len;
        /* tag 1 - requestingSource */
        len =
            encode_context_character_string(&apdu[apdu_len], 1,
            &data->requestingSrc);
        apdu_len += len;
        /*
           Operation
         */
        len = encode_context_enumerated(&apdu[apdu_len], 2, data->operation);
        apdu_len += len;
        /*
           Object ID
         */

        len =
            encode_context_object_id(&apdu[apdu_len], 3,
            (int) data->targetObject.type, data->targetObject.instance);

        apdu_len += len;
    }

    return apdu_len;
}
Example #4
0
int whohas_encode_apdu(
    uint8_t * apdu,
    BACNET_WHO_HAS_DATA * data)
{
    int len = 0;        /* length of each encoding */
    int apdu_len = 0;   /* total length of the apdu, return value */

    if (apdu && data) {
        apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST;
        apdu[1] = SERVICE_UNCONFIRMED_WHO_HAS;  /* service choice */
        apdu_len = 2;
        /* optional limits - must be used as a pair */
        if ((data->low_limit >= 0)
            && (data->low_limit <= BACNET_MAX_INSTANCE)
            && (data->high_limit >= 0)
            && (data->high_limit <= BACNET_MAX_INSTANCE)) {
            len = encode_context_unsigned(&apdu[apdu_len], 0, data->low_limit);
            apdu_len += len;
            len =
                encode_context_unsigned(&apdu[apdu_len], 1, data->high_limit);
            apdu_len += len;
        }
        if (data->object_name) {
            len =
                encode_context_character_string(&apdu[apdu_len], 3,
                &data->object.name);
            apdu_len += len;
        } else {
            len =
                encode_context_object_id(&apdu[apdu_len], 2,
                (int) data->object.identifier.type,
                data->object.identifier.instance);
            apdu_len += len;
        }
    }

    return apdu_len;
}