added ReadPropertyMultiple client demo application, bacrpm.
This commit is contained in:
@@ -439,7 +439,7 @@ bool decode_is_context_tag_with_length(
|
||||
}
|
||||
|
||||
/* from clause 20.2.1.3.2 Constructed Data */
|
||||
/* returns the number of apdu bytes consumed */
|
||||
/* returns the true if the tag matches */
|
||||
bool decode_is_opening_tag_number(
|
||||
uint8_t * apdu,
|
||||
uint8_t tag_number)
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*####COPYRIGHTBEGIN####
|
||||
-------------------------------------------
|
||||
Copyright (C) 2008 Steve Karg
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
The Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA.
|
||||
|
||||
As a special exception, if other files instantiate templates or
|
||||
use macros or inline functions from this file, or you compile
|
||||
this file and link it with other works to produce a work based
|
||||
on this file, this file does not by itself cause the resulting
|
||||
work to be covered by the GNU General Public License. However
|
||||
the source code for this file must still be made available in
|
||||
accordance with section (3) of the GNU General Public License.
|
||||
|
||||
This exception does not invalidate any other reasons why a work
|
||||
based on this file might be covered by the GNU General Public
|
||||
License.
|
||||
-------------------------------------------
|
||||
####COPYRIGHTEND####*/
|
||||
#include <stddef.h>
|
||||
|
||||
/* copy len bytes from src to offset of dest if there is enough space. */
|
||||
/* returns 0 if there is not enough space, or the number of bytes copied. */
|
||||
size_t memcopy(
|
||||
void * dest,
|
||||
void * src,
|
||||
size_t offset, /* where in dest to put the data */
|
||||
size_t len, /* amount of data to copy */
|
||||
size_t max) /* total size of destination */
|
||||
{
|
||||
size_t i;
|
||||
size_t copy_len = 0;
|
||||
char *s1, *s2;
|
||||
|
||||
s1 = dest;
|
||||
s2 = src;
|
||||
if (len <= (max - offset)) {
|
||||
for (i = 0; i < len; i++) {
|
||||
s1[offset + i] = s2[i];
|
||||
copy_len++;
|
||||
}
|
||||
}
|
||||
|
||||
return copy_len;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ctest.h"
|
||||
|
||||
void test_memcopy(
|
||||
Test * pTest)
|
||||
{
|
||||
char *data1 = "Joshua";
|
||||
char *data2 = "Anna";
|
||||
char buffer[480] = "";
|
||||
char big_buffer[480] = "";
|
||||
size_t len = 0;
|
||||
|
||||
len = memcopy(&buffer[0], &data1[0], 0,
|
||||
sizeof(data1), sizeof(buffer));
|
||||
ct_test(pTest, len == sizeof(data1));
|
||||
ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0);
|
||||
len = memcopy(&buffer[0], &data2[0], len,
|
||||
sizeof(data2), sizeof(buffer));
|
||||
ct_test(pTest, len == sizeof(data2));
|
||||
len = memcopy(&buffer[0], &big_buffer[0], 1,
|
||||
sizeof(big_buffer), sizeof(buffer));
|
||||
ct_test(pTest, len == 0);
|
||||
}
|
||||
|
||||
#ifdef TEST_MEM_COPY
|
||||
int main(
|
||||
void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
|
||||
pTest = ct_create("Memory Copy", NULL);
|
||||
|
||||
/* individual tests */
|
||||
rc = ct_addTestFunction(pTest, test_memcopy);
|
||||
assert(rc);
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void) ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif /* TEST */
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "bacdcode.h"
|
||||
#include "bacdef.h"
|
||||
#include "bacapp.h"
|
||||
#include "memcopy.h"
|
||||
#include "rpm.h"
|
||||
|
||||
/* encode the initial portion of the service */
|
||||
@@ -105,6 +106,75 @@ int rpm_encode_apdu_object_end(
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
int rpm_encode_apdu(
|
||||
uint8_t * apdu,
|
||||
size_t max_apdu,
|
||||
uint8_t invoke_id,
|
||||
BACNET_READ_ACCESS_DATA *read_access_data)
|
||||
{
|
||||
int apdu_len = 0; /* total length of the apdu, return value */
|
||||
int len = 0; /* length of the data */
|
||||
BACNET_READ_ACCESS_DATA *rpm_object; /* current object */
|
||||
uint8_t apdu_temp[16]; /* temp for data before copy */
|
||||
BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */
|
||||
|
||||
len = rpm_encode_apdu_init(&apdu_temp[0], invoke_id);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
rpm_object = read_access_data;
|
||||
while (rpm_object) {
|
||||
len = encode_context_object_id(&apdu_temp[0], 0,
|
||||
rpm_object->object_type,
|
||||
rpm_object->object_instance);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
/* Tag 1: sequence of ReadAccessSpecification */
|
||||
len = encode_opening_tag(&apdu_temp[0], 1);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
rpm_property = rpm_object->listOfProperties;
|
||||
while (rpm_property) {
|
||||
/* stuff as many properties into it as APDU length will allow */
|
||||
len = encode_context_enumerated(&apdu_temp[0], 0,
|
||||
rpm_property->propertyIdentifier);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
/* optional array index */
|
||||
if (rpm_property->propertyArrayIndex != BACNET_ARRAY_ALL) {
|
||||
len = encode_context_unsigned(&apdu_temp[0], 1,
|
||||
rpm_property->propertyArrayIndex);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
}
|
||||
rpm_property = rpm_property->next;
|
||||
}
|
||||
len = encode_closing_tag(&apdu_temp[0], 1);
|
||||
len = memcopy(&apdu[0], &apdu_temp[0], apdu_len, len, max_apdu);
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
apdu_len += len;
|
||||
rpm_object = rpm_object->next;
|
||||
}
|
||||
|
||||
return apdu_len;
|
||||
}
|
||||
|
||||
/* decode the object portion of the service request only */
|
||||
int rpm_decode_object_id(
|
||||
uint8_t * apdu,
|
||||
|
||||
+10
-9
@@ -42,9 +42,9 @@
|
||||
|
||||
void sbuf_init(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* actual size, in bytes, of the data block or array of data */
|
||||
unsigned size)
|
||||
{ /* number of bytes used */
|
||||
char *data, /* data block */
|
||||
unsigned size) /* actual size, in bytes, of the data block or array of data */
|
||||
{
|
||||
if (b) {
|
||||
b->data = data;
|
||||
b->size = size;
|
||||
@@ -83,9 +83,9 @@ unsigned sbuf_count(
|
||||
bool sbuf_put(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
unsigned offset, /* where to start */
|
||||
char *data, /* number of bytes used */
|
||||
char *data, /* data to place in buffer */
|
||||
unsigned data_size)
|
||||
{ /* how many to add */
|
||||
{ /* how many bytes to add */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (b && b->data) {
|
||||
@@ -107,13 +107,14 @@ bool sbuf_put(
|
||||
/* returns true if successful, false if not enough room to append data */
|
||||
bool sbuf_append(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
char *data, /* number of bytes used */
|
||||
char *data, /* data to place in buffer */
|
||||
unsigned data_size)
|
||||
{ /* how many to add */
|
||||
{ /* how many bytes to add */
|
||||
unsigned count = 0;
|
||||
|
||||
if (b)
|
||||
if (b) {
|
||||
count = b->count;
|
||||
}
|
||||
|
||||
return sbuf_put(b, count, data, data_size);
|
||||
}
|
||||
@@ -122,7 +123,7 @@ bool sbuf_append(
|
||||
bool sbuf_truncate(
|
||||
STATIC_BUFFER * b, /* static buffer structure */
|
||||
unsigned count)
|
||||
{ /* total number of bytes in use */
|
||||
{ /* total number of bytes in to remove */
|
||||
bool status = false; /* return value */
|
||||
|
||||
if (b) {
|
||||
|
||||
Reference in New Issue
Block a user