Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
1#ifndef NETWORK_H
2#define NETWORK_H
3
5#include "api/network/bus.h"
7
8class Network {
9 public:
10 enum class EntityType { VEHICLE, RSU };
15
16 Network(const unsigned int id = 0, EntityType entity_type = EntityType::VEHICLE);
17 ~Network();
18
19 void stop() {
20 if (_nic)
21 _nic->stop();
22 }
23
25 CAN* bus();
26 const NIC::Address address();
27
28 // New: Set RSU manager for vehicles
30 private:
31 unsigned int _id;
32 Protocol* _protocol;
33 NIC* _nic;
34 CAN* _can;
35 EntityType _entity_type;
36};
37
38inline Network::Network(const unsigned int id, EntityType entity_type) : _id(id), _entity_type(entity_type) {
40 if (id) {
41 NIC::Address addr; // We don't set the address here anymore;
42 addr.bytes[0] = 0x02; // the NIC gets its address from the SocketEngine.
43 addr.bytes[1] = 0x00;
44 addr.bytes[2] = 0x00;
45 addr.bytes[3] = 0x00;
46 addr.bytes[4] = (id >> 8) & 0xFF;
47 addr.bytes[5] = id & 0xFF;
48 _nic->setAddress(addr);
49 }
50
51 // Pass entity type to Protocol
55 _can = new CAN();
56}
57
59 delete _can;
60 _can = nullptr;
61 delete _protocol;
62 _protocol = nullptr;
63 delete _nic;
64 _nic = nullptr;
65}
66
68 return _protocol;
69}
70
71inline CAN* Network::bus() {
72 return _can;
73}
74
76 return _nic->address();
77}
78
84
85#endif // NETWORK_H
Definition bus.h:52
Definition communicator.h:16
static NIC_T * create_nic()
Creates a network interface abstraction.
Definition initializer.h:50
static Protocol_T * create_protocol(NIC_T *nic)
Creates a protocol for system communication.
Definition initializer.h:54
Template class for network messages with Clock integration.
Definition message.h:31
Definition nic.h:28
const Address & address()
Definition nic.h:439
void setAddress(Address address)
Definition nic.h:444
void stop()
Definition nic.h:173
Definition network.h:8
void stop()
Definition network.h:19
EntityType
Definition network.h:10
Initializer::NIC_T NIC
Definition network.h:11
Initializer::Communicator_T Communicator
Definition network.h:14
CAN * bus()
Definition network.h:71
void set_vehicle_rsu_manager(VehicleRSUManager< Protocol > *manager)
Definition network.h:79
~Network()
Definition network.h:58
Initializer::Protocol_T Protocol
Definition network.h:12
Protocol * channel()
Definition network.h:67
Initializer::Message Message
Definition network.h:13
const NIC::Address address()
Definition network.h:75
Network(const unsigned int id=0, EntityType entity_type=EntityType::VEHICLE)
Definition network.h:38
Definition protocol.h:29
void set_vehicle_rsu_manager(VehicleRSUManager< Protocol< NIC > > *manager)
Definition protocol.h:1271
EntityType
Definition protocol.h:161
Definition rsu.h:17
Definition vehicleRSUManager.h:33
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition debug.h:166
Definition ethernet.h:16
std::uint8_t bytes[MAC_SIZE]
Definition ethernet.h:17