99 lines
1.8 KiB
C
99 lines
1.8 KiB
C
/// © MiroZ 2024
|
|
#ifndef __SENSOR_DATA_H__
|
|
#define __SENSOR_DATA_H__
|
|
#include <stdint.h>
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct MESSAGE_HEADER // 18 bytes
|
|
{
|
|
uint32_t sec;
|
|
uint32_t usec;
|
|
uint8_t mac[6];
|
|
uint32_t group_id;
|
|
};
|
|
|
|
struct MESSAGE_RADAR_BLOCK // 67 bytes
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
uint16_t vals[24];
|
|
};
|
|
|
|
struct GAS_DATA
|
|
{
|
|
uint8_t index;
|
|
float resistance;
|
|
};
|
|
|
|
struct MESSAGE_SENSORS_BLOCK
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
float pressure;
|
|
float temperature;
|
|
uint16_t light;
|
|
float humidity;
|
|
uint8_t num_data;
|
|
struct GAS_DATA data[0];
|
|
};
|
|
|
|
struct MESSAGE_NOTIFY_PRESSURE
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
float value;
|
|
};
|
|
|
|
struct MESSAGE_NOTIFY_TEMPERATURE
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
float value;
|
|
};
|
|
|
|
struct MESSAGE_NOTIFY_HUMIDITY
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
float value;
|
|
};
|
|
|
|
struct MESSAGE_NOTIFY_LIGHT // 21 bytes
|
|
{
|
|
struct MESSAGE_HEADER header;
|
|
uint8_t id;
|
|
uint16_t value;
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
#define MQTT_MESSAGE_BLOCK_RADAR(msgaddr_) \
|
|
createHeader(&(*msgaddr_).header); \
|
|
(msgaddr_)->id = MESSAGE_TYPE_BLOCK_RADAR;
|
|
|
|
#define MQTT_MESSAGE_BLOCK_SENSOR(msgaddr_) \
|
|
createHeader(&(*msgaddr_).header); \
|
|
(msgaddr_)->id = MESSAGE_TYPE_BLOCK_SENSOR;
|
|
|
|
#define MQTT_MESSAGE_NOTIFY_LIGHT(msgaddr_) \
|
|
createHeader(&(msgaddr_)->header); \
|
|
(msgaddr_)->id = MESSAGE_TYPE_NOTIFY_LIGHT;
|
|
|
|
#define MQTT_MESSAGE_NOTIFY_PRESSURE(msgaddr_) \
|
|
createHeader(&(msgaddr_)->header); \
|
|
(msgaddr_)->id = MESSAGE_TYPE_NOTIFY_PRESSURE;
|
|
|
|
|
|
#define MESSAGE_TYPE_NOTIFY_PRESSURE 0x01
|
|
#define MESSAGE_TYPE_NOTIFY_TEMPERATURE 0x02
|
|
#define MESSAGE_TYPE_NOTIFY_HUMIDITY 0x03
|
|
#define MESSAGE_TYPE_NOTIFY_LIGHT 0x04
|
|
|
|
#define MESSAGE_TYPE_BLOCK_RADAR 0x10
|
|
#define MESSAGE_TYPE_BLOCK_SENSOR 0x11
|
|
|
|
void createHeader(struct MESSAGE_HEADER * header);
|
|
|
|
#endif |