Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Base DAQ
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
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
BIAS
DAQs
Base DAQ
Compare revisions
840f0fa1970e363716386175149aecf60e82c996 to 4ab0a2d1455b3f285bba05e54c732772ad6852ac
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
bias/daqs/base-daq
Select target project
No results found
4ab0a2d1455b3f285bba05e54c732772ad6852ac
Select Git revision
Swap
Target
bias/daqs/base-daq
Select target project
bias/daqs/base-daq
1 result
840f0fa1970e363716386175149aecf60e82c996
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (1)
added copy contructors
· 4ab0a2d1
Valerio Pastore
authored
1 year ago
4ab0a2d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/Base_Packet.h
+48
-28
48 additions, 28 deletions
include/Base_Packet.h
with
48 additions
and
28 deletions
include/Base_Packet.h
View file @
4ab0a2d1
...
...
@@ -22,6 +22,7 @@ namespace inaf::oasbo::PacketLib {
class
BasePacketStructure
{
protected:
std
::
string
source
;
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
structure
;
uint
byteSize
;
std
::
vector
<
uint
>
fieldSizes
;
std
::
unordered_map
<
uint
,
uint
>
indexToOffsetsMap
;
...
...
@@ -57,17 +58,27 @@ protected:
}
void
updateStructure
(
std
::
string
source
)
{
this
->
source
=
source
;
std
::
vector
<
std
::
tuple
<
uint
,
std
::
string
,
uint
>>
paramsTuple
=
readStructureFromSource
(
source
);
updateFieldSizes
(
paramsTuple
);
updateFieldOffsets
(
paramsTuple
);
updateFieldNameAndIndexMap
(
paramsTuple
);
this
->
structure
=
readStructureFromSource
(
source
);
updateFieldSizes
(
structure
);
updateFieldOffsets
(
structure
);
updateFieldNameAndIndexMap
(
structure
);
this
->
byteSize
=
std
::
accumulate
(
fieldSizes
.
begin
(),
fieldSizes
.
end
(),
0
)
/
8
+
1
;
// /8 +1 for byte size
}
public
:
virtual
~
BasePacketStructure
()
=
default
;
BasePacketStructure
(
std
::
string
source
)
:
source
(
source
){};
BasePacketStructure
(
const
BasePacketStructure
&
other
){
this
->
source
=
other
.
source
;
this
->
byteSize
=
other
.
byteSize
;
this
->
fieldSizes
=
other
.
fieldSizes
;
this
->
indexToOffsetsMap
=
other
.
indexToOffsetsMap
;
this
->
fieldNameToIndexMap
=
other
.
fieldNameToIndexMap
;
this
->
indexToFieldNameMap
=
other
.
indexToFieldNameMap
;
}
void
changeSource
(
std
::
string
source
)
{
updateStructure
(
source
);
}
...
...
@@ -255,10 +266,18 @@ public:
this
->
binaryPointer
=
new
uint8_t
[
structure
.
getByteSize
()];
}
BasePacketTempl
(
const
BasePacketTempl
&
other
)
{
this
->
structure
=
new
BasePacketStructure
(
other
.
getPacketStructure
());
this
->
binaryPointer
=
new
uint8_t
[
other
.
structure
->
getByteSize
()];
std
::
memcpy
(
this
->
binaryPointer
,
other
.
binaryPointer
,
other
.
structure
->
getByteSize
());
}
virtual
~
BasePacketTempl
()
=
default
;
void
updateStructure
(
BasePacketStructure
&
structure
)
{
size_t
newSize
=
std
::
min
(
structure
.
getByteSize
(),
this
->
structure
->
getByteSize
());
size_t
newSize
=
std
::
min
(
structure
.
getByteSize
(),
this
->
structure
->
getByteSize
());
this
->
structure
=
&
structure
;
uint8_t
*
buff
=
new
uint8_t
[
newSize
];
...
...
@@ -291,14 +310,13 @@ public:
uint
max_writable
=
this
->
structure
->
getByteSize
();
if
(
size
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy "
<<
size
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
std
::
memcpy
(
binaryPointer
,
from
,
max_writable
);
return
max_writable
;
}
else
{
}
else
{
std
::
memcpy
(
binaryPointer
,
from
,
size
);
return
size
;
}
...
...
@@ -306,23 +324,22 @@ public:
int
copyToBinaryPointer
(
const
uint8_t
*
from
,
uint
size
,
uint
offset
)
{
uint
max_writable
=
this
->
structure
->
getByteSize
();
if
(
offset
>
max_writable
){
std
::
cerr
<<
"Error: you are trying to copy starting from "
<<
offset
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
if
(
offset
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy starting from "
<<
offset
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
return
-
1
;
}
if
(
size
+
offset
>
max_writable
)
{
std
::
cerr
<<
"Error: you are trying to copy "
<<
size
+
offset
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
int
to_write
=
max_writable
-
offset
;
<<
"byte where the max size is: "
<<
max_writable
<<
std
::
endl
;
std
::
cerr
<<
"
\t
I copy only until "
<<
max_writable
<<
" byte"
<<
std
::
endl
;
int
to_write
=
max_writable
-
offset
;
std
::
memcpy
(
&
binaryPointer
[
offset
],
from
,
to_write
);
return
to_write
;
}
else
{
}
else
{
std
::
memcpy
(
&
binaryPointer
[
offset
],
from
,
size
);
return
size
;
}
...
...
@@ -351,8 +368,7 @@ public:
&
_readValueFromBinaryAt_
);
}
std
::
optional
<
int
>
writeValueToBinaryAtIndex
(
uint
index
,
ValueType
value
)
{
std
::
optional
<
int
>
writeValueToBinaryAtIndex
(
uint
index
,
ValueType
value
)
{
auto
offset
=
this
->
structure
->
bitOffsetOf
(
index
);
auto
numbits
=
this
->
structure
->
bitSizeOf
(
index
);
size_t
min_req
=
minBitsRequired
(
value
);
...
...
@@ -387,9 +403,13 @@ public:
}
return
numbits_written
;
}
uint
getPacketStructureByteSize
()
const
{
return
structure
->
getByteSize
();}
BasePacketStructure
&
getPacketStructure
()
const
{
return
*
(
this
->
structure
);}
uint
getPacketStructureByteSize
()
const
{
return
structure
->
getByteSize
();
}
BasePacketStructure
&
getPacketStructure
()
const
{
return
*
(
this
->
structure
);
}
virtual
bool
isRecognizedHeader
()
const
=
0
;
virtual
bool
isRecognizedHeader
(
std
::
vector
<
uint8_t
>
buff
)
const
=
0
;
...
...
This diff is collapsed.
Click to expand it.