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

Dependencies:   mbed

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

Committer:
sblair
Date:
Tue Oct 02 21:31:05 2012 +0000
Revision:
0:f09b7bb8bcce
converted library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sblair 0:f09b7bb8bcce 1 /**
sblair 0:f09b7bb8bcce 2 * Rapid-prototyping protection schemes with IEC 61850
sblair 0:f09b7bb8bcce 3 *
sblair 0:f09b7bb8bcce 4 * Copyright (c) 2012 Steven Blair
sblair 0:f09b7bb8bcce 5 *
sblair 0:f09b7bb8bcce 6 * This program is free software; you can redistribute it and/or
sblair 0:f09b7bb8bcce 7 * modify it under the terms of the GNU General Public License
sblair 0:f09b7bb8bcce 8 * as published by the Free Software Foundation; either version 2
sblair 0:f09b7bb8bcce 9 * of the License, or (at your option) any later version.
sblair 0:f09b7bb8bcce 10
sblair 0:f09b7bb8bcce 11 * This program is distributed in the hope that it will be useful,
sblair 0:f09b7bb8bcce 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sblair 0:f09b7bb8bcce 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
sblair 0:f09b7bb8bcce 14 * GNU General Public License for more details.
sblair 0:f09b7bb8bcce 15
sblair 0:f09b7bb8bcce 16 * You should have received a copy of the GNU General Public License
sblair 0:f09b7bb8bcce 17 * along with this program; if not, write to the Free Software
sblair 0:f09b7bb8bcce 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
sblair 0:f09b7bb8bcce 19 */
sblair 0:f09b7bb8bcce 20
sblair 0:f09b7bb8bcce 21 #include "ctypes.h"
sblair 0:f09b7bb8bcce 22 #include "datatypes.h"
sblair 0:f09b7bb8bcce 23 #include "ied.h"
sblair 0:f09b7bb8bcce 24 #include "svEncodeBasic.h"
sblair 0:f09b7bb8bcce 25
sblair 0:f09b7bb8bcce 26 // SV encoding of basic types
sblair 0:f09b7bb8bcce 27 int ENCODE_CTYPE_FLOAT32(unsigned char *buf, CTYPE_FLOAT32 *value) {
sblair 0:f09b7bb8bcce 28 netmemcpy(buf, value, SV_GET_LENGTH_FLOAT32);
sblair 0:f09b7bb8bcce 29
sblair 0:f09b7bb8bcce 30 return SV_GET_LENGTH_FLOAT32;
sblair 0:f09b7bb8bcce 31 }
sblair 0:f09b7bb8bcce 32 int ENCODE_CTYPE_FLOAT64(unsigned char *buf, CTYPE_FLOAT64 *value) {
sblair 0:f09b7bb8bcce 33 netmemcpy(buf, value, SV_GET_LENGTH_FLOAT64);
sblair 0:f09b7bb8bcce 34
sblair 0:f09b7bb8bcce 35 return SV_GET_LENGTH_FLOAT64;
sblair 0:f09b7bb8bcce 36 }
sblair 0:f09b7bb8bcce 37 int ENCODE_CTYPE_QUALITY(unsigned char *buf, CTYPE_QUALITY *value) {
sblair 0:f09b7bb8bcce 38 netmemcpy(&buf[2], value, 2); // assumes Quality is stored as 16-bit, but SV encoding is 32-bit
sblair 0:f09b7bb8bcce 39
sblair 0:f09b7bb8bcce 40 return SV_GET_LENGTH_QUALITY;
sblair 0:f09b7bb8bcce 41 }
sblair 0:f09b7bb8bcce 42 int ENCODE_CTYPE_TIMESTAMP(unsigned char *buf, CTYPE_TIMESTAMP *value) {
sblair 0:f09b7bb8bcce 43 netmemcpy(buf, value, SV_GET_LENGTH_TIMESTAMP);
sblair 0:f09b7bb8bcce 44
sblair 0:f09b7bb8bcce 45 return SV_GET_LENGTH_TIMESTAMP;
sblair 0:f09b7bb8bcce 46 }
sblair 0:f09b7bb8bcce 47 int ENCODE_CTYPE_ENUM(unsigned char *buf, CTYPE_ENUM *value) { // assuming enum is an int - allows any enum type to be used
sblair 0:f09b7bb8bcce 48 netmemcpy(buf, value, SV_GET_LENGTH_ENUM);
sblair 0:f09b7bb8bcce 49
sblair 0:f09b7bb8bcce 50 return SV_GET_LENGTH_ENUM;
sblair 0:f09b7bb8bcce 51 }
sblair 0:f09b7bb8bcce 52 int ENCODE_CTYPE_INT8(unsigned char *buf, CTYPE_INT8 *value) {
sblair 0:f09b7bb8bcce 53 netmemcpy(buf, value, SV_GET_LENGTH_INT8);
sblair 0:f09b7bb8bcce 54
sblair 0:f09b7bb8bcce 55 return SV_GET_LENGTH_INT8;
sblair 0:f09b7bb8bcce 56 }
sblair 0:f09b7bb8bcce 57 int ENCODE_CTYPE_INT16(unsigned char *buf, CTYPE_INT16 *value) {
sblair 0:f09b7bb8bcce 58 netmemcpy(buf, value, SV_GET_LENGTH_INT16);
sblair 0:f09b7bb8bcce 59
sblair 0:f09b7bb8bcce 60 return SV_GET_LENGTH_INT16;
sblair 0:f09b7bb8bcce 61 }
sblair 0:f09b7bb8bcce 62 int ENCODE_CTYPE_INT32(unsigned char *buf, CTYPE_INT32 *value) {
sblair 0:f09b7bb8bcce 63 netmemcpy(buf, value, SV_GET_LENGTH_INT32);
sblair 0:f09b7bb8bcce 64
sblair 0:f09b7bb8bcce 65 return SV_GET_LENGTH_INT32;
sblair 0:f09b7bb8bcce 66 }
sblair 0:f09b7bb8bcce 67 int ENCODE_CTYPE_INT16U(unsigned char *buf, CTYPE_INT16U *value) {
sblair 0:f09b7bb8bcce 68 netmemcpy(buf, value, SV_GET_LENGTH_INT16U);
sblair 0:f09b7bb8bcce 69
sblair 0:f09b7bb8bcce 70 return SV_GET_LENGTH_INT16U;
sblair 0:f09b7bb8bcce 71 }
sblair 0:f09b7bb8bcce 72 int ENCODE_CTYPE_INT32U(unsigned char *buf, CTYPE_INT32U *value) {
sblair 0:f09b7bb8bcce 73 netmemcpy(buf, value, SV_GET_LENGTH_INT32U);
sblair 0:f09b7bb8bcce 74
sblair 0:f09b7bb8bcce 75 return SV_GET_LENGTH_INT32U;
sblair 0:f09b7bb8bcce 76 }
sblair 0:f09b7bb8bcce 77 int ENCODE_CTYPE_VISSTRING255(unsigned char *buf, CTYPE_VISSTRING255 *value) {
sblair 0:f09b7bb8bcce 78 netmemcpy(buf, value, SV_GET_LENGTH_VISSTRING255);
sblair 0:f09b7bb8bcce 79
sblair 0:f09b7bb8bcce 80 return SV_GET_LENGTH_VISSTRING255;
sblair 0:f09b7bb8bcce 81 }
sblair 0:f09b7bb8bcce 82 int ENCODE_CTYPE_BOOLEAN(unsigned char *buf, CTYPE_BOOLEAN *value) {
sblair 0:f09b7bb8bcce 83 netmemcpy(buf, value, SV_GET_LENGTH_BOOLEAN);
sblair 0:f09b7bb8bcce 84
sblair 0:f09b7bb8bcce 85 return SV_GET_LENGTH_BOOLEAN;
sblair 0:f09b7bb8bcce 86 }
sblair 0:f09b7bb8bcce 87 int ENCODE_CTYPE_DBPOS(unsigned char *buf, CTYPE_DBPOS *value) {
sblair 0:f09b7bb8bcce 88 netmemcpy(buf, value, SV_GET_LENGTH_DBPOS);
sblair 0:f09b7bb8bcce 89
sblair 0:f09b7bb8bcce 90 return SV_GET_LENGTH_DBPOS;
sblair 0:f09b7bb8bcce 91 }