-
Notifications
You must be signed in to change notification settings - Fork 49
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
Expose the workarounds
struct as part of public API
#133
Conversation
thanks for taking this on! it seems a bit scary to need so much code for this, "easier" (for the codebase, not the user) solutions could be:
|
don't have time for a detailed code review atm, will try to have a closer look asap. |
it's the same in any language, you need some data structure(s) to manage state - object oriented programming only makes it more explicit, but the logic is the same. (almost) every function you added the workarounds parameter to already takes an sml_buffer, which should be the right place to add the flag. |
60accef
to
90e9b73
Compare
I made the |
actually it's quite wasteful to use a struct of ints for a set of boolean flags. |
Definitely more efficient, yes. I feel like I'm leaving my comfort zone of a desktop developer when it comes to keeping things really small and portable though. :) Just to sync before I do the rebase dance, I'd set it up like this: typedef int16_t sml_workarounds;
const int16_t sml_workaround_dzg_negative = 0x01;
// Add it to sml_buffer:
sml_workarounds workarounds;
// Now we can simply
if (buf->workarounds & sml_workaround_dzg_negative) { /* profit */ } ...so that the magic numbers actually have names. While I don't like this (potential) heap of not-really-encapsulated numbers too much I have to admit this is more elegant than copying values into the |
one would normally use constants (#define, in uppercase) to label the bits, no need to waste space on read-only variables :) i'm sorry that i don't find the time for a more detailed review, it seems a waste of your time to keep rewriting most of the code for such small iterative steps. |
The struct `sml_workarounds` has become a bitmap now, and it is part of the public API. I rephrased the DZG workaround explanation a bit to match the new information: The workaround can't be applied automatically because we need meter model *and* serial number, but only get the latter via SML. The serial numbers that have the fix apparently differ between DZG meter models. This is also why `sml_workarounds` needs to be public: There needs to be a way for the libsml user to configure at least this workaround for the meter at hand. Implementing it as a bitmap is memory-efficient in contrast to passing an additional struct around everywhere. Adding `sml_workarounds` to `sml_buffer` makes it possible to configure workarounds individually for multiple meters that may be handled by the user, each of which will have their own buffer.
This is necessary since we can't decide automatically if the workaround needs to be enabled. (See previous commits for details.)
90e9b73
to
e4201d3
Compare
Aaah, the C world comes at me in big waves. I'd love to put the workaround options into an
I'm used to iterative reviews, no worries. And I do appreciate very much that you are as responsive as you are, things are lingering around for much longer in other places! :) The changeset has become much smaller by now and feels less invasive, so the iteration was definitely worth it. |
Make use of libsml's workaround options to apply a workaround for DZG meters. This builds upon the changes from [libsml PR volkszaehler#133](volkszaehler/libsml#133).
Make use of libsml's workaround options to apply a workaround for DZG meters. This builds upon the changes from [libsml PR volkszaehler#133](volkszaehler/libsml#133).
@@ -56,6 +56,43 @@ typedef int64_t i64; | |||
#define SML_TYPE_NUMBER_32 sizeof(u32) | |||
#define SML_TYPE_NUMBER_64 sizeof(u64) | |||
|
|||
// A bitmap to configure workarounds. | |||
typedef int16_t sml_workarounds; |
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.
would make this uint
, so we can safely use all the bits.
i wonder if it should be 32 bits, this library is probably too large for 16 bit machines, otoh. we won't need that many entries anyway...
sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) { | ||
sml_file *sml_file_parse(unsigned char *buffer, | ||
size_t buffer_len, | ||
const sml_workarounds workarounds) { |
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.
i'm a bit confused that our "constructor" is named _parse
, but yes, this is the correct place for that code :)
printf("-h - help\n"); | ||
printf("-s - process only one OBIS data stream (single)\n"); | ||
printf("-v - verbose\n"); | ||
exit(0); // exit here | ||
break; | ||
case 'd': |
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.
in "production" we should probably not have an extra flag for each workaround, but i guess in an example program and while there is only one, this is ok :)
/* | ||
* Workaround for certain DZG meters that encode the consumption wrongly. | ||
* Affected: | ||
* - Model TODO with serial numbers starting with 6 (in decimal) |
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.
DVS74
https://www.dzg.de/fileadmin/dzg/content/downloads/produkte-zaehler/dvs74/DZG_DVS74-G2_data_sheet.pdf
the other parts of the model I mentioned are just encoding how many things it can measure, afaict
* - Model TODO with serial numbers starting with 6 (in decimal) | ||
* | ||
* We only get the serial number, not the meter model via SML. Since model | ||
* DWSB.2TH (serial starting with 4) does not exhibit this bug, we can't |
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.
is that an EWE specific model? I only found this
https://www.ewe-netz.de/-/media/ewe-netz/downloads/zaehleranleitung/dzg_dwsb20_2th_95003041.pdf
then again, there's this
https://www.dzg.de/fileadmin/dzg/content/downloads/produkte-zaehler/dvsb/DZG_DVSB_DWSB_Handbuch_230612_01.pdf and https://www.dzg.de/produkte/moderne-messeinrichtung#dvsb
which documents the whole series - so maybe this is the whole DVSB series?
This has become obsolete through the more specific workaround merged above. |
This is supposed to become a sensible fix for #132. In that issue, it turned out that the workaround for broken negative values from DZG power meters cannot be applied automatically. For one model, DZG confirmed that the bug was fixed in devices with serial numbers starting with 6 (#106) - of a certain model, apparently. I have a different model, the DZG DWSB20.2TH with a serial number starting with 4. Mine does not exhibit the bug.
Since we only get the serial number and not the meter model via SML there is no way to reliably enable the fix automatically. Therefore I tried to expose the struct holding workaround flags as part of the public
libsml
API.This also implies a corresponding PR for vzlogger. I have the code already and could push it anytime, however I may spare myself a rebase or two if we discuss this one first, maybe?
Open Questions