An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.
ctypes.h
00001 /** 00002 * Rapid-prototyping protection schemes with IEC 61850 00003 * 00004 * Copyright (c) 2012 Steven Blair 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef CTYPES_H 00022 #define CTYPES_H 00023 00024 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ 00025 extern "C" { 00026 #endif 00027 00028 #include <string.h> 00029 00030 #ifndef LITTLE_ENDIAN 00031 #define LITTLE_ENDIAN 1 00032 #endif 00033 #define TIMESTAMP_SUPPORTED 0 00034 #define GOOSE_FIXED_SIZE 0 // set to 1 to enable fixed-sized GOOSE encoding, which is slightly more efficient to encode. 00035 #define HIGH_LEVEL_INTERFACE 0 // 00036 00037 #define LOCAL_MAC_ADDRESS_VALUE {0x01, 0x0C, 0xCD, 0x01, 0x00, 0x02} 00038 00039 // platform-specific data types to conform to SV type sizes (Table 14 in IEC 61850-9-2) 00040 #define CTYPE_BOOLEAN unsigned char 00041 #define CTYPE_INT8 char 00042 #define CTYPE_INT16 short 00043 #define CTYPE_INT32 int 00044 #define CTYPE_INT8U unsigned char 00045 #define CTYPE_INT16U unsigned short 00046 #define CTYPE_INT32U unsigned int 00047 #if GOOSE_FIXED_SIZE == 1 00048 #define CTYPE_ENUM CTYPE_INT8 00049 #else 00050 #define CTYPE_ENUM CTYPE_INT32 00051 #endif 00052 #define CTYPE_FLOAT32 float 00053 #define CTYPE_FLOAT64 double 00054 #define CTYPE_VISSTRING255 char * 00055 #define CTYPE_DBPOS int 00056 #define CTYPE_QUALITY CTYPE_INT16U 00057 #define CTYPE_TIMESTAMP long long 00058 00059 // sampled value dataset type sizes, in bytes 00060 #define SV_GET_LENGTH_FLOAT32 4 00061 #define SV_GET_LENGTH_FLOAT64 8 00062 #define SV_GET_LENGTH_TIMESTAMP 8 00063 #define SV_GET_LENGTH_INT8 1 00064 #define SV_GET_LENGTH_INT16 2 00065 #define SV_GET_LENGTH_INT32 4 00066 #define SV_GET_LENGTH_INT8U 1 00067 #define SV_GET_LENGTH_INT16U 2 00068 #define SV_GET_LENGTH_INT32U 4 00069 #define SV_GET_LENGTH_VISSTRING255 35 00070 #define SV_GET_LENGTH_BOOLEAN 1 00071 #define SV_GET_LENGTH_ENUM 4 00072 #define SV_GET_LENGTH_QUALITY 4 00073 #define SV_GET_LENGTH_DBPOS 4 00074 00075 #if GOOSE_FIXED_SIZE == 1 00076 #define BER_GET_LENGTH_CTYPE_FLOAT32(x) (SV_GET_LENGTH_FLOAT32 + 1) 00077 #define BER_GET_LENGTH_CTYPE_FLOAT64(x) (SV_GET_LENGTH_FLOAT64 + 1) // fixed-size FLOAT64 not actually specified in -8-1 00078 #define BER_GET_LENGTH_CTYPE_TIMESTAMP(x) (SV_GET_LENGTH_TIMESTAMP) 00079 #define BER_GET_LENGTH_CTYPE_INT8(x) (2) // 8-bit datatypes are encoded in 16 bits! 00080 #define BER_GET_LENGTH_CTYPE_INT16(x) (3) 00081 #define BER_GET_LENGTH_CTYPE_INT32(x) (5) 00082 #define BER_GET_LENGTH_CTYPE_INT16U(x) (3) 00083 #define BER_GET_LENGTH_CTYPE_INT32U(x) (5) 00084 #define BER_GET_LENGTH_CTYPE_VISSTRING255(x) (SV_GET_LENGTH_VISSTRING255) 00085 #define BER_GET_LENGTH_CTYPE_BOOLEAN(x) (SV_GET_LENGTH_BOOLEAN) 00086 #define BER_GET_LENGTH_CTYPE_ENUM(x) (2) 00087 #define BER_GET_LENGTH_CTYPE_QUALITY(x) (3) 00088 #define BER_GET_LENGTH_CTYPE_DBPOS(x) (SV_GET_LENGTH_DBPOS) 00089 #else 00090 // BER datatype sizes, which are dependent on the actual data 00091 #define BER_GET_LENGTH_CTYPE_FLOAT32(x) (SV_GET_LENGTH_FLOAT32 + 1) // + 1 byte for number of exponent bits 00092 #define BER_GET_LENGTH_CTYPE_FLOAT64(x) (SV_GET_LENGTH_FLOAT64 + 1) // + 1 byte for number of exponent bits 00093 #define BER_GET_LENGTH_CTYPE_TIMESTAMP(x) (SV_GET_LENGTH_TIMESTAMP) 00094 #define BER_GET_LENGTH_CTYPE_INT8(x) (ber_integer_length((x), SV_GET_LENGTH_INT8)) 00095 #define BER_GET_LENGTH_CTYPE_INT16(x) (ber_integer_length((x), SV_GET_LENGTH_INT16)) 00096 #define BER_GET_LENGTH_CTYPE_INT32(x) (ber_integer_length((x), SV_GET_LENGTH_INT32)) 00097 #define BER_GET_LENGTH_CTYPE_INT16U(x) (ber_integer_length((x), SV_GET_LENGTH_INT16U)) 00098 #define BER_GET_LENGTH_CTYPE_INT32U(x) (ber_integer_length((x), SV_GET_LENGTH_INT32U)) 00099 #define BER_GET_LENGTH_CTYPE_VISSTRING255(x) (SV_GET_LENGTH_VISSTRING255) 00100 #define BER_GET_LENGTH_CTYPE_BOOLEAN(x) (SV_GET_LENGTH_BOOLEAN) 00101 #define BER_GET_LENGTH_CTYPE_ENUM(x) (ber_integer_length((x), SV_GET_LENGTH_ENUM)) 00102 #define BER_GET_LENGTH_CTYPE_QUALITY(x) (2 + 1) // + 1 byte for padding 00103 #define BER_GET_LENGTH_CTYPE_DBPOS(x) (SV_GET_LENGTH_DBPOS) 00104 #endif 00105 00106 #define ASN1_TAG_SEQUENCE 0x61 00107 #define ASN1_TAG_ARRAY 0x81 00108 #define ASN1_TAG_STRUCTURE 0x82 00109 #define ASN1_TAG_BOOLEAN 0x83 00110 #define ASN1_TAG_BIT_STRING 0x84 00111 #define ASN1_TAG_INTEGER 0x85 00112 #define ASN1_TAG_UNSIGNED 0x86 00113 #define ASN1_TAG_FLOATING_POINT 0x87 00114 #define ASN1_TAG_REAL 0x88 00115 #define ASN1_TAG_OCTET_STRING 0x89 00116 #define ASN1_TAG_VISIBLE_STRING 0x8A 00117 00118 #define GSE_TAG_GOCBREF 0x80 00119 #define GSE_TAG_TIME_ALLOWED_TO_LIVE 0x81 00120 #define GSE_TAG_DATSET 0x82 00121 #define GSE_TAG_GOID 0x83 00122 #define GSE_TAG_T 0x84 00123 #define GSE_TAG_STNUM 0x85 00124 #define GSE_TAG_SQNUM 0x86 00125 #define GSE_TAG_SIMULATION 0x87 00126 #define GSE_TAG_CONFREV 0x88 00127 #define GSE_TAG_NDSCOM 0x89 00128 #define GSE_TAG_NUMDATSETENTRIES 0x8A 00129 #define GSE_TAG_ALLDATA 0xAB 00130 00131 #define SV_TAG_SAVPDU 0x60 00132 #define SV_TAG_NOASDU 0x80 00133 #define SV_TAG_SECURITY 0x81 00134 #define SV_TAG_SEQUENCEOFASDU 0xA2 00135 #define SV_TAG_ASDU 0x30 00136 #define SV_TAG_SVID 0x80 00137 #define SV_TAG_DATSET 0x81 00138 #define SV_TAG_SMPCNT 0x82 00139 #define SV_TAG_CONFREV 0x83 00140 #define SV_TAG_REFRTM 0x84 00141 #define SV_TAG_SMPSYNCH 0x85 00142 #define SV_TAG_SMPRATE 0x86 00143 #define SV_TAG_SEQUENCEOFDATA 0x87 00144 00145 #define QUALITY_UNUSED_BITS 3 // total_bits (16) - used_bits (13) = 3 00146 00147 int ber_integer_length(void *value, int maxLength); 00148 int ber_encode_integer(unsigned char *bufDst, void *value, int maxLength); 00149 int ber_encode_integer_fixed_size(unsigned char *bufDst, void *value, int maxLength); 00150 void ber_decode_integer(unsigned char *buf, int length, void *value, int maxLength); 00151 00152 void reversememcpy(unsigned char *dst, const unsigned char *src, unsigned int len); 00153 void netmemcpy(void *dst, const void *src, unsigned int len); 00154 void hostmemcpy(void *dst, const void *src, unsigned int len); 00155 00156 void setTimestamp(CTYPE_TIMESTAMP *t); 00157 void gse_sv_packet_filter(unsigned char *buf, int len); 00158 00159 struct UtcTime { 00160 unsigned char bytes[8]; // format: ssssssssssssssssssssssssssssssssffffffffffffffffffffffffqqqqqqqq 00161 }; 00162 00163 extern unsigned char LOCAL_MAC_ADDRESS[]; 00164 00165 struct ethHeaderData { 00166 unsigned char destMACAddress[6]; // stored in big-endian format 00167 CTYPE_INT16U APPID; 00168 CTYPE_INT16U VLAN_ID; 00169 CTYPE_INT16U VLAN_PRIORITY; 00170 }; 00171 00172 #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ 00173 } 00174 #endif 00175 00176 #endif 00177
Generated on Sat Jul 23 2022 01:15:10 by 1.7.2