forked from g4klx/MMDVMHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlotType.cpp
92 lines (73 loc) · 2.29 KB
/
SlotType.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
/*
* Copyright (C) 2015 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "SlotType.h"
#include "Golay2087.h"
#include <cstdio>
#include <cassert>
CSlotType::CSlotType() :
m_colorCode(0U),
m_dataType(0U)
{
}
CSlotType::~CSlotType()
{
}
void CSlotType::putData(const unsigned char* data)
{
assert(data != NULL);
unsigned char slotType[3U];
slotType[0U] = (data[12U] << 2) & 0xFCU;
slotType[0U] |= (data[13U] >> 6) & 0x03U;
slotType[1U] = (data[13U] << 2) & 0xC0U;
slotType[1U] |= (data[19U] << 2) & 0x3CU;
slotType[1U] |= (data[20U] >> 6) & 0x03U;
slotType[2U] = (data[20U] << 2) & 0xF0U;
unsigned char code = CGolay2087::decode(slotType);
m_colorCode = (code >> 4) & 0x0FU;
m_dataType = (code >> 0) & 0x0FU;
}
void CSlotType::getData(unsigned char* data) const
{
assert(data != NULL);
unsigned char slotType[3U];
slotType[0U] = (m_colorCode << 4) & 0xF0U;
slotType[0U] |= (m_dataType << 0) & 0x0FU;
slotType[1U] = 0x00U;
slotType[2U] = 0x00U;
CGolay2087::encode(slotType);
data[12U] = (data[12U] & 0xC0U) | ((slotType[0U] >> 2) & 0x3FU);
data[13U] = (data[13U] & 0x0FU) | ((slotType[0U] << 6) & 0xC0U) | ((slotType[1U] >> 2) & 0x30U);
data[19U] = (data[19U] & 0xF0U) | ((slotType[1U] >> 2) & 0x0FU);
data[20U] = (data[20U] & 0x03U) | ((slotType[1U] << 6) & 0xC0U) | ((slotType[2U] >> 2) & 0x3CU);
}
unsigned char CSlotType::getColorCode() const
{
return m_colorCode;
}
void CSlotType::setColorCode(unsigned char code)
{
m_colorCode = code;
}
unsigned char CSlotType::getDataType() const
{
return m_dataType;
}
void CSlotType::setDataType(unsigned char type)
{
m_dataType = type;
}