@postman network func. upd.
support burst repeat -> use of 'recent list'
This commit is contained in:
parent
88933fd25d
commit
66582b4c28
1 changed files with 47 additions and 19 deletions
|
|
@ -23,8 +23,8 @@
|
||||||
//============<identities>============
|
//============<identities>============
|
||||||
//
|
//
|
||||||
#define MY_GROUP_ID (20000)
|
#define MY_GROUP_ID (20000)
|
||||||
#define MY_ID (MY_GROUP_ID + 19)
|
#define MY_ID (MY_GROUP_ID + 999)
|
||||||
#define MY_SIGN ("@POSTMAN|@SAMPLER")
|
#define MY_SIGN ("@POSTMAN|REPEATER")
|
||||||
//
|
//
|
||||||
//============</identities>============
|
//============</identities>============
|
||||||
|
|
||||||
|
|
@ -101,6 +101,10 @@
|
||||||
//post & addresses
|
//post & addresses
|
||||||
#include "../../post.h"
|
#include "../../post.h"
|
||||||
|
|
||||||
|
//vector
|
||||||
|
#include <vector>
|
||||||
|
std::vector<Note> recentNotes;
|
||||||
|
|
||||||
//espnow
|
//espnow
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <espnow.h>
|
#include <espnow.h>
|
||||||
|
|
@ -123,22 +127,18 @@ Note note_now = {
|
||||||
-1, // float x4;
|
-1, // float x4;
|
||||||
-1 // float ps;
|
-1 // float ps;
|
||||||
};
|
};
|
||||||
#define NEW_NOTE_TIMEOUT (3000)
|
#define RECENT_NOTES_TIMEOUT (3000)
|
||||||
static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT);
|
static unsigned long last_note_time = 0;
|
||||||
void repeat() {
|
void recent_clear() {
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Note) + 2;
|
if (millis() - last_note_time > RECENT_NOTES_TIMEOUT) {
|
||||||
uint8_t frm[frm_size];
|
recentNotes.clear();
|
||||||
frm[0] = '[';
|
Serial.println("recent list cleared");
|
||||||
memcpy(frm + 1, (uint8_t *) ¬e_now, sizeof(Note));
|
last_note_time = millis();
|
||||||
frm[frm_size - 1] = ']';
|
|
||||||
//
|
|
||||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
|
||||||
//
|
|
||||||
MONITORING_SERIAL.print("repeat! ==> ");
|
|
||||||
MONITORING_SERIAL.println(note_now.to_string());
|
|
||||||
}
|
}
|
||||||
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
//
|
||||||
|
}
|
||||||
|
Task recent_clear_task(100, TASK_FOREVER, &recent_clear, &runner, true);
|
||||||
#endif
|
#endif
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
||||||
|
|
@ -278,11 +278,39 @@ void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
MONITORING_SERIAL.println(note.to_string());
|
MONITORING_SERIAL.println(note.to_string());
|
||||||
|
|
||||||
#if defined(REPLICATE_NOTE_REQ)
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
if (millis() - new_note_time > NEW_NOTE_TIMEOUT) {
|
last_note_time = millis(); //clear timer reset : the recent list holding (re)started
|
||||||
note_now = note;
|
// check if this note is in the list?
|
||||||
repeat_task.restart();
|
bool check = false;
|
||||||
new_note_time = millis();
|
for (uint32_t idx = 0; idx < recentNotes.size(); idx++) {
|
||||||
|
if (recentNotes[idx].pitch == note.pitch && recentNotes[idx].id == note.id) {
|
||||||
|
check = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// if not, add this into the list and repeat!
|
||||||
|
if (check == false) {
|
||||||
|
//
|
||||||
|
recentNotes.push_back(note);
|
||||||
|
//
|
||||||
|
uint8_t frm_size = sizeof(Note) + 2;
|
||||||
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '[';
|
||||||
|
memcpy(frm + 1, (uint8_t *) ¬e, sizeof(Note));
|
||||||
|
frm[frm_size - 1] = ']';
|
||||||
|
//
|
||||||
|
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
|
//
|
||||||
|
MONITORING_SERIAL.print("repeat! ==> ");
|
||||||
|
MONITORING_SERIAL.println(note.to_string());
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//EMERGENCY PATCH.HACK:
|
||||||
|
// original code is not intended for a BURST of notes.
|
||||||
|
// so, only 1 msg. will be repeated in 3 sec. all others will be simply ignored.
|
||||||
|
// to make a burst of msgs repeatible:
|
||||||
|
// --> make a list of recent 'pitches'
|
||||||
|
// if there is any new msg. check if this is in the list, if not, add it & repeat, if yes, skip it.
|
||||||
|
// after 3sec no new msg., the list will be flushed. every new msg. will reset timeout + save the list for extra. 3 sec.
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue