Skyward boardcore
Loading...
Searching...
No Matches
CanProtocolData.h
Go to the documentation of this file.
1/* Copyright (c) 2022 Skyward Experimental Rocketry
2 * Author: Federico Mandelli
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <stdint.h>
26
27namespace Boardcore
28{
29
30namespace Canbus
31{
32
60enum class CanProtocolIdMask : uint32_t
61{
62 PRIORITY = 0x1E000000,
63 PRIMARY_TYPE = 0x01F80000,
64 SOURCE = 0x00078000,
65 DESTINATION = 0x00007800,
66 SECONDARY_TYPE = 0x00000780,
67
68 MESSAGE_INFORMATION = 0x1FFFFF80,
69
70 FIRST_PACKET_FLAG = 0x00000040,
71 LEFT_TO_SEND = 0x0000003F,
72
73 SEQUENTIAL_INFORMATION = 0x0000007F
74};
75
77{
78 // Shift values for message informations
81 SOURCE = 15,
84
85 // Shift values for sequential informations
88
89 // Position of the message infos relative to the entire can packet id
91};
92
105{
106 int32_t id = -1;
107 uint8_t length = 0;
108 uint64_t payload[65];
109
110 uint8_t getPriority() const
111 {
112 return id >>
113 static_cast<uint8_t>(CanProtocolShiftInformation::PRIORITY);
114 }
115
116 uint8_t getPrimaryType() const
117 {
118 return (id & static_cast<uint32_t>(CanProtocolIdMask::PRIMARY_TYPE)) >>
119 static_cast<uint8_t>(CanProtocolShiftInformation::PRIMARY_TYPE);
120 }
121
122 uint8_t getSource() const
123 {
124 return (id & static_cast<uint32_t>(CanProtocolIdMask::SOURCE)) >>
125 static_cast<uint8_t>(CanProtocolShiftInformation::SOURCE);
126 }
127
128 uint8_t getDestination() const
129 {
130 return (id & static_cast<uint32_t>(CanProtocolIdMask::DESTINATION)) >>
131 static_cast<uint8_t>(CanProtocolShiftInformation::DESTINATION);
132 }
133
134 uint8_t getSecondaryType() const
135 {
136 return (id &
137 static_cast<uint32_t>(CanProtocolIdMask::SECONDARY_TYPE)) >>
138 static_cast<uint8_t>(
140 }
141};
142
143inline bool operator==(const CanMessage& lhs, const CanMessage& rhs)
144{
145 if (lhs.id != rhs.id || lhs.length != rhs.length)
146 return false;
147
148 for (int i = 0; i < lhs.length; i++)
149 if (lhs.payload[i] != rhs.payload[i])
150 return false;
151
152 return true;
153}
154
155inline bool operator!=(const CanMessage& lhs, const CanMessage& rhs)
156{
157 return !(lhs == rhs);
158}
159
160} // namespace Canbus
161
162} // namespace Boardcore
bool operator==(const CanMessage &lhs, const CanMessage &rhs)
bool operator!=(const CanMessage &lhs, const CanMessage &rhs)
CanProtocolIdMask
Masks of the elements composing can packets ids.
This file includes all the types the logdecoder script will decode.
Generic struct that contains a can protocol message.
uint8_t length
Length of the message content.