Skip to content

Commit 6f1800d

Browse files
committed
Fixed loads of errors when compiling
1 parent 52d324c commit 6f1800d

File tree

2 files changed

+79
-21
lines changed

2 files changed

+79
-21
lines changed

hardware/HEOS.cpp

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <iostream>
1717

18+
#define DEBUG_LOGGING true
19+
1820
CHEOS::CHEOS(const int ID, const std::string &IPAddress, const int Port, const std::string &User, const std::string &Pwd, const int PollIntervalsec, const int PingTimeoutms) :
1921
m_IP(IPAddress),
2022
m_User(User),
@@ -91,9 +93,10 @@ void CHEOS::handleMessage(std::string& pMessage)
9193
if (root.isMember("payload"))
9294
{
9395
for( Json::ValueIterator itr = root["payload"].begin() ; itr != root["payload"].end() ; itr++ ) {
94-
if (root["payload"][itr].isMember("name") && root["payload"][itr].isMember("pid"))
96+
std::string key = itr.key().asString();
97+
if (root["payload"][key].isMember("name") && root["payload"][key].isMember("pid"))
9598
{
96-
AddNode(root["payload"][itr]["name"], root["payload"][itr]["pid"]);
99+
AddNode(root["payload"][key]["name"].asString(), root["payload"][key]["pid"].asString());
97100
}
98101
else
99102
{
@@ -121,11 +124,13 @@ void CHEOS::handleMessage(std::string& pMessage)
121124
std::string pid = SplitMessagePlayer[1];
122125
std::string state = SplitMessageState[1];
123126

124-
if (sMode == "play")
127+
_eMediaStatus nStatus = MSTAT_UNKNOWN;
128+
129+
if (state == "play")
125130
nStatus = MSTAT_PLAYING;
126-
else if (sMode == "pause")
131+
else if (state == "pause")
127132
nStatus = MSTAT_PAUSED;
128-
else if (sMode == "stop")
133+
else if (state == "stop")
129134
nStatus = MSTAT_STOPPED;
130135
else
131136
nStatus = MSTAT_ON;
@@ -135,7 +140,7 @@ void CHEOS::handleMessage(std::string& pMessage)
135140
UpdateNodeStatus(pid, nStatus, sStatus);
136141

137142
/* If playing request now playing information */
138-
if (sMode == "play") {
143+
if (state == "play") {
139144
int PlayerID = atoi(pid.c_str());
140145
SendCommand("player/get_now_playing_media", PlayerID);
141146
}
@@ -150,16 +155,17 @@ void CHEOS::handleMessage(std::string& pMessage)
150155
StringSplit(root["heos"]["message"].asString(), "=", SplitMessage);
151156
if (SplitMessage.size() > 0)
152157
{
158+
std::string sLabel = "";
159+
std::string sStatus = "";
160+
std::string pid = SplitMessage[1];
161+
153162
if (root["heos"].isMember("payload"))
154163
{
155-
std::string pid = SplitMessage[1];
156-
std::string sStatus = "";
157-
164+
158165
std::string sTitle = "";
159166
std::string sAlbum = "";
160167
std::string sArtist = "";
161168
std::string sStation = "";
162-
std::string sLabel = "";
163169

164170
sTitle = root["payload"]["song"].asString();
165171
sAlbum = root["payload"]["album"].asString();
@@ -218,17 +224,18 @@ void CHEOS::handleConnect()
218224
if (!m_stoprequested && !m_Socket)
219225
{
220226
m_iMissedPongs = 0;
227+
std::string sPort = std::to_string(m_Port);
221228
boost::system::error_code ec;
222229
boost::asio::ip::tcp::resolver resolver(*m_Ios);
223-
boost::asio::ip::tcp::resolver::query query(m_IP, (m_Port[0] != '-' ? m_Port : m_Port.substr(1)));
230+
boost::asio::ip::tcp::resolver::query query(m_IP, sPort);
224231
boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
225232
boost::asio::ip::tcp::endpoint endpoint = *iter;
226233
m_Socket = new boost::asio::ip::tcp::socket(*m_Ios);
227234
m_Socket->connect(endpoint, ec);
228235
if (!ec)
229236
{
230-
_log.Log(LOG_NORM, "HEOS by DENON: Connected to '%s:%s'.", m_IP.c_str(), (m_Port[0] != '-' ? m_Port.c_str() : m_Port.substr(1).c_str()));
231-
m_Socket->async_read_some(boost::asio::buffer(m_Buffer, sizeof m_Buffer), boost::bind(&CHEOS::handleRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
237+
_log.Log(LOG_NORM, "HEOS by DENON: Connected to '%s:%s'.", m_IP.c_str(), sPort);
238+
m_Socket->async_read_some(boost::asio::buffer(m_Buffer, sizeof m_Buffer), boost::bind(&CHEOS::handleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
232239
// Disable registration for change events following HEOS Controller advise
233240
handleWrite(std::string("heos://system/register_for_change_events?enable=off"));
234241
}
@@ -244,7 +251,7 @@ void CHEOS::handleConnect()
244251
)
245252
) // Connection failed due to no response, no route or active refusal
246253
{
247-
_log.Log(LOG_NORM, "HEOS by DENON: Connect to '%s:%s' failed: (%d) %s", m_IP.c_str(), (m_Port[0] != '-' ? m_Port.c_str() : m_Port.substr(1).c_str()), ec.value(), ec.message().c_str());
254+
_log.Log(LOG_NORM, "HEOS by DENON: Connect to '%s:%s' failed: (%d) %s", m_IP.c_str(), sPort, ec.value(), ec.message().c_str());
248255
}
249256
delete m_Socket;
250257
m_Socket = NULL;
@@ -289,7 +296,7 @@ void CHEOS::handleRead(const boost::system::error_code& e, std::size_t bytes_tra
289296
if (!m_stoprequested && m_Socket)
290297
m_Socket->async_read_some( boost::asio::buffer(m_Buffer, sizeof m_Buffer),
291298
boost::bind(&CHEOS::handleRead,
292-
shared_from_this(),
299+
this,
293300
boost::asio::placeholders::error,
294301
boost::asio::placeholders::bytes_transferred));
295302
}
@@ -715,7 +722,8 @@ void CHEOS::UpdateNodesStatus(const std::string &DevID, const std::string &sStat
715722

716723
void CHEOS::AddNode(const std::string &Name, const std::string &PlayerID)
717724
{
718-
//Check if exists
725+
std::vector<std::vector<std::string> > result;
726+
719727
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q')", m_HwdID, PlayerID.c_str());
720728
if (result.size()>0) {
721729
int ID = atoi(result[0][0].c_str());
@@ -756,6 +764,51 @@ void CHEOS::Restart()
756764
StartHardware();
757765
}
758766

767+
bool CHEOS::WriteToHardware(const char *pdata, const unsigned char length)
768+
{
769+
const tRBUF *pSen = reinterpret_cast<const tRBUF*>(pdata);
770+
771+
unsigned char packettype = pSen->ICMND.packettype;
772+
773+
if (packettype != pTypeLighting2)
774+
return false;
775+
776+
long DevID = (pSen->LIGHTING2.id3 << 8) | pSen->LIGHTING2.id4;
777+
std::vector<HEOSNode>::const_iterator itt;
778+
for (itt = m_nodes.begin(); itt != m_nodes.end(); ++itt)
779+
{
780+
if (itt->DevID == DevID)
781+
{
782+
int iParam = pSen->LIGHTING2.level;
783+
std::string sParam;
784+
switch (pSen->LIGHTING2.cmnd)
785+
{
786+
case light2_sOn:
787+
case light2_sGroupOn:
788+
case light2_sOff:
789+
case light2_sGroupOff:
790+
case gswitch_sPlay:
791+
SendCommand("getNowPlaying", itt->DevID);
792+
SendCommand("setPlayStatePlay", itt->DevID);
793+
return true;
794+
case gswitch_sPlayPlaylist:
795+
case gswitch_sPlayFavorites:
796+
case gswitch_sStop:
797+
SendCommand("setPlayStateStop", itt->DevID);
798+
return true;
799+
case gswitch_sPause:
800+
SendCommand("setPlayStatePause", itt->DevID);
801+
return true;
802+
case gswitch_sSetVolume:
803+
default:
804+
return true;
805+
}
806+
}
807+
}
808+
809+
return false;
810+
}
811+
759812
void CHEOS::ReloadNodes()
760813
{
761814
m_nodes.clear();
@@ -840,7 +893,7 @@ namespace http {
840893
if (result.size() == 1)
841894
{
842895
_eSwitchType sType = (_eSwitchType)atoi(result[0][0].c_str());
843-
int PlayerID = atoi(result[0][1]..c_str());
896+
int PlayerID = atoi(result[0][1].c_str());
844897
_eHardwareTypes hType = (_eHardwareTypes)atoi(result[0][2].c_str());
845898
int HwID = atoi(result[0][3].c_str());
846899
// Is the device a media Player?
@@ -849,7 +902,7 @@ namespace http {
849902
switch (hType) {
850903
case HTYPE_HEOS:
851904
CHEOS HEOS(HwID);
852-
HEOS.SendCommand(sAction, PlayerId);
905+
HEOS.SendCommand(sAction, PlayerID);
853906
break;
854907
// put other players here ...
855908
}

hardware/HEOS.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "../json/json.h"
88
#include <boost/asio.hpp>
99
#include <boost/array.hpp>
10-
#include <boost/enable_shared_from_this.hpp>
1110

1211
#define SSTR( x ) dynamic_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
1312

@@ -29,6 +28,7 @@ class CHEOS : public CDomoticzHardwareBase
2928
CHEOS(const int ID, const std::string &IPAddress, const int Port, const std::string &User, const std::string &Pwd, const int PollIntervalsec, const int PingTimeoutms);
3029
explicit CHEOS(const int ID);
3130
~CHEOS(void);
31+
bool WriteToHardware(const char *pdata, const unsigned char length);
3232
void SetSettings(const int PollIntervalsec, const int PingTimeoutms);
3333
void Restart();
3434
void SendCommand(const std::string&);
@@ -52,6 +52,11 @@ class CHEOS : public CDomoticzHardwareBase
5252
bool m_bShowedStartupMessage;
5353
int m_iMissedQueries;
5454
std::string m_RetainedData;
55+
int m_iMissedPongs;
56+
std::string m_sLastMessage;
57+
boost::asio::io_service *m_Ios;
58+
boost::asio::ip::tcp::socket *m_Socket;
59+
boost::array<char, 256> m_Buffer;
5560

5661
boost::shared_ptr<boost::thread> m_thread;
5762
volatile bool m_stoprequested;
@@ -68,9 +73,9 @@ class CHEOS : public CDomoticzHardwareBase
6873
bool StopHardware();
6974

7075
void AddNode(const std::string &Name, const std::string &PlayerID);
71-
bool UpdateNode(const int ID, const std::string &Name);
76+
void UpdateNode(const int ID, const std::string &Name);
7277
void UpdateNodeStatus(const std::string &DevID, const _eMediaStatus nStatus, const std::string &sStatus);
73-
void UpdateNodeStatus(const std::string &DevID, const std::string &sStatus);
78+
void UpdateNodesStatus(const std::string &DevID, const std::string &sStatus);
7479
// void RemoveNode(const int ID);
7580
void ReloadNodes();
7681

0 commit comments

Comments
 (0)