mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 18:34:25 +01:00
Added door state to Clientmessage / Doormessage
This commit is contained in:
parent
404f219b6c
commit
b8cb8f9876
@ -7,6 +7,7 @@ const std::string Clientmessage::_tokenKey = "token";
|
|||||||
const std::string Clientmessage::_unlockButtonKey = "unlockButton";
|
const std::string Clientmessage::_unlockButtonKey = "unlockButton";
|
||||||
const std::string Clientmessage::_lockButtonKey = "lockButton";
|
const std::string Clientmessage::_lockButtonKey = "lockButton";
|
||||||
const std::string Clientmessage::_emergencyUnlockKey = "emergencyUnlock";
|
const std::string Clientmessage::_emergencyUnlockKey = "emergencyUnlock";
|
||||||
|
const std::string Clientmessage::_isOpenKey = "isOpen";
|
||||||
|
|
||||||
Clientmessage::Clientmessage(std::string token,
|
Clientmessage::Clientmessage(std::string token,
|
||||||
Doormessage doormessage) :
|
Doormessage doormessage) :
|
||||||
@ -24,6 +25,7 @@ std::string Clientmessage::toJson() const
|
|||||||
message[_unlockButtonKey] = _doormessage.isUnlockButton;
|
message[_unlockButtonKey] = _doormessage.isUnlockButton;
|
||||||
message[_lockButtonKey] = _doormessage.isLockButton;
|
message[_lockButtonKey] = _doormessage.isLockButton;
|
||||||
message[_emergencyUnlockKey] = _doormessage.isEmergencyUnlock;
|
message[_emergencyUnlockKey] = _doormessage.isEmergencyUnlock;
|
||||||
|
message[_isOpenKey] = _doormessage.isOpen;
|
||||||
|
|
||||||
return writer.write(message);
|
return writer.write(message);
|
||||||
}
|
}
|
||||||
@ -52,6 +54,7 @@ Clientmessage Clientmessage::fromJson(const std::string &json)
|
|||||||
doormessage.isLockButton = getJsonOrFail<bool>(root, _lockButtonKey);
|
doormessage.isLockButton = getJsonOrFail<bool>(root, _lockButtonKey);
|
||||||
doormessage.isUnlockButton = getJsonOrFail<bool>(root, _unlockButtonKey);
|
doormessage.isUnlockButton = getJsonOrFail<bool>(root, _unlockButtonKey);
|
||||||
doormessage.isEmergencyUnlock = getJsonOrFail<bool>(root, _emergencyUnlockKey);
|
doormessage.isEmergencyUnlock = getJsonOrFail<bool>(root, _emergencyUnlockKey);
|
||||||
|
doormessage.isOpen = getJsonOrFail<bool>(root, _isOpenKey);
|
||||||
|
|
||||||
return Clientmessage(token, doormessage);
|
return Clientmessage(token, doormessage);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ private:
|
|||||||
const static std::string _unlockButtonKey;
|
const static std::string _unlockButtonKey;
|
||||||
const static std::string _lockButtonKey;
|
const static std::string _lockButtonKey;
|
||||||
const static std::string _emergencyUnlockKey;
|
const static std::string _emergencyUnlockKey;
|
||||||
|
const static std::string _isOpenKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,6 +56,7 @@ void Door::_asyncRead()
|
|||||||
boost::asio::buffer(&recvBuf, sizeof(recvBuf)),
|
boost::asio::buffer(&recvBuf, sizeof(recvBuf)),
|
||||||
[this] (const boost::system::error_code &ec, size_t bytes_transferred) {
|
[this] (const boost::system::error_code &ec, size_t bytes_transferred) {
|
||||||
Doormessage m;
|
Doormessage m;
|
||||||
|
m.isOpen = _state == Door::State::Unlocked;
|
||||||
|
|
||||||
if (ec) {
|
if (ec) {
|
||||||
// Operation canceled occurs on system shutdown
|
// Operation canceled occurs on system shutdown
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define DOORMESSAGE_H
|
#define DOORMESSAGE_H
|
||||||
|
|
||||||
struct Doormessage {
|
struct Doormessage {
|
||||||
|
bool isOpen = { false };
|
||||||
bool isUnlockButton = { false };
|
bool isUnlockButton = { false };
|
||||||
bool isLockButton = { false };
|
bool isLockButton = { false };
|
||||||
bool isEmergencyUnlock = { false };
|
bool isEmergencyUnlock = { false };
|
||||||
|
Loading…
Reference in New Issue
Block a user