Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
Fix entertainment mode support
Browse files Browse the repository at this point in the history
- Add mbedtls as submodule
- Add bin folder to gitignore
  • Loading branch information
enwi committed Mar 24, 2021
1 parent d218d9d commit 2780404
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# build directory
/build*
/out
/bin

# Generated documentation
/doc/html
Expand All @@ -44,7 +45,6 @@
# Icon must end with two \r
Icon


# Thumbnails
._*

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/mbedtls"]
path = lib/mbedtls
url = https://github.com/ARMmbed/mbedtls.git
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ if (1 AND APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif()

add_subdirectory("lib/mbedtls")

add_subdirectory(src)

# if the user decided to use tests add the subdirectory
Expand Down
1 change: 1 addition & 0 deletions include/hueplusplus/Bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BridgeFinder

//! \brief Function that adds a client key to the clientkeys map
//!
//! The client key is only needed for entertainment mode, otherwise it is optional.
//! \param mac MAC address of Hue bridge
//! \param clientkey Client key that is used to control the Hue bridge in entertainment mode
void AddClientKey(const std::string& mac, const std::string& clientkey);
Expand Down
60 changes: 36 additions & 24 deletions include/hueplusplus/EntertainmentMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,61 @@
#include "Bridge.h"
#include "Group.h"

#include "mbedtls/ssl.h"
#include "mbedtls/net_sockets.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h"
#include "mbedtls/error.h"
#include "mbedtls/certs.h"
#include "mbedtls/debug.h"
#include "mbedtls/timing.h"

#define HUE_ENTERTAINMENT_HEADER_SIZE 16
#define HUE_ENTERTAINMENT_LIGHT_SIZE 9

namespace hueplusplus
{
struct TLSContext;

//! \brief Class for Hue Entertainment Mode
//!
//! Provides methods to initialize and control Entertainment groups.
class EntertainmentMode
{
public:
EntertainmentMode(Bridge& bridge, Group& group);
//! @brief Constructor
//!
//! @param b Bridge reference
//! @param g Group to control in entertainment mode reference
EntertainmentMode(Bridge& b, Group& g);

//! @brief Destroy the Entertainment Mode object
~EntertainmentMode();

//! @brief Connect and start streaming
//!
//! @return true If conected and ready to receive commands
//! @return false If an error occured
bool Connect();

//! @brief Disconnect and stop streaming
//!
//! @return true If disconnected successfully
//! @return false If an error occurred
bool Disconnect();


//! @brief Set the color of the given light in RGB format
//!
//! @param light_index Light index inside the group
//! @param red Red color value (0-255)
//! @param green Green color value (0-255)
//! @param blue Blue color value (0-255)
//! @return true If light_index was valid
//! @return false If light_index was invalid
bool SetColorRGB(uint8_t light_index, uint8_t red, uint8_t green, uint8_t blue);

void Update();
//! @brief Update all set colors by @ref SetColorRGB
//!
//! @return true If all color values for all lights have ben written/sent
//! @return false If there was an error while writing
bool Update();

protected:
Bridge& bridge;
Group& group;
Bridge* bridge; //!< Associated bridge
Group* group; //!< Associated group

std::vector<uint8_t> entertainment_msg; //!< buffer containing the entertainment mode packet data
uint8_t entertainment_num_lights; //!< number of lights in entertainment mode group

mbedtls_ssl_context ssl;
mbedtls_net_context server_fd;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_config conf;
mbedtls_x509_crt cacert;
mbedtls_timing_delay_context timer;
std::unique_ptr<TLSContext> tls_context; //!< tls context
};
} // namespace hueplusplus

Expand Down
2 changes: 1 addition & 1 deletion include/hueplusplus/LinHttpHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LinHttpHandler : public BaseHttpHandler
//! decimal notation like "192.168.2.1" \param port Optional integer that
//! specifies the port to which the request is sent to. Default is 80 \return
//! String containing the response of the host
virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const;
virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const override;

//! \brief Function that sends a multicast request with the specified message.
//!
Expand Down
1 change: 1 addition & 0 deletions lib/mbedtls
Submodule mbedtls added at fc86f3
27 changes: 11 additions & 16 deletions src/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ std::string Bridge::requestUsername()

bool Bridge::StartStreaming(std::string group_identifier)
{
if (clientkey.empty())
{
throw HueException(CURRENT_FILE_INFO, "Cannot stream without client key!");
}

nlohmann::json request;

request["stream"]["active"] = true;
Expand All @@ -260,20 +265,10 @@ bool Bridge::StartStreaming(std::string group_identifier)

answer = http_handler->PUTJson(uri, request, ip, port);

if(answer[0].contains("success"))
{
std::string key = "/groups/" + group_identifier + "/stream/active";
std::string key = "/groups/" + group_identifier + "/stream/active";
nlohmann::json success = utils::safeGetMember(answer, 0, "success", key);

if(answer[0]["success"].contains(key))
{
if(answer[0]["success"][key] == true)
{
return true;
}
}
}

return false;
return success == true;
}

bool Bridge::StopStreaming(std::string group_identifier)
Expand All @@ -288,13 +283,13 @@ bool Bridge::StopStreaming(std::string group_identifier)

answer = http_handler->PUTJson(uri, request, ip, port);

if(answer[0].contains("success"))
if (answer[0].contains("success"))
{
std::string key = "/groups/" + group_identifier + "/stream/active";

if(answer[0]["success"].contains(key))
if (answer[0]["success"].contains(key))
{
if(answer[0]["success"][key] == false)
if (answer[0]["success"][key] == false)
{
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(hueplusplus_SOURCES
BridgeConfig.cpp
CLIPSensors.cpp
ColorUnits.cpp
EntertainmentMode.cpp
ExtendedColorHueStrategy.cpp
ExtendedColorTemperatureStrategy.cpp
Group.cpp
Expand Down Expand Up @@ -58,12 +59,14 @@ set(hueplusplus_SOURCES ${_srcList} PARENT_SCOPE)

# hueplusplus shared library
add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES})
target_link_libraries(hueplusplusshared PRIVATE mbedtls)
target_compile_features(hueplusplusshared PUBLIC cxx_std_14)
target_include_directories(hueplusplusshared PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
install(TARGETS hueplusplusshared DESTINATION lib)

# hueplusplus static library
add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES})
target_link_libraries(hueplusplusstatic PRIVATE mbedtls)
target_compile_features(hueplusplusstatic PUBLIC cxx_std_14)
install(TARGETS hueplusplusstatic DESTINATION lib)
target_include_directories(hueplusplusstatic PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
Expand Down
Loading

0 comments on commit 2780404

Please sign in to comment.