An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.
sv.c
00001 /** 00002 * Rapid-prototyping protection schemes with IEC 61850 00003 * 00004 * Copyright (c) 2012 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 "ied.h" 00022 #include "sv.h" 00023 #include "svPacketData.h" 00024 #include "svDecode.h" 00025 #include "svEncode.h" 00026 00027 00028 00029 00030 00031 00032 // returns 1 if buf contains valid packet data 00033 int sv_update_LE_IED_MUnn_MSVCB01(unsigned char *buf) { 00034 int size = encode_control_LE_IED_MUnn_MSVCB01(LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].data.data); 00035 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].data.size = size; 00036 00037 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].smpCnt = LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster; 00038 LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster++; 00039 00040 if (LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster == LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount].smpRate) { 00041 LE_IED.S1.MUnn.LN0.MSVCB01.sampleCountMaster = 0; 00042 } 00043 00044 if (++LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount == LE_IED.S1.MUnn.LN0.MSVCB01.noASDU) { 00045 LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount = 0; 00046 return svEncodePacket(&LE_IED.S1.MUnn.LN0.MSVCB01, buf); 00047 } 00048 00049 return 0; 00050 } 00051 00052 void init_sv() { 00053 int i = 0; 00054 00055 LE_IED.S1.MUnn.LN0.MSVCB01.noASDU = 1; 00056 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[0] = 0x01; 00057 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[1] = 0x0C; 00058 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[2] = 0xCD; 00059 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[3] = 0x04; 00060 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[4] = 0x00; 00061 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.destMACAddress[5] = 0x01; 00062 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.APPID = 0x4000; 00063 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.VLAN_ID = 0x123; 00064 LE_IED.S1.MUnn.LN0.MSVCB01.ethHeaderData.VLAN_PRIORITY = 0x4; 00065 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU = (struct ASDU *) malloc(1 * sizeof(struct ASDU)); 00066 for (i = 0; i < 1; i++) { 00067 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].svID = (unsigned char *) malloc(11); 00068 strncpy((char *) LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].svID, "0000MU0001\0", 11); 00069 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].datset = (unsigned char *) malloc(9); 00070 strncpy((char *) LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].datset, "PhsMeas1\0", 9); 00071 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpCnt = 0; 00072 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].confRev = 1; 00073 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpSynch = 1; 00074 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showRefrTm = 0; 00075 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showDatset = 0; 00076 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].showSmpRate = 0; 00077 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].smpRate = 4000; 00078 LE_IED.S1.MUnn.LN0.MSVCB01.ASDU[i].data.size = 0; 00079 } 00080 LE_IED.S1.MUnn.LN0.MSVCB01.ASDUCount = 0; 00081 LE_IED.S1.MUnn.LN0.MSVCB01.update = &sv_update_LE_IED_MUnn_MSVCB01; 00082 } 00083
Generated on Sat Jul 23 2022 01:15:10 by 1.7.2