Skip to content
Snippets Groups Projects
Commit 58bf130f authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

Management of packets length of 32 bits

parent ca6ba07f
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ CC = gcc
CXX = g++
#Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user
#- g3
CFLAGS = -O2 -O0 -g3 -m64 -fPIC
CFLAGS = -O2 -O0 -m64 -fPIC
#-O2 -O0 -g3
#Set INCPATH to add the inclusion paths
INCPATH = -I ./include
......
......@@ -19,10 +19,12 @@
#include "PacketLibDefinition.h"
namespace PacketLib {
namespace PacketLib
{
class FieldType {
class FieldType
{
public:
......@@ -56,18 +58,33 @@ class Field
word value;
//Dimension of field in bit.
inline dword getDimension() { return type->dimension; };
inline dword getDimension()
{
return type->dimension;
};
//It indicates that there's a predefined value for this field.
inline bool thereIsPredefinedValue() { return type->thereIsPredefinedValue; };
inline bool thereIsPredefinedValue()
{
return type->thereIsPredefinedValue;
};
//Predefined value of field (for the generation of packet).
inline int getPredefinedValue() { return type->predefinedValue; };
inline int getPredefinedValue()
{
return type->predefinedValue;
};
//Name of the field.
inline char* getName() { return type->name; };
inline char* getName()
{
return type->name;
};
inline int getProgressiv() { return progressiv; };
inline int getProgressiv()
{
return progressiv;
};
protected:
......
......@@ -69,7 +69,7 @@ class File : public Device
//## Reads a pair number of byte from opened file and manages the big or little endian
//## format. If the format of machine is little endian, a pair of byte is swapped.
//## \pre The file must be opened.
virtual ByteStream* getNByte( int N = 1 );
virtual ByteStream* getNByte( dword N = 1 );
//##ModelId=3C0F6C1A001B
//##Documentation
......@@ -96,12 +96,12 @@ class File : public Device
//##ModelId=3C205AF20278
//## Sets the position into file.
//## \pre The file must be opened.
virtual long setpos(long offset) throw(PacketExceptionIO*);
virtual dword setpos(dword offset) throw(PacketExceptionIO*);
//##ModelId=3C205AF202C3
//## Gets the current file position.
//## \pre The file must be opened.
virtual long getpos();
virtual dword getpos();
//##ModelId=3C205AF20313
//##Documentation
......@@ -149,10 +149,10 @@ class File : public Device
long getNumberOfStringLines();
//##ModelId=3EADC12702C9
static unsigned long byte_read;
static dword byte_read;
//##ModelId=3EADC1270363
static unsigned long char_read;
static dword char_read;
protected:
......@@ -163,10 +163,10 @@ class File : public Device
FILE* fp;
//##ModelId=3C187750023E
long bookmarkPos;
dword bookmarkPos;
//##ModelId=3C51324900FB
long startPosition;
dword startPosition;
//##ModelId=3C5132490213
char* filename;
......
......@@ -43,7 +43,7 @@ class Input
virtual bool open( char** parameters ) throw(PacketExceptionIO*) = 0;
//##ModelId=3EADC128033E
virtual ByteStream* readByteStream(int n_byte) throw(PacketExceptionIO*) = 0;
virtual ByteStream* readByteStream(dword n_byte) throw(PacketExceptionIO*) = 0;
//##ModelId=3EADC1280341
virtual char* readString() throw(PacketExceptionIO*) = 0;
......
......@@ -46,7 +46,7 @@ class InputFile : public Input
virtual void close() throw(PacketExceptionIO*);
//##ModelId=3EADC1280371
virtual ByteStream* readByteStream(int n_byte) throw(PacketExceptionIO*);
virtual ByteStream* readByteStream(dword n_byte) throw(PacketExceptionIO*);
//##ModelId=3EADC1280377
virtual char* readString() throw(PacketExceptionIO*);
......
......@@ -52,11 +52,16 @@ class PacketHeader : public PartOfPacket
//##ModelId=3C15ED930064
//##Documentation
//## Returns the total lenght of packet data field (data field header plus source data field)
word getPacketLength();
dword getPacketLength();
//set the length of the packet in the 'packet lenght' field (the data field dimension - 1)
void setPacketLength(dword dim);
//##ModelId=3EADC13A00BC
Field * getFieldWithPacketDimension();
inline word getDimensionOfPacketLenght() { return dimensionOfPacketLenght; };
private:
//##ModelId=3EADC1390359
......@@ -68,6 +73,9 @@ class PacketHeader : public PartOfPacket
//## Numbers of fields into the header that contains the dimension of packet.
word numberOfFieldWithPacketDimension;
//16 or 32 bit
word dimensionOfPacketLenght;
};
}
......
......@@ -26,7 +26,8 @@
#include "PacketException.h"
#include "MemoryBuffer.h"
namespace PacketLib {
namespace PacketLib
{
extern word pattern[17];
......@@ -65,13 +66,15 @@ class PartOfPacket
virtual MemoryBuffer* loadFieldsInBuffer(InputText & fp);
//Returns the dimension (in byte) of this part of packet.
virtual inline dword getDimension() {
virtual inline dword getDimension()
{
return fieldsDimension / 8;
};
//Returns a pointer of a field in the list of fields of this part of packet.
//\param index Represent the index in the list.
virtual inline Field* getFields(word index) {
virtual inline Field* getFields(word index)
{
if(index < numberOfFields)
return fields[index];
else
......@@ -80,7 +83,8 @@ class PartOfPacket
//Returns the value of a field in the list of fields of this part of packet.
//\param index Represent the index in the list.
virtual inline word getFieldValue(word index) {
virtual inline word getFieldValue(word index)
{
if(index < numberOfFields)
return fields[index]->value;
else
......@@ -234,7 +238,8 @@ class PartOfPacket
virtual void setFieldValue(word index, word value);
//## Returns the number of fields.
virtual inline word getNumberOfFields() {
virtual inline word getNumberOfFields()
{
return numberOfFields;
};
......
This diff is collapsed.
......@@ -15,7 +15,8 @@ Field::Field(char* n, char* dim, char* prVal, int count) : progressiv(count)
{
//create FieldType list
if(filedTypeList == 0) {
if(filedTypeList == 0)
{
//cout << "create list" << endl;
dword nb = CONFIG_MAXNUMBEROFLINES_OFCONFIGILES/3;
filedTypeList = (FieldType**) new FieldType* [nb];
......@@ -25,9 +26,11 @@ Field::Field(char* n, char* dim, char* prVal, int count) : progressiv(count)
//cout << "------" << endl;
int i = 0;
type = 0;
while(filedTypeList[i] != 0) {
while(filedTypeList[i] != 0)
{
//cout << filedTypeList[i]->name << " " << n << endl;
if(filedTypeList[i]->name == n) {
if(filedTypeList[i]->name == n)
{
type = filedTypeList[i];
break;
}
......@@ -35,7 +38,8 @@ Field::Field(char* n, char* dim, char* prVal, int count) : progressiv(count)
i++;
}
//cout << type << endl;
if(type == 0) {
if(type == 0)
{
type = new FieldType;
filedTypeList[i] = type;
......
......@@ -24,9 +24,9 @@
using namespace PacketLib;
//##ModelId=3DA3E56900F0
unsigned long File::byte_read = 0;
dword File::byte_read = 0;
//##ModelId=3DA3E56A0078
unsigned long File::char_read = 0;
dword File::char_read = 0;
//##ModelId=3C0F6C1A0012
File::File() : Device(false)
......@@ -108,9 +108,9 @@ int File::getByte()
//##ModelId=3C0F6C1A0018
ByteStream* File::getNByte(int N)
ByteStream* File::getNByte(dword N)
{
int i = 0;
dword i = 0;
int c1, c2;
if(N == 0)
return new ByteStream(0, bigendian);
......@@ -163,7 +163,7 @@ char* File::getLine() throw(PacketExceptionIO*)
static char s[2048];
// static unsigned long dimalloc = 0;
char c;
int i = 0;
dword i = 0;
if(!closed)
{
......@@ -241,9 +241,9 @@ char* File::getLastLineRead()
//##ModelId=3C205AF20278
long File::setpos(long offset) throw(PacketExceptionIO*)
dword File::setpos(dword offset) throw(PacketExceptionIO*)
{
long f;
dword f;
//clearerr(fp);
f = fseek(fp, offset, 0);
if(feof(fp))
......@@ -255,7 +255,7 @@ long File::setpos(long offset) throw(PacketExceptionIO*)
//##ModelId=3C205AF202C3
long File::getpos()
dword File::getpos()
{
return ftell(fp);
}
......@@ -264,7 +264,7 @@ long File::getpos()
//##ModelId=3C205AF20313
bool File::memBookmarkPos()
{
if((bookmarkPos = ftell(fp)) != -1)
if((bookmarkPos = ftell(fp)) != (dword) -1)
return true;
else
return false;
......
......@@ -54,7 +54,7 @@ void InputFile::close() throw(PacketExceptionIO*)
//##ModelId=3DBFBFBD0104
ByteStream* InputFile::readByteStream(int n_byte) throw(PacketExceptionIO*)
ByteStream* InputFile::readByteStream(dword n_byte) throw(PacketExceptionIO*)
{
ByteStream* bs;
if(!closed)
......
......@@ -60,7 +60,7 @@ int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packet)
{
// Iterate through list and output each element.
// Il packetType 0 e' il packet not recognized
for (int i = 1; i<numberOfPacketType; i++)
for (dword i = 1; i<numberOfPacketType; i++)
{
Packet* p = getPacketType(i);
if(p->verifyPacketValue(prefix, packet))
......@@ -83,20 +83,22 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
unsigned dimHeader = getHeaderDimension();
unsigned dimPrefix = getPrefixDimension();
ByteStream* b1 = 0, *b2 = 0, *b0 = 0;
word pl, dim, pindex;
dword pl, dim, pindex;
try
{
if(in == 0)
throw new PacketExceptionIO("no input set.");
b0 = in->readByteStream(dimPrefix);
if(b0 == 0 && dimPrefix != 0) {
if(b0 == 0 && dimPrefix != 0)
{
if(!in->isEOF())
throw new PacketExceptionIO("it is impossible to read the prefix.");
else
return 0;
}
b1 = in->readByteStream(dimHeader);
if(b1 == 0) {
if(b1 == 0)
{
if(!in->isEOF())
throw new PacketExceptionIO("it is impossible to read the header.");
else
......@@ -120,7 +122,8 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
} */
pl = headerReference->getPacketLength();
b2 = in->readByteStream(pl);
if(b2 == 0) {
if(b2 == 0)
{
if(!in->isEOF())
throw new PacketExceptionIO("it is impossible to read the data field.");
else
......@@ -138,6 +141,7 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*)
pindex = detPacketType(b0, b1, b2);
}
Packet* p = packetType[pindex];
cout << "entro " << pindex << endl;
if(!p->setPacketValue(b0, b1, b2)) //gli stream diventano del packet
throw new PacketExceptionIO("it is impossible to resolve the packet.");
return p;
......
......@@ -276,7 +276,7 @@ void Packet::printIdentifiers() {
//##ModelId=3C301E890023
bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) {
cout << "@ " << packetDataField->getDimension() << endl;
memByteStream(prefix, packetHeader, packetDataField);
ByteStream* packet = new ByteStream(packetHeader, packetDataField, 0);
memByteStream(prefix, packet);
......@@ -317,7 +317,7 @@ bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteSt
//##ModelId=3DA3E5890136
bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packet) {
word dimHeader = header->getDimension();
dword dimHeader = header->getDimension();
memByteStream(prefix, packet);
tempHeader->setStream(packet, 0, dimHeader-1);
tempDataField->setStream(packet, dimHeader, packet->getDimension());
......@@ -327,7 +327,7 @@ bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packet) {
//##ModelId=3DA3E58A0320
bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packet) {
word dimHeader = header->getDimension();
dword dimHeader = header->getDimension();
memByteStream(prefix, packet);
tempHeader->setStream(packet, 0, dimHeader-1);
tempDataField->setStream(packet, dimHeader, packet->getDimension());
......@@ -398,7 +398,7 @@ bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, Byt
//##ModelId=3DA3E58600B4
bool Packet::setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packet) {
word dimHeader = header->getDimension();
dword dimHeader = header->getDimension();
memByteStream(prefix, packet);
tempHeader->setStream(packet, 0, dimHeader-1);
tempDataField->setStream(packet, dimHeader, packet->getDimension());
......@@ -508,8 +508,10 @@ void Packet::generateStream() {
dataField->sourceDataField->set_reset_output_stream(false);
}
Field* f = header->getFieldWithPacketDimension();
f->value = dataField->getDimension() - 1;
//PACKET DIMENSIONE MANAGEMENT
header->setPacketLength(dataField->getDimension());
//Field* f = header->getFieldWithPacketDimension();
//f->value = dataField->getDimension() - 1;
header->generateStream(bigendian);
dataField->generateStream(bigendian);
......@@ -541,7 +543,7 @@ bool Packet::setPacketValuePrefix(ByteStream* prefix) {
//##ModelId=3DA3E599012C
bool Packet::setPacketValueDataFieldHeader(ByteStream* packetDataField) {
bool b;
word packetLength;
dword packetLength;
//4) data field header
packetLength = dataField->dataFieldHeader->getDimension();
//si legge e si setta il data field header
......@@ -559,14 +561,14 @@ bool Packet::setPacketValueDataFieldHeader(ByteStream* packetDataField) {
//##ModelId=3DA3E59A033E
bool Packet::setPacketValueSourceDataField(ByteStream* packetDataField) {
bool b;
word packetLength;
word packetLength2;
dword packetLength;
dword packetLength2;
//5) source data field
//se necessario, si setta il numero di blocchi reali presenti
if(dataField->sourceDataField->isBlock()) {
word nrd = dataField->getNumberOfRealDataBlock();
dword nrd = dataField->getNumberOfRealDataBlock();
dataField->sourceDataField->setNumberOfRealDataBlock(nrd);
}
/*if(dataField->sourceDataField->isRBlock()) {
......@@ -576,9 +578,9 @@ bool Packet::setPacketValueSourceDataField(ByteStream* packetDataField) {
packetLength = dataField->dataFieldHeader->getDimension();
int pl1 = header->getPacketLength();
int pl3 = dataField->dataFieldHeader->getDimension();
int pl4 = dataField->tail->getDimension();
dword pl1 = header->getPacketLength();
dword pl3 = dataField->dataFieldHeader->getDimension();
dword pl4 = dataField->tail->getDimension();
packetLength2 = pl1 - pl3 -pl4;
b = tempPacketDataField->setStream(packetDataField, packetLength, packetLength+packetLength2-1);
if(b)
......@@ -596,7 +598,7 @@ bool Packet::setPacketValueSourceDataField(ByteStream* packetDataField) {
bool Packet::setPacketValueTail(ByteStream* packetDataField) {
bool b;
word s, e;
dword s, e;
if(dataField->tail->getDimension() == 0)
return true;
/* NON CANCELLLARE: questo codice sotto funziona bene. Si utilizza
......
......@@ -8,6 +8,7 @@ using namespace PacketLib;
PacketHeader::PacketHeader() : PartOfPacket("Packet Header")
{
name = 0;
dimensionOfPacketLenght = 16;
}
//##ModelId=3DA3E5A7012C
......@@ -34,6 +35,14 @@ bool PacketHeader::loadHeader(char* fileName) throw(PacketException*)
numberOfFieldWithPacketDimension = atoi(line);
//delete[] line;
line = header.getLine();
if(strcmp(line, "[Field]") == 0)
dimensionOfPacketLenght = 16;
else
dimensionOfPacketLenght = atoi(line);
//cout << dimensionOfPacketLenght << endl;
header.setpos(0);
//find the start position of the fields
line = header.getLine("[Field]");
//delete[] line;
......@@ -55,14 +64,26 @@ bool PacketHeader::loadHeader(char* fileName) throw(PacketException*)
//##ModelId=3C15ED930064
word PacketHeader::getPacketLength()
dword PacketHeader::getPacketLength()
{
if(dimensionOfPacketLenght == 16) {
Field* f = getFields(numberOfFieldWithPacketDimension);
//standard ESA Nel packet lenght bisogna aggiungere 1
return f->value + 1;
} else {
return getFieldValue_4_14(numberOfFieldWithPacketDimension) + 1;
}
}
void PacketHeader::setPacketLength(dword dim) {
if(dimensionOfPacketLenght == 16) {
Field* f = getFields(numberOfFieldWithPacketDimension);
//standard ESA Nel packet lenght bisogna aggiungere 1
f->value = (word) dim-1;
} else {
setFieldValue_4_14(numberOfFieldWithPacketDimension, dim-1);
}
}
//##ModelId=3DA3E5A70208
......
......@@ -92,7 +92,8 @@ bool PartOfPacket::loadFields(InputText& fp) throw(PacketException*)
//count the number of fields
long pos = fp.getpos();
count++;
while(strlen(name) != 0) {
while(strlen(name) != 0)
{
name = fp.getLine();
count++;
if(name[0] == '[')
......@@ -250,7 +251,8 @@ bool PartOfPacket::setByteStream(ByteStream* s)
wordtemp = bl * 256 + bh;
numberOfShift = 16 - (posbit + dimbit);
//parte nuova
if(numberOfShift < 0) { //NB: se non si verifica mai questa condizione, il codice è assolutamente uguale al pre PacketLib 1.3.3
if(numberOfShift < 0) //NB: se non si verifica mai questa condizione, il codice è assolutamente uguale al pre PacketLib 1.3.3
{
short currentDimBit = dimbit + numberOfShift;
dimbit = abs(numberOfShift);
ftemp->value = (wordtemp & pattern[currentDimBit] ) << dimbit;
......@@ -272,7 +274,8 @@ bool PartOfPacket::setByteStream(ByteStream* s)
/* cout << i << ": " << ftemp->value << endl;
cout << i << ": " << (wordtemp & pattern[dimbit]) << endl;*/
}
else {
else
{
//questa fa parte della parte vecchia
wordtemp = wordtemp >> numberOfShift;
ftemp->value = wordtemp & pattern[dimbit];
......@@ -367,6 +370,10 @@ void PartOfPacket::printValueStdout()
s3 = s1 + s2;
cout << s3 << endl;
}
/* if(stream)
cout << stream->printStreamInHexadecimal() << endl;
if(outputstream)
cout << stream->printStreamInHexadecimal() << endl;*/
}
......@@ -398,7 +405,8 @@ ByteStream* PartOfPacket::generateStream(bool bigendian)
wtemp = fields[i]->getPredefinedValue();
dimbit = fields[i]->getDimension();
shift = 16 - dimbit - posbit;
if(shift < 0) {
if(shift < 0)
{
byte nbitshigh = abs(shift);
//word wh = wtemp >> (16 - nbitshigh);
word wh = wtemp >> (nbitshigh);
......@@ -411,7 +419,9 @@ ByteStream* PartOfPacket::generateStream(bool bigendian)
posbit = nbitshigh;
w = (wtemp & pattern[nbitshigh]) << (16-posbit);
} else {
}
else
{
wtemp = (wtemp << shift);
w = w | wtemp;
//cout << (Utility::wordToBinary(w, 16))->c_str() << endl;
......@@ -446,13 +456,16 @@ bool PartOfPacket::setOutputStream(ByteStream* os, dword first)
return true;
}
void PartOfPacket::setFieldValue(word index, word value) {
void PartOfPacket::setFieldValue(word index, word value)
{
if(index < numberOfFields)
fields[index]->value = (value & pattern[fields[index]->getDimension()]);
}
float PartOfPacket::getFieldValue_5_1(word index) {
union u_tag {
float PartOfPacket::getFieldValue_5_1(word index)
{
union u_tag
{
unsigned long i; //32 bit
float f; //32 bit single precision
} u;
......@@ -460,8 +473,10 @@ union u_tag {
return u.f;
}
void PartOfPacket::setFieldValue_5_1(word index, float value) {
union u_tag {
void PartOfPacket::setFieldValue_5_1(word index, float value)
{
union u_tag
{
unsigned long i; //32 bit
float f; //32 bit single precision
} u;
......@@ -473,13 +488,15 @@ word w;
setFieldValue(index + 1, w);
}
signed long PartOfPacket::getFieldValue_4_14(word index) {
signed long PartOfPacket::getFieldValue_4_14(word index)
{
long l;
l = (long)(getFieldValue(index) << 16) | (long)getFieldValue(index + 1);
return l;
}
void PartOfPacket::setFieldValue_4_14(word index, signed long value) {
void PartOfPacket::setFieldValue_4_14(word index, signed long value)
{
word w;
w = (word)(value >> 16);
setFieldValue(index, w);
......@@ -487,13 +504,15 @@ word w;
setFieldValue(index + 1, w);
}
unsigned long PartOfPacket::getFieldValue_3_14(word index) {
unsigned long PartOfPacket::getFieldValue_3_14(word index)
{
dword l;
l = (dword)(getFieldValue(index) << 16) | (dword)getFieldValue(index + 1);
return l;
}
void PartOfPacket::setFieldValue_3_14(word index, unsigned long value) {
void PartOfPacket::setFieldValue_3_14(word index, unsigned long value)
{
word w;
w = (word)(value >> 16);
setFieldValue(index, w);
......@@ -501,14 +520,16 @@ word w;
setFieldValue(index + 1, w);
}
unsigned long PartOfPacket::getFieldValue_3_13(word index) {
unsigned long PartOfPacket::getFieldValue_3_13(word index)
{
word wh, wl;
wh = getFieldValue(index);
wl = getFieldValue(index + 1);
return (dword)(wh << 8) | (dword)(wl & 0xFF);
}
void PartOfPacket::setFieldValue_3_13(word index, unsigned long value) throw(PacketException*) {
void PartOfPacket::setFieldValue_3_13(word index, unsigned long value) throw(PacketException*)
{
word w;
if(value > U24BITINTGEGERUNSIGNED_MAX)
throw new PacketException("setFieldValue_3_13(): the max value of 24 bit unsigned integer should be 16777215");
......@@ -518,8 +539,10 @@ word w;
setFieldValue(index + 1, w);
}
signed long PartOfPacket::getFieldValue_4_13(word index) {
union u_tag {
signed long PartOfPacket::getFieldValue_4_13(word index)
{
union u_tag
{
unsigned long u; //32 bit
signed long s;
} us;
......@@ -535,8 +558,10 @@ union u_tag {
}
void PartOfPacket::setFieldValue_4_13(word index, signed long value) throw(PacketException*) {
union u_tag {
void PartOfPacket::setFieldValue_4_13(word index, signed long value) throw(PacketException*)
{
union u_tag
{
unsigned long u; //32 bit
signed long s;
} us;
......
1.3.8
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment