diff --git a/zh_rf_config.h b/zh_rf_config.h index d008956..3cbff56 100644 --- a/zh_rf_config.h +++ b/zh_rf_config.h @@ -19,37 +19,71 @@ extern "C" { int16_t id; int16_t type; - int16_t battery_voltage; + int16_t battery; int16_t value_1; int16_t value_2; int16_t value_3; int16_t value_4; + int16_t value_5; + int16_t value_6; + int16_t value_7; + int16_t value_8; + int16_t value_9; + int16_t value_10; } zh_rf_sensor_transmitted_data_t; -#define ZH_RF_SENSOR_TYPE \ - DF(ZH_RF_SENSOR_NONE, "") \ - DF(ZH_RF_SENSOR_BME280, "bme280") /* {id, ZH_RF_SENSOR_BME280, battery_voltage, humidity, temperature, pressure, 0} */ \ - DF(ZH_RF_SENSOR_BMP280, "bmp280") /* {id, ZH_RF_SENSOR_BMP280, battery_voltage, temperature, pressure, 0, 0} */ \ - DF(ZH_RF_SENSOR_BME680, "bme680") /* {id, ZH_RF_SENSOR_BME680, battery_voltage, humidity, temperature, pressure, quality} */ \ - DF(ZH_RF_SENSOR_TOUCH_SWITCH, "touch_switch") /* {id, ZH_RF_SENSOR_TOUCH_SWITCH, battery_voltage, 0, 0, 0, 0} */ \ - DF(ZH_RF_SENSOR_WATER_LEAKAGE, "water_leakage") /* {id, ZH_RF_SENSOR_WATER_LEAKAGE, battery_voltage, status (ALARM/DRY), 0, 0, 0} */ \ - DF(ZH_RF_SENSOR_PLANT_HUMIDITY, "plant_humidity") /* {id, ZH_RF_SENSOR_PLANT_HUMIDITY, battery_voltage, humidity, 0, 0, 0} */ \ - DF(ZH_RF_SENSOR_OPEN_CLOSE, "open_close") /* {id, ZH_RF_SENSOR_OPEN_CLOSE, battery_voltage, status (OPEN/CLOSE), 0, 0, 0} */ \ - DF(ZH_RF_SENSOR_MAX, "") + typedef struct + { + uint8_t type; + uint8_t magic; + uint8_t token_hi; + uint8_t token_lo; + uint8_t id; + } zh_rf_sensor_pairing_data_t; + +#define ZH_RF_PAIRING_PACKET_SIZE 5 +#define ZH_RF_PAIRING_REQ_MAGIC 0xA5 +#define ZH_RF_PAIRING_ACK_MAGIC 0x5A + + /** + * @brief Sensor types description. + * + * DF(value, name, payload size (in bytes)) + * + * - BME280 12 — {id, type, battery, humidity, temperature, pressure} + * - BMP280 10 — {id, type, battery, temperature, pressure} + * - BME680 14 — {id, type, battery, humidity, temperature, pressure, quality} + * - TOUCH_SWITCH 6 — {id, type, battery} + * - WATER_LEAKAGE 8 — {id, type, battery, status} + * - PLANT_HUMIDITY 8 — {id, type, battery, humidity} + * - OPEN_CLOSE 8 — {id, type, battery, status} + * + * @note payload size - FULL packet size, including the header (id + type + battery). + */ +#define ZH_RF_SENSOR_TYPE \ + DF(ZH_RF_SENSOR_NONE, "", 0) \ + DF(ZH_RF_SENSOR_BME280, "bme280", 12) \ + DF(ZH_RF_SENSOR_BMP280, "bmp280", 10) \ + DF(ZH_RF_SENSOR_BME680, "bme680", 14) \ + DF(ZH_RF_SENSOR_TOUCH_SWITCH, "touch_switch", 6) \ + DF(ZH_RF_SENSOR_WATER_LEAKAGE, "water_leakage", 8) \ + DF(ZH_RF_SENSOR_PLANT_HUMIDITY, "plant_humidity", 8) \ + DF(ZH_RF_SENSOR_OPEN_CLOSE, "open_close", 8) \ + DF(ZH_RF_SENSOR_MAX, "", 0) typedef enum { -#define DF(_value, _name) _value, +#define DF(_value, _name, _size) _value, ZH_RF_SENSOR_TYPE #undef DF } zh_rf_sensor_type_t; - const char *get_zh_rf_sensor_type_name(zh_rf_sensor_type_t value) + static inline const char *zh_get_rf_sensor_type_name(zh_rf_sensor_type_t value) { switch (value) { -#define DF(_value, _name) \ - case _value: \ +#define DF(_value, _name, _size) \ + case _value: \ return _name; ZH_RF_SENSOR_TYPE #undef DF @@ -60,6 +94,22 @@ extern "C" return ""; } + static inline uint8_t zh_get_rf_sensor_payload_size(int16_t type) + { + switch (type) + { +#define DF(_value, _name, _size) \ + case _value: \ + return (uint8_t)(_size); + ZH_RF_SENSOR_TYPE +#undef DF + break; + default: + break; + } + return 0; + } + #ifdef __cplusplus } #endif \ No newline at end of file