2020-02-03 09:13:19 -08:00
|
|
|
#pragma once
|
2024-03-21 09:06:37 -05:00
|
|
|
#include <vector>
|
2020-02-03 09:13:19 -08:00
|
|
|
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "mesh/generated/meshtastic/admin.pb.h"
|
2023-01-18 14:51:48 -06:00
|
|
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
|
|
|
|
#include "mesh/generated/meshtastic/localonly.pb.h"
|
|
|
|
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
2020-02-03 09:13:19 -08:00
|
|
|
|
|
|
|
|
// this file defines constants which come from mesh.options
|
|
|
|
|
|
|
|
|
|
// Tricky macro to let you find the sizeof a type member
|
|
|
|
|
#define member_size(type, member) sizeof(((type *)0)->member)
|
|
|
|
|
|
|
|
|
|
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
2023-01-18 14:51:48 -06:00
|
|
|
// 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]))
|
2024-08-01 19:29:49 -05:00
|
|
|
#ifndef MAX_RX_TOPHONE
|
2020-06-16 15:26:30 -07:00
|
|
|
#define MAX_RX_TOPHONE 32
|
2024-08-01 19:29:49 -05:00
|
|
|
#endif
|
2020-02-03 09:13:19 -08:00
|
|
|
|
2025-03-18 21:19:51 -04:00
|
|
|
/// max number of nodes allowed in the nodeDB
|
2024-03-21 18:26:37 -05:00
|
|
|
#ifndef MAX_NUM_NODES
|
2025-03-18 21:19:51 -04:00
|
|
|
#if defined(ARCH_STM32WL)
|
|
|
|
|
#define MAX_NUM_NODES 10
|
|
|
|
|
#elif defined(ARCH_NRF52)
|
|
|
|
|
#define MAX_NUM_NODES 80
|
|
|
|
|
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
|
|
|
|
|
#include "Esp.h"
|
|
|
|
|
static inline int get_max_num_nodes()
|
|
|
|
|
{
|
|
|
|
|
uint32_t flash_size = ESP.getFlashChipSize() / (1024 * 1024); // Convert Bytes to MB
|
|
|
|
|
if (flash_size >= 15) {
|
|
|
|
|
return 250;
|
|
|
|
|
} else if (flash_size >= 7) {
|
|
|
|
|
return 200;
|
|
|
|
|
} else {
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#define MAX_NUM_NODES get_max_num_nodes()
|
|
|
|
|
#else
|
2024-03-21 09:06:37 -05:00
|
|
|
#define MAX_NUM_NODES 100
|
|
|
|
|
#endif
|
2025-03-18 21:19:51 -04:00
|
|
|
#endif
|
2024-11-13 18:44:35 -06:00
|
|
|
|
2021-02-16 15:41:52 +08:00
|
|
|
/// Max number of channels allowed
|
2023-01-21 18:22:19 +01:00
|
|
|
#define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0]))
|
2021-02-16 15:41:52 +08:00
|
|
|
|
2020-02-03 11:15:17 -08:00
|
|
|
/// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic
|
|
|
|
|
/// returns the encoded packet size
|
|
|
|
|
size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct);
|
|
|
|
|
|
|
|
|
|
/// helper function for decoding a record as a protobuf, we will return false if the decoding failed
|
2020-02-07 09:36:15 -08:00
|
|
|
bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msgdesc_t *fields, void *dest_struct);
|
|
|
|
|
|
|
|
|
|
/// Read from an Arduino File
|
|
|
|
|
bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count);
|
|
|
|
|
|
|
|
|
|
/// Write to an arduino file
|
|
|
|
|
bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count);
|
2020-05-23 10:01:36 -07:00
|
|
|
|
|
|
|
|
/** is_in_repeated is a macro/function that returns true if a specified word appears in a repeated protobuf array.
|
|
|
|
|
* It relies on the following naming conventions from nanopb:
|
2023-01-18 14:51:48 -06:00
|
|
|
*
|
2020-05-23 10:01:36 -07:00
|
|
|
* pb_size_t ignore_incoming_count;
|
|
|
|
|
* uint32_t ignore_incoming[3];
|
|
|
|
|
*/
|
|
|
|
|
bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count);
|
|
|
|
|
|
|
|
|
|
#define is_in_repeated(name, n) is_in_helper(n, name, name##_count)
|