/**************************************************************************** ** File name : HTIEC61850Macros.h ** Description : IEC 61850 Macros define ** Create date : 2019.09.01 ** Auther by : Liuyx ** Version info : V1.0.01 ** Copyright (C) 2002-2019 xi'an huatek, Inc Co., Ltd ** Update record: ** DATE AUTHER DESC ** ------------------------------------------------------------------------- ** 2019.09.01 Liuyx first build ****************************************************************************/ #ifndef __HT_IEC_61850_MACROS_H #define __HT_IEC_61850_MACROS_H #include "HTGlobal.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /************************************************************************************ * 关于comtrade文件配置文件的宏定义。 * 在此采用预定义最大个数方法,避免动态内存管理的问题。 * * 相关字符串最大字符个数,一般不会超过16个; * 模拟量端口最大个数,一般不会超过64个; * 数字量量端口最大个数,一般不会超过64个; * 采样率最大个数,一般不会超过8个; * ************************************************************************************/ #define CMTR_REV_YEAR_LENGTH 4 #define CMTR_STRING_MAX_LENGTH 64 #define CMTR_ANALOG_MAX_COUNT 255 #define CMTR_DIGIT_MAX_COUNT 255 #define CMTR_SMPRATE_MAX_COUNT 255 #ifdef _WIN32 #define f_open _open #define f_read _read #define f_write _write #define f_close _close #else #define f_open open #define f_read read #define f_write write #define f_close close #endif /************************************************************************************ * ht_cmtr_openrb/ht_cmtr_openwb/ht_cmtr_openab/ht_cmtr_close * - 可以根据需要改写该接口,如重定义为网口的recv\send、串口r\w等 * @pfd: 文件地址、缓冲区地址、或者socket地址等 * @str: 文件路径或者联机ip或者串口地址或者共享内存名称 * ************************************************************************************/ #define ht_cmtr_openrb(str) (f_open((str), O_RDONLY, S_IWRITE | S_IREAD)) #define ht_cmtr_openwb(str) (f_open((str), O_CREAT | O_RDWR, S_IWRITE | S_IREAD)) #define ht_cmtr_openab(str) (f_open((str), O_CREAT | O_APPEND | O_RDWR, S_IWRITE | S_IREAD)) #define ht_cmtr_close(pfd) (f_close(pfd)) //字节序高低位转换开关 //#define ENDIAN_CONIVER // 宏开关 定义为文件读写 #define CMTR_IOFILE //#define CMTR_IOBUFFER // 是否输出txt的文本文件 //#define CMTR_OUT_TXTFILE // 数据库操作类型 #define DB_OPT_INSERT 1 #define DB_OPT_UPDATE 2 #define DB_OPT_DELETE 3 /************************************************************************************ * 宏定义文件的读写操作,可以根据需要改写该接口,如重定义 * 为网口的recv\send、串口r\w等。 * * ht_read_cmtr_bufn/ht_read_cmtr_bufn - cmtr的读写操作 * @pfd: 读写地址,可以为文件的fd、或者buffer地址等 * @buf: 缓冲区地址 * @count: 需要读写的字节数 * ************************************************************************************/ #if defined(CMTR_IOFILE) //typedef int _my_cmtr_ioptr; #define ht_read_cmtr_bufn(pfd, buf, count) \ do { \ if (f_read((pfd), (buf), (count)) <= 0) { \ (pfd) = -1; \ } \ } while (0); #define ht_write_cmtr_bufn(pfd, buf, count) \ do { \ if (f_write((pfd), (buf), (count)) <= 0) { \ (pfd) = -1; \ } \ } while (0); #define ht_check_cmtr_ptr(pfd) \ (((pfd) != -1) && ((pfd) != 0)) #elif defined(CMTR_IOBUFFER) //typedef u8* _my_cmtr_ioptr; //typedef unsigned char* _my_cmtr_ioptr; #define ht_read_cmtr_bufn(pfd, buf, count) \ do { \ memcpy((buf), (pfd), (count)); \ (pfd) += (count); \ } while (0); #define ht_write_cmtr_bufn(pfd, buf, count) \ do { \ memcpy((pfd), (buf), (count)); \ (pfd) += (count); \ } while (0); #define ht_check_cmtr_ptr(pfd) \ (((pfd) != -1) && ((pfd) != 0)) #endif /************************************************************************************ * ht_read_cmtr_data/ht_write_cmtr_data - 读取/写入并且转换cmtr数据。 * @src: 读写地址,为buffer地址; * @data: 读取/写入的数据; * @count: 需要读取/写入的字节个数; * @counter: 读取/写入的字节计数器; * ************************************************************************************/ #define ht_read_cmtr_data(src, data, count, counter) \ do { \ if (ht_check_cmtr_ptr(src)) { \ ht_read_cmtr_bufn((src), (data), (count)); \ (counter) += (count); \ } \ } while (0); #define ht_write_cmtr_data(src, data, count, counter) \ do { \ if (ht_check_cmtr_ptr(src)) { \ ht_write_cmtr_bufn((src), (data), (count)); \ (counter) += (count); \ } \ } while (0); #ifdef __cplusplus } #endif #endif /* end __HT_IEC_61850_MACROS_H */