AppFuncLib.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /***
  2. * @Author: chenjie
  3. * @Date: 2022-06-06
  4. * @LastEditTime: 2022-11-10
  5. * @LastEditors: chenjie
  6. * @Description:
  7. * @FilePath: \S32K146_4G\code\app\lib\AppFuncLib.h
  8. * @Copyright (c) 2022 by chenjie, All Rights Reserved.
  9. */
  10. #ifndef APPFUNCLIB_H_
  11. #define APPFUNCLIB_H_
  12. #include <stdarg.h>
  13. #include "stdio.h"
  14. #include <math.h>
  15. #include "rtwtypes.h"
  16. #ifndef va_copy
  17. #define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list))
  18. #endif
  19. #ifndef min
  20. #define min(A, B) ((A) <= (B) ? (A) : (B))
  21. #endif
  22. #ifndef max
  23. #define max(A, B) ((A) < (B) ? (B) : (A))
  24. #endif
  25. #define getbit(x, y) ((x) >> (y)&1) // 获取x的第y位的数值
  26. #define setbit(x, y) x |= (1 << y) // x的第y位置1
  27. #define clrbit(x, y) x &= ~(1 << y) // x的第y位置0
  28. uint16_t GetErrorNum(uint16_t *ErrorArray, uint8_t Errorlen);
  29. uint8_t PutErrorNum(uint16_t *ErrorArray, uint8_t Errorlen, uint16_t ErrorNum);
  30. uint16_t ATstrdel(char *str);
  31. uint16_t mstrlen(const char *s);
  32. int mstrncmp(const char *s1, const char *s2, int n);
  33. unsigned char HexToChar(unsigned char bHex);
  34. unsigned char CharToHex(unsigned char bChar);
  35. uint8_t AtStrCompare(const char *a, const char *b);
  36. unsigned short CRC16_Modbus(unsigned char *pdata, int len);
  37. uint8_t bcc_chk(uint8_t *data, uint16_t length);
  38. char *Myitoa(int value, char *result, int base);
  39. // 整数转字符串
  40. int _itoa(int num, char buf[32]);
  41. int _i2a(int num, char buf[32], int radix);
  42. // 浮点转字符串
  43. int _ftoa(double val, char buf[32], int eps);
  44. // 浮点转字符串,范围(-1,1)
  45. int __ftoa(double val, char buf[32], int eps);
  46. // 替代sprintf
  47. int _sprintf(char *dst, const char *format, ...);
  48. // 串口校验
  49. uint16_t crc_chk(uint8_t *data, uint8_t length);
  50. /*********************************************************************************************/
  51. #define SIZE_FFT 64
  52. typedef struct _fft_Freq
  53. {
  54. real_T freq;
  55. real_T amp;
  56. }fft_type;
  57. extern uint16_T ArrMax(uint16_T *Data, uint16_t m);
  58. extern uint16_T ArrMin(uint16_T *Data, uint16_T m);
  59. extern int16_T ArrMean(int16_T *Data, uint16_T n);
  60. extern real_T Saturation_r(real_T in, real_T LowLim, real_T UpLim);
  61. extern uint16_T Saturation_u(uint16_T in, uint16_T LowLim, uint16_T UpLim);
  62. extern uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim);
  63. extern uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_T Lim);
  64. extern uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0, const uint16_T *table, uint16_T MaxLen);
  65. extern uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table, uint16_T MaxLen);
  66. extern uint16_T look2_u16u16tu16(uint16_T x, uint16_T y, const uint16_T xTable[], const uint16_T yTable[], const uint16_T zTable[], uint16_T xLen, uint16_T yLen);
  67. extern boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
  68. extern boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
  69. extern boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr);
  70. extern void RaderReverse(creal_T *X, uint16_T N);
  71. extern void fft(real_T *S, uint16_T N, real_T freq, real_T *returnFreq, real_T *returnP);
  72. extern void cmul(creal_T a, creal_T b, creal_T *c);
  73. extern void cadd(creal_T a, creal_T b, creal_T *c);
  74. extern void csub(creal_T a, creal_T b, creal_T *c);
  75. /***********************************************************************************************/
  76. #endif /* APPFUNCLIB_H_ */