Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
gseDecode.c
00001 /** 00002 * Rapid-prototyping protection schemes with IEC 61850 00003 * 00004 * Copyright (c) 2011 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 #include "gseDecodeBasic.h" 00022 #include "ied.h" 00023 #include "gseDecode.h" 00024 00025 00026 00027 int ber_decode_myAnalogValue(unsigned char *buf, struct myAnalogValue *myAnalogValue) { 00028 int offset = 0; 00029 00030 if (buf[offset++] == 0xA2) { 00031 offset += getLengthFieldSize(buf[offset]); 00032 00033 offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &myAnalogValue->f); 00034 } 00035 00036 return offset; 00037 } 00038 int ber_decode_ScaledValueConfig(unsigned char *buf, struct ScaledValueConfig *ScaledValueConfig) { 00039 int offset = 0; 00040 00041 if (buf[offset++] == 0xA2) { 00042 offset += getLengthFieldSize(buf[offset]); 00043 00044 offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->scaleFactor); 00045 offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->offset); 00046 } 00047 00048 return offset; 00049 } 00050 int ber_decode_myVector(unsigned char *buf, struct myVector *myVector) { 00051 int offset = 0; 00052 00053 if (buf[offset++] == 0xA2) { 00054 offset += getLengthFieldSize(buf[offset]); 00055 00056 offset += ber_decode_myAnalogValue(&buf[offset], &myVector->mag); 00057 offset += ber_decode_myAnalogValue(&buf[offset], &myVector->ang); 00058 } 00059 00060 return offset; 00061 } 00062 int ber_decode_simpleVector(unsigned char *buf, struct simpleVector *simpleVector) { 00063 int offset = 0; 00064 00065 if (buf[offset++] == 0xA2) { 00066 offset += getLengthFieldSize(buf[offset]); 00067 00068 offset += ber_decode_myAnalogValue(&buf[offset], &simpleVector->mag); 00069 offset += ber_decode_myAnalogValue(&buf[offset], &simpleVector->ang); 00070 } 00071 00072 return offset; 00073 } 00074 int ber_decode_myMod(unsigned char *buf, struct myMod *myMod) { 00075 int offset = 0; 00076 00077 if (buf[offset++] == 0xA2) { 00078 offset += getLengthFieldSize(buf[offset]); 00079 00080 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->ctlVal); 00081 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->stVal); 00082 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &myMod->q); 00083 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &myMod->t); 00084 } 00085 00086 return offset; 00087 } 00088 int ber_decode_myHealth(unsigned char *buf, struct myHealth *myHealth) { 00089 int offset = 0; 00090 00091 if (buf[offset++] == 0xA2) { 00092 offset += getLengthFieldSize(buf[offset]); 00093 00094 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myHealth->stVal); 00095 } 00096 00097 return offset; 00098 } 00099 int ber_decode_myBeh(unsigned char *buf, struct myBeh *myBeh) { 00100 int offset = 0; 00101 00102 if (buf[offset++] == 0xA2) { 00103 offset += getLengthFieldSize(buf[offset]); 00104 00105 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myBeh->stVal); 00106 } 00107 00108 return offset; 00109 } 00110 int ber_decode_myINS(unsigned char *buf, struct myINS *myINS) { 00111 int offset = 0; 00112 00113 if (buf[offset++] == 0xA2) { 00114 offset += getLengthFieldSize(buf[offset]); 00115 00116 offset += BER_DECODE_CTYPE_INT32(&buf[offset], &myINS->stVal); 00117 } 00118 00119 return offset; 00120 } 00121 int ber_decode_myLPL(unsigned char *buf, struct myLPL *myLPL) { 00122 int offset = 0; 00123 00124 if (buf[offset++] == 0xA2) { 00125 offset += getLengthFieldSize(buf[offset]); 00126 00127 offset += BER_DECODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->ldNs); 00128 offset += BER_DECODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->configRev); 00129 } 00130 00131 return offset; 00132 } 00133 int ber_decode_myDPL(unsigned char *buf, struct myDPL *myDPL) { 00134 int offset = 0; 00135 00136 if (buf[offset++] == 0xA2) { 00137 offset += getLengthFieldSize(buf[offset]); 00138 00139 offset += BER_DECODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->vendor); 00140 offset += BER_DECODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->hwRev); 00141 } 00142 00143 return offset; 00144 } 00145 int ber_decode_myPos(unsigned char *buf, struct myPos *myPos) { 00146 int offset = 0; 00147 00148 if (buf[offset++] == 0xA2) { 00149 offset += getLengthFieldSize(buf[offset]); 00150 00151 offset += BER_DECODE_CTYPE_DBPOS(&buf[offset], &myPos->stVal); 00152 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &myPos->q); 00153 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &myPos->t); 00154 offset += BER_DECODE_CTYPE_BOOLEAN(&buf[offset], &myPos->ctlVal); 00155 } 00156 00157 return offset; 00158 } 00159 int ber_decode_mySPS(unsigned char *buf, struct mySPS *mySPS) { 00160 int offset = 0; 00161 00162 if (buf[offset++] == 0xA2) { 00163 offset += getLengthFieldSize(buf[offset]); 00164 00165 offset += BER_DECODE_CTYPE_INT32(&buf[offset], &mySPS->stVal); 00166 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &mySPS->q); 00167 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &mySPS->t); 00168 } 00169 00170 return offset; 00171 } 00172 int ber_decode_myMV(unsigned char *buf, struct myMV *myMV) { 00173 int offset = 0; 00174 00175 if (buf[offset++] == 0xA2) { 00176 offset += getLengthFieldSize(buf[offset]); 00177 00178 offset += ber_decode_myAnalogValue(&buf[offset], &myMV->mag); 00179 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &myMV->q); 00180 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &myMV->t); 00181 offset += ber_decode_ScaledValueConfig(&buf[offset], &myMV->sVC); 00182 } 00183 00184 return offset; 00185 } 00186 int ber_decode_simpleMV(unsigned char *buf, struct simpleMV *simpleMV) { 00187 int offset = 0; 00188 00189 if (buf[offset++] == 0xA2) { 00190 offset += getLengthFieldSize(buf[offset]); 00191 00192 offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &simpleMV->mag); 00193 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &simpleMV->q); 00194 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &simpleMV->t); 00195 offset += ber_decode_ScaledValueConfig(&buf[offset], &simpleMV->sVC); 00196 } 00197 00198 return offset; 00199 } 00200 int ber_decode_simpleCMV(unsigned char *buf, struct simpleCMV *simpleCMV) { 00201 int offset = 0; 00202 00203 if (buf[offset++] == 0xA2) { 00204 offset += getLengthFieldSize(buf[offset]); 00205 00206 offset += ber_decode_simpleVector(&buf[offset], &simpleCMV->cVal); 00207 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &simpleCMV->q); 00208 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &simpleCMV->t); 00209 } 00210 00211 return offset; 00212 } 00213 int ber_decode_simpleWYE(unsigned char *buf, struct simpleWYE *simpleWYE) { 00214 int offset = 0; 00215 00216 if (buf[offset++] == 0xA2) { 00217 offset += getLengthFieldSize(buf[offset]); 00218 00219 offset += ber_decode_simpleCMV(&buf[offset], &simpleWYE->phsA); 00220 offset += ber_decode_simpleCMV(&buf[offset], &simpleWYE->phsB); 00221 offset += ber_decode_simpleCMV(&buf[offset], &simpleWYE->phsC); 00222 } 00223 00224 return offset; 00225 } 00226 int ber_decode_myCMV(unsigned char *buf, struct myCMV *myCMV) { 00227 int offset = 0; 00228 00229 if (buf[offset++] == 0xA2) { 00230 offset += getLengthFieldSize(buf[offset]); 00231 00232 offset += ber_decode_myVector(&buf[offset], &myCMV->cVal); 00233 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &myCMV->q); 00234 offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &myCMV->t); 00235 } 00236 00237 return offset; 00238 } 00239 int ber_decode_mySEQ(unsigned char *buf, struct mySEQ *mySEQ) { 00240 int offset = 0; 00241 00242 if (buf[offset++] == 0xA2) { 00243 offset += getLengthFieldSize(buf[offset]); 00244 00245 offset += ber_decode_myCMV(&buf[offset], &mySEQ->c1); 00246 offset += ber_decode_myCMV(&buf[offset], &mySEQ->c2); 00247 offset += ber_decode_myCMV(&buf[offset], &mySEQ->c3); 00248 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &mySEQ->seqT); 00249 } 00250 00251 return offset; 00252 } 00253 int ber_decode_mySAV(unsigned char *buf, struct mySAV *mySAV) { 00254 int offset = 0; 00255 00256 if (buf[offset++] == 0xA2) { 00257 offset += getLengthFieldSize(buf[offset]); 00258 00259 offset += ber_decode_myAnalogValue(&buf[offset], &mySAV->instMag); 00260 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &mySAV->q); 00261 } 00262 00263 return offset; 00264 } 00265 int ber_decode_simpleSAV(unsigned char *buf, struct simpleSAV *simpleSAV) { 00266 int offset = 0; 00267 00268 if (buf[offset++] == 0xA2) { 00269 offset += getLengthFieldSize(buf[offset]); 00270 00271 offset += ber_decode_myAnalogValue(&buf[offset], &simpleSAV->instMag); 00272 offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &simpleSAV->q); 00273 } 00274 00275 return offset; 00276 } 00277 int ber_decode_Positions_RSYN_1(unsigned char *buf) { 00278 int offset = 0; 00279 00280 offset += ber_decode_myAnalogValue(&buf[offset], &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.instMag_1); 00281 offset += ber_decode_myPos(&buf[offset], &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.Pos_1); 00282 offset += ber_decode_myPos(&buf[offset], &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.Pos_2); 00283 offset += BER_DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.stVal_1); 00284 offset += ber_decode_myMV(&buf[offset], &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.Amps_1); 00285 offset += ber_decode_myMV(&buf[offset], &D1Q1SB4.S1.C1.RSYN_1.gse_inputs.Volts_1); 00286 00287 return offset; 00288 } 00289 00290 void gseDecodeDataset(unsigned char *dataset, int datasetLength, unsigned char *datSet, int datSetLength) { 00291 00292 if (strncmp((const char *) datSet, "E1Q1SB1C1/LLN0$Positions", datSetLength) == 0) { 00293 ber_decode_Positions_RSYN_1(dataset); 00294 } 00295 } 00296 00297
Generated on Mon Jul 18 2022 18:17:52 by
1.7.2