Steven Blair / rapid61850example
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers svEncode.c Source File

svEncode.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 "svEncodeBasic.h"
00022 #include "ied.h"
00023 #include "svEncode.h"
00024 
00025 
00026 
00027 int encode_myAnalogValue(unsigned char *buf, struct myAnalogValue *myAnalogValue) {
00028     int offset = 0;
00029 
00030     offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &myAnalogValue->f);
00031 
00032     return offset;
00033 }
00034 int encode_ScaledValueConfig(unsigned char *buf, struct ScaledValueConfig *ScaledValueConfig) {
00035     int offset = 0;
00036 
00037     offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->scaleFactor);
00038     offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->offset);
00039 
00040     return offset;
00041 }
00042 int encode_myVector(unsigned char *buf, struct myVector *myVector) {
00043     int offset = 0;
00044 
00045     offset += encode_myAnalogValue(&buf[offset], &myVector->mag);
00046     offset += encode_myAnalogValue(&buf[offset], &myVector->ang);
00047 
00048     return offset;
00049 }
00050 int encode_simpleVector(unsigned char *buf, struct simpleVector *simpleVector) {
00051     int offset = 0;
00052 
00053     offset += encode_myAnalogValue(&buf[offset], &simpleVector->mag);
00054     offset += encode_myAnalogValue(&buf[offset], &simpleVector->ang);
00055 
00056     return offset;
00057 }
00058 int encode_myMod(unsigned char *buf, struct myMod *myMod) {
00059     int offset = 0;
00060 
00061     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->ctlVal);
00062     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->stVal);
00063     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myMod->q);
00064     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myMod->t);
00065 
00066     return offset;
00067 }
00068 int encode_myHealth(unsigned char *buf, struct myHealth *myHealth) {
00069     int offset = 0;
00070 
00071     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myHealth->stVal);
00072 
00073     return offset;
00074 }
00075 int encode_myBeh(unsigned char *buf, struct myBeh *myBeh) {
00076     int offset = 0;
00077 
00078     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myBeh->stVal);
00079 
00080     return offset;
00081 }
00082 int encode_myINS(unsigned char *buf, struct myINS *myINS) {
00083     int offset = 0;
00084 
00085     offset += ENCODE_CTYPE_INT32(&buf[offset], &myINS->stVal);
00086 
00087     return offset;
00088 }
00089 int encode_myLPL(unsigned char *buf, struct myLPL *myLPL) {
00090     int offset = 0;
00091 
00092     offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->ldNs);
00093     offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->configRev);
00094 
00095     return offset;
00096 }
00097 int encode_myDPL(unsigned char *buf, struct myDPL *myDPL) {
00098     int offset = 0;
00099 
00100     offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->vendor);
00101     offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->hwRev);
00102 
00103     return offset;
00104 }
00105 int encode_myPos(unsigned char *buf, struct myPos *myPos) {
00106     int offset = 0;
00107 
00108     offset += ENCODE_CTYPE_DBPOS(&buf[offset], &myPos->stVal);
00109     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myPos->q);
00110     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myPos->t);
00111     offset += ENCODE_CTYPE_BOOLEAN(&buf[offset], &myPos->ctlVal);
00112 
00113     return offset;
00114 }
00115 int encode_mySPS(unsigned char *buf, struct mySPS *mySPS) {
00116     int offset = 0;
00117 
00118     offset += ENCODE_CTYPE_INT32(&buf[offset], &mySPS->stVal);
00119     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &mySPS->q);
00120     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &mySPS->t);
00121 
00122     return offset;
00123 }
00124 int encode_myMV(unsigned char *buf, struct myMV *myMV) {
00125     int offset = 0;
00126 
00127     offset += encode_myAnalogValue(&buf[offset], &myMV->mag);
00128     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myMV->q);
00129     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myMV->t);
00130     offset += encode_ScaledValueConfig(&buf[offset], &myMV->sVC);
00131 
00132     return offset;
00133 }
00134 int encode_simpleMV(unsigned char *buf, struct simpleMV *simpleMV) {
00135     int offset = 0;
00136 
00137     offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &simpleMV->mag);
00138     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleMV->q);
00139     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &simpleMV->t);
00140     offset += encode_ScaledValueConfig(&buf[offset], &simpleMV->sVC);
00141 
00142     return offset;
00143 }
00144 int encode_simpleCMV(unsigned char *buf, struct simpleCMV *simpleCMV) {
00145     int offset = 0;
00146 
00147     offset += encode_simpleVector(&buf[offset], &simpleCMV->cVal);
00148     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleCMV->q);
00149     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &simpleCMV->t);
00150 
00151     return offset;
00152 }
00153 int encode_simpleWYE(unsigned char *buf, struct simpleWYE *simpleWYE) {
00154     int offset = 0;
00155 
00156     offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsA);
00157     offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsB);
00158     offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsC);
00159 
00160     return offset;
00161 }
00162 int encode_myCMV(unsigned char *buf, struct myCMV *myCMV) {
00163     int offset = 0;
00164 
00165     offset += encode_myVector(&buf[offset], &myCMV->cVal);
00166     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myCMV->q);
00167     offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myCMV->t);
00168 
00169     return offset;
00170 }
00171 int encode_mySEQ(unsigned char *buf, struct mySEQ *mySEQ) {
00172     int offset = 0;
00173 
00174     offset += encode_myCMV(&buf[offset], &mySEQ->c1);
00175     offset += encode_myCMV(&buf[offset], &mySEQ->c2);
00176     offset += encode_myCMV(&buf[offset], &mySEQ->c3);
00177     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &mySEQ->seqT);
00178 
00179     return offset;
00180 }
00181 int encode_mySAV(unsigned char *buf, struct mySAV *mySAV) {
00182     int offset = 0;
00183 
00184     offset += encode_myAnalogValue(&buf[offset], &mySAV->instMag);
00185     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &mySAV->q);
00186 
00187     return offset;
00188 }
00189 int encode_simpleSAV(unsigned char *buf, struct simpleSAV *simpleSAV) {
00190     int offset = 0;
00191 
00192     offset += encode_myAnalogValue(&buf[offset], &simpleSAV->instMag);
00193     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleSAV->q);
00194 
00195     return offset;
00196 }
00197 int encode_11(unsigned char *buf) {
00198     int offset = 0;
00199 
00200     offset += encode_myAnalogValue(&buf[offset], &E1Q1SB1.S1.C1.TVTR_1.Vol.instMag);
00201     offset += encode_myMod(&buf[offset], &E1Q1SB1.S1.C1.CSWI_1.Mod);
00202     offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &E1Q1SB1.S1.C1.MMXU_1.Mod.stVal);
00203     offset += ENCODE_CTYPE_QUALITY(&buf[offset], &E1Q1SB1.S1.C1.MMXU_1.Volts.q);
00204     offset += encode_myMV(&buf[offset], &E1Q1SB1.S1.C1.MMXU_1.Amps);
00205     offset += encode_myPos(&buf[offset], &E1Q1SB1.S1.C1.CSWI_2.Pos);
00206 
00207     return offset;
00208 }
00209 int encode_rmxu(unsigned char *buf) {
00210     int offset = 0;
00211 
00212     offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsA);
00213     offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsB);
00214     offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsC);
00215 
00216     return offset;
00217 }
00218 
00219