binary.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. voltlogger_oscilloscope
  3. Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <assert.h> /* assert() */
  16. #include <unistd.h>
  17. #include <stdio.h>
  18. #include "configuration.h"
  19. #include "binary.h"
  20. #define DECLARE_GET_X_t(x) \
  21. x ## _t get_ ## x (FILE *i_f) { \
  22. x ## _t r; \
  23. \
  24. \
  25. if (fread(&r, sizeof(r), 1, i_f) < 1) { \
  26. while (feof(i_f)) { \
  27. usleep(AUTOUPDATE_USECS);\
  28. clearerr(i_f);\
  29. if (fread(&r, sizeof(r), 1, i_f) < 1 && !feof(i_f))\
  30. assert (ferror(i_f)); \
  31. return r;\
  32. } \
  33. assert (ferror(i_f)); \
  34. } \
  35. \
  36. return r; \
  37. }
  38. DECLARE_GET_X_t(uint64);
  39. DECLARE_GET_X_t(uint32);
  40. DECLARE_GET_X_t(uint16);
  41. DECLARE_GET_X_t(uint8);