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

min_value option for time fields is being read incorrectly #48

Closed
tomtrafford opened this issue Feb 29, 2024 · 8 comments
Closed

min_value option for time fields is being read incorrectly #48

tomtrafford opened this issue Feb 29, 2024 · 8 comments

Comments

@tomtrafford
Copy link
Contributor

The server should try to parse a min_value (preceded by a '>' character) of Time fields in the config file. Currently this leads to an unexpected character error. After discussing this with @Araneidae, there is a bug in the server as it is trying to parse the min_value from the registers file instead.

This functionality is not currently used, is it worth implementing correctly or should this be removed. @coretl Are there use cases for this to be implemented correctly?

@Araneidae
Copy link
Contributor

The documentation clearly describes this as part of the field type (rather than subtype) here:

``time`` [ ``>`` min_value ]
Time fields behave like ``param`` fields, but need special treatment because
the underlying value is 64-bits and so two registers need to be written.
If desired a minimum valid value can be specified as `min_value`. This will
prevent the writing of values less than this value and can be read as the
``.MIN`` attribute.
but alas the implementation, as @tomtrafford says, parses this as part of the register file parsing here:
IF(**line != '\0',
parse_whitespace(line) ?:
parse_char(line, '>') ?:
parse_uint64(line, &state->min_value));

We can fix the documentation, fix the implementation, or drop the functionality altogether. In order, I'd prefer to drop the functionality or fix the implementation if necessary; this behaviour is part of the user interface (and it can be interrogated via the .MIN attribute), so definitely belongs in config, not register. However, if this is obsolete and unused it ought to go! We'd have to remove .MIN at the same time, of course.

@Araneidae
Copy link
Contributor

@coretl, do you have a preference here? I'd prefer to drop support for this feature altogether as it doesn't appear to be used.

Araneidae added a commit that referenced this issue Mar 7, 2024
This will fix issues #48 and #30 in the simplest possible way!
@coretl
Copy link
Contributor

coretl commented Mar 8, 2024

There are a couple of cases where the field must be non-zero, but generally we just treat 0 as "the shortest possible time period", so I'm happy to stick with that behaviour and remove this feature

@Araneidae
Copy link
Contributor

The code always guards against writing 0 to time fields, and I haven't changed that, here's the relevant part of the diff:

diff --git a/server/time.c b/server/time.c
@@ -143,7 +135,7 @@ static error__t write_time_value(
 {
     struct time_class_state *state = class_data;
     error__t error =
-        TEST_OK_(value == 0  ||  value > state->min_value, "Value too small");
+        TEST_OK_(value == 0, "Value too small");
     if (!error)
         WITH_MUTEX(state->mutex)
         {

I would push my merge, but PR #55 needs to be approved first.

@coretl
Copy link
Contributor

coretl commented Mar 11, 2024

Well I'm very confused then, because we explicitly use PULSE.WIDTH = 0 as a flag:
https://github.com/PandABlocks/PandABlocks-FPGA/blob/e967856854a5d4face263292523fb4ec8e70dd26/modules/pulse/pulse.block.ini#L14-L17

And I've just testing writing 0 to PULSE.WIDTH on a live PandA and it works...

@coretl
Copy link
Contributor

coretl commented Mar 11, 2024

Wait, doesn't this:

TEST_OK_(value == 0  ||  value > state->min_value, "Value too small");

mean that a value of 0, or a value greater than min_value is fine? In which case deleting the TEST_OK_ line completely seems better?

@Araneidae
Copy link
Contributor

Oops. It's worse than that: my patch now only accepts 0 as an input. I'd better fix that...

Araneidae added a commit that referenced this issue Mar 12, 2024
This will fix issues #48 and #30 in the simplest possible way!
@Araneidae
Copy link
Contributor

I do realise now that simply fixing the documentation would have been easier. Oh well, it's not being used, so let's get rid of the feature.

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