void testWhoIs( Test * pTest) { uint8_t apdu[480] = { 0 }; int len = 0; int apdu_len = 0; int32_t low_limit = -1; int32_t high_limit = -1; int32_t test_low_limit = 0; int32_t test_high_limit = 0; /* normal who-is without limits */ len = whois_encode_apdu(&apdu[0], low_limit, high_limit); ct_test(pTest, len > 0); apdu_len = len; len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); /* normal who-is with limits - complete range */ for (low_limit = 0; low_limit <= BACNET_MAX_INSTANCE; low_limit += (BACNET_MAX_INSTANCE / 4)) { for (high_limit = 0; high_limit <= BACNET_MAX_INSTANCE; high_limit += (BACNET_MAX_INSTANCE / 4)) { len = whois_encode_apdu(&apdu[0], low_limit, high_limit); apdu_len = len; ct_test(pTest, len > 0); len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); } } /* abnormal case: who-is with no limits, but with APDU containing 2 limits */ low_limit = 0; high_limit = 0; len = whois_encode_apdu(&apdu[0], low_limit, high_limit); ct_test(pTest, len > 0); apdu_len = len; low_limit = -1; high_limit = -1; len = whois_encode_apdu(&apdu[0], low_limit, high_limit); ct_test(pTest, len > 0); apdu_len = len; len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); }
/** Send a Who-Is request to a remote network for a specific device, a range, * or any device. * If low_limit and high_limit both are -1, then the range is unlimited. * If low_limit and high_limit have the same non-negative value, then only * that device will respond. * Otherwise, low_limit must be less than high_limit. * @param target_address [in] BACnet address of target router * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ void Send_WhoIs_To_Network( BACNET_ADDRESS * target_address, int32_t low_limit, int32_t high_limit) { int len = 0; int pdu_len = 0; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; 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], target_address, &my_address, &npdu_data); /* encode the APDU portion of the packet */ len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit, high_limit); pdu_len += len; bytes_sent = datalink_send_pdu(target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", strerror(errno)); #endif }
void testWhoIs( Test * pTest) { uint8_t apdu[480] = { 0 }; int len = 0; int apdu_len = 0; int32_t low_limit = -1; int32_t high_limit = -1; int32_t test_low_limit = -1; int32_t test_high_limit = -1; len = whois_encode_apdu(&apdu[0], low_limit, high_limit); ct_test(pTest, len != 0); apdu_len = len; len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, &test_high_limit); ct_test(pTest, len != -1); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); for (low_limit = 0; low_limit <= BACNET_MAX_INSTANCE; low_limit += (BACNET_MAX_INSTANCE / 4)) { for (high_limit = 0; high_limit <= BACNET_MAX_INSTANCE; high_limit += (BACNET_MAX_INSTANCE / 4)) { len = whois_encode_apdu(&apdu[0], low_limit, high_limit); apdu_len = len; ct_test(pTest, len != 0); len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, &test_high_limit); ct_test(pTest, len != -1); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); } } }