An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.
An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.
rapid61850/gseDecode.c@0:f09b7bb8bcce, 2012-10-02 (annotated)
- Committer:
- sblair
- Date:
- Tue Oct 02 21:31:05 2012 +0000
- Revision:
- 0:f09b7bb8bcce
converted library to folder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sblair | 0:f09b7bb8bcce | 1 | /** |
sblair | 0:f09b7bb8bcce | 2 | * Rapid-prototyping protection schemes with IEC 61850 |
sblair | 0:f09b7bb8bcce | 3 | * |
sblair | 0:f09b7bb8bcce | 4 | * Copyright (c) 2012 Steven Blair |
sblair | 0:f09b7bb8bcce | 5 | * |
sblair | 0:f09b7bb8bcce | 6 | * This program is free software; you can redistribute it and/or |
sblair | 0:f09b7bb8bcce | 7 | * modify it under the terms of the GNU General Public License |
sblair | 0:f09b7bb8bcce | 8 | * as published by the Free Software Foundation; either version 2 |
sblair | 0:f09b7bb8bcce | 9 | * of the License, or (at your option) any later version. |
sblair | 0:f09b7bb8bcce | 10 | |
sblair | 0:f09b7bb8bcce | 11 | * This program is distributed in the hope that it will be useful, |
sblair | 0:f09b7bb8bcce | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
sblair | 0:f09b7bb8bcce | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
sblair | 0:f09b7bb8bcce | 14 | * GNU General Public License for more details. |
sblair | 0:f09b7bb8bcce | 15 | |
sblair | 0:f09b7bb8bcce | 16 | * You should have received a copy of the GNU General Public License |
sblair | 0:f09b7bb8bcce | 17 | * along with this program; if not, write to the Free Software |
sblair | 0:f09b7bb8bcce | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
sblair | 0:f09b7bb8bcce | 19 | */ |
sblair | 0:f09b7bb8bcce | 20 | |
sblair | 0:f09b7bb8bcce | 21 | #include "gseDecodeBasic.h" |
sblair | 0:f09b7bb8bcce | 22 | #include "gse.h" |
sblair | 0:f09b7bb8bcce | 23 | #include "ied.h" |
sblair | 0:f09b7bb8bcce | 24 | #include "gseDecode.h" |
sblair | 0:f09b7bb8bcce | 25 | |
sblair | 0:f09b7bb8bcce | 26 | |
sblair | 0:f09b7bb8bcce | 27 | |
sblair | 0:f09b7bb8bcce | 28 | |
sblair | 0:f09b7bb8bcce | 29 | int ber_decode_IEC_61850_9_2LEAV(unsigned char *buf, struct IEC_61850_9_2LEAV *IEC_61850_9_2LEAV) { |
sblair | 0:f09b7bb8bcce | 30 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 31 | |
sblair | 0:f09b7bb8bcce | 32 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 33 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 34 | |
sblair | 0:f09b7bb8bcce | 35 | offset += BER_DECODE_CTYPE_INT32(&buf[offset], &IEC_61850_9_2LEAV->i); |
sblair | 0:f09b7bb8bcce | 36 | } |
sblair | 0:f09b7bb8bcce | 37 | |
sblair | 0:f09b7bb8bcce | 38 | return offset; |
sblair | 0:f09b7bb8bcce | 39 | } |
sblair | 0:f09b7bb8bcce | 40 | int ber_decode_IEC_61850_9_2LEsVCAmp(unsigned char *buf, struct IEC_61850_9_2LEsVCAmp *IEC_61850_9_2LEsVCAmp) { |
sblair | 0:f09b7bb8bcce | 41 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 42 | |
sblair | 0:f09b7bb8bcce | 43 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 44 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 45 | |
sblair | 0:f09b7bb8bcce | 46 | offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &IEC_61850_9_2LEsVCAmp->scaleFactor); |
sblair | 0:f09b7bb8bcce | 47 | offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &IEC_61850_9_2LEsVCAmp->offset); |
sblair | 0:f09b7bb8bcce | 48 | } |
sblair | 0:f09b7bb8bcce | 49 | |
sblair | 0:f09b7bb8bcce | 50 | return offset; |
sblair | 0:f09b7bb8bcce | 51 | } |
sblair | 0:f09b7bb8bcce | 52 | int ber_decode_IEC_61850_9_2LEsVCVol(unsigned char *buf, struct IEC_61850_9_2LEsVCVol *IEC_61850_9_2LEsVCVol) { |
sblair | 0:f09b7bb8bcce | 53 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 54 | |
sblair | 0:f09b7bb8bcce | 55 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 56 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 57 | |
sblair | 0:f09b7bb8bcce | 58 | offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &IEC_61850_9_2LEsVCVol->scaleFactor); |
sblair | 0:f09b7bb8bcce | 59 | offset += BER_DECODE_CTYPE_FLOAT32(&buf[offset], &IEC_61850_9_2LEsVCVol->offset); |
sblair | 0:f09b7bb8bcce | 60 | } |
sblair | 0:f09b7bb8bcce | 61 | |
sblair | 0:f09b7bb8bcce | 62 | return offset; |
sblair | 0:f09b7bb8bcce | 63 | } |
sblair | 0:f09b7bb8bcce | 64 | int ber_decode_IEC_61850_9_2LESAVAmp(unsigned char *buf, struct IEC_61850_9_2LESAVAmp *IEC_61850_9_2LESAVAmp) { |
sblair | 0:f09b7bb8bcce | 65 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 66 | |
sblair | 0:f09b7bb8bcce | 67 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 68 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 69 | |
sblair | 0:f09b7bb8bcce | 70 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &IEC_61850_9_2LESAVAmp->instMag); |
sblair | 0:f09b7bb8bcce | 71 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &IEC_61850_9_2LESAVAmp->q); |
sblair | 0:f09b7bb8bcce | 72 | offset += ber_decode_IEC_61850_9_2LEsVCAmp(&buf[offset], &IEC_61850_9_2LESAVAmp->sVC); |
sblair | 0:f09b7bb8bcce | 73 | } |
sblair | 0:f09b7bb8bcce | 74 | |
sblair | 0:f09b7bb8bcce | 75 | return offset; |
sblair | 0:f09b7bb8bcce | 76 | } |
sblair | 0:f09b7bb8bcce | 77 | int ber_decode_IEC_61850_9_2LESAVVol(unsigned char *buf, struct IEC_61850_9_2LESAVVol *IEC_61850_9_2LESAVVol) { |
sblair | 0:f09b7bb8bcce | 78 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 79 | |
sblair | 0:f09b7bb8bcce | 80 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 81 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 82 | |
sblair | 0:f09b7bb8bcce | 83 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &IEC_61850_9_2LESAVVol->instMag); |
sblair | 0:f09b7bb8bcce | 84 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &IEC_61850_9_2LESAVVol->q); |
sblair | 0:f09b7bb8bcce | 85 | offset += ber_decode_IEC_61850_9_2LEsVCVol(&buf[offset], &IEC_61850_9_2LESAVVol->sVC); |
sblair | 0:f09b7bb8bcce | 86 | } |
sblair | 0:f09b7bb8bcce | 87 | |
sblair | 0:f09b7bb8bcce | 88 | return offset; |
sblair | 0:f09b7bb8bcce | 89 | } |
sblair | 0:f09b7bb8bcce | 90 | int ber_decode_IEC_61850_9_2LEINC(unsigned char *buf, struct IEC_61850_9_2LEINC *IEC_61850_9_2LEINC) { |
sblair | 0:f09b7bb8bcce | 91 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 92 | |
sblair | 0:f09b7bb8bcce | 93 | if (buf[offset++] == 0xA2) { |
sblair | 0:f09b7bb8bcce | 94 | offset += getLengthFieldSize(buf[offset]); |
sblair | 0:f09b7bb8bcce | 95 | |
sblair | 0:f09b7bb8bcce | 96 | offset += BER_DECODE_CTYPE_INT32(&buf[offset], &IEC_61850_9_2LEINC->ctlVal); |
sblair | 0:f09b7bb8bcce | 97 | offset += BER_DECODE_CTYPE_INT32(&buf[offset], &IEC_61850_9_2LEINC->stVal); |
sblair | 0:f09b7bb8bcce | 98 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &IEC_61850_9_2LEINC->q); |
sblair | 0:f09b7bb8bcce | 99 | offset += BER_DECODE_CTYPE_TIMESTAMP(&buf[offset], &IEC_61850_9_2LEINC->t); |
sblair | 0:f09b7bb8bcce | 100 | } |
sblair | 0:f09b7bb8bcce | 101 | |
sblair | 0:f09b7bb8bcce | 102 | return offset; |
sblair | 0:f09b7bb8bcce | 103 | } |
sblair | 0:f09b7bb8bcce | 104 | int ber_decode_LE_IED_MUnn_PhsMeas1(unsigned char *buf, struct LE_IED_MUnn_PhsMeas1 *LE_IED_MUnn_PhsMeas1) { |
sblair | 0:f09b7bb8bcce | 105 | int offset = 0; |
sblair | 0:f09b7bb8bcce | 106 | |
sblair | 0:f09b7bb8bcce | 107 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_1_Amp_instMag); |
sblair | 0:f09b7bb8bcce | 108 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_1_Amp_q); |
sblair | 0:f09b7bb8bcce | 109 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_2_Amp_instMag); |
sblair | 0:f09b7bb8bcce | 110 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_2_Amp_q); |
sblair | 0:f09b7bb8bcce | 111 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_3_Amp_instMag); |
sblair | 0:f09b7bb8bcce | 112 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_3_Amp_q); |
sblair | 0:f09b7bb8bcce | 113 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_4_Amp_instMag); |
sblair | 0:f09b7bb8bcce | 114 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TCTR_4_Amp_q); |
sblair | 0:f09b7bb8bcce | 115 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_1_Vol_instMag); |
sblair | 0:f09b7bb8bcce | 116 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_1_Vol_q); |
sblair | 0:f09b7bb8bcce | 117 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_2_Vol_instMag); |
sblair | 0:f09b7bb8bcce | 118 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_2_Vol_q); |
sblair | 0:f09b7bb8bcce | 119 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_3_Vol_instMag); |
sblair | 0:f09b7bb8bcce | 120 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_3_Vol_q); |
sblair | 0:f09b7bb8bcce | 121 | offset += ber_decode_IEC_61850_9_2LEAV(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_4_Vol_instMag); |
sblair | 0:f09b7bb8bcce | 122 | offset += BER_DECODE_CTYPE_QUALITY(&buf[offset], &LE_IED_MUnn_PhsMeas1->MUnn_TVTR_4_Vol_q); |
sblair | 0:f09b7bb8bcce | 123 | |
sblair | 0:f09b7bb8bcce | 124 | return offset; |
sblair | 0:f09b7bb8bcce | 125 | } |
sblair | 0:f09b7bb8bcce | 126 | |
sblair | 0:f09b7bb8bcce | 127 | void gseDecodeDataset(unsigned char *dataset, CTYPE_INT16U datasetLength, unsigned char *gocbRef, CTYPE_INT16U gocbRefLength, CTYPE_INT32U timeAllowedToLive, CTYPE_TIMESTAMP T, CTYPE_INT32U stNum, CTYPE_INT32U sqNum) { |
sblair | 0:f09b7bb8bcce | 128 | |
sblair | 0:f09b7bb8bcce | 129 | } |
sblair | 0:f09b7bb8bcce | 130 | |
sblair | 0:f09b7bb8bcce | 131 |