int bacapp_decode_context_device_obj_property_ref( uint8_t * apdu, uint8_t tag_number, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value) { int len = 0; int section_length; if (decode_is_opening_tag_number(&apdu[len], tag_number)) { len++; section_length = bacapp_decode_device_obj_property_ref(&apdu[len], value); if (section_length == -1) { len = -1; } else { len += section_length; if (decode_is_closing_tag_number(&apdu[len], tag_number)) { len++; } else { len = -1; } } } else { len = -1; } return len; }
void testDevIdPropRef( Test * pTest) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData; BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData; uint8_t buffer[MAX_APDU]; int inLen; int outLen; inData.objectIdentifier.instance = 0x1234; inData.objectIdentifier.type = 15; inData.propertyIdentifier = 25; inData.arrayIndex = 0x5678; inData.deviceIndentifier.instance = 0x4343; inData.deviceIndentifier.type = 28; inLen = bacapp_encode_device_obj_property_ref(buffer, &inData); outLen = bacapp_decode_device_obj_property_ref(buffer, &outData); ct_test(pTest, outLen == inLen); ct_test(pTest, inData.objectIdentifier.instance == outData.objectIdentifier.instance); ct_test(pTest, inData.objectIdentifier.type == outData.objectIdentifier.type); ct_test(pTest, inData.propertyIdentifier == outData.propertyIdentifier); ct_test(pTest, inData.arrayIndex == outData.arrayIndex); ct_test(pTest, inData.deviceIndentifier.instance == outData.deviceIndentifier.instance); ct_test(pTest, inData.deviceIndentifier.type == outData.deviceIndentifier.type); }
static void testDevObjPropRef( Test * pTest, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData; uint8_t buffer[MAX_APDU] = {0}; int inLen = 0; int outLen = 0; /* encode */ inLen = bacapp_encode_device_obj_property_ref(buffer, inData); /* add a closing tag at the end of the buffer to verify proper handling when that is encountered in real packets */ encode_closing_tag(&buffer[inLen], 3); /* decode */ outLen = bacapp_decode_device_obj_property_ref(buffer, &outData); ct_test(pTest, outLen == inLen); ct_test(pTest, inData->objectIdentifier.instance == outData.objectIdentifier.instance); ct_test(pTest, inData->objectIdentifier.type == outData.objectIdentifier.type); ct_test(pTest, inData->propertyIdentifier == outData.propertyIdentifier); if (inData->arrayIndex != BACNET_ARRAY_ALL) { ct_test(pTest, inData->arrayIndex == outData.arrayIndex); } else { ct_test(pTest, outData.arrayIndex == BACNET_ARRAY_ALL); } if (inData->deviceIndentifier.type == OBJECT_DEVICE) { ct_test(pTest, inData->deviceIndentifier.instance == outData.deviceIndentifier.instance); ct_test(pTest, inData->deviceIndentifier.type == outData.deviceIndentifier.type); } else { ct_test(pTest,outData.deviceIndentifier.instance == BACNET_NO_DEV_ID); ct_test(pTest,outData.deviceIndentifier.type == BACNET_NO_DEV_TYPE); } }