sforkowany z mirror/meshtastic-firmware
autoformat per formatting rules
rodzic
8eb3045451
commit
176532f55f
|
@ -6,17 +6,8 @@
|
||||||
#include <RHGenericDriver.h>
|
#include <RHGenericDriver.h>
|
||||||
|
|
||||||
RHGenericDriver::RHGenericDriver()
|
RHGenericDriver::RHGenericDriver()
|
||||||
:
|
: _mode(RHModeInitialising), _thisAddress(RH_BROADCAST_ADDRESS), _txHeaderTo(RH_BROADCAST_ADDRESS),
|
||||||
_mode(RHModeInitialising),
|
_txHeaderFrom(RH_BROADCAST_ADDRESS), _txHeaderId(0), _txHeaderFlags(0), _rxBad(0), _rxGood(0), _txGood(0), _cad_timeout(0)
|
||||||
_thisAddress(RH_BROADCAST_ADDRESS),
|
|
||||||
_txHeaderTo(RH_BROADCAST_ADDRESS),
|
|
||||||
_txHeaderFrom(RH_BROADCAST_ADDRESS),
|
|
||||||
_txHeaderId(0),
|
|
||||||
_txHeaderFlags(0),
|
|
||||||
_rxBad(0),
|
|
||||||
_rxGood(0),
|
|
||||||
_txGood(0),
|
|
||||||
_cad_timeout(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +20,7 @@ bool RHGenericDriver::init()
|
||||||
void RHGenericDriver::waitAvailable()
|
void RHGenericDriver::waitAvailable()
|
||||||
{
|
{
|
||||||
while (!available())
|
while (!available())
|
||||||
YIELD;
|
YIELD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocks until a valid message is received or timeout expires
|
// Blocks until a valid message is received or timeout expires
|
||||||
|
@ -38,13 +29,11 @@ void RHGenericDriver::waitAvailable()
|
||||||
bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)
|
bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)
|
||||||
{
|
{
|
||||||
unsigned long starttime = millis();
|
unsigned long starttime = millis();
|
||||||
while ((millis() - starttime) < timeout)
|
while ((millis() - starttime) < timeout) {
|
||||||
{
|
if (available()) {
|
||||||
if (available())
|
return true;
|
||||||
{
|
}
|
||||||
return true;
|
YIELD;
|
||||||
}
|
|
||||||
YIELD;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -52,18 +41,17 @@ bool RHGenericDriver::waitAvailableTimeout(uint16_t timeout)
|
||||||
bool RHGenericDriver::waitPacketSent()
|
bool RHGenericDriver::waitPacketSent()
|
||||||
{
|
{
|
||||||
while (_mode == RHModeTx)
|
while (_mode == RHModeTx)
|
||||||
YIELD; // Wait for any previous transmit to finish
|
YIELD; // Wait for any previous transmit to finish
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RHGenericDriver::waitPacketSent(uint16_t timeout)
|
bool RHGenericDriver::waitPacketSent(uint16_t timeout)
|
||||||
{
|
{
|
||||||
unsigned long starttime = millis();
|
unsigned long starttime = millis();
|
||||||
while ((millis() - starttime) < timeout)
|
while ((millis() - starttime) < timeout) {
|
||||||
{
|
|
||||||
if (_mode != RHModeTx) // Any previous transmit finished?
|
if (_mode != RHModeTx) // Any previous transmit finished?
|
||||||
return true;
|
return true;
|
||||||
YIELD;
|
YIELD;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +60,7 @@ bool RHGenericDriver::waitPacketSent(uint16_t timeout)
|
||||||
bool RHGenericDriver::waitCAD()
|
bool RHGenericDriver::waitCAD()
|
||||||
{
|
{
|
||||||
if (!_cad_timeout)
|
if (!_cad_timeout)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Wait for any channel activity to finish or timeout
|
// Wait for any channel activity to finish or timeout
|
||||||
// Sophisticated DCF function...
|
// Sophisticated DCF function...
|
||||||
|
@ -80,14 +68,13 @@ bool RHGenericDriver::waitCAD()
|
||||||
// 100 - 1000 ms
|
// 100 - 1000 ms
|
||||||
// 10 sec timeout
|
// 10 sec timeout
|
||||||
unsigned long t = millis();
|
unsigned long t = millis();
|
||||||
while (isChannelActive())
|
while (isChannelActive()) {
|
||||||
{
|
if (millis() - t > _cad_timeout)
|
||||||
if (millis() - t > _cad_timeout)
|
return false;
|
||||||
return false;
|
|
||||||
#if (RH_PLATFORM == RH_PLATFORM_STM32) // stdlib on STMF103 gets confused if random is redefined
|
#if (RH_PLATFORM == RH_PLATFORM_STM32) // stdlib on STMF103 gets confused if random is redefined
|
||||||
delay(_random(1, 10) * 100);
|
delay(_random(1, 10) * 100);
|
||||||
#else
|
#else
|
||||||
delay(random(1, 10) * 100); // Should these values be configurable? Macros?
|
delay(random(1, 10) * 100); // Should these values be configurable? Macros?
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,36 +143,34 @@ int16_t RHGenericDriver::lastRssi()
|
||||||
return _lastRssi;
|
return _lastRssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
RHGenericDriver::RHMode RHGenericDriver::mode()
|
RHGenericDriver::RHMode RHGenericDriver::mode()
|
||||||
{
|
{
|
||||||
return _mode;
|
return _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RHGenericDriver::setMode(RHMode mode)
|
void RHGenericDriver::setMode(RHMode mode)
|
||||||
{
|
{
|
||||||
_mode = mode;
|
_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RHGenericDriver::sleep()
|
bool RHGenericDriver::sleep()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diagnostic help
|
// Diagnostic help
|
||||||
void RHGenericDriver::printBuffer(const char* prompt, const uint8_t* buf, uint8_t len)
|
void RHGenericDriver::printBuffer(const char *prompt, const uint8_t *buf, uint8_t len)
|
||||||
{
|
{
|
||||||
#ifdef RH_HAVE_SERIAL
|
#ifdef RH_HAVE_SERIAL
|
||||||
Serial.println(prompt);
|
Serial.println(prompt);
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++) {
|
||||||
{
|
if (i % 16 == 15)
|
||||||
if (i % 16 == 15)
|
Serial.println(buf[i], HEX);
|
||||||
Serial.println(buf[i], HEX);
|
else {
|
||||||
else
|
Serial.print(buf[i], HEX);
|
||||||
{
|
Serial.print(' ');
|
||||||
Serial.print(buf[i], HEX);
|
}
|
||||||
Serial.print(' ');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
#endif
|
#endif
|
||||||
|
@ -216,6 +201,7 @@ void RHGenericDriver::setCADTimeout(unsigned long cad_timeout)
|
||||||
// get linking complaints from the default code generated for pure virtual functions
|
// get linking complaints from the default code generated for pure virtual functions
|
||||||
extern "C" void __cxa_pure_virtual()
|
extern "C" void __cxa_pure_virtual()
|
||||||
{
|
{
|
||||||
while (1);
|
while (1)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Ładowanie…
Reference in New Issue