-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.h
More file actions
194 lines (164 loc) · 6.3 KB
/
Copy pathheader.h
File metadata and controls
194 lines (164 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* @file header.h
* @brief Fichier d'en-tête global pour le projet Nectar-RxStation-LoRa32.
* @version 1.6.2
* @author Paul Miailhe
* @date 27/06/2026
*
* Contient les définitions des broches, les structures de données,
* les paramètres de configuration native, et les déclarations de fonctions.
* Version 1.6.2 : Alignement RF et suppression du saut de ligne série pour NectarMC.
*/
#ifndef HEADER_H
#define HEADER_H
#define FW_VERSION "1.6.2"
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <SD.h>
#include <FS.h>
#include <ESP32Time.h>
#include <RadioLib.h>
#include <U8g2lib.h>
// ============================================================================
// Configuration du Bluetooth et de la télémétrie
// ============================================================================
#define ENABLE_BLUETOOTH 1
#if ENABLE_BLUETOOTH
#include "BluetoothSerial.h"
extern BluetoothSerial SerialBT;
#endif
// ============================================================================
// Définitions des broches (Pinout TTGO LoRa32 v2.1.6)
// ============================================================================
// Bus I2C pour l'afficheur OLED
#define I2C_SDA 21
#define I2C_SCL 22
// Connexions du module radio LoRa (SX1276)
#define RADIO_SCLK_PIN 5
#define RADIO_MISO_PIN 19
#define RADIO_MOSI_PIN 27
#define RADIO_CS_PIN 18
#define RADIO_DIO0_PIN 26
#define RADIO_RST_PIN 23
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 32
// Connexions du lecteur de carte SD (bus HSPI)
#define SDCARD_MOSI 15
#define SDCARD_MISO 2
#define SDCARD_SCLK 14
#define SDCARD_CS 13
// LED embarquée
#define BOARD_LED 25
#define LED_ON HIGH
// Broche de lecture de la tension de batterie
#define BATTERY_PIN 35
// ============================================================================
// Paramètres LoRa et protocoles de trames
// ============================================================================
#define MAX_FRAME_SIZE 255
#define NECTAR_MAGIC 0xEB
// Détermination de la bande radio native
#ifndef LORA_BAND_NATIVE
#define LORA_BAND_NATIVE 868
#endif
#if LORA_BAND_NATIVE == 868
#define FREQ_MIN 863.0f
#define FREQ_MAX 870.0f
#define DEFAULT_FREQUENCY 869.525f
#define DEFAULT_SF 8
#define DEFAULT_BW 250.0f
#elif LORA_BAND_NATIVE == 433
#define FREQ_MIN 433.05f
#define FREQ_MAX 434.79f
#define DEFAULT_FREQUENCY 433.500f
#define DEFAULT_SF 8
#define DEFAULT_BW 250.0f
#else
#error "Configuration LORA_BAND_NATIVE invalide !"
#endif
// ============================================================================
// Structures et variables globales
// ============================================================================
#define DEFAULT_FRAME_FORMAT 2 // 0: Sans GSFLAG, 1: GS 0x3F, 2: GS 0x03, 3: GS 0x00
struct LoRaConfig {
float frequency;
uint8_t spreadingFactor;
float bandwidth;
bool crcEnable;
bool crcMode; // false = CCITT, true = IBM
uint8_t activeFrameFormat; // Format de trame série (0: Sans GSFLAG, 1: GS 0x3F, 2: GS 0x03, 3: GS 0x00)
};
// Structure encapsulant un paquet reçu et ses métadonnées pour transfert inter-cœur
struct LoRaPacket {
uint8_t data[MAX_FRAME_SIZE];
size_t length;
int8_t rssi;
int8_t snr;
uint32_t timestamp;
uint8_t ssid_num;
uint8_t apid;
uint8_t ssid_type;
uint16_t id_mission;
};
extern LoRaConfig activeConfig;
extern ESP32Time rtc;
extern char logFileName[32];
extern char dispStatus[32];
extern char dispSsidApid[32];
extern bool *SDCard;
extern float dispRssi;
extern float dispSnr;
extern bool dispHasFrame;
extern bool displayNeedsUpdate;
// Handles FreeRTOS pour la synchronisation et communication multitâche
extern SemaphoreHandle_t rxSemaphore;
extern SemaphoreHandle_t radioMutex;
extern QueueHandle_t rxQueue;
extern TaskHandle_t xRadioRxTaskHandle;
extern TaskHandle_t xIOProcessingTaskHandle;
extern TaskHandle_t xPeripheralTaskHandle;
// Variables de statistiques partagées pour l'affichage
extern unsigned long lastTrackerPacketTime[256];
extern uint32_t bytesReceivedThisSecond;
extern uint32_t errCount;
// ============================================================================
// Prototypes de fonctions
// ============================================================================
// Fonctions matérielles et de mesure
static inline const char* getSsidPrefix(uint8_t type) {
switch (type) {
case 0: return "FX";
case 1: return "MF";
case 2: return "BALLOON";
default: return "OTHER";
}
}
float readBatteryVoltage();
// Gestion de l'affichage OLED
void ScreenText(U8G2_SSD1306_128X64_NONAME_F_HW_I2C* u8g2);
void updateDisplay(U8G2_SSD1306_128X64_NONAME_F_HW_I2C* u8g2, SX1276* radio);
// Gestion de la carte SD
void SDCardDetection(U8G2_SSD1306_128X64_NONAME_F_HW_I2C* u8g2, SPIClass* SDSPI, bool* SDCard);
void checkSDCardSpace();
void writeFrameToFile(const char* filepath, const uint8_t* frame, size_t length, float rssi, float snr, const char* ssid_str, uint8_t apid);
// Gestion de la configuration non-volatile (NVS)
void loadLoRaConfig();
void saveLoRaConfig();
void resetLoRaConfig();
// Gestion du module radio SX1276
void RadioSettings(U8G2_SSD1306_128X64_NONAME_F_HW_I2C* u8g2, SX1276 *radio);
size_t RadioReceive(SX1276 *radio, uint8_t* byteArr, size_t maxLen, float *outRssi, float *outSnr);
void RadioStartListen(SX1276 *radio);
void IRAM_ATTR setFlag(void);
// Protocoles et communication NectarMC
uint16_t calculate_crc16(const uint8_t *data, size_t len);
void sendNectarFrame(const uint8_t *header_bytes, const uint8_t *payload, size_t len, int8_t rssi, int8_t snr);
// Commandes de configuration AT (Série / Bluetooth)
void checkSerialCommands(SX1276 *radio);
void handleConfigCommand(const char* cmd, Stream& responseStream, SX1276 *radio);
// Tâches FreeRTOS (Dual-Core)
void vRadioRxTask(void *pvParameters);
void vIOProcessingTask(void *pvParameters);
void vPeripheralTask(void *pvParameters);
#endif // HEADER_H