Feature/apdu null length returned (#285)

* Add APDU as NULL to get BACnet type lengths.

* Fix bacapp copy test to succeed

* fix BACnet REAL and DOUBLE decode

* Add unit test for NULL APDU encoding for length

* Add unit tests for bacapp context

* refactor host-n-port to hostnport.c module

* fix BVLC decoder

* additional unit testing for bacapp

* include bacdevobjpropref module in builds

* simplify bacapp snprintf to be able to return length

* adjust compiler for variable-length arrays

* fix bug found by scan-build

Authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2022-06-01 15:42:50 -05:00
committed by GitHub
parent 810bfefb34
commit f147283293
76 changed files with 3474 additions and 2791 deletions
+2
View File
@@ -369,6 +369,8 @@ add_library(${PROJECT_NAME}
src/bacnet/get_alarm_sum.h src/bacnet/get_alarm_sum.h
src/bacnet/getevent.c src/bacnet/getevent.c
src/bacnet/getevent.h src/bacnet/getevent.h
src/bacnet/hostnport.c
src/bacnet/hostnport.h
src/bacnet/iam.c src/bacnet/iam.c
src/bacnet/iam.h src/bacnet/iam.h
src/bacnet/ihave.c src/bacnet/ihave.c
+5
View File
@@ -212,6 +212,11 @@ pretty-ports:
find ./ports -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \ find ./ports -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \; clang-format -i -style=file -fallback-style=none {} \;
.PHONY: pretty-test
pretty-test:
find ./test/bacnet -maxdepth 2 -type f -iname *.h -o -iname *.c -exec \
clang-format -i -style=file -fallback-style=none {} \;
CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements" CLANG_TIDY_OPTIONS = -fix-errors -checks="readability-braces-around-statements"
CLANG_TIDY_OPTIONS += -- -Isrc -Iports/linux CLANG_TIDY_OPTIONS += -- -Isrc -Iports/linux
.PHONY: tidy .PHONY: tidy
+2
View File
@@ -81,6 +81,7 @@ CORESRC = $(BACNET_CORE)/abort.c \
$(BACNET_CORE)/bacaddr.c \ $(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/bacapp.c \ $(BACNET_CORE)/bacapp.c \
$(BACNET_CORE)/bacdcode.c \ $(BACNET_CORE)/bacdcode.c \
$(BACNET_CORE)/bacdevobjpropref.c \
$(BACNET_CORE)/bacerror.c \ $(BACNET_CORE)/bacerror.c \
$(BACNET_CORE)/bacint.c \ $(BACNET_CORE)/bacint.c \
$(BACNET_CORE)/bacreal.c \ $(BACNET_CORE)/bacreal.c \
@@ -90,6 +91,7 @@ CORESRC = $(BACNET_CORE)/abort.c \
$(BACNET_CORE)/dcc.c \ $(BACNET_CORE)/dcc.c \
$(BACNET_CORE)/iam.c \ $(BACNET_CORE)/iam.c \
$(BACNET_CORE)/ihave.c \ $(BACNET_CORE)/ihave.c \
$(BACNET_CORE)/hostnport.c \
$(BACNET_CORE)/lighting.c \ $(BACNET_CORE)/lighting.c \
$(BACNET_CORE)/memcopy.c \ $(BACNET_CORE)/memcopy.c \
$(BACNET_CORE)/npdu.c \ $(BACNET_CORE)/npdu.c \
+1204 -1105
View File
File diff suppressed because it is too large Load Diff
+8
View File
@@ -359,6 +359,10 @@
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>BACnet Core\bacdcode.c</Link> <Link>BACnet Core\bacdcode.c</Link>
</Compile> </Compile>
<Compile Include="..\..\src\bacnet\bacdevobjpropref.c">
<SubType>compile</SubType>
<Link>BACnet Core\bacdevobjpropref.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\bacerror.c"> <Compile Include="..\..\src\bacnet\bacerror.c">
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>BACnet Core\bacerror.c</Link> <Link>BACnet Core\bacerror.c</Link>
@@ -395,6 +399,10 @@
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>BACnet Core\ihave.c</Link> <Link>BACnet Core\ihave.c</Link>
</Compile> </Compile>
<Compile Include="..\..\src\bacnet\hostnport.c">
<SubType>compile</SubType>
<Link>BACnet Core\hostnport.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\lighting.c"> <Compile Include="..\..\src\bacnet\lighting.c">
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>BACnet Core\lighting.c</Link> <Link>BACnet Core\lighting.c</Link>
+3
View File
@@ -4442,6 +4442,9 @@
<file> <file>
<name>$PROJ_DIR$\mstimer-init.c</name> <name>$PROJ_DIR$\mstimer-init.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\netport.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\rs485.c</name> <name>$PROJ_DIR$\rs485.c</name>
</file> </file>
+1
View File
@@ -38,6 +38,7 @@ Goto lib/stack and copy the requested files from Steve code :
h_whois.c h_whois.c
h_wp.c h_wp.c
iam.c iam.c
hostnport.c
lighting.c lighting.c
memcopy.c memcopy.c
noserv.c noserv.c
@@ -1,8 +1,6 @@
# #
#Mon May 30 09:47:38 CDT 2016 #Sun Aug 22 10:50:21 CDT 2021
default.com-microchip-mplab-nbide-toolchainC18-C18LanguageToolchain.md5=21ae92f54c0f89bc027339aedc19b7f9 configurations-xml=76d5fe9d80d284cbe317219a22001b30
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\mplabc18\\v3.40\\bin com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=9db8f8a224aa17d0023ea7f468f871dc
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=ef199adcc8f049579a105cca20571dcb host.platform=linux
default.languagetoolchain.version=3.40 conf.ids=
host.platform=windows
conf.ids=default
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configurationDescriptor version="62"> <configurationDescriptor version="65">
<logicalFolder name="root" displayName="root" projectFiles="true"> <logicalFolder name="root" displayName="root" projectFiles="true">
<logicalFolder name="HeaderFiles" <logicalFolder name="HeaderFiles"
displayName="Header Files" displayName="Header Files"
@@ -94,15 +94,25 @@
<languageToolchainVersion>3.40</languageToolchainVersion> <languageToolchainVersion>3.40</languageToolchainVersion>
<platform>3</platform> <platform>3</platform>
</toolsSet> </toolsSet>
<packs>
<pack name="PIC18Fxxxx_DFP" vendor="Microchip" version="1.2.26"/>
</packs>
<ScriptingSettings>
</ScriptingSettings>
<compileType> <compileType>
<linkerTool> <linkerTool>
<linkerLibItems> <linkerLibItems>
</linkerLibItems> </linkerLibItems>
</linkerTool> </linkerTool>
<archiverTool>
</archiverTool>
<loading> <loading>
<useAlternateLoadableFile>false</useAlternateLoadableFile> <useAlternateLoadableFile>false</useAlternateLoadableFile>
<parseOnProdLoad>false</parseOnProdLoad>
<alternateLoadableFile></alternateLoadableFile> <alternateLoadableFile></alternateLoadableFile>
</loading> </loading>
<subordinates>
</subordinates>
</compileType> </compileType>
<makeCustomizationType> <makeCustomizationType>
<makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled> <makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled>
@@ -10,7 +10,20 @@
<cpp-extensions/> <cpp-extensions/>
<header-extensions>h</header-extensions> <header-extensions>h</header-extensions>
<sourceEncoding>ISO-8859-1</sourceEncoding> <sourceEncoding>ISO-8859-1</sourceEncoding>
<asminc-extensions/>
<make-dep-projects/> <make-dep-projects/>
<sourceRootList>
<sourceRootElem>../</sourceRootElem>
</sourceRootList>
<confList>
<confElem>
<name>default</name>
<type>2</type>
</confElem>
</confList>
<formatting>
<project-formatting-style>false</project-formatting-style>
</formatting>
</data> </data>
</configuration> </configuration>
</project> </project>
+2
View File
@@ -55,6 +55,7 @@ BACNET_SRC = \
$(BACNET_CORE)/bacaddr.c \ $(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/bacapp.c \ $(BACNET_CORE)/bacapp.c \
$(BACNET_CORE)/bacdcode.c \ $(BACNET_CORE)/bacdcode.c \
$(BACNET_CORE)/bacdevobjpropref.c \
$(BACNET_CORE)/bacerror.c \ $(BACNET_CORE)/bacerror.c \
$(BACNET_CORE)/bacint.c \ $(BACNET_CORE)/bacint.c \
$(BACNET_CORE)/bacreal.c \ $(BACNET_CORE)/bacreal.c \
@@ -63,6 +64,7 @@ BACNET_SRC = \
$(BACNET_CORE)/dcc.c \ $(BACNET_CORE)/dcc.c \
$(BACNET_CORE)/iam.c \ $(BACNET_CORE)/iam.c \
$(BACNET_CORE)/ihave.c \ $(BACNET_CORE)/ihave.c \
$(BACNET_CORE)/hostnport.c \
$(BACNET_CORE)/lighting.c \ $(BACNET_CORE)/lighting.c \
$(BACNET_CORE)/memcopy.c \ $(BACNET_CORE)/memcopy.c \
$(BACNET_CORE)/npdu.c \ $(BACNET_CORE)/npdu.c \
+6
View File
@@ -1057,6 +1057,9 @@
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\bacdcode.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\bacdcode.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\bacdevobjpropref.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\bacerror.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\bacerror.c</name>
</file> </file>
@@ -1078,6 +1081,9 @@
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\ihave.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\ihave.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\hostnport.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\lighting.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\lighting.c</name>
</file> </file>
+2
View File
@@ -53,6 +53,7 @@ BACNET_SRC = \
$(BACNET_CORE)/bacaddr.c \ $(BACNET_CORE)/bacaddr.c \
$(BACNET_CORE)/bacapp.c \ $(BACNET_CORE)/bacapp.c \
$(BACNET_CORE)/bacdcode.c \ $(BACNET_CORE)/bacdcode.c \
$(BACNET_CORE)/bacdevobjpropref.c \
$(BACNET_CORE)/bacerror.c \ $(BACNET_CORE)/bacerror.c \
$(BACNET_CORE)/bacint.c \ $(BACNET_CORE)/bacint.c \
$(BACNET_CORE)/bacreal.c \ $(BACNET_CORE)/bacreal.c \
@@ -61,6 +62,7 @@ BACNET_SRC = \
$(BACNET_CORE)/dcc.c \ $(BACNET_CORE)/dcc.c \
$(BACNET_CORE)/iam.c \ $(BACNET_CORE)/iam.c \
$(BACNET_CORE)/ihave.c \ $(BACNET_CORE)/ihave.c \
$(BACNET_CORE)/hostnport.c \
$(BACNET_CORE)/lighting.c \ $(BACNET_CORE)/lighting.c \
$(BACNET_CORE)/memcopy.c \ $(BACNET_CORE)/memcopy.c \
$(BACNET_CORE)/npdu.c \ $(BACNET_CORE)/npdu.c \
+3
View File
@@ -1090,6 +1090,9 @@
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\ihave.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\ihave.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\..\src\bacnet\hostnport.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\..\src\bacnet\lighting.c</name> <name>$PROJ_DIR$\..\..\src\bacnet\lighting.c</name>
</file> </file>
@@ -198,6 +198,7 @@
<ClCompile Include="..\..\..\..\src\bacnet\indtext.c" /> <ClCompile Include="..\..\..\..\src\bacnet\indtext.c" />
<ClCompile Include="..\..\..\..\src\bacnet\basic\sys\key.c" /> <ClCompile Include="..\..\..\..\src\bacnet\basic\sys\key.c" />
<ClCompile Include="..\..\..\..\src\bacnet\basic\sys\keylist.c" /> <ClCompile Include="..\..\..\..\src\bacnet\basic\sys\keylist.c" />
<ClCompile Include="..\..\..\..\src\bacnet\hostnport.c" />
<ClCompile Include="..\..\..\..\src\bacnet\lighting.c" /> <ClCompile Include="..\..\..\..\src\bacnet\lighting.c" />
<ClCompile Include="..\..\..\..\src\bacnet\lso.c" /> <ClCompile Include="..\..\..\..\src\bacnet\lso.c" />
<ClCompile Include="..\..\..\..\src\bacnet\memcopy.c" /> <ClCompile Include="..\..\..\..\src\bacnet\memcopy.c" />
@@ -90,6 +90,9 @@
<ClCompile Include="..\..\..\..\src\bacnet\indtext.c"> <ClCompile Include="..\..\..\..\src\bacnet\indtext.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\..\src\bacnet\hostnport.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\bacnet\lighting.c"> <ClCompile Include="..\..\..\..\src\bacnet\lighting.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
+8
View File
@@ -586,6 +586,10 @@
<None Include="ASF\common\drivers\nvm\common_nvm.h"> <None Include="ASF\common\drivers\nvm\common_nvm.h">
<SubType>compile</SubType> <SubType>compile</SubType>
</None> </None>
<Compile Include="..\..\src\bacnet\hostnport.c">
<SubType>compile</SubType>
<Link>bacnet-stack\hostnport.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\lighting.c"> <Compile Include="..\..\src\bacnet\lighting.c">
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>bacnet-stack\lighting.c</Link> <Link>bacnet-stack\lighting.c</Link>
@@ -768,6 +772,10 @@
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>bacnet-stack\bacdcode.c</Link> <Link>bacnet-stack\bacdcode.c</Link>
</Compile> </Compile>
<Compile Include="..\..\src\bacnet\bacdevobjpropref.c">
<SubType>compile</SubType>
<Link>bacnet-stack\bacdevobjpropref.c</Link>
</Compile>
<Compile Include="..\..\src\bacnet\bacerror.c"> <Compile Include="..\..\src\bacnet\bacerror.c">
<SubType>compile</SubType> <SubType>compile</SubType>
<Link>bacnet-stack\bacerror.c</Link> <Link>bacnet-stack\bacerror.c</Link>
+1 -1
View File
@@ -166,7 +166,7 @@ bool bacnet_name_write_unique(uint16_t offset,
bool status = false; bool status = false;
size_t length = 0; size_t length = 0;
uint8_t encoding = 0; uint8_t encoding = 0;
int duplicate_type = 0; BACNET_OBJECT_TYPE duplicate_type = 0;
uint32_t duplicate_instance = 0; uint32_t duplicate_instance = 0;
length = characterstring_length(char_string); length = characterstring_length(char_string);
+498 -887
View File
File diff suppressed because it is too large Load Diff
+32 -36
View File
@@ -1,26 +1,26 @@
/************************************************************************** /**************************************************************************
* *
* Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net> * Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************/ *********************************************************************/
#ifndef BACAPP_H #ifndef BACAPP_H
#define BACAPP_H #define BACAPP_H
@@ -32,15 +32,9 @@
#include "bacnet/bacint.h" #include "bacnet/bacint.h"
#include "bacnet/bacstr.h" #include "bacnet/bacstr.h"
#include "bacnet/datetime.h" #include "bacnet/datetime.h"
#if defined (BACAPP_LIGHTING_COMMAND)
#include "bacnet/lighting.h" #include "bacnet/lighting.h"
#endif
#if defined (BACAPP_DEVICE_OBJECT_PROP_REF)
#include "bacnet/bacdevobjpropref.h" #include "bacnet/bacdevobjpropref.h"
#endif #include "bacnet/hostnport.h"
#if defined(BACAPP_HOST_N_PORT)
#include "bacnet/datalink/datalink.h"
#endif
struct BACnet_Application_Data_Value; struct BACnet_Application_Data_Value;
typedef struct BACnet_Application_Data_Value { typedef struct BACnet_Application_Data_Value {
@@ -85,13 +79,9 @@ typedef struct BACnet_Application_Data_Value {
#if defined (BACAPP_OBJECT_ID) #if defined (BACAPP_OBJECT_ID)
BACNET_OBJECT_ID Object_Id; BACNET_OBJECT_ID Object_Id;
#endif #endif
#if defined (BACAPP_LIGHTING_COMMAND) #if defined (BACAPP_TYPES_EXTRA)
BACNET_LIGHTING_COMMAND Lighting_Command; BACNET_LIGHTING_COMMAND Lighting_Command;
#endif BACNET_HOST_N_PORT Host_Address;
#if defined(BACAPP_HOST_N_PORT)
BACNET_IP_ADDRESS IP_Address;
#endif
#if defined (BACAPP_DEVICE_OBJECT_PROP_REF)
BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE
Device_Object_Property_Reference; Device_Object_Property_Reference;
#endif #endif
@@ -204,6 +194,13 @@ extern "C" {
BACNET_PROPERTY_ID property, BACNET_PROPERTY_ID property,
uint8_t tag_number); uint8_t tag_number);
BACNET_STACK_EXPORT
int bacapp_decode_generic_property(
uint8_t * apdu,
int max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID prop);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
bool bacapp_copy( bool bacapp_copy(
BACNET_APPLICATION_DATA_VALUE * dest_value, BACNET_APPLICATION_DATA_VALUE * dest_value,
@@ -238,7 +235,6 @@ extern "C" {
#define BACAPP_PRINT_ENABLED #define BACAPP_PRINT_ENABLED
#endif #endif
#endif #endif
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
int bacapp_snprintf_value( int bacapp_snprintf_value(
char *str, char *str,
+624 -297
View File
File diff suppressed because it is too large Load Diff
+28 -22
View File
@@ -1,26 +1,26 @@
/************************************************************************** /**************************************************************************
* *
* Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net> * Copyright (C) 2012 Steve Karg <skarg@users.sourceforge.net>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including * "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, * without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************/ *********************************************************************/
#ifndef BACDCODE_H #ifndef BACDCODE_H
#define BACDCODE_H #define BACDCODE_H
@@ -215,10 +215,16 @@ extern "C" {
uint8_t * apdu, uint8_t * apdu,
BACNET_OBJECT_TYPE * object_type, BACNET_OBJECT_TYPE * object_type,
uint32_t * object_instance); uint32_t * object_instance);
int decode_object_id_safe(
uint8_t * apdu,
uint32_t len_value,
BACNET_OBJECT_TYPE * object_type,
uint32_t * object_instance);
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
int bacnet_object_id_decode( int bacnet_object_id_decode(
uint8_t * apdu, uint8_t * apdu,
uint16_t apdu_len_max,
uint32_t len_value, uint32_t len_value,
BACNET_OBJECT_TYPE * object_type, BACNET_OBJECT_TYPE * object_type,
uint32_t * instance); uint32_t * instance);
+100 -55
View File
@@ -43,15 +43,17 @@
int encode_unsigned16(uint8_t *apdu, uint16_t value) int encode_unsigned16(uint8_t *apdu, uint16_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff00) >> 8); if (apdu) {
apdu[1] = (uint8_t)(value & 0x00ff); apdu[0] = (uint8_t)((value & 0xff00) >> 8);
apdu[1] = (uint8_t)(value & 0x00ff);
}
return 2; return 2;
} }
int decode_unsigned16(uint8_t *apdu, uint16_t *value) int decode_unsigned16(uint8_t *apdu, uint16_t *value)
{ {
if (value) { if (apdu && value) {
*value = (uint16_t)((((uint16_t)apdu[0]) << 8) & 0xff00); *value = (uint16_t)((((uint16_t)apdu[0]) << 8) & 0xff00);
*value |= ((uint16_t)(((uint16_t)apdu[1]) & 0x00ff)); *value |= ((uint16_t)(((uint16_t)apdu[1]) & 0x00ff));
} }
@@ -61,16 +63,18 @@ int decode_unsigned16(uint8_t *apdu, uint16_t *value)
int encode_unsigned24(uint8_t *apdu, uint32_t value) int encode_unsigned24(uint8_t *apdu, uint32_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff0000) >> 16); if (apdu) {
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8); apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
apdu[2] = (uint8_t)(value & 0x0000ff); apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t)(value & 0x0000ff);
}
return 3; return 3;
} }
int decode_unsigned24(uint8_t *apdu, uint32_t *value) int decode_unsigned24(uint8_t *apdu, uint32_t *value)
{ {
if (value) { if (apdu && value) {
*value = ((uint32_t)((((uint32_t)apdu[0]) << 16) & 0x00ff0000)); *value = ((uint32_t)((((uint32_t)apdu[0]) << 16) & 0x00ff0000));
*value |= (uint32_t)((((uint32_t)apdu[1]) << 8) & 0x0000ff00); *value |= (uint32_t)((((uint32_t)apdu[1]) << 8) & 0x0000ff00);
*value |= ((uint32_t)(((uint32_t)apdu[2]) & 0x000000ff)); *value |= ((uint32_t)(((uint32_t)apdu[2]) & 0x000000ff));
@@ -81,17 +85,19 @@ int decode_unsigned24(uint8_t *apdu, uint32_t *value)
int encode_unsigned32(uint8_t *apdu, uint32_t value) int encode_unsigned32(uint8_t *apdu, uint32_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff000000) >> 24); if (apdu) {
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16); apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8); apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
apdu[3] = (uint8_t)(value & 0x000000ff); apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t)(value & 0x000000ff);
}
return 4; return 4;
} }
int decode_unsigned32(uint8_t *apdu, uint32_t *value) int decode_unsigned32(uint8_t *apdu, uint32_t *value)
{ {
if (value) { if (apdu && value) {
*value = ((uint32_t)((((uint32_t)apdu[0]) << 24) & 0xff000000)); *value = ((uint32_t)((((uint32_t)apdu[0]) << 24) & 0xff000000));
*value |= ((uint32_t)((((uint32_t)apdu[1]) << 16) & 0x00ff0000)); *value |= ((uint32_t)((((uint32_t)apdu[1]) << 16) & 0x00ff0000));
*value |= ((uint32_t)((((uint32_t)apdu[2]) << 8) & 0x0000ff00)); *value |= ((uint32_t)((((uint32_t)apdu[2]) << 8) & 0x0000ff00));
@@ -110,11 +116,13 @@ int decode_unsigned32(uint8_t *apdu, uint32_t *value)
*/ */
int encode_unsigned40(uint8_t *buffer, uint64_t value) int encode_unsigned40(uint8_t *buffer, uint64_t value)
{ {
buffer[0] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32); if (buffer) {
buffer[1] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24); buffer[0] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32);
buffer[2] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16); buffer[1] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24);
buffer[3] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8); buffer[2] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16);
buffer[4] = (uint8_t)(value & 0x00000000000000ffULL); buffer[3] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8);
buffer[4] = (uint8_t)(value & 0x00000000000000ffULL);
}
return 5; return 5;
} }
@@ -127,7 +135,7 @@ int encode_unsigned40(uint8_t *buffer, uint64_t value)
*/ */
int decode_unsigned40(uint8_t *buffer, uint64_t *value) int decode_unsigned40(uint8_t *buffer, uint64_t *value)
{ {
if (value) { if (buffer && value) {
*value = *value =
((uint64_t)((((uint64_t)buffer[0]) << 32) & 0x000000ff00000000ULL)); ((uint64_t)((((uint64_t)buffer[0]) << 32) & 0x000000ff00000000ULL));
*value |= *value |=
@@ -150,12 +158,14 @@ int decode_unsigned40(uint8_t *buffer, uint64_t *value)
*/ */
int encode_unsigned48(uint8_t *buffer, uint64_t value) int encode_unsigned48(uint8_t *buffer, uint64_t value)
{ {
buffer[0] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40); if (buffer) {
buffer[1] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32); buffer[0] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40);
buffer[2] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24); buffer[1] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32);
buffer[3] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16); buffer[2] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24);
buffer[4] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8); buffer[3] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16);
buffer[5] = (uint8_t)(value & 0x00000000000000ffULL); buffer[4] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8);
buffer[5] = (uint8_t)(value & 0x00000000000000ffULL);
}
return 6; return 6;
} }
@@ -168,7 +178,7 @@ int encode_unsigned48(uint8_t *buffer, uint64_t value)
*/ */
int decode_unsigned48(uint8_t *buffer, uint64_t *value) int decode_unsigned48(uint8_t *buffer, uint64_t *value)
{ {
if (value) { if (buffer && value) {
*value = *value =
((uint64_t)((((uint64_t)buffer[0]) << 40) & 0x0000ff0000000000ULL)); ((uint64_t)((((uint64_t)buffer[0]) << 40) & 0x0000ff0000000000ULL));
*value |= *value |=
@@ -193,13 +203,15 @@ int decode_unsigned48(uint8_t *buffer, uint64_t *value)
*/ */
int encode_unsigned56(uint8_t *buffer, uint64_t value) int encode_unsigned56(uint8_t *buffer, uint64_t value)
{ {
buffer[0] = (uint8_t)((value & 0x00ff000000000000ULL) >> 48); if (buffer) {
buffer[1] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40); buffer[0] = (uint8_t)((value & 0x00ff000000000000ULL) >> 48);
buffer[2] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32); buffer[1] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40);
buffer[3] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24); buffer[2] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32);
buffer[4] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16); buffer[3] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24);
buffer[5] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8); buffer[4] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16);
buffer[6] = (uint8_t)(value & 0x00000000000000ffULL); buffer[5] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8);
buffer[6] = (uint8_t)(value & 0x00000000000000ffULL);
}
return 7; return 7;
} }
@@ -212,7 +224,7 @@ int encode_unsigned56(uint8_t *buffer, uint64_t value)
*/ */
int decode_unsigned56(uint8_t *buffer, uint64_t *value) int decode_unsigned56(uint8_t *buffer, uint64_t *value)
{ {
if (value) { if (buffer && value) {
*value = *value =
((uint64_t)((((uint64_t)buffer[0]) << 48) & 0x00ff000000000000ULL)); ((uint64_t)((((uint64_t)buffer[0]) << 48) & 0x00ff000000000000ULL));
*value |= *value |=
@@ -239,14 +251,16 @@ int decode_unsigned56(uint8_t *buffer, uint64_t *value)
*/ */
int encode_unsigned64(uint8_t *buffer, uint64_t value) int encode_unsigned64(uint8_t *buffer, uint64_t value)
{ {
buffer[0] = (uint8_t)((value & 0xff00000000000000ULL) >> 56); if (buffer) {
buffer[1] = (uint8_t)((value & 0x00ff000000000000ULL) >> 48); buffer[0] = (uint8_t)((value & 0xff00000000000000ULL) >> 56);
buffer[2] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40); buffer[1] = (uint8_t)((value & 0x00ff000000000000ULL) >> 48);
buffer[3] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32); buffer[2] = (uint8_t)((value & 0x0000ff0000000000ULL) >> 40);
buffer[4] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24); buffer[3] = (uint8_t)((value & 0x000000ff00000000ULL) >> 32);
buffer[5] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16); buffer[4] = (uint8_t)((value & 0x00000000ff000000ULL) >> 24);
buffer[6] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8); buffer[5] = (uint8_t)((value & 0x0000000000ff0000ULL) >> 16);
buffer[7] = (uint8_t)(value & 0x00000000000000ffULL); buffer[6] = (uint8_t)((value & 0x000000000000ff00ULL) >> 8);
buffer[7] = (uint8_t)(value & 0x00000000000000ffULL);
}
return 8; return 8;
} }
@@ -259,7 +273,7 @@ int encode_unsigned64(uint8_t *buffer, uint64_t value)
*/ */
int decode_unsigned64(uint8_t *buffer, uint64_t *value) int decode_unsigned64(uint8_t *buffer, uint64_t *value)
{ {
if (value) { if (buffer && value) {
*value = *value =
((uint64_t)((((uint64_t)buffer[0]) << 56) & 0xff00000000000000ULL)); ((uint64_t)((((uint64_t)buffer[0]) << 56) & 0xff00000000000000ULL));
*value |= *value |=
@@ -320,14 +334,16 @@ int bacnet_unsigned_length(BACNET_UNSIGNED_INTEGER value)
#if BACNET_USE_SIGNED #if BACNET_USE_SIGNED
int encode_signed8(uint8_t *apdu, int8_t value) int encode_signed8(uint8_t *apdu, int8_t value)
{ {
apdu[0] = (uint8_t)value; if (apdu) {
apdu[0] = (uint8_t)value;
}
return 1; return 1;
} }
int decode_signed8(uint8_t *apdu, int32_t *value) int decode_signed8(uint8_t *apdu, int32_t *value)
{ {
if (value) { if (apdu && value) {
/* negative - bit 7 is set */ /* negative - bit 7 is set */
if (apdu[0] & 0x80) { if (apdu[0] & 0x80) {
*value = 0xFFFFFF00; *value = 0xFFFFFF00;
@@ -342,15 +358,17 @@ int decode_signed8(uint8_t *apdu, int32_t *value)
int encode_signed16(uint8_t *apdu, int16_t value) int encode_signed16(uint8_t *apdu, int16_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff00) >> 8); if (apdu) {
apdu[1] = (uint8_t)(value & 0x00ff); apdu[0] = (uint8_t)((value & 0xff00) >> 8);
apdu[1] = (uint8_t)(value & 0x00ff);
}
return 2; return 2;
} }
int decode_signed16(uint8_t *apdu, int32_t *value) int decode_signed16(uint8_t *apdu, int32_t *value)
{ {
if (value) { if (apdu && value) {
/* negative - bit 7 is set */ /* negative - bit 7 is set */
if (apdu[0] & 0x80) { if (apdu[0] & 0x80) {
*value = 0xFFFF0000; *value = 0xFFFF0000;
@@ -366,16 +384,18 @@ int decode_signed16(uint8_t *apdu, int32_t *value)
int encode_signed24(uint8_t *apdu, int32_t value) int encode_signed24(uint8_t *apdu, int32_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff0000) >> 16); if (apdu) {
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8); apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
apdu[2] = (uint8_t)(value & 0x0000ff); apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t)(value & 0x0000ff);
}
return 3; return 3;
} }
int decode_signed24(uint8_t *apdu, int32_t *value) int decode_signed24(uint8_t *apdu, int32_t *value)
{ {
if (value) { if (apdu && value) {
/* negative - bit 7 is set */ /* negative - bit 7 is set */
if (apdu[0] & 0x80) { if (apdu[0] & 0x80) {
*value = 0xFF000000; *value = 0xFF000000;
@@ -392,10 +412,12 @@ int decode_signed24(uint8_t *apdu, int32_t *value)
int encode_signed32(uint8_t *apdu, int32_t value) int encode_signed32(uint8_t *apdu, int32_t value)
{ {
apdu[0] = (uint8_t)((value & 0xff000000) >> 24); if (apdu) {
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16); apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8); apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
apdu[3] = (uint8_t)(value & 0x000000ff); apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t)(value & 0x000000ff);
}
return 4; return 4;
} }
@@ -411,4 +433,27 @@ int decode_signed32(uint8_t *apdu, int32_t *value)
return 4; return 4;
} }
/**
* @brief Determines the number of bytes used by a BACnet Signed Integer
* from clause 20.2.5 Encoding of an Signed Integer Value
* @param value - signed value
* @return number of bytes used by a BACnet Signed Integer
*/
int bacnet_signed_length(int32_t value)
{
int len;
if ((value >= -128) && (value < 128)) {
len = 1;
} else if ((value >= -32768) && (value < 32768)) {
len = 2;
} else if ((value > -8388608) && (value < 8388608)) {
len = 3;
} else {
len = 4;
}
return len;
}
#endif #endif
+5
View File
@@ -100,9 +100,14 @@ extern "C" {
uint8_t * buffer, uint8_t * buffer,
uint64_t * value); uint64_t * value);
#endif #endif
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
int bacnet_unsigned_length( int bacnet_unsigned_length(
BACNET_UNSIGNED_INTEGER value); BACNET_UNSIGNED_INTEGER value);
BACNET_STACK_EXPORT
int bacnet_signed_length(
int32_t value);
/* signed value encoding and decoding */ /* signed value encoding and decoding */
BACNET_STACK_EXPORT BACNET_STACK_EXPORT
int encode_signed8( int encode_signed8(
+78 -62
View File
@@ -56,20 +56,24 @@ int decode_real(uint8_t *apdu, float *real_value)
float real_value; float real_value;
} my_data; } my_data;
/* NOTE: assumes the compiler stores float as IEEE-754 float */ if (apdu) {
if (big_endian()) { /* NOTE: assumes the compiler stores float as IEEE-754 float */
my_data.byte[0] = apdu[0]; if (big_endian()) {
my_data.byte[1] = apdu[1]; my_data.byte[0] = apdu[0];
my_data.byte[2] = apdu[2]; my_data.byte[1] = apdu[1];
my_data.byte[3] = apdu[3]; my_data.byte[2] = apdu[2];
} else { my_data.byte[3] = apdu[3];
my_data.byte[0] = apdu[3]; } else {
my_data.byte[1] = apdu[2]; my_data.byte[0] = apdu[3];
my_data.byte[2] = apdu[1]; my_data.byte[1] = apdu[2];
my_data.byte[3] = apdu[0]; my_data.byte[2] = apdu[1];
my_data.byte[3] = apdu[0];
}
if (real_value) {
*real_value = my_data.real_value;
}
} }
*real_value = my_data.real_value;
return 4; return 4;
} }
@@ -77,7 +81,9 @@ int decode_real(uint8_t *apdu, float *real_value)
int decode_real_safe(uint8_t *apdu, uint32_t len_value, float *real_value) int decode_real_safe(uint8_t *apdu, uint32_t len_value, float *real_value)
{ {
if (len_value != 4) { if (len_value != 4) {
*real_value = 0.0f; if (real_value) {
*real_value = 0.0f;
}
return (int)len_value; return (int)len_value;
} else { } else {
return decode_real(apdu, real_value); return decode_real(apdu, real_value);
@@ -95,16 +101,18 @@ int encode_bacnet_real(float value, uint8_t *apdu)
/* NOTE: assumes the compiler stores float as IEEE-754 float */ /* NOTE: assumes the compiler stores float as IEEE-754 float */
my_data.real_value = value; my_data.real_value = value;
if (big_endian()) { if (apdu) {
apdu[0] = my_data.byte[0]; if (big_endian()) {
apdu[1] = my_data.byte[1]; apdu[0] = my_data.byte[0];
apdu[2] = my_data.byte[2]; apdu[1] = my_data.byte[1];
apdu[3] = my_data.byte[3]; apdu[2] = my_data.byte[2];
} else { apdu[3] = my_data.byte[3];
apdu[0] = my_data.byte[3]; } else {
apdu[1] = my_data.byte[2]; apdu[0] = my_data.byte[3];
apdu[2] = my_data.byte[1]; apdu[1] = my_data.byte[2];
apdu[3] = my_data.byte[0]; apdu[2] = my_data.byte[1];
apdu[3] = my_data.byte[0];
}
} }
return 4; return 4;
@@ -121,27 +129,31 @@ int decode_double(uint8_t *apdu, double *double_value)
double double_value; double double_value;
} my_data; } my_data;
/* NOTE: assumes the compiler stores float as IEEE-754 float */ if (apdu) {
if (big_endian()) { /* NOTE: assumes the compiler stores float as IEEE-754 float */
my_data.byte[0] = apdu[0]; if (big_endian()) {
my_data.byte[1] = apdu[1]; my_data.byte[0] = apdu[0];
my_data.byte[2] = apdu[2]; my_data.byte[1] = apdu[1];
my_data.byte[3] = apdu[3]; my_data.byte[2] = apdu[2];
my_data.byte[4] = apdu[4]; my_data.byte[3] = apdu[3];
my_data.byte[5] = apdu[5]; my_data.byte[4] = apdu[4];
my_data.byte[6] = apdu[6]; my_data.byte[5] = apdu[5];
my_data.byte[7] = apdu[7]; my_data.byte[6] = apdu[6];
} else { my_data.byte[7] = apdu[7];
my_data.byte[0] = apdu[7]; } else {
my_data.byte[1] = apdu[6]; my_data.byte[0] = apdu[7];
my_data.byte[2] = apdu[5]; my_data.byte[1] = apdu[6];
my_data.byte[3] = apdu[4]; my_data.byte[2] = apdu[5];
my_data.byte[4] = apdu[3]; my_data.byte[3] = apdu[4];
my_data.byte[5] = apdu[2]; my_data.byte[4] = apdu[3];
my_data.byte[6] = apdu[1]; my_data.byte[5] = apdu[2];
my_data.byte[7] = apdu[0]; my_data.byte[6] = apdu[1];
my_data.byte[7] = apdu[0];
}
if (double_value) {
*double_value = my_data.double_value;
}
} }
*double_value = my_data.double_value;
return 8; return 8;
} }
@@ -149,7 +161,9 @@ int decode_double(uint8_t *apdu, double *double_value)
int decode_double_safe(uint8_t *apdu, uint32_t len_value, double *double_value) int decode_double_safe(uint8_t *apdu, uint32_t len_value, double *double_value)
{ {
if (len_value != 8) { if (len_value != 8) {
*double_value = 0.0; if (double_value) {
*double_value = 0.0;
}
return (int)len_value; return (int)len_value;
} else { } else {
return decode_double(apdu, double_value); return decode_double(apdu, double_value);
@@ -167,24 +181,26 @@ int encode_bacnet_double(double value, uint8_t *apdu)
/* NOTE: assumes the compiler stores float as IEEE-754 float */ /* NOTE: assumes the compiler stores float as IEEE-754 float */
my_data.double_value = value; my_data.double_value = value;
if (big_endian()) { if (apdu) {
apdu[0] = my_data.byte[0]; if (big_endian()) {
apdu[1] = my_data.byte[1]; apdu[0] = my_data.byte[0];
apdu[2] = my_data.byte[2]; apdu[1] = my_data.byte[1];
apdu[3] = my_data.byte[3]; apdu[2] = my_data.byte[2];
apdu[4] = my_data.byte[4]; apdu[3] = my_data.byte[3];
apdu[5] = my_data.byte[5]; apdu[4] = my_data.byte[4];
apdu[6] = my_data.byte[6]; apdu[5] = my_data.byte[5];
apdu[7] = my_data.byte[7]; apdu[6] = my_data.byte[6];
} else { apdu[7] = my_data.byte[7];
apdu[0] = my_data.byte[7]; } else {
apdu[1] = my_data.byte[6]; apdu[0] = my_data.byte[7];
apdu[2] = my_data.byte[5]; apdu[1] = my_data.byte[6];
apdu[3] = my_data.byte[4]; apdu[2] = my_data.byte[5];
apdu[4] = my_data.byte[3]; apdu[3] = my_data.byte[4];
apdu[5] = my_data.byte[2]; apdu[4] = my_data.byte[3];
apdu[6] = my_data.byte[1]; apdu[5] = my_data.byte[2];
apdu[7] = my_data.byte[0]; apdu[6] = my_data.byte[1];
apdu[7] = my_data.byte[0];
}
} }
return 8; return 8;
+25 -3
View File
@@ -129,8 +129,8 @@ const char *bactext_unconfirmed_service_name(unsigned index)
bacnet_unconfirmed_service_names, index, ASHRAE_Reserved_String); bacnet_unconfirmed_service_names, index, ASHRAE_Reserved_String);
} }
INDTEXT_DATA bacnet_application_tag_names[] = { { BACNET_APPLICATION_TAG_NULL, INDTEXT_DATA bacnet_application_tag_names[] = {
"Null" }, { BACNET_APPLICATION_TAG_NULL, "Null" },
{ BACNET_APPLICATION_TAG_BOOLEAN, "Boolean" }, { BACNET_APPLICATION_TAG_BOOLEAN, "Boolean" },
{ BACNET_APPLICATION_TAG_UNSIGNED_INT, "Unsigned Int" }, { BACNET_APPLICATION_TAG_UNSIGNED_INT, "Unsigned Int" },
{ BACNET_APPLICATION_TAG_SIGNED_INT, "Signed Int" }, { BACNET_APPLICATION_TAG_SIGNED_INT, "Signed Int" },
@@ -145,7 +145,29 @@ INDTEXT_DATA bacnet_application_tag_names[] = { { BACNET_APPLICATION_TAG_NULL,
{ BACNET_APPLICATION_TAG_OBJECT_ID, "Object ID" }, { BACNET_APPLICATION_TAG_OBJECT_ID, "Object ID" },
{ BACNET_APPLICATION_TAG_RESERVE1, "Reserved 1" }, { BACNET_APPLICATION_TAG_RESERVE1, "Reserved 1" },
{ BACNET_APPLICATION_TAG_RESERVE2, "Reserved 2" }, { BACNET_APPLICATION_TAG_RESERVE2, "Reserved 2" },
{ BACNET_APPLICATION_TAG_RESERVE3, "Reserved 3" }, { 0, NULL } }; { BACNET_APPLICATION_TAG_RESERVE3, "Reserved 3" },
/* complex data types */
{ BACNET_APPLICATION_TAG_EMPTYLIST, "Empty List" },
{ BACNET_APPLICATION_TAG_WEEKNDAY, "BACnetWeeknday" },
{ BACNET_APPLICATION_TAG_DATERANGE, "BACnetDateRange" },
{ BACNET_APPLICATION_TAG_DATETIME, "BACnetDateTime" },
{ BACNET_APPLICATION_TAG_TIMESTAMP, "BACnetTimeStamp" },
{ BACNET_APPLICATION_TAG_ERROR, "Error" },
{ BACNET_APPLICATION_TAG_DEVICE_OBJECT_PROPERTY_REFERENCE,
"BACnetDeviceObjectPropertyReference" },
{ BACNET_APPLICATION_TAG_DEVICE_OBJECT_REFERENCE,
"BACnetDeviceObjectReference" },
{ BACNET_APPLICATION_TAG_DESTINATION, "BACnetDestination" },
{ BACNET_APPLICATION_TAG_RECIPIENT, "BACnetRecipient" },
{ BACNET_APPLICATION_TAG_COV_SUBSCRIPTION, "BACnetCOVSubscription" },
{ BACNET_APPLICATION_TAG_CALENDAR_ENTRY, "BACnetCalendarEntry" },
{ BACNET_APPLICATION_TAG_WEEKLY_SCHEDULE, "BACnetWeeklySchedule" },
{ BACNET_APPLICATION_TAG_SPECIAL_EVENT, "BACnetSpecialEvent" },
{ BACNET_APPLICATION_TAG_READ_ACCESS_SPECIFICATION,
"BACnetReadAccessSpecification" },
{ BACNET_APPLICATION_TAG_LIGHTING_COMMAND, "BACnetLightingCommand" },
{ BACNET_APPLICATION_TAG_HOST_N_PORT, "BACnetHostNPort" },
{ 0, NULL } };
const char *bactext_application_tag_name(unsigned index) const char *bactext_application_tag_name(unsigned index)
{ {
+3 -3
View File
@@ -45,7 +45,7 @@
#include "bacnet/proplist.h" #include "bacnet/proplist.h"
#include "bacnet/lighting.h" #include "bacnet/lighting.h"
#include "bacnet/basic/object/device.h" #include "bacnet/basic/object/device.h"
#if defined(CHANNEL_LIGHTING_COMMAND) || defined(BACAPP_LIGHTING_COMMAND) #if defined(CHANNEL_LIGHTING_COMMAND)
#include "bacnet/basic/object/lo.h" #include "bacnet/basic/object/lo.h"
#endif #endif
/* me! */ /* me! */
@@ -628,7 +628,7 @@ bool Channel_Value_Copy(
status = true; status = true;
break; break;
#endif #endif
#if defined(BACAPP_LIGHTING_COMMAND) && defined(CHANNEL_LIGHTING_COMMAND) #if defined(BACAPP_TYPES_EXTRA) && defined(CHANNEL_LIGHTING_COMMAND)
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
cvalue->tag = value->tag; cvalue->tag = value->tag;
lighting_command_copy( lighting_command_copy(
@@ -1045,7 +1045,7 @@ int Channel_Coerce_Data_Encode(uint8_t *apdu,
} }
break; break;
#endif #endif
#if defined(BACAPP_LIGHTING_COMMAND) #if defined(BACAPP_TYPES_EXTRA)
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
if (tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) { if (tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) {
apdu_len = lighting_command_encode( apdu_len = lighting_command_encode(
+1 -1
View File
@@ -279,7 +279,7 @@ int cl_decode_apdu(uint8_t *apdu,
&bcl->Value.type.Object_Id.type, &bcl->Value.type.Object_Id.type,
&bcl->Value.type.Object_Id.instance); &bcl->Value.type.Object_Id.instance);
break; break;
#if defined(BACAPP_LIGHTING_COMMAND) #if defined(BACAPP_TYPES_EXTRA)
case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: case BACNET_APPLICATION_TAG_LIGHTING_COMMAND:
len = lighting_command_decode(&apdu[dec_len], apdu_len - dec_len, len = lighting_command_decode(&apdu[dec_len], apdu_len - dec_len,
&bcl->Value.type.Lighting_Command); &bcl->Value.type.Lighting_Command);
+1 -1
View File
@@ -210,7 +210,7 @@ static object_functions_t My_Object_Table[] = {
Trend_Log_Write_Property, Trend_Log_Property_Lists, TrendLogGetRRInfo, Trend_Log_Write_Property, Trend_Log_Property_Lists, TrendLogGetRRInfo,
NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */,
NULL /* COV Clear */, NULL /* Intrinsic Reporting */ }, NULL /* COV Clear */, NULL /* Intrinsic Reporting */ },
#if (BACNET_PROTOCOL_REVISION >= 14) && defined(BACAPP_LIGHTING_COMMAND) #if (BACNET_PROTOCOL_REVISION >= 14)
{ OBJECT_LIGHTING_OUTPUT, Lighting_Output_Init, Lighting_Output_Count, { OBJECT_LIGHTING_OUTPUT, Lighting_Output_Init, Lighting_Output_Count,
Lighting_Output_Index_To_Instance, Lighting_Output_Valid_Instance, Lighting_Output_Index_To_Instance, Lighting_Output_Valid_Instance,
Lighting_Output_Object_Name, Lighting_Output_Read_Property, Lighting_Output_Object_Name, Lighting_Output_Read_Property,
+3 -5
View File
@@ -143,9 +143,8 @@
defined(BACAPP_ENUMERATED) || \ defined(BACAPP_ENUMERATED) || \
defined(BACAPP_DATE) || \ defined(BACAPP_DATE) || \
defined(BACAPP_TIME) || \ defined(BACAPP_TIME) || \
defined(BACAPP_LIGHTING_COMMAND) || \ defined(BACAPP_OBJECT_ID) || \
defined(BACAPP_DEVICE_OBJECT_PROP_REF) || \ defined(BACAPP_TYPES_EXTRA))
defined(BACAPP_OBJECT_ID))
#define BACAPP_ALL #define BACAPP_ALL
#endif #endif
@@ -163,8 +162,7 @@
#define BACAPP_DATE #define BACAPP_DATE
#define BACAPP_TIME #define BACAPP_TIME
#define BACAPP_OBJECT_ID #define BACAPP_OBJECT_ID
#define BACAPP_DEVICE_OBJECT_PROP_REF #define BACAPP_TYPES_EXTRA
#define BACAPP_LIGHTING_COMMAND
#elif defined (BACAPP_MINIMAL) #elif defined (BACAPP_MINIMAL)
#define BACAPP_NULL #define BACAPP_NULL
#define BACAPP_BOOLEAN #define BACAPP_BOOLEAN
+25 -105
View File
@@ -39,6 +39,7 @@
#include "bacnet/bacdcode.h" #include "bacnet/bacdcode.h"
#include "bacnet/bacint.h" #include "bacnet/bacint.h"
#include "bacnet/bacdef.h" #include "bacnet/bacdef.h"
#include "bacnet/hostnport.h"
#include "bacnet/datalink/bvlc.h" #include "bacnet/datalink/bvlc.h"
/** /**
@@ -2623,15 +2624,6 @@ const char *bvlc_result_code_name(uint16_t result_code)
/** /**
* @brief Encode a BBMD Address for Network Port object * @brief Encode a BBMD Address for Network Port object
*
* BACnetHostNPort ::= SEQUENCE {
* host [0] BACnetHostAddress,
* BACnetHostAddress ::= CHOICE {
* ip-address [1] OCTET STRING, -- 4 octets for B/IP
* }
* port [1] Unsigned16
* }
*
* @param apdu - the APDU buffer * @param apdu - the APDU buffer
* @param apdu_size - the APDU buffer size * @param apdu_size - the APDU buffer size
* @param ip_address - IP address and port number * @param ip_address - IP address and port number
@@ -2641,27 +2633,17 @@ int bvlc_foreign_device_bbmd_host_address_encode(uint8_t *apdu,
uint16_t apdu_size, uint16_t apdu_size,
BACNET_IP_ADDRESS *ip_address) BACNET_IP_ADDRESS *ip_address)
{ {
int len = 0; BACNET_HOST_N_PORT address = { 0 };
int apdu_len = 0; int apdu_len = 0;
BACNET_OCTET_STRING octet_string;
if (apdu && (apdu_size >= 9) && ip_address) { address.host_ip_address = true;
/* host [0] BACnetHostAddress - opening */ address.host_name = false;
len = encode_opening_tag(&apdu[apdu_len], 0); octetstring_init(&address.host.ip_address, &ip_address->address[0],
apdu_len += len; IP_ADDRESS_MAX);
/* CHOICE - ip-address [1] OCTET STRING */ address.port = ip_address->port;
octetstring_init(&octet_string, apdu_len = host_n_port_encode(NULL, &address);
&ip_address->address[0], IP_ADDRESS_MAX); if (apdu_len <= apdu_size) {
len = encode_context_octet_string(&apdu[apdu_len], 1, apdu_len = host_n_port_encode(apdu, &address);
&octet_string);
apdu_len += len;
/* host [0] BACnetHostAddress - closing */
len = encode_closing_tag(&apdu[apdu_len], 0);
apdu_len += len;
/* port [1] Unsigned16 */
len = encode_context_unsigned(
&apdu[apdu_len], 1, ip_address->port);
apdu_len += len;
} }
return apdu_len; return apdu_len;
@@ -2669,15 +2651,6 @@ int bvlc_foreign_device_bbmd_host_address_encode(uint8_t *apdu,
/** /**
* @brief Decode the Broadcast-Distribution-Table for Network Port object * @brief Decode the Broadcast-Distribution-Table for Network Port object
*
* BACnetHostNPort ::= SEQUENCE {
* host [0] BACnetHostAddress,
* BACnetHostAddress ::= CHOICE {
* ip-address [1] OCTET STRING, -- 4 octets for B/IP
* }
* port [1] Unsigned16
* }
*
* @param apdu - the APDU buffer * @param apdu - the APDU buffer
* @param apdu_len - the APDU buffer length * @param apdu_len - the APDU buffer length
* @param ip_address - IP address and port number * @param ip_address - IP address and port number
@@ -2688,77 +2661,24 @@ int bvlc_foreign_device_bbmd_host_address_decode(uint8_t *apdu,
BACNET_ERROR_CODE *error_code, BACNET_ERROR_CODE *error_code,
BACNET_IP_ADDRESS *ip_address) BACNET_IP_ADDRESS *ip_address)
{ {
BACNET_HOST_N_PORT address = { 0 };
int len = 0; int len = 0;
BACNET_OCTET_STRING octet_string = { 0 };
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
BACNET_UNSIGNED_INTEGER unsigned_value = 0;
/* default reject code */ len = host_n_port_decode(apdu, apdu_len, error_code, &address);
if (error_code) { if (len > 0) {
*error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; if (address.host_ip_address) {
} ip_address->port = address.port;
/* check for value pointers */ (void)octetstring_copy_value(
if ((apdu_len == 0) || (!apdu)) { &ip_address->address[0],
return BACNET_STATUS_REJECT; IP_ADDRESS_MAX,
} &address.host.ip_address);
/* host [0] BACnetHostAddress - opening */ } else {
if (!decode_is_opening_tag_number(&apdu[len++], 0)) { len = BACNET_STATUS_REJECT;
if (error_code) { if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG; *error_code = ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE;
}
} }
return BACNET_STATUS_REJECT;
}
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
/* CHOICE - ip-address [1] OCTET STRING */
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value_type);
if (tag_number != 1) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
len += decode_octet_string(&apdu[len], len_value_type,
&octet_string);
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
(void)octetstring_copy_value(&ip_address->address[0],
IP_ADDRESS_MAX, &octet_string);
/* host [0] BACnetHostAddress - closing */
if (!decode_is_closing_tag_number(&apdu[len++], 0)) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
/* port [1] Unsigned16 */
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value_type);
if (tag_number != 1) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
len += decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
if (unsigned_value <= UINT16_MAX) {
ip_address->port = unsigned_value;
} else {
if (error_code) {
*error_code = ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE;
}
return BACNET_STATUS_REJECT;
} }
return apdu_len; return len;
} }
+1 -1
View File
@@ -55,7 +55,7 @@ typedef struct dlmstp_statistics {
} DLMSTP_STATISTICS; } DLMSTP_STATISTICS;
/* callback to signify the receipt of a preamble */ /* callback to signify the receipt of a preamble */
typedef void (*dlmstp_hook_frame_rx_start_cb)(); typedef void (*dlmstp_hook_frame_rx_start_cb)(void);
/* callback on for receiving every valid frame */ /* callback on for receiving every valid frame */
typedef void (*dlmstp_hook_frame_rx_complete_cb)( typedef void (*dlmstp_hook_frame_rx_complete_cb)(
+308
View File
@@ -0,0 +1,308 @@
/**
* @file
* @brief BACnetHostNPort complex data type encode and decode
* @author Steve Karg <skarg@users.sourceforge.net>
* @date May 2022
* @section LICENSE
*
* Copyright (C) 2022 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include "bacnet/hostnport.h"
#include "bacnet/bacdcode.h"
/**
* @brief Encode a BACnetHostNPort complex data type
*
* BACnetHostNPort ::= SEQUENCE {
* host [0] BACnetHostAddress,
* BACnetHostAddress ::= CHOICE {
* none [0] NULL,
* ip-address [1] OCTET STRING,
* -- 4 octets for B/IP or 16 octets for B/IPv6
* name [2] CharacterString
* -- Internet host name (see RFC 1123)
* }
* port [1] Unsigned16
* }
*
* @param apdu - the APDU buffer, or NULL for length
* @param address - IP address and port number
* @return length of the encoded APDU buffer
*/
int host_n_port_encode(uint8_t *apdu,
BACNET_HOST_N_PORT *address)
{
int len = 0;
int apdu_len = 0;
uint8_t *apdu_offset = NULL;
if (address) {
/* host [0] BACnetHostAddress - opening */
len = encode_opening_tag(apdu, 0);
apdu_len += len;
if (address->host_ip_address) {
/* CHOICE - ip-address [1] OCTET STRING */
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_context_octet_string(apdu_offset, 1, &address->host.ip_address);
apdu_len += len;
} else if (address->host_name) {
/* CHOICE - name [2] CharacterString */
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_context_character_string(apdu_offset, 1,
&address->host.name);
apdu_len += len;
} else {
/* none */
}
/* host [0] BACnetHostAddress - closing */
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_closing_tag(apdu_offset, 0);
apdu_len += len;
/* port [1] Unsigned16 */
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_context_unsigned(
apdu_offset, 1, address->port);
apdu_len += len;
}
return apdu_len;
}
/**
* @brief Encode a BACnetHostNPort complex data type
* @param apdu - the APDU buffer
* @param tag_number - the APDU buffer size
* @param address - IP address and port number
* @return length of the APDU buffer, or 0 if not able to encode
*/
int host_n_port_context_encode(
uint8_t * apdu,
uint8_t tag_number,
BACNET_HOST_N_PORT *address)
{
int len = 0;
int apdu_len = 0;
uint8_t *apdu_offset = NULL;
if (address) {
apdu_offset = apdu;
len = encode_opening_tag(apdu_offset, tag_number);
apdu_len += len;
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = host_n_port_encode(apdu_offset, address);
apdu_len += len;
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_closing_tag(apdu_offset, tag_number);
apdu_len += len;
}
return apdu_len;
}
/**
* @brief Decode the BACnetHostNPort complex data
*
* BACnetHostNPort ::= SEQUENCE {
* host [0] BACnetHostAddress,
* BACnetHostAddress ::= CHOICE {
* BACnetHostAddress ::= CHOICE {
* none [0] NULL,
* ip-address [1] OCTET STRING,
* -- 4 octets for B/IP or 16 octets for B/IPv6
* name [2] CharacterString
* -- Internet host name (see RFC 1123)
* }
* port [1] Unsigned16
* }
*
* @param apdu - the APDU buffer
* @param apdu_len - the APDU buffer length
* @param ip_address - IP address and port number
* @return length of the APDU buffer decoded, or ERROR, REJECT, or ABORT
*/
int host_n_port_decode(uint8_t *apdu,
uint16_t apdu_len,
BACNET_ERROR_CODE *error_code,
BACNET_HOST_N_PORT *address)
{
int len = 0;
BACNET_OCTET_STRING octet_string = { 0 };
BACNET_CHARACTER_STRING char_string = { 0 };
uint8_t tag_number = 0;
uint32_t len_value_type = 0;
BACNET_UNSIGNED_INTEGER unsigned_value = 0;
/* default reject code */
if (error_code) {
*error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER;
}
/* check for value pointers */
if ((apdu_len == 0) || (!apdu)) {
return BACNET_STATUS_REJECT;
}
/* host [0] BACnetHostAddress - opening */
if (!decode_is_opening_tag_number(&apdu[len++], 0)) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value_type);
if (tag_number == 0) {
/* CHOICE - none [0] NULL */
address->host_ip_address = false;
address->host_name = false;
} else if (tag_number == 1) {
/* CHOICE - ip-address [1] OCTET STRING */
address->host_ip_address = true;
address->host_name = false;
len += decode_octet_string(&apdu[len], len_value_type,
&octet_string);
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
(void)octetstring_copy(&address->host.ip_address,
&octet_string);
} else if (tag_number == 2) {
address->host_ip_address = false;
address->host_name = true;
len += decode_character_string(&apdu[len], len_value_type,
&char_string);
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
(void)characterstring_copy(&address->host.name,
&char_string);
} else {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
/* host [0] BACnetHostAddress - closing */
if (!decode_is_closing_tag_number(&apdu[len++], 0)) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
/* port [1] Unsigned16 */
len += decode_tag_number_and_value(
&apdu[len], &tag_number, &len_value_type);
if (tag_number != 1) {
if (error_code) {
*error_code = ERROR_CODE_REJECT_INVALID_TAG;
}
return BACNET_STATUS_REJECT;
}
len += decode_unsigned(&apdu[len], len_value_type, &unsigned_value);
if (len > apdu_len) {
return BACNET_STATUS_REJECT;
}
if (unsigned_value <= UINT16_MAX) {
address->port = unsigned_value;
} else {
if (error_code) {
*error_code = ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE;
}
return BACNET_STATUS_REJECT;
}
return apdu_len;
}
/**
* @brief Copy the BACnetHostNPort complex data from src to dst
* @param dst - destination structure
* @param src - source structure
* @return true if successfully copied
*/
bool host_n_port_copy(
BACNET_HOST_N_PORT * dst,
BACNET_HOST_N_PORT * src)
{
bool status = false;
if (dst && src) {
dst->host_ip_address = src->host_ip_address;
dst->host_name = src->host_name;
if (src->host_ip_address) {
status = octetstring_copy(
&dst->host.ip_address,
&src->host.ip_address);
} else if (src->host_name) {
status = characterstring_copy(
&dst->host.name,
&src->host.name);
} else {
status = true;
}
dst->port = src->port;
}
return status;
}
/**
* @brief Compare the BACnetHostNPort complex data of src and dst
* @param host1 - host 1 structure
* @param host2 - host 2 structure
* @return true if successfully copied
*/
bool host_n_port_same(
BACNET_HOST_N_PORT * host1,
BACNET_HOST_N_PORT * host2)
{
bool status = false;
if (host1 && host2) {
if ((host1->host_ip_address == host2->host_ip_address) &&
(host1->host_name == host2->host_name)) {
if (host1->host_ip_address) {
status = octetstring_value_same(
&host1->host.ip_address,
&host2->host.ip_address);
} else if (host1->host_name) {
status = characterstring_same(
&host1->host.name,
&host2->host.name);
} else {
status = true;
}
if (status) {
if (host1->port != host2->port) {
status = false;
}
}
}
}
return status;
}
+74
View File
@@ -0,0 +1,74 @@
/**
* @file
* @brief API for BACnetHostNPort complex data type encode and decode
* @author Steve Karg <skarg@users.sourceforge.net>
* @date May 2022
* @section LICENSE
*
* Copyright (C) 2022 Steve Karg <skarg@users.sourceforge.net>
*
* SPDX-License-Identifier: MIT
*/
#ifndef BACNET_HOST_N_PORT_H
#define BACNET_HOST_N_PORT_H
#include <stdint.h>
#include <stdbool.h>
#include "bacnet/bacnet_stack_exports.h"
#include "bacnet/bacenum.h"
#include "bacnet/bacstr.h"
#include "bacnet/datalink/bvlc.h"
/**
* BACnetHostNPort ::= SEQUENCE {
* host [0] BACnetHostAddress,
* BACnetHostAddress ::= CHOICE {
* none [0] NULL,
* ip-address [1] OCTET STRING,
* name [2] CharacterString
* }
* port [1] Unsigned16
* }
*/
typedef struct BACnetHostNPort {
bool host_ip_address:1;
bool host_name:1;
union BACnetHostAddress {
/* none = host_ip_address AND host_name are FALSE */
BACNET_OCTET_STRING ip_address;
BACNET_CHARACTER_STRING name;
} host;
uint16_t port;
} BACNET_HOST_N_PORT;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
int host_n_port_encode(
uint8_t * apdu,
BACNET_HOST_N_PORT *address);
BACNET_STACK_EXPORT
int host_n_port_context_encode(
uint8_t * apdu,
uint8_t tag_number,
BACNET_HOST_N_PORT *address);
BACNET_STACK_EXPORT
int host_n_port_decode(uint8_t *apdu,
uint16_t apdu_len,
BACNET_ERROR_CODE *error_code,
BACNET_HOST_N_PORT *address);
BACNET_STACK_EXPORT
bool host_n_port_copy(
BACNET_HOST_N_PORT * dst,
BACNET_HOST_N_PORT * src);
BACNET_STACK_EXPORT
bool host_n_port_same(
BACNET_HOST_N_PORT * dst,
BACNET_HOST_N_PORT * src);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+49 -100
View File
@@ -50,44 +50,58 @@
/** /**
* Encodes into bytes from the lighting-command structure * Encodes into bytes from the lighting-command structure
* *
* @param apdu - buffer to hold the bytes * @param apdu - buffer to hold the bytes, or null for length
* @param value - lighting command value to encode * @param value - lighting command value to encode
* *
* @return number of bytes encoded, or 0 if unable to encode. * @return number of bytes encoded
*/ */
int lighting_command_encode(uint8_t *apdu, BACNET_LIGHTING_COMMAND *data) int lighting_command_encode(uint8_t *apdu, BACNET_LIGHTING_COMMAND *data)
{ {
int apdu_len = 0; /* total length of the apdu, return value */ int apdu_len = 0; /* total length of the apdu, return value */
int len = 0; /* total length of the apdu, return value */ int len = 0; /* total length of the apdu, return value */
uint8_t *apdu_offset = NULL;
if (apdu) { len = encode_context_enumerated(apdu, 0, data->operation);
len = encode_context_enumerated(&apdu[apdu_len], 0, data->operation); apdu_len += len;
/* optional target-level */
if (data->use_target_level) {
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
len = encode_context_real(apdu_offset, 1, data->target_level);
apdu_len += len; apdu_len += len;
/* optional target-level */ }
if (data->use_target_level) { /* optional ramp-rate */
len = encode_context_real(&apdu[apdu_len], 1, data->target_level); if (data->use_ramp_rate) {
apdu_len += len; if (apdu) {
apdu_offset = &apdu[apdu_len];
} }
/* optional ramp-rate */ len = encode_context_real(apdu_offset, 2, data->ramp_rate);
if (data->use_ramp_rate) { apdu_len += len;
len = encode_context_real(&apdu[apdu_len], 2, data->ramp_rate); }
apdu_len += len; /* optional step increment */
if (data->use_step_increment) {
if (apdu) {
apdu_offset = &apdu[apdu_len];
} }
/* optional step increment */ len = encode_context_real(apdu_offset, 3, data->step_increment);
if (data->use_step_increment) { apdu_len += len;
len = encode_context_real(&apdu[apdu_len], 3, data->step_increment); }
apdu_len += len; /* optional fade time */
if (data->use_fade_time) {
if (apdu) {
apdu_offset = &apdu[apdu_len];
} }
/* optional fade time */ len = encode_context_unsigned(apdu_offset, 4, data->fade_time);
if (data->use_fade_time) { apdu_len += len;
len = encode_context_unsigned(&apdu[apdu_len], 4, data->fade_time); }
apdu_len += len; /* optional priority */
} if (data->use_priority) {
/* optional priority */ if (apdu) {
if (data->use_priority) { apdu_offset = &apdu[apdu_len];
len = encode_context_unsigned(&apdu[apdu_len], 5, data->priority);
apdu_len += len;
} }
len = encode_context_unsigned(apdu_offset, 5, data->priority);
apdu_len += len;
} }
return apdu_len; return apdu_len;
@@ -107,10 +121,17 @@ int lighting_command_encode_context(
uint8_t *apdu, uint8_t tag_number, BACNET_LIGHTING_COMMAND *value) uint8_t *apdu, uint8_t tag_number, BACNET_LIGHTING_COMMAND *value)
{ {
int apdu_len = 0; int apdu_len = 0;
uint8_t *apdu_offset = NULL;
apdu_len += encode_opening_tag(&apdu[apdu_len], tag_number); apdu_len += encode_opening_tag(apdu, tag_number);
apdu_len += lighting_command_encode(&apdu[apdu_len], value); if (apdu) {
apdu_len += encode_closing_tag(&apdu[apdu_len], tag_number); apdu_offset = &apdu[apdu_len];
}
apdu_len += lighting_command_encode(apdu_offset, value);
if (apdu) {
apdu_offset = &apdu[apdu_len];
}
apdu_len += encode_closing_tag(apdu_offset, tag_number);
return apdu_len; return apdu_len;
} }
@@ -292,75 +313,3 @@ bool lighting_command_same(
return status; return status;
} }
#ifdef TEST_LIGHTING_COMMAND
#include <assert.h>
#include <string.h>
#include "ctest.h"
static void testBACnetLightingCommand(Test *pTest, BACNET_LIGHTING_COMMAND *data)
{
bool status = false;
BACNET_LIGHTING_COMMAND test_data;
int len, apdu_len;
uint8_t apdu[MAX_APDU] = { 0 };
status = lighting_command_copy(&test_data, NULL);
ct_test(pTest, status == false);
status = lighting_command_copy(NULL, data);
ct_test(pTest, status == false);
status = lighting_command_copy(&test_data, data);
ct_test(pTest, status == true);
status = lighting_command_same(&test_data, data);
ct_test(pTest, status == true);
len = lighting_command_encode(apdu, data);
apdu_len = lighting_command_decode(apdu, sizeof(apdu), &test_data);
ct_test(pTest, len > 0);
ct_test(pTest, apdu_len > 0);
status = lighting_command_same(&test_data, data);
}
static void testBACnetLightingCommandAll(Test *pTest)
{
BACNET_LIGHTING_COMMAND data;
data.operation = BACNET_LIGHTS_NONE;
data.use_target_level = false;
data.use_ramp_rate = false;
data.use_step_increment = false;
data.use_fade_time = false;
data.use_priority = false;
data.target_level = 0.0;
data.ramp_rate = 100.0;
data.step_increment = 1.0;
data.fade_time = 100;
data.priority = 1;
testBACnetLightingCommand(pTest, &data);
data.operation = BACNET_LIGHTS_STOP;
data.use_target_level = true;
data.use_ramp_rate = true;
data.use_step_increment = true;
data.use_fade_time = true;
data.use_priority = true;
testBACnetLightingCommand(pTest, &data);
}
int main(void)
{
Test *pTest;
bool rc;
pTest = ct_create("BACnet Lighting Command", NULL);
/* individual tests */
rc = ct_addTestFunction(pTest, testBACnetLightingCommandAll);
assert(rc);
ct_setStream(pTest, stdout);
ct_run(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif
+2 -1
View File
@@ -24,7 +24,7 @@ add_compile_definitions(
BIG_ENDIAN=0 BIG_ENDIAN=0
CONFIG_ZTEST=1 CONFIG_ZTEST=1
PRINT_ENABLED=1 PRINT_ENABLED=1
BACAPP_HOST_N_PORT=1 BACAPP_ALL=1
) )
include_directories( include_directories(
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/datalink/bvlc.c ${SRC_DIR}/bacnet/datalink/bvlc.c
+217 -72
View File
@@ -13,6 +13,51 @@
#include <ztest.h> #include <ztest.h>
#include <bacnet/bacdcode.h> #include <bacnet/bacdcode.h>
#include <bacnet/bacapp.h> #include <bacnet/bacapp.h>
#include <bacnet/bactext.h>
static const BACNET_APPLICATION_TAG tag_list[] = {
BACNET_APPLICATION_TAG_NULL,
#if defined(BACAPP_BOOLEAN)
BACNET_APPLICATION_TAG_BOOLEAN,
#endif
#if defined(BACAPP_UNSIGNED)
BACNET_APPLICATION_TAG_UNSIGNED_INT,
#endif
#if defined(BACAPP_SIGNED)
BACNET_APPLICATION_TAG_SIGNED_INT,
#endif
#if defined(BACAPP_REAL)
BACNET_APPLICATION_TAG_REAL,
#endif
#if defined(BACAPP_DOUBLE)
BACNET_APPLICATION_TAG_DOUBLE,
#endif
#if defined(BACAPP_OCTET_STRING)
BACNET_APPLICATION_TAG_OCTET_STRING,
#endif
#if defined(BACAPP_CHARACTER_STRING)
BACNET_APPLICATION_TAG_CHARACTER_STRING,
#endif
#if defined(BACAPP_BIT_STRING)
BACNET_APPLICATION_TAG_BIT_STRING,
#endif
#if defined(BACAPP_ENUMERATED)
BACNET_APPLICATION_TAG_ENUMERATED,
#endif
#if defined(BACAPP_DATE)
BACNET_APPLICATION_TAG_DATE,
#endif
#if defined(BACAPP_TIME)
BACNET_APPLICATION_TAG_TIME,
#endif
#if defined(BACAPP_OBJECT_ID)
BACNET_APPLICATION_TAG_OBJECT_ID,
#endif
#if defined(BACAPP_TYPES_EXTRA)
BACNET_APPLICATION_TAG_LIGHTING_COMMAND,
BACNET_APPLICATION_TAG_HOST_N_PORT,
#endif
};
/** /**
* @addtogroup bacnet_tests * @addtogroup bacnet_tests
@@ -103,57 +148,13 @@ static void test_bacapp_copy(void)
memset(&src_value, 0xAA, sizeof(src_value)); memset(&src_value, 0xAA, sizeof(src_value));
memset(&dest_value, 0, sizeof(dest_value)); memset(&dest_value, 0, sizeof(dest_value));
zassert_false(bacapp_copy(&dest_value, &src_value), NULL); zassert_true(bacapp_copy(&dest_value, &src_value), NULL);
zassert_equal(dest_value.tag, src_value.tag, NULL); zassert_equal(dest_value.tag, src_value.tag, NULL);
zassert_equal(dest_value.next, src_value.next, NULL); zassert_equal(dest_value.next, src_value.next, NULL);
const BACNET_APPLICATION_TAG tags[] = { for (i = 0; i < sizeof(tag_list)/sizeof(tag_list[0]); ++i) {
BACNET_APPLICATION_TAG_NULL, BACNET_APPLICATION_TAG tag = tag_list[i];
#if defined(BACAPP_BOOLEAN) bool result;
BACNET_APPLICATION_TAG_BOOLEAN,
#endif
#if defined(BACAPP_UNSIGNED)
BACNET_APPLICATION_TAG_UNSIGNED_INT,
#endif
#if defined(BACAPP_SIGNED)
BACNET_APPLICATION_TAG_SIGNED_INT,
#endif
#if defined(BACAPP_REAL)
BACNET_APPLICATION_TAG_REAL,
#endif
#if defined(BACAPP_DOUBLE)
BACNET_APPLICATION_TAG_DOUBLE,
#endif
#if defined(BACAPP_OCTET_STRING)
BACNET_APPLICATION_TAG_OCTET_STRING,
#endif
#if defined(BACAPP_CHARACTER_STRING)
BACNET_APPLICATION_TAG_CHARACTER_STRING,
#endif
#if defined(BACAPP_BIT_STRING)
BACNET_APPLICATION_TAG_BIT_STRING,
#endif
#if defined(BACAPP_ENUMERATED)
BACNET_APPLICATION_TAG_ENUMERATED,
#endif
#if defined(BACAPP_DATE)
BACNET_APPLICATION_TAG_DATE,
#endif
#if defined(BACAPP_TIME)
BACNET_APPLICATION_TAG_TIME,
#endif
#if defined(BACAPP_OBJECT_ID)
BACNET_APPLICATION_TAG_OBJECT_ID,
#endif
#if defined(BACAPP_LIGHTING_COMMAND)
BACNET_APPLICATION_TAG_LIGHTING_COMMAND,
#endif
#if defined(BACAPP_HOST_N_PORT)
BACNET_APPLICATION_TAG_HOST_N_PORT,
#endif
};
for (i = 0; i < sizeof(tags)/sizeof(tags[0]); ++i) {
BACNET_APPLICATION_TAG tag = tags[i];
bool expected_result = true; bool expected_result = true;
#if ! defined(BACAPP_NULL) #if ! defined(BACAPP_NULL)
@@ -163,11 +164,18 @@ static void test_bacapp_copy(void)
#endif #endif
memset(&src_value, 0, sizeof(src_value)); memset(&src_value, 0, sizeof(src_value));
src_value.next = NULL;
memset(&dest_value, 0xBB, sizeof(dest_value)); memset(&dest_value, 0xBB, sizeof(dest_value));
dest_value.next = NULL;
src_value.tag = tag; src_value.tag = tag;
src_value.next = (struct BACnet_Application_Data_Value *)(((uint32_t)tags[i]) << 8); result = bacapp_copy(&dest_value, &src_value);
zassert_equal(bacapp_copy(&dest_value, &src_value), expected_result, NULL); zassert_equal(result, expected_result, NULL);
zassert_true(bacapp_same_value(&dest_value, &src_value), NULL); result = bacapp_same_value(&dest_value, &src_value);
if (!result) {
printf("bacapp: same-value of tag=%s[%u]\n",
bactext_application_tag_name(tag), tag);
}
zassert_true(result, NULL);
zassert_equal(dest_value.next, src_value.next, NULL); zassert_equal(dest_value.next, src_value.next, NULL);
} }
} }
@@ -428,7 +436,7 @@ static void test_bacapp_same_value(void)
memset(&test_value, 0, sizeof(test_value)); memset(&test_value, 0, sizeof(test_value));
test_value.tag = BACNET_APPLICATION_TAG_LIGHTING_COMMAND; test_value.tag = BACNET_APPLICATION_TAG_LIGHTING_COMMAND;
value = test_value; /* Struct copy */ value = test_value; /* Struct copy */
#if defined(BACAPP_LIGHTING_COMMAND) #if defined(BACAPP_TYPES_EXTRA)
zassert_true(bacapp_same_value(&value, &test_value), NULL); zassert_true(bacapp_same_value(&value, &test_value), NULL);
#else #else
zassert_false(bacapp_same_value(&value, &test_value), NULL); zassert_false(bacapp_same_value(&value, &test_value), NULL);
@@ -528,7 +536,6 @@ static void testBACnetApplicationData_Safe(void)
break; break;
} }
single_length_segment = bacapp_encode_data(&apdu[len], &input_value[i]); single_length_segment = bacapp_encode_data(&apdu[len], &input_value[i]);
;
zassert_true(single_length_segment > 0, NULL); zassert_true(single_length_segment > 0, NULL);
/* len_segment is accumulated length */ /* len_segment is accumulated length */
if (i == 0) { if (i == 0) {
@@ -724,10 +731,38 @@ static bool verifyBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *valu
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
int apdu_len = 0; int apdu_len = 0;
BACNET_APPLICATION_DATA_VALUE test_value; int null_len = 0;
BACNET_APPLICATION_DATA_VALUE test_value = { 0 };
apdu_len = bacapp_encode_application_data(&apdu[0], value); apdu_len = bacapp_encode_application_data(&apdu[0], value);
bacapp_decode_application_data(&apdu[0], apdu_len, &test_value); zassert_true(apdu_len > 0, NULL);
null_len = bacapp_encode_application_data(NULL, value);
zassert_equal(apdu_len, null_len, NULL);
apdu_len = bacapp_decode_application_data(&apdu[0], apdu_len, &test_value);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
return bacapp_same_value(value, &test_value);
}
/**
* @brief Test
*/
static bool verifyBACnetComplexDataValue(
BACNET_APPLICATION_DATA_VALUE *value,
BACNET_PROPERTY_ID prop)
{
uint8_t apdu[480] = { 0 };
int apdu_len = 0;
int null_len = 0;
BACNET_APPLICATION_DATA_VALUE test_value = { 0 };
apdu_len = bacapp_encode_application_data(&apdu[0], value);
zassert_true(apdu_len > 0, NULL);
null_len = bacapp_encode_application_data(NULL, value);
zassert_equal(apdu_len, null_len, NULL);
apdu_len = bacapp_decode_generic_property(&apdu[0], apdu_len,
&test_value, prop);
zassert_true(apdu_len != BACNET_STATUS_ERROR, NULL);
return bacapp_same_value(value, &test_value); return bacapp_same_value(value, &test_value);
} }
@@ -737,7 +772,7 @@ static bool verifyBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *valu
*/ */
static void testBACnetApplicationData(void) static void testBACnetApplicationData(void)
{ {
BACNET_APPLICATION_DATA_VALUE value; BACNET_APPLICATION_DATA_VALUE value = { 0 };
bool status = false; bool status = false;
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
@@ -816,6 +851,64 @@ static void testBACnetApplicationData(void)
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL); zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_DOUBLE, "0.0", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_DOUBLE, "-1.0", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_DOUBLE, "1.0", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_DOUBLE, "3.14159", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_DOUBLE, "-3.14159", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "1234567890ABCDEF", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "12-34-56-78-90-AB-CD-EF", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "12 34 56 78 90 AB CD EF", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
/* test empty string */
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
/* test empty string */
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_CHARACTER_STRING, "", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_BIT_STRING, "1011010010011111", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_BIT_STRING, "111100001111", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_ENUMERATED, "0", &value); BACNET_APPLICATION_TAG_ENUMERATED, "0", &value);
zassert_true(status, NULL); zassert_true(status, NULL);
@@ -906,35 +999,85 @@ static void testBACnetApplicationData(void)
zassert_true(verifyBACnetApplicationDataValue(&value), NULL); zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value); BACNET_APPLICATION_TAG_OBJECT_ID, "8:4194303", &value);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL); zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
/* test empty string */
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_CHARACTER_STRING, "", &value); BACNET_APPLICATION_TAG_OBJECT_ID, "0:0", &value);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL); zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "1234567890ABCDEF", &value); BACNET_APPLICATION_TAG_HOST_N_PORT, "192", &value);
zassert_true(status, NULL); zassert_false(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "12-34-56-78-90-AB-CD-EF", &value); BACNET_APPLICATION_TAG_HOST_N_PORT, "192.168.1.1", &value);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
status = bacapp_parse_application_data( status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_OCTET_STRING, "12 34 56 78 90 AB CD EF", &value); BACNET_APPLICATION_TAG_HOST_N_PORT, "192.168.1.1:47808", &value);
zassert_true(status, NULL); zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL); status = verifyBACnetComplexDataValue(&value, PROP_FD_BBMD_ADDRESS);
/* test empty string */ status = verifyBACnetComplexDataValue(&value,
status = bacapp_parse_application_data( PROP_BACNET_IP_GLOBAL_ADDRESS);
BACNET_APPLICATION_TAG_OCTET_STRING, "", &value);
zassert_true(status, NULL);
zassert_true(verifyBACnetApplicationDataValue(&value), NULL);
return; return;
} }
/**
* @brief Test
*/
static void test_bacapp_context_data(void)
{
const uint8_t context_tag_number = 1;
uint8_t apdu[480] = { 0 };
BACNET_APPLICATION_DATA_VALUE value = { 0 };
BACNET_APPLICATION_DATA_VALUE test_value = { 0 };
bool status = false;
int apdu_len, null_len, test_len;
unsigned i = 0;
for (i = 0; i < sizeof(tag_list)/sizeof(tag_list[0]); i++) {
BACNET_APPLICATION_TAG tag = tag_list[i];
value.tag = tag;
null_len = bacapp_encode_context_data_value(NULL,
context_tag_number, &value);
apdu_len = bacapp_encode_context_data_value(apdu,
context_tag_number, &value);
if (apdu_len != null_len) {
printf("bacapp: NULL len=%d != APDU len=%d for tag=%s",
null_len, apdu_len, bactext_application_tag_name(tag));
}
zassert_equal(apdu_len, null_len, NULL);
}
}
/**
* @brief Test
*/
static void test_bacapp_sprintf_data(void)
{
BACNET_APPLICATION_DATA_VALUE value = { 0 };
BACNET_OBJECT_PROPERTY_VALUE object_value = { 0 };
bool status = false;
int str_len = 0;
object_value.object_type = OBJECT_DEVICE;
object_value.object_instance = 0;
object_value.object_property = PROP_DAYLIGHT_SAVINGS_STATUS;
object_value.array_index = BACNET_ARRAY_ALL;
object_value.value = &value;
status = bacapp_parse_application_data(
BACNET_APPLICATION_TAG_NULL, NULL, &value);
zassert_true(status, NULL);
str_len = bacapp_snprintf_value(NULL, 0, &object_value);
if (str_len > 0) {
char str[str_len+1];
bacapp_snprintf_value(str, str_len+1, &object_value);
zassert_mem_equal(str, "Null", str_len, NULL);
}
}
/** /**
* @} * @}
*/ */
@@ -951,7 +1094,9 @@ void test_main(void)
ztest_unit_test(test_bacapp_same_value), ztest_unit_test(test_bacapp_same_value),
ztest_unit_test(testBACnetApplicationData), ztest_unit_test(testBACnetApplicationData),
ztest_unit_test(testBACnetApplicationDataLength), ztest_unit_test(testBACnetApplicationDataLength),
ztest_unit_test(testBACnetApplicationData_Safe) ztest_unit_test(testBACnetApplicationData_Safe),
ztest_unit_test(test_bacapp_context_data),
ztest_unit_test(test_bacapp_sprintf_data)
); );
ztest_run_test_suite(bacapp_tests); ztest_run_test_suite(bacapp_tests);
+75 -22
View File
@@ -101,6 +101,8 @@ static void testBACDCodeTags(void)
len = encode_opening_tag(&apdu[0], tag_number); len = encode_opening_tag(&apdu[0], tag_number);
test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), 0); test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), 0);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
test_len = encode_opening_tag(NULL, tag_number);
zassert_equal(len, test_len, NULL);
len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value); len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value);
zassert_equal(value, 0, NULL); zassert_equal(value, 0, NULL);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
@@ -109,6 +111,8 @@ static void testBACDCodeTags(void)
zassert_false(IS_CLOSING_TAG(apdu[0]), NULL); zassert_false(IS_CLOSING_TAG(apdu[0]), NULL);
len = encode_closing_tag(&apdu[0], tag_number); len = encode_closing_tag(&apdu[0], tag_number);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
test_len = encode_closing_tag(NULL, tag_number);
zassert_equal(len, test_len, NULL);
len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value); len = decode_tag_number_and_value(&apdu[0], &test_tag_number, &value);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
zassert_equal(value, 0, NULL); zassert_equal(value, 0, NULL);
@@ -145,18 +149,20 @@ static void testBACDCodeEnumerated(void)
uint32_t value = 1; uint32_t value = 1;
uint32_t decoded_value = 0; uint32_t decoded_value = 0;
int i = 0, apdu_len = 0; int i = 0, apdu_len = 0;
int len = 0; int len = 0, null_len = 0;
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
for (i = 0; i < 31; i++) { for (i = 0; i < 31; i++) {
apdu_len = encode_application_enumerated(&array[0], value); apdu_len = encode_application_enumerated(&array[0], value);
null_len = encode_application_enumerated(NULL, value);
len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); len = decode_tag_number_and_value(&array[0], &tag_number, &len_value);
len += decode_enumerated(&array[len], len_value, &decoded_value); len += decode_enumerated(&array[len], len_value, &decoded_value);
zassert_equal(decoded_value, value, NULL); zassert_equal(decoded_value, value, NULL);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_ENUMERATED, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_ENUMERATED, NULL);
zassert_equal(len, apdu_len, NULL); zassert_equal(len, apdu_len, NULL);
zassert_equal(null_len, apdu_len, NULL);
/* encode back the value */ /* encode back the value */
encode_application_enumerated(&encoded_array[0], decoded_value); encode_application_enumerated(&encoded_array[0], decoded_value);
zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL); zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL);
@@ -169,10 +175,12 @@ static void testBACDCodeEnumerated(void)
zassert_false(IS_CONTEXT_SPECIFIC(apdu[0]), NULL); zassert_false(IS_CONTEXT_SPECIFIC(apdu[0]), NULL);
/* context specific encoding */ /* context specific encoding */
apdu_len = encode_context_enumerated(&apdu[0], 3, value); apdu_len = encode_context_enumerated(&apdu[0], 3, value);
null_len = encode_context_enumerated(NULL, 3, value);
zassert_true(IS_CONTEXT_SPECIFIC(apdu[0]), NULL); zassert_true(IS_CONTEXT_SPECIFIC(apdu[0]), NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL);
zassert_equal(len, 1, NULL); zassert_equal(len, 1, NULL);
zassert_equal(tag_number, 3, NULL); zassert_equal(tag_number, 3, NULL);
zassert_equal(null_len, apdu_len, NULL);
/* test the interesting values */ /* test the interesting values */
value = value << 1; value = value << 1;
} }
@@ -187,7 +195,7 @@ static void testBACDCodeReal(void)
float value = 42.123F; float value = 42.123F;
float decoded_value = 0.0F; float decoded_value = 0.0F;
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, apdu_len = 0; int len = 0, apdu_len = 0, null_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t long_value = 0; uint32_t long_value = 0;
@@ -199,7 +207,9 @@ static void testBACDCodeReal(void)
/* a real will take up 4 octects plus a one octet tag */ /* a real will take up 4 octects plus a one octet tag */
apdu_len = encode_application_real(&apdu[0], value); apdu_len = encode_application_real(&apdu[0], value);
null_len = encode_application_real(NULL, value);
zassert_equal(apdu_len, 5, NULL); zassert_equal(apdu_len, 5, NULL);
zassert_equal(apdu_len, null_len, NULL);
/* len tells us how many octets were used for encoding the value */ /* len tells us how many octets were used for encoding the value */
len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_REAL, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_REAL, NULL);
@@ -219,7 +229,7 @@ static void testBACDCodeDouble(void)
double value = 42.123; double value = 42.123;
double decoded_value = 0.0; double decoded_value = 0.0;
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
int len = 0, apdu_len = 0; int len = 0, apdu_len = 0, null_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t long_value = 0; uint32_t long_value = 0;
@@ -231,7 +241,9 @@ static void testBACDCodeDouble(void)
/* a real will take up 4 octects plus a one octet tag */ /* a real will take up 4 octects plus a one octet tag */
apdu_len = encode_application_double(&apdu[0], value); apdu_len = encode_application_double(&apdu[0], value);
null_len = encode_application_double(NULL, value);
zassert_equal(apdu_len, 10, NULL); zassert_equal(apdu_len, 10, NULL);
zassert_equal(apdu_len, null_len, NULL);
/* len tells us how many octets were used for encoding the value */ /* len tells us how many octets were used for encoding the value */
len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &long_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_DOUBLE, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_DOUBLE, NULL);
@@ -249,7 +261,7 @@ static void verifyBACDCodeUnsignedValue(BACNET_UNSIGNED_INTEGER value)
uint8_t array[5] = { 0 }; uint8_t array[5] = { 0 };
uint8_t encoded_array[5] = { 0 }; uint8_t encoded_array[5] = { 0 };
BACNET_UNSIGNED_INTEGER decoded_value = 0; BACNET_UNSIGNED_INTEGER decoded_value = 0;
int len; int len = 0, null_len = 0;
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
@@ -267,7 +279,9 @@ static void verifyBACDCodeUnsignedValue(BACNET_UNSIGNED_INTEGER value)
zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL); zassert_equal(memcmp(&array[0], &encoded_array[0], sizeof(array)), 0, NULL);
/* an unsigned will take up to 4 octects */ /* an unsigned will take up to 4 octects */
/* plus a one octet for the tag */ /* plus a one octet for the tag */
encode_application_unsigned(&apdu[0], value); len = encode_application_unsigned(&apdu[0], value);
null_len = encode_application_unsigned(NULL, value);
zassert_equal(len, null_len, NULL);
/* apdu_len varies... */ /* apdu_len varies... */
len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL);
zassert_equal(len, 1, NULL); zassert_equal(len, 1, NULL);
@@ -298,15 +312,23 @@ static void testBACDCodeUnsigned(void)
static void testBACnetUnsigned(void) static void testBACnetUnsigned(void)
{ {
uint8_t apdu[32] = { 0 }; uint8_t apdu[32] = { 0 };
BACNET_UNSIGNED_INTEGER value = 0, test_value = 0; BACNET_UNSIGNED_INTEGER value = 1, test_value = 0;
int len = 0, test_len = 0; int len = 0, test_len = 0, null_len = 0;
unsigned i;
#ifdef UINT64_MAX
const unsigned max_bits = 64;
#else
const unsigned max_bits = 32;
#endif
for (value = 0; value == BACNET_UNSIGNED_INTEGER_MAX; for (i = 0; i < max_bits; i++) {
value = (value << 8) | 0xff) {
len = encode_bacnet_unsigned(&apdu[0], value); len = encode_bacnet_unsigned(&apdu[0], value);
null_len = encode_bacnet_unsigned(NULL, value);
test_len = decode_unsigned(&apdu[0], len, &test_value); test_len = decode_unsigned(&apdu[0], len, &test_value);
zassert_equal(len, null_len, NULL);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
value |= (value << 1);
} }
} }
@@ -315,13 +337,15 @@ static void testBACDCodeSignedValue(int32_t value)
uint8_t array[5] = { 0 }; uint8_t array[5] = { 0 };
uint8_t encoded_array[5] = { 0 }; uint8_t encoded_array[5] = { 0 };
int32_t decoded_value = 0; int32_t decoded_value = 0;
int len = 0; int len = 0, null_len = 0;
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
int diff = 0; int diff = 0;
len = encode_application_signed(&array[0], value); len = encode_application_signed(&array[0], value);
null_len = encode_application_signed(NULL, value);
zassert_equal(null_len, len, NULL);
len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); len = decode_tag_number_and_value(&array[0], &tag_number, &len_value);
len = decode_signed(&array[len], len_value, &decoded_value); len = decode_signed(&array[len], len_value, &decoded_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL);
@@ -331,7 +355,9 @@ static void testBACDCodeSignedValue(int32_t value)
"value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value); "value=%ld decoded_value=%ld\n", (long)value, (long)decoded_value);
print_apdu(&array[0], sizeof(array)); print_apdu(&array[0], sizeof(array));
} }
encode_application_signed(&encoded_array[0], decoded_value); len = encode_application_signed(&encoded_array[0], decoded_value);
null_len = encode_application_signed(NULL, decoded_value);
zassert_equal(null_len, len, NULL);
diff = memcmp(&array[0], &encoded_array[0], sizeof(array)); diff = memcmp(&array[0], &encoded_array[0], sizeof(array));
zassert_equal(diff, 0, NULL); zassert_equal(diff, 0, NULL);
if (diff) { if (diff) {
@@ -342,7 +368,9 @@ static void testBACDCodeSignedValue(int32_t value)
} }
/* a signed int will take up to 4 octects */ /* a signed int will take up to 4 octects */
/* plus a one octet for the tag */ /* plus a one octet for the tag */
encode_application_signed(&apdu[0], value); len = encode_application_signed(&apdu[0], value);
null_len = encode_application_signed(NULL, value);
zassert_equal(null_len, len, NULL);
len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL); len = decode_tag_number_and_value(&apdu[0], &tag_number, NULL);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_SIGNED_INT, NULL);
zassert_false(IS_CONTEXT_SPECIFIC(apdu[0]), NULL); zassert_false(IS_CONTEXT_SPECIFIC(apdu[0]), NULL);
@@ -378,19 +406,28 @@ static void testBACnetSigned(void)
{ {
uint8_t apdu[32] = { 0 }; uint8_t apdu[32] = { 0 };
int32_t value = 0, test_value = 0; int32_t value = 0, test_value = 0;
int len = 0, test_len = 0; int len = 0, test_len = 0, null_len = 0;
unsigned i = 0;
for (value = -2147483647; value < 0; value += 127) { value = -2147483647;
for (i = 0; i < 32; i++) {
len = encode_bacnet_signed(&apdu[0], value); len = encode_bacnet_signed(&apdu[0], value);
null_len = encode_bacnet_signed(NULL, value);
test_len = decode_signed(&apdu[0], len, &test_value); test_len = decode_signed(&apdu[0], len, &test_value);
zassert_equal(len, null_len, NULL);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
value /= 2;
} }
for (value = 2147483647; value > 0; value -= 127) { value = 2147483647;
for (i = 0; i < 32; i++) {
len = encode_bacnet_signed(&apdu[0], value); len = encode_bacnet_signed(&apdu[0], value);
null_len = encode_bacnet_signed(NULL, value);
test_len = decode_signed(&apdu[0], len, &test_value); test_len = decode_signed(&apdu[0], len, &test_value);
zassert_equal(len, null_len, NULL);
zassert_equal(len, test_len, NULL); zassert_equal(len, test_len, NULL);
zassert_equal(value, test_value, NULL); zassert_equal(value, test_value, NULL);
value /= 2;
} }
} }
@@ -402,8 +439,7 @@ static void testBACDCodeOctetString(void)
BACNET_OCTET_STRING test_octet_string; BACNET_OCTET_STRING test_octet_string;
uint8_t test_value[MAX_APDU] = { "" }; uint8_t test_value[MAX_APDU] = { "" };
int i; /* for loop counter */ int i; /* for loop counter */
int apdu_len; int apdu_len = 0, len = 0, null_len = 0;
int len;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
bool status = false; bool status = false;
@@ -412,6 +448,8 @@ static void testBACDCodeOctetString(void)
status = octetstring_init(&octet_string, NULL, 0); status = octetstring_init(&octet_string, NULL, 0);
zassert_true(status, NULL); zassert_true(status, NULL);
apdu_len = encode_application_octet_string(&array[0], &octet_string); apdu_len = encode_application_octet_string(&array[0], &octet_string);
null_len = encode_application_octet_string(NULL, &octet_string);
zassert_equal(apdu_len, null_len, NULL);
len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); len = decode_tag_number_and_value(&array[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL);
len += decode_octet_string(&array[len], len_value, &test_octet_string); len += decode_octet_string(&array[len], len_value, &test_octet_string);
@@ -426,6 +464,8 @@ static void testBACDCodeOctetString(void)
zassert_true(status, NULL); zassert_true(status, NULL);
apdu_len = apdu_len =
encode_application_octet_string(&encoded_array[0], &octet_string); encode_application_octet_string(&encoded_array[0], &octet_string);
null_len = encode_application_octet_string(NULL, &octet_string);
zassert_equal(apdu_len, null_len, NULL);
len = decode_tag_number_and_value( len = decode_tag_number_and_value(
&encoded_array[0], &tag_number, &len_value); &encoded_array[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_OCTET_STRING, NULL);
@@ -454,8 +494,7 @@ static void testBACDCodeCharacterString(void)
BACNET_CHARACTER_STRING test_char_string; BACNET_CHARACTER_STRING test_char_string;
char test_value[MAX_APDU] = { "" }; char test_value[MAX_APDU] = { "" };
int i; /* for loop counter */ int i; /* for loop counter */
int apdu_len; int apdu_len = 0, len = 0, null_len = 0;
int len;
uint8_t tag_number = 0; uint8_t tag_number = 0;
uint32_t len_value = 0; uint32_t len_value = 0;
int diff = 0; /* for comparison */ int diff = 0; /* for comparison */
@@ -464,6 +503,8 @@ static void testBACDCodeCharacterString(void)
status = characterstring_init(&char_string, CHARACTER_ANSI_X34, NULL, 0); status = characterstring_init(&char_string, CHARACTER_ANSI_X34, NULL, 0);
zassert_true(status, NULL); zassert_true(status, NULL);
apdu_len = encode_application_character_string(&array[0], &char_string); apdu_len = encode_application_character_string(&array[0], &char_string);
null_len = encode_application_character_string(NULL, &char_string);
zassert_equal(apdu_len, null_len, NULL);
len = decode_tag_number_and_value(&array[0], &tag_number, &len_value); len = decode_tag_number_and_value(&array[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL);
len += decode_character_string(&array[len], len_value, &test_char_string); len += decode_character_string(&array[len], len_value, &test_char_string);
@@ -478,6 +519,8 @@ static void testBACDCodeCharacterString(void)
zassert_true(status, NULL); zassert_true(status, NULL);
apdu_len = encode_application_character_string( apdu_len = encode_application_character_string(
&encoded_array[0], &char_string); &encoded_array[0], &char_string);
null_len = encode_application_character_string(NULL, &char_string);
zassert_equal(apdu_len, null_len, NULL);
len = decode_tag_number_and_value( len = decode_tag_number_and_value(
&encoded_array[0], &tag_number, &len_value); &encoded_array[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_CHARACTER_STRING, NULL);
@@ -506,10 +549,12 @@ static void testBACDCodeObject(void)
BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_OUTPUT; BACNET_OBJECT_TYPE decoded_type = OBJECT_ANALOG_OUTPUT;
uint32_t instance = 123; uint32_t instance = 123;
uint32_t decoded_instance = 0; uint32_t decoded_instance = 0;
int len = 0; int apdu_len = 0, len = 0, null_len = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
encode_bacnet_object_id(&encoded_array[0], type, instance); apdu_len = encode_bacnet_object_id(&encoded_array[0], type, instance);
null_len = encode_bacnet_object_id(NULL, type, instance);
zassert_equal(apdu_len, null_len, NULL);
decode_object_id(&encoded_array[0], &decoded_type, &decoded_instance); decode_object_id(&encoded_array[0], &decoded_type, &decoded_instance);
zassert_equal(decoded_type, type, NULL); zassert_equal(decoded_type, type, NULL);
zassert_equal(decoded_instance, instance, NULL); zassert_equal(decoded_instance, instance, NULL);
@@ -520,6 +565,8 @@ static void testBACDCodeObject(void)
/* test application encoded */ /* test application encoded */
len = len =
encode_application_object_id(&encoded_array[0], type, instance); encode_application_object_id(&encoded_array[0], type, instance);
null_len = encode_application_object_id(NULL, type, instance);
zassert_equal(len, null_len, NULL);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
bacnet_object_id_application_decode( bacnet_object_id_application_decode(
&encoded_array[0], len, &decoded_type, &decoded_instance); &encoded_array[0], len, &decoded_type, &decoded_instance);
@@ -549,6 +596,8 @@ static void testBACDCodeObject(void)
len = encode_context_object_id( len = encode_context_object_id(
&encoded_array[0], tag_number, type, instance); &encoded_array[0], tag_number, type, instance);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
null_len = encode_context_object_id(NULL, tag_number, type, instance);
zassert_equal(len, null_len, NULL);
len = decode_context_object_id( len = decode_context_object_id(
&encoded_array[0], tag_number, &decoded_type, &decoded_instance); &encoded_array[0], tag_number, &decoded_type, &decoded_instance);
zassert_true(len > 0, NULL); zassert_true(len > 0, NULL);
@@ -588,7 +637,7 @@ static void testBACDCodeBitString(void)
uint8_t apdu[MAX_APDU] = { 0 }; uint8_t apdu[MAX_APDU] = { 0 };
uint32_t len_value = 0; uint32_t len_value = 0;
uint8_t tag_number = 0; uint8_t tag_number = 0;
int len = 0; int len = 0, null_len = 0;
bitstring_init(&bit_string); bitstring_init(&bit_string);
/* verify initialization */ /* verify initialization */
@@ -603,6 +652,8 @@ static void testBACDCodeBitString(void)
zassert_true(bitstring_bit(&bit_string, bit), NULL); zassert_true(bitstring_bit(&bit_string, bit), NULL);
/* encode */ /* encode */
len = encode_application_bitstring(&apdu[0], &bit_string); len = encode_application_bitstring(&apdu[0], &bit_string);
null_len = encode_application_bitstring(NULL, &bit_string);
zassert_equal(len, null_len, NULL);
/* decode */ /* decode */
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_BIT_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_BIT_STRING, NULL);
@@ -618,6 +669,8 @@ static void testBACDCodeBitString(void)
zassert_false(bitstring_bit(&bit_string, bit), NULL); zassert_false(bitstring_bit(&bit_string, bit), NULL);
/* encode */ /* encode */
len = encode_application_bitstring(&apdu[0], &bit_string); len = encode_application_bitstring(&apdu[0], &bit_string);
null_len = encode_application_bitstring(NULL, &bit_string);
zassert_equal(len, null_len, NULL);
/* decode */ /* decode */
len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value); len = decode_tag_number_and_value(&apdu[0], &tag_number, &len_value);
zassert_equal(tag_number, BACNET_APPLICATION_TAG_BIT_STRING, NULL); zassert_equal(tag_number, BACNET_APPLICATION_TAG_BIT_STRING, NULL);
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
# Test and test library files # Test and test library files
./src/main.c ./src/main.c
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
# Test and test library files # Test and test library files
./src/main.c ./src/main.c
@@ -44,6 +44,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
# Test and test library files # Test and test library files
@@ -48,6 +48,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/timestamp.c ${SRC_DIR}/bacnet/timestamp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -49,6 +49,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -48,6 +48,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/timestamp.c ${SRC_DIR}/bacnet/timestamp.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -79,6 +79,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/dcc.c ${SRC_DIR}/bacnet/dcc.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/npdu.c ${SRC_DIR}/bacnet/npdu.c
@@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
./stubs.c ./stubs.c
@@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/proplist.c ${SRC_DIR}/bacnet/proplist.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/wp.c ${SRC_DIR}/bacnet/wp.c
# Test and test library files # Test and test library files
+1
View File
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
# Test and test library files # Test and test library files
+3
View File
@@ -38,8 +38,11 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/bacint.c ${SRC_DIR}/bacnet/bacint.c
${SRC_DIR}/bacnet/bacreal.c ${SRC_DIR}/bacnet/bacreal.c
${SRC_DIR}/bacnet/bacstr.c ${SRC_DIR}/bacnet/bacstr.c
${SRC_DIR}/bacnet/bactext.c
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/indtext.c
# Test and test library files # Test and test library files
./src/main.c ./src/main.c
${ZTST_DIR}/ztest_mock.c ${ZTST_DIR}/ztest_mock.c
+6 -4
View File
@@ -819,12 +819,11 @@ static void test_BVLC_Address_Get_Set(void)
static void test_BVLC_BBMD_Address(void) static void test_BVLC_BBMD_Address(void)
{ {
uint8_t apdu[480] = { 0 }; uint8_t apdu[480] = { 0 };
uint16_t apdu_len = 0; int apdu_len = 0;
int16_t test_apdu_len = 0; int test_apdu_len = 0;
uint16_t i = 0;
BACNET_IP_ADDRESS bbmd_address; BACNET_IP_ADDRESS bbmd_address;
BACNET_IP_ADDRESS test_bbmd_address; BACNET_IP_ADDRESS test_bbmd_address;
BACNET_ERROR_CODE error_code = 0; BACNET_ERROR_CODE error_code = ERROR_CODE_SUCCESS;
bool status = false; bool status = false;
status = bvlc_address_port_from_ascii( status = bvlc_address_port_from_ascii(
@@ -835,6 +834,9 @@ static void test_BVLC_BBMD_Address(void)
zassert_not_equal(apdu_len, 0, NULL); zassert_not_equal(apdu_len, 0, NULL);
test_apdu_len = bvlc_foreign_device_bbmd_host_address_decode(apdu, test_apdu_len = bvlc_foreign_device_bbmd_host_address_decode(apdu,
apdu_len, &error_code, &test_bbmd_address); apdu_len, &error_code, &test_bbmd_address);
if (test_apdu_len < 0) {
printf("BVLC: error-code=%s\n", bactext_error_code_name(error_code));
}
zassert_not_equal(test_apdu_len, 0, NULL); zassert_not_equal(test_apdu_len, 0, NULL);
zassert_not_equal(test_apdu_len, BACNET_STATUS_ERROR, NULL); zassert_not_equal(test_apdu_len, BACNET_STATUS_ERROR, NULL);
zassert_not_equal(test_apdu_len, BACNET_STATUS_ABORT, NULL); zassert_not_equal(test_apdu_len, BACNET_STATUS_ABORT, NULL);
+1
View File
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/timestamp.c ${SRC_DIR}/bacnet/timestamp.c
+1
View File
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/timestamp.c ${SRC_DIR}/bacnet/timestamp.c
+1
View File
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
# Test and test library files # Test and test library files
+1
View File
@@ -46,6 +46,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
# Test and test library files # Test and test library files
./src/main.c ./src/main.c
+1
View File
@@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/memcopy.c ${SRC_DIR}/bacnet/memcopy.c
# Test and test library files # Test and test library files
+1
View File
@@ -47,6 +47,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
# Test and test library files # Test and test library files
./src/main.c ./src/main.c
+1
View File
@@ -45,6 +45,7 @@ add_executable(${PROJECT_NAME}
${SRC_DIR}/bacnet/basic/sys/bigend.c ${SRC_DIR}/bacnet/basic/sys/bigend.c
${SRC_DIR}/bacnet/datetime.c ${SRC_DIR}/bacnet/datetime.c
${SRC_DIR}/bacnet/basic/sys/days.c ${SRC_DIR}/bacnet/basic/sys/days.c
${SRC_DIR}/bacnet/hostnport.c
${SRC_DIR}/bacnet/lighting.c ${SRC_DIR}/bacnet/lighting.c
${SRC_DIR}/bacnet/indtext.c ${SRC_DIR}/bacnet/indtext.c
# Test and test library files # Test and test library files