Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/asterix/DataBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

extern bool gFiltering;

DataBlock::DataBlock(Category *cat, unsigned long len, const unsigned char *data, double nTimestamp)
: m_pCategory(cat), m_nLength(len), m_nTimestamp(nTimestamp), m_bFormatOK(false) {
DataBlock::DataBlock(Category *cat, unsigned long len, const unsigned char *data, double nTimestamp, unsigned int nIP)
: m_pCategory(cat), m_nLength(len), m_nTimestamp(nTimestamp), m_nIP(nIP), m_bFormatOK(false) {
const unsigned char *m_pItemDataStart = data;
long nUnparsed = len;
int counter = 1;
Expand All @@ -40,7 +40,7 @@ DataBlock::DataBlock(Category *cat, unsigned long len, const unsigned char *data
}

while (nUnparsed > 0) {
DataRecord *dr = new DataRecord(cat, counter++, nUnparsed, m_pItemDataStart, nTimestamp);
DataRecord *dr = new DataRecord(cat, counter++, nUnparsed, m_pItemDataStart, nTimestamp, nIP);

if (!dr) {
Tracer::Error("Error DataBlock format.");
Expand Down Expand Up @@ -87,6 +87,7 @@ bool DataBlock::getText(std::string &strResult, const unsigned int formatType) {
strResult += format("\nLen: %ld", m_nLength);
strResult += format("\nTimestamp: %lf", m_nTimestamp);
strResult += format("\nHexData: %02X%02X%02X", m_pCategory->m_id, ((m_nLength + 3) >> 8) & 0xff, (m_nLength + 3) & 0xff);
strResult += format("\nSrc IP: %lu", m_nIP);
break;
case CAsterixFormat::EOut:
strHeader = format("Asterix.CAT%03d", m_pCategory->m_id);
Expand Down
3 changes: 2 additions & 1 deletion src/asterix/DataBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

class DataBlock {
public:
DataBlock(Category *cat, unsigned long len, const unsigned char *data, double nTimestamp = 0.0);
DataBlock(Category *cat, unsigned long len, const unsigned char *data, double nTimestamp = 0.0, unsigned int nIP = 0);

virtual
~DataBlock();

Category *m_pCategory;
unsigned long m_nLength;
double m_nTimestamp; // Date and time when this packet was captured. This value is in seconds since January 1, 1970 00:00:00 GMT
unsigned int m_nIP; // source ip when reading GPS files
bool m_bFormatOK;

std::list<DataRecord *> m_lDataRecords;
Expand Down
22 changes: 14 additions & 8 deletions src/asterix/DataRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include "Utils.h"
#include "asterixformat.hxx"

DataRecord::DataRecord(Category *cat, int nID, unsigned long len, const unsigned char *data, double nTimestamp)
DataRecord::DataRecord(Category *cat, int nID, unsigned long len, const unsigned char *data, double nTimestamp, unsigned int nIP)
: m_pCategory(cat), m_nID(nID), m_nLength(len), m_nFSPECLength(0), m_pFSPECData(NULL), m_nTimestamp(nTimestamp),
m_nCrc(0), m_pHexData(NULL), m_bFormatOK(false) {
m_nIP(nIP), m_nCrc(0), m_pHexData(NULL), m_bFormatOK(false) {
const unsigned char *m_pItemDataStart = data;
long nUnparsed = len;

Expand Down Expand Up @@ -164,6 +164,11 @@
Tracer::Error("Record not parsed properly. CAT%03d len=%ld", m_pCategory->m_id, m_nLength);
return false;
}
unsigned char ip[4];

Check warning on line 167 in src/asterix/DataRecord.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::string" instead of a C-style char array.

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpax8ar6aFTbyWouT&open=AZ0kpax8ar6aFTbyWouT&pullRequest=253
ip[0] = (unsigned char)(m_nIP >> 24);
ip[1] = (unsigned char)(m_nIP >> 16);
ip[2] = (unsigned char)(m_nIP >> 8);
ip[3] = (unsigned char)(m_nIP);

std::string strNewResult;

Expand All @@ -172,25 +177,26 @@
strNewResult = format("\n-------------------------\nData Record %d", m_nID);
strNewResult += format("\nLen: %ld", m_nLength);
strNewResult += format("\nCRC: %08X", m_nCrc);
strNewResult += format("\nSource IP: %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
strNewResult += format("\nHexData: %s", m_pHexData);
break;
case CAsterixFormat::EJSON:
strNewResult = format(
"{\"id\":%d,\"cat\":%d,\"length\":%ld,\"crc\":\"%08X\",\"timestamp\":%lf,\"hexdata\":\"%s\",\"CAT%03d\":{",
m_nID, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, m_pHexData, m_pCategory->m_id);
"{\"id\":%d,\"cat\":%d,\"length\":%ld,\"crc\":\"%08X\",\"timestamp\":%lf,\"srcip\":\"%u.%u.%u.%u\",\"hexdata\":\"%s\",\"CAT%03d\":{",

Check warning on line 185 in src/asterix/DataRecord.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Convert this string literal to a raw string literal.

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpax8ar6aFTbyWouU&open=AZ0kpax8ar6aFTbyWouU&pullRequest=253
m_nID, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, ip[0], ip[1], ip[2], ip[3], m_pHexData, m_pCategory->m_id);
break;
case CAsterixFormat::EJSONH:
case CAsterixFormat::EJSONE:
strNewResult = format(
"{\"id\":%d,\n\"cat\":%d,\n\"length\":%ld,\n\"crc\":\"%08X\",\n\"timestamp\":%lf,\n\"hexdata\":\"%s\",\n\"CAT%03d\":{\n",
m_nID, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, m_pHexData, m_pCategory->m_id);
"{\"id\":%d,\n\"cat\":%d,\n\"length\":%ld,\n\"crc\":\"%08X\",\n\"timestamp\":%lf,\n\"srcip\":\"%u.%u.%u.%u\",\n\"hexdata\":\"%s\",\n\"CAT%03d\":{\n",
m_nID, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, ip[0], ip[1], ip[2], ip[3], m_pHexData, m_pCategory->m_id);
break;
case CAsterixFormat::EXML:
case CAsterixFormat::EXMLH: {
const int nXIDEFv = 1;
strNewResult = format(
"<ASTERIX ver=\"%d\" cat=\"%d\" length=\"%ld\" crc=\"%08X\" timestamp=\"%lf\" hexdata=\"%s\">",
nXIDEFv, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, m_pHexData);
"<ASTERIX ver=\"%d\" cat=\"%d\" length=\"%ld\" crc=\"%08X\" timestamp=\"%lf\" srcip=\"%u.%u.%u.%u\" hexdata=\"%s\">",

Check warning on line 198 in src/asterix/DataRecord.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Convert this string literal to a raw string literal.

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpax8ar6aFTbyWouV&open=AZ0kpax8ar6aFTbyWouV&pullRequest=253
nXIDEFv, m_pCategory->m_id, m_nLength, m_nCrc, m_nTimestamp, ip[0], ip[1], ip[2], ip[3], m_pHexData);
break;
}
}
Expand Down Expand Up @@ -373,7 +379,7 @@
DataItem* di = (DataItem*)(*it);
if (di)
{
PyObject* v1 = di->getData(verbose);

Check warning on line 382 in src/asterix/DataRecord.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declaration shadows a local variable "v1" in the outer scope.

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpax8ar6aFTbyWouW&open=AZ0kpax8ar6aFTbyWouW&pullRequest=253
if (v1 == NULL) {
v1 = Py_BuildValue("s", "Error");
}
Expand Down
3 changes: 2 additions & 1 deletion src/asterix/DataRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class DataRecord {
public:
DataRecord(Category *cat, int id, unsigned long len, const unsigned char *data, double nTimestamp);
DataRecord(Category *cat, int id, unsigned long len, const unsigned char *data, double nTimestamp, unsigned int nIP);

virtual
~DataRecord();
Expand All @@ -39,6 +39,7 @@ class DataRecord {
unsigned long m_nFSPECLength;
unsigned char *m_pFSPECData;
double m_nTimestamp; // Date and time when this packet was captured. This value is in seconds since January 1, 1970 00:00:00 GMT
unsigned m_nIP; // source ip when reading from GPS
uint32_t m_nCrc;
char *m_pHexData; // hexa conversion of data to display
bool m_bFormatOK;
Expand Down
8 changes: 4 additions & 4 deletions src/asterix/InputParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ InputParser::InputParser(AsterixDefinition *pDefinition)
* Parse data
*/
AsterixData *
InputParser::parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferSize, double nTimestamp) {
InputParser::parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferSize, double nTimestamp, unsigned int nIP) {
AsterixData *pAsterixData = new AsterixData();
unsigned int m_nPos = 0;
unsigned int m_nDataLength = 0;
Expand Down Expand Up @@ -100,7 +100,7 @@ InputParser::parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferS
hexString.erase(hexString.size() - 1);
LOGDEBUG(1, "[%s]\n", hexString.c_str());
#endif
DataBlock *db = new DataBlock(m_pDefinition->getCategory(nCategory), dataLen, m_pData, nTimestamp);
DataBlock *db = new DataBlock(m_pDefinition->getCategory(nCategory), dataLen, m_pData, nTimestamp, nIP);
m_pData += dataLen;
m_nPos += dataLen;
pAsterixData->m_lDataBlocks.push_back(db);
Expand All @@ -116,7 +116,7 @@ InputParser::parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferS

DataBlock *
InputParser::parse_next_data_block(const unsigned char *m_pData, unsigned int &m_nPos, unsigned int m_nBufferSize,
double nTimestamp, unsigned int &m_nDataLength)
double nTimestamp, unsigned int nIP, unsigned int &m_nDataLength)
/* parse next data block
* AUTHOR: Krzysztof Rutkowski, ICM UW, krutk@icm.edu.pl
*/
Expand Down Expand Up @@ -170,7 +170,7 @@ InputParser::parse_next_data_block(const unsigned char *m_pData, unsigned int &m
hexString.erase(hexString.size() - 1);
LOGDEBUG(1, "[%s]\n", hexString.c_str());
#endif
DataBlock *db = new DataBlock(m_pDefinition->getCategory(nCategory), dataLen, m_pData, nTimestamp);
DataBlock *db = new DataBlock(m_pDefinition->getCategory(nCategory), dataLen, m_pData, nTimestamp, nIP);
m_pData += dataLen;
m_nPos += dataLen;
m_nDataLength -= dataLen;
Expand Down
4 changes: 2 additions & 2 deletions src/asterix/InputParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class InputParser {

~InputParser() { if (m_pDefinition) delete m_pDefinition; }

AsterixData *parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferSize, double nTimestamp = 0.0);
AsterixData *parsePacket(const unsigned char *m_pBuffer, unsigned int m_nBufferSize, double nTimestamp = 0.0, unsigned int nIP = 0);

DataBlock *parse_next_data_block(const unsigned char *m_pData, unsigned int &m_nPos, unsigned int m_nBufferSize,
double nTimestamp, unsigned int &m_nDataLength);
double nTimestamp, unsigned int nIP, unsigned int &m_nDataLength);

std::string printDefinition();

Expand Down
21 changes: 20 additions & 1 deletion src/asterix/asterixformatdescriptor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
m_pBuffer(NULL),
m_nBufferSize(0),
m_nDataSize(0),
m_nTimeStamp(0) {
m_nTimeStamp(0),
m_nIP(0) {

Check warning on line 55 in src/asterix/asterixformatdescriptor.hxx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not use the constructor's initializer list for data member "m_nIP". Use the in-class initializer instead.

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpau9ar6aFTbyWouR&open=AZ0kpau9ar6aFTbyWouR&pullRequest=253
}

/**
Expand Down Expand Up @@ -110,6 +111,23 @@
m_nTimeStamp = ts;
}

void SetIP(unsigned char ip0, unsigned char ip1, unsigned char ip2, unsigned char ip3) {
uint32_t v =
((uint32_t)ip0 << 24) |
((uint32_t)ip1 << 16) |
((uint32_t)ip2 << 8) |
((uint32_t)ip3 );
m_nIP = v;
}

void SetIP(unsigned int ip) {
m_nIP = ip;
}

unsigned int GetIP() {

Check warning on line 127 in src/asterix/asterixformatdescriptor.hxx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpau9ar6aFTbyWouS&open=AZ0kpau9ar6aFTbyWouS&pullRequest=253
return m_nIP;
}

// used only in PCAP (TODO)
typedef enum {
NET_ETHERNET = 0,
Expand All @@ -132,6 +150,7 @@
unsigned int m_nBufferSize; // input buffer size
unsigned int m_nDataSize; // size of data in buffer
double m_nTimeStamp; // Date and time when this packet was captured. This value is in seconds since January 1, 1970 00:00:00 GMT
uint32_t m_nIP; // src ip of packet
};

#endif
6 changes: 5 additions & 1 deletion src/asterix/asterixgpssubformat.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ bool CAsterixGPSSubformat::ReadPacket(CBaseFormatDescriptor &formatDescriptor, C
GPSPost[2], GPSPost[3], GPSPost[4], GPSPost[5], GPSPost[6], GPSPost[7],
GPSPost[8], GPSPost[9]);
LOGDEBUG(1, "GPS Timestamp [%lf]\n", dTimeStamp);
LOGDEBUG(1, "SRC IP [%u.%u.%u.%u]\n", GPSPost[3], GPSPost[2], GPSPost[1], GPSPost[0]);
#endif
Descriptor.SetTimeStamp(dTimeStamp);
Descriptor.SetIP(GPSPost[3], GPSPost[2], GPSPost[1], GPSPost[0]);

}
}
Expand Down Expand Up @@ -252,8 +254,10 @@ bool CAsterixGPSSubformat::ProcessPacket(CBaseFormatDescriptor &formatDescriptor
}
} else {
double dTimeStamp = Descriptor.GetTimeStamp();
unsigned int nIP = Descriptor.GetIP();
Descriptor.m_pAsterixData = Descriptor.m_InputParser.parsePacket(Descriptor.GetBuffer(),
Descriptor.GetBufferLen(), dTimeStamp);
Descriptor.GetBufferLen(),
dTimeStamp, nIP);
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/asterix/asterixrawsubformat.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ bool CAsterixRawSubformat::ProcessPacket(CBaseFormatDescriptor &formatDescriptor
}
} else {
Descriptor.m_pAsterixData = Descriptor.m_InputParser.parsePacket(Descriptor.GetBuffer(),
Descriptor.GetBufferLen(), dTimestamp);
Descriptor.GetBufferLen(),
dTimestamp, device.getLastSourceIP());
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/basedevice.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public:
ResetErrors(true);
}

virtual unsigned int getLastSourceIP() { return false; }

protected: // to be used by derived class for error counting
virtual void CountReadError() {
_nReadErrors++;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/channelfactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ bool CChannelFactory::ReadPacket() {
return false;
}

// Get thr format descriptor and number
// Get the format descriptor and number
CBaseFormatDescriptor *formatDescriptor = _inputChannel->GetFormatDescriptor();
if (formatDescriptor == NULL) {
LOGERROR(1, "ReadPacket() - Cannot get the format descriptor.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/engine/udpdevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool CUdpDevice::Read(void *data, size_t *len) {
inet_ntoa(_mcastAddr.sin_addr),
lenread);


setLastSourceIP(ntohl(clientAddr.sin_addr.s_addr));
ResetReadErrors(true);
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion src/engine/udpdevice.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
bool _server;
struct sockaddr_in _mcastAddr;
struct in_addr _interfaceAddr;
struct in_addr _sourceAddr;
struct in_addr _sourceAddr; // from the subscribe command line option
uint32_t _nSrcIP; // IP from the recvfrom syscall
int _port;
std::vector<int> _socketDesc;
fd_set _descToRead;
Expand Down Expand Up @@ -97,6 +98,9 @@
MaxPacketSize() { return MAX_UDP_PACKET_SIZE; } // return maximal packet size (only for packet devices)
virtual unsigned int BytesLeftToRead() { return 0; } // return number of bytes left to read or 0 if unknown

unsigned int getLastSourceIP() { return this->_nSrcIP; }

Check warning on line 101 in src/engine/udpdevice.hxx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Annotate this function with "override" or "final".

See more on https://sonarcloud.io/project/issues?id=CroatiaControlLtd_asterix&issues=AZ0kpazjar6aFTbyWouX&open=AZ0kpazjar6aFTbyWouX&pullRequest=253
void setLastSourceIP(uint32_t nIP) { this->_nSrcIP = nIP; }

private:
void Init(const char *mcastAddress, const char *interfaceAddress, const char *srcAddress, const int port,
const bool server);
Expand Down