DESERT 3.5.1
Loading...
Searching...
No Matches
uwsc-rovctr-module.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2024 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
39#include "uwsc-rovctr-module.h"
40#include <iostream>
41
42#define HDR_UWROV_MONITORING(p) (hdr_uwROV_monitoring::access(p))
43
47static class UwSCROVCtrModuleClass : public TclClass {
48public:
49
53 UwSCROVCtrModuleClass() : TclClass("Module/UW/SC/CTR") {
54 }
55
60 TclObject* create(int, const char*const*) {
61 return (new UwSCROVCtrModule());
62 }
64
67 , leader_id(0)
68 , rov_status(false)
69{
70}
71
72int UwSCROVCtrModule::command(int argc, const char*const* argv) {
73 Tcl& tcl = Tcl::instance();
74 if (argc == 3){
75 if (strcasecmp(argv[1], "setLeaderId") == 0) {
76 leader_id = std::atoi(argv[2]);
77
78 tcl.resultf("%s", "leader_id Setted\n");
79
80 return TCL_OK;
81 }
82 } else if(argc == 5){
83 if (strcasecmp(argv[1], "sendPosition") == 0) {
84 if (!rov_status)
85 {
86 newX = std::atof(argv[2]);
87 newY = std::atof(argv[3]);
88 newZ = std::atof(argv[4]);
89
92
93 tcl.resultf("%s", "position Setted");
94 }
95 return TCL_OK;
96 }
97 } else if(argc == 6){
98 if (strcasecmp(argv[1], "sendPosition") == 0) {
99 if (!rov_status)
100 {
101 newX = std::atof(argv[2]);
102 newY = std::atof(argv[3]);
103 newZ = std::atof(argv[4]);
104 speed = std::atof(argv[5]);
105
108
109 tcl.resultf("%s", "position Setted");
110 }
111 return TCL_OK;
112 }
113 }
114
115 return UwROVCtrModule::command(argc,argv);
116}
117
118void
121 Position temp_rov_position = Position();
122 temp_rov_position.setX(monitoring->x());
123 temp_rov_position.setY(monitoring->y());
124 temp_rov_position.setZ(monitoring->z());
125
127 m.setRovPosition(&temp_rov_position);
128 sendSyncClMsg(&m);
129
130 if (debug_)
131 std::cout << NOW << " UwSCROVCtrModule::recv(Packet *p) ROV monitoring "
132 << "(" << m.getSource() << ")"
133 << " position: X = " << temp_rov_position.getX()
134 << ", Y = " << temp_rov_position.getY()
135 << ", Z = " << temp_rov_position.getZ() << std::endl;
136
138}
139
140int
142{
143 if (m->type() == CLMSG_MC2CTR_SETPOS)
144 {
145 Position* p = ((ClMsgMc2CtrPosition*)m)->getRovDestination();
146 newX = p->getX();
147 newY = p->getY();
148 newZ = p->getZ();
149
150 rov_status = true;
151
154
155 if (debug_)
156 std::cout << NOW << " UwSCROVCtrModule::recvSyncClMsg(ClMessage* m)"
157 << " Set new destination of ROV " << m->getDest()
158 << " to position: X = " << newX << ", Y = " << newY
159 << ", Z = " << newZ << std::endl;
160
161 return 0;
162 }
163 else if (m->type() == CLMSG_MC2CTR_SETSTATUS)
164 {
165 rov_status = ((ClMsgMc2CtrStatus*)m)->getRovStatus();
166
167 if (debug_)
168 std::cout << NOW << " UwSCROVCtrModule::recvSyncClMsg(ClMessage* m)"
169 << " Mine detected at position: X = " << x_rov
170 << ", Y = " << y_rov << ", Z = " << z_rov
171 << " is removed " << std::endl;
172
173 return 0;
174 }
175
176 return UwCbrModule::recvSyncClMsg(m);
177}
ClMessage_t CLMSG_MC2CTR_SETPOS
ClMessage_t CLMSG_MC2CTR_SETSTATUS
Class that manages cross layer messages that require the position of the ROV follower.
Definition uwsc-clmsg.h:62
void setRovPosition(Position *position)
Sets the ROV follower position.
Definition uwsc-clmsg.cc:54
Class that manages cross layer messages that require the new destination of the ROV follower.
Definition uwsc-clmsg.h:103
Class that manages cross layer messages that require the status of the ROV follower.
Definition uwsc-clmsg.h:145
int debug_
Flag to enable several levels of debug.
UwROVCtrModule class is used to manage UWROVCtr packets and to collect statistics about them.
float y_rov
Y of the last ROV position monitored.
Packet * p
Sequence number of the last control packet sent.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
float x_rov
X of the last ROV position monitored.
float newY
Y of the new position sent to the ROV.
float newZ
Z of the new position sent to the ROV.
float z_rov
Z of the last ROV position monitored.
float newX
X of the new position sent to the ROV.
void reset_retx()
Reset retransmissions.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
virtual void transmit()
Creates and transmits a packet.
float speed
Moving speed sent to the ROV.
Class that represents the binding with the tcl configuration script.
UwSCROVCtrModuleClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwSCROVCtrModule class adds to the UwROVCtrModule class the possibility to receive and send cross lay...
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
bool rov_status
Status of the ROV follower, true if detected a mine.
int leader_id
Id of the Mission Coordinator module.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
virtual int recvSyncClMsg(ClMessage *m) override
Recv syncronous cross layer messages to require an operation from another module.
UwSCROVCtrModule()
Constructor of UwSCROVCtrModule class.
hdr_uwROV_monitoring describes UWROV_monitoring packets sent by the ROV to the base station for monit...
#define HDR_UWROV_MONITORING(p)
UwSCROVCtrModuleClass class_module_uwROV_ctr
Provides the definition of the class UWSCROVCTR.