AppFuncLib.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "hal_adapter.h"
  13. #include <stdarg.h>
  14. #include "stdio.h"
  15. #include <math.h>
  16. #ifndef va_copy
  17. #define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list))
  18. #endif
  19. uint16 GetErrorNum(uint16 *ErrorArray, uint8 Errorlen);
  20. uint8 PutErrorNum(uint16 *ErrorArray, uint8 Errorlen, uint16 ErrorNum);
  21. uint16 ATstrdel(char *str);
  22. uint16 mstrlen(const char *s);
  23. int mstrncmp(const char *s1, const char *s2, int n);
  24. unsigned char HexToChar(unsigned char bHex);
  25. unsigned char CharToHex(unsigned char bChar);
  26. uint8 AtStrCompare(const char *a, const char *b);
  27. unsigned short CRC16_Modbus(unsigned char *pdata, int len);
  28. uint8 bcc_chk(uint8 *data, uint16 length);
  29. char *Myitoa(int value, char *result, int base);
  30. // 整数转字符串
  31. int _itoa(int num, char buf[32]);
  32. int _i2a(int num, char buf[32], int radix);
  33. // 浮点转字符串
  34. int _ftoa(double val, char buf[32], int eps);
  35. // 浮点转字符串,范围(-1,1)
  36. int __ftoa(double val, char buf[32], int eps);
  37. // 替代sprintf
  38. int _sprintf(char *dst, const char *format, ...);
  39. // 串口校验
  40. uint16 crc_chk(uint8 *data, uint8 length);
  41. /*********************************************************************************************/
  42. #define SIZE_FFT 64
  43. typedef struct _fft_Freq
  44. {
  45. real_T freq;
  46. real_T amp;
  47. }fft_type;
  48. extern uint16_T ArrMax(uint16_T *Data, uint16_T m);
  49. extern uint16_T ArrMin(uint16_T *Data, uint16_T m);
  50. extern int16_T ArrMean(int16_T *Data, uint16_T n);
  51. extern real_T Saturation_r(real_T in, real_T LowLim, real_T UpLim);
  52. extern uint16_T Saturation_u(uint16_T in, uint16_T LowLim, uint16_T UpLim);
  53. extern uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim);
  54. extern uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_T Lim);
  55. extern uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0, const uint16_T *table, uint16_T MaxLen);
  56. extern uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table, uint16_T MaxLen);
  57. 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);
  58. 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);
  59. 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);
  60. extern boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr);
  61. extern void RaderReverse(creal_T *X, uint16_T N);
  62. extern void fft(real_T *S, uint16_T N, real_T freq, real_T *returnFreq, real_T *returnP);
  63. extern void cmul(creal_T a, creal_T b, creal_T *c);
  64. extern void cadd(creal_T a, creal_T b, creal_T *c);
  65. extern void csub(creal_T a, creal_T b, creal_T *c);
  66. /***********************************************************************************************/
  67. #endif /* APPFUNCLIB_H_ */