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@0:230c10b228ea, 2011-10-07 (annotated)
- Committer:
- sblair
- Date:
- Fri Oct 07 13:41:08 2011 +0000
- Revision:
- 0:230c10b228ea
- Child:
- 1:9399d44c2b1a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sblair | 0:230c10b228ea | 1 | #include "decodePacket.h" |
sblair | 0:230c10b228ea | 2 | //#include "svEncodeBasic.h" |
sblair | 0:230c10b228ea | 3 | |
sblair | 0:230c10b228ea | 4 | |
sblair | 0:230c10b228ea | 5 | // returns size of length field, from first byte |
sblair | 0:230c10b228ea | 6 | int getLengthFieldSize(unsigned char byte) { |
sblair | 0:230c10b228ea | 7 | if (byte <= 126) { |
sblair | 0:230c10b228ea | 8 | return 1; |
sblair | 0:230c10b228ea | 9 | } |
sblair | 0:230c10b228ea | 10 | else { |
sblair | 0:230c10b228ea | 11 | return 1 + (byte & 0x7F); |
sblair | 0:230c10b228ea | 12 | } |
sblair | 0:230c10b228ea | 13 | } |
sblair | 0:230c10b228ea | 14 | |
sblair | 0:230c10b228ea | 15 | //TODO check this works for all inputs, e.g., buf[1] = 0xFF |
sblair | 0:230c10b228ea | 16 | int decodeLength(unsigned char *buf) { |
sblair | 0:230c10b228ea | 17 | if (buf[0] <= 126) { |
sblair | 0:230c10b228ea | 18 | return buf[0]; |
sblair | 0:230c10b228ea | 19 | } |
sblair | 0:230c10b228ea | 20 | else { |
sblair | 0:230c10b228ea | 21 | int bytes = (buf[0] & 0x7F); |
sblair | 0:230c10b228ea | 22 | |
sblair | 0:230c10b228ea | 23 | if (bytes == 1) { |
sblair | 0:230c10b228ea | 24 | return buf[1]; |
sblair | 0:230c10b228ea | 25 | } |
sblair | 0:230c10b228ea | 26 | else if (bytes == 2) { // assumes max length of 2^15 |
sblair | 0:230c10b228ea | 27 | return ((buf[1] & 0xFF) << 8) | (buf[2] & 0xFF); |
sblair | 0:230c10b228ea | 28 | } |
sblair | 0:230c10b228ea | 29 | } |
sblair | 0:230c10b228ea | 30 | |
sblair | 0:230c10b228ea | 31 | return 0; |
sblair | 0:230c10b228ea | 32 | } |