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/

Committer:
sblair
Date:
Fri Oct 07 13:41:08 2011 +0000
Revision:
0:230c10b228ea
Child:
1:9399d44c2b1a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sblair 0:230c10b228ea 1 #include "encodePacket.h"
sblair 0:230c10b228ea 2 #include "svEncodeBasic.h"
sblair 0:230c10b228ea 3
sblair 0:230c10b228ea 4 int getLengthBytes(int len) {
sblair 0:230c10b228ea 5 if (len <= 126) {
sblair 0:230c10b228ea 6 return 1;
sblair 0:230c10b228ea 7 }
sblair 0:230c10b228ea 8 else if (len <= 255) {
sblair 0:230c10b228ea 9 return 2;
sblair 0:230c10b228ea 10 }
sblair 0:230c10b228ea 11 else {
sblair 0:230c10b228ea 12 return 3;
sblair 0:230c10b228ea 13 }
sblair 0:230c10b228ea 14 }
sblair 0:230c10b228ea 15
sblair 0:230c10b228ea 16 int encodeLength(unsigned char *buf, CTYPE_INT16U len) {
sblair 0:230c10b228ea 17 if (len <= 126) {
sblair 0:230c10b228ea 18 buf[0] = (unsigned char) len;
sblair 0:230c10b228ea 19 return 1;
sblair 0:230c10b228ea 20 }
sblair 0:230c10b228ea 21 else if (len <= 255) {
sblair 0:230c10b228ea 22 buf[0] = (unsigned char) 0x81; // 0x80 specifies larger than one byte; 0x02 is number of length bytes to follow
sblair 0:230c10b228ea 23 buf[1] = (unsigned char) len;
sblair 0:230c10b228ea 24
sblair 0:230c10b228ea 25 return 2;
sblair 0:230c10b228ea 26 }
sblair 0:230c10b228ea 27 else {
sblair 0:230c10b228ea 28 // assume length is not greater than 2^15
sblair 0:230c10b228ea 29 buf[0] = (unsigned char) 0x82; // 0x80 specifies larger than one byte; 0x02 is number of length bytes to follow
sblair 0:230c10b228ea 30 ENCODE_CTYPE_INT16U(&buf[1], &len);
sblair 0:230c10b228ea 31
sblair 0:230c10b228ea 32 return 3;
sblair 0:230c10b228ea 33 }
sblair 0:230c10b228ea 34 }