measurement_report_test.cpp
Go to the documentation of this file.
00001 
00027 #include <gtest/gtest.h>
00028 #include <boost/asio.hpp>
00029 
00030 #include "omron_os32c_driver/measurement_report.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 MeasurementReportTest : public :: testing :: Test
00042 {
00043 
00044 };
00045 
00046 TEST_F(MeasurementReportTest, test_deserialize)
00047 {
00048   EIP_BYTE d[56 + 2000];
00049 
00050   // use a measurement report header to serialize the header data
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   ASSERT_EQ(sizeof(d), writer.getByteCount());
00078 
00079   BufferReader reader(buffer(d));
00080   MeasurementReport mr;
00081   mr.deserialize(reader);
00082   EXPECT_EQ(sizeof(d), reader.getByteCount());
00083 
00084   EXPECT_EQ(0xDEADBEEF, mr.header.scan_count);
00085   EXPECT_EQ(40000, mr.header.scan_rate);
00086   EXPECT_EQ(0x55AA55AA, mr.header.scan_timestamp);
00087   EXPECT_EQ(43333, mr.header.scan_beam_period);
00088   EXPECT_EQ(3, mr.header.machine_state);
00089   EXPECT_EQ(7, mr.header.machine_stop_reasons);
00090   EXPECT_EQ(0x45, mr.header.active_zone_set);
00091   EXPECT_EQ(0xAA, mr.header.zone_inputs);
00092   EXPECT_EQ(0x0F, mr.header.detection_zone_status);
00093   EXPECT_EQ(7, mr.header.output_status);
00094   EXPECT_EQ(3, mr.header.input_status);
00095   EXPECT_EQ(0x0402, mr.header.display_status);
00096   EXPECT_EQ(0x55AA, mr.header.non_safety_config_checksum);
00097   EXPECT_EQ(0x5AA5, mr.header.safety_config_checksum);
00098   EXPECT_EQ(1, mr.header.range_report_format);
00099   EXPECT_EQ(1, mr.header.refletivity_report_format);
00100   EXPECT_EQ(1000, mr.header.num_beams);
00101 
00102   EXPECT_EQ(1000, mr.measurement_data.size());
00103   for (int i = 0; i < mr.measurement_data.size(); ++i)
00104   {
00105     EXPECT_EQ(i + 10000, mr.measurement_data[i]);
00106   }
00107 }
00108 
00109 TEST_F(MeasurementReportTest, test_serialize)
00110 {
00111   MeasurementReport mr;
00112   mr.header.scan_count = 0xDEADBEEF;
00113   mr.header.scan_rate = 40000;
00114   mr.header.scan_timestamp = 0x55AA55AA;
00115   mr.header.scan_beam_period = 43333;
00116   mr.header.machine_state = 3;
00117   mr.header.machine_stop_reasons = 7;
00118   mr.header.active_zone_set = 0x45;
00119   mr.header.zone_inputs = 0xAA;
00120   mr.header.detection_zone_status = 0x0F;
00121   mr.header.output_status = 7;
00122   mr.header.input_status = 3;
00123   mr.header.display_status = 0x0402;
00124   mr.header.non_safety_config_checksum = 0x55AA;
00125   mr.header.safety_config_checksum = 0x5AA5;
00126   mr.header.range_report_format = 1;
00127   mr.header.refletivity_report_format = 1;
00128   mr.header.num_beams = 1000;
00129 
00130   mr.measurement_data.resize(1000);
00131   for (int i = 0; i <  1000; ++i) {
00132     mr.measurement_data[i] = i + 30000;
00133   }
00134 
00135   EIP_BYTE d[56 + 2000];
00136   EXPECT_EQ(sizeof(d), mr.getLength());
00137   BufferWriter writer(buffer(d));
00138   mr.serialize(writer);
00139   EXPECT_EQ(sizeof(d), writer.getByteCount());
00140 
00141   EXPECT_EQ(d[0], 0xEF);
00142   EXPECT_EQ(d[1], 0xBE);
00143   EXPECT_EQ(d[2], 0xAD);
00144   EXPECT_EQ(d[3], 0xDE);
00145   EXPECT_EQ(d[4], 0x40);
00146   EXPECT_EQ(d[5], 0x9C);
00147   EXPECT_EQ(d[6], 0);
00148   EXPECT_EQ(d[7], 0);
00149   EXPECT_EQ(d[8], 0xAA);
00150   EXPECT_EQ(d[9], 0x55);
00151   EXPECT_EQ(d[10], 0xAA);
00152   EXPECT_EQ(d[11], 0x55);
00153   EXPECT_EQ(d[12], 0x45);
00154   EXPECT_EQ(d[13], 0xA9);
00155   EXPECT_EQ(d[14], 0);
00156   EXPECT_EQ(d[15], 0);
00157   EXPECT_EQ(d[16], 3);
00158   EXPECT_EQ(d[17], 0);
00159   EXPECT_EQ(d[18], 7);
00160   EXPECT_EQ(d[19], 0);
00161   EXPECT_EQ(d[20], 0x45);
00162   EXPECT_EQ(d[21], 0);
00163   EXPECT_EQ(d[22], 0xAA);
00164   EXPECT_EQ(d[23], 0);
00165   EXPECT_EQ(d[24], 0x0F);
00166   EXPECT_EQ(d[25], 0);
00167   EXPECT_EQ(d[26], 0x07);
00168   EXPECT_EQ(d[27], 0);
00169   EXPECT_EQ(d[28], 0x03);
00170   EXPECT_EQ(d[29], 0);
00171   EXPECT_EQ(d[30], 0x02);
00172   EXPECT_EQ(d[31], 0x04);
00173   EXPECT_EQ(d[32], 0xAA);
00174   EXPECT_EQ(d[33], 0x55);
00175   EXPECT_EQ(d[34], 0xA5);
00176   EXPECT_EQ(d[35], 0x5A);
00177   EXPECT_EQ(d[36], 0);
00178   EXPECT_EQ(d[37], 0);
00179   EXPECT_EQ(d[38], 0);
00180   EXPECT_EQ(d[39], 0);
00181   EXPECT_EQ(d[40], 0);
00182   EXPECT_EQ(d[41], 0);
00183   EXPECT_EQ(d[42], 0);
00184   EXPECT_EQ(d[43], 0);
00185   EXPECT_EQ(d[44], 0);
00186   EXPECT_EQ(d[45], 0);
00187   EXPECT_EQ(d[46], 0);
00188   EXPECT_EQ(d[47], 0);
00189   EXPECT_EQ(d[48], 1);
00190   EXPECT_EQ(d[49], 0);
00191   EXPECT_EQ(d[50], 1);
00192   EXPECT_EQ(d[51], 0);
00193   EXPECT_EQ(d[52], 0);
00194   EXPECT_EQ(d[53], 0);
00195   EXPECT_EQ(d[54], 0xE8);
00196   EXPECT_EQ(d[55], 0x03);
00197 
00198   for (int i = 0; i < 1000; ++i)
00199   {
00200     EIP_UINT exp_value = i + 30000;
00201     EXPECT_EQ((exp_value) & 0x00FF, d[56 + i*2]);
00202     EXPECT_EQ((exp_value >> 8) & 0x00FF, d[56 + i*2 + 1]);
00203   }
00204 }


omron_os32c_driver
Author(s): Kareem Shehata
autogenerated on Thu Jun 6 2019 19:00:54