- Added handling to WritePropertyMultiple.
- Added encode_tagged_enumerated function.
This commit is contained in:
@@ -118,6 +118,8 @@ static void Init_Service_Handlers(
|
||||
handler_read_property_multiple);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||
handler_write_property);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE,
|
||||
handler_write_property_multiple);
|
||||
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE,
|
||||
handler_read_range);
|
||||
#if defined(BACFILE)
|
||||
|
||||
@@ -313,6 +313,9 @@ extern "C" {
|
||||
int encode_bacnet_enumerated(
|
||||
uint8_t * apdu,
|
||||
uint32_t value);
|
||||
int encode_tagged_enumerated(
|
||||
uint8_t * apdu,
|
||||
int value);
|
||||
int encode_application_enumerated(
|
||||
uint8_t * apdu,
|
||||
uint32_t value);
|
||||
|
||||
@@ -118,6 +118,12 @@ extern "C" {
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||
|
||||
void handler_write_property_multiple(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data);
|
||||
|
||||
bool WPValidateString(
|
||||
BACNET_APPLICATION_DATA_VALUE * pValue,
|
||||
int iMaxLen,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#ifndef WRITEPROPERTYMULTIPLE_H
|
||||
#define WRITEPROPERTYMULTIPLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "bacdcode.h"
|
||||
#include "bacapp.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* decode the service request only */
|
||||
int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len,
|
||||
BACNET_WRITE_PROPERTY_DATA * data);
|
||||
|
||||
int wpm_decode_object_property(uint8_t * apdu,
|
||||
uint16_t apdu_len,
|
||||
BACNET_WRITE_PROPERTY_DATA * wpm_data);
|
||||
|
||||
|
||||
/* encode service */
|
||||
int wpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id);
|
||||
|
||||
int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id,
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
/** @defgroup DSWP Data Sharing - Write Property Multiple Service (DS-WPM)
|
||||
* @ingroup DataShare
|
||||
* 15.10 WriteProperty Multiple Service <br>
|
||||
* The WritePropertyMultiple service is used by a client BACnet-user
|
||||
* to modify the value of one or more specified properties of a BACnet object.
|
||||
* This service potentially allows write access to any property of any object,
|
||||
* whether a BACnet-defined object or not.
|
||||
* Properties shall be modified by the WritePropertyMultiple service
|
||||
* in the order specified in the 'List of Write Access Specifications' parameter,
|
||||
* and execution of the service shall continue until all of the specified
|
||||
* properties have been written to or a property is encountered that
|
||||
* for some reason cannot be modified as requested.
|
||||
* Some implementors may wish to restrict write access to certain properties
|
||||
* of certain objects. In such cases, an attempt to modify a restricted property
|
||||
* shall result in the return of an error of 'Error Class' PROPERTY and 'Error Code'
|
||||
* WRITE_ACCESS_DENIED. Note that these restricted properties may be accessible
|
||||
* through the use of Virtual Terminal services or other means at the discretion
|
||||
* of the implementor.
|
||||
*/
|
||||
#endif
|
||||
@@ -42,6 +42,7 @@ CORE_SRC = \
|
||||
$(BACNET_CORE)/whohas.c \
|
||||
$(BACNET_CORE)/whois.c \
|
||||
$(BACNET_CORE)/wp.c \
|
||||
$(BACNET_CORE)/wpm.c \
|
||||
$(BACNET_CORE)/abort.c \
|
||||
$(BACNET_CORE)/reject.c \
|
||||
$(BACNET_CORE)/bacerror.c \
|
||||
@@ -73,6 +74,7 @@ HANDLER_SRC = \
|
||||
$(BACNET_HANDLER)/h_rpm_a.c \
|
||||
$(BACNET_HANDLER)/h_rr.c \
|
||||
$(BACNET_HANDLER)/h_wp.c \
|
||||
$(BACNET_HANDLER)/h_wpm.c \
|
||||
$(BACNET_HANDLER)/h_arf.c \
|
||||
$(BACNET_HANDLER)/h_arf_a.c \
|
||||
$(BACNET_HANDLER)/h_awf.c \
|
||||
|
||||
@@ -1260,6 +1260,23 @@ int encode_bacnet_enumerated(
|
||||
return encode_bacnet_unsigned(apdu, value);
|
||||
}
|
||||
|
||||
/* from clause 20.2.11 Encoding of an Enumerated Value */
|
||||
/* and 20.2.1 General Rules for Encoding BACnet Tags */
|
||||
/* returns the number of apdu bytes consumed */
|
||||
int encode_tagged_enumerated(
|
||||
uint8_t * apdu,
|
||||
int value)
|
||||
{
|
||||
int len = 0; /* return value */
|
||||
|
||||
/* assumes that the tag only consumes 1 octet */
|
||||
len = encode_bacnet_enumerated(&apdu[1], value);
|
||||
len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED,
|
||||
false, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/* from clause 20.2.11 Encoding of an Enumerated Value */
|
||||
/* and 20.2.1 General Rules for Encoding BACnet Tags */
|
||||
/* returns the number of apdu bytes consumed */
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2011 Krzysztof Malorny <malornykrzysztof@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#include <stdint.h>
|
||||
#include "bacapp.h"
|
||||
#include "bacenum.h"
|
||||
#include "bacdcode.h"
|
||||
#include "bacdef.h"
|
||||
#include "wp.h"
|
||||
#include "wpm.h"
|
||||
|
||||
/** @file wpm.c Encode/Decode BACnet Write Property Multiple APDUs */
|
||||
|
||||
/* decode service */
|
||||
int wpm_decode_object_id(uint8_t * apdu, uint16_t apdu_len,
|
||||
BACNET_WRITE_PROPERTY_DATA * data)
|
||||
{
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint32_t object_instance = 0;
|
||||
uint16_t object_type = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
if((apdu )&& (apdu_len))
|
||||
{
|
||||
// Context tag 0 - Object ID
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if(tag_number == 0)
|
||||
{
|
||||
len += decode_object_id(&apdu[len], &object_type, &object_instance);
|
||||
data->object_type = object_type;
|
||||
data->object_instance = object_instance;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int wpm_decode_object_property(uint8_t * apdu,
|
||||
uint16_t apdu_len,
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data)
|
||||
{
|
||||
uint8_t tag_number = 0;
|
||||
uint32_t len_value = 0;
|
||||
uint32_t ulVal = 0;
|
||||
int len = 0, i = 0;
|
||||
|
||||
|
||||
if((apdu) && (apdu_len) && (wp_data))
|
||||
{
|
||||
wp_data->array_index = BACNET_ARRAY_ALL;
|
||||
wp_data->priority = BACNET_NO_PRIORITY;
|
||||
wp_data->application_data_len = 0;
|
||||
|
||||
// tag 0 - Property Identifier
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if(tag_number == 0)
|
||||
{
|
||||
len += decode_enumerated(&apdu[len], len_value, &ulVal);
|
||||
wp_data->object_property = ulVal;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
// tag 1 - Property Array Index - optional
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if(tag_number ==1)
|
||||
{
|
||||
len += decode_unsigned(&apdu[len],len_value, &ulVal);
|
||||
wp_data->array_index = ulVal;
|
||||
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
}
|
||||
// tag 2 - Property Value
|
||||
if((tag_number == 2) && (decode_is_opening_tag(&apdu[len-1])))
|
||||
{
|
||||
len--;
|
||||
wp_data->application_data_len = bacapp_data_len(&apdu[len],
|
||||
apdu_len - len, wp_data->object_property);
|
||||
len++;
|
||||
|
||||
// copy application data
|
||||
for(i = 0; i < wp_data->application_data_len; i++)
|
||||
wp_data->application_data[i] = apdu[len+i];
|
||||
len += wp_data->application_data_len;
|
||||
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
// closing tag 2
|
||||
if((tag_number != 2) &&(decode_is_closing_tag(&apdu[len-1])))
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
// tag 3 - Priority - optional
|
||||
len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value);
|
||||
if(tag_number == 3)
|
||||
{
|
||||
uint32_t priority = BACNET_NO_PRIORITY;
|
||||
|
||||
len += decode_unsigned(&apdu[len], len_value, &priority);
|
||||
wp_data->priority = priority;
|
||||
}
|
||||
else
|
||||
len--;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int wpm_ack_encode_apdu_init(uint8_t * apdu, uint8_t invoke_id)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
if (apdu) {
|
||||
apdu[len++] = PDU_TYPE_SIMPLE_ACK;
|
||||
apdu[len++] = invoke_id;
|
||||
apdu[len++] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int wpm_error_ack_encode_apdu(uint8_t * apdu, uint8_t invoke_id,
|
||||
BACNET_WRITE_PROPERTY_DATA * wp_data)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
if (apdu)
|
||||
{
|
||||
apdu[len++] = PDU_TYPE_ERROR;
|
||||
apdu[len++] = invoke_id;
|
||||
apdu[len++] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE;
|
||||
|
||||
len += encode_opening_tag(&apdu[len], 0);
|
||||
len += encode_tagged_enumerated(&apdu[len], wp_data->error_class);
|
||||
len += encode_tagged_enumerated(&apdu[len], wp_data->error_code);
|
||||
len += encode_closing_tag(&apdu[len], 0);
|
||||
|
||||
len += encode_opening_tag(&apdu[len], 1);
|
||||
len += encode_context_object_id(&apdu[len], 0,
|
||||
wp_data->object_type, wp_data->object_instance);
|
||||
len += encode_context_enumerated(&apdu[len], 1,
|
||||
wp_data->object_property);
|
||||
|
||||
if(wp_data->array_index != BACNET_ARRAY_ALL)
|
||||
len += encode_context_unsigned(&apdu[len], 2, wp_data->array_index);
|
||||
len += encode_closing_tag(&apdu[len], 1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user