/*** * @Author: * @Date: 2023-04-04 08:13:11 * @LastEditors: xxx * @LastEditTime: 2023-04-04 10:13:21 * @Description: * @email: * @Copyright (c) 2023 by xxx, All Rights Reserved. */ #ifndef __LIB_H #define __LIB_H #include #include #include #include "data_type_def.h" #include "malloc.h" #include "data_analysis.h" #include "osel_arch.h" #include "debug.h" #include "sqqueue.h" #include "clist.h" #define INTERNAL_EXTERN extern #ifndef STM32 #include "log.h" #else #define LOG_PRINT(fmt, ...) \ do \ { \ } while (0); #define LOG_ERR(fmt, ...) \ do \ { \ } while (0); #define LOG_HEX(data, len) \ do \ { \ } while (0); #endif #define EXIT(x) \ do \ { \ DBG_ASSERT(FALSE, __DBG_LINE); \ } while (0); ////< 时间结构 typedef union { uint8_t data[6]; struct { uint8_t year; uint8_t month; uint8_t day; uint8_t hour; uint8_t minute; uint8_t second; } date; } date_time_t; typedef struct { uint16_t year; uint8_t month; uint8_t day; } rtc_date_t; typedef struct { uint8_t hour; uint8_t minute; uint8_t second; } rtc_time_t; typedef struct { float32 x; float32 y; } point_t; typedef struct { float32 a; float32 b; } linear_func_param_t; #define S_CURVE_POINTS 70 typedef struct { float32 start; float32 end; float32 current; float32 t[S_CURVE_POINTS]; uint16_t index; } s_curve_generator_t; extern void assic_to_str(uint8_t *assic, uint8_t len, uint8_t *str); // ASCII码转字符串 extern void get_cpu_id(uint32_t *id); // 获取CPU ID extern uint32_t cpu_encrypt(void); // CPU加密 extern BOOL cpu_judge_encrypt(uint32_t cupid_encrypt); // CPU判断加密 extern void version_split(uint8_t *version, uint8_t *hi, uint8_t *lo); // 版本号1.0拆解成1和0 extern void reverse(uint8_t *buf, uint16_t len); // 反序数组 extern BOOL is_in_array(uint16_t *arr, uint16_t len, uint16_t val); // 判断val是否在数组arr中 extern BOOL is_same_value(uint8_t *buf, uint16_t len, uint8_t value); // 判断数组中的值是否都相等 extern uint16_t crc16_compute(const uint8_t *const data, uint16_t length); // CRC16校验 extern uint32_t crc32_compute(const uint8_t *const data, uint16_t length); // CRC32校验 extern uint64_t crc64_compute(const uint8_t *const data, const uint16_t length); // CRC64校验 extern uint8_t xor_compute(const uint8_t *const data, uint16_t length); // 异或校验 extern uint8_t get_bit_num(uint8_t bit); // 获取bit位的值 extern BOOL is_bit_set(int x, int k); // 判断x的第k位是否为1 extern uint8_t is_leap_year(uint16_t year); // 检查是否是闰年 extern BOOL is_valid_date(uint8_t year, uint8_t month, uint8_t day); // 检查日期是否有效 extern BOOL is_valid_time(uint8_t hour, uint8_t minute, uint8_t second); // 检查时间是否有效 extern BOOL is_valid_datetime(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); // 检查日期和时间是否有效 extern uint32_t days_since_1970(uint16_t year, uint8_t month, uint8_t day); // 计算从1970年1月1日到给定年月日的天数 extern uint32_t date_to_seconds(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second); // 将日期转换为秒数 extern void seconds_to_date(uint32_t total_seconds, rtc_date_t *date, rtc_time_t *time); // 将秒数转换为日期 extern uint16_t dayOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几天 extern uint16_t weekOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几周 extern uint8_t get_weekday(uint16_t year, uint8_t month, uint8_t day); // 获取今天星期几 extern uint8_t hex_format_dec(uint8_t hex); // 十六进制转十进制 extern uint8_t dec_format_hex(uint8_t dec); // 十进制转十六进制 extern void quicksort(uint16_t arr[], int low, int high); // 快速排序 extern void insertion_sort(uint16_t arr[], uint16_t n); // 插入排序 extern uint32_t time2stamp(const rtc_date_t *const date, const rtc_time_t *const time); // 日期时间转时间戳 extern void stamp2time(uint32_t stamp, rtc_date_t *date, rtc_time_t *time); // 时间戳转北京时间 extern void convert_seconds(uint32_t total_seconds, char *date); // 秒数转换成时分秒 extern void add_commas(uint32_t num, char *result); // 数字添加逗号 extern linear_func_param_t calculate_linear_regression(const point_t *points, int32_t count); // 计算线性回归 extern float32 get_linearity_value(const point_t *points, int32_t count, linear_func_param_t param); // 获取线性度 void s_curve_generator_init(s_curve_generator_t *gen, float32 start); float32 s_curve_generate_point(s_curve_generator_t *gen, float32 target); #endif //__LIB_H