149 lines
3.5 KiB
C
149 lines
3.5 KiB
C
/// © MiroZ 2024
|
|
#ifndef __SENSOR_DATA_H__
|
|
#define __SENSOR_DATA_H__
|
|
#include <stdint.h>
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct MESSAGE_HEADER // 19 bytes
|
|
{
|
|
uint8_t type;
|
|
uint32_t sec;
|
|
uint32_t usec;
|
|
uint8_t mac[6];
|
|
uint32_t group_id;
|
|
};
|
|
|
|
struct MESSAGE_TYPE_VAL_REASON
|
|
{
|
|
uint8_t type;
|
|
uint32_t val;
|
|
uint8_t reason;
|
|
};
|
|
|
|
struct RADAR // 49
|
|
{
|
|
uint8_t type;
|
|
uint16_t vals[24];
|
|
};
|
|
|
|
struct GAS_HEADER // 2 bytes
|
|
{
|
|
uint8_t type;
|
|
uint8_t num_measurements;
|
|
};
|
|
|
|
struct GAS_DATA //5 bytes
|
|
{
|
|
uint8_t index;
|
|
float gas_resistance;
|
|
};
|
|
|
|
struct OTHERS
|
|
{
|
|
float pressure;
|
|
float temp;
|
|
uint16_t light;
|
|
};
|
|
|
|
struct GAS // 6 + num_gas_data * 5
|
|
{
|
|
struct GAS_HEADER header;
|
|
float humidity;
|
|
struct GAS_DATA data[0];
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
#define HEADER_MESSAGE(name_) \
|
|
struct MESSAGE_HEADER name_; \
|
|
createHeader(&name_);
|
|
|
|
#define HEADER_MESSAGE_P(addr_) \
|
|
createHeader(addr_);
|
|
|
|
#define PRESSURE_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_PRESSURE; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define PRESSURE_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr)->type = MESSAGE_TYPE_PRESSURE; \
|
|
(addr)->val = val_; (addr)->reason = reason_;
|
|
|
|
#define LIGHT_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_LIGHT; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define LIGHT_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr_)->type = MESSAGE_TYPE_LIGHT; \
|
|
(addr_)->val = val_; (addr_)->reason = reason_;
|
|
|
|
#define TEMP_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_TEMP; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define TEMP_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr_)->type = MESSAGE_TYPE_TEMP; \
|
|
(addr_)->val = val_; (addr_)->reason = reason_;
|
|
|
|
#define HUM_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_HUMIDITY; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define HUM_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr_)->type = MESSAGE_TYPE_HUMIDITY; \
|
|
(addr_)->val = val_; (addr_)->reason = reason_;
|
|
|
|
#define GAS_IX_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_GAS_IX; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define GAS_IX_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr_)->type = MESSAGE_TYPE_GAS_IX; \
|
|
(addr_)->val = val_; (addr_)->reason = reason_;
|
|
|
|
#define GAS_VAL_MESSAGE(name_, val_, reason_) \
|
|
struct MESSAGE_TYPE_VAL_REASON name_; \
|
|
name_.type = MESSAGE_TYPE_GAS_VAL; \
|
|
name_.val = val_; name_.reason = reason_;
|
|
|
|
#define GAS_VAL_MESSAGE_P(addr_, val_, reason_) \
|
|
(addr_)->type = MESSAGE_TYPE_GAS_VAL; \
|
|
(addr_)->val = val_; (addr_)->reason = reason_;
|
|
|
|
#define RADAR_MESSAGE(name_) \
|
|
struct RADAR name_; \
|
|
name_.type = MESSAGE_TYPE_RADAR;
|
|
|
|
#define RADAR_MESSAGE_P(addr_) \
|
|
(addr_)->type = MESSAGE_TYPE_RADAR;
|
|
|
|
#define GAS_MESSAGE(name_, num_vals_) \
|
|
struct GAS name_; \
|
|
name_.header.type = MESSAGE_TYPE_GAS; \
|
|
name_.header.num_measurements = num_vals_;
|
|
|
|
#define GAS_MESSAGE_P(addr_, num_vals_) \
|
|
(addr_)->header.type = MESSAGE_TYPE_GAS; \
|
|
(addr_)->header.num_measurements = num_vals_;
|
|
|
|
#define MESSAGE_TYPE_HEADER 0xa5
|
|
#define MESSAGE_TYPE_PRESSURE 0x04
|
|
#define MESSAGE_TYPE_RADAR 0x37
|
|
#define MESSAGE_TYPE_LIGHT 0x06
|
|
#define MESSAGE_TYPE_TEMP 0x07
|
|
#define MESSAGE_TYPE_HUMIDITY 0x08
|
|
#define MESSAGE_TYPE_GAS_IX 0x09 // deprecated
|
|
#define MESSAGE_TYPE_GAS_VAL 0x0a // deprecated
|
|
#define MESSAGE_TYPE_GAS 0x0b
|
|
#define MESSAGE_TYPE_SENSOR_BLOCK 0x0c
|
|
|
|
void createHeader(struct MESSAGE_HEADER * header);
|
|
|
|
#endif |