The goal of this software is to automatically generate C/C++ code which reads and writes GOOSE and Sampled Value packets. Any valid IEC 61850 Substation Configuration Description (SCD) file, describing GOOSE and/or SV communications, can be used as the input. The output code is lightweight and platform-independent, so it can run on a variety of devices, including low-cost microcontrollers. It\'s ideal for rapid-prototyping new protection and control systems that require communications. This mbed project is a simple example of this functionality. Other code: https://github.com/stevenblair/rapid61850 Project homepage: http://personal.strath.ac.uk/steven.m.blair/

Committer:
sblair
Date:
Fri Oct 07 13:41:08 2011 +0000
Revision:
0:230c10b228ea
Child:
1:9399d44c2b1a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sblair 0:230c10b228ea 1 #include "svEncodeBasic.h"
sblair 0:230c10b228ea 2 #include "ied.h"
sblair 0:230c10b228ea 3 #include "svEncode.h"
sblair 0:230c10b228ea 4
sblair 0:230c10b228ea 5
sblair 0:230c10b228ea 6
sblair 0:230c10b228ea 7 int encode_myAnalogValue(unsigned char *buf, struct myAnalogValue *myAnalogValue) {
sblair 0:230c10b228ea 8 int offset = 0;
sblair 0:230c10b228ea 9
sblair 0:230c10b228ea 10 offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &myAnalogValue->f);
sblair 0:230c10b228ea 11
sblair 0:230c10b228ea 12 return offset;
sblair 0:230c10b228ea 13 }
sblair 0:230c10b228ea 14 int encode_ScaledValueConfig(unsigned char *buf, struct ScaledValueConfig *ScaledValueConfig) {
sblair 0:230c10b228ea 15 int offset = 0;
sblair 0:230c10b228ea 16
sblair 0:230c10b228ea 17 offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->scaleFactor);
sblair 0:230c10b228ea 18 offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->offset);
sblair 0:230c10b228ea 19
sblair 0:230c10b228ea 20 return offset;
sblair 0:230c10b228ea 21 }
sblair 0:230c10b228ea 22 int encode_myVector(unsigned char *buf, struct myVector *myVector) {
sblair 0:230c10b228ea 23 int offset = 0;
sblair 0:230c10b228ea 24
sblair 0:230c10b228ea 25 offset += encode_myAnalogValue(&buf[offset], &myVector->mag);
sblair 0:230c10b228ea 26 offset += encode_myAnalogValue(&buf[offset], &myVector->ang);
sblair 0:230c10b228ea 27
sblair 0:230c10b228ea 28 return offset;
sblair 0:230c10b228ea 29 }
sblair 0:230c10b228ea 30 int encode_simpleVector(unsigned char *buf, struct simpleVector *simpleVector) {
sblair 0:230c10b228ea 31 int offset = 0;
sblair 0:230c10b228ea 32
sblair 0:230c10b228ea 33 offset += encode_myAnalogValue(&buf[offset], &simpleVector->mag);
sblair 0:230c10b228ea 34 offset += encode_myAnalogValue(&buf[offset], &simpleVector->ang);
sblair 0:230c10b228ea 35
sblair 0:230c10b228ea 36 return offset;
sblair 0:230c10b228ea 37 }
sblair 0:230c10b228ea 38 int encode_myMod(unsigned char *buf, struct myMod *myMod) {
sblair 0:230c10b228ea 39 int offset = 0;
sblair 0:230c10b228ea 40
sblair 0:230c10b228ea 41 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->ctlVal);
sblair 0:230c10b228ea 42 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->stVal);
sblair 0:230c10b228ea 43 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myMod->q);
sblair 0:230c10b228ea 44 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myMod->t);
sblair 0:230c10b228ea 45
sblair 0:230c10b228ea 46 return offset;
sblair 0:230c10b228ea 47 }
sblair 0:230c10b228ea 48 int encode_myHealth(unsigned char *buf, struct myHealth *myHealth) {
sblair 0:230c10b228ea 49 int offset = 0;
sblair 0:230c10b228ea 50
sblair 0:230c10b228ea 51 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myHealth->stVal);
sblair 0:230c10b228ea 52
sblair 0:230c10b228ea 53 return offset;
sblair 0:230c10b228ea 54 }
sblair 0:230c10b228ea 55 int encode_myBeh(unsigned char *buf, struct myBeh *myBeh) {
sblair 0:230c10b228ea 56 int offset = 0;
sblair 0:230c10b228ea 57
sblair 0:230c10b228ea 58 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myBeh->stVal);
sblair 0:230c10b228ea 59
sblair 0:230c10b228ea 60 return offset;
sblair 0:230c10b228ea 61 }
sblair 0:230c10b228ea 62 int encode_myINS(unsigned char *buf, struct myINS *myINS) {
sblair 0:230c10b228ea 63 int offset = 0;
sblair 0:230c10b228ea 64
sblair 0:230c10b228ea 65 offset += ENCODE_CTYPE_INT32(&buf[offset], &myINS->stVal);
sblair 0:230c10b228ea 66
sblair 0:230c10b228ea 67 return offset;
sblair 0:230c10b228ea 68 }
sblair 0:230c10b228ea 69 int encode_myLPL(unsigned char *buf, struct myLPL *myLPL) {
sblair 0:230c10b228ea 70 int offset = 0;
sblair 0:230c10b228ea 71
sblair 0:230c10b228ea 72 offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->ldNs);
sblair 0:230c10b228ea 73 offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->configRev);
sblair 0:230c10b228ea 74
sblair 0:230c10b228ea 75 return offset;
sblair 0:230c10b228ea 76 }
sblair 0:230c10b228ea 77 int encode_myDPL(unsigned char *buf, struct myDPL *myDPL) {
sblair 0:230c10b228ea 78 int offset = 0;
sblair 0:230c10b228ea 79
sblair 0:230c10b228ea 80 offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->vendor);
sblair 0:230c10b228ea 81 offset += ENCODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->hwRev);
sblair 0:230c10b228ea 82
sblair 0:230c10b228ea 83 return offset;
sblair 0:230c10b228ea 84 }
sblair 0:230c10b228ea 85 int encode_myPos(unsigned char *buf, struct myPos *myPos) {
sblair 0:230c10b228ea 86 int offset = 0;
sblair 0:230c10b228ea 87
sblair 0:230c10b228ea 88 offset += ENCODE_CTYPE_DBPOS(&buf[offset], &myPos->stVal);
sblair 0:230c10b228ea 89 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myPos->q);
sblair 0:230c10b228ea 90 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myPos->t);
sblair 0:230c10b228ea 91 offset += ENCODE_CTYPE_BOOLEAN(&buf[offset], &myPos->ctlVal);
sblair 0:230c10b228ea 92
sblair 0:230c10b228ea 93 return offset;
sblair 0:230c10b228ea 94 }
sblair 0:230c10b228ea 95 int encode_mySPS(unsigned char *buf, struct mySPS *mySPS) {
sblair 0:230c10b228ea 96 int offset = 0;
sblair 0:230c10b228ea 97
sblair 0:230c10b228ea 98 offset += ENCODE_CTYPE_INT32(&buf[offset], &mySPS->stVal);
sblair 0:230c10b228ea 99 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &mySPS->q);
sblair 0:230c10b228ea 100 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &mySPS->t);
sblair 0:230c10b228ea 101
sblair 0:230c10b228ea 102 return offset;
sblair 0:230c10b228ea 103 }
sblair 0:230c10b228ea 104 int encode_myMV(unsigned char *buf, struct myMV *myMV) {
sblair 0:230c10b228ea 105 int offset = 0;
sblair 0:230c10b228ea 106
sblair 0:230c10b228ea 107 offset += encode_myAnalogValue(&buf[offset], &myMV->mag);
sblair 0:230c10b228ea 108 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myMV->q);
sblair 0:230c10b228ea 109 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myMV->t);
sblair 0:230c10b228ea 110 offset += encode_ScaledValueConfig(&buf[offset], &myMV->sVC);
sblair 0:230c10b228ea 111
sblair 0:230c10b228ea 112 return offset;
sblair 0:230c10b228ea 113 }
sblair 0:230c10b228ea 114 int encode_simpleMV(unsigned char *buf, struct simpleMV *simpleMV) {
sblair 0:230c10b228ea 115 int offset = 0;
sblair 0:230c10b228ea 116
sblair 0:230c10b228ea 117 offset += ENCODE_CTYPE_FLOAT32(&buf[offset], &simpleMV->mag);
sblair 0:230c10b228ea 118 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleMV->q);
sblair 0:230c10b228ea 119 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &simpleMV->t);
sblair 0:230c10b228ea 120 offset += encode_ScaledValueConfig(&buf[offset], &simpleMV->sVC);
sblair 0:230c10b228ea 121
sblair 0:230c10b228ea 122 return offset;
sblair 0:230c10b228ea 123 }
sblair 0:230c10b228ea 124 int encode_simpleCMV(unsigned char *buf, struct simpleCMV *simpleCMV) {
sblair 0:230c10b228ea 125 int offset = 0;
sblair 0:230c10b228ea 126
sblair 0:230c10b228ea 127 offset += encode_simpleVector(&buf[offset], &simpleCMV->cVal);
sblair 0:230c10b228ea 128 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleCMV->q);
sblair 0:230c10b228ea 129 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &simpleCMV->t);
sblair 0:230c10b228ea 130
sblair 0:230c10b228ea 131 return offset;
sblair 0:230c10b228ea 132 }
sblair 0:230c10b228ea 133 int encode_simpleWYE(unsigned char *buf, struct simpleWYE *simpleWYE) {
sblair 0:230c10b228ea 134 int offset = 0;
sblair 0:230c10b228ea 135
sblair 0:230c10b228ea 136 offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsA);
sblair 0:230c10b228ea 137 offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsB);
sblair 0:230c10b228ea 138 offset += encode_simpleCMV(&buf[offset], &simpleWYE->phsC);
sblair 0:230c10b228ea 139
sblair 0:230c10b228ea 140 return offset;
sblair 0:230c10b228ea 141 }
sblair 0:230c10b228ea 142 int encode_myCMV(unsigned char *buf, struct myCMV *myCMV) {
sblair 0:230c10b228ea 143 int offset = 0;
sblair 0:230c10b228ea 144
sblair 0:230c10b228ea 145 offset += encode_myVector(&buf[offset], &myCMV->cVal);
sblair 0:230c10b228ea 146 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &myCMV->q);
sblair 0:230c10b228ea 147 offset += ENCODE_CTYPE_TIMESTAMP(&buf[offset], &myCMV->t);
sblair 0:230c10b228ea 148
sblair 0:230c10b228ea 149 return offset;
sblair 0:230c10b228ea 150 }
sblair 0:230c10b228ea 151 int encode_mySEQ(unsigned char *buf, struct mySEQ *mySEQ) {
sblair 0:230c10b228ea 152 int offset = 0;
sblair 0:230c10b228ea 153
sblair 0:230c10b228ea 154 offset += encode_myCMV(&buf[offset], &mySEQ->c1);
sblair 0:230c10b228ea 155 offset += encode_myCMV(&buf[offset], &mySEQ->c2);
sblair 0:230c10b228ea 156 offset += encode_myCMV(&buf[offset], &mySEQ->c3);
sblair 0:230c10b228ea 157 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &mySEQ->seqT);
sblair 0:230c10b228ea 158
sblair 0:230c10b228ea 159 return offset;
sblair 0:230c10b228ea 160 }
sblair 0:230c10b228ea 161 int encode_mySAV(unsigned char *buf, struct mySAV *mySAV) {
sblair 0:230c10b228ea 162 int offset = 0;
sblair 0:230c10b228ea 163
sblair 0:230c10b228ea 164 offset += encode_myAnalogValue(&buf[offset], &mySAV->instMag);
sblair 0:230c10b228ea 165 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &mySAV->q);
sblair 0:230c10b228ea 166
sblair 0:230c10b228ea 167 return offset;
sblair 0:230c10b228ea 168 }
sblair 0:230c10b228ea 169 int encode_simpleSAV(unsigned char *buf, struct simpleSAV *simpleSAV) {
sblair 0:230c10b228ea 170 int offset = 0;
sblair 0:230c10b228ea 171
sblair 0:230c10b228ea 172 offset += encode_myAnalogValue(&buf[offset], &simpleSAV->instMag);
sblair 0:230c10b228ea 173 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &simpleSAV->q);
sblair 0:230c10b228ea 174
sblair 0:230c10b228ea 175 return offset;
sblair 0:230c10b228ea 176 }
sblair 0:230c10b228ea 177 int encode_11(unsigned char *buf) {
sblair 0:230c10b228ea 178 int offset = 0;
sblair 0:230c10b228ea 179
sblair 0:230c10b228ea 180 offset += encode_myAnalogValue(&buf[offset], &E1Q1SB1.S1.C1.TVTR_1.Vol.instMag);
sblair 0:230c10b228ea 181 offset += encode_myMod(&buf[offset], &E1Q1SB1.S1.C1.CSWI_1.Mod);
sblair 0:230c10b228ea 182 offset += ENCODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &E1Q1SB1.S1.C1.MMXU_1.Mod.stVal);
sblair 0:230c10b228ea 183 offset += ENCODE_CTYPE_QUALITY(&buf[offset], &E1Q1SB1.S1.C1.MMXU_1.Volts.q);
sblair 0:230c10b228ea 184 offset += encode_myMV(&buf[offset], &E1Q1SB1.S1.C1.MMXU_1.Amps);
sblair 0:230c10b228ea 185 offset += encode_myPos(&buf[offset], &E1Q1SB1.S1.C1.CSWI_2.Pos);
sblair 0:230c10b228ea 186
sblair 0:230c10b228ea 187 return offset;
sblair 0:230c10b228ea 188 }
sblair 0:230c10b228ea 189 int encode_rmxu(unsigned char *buf) {
sblair 0:230c10b228ea 190 int offset = 0;
sblair 0:230c10b228ea 191
sblair 0:230c10b228ea 192 offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsA);
sblair 0:230c10b228ea 193 offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsB);
sblair 0:230c10b228ea 194 offset += encode_simpleSAV(&buf[offset], &E1Q1SB1.S1.C1.RMXU_1.AmpLocPhsC);
sblair 0:230c10b228ea 195
sblair 0:230c10b228ea 196 return offset;
sblair 0:230c10b228ea 197 }
sblair 0:230c10b228ea 198
sblair 0:230c10b228ea 199