From 2bb1a929254da6cdae2089bde0aefd2bb06fa516 Mon Sep 17 00:00:00 2001 From: dsalanti Date: Fri, 12 Feb 2021 08:47:06 +0100 Subject: [PATCH] Issue #178 Explicit items with more elements then in definition should be put to list --- HISTORY | 2 +- asterix/version.py | 2 +- src/asterix/DataItemFormatExplicit.cpp | 56 +++++++++++++++++++------- src/main/version.h | 4 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/HISTORY b/HISTORY index 59cc108c..fb2e074f 100644 --- a/HISTORY +++ b/HISTORY @@ -239,7 +239,7 @@ Issue #169 Problem decoding BDS 4,5 reserved bits Issue #171 Hexdata presentation is not correct for multiple records in block RE item added to CAT010 -Not versioned yet +2.8.0 (python_v0.7.0) Issue #175 Cat021 Ed2.4 SelH is not reasonable Issue #174 Warning: ‘char* strncpy(char*, const char*, size_t)’ output may be truncated Issue #122 glibc version 2.1 behaves diffrently than glibc 2.0.6 diff --git a/asterix/version.py b/asterix/version.py index 8411e551..a71c5c7f 100644 --- a/asterix/version.py +++ b/asterix/version.py @@ -1 +1 @@ -__version__ = '0.6.1' +__version__ = '0.7.0' diff --git a/src/asterix/DataItemFormatExplicit.cpp b/src/asterix/DataItemFormatExplicit.cpp index b12a838a..0acf36dc 100644 --- a/src/asterix/DataItemFormatExplicit.cpp +++ b/src/asterix/DataItemFormatExplicit.cpp @@ -206,24 +206,50 @@ fulliautomatix_data* DataItemFormatExplicit::getData(unsigned char* pData, long, PyObject* DataItemFormatExplicit::getObject(unsigned char* pData, long nLength, int verbose) { - PyObject* p = PyDict_New(); - insertToDict(p, pData, nLength, verbose); - return p; + std::list::iterator it; + int bodyLength = 0; + + pData++; // skip explicit length byte (it is already in nLength) + + // calculate the size of all sub items + for (it = m_lSubItems.begin(); it != m_lSubItems.end(); it++) { + DataItemFormat *di = (DataItemFormat *) (*it); + bodyLength += di->getLength(pData + bodyLength); // calculate length of body + } + + int nFullLength = nLength - 1; // calculate full length + + // full length must be multiple of body length + if (bodyLength == 0 || nFullLength % bodyLength != 0) { + //TODO Tracer::Error("Wrong data length in Explicit. Needed=%d and there is %d bytes.", bodyLength, nFullLength); + return NULL; + } + + if (nFullLength == bodyLength) { + PyObject* p = PyDict_New(); + DataItemFormat *di = m_lSubItems.size() ? (DataItemFormatFixed*)m_lSubItems.front() : NULL; + if (di != NULL) { + di->insertToDict(p, pData, bodyLength, verbose); + } + return p; + } + else { + PyObject* p = PyList_New(0); + for (int i = 0; i < nFullLength; i += bodyLength) { + for (it = m_lSubItems.begin(); it != m_lSubItems.end(); it++) { + DataItemFormat *di = (DataItemFormat *) (*it); + PyObject* p1 = di->getObject(pData, bodyLength, verbose); + PyList_Append(p, p1); + Py_DECREF(p1); + pData += bodyLength; + } + } + return p; + } } void DataItemFormatExplicit::insertToDict(PyObject* p, unsigned char* pData, long nLength, int verbose) { - DataItemFormatFixed* pFixed = m_lSubItems.size() ? (DataItemFormatFixed*)m_lSubItems.front() : NULL; - if (pFixed == NULL) - { - //TODO Tracer::Error("Wrong format of explicit item"); - return; - } - - int fixedLength = pFixed->getLength(pData); - //unsigned char nFullLength = *pData; - pData++; - - pFixed->insertToDict(p, pData, fixedLength, verbose); + // Not supported } #endif diff --git a/src/main/version.h b/src/main/version.h index 8eb76aa7..fc54a167 100644 --- a/src/main/version.h +++ b/src/main/version.h @@ -26,7 +26,7 @@ #ifndef VERSION_H #define VERSION_H -#define _VERSION 2.7.1 -#define _VERSION_STR "2.7.1" +#define _VERSION 2.8.0 +#define _VERSION_STR "2.8.0" #endif