116 lines
2.8 KiB
C
116 lines
2.8 KiB
C
|
|
/**
|
|||
|
|
******************************************************************************
|
|||
|
|
* @file rf433_tx_app.h
|
|||
|
|
* @brief RF433 TX应用层接口
|
|||
|
|
******************************************************************************
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef __RF433_TX_APP_H__
|
|||
|
|
#define __RF433_TX_APP_H__
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
extern "C" {
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#include "rf433.h"
|
|||
|
|
#include <stdint.h>
|
|||
|
|
#include <stdbool.h>
|
|||
|
|
|
|||
|
|
/* ============================================================================
|
|||
|
|
* 数据类型定义
|
|||
|
|
* ============================================================================ */
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief TX状态机状态
|
|||
|
|
*/
|
|||
|
|
typedef enum {
|
|||
|
|
TX_STATE_INIT = 0, /**< 初始化状态 */
|
|||
|
|
TX_STATE_SENDING, /**< 发送中状态 */
|
|||
|
|
TX_STATE_WAITING, /**< 等待状态 */
|
|||
|
|
TX_STATE_IDLE, /**< 空闲状态 */
|
|||
|
|
} tx_state_t;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief TX应用结构体
|
|||
|
|
*/
|
|||
|
|
typedef struct {
|
|||
|
|
tx_state_t state; /**< 当前状态 */
|
|||
|
|
uint32_t send_count; /**< 已发送次数 */
|
|||
|
|
uint32_t total_count; /**< 总发送次数 */
|
|||
|
|
uint32_t send_interval_ms; /**< 发送间隔(ms) */
|
|||
|
|
uint32_t last_send_time; /**< 上次发送时间 */
|
|||
|
|
rf433_register_t config; /**< RF433配置 */
|
|||
|
|
bool is_running; /**< 是否正在运行 */
|
|||
|
|
} rf433_tx_app_t;
|
|||
|
|
|
|||
|
|
/* ============================================================================
|
|||
|
|
* API函数声明
|
|||
|
|
* ============================================================================ */
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 初始化TX应用层
|
|||
|
|
* @param config RF433配置参数
|
|||
|
|
* @retval RF433_OK 成功
|
|||
|
|
* @retval RF433_ERROR 参数错误
|
|||
|
|
*/
|
|||
|
|
rf433_error_t rf433_tx_app_init(const rf433_register_t *config);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 启动TX自动发送
|
|||
|
|
* @param count 总发送次数
|
|||
|
|
* @param interval_ms 发送间隔(ms)
|
|||
|
|
* @retval RF433_OK 成功
|
|||
|
|
* @retval RF433_ERROR 参数错误
|
|||
|
|
*/
|
|||
|
|
rf433_error_t rf433_tx_app_start(uint32_t count, uint32_t interval_ms);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 停止TX自动发送
|
|||
|
|
* @retval RF433_OK 成功
|
|||
|
|
*/
|
|||
|
|
rf433_error_t rf433_tx_app_stop(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 手动发送数据
|
|||
|
|
* @param data 数据指针
|
|||
|
|
* @param length 数据长度
|
|||
|
|
* @retval RF433_OK 成功
|
|||
|
|
* @retval RF433_ERROR 参数错误
|
|||
|
|
* @retval RF433_ERROR_BUSY 模块忙
|
|||
|
|
*/
|
|||
|
|
rf433_error_t rf433_tx_app_manual_send(uint8_t *data, uint16_t length);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief TX任务函数(在主循环中调用)
|
|||
|
|
*/
|
|||
|
|
void rf433_tx_app_task(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取TX状态
|
|||
|
|
* @return 当前TX状态
|
|||
|
|
*/
|
|||
|
|
tx_state_t rf433_tx_app_get_state(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取已发送次数
|
|||
|
|
* @return 已发送次数
|
|||
|
|
*/
|
|||
|
|
uint32_t rf433_tx_app_get_send_count(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取总发送次数
|
|||
|
|
* @return 总发送次数
|
|||
|
|
*/
|
|||
|
|
uint32_t rf433_tx_app_get_total_count(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 重置TX计数器
|
|||
|
|
*/
|
|||
|
|
void rf433_tx_app_reset_count(void);
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#endif /* __RF433_TX_APP_H__ */
|