-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCardMsgCodec.cpp
More file actions
32 lines (27 loc) · 860 Bytes
/
CCardMsgCodec.cpp
File metadata and controls
32 lines (27 loc) · 860 Bytes
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
#include "CCardMsgCodec.h"
namespace IrvCS
{
/**
* Create the DSA command data with programmer-friendly API.
* @param cmd the command to execute
* @param id The ID of the device to execute the command on
* @return 0 for success, nonzero otherwise
**/
uint8_t CCardMsgCodec::
encodeMsgData(const uint8_t msgType, const uint8_t id, const uint8_t cmd,
uint32_t &data)
{
data = id;
data |= (cmd<<MSG_CMD_OFFSET_BITS) | (msgType<<MSG_TYPE_OFFSET_BITS);
return 0;
}
uint8_t CCardMsgCodec::
decodeMsgData(const uint32_t data,
uint8_t &msgType, uint8_t &id, uint8_t &cmd)
{
msgType = (data>>MSG_TYPE_OFFSET_BITS) & 0xFF;
cmd = (data>>MSG_CMD_OFFSET_BITS) & 0xFF; // command is in the higher bit
id = data & 0xFF; // filter out the higher bits
return 0;
}
}