style!: big renaming

This commit is contained in:
aZholtikov committed 2026-10-25 11:33:12 +03:00
1 parent a9843e634e
commit 8f3940ec6a
1 file changed
+79 -79
+79 -79
View File
@@ -1,7 +1,7 @@
/** /**
* @file zh_rf_config.h * @file zh_nrf24_config.h
* *
* @brief RF sensor configuration types and pairing protocol definitions. * @brief nRF24 sensor configuration types and pairing protocol definitions.
* *
* This header defines data structures and enumerations for RF sensor devices, * This header defines data structures and enumerations for RF sensor devices,
* including transmitted payload, pairing packet format, sensor status values, * including transmitted payload, pairing packet format, sensor status values,
@@ -36,16 +36,16 @@ extern "C"
*/ */
typedef enum typedef enum
{ {
ZH_RF_SENSOR_STATUS_NONE, /*!< Status is not set or unknown */ ZH_NRF24_SENSOR_STATUS_NONE, /*!< Status is not set or unknown */
ZH_RF_SENSOR_STATUS_OPEN, /*!< Contact sensor is open */ ZH_NRF24_SENSOR_STATUS_OPEN, /*!< Contact sensor is open */
ZH_RF_SENSOR_STATUS_CLOSE, /*!< Contact sensor is closed */ ZH_NRF24_SENSOR_STATUS_CLOSE, /*!< Contact sensor is closed */
ZH_RF_SENSOR_STATUS_ALARM, /*!< Leak detector reports wet/alarm */ ZH_NRF24_SENSOR_STATUS_ALARM, /*!< Leak detector reports wet/alarm */
ZH_RF_SENSOR_STATUS_DRY, /*!< Leak detector reports dry/no-alarm */ ZH_NRF24_SENSOR_STATUS_DRY, /*!< Leak detector reports dry/no-alarm */
ZH_RF_SENSOR_STATUS_MAX /*!< Sentinel value marking the end of the enumeration */ ZH_NRF24_SENSOR_STATUS_MAX /*!< Sentinel value marking the end of the enumeration */
} zh_rf_sensor_status_type_t; } zh_nrf24_sensor_status_type_t;
/** /**
* @brief Fixed-width payload transmitted by an RF sensor. * @brief Fixed-width payload transmitted by an nRF24 sensor.
* *
* Header fields (id, type, battery) are present in every transmission. * Header fields (id, type, battery) are present in every transmission.
* Value fields are used only by sensor types that report measurements. * Value fields are used only by sensor types that report measurements.
@@ -53,7 +53,7 @@ extern "C"
typedef struct typedef struct
{ {
int16_t id; /*!< Sensor identifier assigned during pairing */ int16_t id; /*!< Sensor identifier assigned during pairing */
int16_t type; /*!< Sensor type code from zh_rf_sensor_type_t */ int16_t type; /*!< Sensor type code from zh_nrf24_sensor_type_t */
int16_t battery; /*!< Battery level reported by the sensor */ int16_t battery; /*!< Battery level reported by the sensor */
int16_t value_1; /*!< First measurement or status value */ int16_t value_1; /*!< First measurement or status value */
int16_t value_2; /*!< Second measurement or status value */ int16_t value_2; /*!< Second measurement or status value */
@@ -65,10 +65,10 @@ extern "C"
int16_t value_8; /*!< Eighth measurement or status value */ int16_t value_8; /*!< Eighth measurement or status value */
int16_t value_9; /*!< Ninth measurement or status value */ int16_t value_9; /*!< Ninth measurement or status value */
int16_t value_10; /*!< Tenth measurement or status value */ int16_t value_10; /*!< Tenth measurement or status value */
} zh_rf_sensor_transmitted_data_t; } zh_nrf24_sensor_transmitted_data_t;
/** /**
* @brief States of the RF sensor pairing state machine. * @brief States of the nRF24 sensor pairing state machine.
* *
* Describes the current step of the pairing exchange between a sensor and * Describes the current step of the pairing exchange between a sensor and
* the hub. The machine cycles through sending a pairing request, waiting * the hub. The machine cycles through sending a pairing request, waiting
@@ -77,17 +77,17 @@ extern "C"
*/ */
typedef enum typedef enum
{ {
ZH_RF_PAIR_SEND, /*!< Build and submit a pairing request packet for transmission */ ZH_NRF24_PAIR_SEND, /*!< Build and submit a pairing request packet for transmission */
ZH_RF_PAIR_TX_WAIT, /*!< Wait until the radio has finished sending the request */ ZH_NRF24_PAIR_TX_WAIT, /*!< Wait until the radio has finished sending the request */
ZH_RF_PAIR_RX_WAIT, /*!< Listen for the acknowledge packet from the hub */ ZH_NRF24_PAIR_RX_WAIT, /*!< Listen for the acknowledge packet from the hub */
ZH_RF_PAIR_BACKOFF /*!< Idle for a random delay before restarting the pairing attempt */ ZH_NRF24_PAIR_BACKOFF /*!< Idle for a random delay before restarting the pairing attempt */
} zh_rf_sensor_pairing_state_t; } zh_nrf24_sensor_pairing_state_t;
/** /**
* @brief Pairing packet exchanged between a sensor and the hub. * @brief Pairing packet exchanged between a sensor and the hub.
* *
* A pairing request carries ZH_RF_PAIRING_REQ_MAGIC as its magic byte; * A pairing request carries ZH_NRF24_PAIRING_REQ_MAGIC as its magic byte;
* the acknowledge response uses ZH_RF_PAIRING_ACK_MAGIC. Token fields * the acknowledge response uses ZH_NRF24_PAIRING_ACK_MAGIC. Token fields
* form a 16-bit association identifier split into high and low bytes. * form a 16-bit association identifier split into high and low bytes.
*/ */
typedef struct typedef struct
@@ -97,18 +97,18 @@ extern "C"
uint8_t token_hi; /*!< High byte of the pairing token */ uint8_t token_hi; /*!< High byte of the pairing token */
uint8_t token_lo; /*!< Low byte of the pairing token */ uint8_t token_lo; /*!< Low byte of the pairing token */
uint8_t id; /*!< Sensor identifier assigned by the hub */ uint8_t id; /*!< Sensor identifier assigned by the hub */
} zh_rf_sensor_pairing_data_t; } zh_nrf24_sensor_pairing_data_t;
#define ZH_RF_PAIRING_PACKET_SIZE 5 #define ZH_NRF24_PAIRING_PACKET_SIZE 5
#define ZH_RF_PAIRING_REQ_MAGIC 0xA5 #define ZH_NRF24_PAIRING_REQ_MAGIC 0xA5
#define ZH_RF_PAIRING_ACK_MAGIC 0x5A #define ZH_NRF24_PAIRING_ACK_MAGIC 0x5A
#define ZH_RF_DATA_HEADER_SIZE 6 #define ZH_NRF24_DATA_HEADER_SIZE 6
#define ZH_RF_DATA_FIELD_SIZE 2 #define ZH_NRF24_DATA_FIELD_SIZE 2
#define ZH_RF_MAX_PAYLOAD_SIZE 32 #define ZH_NRF24_MAX_PAYLOAD_SIZE 32
/** /**
* @brief X-macro table describing every supported RF sensor type. * @brief X-macro table describing every supported nRF24 sensor type.
* *
* Each entry expands as DF(value, name, payload size (in bytes)): * Each entry expands as DF(value, name, payload size (in bytes)):
* - BME280 12 — {id, type, battery, humidity, temperature, pressure} * - BME280 12 — {id, type, battery, humidity, temperature, pressure}
@@ -121,46 +121,46 @@ extern "C"
* *
* @note Payload size is the full packet size, including the header (id + type + battery). * @note Payload size is the full packet size, including the header (id + type + battery).
*/ */
#define ZH_RF_SENSOR_TYPE \ #define ZH_NRF24_SENSOR_TYPE \
DF(ZH_RF_SENSOR_NONE, "", 0) \ DF(ZH_NRF24_SENSOR_NONE, "", 0) \
DF(ZH_RF_SENSOR_BME280, "bme280", 12) \ DF(ZH_NRF24_SENSOR_BME280, "bme280", 12) \
DF(ZH_RF_SENSOR_BMP280, "bmp280", 10) \ DF(ZH_NRF24_SENSOR_BMP280, "bmp280", 10) \
DF(ZH_RF_SENSOR_BME680, "bme680", 14) \ DF(ZH_NRF24_SENSOR_BME680, "bme680", 14) \
DF(ZH_RF_SENSOR_TOUCH_SWITCH, "touch_switch", 6) \ DF(ZH_NRF24_SENSOR_TOUCH_SWITCH, "touch_switch", 6) \
DF(ZH_RF_SENSOR_WATER_LEAKAGE, "water_leakage", 8) \ DF(ZH_NRF24_SENSOR_WATER_LEAKAGE, "water_leakage", 8) \
DF(ZH_RF_SENSOR_PLANT_HUMIDITY, "plant_humidity", 8) \ DF(ZH_NRF24_SENSOR_PLANT_HUMIDITY, "plant_humidity", 8) \
DF(ZH_RF_SENSOR_OPEN_CLOSE, "open_close", 8) \ DF(ZH_NRF24_SENSOR_OPEN_CLOSE, "open_close", 8) \
DF(ZH_RF_SENSOR_MAX, "", 0) DF(ZH_NRF24_SENSOR_MAX, "", 0)
/** /**
* @brief Identifiers of supported RF sensor types. * @brief Identifiers of supported nRF24 sensor types.
* *
* Generated from the ZH_RF_SENSOR_TYPE X-macro table. ZH_RF_SENSOR_NONE * Generated from the ZH_NRF24_SENSOR_TYPE X-macro table. ZH_NRF24_SENSOR_NONE
* marks an unset type and ZH_RF_SENSOR_MAX serves as a sentinel value. * marks an unset type and ZH_NRF24_SENSOR_MAX serves as a sentinel value.
*/ */
typedef enum typedef enum
{ {
#define DF(_value, _name, _size) _value, #define DF(_value, _name, _size) _value,
ZH_RF_SENSOR_TYPE ZH_NRF24_SENSOR_TYPE
#undef DF #undef DF
} zh_rf_sensor_type_t; } zh_nrf24_sensor_type_t;
/** /**
* @brief Retrieve the human-readable name of a sensor type. * @brief Retrieve the human-readable name of a sensor type.
* *
* @param[in] value Sensor type code from zh_rf_sensor_type_t * @param[in] value Sensor type code from zh_nrf24_sensor_type_t
* *
* @return Type name string on success * @return Type name string on success
* @return Empty string if the value has no associated name * @return Empty string if the value has no associated name
*/ */
static inline const char *zh_get_rf_sensor_type_name(zh_rf_sensor_type_t value) static inline const char *zh_get_nrf24_sensor_type_name(zh_nrf24_sensor_type_t value)
{ {
switch (value) switch (value)
{ {
#define DF(_value, _name, _size) \ #define DF(_value, _name, _size) \
case _value: \ case _value: \
return _name; return _name;
ZH_RF_SENSOR_TYPE ZH_NRF24_SENSOR_TYPE
#undef DF #undef DF
break; break;
default: default:
@@ -172,19 +172,19 @@ extern "C"
/** /**
* @brief Retrieve the full payload size of a sensor transmission. * @brief Retrieve the full payload size of a sensor transmission.
* *
* @param[in] type Sensor type code from zh_rf_sensor_type_t * @param[in] type Sensor type code from zh_nrf24_sensor_type_t
* *
* @return Payload size in bytes (including the id, type, battery header) on success * @return Payload size in bytes (including the id, type, battery header) on success
* @return Zero if the type has no associated payload size * @return Zero if the type has no associated payload size
*/ */
static inline uint8_t zh_get_rf_sensor_payload_size(int16_t type) static inline uint8_t zh_get_nrf24_sensor_payload_size(int16_t type)
{ {
switch (type) switch (type)
{ {
#define DF(_value, _name, _size) \ #define DF(_value, _name, _size) \
case _value: \ case _value: \
return (uint8_t)(_size); return (uint8_t)(_size);
ZH_RF_SENSOR_TYPE ZH_NRF24_SENSOR_TYPE
#undef DF #undef DF
break; break;
default: default:
@@ -203,7 +203,7 @@ extern "C"
* @param[in,out] pos Current write position (must be < buf_max - 1) * @param[in,out] pos Current write position (must be < buf_max - 1)
* @param[in] val Value to write * @param[in] val Value to write
*/ */
static inline void zh_rf_sensor_append_i16_le(uint8_t *buf, uint8_t *pos, int16_t val) static inline void zh_nrf24_sensor_append_i16_le(uint8_t *buf, uint8_t *pos, int16_t val)
{ {
buf[(*pos)++] = (uint8_t)((uint16_t)val & 0xFF); buf[(*pos)++] = (uint8_t)((uint16_t)val & 0xFF);
buf[(*pos)++] = (uint8_t)(((uint16_t)val >> 8) & 0xFF); buf[(*pos)++] = (uint8_t)(((uint16_t)val >> 8) & 0xFF);
@@ -221,7 +221,7 @@ extern "C"
* *
* @return 16-bit value assembled from the two bytes at the current position * @return 16-bit value assembled from the two bytes at the current position
*/ */
static inline int16_t zh_rf_sensor_read_i16_le(const uint8_t *buf, uint8_t *pos) static inline int16_t zh_nrf24_sensor_read_i16_le(const uint8_t *buf, uint8_t *pos)
{ {
int16_t value = (int16_t)((uint16_t)buf[*pos] | ((uint16_t)buf[*pos + 1] << 8)); int16_t value = (int16_t)((uint16_t)buf[*pos] | ((uint16_t)buf[*pos + 1] << 8));
*pos += 2; *pos += 2;
@@ -240,7 +240,7 @@ extern "C"
* *
* @return 16-bit value assembled from the two bytes at the specified offset * @return 16-bit value assembled from the two bytes at the specified offset
*/ */
static inline int16_t zh_rf_sensor_read_i16_le_at(const uint8_t *buf, uint8_t offset) static inline int16_t zh_nrf24_sensor_read_i16_le_at(const uint8_t *buf, uint8_t offset)
{ {
return (int16_t)((uint16_t)buf[offset] | ((uint16_t)buf[offset + 1] << 8)); return (int16_t)((uint16_t)buf[offset] | ((uint16_t)buf[offset + 1] << 8));
} }
@@ -260,60 +260,60 @@ extern "C"
* @return Zero if the buffer is too small for the sensor's payload format * @return Zero if the buffer is too small for the sensor's payload format
* @return Zero if the sensor type is unknown * @return Zero if the sensor type is unknown
*/ */
static inline uint8_t zh_rf_sensor_build_payload(const zh_rf_sensor_transmitted_data_t *data, uint8_t *buf, uint8_t buf_max) static inline uint8_t zh_nrf24_sensor_build_payload(const zh_nrf24_sensor_transmitted_data_t *data, uint8_t *buf, uint8_t buf_max)
{ {
uint8_t pos = 0; uint8_t pos = 0;
if (buf_max < ZH_RF_DATA_HEADER_SIZE) if (buf_max < ZH_NRF24_DATA_HEADER_SIZE)
{ {
return 0; return 0;
} }
zh_rf_sensor_append_i16_le(buf, &pos, data->id); zh_nrf24_sensor_append_i16_le(buf, &pos, data->id);
zh_rf_sensor_append_i16_le(buf, &pos, data->type); zh_nrf24_sensor_append_i16_le(buf, &pos, data->type);
zh_rf_sensor_append_i16_le(buf, &pos, data->battery); zh_nrf24_sensor_append_i16_le(buf, &pos, data->battery);
switch (data->type) switch (data->type)
{ {
case ZH_RF_SENSOR_TOUCH_SWITCH: case ZH_NRF24_SENSOR_TOUCH_SWITCH:
break; break;
case ZH_RF_SENSOR_WATER_LEAKAGE: case ZH_NRF24_SENSOR_WATER_LEAKAGE:
case ZH_RF_SENSOR_OPEN_CLOSE: case ZH_NRF24_SENSOR_OPEN_CLOSE:
case ZH_RF_SENSOR_PLANT_HUMIDITY: case ZH_NRF24_SENSOR_PLANT_HUMIDITY:
if (buf_max < pos + ZH_RF_DATA_FIELD_SIZE) if (buf_max < pos + ZH_NRF24_DATA_FIELD_SIZE)
{ {
return 0; return 0;
} }
zh_rf_sensor_append_i16_le(buf, &pos, data->value_1); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_1);
break; break;
case ZH_RF_SENSOR_BMP280: case ZH_NRF24_SENSOR_BMP280:
if (buf_max < pos + 2 * ZH_RF_DATA_FIELD_SIZE) if (buf_max < pos + 2 * ZH_NRF24_DATA_FIELD_SIZE)
{ {
return 0; return 0;
} }
zh_rf_sensor_append_i16_le(buf, &pos, data->value_1); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_1);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_2); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_2);
break; break;
case ZH_RF_SENSOR_BME280: case ZH_NRF24_SENSOR_BME280:
if (buf_max < pos + 3 * ZH_RF_DATA_FIELD_SIZE) if (buf_max < pos + 3 * ZH_NRF24_DATA_FIELD_SIZE)
{ {
return 0; return 0;
} }
zh_rf_sensor_append_i16_le(buf, &pos, data->value_1); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_1);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_2); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_2);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_3); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_3);
break; break;
case ZH_RF_SENSOR_BME680: case ZH_NRF24_SENSOR_BME680:
if (buf_max < pos + 4 * ZH_RF_DATA_FIELD_SIZE) if (buf_max < pos + 4 * ZH_NRF24_DATA_FIELD_SIZE)
{ {
return 0; return 0;
} }
zh_rf_sensor_append_i16_le(buf, &pos, data->value_1); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_1);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_2); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_2);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_3); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_3);
zh_rf_sensor_append_i16_le(buf, &pos, data->value_4); zh_nrf24_sensor_append_i16_le(buf, &pos, data->value_4);
break; break;
default: default:
return 0; return 0;
} }
if (pos != zh_get_rf_sensor_payload_size(data->type)) if (pos != zh_get_nrf24_sensor_payload_size(data->type))
{ {
return 0; return 0;
} }