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/sv.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 "ied.h" |
sblair | 0:f09b7bb8bcce | 22 | #include "sv.h" |
sblair | 0:f09b7bb8bcce | 23 | #include "svPacketData.h" |
sblair | 0:f09b7bb8bcce | 24 | #include "svDecode.h" |
sblair | 0:f09b7bb8bcce | 25 | #include "svEncode.h" |
sblair | 0:f09b7bb8bcce | 26 | |
sblair | 0:f09b7bb8bcce | 27 | |
sblair | 0:f09b7bb8bcce | 28 | |
sblair | 0:f09b7bb8bcce | 29 | |
sblair | 0:f09b7bb8bcce | 30 | |
sblair | 0:f09b7bb8bcce | 31 | |
sblair | 0:f09b7bb8bcce | 32 | // returns 1 if buf contains valid packet data |
sblair | 0:f09b7bb8bcce | 33 | int sv_update_LE_IED_MUnn_MSVCB01(unsigned char *buf) { |
sblair | 0:f09b7bb8bcce | 34 | int size = encode_control_LE_IED_MUnn_MSVCB01(LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].data.data); |
sblair | 0:f09b7bb8bcce | 35 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].data.size = size; |
sblair | 0:f09b7bb8bcce | 36 | |
sblair | 0:f09b7bb8bcce | 37 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].smpCnt = LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster; |
sblair | 0:f09b7bb8bcce | 38 | LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster++; |
sblair | 0:f09b7bb8bcce | 39 | |
sblair | 0:f09b7bb8bcce | 40 | if (LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster == LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].smpRate) { |
sblair | 0:f09b7bb8bcce | 41 | LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster = 0; |
sblair | 0:f09b7bb8bcce | 42 | } |
sblair | 0:f09b7bb8bcce | 43 | |
sblair | 0:f09b7bb8bcce | 44 | if (++LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount == LE_IED.S1.MUnn.LN0.MSVCB01.noASDU) { |
sblair | 0:f09b7bb8bcce | 45 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount = 0; |
sblair | 0:f09b7bb8bcce | 46 | return svEncodePacket(&LE_IED.S1.MUnn.LN0.MSVCB01, buf); |
sblair | 0:f09b7bb8bcce | 47 | } |
sblair | 0:f09b7bb8bcce | 48 | |
sblair | 0:f09b7bb8bcce | 49 | return 0; |
sblair | 0:f09b7bb8bcce | 50 | } |
sblair | 0:f09b7bb8bcce | 51 | |
sblair | 0:f09b7bb8bcce | 52 | void init_sv() { |
sblair | 0:f09b7bb8bcce | 53 | int i = 0; |
sblair | 0:f09b7bb8bcce | 54 | |
sblair | 0:f09b7bb8bcce | 55 | LE_IED.S1.MUnn.LN0.MSVCB01.noASDU = 1; |
sblair | 0:f09b7bb8bcce | 56 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[0] = 0x01; |
sblair | 0:f09b7bb8bcce | 57 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[1] = 0x0C; |
sblair | 0:f09b7bb8bcce | 58 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[2] = 0xCD; |
sblair | 0:f09b7bb8bcce | 59 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[3] = 0x04; |
sblair | 0:f09b7bb8bcce | 60 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[4] = 0x00; |
sblair | 0:f09b7bb8bcce | 61 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[5] = 0x01; |
sblair | 0:f09b7bb8bcce | 62 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.APPID = 0x4000; |
sblair | 0:f09b7bb8bcce | 63 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.VLAN_ID = 0x123; |
sblair | 0:f09b7bb8bcce | 64 | LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.VLAN_PRIORITY = 0x4; |
sblair | 0:f09b7bb8bcce | 65 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU = (struct ASDU *) malloc(1 * sizeof(struct ASDU)); |
sblair | 0:f09b7bb8bcce | 66 | for (i = 0; i < 1; i++) { |
sblair | 0:f09b7bb8bcce | 67 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].svID = (unsigned char *) malloc(11); |
sblair | 0:f09b7bb8bcce | 68 | strncpy((char *) LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].svID, "0000MU0001\0", 11); |
sblair | 0:f09b7bb8bcce | 69 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].datset = (unsigned char *) malloc(9); |
sblair | 0:f09b7bb8bcce | 70 | strncpy((char *) LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].datset, "PhsMeas1\0", 9); |
sblair | 0:f09b7bb8bcce | 71 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpCnt = 0; |
sblair | 0:f09b7bb8bcce | 72 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].confRev = 1; |
sblair | 0:f09b7bb8bcce | 73 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpSynch = 1; |
sblair | 0:f09b7bb8bcce | 74 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showRefrTm = 0; |
sblair | 0:f09b7bb8bcce | 75 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showDatset = 0; |
sblair | 0:f09b7bb8bcce | 76 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showSmpRate = 0; |
sblair | 0:f09b7bb8bcce | 77 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpRate = 4000; |
sblair | 0:f09b7bb8bcce | 78 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].data.size = 0; |
sblair | 0:f09b7bb8bcce | 79 | } |
sblair | 0:f09b7bb8bcce | 80 | LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount = 0; |
sblair | 0:f09b7bb8bcce | 81 | LE_IED.S1.MUnn.LN0.MSVCB01.update = &sv_update_LE_IED_MUnn_MSVCB01; |
sblair | 0:f09b7bb8bcce | 82 | } |
sblair | 0:f09b7bb8bcce | 83 |