This commit is contained in:
DevilBinder 2022-06-24 18:21:39 +02:00
parent a0e65ffeff
commit f06d094d53
3 changed files with 16 additions and 16 deletions

View File

@ -11,11 +11,11 @@ uint32_t wait_time = 0;
FDRSBase::FDRSBase(uint8_t gtwy_mac,uint8_t reading_id): FDRSBase::FDRSBase(uint8_t gtwy_mac,uint8_t reading_id):
_gtwy_mac(gtwy_mac), _gtwy_mac(gtwy_mac),
_espnow_size(250 / sizeof(DataReading)), _espnow_size(250 / sizeof(DataReading_t)),
_reading_id(reading_id), _reading_id(reading_id),
_data_count(0) _data_count(0)
{ {
fdrsData = new DataReading[_espnow_size]; fdrsData = new DataReading_t[_espnow_size];
} }
FDRSBase::~FDRSBase(){ FDRSBase::~FDRSBase(){
@ -53,7 +53,7 @@ void FDRSBase::load(float data, uint8_t type) {
if (_data_count > _espnow_size){ if (_data_count > _espnow_size){
send(); send();
} }
DataReading dr; DataReading_t dr;
dr.id = _reading_id; dr.id = _reading_id;
dr.type = type; dr.type = type;
dr.data = data; dr.data = data;
@ -121,8 +121,8 @@ void FDRS_EspNow::init(void){
DBG(" ESP-NOW Initialized."); DBG(" ESP-NOW Initialized.");
} }
void FDRS_EspNow::transmit(DataReading *fdrsData, uint8_t _data_count){ void FDRS_EspNow::transmit(DataReading_t *fdrsData, uint8_t _data_count){
esp_now_send(_gatewayAddress, (uint8_t *) fdrsData, _data_count * sizeof(DataReading)); esp_now_send(_gatewayAddress, (uint8_t *) fdrsData, _data_count * sizeof(DataReading_t));
delay(5); delay(5);
DBG(" ESP-NOW sent."); DBG(" ESP-NOW sent.");
} }
@ -164,17 +164,17 @@ void FDRSLoRa::init(void){
DBG("LoRa Initialized."); DBG("LoRa Initialized.");
} }
void FDRSLoRa::buildPacket(uint8_t* mac, DataReading * packet, uint8_t len) { void FDRSLoRa::buildPacket(uint8_t* mac, DataReading_t * packet, uint8_t len) {
uint8_t pkt[5 + (len * sizeof(DataReading))]; uint8_t pkt[5 + (len * sizeof(DataReading_t))];
memcpy(&pkt, mac, 3); // memcpy(&pkt, mac, 3); //
memcpy(&pkt[3], &LoRaAddress, 2); memcpy(&pkt[3], &LoRaAddress, 2);
memcpy(&pkt[5], packet, len * sizeof(DataReading)); memcpy(&pkt[5], packet, len * sizeof(DataReading_t));
LoRa.beginPacket(); LoRa.beginPacket();
LoRa.write((uint8_t*)&pkt, sizeof(pkt)); LoRa.write((uint8_t*)&pkt, sizeof(pkt));
LoRa.endPacket(); LoRa.endPacket();
} }
void FDRSLoRa::transmit(DataReading *fdrsData, uint8_t _data_count){ void FDRSLoRa::transmit(DataReading_t *fdrsData, uint8_t _data_count){
buildPacket(_gatewayAddress, fdrsData, _data_count); buildPacket(_gatewayAddress, fdrsData, _data_count);
DBG(" LoRa sent."); DBG(" LoRa sent.");
} }

View File

@ -95,10 +95,10 @@ private:
const uint16_t _espnow_size; const uint16_t _espnow_size;
uint8_t _reading_id; uint8_t _reading_id;
uint8_t _data_count; uint8_t _data_count;
DataReading *fdrsData; DataReading_t *fdrsData;
virtual void init(void) = 0; virtual void init(void) = 0;
virtual void transmit(DataReading *fdrsData, uint8_t _data_count) = 0; virtual void transmit(DataReading_t *fdrsData, uint8_t _data_count) = 0;
}; };
@ -110,7 +110,7 @@ public:
private: private:
uint8_t _gatewayAddress[ESP_GATEWAY_ADDRESS_SIZE]; uint8_t _gatewayAddress[ESP_GATEWAY_ADDRESS_SIZE];
void transmit(DataReading *fdrsData, uint8_t _data_count) override; void transmit(DataReading_t *fdrsData, uint8_t _data_count) override;
void init(void) override; void init(void) override;
}; };
@ -132,8 +132,8 @@ private:
uint32_t _band; uint32_t _band;
uint8_t _sf; uint8_t _sf;
void buildPacket(uint8_t* mac, DataReading * packet, uint8_t len); void buildPacket(uint8_t* mac, DataReading_t * packet, uint8_t len);
void transmit(DataReading *fdrsData, uint8_t _data_count) override; void transmit(DataReading_t *fdrsData, uint8_t _data_count) override;
void init(void) override; void init(void) override;
}; };

View File

@ -3,10 +3,10 @@
#include <stdint.h> #include <stdint.h>
typedef struct __attribute__((packed)) DataReading { typedef struct __attribute__((packed)) DataReading_t {
float data; float data;
uint16_t id; uint16_t id;
uint8_t type; uint8_t type;
} DataReading; } DataReading_t;
#endif #endif