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.
Dependents: Threaded_LoRa_Modem
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 } 00050 // ThisThread::sleep_for(1); 00051 YIELD; 00052 } 00053 return false; 00054 } 00055 00056 bool RHGenericDriver::waitPacketSent() 00057 { 00058 while (_mode == RHModeTx){ 00059 YIELD; // Wait for any previous transmit to finish 00060 } 00061 return true; 00062 } 00063 00064 bool RHGenericDriver::waitPacketSent(uint16_t timeout) 00065 { 00066 unsigned long starttime = millis(); 00067 while ((millis() - starttime) < timeout) 00068 { 00069 if (_mode != RHModeTx) // Any previous transmit finished? 00070 return true; 00071 YIELD; 00072 } 00073 return false; 00074 } 00075 00076 void RHGenericDriver::setPromiscuous(bool promiscuous) 00077 { 00078 _promiscuous = promiscuous; 00079 } 00080 00081 void RHGenericDriver::setThisAddress(uint8_t address) 00082 { 00083 _thisAddress = address; 00084 } 00085 00086 void RHGenericDriver::setHeaderTo(uint8_t to) 00087 { 00088 _txHeaderTo = to; 00089 } 00090 00091 void RHGenericDriver::setHeaderFrom(uint8_t from) 00092 { 00093 _txHeaderFrom = from; 00094 } 00095 00096 void RHGenericDriver::setHeaderId(uint8_t id) 00097 { 00098 _txHeaderId = id; 00099 } 00100 00101 void RHGenericDriver::setHeaderFlags(uint8_t set, uint8_t clear) 00102 { 00103 _txHeaderFlags &= ~clear; 00104 _txHeaderFlags |= set; 00105 } 00106 00107 uint8_t RHGenericDriver::headerTo() 00108 { 00109 return _rxHeaderTo; 00110 } 00111 00112 uint8_t RHGenericDriver::headerFrom() 00113 { 00114 return _rxHeaderFrom; 00115 } 00116 00117 uint8_t RHGenericDriver::headerId() 00118 { 00119 return _rxHeaderId; 00120 } 00121 00122 uint8_t RHGenericDriver::headerFlags() 00123 { 00124 return _rxHeaderFlags; 00125 } 00126 00127 int8_t RHGenericDriver::lastRssi() 00128 { 00129 return _lastRssi; 00130 } 00131 00132 RHGenericDriver::RHMode RHGenericDriver::mode() 00133 { 00134 return _mode; 00135 } 00136 00137 void RHGenericDriver::setMode(RHMode mode) 00138 { 00139 _mode = mode; 00140 } 00141 00142 bool RHGenericDriver::sleep() 00143 { 00144 return false; 00145 } 00146 00147 // Diagnostic help 00148 void RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_t len) 00149 { 00150 uint8_t i; 00151 00152 #ifdef RH_HAVE_SERIAL 00153 Serial.println(prompt); 00154 for (i = 0; i < len; i++) 00155 { 00156 if (i % 16 == 15) 00157 Serial.println(buf[i], HEX); 00158 else 00159 { 00160 Serial.print(buf[i], HEX); 00161 Serial.print(' '); 00162 } 00163 } 00164 Serial.println(""); 00165 #endif 00166 } 00167 00168 uint16_t RHGenericDriver::rxBad() 00169 { 00170 return _rxBad; 00171 } 00172 00173 uint16_t RHGenericDriver::rxGood() 00174 { 00175 return _rxGood; 00176 } 00177 00178 uint16_t RHGenericDriver::txGood() 00179 { 00180 return _txGood; 00181 } 00182 00183 #if (RH_PLATFORM == RH_PLATFORM_ARDUINO) && defined(RH_PLATFORM_ATTINY) 00184 // Tinycore does not have __cxa_pure_virtual, so without this we 00185 // get linking complaints from the default code generated for pure virtual functions 00186 extern "C" void __cxa_pure_virtual() 00187 { 00188 while (1); 00189 } 00190 #endif
Generated on Thu Jul 14 2022 12:14:49 by
1.7.2