Safe Sprinkler
Master/slave irrigation system (ESP-NOW + LoRaWAN)
Loading...
Searching...
No Matches
Macros | Functions
lora_msg_serializer.h File Reference
#include "esp_err.h"
#include "general/node_cfg.h"
#include "master/lora_msg_protocol.h"
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for lora_msg_serializer.h:

Go to the source code of this file.

Macros

#define LORA_REG_MSG_SIZE   42
 
#define LORA_PERIODIC_HEADER_SIZE   2
 
#define LORA_PERIODIC_SLAVE_SIZE   3
 
#define LORA_PERIODIC_MAX_SIZE   (LORA_PERIODIC_HEADER_SIZE + MAX_SLAVE_NUM * LORA_PERIODIC_SLAVE_SIZE)
 
#define LORA_ALARM_MSG_SIZE   2
 

Functions

uint8_t lora_serialize_registration (uint8_t *buffer, uint8_t slave_id, const char *name, int32_t longitude, int32_t latitude)
 Serialize a registration message into a compact byte buffer.
 
uint8_t lora_serialize_periodic (uint8_t *buffer, const slave_data *slaves, uint8_t slave_count)
 Serialize a periodic status message for all registered slaves.
 
uint8_t lora_serialize_alarm (uint8_t *buffer, uint8_t slave_id)
 Serialize an alarm message.
 
int lora_send_registration (uint8_t slave_id, const char *name, int32_t longitude, int32_t latitude)
 Send a registration message via LoRaWAN.
 
int lora_send_periodic (const slave_data *slaves, uint8_t slave_count)
 Send periodic status for all slaves via LoRaWAN.
 
int lora_send_alarm (uint8_t slave_id)
 Send an alarm message via LoRaWAN.
 

Macro Definition Documentation

◆ LORA_ALARM_MSG_SIZE

#define LORA_ALARM_MSG_SIZE   2

◆ LORA_PERIODIC_HEADER_SIZE

#define LORA_PERIODIC_HEADER_SIZE   2

◆ LORA_PERIODIC_MAX_SIZE

#define LORA_PERIODIC_MAX_SIZE   (LORA_PERIODIC_HEADER_SIZE + MAX_SLAVE_NUM * LORA_PERIODIC_SLAVE_SIZE)

◆ LORA_PERIODIC_SLAVE_SIZE

#define LORA_PERIODIC_SLAVE_SIZE   3

◆ LORA_REG_MSG_SIZE

#define LORA_REG_MSG_SIZE   42

Function Documentation

◆ lora_send_alarm()

int lora_send_alarm ( uint8_t  slave_id)

Send an alarm message via LoRaWAN.

Parameters
slave_idID of the slave that detected tampering/sabotage
Returns
ESP_OK on success

◆ lora_send_periodic()

int lora_send_periodic ( const slave_data slaves,
uint8_t  slave_count 
)

Send periodic status for all slaves via LoRaWAN.

Parameters
slavesArray of slave data
slave_countNumber of active slaves
Returns
ESP_OK on success

◆ lora_send_registration()

int lora_send_registration ( uint8_t  slave_id,
const char *  name,
int32_t  longitude,
int32_t  latitude 
)

Send a registration message via LoRaWAN.

Parameters
slave_idSlave device ID
nameDevice name
longitudeGPS longitude (fixed-point, *1e6)
latitudeGPS latitude (fixed-point, *1e6)
Returns
ESP_OK on success

◆ lora_serialize_alarm()

uint8_t lora_serialize_alarm ( uint8_t *  buffer,
uint8_t  slave_id 
)

Serialize an alarm message.

Format: [msg_type:1][slave_id:1] Total: 2 bytes

Parameters
bufferOutput buffer (must be at least LORA_ALARM_MSG_SIZE bytes)
slave_idID of the slave that triggered the alarm
Returns
Number of bytes written

◆ lora_serialize_periodic()

uint8_t lora_serialize_periodic ( uint8_t *  buffer,
const slave_data slaves,
uint8_t  slave_count 
)

Serialize a periodic status message for all registered slaves.

Format: [msg_type:1][slave_count:1][slave_data:N*3] Each slave: [slave_id:1][battery:1][moisture:1]

Parameters
bufferOutput buffer (must be at least LORA_PERIODIC_MAX_SIZE bytes)
slavesArray of slave data structures
slave_countNumber of registered slaves (will be capped at MAX_SLAVE_NUM)
Returns
Number of bytes written

◆ lora_serialize_registration()

uint8_t lora_serialize_registration ( uint8_t *  buffer,
uint8_t  slave_id,
const char *  name,
int32_t  longitude,
int32_t  latitude 
)

Serialize a registration message into a compact byte buffer.

Format: [msg_type:1][slave_id:1][name:32][longitude:4][latitude:4] Total: 42 bytes

Parameters
bufferOutput buffer (must be at least LORA_REG_MSG_SIZE bytes)
slave_idSlave device ID (0-15)
nameDevice name (32 char max, will be padded/truncated)
longitudeGPS longitude as fixed-point (multiply by 1e6)
latitudeGPS latitude as fixed-point (multiply by 1e6)
Returns
Number of bytes written