Added ascii-hex conversion in the octet-string library to allow ascii-hex to be parsed correctly from demo applications.
This commit is contained in:
@@ -162,7 +162,14 @@ extern "C" {
|
|||||||
BACNET_OCTET_STRING * octet_string,
|
BACNET_OCTET_STRING * octet_string,
|
||||||
uint8_t * value,
|
uint8_t * value,
|
||||||
size_t length);
|
size_t length);
|
||||||
bool octetstring_copy(
|
#ifdef PRINT_ENABLED
|
||||||
|
/* converts an null terminated ASCII Hex string to an octet string.
|
||||||
|
returns true if successfully converted and fits; false if too long */
|
||||||
|
bool octetstring_init_ascii_hex(
|
||||||
|
BACNET_OCTET_STRING * octet_string,
|
||||||
|
const char * ascii_hex);
|
||||||
|
#endif
|
||||||
|
bool octetstring_copy(
|
||||||
BACNET_OCTET_STRING * dest,
|
BACNET_OCTET_STRING * dest,
|
||||||
BACNET_OCTET_STRING * src);
|
BACNET_OCTET_STRING * src);
|
||||||
/* returns false if the string exceeds capacity */
|
/* returns false if the string exceeds capacity */
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include "bacapp.h"
|
#include "bacapp.h"
|
||||||
#include "bactext.h"
|
#include "bactext.h"
|
||||||
#include "datetime.h"
|
#include "datetime.h"
|
||||||
|
#include "bacstr.h"
|
||||||
|
|
||||||
/** @file bacapp.c Utilities for the BACnet_Application_Data_Value */
|
/** @file bacapp.c Utilities for the BACnet_Application_Data_Value */
|
||||||
|
|
||||||
@@ -1188,8 +1189,8 @@ bool bacapp_parse_application_data(
|
|||||||
#endif
|
#endif
|
||||||
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||||
status =
|
status =
|
||||||
octetstring_init(&value->type.Octet_String,
|
octetstring_init_ascii_hex(&value->type.Octet_String,
|
||||||
(uint8_t *) argv, strlen(argv));
|
argv);
|
||||||
break;
|
break;
|
||||||
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||||
status =
|
status =
|
||||||
|
|||||||
@@ -35,6 +35,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h> /* for strlen */
|
#include <string.h> /* for strlen */
|
||||||
|
#ifdef PRINT_ENABLED
|
||||||
|
#include <stdlib.h> /* for strtol */
|
||||||
|
#include <ctype.h> /* for isalnum */
|
||||||
|
#endif
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "bacstr.h"
|
#include "bacstr.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
@@ -641,6 +645,49 @@ bool octetstring_init(
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PRINT_ENABLED
|
||||||
|
/* converts an null terminated ASCII Hex string to an octet string.
|
||||||
|
returns true if successfully converted and fits; false if too long */
|
||||||
|
bool octetstring_init_ascii_hex(
|
||||||
|
BACNET_OCTET_STRING * octet_string,
|
||||||
|
const char * ascii_hex)
|
||||||
|
{
|
||||||
|
bool status = false; /* return value */
|
||||||
|
unsigned index = 0; /* offset into buffer */
|
||||||
|
uint8_t value = 0;
|
||||||
|
char hex_pair_string[3] = "";
|
||||||
|
|
||||||
|
if (octet_string) {
|
||||||
|
octet_string->length = 0;
|
||||||
|
while (ascii_hex[index] != 0) {
|
||||||
|
if (!isalnum(ascii_hex[index])) {
|
||||||
|
/* skip non-numeric or alpha */
|
||||||
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ascii_hex[index+1] == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
hex_pair_string[0] = ascii_hex[index];
|
||||||
|
hex_pair_string[1] = ascii_hex[index+1];
|
||||||
|
value = (uint8_t)strtol(hex_pair_string, NULL, 16);
|
||||||
|
if (octet_string->length <= MAX_OCTET_STRING_BYTES) {
|
||||||
|
octet_string->value[octet_string->length] = value;
|
||||||
|
octet_string->length++;
|
||||||
|
status = true;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
/* set up for next pair */
|
||||||
|
index += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool octetstring_copy(
|
bool octetstring_copy(
|
||||||
BACNET_OCTET_STRING * dest,
|
BACNET_OCTET_STRING * dest,
|
||||||
BACNET_OCTET_STRING * src)
|
BACNET_OCTET_STRING * src)
|
||||||
|
|||||||
Reference in New Issue
Block a user