-
Notifications
You must be signed in to change notification settings - Fork 3
/
V2VService.hpp
63 lines (50 loc) · 1.83 KB
/
V2VService.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef V2V_PROTOCOL_DEMO_V2VSERVICE_H
#define V2V_PROTOCOL_DEMO_V2VSERVICE_H
#include <iomanip>
#include <unistd.h>
#include <sys/time.h>
#include "cluon/OD4Session.hpp"
#include "cluon/UDPSender.hpp"
#include "cluon/UDPReceiver.hpp"
#include "cluon/Envelope.hpp"
#include "Messages.hpp"
#include <iostream>
/** ADD YOUR CAR_IP AND GROUP_ID HERE: *****************/
static const std::string YOUR_CAR_IP = "172.20.10.6";
static const std::string YOUR_GROUP_ID = "2";
/********************************************************/
/** DON'T CHANGE STUFF BELOW THIS LINE. *****************/
/********************************************************/
static const int BROADCAST_CHANNEL = 250;
static const int DEFAULT_PORT = 50001;
static const int ANNOUNCE_PRESENCE = 1001;
static const int FOLLOW_REQUEST = 1002;
static const int FOLLOW_RESPONSE = 1003;
static const int STOP_FOLLOW = 1004;
static const int LEADER_STATUS = 2001;
static const int FOLLOWER_STATUS = 3001;
class V2VService {
public:
std::map <std::string, std::string> presentCars;
V2VService();
void announcePresence();
void followRequest(std::string vehicleIp);
void followResponse();
void stopFollow(std::string vehicleIp);
void leaderStatus(float speed, float steeringAngle, uint8_t distanceTraveled);
void followerStatus();
private:
std::string leaderIp;
std::string followerIp;
std::shared_ptr<cluon::OD4Session> broadcast;
std::shared_ptr<cluon::UDPReceiver> incoming;
std::shared_ptr<cluon::UDPSender> toLeader;
std::shared_ptr<cluon::UDPSender> toFollower;
static uint32_t getTime();
static std::pair<int16_t, std::string> extract(std::string data);
template <class T>
static std::string encode(T msg);
template <class T>
static T decode(std::string data);
};
#endif //V2V_PROTOCOL_DEMO_V2VSERVICE_H