1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #ifndef _DLT645_H
- #define _DLT645_H
- #include "stm32f2xx.h"
- #include <stdint.h>
- #include "FreeRTOS.h"
- #include "task.h"
- #define DL645_MAX_READ_LEN 200 //读数据的最大数据长度
- #define DL645_MAX_WRITE_LEN 50 //写数据的最大数据长度
- // port setting
- #define DLT645_DEFAULT_RESPONSE_TIMEOUT 500 //500ms
- #define MAX_DEVICE_NAME_LEN 10 //最大设备名长度
- #define dlt_malloc malloc
- #define dlt_free free
- #define gettick() ( xTaskGetTickCount() )
- //DLT645 环境结构体
- typedef struct dlt645
- {
- uint8_t addr[6]; //从机地址
- uint8_t debug; //调试标志
- int (*write)(struct dlt645 *ctx, uint8_t *buf, uint16_t len); //底层写函数
- int (*read) (struct dlt645 *ctx, uint8_t *msg, uint16_t len); //底层读函数
- void *port_data; //移植层拓展接口
- } dlt645_t;
- typedef enum
- {
- DLT645_2007 = 1,
- DLT645_1997
- } dlt645_protocal;
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #define DLT_RXSIZE 200
- // DLT645采集使用的串口名
- #define DLT645_USART USART_485
- #define DLT645_CTRL_GPIO USART_485_DE_GPIO_PORT
- #define DLT645_CTRL_PIN USART_485_DE_PIN
- // DL/T 645硬件拓展结构体
- typedef struct
- {
- uint8_t dlt645_Tx; // 用于串口接收的状态
- uint32_t timeout; //
- uint8_t rxBuf[DLT_RXSIZE];
- uint8_t done;
- uint8_t index;
- } dlt645_port_t;
- extern dlt645_port_t dlt645_port;
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //设置从机地址
- extern void dlt645_set_addr(dlt645_t *ctx, uint8_t *addr);
- //设置调试开关
- extern int dlt645_set_debug(dlt645_t *ctx, int flag);
- //数据采集
- extern int dlt645_read_data(dlt645_t *ctx, uint32_t code, uint8_t *read_data, dlt645_protocal protocal);
- //十进制转BCD码(32位)
- extern uint32_t dec_to_bcd(uint32_t val);
- //字符串转BCD形式
- extern int str_to_bcd(char *str, uint8_t *bcd_store_address, uint16_t bcd_len);
- extern void dlt645_init(uint32_t timeout);
- extern void dlt_callback(UART_HandleTypeDef *husart);
- #endif
|