| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #ifndef __PRJ_COM_H__
- #define __PRJ_COM_H__
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "stdint.h"
- /**
- * Get x sign bit only for little-endian
- * if x >= 0 then 0(false)
- * if x < 0 then -1(true)
- */
- #define IsNegative(x) ((sizeof(x)==4) ? *((int32_t *)&x)>>31 : \
- (sizeof(x)==2) ? *((int16_t *)&x)>>15 : \
- *((int8_t *)&x)>>7)
- #define IsPositive(x) (~IsNegative(x))
- #define BcdToOct(bcd) (((bcd) & 0x0f) + ((bcd) >> 4) * 10)
- #define OctToBcd(bcd) (((bcd / 10) <<4 ) + ((bcd) % 10))
- #define SET_BIT_WARN(data, bit) do{ (data) |= 1<<(bit); }while(0)
- #define RESET_BIT_WARN(data, bit) do{ (data) &= (~(1<<(bit))); }while(0)
- #define BIT_VAL(data, bit) (((data) & (1 << bit)) > 0 ? 1 : 0)
- typedef struct {
- uint16_t year;
- uint16_t month;
- uint16_t day;
- uint32_t hour;
- uint32_t min;
- uint32_t sec;
- }tm_t;
- extern void HexToStr(uint32_t Hex, char *Str, int16_t Len);
- extern int str2int(char *str, uint32_t *n);
- extern int str2float(char *str, float *f);
- extern void int2str(int n, char *str);
- extern void HexBufToStr(char *dest, unsigned char *src, int len);
- extern void StrToHexBuf(char *dest, char *src, int len);
- extern void num2str(char *str, float value, uint8_t g, uint8_t l);
- extern void ToggleEndian(uint8_t *src, uint8_t *dst, uint16_t width, uint16_t num);
- extern uint32_t com_crc32L_next(uint32_t crc_cur, uint8_t *data, uint32_t len, uint32_t pattern);
- extern uint16_t com_crc16L_next(uint16_t crc_cur, uint8_t *data, uint32_t len, uint16_t pattern);
- extern uint32_t com_crc32H_next(uint32_t crc_cur, uint8_t *data, uint32_t len, uint32_t pattern);
- extern uint16_t com_crc16H_next(uint16_t crc_cur, uint8_t *data, uint32_t len, uint16_t pattern);
- extern uint32_t strnchar(const char *src, char ch, int index);
- extern uint32_t strcntchar(const char *src, char ch);
- extern uint8_t is_leap(uint16_t year);
- extern uint8_t last_day_of_month(uint8_t year, uint8_t month);
- extern uint32_t days_from_leap_year_begin(uint8_t month, uint8_t day);
- extern uint32_t next_day(uint32_t date);
- extern uint32_t next_month(uint32_t date);
- extern uint32_t prev_month(uint32_t date);
- extern uint32_t prev_day(uint32_t date);
- extern void time_add_secs(tm_t *dest, tm_t *src, uint32_t secs);
- extern void time_sub_secs(tm_t *dest, tm_t *src, uint32_t secs);
- extern uint8_t check_sum(volatile uint8_t *data, uint16_t len);
- extern uint16_t check_sum_2_byte(volatile uint8_t *data, uint16_t len);//add by yuewei 20260304
- extern uint16_t crc16_modbus(volatile uint8_t *data, uint16_t length);//add by yuewei 20260317
- #ifdef __cplusplus
- }
- #endif
- #endif
|