An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers svEncodeBasic.c Source File

svEncodeBasic.c

00001 /**
00002  * Rapid-prototyping protection schemes with IEC 61850
00003  *
00004  * Copyright (c) 2012 Steven Blair
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "ctypes.h"
00022 #include "datatypes.h"
00023 #include "ied.h"
00024 #include "svEncodeBasic.h"
00025 
00026 // SV encoding of basic types
00027 int ENCODE_CTYPE_FLOAT32(unsigned char *buf, CTYPE_FLOAT32 *value) {
00028     netmemcpy(buf, value, SV_GET_LENGTH_FLOAT32);
00029 
00030     return SV_GET_LENGTH_FLOAT32;
00031 }
00032 int ENCODE_CTYPE_FLOAT64(unsigned char *buf, CTYPE_FLOAT64 *value) {
00033     netmemcpy(buf, value, SV_GET_LENGTH_FLOAT64);
00034 
00035     return SV_GET_LENGTH_FLOAT64;
00036 }
00037 int ENCODE_CTYPE_QUALITY(unsigned char *buf, CTYPE_QUALITY *value) {
00038     netmemcpy(&buf[2], value, 2);            // assumes Quality is stored as 16-bit, but SV encoding is 32-bit
00039 
00040     return SV_GET_LENGTH_QUALITY;
00041 }
00042 int ENCODE_CTYPE_TIMESTAMP(unsigned char *buf, CTYPE_TIMESTAMP *value) {
00043     netmemcpy(buf, value, SV_GET_LENGTH_TIMESTAMP);
00044 
00045     return SV_GET_LENGTH_TIMESTAMP;
00046 }
00047 int ENCODE_CTYPE_ENUM(unsigned char *buf, CTYPE_ENUM *value) {    // assuming enum is an int - allows any enum type to be used
00048     netmemcpy(buf, value, SV_GET_LENGTH_ENUM);
00049 
00050     return SV_GET_LENGTH_ENUM;
00051 }
00052 int ENCODE_CTYPE_INT8(unsigned char *buf, CTYPE_INT8 *value) {
00053     netmemcpy(buf, value, SV_GET_LENGTH_INT8);
00054 
00055     return SV_GET_LENGTH_INT8;
00056 }
00057 int ENCODE_CTYPE_INT16(unsigned char *buf, CTYPE_INT16 *value) {
00058     netmemcpy(buf, value, SV_GET_LENGTH_INT16);
00059 
00060     return SV_GET_LENGTH_INT16;
00061 }
00062 int ENCODE_CTYPE_INT32(unsigned char *buf, CTYPE_INT32 *value) {
00063     netmemcpy(buf, value, SV_GET_LENGTH_INT32);
00064 
00065     return SV_GET_LENGTH_INT32;
00066 }
00067 int ENCODE_CTYPE_INT16U(unsigned char *buf, CTYPE_INT16U *value) {
00068     netmemcpy(buf, value, SV_GET_LENGTH_INT16U);
00069 
00070     return SV_GET_LENGTH_INT16U;
00071 }
00072 int ENCODE_CTYPE_INT32U(unsigned char *buf, CTYPE_INT32U *value) {
00073     netmemcpy(buf, value, SV_GET_LENGTH_INT32U);
00074 
00075     return SV_GET_LENGTH_INT32U;
00076 }
00077 int ENCODE_CTYPE_VISSTRING255(unsigned char *buf, CTYPE_VISSTRING255 *value) {
00078     netmemcpy(buf, value, SV_GET_LENGTH_VISSTRING255);
00079 
00080     return SV_GET_LENGTH_VISSTRING255;
00081 }
00082 int ENCODE_CTYPE_BOOLEAN(unsigned char *buf, CTYPE_BOOLEAN *value) {
00083     netmemcpy(buf, value, SV_GET_LENGTH_BOOLEAN);
00084 
00085     return SV_GET_LENGTH_BOOLEAN;
00086 }
00087 int ENCODE_CTYPE_DBPOS(unsigned char *buf, CTYPE_DBPOS *value) {
00088     netmemcpy(buf, value, SV_GET_LENGTH_DBPOS);
00089 
00090     return SV_GET_LENGTH_DBPOS;
00091 }