示例#1
0
static void Init_Service_Handlers(
    void)
{
    Device_Init(NULL);
    /* we need to handle who-is
       to support dynamic device binding to us */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
    /* handle i-am to support binding to other devices */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind);
    /* set the handler for all the services we don't implement
       It is required to send the proper reject message... */
    apdu_set_unrecognized_service_handler_handler
        (handler_unrecognized_service);
    /* we must implement read property - it's required! */
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property);

    apdu_set_confirmed_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER,
        handler_conf_private_trans);
    /* handle the data coming back from confirmed requests */
    apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property_ack);

    apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER,
        handler_conf_private_trans_ack);

    /* handle any errors coming back */
    apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler);
    apdu_set_error_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER, MyErrorHandler);
    apdu_set_abort_handler(MyAbortHandler);
    apdu_set_reject_handler(MyRejectHandler);
}
示例#2
0
int BacnetAtomicReadFile(
    int deviceInstanceNumber,
    int fileInstanceNumber,
    int startOffset,
    int numBytes)
{
    if (!isAtomicReadFileHandlerRegistered) {
        /* handle the data coming back from confirmed requests */
        apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
            AtomicReadFileAckHandler);

        /* handle any errors coming back */
        apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
            My_Error_Handler);

        /* indicate that handlers are now registered */
        isAtomicReadFileHandlerRegistered = true;
    }
    /* Send the message out */
    Request_Invoke_ID =
        Send_Atomic_Read_File_Stream(deviceInstanceNumber, fileInstanceNumber,
        startOffset, numBytes);
    Wait_For_Answer_Or_Timeout(100, waitAnswer);

    int isFailure = Error_Detected;
    Error_Detected = 0;
    return isFailure;
}
示例#3
0
int BacnetReadProperty(
    int deviceInstanceNumber,
    int objectType,
    int objectInstanceNumber,
    int objectProperty,
    int objectIndex)
{
    if (!isReadPropertyHandlerRegistered) {
        /* handle the data coming back from confirmed requests */
        apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
            My_Read_Property_Ack_Handler);

        /* handle any errors coming back */
        apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY,
            My_Error_Handler);

        /* indicate that handlers are now registered */
        isReadPropertyHandlerRegistered = true;
    }
    /* Send the message out */
    Request_Invoke_ID =
        Send_Read_Property_Request(deviceInstanceNumber, objectType,
        objectInstanceNumber, objectProperty, objectIndex);
    Wait_For_Answer_Or_Timeout(100, waitAnswer);

    int isFailure = Error_Detected;
    Error_Detected = 0;
    return isFailure;
}
示例#4
0
static void Init_Service_Handlers(
    void)
{
    Device_Init(NULL);
    /* we need to handle who-is
       to support dynamic device binding to us */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
    /* handle i-am to support binding to other devices */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler);
    /* set the handler for all the services we don't implement
       It is required to send the proper reject message... */
    apdu_set_unrecognized_service_handler_handler
        (handler_unrecognized_service);
    /* we must implement read property - it's required! */
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property);
    /* handle the data coming back from confirmed requests */
    apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
        AtomicReadFileAckHandler);
    /* handle any errors coming back */
    apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
        Atomic_Read_File_Error_Handler);
    apdu_set_abort_handler(MyAbortHandler);
    apdu_set_reject_handler(MyRejectHandler);
}
示例#5
0
static void Init_Service_Handlers(
    void)
{
    Device_Init(NULL);

    /* we need to handle who-is to support dynamic device binding */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler);

    /* set the handler for all the services we don't implement */
    /* It is required to send the proper reject message... */
    apdu_set_unrecognized_service_handler_handler
        (handler_unrecognized_service);
    /* we must implement read property - it's required! */
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property);
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
        handler_read_property_multiple);
    /* handle the data coming back from confirmed requests */
    apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property_ack);
#if defined(BACFILE)
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE,
        handler_atomic_read_file);
#endif
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV,
        handler_cov_subscribe);

#if 0
    /* Adding these handlers require the project(s) to change. */
#if defined(BACFILE)
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_WRITE_FILE,
        handler_atomic_write_file);
#endif
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE,
        handler_read_range);
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE,
        handler_reinitialize_device);
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION,
        handler_timesync_utc);
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION,
        handler_timesync);
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_COV_NOTIFICATION,
        handler_ucov_notification);
    /* handle communication so we can shutup when asked */
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
        handler_device_communication_control);
#endif
}
示例#6
0
static void Init_Service_Handlers(
    void)
{
    Device_Init();
    handler_read_property_object_set(OBJECT_DEVICE,
        Device_Encode_Property_APDU, Device_Valid_Object_Instance_Number);
    /* we need to handle who-is to support dynamic device binding */
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
    apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler);

    /* set the handler for all the services we don't implement */
    /* It is required to send the proper reject message... */
    apdu_set_unrecognized_service_handler_handler
        (handler_unrecognized_service);
    /* Set the handlers for any confirmed services that we support. */
    /* We must implement read property - it's required! */
    apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property);
    /* handle the data coming back from confirmed requests */
    apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
        handler_read_property_ack);
}
示例#7
0
int BacnetReadPropertyMultiple(
    int deviceInstanceNumber,
    ...)
{
    /* Get the variable argument list from the stack */
    Inline_Stack_Vars;
    int rpmIndex = 1;
    BACNET_READ_ACCESS_DATA *rpm_object =
        calloc(1, sizeof(BACNET_READ_ACCESS_DATA));
    BACNET_READ_ACCESS_DATA *Read_Access_Data = rpm_object;
    BACNET_PROPERTY_REFERENCE *rpm_property;
    uint8_t buffer[MAX_PDU] = { 0 };

    while (rpmIndex < Inline_Stack_Items) {
        SV *pSV = Inline_Stack_Item(rpmIndex++);

        /* Make sure the argument is an Array Reference */
        if (SvTYPE(SvRV(pSV)) != SVt_PVAV) {
            LogError("Argument is not an Array reference");
            break;
        }
        /* Make sure we can access the memory */
        if (rpm_object) {
            rpm_object->listOfProperties = NULL;
        } else {
            LogError("Memory Allocation Issue");
            break;
        }

        AV *pAV = (AV *) SvRV(pSV);
        SV **ppSV;

        /* The 0th argument is the object type */
        ppSV = av_fetch(pAV, 0, 0);
        if (ppSV) {
            rpm_object->object_type = SvIV(*ppSV);
        } else {
            LogError("Problem parsing the Array of arguments");
            break;
        }

        /* The 1st argument is the object instance */
        ppSV = av_fetch(pAV, 1, 0);
        if (ppSV) {
            rpm_object->object_instance = SvIV(*ppSV);
        } else {
            LogError("Problem parsing the Array of arguments");
            break;
        }

        /* The 2nd argument is the property type */
        ppSV = av_fetch(pAV, 2, 0);
        if (ppSV) {
            rpm_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE));
            rpm_object->listOfProperties = rpm_property;
            if (rpm_property) {
                rpm_property->propertyIdentifier = SvIV(*ppSV);
            } else {
                LogError("Memory allocation error");
                break;
            }
        } else {
            LogError("Problem parsing the Array of arguments");
            break;
        }

        /* The 3rd argument is the property index */
        ppSV = av_fetch(pAV, 3, 0);
        if (ppSV) {
            rpm_property->propertyArrayIndex = SvIV(*ppSV);
        } else {
            LogError("Problem parsing the Array of arguments");
            break;
        }

        /* Advance to the next RPM index */
        if (rpmIndex < Inline_Stack_Items) {
            rpm_object->next = calloc(1, sizeof(BACNET_READ_ACCESS_DATA));
            rpm_object = rpm_object->next;
        } else {
            rpm_object->next = NULL;
        }
    }

    if (!isReadPropertyMultipleHandlerRegistered) {
        /* handle the data coming back from confirmed requests */
        apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
            My_Read_Property_Multiple_Ack_Handler);

        /* handle any errors coming back */
        apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
            My_Error_Handler);

        /* indicate that handlers are now registered */
        isReadPropertyMultipleHandlerRegistered = true;
    }
    /* Send the message out */
    if (!Error_Detected) {
        Request_Invoke_ID =
            Send_Read_Property_Multiple_Request(&buffer[0], sizeof(buffer),
            deviceInstanceNumber, Read_Access_Data);
        Wait_For_Answer_Or_Timeout(100, waitAnswer);
    }
    /* Clean up allocated memory */
    BACNET_READ_ACCESS_DATA *old_rpm_object;
    BACNET_PROPERTY_REFERENCE *old_rpm_property;

    rpm_object = Read_Access_Data;
    old_rpm_object = rpm_object;
    while (rpm_object) {
        rpm_property = rpm_object->listOfProperties;
        while (rpm_property) {
            old_rpm_property = rpm_property;
            rpm_property = rpm_property->next;
            free(old_rpm_property);
        }
        old_rpm_object = rpm_object;
        rpm_object = rpm_object->next;
        free(old_rpm_object);
    }

    /* Process the return value */
    int isFailure = Error_Detected;
    Error_Detected = 0;
    return isFailure;
}