mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 19:20:41 +00:00
Log levels refactoring
This commit is contained in:
@@ -46,7 +46,7 @@ class ESP32CryptoEngine : public CryptoEngine
|
||||
static uint8_t scratch[MAX_BLOCKSIZE];
|
||||
size_t nc_off = 0;
|
||||
|
||||
DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
LOG_DEBUG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
initNonce(fromNode, packetId);
|
||||
assert(numBytes <= MAX_BLOCKSIZE);
|
||||
memcpy(scratch, bytes, numBytes);
|
||||
|
||||
@@ -66,17 +66,17 @@ void enableSlowCLK()
|
||||
uint32_t cal_32k = CALIBRATE_ONE(RTC_CAL_32K_XTAL);
|
||||
|
||||
if (cal_32k == 0) {
|
||||
DEBUG_MSG("32K XTAL OSC has not started up\n");
|
||||
LOG_DEBUG("32K XTAL OSC has not started up\n");
|
||||
} else {
|
||||
rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);
|
||||
DEBUG_MSG("Switching RTC Source to 32.768Khz succeeded, using 32K XTAL\n");
|
||||
LOG_DEBUG("Switching RTC Source to 32.768Khz succeeded, using 32K XTAL\n");
|
||||
CALIBRATE_ONE(RTC_CAL_RTC_MUX);
|
||||
CALIBRATE_ONE(RTC_CAL_32K_XTAL);
|
||||
}
|
||||
CALIBRATE_ONE(RTC_CAL_RTC_MUX);
|
||||
CALIBRATE_ONE(RTC_CAL_32K_XTAL);
|
||||
if (rtc_clk_slow_freq_get() != RTC_SLOW_FREQ_32K_XTAL) {
|
||||
DEBUG_MSG("Warning: Failed to switch 32K XTAL RTC source to 32.768Khz !!! \n"); return;
|
||||
LOG_WARN("Failed to switch 32K XTAL RTC source to 32.768Khz !!! \n"); return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -85,21 +85,21 @@ void enableSlowCLK()
|
||||
void esp32Setup()
|
||||
{
|
||||
uint32_t seed = esp_random();
|
||||
DEBUG_MSG("Setting random seed %u\n", seed);
|
||||
LOG_DEBUG("Setting random seed %u\n", seed);
|
||||
randomSeed(seed); // ESP docs say this is fairly random
|
||||
|
||||
DEBUG_MSG("Total heap: %d\n", ESP.getHeapSize());
|
||||
DEBUG_MSG("Free heap: %d\n", ESP.getFreeHeap());
|
||||
DEBUG_MSG("Total PSRAM: %d\n", ESP.getPsramSize());
|
||||
DEBUG_MSG("Free PSRAM: %d\n", ESP.getFreePsram());
|
||||
LOG_DEBUG("Total heap: %d\n", ESP.getHeapSize());
|
||||
LOG_DEBUG("Free heap: %d\n", ESP.getFreeHeap());
|
||||
LOG_DEBUG("Total PSRAM: %d\n", ESP.getPsramSize());
|
||||
LOG_DEBUG("Free PSRAM: %d\n", ESP.getFreePsram());
|
||||
|
||||
nvs_stats_t nvs_stats;
|
||||
auto res = nvs_get_stats(NULL, &nvs_stats);
|
||||
assert(res == ESP_OK);
|
||||
DEBUG_MSG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d, NameSpaces %d\n", nvs_stats.used_entries, nvs_stats.free_entries,
|
||||
LOG_DEBUG("NVS: UsedEntries %d, FreeEntries %d, AllEntries %d, NameSpaces %d\n", nvs_stats.used_entries, nvs_stats.free_entries,
|
||||
nvs_stats.total_entries, nvs_stats.namespace_count);
|
||||
|
||||
DEBUG_MSG("Setup Preferences in Flash Storage\n");
|
||||
LOG_DEBUG("Setup Preferences in Flash Storage\n");
|
||||
|
||||
// Create object to store our persistant data
|
||||
Preferences preferences;
|
||||
@@ -109,12 +109,12 @@ void esp32Setup()
|
||||
rebootCounter++;
|
||||
preferences.putUInt("rebootCounter", rebootCounter);
|
||||
preferences.end();
|
||||
DEBUG_MSG("Number of Device Reboots: %d\n", rebootCounter);
|
||||
LOG_DEBUG("Number of Device Reboots: %d\n", rebootCounter);
|
||||
String BLEOTA=BleOta::getOtaAppVersion();
|
||||
if (BLEOTA.isEmpty()) {
|
||||
DEBUG_MSG("No OTA firmware available\n");
|
||||
LOG_DEBUG("No OTA firmware available\n");
|
||||
}else{
|
||||
DEBUG_MSG("OTA firmware version %s\n", BLEOTA.c_str());
|
||||
LOG_DEBUG("OTA firmware version %s\n", BLEOTA.c_str());
|
||||
}
|
||||
|
||||
// enableModemSleep();
|
||||
@@ -141,13 +141,13 @@ void esp32Setup()
|
||||
uint32_t axpDebugRead()
|
||||
{
|
||||
axp.debugCharging();
|
||||
DEBUG_MSG("vbus current %f\n", axp.getVbusCurrent());
|
||||
DEBUG_MSG("charge current %f\n", axp.getBattChargeCurrent());
|
||||
DEBUG_MSG("bat voltage %f\n", axp.getBattVoltage());
|
||||
DEBUG_MSG("batt pct %d\n", axp.getBattPercentage());
|
||||
DEBUG_MSG("is battery connected %d\n", axp.isBatteryConnect());
|
||||
DEBUG_MSG("is USB connected %d\n", axp.isVBUSPlug());
|
||||
DEBUG_MSG("is charging %d\n", axp.isChargeing());
|
||||
LOG_DEBUG("vbus current %f\n", axp.getVbusCurrent());
|
||||
LOG_DEBUG("charge current %f\n", axp.getBattChargeCurrent());
|
||||
LOG_DEBUG("bat voltage %f\n", axp.getBattVoltage());
|
||||
LOG_DEBUG("batt pct %d\n", axp.getBattPercentage());
|
||||
LOG_DEBUG("is battery connected %d\n", axp.isBatteryConnect());
|
||||
LOG_DEBUG("is USB connected %d\n", axp.isVBUSPlug());
|
||||
LOG_DEBUG("is charging %d\n", axp.isChargeing());
|
||||
|
||||
return 30 * 1000;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class BluetoothPhoneAPI : public PhoneAPI
|
||||
{
|
||||
PhoneAPI::onNowHasData(fromRadioNum);
|
||||
|
||||
DEBUG_MSG("BLE notify fromNum\n");
|
||||
LOG_DEBUG("BLE notify fromNum\n");
|
||||
fromNum.notify32(fromRadioNum);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void onConnect(uint16_t conn_handle)
|
||||
char central_name[32] = {0};
|
||||
connection->getPeerName(central_name, sizeof(central_name));
|
||||
|
||||
DEBUG_MSG("BLE Connected to %s\n", central_name);
|
||||
LOG_DEBUG("BLE Connected to %s\n", central_name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,21 +66,21 @@ void onConnect(uint16_t conn_handle)
|
||||
void onDisconnect(uint16_t conn_handle, uint8_t reason)
|
||||
{
|
||||
// FIXME - we currently assume only one active connection
|
||||
DEBUG_MSG("BLE Disconnected, reason = 0x%x\n", reason);
|
||||
LOG_DEBUG("BLE Disconnected, reason = 0x%x\n", reason);
|
||||
}
|
||||
|
||||
void onCccd(uint16_t conn_hdl, BLECharacteristic *chr, uint16_t cccd_value)
|
||||
{
|
||||
// Display the raw request packet
|
||||
DEBUG_MSG("CCCD Updated: %u\n", cccd_value);
|
||||
LOG_DEBUG("CCCD Updated: %u\n", cccd_value);
|
||||
|
||||
// Check the characteristic this CCCD update is associated with in case
|
||||
// this handler is used for multiple CCCD records.
|
||||
if (chr->uuid == fromNum.uuid) {
|
||||
if (chr->notifyEnabled(conn_hdl)) {
|
||||
DEBUG_MSG("fromNum 'Notify' enabled\n");
|
||||
LOG_DEBUG("fromNum 'Notify' enabled\n");
|
||||
} else {
|
||||
DEBUG_MSG("fromNum 'Notify' disabled\n");
|
||||
LOG_DEBUG("fromNum 'Notify' disabled\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,14 +135,14 @@ void onFromRadioAuthorize(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_e
|
||||
// or make empty if the queue is empty
|
||||
fromRadio.write(fromRadioBytes, numBytes);
|
||||
} else {
|
||||
// DEBUG_MSG("Ignoring successor read\n");
|
||||
// LOG_DEBUG("Ignoring successor read\n");
|
||||
}
|
||||
authorizeRead(conn_hdl);
|
||||
}
|
||||
|
||||
void onToRadioWrite(uint16_t conn_hdl, BLECharacteristic *chr, uint8_t *data, uint16_t len)
|
||||
{
|
||||
DEBUG_MSG("toRadioWriteCb data %p, len %u\n", data, len);
|
||||
LOG_DEBUG("toRadioWriteCb data %p, len %u\n", data, len);
|
||||
|
||||
bluetoothPhoneAPI->handleToRadio(data, len);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void onToRadioWrite(uint16_t conn_hdl, BLECharacteristic *chr, uint8_t *data, ui
|
||||
*/
|
||||
void onFromNumAuthorize(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_evt_read_t *request)
|
||||
{
|
||||
DEBUG_MSG("fromNumAuthorizeCb\n");
|
||||
LOG_DEBUG("fromNumAuthorizeCb\n");
|
||||
|
||||
authorizeRead(conn_hdl);
|
||||
}
|
||||
@@ -204,14 +204,14 @@ static uint32_t configuredPasskey;
|
||||
void NRF52Bluetooth::shutdown()
|
||||
{
|
||||
// Shutdown bluetooth for minimum power draw
|
||||
DEBUG_MSG("Disable NRF52 bluetooth\n");
|
||||
LOG_DEBUG("Disable NRF52 bluetooth\n");
|
||||
Bluefruit.Advertising.stop();
|
||||
}
|
||||
|
||||
void NRF52Bluetooth::setup()
|
||||
{
|
||||
// Initialise the Bluefruit module
|
||||
DEBUG_MSG("Initialize the Bluefruit nRF52 module\n");
|
||||
LOG_DEBUG("Initialize the Bluefruit nRF52 module\n");
|
||||
Bluefruit.autoConnLed(false);
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
Bluefruit.begin();
|
||||
@@ -225,7 +225,7 @@ void NRF52Bluetooth::setup()
|
||||
configuredPasskey = config.bluetooth.mode == Config_BluetoothConfig_PairingMode_FIXED_PIN ?
|
||||
config.bluetooth.fixed_pin : random(100000, 999999);
|
||||
auto pinString = std::to_string(configuredPasskey);
|
||||
DEBUG_MSG("Bluetooth pin set to '%i'\n", configuredPasskey);
|
||||
LOG_DEBUG("Bluetooth pin set to '%i'\n", configuredPasskey);
|
||||
Bluefruit.Security.setPIN(pinString.c_str());
|
||||
Bluefruit.Security.setIOCaps(true, false, false);
|
||||
Bluefruit.Security.setPairPasskeyCallback(NRF52Bluetooth::onPairingPasskey);
|
||||
@@ -248,30 +248,30 @@ void NRF52Bluetooth::setup()
|
||||
bledfu.begin(); // Install the DFU helper
|
||||
|
||||
// Configure and Start the Device Information Service
|
||||
DEBUG_MSG("Configuring the Device Information Service\n");
|
||||
LOG_DEBUG("Configuring the Device Information Service\n");
|
||||
bledis.setModel(optstr(HW_VERSION));
|
||||
bledis.setFirmwareRev(optstr(APP_VERSION));
|
||||
bledis.begin();
|
||||
|
||||
// Start the BLE Battery Service and set it to 100%
|
||||
DEBUG_MSG("Configuring the Battery Service\n");
|
||||
LOG_DEBUG("Configuring the Battery Service\n");
|
||||
blebas.begin();
|
||||
blebas.write(0); // Unknown battery level for now
|
||||
|
||||
|
||||
// Setup the Heart Rate Monitor service using
|
||||
// BLEService and BLECharacteristic classes
|
||||
DEBUG_MSG("Configuring the Mesh bluetooth service\n");
|
||||
LOG_DEBUG("Configuring the Mesh bluetooth service\n");
|
||||
setupMeshService();
|
||||
|
||||
// Supposedly debugging works with soft device if you disable advertising
|
||||
if (isSoftDeviceAllowed)
|
||||
{
|
||||
// Setup the advertising packet(s)
|
||||
DEBUG_MSG("Setting up the advertising payload(s)\n");
|
||||
LOG_DEBUG("Setting up the advertising payload(s)\n");
|
||||
startAdv();
|
||||
|
||||
DEBUG_MSG("Advertising\n");
|
||||
LOG_DEBUG("Advertising\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ void updateBatteryLevel(uint8_t level)
|
||||
|
||||
void NRF52Bluetooth::clearBonds()
|
||||
{
|
||||
DEBUG_MSG("Clearing bluetooth bonds!\n");
|
||||
LOG_DEBUG("Clearing bluetooth bonds!\n");
|
||||
bond_print_list(BLE_GAP_ROLE_PERIPH);
|
||||
bond_print_list(BLE_GAP_ROLE_CENTRAL);
|
||||
|
||||
@@ -293,12 +293,12 @@ void NRF52Bluetooth::clearBonds()
|
||||
|
||||
void NRF52Bluetooth::onConnectionSecured(uint16_t conn_handle)
|
||||
{
|
||||
DEBUG_MSG("BLE connection secured\n");
|
||||
LOG_DEBUG("BLE connection secured\n");
|
||||
}
|
||||
|
||||
bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passkey[6], bool match_request)
|
||||
{
|
||||
DEBUG_MSG("BLE pairing process started with passkey %.3s %.3s\n", passkey, passkey+3);
|
||||
LOG_DEBUG("BLE pairing process started with passkey %.3s %.3s\n", passkey, passkey+3);
|
||||
screen->startBluetoothPinScreen(configuredPasskey);
|
||||
|
||||
if (match_request)
|
||||
@@ -309,16 +309,16 @@ bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passke
|
||||
if (!Bluefruit.connected(conn_handle)) break;
|
||||
}
|
||||
}
|
||||
DEBUG_MSG("BLE passkey pairing: match_request=%i\n", match_request);
|
||||
LOG_DEBUG("BLE passkey pairing: match_request=%i\n", match_request);
|
||||
return true;
|
||||
}
|
||||
|
||||
void NRF52Bluetooth::onPairingCompleted(uint16_t conn_handle, uint8_t auth_status)
|
||||
{
|
||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
|
||||
DEBUG_MSG("BLE pairing success\n");
|
||||
LOG_DEBUG("BLE pairing success\n");
|
||||
else
|
||||
DEBUG_MSG("BLE pairing failed\n");
|
||||
LOG_DEBUG("BLE pairing failed\n");
|
||||
|
||||
screen->stopBluetoothPinScreen();
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ class NRF52CryptoEngine : public CryptoEngine
|
||||
virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override
|
||||
{
|
||||
if (key.length > 16) {
|
||||
DEBUG_MSG("Software encrypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
LOG_DEBUG("Software encrypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
AES_ctx ctx;
|
||||
initNonce(fromNode, packetId);
|
||||
AES_init_ctx_iv(&ctx, key.bytes, nonce);
|
||||
AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes);
|
||||
} else if (key.length > 0) {
|
||||
DEBUG_MSG("nRF52 encrypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
LOG_DEBUG("nRF52 encrypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetId, numBytes);
|
||||
nRFCrypto.begin();
|
||||
nRFCrypto_AES ctx;
|
||||
uint8_t myLen = ctx.blockLen(numBytes);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
enum { r0, r1, r2, r3, r12, lr, pc, psr };
|
||||
|
||||
// we can't use the regular DEBUG_MSG for these crash dumps because it depends on threading still being running. Instead use the
|
||||
// we can't use the regular LOG_DEBUG for these crash dumps because it depends on threading still being running. Instead use the
|
||||
// segger in memory tool
|
||||
#define FAULT_MSG(...) SEGGER_MSG(__VA_ARGS__)
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ bool loopCanSleep() {
|
||||
// handle standard gcc assert failures
|
||||
void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
||||
{
|
||||
DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr);
|
||||
LOG_DEBUG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr);
|
||||
// debugger_break(); FIXME doesn't work, possibly not for segger
|
||||
// Reboot cpu
|
||||
NVIC_SystemReset();
|
||||
@@ -73,7 +73,7 @@ void setBluetoothEnable(bool on)
|
||||
if (on) {
|
||||
if (!nrf52Bluetooth) {
|
||||
if (!useSoftDevice)
|
||||
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
LOG_DEBUG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||
else {
|
||||
nrf52Bluetooth = new NRF52Bluetooth();
|
||||
nrf52Bluetooth->setup();
|
||||
@@ -112,7 +112,7 @@ void checkSDEvents()
|
||||
break;
|
||||
|
||||
default:
|
||||
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
||||
LOG_DEBUG("Unexpected SDevt %d\n", evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ void nrf52Setup()
|
||||
auto why = NRF_POWER->RESETREAS;
|
||||
// per
|
||||
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
||||
DEBUG_MSG("Reset reason: 0x%x\n", why);
|
||||
LOG_DEBUG("Reset reason: 0x%x\n", why);
|
||||
|
||||
// Per
|
||||
// https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse
|
||||
@@ -142,7 +142,7 @@ void nrf52Setup()
|
||||
#ifdef BQ25703A_ADDR
|
||||
auto *bq = new BQ25713();
|
||||
if (!bq->setup())
|
||||
DEBUG_MSG("ERROR! Charge controller init failed\n");
|
||||
LOG_DEBUG("ERROR! Charge controller init failed\n");
|
||||
#endif
|
||||
|
||||
// Init random seed
|
||||
@@ -152,7 +152,7 @@ void nrf52Setup()
|
||||
} seed;
|
||||
nRFCrypto.begin();
|
||||
nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8));
|
||||
DEBUG_MSG("Setting random seed %u\n", seed.seed32);
|
||||
LOG_DEBUG("Setting random seed %u\n", seed.seed32);
|
||||
randomSeed(seed.seed32);
|
||||
nRFCrypto.end();
|
||||
}
|
||||
@@ -178,7 +178,7 @@ void cpuDeepSleep(uint64_t msecToWake)
|
||||
|
||||
auto ok = sd_power_system_off();
|
||||
if (ok != NRF_SUCCESS) {
|
||||
DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing "
|
||||
LOG_DEBUG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing "
|
||||
"system-off!\n");
|
||||
NRF_POWER->SYSTEMOFF = 1;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ void cpuDeepSleep(uint64_t msecToWake)
|
||||
// The following code should not be run, because we are off
|
||||
while (1) {
|
||||
delay(5000);
|
||||
DEBUG_MSG(".");
|
||||
LOG_DEBUG(".");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine
|
||||
virtual void setKey(const CryptoKey &k) override
|
||||
{
|
||||
CryptoEngine::setKey(k);
|
||||
DEBUG_MSG("Installing AES%d key!\n", key.length * 8);
|
||||
LOG_DEBUG("Installing AES%d key!\n", key.length * 8);
|
||||
if (ctr) {
|
||||
delete ctr;
|
||||
ctr = NULL;
|
||||
@@ -54,7 +54,7 @@ class CrossPlatformCryptoEngine : public CryptoEngine
|
||||
static uint8_t scratch[MAX_BLOCKSIZE];
|
||||
//size_t nc_off = 0;
|
||||
|
||||
// DEBUG_MSG("ESP32 encrypt!\n");
|
||||
// LOG_DEBUG("ESP32 encrypt!\n");
|
||||
initNonce(fromNode, packetId);
|
||||
assert(numBytes <= MAX_BLOCKSIZE);
|
||||
memcpy(scratch, bytes, numBytes);
|
||||
|
||||
@@ -22,7 +22,7 @@ ErrorCode SimRadio::send(MeshPacket *p)
|
||||
|
||||
// set (random) transmit delay to let others reconfigure their radio,
|
||||
// to avoid collisions and implement timing-based flooding
|
||||
DEBUG_MSG("Set random delay before transmitting.\n");
|
||||
LOG_DEBUG("Set random delay before transmitting.\n");
|
||||
setTransmitDelay();
|
||||
return res;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ void SimRadio::setTransmitDelay()
|
||||
startTransmitTimer(true);
|
||||
} else {
|
||||
// If there is a SNR, start a timer scaled based on that SNR.
|
||||
DEBUG_MSG("rx_snr found. hop_limit:%d rx_snr:%f\n", p->hop_limit, p->rx_snr);
|
||||
LOG_DEBUG("rx_snr found. hop_limit:%d rx_snr:%f\n", p->hop_limit, p->rx_snr);
|
||||
startTransmitTimerSNR(p->rx_snr);
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,11 @@ void SimRadio::startTransmitTimer(bool withDelay)
|
||||
// If we have work to do and the timer wasn't already scheduled, schedule it now
|
||||
if (!txQueue.empty()) {
|
||||
uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec();
|
||||
// DEBUG_MSG("xmit timer %d\n", delay);
|
||||
// LOG_DEBUG("xmit timer %d\n", delay);
|
||||
delay(delayMsec);
|
||||
onNotify(TRANSMIT_DELAY_COMPLETED);
|
||||
} else {
|
||||
DEBUG_MSG("TX QUEUE EMPTY!\n");
|
||||
LOG_DEBUG("TX QUEUE EMPTY!\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ void SimRadio::startTransmitTimerSNR(float snr)
|
||||
// If we have work to do and the timer wasn't already scheduled, schedule it now
|
||||
if (!txQueue.empty()) {
|
||||
uint32_t delayMsec = getTxDelayMsecWeighted(snr);
|
||||
// DEBUG_MSG("xmit timer %d\n", delay);
|
||||
// LOG_DEBUG("xmit timer %d\n", delay);
|
||||
delay(delayMsec);
|
||||
onNotify(TRANSMIT_DELAY_COMPLETED);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ void SimRadio::completeSending()
|
||||
|
||||
// We are done sending that packet, release it
|
||||
packetPool.release(p);
|
||||
// DEBUG_MSG("Done with send\n");
|
||||
// LOG_DEBUG("Done with send\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ bool SimRadio::canSendImmediately()
|
||||
|
||||
if (busyTx || busyRx) {
|
||||
if (busyTx)
|
||||
DEBUG_MSG("Can not send yet, busyTx\n");
|
||||
LOG_DEBUG("Can not send yet, busyTx\n");
|
||||
if (busyRx)
|
||||
DEBUG_MSG("Can not send yet, busyRx\n");
|
||||
LOG_DEBUG("Can not send yet, busyRx\n");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
@@ -134,7 +134,7 @@ bool SimRadio::cancelSending(NodeNum from, PacketId id)
|
||||
packetPool.release(p); // free the packet we just removed
|
||||
|
||||
bool result = (p != NULL);
|
||||
DEBUG_MSG("cancelSending id=0x%x, removed=%d\n", id, result);
|
||||
LOG_DEBUG("cancelSending id=0x%x, removed=%d\n", id, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -144,24 +144,24 @@ void SimRadio::onNotify(uint32_t notification)
|
||||
switch (notification) {
|
||||
case ISR_TX:
|
||||
handleTransmitInterrupt();
|
||||
DEBUG_MSG("tx complete - starting timer\n");
|
||||
LOG_DEBUG("tx complete - starting timer\n");
|
||||
startTransmitTimer();
|
||||
break;
|
||||
case ISR_RX:
|
||||
DEBUG_MSG("rx complete - starting timer\n");
|
||||
LOG_DEBUG("rx complete - starting timer\n");
|
||||
break;
|
||||
case TRANSMIT_DELAY_COMPLETED:
|
||||
DEBUG_MSG("delay done\n");
|
||||
LOG_DEBUG("delay done\n");
|
||||
|
||||
// If we are not currently in receive mode, then restart the random delay (this can happen if the main thread
|
||||
// has placed the unit into standby) FIXME, how will this work if the chipset is in sleep mode?
|
||||
if (!txQueue.empty()) {
|
||||
if (!canSendImmediately()) {
|
||||
// DEBUG_MSG("Currently Rx/Tx-ing: set random delay\n");
|
||||
// LOG_DEBUG("Currently Rx/Tx-ing: set random delay\n");
|
||||
setTransmitDelay(); // currently Rx/Tx-ing: reset random delay
|
||||
} else {
|
||||
if (isChannelActive()) { // check if there is currently a LoRa packet on the channel
|
||||
// DEBUG_MSG("Channel is active: set random delay\n");
|
||||
// LOG_DEBUG("Channel is active: set random delay\n");
|
||||
setTransmitDelay(); // reset random delay
|
||||
} else {
|
||||
// Send any outgoing packets we have ready
|
||||
@@ -177,7 +177,7 @@ void SimRadio::onNotify(uint32_t notification)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// DEBUG_MSG("done with txqueue\n");
|
||||
// LOG_DEBUG("done with txqueue\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -194,12 +194,12 @@ void SimRadio::startSend(MeshPacket * txp)
|
||||
perhapsDecode(p);
|
||||
Compressed c = Compressed_init_default;
|
||||
c.portnum = p->decoded.portnum;
|
||||
// DEBUG_MSG("Sending back to simulator with portNum %d\n", p->decoded.portnum);
|
||||
// LOG_DEBUG("Sending back to simulator with portNum %d\n", p->decoded.portnum);
|
||||
if (p->decoded.payload.size <= sizeof(c.data.bytes)) {
|
||||
memcpy(&c.data.bytes, p->decoded.payload.bytes, p->decoded.payload.size);
|
||||
c.data.size = p->decoded.payload.size;
|
||||
} else {
|
||||
DEBUG_MSG("Payload size is larger than compressed message allows! Sending empty payload.\n");
|
||||
LOG_DEBUG("Payload size is larger than compressed message allows! Sending empty payload.\n");
|
||||
}
|
||||
p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &Compressed_msg, &c);
|
||||
p->decoded.portnum = PortNum_SIMULATOR_APP;
|
||||
@@ -218,7 +218,7 @@ void SimRadio::startReceive(MeshPacket *p) {
|
||||
|
||||
void SimRadio::handleReceiveInterrupt(MeshPacket *p)
|
||||
{
|
||||
DEBUG_MSG("HANDLE RECEIVE INTERRUPT\n");
|
||||
LOG_DEBUG("HANDLE RECEIVE INTERRUPT\n");
|
||||
uint32_t xmitMsec;
|
||||
assert(isReceiving);
|
||||
isReceiving = false;
|
||||
@@ -226,7 +226,7 @@ void SimRadio::handleReceiveInterrupt(MeshPacket *p)
|
||||
// read the number of actually received bytes
|
||||
size_t length = getPacketLength(p);
|
||||
xmitMsec = getPacketTime(length);
|
||||
// DEBUG_MSG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length);
|
||||
// LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length);
|
||||
|
||||
MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packtPool
|
||||
mp->which_payload_variant = MeshPacket_decoded_tag; // Mark that the payload is already decoded
|
||||
|
||||
Reference in New Issue
Block a user