Merge pull request #24 from Devilbinder/dev

Implement Forwarding
This commit is contained in:
Timm Bogner 2022-06-28 02:09:18 -05:00 committed by GitHub
commit bf54b7c7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 4 deletions

View File

@ -126,8 +126,16 @@ void loop() {
#endif #endif
#if defined(ESP_SEND) #if defined(ESP_SEND)
#ifdef ESPNOW_ALL
ESPNow.release(); ESPNow.release();
#endif #endif
#ifdef ESPNOW_PEER_1
ESPNow.release(ESPNOW1);
#endif
#ifdef ESPNOW_PEER_2
ESPNow.release(ESPNOW2);
#endif
#endif
#if defined(MQTT_SEND) #if defined(MQTT_SEND)
MQTT.release(); MQTT.release();

View File

@ -29,6 +29,7 @@
#define LORA_PEER_1 0x0E // LoRa1 Address #define LORA_PEER_1 0x0E // LoRa1 Address
#define LORA_PEER_2 0x0F // LoRa2 Address #define LORA_PEER_2 0x0F // LoRa2 Address
#define ESPNOW_ALL //send to all know and unknow peers
#define ESPNOW_PEER_1 0x0C // ESPNOW1 Address #define ESPNOW_PEER_1 0x0C // ESPNOW1 Address
#define ESPNOW_PEER_2 0x0D // ESPNOW2 Address #define ESPNOW_PEER_2 0x0D // ESPNOW2 Address

View File

@ -63,10 +63,16 @@ FDRSGateWayBase::FDRSGateWayBase(){
FDRSGateWayBase::~FDRSGateWayBase(){ FDRSGateWayBase::~FDRSGateWayBase(){
} }
void FDRSGateWayBase::release(void){
send(_data); void FDRSGateWayBase::release(uint8_t *peer_mac){
if(peer_mac == NULL){
send(_data);
}
forward(peer_mac ,_data);
} }
void FDRSGateWayBase::flush(void){ void FDRSGateWayBase::flush(void){
_data.clear(); _data.clear();
} }
@ -75,6 +81,10 @@ void FDRSGateWayBase::add_data(DataReading_t *data){
_data.push_back(*data); _data.push_back(*data);
} }
std::vector<DataReading_t> *FDRSGateWayBase::get_data(){
return &_data;
}
ESP_FDRSGateWay::ESP_FDRSGateWay(void) ESP_FDRSGateWay::ESP_FDRSGateWay(void)
{ {
@ -232,6 +242,24 @@ void ESP_FDRSGateWay::send(std::vector<DataReading_t> data){
} }
void ESP_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> data){
const uint8_t espnow_size = 250 / sizeof(DataReading_t);
uint32_t i = 0;
uint8_t d = data.size() / espnow_size;
DataReading_t buffer1[d];
for(i = 0; i < d; i++){
buffer1[i] = data[i];
}
esp_now_send(peer_mac, (uint8_t *) buffer1, d * sizeof(DataReading_t));
}
MQTT_FDRSGateWay::MQTT_FDRSGateWay(const char *ssid, const char *password, const char *server,int port): MQTT_FDRSGateWay::MQTT_FDRSGateWay(const char *ssid, const char *password, const char *server,int port):
_ssid(ssid), _ssid(ssid),
_password(password), _password(password),
@ -334,6 +362,9 @@ void MQTT_FDRSGateWay::send(std::vector<DataReading_t> data) {
} }
void MQTT_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> data){
//does nothing. just here implement the pure virtule from the base class.
}
Serial_FDRSGateWay::Serial_FDRSGateWay(HardwareSerial *serial, uint32_t baud): Serial_FDRSGateWay::Serial_FDRSGateWay(HardwareSerial *serial, uint32_t baud):
_serial(serial), _serial(serial),
@ -399,6 +430,10 @@ void Serial_FDRSGateWay::send(std::vector<DataReading_t> data){
_serial->println(); _serial->println();
} }
void Serial_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> data){
//does nothing. just here implement the pure virtule from the base class.
}
LoRa_FDRSGateWay::LoRa_FDRSGateWay(uint8_t miso,uint8_t mosi,uint8_t sck, uint8_t ss,uint8_t rst,uint8_t dio0,double band,uint8_t sf): LoRa_FDRSGateWay::LoRa_FDRSGateWay(uint8_t miso,uint8_t mosi,uint8_t sck, uint8_t ss,uint8_t rst,uint8_t dio0,double band,uint8_t sf):
_miso(miso), _miso(miso),
_mosi(mosi), _mosi(mosi),
@ -517,6 +552,10 @@ void LoRa_FDRSGateWay::send(std::vector<DataReading_t> data){
} }
void LoRa_FDRSGateWay::forward(uint8_t *peer_mac ,std::vector<DataReading_t> data){
//TODO: add peer forwading.
}
void LoRa_FDRSGateWay::transmit(DataReading_t *packet, uint8_t len) { void LoRa_FDRSGateWay::transmit(DataReading_t *packet, uint8_t len) {
DBG("Transmitting LoRa."); DBG("Transmitting LoRa.");
uint8_t pkt[5 + (len * sizeof(DataReading_t))]; uint8_t pkt[5 + (len * sizeof(DataReading_t))];

View File

@ -39,13 +39,18 @@ public:
static void add_data(DataReading_t *data); static void add_data(DataReading_t *data);
void release(void); void release(uint8_t *peer_mac = NULL);
void flush(void); void flush(void);
protected:
std::vector<DataReading_t> *get_data();
private: private:
static uint32_t peer_id; static uint32_t peer_id;
static std::vector<DataReading_t> _data; static std::vector<DataReading_t> _data;
virtual void send(std::vector<DataReading_t> data) = 0; virtual void send(std::vector<DataReading_t> data) = 0;
virtual void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) = 0;
}; };
class ESP_FDRSGateWay: public FDRSGateWayBase{ class ESP_FDRSGateWay: public FDRSGateWayBase{
@ -69,6 +74,7 @@ private:
static void setup(void); static void setup(void);
void send(std::vector<DataReading_t> data) override; void send(std::vector<DataReading_t> data) override;
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
void list_peer(uint8_t peer_mac[6]); void list_peer(uint8_t peer_mac[6]);
void unlist_peer(uint8_t peer_mac[6]); void unlist_peer(uint8_t peer_mac[6]);
@ -101,6 +107,7 @@ private:
void reconnect(); void reconnect();
void send(std::vector<DataReading_t> data) override; void send(std::vector<DataReading_t> data) override;
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
}; };
@ -122,6 +129,7 @@ private:
static void setup(void); static void setup(void);
void pull(void); void pull(void);
void send(std::vector<DataReading_t> data) override; void send(std::vector<DataReading_t> data) override;
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
}; };
@ -152,8 +160,8 @@ private:
void transmit(DataReading_t *packet, uint8_t len); void transmit(DataReading_t *packet, uint8_t len);
void send(std::vector<DataReading_t> data) override; void send(std::vector<DataReading_t> data) override;
void forward(uint8_t *peer_mac ,std::vector<DataReading_t> data) override;
}; };