2020-02-03 09:13:19 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-03-18 19:15:51 -07:00
|
|
|
// low level types
|
2020-02-03 09:13:19 -08:00
|
|
|
|
2020-04-17 09:48:54 -07:00
|
|
|
#include "MemoryPool.h"
|
2020-12-30 12:34:22 +08:00
|
|
|
#include "mesh/mesh-pb-constants.h"
|
2020-02-03 09:13:19 -08:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
2020-06-06 13:16:36 -07:00
|
|
|
typedef uint32_t NodeNum;
|
|
|
|
|
typedef uint32_t PacketId; // A packet sequence number
|
2020-02-03 09:13:19 -08:00
|
|
|
|
2020-11-28 09:56:21 +08:00
|
|
|
#define NODENUM_BROADCAST UINT32_MAX
|
2024-07-21 07:09:10 -05:00
|
|
|
#define NODENUM_BROADCAST_NO_LORA \
|
|
|
|
|
1 // Reserved to only deliver packets over high speed (non-lora) transports, such as MQTT or BLE mesh (not yet implemented)
|
2020-02-03 09:13:19 -08:00
|
|
|
#define ERRNO_OK 0
|
2020-04-23 12:47:41 -07:00
|
|
|
#define ERRNO_NO_INTERFACES 33
|
2024-08-26 15:48:47 -05:00
|
|
|
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
|
|
|
|
|
#define ERRNO_DISABLED 34 // the interface is disabled
|
|
|
|
|
#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID
|
2020-02-03 09:13:19 -08:00
|
|
|
|
2021-10-09 13:48:30 +00:00
|
|
|
/*
|
|
|
|
|
* Source of a received message
|
|
|
|
|
*/
|
|
|
|
|
enum RxSource {
|
2023-01-21 14:34:29 +01:00
|
|
|
RX_SRC_LOCAL, // message was generated locally
|
|
|
|
|
RX_SRC_RADIO, // message was received from radio mesh
|
|
|
|
|
RX_SRC_USER // message was received from end-user device
|
2021-10-09 13:48:30 +00:00
|
|
|
};
|
|
|
|
|
|
2020-05-18 17:35:23 -07:00
|
|
|
/**
|
|
|
|
|
* the max number of hops a message can pass through, used as the default max for hop_limit in MeshPacket.
|
|
|
|
|
*
|
|
|
|
|
* We reserve 3 bits in the header so this could be up to 7, but given the high range of lora and typical usecases, keeping
|
|
|
|
|
* maxhops to 3 should be fine for a while. This also serves to prevent routing/flooding attempts to be attempted for
|
|
|
|
|
* too long.
|
|
|
|
|
**/
|
2020-05-18 17:57:58 -07:00
|
|
|
#define HOP_MAX 7
|
|
|
|
|
|
|
|
|
|
/// We normally just use max 3 hops for sending reliable messages
|
|
|
|
|
#define HOP_RELIABLE 3
|
2020-05-18 17:35:23 -07:00
|
|
|
|
2020-04-17 09:48:54 -07:00
|
|
|
typedef int ErrorCode;
|
|
|
|
|
|
|
|
|
|
/// Alloc and free packets to our global, ISR safe pool
|
2023-01-21 18:22:19 +01:00
|
|
|
extern Allocator<meshtastic_MeshPacket> &packetPool;
|
2021-03-05 10:19:27 +08:00
|
|
|
|
|
|
|
|
/**
|
2021-04-05 09:24:00 +08:00
|
|
|
* Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on
|
|
|
|
|
* the local node. If from is zero this function returns our node number instead
|
2021-03-05 10:19:27 +08:00
|
|
|
*/
|
2024-08-30 21:54:44 +02:00
|
|
|
NodeNum getFrom(const meshtastic_MeshPacket *p);
|
|
|
|
|
|
|
|
|
|
/* Some clients might not properly set priority, therefore we fix it here. */
|
|
|
|
|
void fixPriority(meshtastic_MeshPacket *p);
|