You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.cpp 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #define _POSIX_C_SOURCE 199309L
  2. #include <sys/time.h>
  3. #include <time.h>
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <signal.h>
  10. #include "gpio-raw.h"
  11. volatile unsigned n = 350000000 / sizeof(unsigned char);
  12. void signal_handler(int signo)
  13. {
  14. std::cout << "signal catched" << std::endl;
  15. n = 0;
  16. }
  17. int main(int argc, char* argv[])
  18. {
  19. setup_io();
  20. INP_GPIO(4);
  21. struct timeval t1, t2;
  22. unsigned char* v = new unsigned char[n];
  23. unsigned count = 0;
  24. std::cout << "Ready to sniff. Press enter...";
  25. getchar();
  26. signal(SIGINT, signal_handler);
  27. gettimeofday(&t1, NULL);
  28. for (; count < n; ++count)
  29. {
  30. const unsigned value = GPIO_LEV;
  31. v[count] = GPIO_VALUE_R(value, 6) | (GPIO_VALUE_R(value, 26) << 1);
  32. }
  33. gettimeofday(&t2, NULL);
  34. signal(SIGINT, SIG_DFL);
  35. unsigned long long ut1 = (__suseconds_t)(1000000L * t1.tv_sec + t1.tv_usec);
  36. unsigned long long ut2 = (__suseconds_t)(1000000L * t2.tv_sec + t2.tv_usec);
  37. unsigned long long diff = ut2 - ut1;
  38. double unit = (double)diff / count;
  39. double mhz = (1000000.0 / unit) / 1000000.0;
  40. std::cout << "count: " << count << " diff: " << diff << " unit: "
  41. << unit << " Mhz: " << mhz << std::endl;
  42. std::cout << "Saving file..." << std::endl;
  43. int fd = open("gpio.out", O_CREAT | O_WRONLY);
  44. write(fd, (void*)v, count * sizeof(*v));
  45. close(fd);
  46. return 0;
  47. }