Skip to content

Commit 6c5a5c0

Browse files
committed
Rework header structure to troubleshoot PIO linker issues
1 parent da73b4a commit 6c5a5c0

File tree

2 files changed

+80
-75
lines changed

2 files changed

+80
-75
lines changed

src/Meshtastic.h

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,6 @@
55
#include "meshtastic/mesh.pb.h"
66
#include <pb_encode.h>
77
#include <pb_decode.h>
8-
9-
// Some sane limits on a few strings that the protocol would otherwise allow to be unlimited length
10-
#define MAX_USER_ID_LEN (sizeof(meshtastic_User().id) - 1)
11-
#define MAX_LONG_NAME_LEN (sizeof(meshtastic_User().long_name) - 1)
12-
#define MAX_SHORT_NAME_LEN (sizeof(meshtastic_User().short_name) - 1)
13-
14-
#define BAUD_DEFAULT 9600
15-
#define BROADCAST_ADDR 0xFFFFFFFF
16-
17-
extern uint32_t my_node_num;
18-
19-
// The strings will be truncated if they're longer than the lengths above, but
20-
// will always be NUL-terminated. If not available, they'll be NULL.
21-
typedef struct {
22-
uint32_t node_num;
23-
bool is_mine;
24-
bool has_user;
25-
char user_id[MAX_USER_ID_LEN];
26-
char long_name[MAX_LONG_NAME_LEN];
27-
char short_name[MAX_SHORT_NAME_LEN];
28-
double latitude;
29-
double longitude;
30-
int8_t altitude; // To the nearest meter above (or below) sea level
31-
uint16_t ground_speed; // meters per second
32-
uint8_t battery_level;
33-
uint32_t last_heard_from;
34-
uint32_t last_heard_position;
35-
uint32_t time_of_last_position;
36-
float voltage;
37-
float channel_utilization;
38-
float air_util_tx;
39-
} mt_node_t;
40-
41-
// Initialize, using wifi to connect to the MT radio
42-
void mt_wifi_init(int8_t cs_pin, int8_t irq_pin, int8_t reset_pin,
43-
int8_t enable_pin, const char * ssid, const char * password);
44-
45-
// Initialize, using serial pins and baud rate to connect to the MT radio
46-
void mt_serial_init(int8_t rx_pin, int8_t tx_pin, uint32_t baud = BAUD_DEFAULT);
47-
48-
// Call this once per loop() and pass the current millis(). Returns bool indicating whether the connection is ready.
49-
bool mt_loop(uint32_t now);
50-
51-
// Will print lots of (semi)useful information to the main Serial output
52-
void mt_set_debug(bool on);
53-
54-
typedef enum {
55-
MT_NR_IN_PROGRESS,
56-
MT_NR_DONE,
57-
MT_NR_INVALID
58-
} mt_nr_progress_t;
59-
60-
// Ask the MT radio for a node report (it won't arrive right away)
61-
// For each node it receives, your callback will be called with
62-
// the second parameter set to MT_NR_IN_PROGRESS. At the end of the
63-
// report, if the IDs matched, the callback will be called with
64-
// NULL as the first parameter and the second set to either MT_NR_DONE
65-
// (if it was indeed the reply to our request) or MT_NR_INVALID (if it
66-
// turned out to have been a reply to someone else's request).
67-
//
68-
// Everything we pass to your callback could be destroyed immediately
69-
// after it returns, so it should save it somewhere else if it needs it.
70-
//
71-
// Returns true if we were able to request the report, false if we couldn't
72-
// even do that.
73-
bool mt_request_node_report(void (*callback)(mt_node_t *, mt_nr_progress_t));
74-
75-
// Set the callback function that gets called when the node receives a text message.
76-
void set_text_message_callback(void (*callback)(uint32_t from, const char * text));
77-
78-
// Set the callback function that gets called when the node receives a text message.
79-
void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry));
80-
81-
// Send a text message with *text* as payload, to a destination node (optional), on a certain channel (optional).
82-
bool mt_send_text(const char * text, uint32_t dest = BROADCAST_ADDR, uint8_t channel_index = 0);
8+
#include "mt_protocol.h"
839

8410
#endif

src/mt_protocol.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <Arduino.h>
2+
#include "meshtastic/mesh.pb.h"
3+
#include <pb_encode.h>
4+
#include <pb_decode.h>
5+
6+
// Some sane limits on a few strings that the protocol would otherwise allow to be unlimited length
7+
#define MAX_USER_ID_LEN (sizeof(meshtastic_User().id) - 1)
8+
#define MAX_LONG_NAME_LEN (sizeof(meshtastic_User().long_name) - 1)
9+
#define MAX_SHORT_NAME_LEN (sizeof(meshtastic_User().short_name) - 1)
10+
11+
#define BAUD_DEFAULT 9600
12+
#define BROADCAST_ADDR 0xFFFFFFFF
13+
14+
extern uint32_t my_node_num;
15+
16+
// The strings will be truncated if they're longer than the lengths above, but
17+
// will always be NUL-terminated. If not available, they'll be NULL.
18+
typedef struct {
19+
uint32_t node_num;
20+
bool is_mine;
21+
bool has_user;
22+
char user_id[MAX_USER_ID_LEN];
23+
char long_name[MAX_LONG_NAME_LEN];
24+
char short_name[MAX_SHORT_NAME_LEN];
25+
double latitude;
26+
double longitude;
27+
int8_t altitude; // To the nearest meter above (or below) sea level
28+
uint16_t ground_speed; // meters per second
29+
uint8_t battery_level;
30+
uint32_t last_heard_from;
31+
uint32_t last_heard_position;
32+
uint32_t time_of_last_position;
33+
float voltage;
34+
float channel_utilization;
35+
float air_util_tx;
36+
} mt_node_t;
37+
38+
// Initialize, using wifi to connect to the MT radio
39+
void mt_wifi_init(int8_t cs_pin, int8_t irq_pin, int8_t reset_pin,
40+
int8_t enable_pin, const char * ssid, const char * password);
41+
42+
// Initialize, using serial pins and baud rate to connect to the MT radio
43+
void mt_serial_init(int8_t rx_pin, int8_t tx_pin, uint32_t baud = BAUD_DEFAULT);
44+
45+
// Call this once per loop() and pass the current millis(). Returns bool indicating whether the connection is ready.
46+
bool mt_loop(uint32_t now);
47+
48+
// Will print lots of (semi)useful information to the main Serial output
49+
void mt_set_debug(bool on);
50+
51+
typedef enum {
52+
MT_NR_IN_PROGRESS,
53+
MT_NR_DONE,
54+
MT_NR_INVALID
55+
} mt_nr_progress_t;
56+
57+
// Ask the MT radio for a node report (it won't arrive right away)
58+
// For each node it receives, your callback will be called with
59+
// the second parameter set to MT_NR_IN_PROGRESS. At the end of the
60+
// report, if the IDs matched, the callback will be called with
61+
// NULL as the first parameter and the second set to either MT_NR_DONE
62+
// (if it was indeed the reply to our request) or MT_NR_INVALID (if it
63+
// turned out to have been a reply to someone else's request).
64+
//
65+
// Everything we pass to your callback could be destroyed immediately
66+
// after it returns, so it should save it somewhere else if it needs it.
67+
//
68+
// Returns true if we were able to request the report, false if we couldn't
69+
// even do that.
70+
bool mt_request_node_report(void (*callback)(mt_node_t *, mt_nr_progress_t));
71+
72+
// Set the callback function that gets called when the node receives a text message.
73+
void set_text_message_callback(void (*callback)(uint32_t from, const char * text));
74+
75+
// Set the callback function that gets called when the node receives a text message.
76+
void set_telemetry_callback(void (*callback)(uint32_t from, meshtastic_Telemetry * telemetry));
77+
78+
// Send a text message with *text* as payload, to a destination node (optional), on a certain channel (optional).
79+
bool mt_send_text(const char * text, uint32_t dest = BROADCAST_ADDR, uint8_t channel_index = 0);

0 commit comments

Comments
 (0)