forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RxStatusResponse.cs
149 lines (127 loc) · 4.43 KB
/
RxStatusResponse.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Iot.Device.Mcp25xxx
{
/// <summary>
/// Response from RX STATUS instruction.
/// </summary>
public class RxStatusResponse
{
/// <summary>
/// Initializes a new instance of the RxStatusResponse class.
/// </summary>
/// <param name="receivedMessage">
/// RXxIF (CANINTF) bits are mapped to bits 7 and 6.</param>
/// <param name="messageTypeReceived">
/// The extended ID bit is mapped to bit 4. The RTR bit is mapped to bit 3.</param>
/// <param name="filterMatch">Filter match type</param>
public RxStatusResponse(
FilterMatchType filterMatch,
MessageReceivedType messageTypeReceived,
ReceivedMessageType receivedMessage)
{
FilterMatch = filterMatch;
MessageTypeReceived = messageTypeReceived;
ReceivedMessage = receivedMessage;
}
/// <summary>
/// Initializes a new instance of the RxStatusResponse class.
/// </summary>
/// <param name="value">The value that represents the ReceivedMessage, MessageTypeReceived and FilterMatch.</param>
public RxStatusResponse(byte value)
{
ReceivedMessage = (ReceivedMessageType)((value & 0b1100_0000) >> 6);
MessageTypeReceived = (MessageReceivedType)((value & 0b0001_1000) >> 3);
FilterMatch = (FilterMatchType)(value & 0b0000_0111);
}
/// <summary>
/// Filter match type
/// </summary>
public FilterMatchType FilterMatch { get; }
/// <summary>
/// The extended ID bit is mapped to bit 4. The RTR bit is mapped to bit 3.
/// </summary>
public MessageReceivedType MessageTypeReceived { get; }
/// <summary>
/// RXxIF (CANINTF) bits are mapped to bits 7 and 6.
/// </summary>
public ReceivedMessageType ReceivedMessage { get; }
/// <summary>
/// RXxIF (CANINTF) bits are mapped to bits 7 and 6.
/// </summary>
public enum ReceivedMessageType
{
/// <summary>
/// No RX Message.
/// </summary>
NoRxMessage = 0,
/// <summary>
/// Message in RXB0.
/// </summary>
MessageInRxB0 = 1,
/// <summary>
/// Message in RXB1.
/// </summary>
MessageInRxB1 = 2,
/// <summary>
/// Messages in Both Buffers.
/// </summary>
MessagesInBothBuffers = 3
}
/// <summary>
/// The extended ID bit is mapped to bit 4. The RTR bit is mapped to bit 3.
/// </summary>
public enum MessageReceivedType
{
/// <summary>
/// Standard Data Frame.
/// </summary>
StandardDataFrame = 0,
/// <summary>
/// Standard Remote Frame.
/// </summary>
StandardRemoteFrame = 1,
/// <summary>
/// Extended Data Frame.
/// </summary>
ExtendedDataFrame = 2,
/// <summary>
/// Extended Remote Frame.
/// </summary>
ExtendedRemoteFrame = 3
}
/// <summary>
/// Filter match type
/// </summary>
public enum FilterMatchType
{
/// <summary>RxF0</summary>
RxF0 = 0,
/// <summary>RxF1</summary>
RxF1 = 1,
/// <summary>RxF2</summary>
RxF2 = 2,
/// <summary>RxF3</summary>
RxF3 = 3,
/// <summary>RxF4</summary>
RxF4 = 4,
/// <summary>RxF5</summary>
RxF5 = 5,
/// <summary>RxF0RolloverToRxB1</summary>
RxF0RolloverToRxB1 = 6,
/// <summary>RxF1RolloverToRxB1</summary>
RxF1RolloverToRxB1 = 7,
}
/// <summary>
/// Converts contents to a byte.
/// </summary>
/// <returns>The byte that represent the response contents.</returns>
public byte ToByte()
{
byte value = (byte)((byte)ReceivedMessage << 6);
value |= (byte)((byte)MessageTypeReceived << 3);
value |= (byte)FilterMatch;
return value;
}
}
}