Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
RHGenericDriver.cpp
00001 // RHGenericDriver.cpp 00002 // 00003 // Copyright (C) 2014 Mike McCauley 00004 // $Id: RHGenericDriver.cpp,v 1.18 2015/01/02 21:38:24 mikem Exp $ 00005 00006 #include <RHGenericDriver.h> 00007 00008 Timer _millisTimer; 00009 00010 RHGenericDriver::RHGenericDriver() 00011 : 00012 _mode(RHModeInitialising), 00013 _thisAddress(RH_BROADCAST_ADDRESS), 00014 _txHeaderTo(RH_BROADCAST_ADDRESS), 00015 _txHeaderFrom(RH_BROADCAST_ADDRESS), 00016 _txHeaderId(0), 00017 _txHeaderFlags(0), 00018 _rxBad(0), 00019 _rxGood(0), 00020 _txGood(0) 00021 { 00022 #if (RH_PLATFORM == RH_PLATFORM_MBED) 00023 _millisTimer.start(); 00024 #endif 00025 } 00026 00027 bool RHGenericDriver::init() 00028 { 00029 return true; 00030 } 00031 00032 // Blocks until a valid message is received 00033 void RHGenericDriver::waitAvailable() 00034 { 00035 while (!available()) 00036 YIELD; 00037 } 00038 00039 // Blocks until a valid message is received or timeout expires 00040 // Return true if there is a message available 00041 // Works correctly even on millis() rollover 00042 bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout) 00043 { 00044 unsigned long starttime = millis(); 00045 while ((millis() - starttime) < timeout) 00046 { 00047 if (available()) 00048 return true; 00049 YIELD; 00050 } 00051 return false; 00052 } 00053 00054 bool RHGenericDriver::waitPacketSent() 00055 { 00056 while (_mode == RHModeTx) 00057 YIELD; // Wait for any previous transmit to finish 00058 return true; 00059 } 00060 00061 bool RHGenericDriver::waitPacketSent(uint16_t timeout) 00062 { 00063 unsigned long starttime = millis(); 00064 while ((millis() - starttime) < timeout) 00065 { 00066 if (_mode != RHModeTx) // Any previous transmit finished? 00067 return true; 00068 YIELD; 00069 } 00070 return false; 00071 } 00072 00073 void RHGenericDriver::setPromiscuous(bool promiscuous) 00074 { 00075 _promiscuous = promiscuous; 00076 } 00077 00078 void RHGenericDriver::setThisAddress(uint8_t address) 00079 { 00080 _thisAddress = address; 00081 } 00082 00083 void RHGenericDriver::setHeaderTo(uint8_t to) 00084 { 00085 _txHeaderTo = to; 00086 } 00087 00088 void RHGenericDriver::setHeaderFrom(uint8_t from) 00089 { 00090 _txHeaderFrom = from; 00091 } 00092 00093 void RHGenericDriver::setHeaderId(uint8_t id) 00094 { 00095 _txHeaderId = id; 00096 } 00097 00098 void RHGenericDriver::setHeaderFlags(uint8_t set, uint8_t clear) 00099 { 00100 _txHeaderFlags &= ~clear; 00101 _txHeaderFlags |= set; 00102 } 00103 00104 uint8_t RHGenericDriver::headerTo() 00105 { 00106 return _rxHeaderTo; 00107 } 00108 00109 uint8_t RHGenericDriver::headerFrom() 00110 { 00111 return _rxHeaderFrom; 00112 } 00113 00114 uint8_t RHGenericDriver::headerId() 00115 { 00116 return _rxHeaderId; 00117 } 00118 00119 uint8_t RHGenericDriver::headerFlags() 00120 { 00121 return _rxHeaderFlags; 00122 } 00123 00124 int8_t RHGenericDriver::lastRssi() 00125 { 00126 return _lastRssi; 00127 } 00128 00129 RHGenericDriver::RHMode RHGenericDriver::mode() 00130 { 00131 return _mode; 00132 } 00133 00134 void RHGenericDriver::setMode(RHMode mode) 00135 { 00136 _mode = mode; 00137 } 00138 00139 bool RHGenericDriver::sleep() 00140 { 00141 return false; 00142 } 00143 00144 // Diagnostic help 00145 void RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_t len) 00146 { 00147 uint8_t i; 00148 00149 #ifdef RH_HAVE_SERIAL 00150 Serial.println(prompt); 00151 for (i = 0; i < len; i++) 00152 { 00153 if (i % 16 == 15) 00154 Serial.println(buf[i], HEX); 00155 else 00156 { 00157 Serial.print(buf[i], HEX); 00158 Serial.print(' '); 00159 } 00160 } 00161 Serial.println(""); 00162 #endif 00163 } 00164 00165 uint16_t RHGenericDriver::rxBad() 00166 { 00167 return _rxBad; 00168 } 00169 00170 uint16_t RHGenericDriver::rxGood() 00171 { 00172 return _rxGood; 00173 } 00174 00175 uint16_t RHGenericDriver::txGood() 00176 { 00177 return _txGood; 00178 } 00179 00180 #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(RH_PLATFORM_ATTINY) 00181 // Tinycore does not have __cxa_pure_virtual, so without this we 00182 // get linking complaints from the default code generated for pure virtual functions 00183 extern "C" void __cxa_pure_virtual() 00184 { 00185 while (1); 00186 } 00187 #endif
Generated on Tue Jul 12 2022 18:05:56 by
