2021-06-27 10:56:28 -07:00
# include "configuration.h"
2024-03-25 05:33:57 -06:00
# if !MESHTASTIC_EXCLUDE_GPS
# include "GPS.h"
# endif
2020-02-02 12:45:32 -08:00
2020-07-09 19:57:55 -07:00
# include "../concurrency/Periodic.h"
# include "BluetoothCommon.h" // needed for updateBatteryLevel, FIXME, eventually when we pull mesh out into a lib we shouldn't be whacking bluetooth from here
2020-03-18 19:15:51 -07:00
# include "MeshService.h"
2020-02-03 09:13:19 -08:00
# include "NodeDB.h"
2020-03-03 13:31:44 -08:00
# include "PowerFSM.h"
2020-10-08 07:28:57 +08:00
# include "RTC.h"
2023-06-17 09:10:09 -05:00
# include "TypeConversions.h"
2020-03-18 19:15:51 -07:00
# include "main.h"
# include "mesh-pb-constants.h"
2024-11-04 05:05:03 -06:00
# include "meshUtils.h"
2022-02-27 00:18:35 -08:00
# include "modules/NodeInfoModule.h"
# include "modules/PositionModule.h"
2025-07-20 20:12:10 -05:00
# include "modules/RoutingModule.h"
2020-12-05 10:00:46 +08:00
# include "power.h"
2024-03-25 05:33:57 -06:00
# include <assert.h>
# include <string>
2020-02-02 12:45:32 -08:00
2024-08-01 19:29:49 -05:00
# if ARCH_PORTDUINO
# include "PortduinoGlue.h"
# endif
2020-02-02 12:45:32 -08:00
/*
receivedPacketQueue - this is a queue of messages we ' ve received from the mesh , which we are keeping to deliver to the phone .
2020-03-18 19:15:51 -07:00
It is implemented with a FreeRTos queue ( wrapped with a little RTQueue class ) of pointers to MeshPacket protobufs ( which were
alloced with new ) . After a packet ptr is removed from the queue and processed it should be deleted . ( eventually we should move
sent packets into a ' sentToPhone ' queue of packets we can delete just as soon as we are sure the phone has acked those packets -
when the phone writes to FromNum )
2020-02-02 12:45:32 -08:00
2020-03-18 19:15:51 -07:00
mesh - an instance of Mesh class . Which manages the interface to the mesh radio library , reception of packets from other nodes ,
arbitrating to select a node number and keeping the current nodedb .
2020-02-02 12:45:32 -08:00
*/
2020-02-08 12:42:54 -08:00
/* Broadcast when a newly powered mesh node wants to find a node num it can use
2023-07-14 17:25:20 -04:00
The algorithm is as follows :
2020-03-18 19:15:51 -07:00
* when a node starts up , it broadcasts their user and the normal flow is for all other nodes to reply with their User as well ( so
the new node can build its node db )
2020-02-08 12:42:54 -08:00
*/
2020-02-02 12:45:32 -08:00
2024-08-01 19:29:49 -05:00
MeshService * service ;
2020-02-08 10:00:15 -08:00
2023-07-08 20:37:04 -05:00
static MemoryDynamic < meshtastic_MqttClientProxyMessage > staticMqttClientProxyMessagePool ;
2023-01-21 18:22:19 +01:00
static MemoryDynamic < meshtastic_QueueStatus > staticQueueStatusPool ;
2023-01-04 14:56:52 +02:00
2024-08-10 08:33:42 -05:00
static MemoryDynamic < meshtastic_ClientNotification > staticClientNotificationPool ;
2023-07-08 20:37:04 -05:00
Allocator < meshtastic_MqttClientProxyMessage > & mqttClientProxyMessagePool = staticMqttClientProxyMessagePool ;
2024-08-10 08:33:42 -05:00
Allocator < meshtastic_ClientNotification > & clientNotificationPool = staticClientNotificationPool ;
2023-01-21 18:22:19 +01:00
Allocator < meshtastic_QueueStatus > & queueStatusPool = staticQueueStatusPool ;
2023-01-04 14:56:52 +02:00
2020-04-17 09:48:54 -07:00
# include "Router.h"
2020-02-03 09:13:19 -08:00
2023-07-08 20:37:04 -05:00
MeshService : : MeshService ( )
2025-09-09 08:21:46 -05:00
# ifdef ARCH_PORTDUINO
: toPhoneQueue ( MAX_RX_TOPHONE ) , toPhoneQueueStatusQueue ( MAX_RX_QUEUESTATUS_TOPHONE ) ,
toPhoneMqttProxyQueue ( MAX_RX_MQTTPROXY_TOPHONE ) , toPhoneClientNotificationQueue ( MAX_RX_NOTIFICATION_TOPHONE )
# endif
2020-02-02 12:45:32 -08:00
{
2023-01-21 14:34:29 +01:00
lastQueueStatus = { 0 , 0 , 16 , 0 } ;
2020-02-02 12:45:32 -08:00
}
void MeshService : : init ( )
{
2024-03-25 05:33:57 -06:00
# if HAS_GPS
2020-09-06 14:45:43 -07:00
if ( gps )
gpsObserver . observe ( & gps - > newStatus ) ;
2024-03-25 05:33:57 -06:00
# endif
2020-02-06 10:58:19 -08:00
}
2023-01-21 18:22:19 +01:00
int MeshService : : handleFromRadio ( const meshtastic_MeshPacket * mp )
2020-02-17 17:47:01 -08:00
{
2021-08-02 22:07:39 -07:00
powerFSM . trigger ( EVENT_PACKET_FOR_PHONE ) ; // Possibly keep the node from sleeping
2020-03-03 13:31:44 -08:00
2024-03-21 09:06:37 -05:00
nodeDB - > updateFrom ( * mp ) ; // update our DB state based off sniffing every RX packet from the radio
2024-11-04 05:05:03 -06:00
bool isPreferredRebroadcaster =
IS_ONE_OF ( config . device . role , meshtastic_Config_DeviceConfig_Role_ROUTER , meshtastic_Config_DeviceConfig_Role_REPEATER ) ;
2023-08-01 18:24:40 -05:00
if ( mp - > which_payload_variant = = meshtastic_MeshPacket_decoded_tag & &
mp - > decoded . portnum = = meshtastic_PortNum_TELEMETRY_APP & & mp - > decoded . request_id > 0 ) {
2024-11-04 20:09:23 +08:00
LOG_DEBUG ( " Received telemetry response. Skip sending our NodeInfo " ) ; // because this potentially a Repeater which will
// ignore our request for its NodeInfo
2024-03-21 09:06:37 -05:00
} else if ( mp - > which_payload_variant = = meshtastic_MeshPacket_decoded_tag & & ! nodeDB - > getMeshNode ( mp - > from ) - > has_user & &
2024-11-04 21:06:12 +01:00
nodeInfoModule & & ! isPreferredRebroadcaster & & ! nodeDB - > isFull ( ) ) {
2024-07-12 11:48:35 -05:00
if ( airTime - > isTxAllowedChannelUtil ( true ) ) {
2025-03-07 20:33:23 -05:00
// Hops used by the request. If somebody in between running modified firmware modified it, ignore it
auto hopStart = mp - > hop_start ;
auto hopLimit = mp - > hop_limit ;
uint8_t hopsUsed = hopStart < hopLimit ? config . lora . hop_limit : hopStart - hopLimit ;
if ( hopsUsed > config . lora . hop_limit + 2 ) {
LOG_DEBUG ( " Skip send NodeInfo: %d hops away is too far away " , hopsUsed ) ;
} else {
LOG_INFO ( " Heard new node on ch. %d, send NodeInfo and ask for response " , mp - > channel ) ;
nodeInfoModule - > sendOurNodeInfo ( mp - > from , true , mp - > channel ) ;
}
2024-07-12 11:48:35 -05:00
} else {
2024-11-04 12:16:25 -06:00
LOG_DEBUG ( " Skip sending NodeInfo > 25%% ch. util " ) ;
2024-07-12 11:48:35 -05:00
}
2023-02-11 13:57:51 +01:00
}
2020-02-17 17:47:01 -08:00
2023-02-11 13:57:51 +01:00
printPacket ( " Forwarding to phone " , mp ) ;
2023-03-14 22:50:32 +01:00
sendToPhone ( packetPool . allocCopy ( * mp ) ) ;
2021-03-05 11:44:45 +08:00
2020-04-17 09:48:54 -07:00
return 0 ;
2020-02-02 12:45:32 -08:00
}
2020-02-08 09:39:26 -08:00
/// Do idle processing (mostly processing messages which have been queued from the radio)
void MeshService : : loop ( )
{
2023-01-04 14:56:52 +02:00
if ( lastQueueStatus . free = = 0 ) { // check if there is now free space in TX queue
2023-01-21 18:22:19 +01:00
meshtastic_QueueStatus qs = router - > getQueueStatus ( ) ;
2023-01-04 14:56:52 +02:00
if ( qs . free ! = lastQueueStatus . free )
( void ) sendQueueStatusToPhone ( qs , 0 , 0 ) ;
}
2020-04-17 09:48:54 -07:00
if ( oldFromNum ! = fromNum ) { // We don't want to generate extra notifies for multiple new packets
2024-01-28 14:53:39 +01:00
int result = fromNumChanged . notifyObservers ( fromNum ) ;
if ( result = = 0 ) // If any observer returns non-zero, we will try again
oldFromNum = fromNum ;
2020-04-17 09:48:54 -07:00
}
2020-02-08 09:39:26 -08:00
}
2020-02-11 11:56:48 -08:00
/// The radioConfig object just changed, call this to force the hw to change to the new settings
2025-03-16 08:19:17 -05:00
void MeshService : : reloadConfig ( int saveWhat )
2020-02-11 11:56:48 -08:00
{
// If we can successfully set this radio to these settings, save them to disk
2020-10-29 13:26:36 +08:00
// This will also update the region as needed
2025-03-16 08:19:17 -05:00
nodeDB - > resetRadioConfig ( ) ; // Don't let the phone send us fatally bad settings
2020-12-05 10:00:46 +08:00
2021-03-11 18:29:47 +08:00
configChanged . notifyObservers ( NULL ) ; // This will cause radio hardware to change freqs etc
2024-03-21 09:06:37 -05:00
nodeDB - > saveToDisk ( saveWhat ) ;
2020-02-11 11:56:48 -08:00
}
2020-09-16 09:08:35 -07:00
/// The owner User record just got updated, update our node DB and broadcast the info into the mesh
2022-11-20 19:50:45 -06:00
void MeshService : : reloadOwner ( bool shouldSave )
2020-09-16 09:08:35 -07:00
{
2024-10-14 06:11:43 +02:00
// LOG_DEBUG("reloadOwner()");
2021-10-29 13:28:48 +00:00
// update our local data directly
2024-03-21 09:06:37 -05:00
nodeDB - > updateUser ( nodeDB - > getNodeNum ( ) , owner ) ;
2022-02-27 02:21:02 -08:00
assert ( nodeInfoModule ) ;
2022-11-20 19:50:45 -06:00
// update everyone else and save to disk
if ( nodeInfoModule & & shouldSave ) {
2022-02-27 02:21:02 -08:00
nodeInfoModule - > sendOurNodeInfo ( ) ;
2022-11-20 19:50:45 -06:00
}
2020-09-16 09:08:35 -07:00
}
2023-12-11 15:11:10 +01:00
// search the queue for a request id and return the matching nodenum
NodeNum MeshService : : getNodenumFromRequestId ( uint32_t request_id )
{
NodeNum nodenum = 0 ;
for ( int i = 0 ; i < toPhoneQueue . numUsed ( ) ; i + + ) {
meshtastic_MeshPacket * p = toPhoneQueue . dequeuePtr ( 0 ) ;
if ( p - > id = = request_id ) {
nodenum = p - > to ;
2023-12-11 15:44:32 +01:00
// make sure to continue this to make one full loop
2023-12-11 15:11:10 +01:00
}
2023-12-11 15:44:32 +01:00
// put it right back on the queue
toPhoneQueue . enqueue ( p , 0 ) ;
2023-12-11 15:11:10 +01:00
}
return nodenum ;
}
2020-04-22 14:55:36 -07:00
/**
* Given a ToRadio buffer parse it and properly handle it ( setup radio , owner or send packet into the mesh )
2020-04-25 10:59:40 -07:00
* Called by PhoneAPI . handleToRadio . Note : p is a scratch buffer , this function is allowed to write to it but it can not keep a
* reference
2020-04-22 14:55:36 -07:00
*/
2023-01-21 18:22:19 +01:00
void MeshService : : handleToRadio ( meshtastic_MeshPacket & p )
2020-02-02 12:45:32 -08:00
{
2024-12-03 13:21:24 +01:00
# if defined(ARCH_PORTDUINO)
if ( SimRadio : : instance & & p . decoded . portnum = = meshtastic_PortNum_SIMULATOR_APP ) {
// Simulates device received a packet via the LoRa chip
SimRadio : : instance - > unpackAndReceive ( p ) ;
2023-01-21 14:34:29 +01:00
return ;
2022-10-01 12:06:59 +02:00
}
2023-01-21 14:34:29 +01:00
# endif
2.6 changes (#5806)
* 2.6 protos
* [create-pull-request] automated change (#5789)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Hello world support for UDP broadcasts over the LAN on ESP32 (#5779)
* UDP local area network meshing on ESP32
* Logs
* Comment
* Update UdpMulticastThread.h
* Changes
* Only use router->send
* Make NodeDatabase (and file) independent of DeviceState (#5813)
* Make NodeDatabase (and file) independent of DeviceState
* 70
* Remove logging statement no longer needed
* Explicitly set CAD symbols, improve slot time calculation and adjust CW size accordingly (#5772)
* File system persistence fixes
* [create-pull-request] automated change (#6000)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Update ref
* Back to 80
* [create-pull-request] automated change (#6002)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* 2.6 <- Next hop router (#6005)
* Initial version of NextHopRouter
* Set original hop limit in header flags
* Short-circuit to FloodingRouter for broadcasts
* If packet traveled 1 hop, set `relay_node` as `next_hop` for the original transmitter
* Set last byte to 0xFF if it ended at 0x00
As per an idea of @S5NC
* Also update next-hop based on received DM for us
* temp
* Add 1 retransmission for intermediate hops when using NextHopRouter
* Add next_hop and relayed_by in PacketHistory for setting next-hop and handle flooding fallback
* Update protos, store multiple relayers
* Remove next-hop update logic from NeighborInfoModule
* Fix retransmissions
* Improve ACKs for repeated packets and responses
* Stop retransmission even if there's not relay node
* Revert perhapsRebroadcast()
* Remove relayer if we cancel a transmission
* Better checking for fallback to flooding
* Fix newlines in traceroute print logs
* Stop retransmission for original packet
* Use relayID
* Also when want_ack is set, we should try to retransmit
* Fix cppcheck error
* Fix 'router' not in scope error
* Fix another cppcheck error
* Check for hop_limit and also update next hop when `hop_start == hop_limit` on ACK
Also check for broadcast in `getNextHop()`
* Formatting and correct NUM_RETRANSMISSIONS
* Update protos
* Start retransmissions in NextHopRouter if ReliableRouter didn't do it
* Handle repeated/fallback to flooding packets properly
First check if it's not still in the TxQueue
* Guard against clients setting `next_hop`/`relay_node`
* Don't cancel relay if we were the assigned next-hop
* Replies (e.g. tapback emoji) are also a valid confirmation of receipt
---------
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
* fix "native" compiler errors/warnings NodeDB.h
* fancy T-Deck / SenseCAP Indicator / unPhone / PICOmputer-S3 TFT screen (#3259)
* lib update: light theme
* fix merge issue
* lib update: home buttons + button try-fix
* lib update: icon color fix
* lib update: fix instability/crash on notification
* update lib: timezone
* timezone label
* lib update: fix set owner
* fix spiLock in RadioLibInterface
* add picomputer tft build
* picomputer build
* fix compiler error std::find()
* fix merge
* lib update: theme runtime config
* lib update: packet logger + T-Deck Plus
* lib update: mesh detector
* lib update: fix brightness & trackball crash
* try-fix less paranoia
* sensecap indicator updates
* lib update: indicator fix
* lib update: statistic & some fixes
* lib-update: other T-Deck touch driver
* use custom touch driver for Indicator
* lower tft task prio
* prepare LVGL ST7789 driver
* lib update: try-fix audio
* Drop received packets from self
* Additional decoded packet ignores
* Honor flip & color for Heltec T114 and T190 (#4786)
* Honor TFT_MESH color if defined for Heltec T114 or T190
* Temporary: point lib_deps at fork of Heltec's ST7789 library
For demo only, until ST7789 is merged
* Update lib_deps; tidy preprocessor logic
* Download debian files after firmware zip
* set title for protobufs bump PR (#4792)
* set title for version bump PR (#4791)
* Enable Dependabot
* chore: trunk fmt
* fix dependabot syntax (#4795)
* fix dependabot syntax
* Update dependabot.yml
* Update dependabot.yml
* Bump peter-evans/create-pull-request from 6 to 7 in /.github/workflows (#4797)
* Bump docker/build-push-action from 5 to 6 in /.github/workflows (#4800)
* Actions: Semgrep Images have moved from returntocorp to semgrep (#4774)
https://hub.docker.com/r/returntocorp/semgrep notes: "We've moved!
Official Docker images for Semgrep now available at semgrep/semgrep."
Patch updates our CI workflow for these images.
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Bump meshtestic from `31ee3d9` to `37245b3` (#4799)
Bumps [meshtestic](https://github.com/meshtastic/meshTestic) from `31ee3d9` to `37245b3`.
- [Commits](https://github.com/meshtastic/meshTestic/compare/31ee3d90c8bef61e835c3271be2c7cda8c4a5cc2...37245b3d612a9272f546bbb092837bafdad46bc2)
---
updated-dependencies:
- dependency-name: meshtestic
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* [create-pull-request] automated change (#4789)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Bump pnpm/action-setup from 2 to 4 in /.github/workflows (#4798)
Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 2 to 4.
- [Release notes](https://github.com/pnpm/action-setup/releases)
- [Commits](https://github.com/pnpm/action-setup/compare/v2...v4)
---
updated-dependencies:
- dependency-name: pnpm/action-setup
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Raspberry Pico2 - needs protos
* Re-order doDeepSleep (#4802)
Make sure PMU sleep takes place before I2C ends
* [create-pull-request] automated change
* heltec-wireless-bridge
requires Proto PR first
* feat: trigger class update when protobufs are changed
* meshtastic/ is a test suite; protobufs/ contains protobufs;
* Update platform-native to pick up portduino crash fix (#4807)
* Hopefully extract and commit to meshtastic.github.io
* CI fixes
* [Board] DIY "t-energy-s3_e22" (#4782)
* New variant "t-energy-s3_e22"
- Lilygo T-Energy-S3
- NanoVHF "Mesh-v1.06-TTGO-T18" board
- Ebyte E22 Series
* add board_level = extra
* Update variant.h
---------
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
* Consolidate variant build steps (#4806)
* poc: consolidate variant build steps
* use build-variant action
* only checkout once and clean up after run
* Revert "Consolidate variant build steps (#4806)" (#4816)
This reverts commit 9f8d86cb25febfb86c57f395549b7deb82458065.
* Make Ublox code more readable (#4727)
* Simplify Ublox code
Ublox comes in a myriad of versions and settings. Presently our
configuration code does a lot of branching based on versions being
or not being present.
This patch adds version detection earlier in the piece and branches
on the set gnssModel instead to create separate setup methods for Ublox 6,
Ublox 7/8/9, and Ublox10.
Additionally, adds a macro to make the code much shorter and more
readable.
* Make trunk happy
* Make trunk happy
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* Consider the LoRa header when checking packet length
* Minor fix (#4666)
* Minor fixes
It turns out setting a map value with the index notation causes
an lookup that can be avoided with emplace. Apply this to one line in
the StoreForward module.
Fix also Cppcheck-determined highly minor performance increase by
passing gpiochipname as a const reference :)
The amount of cycles used on this laptop while learning about these
callouts from cppcheck is unlikely to ever be more than the cycles
saved by the fixes ;)
* Update PortduinoGlue.cpp
* Revert "Update classes on protobufs update" (#4824)
* Revert "Update classes on protobufs update"
* remove quotes to fix trunk.
---------
Co-authored-by: Tom Fifield <tom@tomfifield.net>
* Implement optional second I2C bus for NRF52840
Enabled at compile-time if WIRE_INFERFACES_COUNT defined as 2
* Add I2C bus to Heltec T114 header pins
SDA: P0.13
SCL: P0.16
Uses bus 1, leaving bus 0 routed to the unpopulated footprint for the RTC (general future-proofing)
* Tidier macros
* Swap SDA and SCL
SDA=P0.16, SCL=P0.13
* Refactor and consolidate time window logic (#4826)
* Refactor and consolidate windowing logic
* Trunk
* Fixes
* More
* Fix braces and remove unused now variables.
There was a brace in src/mesh/RadioLibInterface.cpp that was breaking
compile on some architectures.
Additionally, there were some brace errors in
src/modules/Telemetry/AirQualityTelemetry.cpp
src/modules/Telemetry/EnvironmentTelemetry.cpp
src/mesh/wifi/WiFiAPClient.cpp
Move throttle include in WifiAPClient.cpp to top.
Add Default.h to sleep.cpp
rest of files just remove unused now variables.
* Remove a couple more meows
---------
Co-authored-by: Tom Fifield <tom@tomfifield.net>
* Rename message length headers and set payload max to 255 (#4827)
* Rename message length headers and set payload max to 255
* Add MESHTASTIC_PKC_OVERHEAD
* compare to MESHTASTIC_HEADER_LENGTH
---------
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
* Check for null before printing debug (#4835)
* fix merge
* try-fix crash
* lib update: fix neighbors
* fix GPIO0 mode after I2S audio
* lib update: audio fix
* lib update: fixes and improvements
* extra
* added ILI9342 (from master)
* device-ui persistency
* review update
* fix request, add handled
* fix merge issue
* fix merge issue
* remove newline
* remove newlines from debug log
* playing with locks; but needs more testing
* diy mesh-tab initial files
* board definition for mesh-tab (not yet used)
* use DISPLAY_SET_RESOLUTION to avoid hw dependency in code
* no telemetry for Indicator
* 16MB partition for Indicator
* 8MB partition for Indicator
* stability: add SPI lock before saving via littleFS
* dummy for config transfer (#5154)
* update indicator (due to compile and linker errors)
* remove faulty partition line
* fix missing include
* update indicator board
* update mesh-tab ILI9143 TFT
* fix naming
* mesh-tab targets
* try: disable duplicate locks
* fix nodeDB erase loop when free mem returns invalid value (0, -1).
* upgrade toolchain for nrf52 to gcc 9.3.1
* try-fix (workaround) T-Deck audio crash
* update mesh-tab tft configs
* set T-Deck audio to unused 48 (mem mclk)
* swap mclk to gpio 21
* update meshtab voltage divider
* update mesh-tab ini
* Fixed the issue that indicator device uploads via rp2040 serial port in some cases.
* Fixed the issue that the touch I2C address definition was not effective.
* Fixed the issue that the wifi configuration saved to RAM did not take effect.
* rotation fix; added ST7789 3.2" display
* dreamcatcher: assign GPIO44 to audio mclk
* mesh-tab touch updates
* add mesh-tab powersave as default
* fix DIO1 wakeup
* mesh-tab: enable alert message menu
* Streamline board definitions for first tech preview. (#5390)
* Streamline board definitions for first tech preview. TBD: Indicator Support
* add point-of-checkin
* use board/unphone.json
---------
Co-authored-by: mverch67 <manuel.verch@gmx.de>
* fix native targets
* add RadioLib debugging options for (T-Deck)
* fix T-Deck build
* fix native tft targets for rpi
* remove wrong debug defines
* t-deck-tft button is handled in device-ui
* disable default lightsleep for indicator
* Windows Support - Trunk and Platformio (#5397)
* Add support for GPG
* Add usb device support
* Add trunk.io to devcontainer
* Trunk things
* trunk fmt
* formatting
* fix trivy/DS002, checkov/CKV_DOCKER_3
* hide docker extension popup
* fix trivy/DS026, checkov/CKV_DOCKER_2
* fix radioLib warnings for T-Deck target
* wake screen with button only
* use custom touch driver
* define wake button for unphone
* use board definition for mesh-tab
* mesh-tab rotation upside-down
* update platform native
* use MESH_TAB hardware model definition
* radioLib update (fix crash/assert)
* reference seeed indicator fix commit arduino-esp32
* Remove unneeded file change :)
* disable serial module and tcp socket api for standalone devices (#5591)
* disable serial module and tcp socket api for standalone devices
* just disable webserver, leave wifi available
* disable socket api
* mesh-tab: lower I2C touch frequency
* log error when packet queue is full
* add more locking for shared SPI devices (#5595)
* add more locking for shared SPI devices
* call initSPI before the lock is used
* remove old one
* don't double lock
* Add missing unlock
* More missing unlocks
* Add locks to SafeFile, remove from `readcb`, introduce some LockGuards
* fix lock in setupSDCard()
* pull radiolib trunk with SPI-CS fixes
* change ContentHandler to Constructor type locks, where applicable
---------
Co-authored-by: mverch67 <manuel.verch@gmx.de>
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
* T-Deck: revert back to lovyanGFX touch driver
* T-Deck: increase allocated PSRAM by 50%
* mesh-tab: streamline target definitions
* update RadioLib 7.1.2
* mesh-tab: fix touch rotation 4.0 inch display
* Mesh-Tab platformio: 4.0inch: increase SPI frequency to max
* mesh-tab: fix rotation for 3.5 IPS capacitive display
* mesh-tab: fix rotation for 3.2 IPS capacitive display
* restructure device-ui library into sub-directories
* preparations for generic DisplayDriverFactory
* T-Deck: increase LVGL memory size
* update lib
* trunk fmt
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Jason Murray <15822260+scruplelesswizard@users.noreply.github.com>
Co-authored-by: Jason Murray <jason@chaosaffe.io>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Austin <vidplace7@gmail.com>
Co-authored-by: virgil <virgil.wang.cj@gmail.com>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Kalle Lilja <15094562+ThatKalle@users.noreply.github.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>
* Version this
* Update platformio.ini (#6006)
* tested higher speed and it works
* Un-extra
* Add -tft environments to the ci matrix
* Exclude unphone tft for now. Something is wonky
* fixed Indicator touch issue (causing IO expander issues), added more RAM
* update lib
* fixed Indicator touch issue (causing IO expander issues), added more RAM (#6013)
* increase T-Deck PSRAM to avoid too early out-of-memory when messages fill up the storage
* update device-ui lib
* Fix T-Deck SD card detection (#6023)
* increase T-Deck PSRAM to avoid too early out-of-memory when messages fill up the storage
* fix SDCard for T-Deck; allow SPI frequency config
* meshtasticd: Add X11 480x480 preset (#6020)
* Littlefs per device
* 2.6 update
* [create-pull-request] automated change (#6037)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* InkHUD UI for E-Ink (#6034)
* Decouple ButtonThread from sleep.cpp
Reorganize sleep observables. Don't call ButtonThread methods inside doLightSleep. Instead, handle in class with new lightsleep Observables.
* InkHUD: initial commit (WIP)
Publicly discloses the current work in progress. Not ready for use.
* feat: battery icon
* chore: implement meshtastic/firmware #5454
Clean up some inline functions
* feat: menu & settings for "jump to applet"
* Remove the beforeRender pattern
It hugely complicates things. If we can achieve acceptable performance without it, so much the better.
* Remove previous Map Applet
Needs re-implementation to work without the beforeRender pattern
* refactor: reimplement map applet
Doesn't require own position
Doesn't require the beforeRender pattern to precalculate; now all-at-once in render
Lays groundwork for fixed-size map with custom background image
* feat: autoshow
Allow user to select which applets (if any) should be automatically brought to foreground when they have new data to display
* refactor: tidy-up applet constructors
misc. jobs including:
- consistent naming
- move initializer-list-only constructors to header
- give derived applets unique identifiers for MeshModule and OSThread logging
* hotfix: autoshow always uses FAST update
In future, it *will* often use FAST, but this will be controlled by a WindowManager component which has not yet been written.
Hotfixed, in case anybody is attempting to use this development version on their deployed devices.
* refactor: bringToForeground no longer requests FAST update
In situations where an applet has moved to foreground because of user input, requestUpdate can be manually called, to upgrade to FAST refresh.
More permanent solution for #23e1dfc
* refactor: extract string storage from ThreadedMessageApplet
Separates the code responsible for storing the limited message history, which was previously part of the ThreadedMessageApplet.
We're now also using this code to store the "most recent message". Previously, this was stored in the `InkHUD::settings` struct, which was much less space-efficient.
We're also now storing the latest DM, laying the foundation for an applet to display only DMs, which will complement the threaded message applet.
* fix: text wrapping
Attempts to fix a disparity between `Applet::printWrapped` and `Applet::getWrappedTextHeight`, which would occasionally cause a ThreadedMessageApplet message to render "too short", overlapping other text.
* fix: purge old constructor
This one slipped through the last commit..
* feat: DM Applet
Useful in combination with the ThreadedMessageApplets, which don't show DMs
* fix: applets shouldn't handle events while deactivated
Only one or two applets were actually doing this, but I'm making a habit of having all applets return early from their event handling methods (as good practice), even if those methods are disabled elsewhere (e.g. not observing observable, return false from wantPacket)
* refactor: allow requesting update without requesting autoshow
Some applets may want to redraw, if they are displayed, but not feel the information is worth being brought to foreground for. Example: ActiveNodesApplet, when purging old nodes from list.
* feat: custom "Recently Active" duration
Allows users to tailor how long nodes will appear in the "Recents" applets, to suit the activity level of their mesh.
* refactor: rename some applets
* fix: autoshow
* fix: getWrappedTextHeight
Remove the "simulate" option from printWrapped; too hard to keep inline with genuine printing (because of AdafruitGFX Fonts' xAdvance, mabye?). Instead of simulating, we printWrapped as normal, and discard pixel output by setting crop. Both methods are similarly inefficient, apparently.
* fix: text wrapping in ThreadedMessageApplet
Wrong arguments were passed to Applet::printWrapped
* feat: notifications for text messages
Only shown if current applet does not already display the same info. Autoshow takes priority over notifications, if both would be used to display the same info.
* feat: optimize FAST vs FULL updates
New UpdateMediator class counts the number of each update type, and suggets which one to use, if the code doesn't already have an explicit prefence. Also performs "maintenance refreshes" unprovoked if display is not given an opportunity to before a FULL refresh through organic use.
* chore: update todo list
* fix: rare lock-up of buttons
* refactor: backlight
Replaces the initial proof-of-concept frontlight code for T-Echo
Presses less than 5 seconds momentarily illuminate the display
Presses longer than 5 seconds latch the light, requiring another tap to disable
If user has previously removed the T-Echo's capacitive touch button (some DIY projects), the light is controlled by the on-screen menu. This fallback is used by all T-Echo devices, until a press of the capacitive touch button is detected.
* feat: change tile with aux button
Applied to VM-E290.
Working as is, but a refactor of WindowManager::render is expected shortly, which will also tidy code from this push.
* fix: specify out-of-the-box tile assignments
Prevents placeholder applet showing on initial boot, for devices which use a mult-tile layout by default (VM-E290)
* fix: verify settings version when loading
* fix: wrong settings version
* refactor: remove unimplemented argument from requestUpdate
Specified whether or not to update "async", however the implementation was slightly broken, Applet::requestUpdate is only handled next time WindowManager::runOnce is called. This didn't allow code to actually await an update, which was misleading.
* refactor: renaming
Applet::render becomes Applet::onRender.
Tile::displayedApplet becomes Tile::assignedApplet.
New onRender method name allows us to move some of the pre and post render code from WindowManager into new Applet::render method, which will call onRender for us.
* refactor: rendering
Bit of a tidy-up. No intended change in behavior.
* fix: optimize refresh times
Shorter wait between retrying update if display was previously busy.
Set anticipated update durations closer to observed values. No signifacant performance increase, but does decrease the amount of polling required.
* feat: blocking update for E-Ink
Option to wait for display update to complete before proceeding. Important when shutting down the device.
* refactor: allow system applets to lock rendering
Temporarily prevents other applets from rendering.
* feat: boot and shutdown screens
* feat: BluetoothStatus
Adds a meshtastic::Status object which exposes the state of the Bluetooth connection. Intends to allow decoupling of UI code.
* feat: Bluetooth pairing screen
* fix: InkHUD defaults not honored
* fix: random Bluetooth pin for NicheGraphics UIs
* chore: button interrupts tested
* fix: emoji reactions show as blank messages
* fix: autoshow and notification triggered by outgoing message
* feat: save InkHUD data before reboot
Implemented with a new Observable. Previously, config and a few recent messages were saved on shutdown. These were lost if the device rebooted, for example when firmware settings were changed by a client. Now, the InkHUD config and recent messages saved on reboot, the same as during an intentional shutdown.
* feat: imperial distances
Controlled by the config.display.units setting
* fix: hide features which are not yet implemented
* refactor: faster rendering
Previously, only tiles which requested update were re-rendered. Affected tiles had their region blanked before render, pixel by pixel. Benchmarking revealed that it is significantly faster to memset the framebuffer and redraw all tiles.
* refactor: tile ownership
Tiles and Applets now maintain a reciprocal link, which is enforced by asserts. Less confusing than the old situation, where an applet and a tile may disagree on their relationship. Empty tiles are now identified by a nullptr *Applet, instead of by having the placeholderApplet assigned.
* fix: notifications and battery when menu open
Do render notifications in front of menu; don't render battery icon in front of menu.
* fix: simpler defaults
Don't expose new users to multiplexed applets straight away: make them enable the feature for themselves.
* fix: Inputs::TwoButton interrupts, when only one button in use
* fix: ensure display update is complete when ESP32 enters light sleep
Many panels power down automatically, but some require active intervention from us. If light sleep (ESP32) occurs during a display update, these panels could potentially remain powered on, applying voltage the pixels for an extended period of time, and potentially damaging the display.
* fix: honor per-variant user tile limit
Set as the default value for InkHUD::settings.userTiles.maxCount in nicheGraphics.h
* feat: initial InkHUD support for Wireless Paper v1.1 and VM-E213
* refactor: Heard and Recents Applets
Tidier code, significant speed boost. Possibly no noticable change in responsiveness, but rendering now spends much less time blocking execution, which is important for correction functioning of the other firmware components.
* refactor: use a common pio base config
Easier to make any future PlatformIO config changes
* feat: tips
Show information that we think the user might find helpful. Some info shown first boot only. Other info shown when / if relevant.
* fix: text wrapping for '\n'
Previously, the newline was honored, but the adojining word was not printed.
* Decouple ButtonThread from sleep.cpp
Reorganize sleep observables. Don't call ButtonThread methods inside doLightSleep. Instead, handle in class with new lightsleep Observables.
* feat: BluetoothStatus
Adds a meshtastic::Status object which exposes the state of the Bluetooth connection. Intends to allow decoupling of UI code.
* feat: observable for reboot
* refactor: Heltec VM-E290 installDefaultConfig
* fix: random Bluetooth pin for NicheGraphics UIs
* update device-ui: fix touch/crash issue while light sleep
* Collect inkhud
* fix: InkHUD shouldn't nag about timezone (#6040)
* Guard eink drivers w/ MESHTASTIC_INCLUDE_NICHE_GRAPHICS
* Case sensitive perhaps?
* More case-sensitivity instances
* Moar
* RTC
* Yet another case issue!
* Sigh...
* MUI: BT programming mode (#6046)
* allow BT connection with disabled MUI
* Update device-ui
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* MUI: fix nag timeout, disable BT programming mode for native (#6052)
* allow BT connection with disabled MUI
* Update device-ui
* MUI: fix nag timeout default and remove programming mode for native
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
* remove debuglog leftover
* Wireless Paper: remove stray board_level = extra (#6060)
Makes sure the InkHUD version gets build into the release zip
* Fixed persistence stragglers from NodeDB / Device State divorce (#6059)
* Increase `MAX_THREADS` for InkHUD variants with WiFi (#6064)
* Licensed usage compliance (#6047)
* Prevent psk and legacy admin channel on licensed mode
* Move it
* Consolidate warning strings
* More holes
* Device UI submodule bump
* Prevent licensed users from rebroadcasting unlicensed traffic (#6068)
* Prevent licensed users from rebroadcasting unlicensed traffic
* Added method and enum to make user license status more clear
* MUI: move UI initialization out of main.cpp and adding lightsleep observer + mutex (#6078)
* added device-ui to lightSleep observers for handling graceful sleep; refactoring main.cpp
* bump lib version
* Update device-ui
* unPhone TFT: include into build, enable SD card, increase PSRAM (#6082)
* unPhone-tft: include into build, enable SD card, increase assigned PSRAM
* lib update
* Backup / migrate pub private keys when upgrading to new files in 2.6 (#6096)
* Save a backup of pub/private keys before factory reset
* Fix licensed mode warning
* Unlock spi on else file doesn't exist
* Update device-ui
* Update protos and device-ui
* [create-pull-request] automated change (#6129)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Proto
* [create-pull-request] automated change (#6131)
* Proto update for backup
* [create-pull-request] automated change (#6133)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Update protobufs
* Space
* [create-pull-request] automated change (#6144)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Protos
* [create-pull-request] automated change (#6152)
Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
* Updeet
* device-ui lib update
* fix channel OK button
* device-lib update: fix settings panel -> no scrolling
* device-ui lib: last minute update
* defined(SENSECAP_INDICATOR)
* MUI hot-fix pub/priv keys
* MUI hot-fix username dialog
* MUI: BT programming mode button
* Update protobufs
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>
Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
Co-authored-by: mverch67 <manuel.verch@gmx.de>
Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com>
Co-authored-by: todd-herbert <herbert.todd@gmail.com>
Co-authored-by: Jason Murray <15822260+scruplelesswizard@users.noreply.github.com>
Co-authored-by: Jason Murray <jason@chaosaffe.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
Co-authored-by: Austin <vidplace7@gmail.com>
Co-authored-by: virgil <virgil.wang.cj@gmail.com>
Co-authored-by: Mark Trevor Birss <markbirss@gmail.com>
Co-authored-by: Kalle Lilja <15094562+ThatKalle@users.noreply.github.com>
Co-authored-by: rcarteraz <robert.l.carter2@gmail.com>
2025-03-01 06:18:33 -06:00
p . from = 0 ; // We don't let clients assign nodenums to their sent messages
p . next_hop = NO_NEXT_HOP_PREFERENCE ; // We don't let clients assign next_hop to their sent messages
p . relay_node = NO_RELAY_NODE ; // We don't let clients assign relay_node to their sent messages
2020-02-19 10:53:09 -08:00
2020-04-22 14:55:36 -07:00
if ( p . id = = 0 )
p . id = generatePacketId ( ) ; // If the phone didn't supply one, then pick one
2020-04-17 11:52:20 -07:00
2020-10-09 10:01:13 +08:00
p . rx_time = getValidTime ( RTCQualityFromNet ) ; // Record the time the packet arrived from the phone
2020-10-09 14:16:51 +08:00
// (so we update our nodedb for the local node)
2020-04-17 12:41:01 -07:00
2020-04-22 14:55:36 -07:00
// Send the packet into the mesh
2025-09-09 10:29:07 -05:00
auto heapBefore = memGet . getFreeHeap ( ) ;
auto a = packetPool . allocCopy ( p ) ;
auto heapAfter = memGet . getFreeHeap ( ) ;
LOG_HEAP ( " Alloc in MeshService::handleToRadio() pointer 0x%x, size: %u, free: %u " , a , heapBefore - heapAfter , heapAfter ) ;
2020-02-19 10:53:09 -08:00
2025-09-09 10:29:07 -05:00
sendToMesh ( a , RX_SRC_USER ) ;
2020-04-17 11:52:20 -07:00
2020-04-22 14:55:36 -07:00
bool loopback = false ; // if true send any packet the phone sends back itself (for testing)
if ( loopback ) {
// no need to copy anymore because handle from radio assumes it should _not_ delete
// packetPool.allocCopy(r.variant.packet);
handleFromRadio ( & p ) ;
// handleFromRadio will tell the phone a new packet arrived
2020-03-15 16:27:15 -07:00
}
2020-02-02 12:45:32 -08:00
}
2021-02-11 17:39:53 +08:00
/** Attempt to cancel a previously sent packet from this _local_ node. Returns true if a packet was found we could cancel */
2021-03-05 10:19:27 +08:00
bool MeshService : : cancelSending ( PacketId id )
{
2024-03-21 09:06:37 -05:00
return router - > cancelSending ( nodeDB - > getNodeNum ( ) , id ) ;
2021-02-11 17:39:53 +08:00
}
2023-01-21 18:22:19 +01:00
ErrorCode MeshService : : sendQueueStatusToPhone ( const meshtastic_QueueStatus & qs , ErrorCode res , uint32_t mesh_packet_id )
2023-01-04 14:56:52 +02:00
{
2023-01-21 18:22:19 +01:00
meshtastic_QueueStatus * copied = queueStatusPool . allocCopy ( qs ) ;
2023-01-04 14:56:52 +02:00
copied - > res = res ;
copied - > mesh_packet_id = mesh_packet_id ;
if ( toPhoneQueueStatusQueue . numFree ( ) = = 0 ) {
2024-11-04 19:15:59 -06:00
LOG_INFO ( " tophone queue status queue is full, discard oldest " ) ;
2023-01-21 18:22:19 +01:00
meshtastic_QueueStatus * d = toPhoneQueueStatusQueue . dequeuePtr ( 0 ) ;
2023-01-04 14:56:52 +02:00
if ( d )
releaseQueueStatusToPool ( d ) ;
}
lastQueueStatus = * copied ;
res = toPhoneQueueStatusQueue . enqueue ( copied , 0 ) ;
fromNum + + ;
return res ? ERRNO_OK : ERRNO_UNKNOWN ;
}
2023-01-21 18:22:19 +01:00
void MeshService : : sendToMesh ( meshtastic_MeshPacket * p , RxSource src , bool ccToPhone )
2020-02-02 12:45:32 -08:00
{
2023-01-04 14:56:52 +02:00
uint32_t mesh_packet_id = p - > id ;
2024-03-21 09:06:37 -05:00
nodeDB - > updateFrom ( * p ) ; // update our local DB for this packet (because phone might have sent position packets etc...)
2020-02-18 20:17:11 -08:00
2020-05-19 11:56:17 -07:00
// Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it
2023-01-04 14:56:52 +02:00
ErrorCode res = router - > sendLocal ( p , src ) ;
/* NOTE(pboldin): Prepare and send QueueStatus message to the phone as a
* high - priority message . */
2023-01-21 18:22:19 +01:00
meshtastic_QueueStatus qs = router - > getQueueStatus ( ) ;
2023-01-04 14:56:52 +02:00
ErrorCode r = sendQueueStatusToPhone ( qs , res , mesh_packet_id ) ;
if ( r ! = ERRNO_OK ) {
LOG_DEBUG ( " Can't send status to phone " ) ;
}
2022-04-26 19:40:24 -05:00
2024-11-04 21:13:54 +01:00
if ( ( res = = ERRNO_OK | | res = = ERRNO_SHOULD_RELEASE ) & & ccToPhone ) { // Check if p is not released in case it couldn't be sent
2025-09-09 10:29:07 -05:00
auto heapBefore = memGet . getFreeHeap ( ) ;
auto a = packetPool . allocCopy ( * p ) ;
auto heapAfter = memGet . getFreeHeap ( ) ;
LOG_HEAP ( " Alloc in MeshService::sendToMesh() pointer 0x%x, size: %u, free: %u " , a , heapBefore - heapAfter , heapAfter ) ;
sendToPhone ( a ) ;
2022-04-26 19:40:24 -05:00
}
2024-11-04 21:13:54 +01:00
// Router may ask us to release the packet if it wasn't sent
if ( res = = ERRNO_SHOULD_RELEASE ) {
releaseToPool ( p ) ;
}
2020-02-06 08:49:33 -08:00
}
2020-02-02 12:45:32 -08:00
2024-04-27 08:55:04 -05:00
bool MeshService : : trySendPosition ( NodeNum dest , bool wantReplies )
2020-02-12 14:07:06 -08:00
{
2024-03-21 09:06:37 -05:00
meshtastic_NodeInfoLite * node = nodeDB - > getMeshNode ( nodeDB - > getNodeNum ( ) ) ;
2023-06-17 09:10:09 -05:00
2020-02-12 14:07:06 -08:00
assert ( node ) ;
2024-11-26 14:00:10 -06:00
if ( nodeDB - > hasValidPosition ( node ) ) {
2024-07-05 15:58:16 +02:00
# if HAS_GPS && !MESHTASTIC_EXCLUDE_GPS
2022-02-27 02:21:02 -08:00
if ( positionModule ) {
2024-11-04 12:16:25 -06:00
LOG_INFO ( " Send position ping to 0x%x, wantReplies=%d, channel=%d " , dest , wantReplies , node - > channel ) ;
2023-03-29 13:51:22 +02:00
positionModule - > sendOurPosition ( dest , wantReplies , node - > channel ) ;
2024-04-27 08:55:04 -05:00
return true ;
2021-03-06 10:36:30 +08:00
}
2021-03-25 06:15:15 +08:00
} else {
2024-03-25 05:33:57 -06:00
# endif
2022-02-27 02:21:02 -08:00
if ( nodeInfoModule ) {
2024-11-04 12:16:25 -06:00
LOG_INFO ( " Send nodeinfo ping to 0x%x, wantReplies=%d, channel=%d " , dest , wantReplies , node - > channel ) ;
2023-03-29 13:51:22 +02:00
nodeInfoModule - > sendOurNodeInfo ( dest , wantReplies , node - > channel ) ;
2021-03-06 10:36:30 +08:00
}
}
2024-04-27 08:55:04 -05:00
return false ;
2020-02-12 14:07:06 -08:00
}
2023-01-21 18:22:19 +01:00
void MeshService : : sendToPhone ( meshtastic_MeshPacket * p )
2022-05-07 20:31:21 +10:00
{
2023-10-30 12:12:22 +01:00
perhapsDecode ( p ) ;
2024-07-13 19:36:44 +02:00
# ifdef ARCH_ESP32
# if !MESHTASTIC_EXCLUDE_STOREFORWARD
if ( moduleConfig . store_forward . enabled & & storeForwardModule - > isServer ( ) & &
p - > decoded . portnum = = meshtastic_PortNum_TEXT_MESSAGE_APP ) {
releaseToPool ( p ) ; // Copy is already stored in StoreForward history
fromNum + + ; // Notify observers for packet from radio
return ;
}
# endif
# endif
2022-04-26 19:40:24 -05:00
if ( toPhoneQueue . numFree ( ) = = 0 ) {
2023-10-30 12:12:22 +01:00
if ( p - > decoded . portnum = = meshtastic_PortNum_TEXT_MESSAGE_APP | |
p - > decoded . portnum = = meshtastic_PortNum_RANGE_TEST_APP ) {
2024-11-04 19:15:59 -06:00
LOG_WARN ( " ToPhone queue is full, discard oldest " ) ;
2023-10-30 12:12:22 +01:00
meshtastic_MeshPacket * d = toPhoneQueue . dequeuePtr ( 0 ) ;
if ( d )
releaseToPool ( d ) ;
} else {
2024-11-04 19:15:59 -06:00
LOG_WARN ( " ToPhone queue is full, drop packet " ) ;
2023-10-30 12:12:22 +01:00
releaseToPool ( p ) ;
2024-07-07 16:06:42 +02:00
fromNum + + ; // Make sure to notify observers in case they are reconnected so they can get the packets
2023-10-30 12:12:22 +01:00
return ;
}
2022-04-26 19:40:24 -05:00
}
2025-03-24 22:26:59 +00:00
if ( toPhoneQueue . enqueue ( p , 0 ) = = false ) {
LOG_CRIT ( " Failed to queue a packet into toPhoneQueue! " ) ;
abort ( ) ;
}
2022-04-26 19:40:24 -05:00
fromNum + + ;
}
2023-07-08 20:37:04 -05:00
void MeshService : : sendMqttMessageToClientProxy ( meshtastic_MqttClientProxyMessage * m )
{
2024-11-04 12:16:25 -06:00
LOG_DEBUG ( " Send mqtt message on topic '%s' to client for proxy " , m - > topic ) ;
2023-07-08 20:37:04 -05:00
if ( toPhoneMqttProxyQueue . numFree ( ) = = 0 ) {
2024-11-04 19:15:59 -06:00
LOG_WARN ( " MqttClientProxyMessagePool queue is full, discard oldest " ) ;
2023-07-08 20:37:04 -05:00
meshtastic_MqttClientProxyMessage * d = toPhoneMqttProxyQueue . dequeuePtr ( 0 ) ;
if ( d )
releaseMqttClientProxyMessageToPool ( d ) ;
}
2025-03-24 22:26:59 +00:00
if ( toPhoneMqttProxyQueue . enqueue ( m , 0 ) = = false ) {
LOG_CRIT ( " Failed to queue a packet into toPhoneMqttProxyQueue! " ) ;
abort ( ) ;
}
2023-07-08 20:37:04 -05:00
fromNum + + ;
}
2025-07-20 20:12:10 -05:00
void MeshService : : sendRoutingErrorResponse ( meshtastic_Routing_Error error , const meshtastic_MeshPacket * mp )
{
if ( ! mp ) {
LOG_WARN ( " Cannot send routing error response: null packet " ) ;
return ;
}
// Use the routing module to send the error response
if ( routingModule ) {
routingModule - > sendAckNak ( error , mp - > from , mp - > id , mp - > channel ) ;
} else {
LOG_ERROR ( " Cannot send routing error response: no routing module " ) ;
}
}
2024-08-10 08:33:42 -05:00
void MeshService : : sendClientNotification ( meshtastic_ClientNotification * n )
{
2024-11-04 12:16:25 -06:00
LOG_DEBUG ( " Send client notification to phone " ) ;
2024-08-10 08:33:42 -05:00
if ( toPhoneClientNotificationQueue . numFree ( ) = = 0 ) {
2024-11-04 19:15:59 -06:00
LOG_WARN ( " ClientNotification queue is full, discard oldest " ) ;
2024-08-10 08:33:42 -05:00
meshtastic_ClientNotification * d = toPhoneClientNotificationQueue . dequeuePtr ( 0 ) ;
if ( d )
releaseClientNotificationToPool ( d ) ;
}
2025-03-24 22:26:59 +00:00
if ( toPhoneClientNotificationQueue . enqueue ( n , 0 ) = = false ) {
LOG_CRIT ( " Failed to queue a notification into toPhoneClientNotificationQueue! " ) ;
abort ( ) ;
}
2024-08-10 08:33:42 -05:00
fromNum + + ;
}
2023-06-17 09:10:09 -05:00
meshtastic_NodeInfoLite * MeshService : : refreshLocalMeshNode ( )
2021-03-05 10:19:27 +08:00
{
2024-03-21 09:06:37 -05:00
meshtastic_NodeInfoLite * node = nodeDB - > getMeshNode ( nodeDB - > getNodeNum ( ) ) ;
2021-01-04 09:59:53 +08:00
assert ( node ) ;
// We might not have a position yet for our local node, in that case, at least try to send the time
2021-03-05 10:19:27 +08:00
if ( ! node - > has_position ) {
2021-01-04 09:59:53 +08:00
memset ( & node - > position , 0 , sizeof ( node - > position ) ) ;
node - > has_position = true ;
}
2021-03-05 10:19:27 +08:00
2023-06-17 09:10:09 -05:00
meshtastic_PositionLite & position = node - > position ;
2021-01-04 09:59:53 +08:00
2021-03-27 16:17:01 +08:00
// Update our local node info with our time (even if we don't decide to update anyone else)
2021-03-26 09:30:15 +08:00
node - > last_heard =
2021-03-05 10:19:27 +08:00
getValidTime ( RTCQualityFromNet ) ; // This nodedb timestamp might be stale, so update it if our clock is kinda valid
2021-01-04 09:59:53 +08:00
2023-01-11 07:50:07 -06:00
position . time = getValidTime ( RTCQualityFromNet ) ;
2021-03-27 16:17:01 +08:00
2023-12-02 14:00:20 +01:00
if ( powerStatus - > getHasBattery ( ) = = 1 ) {
updateBatteryLevel ( powerStatus - > getBatteryChargePercent ( ) ) ;
}
2021-01-04 09:59:53 +08:00
return node ;
}
2024-03-25 05:33:57 -06:00
# if HAS_GPS
2021-10-23 03:21:59 +00:00
int MeshService : : onGPSChanged ( const meshtastic : : GPSStatus * newStatus )
2020-02-06 10:58:19 -08:00
{
2020-02-12 14:07:06 -08:00
// Update our local node info with our position (even if we don't decide to update anyone else)
2023-08-12 09:29:19 -05:00
const meshtastic_NodeInfoLite * node = refreshLocalMeshNode ( ) ;
2023-01-21 18:22:19 +01:00
meshtastic_Position pos = meshtastic_Position_init_default ;
2020-09-16 09:18:44 -07:00
2021-10-23 03:21:59 +00:00
if ( newStatus - > getHasLock ( ) ) {
2021-10-24 12:48:48 +00:00
// load data from GPS object, will add timestamp + battery further down
pos = gps - > p ;
2021-03-05 10:19:27 +08:00
} else {
2023-08-24 10:55:49 -05:00
// The GPS has lost lock
2024-11-04 20:09:23 +08:00
# ifdef GPS_DEBUG
2024-10-14 06:11:43 +02:00
LOG_DEBUG ( " onGPSchanged() - lost validLocation " ) ;
2021-10-24 12:48:48 +00:00
# endif
2023-08-24 10:55:49 -05:00
}
2024-03-21 20:45:48 -05:00
// Used fixed position if configured regardless of GPS lock
2023-08-24 10:55:49 -05:00
if ( config . position . fixed_position ) {
2024-11-04 12:16:25 -06:00
LOG_WARN ( " Use fixed position " ) ;
2023-10-11 06:17:05 -05:00
pos = TypeConversions : : ConvertToPosition ( node - > position ) ;
2020-12-09 12:05:15 +08:00
}
2020-02-06 08:49:33 -08:00
2023-09-12 15:54:50 -05:00
// Add a fresh timestamp
pos . time = getValidTime ( RTCQualityFromNet ) ;
2021-10-24 12:48:48 +00:00
// In debug logs, identify position by @timestamp:stage (stage 4 = nodeDB)
2024-10-14 06:11:43 +02:00
LOG_DEBUG ( " onGPSChanged() pos@%x time=%u lat=%d lon=%d alt=%d " , pos . timestamp , pos . time , pos . latitude_i , pos . longitude_i ,
2024-06-21 17:25:54 -05:00
pos . altitude ) ;
2020-08-12 15:51:57 -07:00
2020-12-05 08:46:19 +08:00
// Update our current position in the local DB
2024-03-21 09:06:37 -05:00
nodeDB - > updatePosition ( nodeDB - > getNodeNum ( ) , pos , RX_SRC_LOCAL ) ;
2020-12-05 08:46:19 +08:00
2020-04-10 12:40:44 -07:00
return 0 ;
2020-02-02 12:45:32 -08:00
}
2024-03-25 05:33:57 -06:00
# endif
2023-01-21 14:34:29 +01:00
bool MeshService : : isToPhoneQueueEmpty ( )
2022-10-16 09:58:58 -05:00
{
return toPhoneQueue . isEmpty ( ) ;
2024-10-06 19:40:06 +08:00
}
uint32_t MeshService : : GetTimeSinceMeshPacket ( const meshtastic_MeshPacket * mp )
{
uint32_t now = getTime ( ) ;
uint32_t last_seen = mp - > rx_time ;
int delta = ( int ) ( now - last_seen ) ;
if ( delta < 0 ) // our clock must be slightly off still - not set from GPS yet
delta = 0 ;
return delta ;
2024-11-04 21:06:12 +01:00
}