Steven Blair / rapid61850example
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sv.c Source File

sv.c

00001 /**
00002  * Rapid-prototyping protection schemes with IEC 61850
00003  *
00004  * Copyright (c) 2011 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 "sv.h"
00022 #include "svPacketData.h"
00023 #include "svDecode.h"
00024 #include "svEncode.h"
00025 
00026 struct svData Volt_11;
00027 struct svData rmxuCB_rmxu;
00028 
00029 
00030 
00031 
00032 // returns 1 if buf contains valid packet data
00033 int sv_update_Volt_11(unsigned char *buf) {
00034     int size = encode_11(Volt_11.ASDU[Volt_11.ASDUCount].data.data);
00035     Volt_11.ASDU[Volt_11.ASDUCount].data.size = size;
00036 
00037     Volt_11.ASDU[Volt_11.ASDUCount].smpCnt = Volt_11.sampleCountMaster;
00038     Volt_11.sampleCountMaster++;
00039 
00040     if (++Volt_11.ASDUCount == Volt_11.noASDU) {
00041         Volt_11.ASDUCount = 0;
00042         return svEncodePacket(&Volt_11, buf);
00043     }
00044 
00045     return 0;
00046 }
00047 
00048 // returns 1 if buf contains valid packet data
00049 int sv_update_rmxuCB_rmxu(unsigned char *buf) {
00050     int size = encode_rmxu(rmxuCB_rmxu.ASDU[rmxuCB_rmxu.ASDUCount].data.data);
00051     rmxuCB_rmxu.ASDU[rmxuCB_rmxu.ASDUCount].data.size = size;
00052 
00053     rmxuCB_rmxu.ASDU[rmxuCB_rmxu.ASDUCount].smpCnt = rmxuCB_rmxu.sampleCountMaster;
00054     rmxuCB_rmxu.sampleCountMaster++;
00055 
00056     if (++rmxuCB_rmxu.ASDUCount == rmxuCB_rmxu.noASDU) {
00057         rmxuCB_rmxu.ASDUCount = 0;
00058         return svEncodePacket(&rmxuCB_rmxu, buf);
00059     }
00060 
00061     return 0;
00062 }
00063 
00064 void init_sv() {
00065     int i = 0;
00066 
00067     Volt_11.noASDU = 2;
00068     Volt_11.ethHeaderData.destMACAddress[0] = 0x01;
00069     Volt_11.ethHeaderData.destMACAddress[1] = 0x0C;
00070     Volt_11.ethHeaderData.destMACAddress[2] = 0xCD;
00071     Volt_11.ethHeaderData.destMACAddress[3] = 0x04;
00072     Volt_11.ethHeaderData.destMACAddress[4] = 0x00;
00073     Volt_11.ethHeaderData.destMACAddress[5] = 0x01;
00074     Volt_11.ethHeaderData.APPID = 0x4000;
00075     Volt_11.ethHeaderData.VLAN_ID = 0x123;
00076     Volt_11.ethHeaderData.VLAN_PRIORITY = 0x4;
00077     Volt_11.ASDU = (struct ASDU *) malloc(2 * sizeof(struct ASDU));
00078     for (i = 0; i < 2; i++) {
00079         Volt_11.ASDU[i].svID = (unsigned char *) malloc(3);
00080         strncpy((char *) Volt_11.ASDU[i].svID, "11\0", 3);
00081         Volt_11.ASDU[i].datset = (unsigned char *) malloc(4);
00082         strncpy((char *) Volt_11.ASDU[i].datset, "smv\0", 4);
00083         Volt_11.ASDU[i].smpCnt = 0;
00084         Volt_11.ASDU[i].confRev = 1;
00085         Volt_11.ASDU[i].smpSynch = 1;
00086         Volt_11.ASDU[i].smpRate = 4800;
00087         Volt_11.ASDU[i].data.size = 0;
00088     }
00089     Volt_11.ASDUCount = 0;
00090 
00091     rmxuCB_rmxu.noASDU = 16;
00092     rmxuCB_rmxu.ethHeaderData.destMACAddress[0] = 0x01;
00093     rmxuCB_rmxu.ethHeaderData.destMACAddress[1] = 0x0C;
00094     rmxuCB_rmxu.ethHeaderData.destMACAddress[2] = 0xCD;
00095     rmxuCB_rmxu.ethHeaderData.destMACAddress[3] = 0x04;
00096     rmxuCB_rmxu.ethHeaderData.destMACAddress[4] = 0x00;
00097     rmxuCB_rmxu.ethHeaderData.destMACAddress[5] = 0x01;
00098     rmxuCB_rmxu.ethHeaderData.APPID = 0x4000;
00099     rmxuCB_rmxu.ethHeaderData.VLAN_ID = 0x123;
00100     rmxuCB_rmxu.ethHeaderData.VLAN_PRIORITY = 0x4;
00101     rmxuCB_rmxu.ASDU = (struct ASDU *) malloc(16 * sizeof(struct ASDU));
00102     for (i = 0; i < 16; i++) {
00103         rmxuCB_rmxu.ASDU[i].svID = (unsigned char *) malloc(5);
00104         strncpy((char *) rmxuCB_rmxu.ASDU[i].svID, "rmxu\0", 5);
00105         rmxuCB_rmxu.ASDU[i].datset = (unsigned char *) malloc(5);
00106         strncpy((char *) rmxuCB_rmxu.ASDU[i].datset, "rmxu\0", 5);
00107         rmxuCB_rmxu.ASDU[i].smpCnt = 0;
00108         rmxuCB_rmxu.ASDU[i].confRev = 1;
00109         rmxuCB_rmxu.ASDU[i].smpSynch = 1;
00110         rmxuCB_rmxu.ASDU[i].smpRate = 16;
00111         rmxuCB_rmxu.ASDU[i].data.size = 0;
00112     }
00113     rmxuCB_rmxu.ASDUCount = 0;
00114 }
00115