DIT168 Group9  0.9
Miniature remote-controlled vehicle using OpenDavinci and Libcluon
V2VService.hpp
1 #ifndef GROUP9_V2VSERVICE_HPP
2 #define GROUP9_V2VSERVICE_HPP
3 
4 #include <iomanip>
5 #include <unistd.h>
6 #include <sys/time.h>
7 #include "cluon/OD4Session.hpp"
8 #include "cluon/UDPSender.hpp"
9 #include "cluon/UDPReceiver.hpp"
10 #include "cluon/Envelope.hpp"
11 #include "Messages.hpp"
12 #include <iostream>
13 #include <queue>
14 
17 // static const std::string YOUR_CAR_IP = "192.168.43.157";
18 // static const std::string YOUR_GROUP_ID = "9";
19 
20 /********************************************************/
22 /********************************************************/
23 
24 static const int BROADCAST_CHANNEL = 250;
25 static const int DEFAULT_PORT = 50001;
26 
27 static const int ANNOUNCE_PRESENCE = 1001;
28 static const int FOLLOW_REQUEST = 1002;
29 static const int FOLLOW_RESPONSE = 1003;
30 static const int STOP_FOLLOW = 1004;
31 static const int LEADER_STATUS = 2001;
32 static const int FOLLOWER_STATUS = 3001;
33 
34 class V2VService {
35 public:
36  std::map <std::string, std::string> presentCars;
37 
38  V2VService(std::string ip, std::string id, std::string partnerIp, std::string partnerId,
39  std::string speed_after, std::string left, std::string right, uint16_t queue_max);
40 
41  void announcePresence();
42  void followRequest();
43  void followResponse();
44  void stopFollow(std::string vehicleIp);
45  void leaderStatus(float speed, float steeringAngle, uint8_t distanceTraveled);
46  void followerStatus();
47 
48 private:
49  static constexpr float m_OFFSET = -0.12f;
50  std::string _IP;
51  std::string _ID;
52  std::string _PARTNER_IP;
53  std::string _PARTNER_ID;
54  std::string _SPEED_AFTER;
55  std::string _LEFT;
56  std::string _RIGHT;
57  uint16_t _QUEUE_MAX;
58 
59  bool isPresentPartner = false;
60  bool isFollower = false;
61  bool isLeader = false;
62 // static constexpr float leftAngleOffset = -0.3f;
63 
64  std::string leaderIp;
65 
66  std::shared_ptr<cluon::OD4Session> broadcast;
67  std::shared_ptr<cluon::UDPReceiver> incoming;
68  std::shared_ptr<cluon::UDPSender> toLeader;
69  std::shared_ptr<cluon::UDPSender> toFollower;
70 
71  static uint32_t getTime();
72  static std::pair<int16_t, std::string> extract(std::string data);
73  template <class T>
74  static std::string encode(T msg);
75  template <class T>
76  static T decode(std::string data);
77 };
78 
79 #endif
80 
81 
void followRequest()
Definition: V2VService.cpp:264
void followerStatus()
Definition: V2VService.cpp:331
void announcePresence()
Definition: V2VService.cpp:246
void stopFollow(std::string vehicleIp)
Definition: V2VService.cpp:300
void followResponse()
Definition: V2VService.cpp:281
V2VService(std::string ip, std::string id, std::string partnerIp, std::string partnerId, std::string speed_after, std::string left, std::string right, uint16_t queue_max)
Definition: V2VService.cpp:88
void leaderStatus(float speed, float steeringAngle, uint8_t distanceTraveled)
Definition: V2VService.cpp:346