Performed standard indent script indent.sh on project files.
This commit is contained in:
@@ -277,8 +277,8 @@ static void Init_Service_Handlers(
|
||||
uint32_t Object_Instance;
|
||||
/* Put this client Device into the Routing table (first entry) */
|
||||
Object_Instance = Device_Object_Instance_Number();
|
||||
Add_Routed_Device( Object_Instance, Device_Object_Name(),
|
||||
Device_Description() );
|
||||
Add_Routed_Device(Object_Instance, Device_Object_Name(),
|
||||
Device_Description());
|
||||
#endif
|
||||
|
||||
/* we need to handle who-is
|
||||
@@ -797,10 +797,8 @@ void PrintUsage(
|
||||
(" -t: declare target's MAC instead of using Who-Is to bind to \r\n");
|
||||
printf
|
||||
(" device-instance. Format is \"C0:A8:00:18:BA:C0\" (as usual) \r\n");
|
||||
printf
|
||||
(" Use \"7F:00:00:01:BA:C0\" for loopback testing \r\n");
|
||||
printf
|
||||
(" -n: specify target's DNET if not local BACnet network \r\n");
|
||||
printf(" Use \"7F:00:00:01:BA:C0\" for loopback testing \r\n");
|
||||
printf(" -n: specify target's DNET if not local BACnet network \r\n");
|
||||
printf(" or on routed Virtual Network \r\n");
|
||||
printf("\r\n");
|
||||
printf("Insert the output in your EPICS file as the last section: \r\n");
|
||||
@@ -839,10 +837,12 @@ int CheckCommandLineArgs(
|
||||
break;
|
||||
case 'n':
|
||||
/* Destination Network Number */
|
||||
if ( Target_Address.mac_len == 0 )
|
||||
fprintf(stderr, "Must provide a Target MAC before DNET \r\n");
|
||||
if (Target_Address.mac_len == 0)
|
||||
fprintf(stderr,
|
||||
"Must provide a Target MAC before DNET \r\n");
|
||||
if (++i < argc)
|
||||
Target_Address.net = (uint16_t) strtol(argv[i], NULL, 0);
|
||||
Target_Address.net =
|
||||
(uint16_t) strtol(argv[i], NULL, 0);
|
||||
/* Used strtol so dest.net can be either 0x1234 or 4660 */
|
||||
break;
|
||||
case 't':
|
||||
@@ -854,10 +854,9 @@ int CheckCommandLineArgs(
|
||||
/* loop counter */
|
||||
unsigned j;
|
||||
count =
|
||||
sscanf(argv[i], "%x:%x:%x:%x:%x:%x",
|
||||
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4],
|
||||
&mac[5]);
|
||||
if (count == 6) { /* success */
|
||||
sscanf(argv[i], "%x:%x:%x:%x:%x:%x", &mac[0],
|
||||
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
|
||||
if (count == 6) { /* success */
|
||||
Target_Address.mac_len = count;
|
||||
for (j = 0; j < 6; j++) {
|
||||
Target_Address.mac[j] = (uint8_t) mac[j];
|
||||
@@ -967,30 +966,30 @@ int main(
|
||||
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||
|
||||
if (My_BIP_Port > 0)
|
||||
bip_set_port(htons(0xBAC0)); /* Set back to std BACnet/IP port */
|
||||
bip_set_port(htons(0xBAC0)); /* Set back to std BACnet/IP port */
|
||||
/* try to bind with the target device */
|
||||
found =
|
||||
address_bind_request(Target_Device_Object_Instance, &max_apdu,
|
||||
&Target_Address);
|
||||
if (!found) {
|
||||
if (Provided_Targ_MAC) {
|
||||
if ( Target_Address.net > 0 ) {
|
||||
if (Target_Address.net > 0) {
|
||||
/* We specified a DNET; call Who-Is to find the full
|
||||
* routed path to this Device */
|
||||
Send_WhoIs_Remote(&Target_Address,
|
||||
Target_Device_Object_Instance,
|
||||
Target_Device_Object_Instance);
|
||||
Target_Device_Object_Instance,
|
||||
Target_Device_Object_Instance);
|
||||
|
||||
} else {
|
||||
/* Update by adding the MAC address */
|
||||
if (max_apdu == 0)
|
||||
max_apdu = MAX_APDU; /* Whatever set for this datalink. */
|
||||
max_apdu = MAX_APDU; /* Whatever set for this datalink. */
|
||||
address_add_binding(Target_Device_Object_Instance, max_apdu,
|
||||
&Target_Address);
|
||||
&Target_Address);
|
||||
}
|
||||
} else {
|
||||
Send_WhoIs(Target_Device_Object_Instance,
|
||||
Target_Device_Object_Instance);
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
}
|
||||
myObject.type = OBJECT_DEVICE;
|
||||
@@ -1036,7 +1035,7 @@ int main(
|
||||
} else {
|
||||
/* Print out the header information */
|
||||
printf("List of Objects in device %u: \r\n",
|
||||
Target_Device_Object_Instance);
|
||||
Target_Device_Object_Instance);
|
||||
/* Print Opening brace, then kick off the Device Object */
|
||||
printf("{ \r\n");
|
||||
printf(" { \r\n"); /* And opening brace for the first object */
|
||||
@@ -1158,11 +1157,11 @@ int main(
|
||||
(invoke_id ==
|
||||
Read_Property_Multiple_Data.service_data.invoke_id)) {
|
||||
Read_Property_Multiple_Data.new_data = false;
|
||||
PrintReadPropertyData(Read_Property_Multiple_Data.
|
||||
rpm_data->object_type,
|
||||
PrintReadPropertyData
|
||||
(Read_Property_Multiple_Data.rpm_data->object_type,
|
||||
Read_Property_Multiple_Data.rpm_data->object_instance,
|
||||
Read_Property_Multiple_Data.rpm_data->
|
||||
listOfProperties);
|
||||
Read_Property_Multiple_Data.
|
||||
rpm_data->listOfProperties);
|
||||
if (tsm_invoke_id_free(invoke_id)) {
|
||||
invoke_id = 0;
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
/* Device configuration definitions. */
|
||||
#define FIRST_DEVICE_NUMBER 260001
|
||||
#define VIRTUAL_DNET 2709 /* your choice of number here */
|
||||
#define VIRTUAL_DNET 2709 /* your choice of number here */
|
||||
#define DEV_NAME_BASE "Gateway Demo Device"
|
||||
#define DEV_DESCR_GATEWAY "Gateway Device and Router"
|
||||
#define DEV_DESCR_REMOTE "Routed Remote Device"
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{ANALOG_INPUT_OBJ_FUNCTIONS},
|
||||
{ANALOG_OUTPUT_OBJ_FUNCTIONS},
|
||||
{ANALOG_VALUE_OBJ_FUNCTIONS},
|
||||
@@ -110,7 +110,7 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
* Only one entry since we don't support downstream routers.
|
||||
*/
|
||||
int DNET_list[2] = {
|
||||
VIRTUAL_DNET, -1 /* Need -1 terminator */
|
||||
VIRTUAL_DNET, -1 /* Need -1 terminator */
|
||||
};
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ int DNET_list[2] = {
|
||||
instance number, and subsequent devices to incremented values.
|
||||
*/
|
||||
void Devices_Init(
|
||||
uint32_t first_object_instance )
|
||||
uint32_t first_object_instance)
|
||||
{
|
||||
int i;
|
||||
char nameText[MAX_DEV_NAME_LEN];
|
||||
@@ -128,24 +128,20 @@ void Devices_Init(
|
||||
|
||||
/* Gateway Device has already been initialized.
|
||||
* But give it a better Description. */
|
||||
Routed_Device_Set_Description(DEV_DESCR_GATEWAY, strlen(DEV_DESCR_GATEWAY));
|
||||
Routed_Device_Set_Description(DEV_DESCR_GATEWAY,
|
||||
strlen(DEV_DESCR_GATEWAY));
|
||||
|
||||
/* Now initialize the remote Device objects. */
|
||||
for ( i = 1; i < MAX_NUM_DEVICES; i++ )
|
||||
{
|
||||
for (i = 1; i < MAX_NUM_DEVICES; i++) {
|
||||
#ifdef _MSC_VER
|
||||
_snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d",
|
||||
DEV_NAME_BASE, i+1);
|
||||
_snprintf( descText, MAX_DEV_DESC_LEN, "%s %d",
|
||||
DEV_DESCR_REMOTE, i);
|
||||
_snprintf(nameText, MAX_DEV_NAME_LEN, "%s %d", DEV_NAME_BASE, i + 1);
|
||||
_snprintf(descText, MAX_DEV_DESC_LEN, "%s %d", DEV_DESCR_REMOTE, i);
|
||||
#else
|
||||
snprintf( nameText, MAX_DEV_NAME_LEN, "%s %d",
|
||||
DEV_NAME_BASE, i+1);
|
||||
snprintf( descText, MAX_DEV_DESC_LEN, "%s %d",
|
||||
DEV_DESCR_REMOTE, i);
|
||||
snprintf(nameText, MAX_DEV_NAME_LEN, "%s %d", DEV_NAME_BASE, i + 1);
|
||||
snprintf(descText, MAX_DEV_DESC_LEN, "%s %d", DEV_DESCR_REMOTE, i);
|
||||
#endif
|
||||
|
||||
Add_Routed_Device( (first_object_instance+i), nameText, descText );
|
||||
Add_Routed_Device((first_object_instance + i), nameText, descText);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -155,18 +151,18 @@ void Devices_Init(
|
||||
* @see Device_Init, apdu_set_unconfirmed_handler, apdu_set_confirmed_handler
|
||||
*/
|
||||
static void Init_Service_Handlers(
|
||||
uint32_t first_object_instance )
|
||||
uint32_t first_object_instance)
|
||||
{
|
||||
Device_Initialize_Object_Functions(&Object_Table[0]);
|
||||
Routing_Device_Init( first_object_instance );
|
||||
Routing_Device_Init(first_object_instance);
|
||||
|
||||
/* we need to handle who-is to support dynamic device binding
|
||||
* For the gateway, we want the routing handlers, and we will use the
|
||||
* unicast variety so we can get back through switches to different subnets */
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS,
|
||||
handler_who_is_unicast_for_routing);
|
||||
handler_who_is_unicast_for_routing);
|
||||
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS,
|
||||
handler_who_has_for_routing);
|
||||
handler_who_has_for_routing);
|
||||
/* 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
|
||||
@@ -210,21 +206,22 @@ static void Init_Service_Handlers(
|
||||
* device.) This is sure to be unique! The port number stays the same.
|
||||
* - For MS/TP, [Steve inserts a good idea here]
|
||||
*/
|
||||
void Initialize_Device_Addresses( )
|
||||
void Initialize_Device_Addresses(
|
||||
)
|
||||
{
|
||||
int i = 0; /* First entry is Gateway Device */
|
||||
DEVICE_OBJECT_DATA* pDev;
|
||||
int i = 0; /* First entry is Gateway Device */
|
||||
DEVICE_OBJECT_DATA *pDev;
|
||||
uint16_t myPort;
|
||||
/* Setup info for the main gateway device first */
|
||||
#if defined(BACDL_BIP)
|
||||
struct in_addr *netPtr; /* Lets us cast to this type */
|
||||
struct in_addr *netPtr; /* Lets us cast to this type */
|
||||
uint8_t *gatewayMac = NULL;
|
||||
uint32_t myAddr = bip_get_addr();
|
||||
pDev = Get_Routed_Device_Object( i );
|
||||
gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */
|
||||
memcpy( pDev->bacDevAddr.mac, &myAddr, 4 );
|
||||
pDev = Get_Routed_Device_Object(i);
|
||||
gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */
|
||||
memcpy(pDev->bacDevAddr.mac, &myAddr, 4);
|
||||
myPort = bip_get_port();
|
||||
memcpy( &pDev->bacDevAddr.mac[4], &myPort, 2 );
|
||||
memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
|
||||
pDev->bacDevAddr.mac_len = 6;
|
||||
#elif defined(BACDL_MSTP)
|
||||
/* Todo: */
|
||||
@@ -235,23 +232,23 @@ void Initialize_Device_Addresses( )
|
||||
/* broadcast an I-Am on startup */
|
||||
Send_I_Am(&Handler_Transmit_Buffer[0]);
|
||||
|
||||
for (i = 1; i < MAX_NUM_DEVICES; i++ ) {
|
||||
pDev = Get_Routed_Device_Object( i );
|
||||
if ( pDev == NULL )
|
||||
continue;
|
||||
for (i = 1; i < MAX_NUM_DEVICES; i++) {
|
||||
pDev = Get_Routed_Device_Object(i);
|
||||
if (pDev == NULL)
|
||||
continue;
|
||||
#if defined(BACDL_BIP)
|
||||
netPtr = (struct in_addr *) pDev->bacDevAddr.mac;
|
||||
pDev->bacDevAddr.mac[0] = gatewayMac[3];
|
||||
pDev->bacDevAddr.mac[1] = gatewayMac[2];
|
||||
pDev->bacDevAddr.mac[2] = gatewayMac[1];
|
||||
pDev->bacDevAddr.mac[3] = i;
|
||||
memcpy( &pDev->bacDevAddr.mac[4], &myPort, 2 );
|
||||
memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2);
|
||||
pDev->bacDevAddr.mac_len = 6;
|
||||
pDev->bacDevAddr.net = VIRTUAL_DNET;
|
||||
memcpy( &pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6 );
|
||||
memcpy(&pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6);
|
||||
pDev->bacDevAddr.len = 6;
|
||||
printf( " - Routed device [%d] ID %u at %s \n", i,
|
||||
pDev->bacObj.Object_Instance_Number, inet_ntoa( *netPtr ) );
|
||||
printf(" - Routed device [%d] ID %u at %s \n", i,
|
||||
pDev->bacObj.Object_Instance_Number, inet_ntoa(*netPtr));
|
||||
#elif defined(BACDL_MSTP)
|
||||
/* Todo: set MS/TP net and port #s */
|
||||
pDev->bacDevAddr.mac_len = 2;
|
||||
@@ -298,34 +295,35 @@ int main(
|
||||
time_t current_seconds = 0;
|
||||
uint32_t elapsed_seconds = 0;
|
||||
uint32_t elapsed_milliseconds = 0;
|
||||
uint32_t first_object_instance = FIRST_DEVICE_NUMBER;
|
||||
uint32_t first_object_instance = FIRST_DEVICE_NUMBER;
|
||||
#ifdef BACNET_TEST_VMAC
|
||||
/* Router data */
|
||||
BACNET_DEVICE_PROFILE* device;
|
||||
BACNET_DEVICE_PROFILE *device;
|
||||
BACNET_VMAC_ADDRESS adr;
|
||||
#endif
|
||||
|
||||
/* allow the device ID to be set */
|
||||
if (argc > 1) {
|
||||
first_object_instance = strtol(argv[1], NULL, 0);
|
||||
if ( ( first_object_instance == 0 ) ||
|
||||
( first_object_instance >= BACNET_MAX_INSTANCE ) ) {
|
||||
printf( "Error: Invalid Object Instance %s \n", argv[1] );
|
||||
printf( "Provide a number from 1 to %ul \n", BACNET_MAX_INSTANCE -1 );
|
||||
exit(1);
|
||||
}
|
||||
first_object_instance = strtol(argv[1], NULL, 0);
|
||||
if ((first_object_instance == 0) ||
|
||||
(first_object_instance >= BACNET_MAX_INSTANCE)) {
|
||||
printf("Error: Invalid Object Instance %s \n", argv[1]);
|
||||
printf("Provide a number from 1 to %ul \n",
|
||||
BACNET_MAX_INSTANCE - 1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
printf("BACnet Router Demo\n" "BACnet Stack Version %s\n"
|
||||
"BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version,
|
||||
first_object_instance, MAX_APDU);
|
||||
Init_Service_Handlers( first_object_instance );
|
||||
Init_Service_Handlers(first_object_instance);
|
||||
dlenv_init();
|
||||
Devices_Init( first_object_instance );
|
||||
Initialize_Device_Addresses( );
|
||||
Devices_Init(first_object_instance);
|
||||
Initialize_Device_Addresses();
|
||||
atexit(cleanup);
|
||||
|
||||
#ifdef BACNET_TEST_VMAC
|
||||
/* initialize vmac table and router device */
|
||||
/* initialize vmac table and router device */
|
||||
device = vmac_initialize(99, 2001);
|
||||
debug_printf(device->name, "ROUTER:%u", vmac_get_subnet());
|
||||
#endif
|
||||
@@ -333,8 +331,8 @@ int main(
|
||||
last_seconds = time(NULL);
|
||||
|
||||
/* broadcast an I-am-router-to-network on startup */
|
||||
printf( "Remote Network DNET Number %d \n", DNET_list[0] );
|
||||
Send_I_Am_Router_To_Network( DNET_list );
|
||||
printf("Remote Network DNET Number %d \n", DNET_list[0]);
|
||||
Send_I_Am_Router_To_Network(DNET_list);
|
||||
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
@@ -346,7 +344,7 @@ int main(
|
||||
|
||||
/* process */
|
||||
if (pdu_len) {
|
||||
routing_npdu_handler(&src, DNET_list, &Rx_Buf[0], pdu_len);
|
||||
routing_npdu_handler(&src, DNET_list, &Rx_Buf[0], pdu_len);
|
||||
}
|
||||
/* at least one second has passed */
|
||||
elapsed_seconds = current_seconds - last_seconds;
|
||||
|
||||
@@ -346,9 +346,8 @@ static bool cov_send_request(
|
||||
value_list[1].next = NULL;
|
||||
switch (cov_subscription->monitoredObjectIdentifier.type) {
|
||||
case OBJECT_BINARY_INPUT:
|
||||
Binary_Input_Encode_Value_List
|
||||
(cov_subscription->monitoredObjectIdentifier.instance,
|
||||
&value_list[0]);
|
||||
Binary_Input_Encode_Value_List(cov_subscription->
|
||||
monitoredObjectIdentifier.instance, &value_list[0]);
|
||||
break;
|
||||
default:
|
||||
goto COV_FAILED;
|
||||
@@ -465,8 +464,8 @@ static bool cov_subscribe(
|
||||
|
||||
switch (cov_data->monitoredObjectIdentifier.type) {
|
||||
case OBJECT_BINARY_INPUT:
|
||||
if (Binary_Input_Valid_Instance
|
||||
(cov_data->monitoredObjectIdentifier.instance)) {
|
||||
if (Binary_Input_Valid_Instance(cov_data->
|
||||
monitoredObjectIdentifier.instance)) {
|
||||
status =
|
||||
cov_list_subscribe(src, cov_data, error_class, error_code);
|
||||
} else {
|
||||
|
||||
@@ -67,9 +67,9 @@
|
||||
*/
|
||||
static void network_control_handler(
|
||||
BACNET_ADDRESS * src,
|
||||
int * DNET_list,
|
||||
int *DNET_list,
|
||||
BACNET_NPDU_DATA * npdu_data,
|
||||
uint8_t * npdu,
|
||||
uint8_t * npdu,
|
||||
uint16_t npdu_len)
|
||||
{
|
||||
uint16_t npdu_offset = 0;
|
||||
@@ -78,23 +78,19 @@ static void network_control_handler(
|
||||
|
||||
switch (npdu_data->network_message_type) {
|
||||
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
||||
/* Send I-am-router-to-network with our one-network list if
|
||||
* our specific network is requested, or no specific
|
||||
* network is requested. Silently drop other DNET requests.
|
||||
*/
|
||||
if (npdu_len >= 2)
|
||||
{
|
||||
uint16_t network;
|
||||
len += decode_unsigned16(&npdu[len], &network);
|
||||
if (network == DNET_list[0] )
|
||||
{
|
||||
Send_I_Am_Router_To_Network( DNET_list );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Send_I_Am_Router_To_Network( DNET_list );
|
||||
}
|
||||
/* Send I-am-router-to-network with our one-network list if
|
||||
* our specific network is requested, or no specific
|
||||
* network is requested. Silently drop other DNET requests.
|
||||
*/
|
||||
if (npdu_len >= 2) {
|
||||
uint16_t network;
|
||||
len += decode_unsigned16(&npdu[len], &network);
|
||||
if (network == DNET_list[0]) {
|
||||
Send_I_Am_Router_To_Network(DNET_list);
|
||||
}
|
||||
} else {
|
||||
Send_I_Am_Router_To_Network(DNET_list);
|
||||
}
|
||||
break;
|
||||
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
|
||||
/* Per the standard, we are supposed to process this message and
|
||||
@@ -108,9 +104,9 @@ static void network_control_handler(
|
||||
* -- Unless we act upon NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK
|
||||
* later for congestion control - then it could matter.
|
||||
*/
|
||||
debug_printf("%s for Networks: ",
|
||||
bactext_network_layer_msg_name(
|
||||
NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK ) );
|
||||
debug_printf("%s for Networks: ",
|
||||
bactext_network_layer_msg_name
|
||||
(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK));
|
||||
while (npdu_len) {
|
||||
len = decode_unsigned16(&npdu[npdu_offset], &dnet);
|
||||
debug_printf("%hu", dnet);
|
||||
@@ -126,12 +122,12 @@ static void network_control_handler(
|
||||
/* Do nothing, same as previous case. */
|
||||
break;
|
||||
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
||||
if ( npdu_len >= 3 ) {
|
||||
if (npdu_len >= 3) {
|
||||
decode_unsigned16(&npdu[1], &dnet);
|
||||
debug_printf("Received %s for Network: ",
|
||||
bactext_network_layer_msg_name(
|
||||
NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK ) );
|
||||
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0] );
|
||||
bactext_network_layer_msg_name
|
||||
(NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK));
|
||||
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0]);
|
||||
}
|
||||
break;
|
||||
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
|
||||
@@ -143,18 +139,18 @@ static void network_control_handler(
|
||||
* NETWORK_MESSAGE_INIT_RT_TABLE_ACK and a list of all our
|
||||
* reachable networks.
|
||||
*/
|
||||
if ( npdu_len > 0) {
|
||||
/* If Number of Ports is 0, broadcast our "full" table */
|
||||
if (npdu[0] == 0)
|
||||
Send_Initialize_Routing_Table_Ack( NULL, DNET_list );
|
||||
else {
|
||||
/* If they sent us a list, just politely ACK it
|
||||
* with no routing list of our own. But we don't DO
|
||||
* anything with the info, either.
|
||||
*/
|
||||
int listTerminator = -1;
|
||||
Send_Initialize_Routing_Table_Ack( src, &listTerminator );
|
||||
}
|
||||
if (npdu_len > 0) {
|
||||
/* If Number of Ports is 0, broadcast our "full" table */
|
||||
if (npdu[0] == 0)
|
||||
Send_Initialize_Routing_Table_Ack(NULL, DNET_list);
|
||||
else {
|
||||
/* If they sent us a list, just politely ACK it
|
||||
* with no routing list of our own. But we don't DO
|
||||
* anything with the info, either.
|
||||
*/
|
||||
int listTerminator = -1;
|
||||
Send_Initialize_Routing_Table_Ack(src, &listTerminator);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* Else, fall through to do nothing. */
|
||||
@@ -168,9 +164,9 @@ static void network_control_handler(
|
||||
break;
|
||||
default:
|
||||
/* An unrecognized message is bad; send an error response. */
|
||||
Send_Reject_Message_To_Network( src,
|
||||
NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0] );
|
||||
/* Sending our DNET doesn't make a lot of sense, does it? */
|
||||
Send_Reject_Message_To_Network(src,
|
||||
NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]);
|
||||
/* Sending our DNET doesn't make a lot of sense, does it? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -190,31 +186,32 @@ static void network_control_handler(
|
||||
* Normally just one valid entry; terminated with a -1 value.
|
||||
* @param apdu [in] The apdu portion of the request, to be processed.
|
||||
* @param apdu_len [in] The total (remaining) length of the apdu.
|
||||
*/
|
||||
*/
|
||||
static void routed_apdu_handler(
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_ADDRESS * dest,
|
||||
int * DNET_list,
|
||||
uint8_t * apdu,
|
||||
int *DNET_list,
|
||||
uint8_t * apdu,
|
||||
uint16_t apdu_len)
|
||||
{
|
||||
int cursor = 0; /* Starting hint */
|
||||
{
|
||||
int cursor = 0; /* Starting hint */
|
||||
bool bGotOne = false;
|
||||
|
||||
if (!Routed_Device_Is_Valid_Network( dest->net, DNET_list ) ) {
|
||||
|
||||
if (!Routed_Device_Is_Valid_Network(dest->net, DNET_list)) {
|
||||
/* We don't know how to reach this one */
|
||||
Send_Reject_Message_To_Network( src, NETWORK_REJECT_NO_ROUTE, dest->net );
|
||||
Send_Reject_Message_To_Network(src, NETWORK_REJECT_NO_ROUTE,
|
||||
dest->net);
|
||||
return;
|
||||
}
|
||||
|
||||
while ( Routed_Device_GetNext( dest, DNET_list, &cursor ) ) {
|
||||
apdu_handler(src, apdu, apdu_len);
|
||||
bGotOne = true;
|
||||
if ( cursor < 0 ) /* If no more matches, */
|
||||
break; /* We don't need to keep looking */
|
||||
while (Routed_Device_GetNext(dest, DNET_list, &cursor)) {
|
||||
apdu_handler(src, apdu, apdu_len);
|
||||
bGotOne = true;
|
||||
if (cursor < 0) /* If no more matches, */
|
||||
break; /* We don't need to keep looking */
|
||||
}
|
||||
if ( !bGotOne ) {
|
||||
/* Just silently drop this packet. */
|
||||
if (!bGotOne) {
|
||||
/* Just silently drop this packet. */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,10 +246,10 @@ static void routed_apdu_handler(
|
||||
*/
|
||||
void routing_npdu_handler(
|
||||
BACNET_ADDRESS * src,
|
||||
int * DNET_list,
|
||||
uint8_t * pdu,
|
||||
int *DNET_list,
|
||||
uint8_t * pdu,
|
||||
uint16_t pdu_len)
|
||||
{
|
||||
{
|
||||
int apdu_offset = 0;
|
||||
BACNET_ADDRESS dest = { 0 };
|
||||
BACNET_NPDU_DATA npdu_data = { 0 };
|
||||
@@ -260,29 +257,28 @@ void routing_npdu_handler(
|
||||
/* only handle the version that we know how to handle */
|
||||
if (pdu[0] == BACNET_PROTOCOL_VERSION) {
|
||||
apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data);
|
||||
if ( apdu_offset <= 0 ) {
|
||||
if (apdu_offset <= 0) {
|
||||
debug_printf("NPDU: Decoding failed; Discarded!\n");
|
||||
} else if (npdu_data.network_layer_message) {
|
||||
if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) {
|
||||
network_control_handler( src, DNET_list, &npdu_data,
|
||||
&pdu[apdu_offset],
|
||||
(uint16_t) (pdu_len - apdu_offset));
|
||||
network_control_handler(src, DNET_list, &npdu_data,
|
||||
&pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset));
|
||||
} else {
|
||||
/* The DNET is set, but we don't support downstream routers,
|
||||
* so we just silently drop this network layer message,
|
||||
* since only routers can handle it (even if for our DNET) */
|
||||
}
|
||||
} else if (apdu_offset <= pdu_len) {
|
||||
if ( (dest.net == 0) || (npdu_data.hop_count > 1) )
|
||||
routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset],
|
||||
(uint16_t) (pdu_len - apdu_offset));
|
||||
/* Else, hop_count bottomed out and we discard this one. */
|
||||
if ((dest.net == 0) || (npdu_data.hop_count > 1))
|
||||
routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset],
|
||||
(uint16_t) (pdu_len - apdu_offset));
|
||||
/* Else, hop_count bottomed out and we discard this one. */
|
||||
}
|
||||
} else {
|
||||
/* Should we send NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK? */
|
||||
debug_printf(
|
||||
"NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
|
||||
(unsigned) pdu[0]);
|
||||
debug_printf
|
||||
("NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n",
|
||||
(unsigned) pdu[0]);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -170,7 +170,7 @@ int rp_ack_fully_decode_service_request(
|
||||
read_access_data->listOfProperties = rp1_property;
|
||||
if (rp1_property == NULL) {
|
||||
/* can't proceed if calloc failed. */
|
||||
return BACNET_STATUS_ERROR;
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
rp1_property->propertyIdentifier = rp1data.object_property;
|
||||
rp1_property->propertyArrayIndex = rp1data.array_index;
|
||||
@@ -227,7 +227,7 @@ int rp_ack_fully_decode_service_request(
|
||||
read_access_data->listOfProperties = NULL;
|
||||
return BACNET_STATUS_ERROR;
|
||||
}
|
||||
if (vlen > 0) {
|
||||
if (vlen > 0) {
|
||||
/* If more values */
|
||||
old_value = value;
|
||||
value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||
|
||||
@@ -220,8 +220,8 @@ void rpm_ack_print_data(
|
||||
#if PRINT_ENABLED
|
||||
if (listOfProperties->propertyIdentifier < 512) {
|
||||
fprintf(stdout, " %s: ",
|
||||
bactext_property_name(listOfProperties->
|
||||
propertyIdentifier));
|
||||
bactext_property_name
|
||||
(listOfProperties->propertyIdentifier));
|
||||
} else {
|
||||
fprintf(stdout, " proprietary %u: ",
|
||||
(unsigned) listOfProperties->propertyIdentifier);
|
||||
@@ -268,10 +268,10 @@ void rpm_ack_print_data(
|
||||
#if PRINT_ENABLED
|
||||
/* AccessError */
|
||||
fprintf(stdout, "BACnet Error: %s: %s\r\n",
|
||||
bactext_error_class_name((int) listOfProperties->
|
||||
error.error_class),
|
||||
bactext_error_code_name((int) listOfProperties->
|
||||
error.error_code));
|
||||
bactext_error_class_name((int) listOfProperties->error.
|
||||
error_class),
|
||||
bactext_error_code_name((int) listOfProperties->error.
|
||||
error_code));
|
||||
#endif
|
||||
}
|
||||
listOfProperties = listOfProperties->next;
|
||||
|
||||
@@ -104,8 +104,8 @@ void handler_ucov_notification(
|
||||
fprintf(stderr, "UCOV: ");
|
||||
if (pProperty_value->propertyIdentifier < 512) {
|
||||
fprintf(stderr, "%s ",
|
||||
bactext_property_name
|
||||
(pProperty_value->propertyIdentifier));
|
||||
bactext_property_name(pProperty_value->
|
||||
propertyIdentifier));
|
||||
} else {
|
||||
fprintf(stderr, "proprietary %u ",
|
||||
pProperty_value->propertyIdentifier);
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
* or object ID, if the Device has a match.
|
||||
* @param data [in] The decoded who-has payload from the request.
|
||||
*/
|
||||
static void match_name_or_object(
|
||||
BACNET_WHO_HAS_DATA * data)
|
||||
static void match_name_or_object(
|
||||
BACNET_WHO_HAS_DATA * data)
|
||||
{
|
||||
char *object_name = NULL;
|
||||
int object_type = 0;
|
||||
@@ -98,10 +98,10 @@ void handler_who_has(
|
||||
if ((data.low_limit == -1) || (data.high_limit == -1))
|
||||
directed_to_me = true;
|
||||
else if ((Device_Object_Instance_Number() >= (uint32_t) data.low_limit)
|
||||
&& (Device_Object_Instance_Number() <= (uint32_t) data.high_limit))
|
||||
&& (Device_Object_Instance_Number() <= (uint32_t) data.high_limit))
|
||||
directed_to_me = true;
|
||||
if (directed_to_me) {
|
||||
match_name_or_object(&data);
|
||||
match_name_or_object(&data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,23 +126,23 @@ void handler_who_has_for_routing(
|
||||
int len = 0;
|
||||
BACNET_WHO_HAS_DATA data;
|
||||
int32_t dev_instance;
|
||||
int cursor = 0; /* Starting hint */
|
||||
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
|
||||
int cursor = 0; /* Starting hint */
|
||||
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
|
||||
BACNET_ADDRESS bcast_net;
|
||||
|
||||
(void) src;
|
||||
len = whohas_decode_service_request(service_request, service_len, &data);
|
||||
if (len > 0) {
|
||||
/* Go through all devices, starting with the root gateway Device */
|
||||
memset( &bcast_net, 0, sizeof(BACNET_ADDRESS));
|
||||
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
|
||||
while ( Routed_Device_GetNext( &bcast_net, my_list, &cursor ) ) {
|
||||
dev_instance = Device_Object_Instance_Number();
|
||||
if ( (data.low_limit == -1) || (data.high_limit == -1) ||
|
||||
((dev_instance >= data.low_limit) &&
|
||||
(dev_instance <= data.high_limit)))
|
||||
match_name_or_object(&data);
|
||||
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
|
||||
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
|
||||
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
|
||||
dev_instance = Device_Object_Instance_Number();
|
||||
if ((data.low_limit == -1) || (data.high_limit == -1) ||
|
||||
((dev_instance >= data.low_limit) &&
|
||||
(dev_instance <= data.high_limit)))
|
||||
match_name_or_object(&data);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* BAC_ROUTING */
|
||||
#endif /* BAC_ROUTING */
|
||||
|
||||
@@ -127,44 +127,44 @@ static void check_who_is_for_routing(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src,
|
||||
bool is_unicast )
|
||||
bool is_unicast)
|
||||
{
|
||||
int len = 0;
|
||||
int32_t low_limit = 0;
|
||||
int32_t high_limit = 0;
|
||||
int32_t dev_instance;
|
||||
int cursor = 0; /* Starting hint */
|
||||
int my_list[2] = {0, -1}; /* Not really used, so dummy values */
|
||||
int cursor = 0; /* Starting hint */
|
||||
int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */
|
||||
BACNET_ADDRESS bcast_net;
|
||||
|
||||
|
||||
len =
|
||||
whois_decode_service_request(service_request, service_len, &low_limit,
|
||||
&high_limit);
|
||||
if (len == -1) {
|
||||
/* Invalid; just leave */
|
||||
return;
|
||||
/* Invalid; just leave */
|
||||
return;
|
||||
}
|
||||
/* If len == 0, then high_limit is untouched and still == 0 */
|
||||
/* BACnet wildcard is the max instance number - everyone responds */
|
||||
if ((BACNET_MAX_INSTANCE >= (uint32_t) low_limit) &&
|
||||
(BACNET_MAX_INSTANCE <= (uint32_t) high_limit))
|
||||
high_limit = 0;
|
||||
/* This is the "always accept" case we will test for below */
|
||||
high_limit = 0;
|
||||
/* This is the "always accept" case we will test for below */
|
||||
|
||||
/* Go through all devices, starting with the root gateway Device */
|
||||
memset( &bcast_net, 0, sizeof(BACNET_ADDRESS));
|
||||
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
|
||||
|
||||
while ( Routed_Device_GetNext( &bcast_net, my_list, &cursor ) ) {
|
||||
dev_instance = Device_Object_Instance_Number();
|
||||
if ( (high_limit == 0) ||
|
||||
((dev_instance >= low_limit) && (dev_instance <= high_limit))) {
|
||||
if ( is_unicast )
|
||||
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
|
||||
else
|
||||
Send_I_Am(&Handler_Transmit_Buffer[0]);
|
||||
}
|
||||
}
|
||||
memset(&bcast_net, 0, sizeof(BACNET_ADDRESS));
|
||||
bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */
|
||||
|
||||
while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) {
|
||||
dev_instance = Device_Object_Instance_Number();
|
||||
if ((high_limit == 0) || ((dev_instance >= low_limit) &&
|
||||
(dev_instance <= high_limit))) {
|
||||
if (is_unicast)
|
||||
Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src);
|
||||
else
|
||||
Send_I_Am(&Handler_Transmit_Buffer[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ void handler_who_is_bcast_for_routing(
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
check_who_is_for_routing(service_request, service_len, src, false );
|
||||
check_who_is_for_routing(service_request, service_len, src, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,6 @@ void handler_who_is_unicast_for_routing(
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src)
|
||||
{
|
||||
check_who_is_for_routing(service_request, service_len, src, true );
|
||||
check_who_is_for_routing(service_request, service_len, src, true);
|
||||
}
|
||||
#endif /* BAC_ROUTING */
|
||||
#endif /* BAC_ROUTING */
|
||||
|
||||
@@ -178,12 +178,11 @@ bool WPValidateString(
|
||||
0)) {
|
||||
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
} else if ((bEmptyAllowed == false) &&
|
||||
(!characterstring_printable(
|
||||
&pValue->type.Character_String))) {
|
||||
(!characterstring_printable(&pValue->type.Character_String))) {
|
||||
/* assumption: non-empty also means must be "printable" */
|
||||
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
} else if (characterstring_length(&pValue->
|
||||
type.Character_String) >= iMaxLen) {
|
||||
} else if (characterstring_length(&pValue->type.
|
||||
Character_String) >= iMaxLen) {
|
||||
*pErrorClass = ERROR_CLASS_RESOURCES;
|
||||
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
|
||||
} else
|
||||
|
||||
@@ -70,7 +70,7 @@ uint8_t Send_CEvent_Notify(
|
||||
invoke_id = tsm_next_free_invokeID();
|
||||
if (invoke_id) {
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
|
||||
@@ -65,7 +65,8 @@ int iam_encode_pdu(
|
||||
pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
|
||||
len =
|
||||
iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(),
|
||||
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
|
||||
pdu_len += len;
|
||||
|
||||
@@ -139,8 +140,9 @@ int iam_unicast_encode_pdu(
|
||||
npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
apdu_len = iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
|
||||
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
|
||||
apdu_len =
|
||||
iam_encode_apdu(&buffer[npdu_len], Device_Object_Instance_Number(),
|
||||
MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier());
|
||||
pdu_len = npdu_len + apdu_len;
|
||||
|
||||
return pdu_len;
|
||||
|
||||
@@ -75,7 +75,9 @@ void Send_I_Have(
|
||||
datalink_get_broadcast_address(&dest);
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
data.device_id.type = OBJECT_DEVICE;
|
||||
|
||||
@@ -71,7 +71,7 @@ static void npdu_encode_npdu_network(
|
||||
npdu_data->network_message_type = network_message_type; /* optional */
|
||||
npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */
|
||||
npdu_data->priority = priority;
|
||||
npdu_data->hop_count = DFLT_HOP_COUNT;
|
||||
npdu_data->hop_count = DFLT_HOP_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,119 +97,117 @@ static void npdu_encode_npdu_network(
|
||||
* the type of message.
|
||||
* @return Number of bytes sent, or <=0 if no message was sent.
|
||||
*/
|
||||
int Send_Network_Layer_Message(
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
BACNET_ADDRESS * dst,
|
||||
int * iArgs )
|
||||
int Send_Network_Layer_Message(
|
||||
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
|
||||
BACNET_ADDRESS * dst,
|
||||
int *iArgs)
|
||||
{
|
||||
int len = 0;
|
||||
int pdu_len = 0;
|
||||
int bytes_sent = 0;
|
||||
int *pVal = iArgs; /* Start with first value */
|
||||
int *pVal = iArgs; /* Start with first value */
|
||||
bool data_expecting_reply = false;
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
BACNET_ADDRESS bcastDest;
|
||||
|
||||
if ( iArgs == NULL )
|
||||
return 0; /* Can't do anything here */
|
||||
|
||||
|
||||
if (iArgs == NULL)
|
||||
return 0; /* Can't do anything here */
|
||||
|
||||
/* If dst was NULL, get our (local net) broadcast MAC address. */
|
||||
if ( dst == NULL ) {
|
||||
datalink_get_broadcast_address(&bcastDest);
|
||||
dst = &bcastDest;
|
||||
if (dst == NULL) {
|
||||
datalink_get_broadcast_address(&bcastDest);
|
||||
dst = &bcastDest;
|
||||
}
|
||||
|
||||
if ( network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE )
|
||||
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE)
|
||||
data_expecting_reply = true; /* DER in this one case */
|
||||
npdu_encode_npdu_network(&npdu_data,
|
||||
network_message_type, data_expecting_reply,
|
||||
MESSAGE_PRIORITY_NORMAL);
|
||||
|
||||
npdu_encode_npdu_network(&npdu_data, network_message_type,
|
||||
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
|
||||
|
||||
/* We don't need src information, since a message can't originate from
|
||||
* our downstream BACnet network.
|
||||
*/
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dst, NULL, &npdu_data);
|
||||
|
||||
/* Now encode the optional payload bytes, per message type */
|
||||
switch ( network_message_type )
|
||||
{
|
||||
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
||||
if (*pVal >= 0) {
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) *pVal);
|
||||
pdu_len += len;
|
||||
}
|
||||
/* else, don't encode a DNET */
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||
while ( *pVal >= 0 ) {
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) *pVal);
|
||||
pdu_len += len;
|
||||
pVal++;
|
||||
}
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
||||
/* Encode the Reason byte, then the DNET */
|
||||
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) *pVal;
|
||||
pVal++;
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) *pVal);
|
||||
pdu_len += len;
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_INIT_RT_TABLE:
|
||||
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
|
||||
/* First, count the number of Ports we will encode */
|
||||
len = 0; /* Re-purpose len as our counter here */
|
||||
while ( *pVal >= 0 ) {
|
||||
len++;
|
||||
pVal++;
|
||||
}
|
||||
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len;
|
||||
|
||||
if ( len > 0 ) {
|
||||
uint8_t portID = 1;
|
||||
pVal = iArgs; /* Reset to beginning */
|
||||
/* Now encode each (virtual) BACNET_ROUTER_PORT.
|
||||
* We will simply use a positive index for PortID,
|
||||
* and have no PortInfo.
|
||||
*/
|
||||
while ( *pVal >= 0 ) {
|
||||
/* Now encode the optional payload bytes, per message type */
|
||||
switch (network_message_type) {
|
||||
case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK:
|
||||
if (*pVal >= 0) {
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) *pVal);
|
||||
(uint16_t) * pVal);
|
||||
pdu_len += len;
|
||||
}
|
||||
/* else, don't encode a DNET */
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK:
|
||||
case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK:
|
||||
while (*pVal >= 0) {
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) * pVal);
|
||||
pdu_len += len;
|
||||
Handler_Transmit_Buffer[pdu_len++] = portID++;
|
||||
Handler_Transmit_Buffer[pdu_len++] = 0;
|
||||
debug_printf( " Sending Routing Table entry for %u \n", *pVal );
|
||||
pVal++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
debug_printf("Not sent: %s message unsupported \n",
|
||||
bactext_network_layer_msg_name( network_message_type ) );
|
||||
return 0;
|
||||
break; /* Will never reach this line */
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
|
||||
/* Encode the Reason byte, then the DNET */
|
||||
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) * pVal;
|
||||
pVal++;
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) * pVal);
|
||||
pdu_len += len;
|
||||
break;
|
||||
|
||||
case NETWORK_MESSAGE_INIT_RT_TABLE:
|
||||
case NETWORK_MESSAGE_INIT_RT_TABLE_ACK:
|
||||
/* First, count the number of Ports we will encode */
|
||||
len = 0; /* Re-purpose len as our counter here */
|
||||
while (*pVal >= 0) {
|
||||
len++;
|
||||
pVal++;
|
||||
}
|
||||
Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len;
|
||||
|
||||
if (len > 0) {
|
||||
uint8_t portID = 1;
|
||||
pVal = iArgs; /* Reset to beginning */
|
||||
/* Now encode each (virtual) BACNET_ROUTER_PORT.
|
||||
* We will simply use a positive index for PortID,
|
||||
* and have no PortInfo.
|
||||
*/
|
||||
while (*pVal >= 0) {
|
||||
len =
|
||||
encode_unsigned16(&Handler_Transmit_Buffer[pdu_len],
|
||||
(uint16_t) * pVal);
|
||||
pdu_len += len;
|
||||
Handler_Transmit_Buffer[pdu_len++] = portID++;
|
||||
Handler_Transmit_Buffer[pdu_len++] = 0;
|
||||
debug_printf(" Sending Routing Table entry for %u \n",
|
||||
*pVal);
|
||||
pVal++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
debug_printf("Not sent: %s message unsupported \n",
|
||||
bactext_network_layer_msg_name(network_message_type));
|
||||
return 0;
|
||||
break; /* Will never reach this line */
|
||||
}
|
||||
|
||||
if ( dst != NULL )
|
||||
debug_printf("Sending %s message to BACnet network %u \n",
|
||||
bactext_network_layer_msg_name( network_message_type ),
|
||||
dst->net );
|
||||
|
||||
if (dst != NULL)
|
||||
debug_printf("Sending %s message to BACnet network %u \n",
|
||||
bactext_network_layer_msg_name(network_message_type), dst->net);
|
||||
else
|
||||
debug_printf("Sending %s message to local BACnet network \n",
|
||||
bactext_network_layer_msg_name( network_message_type ) );
|
||||
debug_printf("Sending %s message to local BACnet network \n",
|
||||
bactext_network_layer_msg_name(network_message_type));
|
||||
|
||||
/* Now send the message */
|
||||
bytes_sent =
|
||||
@@ -217,13 +215,13 @@ int Send_Network_Layer_Message(
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0) {
|
||||
int wasErrno = errno; /* preserve the errno */
|
||||
debug_printf("Failed to send %s message (%s)!\n",
|
||||
bactext_network_layer_msg_name( network_message_type ),
|
||||
int wasErrno = errno; /* preserve the errno */
|
||||
debug_printf("Failed to send %s message (%s)!\n",
|
||||
bactext_network_layer_msg_name(network_message_type),
|
||||
strerror(wasErrno));
|
||||
}
|
||||
#endif
|
||||
return bytes_sent;
|
||||
return bytes_sent;
|
||||
}
|
||||
|
||||
|
||||
@@ -242,8 +240,8 @@ void Send_Who_Is_Router_To_Network(
|
||||
BACNET_ADDRESS * dst,
|
||||
int dnet)
|
||||
{
|
||||
Send_Network_Layer_Message( NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK,
|
||||
dst, &dnet );
|
||||
Send_Network_Layer_Message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, dst,
|
||||
&dnet);
|
||||
}
|
||||
|
||||
/** Broadcast an I-am-router-to-network message, giving the list of networks
|
||||
@@ -259,8 +257,8 @@ void Send_I_Am_Router_To_Network(
|
||||
const int DNET_list[])
|
||||
{
|
||||
/* Use a NULL dst here since we want a broadcast MAC address. */
|
||||
Send_Network_Layer_Message( NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||
NULL, (int *) DNET_list );
|
||||
Send_Network_Layer_Message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, NULL,
|
||||
(int *) DNET_list);
|
||||
}
|
||||
|
||||
/** Finds a specific router, or all reachable BACnet networks.
|
||||
@@ -281,9 +279,9 @@ void Send_Reject_Message_To_Network(
|
||||
int iArgs[2];
|
||||
iArgs[0] = reject_reason;
|
||||
iArgs[1] = dnet;
|
||||
Send_Network_Layer_Message( NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK,
|
||||
dst, iArgs );
|
||||
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet );
|
||||
Send_Network_Layer_Message(NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst,
|
||||
iArgs);
|
||||
debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet);
|
||||
}
|
||||
|
||||
|
||||
@@ -308,8 +306,8 @@ void Send_Initialize_Routing_Table(
|
||||
const int DNET_list[])
|
||||
{
|
||||
/* Use a NULL dst here since we want a broadcast MAC address. */
|
||||
Send_Network_Layer_Message( NETWORK_MESSAGE_INIT_RT_TABLE,
|
||||
dst, (int *) DNET_list );
|
||||
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst,
|
||||
(int *) DNET_list);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,6 +332,6 @@ void Send_Initialize_Routing_Table_Ack(
|
||||
BACNET_ADDRESS * dst,
|
||||
const int DNET_list[])
|
||||
{
|
||||
Send_Network_Layer_Message( NETWORK_MESSAGE_INIT_RT_TABLE_ACK,
|
||||
dst, (int *) DNET_list );
|
||||
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, dst,
|
||||
(int *) DNET_list);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,8 @@ void Send_TimeSync(
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
len =
|
||||
@@ -101,7 +102,8 @@ void Send_TimeSyncUTC(
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
pdu_len =
|
||||
|
||||
@@ -61,7 +61,9 @@ void Send_UnconfirmedPrivateTransfer(
|
||||
datalink_get_my_address(&my_address);
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
len =
|
||||
|
||||
@@ -77,7 +77,8 @@ void Send_WhoHas_Name(
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
data.low_limit = low_limit;
|
||||
@@ -131,7 +132,8 @@ void Send_WhoHas_Object(
|
||||
/* encode the NPDU portion of the packet */
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address,
|
||||
&npdu_data);
|
||||
|
||||
/* encode the APDU portion of the packet */
|
||||
data.low_limit = low_limit;
|
||||
|
||||
@@ -72,7 +72,8 @@ void Send_WhoIs_To_Network(
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, &my_address, &npdu_data);
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address,
|
||||
&my_address, &npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
len =
|
||||
whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit,
|
||||
|
||||
@@ -155,9 +155,8 @@ uint8_t Send_Write_Property_Request(
|
||||
#if PRINT_ENABLED_DEBUG
|
||||
fprintf(stderr, "WriteProperty service: " "%s tag=%d\n",
|
||||
(object_value->context_specific ? "context" : "application"),
|
||||
(int) (object_value->
|
||||
context_specific ? object_value->context_tag : object_value->
|
||||
tag));
|
||||
(int) (object_value->context_specific ? object_value->
|
||||
context_tag : object_value->tag));
|
||||
#endif
|
||||
len = bacapp_encode_data(&application_data[apdu_len], object_value);
|
||||
if ((len + apdu_len) < MAX_APDU) {
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -50,8 +50,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
@@ -61,12 +61,12 @@ static uint8_t Rx_Buf[MAX_MPDU] = { 0 };
|
||||
static BACNET_ADDRESS Target_Router_Address;
|
||||
/* static BACNET_ROUTER_PORT *Target_Router_Port_List; */
|
||||
|
||||
#define VIRTUAL_DNET 2709 /* your choice of number here */
|
||||
#define VIRTUAL_DNET 2709 /* your choice of number here */
|
||||
/** The list of DNETs that our router can reach.
|
||||
* Only one entry since we don't support downstream routers.
|
||||
*/
|
||||
int DNET_list[2] = {
|
||||
VIRTUAL_DNET, -1 /* Need -1 terminator */
|
||||
VIRTUAL_DNET, -1 /* Need -1 terminator */
|
||||
};
|
||||
|
||||
static bool Error_Detected = false;
|
||||
@@ -333,8 +333,7 @@ int main(
|
||||
last_seconds = time(NULL);
|
||||
timeout_seconds = apdu_timeout() / 1000;
|
||||
/* send the request */
|
||||
Send_Initialize_Routing_Table(&Target_Router_Address,
|
||||
DNET_list);
|
||||
Send_Initialize_Routing_Table(&Target_Router_Address, DNET_list);
|
||||
/* loop forever */
|
||||
for (;;) {
|
||||
/* increment timer - exit if timed out */
|
||||
|
||||
@@ -182,7 +182,7 @@ int Analog_Input_Read_Property(
|
||||
return 0;
|
||||
}
|
||||
apdu = rpdata->application_data;
|
||||
switch ((int)rpdata->object_property) {
|
||||
switch ((int) rpdata->object_property) {
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len =
|
||||
encode_application_object_id(&apdu[0], OBJECT_ANALOG_INPUT,
|
||||
|
||||
@@ -446,11 +446,11 @@ bool Analog_Output_Write_Property(
|
||||
if (status) {
|
||||
level = AO_LEVEL_NULL;
|
||||
object_index =
|
||||
Analog_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Analog_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
status =
|
||||
Analog_Output_Present_Value_Relinquish
|
||||
(wp_data->object_instance, wp_data->priority);
|
||||
Analog_Output_Present_Value_Relinquish(wp_data->
|
||||
object_instance, wp_data->priority);
|
||||
if (!status) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
|
||||
@@ -396,8 +396,8 @@ bool Analog_Value_Write_Property(
|
||||
if (status) {
|
||||
level = ANALOG_LEVEL_NULL;
|
||||
object_index =
|
||||
Analog_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Analog_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority = wp_data->priority;
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||
priority--;
|
||||
|
||||
@@ -375,8 +375,8 @@ bool Binary_Output_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = (BACNET_BINARY_PV) value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Binary_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority--;
|
||||
Binary_Output_Level[object_index][priority] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
@@ -402,8 +402,8 @@ bool Binary_Output_Write_Property(
|
||||
if (status) {
|
||||
level = BINARY_NULL;
|
||||
object_index =
|
||||
Binary_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Binary_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority = wp_data->priority;
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||
priority--;
|
||||
|
||||
@@ -358,8 +358,8 @@ bool Binary_Value_Write_Property(
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
level = (BACNET_BINARY_PV) value.type.Enumerated;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority--;
|
||||
Binary_Value_Level[object_index][priority] = level;
|
||||
/* Note: you could set the physical output here if we
|
||||
@@ -385,8 +385,8 @@ bool Binary_Value_Write_Property(
|
||||
if (status) {
|
||||
level = BINARY_NULL;
|
||||
object_index =
|
||||
Binary_Value_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Binary_Value_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority = wp_data->priority;
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||
priority--;
|
||||
|
||||
@@ -354,7 +354,7 @@ uint32_t Device_Object_Instance_Number(
|
||||
void)
|
||||
{
|
||||
#ifdef BAC_ROUTING
|
||||
return Routed_Device_Object_Instance_Number();
|
||||
return Routed_Device_Object_Instance_Number();
|
||||
#else
|
||||
return Object_Instance_Number;
|
||||
#endif
|
||||
@@ -1141,8 +1141,8 @@ bool Device_Write_Property_Local(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
(Device_Set_Object_Instance_Number(value.type.Object_Id.
|
||||
instance))) {
|
||||
/* FIXME: we could send an I-Am broadcast to let the world know */
|
||||
} else {
|
||||
status = false;
|
||||
@@ -1175,8 +1175,8 @@ bool Device_Write_Property_Local(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
/* FIXME: bounds check? */
|
||||
Device_Set_Vendor_Identifier((uint16_t) value.
|
||||
type.Unsigned_Int);
|
||||
Device_Set_Vendor_Identifier((uint16_t) value.type.
|
||||
Unsigned_Int);
|
||||
}
|
||||
break;
|
||||
case PROP_SYSTEM_STATUS:
|
||||
@@ -1203,8 +1203,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_NAME_LEN, false,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Object_Name(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Device_Set_Object_Name(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -1213,8 +1213,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_LOC_LEN, true,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Location(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Device_Set_Location(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -1224,8 +1224,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_DESC_LEN, true,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Description(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Device_Set_Description(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -1234,8 +1234,8 @@ bool Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_MOD_LEN, true,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Device_Set_Model_Name(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Device_Set_Model_Name(characterstring_value(&value.type.
|
||||
Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
@@ -1247,8 +1247,8 @@ bool Device_Write_Property_Local(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
if (value.type.Unsigned_Int <= 255) {
|
||||
dlmstp_set_max_info_frames((uint8_t) value.
|
||||
type.Unsigned_Int);
|
||||
dlmstp_set_max_info_frames((uint8_t) value.type.
|
||||
Unsigned_Int);
|
||||
} else {
|
||||
status = false;
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
@@ -1328,7 +1328,7 @@ bool Device_Write_Property(
|
||||
* functions in order to properly support the default handlers.
|
||||
*/
|
||||
void Device_Initialize_Object_Functions(
|
||||
object_functions_t *object_table)
|
||||
object_functions_t * object_table)
|
||||
{
|
||||
Object_Table = object_table;
|
||||
}
|
||||
@@ -1407,25 +1407,26 @@ bool DeviceGetRRInfo(
|
||||
instance number.
|
||||
*/
|
||||
void Routing_Device_Init(
|
||||
uint32_t first_object_instance )
|
||||
uint32_t first_object_instance)
|
||||
{
|
||||
struct object_functions *pDevObject = NULL;
|
||||
|
||||
/* First, do the usual Device_Init() functions: */
|
||||
Device_Init();
|
||||
/* Initialize with our preset strings */
|
||||
Add_Routed_Device( first_object_instance, My_Object_Name, Description );
|
||||
Add_Routed_Device(first_object_instance, My_Object_Name, Description);
|
||||
|
||||
/* Now substitute our routed versions of the main object functions. */
|
||||
pDevObject = &Object_Table[0];
|
||||
pDevObject->Object_Index_To_Instance = Routed_Device_Index_To_Instance;
|
||||
pDevObject->Object_Valid_Instance = Routed_Device_Valid_Object_Instance_Number;
|
||||
pDevObject->Object_Valid_Instance =
|
||||
Routed_Device_Valid_Object_Instance_Number;
|
||||
pDevObject->Object_Name = Routed_Device_Name;
|
||||
pDevObject->Object_Read_Property = Routed_Device_Read_Property_Local;
|
||||
pDevObject->Object_Write_Property = Routed_Device_Write_Property_Local;
|
||||
}
|
||||
|
||||
#endif /* BAC_ROUTING */
|
||||
#endif /* BAC_ROUTING */
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
@@ -114,32 +114,30 @@ uint16_t iCurrent_Device_Idx = 0;
|
||||
* @return The index of this instance in the Devices[] array,
|
||||
* or -1 if there isn't enough room to add this Device.
|
||||
*/
|
||||
uint16_t Add_Routed_Device(
|
||||
uint32_t Object_Instance,
|
||||
const char * sObject_Name,
|
||||
const char * sDescription )
|
||||
uint16_t Add_Routed_Device(
|
||||
uint32_t Object_Instance,
|
||||
const char *sObject_Name,
|
||||
const char *sDescription)
|
||||
{
|
||||
int i = Num_Managed_Devices;
|
||||
if ( i < MAX_NUM_DEVICES )
|
||||
{
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[i];
|
||||
Num_Managed_Devices++;
|
||||
iCurrent_Device_Idx = i;
|
||||
pDev->bacObj.mObject_Type = OBJECT_DEVICE;
|
||||
pDev->bacObj.Object_Instance_Number = Object_Instance;
|
||||
if ( sObject_Name != NULL )
|
||||
Routed_Device_Set_Object_Name( sObject_Name, strlen( sObject_Name ));
|
||||
else
|
||||
Routed_Device_Set_Object_Name( "No Name", strlen( "No Name" ));
|
||||
if ( sDescription != NULL )
|
||||
Routed_Device_Set_Description( sDescription, strlen( sDescription ));
|
||||
else
|
||||
Routed_Device_Set_Description( "No Descr", strlen( "No Descr" ));
|
||||
pDev->Database_Revision = 0; /* Reset/Initialize now */
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
int i = Num_Managed_Devices;
|
||||
if (i < MAX_NUM_DEVICES) {
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[i];
|
||||
Num_Managed_Devices++;
|
||||
iCurrent_Device_Idx = i;
|
||||
pDev->bacObj.mObject_Type = OBJECT_DEVICE;
|
||||
pDev->bacObj.Object_Instance_Number = Object_Instance;
|
||||
if (sObject_Name != NULL)
|
||||
Routed_Device_Set_Object_Name(sObject_Name, strlen(sObject_Name));
|
||||
else
|
||||
Routed_Device_Set_Object_Name("No Name", strlen("No Name"));
|
||||
if (sDescription != NULL)
|
||||
Routed_Device_Set_Description(sDescription, strlen(sDescription));
|
||||
else
|
||||
Routed_Device_Set_Description("No Descr", strlen("No Descr"));
|
||||
pDev->Database_Revision = 0; /* Reset/Initialize now */
|
||||
return i;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,17 +150,16 @@ uint16_t Add_Routed_Device(
|
||||
* @return Pointer to the requested Device Object data, or NULL if the idx
|
||||
* is for an invalid row entry (eg, after the last good Device).
|
||||
*/
|
||||
DEVICE_OBJECT_DATA * Get_Routed_Device_Object(
|
||||
int idx )
|
||||
DEVICE_OBJECT_DATA *Get_Routed_Device_Object(
|
||||
int idx)
|
||||
{
|
||||
if ( idx == -1 )
|
||||
return &Devices[iCurrent_Device_Idx];
|
||||
else if ( (idx >= 0) && (idx < MAX_NUM_DEVICES) ) {
|
||||
iCurrent_Device_Idx = idx;
|
||||
return &Devices[idx];
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
if (idx == -1)
|
||||
return &Devices[iCurrent_Device_Idx];
|
||||
else if ((idx >= 0) && (idx < MAX_NUM_DEVICES)) {
|
||||
iCurrent_Device_Idx = idx;
|
||||
return &Devices[idx];
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Return the BACnet address for the indicated entry.
|
||||
@@ -174,17 +171,16 @@ DEVICE_OBJECT_DATA * Get_Routed_Device_Object(
|
||||
* @return Pointer to the requested Device Object BACnet address, or NULL if the idx
|
||||
* is for an invalid row entry (eg, after the last good Device).
|
||||
*/
|
||||
BACNET_ADDRESS * Get_Routed_Device_Address(
|
||||
int idx )
|
||||
BACNET_ADDRESS *Get_Routed_Device_Address(
|
||||
int idx)
|
||||
{
|
||||
if ( idx == -1 )
|
||||
return &Devices[iCurrent_Device_Idx].bacDevAddr;
|
||||
else if ( (idx >= 0) && (idx < MAX_NUM_DEVICES) ) {
|
||||
iCurrent_Device_Idx = idx;
|
||||
return &Devices[idx].bacDevAddr;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
if (idx == -1)
|
||||
return &Devices[iCurrent_Device_Idx].bacDevAddr;
|
||||
else if ((idx >= 0) && (idx < MAX_NUM_DEVICES)) {
|
||||
iCurrent_Device_Idx = idx;
|
||||
return &Devices[idx].bacDevAddr;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,11 +194,10 @@ BACNET_ADDRESS * Get_Routed_Device_Address(
|
||||
*/
|
||||
void routed_get_my_address(
|
||||
BACNET_ADDRESS * my_address)
|
||||
|
||||
{
|
||||
if (my_address) {
|
||||
memcpy(my_address, &Devices[iCurrent_Device_Idx].bacDevAddr,
|
||||
sizeof( BACNET_ADDRESS ));
|
||||
memcpy(my_address, &Devices[iCurrent_Device_Idx].bacDevAddr,
|
||||
sizeof(BACNET_ADDRESS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,32 +219,32 @@ void routed_get_my_address(
|
||||
* meaning MAC broadcast, so it's an automatic match).
|
||||
* Else False if no match or invalid idx is given.
|
||||
*/
|
||||
bool Routed_Device_Address_Lookup(
|
||||
int idx,
|
||||
uint8_t address_len,
|
||||
uint8_t * mac_adress )
|
||||
bool Routed_Device_Address_Lookup(
|
||||
int idx,
|
||||
uint8_t address_len,
|
||||
uint8_t * mac_adress)
|
||||
{
|
||||
bool result = false;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[idx];
|
||||
int i;
|
||||
bool result = false;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[idx];
|
||||
int i;
|
||||
|
||||
if ( (idx >= 0) && (idx < MAX_NUM_DEVICES) ) {
|
||||
if ( address_len == 0 ) {
|
||||
/* Automatic match */
|
||||
iCurrent_Device_Idx = idx;
|
||||
result = true;
|
||||
} else if ( mac_adress != NULL ) {
|
||||
for (i = 0; i < address_len; i++) {
|
||||
if (pDev->bacDevAddr.mac[i] != mac_adress[i])
|
||||
break;
|
||||
}
|
||||
if ( i == address_len ) { /* Success! */
|
||||
iCurrent_Device_Idx = idx;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
if ((idx >= 0) && (idx < MAX_NUM_DEVICES)) {
|
||||
if (address_len == 0) {
|
||||
/* Automatic match */
|
||||
iCurrent_Device_Idx = idx;
|
||||
result = true;
|
||||
} else if (mac_adress != NULL) {
|
||||
for (i = 0; i < address_len; i++) {
|
||||
if (pDev->bacDevAddr.mac[i] != mac_adress[i])
|
||||
break;
|
||||
}
|
||||
if (i == address_len) { /* Success! */
|
||||
iCurrent_Device_Idx = idx;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -279,63 +274,61 @@ bool Routed_Device_Address_Lookup(
|
||||
* Else False if no match or invalid idx is given; the cursor will
|
||||
* be returned as -1 in these cases.
|
||||
*/
|
||||
bool Routed_Device_GetNext(
|
||||
BACNET_ADDRESS * dest,
|
||||
int * DNET_list,
|
||||
int * cursor )
|
||||
bool Routed_Device_GetNext(
|
||||
BACNET_ADDRESS * dest,
|
||||
int *DNET_list,
|
||||
int *cursor)
|
||||
{
|
||||
int dnet = DNET_list[0]; /* Get the DNET of our virtual network */
|
||||
int dnet = DNET_list[0]; /* Get the DNET of our virtual network */
|
||||
int idx = *cursor;
|
||||
bool bSuccess = false;
|
||||
|
||||
|
||||
/* First, see if the index is out of range.
|
||||
* Eg, last call to GetNext may have been the last successful one.
|
||||
*/
|
||||
if ( (idx < 0) || (idx >= MAX_NUM_DEVICES) )
|
||||
idx = -1;
|
||||
|
||||
if ((idx < 0) || (idx >= MAX_NUM_DEVICES))
|
||||
idx = -1;
|
||||
|
||||
/* Next, see if it's a BACnet broadcast.
|
||||
* For broadcasts, all Devices get a chance at it.
|
||||
*/
|
||||
else if (dest->net == BACNET_BROADCAST_NETWORK) {
|
||||
/* Just take the entry indexed by the cursor */
|
||||
bSuccess = Routed_Device_Address_Lookup( idx++,
|
||||
dest->len, dest->adr );
|
||||
/* Just take the entry indexed by the cursor */
|
||||
bSuccess = Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
|
||||
}
|
||||
/* Or see if it's for the main Gateway Device, because
|
||||
* there's no routing info.
|
||||
*/
|
||||
else if (dest->net == 0) {
|
||||
else if (dest->net == 0) {
|
||||
/* Handle like a normal, non-routed access of the Gateway Device.
|
||||
* But first, make sure our internal access is pointing at
|
||||
* that Device in our table by telling it "no routing info" : */
|
||||
bSuccess = Routed_Device_Address_Lookup( 0,
|
||||
dest->len, dest->adr );
|
||||
/* Next step: no more matches: */
|
||||
idx = -1;
|
||||
bSuccess = Routed_Device_Address_Lookup(0, dest->len, dest->adr);
|
||||
/* Next step: no more matches: */
|
||||
idx = -1;
|
||||
}
|
||||
/* Or if is our virtual DNET, check
|
||||
* against each of our virtually routed Devices.
|
||||
* If we get a match, have it handle the APDU.
|
||||
* For broadcasts, all Devices get a chance at it.
|
||||
*/
|
||||
else if (dest->net == dnet) {
|
||||
if ( idx == 0 ) /* Step over this case (starting point) */
|
||||
idx = 1;
|
||||
while (idx < MAX_NUM_DEVICES) {
|
||||
bSuccess = Routed_Device_Address_Lookup( idx++,
|
||||
dest->len, dest->adr );
|
||||
if ( bSuccess )
|
||||
break; /* We don't need to keep looking */
|
||||
}
|
||||
}
|
||||
else if (dest->net == dnet) {
|
||||
if (idx == 0) /* Step over this case (starting point) */
|
||||
idx = 1;
|
||||
while (idx < MAX_NUM_DEVICES) {
|
||||
bSuccess =
|
||||
Routed_Device_Address_Lookup(idx++, dest->len, dest->adr);
|
||||
if (bSuccess)
|
||||
break; /* We don't need to keep looking */
|
||||
}
|
||||
}
|
||||
|
||||
if ( !bSuccess )
|
||||
*cursor = -1;
|
||||
else if ( idx == MAX_NUM_DEVICES ) /* No more to GetNext */
|
||||
*cursor = -1;
|
||||
if (!bSuccess)
|
||||
*cursor = -1;
|
||||
else if (idx == MAX_NUM_DEVICES) /* No more to GetNext */
|
||||
*cursor = -1;
|
||||
else
|
||||
*cursor = idx;
|
||||
*cursor = idx;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
@@ -353,24 +346,24 @@ bool Routed_Device_GetNext(
|
||||
* an automatic match.
|
||||
* Else False if not a reachable network.
|
||||
*/
|
||||
bool Routed_Device_Is_Valid_Network(
|
||||
uint16_t dest_net,
|
||||
int * DNET_list )
|
||||
bool Routed_Device_Is_Valid_Network(
|
||||
uint16_t dest_net,
|
||||
int *DNET_list)
|
||||
{
|
||||
int dnet = DNET_list[0]; /* Get the DNET of our virtual network */
|
||||
int dnet = DNET_list[0]; /* Get the DNET of our virtual network */
|
||||
bool bSuccess = false;
|
||||
|
||||
|
||||
/* First, see if it's a BACnet broadcast (automatic pass). */
|
||||
if ( dest_net == BACNET_BROADCAST_NETWORK)
|
||||
bSuccess = true;
|
||||
if (dest_net == BACNET_BROADCAST_NETWORK)
|
||||
bSuccess = true;
|
||||
/* Or see if it's for the main Gateway Device, because
|
||||
* there's no routing info.
|
||||
*/
|
||||
else if (dest_net == 0)
|
||||
bSuccess = true;
|
||||
else if (dest_net == 0)
|
||||
bSuccess = true;
|
||||
/* Or see if matches our virtual DNET */
|
||||
else if (dest_net == dnet)
|
||||
bSuccess = true;
|
||||
else if (dest_net == dnet)
|
||||
bSuccess = true;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
@@ -396,20 +389,20 @@ uint32_t Routed_Device_Index_To_Instance(
|
||||
bool Routed_Device_Valid_Object_Instance_Number(
|
||||
uint32_t object_id)
|
||||
{
|
||||
bool bResult = false;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
bool bResult = false;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
/* BACnet allows for a wildcard instance number */
|
||||
if (object_id == BACNET_MAX_INSTANCE)
|
||||
bResult = true;
|
||||
if ( pDev->bacObj.Object_Instance_Number == object_id )
|
||||
bResult = true;
|
||||
return bResult;
|
||||
if (object_id == BACNET_MAX_INSTANCE)
|
||||
bResult = true;
|
||||
if (pDev->bacObj.Object_Instance_Number == object_id)
|
||||
bResult = true;
|
||||
return bResult;
|
||||
}
|
||||
|
||||
char *Routed_Device_Name(
|
||||
uint32_t object_instance)
|
||||
{
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
if (object_instance == pDev->bacObj.Object_Instance_Number) {
|
||||
return pDev->bacObj.Object_Name;
|
||||
}
|
||||
@@ -429,7 +422,7 @@ int Routed_Device_Read_Property_Local(
|
||||
int apdu_len = 0; /* return value */
|
||||
BACNET_CHARACTER_STRING char_string;
|
||||
uint8_t *apdu = NULL;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
|
||||
if ((rpdata == NULL) || (rpdata->application_data == NULL) ||
|
||||
(rpdata->application_data_len == 0)) {
|
||||
@@ -440,7 +433,7 @@ int Routed_Device_Read_Property_Local(
|
||||
case PROP_OBJECT_IDENTIFIER:
|
||||
apdu_len =
|
||||
encode_application_object_id(&apdu[0], OBJECT_DEVICE,
|
||||
pDev->bacObj.Object_Instance_Number);
|
||||
pDev->bacObj.Object_Instance_Number);
|
||||
break;
|
||||
case PROP_OBJECT_NAME:
|
||||
characterstring_init_ansi(&char_string, pDev->bacObj.Object_Name);
|
||||
@@ -457,11 +450,11 @@ int Routed_Device_Read_Property_Local(
|
||||
encode_application_unsigned(&apdu[0], pDev->Database_Revision);
|
||||
break;
|
||||
default:
|
||||
apdu_len = Device_Read_Property_Local( rpdata);
|
||||
apdu_len = Device_Read_Property_Local(rpdata);
|
||||
break;
|
||||
}
|
||||
|
||||
return ( apdu_len );
|
||||
return (apdu_len);
|
||||
}
|
||||
|
||||
bool Routed_Device_Write_Property_Local(
|
||||
@@ -489,8 +482,8 @@ bool Routed_Device_Write_Property_Local(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
|
||||
(Routed_Device_Set_Object_Instance_Number(value.type.
|
||||
Object_Id.instance))) {
|
||||
(Routed_Device_Set_Object_Instance_Number(value.
|
||||
type.Object_Id.instance))) {
|
||||
/* FIXME: we could send an I-Am broadcast to let the world know */
|
||||
} else {
|
||||
status = false;
|
||||
@@ -504,13 +497,13 @@ bool Routed_Device_Write_Property_Local(
|
||||
WPValidateString(&value, MAX_DEV_NAME_LEN, false,
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
Routed_Device_Set_Object_Name(characterstring_value(&value.
|
||||
type.Character_String),
|
||||
Routed_Device_Set_Object_Name(characterstring_value
|
||||
(&value.type.Character_String),
|
||||
characterstring_length(&value.type.Character_String));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
status = Device_Write_Property_Local( wp_data);
|
||||
status = Device_Write_Property_Local(wp_data);
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
@@ -537,7 +530,7 @@ bool Routed_Device_Set_Object_Instance_Number(
|
||||
|
||||
if (object_id <= BACNET_MAX_INSTANCE) {
|
||||
/* Make the change and update the database revision */
|
||||
Devices[iCurrent_Device_Idx].bacObj.Object_Instance_Number = object_id;
|
||||
Devices[iCurrent_Device_Idx].bacObj.Object_Instance_Number = object_id;
|
||||
Routed_Device_Inc_Database_Revision();
|
||||
} else
|
||||
status = false;
|
||||
@@ -558,7 +551,7 @@ bool Routed_Device_Set_Object_Name(
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /*return value */
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
|
||||
if (length < MAX_DEV_NAME_LEN) {
|
||||
/* Make the change and update the database revision */
|
||||
@@ -576,7 +569,7 @@ bool Routed_Device_Set_Description(
|
||||
size_t length)
|
||||
{
|
||||
bool status = false; /*return value */
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
|
||||
if (length < MAX_DEV_DESC_LEN) {
|
||||
memmove(pDev->Description, name, length);
|
||||
@@ -596,8 +589,6 @@ bool Routed_Device_Set_Description(
|
||||
void Routed_Device_Inc_Database_Revision(
|
||||
void)
|
||||
{
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
pDev->Database_Revision++;
|
||||
DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx];
|
||||
pDev->Database_Revision++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -469,8 +469,8 @@ int Lighting_Output_Read_Property(
|
||||
object_index =
|
||||
Lighting_Output_Instance_To_Index(rpdata->object_instance);
|
||||
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
|
||||
if (Lighting_Output_Level[object_index][rpdata->array_index
|
||||
- 1] == LIGHTING_LEVEL_NULL)
|
||||
if (Lighting_Output_Level[object_index][rpdata->
|
||||
array_index - 1] == LIGHTING_LEVEL_NULL)
|
||||
apdu_len = encode_application_null(&apdu[0]);
|
||||
else {
|
||||
real_value = Lighting_Output_Level[object_index]
|
||||
@@ -554,11 +554,11 @@ bool Lighting_Output_Write_Property(
|
||||
if (status) {
|
||||
level = LIGHTING_LEVEL_NULL;
|
||||
object_index =
|
||||
Lighting_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Lighting_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
status =
|
||||
Lighting_Output_Present_Value_Relinquish
|
||||
(wp_data->object_instance, wp_data->priority);
|
||||
Lighting_Output_Present_Value_Relinquish(wp_data->
|
||||
object_instance, wp_data->priority);
|
||||
if (wp_data->priority == 6) {
|
||||
/* Command priority 6 is reserved for use by Minimum On/Off
|
||||
algorithm and may not be used for other purposes in any
|
||||
@@ -585,8 +585,8 @@ bool Lighting_Output_Write_Property(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
object_index =
|
||||
Lighting_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Lighting_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Lighting_Output_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
}
|
||||
|
||||
@@ -323,8 +323,8 @@ bool Life_Safety_Point_Write_Property(
|
||||
if (status) {
|
||||
if (value.type.Enumerated <= MAX_LIFE_SAFETY_MODE) {
|
||||
object_index =
|
||||
Life_Safety_Point_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Life_Safety_Point_Mode[object_index] =
|
||||
value.type.Enumerated;
|
||||
} else {
|
||||
@@ -340,8 +340,8 @@ bool Life_Safety_Point_Write_Property(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
object_index =
|
||||
Life_Safety_Point_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Life_Safety_Point_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Life_Safety_Point_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
}
|
||||
|
||||
@@ -277,8 +277,7 @@ static char *Multistate_Input_State_Text(
|
||||
char *pName = NULL; /* return value */
|
||||
|
||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||
if ((index < MAX_MULTISTATE_INPUTS) &&
|
||||
(state_index > 0) &&
|
||||
if ((index < MAX_MULTISTATE_INPUTS) && (state_index > 0) &&
|
||||
(state_index <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||
state_index--;
|
||||
pName = State_Text[index][state_index];
|
||||
@@ -298,8 +297,7 @@ bool Multistate_Input_State_Text_Set(
|
||||
bool status = false; /* return value */
|
||||
|
||||
index = Multistate_Input_Instance_To_Index(object_instance);
|
||||
if ((index < MAX_MULTISTATE_INPUTS) &&
|
||||
(state_index > 0) &&
|
||||
if ((index < MAX_MULTISTATE_INPUTS) && (state_index > 0) &&
|
||||
(state_index <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||
state_index--;
|
||||
status = true;
|
||||
@@ -405,8 +403,8 @@ int Multistate_Input_Read_Property(
|
||||
/* if no index was specified, then try to encode the entire list */
|
||||
/* into one packet. */
|
||||
object_index =
|
||||
Multistate_Input_Instance_To_Index
|
||||
(rpdata->object_instance);
|
||||
Multistate_Input_Instance_To_Index(rpdata->
|
||||
object_instance);
|
||||
for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) {
|
||||
characterstring_init_ansi(&char_string,
|
||||
Multistate_Input_State_Text(rpdata->object_instance,
|
||||
@@ -427,8 +425,8 @@ int Multistate_Input_Read_Property(
|
||||
}
|
||||
} else {
|
||||
object_index =
|
||||
Multistate_Input_Instance_To_Index
|
||||
(rpdata->object_instance);
|
||||
Multistate_Input_Instance_To_Index(rpdata->
|
||||
object_instance);
|
||||
if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) {
|
||||
characterstring_init_ansi(&char_string,
|
||||
Multistate_Input_State_Text(rpdata->object_instance,
|
||||
@@ -488,8 +486,8 @@ bool Multistate_Input_Write_Property(
|
||||
if (status) {
|
||||
if (Out_Of_Service[object_index]) {
|
||||
status =
|
||||
Multistate_Input_Present_Value_Set
|
||||
(wp_data->object_instance, value.type.Unsigned_Int);
|
||||
Multistate_Input_Present_Value_Set(wp_data->
|
||||
object_instance, value.type.Unsigned_Int);
|
||||
if (!status) {
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||
@@ -507,8 +505,8 @@ bool Multistate_Input_Write_Property(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
object_index =
|
||||
Multistate_Input_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Multistate_Input_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Out_Of_Service[object_index] = value.type.Boolean;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -266,8 +266,8 @@ int Multistate_Output_Read_Property(
|
||||
/* into one packet. */
|
||||
else if (rpdata->array_index == BACNET_ARRAY_ALL) {
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index
|
||||
(rpdata->object_instance);
|
||||
Multistate_Output_Instance_To_Index(rpdata->
|
||||
object_instance);
|
||||
for (i = 0; i < BACNET_MAX_PRIORITY; i++) {
|
||||
/* FIXME: check if we have room before adding it to APDU */
|
||||
if (Multistate_Output_Level[object_index][i] ==
|
||||
@@ -292,8 +292,8 @@ int Multistate_Output_Read_Property(
|
||||
}
|
||||
} else {
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index
|
||||
(rpdata->object_instance);
|
||||
Multistate_Output_Instance_To_Index(rpdata->
|
||||
object_instance);
|
||||
if (rpdata->array_index <= BACNET_MAX_PRIORITY) {
|
||||
if (Multistate_Output_Level[object_index]
|
||||
[rpdata->array_index - 1] == MULTISTATE_NULL)
|
||||
@@ -375,8 +375,8 @@ bool Multistate_Output_Write_Property(
|
||||
(value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) {
|
||||
level = value.type.Unsigned_Int;
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority--;
|
||||
Multistate_Output_Level[object_index][priority] =
|
||||
(uint8_t) level;
|
||||
@@ -403,8 +403,8 @@ bool Multistate_Output_Write_Property(
|
||||
if (status) {
|
||||
level = MULTISTATE_NULL;
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
priority = wp_data->priority;
|
||||
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
|
||||
priority--;
|
||||
@@ -430,8 +430,8 @@ bool Multistate_Output_Write_Property(
|
||||
&wp_data->error_class, &wp_data->error_code);
|
||||
if (status) {
|
||||
object_index =
|
||||
Multistate_Output_Instance_To_Index
|
||||
(wp_data->object_instance);
|
||||
Multistate_Output_Instance_To_Index(wp_data->
|
||||
object_instance);
|
||||
Multistate_Output_Out_Of_Service[object_index] =
|
||||
value.type.Boolean;
|
||||
}
|
||||
|
||||
@@ -735,9 +735,9 @@ bool Trend_Log_Write_Property(
|
||||
if (wp_data->application_data_len != 0) {
|
||||
iOffset += len;
|
||||
len =
|
||||
bacapp_decode_context_data(&wp_data->application_data
|
||||
[iOffset], wp_data->application_data_len, &value,
|
||||
PROP_LOG_DEVICE_OBJECT_PROPERTY);
|
||||
bacapp_decode_context_data(&wp_data->
|
||||
application_data[iOffset], wp_data->application_data_len,
|
||||
&value, PROP_LOG_DEVICE_OBJECT_PROPERTY);
|
||||
if ((len == 0) || ((value.context_tag != 2) &&
|
||||
(value.context_tag != 3))) {
|
||||
/* Bad decode or wrong tag */
|
||||
@@ -754,8 +754,8 @@ bool Trend_Log_Write_Property(
|
||||
if (wp_data->application_data_len != 0) {
|
||||
iOffset += len;
|
||||
len =
|
||||
bacapp_decode_context_data
|
||||
(&wp_data->application_data[iOffset],
|
||||
bacapp_decode_context_data(&wp_data->
|
||||
application_data[iOffset],
|
||||
wp_data->application_data_len, &value,
|
||||
PROP_LOG_DEVICE_OBJECT_PROPERTY);
|
||||
if ((len == 0) || (value.context_tag != 3)) {
|
||||
@@ -1097,8 +1097,8 @@ int rr_trend_log_encode(
|
||||
pRequest->ItemCount = 0; /* Start out with nothing */
|
||||
|
||||
/* Bail out now if nowt - should never happen for a Trend Log but ... */
|
||||
if (LogInfo[Trend_Log_Instance_To_Index(pRequest->
|
||||
object_instance)].ulRecordCount == 0)
|
||||
if (LogInfo[Trend_Log_Instance_To_Index(pRequest->object_instance)].
|
||||
ulRecordCount == 0)
|
||||
return (0);
|
||||
|
||||
if ((pRequest->RequestType == RR_BY_POSITION) ||
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -55,8 +55,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -56,8 +56,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -82,7 +82,7 @@ static object_functions_t Object_Table[] = {
|
||||
#if defined(BACFILE)
|
||||
{FILE_OBJ_FUNCTIONS},
|
||||
#endif
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/** @file server/main.c Example server application using the BACnet Stack. */
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
static void Init_Service_Handlers(
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -51,8 +51,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
@@ -58,8 +58,8 @@
|
||||
|
||||
/* All included BACnet objects */
|
||||
static object_functions_t Object_Table[] = {
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
{DEVICE_OBJ_FUNCTIONS},
|
||||
{MAX_BACNET_OBJECT_TYPE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
/* buffer used for receive */
|
||||
|
||||
Reference in New Issue
Block a user