-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcan_NAME.cpp
161 lines (138 loc) · 3.87 KB
/
can_NAME.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//================================================================================================
/// @file can_NAME.cpp
///
/// @brief A class that represents a control function's NAME
/// @author Adrian Del Grosso
///
/// @copyright 2022 The Open-Agriculture Developers
//================================================================================================
#include "can_NAME.hpp"
#include "can_stack_logger.hpp"
namespace isobus
{
NAME::NAME(std::uint64_t rawNAMEData) :
rawName(rawNAMEData)
{
}
bool NAME::operator==(const NAME &obj) const
{
return this->rawName == obj.rawName;
}
bool NAME::get_arbitrary_address_capable() const
{
return (0 != (rawName >> 63));
}
void NAME::set_arbitrary_address_capable(bool value)
{
rawName &= ~(static_cast<std::uint64_t>(1) << 63);
rawName |= (static_cast<std::uint64_t>(value) << 63);
}
std::uint8_t NAME::get_industry_group() const
{
return ((rawName >> 60) & 0x07);
}
void NAME::set_industry_group(std::uint8_t value)
{
if (value > 0x07)
{
LOG_ERROR("[NAME]: Industry group out of range, must be between 0 and 7");
}
rawName &= ~static_cast<std::uint64_t>(0x7000000000000000);
rawName |= (static_cast<std::uint64_t>(value & 0x07) << 60);
}
std::uint8_t NAME::get_device_class_instance() const
{
return ((rawName >> 56) & 0x0F);
}
void NAME::set_device_class_instance(std::uint8_t value)
{
if (value > 0x0F)
{
LOG_ERROR("[NAME]: Device class instance out of range, must be between 0 and 15");
}
rawName &= ~static_cast<std::uint64_t>(0xF00000000000000);
rawName |= (static_cast<std::uint64_t>(value & 0x0F) << 56);
}
std::uint8_t NAME::get_device_class() const
{
return ((rawName >> 49) & 0x7F);
}
void NAME::set_device_class(std::uint8_t value)
{
if (value > 0x7F)
{
LOG_ERROR("[NAME]: Device class out of range, must be between 0 and 127");
}
rawName &= ~static_cast<std::uint64_t>(0xFE000000000000);
rawName |= (static_cast<std::uint64_t>(value & 0x7F) << 49);
}
std::uint8_t NAME::get_function_code() const
{
return ((rawName >> 40) & 0xFF);
}
void NAME::set_function_code(std::uint8_t value)
{
rawName &= ~static_cast<std::uint64_t>(0xFF0000000000);
rawName |= (static_cast<std::uint64_t>(value & 0xFF) << 40);
}
std::uint8_t NAME::get_function_instance() const
{
return ((rawName >> 35) & 0x1F);
}
void NAME::set_function_instance(std::uint8_t value)
{
if (value > 0x1F)
{
LOG_ERROR("[NAME]: Function instance out of range, must be between 0 and 31");
}
rawName &= ~static_cast<std::uint64_t>(0xF800000000);
rawName |= (static_cast<std::uint64_t>(value & 0x1F) << 35);
}
std::uint8_t NAME::get_ecu_instance() const
{
return ((rawName >> 32) & 0x07);
}
void NAME::set_ecu_instance(std::uint8_t value)
{
if (value > 0x07)
{
LOG_ERROR("[NAME]: ECU instance out of range, must be between 0 and 7");
}
rawName &= ~static_cast<std::uint64_t>(0x700000000);
rawName |= (static_cast<std::uint64_t>(value & 0x07) << 32);
}
std::uint16_t NAME::get_manufacturer_code() const
{
return ((rawName >> 21) & 0x07FF);
}
void NAME::set_manufacturer_code(std::uint16_t value)
{
if (value > 0x07FF)
{
LOG_ERROR("[NAME]: Manufacturer code out of range, must be between 0 and 2047");
}
rawName &= ~static_cast<std::uint64_t>(0xFFE00000);
rawName |= (static_cast<std::uint64_t>(value & 0x07FF) << 21);
}
std::uint32_t NAME::get_identity_number() const
{
return (rawName & 0x001FFFFF);
}
void NAME::set_identity_number(uint32_t value)
{
if (value > 0x001FFFFF)
{
LOG_ERROR("[NAME]: Identity number out of range, must be between 0 and 2097151");
}
rawName &= ~static_cast<std::uint64_t>(0x1FFFFF);
rawName |= static_cast<std::uint64_t>(value & 0x1FFFFF);
}
std::uint64_t NAME::get_full_name() const
{
return rawName;
}
void NAME::set_full_name(std::uint64_t value)
{
rawName = value;
}
} // namespace isobus