Steven Blair / rapid61850example
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers svDecode.c Source File

svDecode.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 "svDecodeBasic.h"
00022 #include "ied.h"
00023 #include "svDecode.h"
00024 
00025 
00026 
00027 int decode_myAnalogValue(unsigned char *buf, struct myAnalogValue *myAnalogValue) {
00028     int offset = 0;
00029 
00030     offset += DECODE_CTYPE_FLOAT32(&buf[offset], &myAnalogValue->f);
00031 
00032     return offset;
00033 }
00034 int decode_ScaledValueConfig(unsigned char *buf, struct ScaledValueConfig *ScaledValueConfig) {
00035     int offset = 0;
00036 
00037     offset += DECODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->scaleFactor);
00038     offset += DECODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->offset);
00039 
00040     return offset;
00041 }
00042 int decode_myVector(unsigned char *buf, struct myVector *myVector) {
00043     int offset = 0;
00044 
00045     offset += decode_myAnalogValue(&buf[offset], &myVector->mag);
00046     offset += decode_myAnalogValue(&buf[offset], &myVector->ang);
00047 
00048     return offset;
00049 }
00050 int decode_simpleVector(unsigned char *buf, struct simpleVector *simpleVector) {
00051     int offset = 0;
00052 
00053     offset += decode_myAnalogValue(&buf[offset], &simpleVector->mag);
00054     offset += decode_myAnalogValue(&buf[offset], &simpleVector->ang);
00055 
00056     return offset;
00057 }
00058 int decode_myMod(unsigned char *buf, struct myMod *myMod) {
00059     int offset = 0;
00060 
00061     offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->ctlVal);
00062     offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->stVal);
00063     offset += DECODE_CTYPE_QUALITY(&buf[offset], &myMod->q);
00064     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myMod->t);
00065 
00066     return offset;
00067 }
00068 int decode_myHealth(unsigned char *buf, struct myHealth *myHealth) {
00069     int offset = 0;
00070 
00071     offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myHealth->stVal);
00072 
00073     return offset;
00074 }
00075 int decode_myBeh(unsigned char *buf, struct myBeh *myBeh) {
00076     int offset = 0;
00077 
00078     offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myBeh->stVal);
00079 
00080     return offset;
00081 }
00082 int decode_myINS(unsigned char *buf, struct myINS *myINS) {
00083     int offset = 0;
00084 
00085     offset += DECODE_CTYPE_INT32(&buf[offset], &myINS->stVal);
00086 
00087     return offset;
00088 }
00089 int decode_myLPL(unsigned char *buf, struct myLPL *myLPL) {
00090     int offset = 0;
00091 
00092     offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->ldNs);
00093     offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->configRev);
00094 
00095     return offset;
00096 }
00097 int decode_myDPL(unsigned char *buf, struct myDPL *myDPL) {
00098     int offset = 0;
00099 
00100     offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->vendor);
00101     offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->hwRev);
00102 
00103     return offset;
00104 }
00105 int decode_myPos(unsigned char *buf, struct myPos *myPos) {
00106     int offset = 0;
00107 
00108     offset += DECODE_CTYPE_DBPOS(&buf[offset], &myPos->stVal);
00109     offset += DECODE_CTYPE_QUALITY(&buf[offset], &myPos->q);
00110     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myPos->t);
00111     offset += DECODE_CTYPE_BOOLEAN(&buf[offset], &myPos->ctlVal);
00112 
00113     return offset;
00114 }
00115 int decode_mySPS(unsigned char *buf, struct mySPS *mySPS) {
00116     int offset = 0;
00117 
00118     offset += DECODE_CTYPE_INT32(&buf[offset], &mySPS->stVal);
00119     offset += DECODE_CTYPE_QUALITY(&buf[offset], &mySPS->q);
00120     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &mySPS->t);
00121 
00122     return offset;
00123 }
00124 int decode_myMV(unsigned char *buf, struct myMV *myMV) {
00125     int offset = 0;
00126 
00127     offset += decode_myAnalogValue(&buf[offset], &myMV->mag);
00128     offset += DECODE_CTYPE_QUALITY(&buf[offset], &myMV->q);
00129     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myMV->t);
00130     offset += decode_ScaledValueConfig(&buf[offset], &myMV->sVC);
00131 
00132     return offset;
00133 }
00134 int decode_simpleMV(unsigned char *buf, struct simpleMV *simpleMV) {
00135     int offset = 0;
00136 
00137     offset += DECODE_CTYPE_FLOAT32(&buf[offset], &simpleMV->mag);
00138     offset += DECODE_CTYPE_QUALITY(&buf[offset], &simpleMV->q);
00139     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &simpleMV->t);
00140     offset += decode_ScaledValueConfig(&buf[offset], &simpleMV->sVC);
00141 
00142     return offset;
00143 }
00144 int decode_simpleCMV(unsigned char *buf, struct simpleCMV *simpleCMV) {
00145     int offset = 0;
00146 
00147     offset += decode_simpleVector(&buf[offset], &simpleCMV->cVal);
00148     offset += DECODE_CTYPE_QUALITY(&buf[offset], &simpleCMV->q);
00149     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &simpleCMV->t);
00150 
00151     return offset;
00152 }
00153 int decode_simpleWYE(unsigned char *buf, struct simpleWYE *simpleWYE) {
00154     int offset = 0;
00155 
00156     offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsA);
00157     offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsB);
00158     offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsC);
00159 
00160     return offset;
00161 }
00162 int decode_myCMV(unsigned char *buf, struct myCMV *myCMV) {
00163     int offset = 0;
00164 
00165     offset += decode_myVector(&buf[offset], &myCMV->cVal);
00166     offset += DECODE_CTYPE_QUALITY(&buf[offset], &myCMV->q);
00167     offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myCMV->t);
00168 
00169     return offset;
00170 }
00171 int decode_mySEQ(unsigned char *buf, struct mySEQ *mySEQ) {
00172     int offset = 0;
00173 
00174     offset += decode_myCMV(&buf[offset], &mySEQ->c1);
00175     offset += decode_myCMV(&buf[offset], &mySEQ->c2);
00176     offset += decode_myCMV(&buf[offset], &mySEQ->c3);
00177     offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &mySEQ->seqT);
00178 
00179     return offset;
00180 }
00181 int decode_mySAV(unsigned char *buf, struct mySAV *mySAV) {
00182     int offset = 0;
00183 
00184     offset += decode_myAnalogValue(&buf[offset], &mySAV->instMag);
00185     offset += DECODE_CTYPE_QUALITY(&buf[offset], &mySAV->q);
00186 
00187     return offset;
00188 }
00189 int decode_simpleSAV(unsigned char *buf, struct simpleSAV *simpleSAV) {
00190     int offset = 0;
00191 
00192     offset += decode_myAnalogValue(&buf[offset], &simpleSAV->instMag);
00193     offset += DECODE_CTYPE_QUALITY(&buf[offset], &simpleSAV->q);
00194 
00195     return offset;
00196 }
00197 int decode_rmxu_MMXU_1(unsigned char *buf, int noASDU) {
00198     int offset = 0;
00199 
00200     offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsA_1[noASDU]);
00201     offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsB_1[noASDU]);
00202     offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsC_1[noASDU]);
00203 
00204     return offset;
00205 }
00206 
00207 void svDecodeDataset(unsigned char *dataset, int datasetLength, int ASDU, unsigned char *svID, int svIDLength) {
00208 
00209     if (strncmp((const char *) svID, "rmxu", svIDLength) == 0) {
00210         decode_rmxu_MMXU_1(dataset, ASDU);
00211     }
00212 }
00213 
00214