Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LREAL support (WIP) #10

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions example/AsProject/Logical/Libraries/Loupe/stringext/Binary.lby
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version='1.0' encoding='utf-8'?>
<Library xmlns="http://br-automation.co.at/AS/Library" Version="0.14.4" SubType="Binary">
<?xml version="1.0" encoding="utf-8"?>
<?AutomationStudio FileVersion="4.9"?>
<Library Version="0.15.0" SubType="Binary" xmlns="http://br-automation.co.at/AS/Library">
<Files>
<File Description="Exported data types">StringExt.typ</File>
<File Description="Exported constants">StringExt.var</File>
<File Description="Exported functions and function blocks">StringExt.fun</File>
<File Type="File">CHANGELOG.md</File>
<File Description="tlsf forward declaration file">tlsf.h</File>
<File Description="Header for internal functions">internal.h</File>
<File>CHANGELOG.md</File>
</Files>
<Dependencies>
<Dependency ObjectName="astime" />
<Dependency ObjectName="AsBrStr" />
<Dependency ObjectName="AsBrWStr" />
</Dependencies>
</Library>
</Library>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.15.0 - Add dtoa, strtod and float variants
0.14.4 - Fix bug in SplitFileName()
0.14.3 - Add support for strptime in GCC6
0.14.2 - Add stringpTime() and stringfTime()
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Automation Studio generated header file */
/* Do not edit ! */
/* stringext 0.14.4 */
/* stringext 0.15.0 */

#ifndef _STRINGEXT_
#define _STRINGEXT_
Expand All @@ -9,7 +9,7 @@ extern "C"
{
#endif
#ifndef _stringext_VERSION
#define _stringext_VERSION 0.14.4
#define _stringext_VERSION 0.15.0
#endif

#include <bur/plctypes.h>
Expand Down Expand Up @@ -85,6 +85,10 @@ _BUR_PUBLIC unsigned char wchar2char(unsigned short wcharacter);
_BUR_PUBLIC signed long formatString(plcstring* dest, unsigned long destSize, plcstring* format, struct StrExtArgs_typ* pArgs);
_BUR_PUBLIC unsigned long stringfTime(unsigned long dest, unsigned long destSize, unsigned long format, plcdt time);
_BUR_PUBLIC plcdt stringpTime(unsigned long src, unsigned long format);
_BUR_PUBLIC unsigned long stringdtoa(double value, plcstring* buffer, unsigned long ndigits, unsigned long bufferSize);
_BUR_PUBLIC unsigned long stringftoa(float value, plcstring* buffer, unsigned long ndigits, unsigned long bufferSize);
_BUR_PUBLIC double stringstrtod(plcstring* value, plcstring** pEnd);
_BUR_PUBLIC float stringstrtof(plcstring* value, plcstring** pEnd);


#ifdef __cplusplus
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Automation Studio generated header file */
/* Do not edit ! */
/* stringext 0.14.4 */
/* stringext 0.15.0 */

#ifndef _STRINGEXT_
#define _STRINGEXT_
Expand All @@ -9,7 +9,7 @@ extern "C"
{
#endif
#ifndef _stringext_VERSION
#define _stringext_VERSION 0.14.4
#define _stringext_VERSION 0.15.0
#endif

#include <bur/plctypes.h>
Expand Down Expand Up @@ -85,6 +85,10 @@ _BUR_PUBLIC unsigned char wchar2char(unsigned short wcharacter);
_BUR_PUBLIC signed long formatString(plcstring* dest, unsigned long destSize, plcstring* format, struct StrExtArgs_typ* pArgs);
_BUR_PUBLIC unsigned long stringfTime(unsigned long dest, unsigned long destSize, unsigned long format, plcdt time);
_BUR_PUBLIC plcdt stringpTime(unsigned long src, unsigned long format);
_BUR_PUBLIC unsigned long stringdtoa(double value, plcstring* buffer, unsigned long ndigits, unsigned long bufferSize);
_BUR_PUBLIC unsigned long stringftoa(float value, plcstring* buffer, unsigned long ndigits, unsigned long bufferSize);
_BUR_PUBLIC double stringstrtod(plcstring* value, plcstring** pEnd);
_BUR_PUBLIC float stringstrtof(plcstring* value, plcstring** pEnd);


#ifdef __cplusplus
Expand Down
32 changes: 32 additions & 0 deletions example/AsProject/Logical/Libraries/Loupe/stringext/StringExt.fun
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,35 @@ FUNCTION stringpTime : DATE_AND_TIME (*Parse time string*)
format : UDINT; (*Assumed format of time string*)
END_VAR
END_FUNCTION

FUNCTION stringdtoa : UDINT
VAR_INPUT
value : LREAL;
buffer : STRING[80];
ndigits : UDINT;
bufferSize : UDINT;
END_VAR
END_FUNCTION

FUNCTION stringftoa : UDINT
VAR_INPUT
value : REAL;
buffer : STRING[80];
ndigits : UDINT;
bufferSize : UDINT;
END_VAR
END_FUNCTION

FUNCTION stringstrtod : LREAL
VAR_INPUT
value : STRING[80];
pEnd : REFERENCE TO STRING[80];
END_VAR
END_FUNCTION

FUNCTION stringstrtof : REAL
VAR_INPUT
value : STRING[80];
pEnd : REFERENCE TO STRING[80];
END_VAR
END_FUNCTION
17 changes: 17 additions & 0 deletions example/AsProject/Logical/Libraries/Loupe/stringext/internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#ifndef STREXT_INTERNAL_H_INCLUDED
#define STREXT_INTERNAL_H_INCLUDED

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif
#endif /* STREXT_INTERNAL_H_INCLUDED */


void lockSelect(n);

void freeSelect(n);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@loupeteam/stringext",
"version": "0.14.4",
"version": "0.15.0",
"description": "Loupe's stringext library for Automation Runtime",
"homepage": "https://loupeteam.github.io/LoupeDocs/libraries/stringext.html",
"scripts": {},
Expand Down
105 changes: 105 additions & 0 deletions example/AsProject/Logical/Libraries/Loupe/stringext/tlsf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/** @file
*******************************************************************************
**
** @brief
** Two Levels Segregate Fit memory allocator (TLSF)
** Written by Miguel Masmano Tello <[email protected]>
**
** This code is released using a dual license strategy: GPL/LGPL
**
*******************************************************************************
** $Header: https://brateggevsvn1.br-automation.co.at/svn/motion_gmc/trunk/GMC/Core/sys/tlsf.h 2314 2013-11-26 09:33:41Z eisenmannm $
*******************************************************************************
**
** @remark
** This file is part of the common AR C++ System environment.
**
** @copyright
** <a href="http://www.br-automation.com/">
** Bernecker + Rainer Industrie-Elektronik Ges.m.b.H.</a>
**
** @date 2012-06-21 File has been adopted by Markus Eisenmann
**
******************************************************************************/

#ifndef _ARSYS_TLSF_H_INCLUDED_
#define _ARSYS_TLSF_H_INCLUDED_

#ifndef _SIZE_T_DEFINED
#include <stddef.h>
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/** @cond COMPILER_SPECIFICS */
#ifndef DECLSPEC_NOTHROW
#if defined(__GNUC__) && ((__GNUC__ > 3) || \
((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
#define DECLSPEC_NOTHROW __attribute__((__nothrow__))
#elif (_MSC_VER >= 1200) && defined(__cplusplus)
#define DECLSPEC_NOTHROW __declspec(nothrow)
#else
#define DECLSPEC_NOTHROW
#endif
#endif

#if defined(__ELF__) && (__GNUC__ >= 4)
#pragma GCC visibility push(hidden)
#define BURTLSF_DLLAPI __attribute__((visibility("default"), __nothrow__))
#else
#if defined(_WIN32) || defined(__WINDOWS__) || defined(__MINGW32__) || defined(__CYGWIN__)
#if defined(_ARSVCREG_EXPORT) || defined(BURTLSF_EXPORTS)
#define BURTLSF_DLLAPI __declspec(dllexport) DECLSPEC_NOTHROW
#else
#define BURTLSF_DLLAPI __declspec(dllimport) DECLSPEC_NOTHROW
#endif
#else /* not Windows */
#define BURTLSF_DLLAPI extern DECLSPEC_NOTHROW
#endif /* end Windows */
#endif
/** @endcond */

DECLSPEC_NOTHROW size_t _tlsf_init_memory_pool(size_t mem_pool_size, void *mem_pool);
DECLSPEC_NOTHROW size_t _tlsf_add_new_area(void *area, size_t area_size, void *mem_pool);
#if !defined(NDEBUG) && (defined(DEBUG) || defined(_DEBUG))
DECLSPEC_NOTHROW size_t _tlsf_get_used_size(void *mem_pool);
DECLSPEC_NOTHROW size_t _tlsf_get_max_size(void *mem_pool);
#endif
DECLSPEC_NOTHROW void _tlsf_destroy_memory_pool(void *mem_pool);
DECLSPEC_NOTHROW void *_tlsf_malloc_ex(size_t size, void *mem_pool);
DECLSPEC_NOTHROW void *_tlsf_free_ex(void *ptr, void *mem_pool);
DECLSPEC_NOTHROW void *_tlsf_realloc_ex(void *ptr, size_t new_size, void *mem_pool);
DECLSPEC_NOTHROW void *_tlsf_calloc_ex(size_t nelem, size_t elem_size, void *mem_pool);

#if defined(__ELF__) && (__GNUC__ >= 4)
#pragma GCC visibility pop
#endif

/*lint -esym(526, tlsf_*) prevent warning about undefined functions*/
/*exos BURTLSF_DLLAPI*/ void *tlsf_malloc(size_t size);
/*exos BURTLSF_DLLAPI*/ void tlsf_free(void *ptr);
/*exos BURTLSF_DLLAPI*/ void *tlsf_realloc(void *ptr, size_t size);
/*exos BURTLSF_DLLAPI*/ void *tlsf_calloc(size_t nelem, size_t elem_size);

/** @cond HIDDEN_INTERNALS */
extern int const _force_tlfs_malloc; /*link symbol to force use of TLSF*/

#if defined(_ENFORCE_TLFS_REDIRECT) && !(defined(_CODECHECK_PASS) || defined(_CODEPARSE_PASS) || defined(__CDT_PARSER__) || defined(_lint) || defined(__DOXYGEN) || defined(_doxygen))
#if (__GNUC__ >= 3) && !defined(WIN32)
__extension__ void *malloc(size_t) __asm__("tlsf_malloc");
__extension__ void free(void *) __asm__("tlsf_free");
__extension__ void *realloc(void *, size_t) __asm__("tlsf_realloc");
__extension__ void *calloc(size_t, size_t) __asm__("tlsf_calloc");
#else
#error "Forcing TSLF-redirection of DSA not supported!"
#endif
#endif
/** @endcond */

#ifdef __cplusplus
} // extern "C"
#endif
#endif /*_ARSYS_TLSF_H_INCLUDED_*/
8 changes: 4 additions & 4 deletions src/Ar/VarTools/ANSIC.lby
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?AutomationStudio FileVersion="4.9"?>
<Library Version="0.11.4" SubType="ANSIC" xmlns="http://br-automation.co.at/AS/Library">
<Library Version="0.11.5" SubType="ANSIC" xmlns="http://br-automation.co.at/AS/Library">
<Files>
<File Description="Exported data types">VarTools.typ</File>
<File Description="Exported constants">VarTools.var</File>
Expand All @@ -15,12 +15,12 @@
<File Description="Set the value of a variable from a string">varVariableWatch.c</File>
<File>variableBrowser.c</File>
<File Description="Force refresh of variable information in next getValue call">varRefresh.c</File>
<File Description="">varToolsInternal.h</File>
</Files>
<File>varToolsInternal.h</File>
</Files>
<Dependencies>
<Dependency ObjectName="sys_lib" />
<Dependency ObjectName="AsBrStr" />
<Dependency ObjectName="AsBrWStr" />
<Dependency ObjectName="stringext" FromVersion="0.14.0" ToVersion="0.15.9" />
<Dependency ObjectName="stringext" FromVersion="0.15.0" ToVersion="0.15.9" />
</Dependencies>
</Library>
1 change: 1 addition & 0 deletions src/Ar/VarTools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.11.5 - Improve lreal support in varGetValue
0.11.4 - Update StringExt dependency
0.11.3 - Increase maximum size of variable list from 50 to 100
0.11.2 - populate variable values will populate ._ with just the parent name
Expand Down
5 changes: 3 additions & 2 deletions src/Ar/VarTools/varGetValue.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unsigned short varGetValue(unsigned long pVariable)
DINT valueDint;
UDINT valueUdint;
REAL valueReal;
LREAL valueLreal;


// Clear the Value string. It will be overwritten below
Expand Down Expand Up @@ -193,9 +194,9 @@ unsigned short varGetValue(unsigned long pVariable)

case VAR_TYPE_LREAL:

valueReal= (REAL)*(LREAL*)(ipVariable->address);
valueLreal= *(LREAL*)(ipVariable->address);

brsftoa( valueReal, (UDINT)ipVariable->value );
stringdtoa(valueLreal, ipVariable->value, 0, sizeof(ipVariable->value));
shanereetz marked this conversation as resolved.
Show resolved Hide resolved

break;

Expand Down