-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update esa.c #2888
base: master
Are you sure you want to change the base?
Update esa.c #2888
Conversation
Update: Support for Gira-EHZ sensor added (Gira Wtterstation). Data format and encoding is very similar to ESA1000. Gira/ELV added two bytes for running power consumption.
@@ -13,72 +15,149 @@ | |||
|
|||
#define MAXMSG 40 // ESA messages | |||
|
|||
static uint8_t decrypt_esa(uint8_t *b) | |||
static uint16_t decrypt_esa(uint8_t *b,unsigned blen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space before keywords, , unsigned
|
||
for (i = 0; i < 15; i++) { | ||
uint8_t i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce scope to the loop, for (int i; ...
for (i = 0; i < 15; i++) { | ||
uint8_t i = 0; | ||
uint8_t byte; | ||
for (i = 0; i < blen-3; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces around operators: blen - 3
byte = b[pos]; | ||
crc += byte; | ||
// byte = b[pos]; // ?? | ||
crc += b[pos];; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra semicolon ;
return crc; | ||
} | ||
|
||
/** | ||
ELV Energy Counter ESA 1000/2000. | ||
ELV Energy Counter ESA 1000/2000, GIRA EHZ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First comment line needs a dot at the end.
|
||
ELVx000 data format, copied from FHEM source: (soory, in German) | ||
|
||
ss Sequenze und Sequenzwiederhohlung mit gesetzten h?chsten Bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preformatted blocks need an indent of four spaces
*/ | ||
static int esa_cost_callback(r_device *decoder, bitbuffer_t *bitbuffer) | ||
{ | ||
data_t *data; | ||
uint8_t b[MAXMSG]; | ||
uint16_t crc ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove space before semicolon
unsigned is_retry, sequence_id, deviceid, impulses; | ||
char *model; | ||
|
||
unsigned is_retry, sequence_id, deviceid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use one line for each var.
|
||
unsigned is_retry, sequence_id, deviceid; | ||
unsigned status=0; | ||
unsigned power=0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space around equal sign
|
||
// remove first two bytes? | ||
bitbuffer_extract_bytes(bitbuffer, 0, 16, b, 160 - 16); | ||
if ( (! (len == 176 || len == 160 )) || bitbuffer->num_rows != 1 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove spaces inside parens: if ((!(len == 176...
Use braces also on single line blocks if () {
|
||
switch(crc) { | ||
case 0xf00f: { // ESA | ||
if (b[3] == 0x01) model = "ESAx000WZ"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need different protocol "model" keys?
// b[8],b[9],b[10],b[11],b[12],b[13],b[14],b[15],b[16] ); | ||
// decoder_logf(decoder, 1, __func__,"Checks: %4i %02x %02x %02x",len,b[17],b[18],b[19]) ; | ||
|
||
switch(crc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this easier to write as if (...) {} else if (...) {} else {}
?
Thanks! Some notes about code style otherwise looks mostly good. |
Update: Support for Gira-EHZ sensor added (part of Gira Wetterstation). Data format and encoding are very similar to ESA1000. Gira/ELV added two bytes for running power consumption.