bus.hpp
1.53 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
/*
* Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
*
* Licensed under GNU General Public License 3.0 or later.
*
* 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.
*/
#ifndef DALI_BUS_CONTROLLER_H_
#define DALI_BUS_CONTROLLER_H_
#include <dali/dali.hpp>
namespace dali {
namespace controller {
class Bus: public IBusDriver::IBusClient {
public:
class Client {
public:
virtual uint8_t getShortAddr() = 0;
virtual uint16_t getGroups() = 0;
virtual Status handleCommand(uint16_t repeat, Command cmd, uint8_t param) = 0;
virtual Status handleIgnoredCommand(Command cmd, uint8_t param) = 0;
virtual void onBusDisconnected() = 0;
};
explicit Bus(IBusDriver* bus, Client* client);
virtual ~Bus();
Status sendAck(uint8_t ack) { return mBus->sendAck(ack); }
Time getLastCommandTime() { return mLastCommandTime; }
void onDataReceived(Time time, uint16_t data) override;
void onBusStateChanged(IBusDriver::IBusState state) override;
private:
Bus(const Bus& other) = delete;
Bus& operator=(const Bus&) = delete;
Command extractCommand(uint16_t data, uint8_t* param);
IBusDriver* const mBus;
Client* mClient;
IBusDriver::IBusState mState;
Command mLastCommand;
uint16_t mCommandRepeatCount;
Time mLastCommandTime;
};
} // namespace controller
} // namespace dali
#endif // DALI_BUS_CONTROLLER_H_