Skip to content

Commit 54dffac

Browse files
authored
Merge pull request #858 from gordonb3/P1MeterPartialLines
Fix for P1 hardware submitting arbitrary partial lines
2 parents ebdf3ce + ba3f03a commit 54dffac

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

hardware/P1MeterBase.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void P1MeterBase::Init()
8585
{
8686
m_linecount=0;
8787
m_exclmarkfound=0;
88+
l_exclmarkfound=0;
8889
m_CRfound=0;
8990
m_bufferpos=0;
9091
l_bufferpos=0;
@@ -155,7 +156,7 @@ bool P1MeterBase::MatchLine()
155156
break;
156157
case EXCLMARK:
157158
if(strncmp(t.key, (const char*)&l_buffer, strlen(t.key)) == 0) {
158-
m_exclmarkfound=1;
159+
l_exclmarkfound=1;
159160
found=1;
160161
}
161162
else
@@ -168,7 +169,7 @@ bool P1MeterBase::MatchLine()
168169
if(!found)
169170
continue;
170171

171-
if (m_exclmarkfound) {
172+
if (l_exclmarkfound) {
172173
time_t atime=mytime(NULL);
173174
sDecodeRXMessage(this, (const unsigned char *)&m_p1power, "Power", 255);
174175
bool bSend2Shared=(atime-m_lastSharedSendElectra>59);
@@ -190,7 +191,7 @@ bool P1MeterBase::MatchLine()
190191
sDecodeRXMessage(this, (const unsigned char *)&m_p1gas, "Gas", 255);
191192
}
192193
m_linecount=0;
193-
m_exclmarkfound=0;
194+
l_exclmarkfound=0;
194195
}
195196
else
196197
{
@@ -368,16 +369,18 @@ void P1MeterBase::ParseData(const unsigned char *pData, int Len, unsigned char d
368369
m_linecount = 1;
369370
l_bufferpos = 0;
370371
m_bufferpos = 0;
372+
m_exclmarkfound = 0;
371373
}
372374

373375
// assemble complete message in message buffer
374-
while ((ii<Len) && (m_linecount>0) && (m_bufferpos<sizeof(m_buffer))){
376+
while ((ii<Len) && (m_linecount>0) && (!m_exclmarkfound) && (m_bufferpos<sizeof(m_buffer))){
375377
const unsigned char c = pData[ii];
376378
m_buffer[m_bufferpos] = c;
377379
m_bufferpos++;
378380
if(c==0x21){
379381
// stop reading at exclamation mark (do not include CRC)
380382
ii=Len;
383+
m_exclmarkfound = 1;
381384
}else{
382385
ii++;
383386
}

hardware/P1MeterBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class P1MeterBase : public CDomoticzHardwareBase
2929
int m_bufferpos;
3030
unsigned char l_buffer[128];
3131
int l_bufferpos;
32+
unsigned char l_exclmarkfound;
3233

3334
bool CheckCRC();
3435
};

0 commit comments

Comments
 (0)