Added parser for command line parsing of a BACnet BitString. This is nice if you want to write Event Enable, for example. Expects the ASCII bits as "1011001" or "1,0,1,1,0,0,1" or "1 0 1 1 0 0 1".
This commit is contained in:
@@ -87,10 +87,12 @@ extern "C" {
|
|||||||
bool bitstring_copy(
|
bool bitstring_copy(
|
||||||
BACNET_BIT_STRING * dest,
|
BACNET_BIT_STRING * dest,
|
||||||
BACNET_BIT_STRING * src);
|
BACNET_BIT_STRING * src);
|
||||||
|
|
||||||
bool bitstring_same(
|
bool bitstring_same(
|
||||||
BACNET_BIT_STRING * bitstring1,
|
BACNET_BIT_STRING * bitstring1,
|
||||||
BACNET_BIT_STRING * bitstring2);
|
BACNET_BIT_STRING * bitstring2);
|
||||||
|
bool bitstring_init_ascii(
|
||||||
|
BACNET_BIT_STRING * bit_string,
|
||||||
|
const char *ascii);
|
||||||
|
|
||||||
/* returns false if the string exceeds capacity
|
/* returns false if the string exceeds capacity
|
||||||
initialize by using length=0 */
|
initialize by using length=0 */
|
||||||
|
|||||||
@@ -1467,9 +1467,9 @@ bool bacapp_parse_application_data(
|
|||||||
(char *) argv);
|
(char *) argv);
|
||||||
break;
|
break;
|
||||||
case BACNET_APPLICATION_TAG_BIT_STRING:
|
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||||
/* FIXME: how to parse a bit string? */
|
#if PRINT_ENABLED
|
||||||
status = false;
|
status = bitstring_init_ascii(&value->type.Bit_String, argv);
|
||||||
bitstring_init(&value->type.Bit_String);
|
#endif
|
||||||
break;
|
break;
|
||||||
case BACNET_APPLICATION_TAG_ENUMERATED:
|
case BACNET_APPLICATION_TAG_ENUMERATED:
|
||||||
unsigned_long_value = strtoul(argv, NULL, 0);
|
unsigned_long_value = strtoul(argv, NULL, 0);
|
||||||
|
|||||||
@@ -230,6 +230,53 @@ bool bitstring_same(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if PRINT_ENABLED
|
||||||
|
/* converts an null terminated ASCII string to an bitstring.
|
||||||
|
Expects "1,0,1,0,1,1" or "101011" as the bits
|
||||||
|
returns true if successfully converted and fits; false if too long */
|
||||||
|
bool bitstring_init_ascii(
|
||||||
|
BACNET_BIT_STRING * bit_string,
|
||||||
|
const char *ascii)
|
||||||
|
{
|
||||||
|
bool status = false; /* return value */
|
||||||
|
unsigned index = 0; /* offset into buffer */
|
||||||
|
uint8_t bit_number = 0;
|
||||||
|
|
||||||
|
if (bit_string) {
|
||||||
|
bitstring_init(bit_string);
|
||||||
|
if (ascii[0] == 0) {
|
||||||
|
/* nothing to decode, so success! */
|
||||||
|
status = true;
|
||||||
|
} else {
|
||||||
|
while (ascii[index] != 0) {
|
||||||
|
if (bit_number > bitstring_bits_capacity(bit_string)) {
|
||||||
|
/* too long of a string */
|
||||||
|
status = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ascii[index] == '1') {
|
||||||
|
bitstring_set_bit(bit_string, bit_number, true);
|
||||||
|
bit_number++;
|
||||||
|
status = true;
|
||||||
|
} else if (ascii[index] == '0') {
|
||||||
|
bitstring_set_bit(bit_string, bit_number, false);
|
||||||
|
bit_number++;
|
||||||
|
status = true;
|
||||||
|
} else {
|
||||||
|
/* skip non-numeric or alpha */
|
||||||
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* next character */
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CHARACTER_STRING_CAPACITY (MAX_CHARACTER_STRING_BYTES - 1)
|
#define CHARACTER_STRING_CAPACITY (MAX_CHARACTER_STRING_BYTES - 1)
|
||||||
/* returns false if the string exceeds capacity
|
/* returns false if the string exceeds capacity
|
||||||
initialize by using value=NULL */
|
initialize by using value=NULL */
|
||||||
|
|||||||
Reference in New Issue
Block a user