Main Page
Namespaces
Classes
Files
File List
File Members
test
measurement_report_header_test.cpp
Go to the documentation of this file.
1
27
#include <gtest/gtest.h>
28
#include <boost/asio.hpp>
29
30
#include "
omron_os32c_driver/measurement_report_header.h
"
31
#include "
odva_ethernetip/serialization/serializable_buffer.h
"
32
#include "
odva_ethernetip/serialization/buffer_writer.h
"
33
#include "
odva_ethernetip/serialization/buffer_reader.h
"
34
35
using namespace
boost::asio
;
36
using namespace
omron_os32c_driver
;
37
using namespace
eip
;
38
using namespace
eip::serialization
;
39
using namespace
boost::asio
;
40
41
class
MeasurementReportHeaderTest
:
public
::testing ::Test
42
{
43
};
44
45
TEST_F
(
MeasurementReportHeaderTest
, test_deserialize)
46
{
47
// clang-format off
48
EIP_BYTE
d
[] = {
49
// scan count
50
0xEF, 0xBE, 0xAD, 0xDE,
51
// scan rate
52
0x40, 0x9C, 0, 0,
53
// scan timestamp
54
0xAA, 0x55, 0xAA, 0x55,
55
// scan beam period
56
0x45, 0xA9, 0, 0,
57
// machine state
58
3, 0,
59
// machine stop reason
60
7, 0,
61
// active zone set
62
0x45, 0,
63
// zone inputs
64
0xAA, 0,
65
// detection zone status
66
0x0F, 0,
67
// output status
68
0x07, 0,
69
// input status
70
0x03, 0,
71
// seven segment display
72
0x02, 0x04,
73
// non-safety config checksum
74
0xAA, 0x55,
75
// safety config checksum
76
0xA5, 0x5A,
77
// reserved bytes
78
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
79
// range report format
80
1, 0,
81
// reflectivity report format
82
1, 0,
83
// reserved
84
0xFF, 0xFF,
85
// number of beams
86
0xA5, 0x02,
87
};
88
// clang-format on
89
90
BufferReader
reader(buffer(d));
91
MeasurementReportHeader
mrh;
92
mrh.
deserialize
(reader);
93
EXPECT_EQ(
sizeof
(d), reader.
getByteCount
());
94
EXPECT_EQ(
sizeof
(d), mrh.
getLength
());
95
EXPECT_EQ(0xDEADBEEF, mrh.
scan_count
);
96
EXPECT_EQ(40000, mrh.
scan_rate
);
97
EXPECT_EQ(0x55AA55AA, mrh.
scan_timestamp
);
98
EXPECT_EQ(43333, mrh.
scan_beam_period
);
99
EXPECT_EQ(3, mrh.
machine_state
);
100
EXPECT_EQ(7, mrh.
machine_stop_reasons
);
101
EXPECT_EQ(0x45, mrh.
active_zone_set
);
102
EXPECT_EQ(0xAA, mrh.
zone_inputs
);
103
EXPECT_EQ(0x0F, mrh.
detection_zone_status
);
104
EXPECT_EQ(7, mrh.
output_status
);
105
EXPECT_EQ(3, mrh.
input_status
);
106
EXPECT_EQ(0x0402, mrh.
display_status
);
107
EXPECT_EQ(0x55AA, mrh.
non_safety_config_checksum
);
108
EXPECT_EQ(0x5AA5, mrh.
safety_config_checksum
);
109
EXPECT_EQ(1, mrh.
range_report_format
);
110
EXPECT_EQ(1, mrh.
refletivity_report_format
);
111
EXPECT_EQ(677, mrh.
num_beams
);
112
}
113
114
TEST_F
(
MeasurementReportHeaderTest
, test_serialize)
115
{
116
MeasurementReportHeader
mrh;
117
mrh.
scan_count
= 0xDEADBEEF;
118
mrh.
scan_rate
= 40000;
119
mrh.
scan_timestamp
= 0x55AA55AA;
120
mrh.
scan_beam_period
= 43333;
121
mrh.
machine_state
= 3;
122
mrh.
machine_stop_reasons
= 7;
123
mrh.
active_zone_set
= 0x45;
124
mrh.
zone_inputs
= 0xAA;
125
mrh.
detection_zone_status
= 0x0F;
126
mrh.
output_status
= 7;
127
mrh.
input_status
= 3;
128
mrh.
display_status
= 0x0402;
129
mrh.
non_safety_config_checksum
= 0x55AA;
130
mrh.
safety_config_checksum
= 0x5AA5;
131
mrh.
range_report_format
= 1;
132
mrh.
refletivity_report_format
= 1;
133
mrh.
num_beams
= 677;
134
135
EIP_BYTE
d
[56];
136
EXPECT_EQ(
sizeof
(d), mrh.
getLength
());
137
BufferWriter
writer(buffer(d));
138
mrh.
serialize
(writer);
139
EXPECT_EQ(
sizeof
(d), writer.getByteCount());
140
141
EXPECT_EQ(d[0], 0xEF);
142
EXPECT_EQ(d[1], 0xBE);
143
EXPECT_EQ(d[2], 0xAD);
144
EXPECT_EQ(d[3], 0xDE);
145
EXPECT_EQ(d[4], 0x40);
146
EXPECT_EQ(d[5], 0x9C);
147
EXPECT_EQ(d[6], 0);
148
EXPECT_EQ(d[7], 0);
149
EXPECT_EQ(d[8], 0xAA);
150
EXPECT_EQ(d[9], 0x55);
151
EXPECT_EQ(d[10], 0xAA);
152
EXPECT_EQ(d[11], 0x55);
153
EXPECT_EQ(d[12], 0x45);
154
EXPECT_EQ(d[13], 0xA9);
155
EXPECT_EQ(d[14], 0);
156
EXPECT_EQ(d[15], 0);
157
EXPECT_EQ(d[16], 3);
158
EXPECT_EQ(d[17], 0);
159
EXPECT_EQ(d[18], 7);
160
EXPECT_EQ(d[19], 0);
161
EXPECT_EQ(d[20], 0x45);
162
EXPECT_EQ(d[21], 0);
163
EXPECT_EQ(d[22], 0xAA);
164
EXPECT_EQ(d[23], 0);
165
EXPECT_EQ(d[24], 0x0F);
166
EXPECT_EQ(d[25], 0);
167
EXPECT_EQ(d[26], 0x07);
168
EXPECT_EQ(d[27], 0);
169
EXPECT_EQ(d[28], 0x03);
170
EXPECT_EQ(d[29], 0);
171
EXPECT_EQ(d[30], 0x02);
172
EXPECT_EQ(d[31], 0x04);
173
EXPECT_EQ(d[32], 0xAA);
174
EXPECT_EQ(d[33], 0x55);
175
EXPECT_EQ(d[34], 0xA5);
176
EXPECT_EQ(d[35], 0x5A);
177
EXPECT_EQ(d[36], 0);
178
EXPECT_EQ(d[37], 0);
179
EXPECT_EQ(d[38], 0);
180
EXPECT_EQ(d[39], 0);
181
EXPECT_EQ(d[40], 0);
182
EXPECT_EQ(d[41], 0);
183
EXPECT_EQ(d[42], 0);
184
EXPECT_EQ(d[43], 0);
185
EXPECT_EQ(d[44], 0);
186
EXPECT_EQ(d[45], 0);
187
EXPECT_EQ(d[46], 0);
188
EXPECT_EQ(d[47], 0);
189
EXPECT_EQ(d[48], 1);
190
EXPECT_EQ(d[49], 0);
191
EXPECT_EQ(d[50], 1);
192
EXPECT_EQ(d[51], 0);
193
EXPECT_EQ(d[52], 0);
194
EXPECT_EQ(d[53], 0);
195
EXPECT_EQ(d[54], 0xA5);
196
EXPECT_EQ(d[55], 0x02);
197
}
198
199
200
TEST_F
(
MeasurementReportHeaderTest
, test_serialize_and_deserialize)
201
{
202
MeasurementReportHeader
mrh;
203
mrh.
scan_count
= 0xDEADBEEF;
204
mrh.
scan_rate
= 40000;
205
mrh.
scan_timestamp
= 0x55AA55AA;
206
mrh.
scan_beam_period
= 43333;
207
mrh.
machine_state
= 3;
208
mrh.
machine_stop_reasons
= 7;
209
mrh.
active_zone_set
= 0x45;
210
mrh.
zone_inputs
= 0xAA;
211
mrh.
detection_zone_status
= 0x0F;
212
mrh.
output_status
= 7;
213
mrh.
input_status
= 3;
214
mrh.
display_status
= 0x0402;
215
mrh.
non_safety_config_checksum
= 0x55AA;
216
mrh.
safety_config_checksum
= 0x5AA5;
217
mrh.
range_report_format
= 1;
218
mrh.
refletivity_report_format
= 1;
219
mrh.
num_beams
= 677;
220
221
EIP_BYTE
d
[56];
222
EXPECT_EQ(
sizeof
(d), mrh.
getLength
());
223
BufferWriter
writer(buffer(d));
224
mrh.
serialize
(writer);
225
EXPECT_EQ(
sizeof
(d), writer.getByteCount());
226
227
BufferReader
reader(buffer(d));
228
MeasurementReportHeader
mrh2;
229
mrh2.
deserialize
(reader);
230
EXPECT_EQ(
sizeof
(d), reader.getByteCount());
231
EXPECT_EQ(
sizeof
(d), mrh2.
getLength
());
232
EXPECT_EQ(0xDEADBEEF, mrh2.
scan_count
);
233
EXPECT_EQ(40000, mrh2.
scan_rate
);
234
EXPECT_EQ(0x55AA55AA, mrh2.
scan_timestamp
);
235
EXPECT_EQ(43333, mrh2.
scan_beam_period
);
236
EXPECT_EQ(3, mrh2.
machine_state
);
237
EXPECT_EQ(7, mrh2.
machine_stop_reasons
);
238
EXPECT_EQ(0x45, mrh2.
active_zone_set
);
239
EXPECT_EQ(0xAA, mrh2.
zone_inputs
);
240
EXPECT_EQ(0x0F, mrh2.
detection_zone_status
);
241
EXPECT_EQ(7, mrh2.
output_status
);
242
EXPECT_EQ(3, mrh2.
input_status
);
243
EXPECT_EQ(0x0402, mrh2.
display_status
);
244
EXPECT_EQ(0x55AA, mrh2.
non_safety_config_checksum
);
245
EXPECT_EQ(0x5AA5, mrh2.
safety_config_checksum
);
246
EXPECT_EQ(1, mrh2.
range_report_format
);
247
EXPECT_EQ(1, mrh2.
refletivity_report_format
);
248
EXPECT_EQ(677, mrh2.
num_beams
);
249
}
d
d
omron_os32c_driver::MeasurementReportHeader::safety_config_checksum
EIP_UINT safety_config_checksum
Definition:
measurement_report_header.h:63
buffer_writer.h
measurement_report_header.h
omron_os32c_driver::MeasurementReportHeader::non_safety_config_checksum
EIP_UINT non_safety_config_checksum
Definition:
measurement_report_header.h:62
omron_os32c_driver::MeasurementReportHeader::detection_zone_status
EIP_WORD detection_zone_status
Definition:
measurement_report_header.h:58
eip::serialization::BufferReader::getByteCount
virtual size_t getByteCount()
omron_os32c_driver::MeasurementReportHeader::refletivity_report_format
EIP_UINT refletivity_report_format
Definition:
measurement_report_header.h:65
asio
omron_os32c_driver::MeasurementReportHeader::active_zone_set
EIP_UINT active_zone_set
Definition:
measurement_report_header.h:56
omron_os32c_driver::MeasurementReportHeader::range_report_format
EIP_UINT range_report_format
Definition:
measurement_report_header.h:64
omron_os32c_driver::MeasurementReportHeader::machine_state
EIP_UINT machine_state
Definition:
measurement_report_header.h:54
omron_os32c_driver::MeasurementReportHeader::display_status
EIP_UINT display_status
Definition:
measurement_report_header.h:61
omron_os32c_driver::MeasurementReportHeader::num_beams
EIP_UINT num_beams
Definition:
measurement_report_header.h:66
omron_os32c_driver::MeasurementReportHeader::deserialize
virtual Reader & deserialize(Reader &reader, size_t length)
Definition:
measurement_report_header.h:115
omron_os32c_driver::MeasurementReportHeader::scan_rate
EIP_UDINT scan_rate
Definition:
measurement_report_header.h:51
EIP_BYTE
uint8_t EIP_BYTE
eip
omron_os32c_driver::MeasurementReportHeader::input_status
EIP_WORD input_status
Definition:
measurement_report_header.h:60
TEST_F
TEST_F(MeasurementReportHeaderTest, test_deserialize)
Definition:
measurement_report_header_test.cpp:45
eip::serialization
omron_os32c_driver::MeasurementReportHeader::scan_count
EIP_UDINT scan_count
Definition:
measurement_report_header.h:50
omron_os32c_driver::MeasurementReportHeader::serialize
virtual Writer & serialize(Writer &writer) const
Definition:
measurement_report_header.h:82
omron_os32c_driver::MeasurementReportHeader::zone_inputs
EIP_WORD zone_inputs
Definition:
measurement_report_header.h:57
omron_os32c_driver::MeasurementReportHeader::getLength
virtual size_t getLength() const
Definition:
measurement_report_header.h:71
omron_os32c_driver
Definition:
measurement_report.h:43
eip::serialization::BufferReader
omron_os32c_driver::MeasurementReportHeader::scan_timestamp
EIP_UDINT scan_timestamp
Definition:
measurement_report_header.h:52
serializable_buffer.h
MeasurementReportHeaderTest
Definition:
measurement_report_header_test.cpp:41
eip::serialization::BufferWriter
omron_os32c_driver::MeasurementReportHeader
Definition:
measurement_report_header.h:47
omron_os32c_driver::MeasurementReportHeader::output_status
EIP_WORD output_status
Definition:
measurement_report_header.h:59
omron_os32c_driver::MeasurementReportHeader::scan_beam_period
EIP_UDINT scan_beam_period
Definition:
measurement_report_header.h:53
buffer_reader.h
omron_os32c_driver::MeasurementReportHeader::machine_stop_reasons
EIP_UINT machine_stop_reasons
Definition:
measurement_report_header.h:55
omron_os32c_driver
Author(s): Kareem Shehata
autogenerated on Fri Nov 27 2020 03:06:12