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/

Revision:
0:230c10b228ea
Child:
1:9399d44c2b1a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decodePacket.c	Fri Oct 07 13:41:08 2011 +0000
@@ -0,0 +1,32 @@
+#include "decodePacket.h"
+//#include "svEncodeBasic.h"
+
+
+// returns size of length field, from first byte
+int getLengthFieldSize(unsigned char byte) {
+	if (byte <= 126) {
+		return 1;
+	}
+	else {
+		return 1 + (byte & 0x7F);
+	}
+}
+
+//TODO	check this works for all inputs, e.g., buf[1] = 0xFF
+int decodeLength(unsigned char *buf) {
+	if (buf[0] <= 126) {
+		return buf[0];
+	}
+	else {
+		int bytes = (buf[0] & 0x7F);
+
+		if (bytes == 1) {
+			return buf[1];
+		}
+		else if (bytes == 2) {	// assumes max length of 2^15
+			return ((buf[1] & 0xFF) << 8) | (buf[2] & 0xFF);
+		}
+	}
+
+	return 0;
+}