fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define SLAVE_TIMEOUT_MS 50
  5. #define MSG_BUF_LEN 80
  6.  
  7. #define make8(v, b) ((b == 0) ? (uint8_t)(v & 0xFF) : (uint8_t)((v >> 8) & 0xFF))
  8.  
  9. int main(void)
  10. {
  11. uint16_t timeout_timer;
  12. uint16_t fstat;
  13. uint8_t msgbuf[MSG_BUF_LEN];
  14. uint8_t *mbptr;
  15. uint16_t fifo[] = {
  16. 0x6857, 0x6E65, 0x6920, 0x206E, 0x6874, 0x2065, 0x6F63, 0x7275,
  17. 0x6573, 0x6F20, 0x2066, 0x7568, 0x616D, 0x206E, 0x7665, 0x6E65,
  18. 0x7374, 0x202C, 0x7469, 0x6220, 0x6365, 0x6D6F, 0x7365, 0x6E20,
  19. 0x6365, 0x7365, 0x6173, 0x7972, 0x2E20, 0x2E2E, 0x0000, 0xFFFF
  20. };
  21. uint16_t *fptr;
  22.  
  23. for (timeout_timer = SLAVE_TIMEOUT_MS, mbptr = msgbuf, fptr = fifo; (timeout_timer > 0); )
  24. {
  25. fstat = *fptr;
  26.  
  27. if (fstat != 0xFFFF)
  28. {
  29. fstat = *fptr++;
  30. *mbptr++ = make8(fstat, 0);
  31. *mbptr = make8(fstat, 1);
  32.  
  33. if (*mbptr++ == 0)
  34. break;
  35.  
  36. timeout_timer = SLAVE_TIMEOUT_MS;
  37. }
  38. }
  39.  
  40. printf("%s\n", msgbuf);
  41. printf("msgbuf: %p mbptr: %p delta = %d strlen = %d\n",
  42. msgbuf, mbptr, mbptr - msgbuf, strlen(msgbuf));
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
When in the course of human events, it becomes necessary ...
msgbuf: 0x7ffcb463eb30  mbptr: 0x7ffcb463eb6e delta = 62 strlen = 60