DESERT 3.5.1
Loading...
Searching...
No Matches
uwsc-tracker-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
38#include "uwsc-tracker-module.h"
39#include "uwsc-clmsg.h"
41#include <iostream>
42
43#define HDR_UWTRACK(p) (hdr_uwTracker::access(p))
44
48static class UwSCTrackerModuleClass : public TclClass
49{
50public:
55 : TclClass("Module/UW/SC/TRACKER")
56 {
57 }
58
63 TclObject *
64 create(int, const char *const *)
65 {
66 return (new UwSCTrackerModule());
67 }
69
72 , leader_id(0)
73 , tracked_mines()
74{
75}
76
77int
78UwSCTrackerModule::command(int argc, const char *const *argv)
79{
80 Tcl &tcl = Tcl::instance();
81
82 if (argc == 3) {
83 if (strcasecmp(argv[1], "setLeaderId") == 0) {
84 leader_id = std::atoi(argv[2]);
85
86 tcl.resultf("%s", "leader_id Setted\n");
87
88 return TCL_OK;
89 }
90 }
91 return UwTrackerModule::command(argc, argv);
92}
93
94void
96{
97 hdr_uwSCFTracker *uwscf_track_h = HDR_UWSCFTRACK(p);
98
99 if (uwscf_track_h->mine_remove()) {
101 m.setMineStatus(uwscf_track_h->mine_remove());
102 sendSyncClMsg(&m);
103
104 if (debug_)
105 std::cout << NOW << " UwSCTrackerModule::recv(Packet* p)"
106 << " ROV (" << m.getSource()
107 << ") removed current detected mine"
108 << " at position X = " << uwscf_track_h->x()
109 << " Y = " << uwscf_track_h->y()
110 << " Z = " << uwscf_track_h->z() << std::endl;
111
112 } else {
113 Position mine_position;
114 mine_position.setX(uwscf_track_h->x());
115 mine_position.setY(uwscf_track_h->y());
116 mine_position.setZ(uwscf_track_h->z());
117
118 for (auto &mine : tracked_mines)
119 if (mine.getDist(&mine_position) == 0)
120 return;
121
122 tracked_mines.emplace_back(mine_position);
123
126 sendSyncClMsg(&m);
127
128 if (debug_)
129 std::cout << NOW << " UwSCTrackerModule::recv(Packet* p)"
130 << " ROV (" << m.getSource()
131 << ") tracked a mine at position: X = "
132 << mine_position.getX()
133 << " , Y = " << mine_position.getY()
134 << " , Z = " << mine_position.getZ() << std::endl;
135 }
136
138}
Class that manages cross layer messages that require the track position of the ROV follower.
Definition uwsc-clmsg.h:187
void setTrackPosition(Position *position)
Sets the track position.
Class that manages cross layer messages that require the status of a mine tracked from a rov follower...
Definition uwsc-clmsg.h:228
void setMineStatus(bool remove)
Sets the current mine status.
int debug_
Flag to enable several levels of debug.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
Class that represents the binding with the tcl configuration script.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
UwSCTrackerModuleClass()
Constructor of the class.
UwSCTrackerModule class adds to the UwTrackerModule class the possibility to send cross layer message...
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
std::list< Position > tracked_mines
Positions of the mines tracked by the follower.
int leader_id
ID of the Tracker leader.
UwSCTrackerModule()
Default Constructor of UwSCTrackerModule class.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
UwTrackerModule class is used to track mobile nodes via sonar and share tracking information via pack...
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
hdr_uwSCFTracker describes the position and status of the current detected mine.
float & y()
Reference to the y variable.
float & x()
Reference to the x variable.
bool & mine_remove()
Reference to the speed variable.
float & z()
Reference to the z variable.
#define HDR_UWSCFTRACK(p)
UwSCTrackerModuleClass class_module_uwSCTracker
Provides the definition of the class UWSCTRACKER.