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