#ifndef _FRT_PROTOCOL_H_ #define _FRT_PROTOCOL_H_ #include "uart_dev.h" #include "pdebug.h" #include "timer.h" #include "comm_types.h" #ifdef __cplusplus extern "C" { #endif /* 富奥通微气象modbus传感器协议 */ /* 功能码 */ typedef enum { FRT_FUNCTION_CODE_READ_REGISTER = 0x03, /* 读寄存器 */ FRT_FUNCTION_CODE_WRITE_REGISTER = 0x10, /* 写寄存器 */ } FRT_MsgFunctionCode_e; /* 寄存器地址 */ typedef enum { FRT_REGISTER_MIN_WIND_DIRECTION = 0, /* 最小风向 */ FRT_REGISTER_AVERAGE_WIND_DIRECTION = 1, /* 平均风向 */ FRT_REGISTER_INSTANTANEOUS_WIND_DIRECTION = 2, /* 瞬时风向 */ FRT_REGISTER_MAX_WIND_DIRECTION = 3, /* 最大风向 */ FRT_REGISTER_MIN_WIND_SPEED = 4, /* 最小风速 */ FRT_REGISTER_THROUGH_WIND_SPEED = 5, /* 极小风速 */ FRT_REGISTER_AVERAGE_WIND_SPEED = 6, /* 平均风速 */ FRT_REGISTER_INSTANTANEOUS_WIND_SPEED = 7, /* 瞬时风速 */ FRT_REGISTER_PEAK_WIND_SPEED = 8, /* 极大风速 */ FRT_REGISTER_MAX_WIND_SPEED = 9, /* 最大风速 */ FRT_REGISTER_TEMPERATURE = 10, /* 大气温度 */ FRT_REGISTER_HUMIDITY = 11, /* 大气湿度 */ FRT_REGISTER_PRESSURE = 12, /* 大气压 */ FRT_REGISTER_RAIN = 13, /* 雨量 */ FRT_REGISTER_PRECIPITATION_INTENSITY = 14, /* 总辐射 */ FRT_REGISTER_DEVICE_ADDR = 20, /* 设备地址 */ FRT_REGISTER_COMMU_BAUDRATE = 21, /* 波特率 */ FRT_REGISTER_SPEED_AVERAGE_TIME = 22, /* 风速平均时间 */ FRT_REGISTER_TEMPHUM_UPDATE_TIME = 23, /* 温湿度更新时间 */ FRT_REGISTER_RAIN_POWER_CONTROL = 24, /* 雨量电源控制 */ FRT_REGISTER_RAIN_REST = 25, /* 雨量复位 */ FRT_REGISTER_SOFT_REST = 26, /* 软件复位 */ FRT_REGISTER_REST_DEFAULT_SETTING = 27, /* 恢复出厂设置 */ FRT_REGISTER_PROTOCOL_SETTING = 28, /* 设置协议:0-ASCII;1-MODBUS协议 */ FRT_REGISTER_TRANSDUCER_CFG_1R5 = 30, /* 换能器参数 */ FRT_REGISTER_TRANSDUCER_CFG_4R5 = 31, /* 换能器参数 */ FRT_REGISTER_TRANSDUCER_CFG_8R0 = 32, /* 换能器参数 */ FRT_REGISTER_RSSI_RANGE = 33, /* RSSI有效范围 */ FRT_REGISTER_DISTANCE = 34, /* 换能器表面距离 */ FRT_REGISTER_ERROR_LOG = 35, /* 错误日志 */ FRT_REGISTER_WIND_C = 36, /* 计算得到的风速 */ FRT_REGISTER_LINEAR_POINT_X_1 = 37, /* 线性插值原始点1 */ FRT_REGISTER_LINEAR_POINT_X_2 = 38, /* 线性插值原始点2 */ FRT_REGISTER_LINEAR_POINT_X_3 = 39, /* 线性插值原始点3 */ FRT_REGISTER_LINEAR_POINT_X_4 = 40, /* 线性插值原始点4 */ FRT_REGISTER_LINEAR_POINT_X_5 = 41, /* 线性插值原始点5 */ FRT_REGISTER_LINEAR_POINT_Y_1 = 42, /* 线性插值校准点1 */ FRT_REGISTER_LINEAR_POINT_Y_2 = 43, /* 线性插值校准点2 */ FRT_REGISTER_LINEAR_POINT_Y_3 = 44, /* 线性插值校准点3 */ FRT_REGISTER_LINEAR_POINT_Y_4 = 45, /* 线性插值校准点4 */ FRT_REGISTER_LINEAR_POINT_Y_5 = 46, /* 线性插值校准点5 */ FRT_REGISTER_LINEAR_ENABLE = 47, /* 线性插值使能 */ }FRT_MsgRegister; #pragma pack(push,1) typedef struct _frt_climate_pack{ unsigned char addr; unsigned char func; unsigned char addr_begin_high_byte; unsigned char addr_begin_low_byte; unsigned char regnum_begin_high_byte; unsigned char regnum_begin_low_byte; unsigned char crc_low_byte; unsigned char crc_high_byte; }frt_climate_pack; typedef struct _frt_climate_pack_write{ unsigned char addr; unsigned char func; unsigned char addr_begin_high_byte; unsigned char addr_begin_low_byte; unsigned char regnum_begin_high_byte; unsigned char regnum_begin_low_byte; unsigned char byte_num; unsigned char *reg_val; unsigned char crc_low_byte; unsigned char crc_high_byte; }frt_climate_pack_write; #define FRT_CLIMATE_PACK_SIZE(x) (sizeof(frt_climate_pack)) #define FRT_CLIMATE_PACK_CRC16(x) ((x->crc_low_byte)|(x->crc_high_byte<<8)) #define FRT_CLIMATE_BUFF_CRC16(x) ((x[MsgLen - 2]) | (x[MsgLen - 1] << 8)) typedef struct _frt_climate_pack_resp{ unsigned char addr; unsigned char func; unsigned char data_len; unsigned char data[1]; }frt_climate_pack_resp; typedef void (*MsgProcFunc)(device_handle device, void*); /* 功能码处理函数 */ typedef struct _FRT_FunctionMsgProcTable_s{ u_int32_t msgId; MsgProcFunc pMsgProc; } FRT_FuncionMsgProcTable_s; typedef u_int16_t (*RegProcFunc)(void*); /* 寄存器处理表 */ typedef struct _FRT_RegProcTable_s{ u_int32_t regId; RegProcFunc pRegProc; } FRT_RegProcTable_s; void read_and_process_uart_data(device_handle uart_handle); #pragma pack(pop) #ifdef __cplusplus } #endif #endif