Advertisement
Guest User

to jest to

a guest
Apr 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. unsigned char message[10]; // wiadomo�� z czujnika SDS011
  6.  
  7. int sds011Read(unsigned char *buf)
  8. {
  9. int state=1;
  10. int*code;
  11.  
  12. while(scanf("%x", &code))
  13. {
  14.  
  15. // Wprowadzenie 0 symuluje brak bajtu w buforze UART - tylko dla przetestowania pomiaru
  16. // czasu oczekiwania na kolejny bajt wiadomo�ci.
  17. // Potem usun��!
  18. if (code == 0x00)
  19. break;
  20. switch(state)
  21. {
  22. case 1:
  23. if(code != 0xAA)
  24. break;
  25. else
  26. {
  27. state++;
  28. break;
  29. }
  30. case 2:
  31. if(i<9)
  32. {
  33. buf[i]= (unsigned char) code;
  34. break;
  35. }
  36. if(i ==9 )
  37. {
  38. state=3;
  39. break;
  40. }
  41.  
  42. case 3:
  43. ;
  44. }
  45.  
  46.  
  47. }
  48.  
  49. return(0);
  50. }
  51.  
  52. int main()
  53. {
  54. unsigned int i;
  55. unsigned long int delay;
  56.  
  57. while(1)
  58. {
  59. if (sds011Read(message))
  60. {
  61. for(i = 0; i < sizeof(message); i++)
  62. printf("%02x ", message[i]);
  63. printf("\n");
  64. }
  65. for(delay = 10000000; delay; delay--);
  66. }
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement