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/
svDecode.c@0:230c10b228ea, 2011-10-07 (annotated)
- Committer:
- sblair
- Date:
- Fri Oct 07 13:41:08 2011 +0000
- Revision:
- 0:230c10b228ea
- Child:
- 1:9399d44c2b1a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sblair | 0:230c10b228ea | 1 | #include "svDecodeBasic.h" |
sblair | 0:230c10b228ea | 2 | #include "ied.h" |
sblair | 0:230c10b228ea | 3 | #include "svDecode.h" |
sblair | 0:230c10b228ea | 4 | |
sblair | 0:230c10b228ea | 5 | |
sblair | 0:230c10b228ea | 6 | |
sblair | 0:230c10b228ea | 7 | int decode_myAnalogValue(unsigned char *buf, struct myAnalogValue *myAnalogValue) { |
sblair | 0:230c10b228ea | 8 | int offset = 0; |
sblair | 0:230c10b228ea | 9 | |
sblair | 0:230c10b228ea | 10 | offset += DECODE_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 decode_ScaledValueConfig(unsigned char *buf, struct ScaledValueConfig *ScaledValueConfig) { |
sblair | 0:230c10b228ea | 15 | int offset = 0; |
sblair | 0:230c10b228ea | 16 | |
sblair | 0:230c10b228ea | 17 | offset += DECODE_CTYPE_FLOAT32(&buf[offset], &ScaledValueConfig->scaleFactor); |
sblair | 0:230c10b228ea | 18 | offset += DECODE_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 decode_myVector(unsigned char *buf, struct myVector *myVector) { |
sblair | 0:230c10b228ea | 23 | int offset = 0; |
sblair | 0:230c10b228ea | 24 | |
sblair | 0:230c10b228ea | 25 | offset += decode_myAnalogValue(&buf[offset], &myVector->mag); |
sblair | 0:230c10b228ea | 26 | offset += decode_myAnalogValue(&buf[offset], &myVector->ang); |
sblair | 0:230c10b228ea | 27 | |
sblair | 0:230c10b228ea | 28 | return offset; |
sblair | 0:230c10b228ea | 29 | } |
sblair | 0:230c10b228ea | 30 | int decode_simpleVector(unsigned char *buf, struct simpleVector *simpleVector) { |
sblair | 0:230c10b228ea | 31 | int offset = 0; |
sblair | 0:230c10b228ea | 32 | |
sblair | 0:230c10b228ea | 33 | offset += decode_myAnalogValue(&buf[offset], &simpleVector->mag); |
sblair | 0:230c10b228ea | 34 | offset += decode_myAnalogValue(&buf[offset], &simpleVector->ang); |
sblair | 0:230c10b228ea | 35 | |
sblair | 0:230c10b228ea | 36 | return offset; |
sblair | 0:230c10b228ea | 37 | } |
sblair | 0:230c10b228ea | 38 | int decode_myMod(unsigned char *buf, struct myMod *myMod) { |
sblair | 0:230c10b228ea | 39 | int offset = 0; |
sblair | 0:230c10b228ea | 40 | |
sblair | 0:230c10b228ea | 41 | offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->ctlVal); |
sblair | 0:230c10b228ea | 42 | offset += DECODE_CTYPE_ENUM(&buf[offset], (CTYPE_ENUM *) &myMod->stVal); |
sblair | 0:230c10b228ea | 43 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &myMod->q); |
sblair | 0:230c10b228ea | 44 | offset += DECODE_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 decode_myHealth(unsigned char *buf, struct myHealth *myHealth) { |
sblair | 0:230c10b228ea | 49 | int offset = 0; |
sblair | 0:230c10b228ea | 50 | |
sblair | 0:230c10b228ea | 51 | offset += DECODE_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 decode_myBeh(unsigned char *buf, struct myBeh *myBeh) { |
sblair | 0:230c10b228ea | 56 | int offset = 0; |
sblair | 0:230c10b228ea | 57 | |
sblair | 0:230c10b228ea | 58 | offset += DECODE_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 decode_myINS(unsigned char *buf, struct myINS *myINS) { |
sblair | 0:230c10b228ea | 63 | int offset = 0; |
sblair | 0:230c10b228ea | 64 | |
sblair | 0:230c10b228ea | 65 | offset += DECODE_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 decode_myLPL(unsigned char *buf, struct myLPL *myLPL) { |
sblair | 0:230c10b228ea | 70 | int offset = 0; |
sblair | 0:230c10b228ea | 71 | |
sblair | 0:230c10b228ea | 72 | offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myLPL->ldNs); |
sblair | 0:230c10b228ea | 73 | offset += DECODE_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 decode_myDPL(unsigned char *buf, struct myDPL *myDPL) { |
sblair | 0:230c10b228ea | 78 | int offset = 0; |
sblair | 0:230c10b228ea | 79 | |
sblair | 0:230c10b228ea | 80 | offset += DECODE_CTYPE_VISSTRING255(&buf[offset], &myDPL->vendor); |
sblair | 0:230c10b228ea | 81 | offset += DECODE_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 decode_myPos(unsigned char *buf, struct myPos *myPos) { |
sblair | 0:230c10b228ea | 86 | int offset = 0; |
sblair | 0:230c10b228ea | 87 | |
sblair | 0:230c10b228ea | 88 | offset += DECODE_CTYPE_DBPOS(&buf[offset], &myPos->stVal); |
sblair | 0:230c10b228ea | 89 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &myPos->q); |
sblair | 0:230c10b228ea | 90 | offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myPos->t); |
sblair | 0:230c10b228ea | 91 | offset += DECODE_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 decode_mySPS(unsigned char *buf, struct mySPS *mySPS) { |
sblair | 0:230c10b228ea | 96 | int offset = 0; |
sblair | 0:230c10b228ea | 97 | |
sblair | 0:230c10b228ea | 98 | offset += DECODE_CTYPE_INT32(&buf[offset], &mySPS->stVal); |
sblair | 0:230c10b228ea | 99 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &mySPS->q); |
sblair | 0:230c10b228ea | 100 | offset += DECODE_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 decode_myMV(unsigned char *buf, struct myMV *myMV) { |
sblair | 0:230c10b228ea | 105 | int offset = 0; |
sblair | 0:230c10b228ea | 106 | |
sblair | 0:230c10b228ea | 107 | offset += decode_myAnalogValue(&buf[offset], &myMV->mag); |
sblair | 0:230c10b228ea | 108 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &myMV->q); |
sblair | 0:230c10b228ea | 109 | offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &myMV->t); |
sblair | 0:230c10b228ea | 110 | offset += decode_ScaledValueConfig(&buf[offset], &myMV->sVC); |
sblair | 0:230c10b228ea | 111 | |
sblair | 0:230c10b228ea | 112 | return offset; |
sblair | 0:230c10b228ea | 113 | } |
sblair | 0:230c10b228ea | 114 | int decode_simpleMV(unsigned char *buf, struct simpleMV *simpleMV) { |
sblair | 0:230c10b228ea | 115 | int offset = 0; |
sblair | 0:230c10b228ea | 116 | |
sblair | 0:230c10b228ea | 117 | offset += DECODE_CTYPE_FLOAT32(&buf[offset], &simpleMV->mag); |
sblair | 0:230c10b228ea | 118 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &simpleMV->q); |
sblair | 0:230c10b228ea | 119 | offset += DECODE_CTYPE_TIMESTAMP(&buf[offset], &simpleMV->t); |
sblair | 0:230c10b228ea | 120 | offset += decode_ScaledValueConfig(&buf[offset], &simpleMV->sVC); |
sblair | 0:230c10b228ea | 121 | |
sblair | 0:230c10b228ea | 122 | return offset; |
sblair | 0:230c10b228ea | 123 | } |
sblair | 0:230c10b228ea | 124 | int decode_simpleCMV(unsigned char *buf, struct simpleCMV *simpleCMV) { |
sblair | 0:230c10b228ea | 125 | int offset = 0; |
sblair | 0:230c10b228ea | 126 | |
sblair | 0:230c10b228ea | 127 | offset += decode_simpleVector(&buf[offset], &simpleCMV->cVal); |
sblair | 0:230c10b228ea | 128 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &simpleCMV->q); |
sblair | 0:230c10b228ea | 129 | offset += DECODE_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 decode_simpleWYE(unsigned char *buf, struct simpleWYE *simpleWYE) { |
sblair | 0:230c10b228ea | 134 | int offset = 0; |
sblair | 0:230c10b228ea | 135 | |
sblair | 0:230c10b228ea | 136 | offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsA); |
sblair | 0:230c10b228ea | 137 | offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsB); |
sblair | 0:230c10b228ea | 138 | offset += decode_simpleCMV(&buf[offset], &simpleWYE->phsC); |
sblair | 0:230c10b228ea | 139 | |
sblair | 0:230c10b228ea | 140 | return offset; |
sblair | 0:230c10b228ea | 141 | } |
sblair | 0:230c10b228ea | 142 | int decode_myCMV(unsigned char *buf, struct myCMV *myCMV) { |
sblair | 0:230c10b228ea | 143 | int offset = 0; |
sblair | 0:230c10b228ea | 144 | |
sblair | 0:230c10b228ea | 145 | offset += decode_myVector(&buf[offset], &myCMV->cVal); |
sblair | 0:230c10b228ea | 146 | offset += DECODE_CTYPE_QUALITY(&buf[offset], &myCMV->q); |
sblair | 0:230c10b228ea | 147 | offset += DECODE_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 decode_mySEQ(unsigned char *buf, struct mySEQ *mySEQ) { |
sblair | 0:230c10b228ea | 152 | int offset = 0; |
sblair | 0:230c10b228ea | 153 | |
sblair | 0:230c10b228ea | 154 | offset += decode_myCMV(&buf[offset], &mySEQ->c1); |
sblair | 0:230c10b228ea | 155 | offset += decode_myCMV(&buf[offset], &mySEQ->c2); |
sblair | 0:230c10b228ea | 156 | offset += decode_myCMV(&buf[offset], &mySEQ->c3); |
sblair | 0:230c10b228ea | 157 | offset += DECODE_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 decode_mySAV(unsigned char *buf, struct mySAV *mySAV) { |
sblair | 0:230c10b228ea | 162 | int offset = 0; |
sblair | 0:230c10b228ea | 163 | |
sblair | 0:230c10b228ea | 164 | offset += decode_myAnalogValue(&buf[offset], &mySAV->instMag); |
sblair | 0:230c10b228ea | 165 | offset += DECODE_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 decode_simpleSAV(unsigned char *buf, struct simpleSAV *simpleSAV) { |
sblair | 0:230c10b228ea | 170 | int offset = 0; |
sblair | 0:230c10b228ea | 171 | |
sblair | 0:230c10b228ea | 172 | offset += decode_myAnalogValue(&buf[offset], &simpleSAV->instMag); |
sblair | 0:230c10b228ea | 173 | offset += DECODE_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 decode_rmxu_MMXU_1(unsigned char *buf, int noASDU) { |
sblair | 0:230c10b228ea | 178 | int offset = 0; |
sblair | 0:230c10b228ea | 179 | |
sblair | 0:230c10b228ea | 180 | offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsA_1[noASDU]); |
sblair | 0:230c10b228ea | 181 | offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsB_1[noASDU]); |
sblair | 0:230c10b228ea | 182 | offset += decode_simpleSAV(&buf[offset], &D1Q1SB4.S1.C1.MMXU_1.sv_inputs.AmpLocPhsC_1[noASDU]); |
sblair | 0:230c10b228ea | 183 | |
sblair | 0:230c10b228ea | 184 | return offset; |
sblair | 0:230c10b228ea | 185 | } |
sblair | 0:230c10b228ea | 186 | |
sblair | 0:230c10b228ea | 187 | void svDecodeDataset(unsigned char *dataset, int datasetLength, int ASDU, unsigned char *svID, int svIDLength) { |
sblair | 0:230c10b228ea | 188 | |
sblair | 0:230c10b228ea | 189 | if (strncmp((const char *) svID, "rmxu", svIDLength) == 0) { |
sblair | 0:230c10b228ea | 190 | decode_rmxu_MMXU_1(dataset, ASDU); |
sblair | 0:230c10b228ea | 191 | } |
sblair | 0:230c10b228ea | 192 | } |
sblair | 0:230c10b228ea | 193 | |
sblair | 0:230c10b228ea | 194 |