fork download
  1. #include <stdio.h>
  2. #include <string>
  3.  
  4. using namespace std;
  5. /*
  6.  0 1 2 3 4 5 6 7 8 9
  7. 8D 00 0A 0A 0A 09 0A 1E 0A 00 // clock version
  8. 8D 00 0A 0A 10 01 20 00 23 00 // ready for display
  9. 8D 00 0A 0A 10 0A 20 00 17 00 // Mode 23
  10. 8D 00 0A 0A 10 0A 0A 64 0A 00 // Mode 23
  11. */
  12.  
  13. int main()
  14. {
  15. char msg[10];
  16. int ackMessage_[5];
  17. string txt;
  18. int clockMode_ = 0; /**< The clock mode */
  19. int clockVersionMain_;
  20. int clockVersionSub_;
  21. msg[0] = 0x8d;
  22. msg[1] = 0x00;
  23. msg[2] = 0x0a;
  24. msg[3] = 0x0a;
  25. msg[4] = 0x10;
  26. msg[5] = 0x0a;
  27. msg[6] = 0x20;
  28. msg[7] = 0x00;
  29. msg[8] = 0x17;
  30. msg[9] = 0x00;
  31.  
  32. int length = (msg[1] << 7) | msg[2];
  33.  
  34. if (((msg[3] & 0x0f) == 0x0a) || ((msg[6] & 0x0f) == 0x0a))
  35. {
  36. ackMessage_[0] = ((msg[4]) & 0x7f) | ((msg[6] << 3) & 0x80);
  37. ackMessage_[1] = ((msg[5]) & 0x7f) | ((msg[6] << 2) & 0x80);
  38. ackMessage_[2] = ((msg[7]) & 0x7f) | ((msg[3] << 3) & 0x80);
  39. ackMessage_[3] = ((msg[8]) & 0x7f) | ((msg[3] << 2) & 0x80);
  40. ackMessage_[4] = 0;
  41.  
  42. if ((0x10 == ackMessage_[0]) && (0x00 == ackMessage_[2]))
  43. {
  44. switch (ackMessage_[1])
  45. {
  46. case 0x81: // Ready for disps
  47. clockMode_ = 0;
  48. printf("GENERATED ACK (ready)\n");
  49. break;
  50.  
  51. case 0x88: // Start/Stop button pressed
  52. clockMode_ = 0;
  53. printf("GENERATED ACK (mode, start/stop pressed)\n");
  54. break;
  55.  
  56. case 0x8a: // Clock mode
  57. clockMode_ = ackMessage_[3];
  58. printf("GENERATED ACK (mode)\n");
  59. break;
  60. }
  61. }
  62. else if ((0x00 != ackMessage_[0]) && (0x00 != ackMessage_[2]))
  63. {
  64. if (0x09 == ackMessage_[1])
  65. {
  66. // We found the version
  67. clockVersionMain_ = ackMessage_[2] / 16;
  68. clockVersionSub_ = ackMessage_[2] % 16;
  69.  
  70. printf("Clock Version: XL %02d.%02d\n" , clockVersionMain_ , clockVersionSub_);
  71. }
  72. else if ((0x10 == ackMessage_[0]) && (0x0a == ackMessage_[1]))
  73. {
  74. // We found a setnrun
  75. clockMode_ = 23;
  76. printf("SETNRUN (Clock Mode = 23)\n");
  77. }
  78. else
  79. {
  80. printf("ACK ERROR %02d\n", ackMessage_[0]);
  81. }
  82. }
  83.  
  84. printf("Clock Mode: %i txt: %s\n",clockMode_,txt.c_str());
  85. }
  86. else
  87. {
  88. int flagLeft_ = (msg[3] & 0x10) != 0;
  89. int timePerMoveLeft_ = (msg[3] & 0x20) != 0;
  90. int fallenLeft_ = (msg[3] & 0x40) != 0;
  91. int hoursLeft_ = msg[3] & 0x0f;
  92. int minutesLeft_ = ((msg[4] >> 4) * 10) + msg[4] % 16;
  93. int secondsLeft_ = ((msg[5] >> 4) * 10) + msg[5] % 16;
  94.  
  95. int flagRight_ = (msg[6] & 0x10) != 0;
  96. int timePerMoveRight_ = (msg[6] & 0x20) != 0;
  97. int fallenRight_ = (msg[6] && 0x40) != 0;
  98. int hoursRight_ = msg[6] & 0x0f;
  99. int minutesRight_ = ((msg[7] >> 4) * 10) + msg[7] % 16;
  100. int secondsRight_ = ((msg[8] >> 4) * 10) + msg[8] % 16;
  101.  
  102. int clockRunning_ = (msg[9] & 0x01) != 0;
  103. int leverLeft_ = (msg[9] & 0x02) != 0;
  104. int lowBattery_ = (msg[9] & 0x04) != 0;
  105. int turnBlack_ = (msg[9] & 0x08) != 0;
  106. int turnWhite_ = (msg[9] & 0x10) != 0;
  107. int noClock_ = (msg[9] & 0x20) != 0;
  108.  
  109. printf("flagLeft: %i timePerMoveLeft: %i fallenLeft: %i hoursLeft: %i minutesLeft: %i secondsLeft: %i flagRight: %i timePerMoveRight: %i fallenRight: %i hoursRight: %i minutesRight: %i secondsRight: %i \n clockRunning: %i leverLeft: %i lowBattery: %i turnBlack: %i turnWhite: %i noClock %i",
  110. flagLeft_,timePerMoveLeft_,fallenLeft_,hoursLeft_,minutesLeft_,secondsLeft_,flagRight_,timePerMoveRight_,fallenRight_,hoursRight_,minutesRight_,secondsRight_, clockRunning_, leverLeft_, lowBattery_, turnBlack_, turnWhite_, noClock_);
  111. }
  112.  
  113. //system("pause");
  114. return 0;
  115. }
  116.  
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:32: warning: unused variable ‘length’
stdout
GENERATED ACK (mode)
Clock Mode: 23 txt: