measurement_report_test.cpp
Go to the documentation of this file.
1 
27 #include <gtest/gtest.h>
28 #include <boost/asio.hpp>
29 
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 MeasurementReportTest : public ::testing ::Test
42 {
43 };
44 
45 TEST_F(MeasurementReportTest, test_deserialize)
46 {
47  EIP_BYTE d[56 + 2000];
48 
49  // use a measurement report header to serialize the header data
51  mrh.scan_count = 0xDEADBEEF;
52  mrh.scan_rate = 40000;
53  mrh.scan_timestamp = 0x55AA55AA;
54  mrh.scan_beam_period = 43333;
55  mrh.machine_state = 3;
56  mrh.machine_stop_reasons = 7;
57  mrh.active_zone_set = 0x45;
58  mrh.zone_inputs = 0xAA;
59  mrh.detection_zone_status = 0x0F;
60  mrh.output_status = 7;
61  mrh.input_status = 3;
62  mrh.display_status = 0x0402;
63  mrh.non_safety_config_checksum = 0x55AA;
64  mrh.safety_config_checksum = 0x5AA5;
65  mrh.range_report_format = 1;
67  mrh.num_beams = 1000;
68 
69  BufferWriter writer(buffer(d));
70  mrh.serialize(writer);
71 
72  for (EIP_UINT i = 10000; i < 10000 + 1000; ++i)
73  {
74  writer.write(i);
75  }
76 
77  ASSERT_EQ(sizeof(d), writer.getByteCount());
78 
79  BufferReader reader(buffer(d));
81  mr.deserialize(reader);
82  EXPECT_EQ(sizeof(d), reader.getByteCount());
83 
84  EXPECT_EQ(0xDEADBEEF, mr.header.scan_count);
85  EXPECT_EQ(40000, mr.header.scan_rate);
86  EXPECT_EQ(0x55AA55AA, mr.header.scan_timestamp);
87  EXPECT_EQ(43333, mr.header.scan_beam_period);
88  EXPECT_EQ(3, mr.header.machine_state);
89  EXPECT_EQ(7, mr.header.machine_stop_reasons);
90  EXPECT_EQ(0x45, mr.header.active_zone_set);
91  EXPECT_EQ(0xAA, mr.header.zone_inputs);
92  EXPECT_EQ(0x0F, mr.header.detection_zone_status);
93  EXPECT_EQ(7, mr.header.output_status);
94  EXPECT_EQ(3, mr.header.input_status);
95  EXPECT_EQ(0x0402, mr.header.display_status);
96  EXPECT_EQ(0x55AA, mr.header.non_safety_config_checksum);
97  EXPECT_EQ(0x5AA5, mr.header.safety_config_checksum);
98  EXPECT_EQ(1, mr.header.range_report_format);
99  EXPECT_EQ(1, mr.header.refletivity_report_format);
100  EXPECT_EQ(1000, mr.header.num_beams);
101 
102  EXPECT_EQ(1000, mr.measurement_data.size());
103  for (int i = 0; i < mr.measurement_data.size(); ++i)
104  {
105  EXPECT_EQ(i + 10000, mr.measurement_data[i]);
106  }
107 }
108 
110 {
112  mr.header.scan_count = 0xDEADBEEF;
113  mr.header.scan_rate = 40000;
114  mr.header.scan_timestamp = 0x55AA55AA;
115  mr.header.scan_beam_period = 43333;
116  mr.header.machine_state = 3;
118  mr.header.active_zone_set = 0x45;
119  mr.header.zone_inputs = 0xAA;
120  mr.header.detection_zone_status = 0x0F;
121  mr.header.output_status = 7;
122  mr.header.input_status = 3;
123  mr.header.display_status = 0x0402;
125  mr.header.safety_config_checksum = 0x5AA5;
128  mr.header.num_beams = 1000;
129 
130  mr.measurement_data.resize(1000);
131  for (int i = 0; i < 1000; ++i)
132  {
133  mr.measurement_data[i] = i + 30000;
134  }
135 
136  EIP_BYTE d[56 + 2000];
137  EXPECT_EQ(sizeof(d), mr.getLength());
138  BufferWriter writer(buffer(d));
139  mr.serialize(writer);
140  EXPECT_EQ(sizeof(d), writer.getByteCount());
141 
142  EXPECT_EQ(d[0], 0xEF);
143  EXPECT_EQ(d[1], 0xBE);
144  EXPECT_EQ(d[2], 0xAD);
145  EXPECT_EQ(d[3], 0xDE);
146  EXPECT_EQ(d[4], 0x40);
147  EXPECT_EQ(d[5], 0x9C);
148  EXPECT_EQ(d[6], 0);
149  EXPECT_EQ(d[7], 0);
150  EXPECT_EQ(d[8], 0xAA);
151  EXPECT_EQ(d[9], 0x55);
152  EXPECT_EQ(d[10], 0xAA);
153  EXPECT_EQ(d[11], 0x55);
154  EXPECT_EQ(d[12], 0x45);
155  EXPECT_EQ(d[13], 0xA9);
156  EXPECT_EQ(d[14], 0);
157  EXPECT_EQ(d[15], 0);
158  EXPECT_EQ(d[16], 3);
159  EXPECT_EQ(d[17], 0);
160  EXPECT_EQ(d[18], 7);
161  EXPECT_EQ(d[19], 0);
162  EXPECT_EQ(d[20], 0x45);
163  EXPECT_EQ(d[21], 0);
164  EXPECT_EQ(d[22], 0xAA);
165  EXPECT_EQ(d[23], 0);
166  EXPECT_EQ(d[24], 0x0F);
167  EXPECT_EQ(d[25], 0);
168  EXPECT_EQ(d[26], 0x07);
169  EXPECT_EQ(d[27], 0);
170  EXPECT_EQ(d[28], 0x03);
171  EXPECT_EQ(d[29], 0);
172  EXPECT_EQ(d[30], 0x02);
173  EXPECT_EQ(d[31], 0x04);
174  EXPECT_EQ(d[32], 0xAA);
175  EXPECT_EQ(d[33], 0x55);
176  EXPECT_EQ(d[34], 0xA5);
177  EXPECT_EQ(d[35], 0x5A);
178  EXPECT_EQ(d[36], 0);
179  EXPECT_EQ(d[37], 0);
180  EXPECT_EQ(d[38], 0);
181  EXPECT_EQ(d[39], 0);
182  EXPECT_EQ(d[40], 0);
183  EXPECT_EQ(d[41], 0);
184  EXPECT_EQ(d[42], 0);
185  EXPECT_EQ(d[43], 0);
186  EXPECT_EQ(d[44], 0);
187  EXPECT_EQ(d[45], 0);
188  EXPECT_EQ(d[46], 0);
189  EXPECT_EQ(d[47], 0);
190  EXPECT_EQ(d[48], 1);
191  EXPECT_EQ(d[49], 0);
192  EXPECT_EQ(d[50], 1);
193  EXPECT_EQ(d[51], 0);
194  EXPECT_EQ(d[52], 0);
195  EXPECT_EQ(d[53], 0);
196  EXPECT_EQ(d[54], 0xE8);
197  EXPECT_EQ(d[55], 0x03);
198 
199  for (int i = 0; i < 1000; ++i)
200  {
201  EIP_UINT exp_value = i + 30000;
202  EXPECT_EQ((exp_value)&0x00FF, d[56 + i * 2]);
203  EXPECT_EQ((exp_value >> 8) & 0x00FF, d[56 + i * 2 + 1]);
204  }
205 }
d
void write(const T &v)
TEST_F(MeasurementReportTest, test_deserialize)
uint8_t EIP_BYTE
uint16_t EIP_UINT
virtual Writer & serialize(Writer &writer) const
virtual Writer & serialize(Writer &writer) const
virtual Reader & deserialize(Reader &reader, size_t length)


omron_os32c_driver
Author(s): Kareem Shehata
autogenerated on Fri Nov 27 2020 03:06:12