An mbed implementation of IEC 61850-9-2LE Sample Values. Creating using the rapid61850 library, available at: https://github.com/stevenblair/rapid61850.
encodePacket.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 "encodePacket.h" 00022 #include "svEncodeBasic.h" 00023 00024 int getLengthBytes(int len) { 00025 if (len <= 126) { 00026 return 1; 00027 } 00028 else if (len <= 255) { 00029 return 2; 00030 } 00031 else { 00032 return 3; 00033 } 00034 } 00035 00036 int encodeLength(unsigned char *buf, CTYPE_INT16U len) { 00037 if (len <= 126) { 00038 buf[0] = (unsigned char) len; 00039 return 1; 00040 } 00041 else if (len <= 255) { 00042 buf[0] = (unsigned char) 0x81; // 0x80 specifies larger than one byte; 0x02 is number of length bytes to follow 00043 buf[1] = (unsigned char) len; 00044 00045 return 2; 00046 } 00047 else { 00048 // assume length is not greater than 2^15 00049 buf[0] = (unsigned char) 0x82; // 0x80 specifies larger than one byte; 0x02 is number of length bytes to follow 00050 ENCODE_CTYPE_INT16U(&buf[1], &len); 00051 00052 return 3; 00053 } 00054 }
Generated on Sat Jul 23 2022 01:15:10 by 1.7.2