Merge pull request #3 from Devilbinder/dataype

Dataype
This commit is contained in:
Binder Tronics 2022-06-24 18:44:45 +02:00 committed by GitHub
commit 60b9e9be58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 26 deletions

View File

@ -1,4 +1,3 @@
#include "fdrs_sensor.h"
@ -11,11 +10,11 @@ uint32_t wait_time = 0;
FDRSBase::FDRSBase(uint8_t gtwy_mac,uint8_t reading_id):
_gtwy_mac(gtwy_mac),
_espnow_size(250 / sizeof(DataReading)),
_espnow_size(250 / sizeof(DataReading_t)),
_reading_id(reading_id),
_data_count(0)
{
fdrsData = new DataReading[_espnow_size];
fdrsData = new DataReading_t[_espnow_size];
}
FDRSBase::~FDRSBase(){
@ -26,7 +25,7 @@ void FDRSBase::begin() {
#ifdef DEBUG
Serial.begin(115200);
#endif
DBG("FDRS Sensor ID " + String(READING_ID) + " initializing...");
DBG("FDRS Sensor ID " + String(_reading_id) + " initializing...");
DBG(" Gateway: " + String (_gtwy_mac, HEX));
#ifdef POWER_CTRL
DBG("Powering up the sensor array!");
@ -36,7 +35,6 @@ void FDRSBase::begin() {
init();
}
void FDRSBase::send(void) {
@ -50,11 +48,11 @@ void FDRSBase::send(void) {
}
void FDRSBase::load(float data, uint8_t type) {
DBG("Data loaded. Type: " + String(t));
DBG("Data loaded. Type: " + String(type));
if (_data_count > _espnow_size){
send();
}
DataReading dr;
DataReading_t dr;
dr.id = _reading_id;
dr.type = type;
dr.data = data;
@ -86,7 +84,6 @@ FDRS_EspNow::FDRS_EspNow(uint8_t gtwy_mac,uint8_t reading_id):
memcpy(_gatewayAddress,MAC_PREFIX,5);
_gatewayAddress[5] = gtwy_mac;
}
@ -121,11 +118,10 @@ void FDRS_EspNow::init(void){
}
#endif
DBG(" ESP-NOW Initialized.");
}
void FDRS_EspNow::transmit(DataReading *fdrsData, uint8_t _data_count){
esp_now_send(_gatewayAddress, (uint8_t *) fdrsData, _data_count * sizeof(DataReading));
void FDRS_EspNow::transmit(DataReading_t *fdrsData, uint8_t _data_count){
esp_now_send(_gatewayAddress, (uint8_t *) fdrsData, _data_count * sizeof(DataReading_t));
delay(5);
DBG(" ESP-NOW sent.");
}
@ -167,17 +163,17 @@ void FDRSLoRa::init(void){
DBG("LoRa Initialized.");
}
void FDRSLoRa::buildPacket(uint8_t* mac, DataReading * packet, uint8_t len) {
uint8_t pkt[5 + (len * sizeof(DataReading))];
void FDRSLoRa::buildPacket(uint8_t* mac, DataReading_t * packet, uint8_t len) {
uint8_t pkt[5 + (len * sizeof(DataReading_t))];
memcpy(&pkt, mac, 3); //
memcpy(&pkt[3], &LoRaAddress, 2);
memcpy(&pkt[5], packet, len * sizeof(DataReading));
memcpy(&pkt[5], packet, len * sizeof(DataReading_t));
LoRa.beginPacket();
LoRa.write((uint8_t*)&pkt, sizeof(pkt));
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);
DBG(" LoRa sent.");
}

View File

@ -9,6 +9,17 @@
#ifndef __FDRS_SENSOR__H__
#define __FDRS_SENSOR__H__
#include "fdrs_types.h"
//1 to enable debugging prints. 0 disables the debugging prints
#define ENABLE_DEBUG 1
#if ENABLE_DEBUG == 1
#ifndef DEBUG
#define DEBUG
#endif
#endif
#define USE_LORA
#if defined(ESP8266)
@ -67,12 +78,6 @@ extern const uint8_t prefix[5];
#define ESP_GATEWAY_ADDRESS_SIZE 6
#define LORA_GATEWAY_ADDRESS_SIZE 3
typedef struct __attribute__((packed)) DataReading {
float data;
uint16_t id;
uint8_t type;
} DataReading;
class FDRSBase{
public:
@ -90,10 +95,10 @@ private:
const uint16_t _espnow_size;
uint8_t _reading_id;
uint8_t _data_count;
DataReading *fdrsData;
DataReading_t *fdrsData;
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;
};
@ -105,7 +110,7 @@ public:
private:
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;
};
@ -127,8 +132,8 @@ private:
uint32_t _band;
uint8_t _sf;
void buildPacket(uint8_t* mac, DataReading * packet, uint8_t len);
void transmit(DataReading *fdrsData, uint8_t _data_count) override;
void buildPacket(uint8_t* mac, DataReading_t * packet, uint8_t len);
void transmit(DataReading_t *fdrsData, uint8_t _data_count) override;
void init(void) override;
};

12
fdrs_types.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __FDRS_TYPES_H__
#define __FDRS_TYPES_H__
#include <stdint.h>
typedef struct __attribute__((packed)) DataReading_t {
float data;
uint16_t id;
uint8_t type;
} DataReading_t;
#endif