00001
00027 #include <gtest/gtest.h>
00028 #include <boost/asio.hpp>
00029
00030 #include "omron_os32c_driver/measurement_report_header.h"
00031 #include "odva_ethernetip/serialization/serializable_buffer.h"
00032 #include "odva_ethernetip/serialization/buffer_writer.h"
00033 #include "odva_ethernetip/serialization/buffer_reader.h"
00034
00035 using namespace boost::asio;
00036 using namespace omron_os32c_driver;
00037 using namespace eip;
00038 using namespace eip::serialization;
00039 using namespace boost::asio;
00040
00041 class MeasurementReportHeaderTest : public :: testing :: Test
00042 {
00043
00044 };
00045
00046 TEST_F(MeasurementReportHeaderTest, test_deserialize)
00047 {
00048 EIP_BYTE d[] = {
00049
00050 0xEF, 0xBE, 0xAD, 0xDE,
00051
00052 0x40, 0x9C, 0, 0,
00053
00054 0xAA, 0x55, 0xAA, 0x55,
00055
00056 0x45, 0xA9, 0, 0,
00057
00058 3, 0,
00059
00060 7, 0,
00061
00062 0x45, 0,
00063
00064 0xAA, 0,
00065
00066 0x0F, 0,
00067
00068 0x07, 0,
00069
00070 0x03, 0,
00071
00072 0x02, 0x04,
00073
00074 0xAA, 0x55,
00075
00076 0xA5, 0x5A,
00077
00078 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
00079
00080 1, 0,
00081
00082 1, 0,
00083
00084 0xFF, 0xFF,
00085
00086 0xA5, 0x02,
00087 };
00088
00089 BufferReader reader(buffer(d));
00090 MeasurementReportHeader mrh;
00091 mrh.deserialize(reader);
00092 EXPECT_EQ(sizeof(d), reader.getByteCount());
00093 EXPECT_EQ(sizeof(d), mrh.getLength());
00094 EXPECT_EQ(0xDEADBEEF, mrh.scan_count);
00095 EXPECT_EQ(40000, mrh.scan_rate);
00096 EXPECT_EQ(0x55AA55AA, mrh.scan_timestamp);
00097 EXPECT_EQ(43333, mrh.scan_beam_period);
00098 EXPECT_EQ(3, mrh.machine_state);
00099 EXPECT_EQ(7, mrh.machine_stop_reasons);
00100 EXPECT_EQ(0x45, mrh.active_zone_set);
00101 EXPECT_EQ(0xAA, mrh.zone_inputs);
00102 EXPECT_EQ(0x0F, mrh.detection_zone_status);
00103 EXPECT_EQ(7, mrh.output_status);
00104 EXPECT_EQ(3, mrh.input_status);
00105 EXPECT_EQ(0x0402, mrh.display_status);
00106 EXPECT_EQ(0x55AA, mrh.non_safety_config_checksum);
00107 EXPECT_EQ(0x5AA5, mrh.safety_config_checksum);
00108 EXPECT_EQ(1, mrh.range_report_format);
00109 EXPECT_EQ(1, mrh.refletivity_report_format);
00110 EXPECT_EQ(677, mrh.num_beams);
00111 }
00112
00113 TEST_F(MeasurementReportHeaderTest, test_serialize)
00114 {
00115 MeasurementReportHeader mrh;
00116 mrh.scan_count = 0xDEADBEEF;
00117 mrh.scan_rate = 40000;
00118 mrh.scan_timestamp = 0x55AA55AA;
00119 mrh.scan_beam_period = 43333;
00120 mrh.machine_state = 3;
00121 mrh.machine_stop_reasons = 7;
00122 mrh.active_zone_set = 0x45;
00123 mrh.zone_inputs = 0xAA;
00124 mrh.detection_zone_status = 0x0F;
00125 mrh.output_status = 7;
00126 mrh.input_status = 3;
00127 mrh.display_status = 0x0402;
00128 mrh.non_safety_config_checksum = 0x55AA;
00129 mrh.safety_config_checksum = 0x5AA5;
00130 mrh.range_report_format = 1;
00131 mrh.refletivity_report_format = 1;
00132 mrh.num_beams = 677;
00133
00134 EIP_BYTE d[56];
00135 EXPECT_EQ(sizeof(d), mrh.getLength());
00136 BufferWriter writer(buffer(d));
00137 mrh.serialize(writer);
00138 EXPECT_EQ(sizeof(d), writer.getByteCount());
00139
00140 EXPECT_EQ(d[0], 0xEF);
00141 EXPECT_EQ(d[1], 0xBE);
00142 EXPECT_EQ(d[2], 0xAD);
00143 EXPECT_EQ(d[3], 0xDE);
00144 EXPECT_EQ(d[4], 0x40);
00145 EXPECT_EQ(d[5], 0x9C);
00146 EXPECT_EQ(d[6], 0);
00147 EXPECT_EQ(d[7], 0);
00148 EXPECT_EQ(d[8], 0xAA);
00149 EXPECT_EQ(d[9], 0x55);
00150 EXPECT_EQ(d[10], 0xAA);
00151 EXPECT_EQ(d[11], 0x55);
00152 EXPECT_EQ(d[12], 0x45);
00153 EXPECT_EQ(d[13], 0xA9);
00154 EXPECT_EQ(d[14], 0);
00155 EXPECT_EQ(d[15], 0);
00156 EXPECT_EQ(d[16], 3);
00157 EXPECT_EQ(d[17], 0);
00158 EXPECT_EQ(d[18], 7);
00159 EXPECT_EQ(d[19], 0);
00160 EXPECT_EQ(d[20], 0x45);
00161 EXPECT_EQ(d[21], 0);
00162 EXPECT_EQ(d[22], 0xAA);
00163 EXPECT_EQ(d[23], 0);
00164 EXPECT_EQ(d[24], 0x0F);
00165 EXPECT_EQ(d[25], 0);
00166 EXPECT_EQ(d[26], 0x07);
00167 EXPECT_EQ(d[27], 0);
00168 EXPECT_EQ(d[28], 0x03);
00169 EXPECT_EQ(d[29], 0);
00170 EXPECT_EQ(d[30], 0x02);
00171 EXPECT_EQ(d[31], 0x04);
00172 EXPECT_EQ(d[32], 0xAA);
00173 EXPECT_EQ(d[33], 0x55);
00174 EXPECT_EQ(d[34], 0xA5);
00175 EXPECT_EQ(d[35], 0x5A);
00176 EXPECT_EQ(d[36], 0);
00177 EXPECT_EQ(d[37], 0);
00178 EXPECT_EQ(d[38], 0);
00179 EXPECT_EQ(d[39], 0);
00180 EXPECT_EQ(d[40], 0);
00181 EXPECT_EQ(d[41], 0);
00182 EXPECT_EQ(d[42], 0);
00183 EXPECT_EQ(d[43], 0);
00184 EXPECT_EQ(d[44], 0);
00185 EXPECT_EQ(d[45], 0);
00186 EXPECT_EQ(d[46], 0);
00187 EXPECT_EQ(d[47], 0);
00188 EXPECT_EQ(d[48], 1);
00189 EXPECT_EQ(d[49], 0);
00190 EXPECT_EQ(d[50], 1);
00191 EXPECT_EQ(d[51], 0);
00192 EXPECT_EQ(d[52], 0);
00193 EXPECT_EQ(d[53], 0);
00194 EXPECT_EQ(d[54], 0xA5);
00195 EXPECT_EQ(d[55], 0x02);
00196 }
00197
00198
00199 TEST_F(MeasurementReportHeaderTest, test_serialize_and_deserialize)
00200 {
00201 MeasurementReportHeader mrh;
00202 mrh.scan_count = 0xDEADBEEF;
00203 mrh.scan_rate = 40000;
00204 mrh.scan_timestamp = 0x55AA55AA;
00205 mrh.scan_beam_period = 43333;
00206 mrh.machine_state = 3;
00207 mrh.machine_stop_reasons = 7;
00208 mrh.active_zone_set = 0x45;
00209 mrh.zone_inputs = 0xAA;
00210 mrh.detection_zone_status = 0x0F;
00211 mrh.output_status = 7;
00212 mrh.input_status = 3;
00213 mrh.display_status = 0x0402;
00214 mrh.non_safety_config_checksum = 0x55AA;
00215 mrh.safety_config_checksum = 0x5AA5;
00216 mrh.range_report_format = 1;
00217 mrh.refletivity_report_format = 1;
00218 mrh.num_beams = 677;
00219
00220 EIP_BYTE d[56];
00221 EXPECT_EQ(sizeof(d), mrh.getLength());
00222 BufferWriter writer(buffer(d));
00223 mrh.serialize(writer);
00224 EXPECT_EQ(sizeof(d), writer.getByteCount());
00225
00226 BufferReader reader(buffer(d));
00227 MeasurementReportHeader mrh2;
00228 mrh2.deserialize(reader);
00229 EXPECT_EQ(sizeof(d), reader.getByteCount());
00230 EXPECT_EQ(sizeof(d), mrh2.getLength());
00231 EXPECT_EQ(0xDEADBEEF, mrh2.scan_count);
00232 EXPECT_EQ(40000, mrh2.scan_rate);
00233 EXPECT_EQ(0x55AA55AA, mrh2.scan_timestamp);
00234 EXPECT_EQ(43333, mrh2.scan_beam_period);
00235 EXPECT_EQ(3, mrh2.machine_state);
00236 EXPECT_EQ(7, mrh2.machine_stop_reasons);
00237 EXPECT_EQ(0x45, mrh2.active_zone_set);
00238 EXPECT_EQ(0xAA, mrh2.zone_inputs);
00239 EXPECT_EQ(0x0F, mrh2.detection_zone_status);
00240 EXPECT_EQ(7, mrh2.output_status);
00241 EXPECT_EQ(3, mrh2.input_status);
00242 EXPECT_EQ(0x0402, mrh2.display_status);
00243 EXPECT_EQ(0x55AA, mrh2.non_safety_config_checksum);
00244 EXPECT_EQ(0x5AA5, mrh2.safety_config_checksum);
00245 EXPECT_EQ(1, mrh2.range_report_format);
00246 EXPECT_EQ(1, mrh2.refletivity_report_format);
00247 EXPECT_EQ(677, mrh2.num_beams);
00248 }