Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. void search_frame()
  2. {
  3. if(Busy_Rx != Empty_Rx)
  4. {
  5. static char c;
  6. c = getchar_BuffRx();
  7. switch(frame_state)
  8. {
  9. case WAIT_START:
  10. {
  11. if(c == END)
  12. {
  13. clear_data();
  14. frame_state = MESSAGE;
  15. }
  16. break;
  17. }
  18. case MESSAGE:
  19. {
  20. if(c == END)
  21. {
  22. if(idx>0)
  23. {
  24. analyze_frame(command);
  25. clear_data();
  26. frame_state = MESSAGE;
  27. }
  28. else
  29. {
  30. clear_data();
  31. frame_state = MESSAGE;
  32. }
  33.  
  34. }
  35. else if(c == ESC)
  36. {
  37. frame_state = AFTER_ESCAPE;
  38. }
  39. else
  40. {
  41. command[idx] = c;
  42. if (idx>=256)
  43. {
  44. frame_state = WAIT_START;
  45. SendFrame("INVALID DATA E2");
  46. break;
  47. }
  48. else
  49. {
  50. idx++;
  51. }
  52. }
  53. break;
  54. }
  55. case AFTER_ESCAPE:
  56. {
  57.  
  58. if(c == ESC_END)
  59. {
  60. command[idx] = END;
  61. if (idx>=256)
  62. {
  63. USART_fsend("TUTAJ");
  64. frame_state = WAIT_START;
  65. SendFrame("INVALID DATA E2");
  66. break;
  67. }
  68. else
  69. {
  70. idx++;
  71. }
  72. }
  73. else if(c == ESC_ESC)
  74. {
  75. command[idx] = ESC;
  76. if (idx>=30)
  77. {
  78. frame_state = WAIT_START;
  79. SendFrame("INVALID DATA E2");
  80. break;
  81. }
  82. else
  83. {
  84. idx++;
  85. }
  86. }
  87. else if(c == END)
  88. {
  89.  
  90. clear_data();
  91. frame_state = MESSAGE;
  92. break;
  93. }
  94. else
  95. {
  96. frame_state = WAIT_START;
  97. SendFrame("INVALID DATA E3");
  98. break;
  99. }
  100. frame_state = MESSAGE;
  101. break;
  102. }
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement