Merge branch 'master' into esp32-c6

This commit is contained in:
Thomas Göttgens
2024-09-28 12:33:50 +02:00
committed by GitHub
23 changed files with 168 additions and 87 deletions

View File

@@ -47,6 +47,9 @@
#endif
#if ARCH_PORTDUINO
#include "input/LinuxInputImpl.h"
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#endif
#if HAS_TELEMETRY
#include "modules/Telemetry/DeviceTelemetry.h"
@@ -67,7 +70,7 @@
#include "modules/esp32/PaxcounterModule.h"
#endif
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/esp32/StoreForwardModule.h"
#include "modules/StoreForwardModule.h"
#endif
#endif
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040)

View File

@@ -15,26 +15,44 @@
// a max of one change per 30 seconds
#define WATCH_INTERVAL_MSEC (30 * 1000)
// Tests for access to read from or write to a specified GPIO pin
static bool pinAccessAllowed(uint64_t mask, uint8_t pin)
{
// If undefined pin access is allowed, don't check the pin and just return true
if (moduleConfig.remote_hardware.allow_undefined_pin_access) {
return true;
}
// Test to see if the pin is in the list of allowed pins and return true if found
if (mask & (1ULL << pin)) {
return true;
}
return false;
}
/// Set pin modes for every set bit in a mask
static void pinModes(uint64_t mask, uint8_t mode)
static void pinModes(uint64_t mask, uint8_t mode, uint64_t maskAvailable)
{
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
if (mask & (1ULL << i)) {
pinMode(i, mode);
if (pinAccessAllowed(maskAvailable, i)) {
pinMode(i, mode);
}
}
}
}
/// Read all the pins mentioned in a mask
static uint64_t digitalReads(uint64_t mask)
static uint64_t digitalReads(uint64_t mask, uint64_t maskAvailable)
{
uint64_t res = 0;
pinModes(mask, INPUT_PULLUP);
pinModes(mask, INPUT_PULLUP, maskAvailable);
for (uint64_t i = 0; i < NUM_GPIOS; i++) {
uint64_t m = 1ULL << i;
if (mask & m) {
if (mask & m && pinAccessAllowed(maskAvailable, i)) {
if (digitalRead(i)) {
res |= m;
}
@@ -50,6 +68,11 @@ RemoteHardwareModule::RemoteHardwareModule()
{
// restrict to the gpio channel for rx
boundChannel = Channels::gpioChannel;
// Pull available pin allowlist from config and build a bitmask out of it for fast comparisons later
for (uint8_t i = 0; i < 4; i++) {
availablePins += 1ULL << moduleConfig.remote_hardware.available_pins[i].gpio_pin;
}
}
bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &req, meshtastic_HardwareMessage *pptr)
@@ -63,10 +86,10 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
// Print notification to LCD screen
screen->print("Write GPIOs\n");
pinModes(p.gpio_mask, OUTPUT);
pinModes(p.gpio_mask, OUTPUT, availablePins);
for (uint8_t i = 0; i < NUM_GPIOS; i++) {
uint64_t mask = 1ULL << i;
if (p.gpio_mask & mask) {
if (p.gpio_mask & mask && pinAccessAllowed(availablePins, i)) {
digitalWrite(i, (p.gpio_value & mask) ? 1 : 0);
}
}
@@ -79,7 +102,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
if (screen)
screen->print("Read GPIOs\n");
uint64_t res = digitalReads(p.gpio_mask);
uint64_t res = digitalReads(p.gpio_mask, availablePins);
// Send the reply
meshtastic_HardwareMessage r = meshtastic_HardwareMessage_init_default;
@@ -121,7 +144,7 @@ int32_t RemoteHardwareModule::runOnce()
if (moduleConfig.remote_hardware.enabled && watchGpios) {
if (!Throttle::isWithinTimespanMs(lastWatchMsec, WATCH_INTERVAL_MSEC)) {
uint64_t curVal = digitalReads(watchGpios);
uint64_t curVal = digitalReads(watchGpios, availablePins);
lastWatchMsec = millis();
if (curVal != previousWatch) {

View File

@@ -17,6 +17,9 @@ class RemoteHardwareModule : public ProtobufModule<meshtastic_HardwareMessage>,
/// The timestamp of our last watch event (we throttle watches to 1 change every 30 seconds)
uint32_t lastWatchMsec = 0;
/// A bitmask of GPIOs that are exposed to the mesh if undefined access is not enabled
uint64_t availablePins = 0;
public:
/** Constructor
* name is for debugging output

View File

@@ -35,7 +35,7 @@ uint32_t heartbeatInterval = 60; // Default to 60 seconds, adjust as needed
int32_t StoreForwardModule::runOnce()
{
#ifdef ARCH_ESP32
#if defined(ARCH_ESP32) || defined(ARCH_PORTDUINO)
if (moduleConfig.store_forward.enabled && is_server) {
// Send out the message queue.
if (this->busy) {
@@ -82,8 +82,12 @@ void StoreForwardModule::populatePSRAM()
uint32_t numberOfPackets =
(this->records ? this->records : (((memGet.getFreePsram() / 3) * 2) / sizeof(PacketHistoryStruct)));
this->records = numberOfPackets;
#if defined(ARCH_ESP32)
this->packetHistory = static_cast<PacketHistoryStruct *>(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)));
#elif defined(ARCH_PORTDUINO)
this->packetHistory = static_cast<PacketHistoryStruct *>(calloc(numberOfPackets, sizeof(PacketHistoryStruct)));
#endif
LOG_DEBUG("*** After PSRAM initialization: heap %d/%d PSRAM %d/%d\n", memGet.getFreeHeap(), memGet.getHeapSize(),
memGet.getFreePsram(), memGet.getPsramSize());
@@ -376,7 +380,7 @@ void StoreForwardModule::statsSend(uint32_t to)
*/
ProcessMessage StoreForwardModule::handleReceived(const meshtastic_MeshPacket &mp)
{
#ifdef ARCH_ESP32
#if defined(ARCH_ESP32) || defined(ARCH_PORTDUINO)
if (moduleConfig.store_forward.enabled) {
if ((mp.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) && is_server) {
@@ -559,7 +563,7 @@ StoreForwardModule::StoreForwardModule()
ProtobufModule("StoreForward", meshtastic_PortNum_STORE_FORWARD_APP, &meshtastic_StoreAndForward_msg)
{
#ifdef ARCH_ESP32
#if defined(ARCH_ESP32) || defined(ARCH_PORTDUINO)
isPromiscuous = true; // Brown chicken brown cow