diff --git a/config/TDMS_config.h b/config/TDMS_config.h index 40a5651..3e4d33d 100644 --- a/config/TDMS_config.h +++ b/config/TDMS_config.h @@ -29,14 +29,6 @@ extern "C" { #define TDMS_CONFIG_MAX_GROUP_OF_FILE 4 #define TDMS_CONFIG_MAX_CHANNEL_OF_GROUP 8 -/** - * @brief Determines system Endianness - * - 0: little-endian - * - 1: big-endian - */ -#define TDMS_CONFIG_SYSTEM_ENDIANNESS 0 - - #ifdef __cplusplus } diff --git a/src/TDMS.c b/src/TDMS.c index a8c91f4..c97aa15 100644 --- a/src/TDMS.c +++ b/src/TDMS.c @@ -81,7 +81,7 @@ /** * @brief Specify the number of days in the month * daysPerMonth[0][]: non leap year - * daysPerMonth[0][]: leap year + * daysPerMonth[1][]: leap year */ const int8_t daysPerMonth[2][13] = {{-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, @@ -147,8 +147,8 @@ const uint8_t dataTypeLength[TDMS_DataType_MAX] = /** * @brief Calculate number of days between LabVIEW Timestamp base and inserted * date - * @param Day: Day number (0 to 31) - * @param Month: Month number (0 to 12) + * @param Day: Day number (1 to 31) + * @param Month: Month number (1 to 12) * @param Year: Year number (1904 to ...) * @retval Number of days */ @@ -168,7 +168,7 @@ TDMS_DateDef(uint8_t Day, uint8_t Month, uint16_t Year) for (m = Month; m >= 1; m--) { if (m == Month) - total_days += Day; + total_days += Day - 1; else total_days += daysPerMonth[leapYear(y)][m]; } @@ -177,18 +177,12 @@ TDMS_DateDef(uint8_t Day, uint8_t Month, uint16_t Year) { for (m = 12; m >= BaseMonth; m--) { - if (m == BaseMonth) - total_days += daysPerMonth[leapYear(y)][m] - BaseDay; - else - total_days += daysPerMonth[leapYear(y)][m]; + total_days += daysPerMonth[leapYear(y)][m]; } } else { - for (m = 12; m >= 1; m--) - { - total_days += daysPerMonth[leapYear(y)][m]; - } + total_days += leapYear(y) ? 366 : 365; } } @@ -252,21 +246,9 @@ TDMS_GenerateChannelPath(TDMS_Group_t *Group, static uint8_t TDMS_SaveDataLittleEndian32(uint8_t *data, uint32_t value) { - typedef union - { - uint32_t Uint32Value; - uint8_t Uint8Value[4]; - } U32toU8_t; - - U32toU8_t Buffer = {.Uint32Value = value,}; - for (uint8_t i = 0; i < 4; i++) { -#if (TDMS_CONFIG_SYSTEM_ENDIANNESS == 0) - data[i] = Buffer.Uint8Value[i]; -#else - data[i] = Buffer.Uint8Value[4-i]; -#endif + data[i] = value >> (8*i); } return 4; @@ -282,21 +264,9 @@ TDMS_SaveDataLittleEndian32(uint8_t *data, uint32_t value) static uint8_t TDMS_SaveDataLittleEndian64(uint8_t *data, uint64_t value) { - typedef union - { - uint32_t Uint64Value; - uint8_t Uint8Value[8]; - } U64toU8_t; - - U64toU8_t Buffer = {.Uint64Value = value,}; - for (uint8_t i = 0; i < 8; i++) { -#if (TDMS_CONFIG_SYSTEM_ENDIANNESS == 0) - data[i] = Buffer.Uint8Value[i]; -#else - data[i] = Buffer.Uint8Value[8-i]; -#endif + data[i] = value >> (8*i); } return 8; diff --git a/src/include/TDMS.h b/src/include/TDMS.h index 9f07201..fea3b04 100644 --- a/src/include/TDMS.h +++ b/src/include/TDMS.h @@ -39,10 +39,6 @@ extern "C" { #define TDMS_CONFIG_MAX_CHANNEL_OF_GROUP 8 #endif -#ifndef TDMS_CONFIG_SYSTEM_ENDIANNESS - #define TDMS_CONFIG_SYSTEM_ENDIANNESS 0 -#endif - /* Exported Data Types ----------------------------------------------------------*/