recv.c 751 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "bus.h"
  6. #ifdef __linux__
  7. #define PIN_DATA 2
  8. #define PIN_CLK 3
  9. #define PIN_ACK 4
  10. int data[3]={0};
  11. #include "io.h"
  12. int main()
  13. {
  14. bus_t bus;
  15. pthread_t thread;
  16. FILE* file = NULL;
  17. struct timeval tv;
  18. setup_io();
  19. bus_init_recv(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
  20. init_read_pin(PIN_DATA, PIN_CLK, PIN_ACK);
  21. pthread_create(&thread, NULL, bus_recv_thread, &bus);
  22. while(1)
  23. {
  24. uint32_t c;
  25. double w;
  26. char buffer[16];
  27. bus_read(&bus, &c, 4);
  28. gettimeofday(&tv, NULL);
  29. printf("%ld' s %ld ms %'d us \n", c/1000000, c%1000000/1000, c%1000);
  30. w=3600.0/(((double)c)/1000000.0);
  31. printf("%ld : %.2lf W %.2lf\n\n", tv.tv_sec, w, w/220);
  32. }
  33. }
  34. #endif