AppFuncLib.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * AppFuncLib.c
  3. *
  4. * Created on: 2022年1月21日
  5. * Author: QiXiang_CHENJIE
  6. */
  7. #include "AppFuncLib.h"
  8. uint16 ATstrdel(char *str)
  9. {
  10. char *p = str;
  11. bool flag = false;
  12. while (*str)
  13. {
  14. if (*str > 0x20)
  15. {
  16. *(p) = *str;
  17. p = p + 1;
  18. flag = false;
  19. }
  20. else
  21. {
  22. if (!flag)
  23. {
  24. *(p) = ',';
  25. p = p + 1;
  26. flag = true;
  27. }
  28. }
  29. str++;
  30. }
  31. *p = '\0';
  32. return 0;
  33. }
  34. uint16 mstrlen(const char *s)
  35. {
  36. const char *ss = s;
  37. while (*ss)
  38. ss++;
  39. return (ss - s);
  40. }
  41. int mstrncmp(const char *s1, const char *s2, int n)
  42. {
  43. const unsigned char *c1 = (const unsigned char *)s1;
  44. const unsigned char *c2 = (const unsigned char *)s2;
  45. unsigned char ch;
  46. int d = 0;
  47. while (n--)
  48. {
  49. d = (int)(ch = *c1++) - (int)*c2++;
  50. if (d || !ch)
  51. break;
  52. }
  53. return d;
  54. }
  55. unsigned char HexToChar(unsigned char bHex)
  56. {
  57. if ((bHex >= 0) && (bHex <= 9))
  58. bHex += 0x30;
  59. else if ((bHex >= 10) && (bHex <= 15)) //大写字母
  60. bHex += 0x37;
  61. else
  62. bHex = 0xff;
  63. return bHex;
  64. }
  65. unsigned char CharToHex(unsigned char bChar)
  66. {
  67. if ((bChar >= 0x30) && (bChar <= 0x39))
  68. bChar -= 0x30;
  69. else if ((bChar >= 0x41) && (bChar <= 0x46)) //大写字母
  70. bChar -= 0x37;
  71. else if ((bChar >= 0x61) && (bChar <= 0x66)) //小写字母
  72. bChar -= 0x57;
  73. else
  74. bChar = 0xff;
  75. return bChar;
  76. }