Skip to content

Commit 914afa8

Browse files
committed
now with correct files
1 parent 2272840 commit 914afa8

File tree

6 files changed

+101
-39
lines changed

6 files changed

+101
-39
lines changed

hardware/OTGWBase.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ extern http::server::CWebServer m_webserver;
2222
OTGWBase::OTGWBase(void)
2323
{
2424
m_OutsideTemperatureIdx=0;//use build in
25+
m_bufferpos = 0;
2526
}
2627

2728
OTGWBase::~OTGWBase(void)
2829
{
2930
}
3031

31-
void OTGWBase::SetModes( const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5)
32+
void OTGWBase::SetModes(const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6)
3233
{
3334
m_OutsideTemperatureIdx=Mode1;
3435
}
@@ -117,7 +118,7 @@ void OTGWBase::UpdateSwitch(const unsigned char Idx, const bool bOn, const std::
117118
szQuery.clear();
118119
szQuery.str("");
119120
szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID=='" << szIdx << "')";
120-
result=m_sql.query(szQuery.str());
121+
m_sql.query(szQuery.str());
121122
}
122123

123124
}
@@ -159,7 +160,7 @@ void OTGWBase::UpdateTempSensor(const unsigned char Idx, const float Temp, const
159160
szQuery.clear();
160161
szQuery.str("");
161162
szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID==" << int(Idx) << ")";
162-
result=m_sql.query(szQuery.str());
163+
m_sql.query(szQuery.str());
163164
}
164165
}
165166

@@ -197,7 +198,7 @@ void OTGWBase::UpdateSetPointSensor(const unsigned char Idx, const float Temp, c
197198
szQuery.clear();
198199
szQuery.str("");
199200
szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID=='" << szID << "')";
200-
result=m_sql.query(szQuery.str());
201+
m_sql.query(szQuery.str());
201202
}
202203
}
203204

@@ -221,7 +222,7 @@ void OTGWBase::UpdatePressureSensor(const unsigned long Idx, const float Pressur
221222
gDevice.subtype=sTypePressure;
222223
gDevice.id=1;
223224
gDevice.floatval1=Pressure;
224-
gDevice.intval1=(int)Idx;
225+
gDevice.intval1 = static_cast<int>(Idx);
225226
sDecodeRXMessage(this, (const unsigned char *)&gDevice);
226227

227228
if (!bDeviceExits)
@@ -230,8 +231,7 @@ void OTGWBase::UpdatePressureSensor(const unsigned long Idx, const float Pressur
230231
szQuery.clear();
231232
szQuery.str("");
232233
szQuery << "UPDATE DeviceStatus SET Name='" << defaultname << "' WHERE (HardwareID==" << m_HwdID << ") AND (DeviceID=='" << szTmp << "') AND (Type==" << int(pTypeGeneral) << ") AND (Subtype==" << int(sTypePressure) << ")";
233-
result=m_sql.query(szQuery.str());
234-
234+
m_sql.query(szQuery.str());
235235
}
236236
}
237237

@@ -292,27 +292,35 @@ void OTGWBase::ParseLine()
292292
bool bDiagnosticEvent=(_status.MsgID[9+1]=='1'); UpdateSwitch(116,bDiagnosticEvent,"DiagnosticEvent");
293293
}
294294

295-
_status.Control_setpoint=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.Control_setpoint,"Control Setpoint");
295+
_status.Control_setpoint=static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx-1,_status.Control_setpoint,"Control Setpoint");
296296
_status.Remote_parameter_flags=results[idx++];
297-
_status.Maximum_relative_modulation_level=(float)atof(results[idx++].c_str());
297+
_status.Maximum_relative_modulation_level = static_cast<float>(atof(results[idx++].c_str()));
298+
if (_status.Maximum_relative_modulation_level != 0)
299+
{
300+
SendPercentageSensor(idx - 1, 1, 255, _status.Maximum_relative_modulation_level, "Maximum Relative Modulation Level");
301+
}
298302
_status.Boiler_capacity_and_modulation_limits=results[idx++];
299-
_status.Room_Setpoint=(float)atof(results[idx++].c_str()); UpdateSetPointSensor(idx-1,_status.Room_Setpoint,"Room Setpoint");
300-
_status.Relative_modulation_level=(float)atof(results[idx++].c_str());
301-
_status.CH_water_pressure=(float)atof(results[idx++].c_str());
303+
_status.Room_Setpoint = static_cast<float>(atof(results[idx++].c_str())); UpdateSetPointSensor(idx - 1, _status.Room_Setpoint, "Room Setpoint");
304+
_status.Relative_modulation_level = static_cast<float>(atof(results[idx++].c_str()));
305+
if (_status.Relative_modulation_level != 0)
306+
{
307+
SendPercentageSensor(idx - 1, 1, 255, _status.Relative_modulation_level, "Relative modulation level");
308+
}
309+
_status.CH_water_pressure = static_cast<float>(atof(results[idx++].c_str()));
302310
if (_status.CH_water_pressure!=0)
303311
{
304312
UpdatePressureSensor(idx-1,_status.CH_water_pressure,"CH Water Pressure");
305313
}
306314

307-
_status.Room_temperature=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.Room_temperature,"Room Temperature");
308-
_status.Boiler_water_temperature=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.Boiler_water_temperature,"Boiler Water Temperature");
309-
_status.DHW_temperature=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.DHW_temperature,"DHW Temperature");
310-
_status.Outside_temperature=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.Outside_temperature,"Outside Temperature");
311-
_status.Return_water_temperature=(float)atof(results[idx++].c_str()); UpdateTempSensor(idx-1,_status.Return_water_temperature,"Return Water Temperature");
315+
_status.Room_temperature = static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx - 1, _status.Room_temperature, "Room Temperature");
316+
_status.Boiler_water_temperature = static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx - 1, _status.Boiler_water_temperature, "Boiler Water Temperature");
317+
_status.DHW_temperature = static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx - 1, _status.DHW_temperature, "DHW Temperature");
318+
_status.Outside_temperature = static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx - 1, _status.Outside_temperature, "Outside Temperature");
319+
_status.Return_water_temperature = static_cast<float>(atof(results[idx++].c_str())); UpdateTempSensor(idx - 1, _status.Return_water_temperature, "Return Water Temperature");
312320
_status.DHW_setpoint_boundaries=results[idx++];
313321
_status.Max_CH_setpoint_boundaries=results[idx++];
314-
_status.DHW_setpoint=(float)atof(results[idx++].c_str()); UpdateSetPointSensor(idx-1,_status.DHW_setpoint,"DHW Setpoint");
315-
_status.Max_CH_water_setpoint=(float)atof(results[idx++].c_str()); UpdateSetPointSensor(idx-1,_status.Max_CH_water_setpoint,"Max_CH Water Setpoint");
322+
_status.DHW_setpoint = static_cast<float>(atof(results[idx++].c_str())); UpdateSetPointSensor(idx - 1, _status.DHW_setpoint, "DHW Setpoint");
323+
_status.Max_CH_water_setpoint = static_cast<float>(atof(results[idx++].c_str())); UpdateSetPointSensor(idx - 1, _status.Max_CH_water_setpoint, "Max_CH Water Setpoint");
316324
_status.Burner_starts=atol(results[idx++].c_str());
317325
_status.CH_pump_starts=atol(results[idx++].c_str());
318326
_status.DHW_pump_valve_starts=atol(results[idx++].c_str());
@@ -351,14 +359,13 @@ bool OTGWBase::GetOutsideTemperatureFromDomoticz(float &tvalue)
351359
Json::Value tempjson;
352360
std::stringstream sstr;
353361
sstr << m_OutsideTemperatureIdx;
354-
m_webserver.GetJSonDevices(tempjson, "", "temp","ID",sstr.str(),"","",true,0);
362+
m_webserver.GetJSonDevices(tempjson, "", "temp","ID",sstr.str(),"","",true,0,true);
355363

356364
size_t tsize=tempjson.size();
357365
if (tsize<1)
358366
return false;
359367

360368
Json::Value::const_iterator itt;
361-
int ii=0;
362369
Json::ArrayIndex rsize=tempjson["result"].size();
363370
if (rsize<1)
364371
return false;

hardware/OTGWBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class OTGWBase : public CDomoticzHardwareBase
4040
std::string m_szSerialPort;
4141
unsigned int m_iBaudRate;
4242
private:
43-
void SetModes( const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5);
43+
void SetModes(const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6);
4444
void ParseData(const unsigned char *pData, int Len);
4545
void ParseLine();
4646
void UpdateTempSensor(const unsigned char Idx, const float Temp, const std::string &defaultname);

hardware/OTGWSerial.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
//
2121
//Class OTGWSerial
2222
//
23-
OTGWSerial::OTGWSerial(const int ID, const std::string& devname, const unsigned int baud_rate, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5)
23+
OTGWSerial::OTGWSerial(const int ID, const std::string& devname, const unsigned int baud_rate, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6)
2424
{
2525
m_HwdID=ID;
2626
m_szSerialPort=devname;
2727
m_iBaudRate=baud_rate;
2828
m_stoprequestedpoller=false;
29-
SetModes(Mode1,Mode2,Mode3,Mode4,Mode5);
29+
SetModes(Mode1,Mode2,Mode3,Mode4,Mode5, Mode6);
3030
}
3131

3232
OTGWSerial::~OTGWSerial()
@@ -70,7 +70,7 @@ void OTGWSerial::readCallback(const char *data, size_t len)
7070
if (!m_bEnableReceive)
7171
return; //receiving not enabled
7272

73-
ParseData((const unsigned char*)data, (int)len);
73+
ParseData((const unsigned char*)data, static_cast<int>(len));
7474
}
7575

7676
void OTGWSerial::StartPollerThread()
@@ -157,6 +157,7 @@ void OTGWSerial::Do_PollWork()
157157
{
158158
bFirstTime=false;
159159
SendOutsideTemperature();
160+
SendTime();
160161
GetGatewayDetails();
161162
}
162163
}
@@ -170,6 +171,24 @@ void OTGWSerial::GetGatewayDetails()
170171
strcpy(szCmd,"PS=1\r\n");
171172
WriteToHardware((const char*)&szCmd,strlen(szCmd));
172173
}
174+
175+
void OTGWSerial::SendTime()
176+
{
177+
time_t atime = mytime(NULL);
178+
struct tm ltime;
179+
localtime_r(&atime, &ltime);
180+
181+
int lday = 0;
182+
if (ltime.tm_wday == 0)
183+
lday = 7;
184+
else
185+
lday = ltime.tm_wday;
186+
187+
char szCmd[20];
188+
sprintf(szCmd, "SC=%d:%02d/%d\r\n", ltime.tm_hour, ltime.tm_min, lday);
189+
WriteToHardware((const char*)&szCmd, strlen(szCmd));
190+
}
191+
173192
void OTGWSerial::SendOutsideTemperature()
174193
{
175194
float temp;
@@ -183,7 +202,14 @@ void OTGWSerial::SendOutsideTemperature()
183202
void OTGWSerial::SetSetpoint(const int idx, const float temp)
184203
{
185204
char szCmd[30];
186-
if (idx==5)
205+
if (idx == 1)
206+
{
207+
//Control Set Point (MsgID=1)
208+
_log.Log(LOG_STATUS, "OTGW: Setting Control SetPoint to: %.1f", temp);
209+
sprintf(szCmd, "CS=%.1f\r\n", temp);
210+
write((const char*)&szCmd, strlen(szCmd));
211+
}
212+
else if (idx == 5)
187213
{
188214
//Room Set Point
189215
//Make this a temporarily Set Point, this will be overridden when the thermostat changes/applying it's program
@@ -207,10 +233,11 @@ void OTGWSerial::SetSetpoint(const int idx, const float temp)
207233
}
208234
}
209235

210-
void OTGWSerial::WriteToHardware(const char *pdata, const unsigned char length)
236+
bool OTGWSerial::WriteToHardware(const char *pdata, const unsigned char length)
211237
{
212-
if (isOpen()) {
213-
write(pdata,length);
214-
}
238+
if (!isOpen())
239+
return false;
240+
write(pdata,length);
241+
return true;
215242
}
216243

hardware/OTGWSerial.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
class OTGWSerial: public AsyncSerial, public OTGWBase
77
{
88
public:
9-
OTGWSerial(const int ID, const std::string& devname, const unsigned int baud_rate, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5);
9+
OTGWSerial(const int ID, const std::string& devname, const unsigned int baud_rate, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6);
1010
~OTGWSerial();
1111

12-
void WriteToHardware(const char *pdata, const unsigned char length);
12+
bool WriteToHardware(const char *pdata, const unsigned char length);
1313
void SetSetpoint(const int idx, const float temp);
1414
private:
1515
bool StartHardware();
@@ -20,6 +20,7 @@ class OTGWSerial: public AsyncSerial, public OTGWBase
2020
void StopPollerThread();
2121
void GetGatewayDetails();
2222
void SendOutsideTemperature();
23+
void SendTime();
2324
void Do_PollWork();
2425
int m_retrycntr;
2526
boost::shared_ptr<boost::thread> m_pollerthread;

hardware/OTGWTCP.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#define RETRY_DELAY 30
1010

11-
OTGWTCP::OTGWTCP(const int ID, const std::string IPAddress, const unsigned short usIPPort, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5)
11+
OTGWTCP::OTGWTCP(const int ID, const std::string IPAddress, const unsigned short usIPPort, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6)
1212
{
1313
m_HwdID=ID;
1414
m_bDoRestart=false;
@@ -33,7 +33,7 @@ OTGWTCP::OTGWTCP(const int ID, const std::string IPAddress, const unsigned short
3333
m_stoprequested=false;
3434
m_szIPAddress=IPAddress;
3535
m_usIPPort=usIPPort;
36-
SetModes(Mode1,Mode2,Mode3,Mode4,Mode5);
36+
SetModes(Mode1,Mode2,Mode3,Mode4,Mode5,Mode6);
3737
}
3838

3939
OTGWTCP::~OTGWTCP(void)
@@ -144,6 +144,7 @@ void OTGWTCP::Do_Work()
144144
{
145145
bFirstTime=false;
146146
SendOutsideTemperature();
147+
SendTime();
147148
GetGatewayDetails();
148149
}
149150
}
@@ -159,6 +160,23 @@ void OTGWTCP::GetGatewayDetails()
159160
write((const unsigned char*)&szCmd,strlen(szCmd));
160161
}
161162

163+
void OTGWTCP::SendTime()
164+
{
165+
time_t atime = mytime(NULL);
166+
struct tm ltime;
167+
localtime_r(&atime, &ltime);
168+
169+
int lday = 0;
170+
if (ltime.tm_wday == 0)
171+
lday = 7;
172+
else
173+
lday = ltime.tm_wday;
174+
175+
char szCmd[20];
176+
sprintf(szCmd, "SC=%d:%02d/%d\r\n", ltime.tm_hour, ltime.tm_min, lday);
177+
WriteToHardware((const char*)&szCmd, strlen(szCmd));
178+
}
179+
162180
void OTGWTCP::SendOutsideTemperature()
163181
{
164182
float temp;
@@ -172,7 +190,14 @@ void OTGWTCP::SendOutsideTemperature()
172190
void OTGWTCP::SetSetpoint(const int idx, const float temp)
173191
{
174192
char szCmd[30];
175-
if (idx==5)
193+
if (idx == 1)
194+
{
195+
//Control Set Point (MsgID=1)
196+
_log.Log(LOG_STATUS, "OTGW: Setting Control SetPoint to: %.1f", temp);
197+
sprintf(szCmd, "CS=%.1f\r\n", temp);
198+
write((const unsigned char*)&szCmd, strlen(szCmd));
199+
}
200+
else if (idx == 5)
176201
{
177202
//Room Set Point
178203
//Make this a temporarily Set Point, this will be overridden when the thermostat changes/applying it's program
@@ -212,11 +237,12 @@ void OTGWTCP::OnError(const boost::system::error_code& error)
212237
_log.Log(LOG_ERROR,"OTGW: Error: %s",error.message().c_str());
213238
}
214239

215-
void OTGWTCP::WriteToHardware(const char *pdata, const unsigned char length)
240+
bool OTGWTCP::WriteToHardware(const char *pdata, const unsigned char length)
216241
{
217242
if (!mIsConnected)
218243
{
219-
return;
244+
return false;
220245
}
221246
// write(pdata,length,0);
247+
return true;
222248
}

hardware/OTGWTCP.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
class OTGWTCP: public OTGWBase, ASyncTCP
99
{
1010
public:
11-
OTGWTCP(const int ID, const std::string IPAddress, const unsigned short usIPPort, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5);
11+
OTGWTCP(const int ID, const std::string IPAddress, const unsigned short usIPPort, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6);
1212
~OTGWTCP(void);
1313
bool isConnected(){ return mIsConnected; };
14-
void WriteToHardware(const char *pdata, const unsigned char length);
14+
bool WriteToHardware(const char *pdata, const unsigned char length);
1515
void SetSetpoint(const int idx, const float temp);
1616
public:
1717
// signals
@@ -22,6 +22,7 @@ class OTGWTCP: public OTGWBase, ASyncTCP
2222
bool StopHardware();
2323
void GetGatewayDetails();
2424
void SendOutsideTemperature();
25+
void SendTime();
2526
protected:
2627
std::string m_szIPAddress;
2728
unsigned short m_usIPPort;

0 commit comments

Comments
 (0)