Issue 2 move folders and use deep path include file names to prevent collisions (#4)

* moving folders and files and adjust server demo build

* Fix Makefile for apps/server on Linux

* fix unit test source file folders

* fix datetime convert UTC functions. Add Code::Blocks project for datetime testing

* added some ignore extensions

* disable parallel make option

* fix build for abort, dcc, and epics apps

* fix build for dcc, epics, error, and getevent apps.

* Fixed building of all apps

* fix the ipv4 to ipv6 router app build

* Change indent style from Google to Webkit

* make pretty to re-format style

* removed common Makefile since we already had one and two was too many

* remove scripts from root folder that are no longer maintained or used

* remove mercurial EOL and ignore files for git repo

* remove .vscodeconfig files from repo

* tweak clang-format style

* clang-format src and apps with tweaked style

* added clang-tidy to fix readability if braces in src

* result of make tidy for src and apps

* fix clang-tidy mangling

* Added code::blocks project for BACnet server simulation

* added code::blocks linux project for WhoIs app

* update text files for EOL

* fix EOL in some files

* fixed make win32 apps for older gcc

* Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler.

* created codeblocks project for apps/epics for Windows

* fixing ports/xplained to work with new data structure.

* fix ports/xplained example for Atmel Studio compile

* fix ports/stm32f10x example for gcc Makefile compile

* fix ports/stm32f10x example for IAR EWARM compile

* fix ports/xplained timer callback

* fix ports/bdk_atxx_mspt build with subdirs

* fix ports/bdk_atxx_mspt build with subdirs

* updated git ignore for IAR build artifacts

* updated gitignore for non-tracked files and folders

* fixed bdk-atxx4-mstp port for Rowley Crossworks project file

* fixed bdk-atxx4-mstp port for GCC AVR Makefile

* fixed atmega168 port for IAR AVR and GCC AVR Makefile

* fixed at91sam7s port for IAR ARM and GCC ARM Makefile

* removed unmaintainable DOS, RTOS32, and atmega8 ports.  Updated rx62n (untested).

* changed arm7 to uip port
This commit is contained in:
Steve Karg
2019-12-13 15:19:10 -06:00
committed by GitHub
parent 8a38dbe2cf
commit d50c190957
912 changed files with 36206 additions and 52502 deletions
+409
View File
@@ -0,0 +1,409 @@
/*####COPYRIGHTBEGIN####
-------------------------------------------
Copyright (C) 2004 Steve Karg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
The Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA.
As a special exception, if other files instantiate templates or
use macros or inline functions from this file, or you compile
this file and link it with other works to produce a work based
on this file, this file does not by itself cause the resulting
work to be covered by the GNU General Public License. However
the source code for this file must still be made available in
accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work
based on this file might be covered by the GNU General Public
License.
-------------------------------------------
####COPYRIGHTEND####*/
/* BACnet Integer encoding and decoding */
#include <stdint.h>
#include <stdbool.h>
#include "bacnet/config.h"
#include "bacnet/bacint.h"
/** @file bacint.c Encode/Decode Integer Types */
int encode_unsigned16(uint8_t *apdu, uint16_t value)
{
apdu[0] = (uint8_t)((value & 0xff00) >> 8);
apdu[1] = (uint8_t)(value & 0x00ff);
return 2;
}
int decode_unsigned16(uint8_t *apdu, uint16_t *value)
{
if (value) {
*value = (uint16_t)((((uint16_t)apdu[0]) << 8) & 0xff00);
*value |= ((uint16_t)(((uint16_t)apdu[1]) & 0x00ff));
}
return 2;
}
int encode_unsigned24(uint8_t *apdu, uint32_t value)
{
apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t)(value & 0x0000ff);
return 3;
}
int decode_unsigned24(uint8_t *apdu, uint32_t *value)
{
if (value) {
*value = ((uint32_t)((((uint32_t)apdu[0]) << 16) & 0x00ff0000));
*value |= (uint32_t)((((uint32_t)apdu[1]) << 8) & 0x0000ff00);
*value |= ((uint32_t)(((uint32_t)apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_unsigned32(uint8_t *apdu, uint32_t value)
{
apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t)(value & 0x000000ff);
return 4;
}
int decode_unsigned32(uint8_t *apdu, uint32_t *value)
{
if (value) {
*value = ((uint32_t)((((uint32_t)apdu[0]) << 24) & 0xff000000));
*value |= ((uint32_t)((((uint32_t)apdu[1]) << 16) & 0x00ff0000));
*value |= ((uint32_t)((((uint32_t)apdu[2]) << 8) & 0x0000ff00));
*value |= ((uint32_t)(((uint32_t)apdu[3]) & 0x000000ff));
}
return 4;
}
#ifdef UINT64_MAX
/**
* @brief Encode a 64-bit unsigned value into buffer
* @param buffer - pointer to bytes for storing encoding
* @param value - 16-bit value to encode
* @return Returns the number of bytes encoded
*/
int encode_unsigned64(uint8_t *buffer, uint64_t value)
{
buffer[0] = (uint8_t)((value & 0xff00000000000000) >> 56);
buffer[1] = (uint8_t)((value & 0x00ff000000000000) >> 48);
buffer[2] = (uint8_t)((value & 0x0000ff0000000000) >> 40);
buffer[3] = (uint8_t)((value & 0x000000ff00000000) >> 32);
buffer[4] = (uint8_t)((value & 0x00000000ff000000) >> 24);
buffer[5] = (uint8_t)((value & 0x0000000000ff0000) >> 16);
buffer[6] = (uint8_t)((value & 0x000000000000ff00) >> 8);
buffer[7] = (uint8_t)(value & 0x00000000000000ff);
return 8;
}
/**
* @brief Decode a 64-bit unsigned value from a buffer
* @param buffer - pointer to bytes for used for decoding
* @param value - pointer to 64-bit value to store the decoded value
* @return Returns the number of bytes decoded
*/
int decode_unsigned64(uint8_t *buffer, uint64_t *value)
{
if (value) {
*value =
((uint64_t)((((uint64_t)buffer[0]) << 56) & 0xff00000000000000));
*value |=
((uint64_t)((((uint64_t)buffer[1]) << 48) & 0x00ff000000000000));
*value |=
((uint64_t)((((uint64_t)buffer[2]) << 40) & 0x0000ff0000000000));
*value |=
((uint64_t)((((uint64_t)buffer[3]) << 32) & 0x000000ff00000000));
*value |=
((uint64_t)((((uint64_t)buffer[4]) << 24) & 0x00000000ff000000));
*value |=
((uint64_t)((((uint64_t)buffer[5]) << 16) & 0x0000000000ff0000));
*value |=
((uint64_t)((((uint64_t)buffer[6]) << 8) & 0x000000000000ff00));
*value |= ((uint64_t)(((uint64_t)buffer[7]) & 0x00000000000000ff));
}
return 8;
}
#endif
#if BACNET_USE_SIGNED
int encode_signed8(uint8_t *apdu, int8_t value)
{
apdu[0] = (uint8_t)value;
return 1;
}
int decode_signed8(uint8_t *apdu, int32_t *value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80) {
*value = 0xFFFFFF00;
} else {
*value = 0;
}
*value |= ((int32_t)(((int32_t)apdu[0]) & 0x000000ff));
}
return 1;
}
int encode_signed16(uint8_t *apdu, int16_t value)
{
apdu[0] = (uint8_t)((value & 0xff00) >> 8);
apdu[1] = (uint8_t)(value & 0x00ff);
return 2;
}
int decode_signed16(uint8_t *apdu, int32_t *value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80) {
*value = 0xFFFF0000;
} else {
*value = 0;
}
*value |= ((int32_t)((((int32_t)apdu[0]) << 8) & 0x0000ff00));
*value |= ((int32_t)(((int32_t)apdu[1]) & 0x000000ff));
}
return 2;
}
int encode_signed24(uint8_t *apdu, int32_t value)
{
apdu[0] = (uint8_t)((value & 0xff0000) >> 16);
apdu[1] = (uint8_t)((value & 0x00ff00) >> 8);
apdu[2] = (uint8_t)(value & 0x0000ff);
return 3;
}
int decode_signed24(uint8_t *apdu, int32_t *value)
{
if (value) {
/* negative - bit 7 is set */
if (apdu[0] & 0x80) {
*value = 0xFF000000;
} else {
*value = 0;
}
*value |= ((int32_t)((((int32_t)apdu[0]) << 16) & 0x00ff0000));
*value |= ((int32_t)((((int32_t)apdu[1]) << 8) & 0x0000ff00));
*value |= ((int32_t)(((int32_t)apdu[2]) & 0x000000ff));
}
return 3;
}
int encode_signed32(uint8_t *apdu, int32_t value)
{
apdu[0] = (uint8_t)((value & 0xff000000) >> 24);
apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16);
apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8);
apdu[3] = (uint8_t)(value & 0x000000ff);
return 4;
}
int decode_signed32(uint8_t *apdu, int32_t *value)
{
if (value) {
*value = ((int32_t)((((int32_t)apdu[0]) << 24) & 0xff000000));
*value |= ((int32_t)((((int32_t)apdu[1]) << 16) & 0x00ff0000));
*value |= ((int32_t)((((int32_t)apdu[2]) << 8) & 0x0000ff00));
*value |= ((int32_t)(((int32_t)apdu[3]) & 0x000000ff));
}
return 4;
}
#endif
/* end of decoding_encoding.c */
#ifdef TEST
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "ctest.h"
static void testBACnetUnsigned16(Test *pTest)
{
uint8_t apdu[32] = { 0 };
uint16_t value = 0, test_value = 0;
int len = 0;
for (value = 0;; value++) {
len = encode_unsigned16(&apdu[0], value);
ct_test(pTest, len == 2);
len = decode_unsigned16(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
if (value == 0xFFFF)
break;
}
}
static void testBACnetUnsigned24(Test *pTest)
{
uint8_t apdu[32] = { 0 };
uint32_t value = 0, test_value = 0;
int len = 0;
for (value = 0;; value += 0xf) {
len = encode_unsigned24(&apdu[0], value);
ct_test(pTest, len == 3);
len = decode_unsigned24(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
if (value == 0xffffff)
break;
}
}
static void testBACnetUnsigned32(Test *pTest)
{
uint8_t apdu[32] = { 0 };
uint32_t value = 0, test_value = 0;
int len = 0;
for (value = 0;; value += 0xff) {
len = encode_unsigned32(&apdu[0], value);
ct_test(pTest, len == 4);
len = decode_unsigned32(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
if (value == 0xffffffff)
break;
}
}
static void testBACnetSigned8(Test *pTest)
{
uint8_t apdu[32] = { 0 };
int32_t value = 0, test_value = 0;
int len = 0;
for (value = -127;; value++) {
len = encode_signed8(&apdu[0], value);
ct_test(pTest, len == 1);
len = decode_signed8(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
if (value == 127)
break;
}
}
static void testBACnetSigned16(Test *pTest)
{
uint8_t apdu[32] = { 0 };
int32_t value = 0, test_value = 0;
int len = 0;
for (value = -32767;; value++) {
len = encode_signed16(&apdu[0], value);
ct_test(pTest, len == 2);
len = decode_signed16(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
if (value == 32767)
break;
}
}
static void testBACnetSigned24(Test *pTest)
{
uint8_t apdu[32] = { 0 };
int32_t value = 0, test_value = 0;
int len = 0;
for (value = -8388607; value <= 8388607; value += 15) {
len = encode_signed24(&apdu[0], value);
ct_test(pTest, len == 3);
len = decode_signed24(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
}
}
static void testBACnetSigned32(Test *pTest)
{
uint8_t apdu[32] = { 0 };
int32_t value = 0, test_value = 0;
int len = 0;
for (value = -2147483647; value < 0; value += 127) {
len = encode_signed32(&apdu[0], value);
ct_test(pTest, len == 4);
len = decode_signed32(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
}
for (value = 2147483647; value > 0; value -= 127) {
len = encode_signed32(&apdu[0], value);
ct_test(pTest, len == 4);
len = decode_signed32(&apdu[0], &test_value);
ct_test(pTest, value == test_value);
}
}
void testBACnetIntegers(Test *pTest)
{
bool rc;
assert(pTest);
/* individual tests */
rc = ct_addTestFunction(pTest, testBACnetUnsigned16);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetUnsigned24);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetUnsigned32);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetSigned8);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetSigned16);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetSigned24);
assert(rc);
rc = ct_addTestFunction(pTest, testBACnetSigned32);
assert(rc);
}
#ifdef TEST_BACINT
int main(void)
{
Test *pTest;
pTest = ct_create("BACint", NULL);
testBACnetIntegers(pTest);
/* configure output */
ct_setStream(pTest, stdout);
ct_run(pTest);
(void)ct_report(pTest);
ct_destroy(pTest);
return 0;
}
#endif /* TEST_BACINT */
#endif /* TEST */