#pragma once #include enum class DeviceRole : uint8_t { Sender = 0, Receiver = 1 }; enum class PayloadType : uint8_t { MeterData = 0, TestCode = 1, TimeSync = 2, MeterBatch = 3, Ack = 4 }; enum class BatchRetryPolicy : uint8_t { Keep = 0, Drop = 1 }; constexpr uint8_t PROTOCOL_VERSION = 1; // Pin definitions constexpr uint8_t PIN_LORA_SCK = 5; constexpr uint8_t PIN_LORA_MISO = 19; constexpr uint8_t PIN_LORA_MOSI = 27; constexpr uint8_t PIN_LORA_NSS = 18; constexpr uint8_t PIN_LORA_RST = 23; constexpr uint8_t PIN_LORA_DIO0 = 26; constexpr uint8_t PIN_OLED_SDA = 21; constexpr uint8_t PIN_OLED_SCL = 22; constexpr uint8_t PIN_OLED_RST = 16; constexpr uint8_t OLED_I2C_ADDR = 0x3C; constexpr uint8_t OLED_WIDTH = 128; constexpr uint8_t OLED_HEIGHT = 64; constexpr uint8_t PIN_BAT_ADC = 35; constexpr uint8_t PIN_ROLE = 13; constexpr uint8_t PIN_OLED_CTRL = 14; constexpr uint8_t PIN_METER_RX = 34; // LoRa settings #ifndef LORA_FREQUENCY_HZ #define LORA_FREQUENCY_HZ 433E6 #endif constexpr long LORA_FREQUENCY = LORA_FREQUENCY_HZ; constexpr uint8_t LORA_SPREADING_FACTOR = 12; constexpr long LORA_BANDWIDTH = 125E3; constexpr uint8_t LORA_CODING_RATE = 5; constexpr uint8_t LORA_SYNC_WORD = 0x34; constexpr uint8_t LORA_PREAMBLE_LEN = 8; // Timing constexpr uint32_t SENDER_WAKE_INTERVAL_SEC = 30; constexpr uint32_t TIME_SYNC_INTERVAL_SEC = 60; constexpr uint32_t TIME_SYNC_SLOW_INTERVAL_SEC = 3600; constexpr uint32_t TIME_SYNC_FAST_WINDOW_MS = 10UL * 60UL * 1000UL; constexpr bool ENABLE_DS3231 = true; constexpr uint32_t OLED_PAGE_INTERVAL_MS = 4000; constexpr uint32_t OLED_AUTO_OFF_MS = 10UL * 60UL * 1000UL; constexpr uint32_t SENDER_OLED_READ_MS = 10000; constexpr uint32_t METER_SAMPLE_INTERVAL_MS = 1000; constexpr uint32_t METER_SEND_INTERVAL_MS = 30000; constexpr uint32_t BATCH_ACK_TIMEOUT_MS = 3000; constexpr uint8_t BATCH_MAX_RETRIES = 2; constexpr uint8_t METER_BATCH_MAX_SAMPLES = 30; constexpr uint8_t BATCH_QUEUE_DEPTH = 10; constexpr BatchRetryPolicy BATCH_RETRY_POLICY = BatchRetryPolicy::Keep; constexpr uint32_t WATCHDOG_TIMEOUT_SEC = 120; constexpr bool ENABLE_HA_DISCOVERY = true; constexpr bool SERIAL_DEBUG_MODE = true; constexpr uint8_t NUM_SENDERS = 1; inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { 0xF19C //433mhz sender //0x7EB4 //868mhz sender }; DeviceRole detect_role();