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

Function needs to return a negative number #4

Open
amravs opened this issue Aug 23, 2023 · 4 comments
Open

Function needs to return a negative number #4

amravs opened this issue Aug 23, 2023 · 4 comments

Comments

@amravs
Copy link

amravs commented Aug 23, 2023

Hi

This is great work and helping me immensely extract data but when I apply the functions the flow of energy is always positive eg battery power should flow in and out depending on the demand?

function read16BitSigned(n) {
if (n < 32768) {
return n;
} else {
return n - 65536;
}

The returned value is always positive and a slight tweak to ensure a signed return would be to multiply the < 32768 by -1?

I aplied this change to my config and my energy flows are now correct.

function read16BitSigned(n) {
if (n < 32768) {
return n*-1;
} else {
return n - 65536;
}

What do you think?

@nazar-pc
Copy link
Owner

If n is 32768 or more the result will be negative. I have no idea why manufacturer couldn't just return normal signed integers, but we have what we have.

@amravs
Copy link
Author

amravs commented Aug 23, 2023 via email

@simonebortolin
Copy link
Contributor

simonebortolin commented Aug 23, 2023

at a guess they are simple 2's complement numbers poorly converted

@amravs
Copy link
Author

amravs commented Aug 23, 2023 via email

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

No branches or pull requests

3 participants