mirror of
https://github.com/Martin-P/OpenV2G.git
synced 2024-11-08 12:45:42 +00:00
Merge SourceForge SVN repository, OpenV2G 0.9.5
This commit is contained in:
commit
671f422a73
2 changed files with 390 additions and 248 deletions
|
@ -1,12 +1,12 @@
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
OpenV2G - an open source project implementing the basic functionality of the ISO IEC 15118 vehicle to grid (V2G) communication interface
|
OpenV2G - an open source project implementing the basic functionality of the ISO IEC 15118 vehicle to grid (V2G) communication interface
|
||||||
Version 0.9.4, released January 30, 2018
|
Version 0.9.5, released March 11, 2022
|
||||||
http://openv2g.sourceforge.net/
|
http://openv2g.sourceforge.net/
|
||||||
|
|
||||||
Please report bugs via the SourceForge bug tracking system at http://sourceforge.net/tracker/?group_id=350113.
|
Please report bugs via the SourceForge bug tracking system at http://sourceforge.net/tracker/?group_id=350113.
|
||||||
Thank you.
|
Thank you.
|
||||||
|
|
||||||
Copyright (C) 2007-2018 Siemens AG
|
Copyright (C) 2007-2022 Siemens AG
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published
|
it under the terms of the GNU Lesser General Public License as published
|
||||||
|
@ -21,6 +21,10 @@ GNU Lesser General Public License for more details.
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
CHANGES from version 0.9.4:
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
* fix possible memory corruption bug
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
CHANGES from version 0.9.3:
|
CHANGES from version 0.9.3:
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2007-2018 Siemens AG
|
* Copyright (C) 2007-2022 Siemens AG
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published
|
* it under the terms of the GNU Lesser General Public License as published
|
||||||
* by the Free Software Foundation, either version 3 of the License, or
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
*
|
*
|
||||||
* @author Daniel.Peintner.EXT@siemens.com
|
* @author Daniel.Peintner.EXT@siemens.com
|
||||||
* @version 2017-03-02
|
* @version 2022-03-08
|
||||||
* @contact Richard.Kuntschke@siemens.com
|
* @contact Richard.Kuntschke@siemens.com
|
||||||
*
|
*
|
||||||
* <p>Code generated by EXIdizer</p>
|
* <p>Code generated by EXIdizer</p>
|
||||||
* <p>Schema: V2G_CI_MsgDef.xsd</p>
|
* <p>Schema: V2G_CI_MsgDef.xsd</p>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "DecoderChannel.h"
|
#include "DecoderChannel.h"
|
||||||
|
@ -261,182 +261,320 @@ int decodeUnsignedInteger64(bitstream_t* stream, uint64_t* uint64) {
|
||||||
|
|
||||||
return errn;
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _reverseArray(uint8_t *array, int number) {
|
void _reverseArray(uint8_t *array, int number) {
|
||||||
int x, t;
|
int x, t;
|
||||||
number--;
|
number--;
|
||||||
|
|
||||||
for(x = 0; x < number; x ++, number --) {
|
for(x = 0; x < number; x ++, number --) {
|
||||||
t = array[x];
|
t = array[x];
|
||||||
array[x] = array[number];
|
array[x] = array[number];
|
||||||
array[number] = t;
|
array[number] = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode an arbitrary precision non negative integer using a sequence of
|
* Decode an arbitrary precision non negative integer using a sequence of
|
||||||
* octets. The most significant bit of the last octet is set to zero to
|
* octets. The most significant bit of the last octet is set to zero to
|
||||||
* indicate sequence termination. Only seven bits per octet are used to
|
* indicate sequence termination. Only seven bits per octet are used to
|
||||||
* store the integer's value.
|
* store the integer's value.
|
||||||
*/
|
*/
|
||||||
int decodeUnsignedIntegerBig(bitstream_t* stream, size_t size, uint8_t* data, size_t* len) {
|
int decodeUnsignedIntegerBig(bitstream_t* stream, size_t size, uint8_t* data, size_t* len) {
|
||||||
int errn = 0;
|
int errn = 0;
|
||||||
uint8_t b = 0;
|
uint8_t b = 0;
|
||||||
unsigned int mShift1 = 0;
|
unsigned int mShift1 = 0;
|
||||||
unsigned int mShift2 = 0;
|
unsigned int mShift2 = 0;
|
||||||
unsigned int mShift3 = 0;
|
unsigned int mShift3 = 0;
|
||||||
unsigned int mShift4 = 0;
|
unsigned int mShift4 = 0;
|
||||||
unsigned int nBytesRead = 0;
|
unsigned int nBytesRead = 0;
|
||||||
unsigned int nBitsAvailable = 0;
|
unsigned int nBitsAvailable = 0;
|
||||||
uint64_t uint64_1 = 0;
|
uint64_t uint64_1 = 0;
|
||||||
uint64_t uint64_2 = 0;
|
uint64_t uint64_2 = 0;
|
||||||
uint64_t uint64_3 = 0;
|
uint64_t uint64_3 = 0;
|
||||||
uint64_t uint64_4 = 0;
|
uint64_t uint64_4 = 0;
|
||||||
|
|
||||||
*len = 0;
|
*len = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
errn = decode(stream, &b);
|
errn = decode(stream, &b);
|
||||||
nBytesRead++;
|
nBytesRead++;
|
||||||
nBitsAvailable += 7;
|
nBitsAvailable += 7;
|
||||||
|
|
||||||
if(nBytesRead <= 8) {
|
if(nBytesRead <= 8) {
|
||||||
uint64_1 += ((uint64_t) (b & 127)) << mShift1;
|
uint64_1 += ((uint64_t) (b & 127)) << mShift1;
|
||||||
mShift1 += 7;
|
mShift1 += 7;
|
||||||
} else if(nBytesRead <= 16) {
|
} else if(nBytesRead <= 16) {
|
||||||
uint64_2 += ((uint64_t) (b & 127)) << mShift2;
|
uint64_2 += ((uint64_t) (b & 127)) << mShift2;
|
||||||
mShift2 += 7;
|
mShift2 += 7;
|
||||||
} else if(nBytesRead <= 24) {
|
} else if(nBytesRead <= 24) {
|
||||||
uint64_3 += ((uint64_t) (b & 127)) << mShift3;
|
uint64_3 += ((uint64_t) (b & 127)) << mShift3;
|
||||||
mShift3 += 7;
|
mShift3 += 7;
|
||||||
} else if(nBytesRead <= 32) {
|
} else if(nBytesRead <= 32) {
|
||||||
uint64_4 += ((uint64_t) (b & 127)) << mShift4;
|
uint64_4 += ((uint64_t) (b & 127)) << mShift4;
|
||||||
mShift4 += 7;
|
mShift4 += 7;
|
||||||
} else {
|
} else {
|
||||||
return -1; // too large
|
return -1; /* too large */
|
||||||
}
|
}
|
||||||
} while (errn == 0 && (b >> 7) == 1);
|
} while (errn == 0 && (b >> 7) == 1);
|
||||||
|
|
||||||
// shift actual data into array
|
/* shift actual data into array */
|
||||||
if(uint64_4 != 0) {
|
if(uint64_4 != 0) {
|
||||||
// 7 octets for uint64_1
|
/* 7 octets for uint64_1 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
if(*len >= size) {
|
||||||
uint64_1 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
}
|
||||||
uint64_1 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
uint64_1 >>= 8;
|
||||||
uint64_1 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_1 >>= 8;
|
}
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||||
uint64_1 >>= 8;
|
uint64_1 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
if(*len >= size) {
|
||||||
uint64_1 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||||
// 7 octets for uint64_2
|
uint64_1 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 1
|
if(*len >= size) {
|
||||||
uint64_2 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 2
|
}
|
||||||
uint64_2 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 3
|
uint64_1 >>= 8;
|
||||||
uint64_2 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 4
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_2 >>= 8;
|
}
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 5
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||||
uint64_2 >>= 8;
|
uint64_1 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 6
|
if(*len >= size) {
|
||||||
uint64_2 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 7
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||||
// 7 octets for uint64_3
|
uint64_1 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 1
|
if(*len >= size) {
|
||||||
uint64_3 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 2
|
}
|
||||||
uint64_3 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 3
|
|
||||||
uint64_3 >>= 8;
|
/* 7 octets for uint64_2 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 4
|
if(*len >= size) {
|
||||||
uint64_3 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 5
|
}
|
||||||
uint64_3 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 1 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 6
|
uint64_2 >>= 8;
|
||||||
uint64_3 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); // 7
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
// remaining octets of uint64_4
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 2 */
|
||||||
while (uint64_4 != 0 && errn == 0) {
|
uint64_2 >>= 8;
|
||||||
data[(*len)++] = uint64_4 & 0xFF;
|
if(*len >= size) {
|
||||||
uint64_4 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
} else if(uint64_3 != 0) {
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 3 */
|
||||||
// 7 octets for uint64_1
|
uint64_2 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
if(*len >= size) {
|
||||||
uint64_1 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
}
|
||||||
uint64_1 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 4 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
uint64_2 >>= 8;
|
||||||
uint64_1 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_1 >>= 8;
|
}
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 5 */
|
||||||
uint64_1 >>= 8;
|
uint64_2 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
if(*len >= size) {
|
||||||
uint64_1 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 6 */
|
||||||
// 7 octets for uint64_2
|
uint64_2 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 1
|
if(*len >= size) {
|
||||||
uint64_2 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 2
|
}
|
||||||
uint64_2 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 7 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 3
|
|
||||||
uint64_2 >>= 8;
|
/* 7 octets for uint64_3 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 4
|
if(*len >= size) {
|
||||||
uint64_2 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 5
|
}
|
||||||
uint64_2 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 1 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 6
|
uint64_3 >>= 8;
|
||||||
uint64_2 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); // 7
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
// remaining octets of uint64_3
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 2 */
|
||||||
while (uint64_3 != 0 && errn == 0) {
|
uint64_3 >>= 8;
|
||||||
data[(*len)++] = uint64_3 & 0xFF;
|
if(*len >= size) {
|
||||||
uint64_3 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 3 */
|
||||||
} else if(uint64_2 != 0) {
|
uint64_3 >>= 8;
|
||||||
// 7 octets for uint64_1
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 1
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_1 >>= 8;
|
}
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 2
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 4 */
|
||||||
uint64_1 >>= 8;
|
uint64_3 >>= 8;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 3
|
if(*len >= size) {
|
||||||
uint64_1 >>= 8;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 4
|
}
|
||||||
uint64_1 >>= 8;
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 5 */
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 5
|
uint64_3 >>= 8;
|
||||||
uint64_1 >>= 8;
|
if(*len >= size) {
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 6
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_1 >>= 8;
|
}
|
||||||
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); // 7
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 6 */
|
||||||
// remaining octets of uint64_2
|
uint64_3 >>= 8;
|
||||||
while (uint64_2 != 0 && errn == 0) {
|
if(*len >= size) {
|
||||||
data[(*len)++] = uint64_2 & 0xFF;
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
uint64_2 >>= 8;
|
}
|
||||||
}
|
data[(*len)++] = (uint8_t)(uint64_3 & 0xFF); /* 7 */
|
||||||
} else if(uint64_1 != 0) {
|
|
||||||
while (uint64_1 != 0 && errn == 0) {
|
/* remaining octets of uint64_4 */
|
||||||
data[(*len)++] = uint64_1 & 0xFF;
|
while (uint64_4 != 0 && errn == 0) {
|
||||||
uint64_1 >>= 8;
|
if(*len >= size) {
|
||||||
}
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
}
|
}
|
||||||
|
data[(*len)++] = uint64_4 & 0xFF;
|
||||||
_reverseArray(data, *len);
|
uint64_4 >>= 8;
|
||||||
|
}
|
||||||
return errn;
|
} else if(uint64_3 != 0) {
|
||||||
|
/* 7 octets for uint64_1 */
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||||
|
|
||||||
|
/* 7 octets for uint64_2 */
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 1 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 2 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 3 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 4 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 5 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 6 */
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_2 & 0xFF); /* 7 */
|
||||||
|
|
||||||
|
/* remaining octets of uint64_3 */
|
||||||
|
while (uint64_3 != 0 && errn == 0) {
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = uint64_3 & 0xFF;
|
||||||
|
uint64_3 >>= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(uint64_2 != 0) {
|
||||||
|
/* 7 octets for uint64_1 */
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 1 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 2 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 3 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 4 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 5 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 6 */
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = (uint8_t)(uint64_1 & 0xFF); /* 7 */
|
||||||
|
/* remaining octets of uint64_2 */
|
||||||
|
while (uint64_2 != 0 && errn == 0) {
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = uint64_2 & 0xFF;
|
||||||
|
uint64_2 >>= 8;
|
||||||
|
}
|
||||||
|
} else if(uint64_1 != 0) {
|
||||||
|
while (uint64_1 != 0 && errn == 0) {
|
||||||
|
if(*len >= size) {
|
||||||
|
return EXI_ERROR_OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
data[(*len)++] = uint64_1 & 0xFF;
|
||||||
|
uint64_1 >>= 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_reverseArray(data, *len);
|
||||||
|
|
||||||
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
int decodeInteger(bitstream_t* stream, exi_integer_t* iv) {
|
int decodeInteger(bitstream_t* stream, exi_integer_t* iv) {
|
||||||
|
@ -529,28 +667,28 @@ int decodeInteger64(bitstream_t* stream, int64_t* int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return errn;
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode an arbitrary precision integer using a sign bit followed by a
|
* Decode an arbitrary precision integer using a sign bit followed by a
|
||||||
* sequence of octets. The most significant bit of the last octet is set to
|
* sequence of octets. The most significant bit of the last octet is set to
|
||||||
* zero to indicate sequence termination. Only seven bits per octet are used
|
* zero to indicate sequence termination. Only seven bits per octet are used
|
||||||
* to store the integer's value.
|
* to store the integer's value.
|
||||||
*/
|
*/
|
||||||
int decodeIntegerBig(bitstream_t* stream, int* negative, size_t size, uint8_t* data, size_t* len) {
|
int decodeIntegerBig(bitstream_t* stream, int* negative, size_t size, uint8_t* data, size_t* len) {
|
||||||
int errn = decodeBoolean(stream, negative);
|
int errn = decodeBoolean(stream, negative);
|
||||||
|
|
||||||
if (errn == 0) {
|
if (errn == 0) {
|
||||||
if (*negative) {
|
if (*negative) {
|
||||||
/* For negative values, the Unsigned Integer holds the
|
/* For negative values, the Unsigned Integer holds the
|
||||||
* magnitude of the value minus 1 */
|
* magnitude of the value minus 1 */
|
||||||
} else {
|
} else {
|
||||||
/* positive */
|
/* positive */
|
||||||
}
|
}
|
||||||
errn = decodeUnsignedIntegerBig(stream, size, data, len);
|
errn = decodeUnsignedIntegerBig(stream, size, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return errn;
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -637,16 +775,16 @@ int decodeString(bitstream_t* stream, exi_string_t* s) {
|
||||||
*/
|
*/
|
||||||
int decodeCharacters(bitstream_t* stream, size_t len, exi_string_character_t* chars, size_t charsSize) {
|
int decodeCharacters(bitstream_t* stream, size_t len, exi_string_character_t* chars, size_t charsSize) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int errn = 0;
|
int errn = 0;
|
||||||
|
|
||||||
unsigned int extraChar = 0;
|
unsigned int extraChar = 0;
|
||||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||||
extraChar = 1; /* null terminator */
|
extraChar = 1; /* null terminator */
|
||||||
#endif /* STRING_REPRESENTATION_ASCII */
|
#endif /* STRING_REPRESENTATION_ASCII */
|
||||||
|
|
||||||
if ( (len + extraChar) > charsSize) {
|
if ( (len + extraChar) > charsSize) {
|
||||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||||
return errn;
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||||
|
@ -679,15 +817,15 @@ int decodeRCSCharacters(bitstream_t* stream, size_t len, exi_string_character_t*
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int errn = 0;
|
int errn = 0;
|
||||||
uint32_t uint32;
|
uint32_t uint32;
|
||||||
unsigned int extraChar = 0;
|
unsigned int extraChar = 0;
|
||||||
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
#if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
extraChar = 1; /* null terminator */
|
extraChar = 1; /* null terminator */
|
||||||
#endif /* STRING_REPRESENTATION_ASCII */
|
#endif /* STRING_REPRESENTATION_ASCII */
|
||||||
|
|
||||||
if ( (len + extraChar) > charsSize) {
|
if ( (len + extraChar) > charsSize) {
|
||||||
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
errn = EXI_ERROR_OUT_OF_STRING_BUFFER;
|
||||||
return errn;
|
return errn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue