-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBoiler.cpp
More file actions
80 lines (67 loc) · 2 KB
/
Boiler.cpp
File metadata and controls
80 lines (67 loc) · 2 KB
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
/*
* Copyright © 2017 Matt Robinson
* Copyright © 2021 Mattias Jonsson
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "Boiler.h"
#include "FramingException.h"
const uint8_t COUNTER_EEPROM_BLOCK = 0x01;
const uint8_t COUNTER_BLOCK_COUNT = 0x02;
const uint8_t DFDU_EEPROM_BLOCK = 0x10;
const uint8_t DFDU_NUM_BYTES = 0x02;
std::vector<uint8_t> Boiler::FetchData(FrameFunction function)
{
int retries = 0;
for(;;)
{
try
{
port.WriteBytes(Frame(FrameType::Request, function));
return Frame(port.ReadBytes()).getData();
}
catch(FramingException&)
{
if(retries == 2)
{
throw;
}
retries++;
}
}
}
std::vector<uint8_t> Boiler::ReadEepromBlock(uint8_t blockNum)
{
auto reply = FetchData((FrameFunction)(FrameFunction::EepromRead + blockNum));
return reply;
}
std::vector<uint8_t> Boiler::ReadEepromBlocks(uint8_t blockNum, uint8_t count)
{
std::vector<uint8_t> data;
for(uint8_t i = blockNum; i < (blockNum + count); i++)
{
auto block = ReadEepromBlock(i);
data.insert(data.end(), block.begin(), block.end());
}
return data;
}
IdentifyMessage Boiler::ReadIdentifyData()
{
auto identData = FetchData(FrameFunction::Identify);
auto dfDu = ReadEepromBlock(DFDU_EEPROM_BLOCK);
// For some reason the 'dF-code' and 'dU-code' (whatever they are) aren't
// included in the response to an identify request, but have to be read
// out of a specific EEPROM block and tacked on to the end of the data
identData.insert(identData.end(), dfDu.begin(), dfDu.begin() + DFDU_NUM_BYTES);
return IdentifyMessage(identData);
}
SampleMessage Boiler::ReadSampleData()
{
auto reply = FetchData(FrameFunction::Sample);
return SampleMessage(reply);
}
CountersMessage Boiler::ReadCountersData()
{
auto reply = ReadEepromBlocks(COUNTER_EEPROM_BLOCK, COUNTER_BLOCK_COUNT);
return CountersMessage(reply);
}