ping_handler.cpp
Go to the documentation of this file.
1 /*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011, Southwest Research Institute
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of the Southwest Research Institute, nor the names
16 * of its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31 #ifndef FLATHEADERS
35 #else
36 #include "ping_handler.h"
37 #include "ping_message.h"
38 #include "log_wrapper.h"
39 #endif
40 
41 using namespace industrial::ping_message;
42 using namespace industrial::simple_message;
43 
44 namespace industrial
45 {
46 namespace ping_handler
47 {
48 
49 
50 bool PingHandler::init(industrial::smpl_msg_connection::SmplMsgConnection* connection)
51 {
52  return this->init(StandardMsgTypes::PING, connection);
53 }
54 
55 bool PingHandler::internalCB(industrial::simple_message::SimpleMessage & in)
56 {
57  bool rtn = false;
58  PingMessage ping;
59  SimpleMessage msg;
60 
61  if (ping.init(in))
62  {
63  if (ping.toReply(msg, ReplyTypes::SUCCESS))
64  {
65  if(this->getConnection()->sendMsg(msg))
66  {
67  LOG_INFO("Ping return sent");
68  rtn = true;
69  }
70  else
71  {
72  LOG_ERROR("Failed to send ping return");
73  rtn = false;
74  }
75  }
76  else
77  {
78  LOG_ERROR("Failed to generate ping reply message");
79  rtn = false;
80  }
81  }
82  else
83  {
84  LOG_ERROR("Failed to initialize ping message");
85  rtn = false;
86  }
87 
88 
89  return rtn;
90 }
91 
92 
93 
94 }//namespace ping_handler
95 }//namespace industrial
96 
97 
98 
LOG_INFO
#define LOG_INFO(format,...)
Definition: log_wrapper.h:132
industrial::simple_message::ReplyTypes::SUCCESS
@ SUCCESS
Definition: simple_message.h:114
industrial
Definition: byte_array.h:45
industrial::ping_message
Definition: ping_message.h:46
LOG_ERROR
#define LOG_ERROR(format,...)
Definition: log_wrapper.h:134
ping_handler.h
ping_message.h
industrial::simple_message::SimpleMessage
This class defines a simple messaging protocol for communicating with an industrial robot controller.
Definition: simple_message.h:164
industrial::typed_message::TypedMessage::toReply
virtual bool toReply(industrial::simple_message::SimpleMessage &msg, industrial::simple_message::ReplyType reply)
creates a simple_message reply
Definition: typed_message.h:110
industrial::ping_message::PingMessage::init
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Definition: ping_message.cpp:61
industrial::simple_message
Definition: simple_message.h:49
industrial::ping_message::PingMessage
Class encapsulated ping message generation methods (either to or from a SimpleMessage type.
Definition: ping_message.h:60
log_wrapper.h
industrial::smpl_msg_connection::SmplMsgConnection
Defines an interface and common methods for sending simple messages (see simple_message)....
Definition: smpl_msg_connection.h:61
industrial::simple_message::StandardMsgTypes::PING
@ PING
Definition: simple_message.h:61
init
void init(const M_string &remappings)


simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53