motoman_read_single_io_reply.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2016, Delft Robotics Institute
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  *  * Neither the name of the Delft Robotics Institute, nor the names
00016  *    of its contributors may be used to endorse or promote products derived
00017  *    from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  * \author G.A. vd. Hoorn (TU Delft Robotics Institute)
00032  */
00033 
00034 #include <string>
00035 #ifdef ROS
00036 #include "motoman_driver/simple_message/motoman_read_single_io.h"
00037 #include "motoman_driver/simple_message/motoman_read_single_io_reply.h"
00038 #include "simple_message/shared_types.h"
00039 #include "simple_message/log_wrapper.h"
00040 #endif
00041 
00042 #ifdef MOTOPLUS
00043 #include "motoman_read_single_io.h"
00044 #include "motoman_read_single_io_reply.h"
00045 #include "shared_types.h"
00046 #include "log_wrapper.h"
00047 #endif
00048 
00049 using industrial::shared_types::shared_int;
00050 namespace ReadSingleIOReplyResults = motoman::simple_message::io_ctrl_reply::ReadSingleIOReplyResults;
00051 
00052 namespace motoman
00053 {
00054 namespace simple_message
00055 {
00056 namespace io_ctrl_reply
00057 {
00058 
00059 ReadSingleIOReply::ReadSingleIOReply(void)
00060 {
00061   this->init();
00062 }
00063 ReadSingleIOReply::~ReadSingleIOReply(void)
00064 {
00065 }
00066 
00067 void ReadSingleIOReply::init()
00068 {
00069   // TODO: is '0' a good initial value?
00070   this->init(0/*value*/, ReadSingleIOReplyResults::SUCCESS);
00071 }
00072 
00073 void ReadSingleIOReply::init(shared_int value, ReadSingleIOReplyResult result_code)
00074 {
00075   this->setValue(value);
00076   this->setResultCode(result_code);
00077 }
00078 
00079 std::string ReadSingleIOReply::getResultString(shared_int result_code)
00080 {
00081   switch (result_code)
00082   {
00083   case ReadSingleIOReplyResults::FAILURE:
00084     return "Failed";
00085   case ReadSingleIOReplyResults::SUCCESS:
00086     return "Success";
00087   default:
00088     return "Unknown";
00089   }
00090 }
00091 
00092 void ReadSingleIOReply::copyFrom(ReadSingleIOReply &src)
00093 {
00094   this->setValue(src.getValue());
00095   this->setResultCode(src.getResultCode());
00096 }
00097 
00098 bool ReadSingleIOReply::operator==(ReadSingleIOReply &rhs)
00099 {
00100   bool rslt = this->value_ == rhs.value_ &&
00101               this->result_code_ == rhs.result_code_;
00102 
00103   return rslt;
00104 }
00105 
00106 bool ReadSingleIOReply::load(industrial::byte_array::ByteArray *buffer)
00107 {
00108   LOG_COMM("Executing ReadSingleIOReply load");
00109 
00110   if (!buffer->load(this->value_))
00111   {
00112     LOG_ERROR("Failed to load ReadSingleIOReply value");
00113     return false;
00114   }
00115 
00116   if (!buffer->load(this->result_code_))
00117   {
00118     LOG_ERROR("Failed to load ReadSingleIOReply result_code");
00119     return false;
00120   }
00121 
00122   LOG_COMM("ReadSingleIOReply data successfully loaded");
00123   return true;
00124 }
00125 
00126 bool ReadSingleIOReply::unload(industrial::byte_array::ByteArray *buffer)
00127 {
00128   LOG_COMM("Executing ReadSingleIOReply unload");
00129 
00130   if (!buffer->unload(this->result_code_))
00131   {
00132     LOG_ERROR("Failed to unload ReadSingleIOReply result_code");
00133     return false;
00134   }
00135 
00136   if (!buffer->unload(this->value_))
00137   {
00138     LOG_ERROR("Failed to unload ReadSingleIOReply value");
00139     return false;
00140   }
00141 
00142   LOG_COMM("ReadSingleIOReply data successfully unloaded");
00143   return true;
00144 }
00145 
00146 }  // namespace io_ctrl_reply
00147 }  // namespace simple_message
00148 }  // namespace motoman


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute)
autogenerated on Sat Jun 8 2019 19:06:58