mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-02 08:00:38 +00:00
Merge branch 'master' into ESP32C3-RISC
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "configuration.h"
|
||||
|
||||
#include "../detect/ScanI2C.h"
|
||||
#include "Channels.h"
|
||||
#include "CryptoEngine.h"
|
||||
#include "FSCommon.h"
|
||||
@@ -181,7 +182,7 @@ void NodeDB::installDefaultConfig()
|
||||
#if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER)
|
||||
bool hasScreen = true;
|
||||
#else
|
||||
bool hasScreen = screen_found;
|
||||
bool hasScreen = screen_found.port != ScanI2C::I2CPort::NO_I2C;
|
||||
#endif
|
||||
config.bluetooth.mode = hasScreen ? meshtastic_Config_BluetoothConfig_PairingMode_RANDOM_PIN
|
||||
: meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN;
|
||||
|
||||
@@ -281,7 +281,7 @@ void printPacket(const char *prefix, const meshtastic_MeshPacket *p)
|
||||
if (p->priority != 0)
|
||||
out += DEBUG_PORT.mt_sprintf(" priority=%d", p->priority);
|
||||
|
||||
out + ")\n";
|
||||
out += ")\n";
|
||||
LOG_DEBUG("%s", out.c_str());
|
||||
}
|
||||
|
||||
@@ -471,6 +471,9 @@ void RadioInterface::applyModemConfig()
|
||||
saveChannelNum(channel_num);
|
||||
saveFreq(freq + loraConfig.frequency_offset);
|
||||
|
||||
preambleTimeMsec = getPacketTime((uint32_t)0);
|
||||
maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader));
|
||||
|
||||
LOG_INFO("Radio freq=%.3f, config.lora.frequency_offset=%.3f\n", freq, loraConfig.frequency_offset);
|
||||
LOG_INFO("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset,
|
||||
channel_num, power);
|
||||
|
||||
@@ -63,7 +63,9 @@ class RadioInterface
|
||||
- Tx/Rx turnaround time (maximum of SX126x and SX127x);
|
||||
- MAC processing time (measured on T-beam) */
|
||||
uint32_t slotTimeMsec = 8.5 * pow(2, sf) / bw + 0.2 + 0.4 + 7;
|
||||
uint16_t preambleLength = 16; // 8 is default, but we use longer to increase the amount of sleep time when receiving
|
||||
uint16_t preambleLength = 16; // 8 is default, but we use longer to increase the amount of sleep time when receiving
|
||||
uint32_t preambleTimeMsec = 165; // calculated on startup, this is the default for LongFast
|
||||
uint32_t maxPacketTimeMsec = 3246; // calculated on startup, this is the default for LongFast
|
||||
const uint32_t PROCESSING_TIME_MSEC =
|
||||
4500; // time to construct, process and construct a packet again (empirically determined)
|
||||
const uint8_t CWmin = 2; // minimum CWsize
|
||||
|
||||
@@ -180,6 +180,7 @@ template <typename T> void SX126xInterface<T>::setStandby()
|
||||
assert(err == RADIOLIB_ERR_NONE);
|
||||
|
||||
isReceiving = false; // If we were receiving, not any more
|
||||
activeReceiveStart = 0;
|
||||
disableInterrupt();
|
||||
completeSending(); // If we were sending, not anymore
|
||||
}
|
||||
@@ -212,9 +213,11 @@ template <typename T> void SX126xInterface<T>::startReceive()
|
||||
|
||||
setStandby();
|
||||
|
||||
// int err = lora.startReceive();
|
||||
int err = lora.startReceiveDutyCycleAuto(); // We use a 32 bit preamble so this should save some power by letting radio sit in
|
||||
// standby mostly.
|
||||
// We use a 16 bit preamble so this should save some power by letting radio sit in standby mostly.
|
||||
// Furthermore, we need the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving
|
||||
int err = lora.startReceiveDutyCycleAuto(preambleLength, 8,
|
||||
RADIOLIB_SX126X_IRQ_RX_DEFAULT | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED |
|
||||
RADIOLIB_SX126X_IRQ_HEADER_VALID);
|
||||
assert(err == RADIOLIB_ERR_NONE);
|
||||
|
||||
isReceiving = true;
|
||||
@@ -224,7 +227,7 @@ template <typename T> void SX126xInterface<T>::startReceive()
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Could we send right now (i.e. either not actively receving or transmitting)? */
|
||||
/** Is the channel currently active? */
|
||||
template <typename T> bool SX126xInterface<T>::isChannelActive()
|
||||
{
|
||||
// check if we can detect a LoRa preamble on the current channel
|
||||
@@ -245,17 +248,29 @@ template <typename T> bool SX126xInterface<T>::isActivelyReceiving()
|
||||
{
|
||||
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
|
||||
// received and handled the interrupt for reading the packet/handling errors.
|
||||
// FIXME: it would be better to check for preamble, but we currently have our ISR not set to fire for packets that
|
||||
// never even get a valid header, so we don't want preamble to get set and stay set due to noise on the network.
|
||||
|
||||
uint16_t irq = lora.getIrqStatus();
|
||||
bool hasPreamble = (irq & RADIOLIB_SX126X_IRQ_HEADER_VALID);
|
||||
bool detected = (irq & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED));
|
||||
// Handle false detections
|
||||
if (detected) {
|
||||
uint32_t now = millis();
|
||||
if (!activeReceiveStart) {
|
||||
activeReceiveStart = now;
|
||||
} else if ((now - activeReceiveStart > 2 * preambleTimeMsec) && !(irq & RADIOLIB_SX126X_IRQ_HEADER_VALID)) {
|
||||
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
||||
activeReceiveStart = 0;
|
||||
LOG_DEBUG("Ignore false preamble detection.\n");
|
||||
return false;
|
||||
} else if (now - activeReceiveStart > maxPacketTimeMsec) {
|
||||
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
||||
activeReceiveStart = 0;
|
||||
LOG_DEBUG("Ignore false header detection.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this is not correct - often always true - need to add an extra conditional
|
||||
// size_t bytesPending = lora.getPacketLength();
|
||||
|
||||
// if (hasPreamble) LOG_DEBUG("rx hasPreamble\n");
|
||||
return hasPreamble;
|
||||
// if (detected) LOG_DEBUG("rx detected\n");
|
||||
return detected;
|
||||
}
|
||||
|
||||
template <typename T> bool SX126xInterface<T>::sleep()
|
||||
|
||||
@@ -68,4 +68,5 @@ template <class T> class SX126xInterface : public RadioLibInterface
|
||||
virtual void setStandby() override;
|
||||
|
||||
private:
|
||||
uint32_t activeReceiveStart = 0;
|
||||
};
|
||||
|
||||
@@ -157,6 +157,7 @@ template <typename T> void SX128xInterface<T>::setStandby()
|
||||
#endif
|
||||
|
||||
isReceiving = false; // If we were receiving, not any more
|
||||
activeReceiveStart = 0;
|
||||
disableInterrupt();
|
||||
completeSending(); // If we were sending, not anymore
|
||||
}
|
||||
@@ -203,7 +204,10 @@ template <typename T> void SX128xInterface<T>::startReceive()
|
||||
digitalWrite(SX128X_TXEN, LOW);
|
||||
#endif
|
||||
|
||||
int err = lora.startReceive();
|
||||
// We use the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving
|
||||
int err = lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT |
|
||||
RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED |
|
||||
RADIOLIB_SX128X_IRQ_HEADER_VALID);
|
||||
|
||||
assert(err == RADIOLIB_ERR_NONE);
|
||||
|
||||
@@ -214,7 +218,7 @@ template <typename T> void SX128xInterface<T>::startReceive()
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Could we send right now (i.e. either not actively receving or transmitting)? */
|
||||
/** Is the channel currently active? */
|
||||
template <typename T> bool SX128xInterface<T>::isChannelActive()
|
||||
{
|
||||
// check if we can detect a LoRa preamble on the current channel
|
||||
@@ -234,8 +238,27 @@ template <typename T> bool SX128xInterface<T>::isChannelActive()
|
||||
template <typename T> bool SX128xInterface<T>::isActivelyReceiving()
|
||||
{
|
||||
uint16_t irq = lora.getIrqStatus();
|
||||
bool hasPreamble = (irq & RADIOLIB_SX128X_IRQ_HEADER_VALID);
|
||||
return hasPreamble;
|
||||
bool detected = (irq & (RADIOLIB_SX128X_IRQ_HEADER_VALID | RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED));
|
||||
|
||||
// Handle false detections
|
||||
if (detected) {
|
||||
uint32_t now = millis();
|
||||
if (!activeReceiveStart) {
|
||||
activeReceiveStart = now;
|
||||
} else if ((now - activeReceiveStart > 2 * preambleTimeMsec) && !(irq & RADIOLIB_SX128X_IRQ_HEADER_VALID)) {
|
||||
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
||||
activeReceiveStart = 0;
|
||||
LOG_DEBUG("Ignore false preamble detection.\n");
|
||||
return false;
|
||||
} else if (now - activeReceiveStart > maxPacketTimeMsec) {
|
||||
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
||||
activeReceiveStart = 0;
|
||||
LOG_DEBUG("Ignore false header detection.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return detected;
|
||||
}
|
||||
|
||||
template <typename T> bool SX128xInterface<T>::sleep()
|
||||
|
||||
@@ -68,4 +68,5 @@ template <class T> class SX128xInterface : public RadioLibInterface
|
||||
virtual void setStandby() override;
|
||||
|
||||
private:
|
||||
uint32_t activeReceiveStart = 0;
|
||||
};
|
||||
|
||||
@@ -135,7 +135,7 @@ typedef struct _meshtastic_AdminMessage {
|
||||
/* Tell the node to reboot into the OTA Firmware in this many seconds (or <0 to cancel reboot)
|
||||
Only Implemented for ESP32 Devices. This needs to be issued to send a new main firmware via bluetooth. */
|
||||
int32_t reboot_ota_seconds;
|
||||
/* This message is only supported for the simulator porduino build.
|
||||
/* This message is only supported for the simulator Portduino build.
|
||||
If received the simulator will exit successfully. */
|
||||
bool exit_simulator;
|
||||
/* Tell the node to reboot in this many seconds (or <0 to cancel reboot) */
|
||||
|
||||
@@ -152,7 +152,7 @@ typedef enum _meshtastic_Config_LoRaConfig_RegionCode {
|
||||
meshtastic_Config_LoRaConfig_RegionCode_US = 1,
|
||||
/* European Union 433mhz */
|
||||
meshtastic_Config_LoRaConfig_RegionCode_EU_433 = 2,
|
||||
/* European Union 433mhz */
|
||||
/* European Union 868mhz */
|
||||
meshtastic_Config_LoRaConfig_RegionCode_EU_868 = 3,
|
||||
/* China */
|
||||
meshtastic_Config_LoRaConfig_RegionCode_CN = 4,
|
||||
@@ -202,11 +202,11 @@ typedef enum _meshtastic_Config_LoRaConfig_ModemPreset {
|
||||
} meshtastic_Config_LoRaConfig_ModemPreset;
|
||||
|
||||
typedef enum _meshtastic_Config_BluetoothConfig_PairingMode {
|
||||
/* Device generates a random pin that will be shown on the screen of the device for pairing */
|
||||
/* Device generates a random PIN that will be shown on the screen of the device for pairing */
|
||||
meshtastic_Config_BluetoothConfig_PairingMode_RANDOM_PIN = 0,
|
||||
/* Device requires a specified fixed pin for pairing */
|
||||
/* Device requires a specified fixed PIN for pairing */
|
||||
meshtastic_Config_BluetoothConfig_PairingMode_FIXED_PIN = 1,
|
||||
/* Device requires no pin for pairing */
|
||||
/* Device requires no PIN for pairing */
|
||||
meshtastic_Config_BluetoothConfig_PairingMode_NO_PIN = 2
|
||||
} meshtastic_Config_BluetoothConfig_PairingMode;
|
||||
|
||||
@@ -364,7 +364,7 @@ typedef struct _meshtastic_Config_DisplayConfig {
|
||||
|
||||
/* Lora Config */
|
||||
typedef struct _meshtastic_Config_LoRaConfig {
|
||||
/* When enabled, the `modem_preset` fields will be adheared to, else the `bandwidth`/`spread_factor`/`coding_rate`
|
||||
/* When enabled, the `modem_preset` fields will be adhered to, else the `bandwidth`/`spread_factor`/`coding_rate`
|
||||
will be taked from their respective manually defined fields */
|
||||
bool use_preset;
|
||||
/* Either modem_config or bandwidth/spreading/coding will be specified - NOT BOTH.
|
||||
@@ -395,12 +395,12 @@ typedef struct _meshtastic_Config_LoRaConfig {
|
||||
/* Disable TX from the LoRa radio. Useful for hot-swapping antennas and other tests.
|
||||
Defaults to false */
|
||||
bool tx_enabled;
|
||||
/* If zero then, use default max legal continuous power (ie. something that won't
|
||||
/* If zero, then use default max legal continuous power (ie. something that won't
|
||||
burn out the radio hardware)
|
||||
In most cases you should use zero here.
|
||||
Units are in dBm. */
|
||||
int8_t tx_power;
|
||||
/* This is controlling the actual hardware frequency the radio is transmitting on.
|
||||
/* This controls the actual hardware frequency the radio transmits on.
|
||||
Most users should never need to be exposed to this field/concept.
|
||||
A channel number between 1 and NUM_CHANNELS (whatever the max is in the current region).
|
||||
If ZERO then the rule is "use the old channel name hash based
|
||||
@@ -422,7 +422,7 @@ typedef struct _meshtastic_Config_LoRaConfig {
|
||||
float override_frequency;
|
||||
/* For testing it is useful sometimes to force a node to never listen to
|
||||
particular other nodes (simulating radio out of range). All nodenums listed
|
||||
in ignore_incoming will have packets they send droped on receive (by router.cpp) */
|
||||
in ignore_incoming will have packets they send dropped on receive (by router.cpp) */
|
||||
pb_size_t ignore_incoming_count;
|
||||
uint32_t ignore_incoming[3];
|
||||
} meshtastic_Config_LoRaConfig;
|
||||
@@ -432,7 +432,7 @@ typedef struct _meshtastic_Config_BluetoothConfig {
|
||||
bool enabled;
|
||||
/* Determines the pairing strategy for the device */
|
||||
meshtastic_Config_BluetoothConfig_PairingMode mode;
|
||||
/* Specified pin for PairingMode.FixedPin */
|
||||
/* Specified PIN for PairingMode.FixedPin */
|
||||
uint32_t fixed_pin;
|
||||
} meshtastic_Config_BluetoothConfig;
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ typedef struct _meshtastic_WifiConnectionStatus {
|
||||
/* Connection status */
|
||||
bool has_status;
|
||||
meshtastic_NetworkConnectionStatus status;
|
||||
/* WiFi access point ssid */
|
||||
/* WiFi access point SSID */
|
||||
char ssid[33];
|
||||
/* Rssi of wireless connection */
|
||||
/* RSSI of wireless connection */
|
||||
int32_t rssi;
|
||||
} meshtastic_WifiConnectionStatus;
|
||||
|
||||
@@ -42,9 +42,9 @@ typedef struct _meshtastic_EthernetConnectionStatus {
|
||||
|
||||
/* Bluetooth connection status */
|
||||
typedef struct _meshtastic_BluetoothConnectionStatus {
|
||||
/* The pairing pin for bluetooth */
|
||||
/* The pairing PIN for bluetooth */
|
||||
uint32_t pin;
|
||||
/* Rssi of bluetooth connection */
|
||||
/* RSSI of bluetooth connection */
|
||||
int32_t rssi;
|
||||
/* Whether the device has an active connection or not */
|
||||
bool is_connected;
|
||||
@@ -52,7 +52,7 @@ typedef struct _meshtastic_BluetoothConnectionStatus {
|
||||
|
||||
/* Serial connection status */
|
||||
typedef struct _meshtastic_SerialConnectionStatus {
|
||||
/* The serial baud rate */
|
||||
/* Serial baud rate */
|
||||
uint32_t baud;
|
||||
/* Whether the device has an active connection or not */
|
||||
bool is_connected;
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef struct _meshtastic_DeviceState {
|
||||
/* Used only during development.
|
||||
Indicates developer is testing and changes should never be saved to flash. */
|
||||
bool no_save;
|
||||
/* Some GPSes seem to have bogus settings from the factory, so we always do one factory reset. */
|
||||
/* Some GPS receivers seem to have bogus settings from the factory, so we always do one factory reset. */
|
||||
bool did_gps_reset;
|
||||
} meshtastic_DeviceState;
|
||||
|
||||
@@ -72,13 +72,13 @@ typedef struct _meshtastic_ChannelFile {
|
||||
typedef PB_BYTES_ARRAY_T(2048) meshtastic_OEMStore_oem_icon_bits_t;
|
||||
typedef PB_BYTES_ARRAY_T(32) meshtastic_OEMStore_oem_aes_key_t;
|
||||
/* This can be used for customizing the firmware distribution. If populated,
|
||||
show a secondary bootup screen with cuatom logo and text for 2.5 seconds. */
|
||||
show a secondary bootup screen with custom logo and text for 2.5 seconds. */
|
||||
typedef struct _meshtastic_OEMStore {
|
||||
/* The Logo width in Px */
|
||||
uint32_t oem_icon_width;
|
||||
/* The Logo height in Px */
|
||||
uint32_t oem_icon_height;
|
||||
/* The Logo in xbm bytechar format */
|
||||
/* The Logo in XBM bytechar format */
|
||||
meshtastic_OEMStore_oem_icon_bits_t oem_icon_bits;
|
||||
/* Use this font for the OEM text. */
|
||||
meshtastic_ScreenFonts oem_font;
|
||||
|
||||
@@ -45,7 +45,7 @@ typedef enum _meshtastic_TelemetrySensorType {
|
||||
/* Struct definitions */
|
||||
/* Key native device metrics such as battery level */
|
||||
typedef struct _meshtastic_DeviceMetrics {
|
||||
/* 1-100 (0 means powered) */
|
||||
/* 0-100 (>100 means powered) */
|
||||
uint32_t battery_level;
|
||||
/* Voltage measured */
|
||||
float voltage;
|
||||
|
||||
Reference in New Issue
Block a user