mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge remote-tracking branch 'origin/dev' into awolden/t3lora
This commit is contained in:
commit
86389579eb
19 changed files with 745 additions and 84 deletions
|
|
@ -88,6 +88,15 @@
|
|||
#error "need to provide a 'board' object"
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
#include <helpers/ui/SSD1306Display.h>
|
||||
|
||||
static DISPLAY_CLASS display;
|
||||
|
||||
#include "UITask.h"
|
||||
static UITask ui_task(display);
|
||||
#endif
|
||||
|
||||
#define PACKET_LOG_FILE "/packet_log"
|
||||
|
||||
/* ------------------------------ Code -------------------------------- */
|
||||
|
|
@ -107,7 +116,8 @@ struct RepeaterStats {
|
|||
uint32_t total_up_time_secs;
|
||||
uint32_t n_sent_flood, n_sent_direct;
|
||||
uint32_t n_recv_flood, n_recv_direct;
|
||||
uint16_t n_full_events, reserved1;
|
||||
uint16_t n_full_events;
|
||||
int16_t last_snr; // x 4
|
||||
uint16_t n_direct_dups, n_flood_dups;
|
||||
};
|
||||
|
||||
|
|
@ -175,7 +185,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||
stats.n_recv_flood = getNumRecvFlood();
|
||||
stats.n_recv_direct = getNumRecvDirect();
|
||||
stats.n_full_events = getNumFullEvents();
|
||||
stats.reserved1 = 0;
|
||||
stats.last_snr = (int16_t)(my_radio->getLastSNR() * 4);
|
||||
stats.n_direct_dups = ((SimpleMeshTables *)getTables())->getNumDirectDups();
|
||||
stats.n_flood_dups = ((SimpleMeshTables *)getTables())->getNumFloodDups();
|
||||
|
||||
|
|
@ -411,27 +421,34 @@ protected:
|
|||
|
||||
if (!(flags == TXT_TYPE_PLAIN || flags == TXT_TYPE_CLI_DATA)) {
|
||||
MESH_DEBUG_PRINTLN("onPeerDataRecv: unsupported text type received: flags=%02x", (uint32_t)flags);
|
||||
} else if (sender_timestamp > client->last_timestamp) { // prevent replay attacks
|
||||
} else if (sender_timestamp >= client->last_timestamp) { // prevent replay attacks
|
||||
bool is_retry = (sender_timestamp == client->last_timestamp);
|
||||
client->last_timestamp = sender_timestamp;
|
||||
client->last_activity = getRTCClock()->getCurrentTime();
|
||||
|
||||
// len can be > original length, but 'text' will be padded with zeroes
|
||||
data[len] = 0; // need to make a C string again, with null terminator
|
||||
|
||||
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
|
||||
mesh::Utils::sha256((uint8_t *) &ack_hash, 4, data, 5 + strlen((char *)&data[5]), client->id.pub_key, PUB_KEY_SIZE);
|
||||
if (flags == TXT_TYPE_PLAIN) { // for legacy CLI, send Acks
|
||||
uint32_t ack_hash; // calc truncated hash of the message timestamp + text + sender pub_key, to prove to sender that we got it
|
||||
mesh::Utils::sha256((uint8_t *) &ack_hash, 4, data, 5 + strlen((char *)&data[5]), client->id.pub_key, PUB_KEY_SIZE);
|
||||
|
||||
mesh::Packet* ack = createAck(ack_hash);
|
||||
if (ack) {
|
||||
if (client->out_path_len < 0) {
|
||||
sendFlood(ack);
|
||||
} else {
|
||||
sendDirect(ack, client->out_path, client->out_path_len);
|
||||
mesh::Packet* ack = createAck(ack_hash);
|
||||
if (ack) {
|
||||
if (client->out_path_len < 0) {
|
||||
sendFlood(ack);
|
||||
} else {
|
||||
sendDirect(ack, client->out_path, client->out_path_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t temp[166];
|
||||
_cli.handleCommand(sender_timestamp, (const char *) &data[5], (char *) &temp[5]);
|
||||
if (is_retry) {
|
||||
temp[0] = 0;
|
||||
} else {
|
||||
_cli.handleCommand(sender_timestamp, (const char *) &data[5], (char *) &temp[5]);
|
||||
}
|
||||
int text_len = strlen((char *) &temp[5]);
|
||||
if (text_len > 0) {
|
||||
uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||
|
|
@ -442,9 +459,6 @@ protected:
|
|||
memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique
|
||||
temp[4] = (TXT_TYPE_CLI_DATA << 2); // NOTE: legacy was: TXT_TYPE_PLAIN
|
||||
|
||||
// calc expected ACK reply
|
||||
//mesh::Utils::sha256((uint8_t *)&expected_ack_crc, 4, temp, 5 + text_len, self_id.pub_key, PUB_KEY_SIZE);
|
||||
|
||||
auto reply = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id, secret, temp, 5 + text_len);
|
||||
if (reply) {
|
||||
if (client->out_path_len < 0) {
|
||||
|
|
@ -509,13 +523,7 @@ public:
|
|||
mesh::Mesh::begin();
|
||||
_fs = fs;
|
||||
// load persisted prefs
|
||||
if (_fs->exists("/node_prefs")) {
|
||||
File file = _fs->open("/node_prefs");
|
||||
if (file) {
|
||||
file.read((uint8_t *) &_prefs, sizeof(_prefs));
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
_cli.loadPrefs(_fs);
|
||||
|
||||
_phy->setFrequency(_prefs.freq);
|
||||
_phy->setSpreadingFactor(_prefs.sf);
|
||||
|
|
@ -528,18 +536,10 @@ public:
|
|||
|
||||
const char* getFirmwareVer() override { return FIRMWARE_VERSION; }
|
||||
const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; }
|
||||
const char* getNodeName() { return _prefs.node_name; }
|
||||
|
||||
void savePrefs() override {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
File file = _fs->open("/node_prefs", FILE_O_WRITE);
|
||||
if (file) { file.seek(0); file.truncate(); }
|
||||
#else
|
||||
File file = _fs->open("/node_prefs", "w", true);
|
||||
#endif
|
||||
if (file) {
|
||||
file.write((const uint8_t *)&_prefs, sizeof(_prefs));
|
||||
file.close();
|
||||
}
|
||||
_cli.savePrefs(_fs);
|
||||
}
|
||||
|
||||
bool formatFileSystem() override {
|
||||
|
|
@ -603,12 +603,15 @@ public:
|
|||
|
||||
updateAdvertTimer(); // schedule next local advert
|
||||
}
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.loop();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
|
||||
#elif defined(LILYGO_TLORA) || defined(HELTEC_LORA_V2) // ESP32 with SX1276
|
||||
#elif defined(LILYGO_TLORA)
|
||||
SPIClass spi;
|
||||
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_0, P_LORA_RESET, P_LORA_DIO_1, spi);
|
||||
#elif defined(P_LORA_SCLK)
|
||||
|
|
@ -650,6 +653,11 @@ void setup() {
|
|||
#else
|
||||
float tcxo = 1.6f;
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
display.begin();
|
||||
#endif
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
|
||||
SPI.begin();
|
||||
|
|
@ -702,6 +710,10 @@ void setup() {
|
|||
|
||||
the_mesh.begin(fs);
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.begin(the_mesh.getNodeName(), FIRMWARE_BUILD_DATE);
|
||||
#endif
|
||||
|
||||
// send out initial Advertisement to the mesh
|
||||
the_mesh.sendSelfAdvertisement(2000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue