-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPCA301.h
86 lines (74 loc) · 1.91 KB
/
PCA301.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
#ifndef _PCA301_h
#define _PCA301_h
#include "Arduino.h"
#include "RFMxx.h"
#include "PCA301Plug.h"
#include "PCA301PlugList.h"
enum class ExpectedAnswers {
None = 0,
On = 1,
Off = 2,
Values = 3
};
enum class ActionTypes {
None = 0,
Poll = 1,
Pair = 2,
};
class PCA301Action {
public:
ActionTypes Action;
byte ID[3];
byte Channel;
unsigned long StartTime;
};
class PCA301 {
public:
struct Frame {
byte Channel;
byte Command;
byte ID[3];
byte Data;
float Power;
float AccumulatedPower;
byte CRC1;
byte CRC2;
bool IsValid;
bool IsFromPlug;
bool IsPairingCommand;
bool IsOnOffCommand;
bool IsOn;
};
////typedef std::function<String(String key, String Value, bool write)> TSettingsCallback;
typedef String TSettingsCallback(String key, String value, bool write);
PCA301();
void Begin(RFMxx *rfm, unsigned long frequency, word interval, TSettingsCallback callback);
bool IsInitialized();
void Handle();
String GetFhemDataString(byte *data);
static bool IsValidDataRate(unsigned long dataRate);
void SendPayload(byte bytes[10], bool isRetry);
RFMxx *GetUsedRadio();
typedef void LogItemCallbackType(String);
void SetLogItemCallback(LogItemCallbackType* callback);
String AnalyzeFrame(byte *payload);
void EnableLogging(bool enabled);
protected:
static const byte FRAME_LENGTH = 12;
bool m_doLogging;
RFMxx *m_rfm;
unsigned long m_lastPoll;
unsigned long m_lastCommand;
ExpectedAnswers m_expectedAnswer;
byte m_retries;
byte m_lastPayload[10];
PCA301Action m_nextAction;
PCA301PlugList m_plugList;
void DecodeFrame(byte *bytes, struct PCA301::Frame *frame);
void CalculateCRC(byte data[], byte result[2]);
LogItemCallbackType *m_logItemCallback;
void Log(String logItem, bool force=false);
String GetPlugIdentifier(byte id1, byte id2, byte id3, byte channel);
TSettingsCallback *m_settingsCallback;
};
#endif