Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PacketLib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Bulgarelli
PacketLib
Commits
9d42b397
Commit
9d42b397
authored
10 years ago
by
Andrea Zoli
Browse files
Options
Downloads
Patches
Plain Diff
Handle ARCH_BIGENDIAN cases.
parent
3425f6c3
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/PacketLibDefinition.h
+19
-3
19 additions, 3 deletions
include/PacketLibDefinition.h
src/ByteStream.cpp
+0
-41
0 additions, 41 deletions
src/ByteStream.cpp
src/Packet.cpp
+5
-1
5 additions, 1 deletion
src/Packet.cpp
src/PartOfPacket.cpp
+38
-44
38 additions, 44 deletions
src/PartOfPacket.cpp
with
62 additions
and
89 deletions
include/PacketLibDefinition.h
+
19
−
3
View file @
9d42b397
...
@@ -36,9 +36,25 @@
...
@@ -36,9 +36,25 @@
#define PACKETNOTRECOGNIZED 0
#define PACKETNOTRECOGNIZED 0
/// define NULL 0
/// define NULL 0
//0 for x86
/*
//1 for motorola
* Little Endian or Big Endian ?
#define ARCH_BIGENDIAN 0
* Overwrite the #define below if you know your architecture endianess
*/
#if defined (__GLIBC__)
# include <endian.h>
# if (__BYTE_ORDER == __BIG_ENDIAN)
# define ARCH_BIGENDIAN 1
# endif
#elif (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN))
# define ARCH_BIGENDIAN 1
#elif defined(__sparc) || defined(__sparc__) \
||
defined
(
__powerpc__
)
||
defined
(
__ppc__
)
||
defined
(
__PPC__
)
\
||
defined
(
__hpux
)
||
defined
(
__hppa
)
\
||
defined
(
_MIPSEB
)
||
defined
(
__s390__
)
# define ARCH_BIGENDIAN 1
#else
/* Little Endian assumed. PDP Endian and other very rare endian format are unsupported. */
#endif
enum
CompressionAlgorithms
{
NONE
,
LZ4
};
enum
CompressionAlgorithms
{
NONE
,
LZ4
};
...
...
This diff is collapsed.
Click to expand it.
src/ByteStream.cpp
+
0
−
41
View file @
9d42b397
...
@@ -423,47 +423,6 @@ bool PacketLib::ByteStream::setWord(dword start, word value)
...
@@ -423,47 +423,6 @@ bool PacketLib::ByteStream::setWord(dword start, word value)
stream
[
start
]
=
b1
;
stream
[
start
]
=
b1
;
stream
[
start
+
1
]
=
b2
;
stream
[
start
+
1
]
=
b2
;
}
}
/*
if(!ARCH_BIGENDIAN && !bigendian )
{
//noswap
stream[start] = b1;
stream[start+1] = b2;
}
if(ARCH_BIGENDIAN && bigendian )
{
//noswap
stream[start] = b1;
stream[start+1] = b2;
}
if(!ARCH_BIGENDIAN && bigendian )
{
/// Swap
stream[start] = b2;
stream[start+1] = b1;
}
if(ARCH_BIGENDIAN && !bigendian )
{
/// Swap
stream[start] = b2;
stream[start+1] = b1;
}
*/
/*
if((bigendian && !ARCH_BIGENDIAN) || (!bigendian && ARCH_BIGENDIAN))
{
/// Swap
stream[start] = b2;
stream[start+1] = b1;
}
else
{
/// No swap for x86
stream[start] = b1;
stream[start+1] = b2;
}
*/
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Packet.cpp
+
5
−
1
View file @
9d42b397
...
@@ -616,7 +616,11 @@ ByteStreamPtr Packet::encodeAndSetData(ByteStreamPtr sourceDataVariable)
...
@@ -616,7 +616,11 @@ ByteStreamPtr Packet::encodeAndSetData(ByteStreamPtr sourceDataVariable)
if
(
sourceDataVariable
->
size
()
!=
size
()
-
dimPacketStartingFixedPart
-
dimPacketTail
)
if
(
sourceDataVariable
->
size
()
!=
size
()
-
dimPacketStartingFixedPart
-
dimPacketTail
)
throw
new
PacketException
(
"the size of the sourceDataVariable is wrong"
);
throw
new
PacketException
(
"the size of the sourceDataVariable is wrong"
);
bool
swapped
=
false
;
bool
swapped
=
false
;
if
((
!
ARCH_BIGENDIAN
&&
bigendian
)
||
(
ARCH_BIGENDIAN
&&
!
bigendian
))
{
#ifdef ARCH_BIGENDIAN
if
(
!
bigendian
)
{
#else
if
(
bigendian
)
{
#endif
sourceDataVariable
->
swapWord
();
sourceDataVariable
->
swapWord
();
swapped
=
true
;
swapped
=
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/PartOfPacket.cpp
+
38
−
44
View file @
9d42b397
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
***************************************************************************/
***************************************************************************/
#include
"PartOfPacket.h"
#include
"PartOfPacket.h"
#include
"PacketLibDefinition.h"
//#define DEBUG 1
using
namespace
PacketLib
;
using
namespace
PacketLib
;
...
@@ -227,7 +230,6 @@ bool PartOfPacket::decode() {
...
@@ -227,7 +230,6 @@ bool PartOfPacket::decode() {
if
(
decoded
)
if
(
decoded
)
return
true
;
return
true
;
Field
*
ftemp
;
Field
*
ftemp
;
//this->stream->setStream(s, 0, s->size() - 1);
/// The pointer is converted from byte to void. The reading from file allows the correct data interpretation
/// The pointer is converted from byte to void. The reading from file allows the correct data interpretation
/// for big or little endian machines
/// for big or little endian machines
byte
*
stream
=
(
byte
*
)
this
->
stream
->
stream
;
byte
*
stream
=
(
byte
*
)
this
->
stream
->
stream
;
...
@@ -243,53 +245,38 @@ bool PartOfPacket::decode() {
...
@@ -243,53 +245,38 @@ bool PartOfPacket::decode() {
/// number of shift for elaboration
/// number of shift for elaboration
short
numberOfShift
=
0
;
short
numberOfShift
=
0
;
/// number of fields
/// number of fields
//unsigned nof = getNumberOfFields();
word
nof
=
numberOfFields
;
word
nof
=
numberOfFields
;
for
(
word
i
=
0
;
i
<
nof
;
i
++
)
for
(
word
i
=
0
;
i
<
nof
;
i
++
)
{
{
ftemp
=
fields
[
i
];
ftemp
=
fields
[
i
];
dimbit
=
ftemp
->
size
();
dimbit
=
ftemp
->
size
();
/// Temporary word to be modified for the elaboration
/// Temporary word to be modified for the elaboration
byte
bh
=
*
(
stream
+
posword
);
byte
bl
=
*
(
stream
+
posword
+
1
);
//word wordtemp = *(stream + posword);
word
wordtemp
;
word
wordtemp
;
if
(
this
->
stream
->
isBigendian
())
// swap bytes if the machine is bigendian and the stream is little endian and vice-versa.
wordtemp
=
bh
*
256
+
bl
;
#ifdef ARCH_BIGENDIAN
else
if
(
!
this
->
stream
->
isBigendian
())
{
wordtemp
=
bl
*
256
+
bh
;
byte
bless
=
*
(
stream
+
posword
);
numberOfShift
=
16
-
(
posbit
+
dimbit
);
byte
bmost
=
*
(
stream
+
posword
+
1
);
//parte nuova
wordtemp
=
(
bmost
<<
8
)
+
bless
;
/// \remarks if the condition is not fulfilled, the code is equal to the versions older than PacketLib 1.3.3
#else
if
(
numberOfShift
<
0
)
if
(
this
->
stream
->
isBigendian
())
{
{
byte
bmost
=
*
(
stream
+
posword
);
short
currentDimBit
=
dimbit
+
numberOfShift
;
byte
bless
=
*
(
stream
+
posword
+
1
);
dimbit
=
abs
(
numberOfShift
);
wordtemp
=
(
bmost
<<
8
)
|
bless
;
ftemp
->
value
=
(
wordtemp
&
pattern
[
currentDimBit
]
)
<<
dimbit
;
#ifdef DEBUG
posbit
=
0
;
std
::
cout
<<
"word: "
<<
wordtemp
<<
std
::
endl
;
posword
+=
2
;
#endif
bh
=
*
(
stream
+
posword
);
#endif
bl
=
*
(
stream
+
posword
+
1
);
}
else
{
if
(
this
->
stream
->
isBigendian
())
wordtemp
=
*
(
(
word
*
)(
stream
+
posword
)
);
wordtemp
=
bh
*
256
+
bl
;
#ifdef DEBUG
else
std
::
cout
<<
"word: "
<<
wordtemp
<<
std
::
endl
;
wordtemp
=
bl
*
256
+
bh
;
#endif
}
numberOfShift
=
16
-
(
posbit
+
dimbit
);
numberOfShift
=
16
-
(
posbit
+
dimbit
);
wordtemp
=
wordtemp
>>
numberOfShift
;
wordtemp
=
wordtemp
>>
numberOfShift
;
/* cout << i << ": " << ftemp->value << endl;
cout << i << ": " << (ftemp->value << currentDimBit) << endl;
cout << i << ": " << wordtemp << endl;*/
ftemp
->
value
=
ftemp
->
value
|
(
wordtemp
&
pattern
[
dimbit
]);
/* cout << i << ": " << ftemp->value << endl;
cout << i << ": " << (wordtemp & pattern[dimbit]) << endl;*/
}
else
{
//questa fa parte della parte vecchia
wordtemp
=
wordtemp
>>
numberOfShift
;
ftemp
->
value
=
wordtemp
&
pattern
[
dimbit
];
ftemp
->
value
=
wordtemp
&
pattern
[
dimbit
];
}
/// Upgrade of pobit and posword
/// Upgrade of pobit and posword
posbit
+=
dimbit
;
posbit
+=
dimbit
;
if
(
posbit
>=
16
)
if
(
posbit
>=
16
)
...
@@ -302,8 +289,6 @@ bool PartOfPacket::decode() {
...
@@ -302,8 +289,6 @@ bool PartOfPacket::decode() {
return
true
;
return
true
;
}
}
char
**
PartOfPacket
::
printValue
(
const
char
*
addString
)
char
**
PartOfPacket
::
printValue
(
const
char
*
addString
)
{
{
decode
();
decode
();
...
@@ -497,6 +482,9 @@ float PartOfPacket::getFieldValue_32f(word index)
...
@@ -497,6 +482,9 @@ float PartOfPacket::getFieldValue_32f(word index)
float
f
;
float
f
;
}
u
;
}
u
;
u
.
i
=
(
(
dword
)
getFieldValue
(
index
)
<<
16
)
|
(
(
dword
)
getFieldValue
(
index
+
1
)
);
u
.
i
=
(
(
dword
)
getFieldValue
(
index
)
<<
16
)
|
(
(
dword
)
getFieldValue
(
index
+
1
)
);
#ifdef DEBUG
std
::
cout
<<
"float: "
<<
u
.
i
<<
std
::
endl
;
#endif
return
u
.
f
;
return
u
.
f
;
}
}
...
@@ -515,10 +503,10 @@ double PartOfPacket::getFieldValue_64f(word index)
...
@@ -515,10 +503,10 @@ double PartOfPacket::getFieldValue_64f(word index)
double
d
;
double
d
;
}
u
;
}
u
;
#ifdef __x86_64__
u
.
i
=
(
unsigned
long
)
(
(
unsigned
long
)
getFieldValue
(
index
)
<<
(
48
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
1
)
<<
(
32
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
2
)
<<
(
16
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
3
)
);
u
.
i
=
(
unsigned
long
)
(
(
unsigned
long
)
getFieldValue
(
index
)
<<
(
48
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
1
)
<<
(
32
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
2
)
<<
(
16
))
|
(
(
unsigned
long
)
getFieldValue
(
index
+
3
)
);
#ifdef DEBUG
std
::
cout
<<
"double: "
<<
u
.
d
<<
std
::
endl
;
#endif
#endif
return
u
.
d
;
return
u
.
d
;
}
}
...
@@ -572,6 +560,9 @@ signed long PartOfPacket::getFieldValue_32i(word index)
...
@@ -572,6 +560,9 @@ signed long PartOfPacket::getFieldValue_32i(word index)
{
{
long
l
;
long
l
;
l
=
(
long
)(
getFieldValue
(
index
)
<<
16
)
|
(
long
)
getFieldValue
(
index
+
1
);
l
=
(
long
)(
getFieldValue
(
index
)
<<
16
)
|
(
long
)
getFieldValue
(
index
+
1
);
#ifdef DEBUG
std
::
cout
<<
"int32: "
<<
l
<<
std
::
endl
;
#endif
return
l
;
return
l
;
}
}
...
@@ -588,6 +579,9 @@ unsigned long PartOfPacket::getFieldValue_32ui(word index)
...
@@ -588,6 +579,9 @@ unsigned long PartOfPacket::getFieldValue_32ui(word index)
{
{
dword
l
;
dword
l
;
l
=
(
dword
)(
getFieldValue
(
index
)
<<
16
)
|
(
dword
)
getFieldValue
(
index
+
1
);
l
=
(
dword
)(
getFieldValue
(
index
)
<<
16
)
|
(
dword
)
getFieldValue
(
index
+
1
);
#ifdef DEBUG
std
::
cout
<<
"uint32: "
<<
l
<<
std
::
endl
;
#endif
return
l
;
return
l
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment