forked from pa-pa/AskSinPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelList.h
317 lines (252 loc) · 7.06 KB
/
ChannelList.h
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
#ifndef __CHANNELLIST_H__
#define __CHANNELLIST_H__
#include "Storage.h"
#include "HMID.h"
namespace as {
class BaseList {
uint16_t addr;
public:
BaseList (uint16_t a) : addr(a) {}
uint16_t address () const { return addr; }
bool valid () const { return addr != 0; }
uint8_t getByte (uint8_t offset) const {
return storage().getByte(addr + offset);
}
uint8_t getByte (uint8_t offset, uint8_t mask, uint8_t shift) const {
return (getByte(offset) & mask) >> shift;
}
bool setByte (uint8_t offset, uint8_t data) const {
return storage().setByte(addr + offset, data);
}
bool setByte (uint8_t offset, uint8_t data, uint8_t mask, uint8_t shift) const {
uint8_t tmp = getByte(offset) & ~mask;
tmp |= (data << shift) & mask;
return setByte(offset, tmp);
}
bool isBitSet (uint8_t offset, uint8_t bit) const {
return (storage().getByte(addr + offset) & bit) == bit;
}
bool setBit (uint8_t offset, uint8_t bit, bool value) const {
if( value == true ) {
return storage().setBits(addr + offset, bit);
}
return storage().clearBits(addr + offset, bit);
}
bool setData (uint8_t offset,uint8_t* buf,uint16_t size) const {
return storage().setData(addr + offset,buf,size);
}
bool getData (uint8_t offset,uint8_t* buf,uint16_t size) const {
return storage().getData(addr + offset,buf,size);
}
void clear (uint8_t offset,uint16_t size) {
storage().clearData(addr + offset,size);
}
void init (const uint8_t* data,uint16_t size) {
for(uint16_t idx=0; idx<size; ++idx) {
storage().setByte(addr + idx,pgm_read_byte(data + idx));
}
}
};
class GenericList : public BaseList {
uint8_t size;
uint8_t (*getregister) (uint8_t off);
uint8_t (*getoffset) (uint8_t reg);
public:
GenericList () : BaseList(0), size(0), getregister(0), getoffset(0) {}
GenericList (uint16_t a,uint8_t s,uint8_t (*getreg) (uint8_t off), uint8_t (*getoff) (uint8_t reg)) : BaseList(a), size(s), getregister(getreg), getoffset(getoff) {}
uint8_t getOffset (uint8_t reg) const {
return getoffset(reg);
}
uint8_t getRegister (uint8_t offset) const {
return getregister(offset);
}
bool writeRegister (uint8_t reg, uint8_t value) const {
bool result = false;
uint8_t offset = getOffset(reg);
if( offset != 0xff ) {
result = setByte(offset,value);
}
return result;
}
uint8_t readRegister (uint8_t reg) const {
uint8_t value = 0;
uint8_t offset = getOffset(reg);
if( offset != 0xff ) {
value = getByte(offset);
}
return value;
}
uint8_t getSize () const {
return size;
}
void dump () const {
DHEX(address());
DPRINT(F(" - "));
storage().dump(address(),getSize());
}
};
template<class DataType>
class ChannelList : public BaseList {
protected:
~ChannelList () {}
public:
ChannelList (uint16_t a) : BaseList(a) {}
static uint8_t getOffset (uint8_t reg) {
return DataType::getOffset(reg);
}
static uint8_t getRegister (uint8_t offset) {
return DataType::getRegister(offset);
}
static uint8_t size () {
return sizeof(DataType);
}
bool writeRegister (uint8_t reg, uint8_t value) const {
bool result = false;
uint8_t offset = getOffset(reg);
if( offset != 0xff ) {
result = setByte(offset,value);
}
return result;
}
uint8_t readRegister (uint8_t reg) const {
uint8_t value = 0;
uint8_t offset = getOffset(reg);
if( offset != 0xff ) {
value = getByte(offset);
}
return value;
}
void dump () const {
DHEX(address());
DPRINT(F(" - "));
storage().dump(address(),size());
}
operator GenericList () const {
return GenericList(address(),size(),getRegister,getOffset);
}
};
class EmptyListData {
public:
static uint8_t getOffset(__attribute__((unused)) uint8_t reg) { return 0xff; }
static uint8_t getRegister(__attribute__((unused)) uint8_t reg) { return 0xff; }
};
class EmptyList : public ChannelList<EmptyListData> {
public:
EmptyList(uint16_t a) : ChannelList(a) {}
void defaults () {}
void single () {}
void even () {}
void odd () {}
// allow compiler to optimize/remove code for EmptyList
static uint8_t size () { return 0; }
};
class List0Data {
public:
uint8_t data :8; // 0x02, s:0, e:8
uint8_t master1 :8; // 0x0A, s:0, e:8
uint8_t master2 :8; // 0x0B, s:0, e:8
uint8_t master3 :8; // 0x0C, s:0, e:8
static uint8_t getOffset(uint8_t reg) {
switch (reg) {
case 0x02: return 0;
case 0x0A: return 1;
case 0x0B: return 2;
case 0x0C: return 3;
default: break;
}
return 0xff;
}
static uint8_t getRegister(uint8_t offset) {
switch (offset) {
case 0: return 0x02;
case 1: return 0x0A;
case 2: return 0x0B;
case 3: return 0x0C;
default: break;
}
return 0xff;
}
};
class List0 : public ChannelList<List0Data> {
public:
List0(uint16_t a) : ChannelList(a) {}
HMID masterid () { return HMID(getByte(1),getByte(2),getByte(3)); }
void masterid (const HMID& mid) {
setByte(1,mid.id0());
setByte(2,mid.id1());
setByte(3,mid.id2());
};
bool aesActive () const { return false; }
bool sabotageMsg () const { return false; }
bool localResetDisable () const { return false; }
uint8_t ledMode () const { return 0x01; } // default LED is on
void defaults () {
setByte(0,0x01);
setByte(1,0x00);
setByte(2,0x00);
setByte(3,0x00);
}
uint8_t transmitDevTryMax () const { return 6; }
};
class List1Data {
public:
uint8_t AesActive :1; // 0x08, s:0, e:1
uint8_t notused :7;
static uint8_t getOffset(uint8_t reg) {
switch (reg) {
case 0x08: return 0;
default: break;
}
return 0xff;
}
static uint8_t getRegister(uint8_t offset) {
switch (offset) {
case 0: return 0x08;
default: break;
}
return 0xff;
}
};
class List1 : public ChannelList<List1Data> {
public:
List1(uint16_t a) : ChannelList(a) {}
bool aesActive () const { return isBitSet(0,0x01); }
bool aesActive (bool s) const { return setBit(0,0x01,s); }
void defaults () {
setByte(0,0x00);
}
};
class List4Data {
public:
uint8_t burst :1; // 0x01, s:0, e:1
uint8_t notused :7;
static uint8_t getOffset(uint8_t reg) {
switch (reg) {
case 0x01: return 0;
default: break;
}
return 0xff;
}
static uint8_t getRegister(uint8_t offset) {
switch (offset) {
case 0: return 0x01;
default: break;
}
return 0xff;
}
};
class List4 : public ChannelList<List4Data> {
public:
List4(uint16_t a) : ChannelList(a) {}
bool burst () const { return isBitSet(0,0x01); }
bool burst (bool s) const { return setBit(0,0x01,s); }
void defaults () {
setByte(0,0x00);
}
};
}
#endif