Skip to content

Commit

Permalink
Merge branch 'master' into pr-genuf2
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville authored Aug 2, 2024
2 parents 35b653f + d2ea430 commit f970c46
Show file tree
Hide file tree
Showing 36 changed files with 110 additions and 83 deletions.
14 changes: 12 additions & 2 deletions bin/config-dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Lora:

# ch341_quirk: true # Uncomment this to use the chunked SPI transfer that seems to fix the ch341

# spiSpeed: 2000000

### Set gpio chip to use in /dev/. Defaults to 0.
### Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4
# gpiochip: 4
Expand Down Expand Up @@ -111,6 +113,9 @@ Display:
# Height: 320
# Rotate: true

### You can also specify the spi device for the display to use
# spidev: spidev0.0

Touchscreen:
### Note, at least for now, the touchscreen must have a CS pin defined, even if you let Linux manage the CS switching.

Expand All @@ -126,9 +131,13 @@ Touchscreen:
# CS: 7
# IRQ: 17

### Configure device for direct keyboard input
### You can also specify the spi device for the touchscreen to use
# spidev: spidev0.0


Input:
### Configure device for direct keyboard input

# KeyboardDevice: /dev/input/by-id/usb-_Raspberry_Pi_Internal_Keyboard-event-kbd

###
Expand All @@ -142,4 +151,5 @@ Webserver:
# RootPath: /usr/share/doc/meshtasticd/web # Root Dir of WebServer

General:
MaxNodes: 200
MaxNodes: 200
MaxMessageQueue: 100
4 changes: 2 additions & 2 deletions src/ButtonThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ int32_t ButtonThread::runOnce()

case BUTTON_EVENT_DOUBLE_PRESSED: {
LOG_BUTTON("Double press!\n");
service.refreshLocalMeshNode();
auto sentPosition = service.trySendPosition(NODENUM_BROADCAST, true);
service->refreshLocalMeshNode();
auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true);
if (screen) {
if (sentPosition)
screen->print("Sent ad-hoc position\n");
Expand Down
15 changes: 10 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ uint32_t timeLastPowered = 0;
static Periodic *ledPeriodic;
static OSThread *powerFSMthread;
static OSThread *ambientLightingThread;
SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);

RadioInterface *rIf = NULL;

Expand All @@ -231,6 +230,12 @@ void printInfo()
void setup()
{
concurrency::hasBeenSetup = true;
#if ARCH_PORTDUINO
SPISettings spiSettings(settingsMap[spiSpeed], MSBFIRST, SPI_MODE0);
#else
SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);
#endif

meshtastic_Config_DisplayConfig_OledType screen_model =
meshtastic_Config_DisplayConfig_OledType::meshtastic_Config_DisplayConfig_OledType_OLED_AUTO;
OLEDDISPLAY_GEOMETRY screen_geometry = GEOMETRY_128_64;
Expand Down Expand Up @@ -714,8 +719,8 @@ void setup()
LOG_DEBUG("Starting audio thread\n");
audioThread = new AudioThread();
#endif

service.init();
service = new MeshService();
service->init();

// Now that the mesh service is created, create any modules
setupModules();
Expand Down Expand Up @@ -1080,7 +1085,7 @@ void loop()
// TODO: This should go into a thread handled by FreeRTOS.
// handleWebResponse();

service.loop();
service->loop();

long delayMsec = mainController.runOrDelay();

Expand All @@ -1094,4 +1099,4 @@ void loop()
mainDelay.delay(delayMsec);
}
// if (didWake) LOG_DEBUG("wake!\n");
}
}
2 changes: 1 addition & 1 deletion src/mesh/MeshModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void MeshModule::callModules(meshtastic_MeshPacket &mp, RxSource src)
if (isDecoded && mp.decoded.want_response && toUs) {
if (currentReply) {
printPacket("Sending response", currentReply);
service.sendToMesh(currentReply);
service->sendToMesh(currentReply);
currentReply = NULL;
} else if (mp.from != ourNodeNum && !ignoreRequest) {
// Note: if the message started with the local node or a module asked to ignore the request, we don't want to send a
Expand Down
6 changes: 5 additions & 1 deletion src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "nimble/NimbleBluetooth.h"
#endif

#if ARCH_PORTDUINO
#include "PortduinoGlue.h"
#endif

/*
receivedPacketQueue - this is a queue of messages we've received from the mesh, which we are keeping to deliver to the phone.
It is implemented with a FreeRTos queue (wrapped with a little RTQueue class) of pointers to MeshPacket protobufs (which were
Expand Down Expand Up @@ -53,7 +57,7 @@ nodenum (filtering against whatever it knows about the nodedb) and rebroadcast t
FIXME in the initial proof of concept we just skip the entire want/deny flow and just hand pick node numbers at first.
*/

MeshService service;
MeshService *service;

static MemoryDynamic<meshtastic_MqttClientProxyMessage> staticMqttClientProxyMessagePool;

Expand Down
2 changes: 1 addition & 1 deletion src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ class MeshService
friend class RoutingModule;
};

extern MeshService service;
extern MeshService *service;
20 changes: 10 additions & 10 deletions src/mesh/PhoneAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void PhoneAPI::handleStartConfig()
// Must be before setting state (because state is how we know !connected)
if (!isConnected()) {
onConnectionChanged(true);
observe(&service.fromNumChanged);
observe(&service->fromNumChanged);
#ifdef FSCom
observe(&xModem.packetReady);
#endif
Expand All @@ -63,7 +63,7 @@ void PhoneAPI::close()
if (state != STATE_SEND_NOTHING) {
state = STATE_SEND_NOTHING;

unobserve(&service.fromNumChanged);
unobserve(&service->fromNumChanged);
#ifdef FSCom
unobserve(&xModem.packetReady);
#endif
Expand Down Expand Up @@ -186,7 +186,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
fromRadioScratch.my_info = myNodeInfo;
state = STATE_SEND_OWN_NODEINFO;

service.refreshLocalMeshNode(); // Update my NodeInfo because the client will be asking for it soon.
service->refreshLocalMeshNode(); // Update my NodeInfo because the client will be asking for it soon.
break;

case STATE_SEND_OWN_NODEINFO: {
Expand Down Expand Up @@ -443,23 +443,23 @@ void PhoneAPI::handleDisconnect()
void PhoneAPI::releasePhonePacket()
{
if (packetForPhone) {
service.releaseToPool(packetForPhone); // we just copied the bytes, so don't need this buffer anymore
service->releaseToPool(packetForPhone); // we just copied the bytes, so don't need this buffer anymore
packetForPhone = NULL;
}
}

void PhoneAPI::releaseQueueStatusPhonePacket()
{
if (queueStatusPacketForPhone) {
service.releaseQueueStatusToPool(queueStatusPacketForPhone);
service->releaseQueueStatusToPool(queueStatusPacketForPhone);
queueStatusPacketForPhone = NULL;
}
}

void PhoneAPI::releaseMqttClientProxyPhonePacket()
{
if (mqttClientProxyMessageForPhone) {
service.releaseMqttClientProxyMessageToPool(mqttClientProxyMessageForPhone);
service->releaseMqttClientProxyMessageToPool(mqttClientProxyMessageForPhone);
mqttClientProxyMessageForPhone = NULL;
}
}
Expand Down Expand Up @@ -495,9 +495,9 @@ bool PhoneAPI::available()
return true; // Always say we have something, because we might need to advance our state machine
case STATE_SEND_PACKETS: {
if (!queueStatusPacketForPhone)
queueStatusPacketForPhone = service.getQueueStatusForPhone();
queueStatusPacketForPhone = service->getQueueStatusForPhone();
if (!mqttClientProxyMessageForPhone)
mqttClientProxyMessageForPhone = service.getMqttClientProxyMessageForPhone();
mqttClientProxyMessageForPhone = service->getMqttClientProxyMessageForPhone();
bool hasPacket = !!queueStatusPacketForPhone || !!mqttClientProxyMessageForPhone;
if (hasPacket)
return true;
Expand All @@ -520,7 +520,7 @@ bool PhoneAPI::available()
#endif

if (!packetForPhone)
packetForPhone = service.getForPhone();
packetForPhone = service->getForPhone();
hasPacket = !!packetForPhone;
// LOG_DEBUG("available hasPacket=%d\n", hasPacket);
return hasPacket;
Expand All @@ -538,7 +538,7 @@ bool PhoneAPI::available()
bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p)
{
printPacket("PACKET FROM PHONE", &p);
service.handleToRadio(p);
service->handleToRadio(p);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/ProtobufModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template <class T> class ProtobufModule : protected SinglePortModule
/**
* Return a mesh packet which has been preinited with a particular protobuf data payload and port number.
* You can then send this packet (after customizing any of the payload fields you might need) with
* service.sendToMesh()
* service->sendToMesh()
*/
meshtastic_MeshPacket *allocDataProtobuf(const T &payload)
{
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ bool RadioInterface::init()
{
LOG_INFO("Starting meshradio init...\n");

configChangedObserver.observe(&service.configChanged);
configChangedObserver.observe(&service->configChanged);
preflightSleepObserver.observe(&preflightSleep);
notifyDeepSleepObserver.observe(&notifyDeepSleep);

Expand Down Expand Up @@ -585,4 +585,4 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p)

sendingPacket = p;
return p->encrypted.size + sizeof(PacketHeader);
}
}
4 changes: 2 additions & 2 deletions src/mesh/SinglePortModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SinglePortModule : public MeshModule
/**
* Return a mesh packet which has been preinited as a data packet with a particular port number.
* You can then send this packet (after customizing any of the payload fields you might need) with
* service.sendToMesh()
* service->sendToMesh()
*/
meshtastic_MeshPacket *allocDataPacket()
{
Expand All @@ -36,4 +36,4 @@ class SinglePortModule : public MeshModule

return p;
}
};
};
2 changes: 2 additions & 0 deletions src/mesh/mesh-pb-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
// FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in
// RAM #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
#ifndef MAX_RX_TOPHONE
#define MAX_RX_TOPHONE 32
#endif

/// max number of nodes allowed in the mesh
#ifndef MAX_NUM_NODES
Expand Down
6 changes: 3 additions & 3 deletions src/modules/AdminModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void AdminModule::handleSetOwner(const meshtastic_User &o)
}

if (changed) { // If nothing really changed, don't broadcast on the network or write to flash
service.reloadOwner(!hasOpenEditTransaction);
service->reloadOwner(!hasOpenEditTransaction);
saveChanges(SEGMENT_DEVICESTATE);
}
}
Expand Down Expand Up @@ -848,7 +848,7 @@ void AdminModule::saveChanges(int saveWhat, bool shouldReboot)
{
if (!hasOpenEditTransaction) {
LOG_INFO("Saving changes to disk\n");
service.reloadConfig(saveWhat); // Calls saveToDisk among other things
service->reloadConfig(saveWhat); // Calls saveToDisk among other things
} else {
LOG_INFO("Delaying save of changes to disk until the open transaction is committed\n");
}
Expand Down Expand Up @@ -879,7 +879,7 @@ void AdminModule::handleSetHamMode(const meshtastic_HamParameters &p)
channels.setChannel(primaryChannel);
channels.onConfigChanged();

service.reloadOwner(false);
service->reloadOwner(false);
saveChanges(SEGMENT_CONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS);
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/AtakPluginModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtast
pb_encode_to_bytes(decompressedCopy->decoded.payload.bytes, sizeof(decompressedCopy->decoded.payload),
meshtastic_TAKPacket_fields, &uncompressed);

service.sendToPhone(decompressedCopy);
service->sendToPhone(decompressedCopy);
}
return;
}
}
8 changes: 4 additions & 4 deletions src/modules/CannedMessageModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
#endif
break;
case 0xaf: // fn+space send network ping like double press does
service.refreshLocalMeshNode();
if (service.trySendPosition(NODENUM_BROADCAST, true)) {
service->refreshLocalMeshNode();
if (service->trySendPosition(NODENUM_BROADCAST, true)) {
showTemporaryMessage("Position \nUpdate Sent");
} else {
showTemporaryMessage("Node Info \nUpdate Sent");
Expand Down Expand Up @@ -388,7 +388,7 @@ void CannedMessageModule::sendText(NodeNum dest, ChannelIndex channel, const cha

LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes);

service.sendToMesh(
service->sendToMesh(
p, RX_SRC_LOCAL,
true); // send to mesh, cc to phone. Even if there's no phone connected, this stores the message to match ACKs
}
Expand Down Expand Up @@ -1048,7 +1048,7 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket &
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
requestFocus(); // Tell Screen::setFrames that our module's frame should be shown, even if not "first" in the frameset
this->runState = CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED;
this->incoming = service.getNodenumFromRequestId(mp.decoded.request_id);
this->incoming = service->getNodenumFromRequestId(mp.decoded.request_id);
meshtastic_Routing decoded = meshtastic_Routing_init_default;
pb_decode_from_bytes(mp.decoded.payload.bytes, mp.decoded.payload.size, meshtastic_Routing_fields, &decoded);
this->ack = decoded.error_reason == meshtastic_Routing_Error_NONE;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/DetectionSensorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void DetectionSensorModule::sendDetectionMessage()
}
LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes);
lastSentToMesh = millis();
service.sendToMesh(p);
service->sendToMesh(p);
delete[] message;
}

Expand All @@ -97,7 +97,7 @@ void DetectionSensorModule::sendCurrentStateMessage()
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
LOG_INFO("Sending message id=%d, dest=%x, msg=%.*s\n", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes);
lastSentToMesh = millis();
service.sendToMesh(p);
service->sendToMesh(p);
delete[] message;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/DropzoneModule.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if !MESHTASTIC_EXCLUDE_DROPZONE

#include "DropzoneModule.h"
#include "MeshService.h"
#include "Meshservice->h"
#include "configuration.h"
#include "gps/GeoCoord.h"
#include "gps/RTC.h"
Expand All @@ -20,7 +20,7 @@ int32_t DropzoneModule::runOnce()
{
// Send on a 5 second delay from receiving the matching request
if (startSendConditions != 0 && (startSendConditions + 5000U) < millis()) {
service.sendToMesh(sendConditions(), RX_SRC_LOCAL);
service->sendToMesh(sendConditions(), RX_SRC_LOCAL);
startSendConditions = 0;
}
// Run every second to check if we need to send conditions
Expand Down
2 changes: 1 addition & 1 deletion src/modules/NeighborInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void NeighborInfoModule::sendNeighborInfo(NodeNum dest, bool wantReplies)
p->to = dest;
p->decoded.want_response = wantReplies;
printNeighborInfo("SENDING", &neighborInfo);
service.sendToMesh(p, RX_SRC_LOCAL, true);
service->sendToMesh(p, RX_SRC_LOCAL, true);
}

/*
Expand Down
Loading

0 comments on commit f970c46

Please sign in to comment.