#ifndef __MB_INTERFACE_H__
#define __MB_INTERFACE_H__

#include "mb_command.h"
#include "mb_regs_def.h"
#include <stdint.h>

/**
 * @brief Initialize Modbus interface module
 *        初始化Modbus接口模块
 */
void mb_interface_init(void);

/**
 * @brief Write current temperature data
 *        写入当前温度数据
 * 
 * @param temp Temperature value to write (°C)
 */
void mb_write_current_temp(float temp);

/**
 * @brief Write current rotation data
 *        写入当前旋光度数据
 * 
 * @param rotation Rotation value to write (°)
 */
void mb_write_current_rotation(float rotation);

/**
 * @brief Write measurement result
 *        写入测量结果
 * 
 * @param mode Measurement mode (0-3)
 * @param value Measurement value
 * @param temp Temperature at measurement time (°C)
 */
void mb_write_measurement_result(uint8_t mode, float value, float temp);

/**
 * @brief Save measurement data to history
 *        保存测量数据到历史记录
 * 
 * @param value Measurement value
 * @param temp Temperature value
 */
void mb_save_to_history(float value, float temp);

/**
 * @brief Get current target temperature
 *        获取当前目标温度设置
 * 
 * @return Target temperature value (°C)
 */
float mb_get_target_temp(void);

/**
 * @brief Get current tube length setting
 *        获取当前旋光管长度设置
 * 
 * @return Tube length value (mm)
 */
float mb_get_tube_length(void);

/**
 * @brief Get current measurement mode
 *        获取当前测量模式
 * 
 * @return Measurement mode code (0-3)
 */
uint8_t mb_get_measure_mode(void);

/**
 * @brief Get current auto measurement count
 *        获取当前自动测量次数设置
 * 
 * @return Auto measurement count (1-255)
 */
uint8_t mb_get_auto_measure_count(void);

/**
 * @brief Get current running state
 *        获取当前运行状态
 * 
 * @return Running state code
 */
PmRunningState mb_get_running_state(void);

/**
 * @brief Check if measurement is complete
 *        检查测量是否完成
 * 
 * @return 1 if complete, 0 otherwise
 */
uint8_t mb_is_measure_complete(void);

#endif /* __MB_INTERFACE_H__ */
