PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RHGenericDriver.cpp 3.2KB

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // RHGenericDriver.cpp
  2. //
  3. // Copyright (C) 2014 Mike McCauley
  4. // $Id: RHGenericDriver.cpp,v 1.19 2015/12/11 01:10:24 mikem Exp $
  5. #include <RHGenericDriver.h>
  6. RHGenericDriver::RHGenericDriver()
  7. :
  8. _mode(RHModeInitialising),
  9. _thisAddress(RH_BROADCAST_ADDRESS),
  10. _txHeaderTo(RH_BROADCAST_ADDRESS),
  11. _txHeaderFrom(RH_BROADCAST_ADDRESS),
  12. _txHeaderId(0),
  13. _txHeaderFlags(0),
  14. _rxBad(0),
  15. _rxGood(0),
  16. _txGood(0)
  17. {
  18. }
  19. bool RHGenericDriver::init()
  20. {
  21. return true;
  22. }
  23. // Blocks until a valid message is received
  24. void RHGenericDriver::waitAvailable()
  25. {
  26. while (!available())
  27. YIELD;
  28. }
  29. // Blocks until a valid message is received or timeout expires
  30. // Return true if there is a message available
  31. // Works correctly even on millis() rollover
  32. bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)
  33. {
  34. unsigned long starttime = millis();
  35. while ((millis() - starttime) < timeout)
  36. {
  37. if (available())
  38. {
  39. return true;
  40. }
  41. YIELD;
  42. }
  43. return false;
  44. }
  45. bool RHGenericDriver::waitPacketSent()
  46. {
  47. while (_mode == RHModeTx)
  48. YIELD; // Wait for any previous transmit to finish
  49. return true;
  50. }
  51. bool RHGenericDriver::waitPacketSent(uint16_t timeout)
  52. {
  53. unsigned long starttime = millis();
  54. while ((millis() - starttime) < timeout)
  55. {
  56. if (_mode != RHModeTx) // Any previous transmit finished?
  57. return true;
  58. YIELD;
  59. }
  60. return false;
  61. }
  62. void RHGenericDriver::setPromiscuous(bool promiscuous)
  63. {
  64. _promiscuous = promiscuous;
  65. }
  66. void RHGenericDriver::setThisAddress(uint8_t address)
  67. {
  68. _thisAddress = address;
  69. }
  70. void RHGenericDriver::setHeaderTo(uint8_t to)
  71. {
  72. _txHeaderTo = to;
  73. }
  74. void RHGenericDriver::setHeaderFrom(uint8_t from)
  75. {
  76. _txHeaderFrom = from;
  77. }
  78. void RHGenericDriver::setHeaderId(uint8_t id)
  79. {
  80. _txHeaderId = id;
  81. }
  82. void RHGenericDriver::setHeaderFlags(uint8_t set, uint8_t clear)
  83. {
  84. _txHeaderFlags &= ~clear;
  85. _txHeaderFlags |= set;
  86. }
  87. uint8_t RHGenericDriver::headerTo()
  88. {
  89. return _rxHeaderTo;
  90. }
  91. uint8_t RHGenericDriver::headerFrom()
  92. {
  93. return _rxHeaderFrom;
  94. }
  95. uint8_t RHGenericDriver::headerId()
  96. {
  97. return _rxHeaderId;
  98. }
  99. uint8_t RHGenericDriver::headerFlags()
  100. {
  101. return _rxHeaderFlags;
  102. }
  103. int8_t RHGenericDriver::lastRssi()
  104. {
  105. return _lastRssi;
  106. }
  107. RHGenericDriver::RHMode RHGenericDriver::mode()
  108. {
  109. return _mode;
  110. }
  111. void RHGenericDriver::setMode(RHMode mode)
  112. {
  113. _mode = mode;
  114. }
  115. bool RHGenericDriver::sleep()
  116. {
  117. return false;
  118. }
  119. // Diagnostic help
  120. void RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_t len)
  121. {
  122. uint8_t i;
  123. #ifdef RH_HAVE_SERIAL
  124. Serial.println(prompt);
  125. for (i = 0; i < len; i++)
  126. {
  127. if (i % 16 == 15)
  128. Serial.println(buf[i], HEX);
  129. else
  130. {
  131. Serial.print(buf[i], HEX);
  132. Serial.print(' ');
  133. }
  134. }
  135. Serial.println("");
  136. #endif
  137. }
  138. uint16_t RHGenericDriver::rxBad()
  139. {
  140. return _rxBad;
  141. }
  142. uint16_t RHGenericDriver::rxGood()
  143. {
  144. return _rxGood;
  145. }
  146. uint16_t RHGenericDriver::txGood()
  147. {
  148. return _txGood;
  149. }
  150. #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(RH_PLATFORM_ATTINY)
  151. // Tinycore does not have __cxa_pure_virtual, so without this we
  152. // get linking complaints from the default code generated for pure virtual functions
  153. extern "C" void __cxa_pure_virtual()
  154. {
  155. while (1);
  156. }
  157. #endif