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/
decodePacket.c@1:9399d44c2b1a, 2011-10-07 (annotated)
- Committer:
- sblair
- Date:
- Fri Oct 07 13:48:18 2011 +0000
- Revision:
- 1:9399d44c2b1a
- Parent:
- 0:230c10b228ea
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sblair | 1:9399d44c2b1a | 1 | /** |
sblair | 1:9399d44c2b1a | 2 | * Rapid-prototyping protection schemes with IEC 61850 |
sblair | 1:9399d44c2b1a | 3 | * |
sblair | 1:9399d44c2b1a | 4 | * Copyright (c) 2011 Steven Blair |
sblair | 1:9399d44c2b1a | 5 | * |
sblair | 1:9399d44c2b1a | 6 | * This program is free software; you can redistribute it and/or |
sblair | 1:9399d44c2b1a | 7 | * modify it under the terms of the GNU General Public License |
sblair | 1:9399d44c2b1a | 8 | * as published by the Free Software Foundation; either version 2 |
sblair | 1:9399d44c2b1a | 9 | * of the License, or (at your option) any later version. |
sblair | 1:9399d44c2b1a | 10 | |
sblair | 1:9399d44c2b1a | 11 | * This program is distributed in the hope that it will be useful, |
sblair | 1:9399d44c2b1a | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
sblair | 1:9399d44c2b1a | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
sblair | 1:9399d44c2b1a | 14 | * GNU General Public License for more details. |
sblair | 1:9399d44c2b1a | 15 | |
sblair | 1:9399d44c2b1a | 16 | * You should have received a copy of the GNU General Public License |
sblair | 1:9399d44c2b1a | 17 | * along with this program; if not, write to the Free Software |
sblair | 1:9399d44c2b1a | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
sblair | 1:9399d44c2b1a | 19 | */ |
sblair | 1:9399d44c2b1a | 20 | |
sblair | 0:230c10b228ea | 21 | #include "decodePacket.h" |
sblair | 0:230c10b228ea | 22 | //#include "svEncodeBasic.h" |
sblair | 0:230c10b228ea | 23 | |
sblair | 0:230c10b228ea | 24 | |
sblair | 0:230c10b228ea | 25 | // returns size of length field, from first byte |
sblair | 0:230c10b228ea | 26 | int getLengthFieldSize(unsigned char byte) { |
sblair | 1:9399d44c2b1a | 27 | if (byte <= 126) { |
sblair | 1:9399d44c2b1a | 28 | return 1; |
sblair | 1:9399d44c2b1a | 29 | } |
sblair | 1:9399d44c2b1a | 30 | else { |
sblair | 1:9399d44c2b1a | 31 | return 1 + (byte & 0x7F); |
sblair | 1:9399d44c2b1a | 32 | } |
sblair | 0:230c10b228ea | 33 | } |
sblair | 0:230c10b228ea | 34 | |
sblair | 1:9399d44c2b1a | 35 | //TODO check this works for all inputs, e.g., buf[1] = 0xFF |
sblair | 0:230c10b228ea | 36 | int decodeLength(unsigned char *buf) { |
sblair | 1:9399d44c2b1a | 37 | if (buf[0] <= 126) { |
sblair | 1:9399d44c2b1a | 38 | return buf[0]; |
sblair | 1:9399d44c2b1a | 39 | } |
sblair | 1:9399d44c2b1a | 40 | else { |
sblair | 1:9399d44c2b1a | 41 | int bytes = (buf[0] & 0x7F); |
sblair | 0:230c10b228ea | 42 | |
sblair | 1:9399d44c2b1a | 43 | if (bytes == 1) { |
sblair | 1:9399d44c2b1a | 44 | return buf[1]; |
sblair | 1:9399d44c2b1a | 45 | } |
sblair | 1:9399d44c2b1a | 46 | else if (bytes == 2) { // assumes max length of 2^15 |
sblair | 1:9399d44c2b1a | 47 | return ((buf[1] & 0xFF) << 8) | (buf[2] & 0xFF); |
sblair | 1:9399d44c2b1a | 48 | } |
sblair | 1:9399d44c2b1a | 49 | } |
sblair | 0:230c10b228ea | 50 | |
sblair | 1:9399d44c2b1a | 51 | return 0; |
sblair | 0:230c10b228ea | 52 | } |