Moved apdu decode into unit test where it was being used since it is being decoded in apdu.c in normal usage.
This commit is contained in:
+20
-20
@@ -134,26 +134,6 @@ int iam_decode_service_request(uint8_t * apdu,
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int iam_decode_apdu(uint8_t * apdu,
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
/* valid data? */
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
|
||||
return -1;
|
||||
apdu_len = iam_decode_service_request(&apdu[2],
|
||||
pDevice_id, pMax_apdu, pSegmentation, pVendor_id);
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int iam_send(uint8_t * buffer)
|
||||
{
|
||||
int pdu_len = 0;
|
||||
@@ -183,6 +163,26 @@ int iam_send(uint8_t * buffer)
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int iam_decode_apdu(uint8_t * apdu,
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
|
||||
/* valid data? */
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
|
||||
return -1;
|
||||
apdu_len = iam_decode_service_request(&apdu[2],
|
||||
pDevice_id, pMax_apdu, pSegmentation, pVendor_id);
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
void testIAm(Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
|
||||
+4
-4
@@ -50,14 +50,14 @@ extern "C" {
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id);
|
||||
|
||||
int iam_decode_apdu(uint8_t * apdu,
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id);
|
||||
|
||||
int iam_send(uint8_t * buffer);
|
||||
|
||||
#ifdef TEST
|
||||
#include "ctest.h"
|
||||
int iam_decode_apdu(uint8_t * apdu,
|
||||
uint32_t * pDevice_id,
|
||||
unsigned *pMax_apdu, int *pSegmentation, uint16_t * pVendor_id);
|
||||
|
||||
void testIAm(Test * pTest);
|
||||
#endif
|
||||
|
||||
|
||||
+31
-31
@@ -109,32 +109,6 @@ int rp_decode_service_request(uint8_t * apdu,
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
int rp_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
/* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */
|
||||
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
|
||||
if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY)
|
||||
return -1;
|
||||
offset = 4;
|
||||
|
||||
if (apdu_len > offset) {
|
||||
len = rp_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int rp_ack_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data)
|
||||
{
|
||||
@@ -213,6 +187,37 @@ int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
int rp_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned offset = 0;
|
||||
|
||||
if (!apdu)
|
||||
return -1;
|
||||
/* optional checking - most likely was already done prior to this call */
|
||||
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
|
||||
return -1;
|
||||
/* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */
|
||||
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
|
||||
if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY)
|
||||
return -1;
|
||||
offset = 4;
|
||||
|
||||
if (apdu_len > offset) {
|
||||
len = rp_decode_service_request(&apdu[offset],
|
||||
apdu_len - offset, data);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data)
|
||||
{
|
||||
@@ -236,11 +241,6 @@ int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the a
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "ctest.h"
|
||||
|
||||
void testReadPropertyAck(Test * pTest)
|
||||
{
|
||||
uint8_t apdu[480] = { 0 };
|
||||
|
||||
+6
-7
@@ -58,22 +58,21 @@ extern "C" {
|
||||
int rp_decode_service_request(uint8_t * apdu,
|
||||
unsigned apdu_len, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
int rp_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
int rp_ack_encode_apdu(uint8_t * apdu,
|
||||
uint8_t invoke_id, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
int rp_ack_decode_service_request(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
#include "ctest.h"
|
||||
int rp_decode_apdu(uint8_t * apdu,
|
||||
unsigned apdu_len,
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
int rp_ack_decode_apdu(uint8_t * apdu, int apdu_len, /* total length of the apdu */
|
||||
uint8_t * invoke_id, BACNET_READ_PROPERTY_DATA * data);
|
||||
|
||||
void test_ReadProperty(Test * pTest);
|
||||
void test_ReadPropertyAck(Test * pTest);
|
||||
|
||||
Reference in New Issue
Block a user