blob: 117ca6232dc21d9681e35ef975ccbfd8c25aa885 [file] [log] [blame]
Ben Tynerfeeea832021-04-06 10:08:11 -05001#include "extended_user_header.hpp"
2
3namespace attn
4{
5namespace pel
6{
7
8ExtendedUserHeader::ExtendedUserHeader(Stream& pel)
9{
10 unflatten(pel);
11}
12
13void ExtendedUserHeader::flatten(Stream& pel) const
14{
15 pel << _header;
16 pel.write(_mtms, mtmsSize);
17 pel.write(_serverFWVersion.data(), _serverFWVersion.size());
18 pel.write(_subsystemFWVersion.data(), _subsystemFWVersion.size());
19 pel << _reserved4B << _refTime << _reserved1B1 << _reserved1B2
20 << _reserved1B3 << _symptomIdSize << _symptomId;
21}
22
23void ExtendedUserHeader::unflatten(Stream& pel)
24{
25 pel >> _header;
26 pel.read(_mtms, mtmsSize);
27 pel.read(_serverFWVersion.data(), _serverFWVersion.size());
28 pel.read(_subsystemFWVersion.data(), _subsystemFWVersion.size());
29 pel >> _reserved4B >> _refTime >> _reserved1B1 >> _reserved1B2 >>
30 _reserved1B3 >> _symptomIdSize >> _symptomId;
31
32 //_symptomId.resize(_symptomIdSize);
33 pel >> _symptomId;
34}
35
36void ExtendedUserHeader::setSymptomId(const std::string& symptomId)
37{
38 // set symptomId to new symptomId
39 std::copy(symptomId.begin(), symptomId.end(),
40 std::back_inserter(_symptomId));
41
42 // new symptom Id cannot be larger than existing symptom Id
43 if (_symptomId.size() > size_t((_symptomIdSize - 1)))
44 {
45 _symptomId.resize(_symptomIdSize - 1);
46 }
47
48 // null terminate new symptom Id (it may have been smaller)
49 _symptomId.push_back(0);
50
51 // pad if new symptom ID (it may have been smaller)
52 while ((_symptomId.size() != _symptomIdSize))
53 {
54 _symptomId.push_back(0);
55 }
56}
57
58} // namespace pel
59} // namespace attn