mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-03-30 12:45:45 +00:00
* Refactor: new AdvertDataHelpers.h
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <helpers/StaticPoolPacketManager.h>
|
||||
#include <helpers/SimpleMeshTables.h>
|
||||
#include <helpers/IdentityStore.h>
|
||||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <RTClib.h>
|
||||
|
||||
/* ------------------------------ Config -------------------------------- */
|
||||
@@ -422,35 +423,14 @@ public:
|
||||
memset(posts, 0, sizeof(posts));
|
||||
}
|
||||
|
||||
#define ADV_TYPE_NONE 0 // unknown
|
||||
#define ADV_TYPE_CHAT 1
|
||||
#define ADV_TYPE_REPEATER 2
|
||||
#define ADV_TYPE_ROOM 3 // New kid on the block!
|
||||
//FUTURE: 4..15
|
||||
|
||||
#define ADV_LATLON_MASK 0x10
|
||||
#define ADV_BATTERY_MASK 0x20
|
||||
#define ADV_TEMPERATURE_MASK 0x40
|
||||
#define ADV_NAME_MASK 0x80
|
||||
|
||||
void sendSelfAdvertisement() {
|
||||
uint8_t app_data[MAX_ADVERT_DATA_SIZE+32];
|
||||
app_data[0] = ADV_TYPE_ROOM | ADV_NAME_MASK;
|
||||
int i = 1;
|
||||
int32_t lat = ADVERT_LAT * 1E6;
|
||||
int32_t lon = ADVERT_LON * 1E6;
|
||||
if (!(lat == 0 && lon == 0)) {
|
||||
app_data[0] |= ADV_LATLON_MASK;
|
||||
memcpy(&app_data[i], &lat, 4); i += 4;
|
||||
memcpy(&app_data[i], &lon, 4); i += 4;
|
||||
uint8_t app_data[MAX_ADVERT_DATA_SIZE];
|
||||
uint8_t app_data_len;
|
||||
{
|
||||
AdvertDataBuilder builder(ADV_TYPE_ROOM, ADVERT_NAME, ADVERT_LAT, ADVERT_LON);
|
||||
app_data_len = builder.encodeTo(app_data);
|
||||
}
|
||||
strcpy((char *)&app_data[i], ADVERT_NAME);
|
||||
int app_data_len = i + strlen(ADVERT_NAME);
|
||||
if (app_data_len > MAX_ADVERT_DATA_SIZE) {
|
||||
app_data_len = MAX_ADVERT_DATA_SIZE;
|
||||
app_data[MAX_ADVERT_DATA_SIZE - 1] = 0; // truncate the ADVERT_NAME
|
||||
}
|
||||
|
||||
|
||||
mesh::Packet* pkt = createAdvert(self_id, app_data, app_data_len);
|
||||
if (pkt) {
|
||||
sendFlood(pkt, 1200); // add slight delay
|
||||
@@ -504,6 +484,7 @@ public:
|
||||
if (c->pending_ack && millisHasNowPassed(c->ack_timeout)) {
|
||||
c->push_failures++;
|
||||
c->pending_ack = 0; // reset (TODO: keep prev expected_ack's in a list, incase they arrive LATER, after we retry)
|
||||
MESH_DEBUG_PRINTLN("pending ACK timed out: push_failures: %d", (uint32_t)c->push_failures);
|
||||
|
||||
if (c->push_failures >= 3) {
|
||||
evict(c);
|
||||
|
||||
Reference in New Issue
Block a user