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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Bulgarelli
PacketLib
Commits
9d42b397
"README.md" did not exist on "9857922aff10083d2df3d8ab34b927abb4cbb727"
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 @@
#define PACKETNOTRECOGNIZED 0
/// define NULL 0
//0 for x86
//1 for motorola
#define ARCH_BIGENDIAN 0
/*
* Little Endian or Big Endian ?
* 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
};
...
...
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)
stream
[
start
]
=
b1
;
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
;
}
...
...
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)
if
(
sourceDataVariable
->
size
()
!=
size
()
-
dimPacketStartingFixedPart
-
dimPacketTail
)
throw
new
PacketException
(
"the size of the sourceDataVariable is wrong"
);
bool
swapped
=
false
;
if
((
!
ARCH_BIGENDIAN
&&
bigendian
)
||
(
ARCH_BIGENDIAN
&&
!
bigendian
))
{
#ifdef ARCH_BIGENDIAN
if
(
!
bigendian
)
{
#else
if
(
bigendian
)
{
#endif
sourceDataVariable
->
swapWord
();
swapped
=
true
;
}
...
...
This diff is collapsed.
Click to expand it.
src/PartOfPacket.cpp
+
38
−
44
View file @
9d42b397
...
...
@@ -16,6 +16,9 @@
***************************************************************************/
#include
"PartOfPacket.h"
#include
"PacketLibDefinition.h"
//#define DEBUG 1
using
namespace
PacketLib
;
...
...
@@ -227,7 +230,6 @@ bool PartOfPacket::decode() {
if
(
decoded
)
return
true
;
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
/// for big or little endian machines
byte
*
stream
=
(
byte
*
)
this
->
stream
->
stream
;
...
...
@@ -243,53 +245,38 @@ bool PartOfPacket::decode() {
/// number of shift for elaboration
short
numberOfShift
=
0
;
/// number of fields
//unsigned nof = getNumberOfFields();
word
nof
=
numberOfFields
;
for
(
word
i
=
0
;
i
<
nof
;
i
++
)
{
ftemp
=
fields
[
i
];
dimbit
=
ftemp
->
size
();
/// Temporary word to be modified for the elaboration
byte
bh
=
*
(
stream
+
posword
);
byte
bl
=
*
(
stream
+
posword
+
1
);
//word wordtemp = *(stream + posword);
word
wordtemp
;
if
(
this
->
stream
->
isBigendian
())
wordtemp
=
bh
*
256
+
bl
;
else
wordtemp
=
bl
*
256
+
bh
;
numberOfShift
=
16
-
(
posbit
+
dimbit
);
//parte nuova
/// \remarks if the condition is not fulfilled, the code is equal to the versions older than PacketLib 1.3.3
if
(
numberOfShift
<
0
)
{
short
currentDimBit
=
dimbit
+
numberOfShift
;
dimbit
=
abs
(
numberOfShift
);
ftemp
->
value
=
(
wordtemp
&
pattern
[
currentDimBit
]
)
<<
dimbit
;
posbit
=
0
;
posword
+=
2
;
bh
=
*
(
stream
+
posword
);
bl
=
*
(
stream
+
posword
+
1
);
if
(
this
->
stream
->
isBigendian
())
wordtemp
=
bh
*
256
+
bl
;
else
wordtemp
=
bl
*
256
+
bh
;
// swap bytes if the machine is bigendian and the stream is little endian and vice-versa.
#ifdef ARCH_BIGENDIAN
if
(
!
this
->
stream
->
isBigendian
())
{
byte
bless
=
*
(
stream
+
posword
);
byte
bmost
=
*
(
stream
+
posword
+
1
);
wordtemp
=
(
bmost
<<
8
)
+
bless
;
#else
if
(
this
->
stream
->
isBigendian
())
{
byte
bmost
=
*
(
stream
+
posword
);
byte
bless
=
*
(
stream
+
posword
+
1
);
wordtemp
=
(
bmost
<<
8
)
|
bless
;
#ifdef DEBUG
std
::
cout
<<
"word: "
<<
wordtemp
<<
std
::
endl
;
#endif
#endif
}
else
{
wordtemp
=
*
(
(
word
*
)(
stream
+
posword
)
);
#ifdef DEBUG
std
::
cout
<<
"word: "
<<
wordtemp
<<
std
::
endl
;
#endif
}
numberOfShift
=
16
-
(
posbit
+
dimbit
);
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
];
}
/// Upgrade of pobit and posword
posbit
+=
dimbit
;
if
(
posbit
>=
16
)
...
...
@@ -302,8 +289,6 @@ bool PartOfPacket::decode() {
return
true
;
}
char
**
PartOfPacket
::
printValue
(
const
char
*
addString
)
{
decode
();
...
...
@@ -497,6 +482,9 @@ float PartOfPacket::getFieldValue_32f(word index)
float
f
;
}
u
;
u
.
i
=
(
(
dword
)
getFieldValue
(
index
)
<<
16
)
|
(
(
dword
)
getFieldValue
(
index
+
1
)
);
#ifdef DEBUG
std
::
cout
<<
"float: "
<<
u
.
i
<<
std
::
endl
;
#endif
return
u
.
f
;
}
...
...
@@ -515,10 +503,10 @@ double PartOfPacket::getFieldValue_64f(word index)
double
d
;
}
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
)
);
#ifdef DEBUG
std
::
cout
<<
"double: "
<<
u
.
d
<<
std
::
endl
;
#endif
return
u
.
d
;
}
...
...
@@ -572,6 +560,9 @@ signed long PartOfPacket::getFieldValue_32i(word index)
{
long
l
;
l
=
(
long
)(
getFieldValue
(
index
)
<<
16
)
|
(
long
)
getFieldValue
(
index
+
1
);
#ifdef DEBUG
std
::
cout
<<
"int32: "
<<
l
<<
std
::
endl
;
#endif
return
l
;
}
...
...
@@ -588,6 +579,9 @@ unsigned long PartOfPacket::getFieldValue_32ui(word index)
{
dword
l
;
l
=
(
dword
)(
getFieldValue
(
index
)
<<
16
)
|
(
dword
)
getFieldValue
(
index
+
1
);
#ifdef DEBUG
std
::
cout
<<
"uint32: "
<<
l
<<
std
::
endl
;
#endif
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