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/

gseDecodePacket.c

Committer:
sblair
Date:
2011-10-07
Revision:
0:230c10b228ea
Child:
1:9399d44c2b1a

File content as of revision 0:230c10b228ea:

#include "gseDecodeBasic.h"
#include "ied.h"
#include "gseDecode.h"
#include "gsePacketData.h"
#include "decodePacket.h"
#include <stddef.h>



//temp
//#include <stdio.h>
//#include <stdlib.h>



unsigned char    datasetName[65] = {0};        // maximum length of 65 bytes
CTYPE_INT16U    datasetNameLength = 0;


void gseDecodePDU(unsigned char *buf) {
    unsigned char    tag = (unsigned char) buf[0];    // assumes only one byte is used
    CTYPE_INT16U    lengthFieldSize = getLengthFieldSize((unsigned char) buf[1]);
    CTYPE_INT16U    lengthValue = decodeLength((unsigned char *) &buf[1]);
    CTYPE_INT16U    offsetForSequence = 1 + lengthFieldSize;
    CTYPE_INT16U    offsetForNonSequence = 1 + lengthFieldSize + lengthValue;

    //printf("tag: %x, lengthFieldSize: %i, lengthValue: %i, offset: %i\n", tag, lengthFieldSize, lengthValue, offsetForNonSequence);

    switch (tag) {
    case 0x61:
        gseDecodePDU(&buf[offsetForSequence]);
        break;
    case 0x82:
        // save dataset name
        memcpy(datasetName, &buf[offsetForSequence], lengthValue);
        datasetNameLength = lengthValue;
        //printf("%s, %d\n", datasetName, datasetNameLength);
        //fflush(stdout);

        gseDecodePDU(&buf[offsetForNonSequence]);
        break;
    case 0xAB:
        gseDecodeDataset(&buf[offsetForSequence], lengthValue, datasetName, datasetNameLength);
        return;
        //break;
    default:
        gseDecodePDU(&buf[offsetForNonSequence]);
        break;
    }
}

void gseDecode(unsigned char *buf, int len) {
    gseDecodePDU(&buf[26]);    // cuts out frame header (fixed size of 26 bytes before start of APDU)
}