Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update esa.c #2888

wants to merge 1 commit into from

Conversation

dclawin
Copy link

@dclawin dclawin commented Mar 29, 2024

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.

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)
Copy link
Collaborator

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;
Copy link
Collaborator

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++) {
Copy link
Collaborator

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];;
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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 ;
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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 )
Copy link
Collaborator

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";
Copy link
Collaborator

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) {
Copy link
Collaborator

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 {}?

@zuckschwerdt
Copy link
Collaborator

Thanks! Some notes about code style otherwise looks mostly good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants