From 90ac2ebd53fea9f34f0d020142bf7d084e337c50 Mon Sep 17 00:00:00 2001 From: joey8869 Date: Thu, 1 Jul 2021 17:24:08 +0800 Subject: [PATCH] change header np_ to neu_ --- include/errorcodes.h | 4 +- include/functions.h | 6 +- include/types.h | 431 +++++++++++++++++++++++-------------------- src/errorcodes.c | 12 +- src/sighandler.c | 8 +- src/types.c | 197 +++++++++++++++++--- 6 files changed, 408 insertions(+), 250 deletions(-) diff --git a/include/errorcodes.h b/include/errorcodes.h index 8ec2df22..4de9cee4 100644 --- a/include/errorcodes.h +++ b/include/errorcodes.h @@ -24,8 +24,8 @@ extern "C" { #endif -#define NP_ERRORCODE_NONE 0x00000000 -#define NP_ERRORCODE_OUTOFMEMORY 0xA0000000 +#define NEU_ERRORCODE_NONE 0x00000000 +#define NEU_ERRORCODE_OUTOFMEMORY 0xA0000000 #ifdef __cplusplus } diff --git a/include/functions.h b/include/functions.h index fdf70551..ab546dbd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -29,9 +29,9 @@ extern "C" { * Signal handling function */ -typedef void (*np_signalStopHandler)(void); -void np_setSignalHandler(np_signalStopHandler stopHandler, np_boolean_t *Running); -void np_setSignalIgnore(np_word_t status); +typedef void (*neu_signalStopHandler)(void); +void neu_setSignalHandler(neu_signalStopHandler stopHandler, neu_boolean_t *Running); +void neu_setSignalIgnore(neu_word_t status); diff --git a/include/types.h b/include/types.h index 5c2e4ee1..8f8fa65b 100644 --- a/include/types.h +++ b/include/types.h @@ -26,7 +26,8 @@ extern "C" { #include #include -#include +#include +#include /** * Order @@ -35,82 +36,82 @@ extern "C" { * elements. **/ typedef enum { - NP_ORDER_LESS = -1, - NP_ORDER_EQ = 0, - NP_ORDER_MORE = 1 -} np_order_t; + NEU_ORDER_LESS = -1, + NEU_ORDER_EQ = 0, + NEU_ORDER_MORE = 1 +} neu_order_t; /** * Boolean * ------- * A logical value (true or false). **/ -typedef bool np_boolean_t; -#define NP_TRUE true -#define NP_FALSE false +typedef bool neu_boolean_t; +#define NEU_TRUE true +#define NEU_FALSE false /** * State * ----- * A state value (on or off). **/ -typedef bool np_state_t; -#define NP_ON true -#define NP_OFF false +typedef bool neu_state_t; +#define NEU_ON true +#define NEU_OFF false /** * Byte * ---- * An integer value between -128 and 127. **/ -typedef int8_t np_byte_t; -#define NP_BYTE_MIN (-128) -#define NP_BYTE_MAX 127 +typedef int8_t neu_byte_t; +#define NEU_BYTE_MIN (-128) +#define NEU_BYTE_MAX 127 /** * Unsigned-Byte * ------------- * An integer value between 0 and 255. **/ -typedef uint8_t np_ubyte_t; -#define NP_UBYTE_MIN 0 -#define NP_UBYTE_MAX 255 +typedef uint8_t neu_ubyte_t; +#define NEU_UBYTE_MIN 0 +#define NEU_UBYTE_MAX 255 /** * Word * ---- * An integer value between -32 768 and 32 767. **/ -typedef int16_t np_word_t; -#define NP_WORD_MIN (-32768) -#define NP_WORD_MAX 32767 +typedef int16_t neu_word_t; +#define NEU_WORD_MIN (-32768) +#define NEU_WORD_MAX 32767 /** * Unsigned-Word * ------------- * An integer value between 0 and 65 535. **/ -typedef uint16_t np_uword_t; -#define NP_UWORD_MIN 0 -#define NP_UWORD_MAX 65535 +typedef uint16_t neu_uword_t; +#define NEU_UWORD_MIN 0 +#define NEU_UWORD_MAX 65535 /** * Double Word * ----------- * An integer value between -2 147 483 648 and 2 147 483 647. **/ -typedef int32_t np_dword_t; -#define NP_DWORD_MIN (-2147483648) -#define NP_DWORD_MAX 2147483647 +typedef int32_t neu_dword_t; +#define NEU_DWORD_MIN (-2147483648) +#define NEU_DWORD_MAX 2147483647 /** * Unsigned Double Word * -------------------- * An integer value between 0 and 4 294 967 295. **/ -typedef uint32_t np_udword_t; -#define NP_UDWORD_MIN 0 -#define NP_UDWORD_MAX 4294967295 +typedef uint32_t neu_udword_t; +#define NEU_UDWORD_MIN 0 +#define NEU_UDWORD_MAX 4294967295 /** * Quarter Word @@ -118,32 +119,36 @@ typedef uint32_t np_udword_t; * An integer value between -9 223 372 036 854 775 808 and * 9 223 372 036 854 775 807. **/ -typedef int64_t np_qword_t; -#define NP_QWORD_MIN (-9223372036854775808) -#define NP_QWORD_MAX 9223372036854775807 +typedef int64_t neu_qword_t; +#define NEU_QWORD_MIN (-9223372036854775808) +#define NEU_QWORD_MAX 9223372036854775807 /** * Unsigned Quarter Word * --------------------- * An integer value between 0 and 18 446 744 073 709 551 615. **/ -typedef uint64_t np_uqword_t; -#define NP_UQWORD_MIN 0 -#define NP_UQWORD_MAX 18446744073709551615 +typedef uint64_t neu_uqword_t; +#define NEU_UQWORD_MIN 0 +#define NEU_UQWORD_MAX 18446744073709551615 /** * Float * ----- * An IEEE single precision (32 bit) floating point value. **/ -typedef float np_float_t; +typedef float neu_float_t; /** * Double * ------ * An IEEE double precision (64 bit) floating point value. **/ -typedef double np_double_t; +typedef double neu_double_t; + +/* decimal point range */ +#define NEU_DECIMAL_MIN 0 +#define NEU_DECIMAL_MAX 5 /** * Byte (decimal) @@ -151,9 +156,11 @@ typedef double np_double_t; * An integer value between -128 and 127 with decimal position. **/ typedef struct { - np_byte_t value; + neu_byte_t value; uint8_t decimal; -} np_byte_deci_t; +} neu_bytedec_t; + +neu_double_t neu_bytedec_toDouble(neu_bytedec_t b); /** * Unsigned-Byte (decimal) @@ -161,9 +168,11 @@ typedef struct { * An integer value between 0 and 255 with decimal position. **/ typedef struct { - np_ubyte_t value; + neu_ubyte_t value; uint8_t decimal; -} np_ubyte_deci_t; +} neu_ubytedec_t; + +neu_double_t neu_ubytedec_toDouble(neu_ubytedec_t ub); /** * Word @@ -171,9 +180,11 @@ typedef struct { * An integer value between -32 768 and 32 767 with decimal position. **/ typedef struct { - np_word_t value; + neu_word_t value; uint8_t decimal; -} np_word_deci_t; +} neu_worddec_t; + +neu_double_t neu_worddec_toDouble(neu_worddec_t w); /** * Unsigned-Word @@ -181,9 +192,11 @@ typedef struct { * An integer value between 0 and 65 535 with decimal position. **/ typedef struct { - np_uword_t value; + neu_uword_t value; uint8_t decimal; -} np_uword_deci_t; +} neu_uworddec_t; + +neu_double_t neu_uworddec_toDouble(neu_uworddec_t uw); /** * Double Word @@ -191,9 +204,11 @@ typedef struct { * An integer value between -2 147 483 648 and 2 147 483 647 with decimal position. **/ typedef struct { - np_dword_t value; + neu_dword_t value; uint8_t decimal; -} np_dword_deci_t; +} neu_dworddec_t; + +neu_double_t neu_dworddec_toDouble(neu_dworddec_t dw); /** * Unsigned Double Word @@ -201,9 +216,11 @@ typedef struct { * An integer value between 0 and 4 294 967 295 with decimal position. **/ typedef struct { - np_udword_t value; + neu_udword_t value; uint8_t decimal; -} np_udword_deci_t; +} neu_udworddec_t; + +neu_double_t neu_udworddec_toDouble(neu_udworddec_t udw); /** * Quarter Word @@ -212,9 +229,11 @@ typedef struct { * 9 223 372 036 854 775 807 with decimal position. **/ typedef struct { - np_qword_t value; + neu_qword_t value; uint8_t decimal; -} np_qword_deci_t; +} neu_qworddec_t; + +neu_double_t neu_qworddec_toDouble(neu_qworddec_t qw); /** * Unsigned Quarter Word @@ -222,9 +241,11 @@ typedef struct { * An integer value between 0 and 18 446 744 073 709 551 615 with decimal position. **/ typedef struct { - np_uqword_t value; + neu_uqword_t value; uint8_t decimal; -} np_uqword_deci_t; +} neu_uqworddec_t; + +neu_double_t neu_uqworddec_toDouble(neu_uqworddec_t uqw); /** * String @@ -234,21 +255,21 @@ typedef struct { typedef struct { size_t length; char *charstr; -} np_string_t; +} neu_string_t; /* returns a string pointing to the original character array. */ -np_string_t np_string_fromArray(char *array); +neu_string_t neu_string_fromArray(char *array); /* returns a copy of the character array content on the heap. */ -np_string_t np_string_fromChars(const char *chars); +neu_string_t neu_string_fromChars(const char *chars); /* returns order type by comparing of two character arrays content. */ -np_order_t np_string_isEqual(const np_string_t *s1, const np_string_t *s2); +neu_order_t neu_string_isEqual(const neu_string_t *s1, const neu_string_t *s2); -extern const np_string_t NP_STRING_NULL; +extern const neu_string_t NEU_STRING_NULL; /* Define strings at compile time */ -#define np_string_fromStatic(CHARS) {sizeof(CHARS)-1, (char*)CHARS} +#define neu_string_fromStatic(CHARS) {sizeof(CHARS)-1, (char*)CHARS} /** * Localized Text @@ -256,23 +277,23 @@ extern const np_string_t NP_STRING_NULL; * Human readable text with an optional locale identifier. **/ typedef struct { - np_string_t locale; - np_string_t text; -} np_text_t; + neu_string_t locale; + neu_string_t text; +} neu_text_t; -static inline np_text_t -np_text_fromArray(char *locale, char *array) { - np_text_t t; - t.locale = np_string_fromArray(locale); - t.text = np_string_fromArray(array); +static inline neu_text_t +neu_text_fromArray(char *locale, char *array) { + neu_text_t t; + t.locale = neu_string_fromArray(locale); + t.text = neu_string_fromArray(array); return t; } -static inline np_text_t -np_text_fromChars(const char *locale, const char *chars) { - np_text_t t; - t.locale = np_string_fromChars(locale); - t.text = np_string_fromChars(chars); +static inline neu_text_t +neu_text_fromChars(const char *locale, const char *chars) { + neu_text_t t; + t.locale = neu_string_fromChars(locale); + t.text = neu_string_fromChars(chars); return t; } @@ -283,11 +304,11 @@ np_text_fromChars(const char *locale, const char *chars) { * or an operation. See the section :ref:`statuscodes` for the meaning of a * specific code. **/ -typedef uint32_t np_errorcode_t; +typedef uint32_t neu_errorcode_t; /* Returns the human-readable name of the StatusCode. If no matching StatusCode * is found, a default string for "Unknown" is returned.*/ -const char *np_errorcode_getName(np_errorcode_t code); +const char *neu_errorcode_getName(neu_errorcode_t code); /** * Time @@ -296,19 +317,19 @@ const char *np_errorcode_getName(np_errorcode_t code); * which represents the number of one second interval since January 1, 1970 * (UTC). **/ -typedef uint32_t np_time_t; +typedef uint32_t neu_time_t; /* The current time in local time */ -np_time_t np_time_now(void); +neu_time_t neu_time_now(void); /* Represents a Datetime as a structure */ -typedef struct tm np_datetime_t; +typedef struct tm neu_datetime_t; /* Returns the datetime structure from time */ -np_datetime_t np_time_getDateTime(np_time_t t); +neu_datetime_t neu_time_getDateTime(neu_time_t t); /* Returns the instance time from datetime structure */ -np_time_t np_time_fromDateTime(np_datetime_t d); +neu_time_t neu_time_fromDateTime(neu_datetime_t d); /** * Uuid @@ -316,19 +337,19 @@ np_time_t np_time_fromDateTime(np_datetime_t d); * A 16 byte value that can be used as a universal unique identifier. **/ typedef struct { - np_udword_t data1; - np_uword_t data2; - np_uword_t data3; - np_ubyte_t data4[8]; -} np_uuid_t; + neu_udword_t data1; + neu_uword_t data2; + neu_uword_t data3; + neu_ubyte_t data4[8]; +} neu_uuid_t; /* Parse the uuid format defined in Part 6, 5.1.3. * Format: C496578A-0DFE-4B8F-870A-745238C6AEAE * | | | | | | * 0 8 13 18 23 36 */ -np_boolean_t np_uuid_isEqual(const np_uuid_t *g1, const np_uuid_t *g2); +neu_boolean_t neu_uuid_isEqual(const neu_uuid_t *g1, const neu_uuid_t *g2); -extern const np_uuid_t NP_UUID_NULL; +extern const neu_uuid_t NEU_UUID_NULL; /** * NodeId @@ -336,13 +357,13 @@ extern const np_uuid_t NP_UUID_NULL; * An identifier for a node to be located in the list. **/ typedef struct { - np_text_t nodeName; - np_string_t identifier; -} np_nodeid_t; + neu_text_t nodeName; + neu_string_t identifier; +} neu_nodeid_t; -np_boolean_t np_nodeid_isNull(const np_nodeid_t *p); +neu_boolean_t neu_nodeid_isNull(const neu_nodeid_t *p); -np_order_t np_nodeid_order(const np_nodeid_t *n1, const np_nodeid_t *n2); +neu_order_t neu_nodeid_order(const neu_nodeid_t *n1, const neu_nodeid_t *n2); /** * Data Type @@ -350,50 +371,50 @@ np_order_t np_nodeid_order(const np_nodeid_t *n1, const np_nodeid_t *n2); * A list of data type **/ typedef enum { - NP_DATATYPE_BOOLEAN, - NP_DATATYPE_STATE, - NP_DATATYPE_BYTE, - NP_DATATYPE_UBYTE, - NP_DATATYPE_WORD, - NP_DATATYPE_UWORD, - NP_DATATYPE_DWORD, - NP_DATATYPE_UDWORD, - NP_DATATYPE_QWORD, - NP_DATATYPE_UQWORD, - NP_DATATYPE_FLOAT, - NP_DATATYPE_DOUBLE, - NP_DATATYPE_BYTE_DECI, - NP_DATATYPE_UBYTE_DECI, - NP_DATATYPE_WORD_DECI, - NP_DATATYPE_UWORD_DECI, - NP_DATATYPE_DWORD_DECI, - NP_DATATYPE_UDWORD_DECI, - NP_DATATYPE_QWORD_DECI, - NP_DATATYPE_UQWORD_DECI, - NP_DATATYPE_STRING, - NP_DATATYPE_LOCALIZEDTEXT, - NP_DATATYPE_ERRORCODE, - NP_DATATYPE_DATETIME, - NP_DATATYPE_UUID, - NP_DATATYPE_ADDRESSELEMENT, - NP_DATATYPE_ADDRESS, - NP_DATATYPE_TAG, - NP_DATATYPE_PARAMETER, - NP_DATATYPE_MODULE, - NP_DATATYPE_VARIABLE, - NP_DATATYPE_VARIABLENODE, - NP_DATATYPE_COUNT -} np_datatype_t; + NEU_DATATYPE_BOOLEAN, + NEU_DATATYPE_STATE, + NEU_DATATYPE_BYTE, + NEU_DATATYPE_UBYTE, + NEU_DATATYPE_WORD, + NEU_DATATYPE_UWORD, + NEU_DATATYPE_DWORD, + NEU_DATATYPE_UDWORD, + NEU_DATATYPE_QWORD, + NEU_DATATYPE_UQWORD, + NEU_DATATYPE_FLOAT, + NEU_DATATYPE_DOUBLE, + NEU_DATATYPE_BYTE_DECI, + NEU_DATATYPE_UBYTE_DECI, + NEU_DATATYPE_WORD_DECI, + NEU_DATATYPE_UWORD_DECI, + NEU_DATATYPE_DWORD_DECI, + NEU_DATATYPE_UDWORD_DECI, + NEU_DATATYPE_QWORD_DECI, + NEU_DATATYPE_UQWORD_DECI, + NEU_DATATYPE_STRING, + NEU_DATATYPE_LOCALIZEDTEXT, + NEU_DATATYPE_ERRORCODE, + NEU_DATATYPE_DATETIME, + NEU_DATATYPE_UUID, + NEU_DATATYPE_ADDRESSELEMENT, + NEU_DATATYPE_ADDRESS, + NEU_DATATYPE_TAG, + NEU_DATATYPE_PARAMETER, + NEU_DATATYPE_MODULE, + NEU_DATATYPE_VARIABLE, + NEU_DATATYPE_VARIABLENODE, + NEU_DATATYPE_COUNT +} neu_datatype_t; /* Test if the data type is a numeric builtin data type. This includes Boolean, * integers and floating point numbers. Not included are Time and ErrorCode. */ -np_boolean_t -np_datatype_isNumeric(const np_datatype_t *type); +neu_boolean_t +neu_datatype_isNumeric(const neu_datatype_t *type); -struct np_variabletype { - np_text_t *typeName; - np_datatype_t typeId; /* The nodeid of the type */ - np_uword_t memSize; /* Size of the struct in memory */ +struct neu_variabletype { + neu_text_t *typeName; + neu_datatype_t typeId; /* The nodeid of the type */ + neu_uword_t memSize; /* Size of the struct in memory */ }; /** @@ -403,25 +424,25 @@ struct np_variabletype { * location. **/ typedef enum { - NP_ADDRESSELEMENTTYPE_HEADER, - NP_ADDRESSELEMENTTYPE_UUID, - NP_ADDRESSELEMENTTYPE_IDENTIFIER, - NP_ADDRESSELEMENTTYPE_STATION, - NP_ADDRESSELEMENTTYPE_NETWORKNO, - NP_ADDRESSELEMENTTYPE_SOURCE, - NP_ADDRESSELEMENTTYPE_DESTINATION, - NP_ADDRESSELEMENTTYPE_REGISTER, - NP_ADDRESSELEMENTTYPE_NAMESPACEINDEX, - NP_ADDRESSELEMENTTYPE_NAMESPACE, - NP_ADDRESSELEMENTTYPE_OBJECTID, - NP_ADDRESSELEMENTTYPE_ATTRIBUTEID -} np_addresselementtype_t; + NEU_ADDRESSELEMENTTYPE_HEADER, + NEU_ADDRESSELEMENTTYPE_UUID, + NEU_ADDRESSELEMENTTYPE_IDENTIFIER, + NEU_ADDRESSELEMENTTYPE_STATION, + NEU_ADDRESSELEMENTTYPE_NETWORKNO, + NEU_ADDRESSELEMENTTYPE_SOURCE, + NEU_ADDRESSELEMENTTYPE_DESTINATION, + NEU_ADDRESSELEMENTTYPE_REGISTER, + NEU_ADDRESSELEMENTTYPE_NAMESPACEINDEX, + NEU_ADDRESSELEMENTTYPE_NAMESPACE, + NEU_ADDRESSELEMENTTYPE_OBJECTID, + NEU_ADDRESSELEMENTTYPE_ATTRIBUTEID +} neu_addresselementtype_t; typedef struct { - np_addresselementtype_t type; - np_boolean_t isNumeric; - np_string_t element; -} np_addresselement_t; + neu_addresselementtype_t type; + neu_boolean_t isNumeric; + neu_string_t element; +} neu_addresselement_t; /** * Address @@ -430,19 +451,19 @@ typedef struct { * the data storage in external device. **/ typedef enum { - NP_ADDRESSTYPE_REGISTER, - NP_ADDRESSTYPE_SYMBOLIC, - NP_ADDRESSTYPE_TOPIC, - NP_ADDRESSTYPE_APIPATH -} np_addresstype_t; + NEU_ADDRESSTYPE_REGISTER, + NEU_ADDRESSTYPE_SYMBOLIC, + NEU_ADDRESSTYPE_TOPIC, + NEU_ADDRESSTYPE_APIPATH +} neu_addresstype_t; typedef struct { - np_addresstype_t type; - np_datatype_t dataType; - np_byte_t delimiter; + neu_addresstype_t type; + neu_datatype_t dataType; + neu_byte_t delimiter; size_t elementSize; - np_addresselement_t *elements; -} np_address_t; + neu_addresselement_t *elements; +} neu_address_t; /** * Tag @@ -451,17 +472,17 @@ typedef struct { * with external device. **/ typedef enum { - NP_ATTRIBUTETYPE_READ, - NP_ATTRIBUTETYPE_WRITE, - NP_ATTRIBUTETYPE_SUBSCRIBE -} np_attributetype_t; + NEU_ATTRIBUTETYPE_READ, + NEU_ATTRIBUTETYPE_WRITE, + NEU_ATTRIBUTETYPE_SUBSCRIBE +} neu_attributetype_t; typedef struct { - np_attributetype_t type; - np_word_t readInterval; - np_datatype_t dataType; - np_address_t address; -} np_tag_t; + neu_attributetype_t type; + neu_word_t readInterval; + neu_datatype_t dataType; + neu_address_t address; +} neu_tag_t; /** * Parameter @@ -470,10 +491,10 @@ typedef struct { * description. **/ typedef struct { - np_text_t paramDesc; - np_string_t paramName; - np_string_t paramData; -} np_parameter_t; + neu_text_t paramDesc; + neu_string_t paramName; + neu_string_t paramData; +} neu_parameter_t; /** * Module @@ -483,13 +504,13 @@ typedef struct { * communication channel. **/ typedef struct { - np_ubyte_t version; - np_string_t moduleName; - np_text_t moduleDesc; + neu_ubyte_t version; + neu_string_t moduleName; + neu_text_t moduleDesc; size_t sizeParam; - np_parameter_t *param; - np_string_t path; -} np_module_t; + neu_parameter_t *param; + neu_string_t path; +} neu_module_t; /** * Variable @@ -502,64 +523,64 @@ typedef struct { * an additional dimensionality defined in an array of dimension lengths. The * actual values are kept in an array of dimensions one. **/ -struct np_variabletype; -typedef struct np_variabletype np_variabletype_t; +struct neu_variabletype; +typedef struct neu_variabletype neu_variabletype_t; typedef struct { - const np_variabletype_t *type; /* The data type description */ + const neu_variabletype_t *type; /* The data type description */ size_t arrayLength; /* The number of elements in the data array */ size_t arrayDimensionsSize; /* The number of dimensions */ - np_udword_t *arrayDimensions; /* The length of each dimension */ + neu_udword_t *arrayDimensions; /* The length of each dimension */ void *data; /* Points to the scalar or array data */ -} np_variable_t; +} neu_variable_t; /* Returns true if the variable has no value defined (contains neither an array * nor a scalar value). */ -static inline np_boolean_t -np_variable_isEmpty(const np_variable_t *var) { +static inline neu_boolean_t +neu_variable_isEmpty(const neu_variable_t *var) { return var->type == NULL; } /* Returns true if the variable contains a scalar value. Note that empty variable * contain an array of length -1 (undefined). */ -static inline np_boolean_t -np_variable_isScalar(const np_variable_t *var) { +static inline neu_boolean_t +neu_variable_isScalar(const neu_variable_t *var) { return (var->arrayLength == 0 && var->data != NULL); } /* Returns true if the variant contains a scalar value of the given type. */ -static inline np_boolean_t -np_variable_hasScalarType(const np_variable_t *var, const np_variabletype_t *type) { - return np_variable_isScalar(var) && type == var->type; +static inline neu_boolean_t +neu_variable_hasScalarType(const neu_variable_t *var, const neu_variabletype_t *type) { + return neu_variable_isScalar(var) && type == var->type; } /* Returns true if the variable contains an array of the given type. */ -static inline np_boolean_t -np_variable_hasArrayType(const np_variable_t *var, const np_variabletype_t *type) { - return (!np_variable_isScalar(var)) && type == var->type; +static inline neu_boolean_t +neu_variable_hasArrayType(const neu_variable_t *var, const neu_variabletype_t *type) { + return (!neu_variable_isScalar(var)) && type == var->type; } /* Set the variable to a scalar value that already resides in memory. The value * takes on the lifecycle of the variable and is deleted with it. */ void -np_variable_setScalar(np_variable_t *var, void *p, - const np_variabletype_t *type); +neu_variable_setScalar(neu_variable_t *var, void *p, + const neu_variabletype_t *type); /* Set the variable to a scalar value that is copied from an existing variable. */ -np_errorcode_t -np_variable_setScalarCopy(np_variable_t *var, const void *p, - const np_variabletype_t *type); +neu_errorcode_t +neu_variable_setScalarCopy(neu_variable_t *var, const void *p, + const neu_variabletype_t *type); /* Set the variable to an array that already resides in memory. The array takes * on the lifecycle of the variant and is deleted with it. */ void -np_variable_setArray(np_variable_t *var, void *array, - size_t arraySize, const np_variabletype_t *type); +neu_variable_setArray(neu_variable_t *var, void *array, + size_t arraySize, const neu_variabletype_t *type); /* Set the variable to an array that is copied from an existing array. */ -np_errorcode_t -np_variable_setArrayCopy(np_variable_t *var, const void *array, - size_t arraySize, const np_variabletype_t *type); +neu_errorcode_t +neu_variable_setArrayCopy(neu_variable_t *var, const void *array, + size_t arraySize, const neu_variabletype_t *type); /** @@ -569,9 +590,9 @@ np_variable_setArrayCopy(np_variable_t *var, const void *array, * variables are mandated to have node id to identify itself for the adaptors. **/ typedef struct { - np_nodeid_t nodeid; - np_variable_t variable; -} np_varaiblenode_t; + neu_nodeid_t nodeid; + neu_variable_t variable; +} neu_varaiblenode_t; diff --git a/src/errorcodes.c b/src/errorcodes.c index 471c07fa..8287e7ad 100644 --- a/src/errorcodes.c +++ b/src/errorcodes.c @@ -21,17 +21,17 @@ #include typedef struct { - np_errorcode_t code; + neu_errorcode_t code; const char *name; -} np_errorcodename_t; +} neu_errorcodename_t; static const size_t errorcodeDescriptionsSize = 2; -static const np_errorcodename_t errorcodeDescriptions[2] = { - {NP_ERRORCODE_NONE, "None"}, - {NP_ERRORCODE_OUTOFMEMORY, "ErrorCodeOutOfMemory"} +static const neu_errorcodename_t errorcodeDescriptions[2] = { + {NEU_ERRORCODE_NONE, "None"}, + {NEU_ERRORCODE_OUTOFMEMORY, "ErrorCodeOutOfMemory"} }; -const char * np_errorcode_getName(np_errorcode_t code) { +const char * neu_errorcode_getName(neu_errorcode_t code) { for (size_t i = 0; i < errorcodeDescriptionsSize; ++i) { if (errorcodeDescriptions[i].code == code) return errorcodeDescriptions[i].name; diff --git a/src/sighandler.c b/src/sighandler.c index 441ca4f2..a90d837c 100644 --- a/src/sighandler.c +++ b/src/sighandler.c @@ -36,12 +36,12 @@ #include #include -static np_boolean_t *running; +static neu_boolean_t *running; static void (*stophandler)(void); static void sigcatch(int sig); void -np_setSignalHandler(np_signalStopHandler stopHandler, np_boolean_t *Running) { +neu_setSignalHandler(neu_signalStopHandler stopHandler, neu_boolean_t *Running) { running = Running; stophandler = stopHandler; signal(SIGHUP, sigcatch); @@ -61,7 +61,7 @@ np_setSignalHandler(np_signalStopHandler stopHandler, np_boolean_t *Running) { void sigcatch(int signal) { - np_setSignalIgnore(NP_ON); + neu_setSignalIgnore(NEU_ON); if (stophandler) stophandler(); if (running) @@ -85,7 +85,7 @@ sigcatch(int signal) { * when the ignore counter goes from 1 to 0. */ void -np_setSignalIgnore(np_word_t status) { +neu_setSignalIgnore(neu_word_t status) { static int sigigndone = 0; static void (*savesighup)(); static void (*savesigint)(); diff --git a/src/types.c b/src/types.c index 009d2466..234d5e6b 100644 --- a/src/types.c +++ b/src/types.c @@ -20,27 +20,95 @@ #include #include +/*****************/ +/* Decimal Types */ +/*****************/ + +neu_double_t +neu_bytedec_toDouble(neu_bytedec_t b) { + neu_word_t dec = 1; + for (int m = 0; m < b.decimal; m++) + dec *= 10; + return (((neu_double_t) (b.value % dec)) / dec + b.value / dec); +} + +neu_double_t +neu_ubytedec_toDouble(neu_ubytedec_t ub) { + neu_word_t dec = 1; + for (int m = 0; m < ub.decimal; m++) + dec *= 10; + return (((neu_double_t) (ub.value % dec)) / dec + ub.value / dec); +} + +neu_double_t +neu_worddec_toDouble(neu_worddec_t w) { + neu_word_t dec = 1; + for (int m = 0; m < w.decimal; m++) + dec *= 10; + return (((neu_double_t) (w.value % dec)) / dec + w.value / dec); +} + +neu_double_t +neu_uworddec_toDouble(neu_uworddec_t uw) { + neu_word_t dec = 1; + for (int m = 0; m < uw.decimal; m++) + dec *= 10; + return (((neu_double_t) (uw.value % dec)) / dec + uw.value / dec); +} + +neu_double_t +neu_dworddec_toDouble(neu_dworddec_t dw) { + neu_word_t dec = 1; + for (int m = 0; m < dw.decimal; m++) + dec *= 10; + return (((neu_double_t) (dw.value % dec)) / dec + dw.value / dec); +} + +neu_double_t +neu_udworddec_toDouble(neu_udworddec_t udw) { + neu_word_t dec = 1; + for (int m = 0; m < udw.decimal; m++) + dec *= 10; + return (((neu_double_t) (udw.value % dec)) / dec + udw.value / dec); +} + +neu_double_t +neu_qworddec_toDouble(neu_qworddec_t qw) { + neu_word_t dec = 1; + for (int m = 0; m < qw.decimal; m++) + dec *= 10; + return (((neu_double_t) (qw.value % dec)) / dec + qw.value / dec); +} + +neu_double_t +neu_uqworddec_toDouble(neu_uqworddec_t uqw) { + neu_word_t dec = 1; + for (int m = 0; m < uqw.decimal; m++) + dec *= 10; + return (((neu_double_t) (uqw.value % dec)) / dec + uqw.value / dec); +} + /****************/ /* String Types */ /****************/ -np_string_t -np_string_fromArray(char *array) { - np_string_t s; s.length = 0; s.charstr = NULL; +neu_string_t +neu_string_fromArray(char *array) { + neu_string_t s; s.length = 0; s.charstr = NULL; if(!array) return s; s.length = strlen(array); s.charstr = (char*)array; return s; } -np_string_t -np_string_fromChars(const char *src) { - np_string_t s; s.length = 0; s.charstr = NULL; +neu_string_t +neu_string_fromChars(const char *src) { + neu_string_t s; s.length = 0; s.charstr = NULL; if(!src) return s; s.length = strlen(src); if(s.length > 0) { - s.charstr = (np_ubyte_t*)UA_malloc(s.length); + s.charstr = (neu_ubyte_t*)malloc(s.length); if(!s.charstr) { s.length = 0; return s; @@ -52,67 +120,136 @@ np_string_fromChars(const char *src) { return s; } -np_order_t -np_string_isEqual(const np_string_t *s1, const np_string_t *s2) { +neu_order_t +neu_string_isEqual(const neu_string_t *s1, const neu_string_t *s2) { if(s1->length != s2->length) return false; if(s1->length == 0) return true; - np_dword_t is = memcmp((char const*)s1->charstr, + neu_dword_t is = memcmp((char const*)s1->charstr, (char const*)s2->charstr, s1->length); - return (is == 0) ? NP_ORDER_EQ : ((is > 0) ? NP_ORDER_MORE : NP_ORDER_LESS); + return (is == 0) ? NEU_ORDER_EQ : ((is > 0) ? NEU_ORDER_MORE : NEU_ORDER_LESS); } -const np_string_t NP_STRING_NULL = {0, NULL}; +const neu_string_t NEU_STRING_NULL = {0, NULL}; /**************/ /* Time Types */ /**************/ -np_time_t -np_time_now(void) { - return ((np_time_t) time(0)); +neu_time_t +neu_time_now(void) { + return ((neu_time_t) time(0)); } +neu_datetime_t +neu_time_getDateTime(neu_time_t t) { + const char days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + neu_datetime_t dt = {0}; + neu_udword_t pass4year; + neu_dword_t yearhours; + + dt.tm_sec = (int) (t % 60); t /= 60; + dt.tm_min = (int) (t % 60); t /= 60; + pass4year = t / (1461L * 24L); + + dt.tm_year = (pass4year << 2) + 1970; + t %= 1461L * 24L; + + while (1) { + yearhours = 365 * 24; + if ((dt.tm_year & 3) == 0) { + yearhours += 24; + } + if (t < yearhours) break; + dt.tm_year++; + t -= yearhours; + } + + dt.tm_hour = (int) (t % 24); + t /= 24; + t++; + + if ((dt.tm_year & 3) == 0) { + if (t > 60) { + t--; + } else { + if (t == 60) { + dt.tm_mon = 1; + dt.tm_mday = 29; + return dt; + } + } + } + for (dt.tm_mon = 0; days[dt.tm_mon] < t; dt.tm_mon++) { + t -= days[dt.tm_mon]; + } + dt.tm_mday = (int) (t); + return dt; +} + +neu_time_t +neu_time_fromDateTime(neu_datetime_t dt) { + const neu_udword_t mon_yday[2][12] = { + {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, + {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}, + }; + neu_word_t leap = ((dt.tm_year) % 4 == 0 && ((dt.tm_year) % 100 != 0 || (dt.tm_year) % 400 == 0)); + neu_udword_t ret = (dt.tm_year - 1970) * 365 * 24 * 3600; + ret += (mon_yday[leap][dt.tm_mon] + dt.tm_mday - 1) * 24 * 3600; + ret += dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; + + for (int i = 1970; i < dt.tm_year; i++) { + if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)) { + ret += 24 * 3600; + } + } + if (ret > 4107715199) {// 2100-02-29 23:59:59 + ret += 24 * 3600; + } + return (ret); +} + + /**************/ /* Uuid Types */ /**************/ -np_boolean_t -np_uuid_isEqual(const np_uuid_t *u1, const np_uuid_t *u2) { - if(memcmp(u1, u2, sizeof(np_uuid_t)) == 0) +neu_boolean_t +neu_uuid_isEqual(const neu_uuid_t *u1, const neu_uuid_t *u2) { + if(memcmp(u1, u2, sizeof(neu_uuid_t)) == 0) return true; return false; } -const np_uuid_t NP_UUID_NULL = {0, 0, 0, {0,0,0,0,0,0,0,0}}; +const neu_uuid_t NEU_UUID_NULL = {0, 0, 0, {0,0,0,0,0,0,0,0}}; /****************/ /* NodeId Types */ /****************/ -np_boolean_t -np_nodeid_isNull(const np_nodeid_t *n) { - if (np_string_isEqual(&n->identifier, &NP_STRING_NULL) == 0) +neu_boolean_t +neu_nodeid_isNull(const neu_nodeid_t *n) { + if (neu_string_isEqual(&n->identifier, &NEU_STRING_NULL) == 0) return true; return false; } /* Ordering for NodeIds */ -np_order_t -np_nodeid_order(const np_nodeid_t *n1, const np_nodeid_t *n2) { - return (np_string_isEqual(&n1->identifier, &n2->identifier)); +neu_order_t +neu_nodeid_order(const neu_nodeid_t *n1, const neu_nodeid_t *n2) { + return (neu_string_isEqual(&n1->identifier, &n2->identifier)); } -const np_nodeid_t NP_NODEID_NULL = {{{0, NULL}, {0, NULL}}, {0, NULL}}; +const neu_nodeid_t NEU_NODEID_NULL = {{{0, NULL}, {0, NULL}}, {0, NULL}}; /******************/ /* Variable Types */ /******************/ void -np_variable_setScalar(np_variable_t *v, void *p, - const np_variabletype_t *type) { +neu_variable_setScalar(neu_variable_t *v, void *p, + const neu_variabletype_t *type) { // init(v) to memset 0; v->type = type; v->arrayLength = 0; @@ -120,8 +257,8 @@ np_variable_setScalar(np_variable_t *v, void *p, } void -np_variable_setArray(np_variable_t *v, void *array, - size_t arraySize, const np_variabletype_t *type) { +neu_variable_setArray(neu_variable_t *v, void *array, + size_t arraySize, const neu_variabletype_t *type) { // init(v) to memset 0; v->data = array; v->arrayLength = arraySize;