motoman_write_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_write_single_io.h"
00037 #include "motoman_driver/simple_message/motoman_write_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_write_single_io.h"
00044 #include "motoman_write_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 WriteSingleIOReplyResults = motoman::simple_message::io_ctrl_reply::WriteSingleIOReplyResults;
00051 
00052 namespace motoman
00053 {
00054 namespace simple_message
00055 {
00056 namespace io_ctrl_reply
00057 {
00058 
00059 WriteSingleIOReply::WriteSingleIOReply(void)
00060 {
00061   this->init();
00062 }
00063 WriteSingleIOReply::~WriteSingleIOReply(void)
00064 {
00065 }
00066 
00067 void WriteSingleIOReply::init()
00068 {
00069   // TODO: is success a good initial value?
00070   this->init(WriteSingleIOReplyResults::SUCCESS);
00071 }
00072 
00073 void WriteSingleIOReply::init(WriteSingleIOReplyResult result_code)
00074 {
00075   this->setResultCode(result_code);
00076 }
00077 
00078 std::string WriteSingleIOReply::getResultString(shared_int result_code)
00079 {
00080   switch (result_code)
00081   {
00082   case WriteSingleIOReplyResults::FAILURE:
00083     return "Failed";
00084   case WriteSingleIOReplyResults::SUCCESS:
00085     return "Success";
00086   default:
00087     return "Unknown";
00088   }
00089 }
00090 
00091 void WriteSingleIOReply::copyFrom(WriteSingleIOReply &src)
00092 {
00093   this->setResultCode(src.getResultCode());
00094 }
00095 
00096 bool WriteSingleIOReply::operator==(WriteSingleIOReply &rhs)
00097 {
00098   bool rslt = this->result_code_ == rhs.result_code_;
00099 
00100   return rslt;
00101 }
00102 
00103 bool WriteSingleIOReply::load(industrial::byte_array::ByteArray *buffer)
00104 {
00105   LOG_COMM("Executing WriteSingleIOReply load");
00106 
00107   if (!buffer->load(this->result_code_))
00108   {
00109     LOG_ERROR("Failed to load WriteSingleIOReply result_code");
00110     return false;
00111   }
00112 
00113   LOG_COMM("WriteSingleIOReply data successfully loaded");
00114   return true;
00115 }
00116 
00117 bool WriteSingleIOReply::unload(industrial::byte_array::ByteArray *buffer)
00118 {
00119   LOG_COMM("Executing WriteSingleIOReply unload");
00120 
00121   if (!buffer->unload(this->result_code_))
00122   {
00123     LOG_ERROR("Failed to unload WriteSingleIOReply result_code");
00124     return false;
00125   }
00126 
00127   LOG_COMM("WriteSingleIOReply data successfully unloaded");
00128   return true;
00129 }
00130 
00131 }  // namespace io_ctrl_reply
00132 }  // namespace simple_message
00133 }  // namespace motoman


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